Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
base.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014, Peter Thorson. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the WebSocket++ Project nor the
12 * names of its contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 */
27
28#ifndef WEBSOCKETPP_PROCESSOR_BASE_HPP
29#define WEBSOCKETPP_PROCESSOR_BASE_HPP
30
31#include <websocketpp/close.hpp>
33#include <websocketpp/uri.hpp>
34
37
38#include <string>
39
40namespace websocketpp {
41namespace processor {
42
44namespace constants {
45
46static char const upgrade_token[] = "websocket";
47static char const connection_token[] = "upgrade";
48static char const handshake_guid[] = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
49
50} // namespace constants
51
52
54namespace error_cat {
55enum value {
56 BAD_REQUEST = 0, // Error was the result of improperly formatted user input
57 INTERNAL_ERROR = 1, // Error was a logic error internal to WebSocket++
60 PAYLOAD_VIOLATION = 4 // Error was due to receiving invalid payload data
61};
62} // namespace error_cat
63
65namespace error {
159
161class processor_category : public lib::error_category {
162public:
164
165 char const * name() const _WEBSOCKETPP_NOEXCEPT_TOKEN_ {
166 return "websocketpp.processor";
167 }
168
169 std::string message(int value) const {
170 switch(value) {
171 case error::general:
172 return "Generic processor error";
174 return "invalid user input";
176 return "Generic protocol violation";
178 return "A message was too large";
180 return "A payload contained invalid data";
182 return "invalid function arguments";
184 return "invalid opcode";
186 return "Control messages are limited to fewer than 125 characters";
188 return "Invalid use of reserved bits";
190 return "Control messages cannot be fragmented";
192 return "Invalid message continuation";
194 return "Clients may not send unmasked frames";
196 return "Servers may not send masked frames";
198 return "Payload length was not minimally encoded";
200 return "64 bit frames are not supported on 32 bit systems";
202 return "Invalid UTF8 encoding";
204 return "Operation required not implemented functionality";
206 return "Invalid HTTP method.";
208 return "Invalid HTTP version.";
210 return "Invalid HTTP status.";
212 return "A required HTTP header is missing";
214 return "SHA-1 library error";
216 return "The WebSocket protocol version in use does not support this feature";
218 return "Reserved close code used";
220 return "Invalid close code used";
222 return "Using a close reason requires a valid close code";
224 return "Error parsing subprotocol header";
226 return "Error parsing extension header";
228 return "Extensions are disabled";
230 return "Short Hybi00 Key 3 read";
231 default:
232 return "Unknown";
233 }
234 }
235};
236
238inline lib::error_category const & get_processor_category() {
239 static processor_category instance;
240 return instance;
241}
242
244inline lib::error_code make_error_code(error::processor_errors e) {
245 return lib::error_code(static_cast<int>(e), get_processor_category());
246}
247
249
261inline close::status::value to_ws(lib::error_code ec) {
262 if (ec.category() != get_processor_category()) {
263 return close::status::blank;
264 }
265
266 switch (ec.value()) {
277 return close::status::protocol_error;
280 return close::status::invalid_payload;
282 return close::status::message_too_big;
283 default:
284 return close::status::internal_endpoint_error;
285 }
286}
287
288} // namespace error
289} // namespace processor
290} // namespace websocketpp
291
293template<> struct is_error_code_enum<websocketpp::processor::error::processor_errors>
294{
295 static bool const value = true;
296};
298
299#endif //WEBSOCKETPP_PROCESSOR_BASE_HPP
Category for processor errors.
Definition base.hpp:161
char const * name() const _WEBSOCKETPP_NOEXCEPT_TOKEN_
Definition base.hpp:165
std::string message(int value) const
Definition base.hpp:169
WebSocket protocol processor abstract base class.
#define _WEBSOCKETPP_NOEXCEPT_TOKEN_
Definition cpp11.hpp:113
const uint8_t constants[]
Definition keccak256.cpp:35
uint16_t value
The type of a close code value.
Definition close.hpp:49
lib::error_category const & get_processor_category()
Get a reference to a static copy of the processor error category.
Definition base.hpp:238
close::status::value to_ws(lib::error_code ec)
Converts a processor error_code into a websocket close code.
Definition base.hpp:261
@ missing_required_header
Missing Required Header.
Definition base.hpp:129
@ control_too_big
Control frame too large.
Definition base.hpp:90
@ invalid_http_method
Invalid HTTP method.
Definition base.hpp:120
@ invalid_rsv_bit
Illegal use of reserved bit.
Definition base.hpp:93
@ reason_requires_code
Using a reason requires a close code.
Definition base.hpp:144
@ invalid_close_code
Invalid close code used.
Definition base.hpp:141
@ masking_required
Clients may not send unmasked frames.
Definition base.hpp:102
@ protocol_violation
Processor encountered a protocol violation in an incoming message.
Definition base.hpp:75
@ extensions_disabled
Extension related operation was ignored because extensions are disabled.
Definition base.hpp:153
@ reserved_close_code
Reserved close code used.
Definition base.hpp:138
@ extension_parse_error
Error parsing extensions.
Definition base.hpp:150
@ masking_forbidden
Servers may not send masked frames.
Definition base.hpp:105
@ not_implemented
Operation required not implemented functionality.
Definition base.hpp:117
@ invalid_opcode
Opcode was invalid for requested operation.
Definition base.hpp:87
@ sha1_library
Embedded SHA-1 library error.
Definition base.hpp:132
@ requires_64bit
Not supported on 32 bit systems.
Definition base.hpp:111
@ subprotocol_parse_error
Error parsing subprotocols.
Definition base.hpp:147
@ bad_request
Error was the result of improperly formatted user input.
Definition base.hpp:72
@ invalid_utf8
Invalid UTF-8 encoding.
Definition base.hpp:114
@ invalid_http_status
Invalid HTTP status.
Definition base.hpp:126
@ invalid_payload
Processor encountered invalid payload data.
Definition base.hpp:81
@ invalid_http_version
Invalid HTTP version.
Definition base.hpp:123
@ message_too_big
Processor encountered a message that was too large.
Definition base.hpp:78
@ no_protocol_support
No support for this feature in this protocol version.
Definition base.hpp:135
@ invalid_arguments
The processor method was called with invalid arguments.
Definition base.hpp:84
@ invalid_continuation
Continuation without message.
Definition base.hpp:99
@ non_minimal_encoding
Payload length not minimally encoded.
Definition base.hpp:108
@ fragmented_control
Fragmented control message.
Definition base.hpp:96
lib::error_code make_error_code(error::processor_errors e)
Create an error code with the given value and the processor category.
Definition base.hpp:244
Namespace for the WebSocket++ project.
Definition base64.hpp:41
#define value
Definition pkcs11.h:157
#define _WEBSOCKETPP_ERROR_CODE_ENUM_NS_END_
#define _WEBSOCKETPP_ERROR_CODE_ENUM_NS_START_