Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
websocketpp::processor Namespace Reference

Processors encapsulate the protocol rules specific to each WebSocket version. More...

Namespaces

namespace  constants
 Constants related to processing WebSocket connections.
 
namespace  error
 Error code category and codes used by all processor types.
 
namespace  error_cat
 Processor class related error codes.
 

Classes

class  hybi00
 Processor for Hybi Draft version 00. More...
 
class  hybi07
 Processor for Hybi Draft version 07. More...
 
class  hybi08
 Processor for Hybi Draft version 08. More...
 
class  hybi13
 Processor for Hybi version 13 (RFC6455) More...
 
class  processor
 WebSocket protocol processor abstract base class. More...
 

Functions

template<typename request_type >
bool is_websocket_handshake (request_type &r)
 Determine whether or not a generic HTTP request is a WebSocket handshake.
 
template<typename request_type >
int get_websocket_version (request_type &r)
 Extract the version from a WebSocket handshake request.
 
template<typename request_type >
uri_ptr get_uri_from_host (request_type &request, std::string scheme)
 Extract a URI ptr from the host header of the request.
 

Detailed Description

The processors namespace includes a number of free functions that operate on various WebSocket related data structures and perform processing that is not related to specific versions of the protocol.

It also includes the abstract interface for the protocol specific processing engines. These engines wrap all of the logic necessary for parsing and validating WebSocket handshakes and messages of specific protocol version and set of allowed extensions.

An instance of a processor represents the state of a single WebSocket connection of the associated version. One processor instance is needed per logical WebSocket connection.

Function Documentation

◆ get_uri_from_host()

template<typename request_type >
uri_ptr websocketpp::processor::get_uri_from_host ( request_type & request,
std::string scheme )
Parameters
requestThe request to extract the Host header from.
schemeThe scheme under which this request was received (ws, wss, http, https, etc)
Returns
A uri_pointer that encodes the value of the host header.

Definition at line 136 of file processor.hpp.

136 {
137 std::string h = request.get_header("Host");
138
139 size_t last_colon = h.rfind(":");
140 size_t last_sbrace = h.rfind("]");
141
142 // no : = hostname with no port
143 // last : before ] = ipv6 literal with no port
144 // : with no ] = hostname with port
145 // : after ] = ipv6 literal with port
146 if (last_colon == std::string::npos ||
147 (last_sbrace != std::string::npos && last_sbrace > last_colon))
148 {
149 return lib::make_shared<uri>(scheme, h, request.get_uri());
150 } else {
151 return lib::make_shared<uri>(scheme,
152 h.substr(0,last_colon),
153 h.substr(last_colon+1),
154 request.get_uri());
155 }
156}
Here is the caller graph for this function:

◆ get_websocket_version()

template<typename request_type >
int websocketpp::processor::get_websocket_version ( request_type & r)

A blank version header indicates a spec before versions were introduced. The only such versions in shipping products are Hixie Draft 75 and Hixie Draft 76. Draft 75 is present in Chrome 4-5 and Safari 5.0.0, Draft 76 (also known as hybi 00 is present in Chrome 6-13 and Safari 5.0.1+. As differentiating between these two sets of browsers is very difficult and Safari 5.0.1+ accounts for the vast majority of cases in the wild this function assumes that all handshakes without a valid version header are Hybi 00.

Parameters
rThe WebSocket handshake request to read.
Returns
The WebSocket handshake version or -1 if there was an extraction error.

Definition at line 107 of file processor.hpp.

107 {
108 if (!r.ready()) {
109 return -2;
110 }
111
112 if (r.get_header("Sec-WebSocket-Version").empty()) {
113 return 0;
114 }
115
116 int version;
117 std::istringstream ss(r.get_header("Sec-WebSocket-Version"));
118
119 if ((ss >> version).fail()) {
120 return -1;
121 }
122
123 return version;
124}
const mie::Vuint & r
Definition bn.cpp:28
Here is the caller graph for this function:

◆ is_websocket_handshake()

template<typename request_type >
bool websocketpp::processor::is_websocket_handshake ( request_type & r)
Parameters
rThe HTTP request to read.
Returns
True if the request is a WebSocket handshake, false otherwise

Definition at line 68 of file processor.hpp.

68 {
69 using utility::ci_find_substr;
70
71 std::string const & upgrade_header = r.get_header("Upgrade");
72
73 if (ci_find_substr(upgrade_header, constants::upgrade_token,
74 sizeof(constants::upgrade_token)-1) == upgrade_header.end())
75 {
76 return false;
77 }
78
79 std::string const & con_header = r.get_header("Connection");
80
81 if (ci_find_substr(con_header, constants::connection_token,
82 sizeof(constants::connection_token)-1) == con_header.end())
83 {
84 return false;
85 }
86
87 return true;
88}
Here is the call graph for this function:
Here is the caller graph for this function: