WebSocket++ 0.8.3-dev
C++ websocket client/server library
Loading...
Searching...
No Matches
response.hpp
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 HTTP_PARSER_RESPONSE_IMPL_HPP
29#define HTTP_PARSER_RESPONSE_IMPL_HPP
30
31#include <algorithm>
32#include <istream>
33#include <sstream>
34#include <string>
35
36#include <websocketpp/http/parser.hpp>
37
38namespace websocketpp {
39namespace http {
40namespace parser {
41
42inline size_t response::consume(char const * buf, size_t len, lib::error_code & ec) {
43 if (m_state == DONE) {
44 // the response is already complete. End immediately without reading.
45 ec = lib::error_code();
46 return 0;
47 }
48
49 if (m_state == BODY) {
50 // The headers are complete, but we are still expecting more body
51 // bytes. Process body bytes.
52 return this->process_body(buf,len,ec);
53 }
54
55 // at this point we have an incomplete response still waiting for headers
56
57 // copy new candidate bytes into our local buffer. This buffer may have
58 // leftover bytes from previous calls. Not all of these bytes are
59 // necessarily header bytes (they might be body or even data after this
60 // request entirely for a keepalive request)
61 m_buf->append(buf,len);
62
63 // Search for delimiter in buf. If found read until then. If not read all
64 std::string::iterator begin = m_buf->begin();
65 std::string::iterator end = begin;
66
67
68 for (;;) {
69 // search for delimiter
70 end = std::search(
71 begin,
72 m_buf->end(),
75 );
76
77 if (end == m_buf->end()) {
78 // we didn't find the delimiter
79
80 // check that the confirmed header bytes plus the outstanding
81 // candidate bytes do not put us over the header size limit.
82 if (m_header_bytes + (end - begin) > max_header_size) {
84 return 0;
85 }
86
87 // We are out of bytes but not over any limits yet. Discard the
88 // processed bytes and copy the remaining unprecessed bytes to the
89 // beginning of the buffer in prep for another call to consume.
90
91 // If there are no processed bytes in the buffer right now don't
92 // copy the unprocessed ones over themselves.
93 if (begin != m_buf->begin()) {
94 std::copy(begin,end,m_buf->begin());
95 m_buf->resize(static_cast<std::string::size_type>(end-begin));
96 }
97
98 m_read += len;
99
100 ec = lib::error_code();
101 return len;
102 }
103
104 // at this point we have found a delimiter and the range [begin,end)
105 // represents a line to be processed
106
107 // update count of header bytes read so far
108 m_header_bytes += (end-begin+sizeof(header_delimiter));
109
110 if (m_header_bytes > max_header_size) {
111 // This read exceeded max header size
113 return 0;
114 }
115
116
117 if (end-begin == 0) {
118 // we got a blank line, which indicates the end of the headers
119
120 // If we are still looking for a response line then this request
121 // is incomplete
122 if (m_state == RESPONSE_LINE) {
124 return 0;
125 }
126
127 // TODO: grab content-length
128 std::string length = get_header("Content-Length");
129
130 if (length.empty()) {
131 // no content length found, read indefinitely?
132 m_read = 0;
133 } else {
134 std::istringstream ss(length);
135
136 if ((ss >> m_read).fail()) {
138 return 0;
139 }
140 }
141
142 // transition state to reading the response body
143 m_state = BODY;
144
145 // calculate how many bytes in the local buffer are bytes we didn't
146 // use for the headers.
147 size_t read = (
148 len - static_cast<std::string::size_type>(m_buf->end() - end)
149 + sizeof(header_delimiter) - 1
150 );
151
152 // if there were bytes left process them as body bytes.
153 // read is incremented with the number of body bytes processed.
154 // It is possible that there are still some bytes not read. These
155 // will be 'returned' to the caller by having the return value be
156 // less than len.
157 if (read < len) {
158 read += this->process_body(buf+read,(len-read),ec);
159 }
160 if (ec) {
161 return 0;
162 }
163
164 // frees memory used temporarily during header parsing
165 m_buf.reset();
166
167 ec = lib::error_code();
168 return read;
169 } else {
170 // we got a line
171 if (m_state == RESPONSE_LINE) {
172 ec = this->process(begin,end);
173 m_state = HEADERS;
174 } else {
175 ec = this->process_header(begin,end);
176 }
177 if (ec) {
178 return 0;
179 }
180 }
181
182 // if we got here it means there is another header line to read.
183 // advance our cursor to the first character after the most recent
184 // delimiter found.
185 begin = end+(sizeof(header_delimiter) - 1);
186 }
187}
188
189inline size_t response::consume(std::istream & s, lib::error_code & ec) {
190 char buf[istream_buffer];
191 size_t bytes_read;
192 size_t bytes_processed;
193 size_t total = 0;
194
195 while (s.good()) {
196 s.getline(buf,istream_buffer);
197 bytes_read = static_cast<size_t>(s.gcount());
198
199 if (s.fail() || s.eof()) {
200 bytes_processed = this->consume(buf,bytes_read,ec);
201 total += bytes_processed;
202
203 if (ec) { return total; }
204
205 if (bytes_processed != bytes_read) {
206 // we read more data from the stream than we needed for the
207 // HTTP response. This extra data gets thrown away now.
208 // Returning it to the caller is complicated so we alert the
209 // caller at least. This whole method has been deprecated
210 // because this convenience method doesnt really add useful
211 // functionality to the library, but makes it difficult to
212 // recover from error cases.
214 return total;
215 }
216 } else if (s.bad()) {
217 // problem
218 break;
219 } else {
220 // the delimiting newline was found. Replace the trailing null with
221 // the newline that was discarded, since our raw consume function
222 // expects the newline to be be there.
223 buf[bytes_read-1] = '\n';
224 bytes_processed = this->consume(buf,bytes_read,ec);
225 total += bytes_processed;
226
227 if (ec) { return total; }
228
229 if (bytes_processed != bytes_read) {
230 // we read more data from the stream than we needed for the
231 // HTTP response. This extra data gets thrown away now.
232 // Returning it to the caller is complicated so we alert the
233 // caller at least. This whole method has been deprecated
234 // because this convenience method doesnt really add useful
235 // functionality to the library, but makes it difficult to
236 // recover from error cases.
238 return total;
239 }
240 }
241 }
242
243 return total;
244}
245
246inline std::string response::raw() const {
247 // TODO: validation. Make sure all required fields have been set?
248
249 std::stringstream ret;
250
251 ret << get_version() << " " << m_status_code << " " << m_status_msg;
252 ret << "\r\n" << raw_headers() << "\r\n";
253
254 ret << m_body;
255
256 return ret.str();
257}
258
259inline lib::error_code response::set_status(status_code::value code) {
260 // In theory the type of status_code::value should prevent setting any
261 // invalid values. Messages are canned and looked up and known to be
262 // valid.
263 // TODO: Is there anything else that would need validation here?
264 m_status_code = code;
265 m_status_msg = get_string(code);
266 return lib::error_code();
267}
268
269inline lib::error_code response::set_status(status_code::value code,
270 std::string const & msg)
271{
272 // In theory the type of status_code::value should prevent setting any
273 // invalid values.
274 // TODO: Is there anything else that would need validation here?
275 // length or content of message?
276 // Per RFC2616
277 // Reason-Phrase = *<TEXT, excluding CR, LF>
278 // TEXT = = <any OCTET except CTLs,but including LWS>
279 // CTL = <any US-ASCII control character (octets 0 - 31) and DEL (127)>
280 // LWS = [CRLF] 1*( SP | HT )
281 m_status_code = code;
282 m_status_msg = msg;
283 return lib::error_code();
284}
285
286inline lib::error_code response::process(std::string::iterator begin,
287 std::string::iterator end)
288{
289 std::string::iterator cursor_start = begin;
290 std::string::iterator cursor_end = std::find(begin,end,' ');
291
292 if (cursor_end == end) {
294 }
295
296 set_version(std::string(cursor_start,cursor_end));
297
298 cursor_start = cursor_end+1;
299 cursor_end = std::find(cursor_start,end,' ');
300
301 if (cursor_end == end) {
303 }
304
305 int code;
306
307 std::istringstream ss(std::string(cursor_start,cursor_end));
308
309 if ((ss >> code).fail()) {
311 }
312
313 // todo: validation of status code? Technically there are limits on what
314 // status codes can be. Right now we follow Postel's law and check only
315 // that the valid is an integer and let the next layer decide what to do.
316 // Is this reasonable or should we be more aggressive?
317
318 // validation of the status message will pass through
319 return set_status(status_code::value(code),std::string(cursor_end+1,end));
320}
321
322inline size_t response::process_body(char const * buf, size_t len, lib::error_code & ec) {
323 // If no content length was set then we read forever and never set m_ready
324 if (m_read == 0) {
325 m_state = DONE;
326 ec = lib::error_code();
327 return 0;
328 }
329
330 // Otherwise m_read is the number of bytes left.
331 size_t to_read;
332
333 if (len >= m_read) {
334 // if we have more bytes than we need read, read only the amount needed
335 // then set done state
336 to_read = m_read;
337 m_state = DONE;
338 } else {
339 // we need more bytes than are available, read them all
340 to_read = len;
341 }
342
343 m_body.append(buf,to_read);
344 m_read -= to_read;
345 ec = lib::error_code();
346 return to_read;
347}
348
349} // namespace parser
350} // namespace http
351} // namespace websocketpp
352
353#endif // HTTP_PARSER_RESPONSE_IMPL_HPP
#define _WEBSOCKETPP_CPP11_FUNCTIONAL_
#define _WEBSOCKETPP_CPP11_THREAD_
#define _WEBSOCKETPP_CPP11_MEMORY_
#define _WEBSOCKETPP_CPP11_SYSTEM_ERROR_
Concurrency policy that uses std::mutex / boost::mutex.
Definition basic.hpp:37
Stub for user supplied base class.
Stub for user supplied base class.
Stub class for use when disabling permessage_deflate extension.
Definition disabled.hpp:53
HTTP parser error category.
An exception type specific to HTTP errors.
header_list const & get_headers() const
Return a list of all HTTP headers.
Definition parser.hpp:211
std::string const & get_body() const
Get HTTP body.
Definition parser.hpp:515
bool body_ready() const
Check if the parser is done parsing the body.
Definition parser.hpp:618
void set_max_body_size(size_t value)
Set body size limit.
Definition parser.hpp:555
bool prepare_body(lib::error_code &ec)
Prepare the parser to begin parsing body data.
Definition parser.hpp:143
std::string raw_headers() const
Generate and return the HTTP headers as a string.
Definition parser.hpp:215
size_t process_body(char const *buf, size_t len, lib::error_code &ec)
Process body data.
Definition parser.hpp:172
std::string const & get_version() const
Get the HTTP version string.
Definition parser.hpp:410
size_t get_max_body_size() const
Get body size limit.
Definition parser.hpp:542
lib::error_code process_header(std::string::iterator begin, std::string::iterator end)
Process a header line.
Definition parser.hpp:191
Stores, parses, and manipulates HTTP requests.
Definition request.hpp:50
std::string raw() const
Returns the full raw request (including the body).
Definition request.hpp:195
std::string const & get_uri() const
Return the requested URI.
Definition request.hpp:123
std::string const & get_method() const
Return the request method.
Definition request.hpp:107
bool ready() const
Returns whether or not the request is ready for reading.
Definition request.hpp:85
size_t consume(char const *buf, size_t len, lib::error_code &ec)
Process bytes in the input buffer.
Definition request.hpp:41
std::string raw_head() const
Returns the raw request headers only (similar to an HTTP HEAD request).
Definition request.hpp:205
Stores, parses, and manipulates HTTP responses.
Definition response.hpp:57
std::string raw() const
Returns the full raw response.
Definition response.hpp:246
size_t consume(char const *buf, size_t len, lib::error_code &ec)
Process bytes in the input buffer.
Definition response.hpp:42
bool headers_ready() const
Returns true if the response headers are fully parsed.
Definition response.hpp:149
size_t consume(std::istream &s, lib::error_code &ec)
Process bytes in the input buffer (istream version).
Definition response.hpp:189
lib::error_code set_status(status_code::value code)
Set response status code and message.
Definition response.hpp:259
bool ready() const
Returns true if the response is ready.
Definition response.hpp:144
const std::string & get_status_msg() const
Return the response status message.
Definition response.hpp:190
status_code::value get_status_code() const
Return the response status code.
Definition response.hpp:185
Basic logger that outputs to an ostream.
Definition basic.hpp:59
Thread safe stub "random" integer generator.
Definition none.hpp:46
Server endpoint role based on the given config.
Basic ASIO endpoint socket component.
Definition none.hpp:318
Asio based endpoint transport component.
Definition endpoint.hpp:54
lib::shared_ptr< type > ptr
Type of a shared pointer to this connection transport component.
connection_hdl get_handle() const
Get the connection handle.
config::alog_type alog_type
Type of this transport's access logging policy.
lib::error_code dispatch(dispatch_handler handler)
Call given handler back within the transport's event system (if present).
void async_shutdown(transport::shutdown_handler handler)
Perform cleanup on socket shutdown_handler.
void set_write_handler(write_handler h)
Sets the write handler.
void set_secure(bool value)
Set whether or not this connection is secure.
void set_shutdown_handler(shutdown_handler h)
Sets the shutdown handler.
connection< config > type
Type of this connection transport component.
config::elog_type elog_type
Type of this transport's error logging policy.
void fatal_error()
Signal transport error.
size_t read_some(char const *buf, size_t len)
Manual input supply (read some).
size_t read_all(char const *buf, size_t len)
Manual input supply (read all).
void async_write(char const *buf, size_t len, transport::write_handler handler)
Asyncronous Transport Write.
size_t readsome(char const *buf, size_t len)
Manual input supply (DEPRECATED).
config::concurrency_type concurrency_type
transport concurrency policy
void init(init_handler handler)
Initialize the connection transport.
timer_ptr set_timer(long, timer_handler)
Call back a function after a period of time.
friend std::istream & operator>>(std::istream &in, type &t)
Overloaded stream input operator.
void set_vector_write_handler(vector_write_handler h)
Sets the vectored write handler.
bool is_secure() const
Tests whether or not the underlying transport is secure.
std::string get_remote_endpoint() const
Get human readable remote endpoint address.
void set_handle(connection_hdl hdl)
Set Connection Handle.
void register_ostream(std::ostream *o)
Register a std::ostream with the transport for writing output.
void async_read_at_least(size_t num_bytes, char *buf, size_t len, read_handler handler)
Initiate an async_read for at least num_bytes bytes into buf.
void async_write(std::vector< buffer > const &bufs, transport::write_handler handler)
Asyncronous Transport Write (scatter-gather).
ptr get_shared()
Get a shared pointer to this component.
iostream::connection< config > transport_con_type
Definition endpoint.hpp:62
config::elog_type elog_type
Type of this endpoint's error logging policy.
Definition endpoint.hpp:56
void set_write_handler(write_handler h)
Sets the write handler.
Definition endpoint.hpp:134
void set_shutdown_handler(shutdown_handler h)
Sets the shutdown handler.
Definition endpoint.hpp:154
bool is_secure() const
Tests whether or not the underlying transport is secure.
Definition endpoint.hpp:116
lib::shared_ptr< type > ptr
Type of a pointer to this endpoint transport component.
Definition endpoint.hpp:51
transport_con_type::ptr transport_con_ptr
Definition endpoint.hpp:65
void async_connect(transport_con_ptr, uri_ptr, connect_handler cb)
Initiate a new connection.
Definition endpoint.hpp:183
lib::error_code init(transport_con_ptr tcon)
Initialize a connection.
Definition endpoint.hpp:197
void init_logging(lib::shared_ptr< alog_type > a, lib::shared_ptr< elog_type > e)
Initialize logging.
Definition endpoint.hpp:171
endpoint type
Type of this endpoint transport component.
Definition endpoint.hpp:49
void register_ostream(std::ostream *o)
Register a default output stream.
Definition endpoint.hpp:80
config::concurrency_type concurrency_type
Type of this endpoint's concurrency policy.
Definition endpoint.hpp:54
void set_secure(bool value)
Set whether or not endpoint can create secure connections.
Definition endpoint.hpp:102
config::alog_type alog_type
Type of this endpoint's access logging policy.
Definition endpoint.hpp:58
iostream transport error category
Definition base.hpp:85
std::string get_query() const
Return the query portion.
Definition uri.hpp:732
bool is_ipv6_literal() const
Definition uri.hpp:651
#define _WEBSOCKETPP_NOEXCEPT_TOKEN_
Definition cpp11.hpp:115
#define __has_extension
Definition cpp11.hpp:40
#define __has_feature(x)
Definition cpp11.hpp:37
Concurrency handling support.
Definition basic.hpp:34
Library level error codes.
Definition error.hpp:44
@ general
Catch-all library error.
Definition error.hpp:47
@ unrequested_subprotocol
Selected subprotocol was not requested by the client.
Definition error.hpp:102
@ invalid_port
Invalid port in URI.
Definition error.hpp:120
@ client_only
Attempted to use a client specific feature on a server endpoint.
Definition error.hpp:105
@ http_connection_ended
HTTP connection ended.
Definition error.hpp:111
@ operation_canceled
The requested operation was canceled.
Definition error.hpp:127
@ no_outgoing_buffers
The endpoint is out of outgoing message buffers.
Definition error.hpp:68
@ http_parse_error
HTTP parse error.
Definition error.hpp:143
@ reserved_close_code
Close code is in a reserved range.
Definition error.hpp:80
@ con_creation_failed
Connection creation attempted failed.
Definition error.hpp:99
@ no_incoming_buffers
The endpoint is out of incoming message buffers.
Definition error.hpp:71
@ invalid_state
The connection was in the wrong state for this operation.
Definition error.hpp:74
@ extension_neg_failed
Extension negotiation failed.
Definition error.hpp:146
@ rejected
Connection rejected.
Definition error.hpp:130
@ unsupported_version
Unsupported WebSocket protocol version.
Definition error.hpp:140
@ invalid_utf8
Invalid UTF-8.
Definition error.hpp:86
@ invalid_close_code
Close code is invalid.
Definition error.hpp:83
@ server_only
Attempted to use a server specific feature on a client endpoint.
Definition error.hpp:108
@ endpoint_not_secure
Attempted to open a secure connection with an insecure endpoint.
Definition error.hpp:57
@ close_handshake_timeout
WebSocket close handshake timed out.
Definition error.hpp:117
@ invalid_subprotocol
Invalid subprotocol.
Definition error.hpp:89
@ bad_close_code
Unable to parse close code.
Definition error.hpp:77
@ open_handshake_timeout
WebSocket opening handshake timed out.
Definition error.hpp:114
@ invalid_version
Invalid WebSocket protocol version.
Definition error.hpp:137
@ transport_error
General transport error, consult more specific transport error code.
Definition error.hpp:149
@ send_queue_full
send attempted when endpoint write queue was full
Definition error.hpp:50
@ test
Unit testing utility error code.
Definition error.hpp:96
@ invalid_uri
An invalid uri was supplied.
Definition error.hpp:65
Implementation of RFC 7692, the permessage-deflate WebSocket extension.
Definition disabled.hpp:44
HTTP parser errors.
status_code::value get_status_code(error::value value)
Get the HTTP status code associated with the error.
lib::error_category const & get_category()
Get a reference to a static copy of the asio transport error category.
@ unknown_transfer_encoding
The transfer encoding is unknown.
@ istream_bad
An istream read command returned with the bad flag set.
@ invalid_format
The specified data contains illegal characters for the context.
@ body_too_large
The body value is larger than the configured maximum size.
@ incomplete_request
The request was missing some required values.
@ unsupported_transfer_encoding
The transfer encoding is not supported.
@ incomplete_status_line
The response status line was missing some required values.
@ missing_header_separator
A header line was missing a separator.
@ invalid_header_name
The header name specified contains illegal characters.
@ request_header_fields_too_large
The request headers are larger than the configured maximum size.
lib::error_code make_error_code(error::value e)
Create an error code with the given value and the asio transport category.
std::string get_string(value code)
Given a status code value, return the default status message.
value
Known values for HTTP Status codes.
HTTP handling support.
Definition request.hpp:37
size_t const max_body_size
Default Maximum size in bytes for HTTP message bodies.
Definition constants.hpp:71
static char const header_separator[]
Literal value of the HTTP header separator.
Definition constants.hpp:62
std::vector< std::pair< std::string, attribute_list > > parameter_list
The type of an HTTP parameter list.
Definition constants.hpp:56
size_t const istream_buffer
Number of bytes to use for temporary istream read buffers.
Definition constants.hpp:74
bool is_not_token_char(unsigned char c)
Is the character a non-token.
size_t const max_header_size
Maximum size in bytes before rejecting an HTTP header as too big.
Definition constants.hpp:68
static char const header_delimiter[]
Literal value of the HTTP header delimiter.
Definition constants.hpp:59
bool is_whitespace_char(unsigned char c)
Is the character whitespace.
static char const header_token[]
invalid HTTP token characters
Definition constants.hpp:81
bool is_not_whitespace_char(unsigned char c)
Is the character non-whitespace.
std::map< std::string, std::string > attribute_list
The type of an HTTP attribute list.
Definition constants.hpp:48
bool is_token_char(unsigned char c)
Is the character a token.
static std::string const empty_header
Literal value of an empty header.
Definition constants.hpp:65
Stub RNG policy that always returns 0.
Definition none.hpp:35
Random number generation policies.
Transport policy that uses asio.
Definition endpoint.hpp:46
Generic transport related errors.
@ pass_through
underlying transport pass through
@ operation_not_supported
Operation not supported.
@ operation_aborted
Operation aborted.
@ invalid_num_bytes
async_read_at_least call requested more bytes than buffer can store
@ action_after_shutdown
read or write after shutdown
@ tls_short_read
TLS short read.
@ double_read
async_read called while another async_read was in progress
iostream transport errors
Definition base.hpp:64
@ invalid_num_bytes
async_read_at_least call requested more bytes than buffer can store
Definition base.hpp:71
@ double_read
async_read called while another async_read was in progress
Definition base.hpp:74
lib::error_code make_error_code(error::value e)
Get an error code with the given value and the iostream transport category.
Definition base.hpp:118
lib::error_category const & get_category()
Get a reference to a static copy of the iostream transport error category.
Definition base.hpp:112
Transport policy that uses STL iostream for I/O and does not support timers.
Definition endpoint.hpp:43
lib::function< lib::error_code(connection_hdl, std::vector< transport::buffer > const &bufs)> vector_write_handler
Definition base.hpp:57
lib::function< lib::error_code(connection_hdl)> shutdown_handler
Definition base.hpp:61
lib::function< lib::error_code(connection_hdl, char const *, size_t)> write_handler
The type and signature of the callback used by iostream transport to write.
Definition base.hpp:48
Transport policies provide network connectivity and timers.
Definition endpoint.hpp:45
lib::function< void(lib::error_code const &, size_t)> read_handler
The type and signature of the callback passed to the read method.
lib::function< void()> dispatch_handler
The type and signature of the callback passed to the dispatch method.
lib::function< void()> interrupt_handler
The type and signature of the callback passed to the interrupt method.
lib::function< void(lib::error_code const &)> accept_handler
The type and signature of the callback passed to the accept method.
Definition endpoint.hpp:80
lib::function< void(lib::error_code const &)> timer_handler
The type and signature of the callback passed to the read method.
lib::function< void(lib::error_code const &)> connect_handler
The type and signature of the callback passed to the connect method.
Definition endpoint.hpp:83
lib::function< void(lib::error_code const &)> write_handler
The type and signature of the callback passed to the write method.
lib::function< void(lib::error_code const &)> init_handler
The type and signature of the callback passed to the init hook.
lib::function< void(lib::error_code const &)> shutdown_handler
The type and signature of the callback passed to the shutdown method.
A group of helper methods for parsing and validating URIs against RFC 3986.
Definition uri.hpp:52
bool digit(char c)
RFC3986 digit character test.
Definition uri.hpp:184
bool gen_delim(char c)
RFC3986 generic delimiter character test.
Definition uri.hpp:78
bool digit(std::string::const_iterator it)
RFC3986 digit character test (iterator version).
Definition uri.hpp:195
bool ipv4_literal(std::string::const_iterator start, std::string::const_iterator end)
Tests a range for a valid IPv4 literal.
Definition uri.hpp:250
bool sub_delim(char c)
RFC3986 subcomponent delimiter character test.
Definition uri.hpp:100
bool reg_name(std::string::const_iterator start, std::string::const_iterator end)
Tests a range for validity for a registry name.
Definition uri.hpp:373
bool pct_encoded(std::string::const_iterator it)
RFC3986 per cent encoded character test.
Definition uri.hpp:211
bool scheme(char c)
RFC3986 scheme character test.
Definition uri.hpp:165
bool unreserved(char c)
RFC3986 unreserved character test.
Definition uri.hpp:61
bool reg_name(char c)
Tests a character for validity for a registry name.
Definition uri.hpp:361
bool hex4(std::string::const_iterator start, std::string::const_iterator end)
Tests a range for a valid IPv6 hex quad.
Definition uri.hpp:279
bool dec_octet(std::string::const_iterator start, std::string::const_iterator end)
Tests a range for a valid IPv4 decimal octet.
Definition uri.hpp:223
bool ipv6_literal(std::string::const_iterator start, std::string::const_iterator end)
Tests a range for a valid IPv6 literal.
Definition uri.hpp:299
bool hexdigit(char c)
RFC3986 hex digit character test.
Definition uri.hpp:128
Generic non-websocket specific utility functions and data structures.
Definition utilities.hpp:39
std::string to_hex(uint8_t const *input, size_t length)
Convert byte array (uint8_t) to ascii printed string of hex digits.
T::const_iterator ci_find_substr(T const &haystack, T const &needle, std::locale const &loc=std::locale())
Find substring (case insensitive).
T::const_iterator ci_find_substr(T const &haystack, typename T::value_type const *needle, typename T::size_type size, std::locale const &loc=std::locale())
Find substring (case insensitive).
std::string to_hex(char const *input, size_t length)
Convert char array to ascii printed string of hex digits.
Namespace for the WebSocket++ project.
static uint16_t const uri_default_secure_port
Default port for wss://.
Definition uri.hpp:47
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
static uint16_t const uri_default_port
Default port for ws://.
Definition uri.hpp:45
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.
Definition uri.hpp:791
std::pair< lib::error_code, std::string > err_str_pair
Combination error code / string type for returning two values.
Definition error.hpp:41
Server config with asio transport and TLS disabled.
static const long timeout_socket_shutdown
Length of time to wait for socket shutdown.
Definition core.hpp:137
static const long timeout_connect
Length of time to wait for TCP connect.
Definition core.hpp:134
static const long timeout_dns_resolve
Length of time to wait for dns resolution.
Definition core.hpp:131
static const long timeout_proxy
Length of time to wait before a proxy handshake is aborted.
Definition core.hpp:121
static const long timeout_socket_pre_init
Default timer values (in ms).
Definition core.hpp:118
static const long timeout_socket_post_init
Length of time to wait for socket post-initialization.
Definition core.hpp:128
Server config with iostream transport.
Definition core.hpp:68
websocketpp::random::none::int_generator< uint32_t > rng_type
RNG policies.
Definition core.hpp:93
static const websocketpp::log::level elog_level
Default static error logging channels.
Definition core.hpp:176
websocketpp::transport::iostream::endpoint< transport_config > transport_type
Transport Endpoint Component.
Definition core.hpp:142
static const size_t max_http_body_size
Default maximum http body size.
Definition core.hpp:252
static const long timeout_open_handshake
Default timer values (in ms).
Definition core.hpp:152
static const size_t max_message_size
Default maximum message size.
Definition core.hpp:240
static const bool drop_on_protocol_error
Drop connections immediately on protocol error.
Definition core.hpp:213
static const long timeout_close_handshake
Length of time before a closing handshake is aborted.
Definition core.hpp:154
static const websocketpp::log::level alog_level
Default static access logging channels.
Definition core.hpp:189
websocketpp::log::basic< concurrency_type, websocketpp::log::elevel > elog_type
Logging policies.
Definition core.hpp:88
static const long timeout_pong
Length of time to wait for a pong after a ping.
Definition core.hpp:156
static const bool silent_close
Suppresses the return of detailed connection close information.
Definition core.hpp:228
static bool const enable_multithreading
Definition core.hpp:98
static const size_t connection_read_buffer_size
Size of the per-connection read buffer.
Definition core.hpp:204
static const bool enable_extensions
Global flag for enabling/disabling extensions.
Definition core.hpp:255
static const int client_version
WebSocket Protocol version to use as a client.
Definition core.hpp:164
Package of log levels for logging access events.
Definition levels.hpp:112
static char const * channel_name(level channel)
Get the textual name of a channel given a channel id.
Definition levels.hpp:164
static level const fail
One line for each failed WebSocket connection with details.
Definition levels.hpp:147
static level const none
Special aggregate value representing "no levels".
Definition levels.hpp:114
static level const debug_handshake
Extra information about opening handshakes.
Definition levels.hpp:137
static level const devel
Development messages (warning: very chatty).
Definition levels.hpp:141
static level const all
Special aggregate value representing "all levels".
Definition levels.hpp:152
static level const debug_close
Extra information about closing handshakes.
Definition levels.hpp:139
static level const frame_payload
One line per frame, includes the full message payload (warning: chatty).
Definition levels.hpp:129
static level const connect
Information about new connections.
Definition levels.hpp:121
static level const app
Special channel for application specific logs. Not used by the library.
Definition levels.hpp:143
static level const frame_header
One line per frame, includes the full frame header.
Definition levels.hpp:127
static level const message_payload
Reserved.
Definition levels.hpp:133
static level const endpoint
Reserved.
Definition levels.hpp:135
static level const message_header
Reserved.
Definition levels.hpp:131
static level const control
One line per control frame.
Definition levels.hpp:125
static level const disconnect
One line for each closed connection. Includes closing codes and reasons.
Definition levels.hpp:123
static level const access_core
Definition levels.hpp:150
static level const http
Access related to HTTP requests.
Definition levels.hpp:145
Package of values for hinting at the nature of a given logger.
Definition levels.hpp:46
static value const none
No information.
Definition levels.hpp:51
static value const access
Access log.
Definition levels.hpp:53
static value const error
Error log.
Definition levels.hpp:55
uint32_t value
Type of a channel type hint value.
Definition levels.hpp:48
Package of log levels for logging errors.
Definition levels.hpp:59
static level const devel
Low level debugging information (warning: very chatty).
Definition levels.hpp:63
static char const * channel_name(level channel)
Get the textual name of a channel given a channel id.
Definition levels.hpp:91
static level const library
Definition levels.hpp:66
static level const info
Definition levels.hpp:69
static level const all
Special aggregate value representing "all levels".
Definition levels.hpp:80
static level const fatal
Definition levels.hpp:78
static level const none
Special aggregate value representing "no levels".
Definition levels.hpp:61
static level const rerror
Definition levels.hpp:75
static level const warn
Definition levels.hpp:72
A simple utility buffer class.
Helper less than functor for case insensitive find.
Definition utilities.hpp:75
Helper functor for case insensitive find.
Definition utilities.hpp:49
bool operator()(charT ch1, charT ch2)
Perform a case insensitive comparison.
Definition utilities.hpp:63
my_equal(std::locale const &loc)
Construct the functor with the given locale.
Definition utilities.hpp:54
#define _WEBSOCKETPP_ERROR_CODE_ENUM_NS_END_
#define _WEBSOCKETPP_ERROR_CODE_ENUM_NS_START_