diff --git a/websocketpp/connection.hpp b/websocketpp/connection.hpp index 248bd1a9fe..134e940f39 100644 --- a/websocketpp/connection.hpp +++ b/websocketpp/connection.hpp @@ -276,7 +276,7 @@ private: }; public: - explicit connection(bool is_server, const std::string& ua, alog_type& alog, + explicit connection(bool is_server, std::string const & ua, alog_type& alog, elog_type& elog, rng_type & rng) : transport_con_type(is_server,alog,elog) , m_user_agent(ua) @@ -296,8 +296,6 @@ public: m_alog.write(log::alevel::devel,"connection constructor"); } - // Public Interface - /////////////////////////// // Set Handler Callbacks // /////////////////////////// @@ -453,7 +451,9 @@ public: size_t get_buffered_amount() const; /// DEPRECATED: use get_buffered_amount instead - size_t buffered_amount() const {return get_buffered_amount();} + size_t buffered_amount() const { + return get_buffered_amount(); + } //////////////////// // Action Methods // @@ -471,7 +471,7 @@ public: * @param op The opcode to generated the message with. Default is * frame::opcode::text */ - lib::error_code send(const std::string& payload, frame::opcode::value op = + lib::error_code send(std::string const & payload, frame::opcode::value op = frame::opcode::TEXT); /// Send a message (raw array overload) @@ -488,7 +488,7 @@ public: * @param op The opcode to generated the message with. Default is * frame::opcode::binary */ - lib::error_code send(const void* payload, size_t len, frame::opcode::value + lib::error_code send(void const * payload, size_t len, frame::opcode::value op = frame::opcode::BINARY); /// Add a message to the outgoing send queue @@ -536,13 +536,13 @@ public: * * @param payload Payload to be used for the ping */ - void ping(const std::string& payload); + void ping(std::string const & payload); /// exception free variant of ping - void ping(const std::string & payload, lib::error_code & ec); + void ping(std::string const & payload, lib::error_code & ec); /// Utility method that gets called back when the ping timer expires - void handle_pong_timeout(std::string payload, const lib::error_code & ec); + void handle_pong_timeout(std::string payload, lib::error_code const & ec); /// Send a pong /** @@ -554,10 +554,10 @@ public: * * @param payload Payload to be used for the pong */ - void pong(const std::string & payload); + void pong(std::string const & payload); /// exception free variant of pong - void pong(const std::string & payload, lib::error_code & ec); + void pong(std::string const & payload, lib::error_code & ec); /// Close the connection /** @@ -577,13 +577,12 @@ public: * if necessary. * * @param code The close code to send - * * @param reason The close reason to send */ - void close(const close::status::value code, const std::string & reason); + void close(close::status::value const code, std::string const & reason); /// exception free variant of close - void close(const close::status::value code, const std::string & reason, + void close(close::status::value const code, std::string const & reason, lib::error_code & ec); //////////////////////////////////////////////// @@ -606,7 +605,7 @@ public: * * @return The host component of the connection URI */ - const std::string& get_host() const; + std::string const & get_host() const; /// Returns the resource component of the connection URI /** @@ -615,7 +614,7 @@ public: * * @return The resource component of the connection URI */ - const std::string& get_resource() const; + std::string const & get_resource() const; /// Returns the port component of the connection URI /** @@ -655,7 +654,7 @@ public: * * @return The negotiated subprotocol */ - const std::string& get_subprotocol() const; + std::string const & get_subprotocol() const; /// Gets all of the subprotocols requested by the client /** @@ -664,7 +663,7 @@ public: * * @return A vector of the requested subprotocol */ - const std::vector & get_requested_subprotocols() const; + std::vector const & get_requested_subprotocols() const; /// Adds the given subprotocol string to the request list (exception free) /** @@ -676,11 +675,10 @@ public: * preference. * * @param request The subprotocol to request - * * @param ec A reference to an error code that will be filled in the case of * errors */ - void add_subprotocol(const std::string &request, lib::error_code & ec); + void add_subprotocol(std::string const & request, lib::error_code & ec); /// Adds the given subprotocol string to the request list /** @@ -693,7 +691,7 @@ public: * * @param request The subprotocol to request */ - void add_subprotocol(const std::string &request); + void add_subprotocol(std::string const & request); /// Select a subprotocol to use (exception free) /** @@ -705,11 +703,10 @@ public: * This member function is valid on server endpoints/connections only * * @param value The subprotocol to select - * * @param ec A reference to an error code that will be filled in the case of * errors */ - void select_subprotocol(const std::string & value, lib::error_code & ec); + void select_subprotocol(std::string const & value, lib::error_code & ec); /// Select a subprotocol to use /** @@ -722,7 +719,7 @@ public: * * @param value The subprotocol to select */ - void select_subprotocol(const std::string & value); + void select_subprotocol(std::string const & value); ///////////////////////////////////////////////////////////// // Pass-through access to the request and response objects // @@ -733,16 +730,18 @@ public: * Retrieve the value of a header from the handshake HTTP request. * * @param key Name of the header to get + * @return The value of the header */ - const std::string & get_request_header(const std::string &key); + std::string const & get_request_header(std::string const & key); /// Retrieve a response header /** * Retrieve the value of a header from the handshake HTTP request. * * @param key Name of the header to get + * @return The value of the header */ - const std::string & get_response_header(const std::string &key); + std::string const & get_response_header(std::string const & key); /// Set response status code and message /** @@ -773,7 +772,7 @@ public: * @param msg Message to set * @see websocketpp::http::response::set_status */ - void set_status(http::status_code::value code, const std::string& msg); + void set_status(http::status_code::value code, std::string const & msg); /// Set response body content /** @@ -788,7 +787,7 @@ public: * @param value String data to include as the body content. * @see websocketpp::http::response::set_body */ - void set_body(const std::string& value); + void set_body(std::string const & value); /// Append a header /** @@ -804,7 +803,7 @@ public: * @see replace_header * @see websocketpp::http::parser::append_header */ - void append_header(const std::string &key,const std::string &val); + void append_header(std::string const &key, std::string const & val); /// Replace a header /** @@ -819,7 +818,7 @@ public: * @see add_header * @see websocketpp::http::parser::replace_header */ - void replace_header(const std::string &key,const std::string &val); + void replace_header(std::string const & key, std::string const & val); /// Remove a header /** @@ -831,7 +830,7 @@ public: * @param key The name of the header to remove * @see websocketpp::http::parser::remove_header */ - void remove_header(const std::string &key); + void remove_header(std::string const & key); /// Get request object /** @@ -882,7 +881,7 @@ public: * * @return The connection's origin value from the opening handshake. */ - const std::string& get_origin() const; + std::string const & get_origin() const; /// Return the connection state. /** @@ -962,18 +961,18 @@ public: void read_handshake(size_t num_bytes); - void handle_read_handshake(const lib::error_code& ec, + void handle_read_handshake(lib::error_code const & ec, size_t bytes_transferred); - void handle_read_http_response(const lib::error_code& ec, + void handle_read_http_response(lib::error_code const & ec, size_t bytes_transferred); - void handle_send_http_response(const lib::error_code& ec); - void handle_send_http_request(const lib::error_code& ec); + void handle_send_http_response(lib::error_code const & ec); + void handle_send_http_request(lib::error_code const & ec); void handle_open_handshake_timeout(lib::error_code const & ec); void handle_close_handshake_timeout(lib::error_code const & ec); - void handle_read_frame(const lib::error_code& ec, + void handle_read_frame(lib::error_code const & ec, size_t bytes_transferred); /// Get array of WebSocket protocol versions that this connection supports. @@ -983,8 +982,8 @@ public: /// internally by the endpoint class. void set_termination_handler(termination_handler new_handler); - void terminate(const lib::error_code & ec); - void handle_terminate(terminate_status tstat, const lib::error_code& ec); + void terminate(lib::error_code const & ec); + void handle_terminate(terminate_status tstat, lib::error_code const & ec); /// Checks if there are frames in the send queue and if there are sends one /** @@ -1006,9 +1005,9 @@ public: * @param ec A status code from the transport layer, zero on success, * non-zero otherwise. */ - void handle_write_frame(bool terminate, const lib::error_code& ec); + void handle_write_frame(bool terminate, lib::error_code const & ec); protected: - void handle_transport_init(const lib::error_code& ec); + void handle_transport_init(lib::error_code const & ec); /// Set m_processor based on information in m_request. Set m_response /// status and return false on error. @@ -1080,13 +1079,11 @@ private: * other settings (such as silent close). * * @param code The close code to send - * * @param reason The close reason to send - * * @return A status code, zero on success, non-zero otherwise */ lib::error_code send_close_ack(close::status::value code = - close::status::blank, const std::string &reason = ""); + close::status::blank, std::string const & reason = ""); /// Send close frame /** @@ -1099,15 +1096,12 @@ private: * whether or not to terminate the TCP connection after sending it. * * @param code The close code to send - * * @param reason The close reason to send - * * @param ack Whether or not this is an acknowledgement close frame - * * @return A status code, zero on success, non-zero otherwise */ lib::error_code send_close_frame(close::status::value code = - close::status::blank, const std::string &reason = "", bool ack = false, + close::status::blank, std::string const & reason = "", bool ack = false, bool terminal = false); /// Get a pointer to a new WebSocket protocol processor for a given version @@ -1128,7 +1122,7 @@ private: * * Must be called while holding m_write_lock * - * \todo unit tests + * @todo unit tests * * @param msg The message to push */ @@ -1141,7 +1135,7 @@ private: * * Must be called while holding m_write_lock * - * \todo unit tests + * @todo unit tests * * @return the message_ptr at the front of the queue */ @@ -1214,7 +1208,7 @@ private: timer_ptr m_handshake_timer; timer_ptr m_ping_timer; - /// \todo this is not memory efficient. this value is not used after the + /// @todo this is not memory efficient. this value is not used after the /// handshake. std::string m_handshake_buffer; @@ -1267,7 +1261,7 @@ private: // of the whole connection. std::vector m_requested_subprotocols; - const bool m_is_server; + bool const m_is_server; alog_type& m_alog; elog_type& m_elog; diff --git a/websocketpp/processors/hybi13.hpp b/websocketpp/processors/hybi13.hpp index e3ff464967..ca28771542 100644 --- a/websocketpp/processors/hybi13.hpp +++ b/websocketpp/processors/hybi13.hpp @@ -84,7 +84,7 @@ public: return m_permessage_deflate.is_implemented(); } - err_str_pair negotiate_extensions(const request_type& req) { + err_str_pair negotiate_extensions(request_type const & req) { err_str_pair ret; // Respect blanket disabling of all extensions and don't even parse @@ -110,7 +110,7 @@ public: http::parameter_list::const_iterator it; - /*if (m_permessage_deflate.is_implemented()) { + if (m_permessage_deflate.is_implemented()) { err_str_pair neg_ret; for (it = p.begin(); it != p.end(); ++it) { // look through each extension, if the key is permessage-deflate @@ -118,7 +118,8 @@ public: std::cout << "mark3: " << std::endl; neg_ret = m_permessage_deflate.negotiate(it->second); - std::cout << neg_ret.first.message() << " - " << neg_ret.second << std::endl; + std::cout << neg_ret.first.message() << " - " + << neg_ret.second << std::endl; if (neg_ret.first) { // Figure out if this is an error that should halt all @@ -134,12 +135,12 @@ public: } } } - }*/ + } return ret; } - lib::error_code validate_handshake(const request_type& r) const { + lib::error_code validate_handshake(request_type const & r) const { if (r.get_method() != "GET") { return make_error_code(error::invalid_http_method); } @@ -163,7 +164,7 @@ public: * generic struct if other user input parameters to the processed handshake * are found. */ - lib::error_code process_handshake(const request_type& request, const + lib::error_code process_handshake(request_type const & request, const std::string & subprotocol, response_type& response) const { std::string server_key = request.get_header("Sec-WebSocket-Key"); @@ -186,7 +187,7 @@ public: } lib::error_code client_handshake_request(request_type& req, uri_ptr - uri, const std::vector & subprotocols) const + uri, std::vector const & subprotocols) const { req.set_method("GET"); req.set_uri(uri->get_resource()); @@ -222,7 +223,7 @@ public: return lib::error_code(); } - lib::error_code validate_server_handshake_response(const request_type& req, + lib::error_code validate_server_handshake_response(request_type const & req, response_type& res) const { // A valid response has an HTTP 101 switching protocols code @@ -231,7 +232,7 @@ public: } // And the upgrade token in an upgrade header - const std::string& upgrade_header = res.get_header("Upgrade"); + std::string const & upgrade_header = res.get_header("Upgrade"); if (utility::ci_find_substr(upgrade_header, constants::upgrade_token, sizeof(constants::upgrade_token)-1) == upgrade_header.end()) { @@ -239,7 +240,7 @@ public: } // And the websocket token in the connection header - const std::string& con_header = res.get_header("Connection"); + std::string const & con_header = res.get_header("Connection"); if (utility::ci_find_substr(con_header, constants::connection_token, sizeof(constants::connection_token)-1) == con_header.end()) { @@ -257,15 +258,15 @@ public: return lib::error_code(); } - std::string get_raw(const response_type& res) const { + std::string get_raw(response_type const & res) const { return res.raw(); } - const std::string& get_origin(const request_type& r) const { + std::string const & get_origin(request_type const & r) const { return r.get_header("Origin"); } - lib::error_code extract_subprotocols(const request_type & req, + lib::error_code extract_subprotocols(request_type const & req, std::vector & subprotocol_list) { if (!req.get_header("Sec-WebSocket-Protocol").empty()) { @@ -284,7 +285,7 @@ public: return lib::error_code(); } - uri_ptr get_uri(const request_type& request) const { + uri_ptr get_uri(request_type const & request) const { return get_uri_from_host(request,(base::m_secure ? "wss" : "ws")); } @@ -496,9 +497,7 @@ public: * TODO: tests * * @param in An unprepared message to prepare - * * @param out A message to be overwritten with the prepared message - * * @return error code */ virtual lib::error_code prepare_data_frame(message_ptr in, message_ptr out) @@ -570,16 +569,17 @@ public: return lib::error_code(); } - lib::error_code prepare_ping(const std::string& in, message_ptr out) const { + /// Get URI + lib::error_code prepare_ping(std::string const & in, message_ptr out) const { return this->prepare_control(frame::opcode::PING,in,out); } - lib::error_code prepare_pong(const std::string& in, message_ptr out) const { + lib::error_code prepare_pong(std::string const & in, message_ptr out) const { return this->prepare_control(frame::opcode::PONG,in,out); } virtual lib::error_code prepare_close(close::status::value code, - const std::string & reason, message_ptr out) const + std::string const & reason, message_ptr out) const { if (close::status::reserved(code)) { return make_error_code(error::reserved_close_code); @@ -631,7 +631,7 @@ protected: } key = base64_encode( - reinterpret_cast(message_digest), + reinterpret_cast(message_digest), 20 ); @@ -642,7 +642,7 @@ protected: } /// Reads bytes from buf into m_basic_header - size_t copy_basic_header_bytes(const uint8_t * buf, size_t len) { + size_t copy_basic_header_bytes(uint8_t const * buf, size_t len) { if (len == 0 || m_bytes_needed == 0) { return 0; } @@ -674,7 +674,7 @@ protected: } /// Reads bytes from buf into m_extended_header - size_t copy_extended_header_bytes(const uint8_t * buf, size_t len) { + size_t copy_extended_header_bytes(uint8_t const * buf, size_t len) { size_t bytes_to_read = std::min(m_bytes_needed,len); std::copy(buf,buf+bytes_to_read,m_extended_header.bytes+m_cursor); @@ -694,11 +694,8 @@ protected: * bytes actually needed. At most min(m_bytes_needed,len) will be processed. * * @param buf Input/working buffer - * * @param len Length of buf - * * @return Number of bytes processed or zero in case of an error - * */ size_t process_payload_bytes(uint8_t * buf, size_t len, lib::error_code& ec) { @@ -719,7 +716,7 @@ protected: #endif } - std::string& out = m_current_msg->msg_ptr->get_raw_payload(); + std::string & out = m_current_msg->msg_ptr->get_raw_payload(); size_t offset = out.size(); // decompress message if needed. @@ -759,15 +756,12 @@ protected: * Validates an incoming hybi13 basic header. * * @param h The basic header to validate - * * @param is_server Whether or not the endpoint that received this frame * is a server. - * * @param new_msg Whether or not this is the first frame of the message - * * @return 0 on success or a non-zero error code on failure */ - lib::error_code validate_incoming_basic_header(const frame::basic_header &h, + lib::error_code validate_incoming_basic_header(frame::basic_header const & h, bool is_server, bool new_msg) const { frame::opcode::value op = frame::get_opcode(h); @@ -838,17 +832,15 @@ protected: /** * Validates an incoming hybi13 full header. * - * \todo unit test for the >32 bit frames on 32 bit systems case + * @todo unit test for the >32 bit frames on 32 bit systems case * * @param h The basic header to validate - * * @param e The extended header to validate - * * @return An error_code, non-zero values indicate why the validation * failed */ - lib::error_code validate_incoming_extended_header(const frame::basic_header h, - const frame::extended_header e) const + lib::error_code validate_incoming_extended_header(frame::basic_header h, + frame::extended_header e) const { uint8_t basic_size = frame::get_basic_size(h); uint64_t payload_size = frame::get_payload_size(h,e); @@ -879,9 +871,7 @@ protected: * Reads input from one string and writes unmasked output to another. * * @param [in] i The input string. - * * @param [out] o The output string. - * * @param [in] key The masking key to use for masking/unmasking */ void masked_copy (std::string const & i, std::string & o, @@ -891,8 +881,8 @@ protected: frame::byte_mask(i.begin(),i.end(),o.begin(),key); #else websocketpp::frame::word_mask_exact( - reinterpret_cast(const_cast(i.data())), - reinterpret_cast(const_cast(o.data())), + reinterpret_cast(const_cast(i.data())), + reinterpret_cast(const_cast(o.data())), i.size(), key ); @@ -904,15 +894,12 @@ protected: * Internal control frame building method. Handles validation, masking, etc * * @param op The control opcode to use - * * @param payload The payload to use - * * @param out The message buffer to store the prepared frame in - * * @return Status code, zero on success, non-zero on error */ lib::error_code prepare_control(frame::opcode::value op, - const std::string & payload, message_ptr out) const + std::string const & payload, message_ptr out) const { if (!out) { return make_error_code(error::invalid_arguments); @@ -996,7 +983,7 @@ protected: msg_metadata m_control_msg; // Pointer to the metadata associated with the frame being read - msg_metadata *m_current_msg; + msg_metadata * m_current_msg; // Extended header of current frame frame::extended_header m_extended_header; @@ -1007,7 +994,7 @@ protected: // utf8 validator // compression state - rng_type& m_rng; + rng_type & m_rng; // Overall state of the processor state m_state;