File indexing completed on 2025-01-18 09:29:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_BEAST_WEBSOCKET_IMPL_ERROR_IPP
0011 #define BOOST_BEAST_WEBSOCKET_IMPL_ERROR_IPP
0012
0013 #include <boost/beast/websocket/error.hpp>
0014
0015 namespace boost {
0016 namespace beast {
0017 namespace websocket {
0018 namespace detail {
0019
0020 class error_codes : public error_category
0021 {
0022 public:
0023
0024 error_codes() : error_category(0x065d7edd7687edafu ) {}
0025
0026 const char*
0027 name() const noexcept override
0028 {
0029 return "boost.beast.websocket";
0030 }
0031
0032 std::string
0033 message(int ev) const override
0034 {
0035 switch(static_cast<error>(ev))
0036 {
0037 default:
0038 case error::closed: return "The WebSocket stream was gracefully closed at both endpoints";
0039 case error::buffer_overflow: return "The WebSocket operation caused a dynamic buffer overflow";
0040 case error::partial_deflate_block: return "The WebSocket stream produced an incomplete deflate block";
0041 case error::message_too_big: return "The WebSocket message exceeded the locally configured limit";
0042
0043 case error::bad_http_version: return "The WebSocket handshake was not HTTP/1.1";
0044 case error::bad_method: return "The WebSocket handshake method was not GET";
0045 case error::no_host: return "The WebSocket handshake Host field is missing";
0046 case error::no_connection: return "The WebSocket handshake Connection field is missing";
0047 case error::no_connection_upgrade: return "The WebSocket handshake Connection field is missing the upgrade token";
0048 case error::no_upgrade: return "The WebSocket handshake Upgrade field is missing";
0049 case error::no_upgrade_websocket: return "The WebSocket handshake Upgrade field is missing the websocket token";
0050 case error::no_sec_key: return "The WebSocket handshake Sec-WebSocket-Key field is missing";
0051 case error::bad_sec_key: return "The WebSocket handshake Sec-WebSocket-Key field is invalid";
0052 case error::no_sec_version: return "The WebSocket handshake Sec-WebSocket-Version field is missing";
0053 case error::bad_sec_version: return "The WebSocket handshake Sec-WebSocket-Version field is invalid";
0054 case error::no_sec_accept: return "The WebSocket handshake Sec-WebSocket-Accept field is missing";
0055 case error::bad_sec_accept: return "The WebSocket handshake Sec-WebSocket-Accept field is invalid";
0056 case error::upgrade_declined: return "The WebSocket handshake was declined by the remote peer";
0057
0058 case error::bad_opcode: return "The WebSocket frame contained an illegal opcode";
0059 case error::bad_data_frame: return "The WebSocket data frame was unexpected";
0060 case error::bad_continuation: return "The WebSocket continuation frame was unexpected";
0061 case error::bad_reserved_bits: return "The WebSocket frame contained illegal reserved bits";
0062 case error::bad_control_fragment: return "The WebSocket control frame was fragmented";
0063 case error::bad_control_size: return "The WebSocket control frame size was invalid";
0064 case error::bad_unmasked_frame: return "The WebSocket frame was unmasked";
0065 case error::bad_masked_frame: return "The WebSocket frame was masked";
0066 case error::bad_size: return "The WebSocket frame size was not canonical";
0067 case error::bad_frame_payload: return "The WebSocket frame payload was not valid utf8";
0068 case error::bad_close_code: return "The WebSocket close frame reason code was invalid";
0069 case error::bad_close_size: return "The WebSocket close frame payload size was invalid";
0070 case error::bad_close_payload: return "The WebSocket close frame payload was not valid utf8";
0071 }
0072 }
0073
0074 error_condition
0075 default_error_condition(int ev) const noexcept override
0076 {
0077 switch(static_cast<error>(ev))
0078 {
0079 default:
0080 case error::closed:
0081 case error::buffer_overflow:
0082 case error::partial_deflate_block:
0083 case error::message_too_big:
0084 return {ev, *this};
0085
0086 case error::bad_http_version:
0087 case error::bad_method:
0088 case error::no_host:
0089 case error::no_connection:
0090 case error::no_connection_upgrade:
0091 case error::no_upgrade:
0092 case error::no_upgrade_websocket:
0093 case error::no_sec_key:
0094 case error::bad_sec_key:
0095 case error::no_sec_version:
0096 case error::bad_sec_version:
0097 case error::no_sec_accept:
0098 case error::bad_sec_accept:
0099 case error::upgrade_declined:
0100 return condition::handshake_failed;
0101
0102 case error::bad_opcode:
0103 case error::bad_data_frame:
0104 case error::bad_continuation:
0105 case error::bad_reserved_bits:
0106 case error::bad_control_fragment:
0107 case error::bad_control_size:
0108 case error::bad_unmasked_frame:
0109 case error::bad_masked_frame:
0110 case error::bad_size:
0111 case error::bad_frame_payload:
0112 case error::bad_close_code:
0113 case error::bad_close_size:
0114 case error::bad_close_payload:
0115 return condition::protocol_violation;
0116 }
0117 }
0118 };
0119
0120 class error_conditions : public error_category
0121 {
0122 public:
0123 const char*
0124 name() const noexcept override
0125 {
0126 return "boost.beast.websocket";
0127 }
0128
0129 error_conditions() : error_category(0x7a8de5d61799ce9eu) {}
0130
0131
0132 std::string
0133 message(int cv) const override
0134 {
0135 switch(static_cast<condition>(cv))
0136 {
0137 default:
0138 case condition::handshake_failed: return "The WebSocket handshake failed";
0139 case condition::protocol_violation: return "A WebSocket protocol violation occurred";
0140 }
0141 }
0142 };
0143
0144 }
0145
0146 error_code
0147 make_error_code(error e)
0148 {
0149 static detail::error_codes const cat{};
0150 return error_code{static_cast<
0151 std::underlying_type<error>::type>(e), cat};
0152 }
0153
0154 error_condition
0155 make_error_condition(condition c)
0156 {
0157 static detail::error_conditions const cat{};
0158 return error_condition{static_cast<
0159 std::underlying_type<condition>::type>(c), cat};
0160 }
0161
0162 }
0163 }
0164 }
0165
0166 #endif