|
7 | 7 | // http://www.boost.org/LICENSE_1_0.txt)
|
8 | 8 |
|
9 | 9 | #include <boost/algorithm/string/predicate.hpp>
|
10 |
| -#include <boost/network/uri/http/detail/uri_parts.hpp> |
11 |
| -#include <boost/network/uri/detail/parse_uri.hpp> |
12 |
| -#include <boost/network/traits/string.hpp> |
13 | 10 |
|
14 |
| -#include <boost/spirit/include/qi_core.hpp> |
15 |
| -#include <boost/spirit/include/qi_sequence.hpp> |
16 |
| -#include <boost/spirit/include/qi_raw.hpp> |
17 |
| -#include <boost/spirit/include/qi_plus.hpp> |
18 |
| -#include <boost/spirit/include/qi_parse.hpp> |
19 |
| -#include <boost/spirit/include/qi_char_.hpp> |
20 |
| -#include <boost/spirit/include/qi_uint.hpp> |
21 |
| -#include <boost/spirit/include/qi_lexeme.hpp> |
22 |
| -#include <boost/spirit/include/qi_eps.hpp> |
23 |
| -#include <boost/spirit/include/qi_optional.hpp> |
24 |
| -#include <boost/spirit/include/phoenix_operator.hpp> |
25 |
| -#include <boost/spirit/include/support_ascii.hpp> |
26 |
| -#include <boost/spirit/include/support_argument.hpp> |
| 11 | +#include <boost/network/traits/string.hpp> |
| 12 | +#include <boost/network/uri/detail/parse_uri.hpp> |
27 | 13 |
|
28 | 14 | namespace boost { namespace network { namespace uri {
|
29 | 15 |
|
30 | 16 | namespace detail {
|
31 | 17 |
|
32 |
| - template <class Tag> |
33 |
| - struct hostname { |
34 |
| - |
35 |
| - typedef typename string<Tag>::type string_type; |
36 |
| - |
37 |
| - template <class Iterator> |
38 |
| - struct parser : spirit::qi::grammar<Iterator, string_type()> { |
39 |
| - typedef spirit::qi::grammar<Iterator, string_type()> base_type; |
40 |
| - parser() : parser::base_type(start, "hostname") { |
41 |
| - using spirit::qi::eps; |
42 |
| - using spirit::qi::alnum; |
43 |
| - using spirit::qi::_val; |
44 |
| - using spirit::qi::_1; |
45 |
| - using spirit::qi::lexeme; |
46 |
| - using spirit::ascii::char_; |
47 |
| - start = eps [_val = ""] |
48 |
| - >> +( |
49 |
| - alnum[ _val += _1 ] |
50 |
| - | lexeme[char_('.') [ _val += '.' ] >> alnum [ _val += _1] ] |
51 |
| - | lexeme[char_('-') [ _val += '-' ] >> alnum [ _val += _1] ] |
52 |
| - ); |
53 |
| - } |
54 |
| - |
55 |
| - spirit::qi::rule<Iterator, string_type()> start; |
56 |
| - }; |
57 |
| - }; |
58 |
| - |
59 | 18 | template <>
|
60 | 19 | inline bool parse_specific<
|
61 |
| - string<tags::http_default_8bit_tcp_resolve>::type, |
62 | 20 | tags::http_default_8bit_tcp_resolve
|
63 | 21 | >(
|
64 |
| - string<tags::http_default_8bit_tcp_resolve>::type & range, |
65 | 22 | uri_parts<tags::http_default_8bit_tcp_resolve> & parts
|
66 | 23 | )
|
67 | 24 | {
|
68 |
| - namespace qi = spirit::qi; |
69 |
| - |
70 |
| - // Require that parts.scheme is either http or https, case insensitive |
71 | 25 | if ((parts.scheme.size() < 4) || (parts.scheme.size() > 5))
|
72 | 26 | return false;
|
| 27 | + |
73 | 28 | if (parts.scheme.size() == 4) {
|
74 |
| - if (not boost::iequals(parts.scheme.substr(0, 4), "http")) |
| 29 | + if (not boost::iequals(parts.scheme, "http")) |
75 | 30 | return false;
|
76 |
| - } else { // size is 5 |
77 |
| - if (not boost::iequals(parts.scheme.substr(0, 5), "https")) |
| 31 | + } else { // size is 5 |
| 32 | + if (not boost::iequals(parts.scheme, "https")) |
78 | 33 | return false;
|
79 | 34 | }
|
80 |
| - |
81 |
| - typedef string<tags::http_default_8bit_tcp_resolve>::type string_type; |
82 |
| - typedef range_iterator<string_type>::type iterator; |
83 |
| - |
84 |
| - iterator start_ = begin(range); |
85 |
| - iterator end_ = end(range); |
86 |
| - fusion::tuple< |
87 |
| - optional<string_type> &, |
88 |
| - string_type &, |
89 |
| - optional<uint16_t> &, |
90 |
| - optional<string_type> &, |
91 |
| - optional<string_type> &, |
92 |
| - optional<string_type> & |
93 |
| - > result = |
94 |
| - fusion::tie( |
95 |
| - parts.user_info, |
96 |
| - parts.host, |
97 |
| - parts.port, |
98 |
| - parts.path, |
99 |
| - parts.query, |
100 |
| - parts.fragment |
101 |
| - ); |
102 | 35 |
|
103 |
| - qi::rule<iterator, string_type::value_type()> gen_delims = qi::char_(":/?#[]@"); |
104 |
| - qi::rule<iterator, string_type::value_type()> sub_delims = qi::char_("!$&'()*+,;="); |
105 |
| - qi::rule<iterator, string_type::value_type()> reserved = gen_delims | sub_delims; |
106 |
| - qi::rule<iterator, string_type::value_type()> unreserved = qi::alnum | qi::char_("-._~"); |
107 |
| - qi::rule<iterator, string_type()> pct_encoded = qi::raw[qi::char_("%") >> qi::repeat(2)[qi::xdigit]]; |
108 |
| - qi::rule<iterator, string_type()> pchar = qi::raw[unreserved | pct_encoded | sub_delims | qi::char_(":@")]; |
109 |
| - |
110 |
| - hostname<tags::http_default_8bit_tcp_resolve>::parser<iterator> hostname; |
111 |
| - bool ok = parse( |
112 |
| - start_, end_, |
113 |
| - ( |
114 |
| - qi::lit("//") |
115 |
| - >> -qi::lexeme[qi::raw[*(unreserved | pct_encoded | sub_delims | qi::char_(":"))] >> '@'] |
116 |
| - >> hostname |
117 |
| - >> -qi::lexeme[':' >> qi::ushort_] |
118 |
| - >> -qi::lexeme['/' >> qi::raw[*pchar >> *('/' >> *pchar)]] |
119 |
| - >> -qi::lexeme['?' >> qi::raw[*(pchar | qi::char_("/?"))]] |
120 |
| - >> -qi::lexeme['#' >> qi::raw[*(pchar | qi::char_("/?"))]] |
121 |
| - ), |
122 |
| - result |
123 |
| - ); |
| 36 | + if ((not parts.host) || parts.host->empty()) |
| 37 | + return false; |
124 | 38 |
|
125 |
| - return ok && start_ == end_; |
| 39 | + return true; |
126 | 40 | }
|
127 | 41 |
|
128 | 42 | } // namespace detail
|
|
0 commit comments