NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
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 
40 namespace websocketpp {
41 namespace processor {
42 
44 namespace constants {
45 
46 static char const upgrade_token[] = "websocket";
47 static char const connection_token[] = "upgrade";
48 static char const handshake_guid[] = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
49 
50 } // namespace constants
51 
52 
54 namespace error_cat {
55 enum 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 
65 namespace error {
69  general = 1,
70 
73 
76 
79 
82 
85 
88 
91 
94 
97 
100 
103 
106 
109 
112 
115 
118 
121 
124 
127 
130 
133 
136 
139 
142 
145 
148 
151 
154 
158 };
159 
161 class processor_category : public lib::error_category {
162 public:
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";
173  case error::bad_request:
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";
201  case error::invalid_utf8:
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";
213  case error::sha1_library:
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";
229  case error::short_key3:
230  return "Short Hybi00 Key 3 read";
231  default:
232  return "Unknown";
233  }
234  }
235 };
236 
238 inline lib::error_category const & get_processor_category() {
239  static processor_category instance;
240  return instance;
241 }
242 
244 inline 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 
261 inline 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()) {
279  case error::invalid_utf8:
283  default:
285  }
286 }
287 
288 } // namespace error
289 } // namespace processor
290 } // namespace websocketpp
291 
293 template<> 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
static value const internal_endpoint_error
An endpoint encountered an unexpected condition that prevented it from fulfilling the request...
Definition: close.hpp:133
static char const connection_token[]
Definition: base.hpp:47
lib::error_code make_error_code(error::value e)
Get an error code with the given value and the stub transport category.
Definition: base.hpp:80
uint16_t value
The type of a close code value.
Definition: close.hpp:49
static value const invalid_payload
An endpoint received message data inconsistent with its type.
Definition: close.hpp:110
char const * name() const _WEBSOCKETPP_NOEXCEPT_TOKEN_
Definition: base.hpp:165
Embedded SHA-1 library error.
Definition: base.hpp:132
Clients may not send unmasked frames.
Definition: base.hpp:102
#define _WEBSOCKETPP_NOEXCEPT_TOKEN_
Definition: cpp11.hpp:113
WebSocket protocol processor abstract base class.
Definition: processor.hpp:160
Using a reason requires a close code.
Definition: base.hpp:144
Illegal use of reserved bit.
Definition: base.hpp:93
No support for this feature in this protocol version.
Definition: base.hpp:135
static value const protocol_error
A protocol error occurred.
Definition: close.hpp:83
lib::error_category const & get_processor_category()
Get a reference to a static copy of the processor error category.
Definition: base.hpp:238
static char const upgrade_token[]
Definition: base.hpp:46
Processor encountered invalid payload data.
Definition: base.hpp:81
Operation required not implemented functionality.
Definition: base.hpp:117
A package of types and methods for manipulating WebSocket close codes.
Continuation without message.
Definition: base.hpp:99
Error was the result of improperly formatted user input.
Definition: base.hpp:72
Processor encountered a protocol violation in an incoming message.
Definition: base.hpp:75
Not supported on 32 bit systems.
Definition: base.hpp:111
Extension related operation was ignored because extensions are disabled.
Definition: base.hpp:153
close::status::value to_ws(lib::error_code ec)
Converts a processor error_code into a websocket close code.
Definition: base.hpp:261
Catch-all error for processor policy errors that don&#39;t fit in other categories.
Definition: base.hpp:69
Namespace for the WebSocket++ project.
Definition: base64.hpp:41
#define _WEBSOCKETPP_ERROR_CODE_ENUM_NS_START_
static char const handshake_guid[]
Definition: base.hpp:48
Servers may not send masked frames.
Definition: base.hpp:105
Catch-all error for transport policy errors that don&#39;t fit in other categories.
Definition: base.hpp:46
Fragmented control message.
Definition: base.hpp:96
Processor encountered a message that was too large.
Definition: base.hpp:78
static value const message_too_big
An endpoint received a message too large to process.
Definition: close.hpp:121
Category for processor errors.
Definition: base.hpp:161
std::string message(int value) const
Definition: base.hpp:169
Opcode was invalid for requested operation.
Definition: base.hpp:87
#define _WEBSOCKETPP_ERROR_CODE_ENUM_NS_END_
The processor method was called with invalid arguments.
Definition: base.hpp:84
Payload length not minimally encoded.
Definition: base.hpp:108
static value const blank
A blank value for internal use.
Definition: close.hpp:52