1 -
//
 
2 -
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
 
3 -
// Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
 
4 -
//
 
5 -
// Distributed under the Boost Software License, Version 1.0. (See accompanying
 
6 -
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
7 -
//
 
8 -
// Official repository: https://github.com/boostorg/url
 
9 -
//
 
10 -

 
11 -

 
12 -
#include <boost/url/detail/config.hpp>
 
13 -
#include <boost/url/rfc/ipv6_address_rule.hpp>
 
14 -
#include "ip_literal_rule.hpp"
 
15 -
#include "ipv6_addrz_rule.hpp"
 
16 -
#include <boost/url/grammar/delim_rule.hpp>
 
17 -
#include <boost/url/grammar/parse.hpp>
 
18 -
#include <boost/url/grammar/tuple_rule.hpp>
 
19 -
#include "ipvfuture_rule.hpp"
 
20 -

 
21 -
namespace boost {
 
22 -
namespace urls {
 
23 -
namespace detail {
 
24 -

 
25 -
auto
 
26 -
ip_literal_rule_t::
 
27 -
parse(
 
28 -
    char const*& it,
 
29 -
    char const* const end
 
30 -
        ) const noexcept ->
 
31 -
    system::result<value_type>
 
32 -
{
 
33 -
    value_type t;
 
34 -

 
35 -
    // '['
 
36 -
    {
 
37 -
        auto rv = grammar::parse(
 
38 -
            it, end, grammar::delim_rule('['));
 
39 -
        if(! rv)
 
40 -
            return rv.error();
 
41 -
    }
 
42 -
    if(it == end)
 
43 -
    {
 
44 -
        // end
 
45 -
        BOOST_URL_RETURN_EC(
 
46 -
            grammar::error::invalid);
 
47 -
    }
 
48 -
    if(*it != 'v')
 
49 -
    {
 
50 -
        // IPv6address
 
51 -
        auto it0 = it;
 
52 -
        auto rv = grammar::parse(
 
53 -
            it, end,
 
54 -
            grammar::tuple_rule(
 
55 -
                ipv6_address_rule,
 
56 -
                grammar::squelch(
 
57 -
                    grammar::delim_rule(']'))));
 
58 -
        if(! rv)
 
59 -
        {
 
60 -
            // IPv6addrz: https://datatracker.ietf.org/doc/html/rfc6874
 
61 -
            it = it0;
 
62 -
            auto rv2 = grammar::parse(
 
63 -
                it, end,
 
64 -
                grammar::tuple_rule(
 
65 -
                    ipv6_addrz_rule,
 
66 -
                    grammar::squelch(
 
67 -
                        grammar::delim_rule(']'))));
 
68 -
            if(! rv2)
 
69 -
                return rv2.error();
 
70 -
            t.ipv6 = rv2->ipv6;
 
71 -
            t.is_ipv6 = true;
 
72 -
            return t;
 
73 -
        }
 
74 -
        t.ipv6 = *rv;
 
75 -
        t.is_ipv6 = true;
 
76 -
        return t;
 
77 -
    }
 
78 -
    {
 
79 -
        // IPvFuture
 
80 -
        auto rv = grammar::parse(
 
81 -
            it, end, 
 
82 -
            grammar::tuple_rule(
 
83 -
                ipvfuture_rule,
 
84 -
                grammar::squelch(
 
85 -
                    grammar::delim_rule(']'))));
 
86 -
        if(! rv)
 
87 -
            return rv.error();
 
88 -
        t.is_ipv6 = false;
 
89 -
        t.ipvfuture = rv->str;
 
90 -
        return t;
 
91 -
    }
 
92 -
}
 
93 -

 
94 -
} // detail
 
95 -
} // urls
 
96 -
} // boost
 
97 -