Loading...
Searching...
No Matches
websocketpp::processor::processor< config > Class Template Referenceabstract

WebSocket protocol processor abstract base class. More...

`#include <processor.hpp>`

Inheritance diagram for websocketpp::processor::processor< 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.
void | set_max_message_size (size_t new_value)
| Set maximum message size.
virtual bool | has_permessage_compress () const
| Returns whether or not the permessage_compress extension is implemented.
virtual err_str_pair | negotiate_extensions (request_type const &)
| Initializes extensions based on the Sec-WebSocket-Extensions header.
virtual err_str_pair | negotiate_extensions (response_type const &)
| Initializes extensions based on the Sec-WebSocket-Extensions header.
virtual lib::error_code | validate_handshake (request_type const &request) const =0
| validate a WebSocket handshake request for this version
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.
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 | validate_server_handshake_response (request_type const &req, response_type &res) const =0
| Validate the server's response to an outgoing handshake request.
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.
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
virtual bool | ready () const =0
| Checks if there is a message ready.
virtual message_ptr | get_message ()=0
| Retrieves the most recently processed message.
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.
virtual lib::error_code | prepare_ping (std::string const &in, message_ptr out) const =0
| Prepare a ping frame.
virtual lib::error_code | prepare_pong (std::string const &in, message_ptr out) const =0
| Prepare a pong frame.
virtual lib::error_code | prepare_close (close::status::value code, std::string const &reason, message_ptr out) const =0
| Prepare a close frame.

## 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 Typedef Documentation

## err_str_pair

template<typename config>

typedef std::pair<lib::error_code,std::string> websocketpp::processor::processor< config >::err_str_pair

Definition at line 166 of file processor.hpp.

## message_ptr

template<typename config>

typedef config::message_type::ptr websocketpp::processor::processor< config >::message_ptr

Definition at line 165 of file processor.hpp.

## request_type

template<typename config>

typedef config::request_type websocketpp::processor::processor< config >::request_type

Definition at line 163 of file processor.hpp.

## response_type

template<typename config>

typedef config::response_type websocketpp::processor::processor< config >::response_type

Definition at line 164 of file processor.hpp.

## type

template<typename config>

typedef processor<config> websocketpp::processor::processor< config >::type

Definition at line 162 of file processor.hpp.

## Constructor & Destructor Documentation

## processor()

template<typename config>

websocketpp::processor::processor< config >::processor | ( | bool | secure,
|  | bool | p_is_server )

inline explicit

Definition at line 168 of file processor.hpp.

## ~processor()

template<typename config>

virtual websocketpp::processor::processor< config >::~processor | ( |  | ) |

inline virtual

Definition at line 174 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

  req | The request to process.

Returns
  An error code, 0 on success, non-zero for other errors

Implemented in websocketpp::processor::hybi00< config >, websocketpp::processor::hybi07< config >, websocketpp::processor::hybi08< config >, and websocketpp::processor::hybi13< 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

  buf | Buffer from which bytes should be read.
  len | Length of buffer
  ec | Reference to an error code to return any errors in

Returns
  Number of bytes processed

Implemented in websocketpp::processor::hybi00< config >, and websocketpp::processor::hybi13< 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] | 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::hybi00< config >, and websocketpp::processor::hybi13< config >.

## get_bytes_needed()

template<typename config>

virtual size_t websocketpp::processor::processor< config >::get_bytes_needed | ( |  | ) | const

inline virtual

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_error()

template<typename config>

virtual bool websocketpp::processor::processor< config >::get_error | ( |  | ) | const

pure virtual

Tests whether the processor is in a fatal error state.

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

## 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::hybi00< config >, and websocketpp::processor::hybi13< config >.

## get_origin()

template<typename config>

virtual std::string const & websocketpp::processor::processor< config >::get_origin | ( | request_type const & | request | ) | const

pure virtual

Return the value of the header containing the CORS origin.

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

## get_raw()

template<typename config>

virtual std::string websocketpp::processor::processor< config >::get_raw | ( | response_type const & | request | ) | const

pure virtual

Given a completed response, get the raw bytes to put on the wire.

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

## get_uri()

template<typename config>

virtual uri_ptr websocketpp::processor::processor< config >::get_uri | ( | request_type const & | request | ) | const

pure virtual

Extracts client uri from a handshake request.

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

## get_version()

template<typename config>

virtual int websocketpp::processor::processor< config >::get_version | ( |  | ) | const

pure virtual

Get the protocol version of this processor.

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

## has_permessage_compress()

template<typename config>

virtual bool websocketpp::processor::processor< config >::has_permessage_compress | ( |  | ) | const

inline virtual

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 & |  | ) |

inline virtual

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

  request | The 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 & |  | ) |

inline virtual

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

  response | The 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

  code | The close code to send
  reason | The reason string to send
  out | The 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

  in | The string to use for the ping payload
  out | The 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

  in | The string to use for the pong payload
  out | The 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

  req | The request to process
  subprotocol | The subprotocol in use
  res | The response to store the processed response in

Returns
  An error code, 0 on success, non-zero for other errors

Implemented in websocketpp::processor::hybi00< config >, and websocketpp::processor::hybi13< 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::hybi00< config >, and websocketpp::processor::hybi13< 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_value | The 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

  request | The 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::hybi00< config >, and websocketpp::processor::hybi13< 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

  req | The original request sent
  res | The reponse to generate

Returns
  An error code, 0 on success, non-zero for other errors

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

## Member Data Documentation

## m_max_message_size

template<typename config>

size_t websocketpp::processor::processor< config >::m_max_message_size

protected

Definition at line 401 of file processor.hpp.

## m_secure

template<typename config>

bool const websocketpp::processor::processor< config >::m_secure

protected

Definition at line 399 of file processor.hpp.

## m_server

template<typename config>

bool const websocketpp::processor::processor< config >::m_server

protected

Definition at line 400 of file processor.hpp.

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

- websocketpp/processors/processor.hpp