websocketpp
0.5.1
C++/Boost Asio based websocket client/server library
|
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 int | get_version () const =0 |
Get the protocol version of this processor. | |
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 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. | |
virtual std::string const & | get_origin (request_type const &request) const =0 |
Return the value of the header containing the CORS origin. | |
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. | |
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. | |
virtual size_t | get_bytes_needed () const |
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.
|
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::hybi00< config >, websocketpp::processor::hybi08< config >, and websocketpp::processor::hybi07< config >.
|
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 >, and websocketpp::processor::hybi00< config >.
|
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 >, and websocketpp::processor::hybi00< config >.
|
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 >.
Definition at line 334 of file processor.hpp.
|
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.
|
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 >, and websocketpp::processor::hybi00< config >.
|
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.
request | The request headers to look at. |
Reimplemented in websocketpp::processor::hybi13< config >.
Definition at line 224 of file processor.hpp.
|
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 |
|
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
|
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. |
|
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. |
|
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 >, and websocketpp::processor::hybi00< config >.
|
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 >, and websocketpp::processor::hybi00< config >.
|
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.
|
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 >, and websocketpp::processor::hybi00< config >.
|
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 >, and websocketpp::processor::hybi00< config >.