Permalink
Browse files

Improvements as mentioned on the mailing list, cleanup

  • Loading branch information...
1 parent 7906db1 commit ae9371d9e97a28631274e71bf13fe96bdeae6340 Jeroen Habraken committed with mikhailberis Dec 15, 2009
File renamed without changes.
@@ -1,7 +1,7 @@
#ifndef BOOST_NETWORK_URL_DETAIL_PARSE_URL_HPP_
#define BOOST_NETWORK_URL_DETAIL_PARSE_URL_HPP_
-// Copyright 2009 Dean Michael Berris.
+// Copyright 2009 Dean Michael Berris, Jeroen Habraken.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
@@ -20,30 +20,23 @@ namespace boost { namespace network { namespace uri {
template <class Range, class Tag>
inline bool parse_uri(Range & range, uri_parts<Tag> & parts) {
- using spirit::qi::parse;
- using spirit::qi::lexeme;
- using spirit::ascii::char_;
- using spirit::ascii::cntrl;
- using spirit::ascii::alnum;
- using spirit::ascii::space;
- using namespace spirit::qi::labels;
- using fusion::tie;
+ namespace qi = boost::spirit::qi;
typedef typename range_iterator<Range>::type iterator;
typedef typename string<Tag>::type string_type;
iterator start_ = begin(range);
iterator end_ = end(range);
fusion::tuple<string_type&,string_type&> result =
- tie(parts.scheme,parts.scheme_specific_part);
+ fusion::tie(parts.scheme,parts.scheme_specific_part);
- bool ok = parse(
+ bool ok = qi::parse(
start_, end_,
(
- +((alnum|char_("+.-")) - ':')
+ (qi::alpha > *(qi::alnum | qi::char_("+.-")))
>> ':'
>>
- +(char_ - (cntrl|space))
+ +(qi::char_ - (qi::cntrl | qi::space))
),
result
);
@@ -1,14 +1,15 @@
#ifndef BOOST_NETWORK_URL_HTTP_DETAIL_PARSE_SPECIFIC_HPP_
#define BOOST_NETWORK_URL_HTTP_DETAIL_PARSE_SPECIFIC_HPP_
-// Copyright 2009 Dean Michael Berris.
+// Copyright 2009 Dean Michael Berris, Jeroen Habraken.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt of copy at
// http://www.boost.org/LICENSE_1_0.txt)
+#include <boost/algorithm/string/case_conv.hpp>
+
#include <boost/network/uri/http/detail/uri_parts.hpp>
#include <boost/network/uri/detail/parse_uri.hpp>
-#include <boost/network/uri/detail/constants.hpp>
#include <boost/network/traits/string.hpp>
namespace boost { namespace network { namespace uri {
@@ -51,6 +52,12 @@ namespace boost { namespace network { namespace uri {
uri_parts<tags::http> & parts
)
{
+ namespace qi = spirit::qi;
+
+ // For resiliency, programs interpreting URI should treat upper
+ // case letters as equivalent to lower case in scheme names
+ boost::to_lower(parts.scheme);
+
// Require that parts.scheme is either http or https
if (parts.scheme.size() < 4)
return false;
@@ -62,17 +69,6 @@ namespace boost { namespace network { namespace uri {
} else if (parts.scheme.size() > 5)
return false;
- using spirit::qi::parse;
- using spirit::qi::lit;
- using spirit::ascii::char_;
- using spirit::ascii::space;
- using spirit::ascii::alnum;
- using spirit::ascii::punct;
- using spirit::qi::lexeme;
- using spirit::qi::uint_;
- using spirit::qi::digit;
- using spirit::qi::rule;
-
typedef string<tags::http>::type string_type;
typedef range_iterator<string_type>::type iterator;
@@ -81,7 +77,7 @@ namespace boost { namespace network { namespace uri {
fusion::tuple<
optional<string_type> &,
string_type &,
- optional<uint32_t> &,
+ optional<uint16_t> &,
optional<string_type> &,
optional<string_type> &,
optional<string_type> &
@@ -95,20 +91,24 @@ namespace boost { namespace network { namespace uri {
parts.fragment
);
+ qi::rule<iterator, string_type::value_type()> reserved = qi::char_(";/?:@&=+$,");
+ qi::rule<iterator, string_type::value_type()> unreserved = qi::alnum | qi::char_("-_.!~*'()");
+ qi::rule<iterator, string_type()> escaped = qi::char_("%") > qi::repeat(2)[qi::xdigit];
+
hostname<tags::http>::parser<iterator> hostname;
- bool ok = parse(
+ bool ok = qi::parse(
start_, end_,
(
- lit("//")
- >> -lexeme[
- *((alnum|punct) - '@')
+ qi::lit("//")
+ >> -qi::lexeme[
+ *((qi::alnum | qi::punct) - '@')
>> '@'
]
>> hostname
- >> -lexeme[':' >> uint_]
- >> -lexeme['/' >> *((alnum|punct) - '?')]
- >> -lexeme['?' >> *((alnum|punct) - '#')]
- >> -lexeme['#' >> *(alnum|punct)]
+ >> -qi::lexeme[':' >> qi::ushort_]
+ >> -qi::lexeme['/' >> *((qi::alnum | qi::punct) - '?')]
+ >> -qi::lexeme['?' >> qi::raw[*(reserved | unreserved | escaped)]]
+ >> -qi::lexeme['#' >> qi::raw[*(reserved | unreserved | escaped)]]
),
result
);
@@ -1,7 +1,7 @@
#ifndef BOOST_NETWORK_URL_HTTP_DETAIL_URL_PARTS_HPP_
#define BOOST_NETWORK_URL_HTTP_DETAIL_URL_PARTS_HPP_
-// Copyright 2009 Dean Michael Berris.
+// Copyright 2009 Dean Michael Berris, Jeroen Habraken.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt of copy at
// http://www.boost.org/LICENSE_1_0.txt)
@@ -19,7 +19,7 @@ namespace boost { namespace network { namespace uri {
string_type scheme_specific_part;
optional<string_type> user_info;
string_type host;
- optional<uint32_t> port;
+ optional<uint16_t> port;
optional<string_type> path;
optional<string_type> query;
optional<string_type> fragment;
@@ -1,7 +1,7 @@
#ifndef BOOST_NETWORK_URL_HTTP_URL_HPP_
#define BOOST_NETWORK_URL_HTTP_URL_HPP_
-// Copyright 2009 Dean Michael Berris.
+// Copyright 2009 Dean Michael Berris, Jeroen Habraken.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
@@ -30,7 +30,7 @@ namespace boost { namespace network { namespace uri {
return parts_.host;
}
- uint32_t port() const {
+ uint16_t port() const {
return parts_.port ? *parts_.port :
(parts_.scheme == "https" ? 443u : 80u);
}
@@ -60,7 +60,7 @@ namespace boost { namespace network { namespace uri {
}
inline
- uint32_t
+ uint16_t
port(basic_uri<tags::http> const & uri) {
return uri.port();
}
@@ -1,7 +1,7 @@
#ifndef BOOST_NETWORK_URL_HTTP_URL_CONCEPT_HPP_
#define BOOST_NETWORK_URL_HTTP_URL_CONCEPT_HPP_
-// Copyright 2009 Dean Michael Berris.
+// Copyright 2009 Dean Michael Berris, Jeroen Habraken.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
@@ -19,7 +19,7 @@ namespace boost { namespace network { namespace uri {
{
string_type user_info_ = user_info(uri);
string_type host_ = host(uri);
- uint32_t port_ = port(uri);
+ uint16_t port_ = port(uri);
port_ = 0u;
string_type path_ = path(uri);
string_type query_ = query(uri);

0 comments on commit ae9371d

Please sign in to comment.