2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
28#ifndef WEBSOCKETPP_PROCESSOR_BASE_HPP
29#define WEBSOCKETPP_PROCESSOR_BASE_HPP
31#include <websocketpp/close.hpp>
32#include <websocketpp/utilities.hpp>
33#include <websocketpp/uri.hpp>
35#include <websocketpp/common/cpp11.hpp>
36#include <websocketpp/common/system_error.hpp>
46static char const upgrade_token[] =
"websocket";
47static char const connection_token[] =
"Upgrade";
48static char const handshake_guid[] =
"258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
58 PROTOCOL_VIOLATION = 2,
163 processor_category() {}
166 return "websocketpp.processor";
169 std::string message(
int value)
const {
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";
250
251
252
253
254
255
256
257
258
259
260
266 switch (ec.value()) {
295 static bool const value =
true;
#define _WEBSOCKETPP_CPP11_FUNCTIONAL_
#define _WEBSOCKETPP_CPP11_THREAD_
#define _WEBSOCKETPP_CPP11_MEMORY_
#define _WEBSOCKETPP_CPP11_SYSTEM_ERROR_
#define _WEBSOCKETPP_INITIALIZER_LISTS_
Concurrency policy that uses std::mutex / boost::mutex.
Stub for user supplied base class.
Represents an individual WebSocket connection.
ptr get_shared()
Get a shared pointer to this component.
config::concurrency_type concurrency_type
Type of the concurrency component of this connection.
void handle_interrupt()
Transport inturrupt callback.
void set_message_handler(message_handler h)
Set message handler.
config::elog_type elog_type
Type of the error logging policy.
lib::error_code interrupt()
Asyncronously invoke handler::on_inturrupt.
void start()
Start the connection state machine.
std::string const & get_request_body() const
Retrieve a request body.
void set_close_handler(close_handler h)
Set close handler.
lib::error_code send(message_ptr msg)
Add a message to the outgoing send queue.
http::status_code::value get_response_code() const
Get response HTTP status code.
lib::error_code defer_http_response()
Defer HTTP Response until later (Exception free)
lib::error_code resume_reading()
Resume reading of new data.
bool get_secure() const
Returns the secure flag from the connection URI.
void set_close_handshake_timeout(long dur)
Set close handshake timeout.
config::alog_type alog_type
Type of the access logging policy.
size_t get_buffered_amount() const
Get the size of the outgoing write buffer (in payload bytes)
std::string const & get_origin() const
Return the same origin policy origin value from the opening request.
std::string const & get_host() const
Returns the host component of the connection URI.
transport_con_type::timer_ptr timer_ptr
Type of a pointer to a transport timer handle.
response_type const & get_response() const
Get response object.
void set_max_message_size(size_t new_value)
Set maximum message size.
std::string const & get_resource() const
Returns the resource component of the connection URI.
lib::error_code process_handshake_request()
void handle_pause_reading()
Pause reading callback.
std::vector< int > const & get_supported_versions() const
Get array of WebSocket protocol versions that this connection supports.
config::rng_type rng_type
Type of RNG.
lib::error_code send(void const *payload, size_t len, frame::opcode::value op=frame::opcode::binary)
Send a message (raw array overload)
uri_ptr get_uri() const
Gets the connection URI.
connection_hdl get_handle() const
Get Connection Handle.
void send_http_response(lib::error_code &ec)
Send deferred HTTP Response (exception free)
void set_http_handler(http_handler h)
Set http handler.
std::string const & get_response_msg() const
Get response HTTP status message.
message_ptr get_message(websocketpp::frame::opcode::value op, size_t size) const
Get a message buffer.
void handle_write_frame(lib::error_code const &ec)
Process the results of a frame write operation and start the next write.
close::status::value get_local_close_code() const
Get the WebSocket close code sent by this endpoint.
lib::error_code get_ec() const
Get the internal error code for a closed/failed connection.
void set_fail_handler(fail_handler h)
Set fail handler.
void write_frame()
Checks if there are frames in the send queue and if there are sends one.
session::state::value get_state() const
Return the connection state.
transport_con_type::ptr transport_con_ptr
Type of a shared pointer to the transport component of this connection.
void set_status(http::status_code::value code)
Set response status code and message.
size_t get_max_http_body_size() const
Get maximum HTTP message body size.
void set_validate_handler(validate_handler h)
Set validate handler.
void set_interrupt_handler(interrupt_handler h)
Set interrupt handler.
size_t buffered_amount() const
Get the size of the outgoing write buffer (in payload bytes)
void send_http_response()
Send deferred HTTP Response.
close::status::value get_remote_close_code() const
Get the WebSocket close code sent by the remote endpoint.
void set_open_handler(open_handler h)
Set open handler.
bool is_server() const
Get whether or not this connection is part of a server or client.
std::string const & get_remote_close_reason() const
Get the WebSocket close reason sent by the remote endpoint.
void set_pong_timeout(long dur)
Set pong timeout.
lib::error_code initialize_processor()
void set_uri(uri_ptr uri)
Sets the connection URI.
void set_termination_handler(termination_handler new_handler)
request_type const & get_request() const
Get request object.
connection< config > type
Type of this connection.
void set_max_http_body_size(size_t new_value)
Set maximum HTTP message body size.
void set_open_handshake_timeout(long dur)
Set open handshake timeout.
lib::error_code pause_reading()
Pause reading of new data.
void handle_resume_reading()
Resume reading callback.
std::vector< std::string > const & get_requested_subprotocols() const
Gets all of the subprotocols requested by the client.
config::transport_type::transport_con_type transport_con_type
Type of the transport component of this connection.
std::string const & get_subprotocol() const
Gets the negotated subprotocol.
void set_handle(connection_hdl hdl)
Set Connection Handle.
void read_frame()
Issue a new transport read unless reading is paused.
lib::shared_ptr< type > ptr
Type of a shared pointer to this connection.
uint16_t get_port() const
Returns the port component of the connection URI.
std::string const & get_local_close_reason() const
Get the WebSocket close reason sent by this endpoint.
size_t get_max_message_size() const
Get maximum message size.
Stub for user supplied base class.
Creates and manages connections associated with a WebSocket endpoint.
void set_max_http_body_size(size_t new_value)
Set maximum HTTP message body size.
concurrency_type::scoped_lock_type scoped_lock_type
Type of our concurrency policy's scoped lock object.
connection_ptr get_con_from_hdl(connection_hdl hdl, lib::error_code &ec)
Retrieves a connection_ptr from a connection_hdl (exception free)
alog_type & get_alog()
Get reference to access logger.
config::rng_type rng_type
Type of RNG.
std::string get_user_agent() const
Returns the user agent string that this endpoint will use.
transport_con_type::ptr transport_con_ptr
void clear_access_channels(log::level channels)
Clear Access logging channels.
void resume_reading(connection_hdl hdl)
Resume reading of new data.
connection connection_type
Type of the connections that this endpoint creates.
elog_type & get_elog()
Get reference to error logger.
bool is_server() const
Returns whether or not this endpoint is a server.
connection_type::message_handler message_handler
Type of message_handler.
void set_close_handshake_timeout(long dur)
Set close handshake timeout.
void set_access_channels(log::level channels)
Set Access logging channel.
void set_max_message_size(size_t new_value)
Set default maximum message size.
size_t get_max_message_size() const
Get default maximum message size.
connection_ptr get_con_from_hdl(connection_hdl hdl)
Retrieves a connection_ptr from a connection_hdl (exception version)
connection_type::weak_ptr connection_weak_ptr
Weak pointer to connection type.
connection_type::message_ptr message_ptr
Type of message pointers that this endpoint uses.
void set_error_channels(log::level channels)
Set Error logging channel.
void clear_error_channels(log::level channels)
Clear Error logging channels.
config::elog_type elog_type
Type of error logger.
void resume_reading(connection_hdl hdl, lib::error_code &ec)
Resume reading of new data (exception free)
concurrency_type::mutex_type mutex_type
Type of our concurrency policy's mutex object.
connection_type::ptr connection_ptr
Shared pointer to connection_type.
void interrupt(connection_hdl hdl, lib::error_code &ec)
void set_pong_timeout(long dur)
Set pong timeout.
config::transport_type transport_type
Type of the transport component of this endpoint.
size_t get_max_http_body_size() const
Get maximum HTTP message body size.
config::concurrency_type concurrency_type
Type of the concurrency component of this endpoint.
void set_open_handshake_timeout(long dur)
Set open handshake timeout.
config::alog_type alog_type
Type of access logger.
void send_http_response(connection_hdl hdl, lib::error_code &ec)
Send deferred HTTP Response.
transport_type::transport_con_type transport_con_type
void pause_reading(connection_hdl hdl, lib::error_code &ec)
Pause reading of new data (exception free)
void send_http_response(connection_hdl hdl)
Send deferred HTTP Response (exception free)
void pause_reading(connection_hdl hdl)
Pause reading of new data.
Stub class for use when disabling permessage_deflate extension.
bool is_implemented() const
err_str_pair negotiate(http::attribute_list const &)
Negotiate extension.
std::string generate_offer() const
Generate extension offer.
lib::error_code init(bool)
Initialize state.
header_list const & get_headers() const
Return a list of all HTTP headers.
size_t process_body(char const *buf, size_t len)
Process body data.
std::string const & get_body() const
Get HTTP body.
void process_header(std::string::iterator begin, std::string::iterator end)
Process a header line.
bool body_ready() const
Check if the parser is done parsing the body.
bool prepare_body()
Prepare the parser to begin parsing body data.
void set_max_body_size(size_t value)
Set body size limit.
std::string raw_headers() const
Generate and return the HTTP headers as a string.
std::string const & get_version() const
Get the HTTP version string.
size_t get_max_body_size() const
Get body size limit.
Stores, parses, and manipulates HTTP requests.
std::string raw() const
Returns the full raw request (including the body)
std::string const & get_uri() const
Return the requested URI.
std::string const & get_method() const
Return the request method.
size_t consume(char const *buf, size_t len)
Process bytes in the input buffer.
bool ready() const
Returns whether or not the request is ready for reading.
std::string raw_head() const
Returns the raw request headers only (similar to an HTTP HEAD request)
Stores, parses, and manipulates HTTP responses.
void set_status(status_code::value code)
Set response status code and message.
std::string raw() const
Returns the full raw response.
size_t consume(std::istream &s)
Process bytes in the input buffer (istream version)
bool headers_ready() const
Returns true if the response headers are fully parsed.
bool ready() const
Returns true if the response is ready.
const std::string & get_status_msg() const
Return the response status message.
status_code::value get_status_code() const
Return the response status code.
size_t consume(char const *buf, size_t len)
Process bytes in the input buffer.
Basic logger that outputs to an ostream.
void write(level channel, char const *msg)
Write a cstring message to the given channel.
bool recycle(message *)
Recycle a message.
message_ptr get_message(frame::opcode::value op, size_t size)
Get a message buffer with specified size and opcode.
message_ptr get_message()
Get an empty message buffer.
con_msg_man_ptr get_manager() const
Get a pointer to a connection message manager.
Represents a buffer for a single WebSocket message.
message(const con_msg_man_ptr manager, frame::opcode::value op, size_t size=128)
Construct a message and fill in some values.
std::string & get_raw_payload()
Get a non-const reference to the payload string.
bool recycle()
Recycle the message.
bool get_compressed() const
Return whether or not the message is flagged as compressed.
bool get_terminal() const
Get whether or not the message is terminal.
std::string const & get_header() const
Return the prepared frame header.
void set_payload(void const *payload, size_t len)
Set payload data.
bool get_fin() const
Read the fin bit.
void append_payload(void const *payload, size_t len)
Append payload data.
void set_opcode(frame::opcode::value op)
Set the opcode.
void set_prepared(bool value)
Set or clear the flag that indicates that the message has been prepared.
frame::opcode::value get_opcode() const
Return the message opcode.
void set_terminal(bool value)
Set the terminal flag.
bool get_prepared() const
Return whether or not the message has been prepared for sending.
void set_compressed(bool value)
Set or clear the compression flag.
message(const con_msg_man_ptr manager)
Construct an empty message.
void set_fin(bool value)
Set the fin bit.
std::string const & get_payload() const
Get a reference to the payload string.
Category for processor errors.
WebSocket protocol processor abstract base class.
virtual lib::error_code prepare_data_frame(message_ptr in, message_ptr out)=0
Prepare a data message for writing.
virtual size_t get_bytes_needed() const
virtual size_t consume(uint8_t *buf, size_t len, lib::error_code &ec)=0
process new websocket connection bytes
virtual err_str_pair negotiate_extensions(response_type const &)
Initializes extensions based on the Sec-WebSocket-Extensions header.
virtual int get_version() const =0
Get the protocol version of this processor.
virtual std::string get_raw(response_type const &request) const =0
Given a completed response, get the raw bytes to put on the wire.
virtual bool ready() const =0
Checks if there is a message ready.
virtual lib::error_code validate_handshake(request_type const &request) const =0
validate a WebSocket handshake request for this version
virtual uri_ptr get_uri(request_type const &request) const =0
Extracts client uri from a handshake request.
virtual err_str_pair negotiate_extensions(request_type const &)
Initializes extensions based on the Sec-WebSocket-Extensions header.
virtual bool has_permessage_compress() const
Returns whether or not the permessage_compress extension is implemented.
virtual lib::error_code validate_server_handshake_response(request_type const &req, response_type &res) const =0
Validate the server's response to an outgoing handshake request.
virtual lib::error_code client_handshake_request(request_type &req, uri_ptr uri, std::vector< std::string > const &subprotocols) const =0
Fill in an HTTP request for an outgoing connection handshake.
virtual lib::error_code extract_subprotocols(const request_type &req, std::vector< std::string > &subprotocol_list)=0
Extracts requested subprotocols from a handshake request.
virtual bool get_error() const =0
Tests whether the processor is in a fatal error state.
void set_max_message_size(size_t new_value)
Set maximum message size.
virtual std::string const & get_origin(request_type const &request) const =0
Return the value of the header containing the CORS origin.
size_t get_max_message_size() const
Get maximum message size.
virtual message_ptr get_message()=0
Retrieves the most recently processed message.
Thread safe stub "random" integer generator.
int_type operator()()
advances the engine's state and returns the generated value
Server endpoint role based on the given config.
void start_accept(lib::error_code &ec)
Starts the server's async connection acceptance loop (exception free)
transport_type::transport_con_type transport_con_type
Type of the connection transport component.
config::transport_type transport_type
Type of the endpoint transport component.
transport_con_type::ptr transport_con_ptr
Type of a shared pointer to the connection transport component.
connection< config > connection_type
Type of the connections this server will create.
endpoint< connection_type, config > endpoint_type
Type of the endpoint component of this server.
connection_ptr get_connection()
Create and initialize a new connection.
void handle_accept(connection_ptr con, lib::error_code const &ec)
Handler callback for start_accept.
server< config > type
Type of this endpoint.
config::concurrency_type concurrency_type
Type of the endpoint concurrency component.
void start_accept()
Starts the server's async connection acceptance loop.
connection_type::ptr connection_ptr
Type of a shared pointer to the connections this server will create.
Basic Asio connection socket component.
lib::asio::ip::tcp::socket socket_type
Type of the ASIO socket being used.
lib::asio::ip::tcp::socket & get_raw_socket()
Retrieve a pointer to the underlying socket.
void set_socket_init_handler(socket_init_handler h)
Set the socket initialization handler.
void set_uri(uri_ptr)
Set uri hook.
lib::shared_ptr< lib::asio::io_service::strand > strand_ptr
Type of a pointer to the Asio io_service strand being used.
lib::asio::io_service * io_service_ptr
Type of a pointer to the Asio io_service being used.
lib::asio::ip::tcp::socket & get_socket()
Retrieve a pointer to the underlying socket.
bool is_secure() const
Check whether or not this connection is secure.
connection type
Type of this connection socket component.
static lib::error_code translate_ec(lib::error_code ec)
static lib::error_code translate_ec(ErrorCodeType)
Translate any security policy specific information about an error code.
void set_handle(connection_hdl hdl)
Sets the connection handle.
lib::asio::error_code cancel_socket()
Cancel all async operations on this socket.
lib::shared_ptr< socket_type > socket_ptr
Type of a shared pointer to the socket being used.
void pre_init(init_handler callback)
Pre-initialize security policy.
std::string get_remote_endpoint(lib::error_code &ec) const
Get the remote endpoint address.
void post_init(init_handler callback)
Post-initialize security policy.
lib::error_code init_asio(io_service_ptr service, strand_ptr, bool)
Perform one time initializations.
ptr get_shared()
Get a shared pointer to this component.
lib::shared_ptr< type > ptr
Type of a shared pointer to this connection socket component.
lib::asio::ip::tcp::socket & get_next_layer()
Retrieve a pointer to the underlying socket.
Basic ASIO endpoint socket component.
void set_socket_init_handler(socket_init_handler h)
Set socket init handler.
endpoint type
The type of this endpoint socket component.
socket_con_type::ptr socket_con_ptr
lib::error_code init(socket_con_ptr scon)
Initialize a connection.
connection socket_con_type
The type of the corresponding connection socket component.
bool is_secure() const
Checks whether the endpoint creates secure connections.
Asio based connection transport component.
void set_proxy_timeout(long duration)
Set the proxy timeout duration (exception)
void set_tcp_post_init_handler(tcp_init_handler h)
Sets the tcp post init handler.
void set_proxy_timeout(long duration, lib::error_code &ec)
Set the proxy timeout duration (exception free)
strand_ptr get_strand()
Get a pointer to this connection's strand.
void async_read_at_least(size_t num_bytes, char *buf, size_t len, read_handler handler)
read at least num_bytes bytes into buf and then call handler.
lib::error_code interrupt(interrupt_handler handler)
Trigger the on_interrupt handler.
lib::shared_ptr< type > ptr
Type of a shared pointer to this connection transport component.
void handle_async_write(write_handler handler, lib::asio::error_code const &ec, size_t)
Async write callback.
void handle_timer(timer_ptr, timer_handler callback, lib::asio::error_code const &ec)
Timer callback.
lib::error_code init_asio(io_service_ptr io_service)
Finish constructing the transport.
config::socket_type::socket_con_type socket_con_type
Type of the socket connection component.
void handle_post_init(timer_ptr post_timer, init_handler callback, lib::error_code const &ec)
Post init timeout callback.
lib::shared_ptr< lib::asio::io_service::strand > strand_ptr
Type of a pointer to the Asio io_service::strand being used.
void async_shutdown(shutdown_handler callback)
close and clean up the underlying socket
config::alog_type alog_type
Type of this transport's access logging policy.
lib::asio::error_code get_transport_ec() const
Get the internal transport error code for a closed/failed connection.
lib::shared_ptr< lib::asio::steady_timer > timer_ptr
Type of a pointer to the Asio timer class.
void handle_post_init_timeout(timer_ptr, init_handler callback, lib::error_code const &ec)
Post init timeout callback.
void handle_async_shutdown_timeout(timer_ptr, init_handler callback, lib::error_code const &ec)
Async shutdown timeout handler.
void async_write(const char *buf, size_t len, write_handler handler)
Initiate a potentially asyncronous write of the given buffer.
void async_write(std::vector< buffer > const &bufs, write_handler handler)
Initiate a potentially asyncronous write of the given buffers.
connection< config > type
Type of this connection transport component.
lib::asio::io_service * io_service_ptr
Type of a pointer to the Asio io_service being used.
timer_ptr set_timer(long duration, timer_handler callback)
Call back a function after a period of time.
void set_tcp_init_handler(tcp_init_handler h)
Sets the tcp pre init handler (deprecated)
void handle_proxy_read(init_handler callback, lib::asio::error_code const &ec, size_t)
Proxy read callback.
void set_uri(uri_ptr u)
Set uri hook.
std::string get_remote_endpoint() const
Get the remote endpoint address.
ptr get_shared()
Get a shared pointer to this component.
void cancel_socket_checked()
Cancel the underlying socket and log any errors.
void set_handle(connection_hdl hdl)
Set Connection Handle.
void set_tcp_pre_init_handler(tcp_init_handler h)
Sets the tcp pre init handler.
config::elog_type elog_type
Type of this transport's error logging policy.
void init(init_handler callback)
Initialize transport for reading.
socket_con_type::ptr socket_con_ptr
Type of a shared pointer to the socket connection component.
connection_hdl get_handle() const
Get the connection handle.
Asio based endpoint transport component.
std::size_t run_one()
wraps the run_one method of the internal io_service object
void stop_listening(lib::error_code &ec)
Stop listening (exception free)
config::concurrency_type concurrency_type
Type of the concurrency policy.
asio::connection< config > transport_con_type
void async_connect(transport_con_ptr tcon, uri_ptr u, connect_handler cb)
Initiate a new connection.
void init_asio()
Initialize asio transport with internal io_service.
void init_logging(const lib::shared_ptr< alog_type > &a, const lib::shared_ptr< elog_type > &e)
Initialize logging.
bool is_secure() const
Return whether or not the endpoint produces secure connections.
void init_asio(io_service_ptr ptr)
initialize asio transport with external io_service
lib::asio::ip::tcp::endpoint get_local_endpoint(lib::asio::error_code &ec)
Get local TCP endpoint.
socket_type::socket_con_type socket_con_type
Type of the socket connection component.
void set_reuse_addr(bool value)
Sets whether to use the SO_REUSEADDR flag when opening listening sockets.
void set_tcp_init_handler(tcp_init_handler h)
Sets the tcp pre init handler (deprecated)
void handle_timer(timer_ptr, timer_handler callback, lib::asio::error_code const &ec)
Timer handler.
void start_perpetual()
Marks the endpoint as perpetual, stopping it from exiting when empty.
void stop()
wraps the stop method of the internal io_service object
std::size_t run()
wraps the run method of the internal io_service object
config::socket_type socket_type
Type of the socket policy.
socket_con_type::ptr socket_con_ptr
Type of a shared pointer to the socket connection component.
config::elog_type elog_type
Type of the error logging policy.
transport_con_type::ptr transport_con_ptr
void set_tcp_post_init_handler(tcp_init_handler h)
Sets the tcp post init handler.
void set_listen_backlog(int backlog)
Sets the maximum length of the queue of pending connections.
bool stopped() const
wraps the stopped method of the internal io_service object
timer_ptr set_timer(long duration, timer_handler callback)
Call back a function after a period of time.
void init_asio(io_service_ptr ptr, lib::error_code &ec)
initialize asio transport with external io_service (exception free)
lib::error_code init(transport_con_ptr tcon)
Initialize a connection.
void init_asio(lib::error_code &ec)
Initialize asio transport with internal io_service (exception free)
void async_accept(transport_con_ptr tcon, accept_handler callback)
Accept the next connection attempt and assign it to con.
void listen(uint16_t port)
Set up endpoint for listening on a port.
lib::shared_ptr< lib::asio::steady_timer > timer_ptr
Type of timer handle.
lib::asio::io_service & get_io_service()
Retrieve a reference to the endpoint's io_service.
std::size_t poll()
wraps the poll method of the internal io_service object
void stop_perpetual()
Clears the endpoint's perpetual flag, allowing it to exit when empty.
endpoint< config > type
Type of this endpoint transport component.
lib::shared_ptr< lib::asio::ip::tcp::resolver > resolver_ptr
Type of a shared pointer to the resolver being used.
void listen(lib::asio::ip::tcp::endpoint const &ep)
Set up endpoint for listening manually.
void handle_resolve_timeout(timer_ptr, connect_handler callback, lib::error_code const &ec)
DNS resolution timeout handler.
void listen(lib::asio::ip::tcp::endpoint const &ep, lib::error_code &ec)
Set up endpoint for listening manually (exception free)
lib::function< lib::error_code(acceptor_ptr)> tcp_pre_bind_handler
Type of socket pre-bind handler.
lib::shared_ptr< lib::asio::io_service::work > work_ptr
Type of a shared pointer to an io_service work object.
void reset()
wraps the reset method of the internal io_service object
void set_tcp_pre_bind_handler(tcp_pre_bind_handler h)
Sets the tcp pre bind handler.
void listen(InternetProtocol const &internet_protocol, uint16_t port)
Set up endpoint for listening with protocol and port.
lib::asio::io_service * io_service_ptr
Type of a pointer to the ASIO io_service being used.
void set_tcp_pre_init_handler(tcp_init_handler h)
Sets the tcp pre init handler.
lib::shared_ptr< lib::asio::ip::tcp::acceptor > acceptor_ptr
Type of a shared pointer to the acceptor being used.
void handle_connect_timeout(transport_con_ptr tcon, timer_ptr, connect_handler callback, lib::error_code const &ec)
Asio connect timeout handler.
void async_accept(transport_con_ptr tcon, accept_handler callback, lib::error_code &ec)
Accept the next connection attempt and assign it to con (exception free)
std::size_t poll_one()
wraps the poll_one method of the internal io_service object
void listen(InternetProtocol const &internet_protocol, uint16_t port, lib::error_code &ec)
Set up endpoint for listening with protocol and port (exception free)
void listen(uint16_t port, lib::error_code &ec)
Set up endpoint for listening on a port (exception free)
config::alog_type alog_type
Type of the access logging policy.
bool is_listening() const
Check if the endpoint is listening.
void stop_listening()
Stop listening.
Asio transport error category.
Error category related to asio transport socket policies.
connection_hdl get_handle() const
Get the connection handle.
lib::error_code dispatch(dispatch_handler handler)
Call given handler back within the transport's event system (if present)
void set_uri(uri_ptr)
Set uri hook.
config::concurrency_type concurrency_type
transport concurrency policy
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.
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)
config::elog_type elog_type
Type of this transport's error logging policy.
lib::shared_ptr< type > ptr
Type of a shared pointer to this connection transport component.
config::alog_type alog_type
Type of this transport's access logging policy.
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)
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.
connection< config > type
Type of this connection transport component.
transport_con_type::ptr transport_con_ptr
void set_write_handler(write_handler h)
Sets the write handler.
config::concurrency_type concurrency_type
Type of this endpoint's concurrency policy.
void set_shutdown_handler(shutdown_handler h)
Sets the shutdown handler.
bool is_secure() const
Tests whether or not the underlying transport is secure.
void async_connect(transport_con_ptr, uri_ptr, connect_handler cb)
Initiate a new connection.
config::alog_type alog_type
Type of this endpoint's access logging policy.
lib::error_code init(transport_con_ptr tcon)
Initialize a connection.
void init_logging(lib::shared_ptr< alog_type > a, lib::shared_ptr< elog_type > e)
Initialize logging.
endpoint type
Type of this endpoint transport component.
iostream::connection< config > transport_con_type
void register_ostream(std::ostream *o)
Register a default output stream.
void set_secure(bool value)
Set whether or not endpoint can create secure connections.
config::elog_type elog_type
Type of this endpoint's error logging policy.
lib::shared_ptr< type > ptr
Type of a pointer to this endpoint transport component.
iostream transport error category
std::string get_query() const
Return the query portion.
Provides streaming UTF8 validation functionality.
bool decode(iterator_type begin, iterator_type end)
Advance validator state with input from an iterator pair.
validator()
Construct and initialize the validator.
bool complete()
Return whether the input sequence ended on a valid utf8 codepoint.
void reset()
Reset the validator to decode another message.
bool consume(uint8_t byte)
Advance the state of the validator with the next input byte.
#define _WEBSOCKETPP_CONSTEXPR_TOKEN_
#define _WEBSOCKETPP_NOEXCEPT_TOKEN_
A package of types and methods for manipulating WebSocket close status'.
static value const service_restart
static value const message_too_big
An endpoint received a message too large to process.
static value const try_again_later
static value const force_tcp_drop
Close the connection with a forced TCP drop.
static value const tls_handshake
An endpoint failed to perform a TLS handshake.
static value const rsv_end
Last value in range reserved for future protocol use.
static value const invalid_payload
An endpoint received message data inconsistent with its type.
bool terminal(value code)
Determine if the code represents an unrecoverable error.
static value const protocol_error
A protocol error occurred.
std::string get_string(value code)
Return a human readable interpretation of a WebSocket close code.
static value const bad_gateway
static value const invalid_subprotocol_data
A invalid subprotocol data.
static value const invalid_high
Last value in range that is always invalid on the wire.
static value const unsupported_data
static value const no_status
A dummy value to indicate that no status code was received.
static value const omit_handshake
Close the connection without a WebSocket close handshake.
static value const normal
static value const blank
A blank value for internal use.
static value const invalid_low
First value in range that is always invalid on the wire.
static value const abnormal_close
A dummy value to indicate that the connection was closed abnormally.
static value const rsv_start
First value in range reserved for future protocol use.
uint16_t value
The type of a close code value.
static value const policy_violation
An endpoint received a message that violated its policy.
static value const extension_required
A client expected the server to accept a required extension request.
bool invalid(value code)
Test whether a close code is invalid on the wire.
static value const internal_endpoint_error
static value const subprotocol_error
A generic subprotocol error.
bool reserved(value code)
Test whether a close code is in a reserved range.
static value const going_away
A package of types and methods for manipulating WebSocket close codes.
Concurrency handling support.
Library level error codes.
@ general
Catch-all library error.
@ unrequested_subprotocol
Selected subprotocol was not requested by the client.
@ invalid_port
Invalid port in URI.
@ client_only
Attempted to use a client specific feature on a server endpoint.
@ http_connection_ended
HTTP connection ended.
@ async_accept_not_listening
@ operation_canceled
The requested operation was canceled.
@ no_outgoing_buffers
The endpoint is out of outgoing message buffers.
@ http_parse_error
HTTP parse error.
@ reserved_close_code
Close code is in a reserved range.
@ con_creation_failed
Connection creation attempted failed.
@ no_incoming_buffers
The endpoint is out of incoming message buffers.
@ invalid_state
The connection was in the wrong state for this operation.
@ extension_neg_failed
Extension negotiation failed.
@ rejected
Connection rejected.
@ unsupported_version
Unsupported WebSocket protocol version.
@ invalid_utf8
Invalid UTF-8.
@ invalid_close_code
Close code is invalid.
@ server_only
Attempted to use a server specific feature on a client endpoint.
@ endpoint_not_secure
Attempted to open a secure connection with an insecure endpoint.
@ close_handshake_timeout
WebSocket close handshake timed out.
@ invalid_subprotocol
Invalid subprotocol.
@ bad_close_code
Unable to parse close code.
@ open_handshake_timeout
WebSocket opening handshake timed out.
@ invalid_version
Invalid WebSocket protocol version.
@ send_queue_full
send attempted when endpoint write queue was full
@ test
Unit testing utility error code.
@ invalid_uri
An invalid uri was supplied.
Implementation of RFC 7692, the permessage-deflate WebSocket extension.
Constants related to frame and payload limits.
static uint8_t const close_reason_size
Maximum size of close frame reason.
static uint64_t const payload_size_jumbo
Maximum size of a jumbo WebSocket payload (basic payload = 127)
static unsigned int const max_extended_header_length
Maximum length of the variable portion of the WebSocket header.
static unsigned int const max_header_length
Maximum length of a WebSocket header.
static uint16_t const payload_size_extended
Maximum size of an extended WebSocket payload (basic payload = 126)
static uint8_t const payload_size_basic
Maximum size of a basic WebSocket payload.
static unsigned int const basic_header_length
Minimum length of a WebSocket frame header.
Constants and utility functions related to WebSocket opcodes.
bool invalid(value v)
Check if an opcode is invalid.
bool reserved(value v)
Check if an opcode is reserved.
bool is_control(value v)
Check if an opcode is for a control frame.
Data structures and utility functions for manipulating WebSocket frames.
unsigned int get_masking_key_offset(basic_header const &)
Calculate the offset location of the masking key within the extended header.
void set_rsv2(basic_header &h, bool value)
Set the frame's RSV2 bit.
static unsigned int const MAX_HEADER_LENGTH
Maximum length of a WebSocket header.
opcode::value get_opcode(basic_header const &h)
Extract opcode from basic header.
void set_rsv3(basic_header &h, bool value)
Set the frame's RSV3 bit.
uint64_t get_payload_size(basic_header const &, extended_header const &)
Extract the full payload size field from a WebSocket header.
uint8_t get_basic_size(basic_header const &)
Extracts the raw payload length specified in the basic header.
size_t byte_mask_circ(uint8_t *input, uint8_t *output, size_t length, size_t prepared_key)
Circular byte aligned mask/unmask.
void byte_mask(input_iter b, input_iter e, output_iter o, masking_key_type const &key, size_t key_offset=0)
Byte by byte mask/unmask.
static unsigned int const MAX_EXTENDED_HEADER_LENGTH
Maximum length of the variable portion of the WebSocket header.
bool get_rsv3(basic_header const &h)
check whether the frame's RSV3 bit is set
bool get_masked(basic_header const &h)
check whether the frame is masked
bool get_rsv2(basic_header const &h)
check whether the frame's RSV2 bit is set
void byte_mask(iter_type b, iter_type e, masking_key_type const &key, size_t key_offset=0)
Byte by byte mask/unmask (in place)
uint16_t get_extended_size(extended_header const &)
Extract the extended size field from an extended header.
size_t byte_mask_circ(uint8_t *data, size_t length, size_t prepared_key)
Circular byte aligned mask/unmask (in place)
bool get_fin(basic_header const &h)
Check whether the frame's FIN bit is set.
size_t circshift_prepared_key(size_t prepared_key, size_t offset)
circularly shifts the supplied prepared masking key by offset bytes
bool get_rsv1(basic_header const &h)
check whether the frame's RSV1 bit is set
void set_masked(basic_header &h, bool value)
Set the frame's MASK bit.
size_t word_mask_circ(uint8_t *input, uint8_t *output, size_t length, size_t prepared_key)
Circular word aligned mask/unmask.
void word_mask_exact(uint8_t *data, size_t length, masking_key_type const &key)
Exact word aligned mask/unmask (in place)
void set_rsv1(basic_header &h, bool value)
Set the frame's RSV1 bit.
size_t get_header_len(basic_header const &)
Calculates the full length of the header based on the first bytes.
void set_fin(basic_header &h, bool value)
Set the frame's FIN bit.
uint64_t get_jumbo_size(extended_header const &)
Extract the jumbo size field from an extended header.
void word_mask_exact(uint8_t *input, uint8_t *output, size_t length, masking_key_type const &key)
Exact word aligned mask/unmask.
std::string prepare_header(const basic_header &h, const extended_header &e)
Generate a properly sized contiguous string that encodes a full frame header.
masking_key_type get_masking_key(basic_header const &, extended_header const &)
Extract the masking key from a frame header.
static unsigned int const BASIC_HEADER_LENGTH
Minimum length of a WebSocket frame header.
size_t word_mask_circ(uint8_t *data, size_t length, size_t prepared_key)
Circular word aligned mask/unmask (in place)
size_t prepare_masking_key(masking_key_type const &key)
Extract a masking key into a value the size of a machine word.
size_t const max_body_size
Default Maximum size in bytes for HTTP message bodies.
static char const header_separator[]
Literal value of the HTTP header separator.
std::vector< std::pair< std::string, attribute_list > > parameter_list
The type of an HTTP parameter list.
size_t const istream_buffer
Number of bytes to use for temporary istream read buffers.
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.
static char const header_delimiter[]
Literal value of the HTTP header delimiter.
bool is_whitespace_char(unsigned char c)
Is the character whitespace.
static char const header_token[]
invalid HTTP token characters
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.
bool is_token_char(unsigned char c)
Is the character a token.
static std::string const empty_header
Literal value of an empty header.
Constants related to processing WebSocket connections.
Processor class related error codes.
Error code category and codes used by all processor types.
lib::error_category const & get_processor_category()
Get a reference to a static copy of the processor error category.
close::status::value to_ws(lib::error_code ec)
Converts a processor error_code into a websocket close code.
@ missing_required_header
Missing Required Header.
@ control_too_big
Control frame too large.
@ invalid_http_method
Invalid HTTP method.
@ invalid_rsv_bit
Illegal use of reserved bit.
@ reason_requires_code
Using a reason requires a close code.
@ invalid_close_code
Invalid close code used.
@ masking_required
Clients may not send unmasked frames.
@ protocol_violation
Processor encountered a protocol violation in an incoming message.
@ extensions_disabled
Extension related operation was ignored because extensions are disabled.
@ reserved_close_code
Reserved close code used.
@ extension_parse_error
Error parsing extensions.
@ masking_forbidden
Servers may not send masked frames.
@ not_implemented
Operation required not implemented functionality.
@ invalid_opcode
Opcode was invalid for requested operation.
@ sha1_library
Embedded SHA-1 library error.
@ requires_64bit
Not supported on 32 bit systems.
@ subprotocol_parse_error
Error parsing subprotocols.
@ bad_request
Error was the result of improperly formatted user input.
@ invalid_utf8
Invalid UTF-8 encoding.
@ invalid_http_status
Invalid HTTP status.
@ invalid_payload
Processor encountered invalid payload data.
@ invalid_http_version
Invalid HTTP version.
@ message_too_big
Processor encountered a message that was too large.
@ no_protocol_support
No support for this feature in this protocol version.
@ invalid_arguments
The processor method was called with invalid arguments.
@ invalid_continuation
Continuation without message.
@ non_minimal_encoding
Payload length not minimally encoded.
@ fragmented_control
Fragmented control message.
lib::error_code make_error_code(error::processor_errors e)
Create an error code with the given value and the processor category.
Processors encapsulate the protocol rules specific to each WebSocket version.
int get_websocket_version(request_type &r)
Extract the version from a WebSocket handshake request.
bool is_websocket_handshake(request_type &r)
Determine whether or not a generic HTTP request is a WebSocket handshake.
Stub RNG policy that always returns 0.
Random number generation policies.
lib::function< void(connection_hdl, lib::asio::ip::tcp::socket &)> socket_init_handler
The signature of the socket init handler for this socket policy.
lib::error_category const & get_category()
Get a reference to a static copy of the asio transport error category.
lib::error_code make_error_code(error::value e)
Create an error code with the given value and the asio transport category.
@ proxy_invalid
Invalid Proxy URI.
@ pass_through
there was an error in the underlying transport library
@ proxy_failed
The connection to the requested proxy server failed.
@ invalid_num_bytes
async_read_at_least call requested more bytes than buffer can store
@ invalid_host_service
Invalid host or service.
Errors related to asio transport sockets.
@ missing_tls_init_handler
Required tls_init handler not present.
@ invalid_state
A function was called in a state that it was illegal to do so.
@ tls_failed_sni_hostname
Failed to set TLS SNI hostname.
@ tls_handshake_failed
TLS Handshake Failed.
@ tls_handshake_timeout
TLS Handshake Timeout.
@ pass_through
pass_through from underlying library
Transport policy that uses asio.
Generic transport related errors.
@ pass_through
underlying transport pass through
@ operation_not_supported
Operation not supported.
@ operation_aborted
Operation aborted.
@ tls_error
Other TLS error.
@ 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
@ invalid_num_bytes
async_read_at_least call requested more bytes than buffer can store
@ double_read
async_read called while another async_read was in progress
lib::error_code make_error_code(error::value e)
Get an error code with the given value and the iostream transport category.
lib::error_category const & get_category()
Get a reference to a static copy of the iostream transport error category.
Transport policy that uses STL iostream for I/O and does not support timers.
lib::function< lib::error_code(connection_hdl, std::vector< transport::buffer > const &bufs)> vector_write_handler
lib::function< lib::error_code(connection_hdl)> shutdown_handler
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.
Transport policies provide network connectivity and timers.
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.
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.
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.
Generic non-websocket specific utility functions and data structures.
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.
lib::function< void(connection_hdl, std::string)> pong_handler
The type and function signature of a pong handler.
lib::function< void(connection_hdl)> close_handler
The type and function signature of a close handler.
lib::function< void(connection_hdl, std::string)> pong_timeout_handler
The type and function signature of a pong timeout handler.
lib::function< void(connection_hdl)> http_handler
The type and function signature of a http handler.
lib::function< void(connection_hdl)> open_handler
The type and function signature of an open handler.
lib::function< void(connection_hdl)> interrupt_handler
The type and function signature of an interrupt handler.
static uint16_t const uri_default_secure_port
Default port for wss://.
lib::function< void(connection_hdl)> fail_handler
The type and function signature of a fail handler.
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
static uint16_t const uri_default_port
Default port for ws://.
lib::function< bool(connection_hdl, std::string)> ping_handler
The type and function signature of a ping handler.
static char const user_agent[]
Default user agent string.
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.
std::pair< lib::error_code, std::string > err_str_pair
Combination error code / string type for returning two values.
lib::function< bool(connection_hdl)> validate_handler
The type and function signature of a validate handler.
static bool is_base64(unsigned char c)
Test whether a character is a valid base64 character.
std::string base64_encode(unsigned char const *input, size_t len)
Encode a char buffer into a base64 string.
Server config with asio transport and TLS disabled.
Extension specific settings:
static const uint8_t minimum_outgoing_window_bits
static const bool allow_disabling_context_takeover
static const long timeout_socket_shutdown
Length of time to wait for socket shutdown.
static const long timeout_connect
Length of time to wait for TCP connect.
static const long timeout_dns_resolve
Length of time to wait for dns resolution.
static const long timeout_proxy
Length of time to wait before a proxy handshake is aborted.
static const long timeout_socket_pre_init
Default timer values (in ms)
static bool const enable_multithreading
static const long timeout_socket_post_init
Length of time to wait for socket post-initialization.
Server config with iostream transport.
websocketpp::random::none::int_generator< uint32_t > rng_type
RNG policies.
static const websocketpp::log::level elog_level
Default static error logging channels.
websocketpp::transport::iostream::endpoint< transport_config > transport_type
Transport Endpoint Component.
static const size_t max_http_body_size
Default maximum http body size.
static const long timeout_open_handshake
Default timer values (in ms)
static const size_t max_message_size
Default maximum message size.
websocketpp::log::basic< concurrency_type, websocketpp::log::elevel > elog_type
Logging policies.
static const bool drop_on_protocol_error
Drop connections immediately on protocol error.
static const long timeout_close_handshake
Length of time before a closing handshake is aborted.
static const websocketpp::log::level alog_level
Default static access logging channels.
static const long timeout_pong
Length of time to wait for a pong after a ping.
static const bool silent_close
Suppresses the return of detailed connection close information.
static bool const enable_multithreading
static const size_t connection_read_buffer_size
Size of the per-connection read buffer.
static const bool enable_extensions
Global flag for enabling/disabling extensions.
static const int client_version
WebSocket Protocol version to use as a client.
Package of log levels for logging access events.
static char const * channel_name(level channel)
Get the textual name of a channel given a channel id.
static level const fail
One line for each failed WebSocket connection with details.
static level const none
Special aggregate value representing "no levels".
static level const debug_handshake
Extra information about opening handshakes.
static level const devel
Development messages (warning: very chatty)
static level const all
Special aggregate value representing "all levels".
static level const debug_close
Extra information about closing handshakes.
static level const frame_payload
One line per frame, includes the full message payload (warning: chatty)
static level const connect
Information about new connections.
static level const app
Special channel for application specific logs. Not used by the library.
static level const frame_header
One line per frame, includes the full frame header.
static level const message_payload
Reserved.
static level const endpoint
Reserved.
static level const message_header
Reserved.
static level const control
One line per control frame.
static level const disconnect
One line for each closed connection. Includes closing codes and reasons.
static level const access_core
static level const http
Access related to HTTP requests.
Package of values for hinting at the nature of a given logger.
static value const none
No information.
uint32_t value
Type of a channel type hint value.
static value const access
Access log.
static value const error
Error log.
Package of log levels for logging errors.
static level const devel
Low level debugging information (warning: very chatty)
static char const * channel_name(level channel)
Get the textual name of a channel given a channel id.
static level const library
static level const all
Special aggregate value representing "all levels".
static level const none
Special aggregate value representing "no levels".
static level const rerror
A simple utility buffer class.
Helper less than functor for case insensitive find.
Helper functor for case insensitive find.
bool operator()(charT ch1, charT ch2)
Perform a case insensitive comparison.
my_equal(std::locale const &loc)
Construct the functor with the given locale.
#define _WEBSOCKETPP_ERROR_CODE_ENUM_NS_END_
#define _WEBSOCKETPP_ERROR_CODE_ENUM_NS_START_
Type used to convert close statuses between integer and wire representations.
Two byte conversion union.
Four byte conversion union.
Eight byte conversion union.