Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:44:03

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_WEBSOCKET_DETAIL_PMD_EXTENSION_HPP
0011 #define BOOST_BEAST_WEBSOCKET_DETAIL_PMD_EXTENSION_HPP
0012 
0013 #include <boost/beast/core/error.hpp>
0014 #include <boost/beast/websocket/option.hpp>
0015 #include <boost/beast/http/rfc7230.hpp>
0016 #include <utility>
0017 #include <type_traits>
0018 
0019 namespace boost {
0020 namespace beast {
0021 namespace websocket {
0022 namespace detail {
0023 
0024 // permessage-deflate offer parameters
0025 //
0026 // "context takeover" means:
0027 // preserve sliding window across messages
0028 //
0029 struct pmd_offer
0030 {
0031     bool accept;
0032 
0033     // 0 = absent, or 8..15
0034     int server_max_window_bits;
0035 
0036     // -1 = present, 0 = absent, or 8..15
0037     int client_max_window_bits;
0038 
0039     // `true` if server_no_context_takeover offered
0040     bool server_no_context_takeover;
0041 
0042     // `true` if client_no_context_takeover offered
0043     bool client_no_context_takeover;
0044 };
0045 
0046 BOOST_BEAST_DECL
0047 int
0048 parse_bits(string_view s);
0049 
0050 BOOST_BEAST_DECL
0051 void
0052 pmd_read_impl(pmd_offer& offer, http::ext_list const& list);
0053 
0054 BOOST_BEAST_DECL
0055 static_string<512>
0056 pmd_write_impl(pmd_offer const& offer);
0057 
0058 BOOST_BEAST_DECL
0059 static_string<512>
0060 pmd_negotiate_impl(
0061     pmd_offer& config,
0062     pmd_offer const& offer,
0063     permessage_deflate const& o);
0064 
0065 // Parse permessage-deflate request fields
0066 //
0067 template<class Allocator>
0068 void
0069 pmd_read(pmd_offer& offer,
0070     http::basic_fields<Allocator> const& fields)
0071 {
0072     http::ext_list list{
0073         fields["Sec-WebSocket-Extensions"]};
0074     detail::pmd_read_impl(offer, list);
0075 }
0076 
0077 // Set permessage-deflate fields for a client offer
0078 //
0079 template<class Allocator>
0080 void
0081 pmd_write(http::basic_fields<Allocator>& fields,
0082     pmd_offer const& offer)
0083 {
0084     auto s = detail::pmd_write_impl(offer);
0085     fields.set(http::field::sec_websocket_extensions, to_string_view(s));
0086 }
0087 
0088 // Negotiate a permessage-deflate client offer
0089 //
0090 template<class Allocator>
0091 void
0092 pmd_negotiate(
0093     http::basic_fields<Allocator>& fields,
0094     pmd_offer& config,
0095     pmd_offer const& offer,
0096     permessage_deflate const& o)
0097 {
0098     if(! (offer.accept && o.server_enable))
0099     {
0100         config.accept = false;
0101         return;
0102     }
0103     config.accept = true;
0104 
0105     auto s = detail::pmd_negotiate_impl(config, offer, o);
0106     if(config.accept)
0107         fields.set(http::field::sec_websocket_extensions, to_string_view(s));
0108 }
0109 
0110 // Normalize the server's response
0111 //
0112 BOOST_BEAST_DECL
0113 void
0114 pmd_normalize(pmd_offer& offer);
0115 
0116 } // detail
0117 } // websocket
0118 } // beast
0119 } // boost
0120 
0121 #if BOOST_BEAST_HEADER_ONLY
0122 #include <boost/beast/websocket/detail/pmd_extension.ipp>
0123 #endif
0124 
0125 #endif