Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:32

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_RFC7230_HPP
0011 #define BOOST_BEAST_HTTP_RFC7230_HPP
0012 
0013 #include <boost/beast/core/detail/config.hpp>
0014 #include <boost/beast/http/detail/rfc7230.hpp>
0015 #include <boost/beast/http/detail/basic_parsed_list.hpp>
0016 
0017 namespace boost {
0018 namespace beast {
0019 namespace http {
0020 
0021 /** A list of parameters in an HTTP extension field value.
0022 
0023     This container allows iteration of the parameter list in an HTTP
0024     extension. The parameter list is a series of name/value pairs
0025     with each pair starting with a semicolon. The value is optional.
0026 
0027     If a parsing error is encountered while iterating the string,
0028     the behavior of the container will be as if a string containing
0029     only characters up to but excluding the first invalid character
0030     was used to construct the list.
0031 
0032     @par BNF
0033     @code
0034         param-list  = *( OWS ";" OWS param )
0035         param       = token OWS [ "=" OWS ( token / quoted-string ) ]
0036     @endcode
0037 
0038     To use this class, construct with the string to be parsed and
0039     then use @ref begin and @ref end, or range-for to iterate each
0040     item:
0041 
0042     @par Example
0043     @code
0044     for(auto const& param : param_list{";level=9;no_context_takeover;bits=15"})
0045     {
0046         std::cout << ";" << param.first;
0047         if(! param.second.empty())
0048             std::cout << "=" << param.second;
0049         std::cout << "\n";
0050     }
0051     @endcode
0052 */
0053 class param_list
0054 {
0055     string_view s_;
0056 
0057 public:
0058     /** The type of each element in the list.
0059 
0060         The first string in the pair is the name of the parameter,
0061         and the second string in the pair is its value (which may
0062         be empty).
0063     */
0064     using value_type =
0065         std::pair<string_view, string_view>;
0066 
0067     /// A constant iterator to the list
0068 #if BOOST_BEAST_DOXYGEN
0069     using const_iterator = __implementation_defined__;
0070 #else
0071     class const_iterator;
0072 #endif
0073 
0074     /// Default constructor.
0075     param_list() = default;
0076 
0077     /** Construct a list.
0078 
0079         @param s A string containing the list contents. The string
0080         must remain valid for the lifetime of the container.
0081     */
0082     explicit
0083     param_list(string_view s)
0084         : s_(s)
0085     {
0086     }
0087 
0088     /// Return a const iterator to the beginning of the list
0089     const_iterator begin() const;
0090 
0091     /// Return a const iterator to the end of the list
0092     const_iterator end() const;
0093 
0094     /// Return a const iterator to the beginning of the list
0095     const_iterator cbegin() const;
0096 
0097     /// Return a const iterator to the end of the list
0098     const_iterator cend() const;
0099 };
0100 
0101 //------------------------------------------------------------------------------
0102 
0103 /** A list of extensions in a comma separated HTTP field value.
0104 
0105     This container allows iteration of the extensions in an HTTP
0106     field value. The extension list is a comma separated list of
0107     token parameter list pairs.
0108 
0109     If a parsing error is encountered while iterating the string,
0110     the behavior of the container will be as if a string containing
0111     only characters up to but excluding the first invalid character
0112     was used to construct the list.
0113 
0114     @par BNF
0115     @code
0116         ext-list    = *( "," OWS ) ext *( OWS "," [ OWS ext ] )
0117         ext         = token param-list
0118         param-list  = *( OWS ";" OWS param )
0119         param       = token OWS [ "=" OWS ( token / quoted-string ) ]
0120     @endcode
0121 
0122     To use this class, construct with the string to be parsed and
0123     then use @ref begin and @ref end, or range-for to iterate each
0124     item:
0125 
0126     @par Example
0127     @code
0128     for(auto const& ext : ext_list{"none, 7z;level=9, zip;no_context_takeover;bits=15"})
0129     {
0130         std::cout << ext.first << "\n";
0131         for(auto const& param : ext.second)
0132         {
0133             std::cout << ";" << param.first;
0134             if(! param.second.empty())
0135                 std::cout << "=" << param.second;
0136             std::cout << "\n";
0137         }
0138     }
0139     @endcode
0140 */
0141 class ext_list
0142 {
0143     using iter_type = string_view::const_iterator;
0144 
0145     string_view s_;
0146 
0147 public:
0148     /** The type of each element in the list.
0149 
0150         The first element of the pair is the extension token, and the
0151         second element of the pair is an iterable container holding the
0152         extension's name/value parameters.
0153     */
0154     using value_type = std::pair<string_view, param_list>;
0155 
0156     /// A constant iterator to the list
0157 #if BOOST_BEAST_DOXYGEN
0158     using const_iterator = __implementation_defined__;
0159 #else
0160     class const_iterator;
0161 #endif
0162 
0163     /** Construct a list.
0164 
0165         @param s A string containing the list contents. The string
0166         must remain valid for the lifetime of the container.
0167     */
0168     explicit
0169     ext_list(string_view s)
0170         : s_(s)
0171     {
0172     }
0173 
0174     /// Return a const iterator to the beginning of the list
0175     const_iterator begin() const;
0176 
0177     /// Return a const iterator to the end of the list
0178     const_iterator end() const;
0179 
0180     /// Return a const iterator to the beginning of the list
0181     const_iterator cbegin() const;
0182 
0183     /// Return a const iterator to the end of the list
0184     const_iterator cend() const;
0185 
0186     /** Find a token in the list.
0187 
0188         @param s The token to find. A case-insensitive comparison is used.
0189 
0190         @return An iterator to the matching token, or `end()` if no
0191         token exists.
0192     */
0193     BOOST_BEAST_DECL
0194     const_iterator
0195     find(string_view const& s);
0196 
0197     /** Return `true` if a token is present in the list.
0198 
0199         @param s The token to find. A case-insensitive comparison is used.
0200     */
0201     BOOST_BEAST_DECL
0202     bool
0203     exists(string_view const& s);
0204 };
0205 
0206 //------------------------------------------------------------------------------
0207 
0208 /** A list of tokens in a comma separated HTTP field value.
0209 
0210     This container allows iteration of a list of items in a
0211     header field value. The input is a comma separated list of
0212     tokens.
0213 
0214     If a parsing error is encountered while iterating the string,
0215     the behavior of the container will be as if a string containing
0216     only characters up to but excluding the first invalid character
0217     was used to construct the list.
0218 
0219     @par BNF
0220     @code
0221         token-list  = *( "," OWS ) token *( OWS "," [ OWS token ] )
0222     @endcode
0223 
0224     To use this class, construct with the string to be parsed and
0225     then use @ref begin and @ref end, or range-for to iterate each
0226     item:
0227 
0228     @par Example
0229     @code
0230     for(auto const& token : token_list{"apple, pear, banana"})
0231         std::cout << token << "\n";
0232     @endcode
0233 */
0234 class token_list
0235 {
0236     using iter_type = string_view::const_iterator;
0237 
0238     string_view s_;
0239 
0240 public:
0241     /// The type of each element in the token list.
0242     using value_type = string_view;
0243 
0244     /// A constant iterator to the list
0245 #if BOOST_BEAST_DOXYGEN
0246     using const_iterator = __implementation_defined__;
0247 #else
0248     class const_iterator;
0249 #endif
0250 
0251     /** Construct a list.
0252 
0253         @param s A string containing the list contents. The string
0254         must remain valid for the lifetime of the container.
0255     */
0256     explicit
0257     token_list(string_view s)
0258         : s_(s)
0259     {
0260     }
0261 
0262     /// Return a const iterator to the beginning of the list
0263     const_iterator begin() const;
0264 
0265     /// Return a const iterator to the end of the list
0266     const_iterator end() const;
0267 
0268     /// Return a const iterator to the beginning of the list
0269     const_iterator cbegin() const;
0270 
0271     /// Return a const iterator to the end of the list
0272     const_iterator cend() const;
0273 
0274     /** Return `true` if a token is present in the list.
0275 
0276         @param s The token to find. A case-insensitive comparison is used.
0277     */
0278     BOOST_BEAST_DECL
0279     bool
0280     exists(string_view const& s);
0281 };
0282 
0283 /** A list of tokens in a comma separated HTTP field value.
0284 
0285     This container allows iteration of a list of items in a
0286     header field value. The input is a comma separated list of
0287     tokens.
0288 
0289     If a parsing error is encountered while iterating the string,
0290     the behavior of the container will be as if a string containing
0291     only characters up to but excluding the first invalid character
0292     was used to construct the list.
0293 
0294     @par BNF
0295     @code
0296         token-list  = *( "," OWS ) token *( OWS "," [ OWS token ] )
0297     @endcode
0298 
0299     To use this class, construct with the string to be parsed and
0300     then use `begin` and `end`, or range-for to iterate each item:
0301 
0302     @par Example
0303     @code
0304     for(auto const& token : token_list{"apple, pear, banana"})
0305         std::cout << token << "\n";
0306     @endcode
0307 */
0308 using opt_token_list =
0309     detail::basic_parsed_list<
0310         detail::opt_token_list_policy>;
0311 
0312 /** Returns `true` if a parsed list is parsed without errors.
0313 
0314     This function iterates a single pass through a parsed list
0315     and returns `true` if there were no parsing errors, else
0316     returns `false`.
0317 */
0318 template<class Policy>
0319 bool
0320 validate_list(detail::basic_parsed_list<
0321     Policy> const& list);
0322 
0323 } // http
0324 } // beast
0325 } // boost
0326 
0327 #include <boost/beast/http/impl/rfc7230.hpp>
0328 
0329 #endif