10 #ifndef BOOST_BEAST_HTTP_DETAIL_BASIC_PARSER_HPP 11 #define BOOST_BEAST_HTTP_DETAIL_BASIC_PARSER_HPP 18 #include <boost/config.hpp> 19 #include <boost/version.hpp> 60 static bool constexpr tab[256] = {
61 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
62 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
63 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
64 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
65 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
66 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
67 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
68 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
69 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
70 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
71 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
72 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
73 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
74 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
75 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
76 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
78 return tab[
static_cast<unsigned char>(c)];
86 static signed char constexpr tab[256] = {
87 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
88 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
89 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
90 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1,
91 -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,
92 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
93 -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,
94 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
96 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
97 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
98 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
99 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
100 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
101 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
102 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
103 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
105 d =
static_cast<unsigned char>(
106 tab[
static_cast<unsigned char>(c)]);
107 return d !=
static_cast<unsigned char>(-1);
114 return static_cast<unsigned char>(c-
'0') < 10;
121 return static_cast<unsigned char>(c-32) < 95;
124 template<
class FwdIt>
131 if(*it !=
' ' && *it !=
'\t')
138 template<
class RanIt>
142 RanIt it, RanIt
const& first)
146 auto const c = it[-1];
147 if(c !=
' ' && c !=
'\t')
158 return {first,
static_cast< 159 std::size_t
>(last - first)};
165 std::pair<char const*, bool>
173 boost::ignore_unused(buf_end, ranges, ranges_size);
181 char const* it,
char const* last,
188 ec.assign(0, ec.category());
195 ec.assign(0, ec.category());
203 ec.assign(0, ec.category());
227 else if(p[2] !=
'\r')
231 else if(p[1] !=
'\n')
235 else if(p[0] !=
'\r')
253 char const*& token_last,
264 if((BOOST_LIKELY(
static_cast< 265 unsigned char>(*p) <
'\040') &&
266 BOOST_LIKELY(*p !=
'\011')) ||
267 BOOST_UNLIKELY(*p ==
'\177'))
271 if(BOOST_LIKELY(*p ==
'\r'))
302 template<
class Iter,
class Un
signed>
314 auto const d = *it -
'0';
315 if(v > ((std::numeric_limits<
316 Unsigned>::max)() - 10) / 10)
323 template<
class Iter,
class Un
signed>
334 if(!
unhex(d, *++it))
348 if( it[0] !=
'\r' || it[1] !=
'\n')
357 char const*& it,
char const* last,
361 auto const first = it;
394 char const*& it,
char const* last,
398 auto const first = it;
431 char const*& it,
char const* last,
469 result = 10 * (*it++ -
'0');
480 result += *it++ -
'0';
486 char const*& it,
char const* last,
500 result = 100 * (*it++ -
'0');
506 result += 10 * (*it++ -
'0');
512 result += *it++ -
'0';
522 char const*& it,
char const* last,
525 auto const first = it;
526 char const* token_last =
nullptr;
528 it, last, token_last, ec);
540 template<std::
size_t N>
568 static char const* is_token =
569 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" 570 "\0\1\0\1\1\1\1\1\0\0\1\1\0\1\1\0\1\1\1\1\1\1\1\1\1\1\0\0\0\0\0\0" 571 "\0\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\0\0\0\1\1" 572 "\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\0\1\0\1\0" 573 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" 574 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" 575 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" 576 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
579 BOOST_ALIGNMENT(16)
static const char ranges1[] =
591 p, last, ranges1,
sizeof(ranges1)-1);
592 if(! found && p >= last)
601 if(! is_token[
static_cast< 622 char const* token_last =
nullptr;
633 if(! (*p ==
' ' || *p ==
'\t'))
654 if(*p !=
' ' && *p !=
'\t')
660 if(token_last != first)
664 buf.
append(first, token_last);
665 BOOST_ASSERT(! buf.
empty());
678 if(! (*p ==
' ' || *p ==
'\t'))
697 token_last =
trim_back(token_last, first);
698 if(first != token_last)
701 buf.
append(first, token_last);
703 if(*p !=
' ' && *p !=
'\t')
711 catch(std::length_error
const&)
743 if(*it !=
' ' && *it !=
'\t' && *it !=
';')
746 if(*it ==
' ' || *it ==
'\t')
756 if(*it !=
' ' && *it !=
'\t')
776 if(*it !=
' ' && *it !=
'\t')
800 if(*it ==
' ' || *it ==
'\t')
810 if(*it !=
' ' && *it !=
'\t')
837 if(*it !=
' ' && *it !=
'\t')
The chunk extension is invalid.
void parse_reason(char const *&it, char const *last, string_view &result, error_code &ec)
Definition: basic_parser.hpp:521
static bool parse_crlf(char const *&it)
Definition: basic_parser.hpp:346
Definition: async_result.hpp:20
bool empty() const
Returns true if the string is empty.
Definition: static_string.hpp:449
static char const * find_eol(char const *it, char const *last, error_code &ec)
Definition: basic_parser.hpp:180
void parse_field(char const *&p, char const *last, string_view &name, string_view &value, static_string< N > &buf, error_code &ec)
Definition: basic_parser.hpp:542
void push_back(CharT ch)
Definition: static_string.ipp:408
static void parse_status(char const *&it, char const *last, unsigned short &result, error_code &ec)
Definition: basic_parser.hpp:485
char is_token_char(char c)
Definition: rfc7230.hpp:84
Definition: beast_common.hpp:6
The HTTP-version is invalid.
size_type size() const
Returns the number of characters, excluding the null terminator.
Definition: static_string.hpp:456
static void parse_version(char const *&it, char const *last, int &result, error_code &ec)
Definition: basic_parser.hpp:430
static bool unhex(unsigned char &d, char c)
Definition: basic_parser.hpp:84
The request-target is invalid.
static char const * find_eom(char const *p, char const *last)
Definition: basic_parser.hpp:214
boost::system::error_code error_code
The type of error code used by the library.
Definition: error.hpp:21
The field name is invalid.
The reason-phrase is invalid.
state
Definition: basic_parser.hpp:38
static bool is_print(char c)
Definition: basic_parser.hpp:119
void resize(std::size_t n)
Definition: static_string.ipp:461
static_string & append(size_type count, CharT ch)
Definition: static_string.hpp:595
The line ending was malformed.
static bool is_pathchar(char c)
Definition: basic_parser.hpp:55
static std::size_t constexpr max_obs_fold
Definition: basic_parser.hpp:36
static bool parse_dec(Iter it, Iter last, Unsigned &v)
Definition: basic_parser.hpp:305
static string_view make_string(char const *first, char const *last)
Definition: basic_parser.hpp:156
boost::string_ref string_view
The type of string view used by the library.
Definition: string.hpp:36
static void parse_method(char const *&it, char const *last, string_view &result, error_code &ec)
Definition: basic_parser.hpp:356
The status-code is invalid.
Definition: static_string.hpp:44
void parse_chunk_extensions(char const *&it, char const *last, error_code &ec)
Definition: basic_parser.hpp:719
static std::pair< char const *, bool > find_fast(char const *buf, char const *buf_end, char const *ranges, size_t ranges_size)
Definition: basic_parser.hpp:166
static bool parse_hex(Iter &it, Unsigned &v)
Definition: basic_parser.hpp:326
static FwdIt trim_front(FwdIt it, FwdIt const &end)
Definition: basic_parser.hpp:127
static bool is_digit(char c)
Definition: basic_parser.hpp:112
static void parse_target(char const *&it, char const *last, string_view &result, error_code &ec)
Definition: basic_parser.hpp:393
CharT * data()
Returns a pointer to the first character of a string.
Definition: static_string.hpp:329
static RanIt trim_back(RanIt it, RanIt const &first)
Definition: basic_parser.hpp:141
static char const * parse_token_to_eol(char const *p, char const *last, char const *&token_last, error_code &ec)
Definition: basic_parser.hpp:250
Definition: basic_parser.hpp:29
The field value is invalid.