1  
//
1  
//
2  
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
2  
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot 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  

10  

11  
#include <boost/url/detail/config.hpp>
11  
#include <boost/url/detail/config.hpp>
12  
#include <boost/url/rfc/authority_rule.hpp>
12  
#include <boost/url/rfc/authority_rule.hpp>
13  
#include <boost/url/grammar/delim_rule.hpp>
13  
#include <boost/url/grammar/delim_rule.hpp>
14  
#include <boost/url/grammar/optional_rule.hpp>
14  
#include <boost/url/grammar/optional_rule.hpp>
15  
#include <boost/url/grammar/parse.hpp>
15  
#include <boost/url/grammar/parse.hpp>
16  
#include <boost/url/grammar/tuple_rule.hpp>
16  
#include <boost/url/grammar/tuple_rule.hpp>
17  
#include "detail/host_rule.hpp"
17  
#include "detail/host_rule.hpp"
18  
#include "detail/port_rule.hpp"
18  
#include "detail/port_rule.hpp"
19  
#include "detail/userinfo_rule.hpp"
19  
#include "detail/userinfo_rule.hpp"
20  

20  

21  
namespace boost {
21  
namespace boost {
22  
namespace urls {
22  
namespace urls {
23  

23  

24  
auto
24  
auto
25  
implementation_defined::authority_rule_t::
25  
implementation_defined::authority_rule_t::
26  
parse(
26  
parse(
27  
    char const*& it,
27  
    char const*& it,
28  
    char const* const end
28  
    char const* const end
29  
        ) const noexcept ->
29  
        ) const noexcept ->
30  
    system::result<value_type>
30  
    system::result<value_type>
31  
{
31  
{
32  
    detail::url_impl u(detail::url_impl::from::authority);
32  
    detail::url_impl u(detail::url_impl::from::authority);
33  
    u.cs_ = it;
33  
    u.cs_ = it;
34  

34  

35  
    // [ userinfo "@" ]
35  
    // [ userinfo "@" ]
36  
    {
36  
    {
37  
        auto rv = grammar::parse(
37  
        auto rv = grammar::parse(
38  
            it, end,
38  
            it, end,
39  
            grammar::optional_rule(
39  
            grammar::optional_rule(
40  
                grammar::tuple_rule(
40  
                grammar::tuple_rule(
41  
                    detail::userinfo_rule,
41  
                    detail::userinfo_rule,
42  
                    grammar::squelch(
42  
                    grammar::squelch(
43  
                        grammar::delim_rule('@')))));
43  
                        grammar::delim_rule('@')))));
44  
        if(! rv)
44  
        if(! rv)
45  
            return rv.error();
45  
            return rv.error();
46  
        if(rv->has_value())
46  
        if(rv->has_value())
47  
        {
47  
        {
48  
            u.apply_userinfo(
48  
            u.apply_userinfo(
49  
                (*rv)->user,
49  
                (*rv)->user,
50  
                (*rv)->has_password
50  
                (*rv)->has_password
51  
                ? &(*rv)->password
51  
                ? &(*rv)->password
52  
                : nullptr);
52  
                : nullptr);
53  
        }
53  
        }
54  
    }
54  
    }
55  

55  

56  
    // host
56  
    // host
57  
    {
57  
    {
58  
        auto rv = grammar::parse(
58  
        auto rv = grammar::parse(
59  
            it, end, detail::host_rule);
59  
            it, end, detail::host_rule);
60  
        if(! rv)
60  
        if(! rv)
61  
            return rv.error();
61  
            return rv.error();
62  
        u.apply_host(rv->host_type,
62  
        u.apply_host(rv->host_type,
63  
            rv->match, rv->addr);
63  
            rv->match, rv->addr);
64  
    }
64  
    }
65  

65  

66  
    // [ ":" port ]
66  
    // [ ":" port ]
67  
    {
67  
    {
68  
        auto rv = grammar::parse(
68  
        auto rv = grammar::parse(
69  
            it, end, detail::port_part_rule);
69  
            it, end, detail::port_part_rule);
70  
        if(! rv)
70  
        if(! rv)
71  
            return rv.error();
71  
            return rv.error();
72  
        if(rv->has_port)
72  
        if(rv->has_port)
73  
            u.apply_port(
73  
            u.apply_port(
74  
                rv->port,
74  
                rv->port,
75  
                rv->port_number);
75  
                rv->port_number);
76  
    }
76  
    }
77  

77  

78  
    return u.construct_authority();
78  
    return u.construct_authority();
79  
}
79  
}
80  

80  

81  
} // urls
81  
} // urls
82  
} // boost
82  
} // boost
83  

83