TLA Line data Source code
1 : //
2 : // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com)
3 : // Copyright (c) 2025 Mohammad Nejati
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/cppalliance/http
9 : //
10 :
11 : #include "src/rfc/detail/transfer_coding_rule.hpp"
12 :
13 : #include <boost/http/rfc/detail/ws.hpp>
14 : #include <boost/http/rfc/quoted_token_rule.hpp>
15 : #include <boost/http/rfc/token_rule.hpp>
16 : #include <boost/url/grammar/ci_string.hpp>
17 : #include <boost/url/grammar/parse.hpp>
18 :
19 : namespace boost {
20 : namespace http {
21 : namespace detail {
22 :
23 : auto
24 HIT 43 : transfer_parameter_rule_t::parse(
25 : char const*& it,
26 : char const* end) const noexcept ->
27 : system::result<value_type>
28 : {
29 43 : value_type t;
30 43 : auto it0 = it;
31 : // OWS
32 43 : it = grammar::find_if_not(
33 : it, end, ws);
34 : // ";"
35 43 : if(it == end)
36 : {
37 13 : it = it0;
38 13 : return grammar::error::need_more;
39 : }
40 30 : if(*it != ';')
41 : {
42 16 : it = it0;
43 16 : return grammar::error::mismatch;
44 : }
45 14 : ++it;
46 : // OWS
47 14 : it = grammar::find_if_not(
48 : it, end, ws);
49 : // token
50 : {
51 14 : auto rv = grammar::parse(
52 : it, end, token_rule);
53 14 : if(! rv)
54 MIS 0 : return rv.error();
55 HIT 14 : t.name = *rv;
56 : }
57 : // BWS
58 14 : it = grammar::find_if_not(
59 : it, end, ws);
60 : // "="
61 14 : if(it == end)
62 : {
63 MIS 0 : it = it0;
64 0 : return grammar::error::need_more;
65 : }
66 HIT 14 : if(*it != '=')
67 : {
68 MIS 0 : it = it0;
69 0 : return grammar::error::syntax;
70 : }
71 HIT 14 : ++it;
72 : // BWS
73 14 : it = grammar::find_if_not(
74 : it, end, ws);
75 : // quoted-token
76 : {
77 14 : auto rv = grammar::parse(
78 : it, end, quoted_token_rule);
79 14 : if(! rv)
80 MIS 0 : return rv.error();
81 HIT 14 : t.value = *rv;
82 : }
83 14 : return t;
84 : }
85 :
86 : //------------------------------------------------
87 :
88 : auto
89 8881 : transfer_coding_rule_t::
90 : parse(
91 : char const*& it,
92 : char const* end) const noexcept ->
93 : system::result<value_type>
94 : {
95 8881 : value_type t;
96 : {
97 : // token
98 8881 : auto rv = grammar::parse(
99 : it, end, token_rule);
100 8881 : if(! rv)
101 8 : return rv.error();
102 :
103 : // These can't have transfer-parameter
104 17746 : if(grammar::ci_is_equal(
105 8873 : *rv, "chunked"))
106 : {
107 8805 : t.id = coding::chunked;
108 8805 : return t;
109 : }
110 136 : if(grammar::ci_is_equal(
111 68 : *rv, "compress"))
112 : {
113 20 : t.id = coding::compress;
114 20 : return t;
115 : }
116 96 : if(grammar::ci_is_equal(
117 48 : *rv, "deflate"))
118 : {
119 7 : t.id = coding::deflate;
120 7 : return t;
121 : }
122 82 : if(grammar::ci_is_equal(
123 41 : *rv, "gzip"))
124 : {
125 12 : t.id = coding::gzip;
126 12 : return t;
127 : }
128 :
129 29 : t.extension.token = *rv;
130 : }
131 : // transfer-extension = token *( OWS ";" OWS transfer-parameter )
132 : {
133 : auto rv = grammar::parse(it, end,
134 29 : grammar::range_rule(
135 29 : detail::transfer_parameter_rule));
136 29 : if(! rv)
137 MIS 0 : return rv.error();
138 HIT 29 : t.extension.params = std::move(*rv);
139 29 : }
140 29 : return t;
141 8881 : }
142 :
143 : } // detail
144 : } // http
145 : } // boost
|