| 1 |
|
|
1 |
|
|
| 2 |
|
// Copyright (c) 2022 Vinnie Falco (vinnie.falco@gmail.com)
|
2 |
|
// Copyright (c) 2022 Vinnie Falco (vinnie.falco@gmail.com)
|
| 3 |
|
|
3 |
|
|
| 4 |
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
4 |
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
| 5 |
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
5 |
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
| 6 |
|
|
6 |
|
|
| 7 |
|
// Official repository: https://github.com/boostorg/url
|
7 |
|
// Official repository: https://github.com/boostorg/url
|
| 8 |
|
|
8 |
|
|
| 9 |
|
|
9 |
|
|
| 10 |
|
#ifndef BOOST_URL_DETAIL_URL_IMPL_HPP
|
10 |
|
#ifndef BOOST_URL_DETAIL_URL_IMPL_HPP
|
| 11 |
|
#define BOOST_URL_DETAIL_URL_IMPL_HPP
|
11 |
|
#define BOOST_URL_DETAIL_URL_IMPL_HPP
|
| 12 |
|
|
12 |
|
|
| 13 |
|
#include <boost/url/host_type.hpp>
|
13 |
|
#include <boost/url/host_type.hpp>
|
| 14 |
|
#include <boost/url/pct_string_view.hpp>
|
14 |
|
#include <boost/url/pct_string_view.hpp>
|
| 15 |
|
#include <boost/url/scheme.hpp>
|
15 |
|
#include <boost/url/scheme.hpp>
|
| 16 |
|
#include <boost/core/detail/string_view.hpp>
|
16 |
|
#include <boost/core/detail/string_view.hpp>
|
| 17 |
|
#include <boost/url/detail/parts_base.hpp>
|
17 |
|
#include <boost/url/detail/parts_base.hpp>
|
| 18 |
|
#include <boost/assert.hpp>
|
18 |
|
#include <boost/assert.hpp>
|
| 19 |
|
|
19 |
|
|
| 20 |
|
|
20 |
|
|
| 21 |
|
|
21 |
|
|
| 22 |
|
|
22 |
|
|
| 23 |
|
|
23 |
|
|
| 24 |
|
|
24 |
|
|
| 25 |
|
|
25 |
|
|
| 26 |
|
|
26 |
|
|
| 27 |
|
|
27 |
|
|
| 28 |
|
|
28 |
|
|
| 29 |
|
constexpr char const* const empty_c_str_ = "";
|
29 |
|
constexpr char const* const empty_c_str_ = "";
|
| 30 |
|
|
30 |
|
|
| 31 |
|
// This is the private 'guts' of a
|
31 |
|
// This is the private 'guts' of a
|
| 32 |
|
// url_view, exposed so different parts
|
32 |
|
// url_view, exposed so different parts
|
| 33 |
|
// of the implementation can work on it.
|
33 |
|
// of the implementation can work on it.
|
| 34 |
|
// It stores the offsets and properties of
|
34 |
|
// It stores the offsets and properties of
|
| 35 |
|
// a URL string stored elsewhere and pointed
|
35 |
|
// a URL string stored elsewhere and pointed
|
| 36 |
|
|
36 |
|
|
| 37 |
|
struct BOOST_URL_DECL url_impl : parts_base
|
37 |
|
struct BOOST_URL_DECL url_impl : parts_base
|
| 38 |
|
|
38 |
|
|
| 39 |
|
|
39 |
|
|
| 40 |
|
|
40 |
|
|
| 41 |
|
std::size_t const zero_ = 0;
|
41 |
|
std::size_t const zero_ = 0;
|
| 42 |
|
|
42 |
|
|
| 43 |
|
|
43 |
|
|
| 44 |
|
char const* cs_ = empty_c_str_;
|
44 |
|
char const* cs_ = empty_c_str_;
|
| 45 |
|
|
45 |
|
|
| 46 |
|
std::size_t offset_[id_end + 1] = {};
|
46 |
|
std::size_t offset_[id_end + 1] = {};
|
| 47 |
|
std::size_t decoded_[id_end] = {};
|
47 |
|
std::size_t decoded_[id_end] = {};
|
| 48 |
|
|
48 |
|
|
| 49 |
|
|
49 |
|
|
| 50 |
|
unsigned char ip_addr_[16] = {};
|
50 |
|
unsigned char ip_addr_[16] = {};
|
| 51 |
|
// VFALCO don't we need a bool?
|
51 |
|
// VFALCO don't we need a bool?
|
| 52 |
|
std::uint16_t port_number_ = 0;
|
52 |
|
std::uint16_t port_number_ = 0;
|
| 53 |
|
|
53 |
|
|
| 54 |
|
|
54 |
|
|
| 55 |
|
|
55 |
|
|
| 56 |
|
|
56 |
|
|
| 57 |
|
|
57 |
|
|
| 58 |
|
from from_ = from::string;
|
58 |
|
from from_ = from::string;
|
| 59 |
|
|
59 |
|
|
| 60 |
|
|
60 |
|
|
| 61 |
|
|
61 |
|
|
| 62 |
|
|
62 |
|
|
| 63 |
|
|
63 |
|
|
| 64 |
|
|
64 |
|
|
| 65 |
|
|
65 |
|
|
| 66 |
|
|
66 |
|
|
| 67 |
|
url_view construct() const noexcept;
|
67 |
|
url_view construct() const noexcept;
|
| 68 |
|
|
68 |
|
|
| 69 |
|
|
69 |
|
|
| 70 |
|
|
70 |
|
|
| 71 |
|
construct_authority() const noexcept;
|
71 |
|
construct_authority() const noexcept;
|
| 72 |
|
|
72 |
|
|
| 73 |
|
std::size_t len(int, int) const noexcept;
|
73 |
|
std::size_t len(int, int) const noexcept;
|
| 74 |
|
std::size_t len(int) const noexcept;
|
74 |
|
std::size_t len(int) const noexcept;
|
| 75 |
|
std::size_t offset(int) const noexcept;
|
75 |
|
std::size_t offset(int) const noexcept;
|
| 76 |
|
core::string_view get(int) const noexcept;
|
76 |
|
core::string_view get(int) const noexcept;
|
| 77 |
|
core::string_view get(int, int) const noexcept;
|
77 |
|
core::string_view get(int, int) const noexcept;
|
| 78 |
|
pct_string_view pct_get(int) const noexcept;
|
78 |
|
pct_string_view pct_get(int) const noexcept;
|
| 79 |
|
pct_string_view pct_get(int, int) const noexcept;
|
79 |
|
pct_string_view pct_get(int, int) const noexcept;
|
| 80 |
|
void set_size(int, std::size_t) noexcept;
|
80 |
|
void set_size(int, std::size_t) noexcept;
|
| 81 |
|
void split(int, std::size_t) noexcept;
|
81 |
|
void split(int, std::size_t) noexcept;
|
| 82 |
|
void adjust_right(int first, int last, std::size_t n) noexcept;
|
82 |
|
void adjust_right(int first, int last, std::size_t n) noexcept;
|
| 83 |
|
void adjust_left(int first, int last, std::size_t n) noexcept;
|
83 |
|
void adjust_left(int first, int last, std::size_t n) noexcept;
|
| 84 |
|
void collapse(int, int, std::size_t) noexcept;
|
84 |
|
void collapse(int, int, std::size_t) noexcept;
|
| 85 |
|
|
85 |
|
|
| 86 |
|
void apply_scheme(core::string_view) noexcept;
|
86 |
|
void apply_scheme(core::string_view) noexcept;
|
| 87 |
|
void apply_userinfo(pct_string_view const&,
|
87 |
|
void apply_userinfo(pct_string_view const&,
|
| 88 |
|
pct_string_view const*) noexcept;
|
88 |
|
pct_string_view const*) noexcept;
|
| 89 |
|
void apply_host(host_type, pct_string_view,
|
89 |
|
void apply_host(host_type, pct_string_view,
|
| 90 |
|
unsigned char const*) noexcept;
|
90 |
|
unsigned char const*) noexcept;
|
| 91 |
|
void apply_port(core::string_view, unsigned short) noexcept;
|
91 |
|
void apply_port(core::string_view, unsigned short) noexcept;
|
| 92 |
|
void apply_authority(authority_view const&) noexcept;
|
92 |
|
void apply_authority(authority_view const&) noexcept;
|
| 93 |
|
void apply_path(pct_string_view, std::size_t) noexcept;
|
93 |
|
void apply_path(pct_string_view, std::size_t) noexcept;
|
| 94 |
|
void apply_query(pct_string_view, std::size_t) noexcept;
|
94 |
|
void apply_query(pct_string_view, std::size_t) noexcept;
|
| 95 |
|
void apply_frag(pct_string_view) noexcept;
|
95 |
|
void apply_frag(pct_string_view) noexcept;
|
| 96 |
|
|
96 |
|
|
| 97 |
|
|
97 |
|
|
| 98 |
|
//------------------------------------------------
|
98 |
|
//------------------------------------------------
|
| 99 |
|
|
99 |
|
|
| 100 |
|
// this allows a path to come from a
|
100 |
|
// this allows a path to come from a
|
| 101 |
|
// url_impl or a separate core::string_view
|
101 |
|
// url_impl or a separate core::string_view
|
| 102 |
|
|
102 |
|
|
| 103 |
|
|
103 |
|
|
| 104 |
|
|
104 |
|
|
| 105 |
|
url_impl const* impl_ = nullptr;
|
105 |
|
url_impl const* impl_ = nullptr;
|
| 106 |
|
char const* data_ = nullptr;
|
106 |
|
char const* data_ = nullptr;
|
| 107 |
|
|
107 |
|
|
| 108 |
|
|
108 |
|
|
| 109 |
|
|
109 |
|
|
| 110 |
|
|
110 |
|
|
| 111 |
|
|
111 |
|
|
| 112 |
|
|
112 |
|
|
| 113 |
|
path_ref(url_impl const& impl) noexcept;
|
113 |
|
path_ref(url_impl const& impl) noexcept;
|
| 114 |
|
path_ref(core::string_view,
|
114 |
|
path_ref(core::string_view,
|
| 115 |
|
std::size_t, std::size_t) noexcept;
|
115 |
|
std::size_t, std::size_t) noexcept;
|
| 116 |
|
pct_string_view buffer() const noexcept;
|
116 |
|
pct_string_view buffer() const noexcept;
|
| 117 |
|
std::size_t size() const noexcept;
|
117 |
|
std::size_t size() const noexcept;
|
| 118 |
|
char const* data() const noexcept;
|
118 |
|
char const* data() const noexcept;
|
| 119 |
|
char const* end() const noexcept;
|
119 |
|
char const* end() const noexcept;
|
| 120 |
|
std::size_t nseg() const noexcept;
|
120 |
|
std::size_t nseg() const noexcept;
|
| 121 |
|
std::size_t decoded_size() const noexcept;
|
121 |
|
std::size_t decoded_size() const noexcept;
|
| 122 |
|
|
122 |
|
|
| 123 |
|
|
123 |
|
|
| 124 |
|
|
124 |
|
|
| 125 |
|
url_impl const& impl) const noexcept
|
125 |
|
url_impl const& impl) const noexcept
|
| 126 |
|
|
126 |
|
|
| 127 |
|
|
127 |
|
|
| 128 |
|
|
128 |
|
|
| 129 |
|
|
129 |
|
|
| 130 |
|
|
130 |
|
|
| 131 |
|
|
131 |
|
|
| 132 |
|
path_ref const& ref) const noexcept
|
132 |
|
path_ref const& ref) const noexcept
|
| 133 |
|
|
133 |
|
|
| 134 |
|
|
134 |
|
|
| 135 |
|
return impl_ == ref.impl_;
|
135 |
|
return impl_ == ref.impl_;
|
| 136 |
|
BOOST_ASSERT(data_ != ref.data_ || (
|
136 |
|
BOOST_ASSERT(data_ != ref.data_ || (
|
| 137 |
|
|
137 |
|
|
| 138 |
|
|
138 |
|
|
| 139 |
|
|
139 |
|
|
| 140 |
|
return data_ == ref.data_;
|
140 |
|
return data_ == ref.data_;
|
| 141 |
|
|
141 |
|
|
| 142 |
|
|
142 |
|
|
| 143 |
|
|
143 |
|
|
| 144 |
|
//------------------------------------------------
|
144 |
|
//------------------------------------------------
|
| 145 |
|
|
145 |
|
|
| 146 |
|
// This class represents a query string, which
|
146 |
|
// This class represents a query string, which
|
| 147 |
|
// can originate from either an url_impl object
|
147 |
|
// can originate from either an url_impl object
|
| 148 |
|
// or an independent core::string_view.
|
148 |
|
// or an independent core::string_view.
|
| 149 |
|
class BOOST_URL_DECL query_ref
|
149 |
|
class BOOST_URL_DECL query_ref
|
| 150 |
|
|
150 |
|
|
| 151 |
|
|
151 |
|
|
| 152 |
|
url_impl const* impl_ = nullptr;
|
152 |
|
url_impl const* impl_ = nullptr;
|
| 153 |
|
char const* data_ = nullptr;
|
153 |
|
char const* data_ = nullptr;
|
| 154 |
|
|
154 |
|
|
| 155 |
|
|
155 |
|
|
| 156 |
|
|
156 |
|
|
| 157 |
|
bool question_mark_ = false;
|
157 |
|
bool question_mark_ = false;
|
| 158 |
|
|
158 |
|
|
| 159 |
|
|
159 |
|
|
| 160 |
|
|
160 |
|
|
| 161 |
|
core::string_view s, // buffer, no '?'
|
161 |
|
core::string_view s, // buffer, no '?'
|
| 162 |
|
std::size_t dn, // decoded size
|
162 |
|
std::size_t dn, // decoded size
|
| 163 |
|
|
163 |
|
|
| 164 |
|
|
164 |
|
|
| 165 |
|
|
165 |
|
|
| 166 |
|
query_ref(url_impl const& impl) noexcept;
|
166 |
|
query_ref(url_impl const& impl) noexcept;
|
| 167 |
|
pct_string_view buffer() const noexcept;
|
167 |
|
pct_string_view buffer() const noexcept;
|
| 168 |
|
std::size_t size() const noexcept; // with '?'
|
168 |
|
std::size_t size() const noexcept; // with '?'
|
| 169 |
|
char const* begin() const noexcept; // no '?'
|
169 |
|
char const* begin() const noexcept; // no '?'
|
| 170 |
|
char const* end() const noexcept;
|
170 |
|
char const* end() const noexcept;
|
| 171 |
|
std::size_t nparam() const noexcept;
|
171 |
|
std::size_t nparam() const noexcept;
|
| 172 |
|
|
172 |
|
|
| 173 |
|
|
173 |
|
|
| 174 |
|
|
174 |
|
|
| 175 |
|
url_impl const& impl) const noexcept
|
175 |
|
url_impl const& impl) const noexcept
|
| 176 |
|
|
176 |
|
|
| 177 |
|
|
177 |
|
|
| 178 |
|
|
178 |
|
|
| 179 |
|
|
179 |
|
|
| 180 |
|
|
180 |
|
|
| 181 |
|
|
181 |
|
|
| 182 |
|
query_ref const& ref) const noexcept
|
182 |
|
query_ref const& ref) const noexcept
|
| 183 |
|
|
183 |
|
|
| 184 |
|
|
184 |
|
|
| 185 |
|
return impl_ == ref.impl_;
|
185 |
|
return impl_ == ref.impl_;
|
| 186 |
|
BOOST_ASSERT(data_ != ref.data_ || (
|
186 |
|
BOOST_ASSERT(data_ != ref.data_ || (
|
| 187 |
|
|
187 |
|
|
| 188 |
|
nparam_ == ref.nparam_ &&
|
188 |
|
nparam_ == ref.nparam_ &&
|
| 189 |
|
|
189 |
|
|
| 190 |
|
return data_ == ref.data_;
|
190 |
|
return data_ == ref.data_;
|
| 191 |
|
|
191 |
|
|
| 192 |
|
|
192 |
|
|
| 193 |
|
|
193 |
|
|
| 194 |
|
|
194 |
|
|
| 195 |
|
|
195 |
|
|
| 196 |
|
|
196 |
|
|
| 197 |
|
|
197 |
|
|
| 198 |
|
|
198 |
|
|
| 199 |
|
|
199 |
|
|