Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit11a11ab

Browse files
committed
Added a first draft of IPv6 support; initial unit tests succeed.
1 parent80c416f commit11a11ab

File tree

3 files changed

+86
-25
lines changed

3 files changed

+86
-25
lines changed

‎boost/network/uri/detail/parse_uri.hpp‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,36 @@ struct uri_grammar : qi::grammar<Iterator, detail::uri_parts<String>()> {
106106
>> iter_pos
107107
;
108108

109+
ip_literal %=
110+
qi::lit('[') >> (ipv6address | ipvfuture) >>']'
111+
;
112+
113+
ipvfuture %=
114+
qi::lit('v') >> +qi::xdigit >>'.' >> +( unreserved | sub_delims |':')
115+
;
116+
117+
ipv6address %= qi::raw[
118+
//qi::lit("1080:0:0:0:8:800:200C:417A")
119+
qi::repeat(6)[h16 >>':'] >> ls32
120+
|"::" >>qi::repeat(5)[h16 >>':'] >> ls32
121+
| qi::raw[ h16] >>"::" >>qi::repeat(4)[h16 >>':'] >> ls32
122+
| qi::raw[+(*(h16 >>':')) >> h16] >>"::" >>qi::repeat(3)[h16 >>':'] >> ls32
123+
| qi::raw[qi::repeat(2)[*(h16 >>':')] >> h16] >>"::" >>qi::repeat(2)[h16 >>':'] >> ls32
124+
| qi::raw[qi::repeat(3)[*(h16 >>':')] >> h16] >>"::" >> h16 >>':' >> ls32
125+
| qi::raw[qi::repeat(4)[*(h16 >>':')] >> h16] >>"::" >> ls32
126+
| qi::raw[qi::repeat(5)[*(h16 >>':')] >> h16] >>"::" >> h16
127+
| qi::raw[qi::repeat(6)[*(h16 >>':')] >> h16] >>"::"
128+
129+
];
130+
131+
// ls32 = ( h16 ":" h16 ) / IPv4address
132+
ls32 %= (h16 >>':' >> h16) | ipv4address
133+
;
134+
135+
// h16 = 1*4HEXDIG
136+
h16 %=qi::repeat(1,4)[qi::xdigit]
137+
;
138+
109139
// dec-octet = DIGIT / %x31-39 DIGIT / "1" 2DIGIT / "2" %x30-34 DIGIT / "25" %x30-35
110140
dec_octet %=
111141
!(qi::lit('0') >> qi::digit)
@@ -126,7 +156,7 @@ struct uri_grammar : qi::grammar<Iterator, detail::uri_parts<String>()> {
126156
// TODO, host = IP-literal / IPv4address / reg-name
127157
host %=
128158
iter_pos
129-
>> qi::omit[ipv4address | reg_name]
159+
>> qi::omit[ip_literal |ipv4address | reg_name]
130160
>> iter_pos
131161
;
132162

@@ -193,7 +223,10 @@ struct uri_grammar : qi::grammar<Iterator, detail::uri_parts<String>()> {
193223
path_abempty, path_absolute, path_rootless, path_empty;
194224

195225
qi::rule<Iterator, String()>
196-
dec_octet, ipv4address, reg_name;
226+
dec_octet, ipv4address, reg_name, ipv6address, ipvfuture, ip_literal;
227+
228+
qi::rule<Iterator, String()>
229+
h16, ls32;
197230

198231
qi::rule<Iterator, iterator_range<String>()>
199232
host, port;

‎boost/network/uri/uri_accessors.hpp‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,26 @@ typename basic_uri<Tag>::string_type decoded_path(const basic_uri<Tag> &uri) {
9292
decode(path_range,std::back_inserter(decoded_path));
9393
return decoded_path;
9494
}
95+
96+
template<
97+
classTag
98+
>
99+
typename basic_uri<Tag>::string_typedecoded_query(const basic_uri<Tag> &uri) {
100+
typename basic_uri<Tag>::const_range_type query_range = uri.query_range();
101+
typename basic_uri<Tag>::string_type decoded_query;
102+
decode(query_range,std::back_inserter(decoded_query));
103+
return decoded_query;
104+
}
105+
106+
template<
107+
classTag
108+
>
109+
typename basic_uri<Tag>::string_typedecoded_fragment(const basic_uri<Tag> &uri) {
110+
typename basic_uri<Tag>::const_range_type fragment_range = uri.fragment_range();
111+
typename basic_uri<Tag>::string_type decoded_fragment;
112+
decode(fragment_range,std::back_inserter(decoded_fragment));
113+
return decoded_fragment;
114+
}
95115
}// namespace uri
96116
}// namespace network
97117
}// namespace boost

‎libs/network/test/uri/url_test.cpp‎

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -127,29 +127,37 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ipv4_address_test, T, tag_types) {
127127
BOOST_CHECK(boost::equal(uri::path(instance), path));
128128
}
129129

130-
//// IPv6 is not yet supported by the parser
131-
//BOOST_AUTO_TEST_CASE_TEMPLATE(ipv6_address_test, T, tag_types) {
132-
// typedef uri::basic_uri<T> uri_type;
133-
// typedef typename uri_type::string_type string_type;
134-
//
135-
// const std::string url("http://1080:0:0:0:8:800:200C:417A/");
136-
// const std::string scheme("http");
137-
// const std::string host("1080:0:0:8:800:200C:417A");
138-
// const std::string path("/");
139-
//
140-
// uri_type instance(string_type(boost::begin(url), boost::end(url)));
141-
// std::cout << uri::scheme(instance) << std::endl;
142-
// std::cout << uri::user_info(instance) << std::endl;
143-
// std::cout << uri::host(instance) << std::endl;
144-
// std::cout << uri::port(instance) << std::endl;
145-
// std::cout << uri::path(instance) << std::endl;
146-
// std::cout << uri::query(instance) << std::endl;
147-
// std::cout << uri::fragment(instance) << std::endl;
148-
// BOOST_REQUIRE(uri::is_valid(instance));
149-
// BOOST_CHECK(boost::equal(uri::scheme(instance), scheme));
150-
// BOOST_CHECK(boost::equal(uri::host(instance), host));
151-
// BOOST_CHECK(boost::equal(uri::path(instance), path));
152-
//}
130+
BOOST_AUTO_TEST_CASE_TEMPLATE(ipv6_address_test_1, T, tag_types) {
131+
typedef uri::basic_uri<T> uri_type;
132+
typedeftypename uri_type::string_type string_type;
133+
134+
const std::stringurl("http://[1080:0:0:0:8:800:200C:417A]/");
135+
const std::stringscheme("http");
136+
const std::stringhost("[1080:0:0:0:8:800:200C:417A]");
137+
const std::stringpath("/");
138+
139+
uri_typeinstance(string_type(boost::begin(url),boost::end(url)));
140+
BOOST_REQUIRE(uri::is_valid(instance));
141+
BOOST_CHECK(boost::equal(uri::scheme(instance), scheme));
142+
BOOST_CHECK(boost::equal(uri::host(instance), host));
143+
BOOST_CHECK(boost::equal(uri::path(instance), path));
144+
}
145+
146+
BOOST_AUTO_TEST_CASE_TEMPLATE(ipv6_address_test_2, T, tag_types) {
147+
typedef uri::basic_uri<T> uri_type;
148+
typedeftypename uri_type::string_type string_type;
149+
150+
const std::stringurl("http://[2001:db8:85a3:8d3:1319:8a2e:370:7348]/");
151+
const std::stringscheme("http");
152+
const std::stringhost("[2001:db8:85a3:8d3:1319:8a2e:370:7348]");
153+
const std::stringpath("/");
154+
155+
uri_typeinstance(string_type(boost::begin(url),boost::end(url)));
156+
BOOST_REQUIRE(uri::is_valid(instance));
157+
BOOST_CHECK(boost::equal(uri::scheme(instance), scheme));
158+
BOOST_CHECK(boost::equal(uri::host(instance), host));
159+
BOOST_CHECK(boost::equal(uri::path(instance), path));
160+
}
153161

154162
BOOST_AUTO_TEST_CASE_TEMPLATE(ftp_test, T, tag_types) {
155163
typedef uri::basic_uri<T> uri_type;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp