WebSocket++
0.8.3-dev
C++ websocket client/server library
|
28 #ifndef WEBSOCKETPP_PROCESSOR_HPP
29 #define WEBSOCKETPP_PROCESSOR_HPP
31 #include <websocketpp/processors/base.hpp>
32 #include <websocketpp/common/system_error.hpp>
34 #include <websocketpp/close.hpp>
35 #include <websocketpp/utilities.hpp>
36 #include <websocketpp/uri.hpp>
67 template <
typename request_type>
69 using utility::ci_find_substr;
71 std::string
const & upgrade_header = r.get_header(
"Upgrade");
73 if (ci_find_substr(upgrade_header, constants::upgrade_token,
74 sizeof(constants::upgrade_token)-1) == upgrade_header.end())
79 std::string
const & con_header = r.get_header(
"Connection");
81 if (ci_find_substr(con_header, constants::connection_token,
82 sizeof(constants::connection_token)-1) == con_header.end())
106 template <
typename request_type>
112 if (r.get_header(
"Sec-WebSocket-Version").empty()) {
117 std::istringstream ss(r.get_header(
"Sec-WebSocket-Version"));
119 if ((ss >> version).fail()) {
135 template <
typename request_type>
137 std::string h = request.get_header(
"Host");
139 size_t last_colon = h.rfind(
":");
140 size_t last_sbrace = h.rfind(
"]");
146 if (last_colon == std::string::npos ||
147 (last_sbrace != std::string::npos && last_sbrace > last_colon))
149 return lib::make_shared<uri>(scheme, h, request.get_uri());
151 return lib::make_shared<uri>(scheme,
152 h.substr(0,last_colon),
153 h.substr(last_colon+1),
159 template <
typename config>
163 typedef typename config::request_type request_type;
164 typedef typename config::response_type response_type;
165 typedef typename config::message_type::ptr message_ptr;
166 typedef std::pair<lib::error_code,std::string> err_str_pair;
168 explicit processor(
bool secure,
bool p_is_server)
170 , m_server(p_is_server)
171 , m_max_message_size(config::max_message_size)
174 virtual ~processor() {}
189 return m_max_message_size;
204 m_max_message_size = new_value;
226 return err_str_pair();
240 return err_str_pair();
401 size_t m_max_message_size;
int get_websocket_version(request_type &r)
Extract the version from a WebSocket handshake request.
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 prepare_ping(std::string const &in, message_ptr out) const =0
Prepare a ping frame.
virtual bool get_error() const =0
Tests whether the processor is in a fatal error state.
virtual lib::error_code prepare_close(close::status::value code, std::string const &reason, message_ptr out) const =0
Prepare a close frame.
virtual lib::error_code extract_subprotocols(const request_type &req, std::vector< std::string > &subprotocol_list)=0
Extracts requested subprotocols from a handshake request.
uri_ptr get_uri_from_host(request_type &request, std::string scheme)
Extract a URI ptr from the host header of the request.
bool is_websocket_handshake(request_type &r)
Determine whether or not a generic HTTP request is a WebSocket handshake.
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.
void set_max_message_size(size_t new_value)
Set maximum message size.
size_t get_max_message_size() const
Get maximum message size.
static std::vector< int > const versions_supported(helper, helper+4)
Container that stores the list of protocol versions supported.
WebSocket protocol processor abstract base class.
virtual size_t get_bytes_needed() const
virtual size_t consume(uint8_t *buf, size_t len, lib::error_code &ec)=0
process new websocket connection bytes
virtual uri_ptr get_uri(request_type const &request) const =0
Extracts client uri from a handshake request.
virtual bool has_permessage_compress() const
Returns whether or not the permessage_compress extension is implemented.
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.
Processors encapsulate the protocol rules specific to each WebSocket version.
virtual lib::error_code prepare_data_frame(message_ptr in, message_ptr out)=0
Prepare a data message for writing.
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 lib::error_code prepare_pong(std::string const &in, message_ptr out) const =0
Prepare a pong frame.
virtual bool ready() const =0
Checks if there is a message ready.
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 message_ptr get_message()=0
Retrieves the most recently processed message.
virtual err_str_pair negotiate_extensions(request_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 int get_version() const =0
Get the protocol version of this processor.
virtual err_str_pair negotiate_extensions(response_type const &)
Initializes extensions based on the Sec-WebSocket-Extensions header.