28 #ifndef WEBSOCKETPP_PROCESSOR_HYBI00_HPP    29 #define WEBSOCKETPP_PROCESSOR_HYBI00_HPP    53 template <
typename config>
    66     explicit hybi00(
bool secure, 
bool p_is_server, msg_manager_ptr manager)
    71       , m_msg_manager(manager) {}
    78         if (r.get_method() != 
"GET") {
    82         if (r.get_version() != 
"HTTP/1.1") {
    90         if (r.get_header(
"Sec-WebSocket-Key1").empty() ||
    91             r.get_header(
"Sec-WebSocket-Key2").empty() ||
    92             r.get_header(
"Sec-WebSocket-Key3").empty())
    97         return lib::error_code();
   101         std::string 
const & subprotocol, response_type & res)
 const   106         decode_client_key(req.get_header(
"Sec-WebSocket-Key1"), &key_final[0]);
   109         decode_client_key(req.get_header(
"Sec-WebSocket-Key2"), &key_final[4]);
   116         std::string 
const & key3 = req.get_header(
"Sec-WebSocket-Key3");
   117         std::copy(key3.c_str(),
   118                   key3.c_str()+(std::min)(static_cast<size_t>(8), key3.size()),
   122             "Sec-WebSocket-Key3",
   126         res.append_header(
"Upgrade",
"WebSocket");
   127         res.append_header(
"Connection",
"Upgrade");
   131         if (res.get_header(
"Sec-WebSocket-Origin").empty()) {
   132             res.append_header(
"Sec-WebSocket-Origin",req.get_header(
"Origin"));
   137         if (res.get_header(
"Sec-WebSocket-Location").empty()) {
   139             res.append_header(
"Sec-WebSocket-Location",uri->str());
   142         if (!subprotocol.empty()) {
   143             res.replace_header(
"Sec-WebSocket-Protocol",subprotocol);
   146         return lib::error_code();
   159         std::vector<std::string> 
const &)
 const   174         response_type &)
 const   179     std::string 
get_raw(response_type 
const & res)
 const {
   180         response_type temp = res;
   181         temp.remove_header(
"Sec-WebSocket-Key3");
   182         return temp.raw() + res.get_header(
"Sec-WebSocket-Key3");
   185     std::string 
const & 
get_origin(request_type 
const & r)
 const {
   186         return r.get_header(
"Origin");
   199         std::vector<std::string> & subprotocol_list)
   201         if (!req.get_header(
"Sec-WebSocket-Protocol").empty()) {
   204              if (!req.get_header_as_plist(
"Sec-WebSocket-Protocol",p)) {
   205                  http::parameter_list::const_iterator it;
   207                  for (it = p.begin(); it != p.end(); ++it) {
   208                      subprotocol_list.push_back(it->first);
   214         return lib::error_code();
   218         std::string h = request.get_header(
"Host");
   220         size_t last_colon = h.rfind(
":");
   221         size_t last_sbrace = h.rfind(
"]");
   228         if (last_colon == std::string::npos ||
   229             (last_sbrace != std::string::npos && last_sbrace > last_colon))
   231             return lib::make_shared<uri>(
base::m_secure, h, request.get_uri());
   234                                    h.substr(0,last_colon),
   235                                    h.substr(last_colon+1),
   252     size_t consume(uint8_t * buf, 
size_t len, lib::error_code & ec) {
   258         ec = lib::error_code();
   261             if (m_state == HEADER) {
   262                 if (buf[p] == msg_hdr) {
   268                         m_state = FATAL_ERROR;
   274                     m_state = FATAL_ERROR;
   276             } 
else if (m_state == PAYLOAD) {
   277                 uint8_t *it = std::find(buf+p,buf+len,msg_ftr);
   283                 l = 
static_cast<size_t>(it-(buf+p));
   284                 m_msg_ptr->append_payload(buf+p,l);
   310         return (m_state == READY);
   318         message_ptr ret = m_msg_ptr;
   342         std::string& i = in->get_raw_payload();
   351         out->set_header(std::string(reinterpret_cast<char const *>(&msg_hdr),1));
   355         out->append_payload(std::string(reinterpret_cast<char const *>(&msg_ftr),1));
   360         out->set_prepared(
true);
   362         return lib::error_code();
   402         message_ptr out)
 const   409         val.append(1,
'\xff');
   410         val.append(1,
'\x00');
   411         out->set_payload(val);
   412         out->set_prepared(
true);
   414         return lib::error_code();
   417     void decode_client_key(std::string 
const & key, 
char * result)
 const {
   418         unsigned int spaces = 0;
   423         for (
size_t i = 0; i < key.size(); i++) {
   426             } 
else if (key[i] >= 
'0' && key[i] <= 
'9') {
   431         num = 
static_cast<uint32_t
>(strtoul(digits.c_str(), NULL, 10));
   432         if (spaces > 0 && num > 0) {
   433             num = htonl(num/spaces);
   434             std::copy(reinterpret_cast<char*>(&num),
   435                       reinterpret_cast<char*>(&num)+4,
   438             std::fill(result,result+4,0);
   449     uint8_t 
const msg_hdr;
   450     uint8_t 
const msg_ftr;
   454     msg_manager_ptr m_msg_manager;
   455     message_ptr m_msg_ptr;
   462 #endif //WEBSOCKETPP_PROCESSOR_HYBI00_HPP bool ready() const 
Checks if there is a message ready. 
 
int get_version() const 
Get the protocol version of this processor. 
 
hybi00(bool secure, bool p_is_server, msg_manager_ptr manager)
 
uint16_t value
The type of a close code value. 
 
lib::error_code make_error_code(error::value e)
 
lib::error_code validate_handshake(request_type const &r) const 
validate a WebSocket handshake request for this version 
 
config::con_msg_manager_type::ptr msg_manager_ptr
 
lib::error_code process_handshake(request_type const &req, std::string const &subprotocol, response_type &res) const 
Calculate the appropriate response for this websocket request. 
 
WebSocket protocol processor abstract base class. 
 
config::request_type request_type
 
Provides streaming UTF8 validation functionality. 
 
lib::error_code extract_subprotocols(request_type const &req, std::vector< std::string > &subprotocol_list)
Extracts requested subprotocols from a handshake request. 
 
No support for this feature in this protocol version. 
 
std::vector< std::pair< std::string, attribute_list > > parameter_list
The type of an HTTP parameter list. 
 
Processor encountered invalid payload data. 
 
std::string const & get_origin(request_type const &r) const 
Return the value of the header containing the CORS origin. 
 
Stores, parses, and manipulates HTTP responses. 
 
Processor encountered a protocol violation in an incoming message. 
 
uri_ptr get_uri(request_type const &request) const 
Extracts client uri from a handshake request. 
 
config::response_type response_type
 
lib::shared_ptr< message > ptr
 
lib::error_code prepare_close(close::status::value, std::string const &, message_ptr out) const 
Prepare a close frame. 
 
bool validate(std::string const &s)
Validate a UTF8 string. 
 
message_ptr get_message()
Retrieves the most recently processed message. 
 
lib::error_code make_error_code(error::processor_errors e)
Create an error code with the given value and the processor category. 
 
size_t consume(uint8_t *buf, size_t len, lib::error_code &ec)
Process new websocket connection bytes. 
 
std::string get_key3() const 
Get hybi00 handshake key3. 
 
Namespace for the WebSocket++ project. 
 
bool get_error() const 
Tests whether the processor is in a fatal error state. 
 
std::string md5_hash_string(std::string const &s)
 
Error parsing subprotocols. 
 
Represents a buffer for a single WebSocket message. 
 
The endpoint is out of incoming message buffers. 
 
lib::shared_ptr< uri > uri_ptr
Pointer to a URI. 
 
std::string get_raw(response_type const &res) const 
Given a completed response, get the raw bytes to put on the wire. 
 
Stores, parses, and manipulates HTTP requests. 
 
virtual lib::error_code prepare_data_frame(message_ptr in, message_ptr out)
Prepare a message for writing. 
 
lib::shared_ptr< con_msg_manager > ptr
 
Opcode was invalid for requested operation. 
 
message_type::ptr message_ptr
 
lib::error_code client_handshake_request(request_type &, uri_ptr, std::vector< std::string > const &) const 
Fill in a set of request headers for a client connection request. 
 
config::message_type message_type
 
lib::error_code validate_server_handshake_response(request_type const &, response_type &) const 
Validate the server's response to an outgoing handshake request. 
 
lib::error_code prepare_pong(std::string const &, message_ptr) const 
Prepare a pong frame. 
 
lib::error_code prepare_ping(std::string const &, message_ptr) const 
Prepare a ping frame. 
 
The processor method was called with invalid arguments. 
 
Processor for Hybi Draft version 00.