Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:29:29

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/beast
0008 //
0009 
0010 #ifndef BOOST_BEAST_HTTP_DETAIL_BASIC_PARSER_HPP
0011 #define BOOST_BEAST_HTTP_DETAIL_BASIC_PARSER_HPP
0012 
0013 #include <boost/beast/core/string.hpp>
0014 #include <boost/beast/core/detail/char_buffer.hpp>
0015 #include <boost/beast/http/error.hpp>
0016 #include <boost/beast/http/detail/rfc7230.hpp>
0017 #include <boost/config.hpp>
0018 #include <boost/version.hpp>
0019 #include <cstddef>
0020 #include <utility>
0021 
0022 namespace boost {
0023 namespace beast {
0024 namespace http {
0025 namespace detail {
0026 
0027 struct basic_parser_base
0028 {
0029     // limit on the size of the obs-fold buffer
0030     //
0031     // https://stackoverflow.com/questions/686217/maximum-on-http-header-values
0032     //
0033     static std::size_t constexpr max_obs_fold = 4096;
0034 
0035     enum class state
0036     {
0037         nothing_yet = 0,
0038         start_line,
0039         fields,
0040         body0,
0041         body,
0042         body_to_eof0,
0043         body_to_eof,
0044         chunk_header0,
0045         chunk_header,
0046         chunk_body,
0047         trailer_fields,
0048         complete
0049     };
0050 
0051     static
0052     bool
0053     is_digit(char c)
0054     {
0055         return static_cast<unsigned char>(c-'0') < 10;
0056     }
0057 
0058     static
0059     bool
0060     is_print(char c)
0061     {
0062         return static_cast<unsigned char>(c-32) < 95;
0063     }
0064 
0065     BOOST_BEAST_DECL
0066     static
0067     char const*
0068     trim_front(char const* it, char const* end);
0069 
0070     BOOST_BEAST_DECL
0071     static
0072     char const*
0073     trim_back(
0074         char const* it, char const* first);
0075 
0076     static
0077     string_view
0078     make_string(char const* first, char const* last)
0079     {
0080         return {first, static_cast<
0081             std::size_t>(last - first)};
0082     }
0083 
0084     //--------------------------------------------------------------------------
0085 
0086     BOOST_BEAST_DECL
0087     static
0088     bool
0089     is_pathchar(char c);
0090 
0091     BOOST_BEAST_DECL
0092     static
0093     bool
0094     unhex(unsigned char& d, char c);
0095 
0096     BOOST_BEAST_DECL
0097     static
0098     std::pair<char const*, bool>
0099     find_fast(
0100         char const* buf,
0101         char const* buf_end,
0102         char const* ranges,
0103         size_t ranges_size);
0104 
0105     BOOST_BEAST_DECL
0106     static
0107     char const*
0108     find_eol(
0109         char const* it, char const* last,
0110             error_code& ec);
0111 
0112     //--------------------------------------------------------------------------
0113 
0114     BOOST_BEAST_DECL
0115     static
0116     char const*
0117     parse_token_to_eol(
0118         char const* p,
0119         char const* last,
0120         char const*& token_last,
0121         error_code& ec);
0122 
0123     BOOST_BEAST_DECL
0124     static
0125     bool
0126     parse_dec(string_view s, std::uint64_t& v);
0127 
0128     BOOST_BEAST_DECL
0129     static
0130     bool
0131     parse_hex(char const*& it, std::uint64_t& v);
0132 
0133     BOOST_BEAST_DECL
0134     static
0135     bool
0136     parse_crlf(char const*& it);
0137 
0138     BOOST_BEAST_DECL
0139     static
0140     void
0141     parse_method(
0142         char const*& it, char const* last,
0143         string_view& result, error_code& ec);
0144 
0145     BOOST_BEAST_DECL
0146     static
0147     void
0148     parse_target(
0149         char const*& it, char const* last,
0150         string_view& result, error_code& ec);
0151 
0152     BOOST_BEAST_DECL
0153     static
0154     void
0155     parse_version(
0156         char const*& it, char const* last,
0157         int& result, error_code& ec);
0158 
0159     BOOST_BEAST_DECL
0160     static
0161     void
0162     parse_status(
0163         char const*& it, char const* last,
0164         unsigned short& result, error_code& ec);
0165 
0166     BOOST_BEAST_DECL
0167     static
0168     void
0169     parse_reason(
0170         char const*& it, char const* last,
0171         string_view& result, error_code& ec);
0172 
0173     BOOST_BEAST_DECL
0174     static
0175     void
0176     parse_field(
0177         char const*& p,
0178         char const* last,
0179         string_view& name,
0180         string_view& value,
0181         beast::detail::char_buffer<max_obs_fold>& buf,
0182         error_code& ec);
0183 
0184     BOOST_BEAST_DECL
0185     static
0186     void
0187     parse_chunk_extensions(
0188         char const*& it,
0189         char const* last,
0190         error_code& ec);
0191 };
0192 
0193 } // detail
0194 } // http
0195 } // beast
0196 } // boost
0197 
0198 #ifdef BOOST_BEAST_HEADER_ONLY
0199 #include <boost/beast/http/detail/basic_parser.ipp>
0200 #endif
0201 
0202 #endif