Back to home page

EIC code displayed by LXR

 
 

    


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

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_IMPL_RFC7230_IPP
0011 #define BOOST_BEAST_HTTP_IMPL_RFC7230_IPP
0012 
0013 #include <boost/beast/http/rfc7230.hpp>
0014 #include <algorithm>
0015 
0016 namespace boost {
0017 namespace beast {
0018 namespace http {
0019 
0020 
0021 void param_list::const_iterator::
0022 unquote(string_view sr, std::string &s)
0023 {
0024     s.clear();
0025     s.reserve(sr.size());
0026     auto it = sr.begin() + 1;
0027     auto end = sr.end() - 1;
0028     while(it != end)
0029     {
0030         if(*it == '\\')
0031             ++it;
0032         s.push_back(*it);
0033         ++it;
0034     }
0035 }
0036 
0037 void
0038 param_list::const_iterator::
0039 increment()
0040 {
0041     s_.clear();
0042     pi_.increment();
0043     if(pi_.empty())
0044     {
0045         pi_.it = pi_.last;
0046         pi_.first = pi_.last;
0047     }
0048     else if(! pi_.v.second.empty() &&
0049         pi_.v.second.front() == '"')
0050     {
0051         unquote(pi_.v.second, s_);
0052         pi_.v.second = string_view{
0053             s_.data(), s_.size()};
0054     }
0055 }
0056 
0057 void
0058 ext_list::const_iterator::
0059 increment()
0060 {
0061     /*
0062         ext-list    = *( "," OWS ) ext *( OWS "," [ OWS ext ] )
0063         ext         = token param-list
0064         param-list  = *( OWS ";" OWS param )
0065         param       = token OWS "=" OWS ( token / quoted-string )
0066 
0067         chunked;a=b;i=j;gzip;windowBits=12
0068         x,y
0069         ,,,,,chameleon
0070     */
0071     auto const err =
0072         [&]
0073         {
0074             it_ = last_;
0075             first_ = last_;
0076         };
0077     auto need_comma = it_ != first_;
0078     v_.first = {};
0079     first_ = it_;
0080     for(;;)
0081     {
0082         detail::skip_ows(it_, last_);
0083         if(it_ == last_)
0084             return err();
0085         auto const c = *it_;
0086         if(detail::is_token_char(c))
0087         {
0088             if(need_comma)
0089                 return err();
0090             auto const p0 = it_;
0091             for(;;)
0092             {
0093                 ++it_;
0094                 if(it_ == last_)
0095                     break;
0096                 if(! detail::is_token_char(*it_))
0097                     break;
0098             }
0099             v_.first = string_view{&*p0,
0100                 static_cast<std::size_t>(it_ - p0)};
0101             if (it_ == last_)
0102                 return;
0103             detail::param_iter pi;
0104             pi.it = it_;
0105             pi.first = it_;
0106             pi.last = last_;
0107             for(;;)
0108             {
0109                 pi.increment();
0110                 if(pi.empty())
0111                     break;
0112             }
0113             v_.second = param_list{string_view{&*it_,
0114                 static_cast<std::size_t>(pi.it - it_)}};
0115             it_ = pi.it;
0116             return;
0117         }
0118         if(c != ',')
0119             return err();
0120         need_comma = false;
0121         ++it_;
0122     }
0123 }
0124 
0125 auto
0126 ext_list::
0127 find(string_view const& s) -> const_iterator
0128 {
0129     return std::find_if(begin(), end(),
0130         [&s](value_type const& v)
0131         {
0132             return beast::iequals(s, v.first);
0133         });
0134 }
0135 
0136 bool
0137 ext_list::
0138 exists(string_view const& s)
0139 {
0140     return find(s) != end();
0141 }
0142 
0143 void
0144 token_list::const_iterator::
0145 increment()
0146 {
0147     /*
0148         token-list  = *( "," OWS ) token *( OWS "," [ OWS ext ] )
0149     */
0150     auto const err =
0151         [&]
0152         {
0153             it_ = last_;
0154             first_ = last_;
0155         };
0156     auto need_comma = it_ != first_;
0157     v_ = {};
0158     first_ = it_;
0159     for(;;)
0160     {
0161         detail::skip_ows(it_, last_);
0162         if(it_ == last_)
0163             return err();
0164         auto const c = *it_;
0165         if(detail::is_token_char(c))
0166         {
0167             if(need_comma)
0168                 return err();
0169             auto const p0 = it_;
0170             for(;;)
0171             {
0172                 ++it_;
0173                 if(it_ == last_)
0174                     break;
0175                 if(! detail::is_token_char(*it_))
0176                     break;
0177             }
0178             v_ = string_view{&*p0,
0179                 static_cast<std::size_t>(it_ - p0)};
0180             return;
0181         }
0182         if(c != ',')
0183             return err();
0184         need_comma = false;
0185         ++it_;
0186     }
0187 }
0188 
0189 bool
0190 token_list::
0191 exists(string_view const& s)
0192 {
0193     return std::find_if(begin(), end(),
0194         [&s](value_type const& v)
0195         {
0196             return beast::iequals(s, v);
0197         }
0198     ) != end();
0199 }
0200 
0201 } // http
0202 } // beast
0203 } // boost
0204 
0205 #endif // BOOST_BEAST_HTTP_IMPL_RFC7230_IPP