WebSocket++  0.8.3-dev
C++ websocket client/server library
Public Types | Public Member Functions | Protected Attributes | List of all members
websocketpp::processor::processor< config > Class Template Referenceabstract

WebSocket protocol processor abstract base class. More...

#include <processor.hpp>

Inheritance diagram for websocketpp::processor::processor< config >:
websocketpp::processor::hybi00< config > websocketpp::processor::hybi13< config > websocketpp::processor::hybi08< config > websocketpp::processor::hybi07< config >

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 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.
 
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
 

Detailed Description

template<typename config>
class websocketpp::processor::processor< config >

WebSocket protocol processor abstract base class.

Definition at line 160 of file processor.hpp.

Member Function Documentation

◆ client_handshake_request()

template<typename config >
virtual lib::error_code websocketpp::processor::processor< config >::client_handshake_request ( request_type &  req,
uri_ptr  uri,
std::vector< std::string > const &  subprotocols 
) const
pure virtual

Fill in an HTTP request for an outgoing connection handshake.

Parameters
reqThe request to process.
Returns
An error code, 0 on success, non-zero for other errors

Implemented in websocketpp::processor::hybi13< config >, websocketpp::processor::hybi00< config >, websocketpp::processor::hybi08< config >, and websocketpp::processor::hybi07< config >.

◆ consume()

template<typename config >
virtual size_t websocketpp::processor::processor< config >::consume ( uint8_t *  buf,
size_t  len,
lib::error_code &  ec 
)
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.

Parameters
bufBuffer from which bytes should be read.
lenLength of buffer
ecReference to an error code to return any errors in
Returns
Number of bytes processed

Implemented in websocketpp::processor::hybi13< config >, and websocketpp::processor::hybi00< config >.

◆ extract_subprotocols()

template<typename config >
virtual lib::error_code websocketpp::processor::processor< config >::extract_subprotocols ( const request_type &  req,
std::vector< std::string > &  subprotocol_list 
)
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.

Parameters
[in]reqThe request to extract from
[out]subprotocol_listA reference to a vector of strings to store the results in.

Implemented in websocketpp::processor::hybi13< config >, and websocketpp::processor::hybi00< config >.

◆ get_bytes_needed()

template<typename config >
virtual size_t websocketpp::processor::processor< config >::get_bytes_needed ( ) const
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 349 of file processor.hpp.

◆ get_max_message_size()

template<typename config >
size_t websocketpp::processor::processor< config >::get_max_message_size ( ) const
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

Since
0.3.0

Definition at line 188 of file processor.hpp.

◆ get_message()

template<typename config >
virtual message_ptr websocketpp::processor::processor< config >::get_message ( )
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.

Returns
A pointer to the most recently processed message or a null shared pointer.

Implemented in websocketpp::processor::hybi13< config >, and websocketpp::processor::hybi00< config >.

◆ has_permessage_compress()

template<typename config >
virtual bool websocketpp::processor::processor< config >::has_permessage_compress ( ) const
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.

◆ negotiate_extensions() [1/2]

template<typename config >
virtual err_str_pair websocketpp::processor::processor< config >::negotiate_extensions ( request_type const &  )
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.

Parameters
requestThe request or response headers to look at.

Reimplemented in websocketpp::processor::hybi13< config >.

Definition at line 225 of file processor.hpp.

◆ negotiate_extensions() [2/2]

template<typename config >
virtual err_str_pair websocketpp::processor::processor< config >::negotiate_extensions ( response_type const &  )
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.

Parameters
responseThe request or response headers to look at.

Reimplemented in websocketpp::processor::hybi13< config >.

Definition at line 239 of file processor.hpp.

◆ prepare_close()

template<typename config >
virtual lib::error_code websocketpp::processor::processor< config >::prepare_close ( close::status::value  code,
std::string const &  reason,
message_ptr  out 
) const
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.

Parameters
codeThe close code to send
reasonThe reason string to send
outThe message buffer to prepare the fame in
Returns
Status code, zero on success, non-zero on failure

◆ prepare_data_frame()

template<typename config >
virtual lib::error_code websocketpp::processor::processor< config >::prepare_data_frame ( message_ptr  in,
message_ptr  out 
)
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

◆ prepare_ping()

template<typename config >
virtual lib::error_code websocketpp::processor::processor< config >::prepare_ping ( std::string const &  in,
message_ptr  out 
) const
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.

Parameters
inThe string to use for the ping payload
outThe message buffer to prepare the ping in.
Returns
Status code, zero on success, non-zero on failure

◆ prepare_pong()

template<typename config >
virtual lib::error_code websocketpp::processor::processor< config >::prepare_pong ( std::string const &  in,
message_ptr  out 
) const
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.

Parameters
inThe string to use for the pong payload
outThe message buffer to prepare the pong in.
Returns
Status code, zero on success, non-zero on failure

◆ process_handshake()

template<typename config >
virtual lib::error_code websocketpp::processor::processor< config >::process_handshake ( request_type const &  req,
std::string const &  subprotocol,
response_type &  res 
) const
pure virtual

Calculate the appropriate response for this websocket request.

Parameters
reqThe request to process
subprotocolThe subprotocol in use
resThe response to store the processed response in
Returns
An error code, 0 on success, non-zero for other errors

Implemented in websocketpp::processor::hybi13< config >, and websocketpp::processor::hybi00< config >.

◆ ready()

template<typename config >
virtual bool websocketpp::processor::processor< config >::ready ( ) const
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.

Returns
Whether or not a message is ready.

Implemented in websocketpp::processor::hybi13< config >, and websocketpp::processor::hybi00< config >.

◆ set_max_message_size()

template<typename config >
void websocketpp::processor::processor< config >::set_max_message_size ( size_t  new_value)
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

Since
0.3.0
Parameters
new_valueThe value to set as the maximum message size.

Definition at line 203 of file processor.hpp.

◆ validate_handshake()

template<typename config >
virtual lib::error_code websocketpp::processor::processor< config >::validate_handshake ( request_type const &  request) const
pure virtual

validate a WebSocket handshake request for this version

Parameters
requestThe WebSocket handshake request to validate. is_websocket_handshake(request) must be true and get_websocket_version(request) must equal this->get_version().
Returns
A status code, 0 on success, non-zero for specific sorts of failure

Implemented in websocketpp::processor::hybi13< config >, and websocketpp::processor::hybi00< config >.

◆ validate_server_handshake_response()

template<typename config >
virtual lib::error_code websocketpp::processor::processor< config >::validate_server_handshake_response ( request_type const &  req,
response_type &  res 
) const
pure virtual

Validate the server's response to an outgoing handshake request.

Parameters
reqThe original request sent
resThe reponse to generate
Returns
An error code, 0 on success, non-zero for other errors

Implemented in websocketpp::processor::hybi13< config >, and websocketpp::processor::hybi00< config >.


The documentation for this class was generated from the following file: