WebSocket protocol processor abstract base class. More...
#include <processor.hpp>
Public Types | |
typedef processor< config > | type |
typedef config::request_type | request_type |
typedef config::response_type | response_type |
typedef config::message_type::ptr | message_ptr |
typedef std::pair< lib::error_code, std::string > | err_str_pair |
Public Member Functions | |
processor (bool secure, bool p_is_server) | |
virtual | ~processor () |
virtual int | get_version () const =0 |
Get the protocol version of this processor. More... | |
size_t | get_max_message_size () const |
Get maximum message size. More... | |
void | set_max_message_size (size_t new_value) |
Set maximum message size. More... | |
virtual bool | has_permessage_compress () const |
Returns whether or not the permessage_compress extension is implemented. More... | |
virtual err_str_pair | negotiate_extensions (request_type const &) |
Initializes extensions based on the Sec-WebSocket-Extensions header. More... | |
virtual err_str_pair | negotiate_extensions (response_type const &) |
Initializes extensions based on the Sec-WebSocket-Extensions header. More... | |
virtual lib::error_code | validate_handshake (request_type const &request) const =0 |
validate a WebSocket handshake request for this version More... | |
virtual lib::error_code | process_handshake (request_type const &req, std::string const &subprotocol, response_type &res) const =0 |
Calculate the appropriate response for this websocket request. More... | |
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. More... | |
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. More... | |
virtual std::string | get_raw (response_type const &request) const =0 |
Given a completed response, get the raw bytes to put on the wire. More... | |
virtual std::string const & | get_origin (request_type const &request) const =0 |
Return the value of the header containing the CORS origin. More... | |
virtual lib::error_code | extract_subprotocols (const request_type &req, std::vector< std::string > &subprotocol_list)=0 |
Extracts requested subprotocols from a handshake request. More... | |
virtual uri_ptr | get_uri (request_type const &request) const =0 |
Extracts client uri from a handshake request. More... | |
virtual size_t | consume (uint8_t *buf, size_t len, lib::error_code &ec)=0 |
process new websocket connection bytes More... | |
virtual bool | ready () const =0 |
Checks if there is a message ready. More... | |
virtual message_ptr | get_message ()=0 |
Retrieves the most recently processed message. More... | |
virtual bool | get_error () const =0 |
Tests whether the processor is in a fatal error state. More... | |
virtual size_t | get_bytes_needed () const |
Retrieves the number of bytes presently needed by the processor This value may be used as a hint to the transport layer as to how many bytes to wait for before running consume again. More... | |
virtual lib::error_code | prepare_data_frame (message_ptr in, message_ptr out)=0 |
Prepare a data message for writing. More... | |
virtual lib::error_code | prepare_ping (std::string const &in, message_ptr out) const =0 |
Prepare a ping frame. More... | |
virtual lib::error_code | prepare_pong (std::string const &in, message_ptr out) const =0 |
Prepare a pong frame. More... | |
virtual lib::error_code | prepare_close (close::status::value code, std::string const &reason, message_ptr out) const =0 |
Prepare a close frame. More... | |
Protected Attributes | |
bool const | m_secure |
bool const | m_server |
size_t | m_max_message_size |
WebSocket protocol processor abstract base class.
Definition at line 160 of file processor.hpp.
typedef processor<config> websocketpp::processor::processor< config >::type |
Definition at line 162 of file processor.hpp.
typedef config::request_type websocketpp::processor::processor< config >::request_type |
Definition at line 163 of file processor.hpp.
typedef config::response_type websocketpp::processor::processor< config >::response_type |
Definition at line 164 of file processor.hpp.
typedef config::message_type::ptr websocketpp::processor::processor< config >::message_ptr |
Definition at line 165 of file processor.hpp.
typedef std::pair<lib::error_code,std::string> websocketpp::processor::processor< config >::err_str_pair |
Definition at line 166 of file processor.hpp.
|
inlineexplicit |
Definition at line 168 of file processor.hpp.
|
inlinevirtual |
Definition at line 174 of file processor.hpp.
|
pure virtual |
Get the protocol version of this processor.
Implemented in websocketpp::processor::hybi13< config >, websocketpp::processor::hybi13< stub_config_ext >, websocketpp::processor::hybi13< stub_config >, websocketpp::processor::hybi00< config >, websocketpp::processor::hybi00< stub_config >, websocketpp::processor::hybi08< config >, and websocketpp::processor::hybi07< config >.
Referenced by websocketpp::processor::processor< stub_config >::~processor().
|
inline |
Get maximum message size.
Get maximum message size. Maximum message size determines the point at which the processor will fail a connection with the message_too_big protocol error.
The default is retrieved from the max_message_size value from the template config
Definition at line 188 of file processor.hpp.
|
inline |
Set maximum message size.
Set maximum message size. Maximum message size determines the point at which the processor will fail a connection with the message_too_big protocol error.
The default is retrieved from the max_message_size value from the template config
new_value | The value to set as the maximum message size. |
Definition at line 203 of file processor.hpp.
Referenced by BOOST_AUTO_TEST_CASE().
|
inlinevirtual |
Returns whether or not the permessage_compress extension is implemented.
Compile time flag that indicates whether this processor has implemented the permessage_compress extension. By default this is false.
Definition at line 212 of file processor.hpp.
|
inlinevirtual |
Initializes extensions based on the Sec-WebSocket-Extensions header.
Reads the Sec-WebSocket-Extensions header and determines if any of the requested extensions are supported by this processor. If they are their settings data is initialized and an extension string to send to the is returned.
request | The request or response headers to look at. |
Reimplemented in websocketpp::processor::hybi13< config >, websocketpp::processor::hybi13< stub_config_ext >, and websocketpp::processor::hybi13< stub_config >.
Definition at line 225 of file processor.hpp.
Referenced by BOOST_AUTO_TEST_CASE().
|
inlinevirtual |
Initializes extensions based on the Sec-WebSocket-Extensions header.
Reads the Sec-WebSocket-Extensions header and determines if any of the requested extensions were accepted by the server. If they are their settings data is initialized. If they are not a list of required extensions (if any) is returned. This list may be sent back to the server as a part of the 1010/Extension required close code.
response | The request or response headers to look at. |
Reimplemented in websocketpp::processor::hybi13< config >, websocketpp::processor::hybi13< stub_config_ext >, and websocketpp::processor::hybi13< stub_config >.
Definition at line 239 of file processor.hpp.
|
pure virtual |
validate a WebSocket handshake request for this version
request | The WebSocket handshake request to validate. is_websocket_handshake(request) must be true and get_websocket_version(request) must equal this->get_version(). |
Implemented in websocketpp::processor::hybi13< config >, websocketpp::processor::hybi13< stub_config_ext >, websocketpp::processor::hybi13< stub_config >, websocketpp::processor::hybi00< config >, and websocketpp::processor::hybi00< stub_config >.
Referenced by websocketpp::processor::processor< stub_config >::negotiate_extensions().
|
pure virtual |
Calculate the appropriate response for this websocket request.
req | The request to process |
subprotocol | The subprotocol in use |
res | The response to store the processed response in |
Implemented in websocketpp::processor::hybi13< config >, websocketpp::processor::hybi13< stub_config_ext >, websocketpp::processor::hybi13< stub_config >, websocketpp::processor::hybi00< config >, and websocketpp::processor::hybi00< stub_config >.
Referenced by websocketpp::processor::processor< stub_config >::negotiate_extensions().
|
pure virtual |
Fill in an HTTP request for an outgoing connection handshake.
req | The request to process. |
Implemented in websocketpp::processor::hybi13< config >, websocketpp::processor::hybi13< stub_config_ext >, websocketpp::processor::hybi13< stub_config >, websocketpp::processor::hybi00< config >, websocketpp::processor::hybi00< stub_config >, websocketpp::processor::hybi08< config >, and websocketpp::processor::hybi07< config >.
Referenced by websocketpp::processor::processor< stub_config >::negotiate_extensions().
|
pure virtual |
Validate the server's response to an outgoing handshake request.
req | The original request sent |
res | The reponse to generate |
Implemented in websocketpp::processor::hybi13< config >, websocketpp::processor::hybi13< stub_config_ext >, websocketpp::processor::hybi13< stub_config >, websocketpp::processor::hybi00< config >, and websocketpp::processor::hybi00< stub_config >.
Referenced by websocketpp::processor::processor< stub_config >::negotiate_extensions().
|
pure virtual |
Given a completed response, get the raw bytes to put on the wire.
Implemented in websocketpp::processor::hybi13< config >, websocketpp::processor::hybi13< stub_config_ext >, websocketpp::processor::hybi13< stub_config >, websocketpp::processor::hybi00< config >, and websocketpp::processor::hybi00< stub_config >.
Referenced by websocketpp::processor::processor< stub_config >::negotiate_extensions().
|
pure virtual |
Return the value of the header containing the CORS origin.
Implemented in websocketpp::processor::hybi13< config >, websocketpp::processor::hybi13< stub_config_ext >, websocketpp::processor::hybi13< stub_config >, websocketpp::processor::hybi00< config >, websocketpp::processor::hybi00< stub_config >, and websocketpp::processor::hybi08< config >.
Referenced by websocketpp::processor::processor< stub_config >::negotiate_extensions().
|
pure virtual |
Extracts requested subprotocols from a handshake request.
Extracts a list of all subprotocols that the client has requested in the given opening handshake request.
[in] | req | The request to extract from |
[out] | subprotocol_list | A reference to a vector of strings to store the results in. |
Implemented in websocketpp::processor::hybi13< config >, websocketpp::processor::hybi13< stub_config_ext >, websocketpp::processor::hybi13< stub_config >, websocketpp::processor::hybi00< config >, and websocketpp::processor::hybi00< stub_config >.
Referenced by websocketpp::processor::processor< stub_config >::negotiate_extensions().
|
pure virtual |
Extracts client uri from a handshake request.
Implemented in websocketpp::processor::hybi13< config >, websocketpp::processor::hybi13< stub_config_ext >, websocketpp::processor::hybi13< stub_config >, websocketpp::processor::hybi00< config >, and websocketpp::processor::hybi00< stub_config >.
Referenced by websocketpp::processor::processor< stub_config >::negotiate_extensions().
|
pure virtual |
process new websocket connection bytes
WebSocket connections are a continous stream of bytes that must be interpreted by a protocol processor into discrete frames.
buf | Buffer from which bytes should be read. |
len | Length of buffer |
ec | Reference to an error code to return any errors in |
Implemented in websocketpp::processor::hybi13< config >, websocketpp::processor::hybi13< stub_config_ext >, websocketpp::processor::hybi13< stub_config >, websocketpp::processor::hybi00< config >, and websocketpp::processor::hybi00< stub_config >.
Referenced by websocketpp::processor::processor< stub_config >::negotiate_extensions().
|
pure virtual |
Checks if there is a message ready.
Checks if the most recent consume operation processed enough bytes to complete a new WebSocket message. The message can be retrieved by calling get_message() which will reset the internal state to not-ready and allow consume to read more bytes.
Implemented in websocketpp::processor::hybi13< config >, websocketpp::processor::hybi13< stub_config_ext >, websocketpp::processor::hybi13< stub_config >, websocketpp::processor::hybi00< config >, and websocketpp::processor::hybi00< stub_config >.
Referenced by websocketpp::processor::processor< stub_config >::negotiate_extensions().
|
pure virtual |
Retrieves the most recently processed message.
Retrieves a shared pointer to the recently completed message if there is one. If ready() returns true then there is a message available. Retrieving the message with get_message will reset the state of ready. As such, each new message may be retrieved only once. Calling get_message when there is no message available will result in a null pointer being returned.
Implemented in websocketpp::processor::hybi13< config >, websocketpp::processor::hybi13< stub_config_ext >, websocketpp::processor::hybi13< stub_config >, websocketpp::processor::hybi00< config >, and websocketpp::processor::hybi00< stub_config >.
Referenced by websocketpp::processor::processor< stub_config >::negotiate_extensions().
|
pure virtual |
Tests whether the processor is in a fatal error state.
Implemented in websocketpp::processor::hybi13< config >, websocketpp::processor::hybi13< stub_config_ext >, websocketpp::processor::hybi13< stub_config >, websocketpp::processor::hybi00< config >, and websocketpp::processor::hybi00< stub_config >.
Referenced by websocketpp::processor::processor< stub_config >::negotiate_extensions().
|
inlinevirtual |
Retrieves the number of bytes presently needed by the processor This value may be used as a hint to the transport layer as to how many bytes to wait for before running consume again.
Reimplemented in websocketpp::processor::hybi13< config >, websocketpp::processor::hybi13< stub_config_ext >, and websocketpp::processor::hybi13< stub_config >.
Definition at line 349 of file processor.hpp.
|
pure virtual |
Prepare a data message for writing.
Performs validation, masking, compression, etc. will return an error if there was an error, otherwise msg will be ready to be written
Implemented in websocketpp::processor::hybi13< config >, and websocketpp::processor::hybi00< config >.
Referenced by websocketpp::processor::processor< stub_config >::get_bytes_needed().
|
pure virtual |
Prepare a ping frame.
Ping preparation is entirely state free. There is no payload validation other than length. Payload need not be UTF-8.
in | The string to use for the ping payload |
out | The message buffer to prepare the ping in. |
Implemented in websocketpp::processor::hybi13< config >, and websocketpp::processor::hybi00< config >.
Referenced by websocketpp::processor::processor< stub_config >::get_bytes_needed().
|
pure virtual |
Prepare a pong frame.
Pong preparation is entirely state free. There is no payload validation other than length. Payload need not be UTF-8.
in | The string to use for the pong payload |
out | The message buffer to prepare the pong in. |
Implemented in websocketpp::processor::hybi13< config >, and websocketpp::processor::hybi00< config >.
Referenced by websocketpp::processor::processor< stub_config >::get_bytes_needed().
|
pure virtual |
Prepare a close frame.
Close preparation is entirely state free. The code and reason are both subject to validation. Reason must be valid UTF-8. Code must be a valid un-reserved WebSocket close code. Use close::status::no_status to indicate no code. If no code is supplied a reason may not be specified.
code | The close code to send |
reason | The reason string to send |
out | The message buffer to prepare the fame in |
Implemented in websocketpp::processor::hybi13< config >, and websocketpp::processor::hybi00< config >.
Referenced by websocketpp::processor::processor< stub_config >::get_bytes_needed().
|
protected |
Definition at line 399 of file processor.hpp.
Referenced by websocketpp::processor::hybi00< stub_config >::get_uri(), and websocketpp::processor::hybi13< stub_config >::get_uri().
|
protected |
Definition at line 400 of file processor.hpp.
Referenced by websocketpp::processor::hybi13< stub_config >::consume(), websocketpp::processor::hybi13< stub_config >::negotiate_extensions_helper(), websocketpp::processor::hybi13< stub_config >::prepare_control(), and websocketpp::processor::hybi13< stub_config >::prepare_data_frame().
|
protected |