|
WebSocket++ 0.8.4
C++ websocket client/server library
|
Processor for Hybi version 13 (RFC6455). More...
#include <hybi13.hpp>
Classes | |
| struct | msg_metadata |
Public Types | |
| typedef processor< config > | base |
| 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< 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 | |
| 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. | |
| bool | has_permessage_deflate () const |
| err_str_pair | negotiate_extensions (request_type const &request) |
| Initializes extensions based on the Sec-WebSocket-Extensions header. | |
| err_str_pair | negotiate_extensions (response_type const &response) |
| Initializes extensions based on the Sec-WebSocket-Extensions header. | |
| template<typename header_type> | |
| err_str_pair | negotiate_extensions_helper (header_type const &header) |
| Extension negotiation helper function. | |
| lib::error_code | validate_handshake (request_type const &r) const |
| validate a WebSocket handshake request for this version | |
| 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. | |
| 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. | |
| 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. | |
| std::string | get_raw (response_type const &res) const |
| Given a completed response, get the raw bytes to put on the wire. | |
| std::string const & | get_origin (request_type const &r) const |
| Return the value of the header containing the CORS origin. | |
| lib::error_code | extract_subprotocols (request_type const &req, std::vector< std::string > &subprotocol_list) |
| Extracts requested subprotocols from a handshake request. | |
| uri_ptr | get_uri (request_type const &request) const |
| Extracts client uri from a handshake request. | |
| size_t | consume (uint8_t *buf, size_t len, lib::error_code &ec) |
| Process new websocket connection bytes. | |
| lib::error_code | finalize_message () |
| Perform any finalization actions on an incoming message. | |
| void | reset_headers () |
| void | handle_max_message_size_changed (size_t new_value) |
| Propagate maximum message size changes to the permessage-deflate extension. | |
| bool | ready () const |
| Test whether or not the processor has a message ready. | |
| message_ptr | get_message () |
| Retrieves the most recently processed message. | |
| bool | get_error () const |
| Test whether or not the processor is in a fatal error state. | |
| size_t | get_bytes_needed () const |
| virtual lib::error_code | prepare_data_frame (message_ptr in, message_ptr out) |
| Prepare a user data message for writing. | |
| lib::error_code | prepare_ping (std::string const &in, message_ptr out) const |
| Get URI. | |
| lib::error_code | prepare_pong (std::string const &in, message_ptr out) const |
| virtual lib::error_code | prepare_close (close::status::value code, std::string const &reason, message_ptr out) const |
| Public Member Functions inherited from websocketpp::processor::processor< config > | |
| processor (bool secure, bool p_is_server) | |
| 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 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 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. | |
| size_t | copy_basic_header_bytes (uint8_t const *buf, size_t len) |
| Reads bytes from buf into m_basic_header. | |
| size_t | copy_extended_header_bytes (uint8_t const *buf, size_t len) |
| Reads bytes from buf into m_extended_header. | |
| size_t | process_payload_bytes (uint8_t *buf, size_t len, lib::error_code &ec) |
| Reads bytes from buf into message payload. | |
| lib::error_code | validate_incoming_basic_header (frame::basic_header const &h, bool is_server, bool new_msg) const |
| Validate an incoming basic header. | |
| lib::error_code | validate_incoming_extended_header (frame::basic_header h, frame::extended_header e) const |
| Validate an incoming extended header. | |
| void | masked_copy (std::string const &i, std::string &o, frame::masking_key_type key) const |
| Copy and mask/unmask in one operation. | |
| 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. | |
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_metadata * | m_current_msg |
| frame::extended_header | m_extended_header |
| rng_type & | m_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 |
Processor for Hybi version 13 (RFC6455).
Definition at line 54 of file hybi13.hpp.
| typedef processor<config> websocketpp::processor::hybi13< config >::base |
Definition at line 56 of file hybi13.hpp.
| typedef std::pair<lib::error_code,std::string> websocketpp::processor::hybi13< config >::err_str_pair |
Definition at line 70 of file hybi13.hpp.
| typedef message_type::ptr websocketpp::processor::hybi13< config >::message_ptr |
Definition at line 62 of file hybi13.hpp.
| typedef config::message_type websocketpp::processor::hybi13< config >::message_type |
Definition at line 61 of file hybi13.hpp.
| typedef msg_manager_type::ptr websocketpp::processor::hybi13< config >::msg_manager_ptr |
Definition at line 65 of file hybi13.hpp.
| typedef config::con_msg_manager_type websocketpp::processor::hybi13< config >::msg_manager_type |
Definition at line 64 of file hybi13.hpp.
| typedef config::permessage_deflate_type websocketpp::processor::hybi13< config >::permessage_deflate_type |
Definition at line 68 of file hybi13.hpp.
| typedef config::request_type websocketpp::processor::hybi13< config >::request_type |
Definition at line 58 of file hybi13.hpp.
| typedef config::response_type websocketpp::processor::hybi13< config >::response_type |
Definition at line 59 of file hybi13.hpp.
| typedef config::rng_type websocketpp::processor::hybi13< config >::rng_type |
Definition at line 66 of file hybi13.hpp.
|
protected |
Definition at line 1043 of file hybi13.hpp.
|
inlineexplicit |
Definition at line 72 of file hybi13.hpp.
|
inlinevirtual |
Fill in a set of request headers for a client connection request.
| [out] | req | Set of headers to fill in |
| [in] | uri | The uri being connected to |
| [in] | subprotocols | The list of subprotocols to request |
Implements websocketpp::processor::processor< config >.
Definition at line 238 of file hybi13.hpp.
|
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
| buf | Input buffer |
| len | Length of input buffer |
Implements websocketpp::processor::processor< config >.
Definition at line 383 of file hybi13.hpp.
|
inlineprotected |
Reads bytes from buf into m_basic_header.
Definition at line 762 of file hybi13.hpp.
|
inlineprotected |
Reads bytes from buf into m_extended_header.
Definition at line 794 of file hybi13.hpp.
|
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.
| [in] | req | The request to extract from |
| [out] | subprotocol_list | A reference to a vector of strings to store the results in. |
Implements websocketpp::processor::processor< config >.
Definition at line 333 of file hybi13.hpp.
|
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.
Definition at line 519 of file hybi13.hpp.
|
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 608 of file hybi13.hpp.
|
inlinevirtual |
Test whether or not the processor is in a fatal error state.
Implements websocketpp::processor::processor< config >.
Definition at line 604 of file hybi13.hpp.
|
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.
Implements websocketpp::processor::processor< config >.
Definition at line 585 of file hybi13.hpp.
|
inlinevirtual |
Return the value of the header containing the CORS origin.
Implements websocketpp::processor::processor< config >.
Definition at line 329 of file hybi13.hpp.
|
inlinevirtual |
Given a completed response, get the raw bytes to put on the wire.
Implements websocketpp::processor::processor< config >.
Definition at line 325 of file hybi13.hpp.
|
inlinevirtual |
Extracts client uri from a handshake request.
Implements websocketpp::processor::processor< config >.
Definition at line 352 of file hybi13.hpp.
|
inlinevirtual |
Get the protocol version of this processor.
Implements websocketpp::processor::processor< config >.
Definition at line 81 of file hybi13.hpp.
|
inlinevirtual |
Propagate maximum message size changes to the permessage-deflate extension.
Overrides the base hook so that calls to set_max_message_size on the processor reach the permessage-deflate extension, which uses the limit to bound decompressed message size.
| new_value | The new maximum message size, in bytes |
Reimplemented from websocketpp::processor::processor< config >.
Definition at line 576 of file hybi13.hpp.
|
inline |
Definition at line 85 of file hybi13.hpp.
|
inlineprotected |
Copy and mask/unmask in one operation.
Reads input from one string and writes unmasked output to another.
| [in] | i | The input string. |
| [out] | o | The output string. |
| [in] | key | The masking key to use for masking/unmasking |
Definition at line 985 of file hybi13.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 from websocketpp::processor::processor< config >.
Definition at line 89 of file hybi13.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 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 from websocketpp::processor::processor< config >.
Definition at line 93 of file hybi13.hpp.
|
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 103 of file hybi13.hpp.
|
inlinevirtual |
Definition at line 714 of file hybi13.hpp.
|
inlineprotected |
Generic prepare control frame with opcode and payload.
Internal control frame building method. Handles validation, masking, etc
| op | The control opcode to use |
| payload | The payload to use |
| out | The message buffer to store the prepared frame in |
Definition at line 1001 of file hybi13.hpp.
|
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
| in | An unprepared message to prepare |
| out | A message to be overwritten with the prepared message |
Definition at line 623 of file hybi13.hpp.
|
inline |
Get URI.
Definition at line 706 of file hybi13.hpp.
|
inline |
Definition at line 710 of file hybi13.hpp.
|
inlinevirtual |
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 |
Implements websocketpp::processor::processor< config >.
Definition at line 210 of file hybi13.hpp.
|
inlineprotected |
Convert a client handshake key into a server response key in place.
Definition at line 751 of file hybi13.hpp.
|
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.
| buf | Input/working buffer |
| len | Length of buf |
Definition at line 817 of file hybi13.hpp.
|
inlinevirtual |
Test whether or not the processor has a message ready.
Implements websocketpp::processor::processor< config >.
Definition at line 581 of file hybi13.hpp.
|
inline |
Definition at line 552 of file hybi13.hpp.
|
inlinevirtual |
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(). |
Implements websocketpp::processor::processor< config >.
Definition at line 186 of file hybi13.hpp.
|
inlineprotected |
Validate an incoming basic header.
Validates an incoming hybi13 basic header.
| h | The basic header to validate |
| is_server | Whether or not the endpoint that received this frame is a server. |
| new_msg | Whether or not this is the first frame of the message |
Definition at line 872 of file hybi13.hpp.
|
inlineprotected |
Validate an incoming extended header.
Validates an incoming hybi13 full header.
| h | The basic header to validate |
| e | The extended header to validate |
Definition at line 950 of file hybi13.hpp.
|
inlinevirtual |
Validate the server's response to an outgoing handshake request.
| req | The original request sent |
| res | The reponse to generate |
Implements websocketpp::processor::processor< config >.
Definition at line 288 of file hybi13.hpp.
|
protected |
Definition at line 1068 of file hybi13.hpp.
|
protected |
Definition at line 1074 of file hybi13.hpp.
|
protected |
Definition at line 1082 of file hybi13.hpp.
|
protected |
Definition at line 1085 of file hybi13.hpp.
|
protected |
Definition at line 1077 of file hybi13.hpp.
|
protected |
Definition at line 1080 of file hybi13.hpp.
|
protected |
Definition at line 1088 of file hybi13.hpp.
|
protected |
Definition at line 1071 of file hybi13.hpp.
|
protected |
Definition at line 1096 of file hybi13.hpp.
|
protected |
Definition at line 1090 of file hybi13.hpp.
|
protected |
Definition at line 1093 of file hybi13.hpp.