| 1 | // |
| 2 | // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) |
| 3 | // |
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | // |
| 7 | // Official repository: https://github.com/boostorg/beast |
| 8 | // |
| 9 | |
| 10 | #ifndef BOOST_BEAST_WEBSOCKET_ERROR_HPP |
| 11 | #define BOOST_BEAST_WEBSOCKET_ERROR_HPP |
| 12 | |
| 13 | #include <boost/beast/core/detail/config.hpp> |
| 14 | #include <boost/beast/core/error.hpp> |
| 15 | |
| 16 | namespace boost { |
| 17 | namespace beast { |
| 18 | namespace websocket { |
| 19 | |
| 20 | /// Error codes returned from @ref boost::beast::websocket::stream operations. |
| 21 | enum class error |
| 22 | { |
| 23 | /** The WebSocket stream was gracefully closed at both endpoints |
| 24 | */ |
| 25 | closed = 1, |
| 26 | |
| 27 | /* The error codes error::failed and error::handshake_failed |
| 28 | are no longer in use. Please change your code to compare values |
| 29 | of type error_code against condition::handshake_failed |
| 30 | and condition::protocol_violation instead. |
| 31 | |
| 32 | Apologies for the inconvenience. |
| 33 | |
| 34 | - VFALCO |
| 35 | */ |
| 36 | #if ! BOOST_BEAST_DOXYGEN |
| 37 | unused1 = 2, // failed |
| 38 | unused2 = 3, // handshake_failed |
| 39 | #endif |
| 40 | |
| 41 | /** The WebSocket operation caused a dynamic buffer overflow |
| 42 | */ |
| 43 | buffer_overflow, |
| 44 | |
| 45 | /** The WebSocket stream produced an incomplete deflate block |
| 46 | */ |
| 47 | partial_deflate_block, |
| 48 | |
| 49 | /** The WebSocket message exceeded the locally configured limit |
| 50 | */ |
| 51 | message_too_big, |
| 52 | |
| 53 | // |
| 54 | // Handshake failure errors |
| 55 | // |
| 56 | // These will compare equal to condition::handshake_failed |
| 57 | // |
| 58 | |
| 59 | /** The WebSocket handshake was not HTTP/1.1 |
| 60 | |
| 61 | Error codes with this value will compare equal to @ref condition::handshake_failed |
| 62 | */ |
| 63 | bad_http_version, |
| 64 | |
| 65 | /** The WebSocket handshake method was not GET |
| 66 | |
| 67 | Error codes with this value will compare equal to @ref condition::handshake_failed |
| 68 | */ |
| 69 | bad_method, |
| 70 | |
| 71 | /** The WebSocket handshake Host field is missing |
| 72 | |
| 73 | Error codes with this value will compare equal to @ref condition::handshake_failed |
| 74 | */ |
| 75 | no_host, |
| 76 | |
| 77 | /** The WebSocket handshake Connection field is missing |
| 78 | |
| 79 | Error codes with this value will compare equal to @ref condition::handshake_failed |
| 80 | */ |
| 81 | no_connection, |
| 82 | |
| 83 | /** The WebSocket handshake Connection field is missing the upgrade token |
| 84 | |
| 85 | Error codes with this value will compare equal to @ref condition::handshake_failed |
| 86 | */ |
| 87 | no_connection_upgrade, |
| 88 | |
| 89 | /** The WebSocket handshake Upgrade field is missing |
| 90 | |
| 91 | Error codes with this value will compare equal to @ref condition::handshake_failed |
| 92 | */ |
| 93 | no_upgrade, |
| 94 | |
| 95 | /** The WebSocket handshake Upgrade field is missing the websocket token |
| 96 | |
| 97 | Error codes with this value will compare equal to @ref condition::handshake_failed |
| 98 | */ |
| 99 | no_upgrade_websocket, |
| 100 | |
| 101 | /** The WebSocket handshake Sec-WebSocket-Key field is missing |
| 102 | |
| 103 | Error codes with this value will compare equal to @ref condition::handshake_failed |
| 104 | */ |
| 105 | no_sec_key, |
| 106 | |
| 107 | /** The WebSocket handshake Sec-WebSocket-Key field is invalid |
| 108 | |
| 109 | Error codes with this value will compare equal to @ref condition::handshake_failed |
| 110 | */ |
| 111 | bad_sec_key, |
| 112 | |
| 113 | /** The WebSocket handshake Sec-WebSocket-Version field is missing |
| 114 | |
| 115 | Error codes with this value will compare equal to @ref condition::handshake_failed |
| 116 | */ |
| 117 | no_sec_version, |
| 118 | |
| 119 | /** The WebSocket handshake Sec-WebSocket-Version field is invalid |
| 120 | |
| 121 | Error codes with this value will compare equal to @ref condition::handshake_failed |
| 122 | */ |
| 123 | bad_sec_version, |
| 124 | |
| 125 | /** The WebSocket handshake Sec-WebSocket-Accept field is missing |
| 126 | |
| 127 | Error codes with this value will compare equal to @ref condition::handshake_failed |
| 128 | */ |
| 129 | no_sec_accept, |
| 130 | |
| 131 | /** The WebSocket handshake Sec-WebSocket-Accept field is invalid |
| 132 | |
| 133 | Error codes with this value will compare equal to @ref condition::handshake_failed |
| 134 | */ |
| 135 | bad_sec_accept, |
| 136 | |
| 137 | /** The WebSocket handshake was declined by the remote peer |
| 138 | |
| 139 | Error codes with this value will compare equal to @ref condition::handshake_failed |
| 140 | */ |
| 141 | upgrade_declined, |
| 142 | |
| 143 | // |
| 144 | // Protocol errors |
| 145 | // |
| 146 | // These will compare equal to condition::protocol_violation |
| 147 | // |
| 148 | |
| 149 | /** The WebSocket frame contained an illegal opcode |
| 150 | |
| 151 | Error codes with this value will compare equal to @ref condition::protocol_violation |
| 152 | */ |
| 153 | bad_opcode, |
| 154 | |
| 155 | /** The WebSocket data frame was unexpected |
| 156 | |
| 157 | Error codes with this value will compare equal to @ref condition::protocol_violation |
| 158 | */ |
| 159 | bad_data_frame, |
| 160 | |
| 161 | /** The WebSocket continuation frame was unexpected |
| 162 | |
| 163 | Error codes with this value will compare equal to @ref condition::protocol_violation |
| 164 | */ |
| 165 | bad_continuation, |
| 166 | |
| 167 | /** The WebSocket frame contained illegal reserved bits |
| 168 | |
| 169 | Error codes with this value will compare equal to @ref condition::protocol_violation |
| 170 | */ |
| 171 | bad_reserved_bits, |
| 172 | |
| 173 | /** The WebSocket control frame was fragmented |
| 174 | |
| 175 | Error codes with this value will compare equal to @ref condition::protocol_violation |
| 176 | */ |
| 177 | bad_control_fragment, |
| 178 | |
| 179 | /** The WebSocket control frame size was invalid |
| 180 | |
| 181 | Error codes with this value will compare equal to @ref condition::protocol_violation |
| 182 | */ |
| 183 | bad_control_size, |
| 184 | |
| 185 | /** The WebSocket frame was unmasked |
| 186 | |
| 187 | Error codes with this value will compare equal to @ref condition::protocol_violation |
| 188 | */ |
| 189 | bad_unmasked_frame, |
| 190 | |
| 191 | /** The WebSocket frame was masked |
| 192 | |
| 193 | Error codes with this value will compare equal to @ref condition::protocol_violation |
| 194 | */ |
| 195 | bad_masked_frame, |
| 196 | |
| 197 | /** The WebSocket frame size was not canonical |
| 198 | |
| 199 | Error codes with this value will compare equal to @ref condition::protocol_violation |
| 200 | */ |
| 201 | bad_size, |
| 202 | |
| 203 | /** The WebSocket frame payload was not valid utf8 |
| 204 | |
| 205 | Error codes with this value will compare equal to @ref condition::protocol_violation |
| 206 | */ |
| 207 | bad_frame_payload, |
| 208 | |
| 209 | /** The WebSocket close frame reason code was invalid |
| 210 | |
| 211 | Error codes with this value will compare equal to @ref condition::protocol_violation |
| 212 | */ |
| 213 | bad_close_code, |
| 214 | |
| 215 | /** The WebSocket close frame payload size was invalid |
| 216 | |
| 217 | Error codes with this value will compare equal to @ref condition::protocol_violation |
| 218 | */ |
| 219 | bad_close_size, |
| 220 | |
| 221 | /** The WebSocket close frame payload was not valid utf8 |
| 222 | |
| 223 | Error codes with this value will compare equal to @ref condition::protocol_violation |
| 224 | */ |
| 225 | bad_close_payload |
| 226 | }; |
| 227 | |
| 228 | /// Error conditions corresponding to sets of error codes. |
| 229 | enum class condition |
| 230 | { |
| 231 | /** The WebSocket handshake failed |
| 232 | |
| 233 | This condition indicates that the WebSocket handshake failed. If |
| 234 | the corresponding HTTP response indicates the keep-alive behavior, |
| 235 | then the handshake may be reattempted. |
| 236 | */ |
| 237 | handshake_failed = 1, |
| 238 | |
| 239 | /** A WebSocket protocol violation occurred |
| 240 | |
| 241 | This condition indicates that the remote peer on the WebSocket |
| 242 | connection sent data which violated the protocol. |
| 243 | */ |
| 244 | protocol_violation |
| 245 | }; |
| 246 | |
| 247 | } // websocket |
| 248 | } // beast |
| 249 | } // boost |
| 250 | |
| 251 | #include <boost/beast/websocket/impl/error.hpp> |
| 252 | #ifdef BOOST_BEAST_HEADER_ONLY |
| 253 | #include <boost/beast/websocket/impl/error.ipp> |
| 254 | #endif |
| 255 | |
| 256 | #endif |
| 257 | |