NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
websocketpp::processor::hybi13< config > Class Template Reference

Processor for Hybi version 13 (RFC6455) More...

#include <hybi13.hpp>

Inheritance diagram for websocketpp::processor::hybi13< config >:
Collaboration diagram for websocketpp::processor::hybi13< config >:

Classes

struct  msg_metadata
 This data structure holds data related to processing a message, such as the buffer it is being written to, its masking key, its UTF8 validation state, and sometimes its compression state. More...
 

Public Types

typedef processor< configbase
 
typedef config::request_type request_type
 
typedef config::response_type response_type
 
typedef config::message_type message_type
 
typedef message_type::ptr message_ptr
 
typedef config::con_msg_manager_type msg_manager_type
 
typedef msg_manager_type::ptr msg_manager_ptr
 
typedef config::rng_type rng_type
 
typedef config::permessage_deflate_type permessage_deflate_type
 
typedef std::pair< lib::error_code, std::string > err_str_pair
 
- Public Types inherited from websocketpp::processor::processor< config >
typedef processor< configtype
 
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

 hybi13 (bool secure, bool p_is_server, msg_manager_ptr manager, rng_type &rng)
 
int get_version () const
 Get the protocol version of this processor. More...
 
bool has_permessage_deflate () const
 
err_str_pair negotiate_extensions (request_type const &request)
 Initializes extensions based on the Sec-WebSocket-Extensions header. More...
 
err_str_pair negotiate_extensions (response_type const &response)
 Initializes extensions based on the Sec-WebSocket-Extensions header. More...
 
template<typename header_type >
err_str_pair negotiate_extensions_helper (header_type const &header)
 Extension negotiation helper function. More...
 
lib::error_code validate_handshake (request_type const &r) const
 validate a WebSocket handshake request for this version More...
 
lib::error_code process_handshake (request_type const &request, std::string const &subprotocol, response_type &response) const
 Calculate the appropriate response for this websocket request. More...
 
lib::error_code client_handshake_request (request_type &req, uri_ptr uri, std::vector< std::string > const &subprotocols) const
 Fill in a set of request headers for a client connection request. More...
 
lib::error_code validate_server_handshake_response (request_type const &req, response_type &res) const
 Validate the server's response to an outgoing handshake request. More...
 
std::string get_raw (response_type const &res) const
 Given a completed response, get the raw bytes to put on the wire. More...
 
std::string const & get_origin (request_type const &r) const
 Return the value of the header containing the CORS origin. More...
 
lib::error_code extract_subprotocols (request_type const &req, std::vector< std::string > &subprotocol_list)
 Extracts requested subprotocols from a handshake request. More...
 
uri_ptr get_uri (request_type const &request) const
 Extracts client uri from a handshake request. More...
 
size_t consume (uint8_t *buf, size_t len, lib::error_code &ec)
 Process new websocket connection bytes. More...
 
lib::error_code finalize_message ()
 Perform any finalization actions on an incoming message. More...
 
void reset_headers ()
 
bool ready () const
 Test whether or not the processor has a message ready. More...
 
message_ptr get_message ()
 Retrieves the most recently processed message. More...
 
bool get_error () const
 Test whether or not the processor is in a fatal error state. More...
 
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)
 Prepare a user data message for writing. More...
 
lib::error_code prepare_ping (std::string const &in, message_ptr out) const
 Get URI. More...
 
lib::error_code prepare_pong (std::string const &in, message_ptr out) const
 Prepare a pong frame. More...
 
virtual lib::error_code prepare_close (close::status::value code, std::string const &reason, message_ptr out) const
 Prepare a close frame. More...
 
- Public Member Functions inherited from websocketpp::processor::processor< config >
 processor (bool secure, bool p_is_server)
 
virtual ~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...
 

Protected Types

enum  state {
  HEADER_BASIC = 0, HEADER_EXTENDED = 1, EXTENSION = 2, APPLICATION = 3,
  READY = 4, FATAL_ERROR = 5
}
 

Protected Member Functions

lib::error_code process_handshake_key (std::string &key) const
 Convert a client handshake key into a server response key in place. More...
 
size_t copy_basic_header_bytes (uint8_t const *buf, size_t len)
 Reads bytes from buf into m_basic_header. More...
 
size_t copy_extended_header_bytes (uint8_t const *buf, size_t len)
 Reads bytes from buf into m_extended_header. More...
 
size_t process_payload_bytes (uint8_t *buf, size_t len, lib::error_code &ec)
 Reads bytes from buf into message payload. More...
 
lib::error_code validate_incoming_basic_header (frame::basic_header const &h, bool is_server, bool new_msg) const
 Validate an incoming basic header. More...
 
lib::error_code validate_incoming_extended_header (frame::basic_header h, frame::extended_header e) const
 Validate an incoming extended header. More...
 
void masked_copy (std::string const &i, std::string &o, frame::masking_key_type key) const
 Copy and mask/unmask in one operation. More...
 
lib::error_code prepare_control (frame::opcode::value op, std::string const &payload, message_ptr out) const
 Generic prepare control frame with opcode and payload. More...
 

Protected Attributes

frame::basic_header m_basic_header
 
msg_manager_ptr m_msg_manager
 
size_t m_bytes_needed
 
size_t m_cursor
 
msg_metadata m_data_msg
 
msg_metadata m_control_msg
 
msg_metadatam_current_msg
 
frame::extended_header m_extended_header
 
rng_typem_rng
 
state m_state
 
permessage_deflate_type m_permessage_deflate
 
- Protected Attributes inherited from websocketpp::processor::processor< config >
bool const m_secure
 
bool const m_server
 
size_t m_max_message_size
 

Detailed Description

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

Processor for Hybi version 13 (RFC6455)

Definition at line 54 of file hybi13.hpp.

Member Typedef Documentation

◆ base

template<typename config>
typedef processor<config> websocketpp::processor::hybi13< config >::base

Definition at line 56 of file hybi13.hpp.

◆ request_type

Definition at line 58 of file hybi13.hpp.

◆ response_type

Definition at line 59 of file hybi13.hpp.

◆ message_type

Definition at line 61 of file hybi13.hpp.

◆ message_ptr

template<typename config>
typedef message_type::ptr websocketpp::processor::hybi13< config >::message_ptr

Definition at line 62 of file hybi13.hpp.

◆ msg_manager_type

Definition at line 64 of file hybi13.hpp.

◆ msg_manager_ptr

Definition at line 65 of file hybi13.hpp.

◆ rng_type

template<typename config>
typedef config::rng_type websocketpp::processor::hybi13< config >::rng_type

Definition at line 66 of file hybi13.hpp.

◆ permessage_deflate_type

template<typename config>
typedef config::permessage_deflate_type websocketpp::processor::hybi13< config >::permessage_deflate_type

Definition at line 68 of file hybi13.hpp.

◆ err_str_pair

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

Definition at line 70 of file hybi13.hpp.

Member Enumeration Documentation

◆ state

template<typename config>
enum websocketpp::processor::hybi13::state
protected
Enumerator
HEADER_BASIC 
HEADER_EXTENDED 
EXTENSION 
APPLICATION 
READY 
FATAL_ERROR 

Definition at line 1019 of file hybi13.hpp.

Constructor & Destructor Documentation

◆ hybi13()

template<typename config>
websocketpp::processor::hybi13< config >::hybi13 ( bool  secure,
bool  p_is_server,
msg_manager_ptr  manager,
rng_type rng 
)
inlineexplicit

Definition at line 72 of file hybi13.hpp.

Member Function Documentation

◆ get_version()

template<typename config>
int websocketpp::processor::hybi13< config >::get_version ( ) const
inlinevirtual

Get the protocol version of this processor.

Implements websocketpp::processor::processor< config >.

Definition at line 80 of file hybi13.hpp.

◆ has_permessage_deflate()

template<typename config>
bool websocketpp::processor::hybi13< config >::has_permessage_deflate ( ) const
inline

Definition at line 84 of file hybi13.hpp.

◆ negotiate_extensions() [1/2]

template<typename config>
err_str_pair websocketpp::processor::hybi13< 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 from websocketpp::processor::processor< config >.

Definition at line 88 of file hybi13.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ negotiate_extensions() [2/2]

template<typename config>
err_str_pair websocketpp::processor::hybi13< 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 from websocketpp::processor::processor< config >.

Definition at line 92 of file hybi13.hpp.

◆ negotiate_extensions_helper()

template<typename config>
template<typename header_type >
err_str_pair websocketpp::processor::hybi13< config >::negotiate_extensions_helper ( header_type const &  header)
inline

Extension negotiation helper function.

This exists mostly because the code for requests and responses is identical and I can't have virtual template methods.

Definition at line 102 of file hybi13.hpp.

Referenced by websocketpp::processor::hybi13< stub_config >::negotiate_extensions().

◆ validate_handshake()

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

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

Implements websocketpp::processor::processor< config >.

Definition at line 185 of file hybi13.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ process_handshake()

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

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

Implements websocketpp::processor::processor< config >.

Definition at line 209 of file hybi13.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ client_handshake_request()

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

Fill in a set of request headers for a client connection request.

Parameters
[out]reqSet of headers to fill in
[in]uriThe uri being connected to
[in]subprotocolsThe list of subprotocols to request

Implements websocketpp::processor::processor< config >.

Definition at line 237 of file hybi13.hpp.

◆ validate_server_handshake_response()

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

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

Implements websocketpp::processor::processor< config >.

Definition at line 287 of file hybi13.hpp.

◆ get_raw()

template<typename config>
std::string websocketpp::processor::hybi13< config >::get_raw ( response_type const &  request) const
inlinevirtual

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

Implements websocketpp::processor::processor< config >.

Definition at line 324 of file hybi13.hpp.

◆ get_origin()

template<typename config>
std::string const& websocketpp::processor::hybi13< config >::get_origin ( request_type const &  request) const
inlinevirtual

Return the value of the header containing the CORS origin.

Implements websocketpp::processor::processor< config >.

Definition at line 328 of file hybi13.hpp.

◆ extract_subprotocols()

template<typename config>
lib::error_code websocketpp::processor::hybi13< config >::extract_subprotocols ( request_type const &  req,
std::vector< std::string > &  subprotocol_list 
)
inlinevirtual

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.

Implements websocketpp::processor::processor< config >.

Definition at line 332 of file hybi13.hpp.

◆ get_uri()

template<typename config>
uri_ptr websocketpp::processor::hybi13< config >::get_uri ( request_type const &  request) const
inlinevirtual

Extracts client uri from a handshake request.

Implements websocketpp::processor::processor< config >.

Definition at line 351 of file hybi13.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ consume()

template<typename config>
size_t websocketpp::processor::hybi13< config >::consume ( uint8_t *  buf,
size_t  len,
lib::error_code &  ec 
)
inlinevirtual

Process new websocket connection bytes.

Hybi 13 data streams represent a series of variable length frames. Each frame is made up of a series of fixed length fields. The lengths of later fields are contained in earlier fields. The first field length is fixed by the spec.

This processor represents a state machine that keeps track of what field is presently being read and how many more bytes are needed to complete it

Read two header bytes Extract full frame length. Read extra header bytes Validate frame header (including extension validate) Read extension data into extension message state object Read payload data into payload

Parameters
bufInput buffer
lenLength of input buffer
Returns
Number of bytes processed or zero on error

Implements websocketpp::processor::processor< config >.

Definition at line 382 of file hybi13.hpp.

◆ finalize_message()

template<typename config>
lib::error_code websocketpp::processor::hybi13< config >::finalize_message ( )
inline

Perform any finalization actions on an incoming message.

Called after the full message is received. Provides the opportunity for extensions to complete any data post processing as well as final UTF8 validation checks for text messages.

Returns
A code indicating errors, if any

Definition at line 518 of file hybi13.hpp.

Referenced by websocketpp::processor::hybi13< stub_config >::consume().

◆ reset_headers()

◆ ready()

template<typename config>
bool websocketpp::processor::hybi13< config >::ready ( ) const
inlinevirtual

Test whether or not the processor has a message ready.

Implements websocketpp::processor::processor< config >.

Definition at line 563 of file hybi13.hpp.

Referenced by websocketpp::processor::hybi13< stub_config >::get_message().

◆ get_message()

template<typename config>
message_ptr websocketpp::processor::hybi13< config >::get_message ( )
inlinevirtual

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.

Implements websocketpp::processor::processor< config >.

Definition at line 567 of file hybi13.hpp.

◆ get_error()

template<typename config>
bool websocketpp::processor::hybi13< config >::get_error ( ) const
inlinevirtual

Test whether or not the processor is in a fatal error state.

Implements websocketpp::processor::processor< config >.

Definition at line 586 of file hybi13.hpp.

◆ get_bytes_needed()

template<typename config>
size_t websocketpp::processor::hybi13< 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 from websocketpp::processor::processor< config >.

Definition at line 590 of file hybi13.hpp.

◆ prepare_data_frame()

template<typename config>
virtual lib::error_code websocketpp::processor::hybi13< config >::prepare_data_frame ( message_ptr  in,
message_ptr  out 
)
inlinevirtual

Prepare a user 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

TODO: tests

Parameters
inAn unprepared message to prepare
outA message to be overwritten with the prepared message
Returns
error code

Implements websocketpp::processor::processor< config >.

Definition at line 605 of file hybi13.hpp.

◆ prepare_ping()

template<typename config>
lib::error_code websocketpp::processor::hybi13< config >::prepare_ping ( std::string const &  in,
message_ptr  out 
) const
inlinevirtual

Get URI.

Implements websocketpp::processor::processor< config >.

Definition at line 688 of file hybi13.hpp.

◆ prepare_pong()

template<typename config>
lib::error_code websocketpp::processor::hybi13< config >::prepare_pong ( std::string const &  in,
message_ptr  out 
) const
inlinevirtual

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

Implements websocketpp::processor::processor< config >.

Definition at line 692 of file hybi13.hpp.

◆ prepare_close()

template<typename config>
virtual lib::error_code websocketpp::processor::hybi13< config >::prepare_close ( close::status::value  code,
std::string const &  reason,
message_ptr  out 
) const
inlinevirtual

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

Implements websocketpp::processor::processor< config >.

Definition at line 696 of file hybi13.hpp.

◆ process_handshake_key()

template<typename config>
lib::error_code websocketpp::processor::hybi13< config >::process_handshake_key ( std::string &  key) const
inlineprotected

Convert a client handshake key into a server response key in place.

Definition at line 733 of file hybi13.hpp.

Referenced by websocketpp::processor::hybi13< stub_config >::process_handshake(), and websocketpp::processor::hybi13< stub_config >::validate_server_handshake_response().

◆ copy_basic_header_bytes()

template<typename config>
size_t websocketpp::processor::hybi13< config >::copy_basic_header_bytes ( uint8_t const *  buf,
size_t  len 
)
inlineprotected

Reads bytes from buf into m_basic_header.

Definition at line 744 of file hybi13.hpp.

Referenced by websocketpp::processor::hybi13< stub_config >::consume().

◆ copy_extended_header_bytes()

template<typename config>
size_t websocketpp::processor::hybi13< config >::copy_extended_header_bytes ( uint8_t const *  buf,
size_t  len 
)
inlineprotected

Reads bytes from buf into m_extended_header.

Definition at line 776 of file hybi13.hpp.

Referenced by websocketpp::processor::hybi13< stub_config >::consume().

◆ process_payload_bytes()

template<typename config>
size_t websocketpp::processor::hybi13< config >::process_payload_bytes ( uint8_t *  buf,
size_t  len,
lib::error_code &  ec 
)
inlineprotected

Reads bytes from buf into message payload.

This function performs unmasking and uncompression, validates the decoded bytes, and writes them to the appropriate message buffer.

This member function will use the input buffer as stratch space for its work. The raw input bytes will not be preserved. This applies only to the bytes actually needed. At most min(m_bytes_needed,len) will be processed.

Parameters
bufInput/working buffer
lenLength of buf
Returns
Number of bytes processed or zero in case of an error

Definition at line 799 of file hybi13.hpp.

Referenced by websocketpp::processor::hybi13< stub_config >::consume().

◆ validate_incoming_basic_header()

template<typename config>
lib::error_code websocketpp::processor::hybi13< config >::validate_incoming_basic_header ( frame::basic_header const &  h,
bool  is_server,
bool  new_msg 
) const
inlineprotected

Validate an incoming basic header.

Validates an incoming hybi13 basic header.

Parameters
hThe basic header to validate
is_serverWhether or not the endpoint that received this frame is a server.
new_msgWhether or not this is the first frame of the message
Returns
0 on success or a non-zero error code on failure

Definition at line 848 of file hybi13.hpp.

Referenced by websocketpp::processor::hybi13< stub_config >::consume().

◆ validate_incoming_extended_header()

template<typename config>
lib::error_code websocketpp::processor::hybi13< config >::validate_incoming_extended_header ( frame::basic_header  h,
frame::extended_header  e 
) const
inlineprotected

Validate an incoming extended header.

Validates an incoming hybi13 full header.

Todo:
unit test for the >32 bit frames on 32 bit systems case
Parameters
hThe basic header to validate
eThe extended header to validate
Returns
An error_code, non-zero values indicate why the validation failed

Definition at line 926 of file hybi13.hpp.

Referenced by websocketpp::processor::hybi13< stub_config >::consume().

◆ masked_copy()

template<typename config>
void websocketpp::processor::hybi13< config >::masked_copy ( std::string const &  i,
std::string &  o,
frame::masking_key_type  key 
) const
inlineprotected

Copy and mask/unmask in one operation.

Reads input from one string and writes unmasked output to another.

Parameters
[in]iThe input string.
[out]oThe output string.
[in]keyThe masking key to use for masking/unmasking

Definition at line 961 of file hybi13.hpp.

Referenced by websocketpp::processor::hybi13< stub_config >::prepare_control(), and websocketpp::processor::hybi13< stub_config >::prepare_data_frame().

◆ prepare_control()

template<typename config>
lib::error_code websocketpp::processor::hybi13< config >::prepare_control ( frame::opcode::value  op,
std::string const &  payload,
message_ptr  out 
) const
inlineprotected

Generic prepare control frame with opcode and payload.

Internal control frame building method. Handles validation, masking, etc

Parameters
opThe control opcode to use
payloadThe payload to use
outThe message buffer to store the prepared frame in
Returns
Status code, zero on success, non-zero on error

Definition at line 977 of file hybi13.hpp.

Referenced by websocketpp::processor::hybi13< stub_config >::prepare_close(), websocketpp::processor::hybi13< stub_config >::prepare_ping(), and websocketpp::processor::hybi13< stub_config >::prepare_pong().

Member Data Documentation

◆ m_basic_header

◆ m_msg_manager

template<typename config>
msg_manager_ptr websocketpp::processor::hybi13< config >::m_msg_manager
protected

Definition at line 1047 of file hybi13.hpp.

Referenced by websocketpp::processor::hybi13< stub_config >::consume().

◆ m_bytes_needed

◆ m_cursor

◆ m_data_msg

◆ m_control_msg

◆ m_current_msg

◆ m_extended_header

◆ m_rng

◆ m_state

◆ m_permessage_deflate


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