Skip to content

Commit

Permalink
Improvements as mentioned on the mailing list, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeroen Habraken authored and deanberris committed Dec 22, 2009
1 parent 7906db1 commit ae9371d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 42 deletions.
File renamed without changes.
Empty file.
19 changes: 6 additions & 13 deletions boost/network/uri/detail/parse_uri.hpp
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
);
Expand Down
44 changes: 22 additions & 22 deletions boost/network/uri/http/detail/parse_specific.hpp
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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> &
Expand All @@ -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
);
Expand Down
4 changes: 2 additions & 2 deletions boost/network/uri/http/detail/uri_parts.hpp
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions boost/network/uri/http/uri.hpp
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions boost/network/uri/http/uri_concept.hpp
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit ae9371d

Please sign in to comment.