From 290b7190487821c9075ecb8b90d75d97ff7e85c1 Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Sun, 20 Jan 2013 09:02:17 -0600 Subject: [PATCH] inlines appropriate functions to work when included in multiple translation units. fixes #178 --- websocketpp/base64/base64.hpp | 132 +++++++++++++----------- websocketpp/close.hpp | 4 +- websocketpp/error.hpp | 6 +- websocketpp/extensions/extension.hpp | 4 +- websocketpp/frame.hpp | 88 ++++++++-------- websocketpp/http/impl/parser.hpp | 32 +++--- websocketpp/http/impl/request.hpp | 14 +-- websocketpp/http/impl/response.hpp | 24 +++-- websocketpp/impl/utilities_impl.hpp | 31 +----- websocketpp/md5/md5.hpp | 6 +- websocketpp/processors/base.hpp | 6 +- websocketpp/transport/iostream/base.hpp | 4 +- 12 files changed, 175 insertions(+), 176 deletions(-) diff --git a/websocketpp/base64/base64.hpp b/websocketpp/base64/base64.hpp index 5fbe679e96..4c09d69bb0 100644 --- a/websocketpp/base64/base64.hpp +++ b/websocketpp/base64/base64.hpp @@ -47,87 +47,97 @@ static inline bool is_base64(unsigned char c) { return (isalnum(c) || (c == '+') || (c == '/')); } -std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) { - std::string ret; - int i = 0; - int j = 0; - unsigned char char_array_3[3]; - unsigned char char_array_4[4]; +inline std::string base64_encode(unsigned char const* bytes_to_encode, unsigned + int in_len) +{ + std::string ret; + int i = 0; + int j = 0; + unsigned char char_array_3[3]; + unsigned char char_array_4[4]; - while (in_len--) { - char_array_3[i++] = *(bytes_to_encode++); - if (i == 3) { - char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; - char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); - char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); - char_array_4[3] = char_array_3[2] & 0x3f; + while (in_len--) { + char_array_3[i++] = *(bytes_to_encode++); + if (i == 3) { + char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; + char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + + ((char_array_3[1] & 0xf0) >> 4); + char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + + ((char_array_3[2] & 0xc0) >> 6); + char_array_4[3] = char_array_3[2] & 0x3f; - for(i = 0; (i <4) ; i++) - ret += base64_chars[char_array_4[i]]; - i = 0; + for(i = 0; (i <4) ; i++) { + ret += base64_chars[char_array_4[i]]; + } + i = 0; + } } - } - if (i) - { - for(j = i; j < 3; j++) - char_array_3[j] = '\0'; + if (i) { + for(j = i; j < 3; j++) { + char_array_3[j] = '\0'; + } - char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; - char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); - char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); - char_array_4[3] = char_array_3[2] & 0x3f; + char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; + char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + + ((char_array_3[1] & 0xf0) >> 4); + char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + + ((char_array_3[2] & 0xc0) >> 6); + char_array_4[3] = char_array_3[2] & 0x3f; - for (j = 0; (j < i + 1); j++) - ret += base64_chars[char_array_4[j]]; - - while((i++ < 3)) - ret += '='; + for (j = 0; (j < i + 1); j++) { + ret += base64_chars[char_array_4[j]]; + } + while((i++ < 3)) { + ret += '='; + } } return ret; - } -std::string base64_decode(std::string const& encoded_string) { - size_t in_len = encoded_string.size(); - int i = 0; - int j = 0; - int in_ = 0; - unsigned char char_array_4[4], char_array_3[3]; - std::string ret; - while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) { - char_array_4[i++] = encoded_string[in_]; in_++; - if (i ==4) { - for (i = 0; i <4; i++) - char_array_4[i] = static_cast(base64_chars.find(char_array_4[i])); +inline std::string base64_decode(std::string const& encoded_string) { + size_t in_len = encoded_string.size(); + int i = 0; + int j = 0; + int in_ = 0; + unsigned char char_array_4[4], char_array_3[3]; + std::string ret; - char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); - char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); - char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; + while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) { + char_array_4[i++] = encoded_string[in_]; in_++; + if (i ==4) { + for (i = 0; i <4; i++) { + char_array_4[i] = static_cast(base64_chars.find(char_array_4[i])); + } - for (i = 0; (i < 3); i++) - ret += char_array_3[i]; - i = 0; + char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); + char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); + char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; + + for (i = 0; (i < 3); i++) { + ret += char_array_3[i]; + } + i = 0; + } } - } - if (i) { - for (j = i; j <4; j++) - char_array_4[j] = 0; + if (i) { + for (j = i; j <4; j++) + char_array_4[j] = 0; - for (j = 0; j <4; j++) - char_array_4[j] = static_cast(base64_chars.find(char_array_4[j])); + for (j = 0; j <4; j++) + char_array_4[j] = static_cast(base64_chars.find(char_array_4[j])); - char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); - char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); - char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; + char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); + char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); + char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; - for (j = 0; (j < i - 1); j++) ret += char_array_3[j]; - } + for (j = 0; (j < i - 1); j++) ret += char_array_3[j]; + } - return ret; + return ret; } #endif // _BASE64_HPP_ \ No newline at end of file diff --git a/websocketpp/close.hpp b/websocketpp/close.hpp index fcc683839c..cc4c46509d 100644 --- a/websocketpp/close.hpp +++ b/websocketpp/close.hpp @@ -116,7 +116,7 @@ union code_converter { * * @return The extracted value */ -status::value extract_code(const std::string& payload, lib::error_code & ec) { +inline status::value extract_code(const std::string& payload, lib::error_code & ec) { ec = lib::error_code(); if (payload.size() == 0) { @@ -156,7 +156,7 @@ status::value extract_code(const std::string& payload, lib::error_code & ec) { * * @return the reason string. */ -std::string extract_reason(const std::string& payload, lib::error_code & ec) { +inline std::string extract_reason(const std::string& payload, lib::error_code & ec) { std::string reason = ""; ec = lib::error_code(); diff --git a/websocketpp/error.hpp b/websocketpp/error.hpp index 4d5b25efc3..dbb1924156 100644 --- a/websocketpp/error.hpp +++ b/websocketpp/error.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Peter Thorson. All rights reserved. + * Copyright (c) 2013, Peter Thorson. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -122,12 +122,12 @@ public: } }; -const lib::error_category& get_category() { +inline const lib::error_category& get_category() { static category instance; return instance; } -lib::error_code make_error_code(error::value e) { +inline lib::error_code make_error_code(error::value e) { return lib::error_code(static_cast(e), get_category()); } diff --git a/websocketpp/extensions/extension.hpp b/websocketpp/extensions/extension.hpp index 6d28c49504..d41d001d48 100644 --- a/websocketpp/extensions/extension.hpp +++ b/websocketpp/extensions/extension.hpp @@ -78,12 +78,12 @@ public: } }; -const lib::error_category& get_category() { +inline const lib::error_category& get_category() { static category instance; return instance; } -lib::error_code make_error_code(error::value e) { +inline lib::error_code make_error_code(error::value e) { return lib::error_code(static_cast(e), get_category()); } diff --git a/websocketpp/frame.hpp b/websocketpp/frame.hpp index 16692fe54e..48f24687e1 100644 --- a/websocketpp/frame.hpp +++ b/websocketpp/frame.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Peter Thorson. All rights reserved. + * Copyright (c) 2013, Peter Thorson. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -30,14 +30,8 @@ #include -// For htonl and htons -#if defined(WIN32) - #include -#else - #include -#endif - #include +#include #include @@ -89,7 +83,8 @@ namespace opcode { }; inline bool reserved(value v) { - return (v >= RSV3 && v <= RSV7) || (v >= CONTROL_RSVB && v <= CONTROL_RSVF); + return (v >= RSV3 && v <= RSV7) || + (v >= CONTROL_RSVB && v <= CONTROL_RSVF); } inline bool invalid(value v) { @@ -136,7 +131,8 @@ struct basic_header { basic_header(uint8_t p0, uint8_t p1) : b0(p0), b1(p1) {} basic_header(opcode::value op, uint64_t size, bool fin, bool mask, - bool rsv1 = false, bool rsv2 = false, bool rsv3 = false) : b0(0x00),b1(0x00) + bool rsv1 = false, bool rsv2 = false, bool rsv3 = false) : b0(0x00), + b1(0x00) { if (fin) { b0 |= BHB0_FIN; @@ -209,7 +205,7 @@ private: } uint64_converter temp64; - temp64.i = utility::htonll(payload_size); + temp64.i = lib::net::htonll(payload_size); std::copy(temp64.c+payload_offset,temp64.c+8,bytes); return 8-payload_offset; @@ -239,8 +235,8 @@ size_t circshift_prepared_key(size_t prepared_key, size_t offset); // Functions for performing xor based masking and unmasking template -void byte_mask(iter_type b, iter_type e, iter_type o, const masking_key_type& key, - size_t key_offset = 0); +void byte_mask(iter_type b, iter_type e, iter_type o, const masking_key_type& + key, size_t key_offset = 0); template void byte_mask(iter_type b, iter_type e, const masking_key_type& key, size_t key_offset = 0); @@ -258,7 +254,7 @@ size_t word_mask_circ(uint8_t* data, size_t length, size_t prepared_key); /** * @return True if the header's fin bit is set. */ -bool get_fin(const basic_header &h) { +inline bool get_fin(const basic_header &h) { return ((h.b0 & BHB0_FIN) == BHB0_FIN); } @@ -268,7 +264,7 @@ bool get_fin(const basic_header &h) { * * @param value Value to set it to */ -void set_fin(basic_header &h, bool value) { +inline void set_fin(basic_header &h, bool value) { h.b0 = (value ? h.b0 | BHB0_FIN : h.b0 & ~BHB0_FIN); } @@ -276,7 +272,7 @@ void set_fin(basic_header &h, bool value) { /** * @return True if the header's RSV1 bit is set. */ -bool get_rsv1(const basic_header &h) { +inline bool get_rsv1(const basic_header &h) { return ((h.b0 & BHB0_RSV1) == BHB0_RSV1); } @@ -286,7 +282,7 @@ bool get_rsv1(const basic_header &h) { * * @param value Value to set it to */ -void set_rsv1(basic_header &h, bool value) { +inline void set_rsv1(basic_header &h, bool value) { h.b0 = (value ? h.b0 | BHB0_RSV1 : h.b0 & ~BHB0_RSV1); } @@ -294,7 +290,7 @@ void set_rsv1(basic_header &h, bool value) { /** * @return True if the header's RSV2 bit is set. */ -bool get_rsv2(const basic_header &h) { +inline bool get_rsv2(const basic_header &h) { return ((h.b0 & BHB0_RSV2) == BHB0_RSV2); } @@ -304,7 +300,7 @@ bool get_rsv2(const basic_header &h) { * * @param value Value to set it to */ -void set_rsv2(basic_header &h, bool value) { +inline void set_rsv2(basic_header &h, bool value) { h.b0 = (value ? h.b0 | BHB0_RSV2 : h.b0 & ~BHB0_RSV2); } @@ -312,7 +308,7 @@ void set_rsv2(basic_header &h, bool value) { /** * @return True if the header's RSV3 bit is set. */ -bool get_rsv3(const basic_header &h) { +inline bool get_rsv3(const basic_header &h) { return ((h.b0 & BHB0_RSV3) == BHB0_RSV3); } @@ -322,12 +318,12 @@ bool get_rsv3(const basic_header &h) { * * @param value Value to set it to */ -void set_rsv3(basic_header &h, bool value) { +inline void set_rsv3(basic_header &h, bool value) { h.b0 = (value ? h.b0 | BHB0_RSV3 : h.b0 & ~BHB0_RSV3); } /// Extract opcode from basic header -opcode::value get_opcode(const basic_header &h) { +inline opcode::value get_opcode(const basic_header &h) { return opcode::value(h.b0 & BHB0_OPCODE); } @@ -335,7 +331,7 @@ opcode::value get_opcode(const basic_header &h) { /** * @return True if the header mask bit is set. */ -bool get_masked(const basic_header &h) { +inline bool get_masked(const basic_header &h) { return ((h.b1 & BHB1_MASK) == BHB1_MASK); } @@ -345,7 +341,7 @@ bool get_masked(const basic_header &h) { * * @param value Value to set it to */ -void set_masked(basic_header &h, bool value) { +inline void set_masked(basic_header &h, bool value) { h.b1 = (value ? h.b1 | BHB1_MASK : h.b1 & ~BHB1_MASK); } @@ -366,7 +362,7 @@ void set_masked(basic_header &h, bool value) { * * @return the exact size encoded in h */ -uint8_t get_basic_size(const basic_header &h) { +inline uint8_t get_basic_size(const basic_header &h) { return h.b1 & BHB1_PAYLOAD; } @@ -376,7 +372,9 @@ uint8_t get_basic_size(const basic_header &h) { * * @param size */ -lib::error_code set_size(basic_header &h, extended_header &eh, uint64_t size) { +inline lib::error_code set_size(basic_header &h, extended_header &eh, uint64_t + size) +{ // make sure value isn't too big uint8_t basic_value; @@ -407,7 +405,7 @@ lib::error_code set_size(basic_header &h, extended_header &eh, uint64_t size) { * * @return Full length of the extended header. */ -size_t get_header_len(const basic_header &h) { +inline size_t get_header_len(const basic_header &h) { // TODO: check extensions? // masking key offset represents the space used for the extended length @@ -431,7 +429,7 @@ size_t get_header_len(const basic_header &h) { * * @return byte offset of the first byte of the masking key */ -unsigned int get_masking_key_offset(const basic_header &h) { +inline unsigned int get_masking_key_offset(const basic_header &h) { if (get_basic_size(h) == payload_size_code_16bit) { return 2; } else if (get_basic_size(h) == payload_size_code_64bit) { @@ -451,7 +449,9 @@ unsigned int get_masking_key_offset(const basic_header &h) { * * @return A contiguous string containing h and e */ -std::string prepare_header(const basic_header &h, const extended_header &e) { +inline std::string prepare_header(const basic_header &h, const + extended_header &e) +{ std::string ret; ret.push_back(char(h.b0)); @@ -476,7 +476,8 @@ std::string prepare_header(const basic_header &h, const extended_header &e) { * * @return The masking key as an integer. */ -masking_key_type get_masking_key(const basic_header &h,const extended_header &e) +inline masking_key_type get_masking_key(const basic_header &h, const + extended_header &e) { masking_key_type temp32; @@ -499,7 +500,7 @@ masking_key_type get_masking_key(const basic_header &h,const extended_header &e) * * @return The size encoded in the extended header in host byte order */ -uint16_t get_extended_size(const extended_header &e) { +inline uint16_t get_extended_size(const extended_header &e) { uint16_converter temp16; std::copy(e.bytes,e.bytes+2,temp16.c); return ntohs(temp16.i); @@ -514,10 +515,10 @@ uint16_t get_extended_size(const extended_header &e) { * * @return The size encoded in the extended header in host byte order */ -uint64_t get_jumbo_size(const extended_header &e) { +inline uint64_t get_jumbo_size(const extended_header &e) { uint64_converter temp64; std::copy(e.bytes,e.bytes+8,temp64.c); - return utility::ntohll(temp64.i); + return lib::net::ntohll(temp64.i); } /// Extract the full payload size field from a WebSocket header @@ -532,7 +533,9 @@ uint64_t get_jumbo_size(const extended_header &e) { * * @return The size encoded in the combined header in host byte order. */ -uint64_t get_payload_size(const basic_header &h, const extended_header &e) { +inline uint64_t get_payload_size(const basic_header &h, const + extended_header &e) +{ uint8_t val = get_basic_size(h); if (val <= limits::payload_size_basic) { @@ -552,7 +555,7 @@ uint64_t get_payload_size(const basic_header &h, const extended_header &e) { * * @return prepared key as a machine word */ -size_t prepare_masking_key(const masking_key_type& key) { +inline size_t prepare_masking_key(const masking_key_type& key) { size_t low_bits = static_cast(key.i); if (sizeof(size_t) == 8) { @@ -569,7 +572,7 @@ size_t prepare_masking_key(const masking_key_type& key) { * restrictions on the machine word size. offset must be greater than or equal * to zero and less than sizeof(size_t). */ -size_t circshift_prepared_key(size_t prepared_key, size_t offset) { +inline size_t circshift_prepared_key(size_t prepared_key, size_t offset) { size_t temp = prepared_key << (sizeof(size_t)-offset)*8; return (prepared_key >> offset*8) | temp; } @@ -594,8 +597,8 @@ size_t circshift_prepared_key(size_t prepared_key, size_t offset) { * @param key_offset offset value to start masking at. */ template -void byte_mask(iter_type b, iter_type e, iter_type o, const masking_key_type& key, - size_t key_offset) +void byte_mask(iter_type b, iter_type e, iter_type o, const masking_key_type& + key, size_t key_offset) { size_t key_index = key_offset%4; for (iter_type i = b, j = o; i != e; i++, j++) { @@ -649,7 +652,7 @@ void byte_mask(iter_type b, iter_type e, const masking_key_type& key, * * @param key Masking key to use */ -void word_mask_exact(uint8_t* input, uint8_t* output, size_t length, +inline void word_mask_exact(uint8_t* input, uint8_t* output, size_t length, const masking_key_type& key) { size_t prepared_key = prepare_masking_key(key); @@ -678,7 +681,8 @@ void word_mask_exact(uint8_t* input, uint8_t* output, size_t length, * * @param key Masking key to use */ -void word_mask_exact(uint8_t* data, size_t length, const masking_key_type& key) +inline void word_mask_exact(uint8_t* data, size_t length, const + masking_key_type& key) { word_mask_exact(data,data,length,key); } @@ -714,7 +718,7 @@ void word_mask_exact(uint8_t* data, size_t length, const masking_key_type& key) * * @return the prepared_key shifted to account for the input length */ -size_t word_mask_circ(uint8_t* input, uint8_t* output, size_t length, +inline size_t word_mask_circ(uint8_t* input, uint8_t* output, size_t length, size_t prepared_key) { size_t n = length / sizeof(size_t); // whole words @@ -750,7 +754,7 @@ size_t word_mask_circ(uint8_t* input, uint8_t* output, size_t length, * * @return the prepared_key shifted to account for the input length */ -size_t word_mask_circ(uint8_t* data, size_t length, size_t prepared_key) { +inline size_t word_mask_circ(uint8_t* data, size_t length, size_t prepared_key){ return word_mask_circ(data,data,length,prepared_key); } diff --git a/websocketpp/http/impl/parser.hpp b/websocketpp/http/impl/parser.hpp index ee76b67bfc..f86c291bb0 100644 --- a/websocketpp/http/impl/parser.hpp +++ b/websocketpp/http/impl/parser.hpp @@ -35,10 +35,8 @@ namespace websocketpp { namespace http { namespace parser { - - -bool parser::parse_parameter_list(const std::string& in, parameter_list& out) - const +inline bool parser::parse_parameter_list(const std::string& in, + parameter_list& out) const { if (in.size() == 0) { return false; @@ -49,8 +47,8 @@ bool parser::parse_parameter_list(const std::string& in, parameter_list& out) return (it == in.begin()); } -bool parser::get_header_as_plist(const std::string& key, parameter_list& out) - const +inline bool parser::get_header_as_plist(const std::string& key, + parameter_list& out) const { header_list::const_iterator it = m_headers.find(key); @@ -67,7 +65,7 @@ bool parser::get_header_as_plist(const std::string& key, parameter_list& out) return this->parse_parameter_list(it->second,out); } -void parser::set_version(const std::string& version) { +inline void parser::set_version(const std::string& version) { // TODO: validation? // first four chars == HTTP/ @@ -75,7 +73,7 @@ void parser::set_version(const std::string& version) { m_version = version; } -const std::string& parser::get_header(const std::string& key) const { +inline const std::string& parser::get_header(const std::string& key) const { header_list::const_iterator h = m_headers.find(key); if (h == m_headers.end()) { @@ -85,7 +83,9 @@ const std::string& parser::get_header(const std::string& key) const { } } -void parser::append_header(const std::string &key,const std::string &val) { +inline void parser::append_header(const std::string &key,const std::string + &val) +{ if (std::find_if(key.begin(),key.end(),is_not_token_char) != key.end()) { throw exception("Invalid header name",status_code::BAD_REQUEST); } @@ -98,16 +98,18 @@ void parser::append_header(const std::string &key,const std::string &val) { } } -void parser::replace_header(const std::string &key,const std::string &val) { +inline void parser::replace_header(const std::string &key,const std::string + &val) +{ m_headers[key] = val; } -void parser::remove_header(const std::string &key) { +inline void parser::remove_header(const std::string &key) { m_headers.erase(key); } -bool parser::parse_headers(std::istream& s) { +inline bool parser::parse_headers(std::istream& s) { std::string header; std::string::size_type end; @@ -129,7 +131,7 @@ bool parser::parse_headers(std::istream& s) { return true; } -std::string parser::raw_headers() const { +inline std::string parser::raw_headers() const { std::stringstream raw; header_list::const_iterator it; @@ -140,7 +142,9 @@ std::string parser::raw_headers() const { return raw.str(); } -void parser::process_header(std::string::iterator begin, std::string::iterator end) { +inline void parser::process_header(std::string::iterator begin, + std::string::iterator end) +{ std::string::iterator cursor = std::search( begin, end, diff --git a/websocketpp/http/impl/request.hpp b/websocketpp/http/impl/request.hpp index 7820250ff9..7e7d10b5b4 100644 --- a/websocketpp/http/impl/request.hpp +++ b/websocketpp/http/impl/request.hpp @@ -37,7 +37,7 @@ namespace websocketpp { namespace http { namespace parser { -bool request::parse_complete(std::istream& s) { +inline bool request::parse_complete(std::istream& s) { std::string request; // get status line @@ -64,7 +64,7 @@ bool request::parse_complete(std::istream& s) { return parse_headers(s); } -size_t request::consume(const char *buf, size_t len) { +inline size_t request::consume(const char *buf, size_t len) { if (m_ready) {return 0;} if (m_buf->size() + len > MAX_HEADER_SIZE) { @@ -131,7 +131,7 @@ size_t request::consume(const char *buf, size_t len) { } } -std::string request::raw() { +inline std::string request::raw() { // TODO: validation. Make sure all required fields have been set? std::stringstream raw; @@ -141,7 +141,7 @@ std::string request::raw() { return raw.str(); } -void request::set_method(const std::string& method) { +inline void request::set_method(const std::string& method) { if (std::find_if(method.begin(),method.end(),is_not_token_char) != method.end()) { throw exception("Invalid method token.",status_code::BAD_REQUEST); } @@ -149,12 +149,14 @@ void request::set_method(const std::string& method) { m_method = method; } -void request::set_uri(const std::string& uri) { +inline void request::set_uri(const std::string& uri) { // TODO: validation? m_uri = uri; } -void request::process(std::string::iterator begin, std::string::iterator end) { +inline void request::process(std::string::iterator begin, std::string::iterator + end) +{ std::string::iterator cursor_start = begin; std::string::iterator cursor_end = std::find(begin,end,' '); diff --git a/websocketpp/http/impl/response.hpp b/websocketpp/http/impl/response.hpp index 3eb7b8442a..839f67c692 100644 --- a/websocketpp/http/impl/response.hpp +++ b/websocketpp/http/impl/response.hpp @@ -37,7 +37,7 @@ namespace websocketpp { namespace http { namespace parser { -size_t response::consume(const char *buf, size_t len) { +inline size_t response::consume(const char *buf, size_t len) { if (m_state == DONE) {return 0;} if (m_state == BODY) { @@ -131,7 +131,7 @@ size_t response::consume(const char *buf, size_t len) { } } -bool response::parse_complete(std::istream& s) { +inline bool response::parse_complete(std::istream& s) { // parse a complete header (ie \r\n\r\n MUST be in the input stream) std::string response; @@ -159,32 +159,34 @@ bool response::parse_complete(std::istream& s) { return parse_headers(s); } -std::string response::raw() const { +inline std::string response::raw() const { // TODO: validation. Make sure all required fields have been set? std::stringstream raw; - raw << get_version() << " " << m_status_code << " " << m_status_msg << "\r\n"; - raw << raw_headers() << "\r\n"; + raw << get_version() << " " << m_status_code << " " << m_status_msg; + raw << "\r\n" << raw_headers() << "\r\n"; raw << m_body; return raw.str(); } -void response::set_status(status_code::value code) { +inline void response::set_status(status_code::value code) { // TODO: validation? m_status_code = code; m_status_msg = get_string(code); } -void response::set_status(status_code::value code, const std::string& msg) { +inline void response::set_status(status_code::value code, const std::string& + msg) +{ // TODO: validation? m_status_code = code; m_status_msg = msg; } -void response::set_body(const std::string& value) { +inline void response::set_body(const std::string& value) { if (value.size() == 0) { remove_header("Content-Length"); m_body = ""; @@ -198,7 +200,9 @@ void response::set_body(const std::string& value) { } -void response::process(std::string::iterator begin, std::string::iterator end) { +inline void response::process(std::string::iterator begin, + std::string::iterator end) +{ std::string::iterator cursor_start = begin; std::string::iterator cursor_end = std::find(begin,end,' '); @@ -226,7 +230,7 @@ void response::process(std::string::iterator begin, std::string::iterator end) { set_status(status_code::value(code),std::string(cursor_end+1,end)); } -size_t response::process_body(const char *buf, size_t len) { +inline size_t response::process_body(const char *buf, size_t len) { // If no content length was set then we read forever and never set m_ready if (m_read == 0) { m_body.append(buf,len); diff --git a/websocketpp/impl/utilities_impl.hpp b/websocketpp/impl/utilities_impl.hpp index b02f1a1786..0762d26e00 100644 --- a/websocketpp/impl/utilities_impl.hpp +++ b/websocketpp/impl/utilities_impl.hpp @@ -31,32 +31,7 @@ namespace websocketpp { namespace utility { -uint64_t htonll(uint64_t src) { - static int typ = TYP_INIT; - unsigned char c; - union { - uint64_t ull; - unsigned char c[8]; - } x; - if (typ == TYP_INIT) { - x.ull = 0x01; - typ = (x.c[7] == 0x01ULL) ? TYP_BIGE : TYP_SMLE; - } - if (typ == TYP_BIGE) - return src; - x.ull = src; - c = x.c[0]; x.c[0] = x.c[7]; x.c[7] = c; - c = x.c[1]; x.c[1] = x.c[6]; x.c[6] = c; - c = x.c[2]; x.c[2] = x.c[5]; x.c[5] = c; - c = x.c[3]; x.c[3] = x.c[4]; x.c[4] = c; - return x.ull; -} - -uint64_t ntohll(uint64_t src) { - return htonll(src); -} - -std::string to_hex(const std::string& input) { +inline std::string to_hex(const std::string& input) { std::string output; std::string hex = "0123456789ABCDEF"; @@ -69,7 +44,7 @@ std::string to_hex(const std::string& input) { return output; } -std::string to_hex(const uint8_t* input,size_t length) { +inline std::string to_hex(const uint8_t* input,size_t length) { std::string output; std::string hex = "0123456789ABCDEF"; @@ -82,7 +57,7 @@ std::string to_hex(const uint8_t* input,size_t length) { return output; } -std::string to_hex(const char* input,size_t length) { +inline std::string to_hex(const char* input,size_t length) { return to_hex(reinterpret_cast(input),length); } diff --git a/websocketpp/md5/md5.hpp b/websocketpp/md5/md5.hpp index c4051a0d5b..4eaffb7378 100644 --- a/websocketpp/md5/md5.hpp +++ b/websocketpp/md5/md5.hpp @@ -83,13 +83,13 @@ typedef struct md5_state_s { } md5_state_t; /* Initialize the algorithm. */ -void md5_init(md5_state_t *pms); +inline void md5_init(md5_state_t *pms); /* Append a string to the message. */ -void md5_append(md5_state_t *pms, const md5_byte_t *data, size_t nbytes); +inline void md5_append(md5_state_t *pms, const md5_byte_t *data, size_t nbytes); /* Finish the message and return the digest. */ -void md5_finish(md5_state_t *pms, md5_byte_t digest[16]); +inline void md5_finish(md5_state_t *pms, md5_byte_t digest[16]); #undef ZSW_MD5_BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */ #ifdef ARCH_IS_BIG_ENDIAN diff --git a/websocketpp/processors/base.hpp b/websocketpp/processors/base.hpp index 0515922e7e..ffc308d990 100644 --- a/websocketpp/processors/base.hpp +++ b/websocketpp/processors/base.hpp @@ -228,12 +228,12 @@ public: } }; -const lib::error_category& get_processor_category() { +inline const lib::error_category& get_processor_category() { static processor_category instance; return instance; } -lib::error_code make_error_code(error::processor_errors e) { +inline lib::error_code make_error_code(error::processor_errors e) { return lib::error_code(static_cast(e), get_processor_category()); } @@ -250,7 +250,7 @@ lib::error_code make_error_code(error::processor_errors e) { * applications, ex: invalid arguments) then * close::status::internal_endpoint_error is returned. */ -close::status::value to_ws(lib::error_code ec) { +inline close::status::value to_ws(lib::error_code ec) { if (ec.category() != get_processor_category()) { return close::status::blank; } diff --git a/websocketpp/transport/iostream/base.hpp b/websocketpp/transport/iostream/base.hpp index 412d9c6d44..aead9b51bd 100644 --- a/websocketpp/transport/iostream/base.hpp +++ b/websocketpp/transport/iostream/base.hpp @@ -83,12 +83,12 @@ class category : public lib::error_category { } }; -const lib::error_category& get_category() { +inline const lib::error_category& get_category() { static category instance; return instance; } -lib::error_code make_error_code(error::value e) { +inline lib::error_code make_error_code(error::value e) { return lib::error_code(static_cast(e), get_category()); }