From 6f0df98a2ca0d9748c11701f30ef45b14582edcb Mon Sep 17 00:00:00 2001 From: bcsgh <33939446+bcsgh@users.noreply.github.com> Date: Sun, 23 Feb 2020 17:23:11 -0800 Subject: [PATCH 01/11] Use default constructor and operator= where possible: etr/libhttpserver#177 --- src/httpserver/basic_auth_fail_response.hpp | 47 +-- src/httpserver/create_webserver.hpp | 338 +++---------------- src/httpserver/deferred_response.hpp | 43 +-- src/httpserver/digest_auth_fail_response.hpp | 61 +--- src/httpserver/file_response.hpp | 46 +-- src/httpserver/http_request.hpp | 74 +--- src/httpserver/http_resource.hpp | 30 +- src/httpserver/http_response.hpp | 56 +-- src/httpserver/string_response.hpp | 46 +-- 9 files changed, 104 insertions(+), 637 deletions(-) diff --git a/src/httpserver/basic_auth_fail_response.hpp b/src/httpserver/basic_auth_fail_response.hpp index c9182dce..ba79c6f8 100644 --- a/src/httpserver/basic_auth_fail_response.hpp +++ b/src/httpserver/basic_auth_fail_response.hpp @@ -33,11 +33,7 @@ namespace httpserver class basic_auth_fail_response : public string_response { public: - basic_auth_fail_response(): - string_response(), - realm("") - { - } + basic_auth_fail_response() = default; explicit basic_auth_fail_response( const std::string& content, @@ -50,46 +46,17 @@ class basic_auth_fail_response : public string_response { } - basic_auth_fail_response(const basic_auth_fail_response& other): - string_response(other), - realm(other.realm) - { - } - - basic_auth_fail_response(basic_auth_fail_response&& other) noexcept: - string_response(std::move(other)), - realm(std::move(other.realm)) - { - } - - basic_auth_fail_response& operator=(const basic_auth_fail_response& b) - { - if (this == &b) return *this; - - (string_response&) (*this) = b; - this->realm = b.realm; + basic_auth_fail_response(const basic_auth_fail_response& other) = default; + basic_auth_fail_response(basic_auth_fail_response&& other) noexcept = default; + basic_auth_fail_response& operator=(const basic_auth_fail_response& b) = default; + basic_auth_fail_response& operator=(basic_auth_fail_response&& b) noexcept = default; - return *this; - } - - basic_auth_fail_response& operator=(basic_auth_fail_response&& b) - { - if (this == &b) return *this; - - (string_response&) (*this) = std::move(b); - this->realm = std::move(b.realm); - - return *this; - } - - ~basic_auth_fail_response() - { - } + ~basic_auth_fail_response() = default; int enqueue_response(MHD_Connection* connection, MHD_Response* response); private: - std::string realm; + std::string realm = ""; }; } diff --git a/src/httpserver/create_webserver.hpp b/src/httpserver/create_webserver.hpp index 596d7b33..895f8625 100644 --- a/src/httpserver/create_webserver.hpp +++ b/src/httpserver/create_webserver.hpp @@ -25,6 +25,7 @@ #ifndef _CREATE_WEBSERVER_HPP_ #define _CREATE_WEBSERVER_HPP_ +#include #include #include "httpserver/http_utils.hpp" #include "httpserver/http_response.hpp" @@ -45,263 +46,14 @@ typedef void(*log_error_ptr)(const std::string&); class create_webserver { public: - create_webserver(): - _port(DEFAULT_WS_PORT), - _start_method(http::http_utils::INTERNAL_SELECT), - _max_threads(0), - _max_connections(0), - _memory_limit(0), - _content_size_limit(static_cast(-1)), - _connection_timeout(DEFAULT_WS_TIMEOUT), - _per_IP_connection_limit(0), - _log_access(0x0), - _log_error(0x0), - _validator(0x0), - _unescaper(0x0), - _bind_address(0x0), - _bind_socket(0), - _max_thread_stack_size(0), - _use_ssl(false), - _use_ipv6(false), - _debug(false), - _pedantic(false), - _https_mem_key(""), - _https_mem_cert(""), - _https_mem_trust(""), - _https_priorities(""), - _cred_type(http::http_utils::NONE), - _digest_auth_random(""), - _nonce_nc_size(0), - _default_policy(http::http_utils::ACCEPT), - _basic_auth_enabled(true), - _digest_auth_enabled(true), - _regex_checking(true), - _ban_system_enabled(true), - _post_process_enabled(true), - _deferred_enabled(false), - _single_resource(false), - _tcp_nodelay(false), - _not_found_resource(0x0), - _method_not_allowed_resource(0x0), - _internal_error_resource(0x0) - { - } - - create_webserver(const create_webserver& b): - _port(b._port), - _start_method(b._start_method), - _max_threads(b._max_threads), - _max_connections(b._max_connections), - _memory_limit(b._memory_limit), - _content_size_limit(b._content_size_limit), - _connection_timeout(b._connection_timeout), - _per_IP_connection_limit(b._per_IP_connection_limit), - _log_access(b._log_access), - _log_error(b._log_error), - _validator(b._validator), - _unescaper(b._unescaper), - _bind_address(b._bind_address), - _bind_socket(b._bind_socket), - _max_thread_stack_size(b._max_thread_stack_size), - _use_ssl(b._use_ssl), - _use_ipv6(b._use_ipv6), - _debug(b._debug), - _pedantic(b._pedantic), - _https_mem_key(b._https_mem_key), - _https_mem_cert(b._https_mem_cert), - _https_mem_trust(b._https_mem_trust), - _https_priorities(b._https_priorities), - _cred_type(b._cred_type), - _digest_auth_random(b._digest_auth_random), - _nonce_nc_size(b._nonce_nc_size), - _default_policy(b._default_policy), - _basic_auth_enabled(b._basic_auth_enabled), - _digest_auth_enabled(b._digest_auth_enabled), - _regex_checking(b._regex_checking), - _ban_system_enabled(b._ban_system_enabled), - _post_process_enabled(b._post_process_enabled), - _deferred_enabled(b._deferred_enabled), - _single_resource(b._single_resource), - _tcp_nodelay(b._tcp_nodelay), - _not_found_resource(b._not_found_resource), - _method_not_allowed_resource(b._method_not_allowed_resource), - _internal_error_resource(b._internal_error_resource) - { - } - - create_webserver(create_webserver&& b): - _port(b._port), - _start_method(b._start_method), - _max_threads(b._max_threads), - _max_connections(b._max_connections), - _memory_limit(b._memory_limit), - _content_size_limit(b._content_size_limit), - _connection_timeout(b._connection_timeout), - _per_IP_connection_limit(b._per_IP_connection_limit), - _log_access(std::move(b._log_access)), - _log_error(std::move(b._log_error)), - _validator(std::move(b._validator)), - _unescaper(std::move(b._unescaper)), - _bind_address(std::move(b._bind_address)), - _bind_socket(b._bind_socket), - _max_thread_stack_size(b._max_thread_stack_size), - _use_ssl(b._use_ssl), - _use_ipv6(b._use_ipv6), - _debug(b._debug), - _pedantic(b._pedantic), - _https_mem_key(std::move(b._https_mem_key)), - _https_mem_cert(std::move(b._https_mem_cert)), - _https_mem_trust(std::move(b._https_mem_trust)), - _https_priorities(std::move(b._https_priorities)), - _cred_type(b._cred_type), - _digest_auth_random(std::move(b._digest_auth_random)), - _nonce_nc_size(b._nonce_nc_size), - _default_policy(b._default_policy), - _basic_auth_enabled(b._basic_auth_enabled), - _digest_auth_enabled(b._digest_auth_enabled), - _regex_checking(b._regex_checking), - _ban_system_enabled(b._ban_system_enabled), - _post_process_enabled(b._post_process_enabled), - _deferred_enabled(b._deferred_enabled), - _single_resource(b._single_resource), - _tcp_nodelay(b._tcp_nodelay), - _not_found_resource(std::move(b._not_found_resource)), - _method_not_allowed_resource(std::move(b._method_not_allowed_resource)), - _internal_error_resource(std::move(b._internal_error_resource)) - { - } - - create_webserver& operator=(const create_webserver& b) - { - if (this == &b) return *this; - - this->_port = b._port; - this->_start_method = b._start_method; - this->_max_threads = b._max_threads; - this->_max_connections = b._max_connections; - this->_memory_limit = b._memory_limit; - this->_content_size_limit = b._content_size_limit; - this->_connection_timeout = b._connection_timeout; - this->_per_IP_connection_limit = b._per_IP_connection_limit; - this->_log_access = b._log_access; - this->_log_error = b._log_error; - this->_validator = b._validator; - this->_unescaper = b._unescaper; - this->_bind_address = b._bind_address; - this->_bind_socket = b._bind_socket; - this->_max_thread_stack_size = b._max_thread_stack_size; - this->_use_ssl = b._use_ssl; - this->_use_ipv6 = b._use_ipv6; - this->_debug = b._debug; - this->_pedantic = b._pedantic; - this->_https_mem_key = b._https_mem_key; - this->_https_mem_cert = b._https_mem_cert; - this->_https_mem_trust = b._https_mem_trust; - this->_https_priorities = b._https_priorities; - this->_cred_type = b._cred_type; - this->_digest_auth_random = b._digest_auth_random; - this->_nonce_nc_size = b._nonce_nc_size; - this->_default_policy = b._default_policy; - this->_basic_auth_enabled = b._basic_auth_enabled; - this->_digest_auth_enabled = b._digest_auth_enabled; - this->_regex_checking = b._regex_checking; - this->_ban_system_enabled = b._ban_system_enabled; - this->_post_process_enabled = b._post_process_enabled; - this->_deferred_enabled = b._deferred_enabled; - this->_single_resource = b._single_resource; - this->_tcp_nodelay = b._tcp_nodelay; - this->_not_found_resource = b._not_found_resource; - this->_method_not_allowed_resource = b._method_not_allowed_resource; - this->_internal_error_resource = b._internal_error_resource; - - return *this; - } - - create_webserver& operator=(create_webserver&& b) - { - if (this == &b) return *this; - - this->_port = b._port; - this->_start_method = b._start_method; - this->_max_threads = b._max_threads; - this->_max_connections = b._max_connections; - this->_memory_limit = b._memory_limit; - this->_content_size_limit = b._content_size_limit; - this->_connection_timeout = b._connection_timeout; - this->_per_IP_connection_limit = b._per_IP_connection_limit; - this->_log_access = std::move(b._log_access); - this->_log_error = std::move(b._log_error); - this->_validator = std::move(b._validator); - this->_unescaper = std::move(b._unescaper); - this->_bind_address = std::move(b._bind_address); - this->_bind_socket = b._bind_socket; - this->_max_thread_stack_size = b._max_thread_stack_size; - this->_use_ssl = b._use_ssl; - this->_use_ipv6 = b._use_ipv6; - this->_debug = b._debug; - this->_pedantic = b._pedantic; - this->_https_mem_key = std::move(b._https_mem_key); - this->_https_mem_cert = std::move(b._https_mem_cert); - this->_https_mem_trust = std::move(b._https_mem_trust); - this->_https_priorities = std::move(b._https_priorities); - this->_cred_type = b._cred_type; - this->_digest_auth_random = std::move(b._digest_auth_random); - this->_nonce_nc_size = b._nonce_nc_size; - this->_default_policy = b._default_policy; - this->_basic_auth_enabled = b._basic_auth_enabled; - this->_digest_auth_enabled = b._digest_auth_enabled; - this->_regex_checking = b._regex_checking; - this->_ban_system_enabled = b._ban_system_enabled; - this->_post_process_enabled = b._post_process_enabled; - this->_deferred_enabled = b._deferred_enabled; - this->_single_resource = b._single_resource; - this->_tcp_nodelay = b._tcp_nodelay; - this->_not_found_resource = std::move(b._not_found_resource); - this->_method_not_allowed_resource = std::move(b._method_not_allowed_resource); - this->_internal_error_resource = std::move(b._internal_error_resource); - - return *this; - } + create_webserver() = default; + create_webserver(const create_webserver& b) = default; + create_webserver(create_webserver&& b) noexcept = default; + create_webserver& operator=(const create_webserver& b) = default; + create_webserver& operator=(create_webserver&& b) noexcept = default; explicit create_webserver(uint16_t port): - _port(port), - _start_method(http::http_utils::INTERNAL_SELECT), - _max_threads(0), - _max_connections(0), - _memory_limit(0), - _content_size_limit(static_cast(-1)), - _connection_timeout(DEFAULT_WS_TIMEOUT), - _per_IP_connection_limit(0), - _log_access(0x0), - _log_error(0x0), - _validator(0x0), - _unescaper(0x0), - _bind_address(0x0), - _bind_socket(0), - _max_thread_stack_size(0), - _use_ssl(false), - _use_ipv6(false), - _debug(false), - _pedantic(false), - _https_mem_key(""), - _https_mem_cert(""), - _https_mem_trust(""), - _https_priorities(""), - _cred_type(http::http_utils::NONE), - _digest_auth_random(""), - _nonce_nc_size(0), - _default_policy(http::http_utils::ACCEPT), - _basic_auth_enabled(true), - _digest_auth_enabled(true), - _regex_checking(true), - _ban_system_enabled(true), - _post_process_enabled(true), - _deferred_enabled(false), - _single_resource(false), - _tcp_nodelay(false), - _not_found_resource(0x0), - _method_not_allowed_resource(0x0), - _internal_error_resource(0x0) + _port(port) { } @@ -500,44 +252,44 @@ class create_webserver } private: - uint16_t _port; - http::http_utils::start_method_T _start_method; - int _max_threads; - int _max_connections; - int _memory_limit; - size_t _content_size_limit; - int _connection_timeout; - int _per_IP_connection_limit; - log_access_ptr _log_access; - log_error_ptr _log_error; - validator_ptr _validator; - unescaper_ptr _unescaper; - const struct sockaddr* _bind_address; - int _bind_socket; - int _max_thread_stack_size; - bool _use_ssl; - bool _use_ipv6; - bool _debug; - bool _pedantic; - std::string _https_mem_key; - std::string _https_mem_cert; - std::string _https_mem_trust; - std::string _https_priorities; - http::http_utils::cred_type_T _cred_type; - std::string _digest_auth_random; - int _nonce_nc_size; - http::http_utils::policy_T _default_policy; - bool _basic_auth_enabled; - bool _digest_auth_enabled; - bool _regex_checking; - bool _ban_system_enabled; - bool _post_process_enabled; - bool _deferred_enabled; - bool _single_resource; - bool _tcp_nodelay; - render_ptr _not_found_resource; - render_ptr _method_not_allowed_resource; - render_ptr _internal_error_resource; + uint16_t _port = DEFAULT_WS_PORT; + http::http_utils::start_method_T _start_method = http::http_utils::INTERNAL_SELECT; + int _max_threads = 0; + int _max_connections = 0; + int _memory_limit = 0; + size_t _content_size_limit = std::numeric_limits::max(); + int _connection_timeout = DEFAULT_WS_TIMEOUT; + int _per_IP_connection_limit = 0; + log_access_ptr _log_access = nullptr; + log_error_ptr _log_error = nullptr; + validator_ptr _validator = nullptr; + unescaper_ptr _unescaper = nullptr; + const struct sockaddr* _bind_address = nullptr; + int _bind_socket = 0; + int _max_thread_stack_size = 0; + bool _use_ssl = false; + bool _use_ipv6 = false; + bool _debug = false; + bool _pedantic = false; + std::string _https_mem_key = ""; + std::string _https_mem_cert = ""; + std::string _https_mem_trust = ""; + std::string _https_priorities = ""; + http::http_utils::cred_type_T _cred_type = http::http_utils::NONE; + std::string _digest_auth_random = ""; + int _nonce_nc_size = 0; + http::http_utils::policy_T _default_policy = http::http_utils::ACCEPT; + bool _basic_auth_enabled = true; + bool _digest_auth_enabled = true; + bool _regex_checking = true; + bool _ban_system_enabled = true; + bool _post_process_enabled = true; + bool _deferred_enabled = false; + bool _single_resource = false; + bool _tcp_nodelay = false; + render_ptr _not_found_resource = nullptr; + render_ptr _method_not_allowed_resource = nullptr; + render_ptr _internal_error_resource = nullptr; friend class webserver; }; diff --git a/src/httpserver/deferred_response.hpp b/src/httpserver/deferred_response.hpp index 02cc745d..6da0f18b 100644 --- a/src/httpserver/deferred_response.hpp +++ b/src/httpserver/deferred_response.hpp @@ -53,45 +53,12 @@ class deferred_response : public string_response { } - deferred_response(const deferred_response& other): - string_response(other), - cycle_callback(other.cycle_callback), - closure_data(other.closure_data) - { - } - - deferred_response(deferred_response&& other) noexcept: - string_response(std::move(other)), - cycle_callback(std::move(other.cycle_callback)), - closure_data(std::move(other.closure_data)) - { - } + deferred_response(const deferred_response& other) = default; + deferred_response(deferred_response&& other) noexcept = default; + deferred_response& operator=(const deferred_response& b) = default; + deferred_response& operator=(deferred_response&& b) noexcept = default; - deferred_response& operator=(const deferred_response& b) - { - if (this == &b) return *this; - - (string_response&) (*this) = b; - this->cycle_callback = b.cycle_callback; - this->closure_data = b.closure_data; - - return *this; - } - - deferred_response& operator=(deferred_response&& b) - { - if (this == &b) return *this; - - (string_response&) (*this) = std::move(b); - this->cycle_callback = std::move(b.cycle_callback); - this->closure_data = std::move(b.closure_data); - - return *this; - } - - ~deferred_response() - { - } + ~deferred_response() = default; MHD_Response* get_raw_response() { diff --git a/src/httpserver/digest_auth_fail_response.hpp b/src/httpserver/digest_auth_fail_response.hpp index 63d02378..0f95136a 100644 --- a/src/httpserver/digest_auth_fail_response.hpp +++ b/src/httpserver/digest_auth_fail_response.hpp @@ -33,13 +33,7 @@ namespace httpserver class digest_auth_fail_response : public string_response { public: - digest_auth_fail_response(): - string_response(), - realm(""), - opaque(""), - reload_nonce(false) - { - } + digest_auth_fail_response() = default; digest_auth_fail_response( const std::string& content, @@ -56,56 +50,19 @@ class digest_auth_fail_response : public string_response { } - digest_auth_fail_response(const digest_auth_fail_response& other): - string_response(other), - realm(other.realm), - opaque(other.opaque), - reload_nonce(other.reload_nonce) - { - } - - digest_auth_fail_response(digest_auth_fail_response&& other) noexcept: - string_response(std::move(other)), - realm(std::move(other.realm)), - opaque(std::move(other.opaque)), - reload_nonce(other.reload_nonce) - { - } - - digest_auth_fail_response& operator=(const digest_auth_fail_response& b) - { - if (this == &b) return *this; - - (string_response&) (*this) = b; - this->realm = b.realm; - this->opaque = b.opaque; - this->reload_nonce = b.reload_nonce; + digest_auth_fail_response(const digest_auth_fail_response& other) = default; + digest_auth_fail_response(digest_auth_fail_response&& other) noexcept = default; + digest_auth_fail_response& operator=(const digest_auth_fail_response& b) = default; + digest_auth_fail_response& operator=(digest_auth_fail_response&& b) noexcept = default; - return *this; - } - - digest_auth_fail_response& operator=(digest_auth_fail_response&& b) - { - if (this == &b) return *this; - - (string_response&) (*this) = std::move(b); - this->realm = std::move(b.realm); - this->opaque = std::move(b.opaque); - this->reload_nonce = b.reload_nonce; - - return *this; - } - - ~digest_auth_fail_response() - { - } + ~digest_auth_fail_response() = default; int enqueue_response(MHD_Connection* connection, MHD_Response* response); private: - std::string realm; - std::string opaque; - bool reload_nonce; + std::string realm = ""; + std::string opaque = ""; + bool reload_nonce = false; }; } diff --git a/src/httpserver/file_response.hpp b/src/httpserver/file_response.hpp index 1192d91a..125c4dcb 100644 --- a/src/httpserver/file_response.hpp +++ b/src/httpserver/file_response.hpp @@ -33,11 +33,7 @@ namespace httpserver class file_response : public http_response { public: - file_response(): - http_response(), - filename("") - { - } + file_response() = default; explicit file_response( const std::string& filename, @@ -49,46 +45,18 @@ class file_response : public http_response { } - file_response(const file_response& other): - http_response(other), - filename(other.filename) - { - } - - file_response(file_response&& other) noexcept: - http_response(std::move(other)), - filename(std::move(other.filename)) - { - } - - file_response& operator=(const file_response& b) - { - if (this == &b) return *this; - - (http_response&) (*this) = b; - this->filename = b.filename; - - return *this; - } - - file_response& operator=(file_response&& b) - { - if (this == &b) return *this; + file_response(const file_response& other) = default; + file_response(file_response&& other) noexcept = default; - (http_response&) (*this) = std::move(b); - this->filename = std::move(b.filename); + file_response& operator=(const file_response& b) = default; + file_response& operator=(file_response&& b) noexcept = default; - return *this; - } - - ~file_response() - { - } + ~file_response() = default; MHD_Response* get_raw_response(); private: - std::string filename; + std::string filename = ""; }; } diff --git a/src/httpserver/http_request.hpp b/src/httpserver/http_request.hpp index 632fe06d..dbc88187 100644 --- a/src/httpserver/http_request.hpp +++ b/src/httpserver/http_request.hpp @@ -25,6 +25,7 @@ #ifndef _HTTP_REQUEST_HPP_ #define _HTTP_REQUEST_HPP_ +#include #include #include #include @@ -216,17 +217,9 @@ class http_request /** * Default constructor of the class. It is a specific responsibility of apis to initialize this type of objects. **/ - http_request(): - content(""), - content_size_limit(static_cast(-1)), - underlying_connection(0x0), - unescaper(0x0) - { - } + http_request() = default; http_request(MHD_Connection* underlying_connection, unescaper_ptr unescaper): - content(""), - content_size_limit(static_cast(-1)), underlying_connection(underlying_connection), unescaper(unescaper) { @@ -236,69 +229,22 @@ class http_request * Copy constructor. * @param b http_request b to copy attributes from. **/ - http_request(const http_request& b): - path(b.path), - method(b.method), - args(b.args), - content(b.content), - content_size_limit(b.content_size_limit), - version(b.version), - underlying_connection(b.underlying_connection), - unescaper(b.unescaper) - { - } - - http_request(http_request&& b) noexcept: - path(std::move(b.path)), - method(std::move(b.method)), - args(std::move(b.args)), - content(std::move(b.content)), - content_size_limit(b.content_size_limit), - version(std::move(b.version)), - underlying_connection(std::move(b.underlying_connection)) - { - } - - http_request& operator=(const http_request& b) - { - if (this == &b) return *this; - - this->path = b.path; - this->method = b.method; - this->args = b.args; - this->content = b.content; - this->content_size_limit = b.content_size_limit; - this->version = b.version; - this->underlying_connection = b.underlying_connection; - - return *this; - } + http_request(const http_request& b) = default; + http_request(http_request&& b) noexcept = default; - http_request& operator=(http_request&& b) - { - if (this == &b) return *this; - - this->path = std::move(b.path); - this->method = std::move(b.method); - this->args = std::move(b.args); - this->content = std::move(b.content); - this->content_size_limit = b.content_size_limit; - this->version = std::move(b.version); - this->underlying_connection = std::move(b.underlying_connection); - - return *this; - } + http_request& operator=(const http_request& b) = default; + http_request& operator=(http_request&& b) noexcept = default; std::string path; std::string method; std::map args; - std::string content; - size_t content_size_limit; + std::string content = ""; + size_t content_size_limit = std::numeric_limits::max(); std::string version; - struct MHD_Connection* underlying_connection; + struct MHD_Connection* underlying_connection = nullptr; - unescaper_ptr unescaper; + unescaper_ptr unescaper = nullptr; static int build_request_header(void *cls, enum MHD_ValueKind kind, const char *key, const char *value diff --git a/src/httpserver/http_resource.hpp b/src/httpserver/http_resource.hpp index ae5e78d4..48e1c4c9 100644 --- a/src/httpserver/http_resource.hpp +++ b/src/httpserver/http_resource.hpp @@ -59,10 +59,7 @@ class http_resource /** * Class destructor **/ - virtual ~http_resource() - { - allowed_methods.clear(); - } + virtual ~http_resource() = default; /** * Method used to answer to a generic request @@ -219,25 +216,10 @@ class http_resource /** * Copy constructor **/ - http_resource(const http_resource& b) : allowed_methods(b.allowed_methods) { } - - http_resource(http_resource&& b) noexcept: allowed_methods(std::move(b.allowed_methods)) { } - - http_resource& operator=(const http_resource& b) - { - if (this == &b) return *this; - - allowed_methods = b.allowed_methods; - return (*this); - } - - http_resource& operator=(http_resource&& b) - { - if (this == &b) return *this; - - allowed_methods = std::move(b.allowed_methods); - return (*this); - } + http_resource(const http_resource& b) = default; + http_resource(http_resource&& b) noexcept = default; + http_resource& operator=(const http_resource& b) = default; + http_resource& operator=(http_resource&& b) noexcept = default; private: friend class webserver; @@ -245,5 +227,5 @@ class http_resource std::map allowed_methods; }; -}; +} #endif diff --git a/src/httpserver/http_response.hpp b/src/httpserver/http_response.hpp index b7f9b9a9..9e35ca20 100644 --- a/src/httpserver/http_response.hpp +++ b/src/httpserver/http_response.hpp @@ -45,10 +45,7 @@ namespace httpserver class http_response { public: - http_response(): - response_code(-1) - { - } + http_response() = default; explicit http_response(int response_code, const std::string& content_type): response_code(response_code) @@ -60,49 +57,13 @@ class http_response * Copy constructor * @param b The http_response object to copy attributes value from. **/ - http_response(const http_response& b): - response_code(b.response_code), - headers(b.headers), - footers(b.footers), - cookies(b.cookies) - { - } - - http_response(http_response&& other) noexcept: - response_code(other.response_code), - headers(std::move(other.headers)), - footers(std::move(other.footers)), - cookies(std::move(other.cookies)) - { - } - - http_response& operator=(const http_response& b) - { - if (this == &b) return *this; + http_response(const http_response& b) = default; + http_response(http_response&& b) noexcept = default; - this->response_code = b.response_code; - this->headers = b.headers; - this->footers = b.footers; - this->cookies = b.cookies; + http_response& operator=(const http_response& b) = default; + http_response& operator=(http_response&& b) noexcept = default; - return *this; - } - - http_response& operator=(http_response&& b) - { - if (this == &b) return *this; - - this->response_code = b.response_code; - this->headers = std::move(b.headers); - this->footers = std::move(b.footers); - this->cookies = std::move(b.cookies); - - return *this; - } - - virtual ~http_response() - { - } + virtual ~http_response() = default; /** * Method used to get a specified header defined for the response @@ -183,14 +144,13 @@ class http_response virtual int enqueue_response(MHD_Connection* connection, MHD_Response* response); protected: - std::string content; - int response_code; + int response_code = -1; std::map headers; std::map footers; std::map cookies; - friend std::ostream &operator<< (std::ostream &os, const http_response &r); + friend std::ostream &operator<< (std::ostream &os, const http_response &r); }; std::ostream &operator<< (std::ostream &os, const http_response &r); diff --git a/src/httpserver/string_response.hpp b/src/httpserver/string_response.hpp index 0397f38c..690fc049 100644 --- a/src/httpserver/string_response.hpp +++ b/src/httpserver/string_response.hpp @@ -33,11 +33,7 @@ namespace httpserver class string_response : public http_response { public: - string_response(): - http_response(), - content("") - { - } + string_response() = default; explicit string_response( const std::string& content, @@ -49,46 +45,18 @@ class string_response : public http_response { } - string_response(const string_response& other): - http_response(other), - content(other.content) - { - } - - string_response(string_response&& other) noexcept: - http_response(std::move(other)), - content(std::move(other.content)) - { - } - - string_response& operator=(const string_response& b) - { - if (this == &b) return *this; - - (http_response&) (*this) = b; - this->content = b.content; - - return *this; - } - - string_response& operator=(string_response&& b) - { - if (this == &b) return *this; + string_response(const string_response& other) = default; + string_response(string_response&& other) noexcept = default; - (http_response&) (*this) = std::move(b); - this->content = std::move(b.content); + string_response& operator=(const string_response& b) = default; + string_response& operator=(string_response&& b) noexcept = default; - return *this; - } - - ~string_response() - { - } + ~string_response() = default; MHD_Response* get_raw_response(); private: - std::string content; + std::string content = ""; }; } From 094bc5c3e3e52c2705af5a5f4838e3521dd2f549 Mon Sep 17 00:00:00 2001 From: bcsgh <33939446+bcsgh@users.noreply.github.com> Date: Sun, 23 Feb 2020 18:43:05 -0800 Subject: [PATCH 02/11] Remove some noexcept's from operator=(T&&) that newer versions of clang reject. --- src/httpserver/create_webserver.hpp | 2 +- src/httpserver/http_request.hpp | 2 +- src/httpserver/string_response.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/httpserver/create_webserver.hpp b/src/httpserver/create_webserver.hpp index 895f8625..fd256acd 100644 --- a/src/httpserver/create_webserver.hpp +++ b/src/httpserver/create_webserver.hpp @@ -50,7 +50,7 @@ class create_webserver create_webserver(const create_webserver& b) = default; create_webserver(create_webserver&& b) noexcept = default; create_webserver& operator=(const create_webserver& b) = default; - create_webserver& operator=(create_webserver&& b) noexcept = default; + create_webserver& operator=(create_webserver&& b) = default; explicit create_webserver(uint16_t port): _port(port) diff --git a/src/httpserver/http_request.hpp b/src/httpserver/http_request.hpp index dbc88187..7251676c 100644 --- a/src/httpserver/http_request.hpp +++ b/src/httpserver/http_request.hpp @@ -233,7 +233,7 @@ class http_request http_request(http_request&& b) noexcept = default; http_request& operator=(const http_request& b) = default; - http_request& operator=(http_request&& b) noexcept = default; + http_request& operator=(http_request&& b) = default; std::string path; std::string method; diff --git a/src/httpserver/string_response.hpp b/src/httpserver/string_response.hpp index 690fc049..87f12c67 100644 --- a/src/httpserver/string_response.hpp +++ b/src/httpserver/string_response.hpp @@ -49,7 +49,7 @@ class string_response : public http_response string_response(string_response&& other) noexcept = default; string_response& operator=(const string_response& b) = default; - string_response& operator=(string_response&& b) noexcept = default; + string_response& operator=(string_response&& b) = default; ~string_response() = default; From f8c6176f64ec1f3bd6b92f30335e4a64d5fa94b6 Mon Sep 17 00:00:00 2001 From: bcsgh <33939446+bcsgh@users.noreply.github.com> Date: Sun, 23 Feb 2020 19:09:12 -0800 Subject: [PATCH 03/11] Remove more noexcept's from operator=(T&&) that newer versions of clang reject. --- src/httpserver/basic_auth_fail_response.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/httpserver/basic_auth_fail_response.hpp b/src/httpserver/basic_auth_fail_response.hpp index ba79c6f8..c7e2d476 100644 --- a/src/httpserver/basic_auth_fail_response.hpp +++ b/src/httpserver/basic_auth_fail_response.hpp @@ -49,7 +49,7 @@ class basic_auth_fail_response : public string_response basic_auth_fail_response(const basic_auth_fail_response& other) = default; basic_auth_fail_response(basic_auth_fail_response&& other) noexcept = default; basic_auth_fail_response& operator=(const basic_auth_fail_response& b) = default; - basic_auth_fail_response& operator=(basic_auth_fail_response&& b) noexcept = default; + basic_auth_fail_response& operator=(basic_auth_fail_response&& b) = default; ~basic_auth_fail_response() = default; From db6f556e6dc75cace2b884941db4cad7d8aa5e4a Mon Sep 17 00:00:00 2001 From: bcsgh <33939446+bcsgh@users.noreply.github.com> Date: Sun, 23 Feb 2020 19:16:34 -0800 Subject: [PATCH 04/11] Remove more noexcept's from operator=(T&&) that newer versions of clang reject. --- src/httpserver/digest_auth_fail_response.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/httpserver/digest_auth_fail_response.hpp b/src/httpserver/digest_auth_fail_response.hpp index 0f95136a..292f477b 100644 --- a/src/httpserver/digest_auth_fail_response.hpp +++ b/src/httpserver/digest_auth_fail_response.hpp @@ -53,7 +53,7 @@ class digest_auth_fail_response : public string_response digest_auth_fail_response(const digest_auth_fail_response& other) = default; digest_auth_fail_response(digest_auth_fail_response&& other) noexcept = default; digest_auth_fail_response& operator=(const digest_auth_fail_response& b) = default; - digest_auth_fail_response& operator=(digest_auth_fail_response&& b) noexcept = default; + digest_auth_fail_response& operator=(digest_auth_fail_response&& b) = default; ~digest_auth_fail_response() = default; From e5116a90df726b33f972f495d5065a99f28df5f6 Mon Sep 17 00:00:00 2001 From: bcsgh <33939446+bcsgh@users.noreply.github.com> Date: Sun, 23 Feb 2020 19:54:50 -0800 Subject: [PATCH 05/11] Remove more noexcept's from operator=(T&&) that newer versions of clang reject. --- src/httpserver/deferred_response.hpp | 2 +- src/httpserver/file_response.hpp | 2 +- src/httpserver/http_resource.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/httpserver/deferred_response.hpp b/src/httpserver/deferred_response.hpp index 6da0f18b..32a97bfc 100644 --- a/src/httpserver/deferred_response.hpp +++ b/src/httpserver/deferred_response.hpp @@ -56,7 +56,7 @@ class deferred_response : public string_response deferred_response(const deferred_response& other) = default; deferred_response(deferred_response&& other) noexcept = default; deferred_response& operator=(const deferred_response& b) = default; - deferred_response& operator=(deferred_response&& b) noexcept = default; + deferred_response& operator=(deferred_response&& b) = default; ~deferred_response() = default; diff --git a/src/httpserver/file_response.hpp b/src/httpserver/file_response.hpp index 125c4dcb..cb80c114 100644 --- a/src/httpserver/file_response.hpp +++ b/src/httpserver/file_response.hpp @@ -49,7 +49,7 @@ class file_response : public http_response file_response(file_response&& other) noexcept = default; file_response& operator=(const file_response& b) = default; - file_response& operator=(file_response&& b) noexcept = default; + file_response& operator=(file_response&& b) = default; ~file_response() = default; diff --git a/src/httpserver/http_resource.hpp b/src/httpserver/http_resource.hpp index 48e1c4c9..42f73498 100644 --- a/src/httpserver/http_resource.hpp +++ b/src/httpserver/http_resource.hpp @@ -219,7 +219,7 @@ class http_resource http_resource(const http_resource& b) = default; http_resource(http_resource&& b) noexcept = default; http_resource& operator=(const http_resource& b) = default; - http_resource& operator=(http_resource&& b) noexcept = default; + http_resource& operator=(http_resource&& b) = default; private: friend class webserver; From ac406203b8f083cac469456131ce7a0e8fec85ea Mon Sep 17 00:00:00 2001 From: bcsgh <33939446+bcsgh@users.noreply.github.com> Date: Sun, 23 Feb 2020 23:25:26 -0800 Subject: [PATCH 06/11] Revert some incedental changes for now. --- src/httpserver/create_webserver.hpp | 19 +++++++++---------- src/httpserver/http_response.hpp | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/httpserver/create_webserver.hpp b/src/httpserver/create_webserver.hpp index fd256acd..af1b93b6 100644 --- a/src/httpserver/create_webserver.hpp +++ b/src/httpserver/create_webserver.hpp @@ -25,7 +25,6 @@ #ifndef _CREATE_WEBSERVER_HPP_ #define _CREATE_WEBSERVER_HPP_ -#include #include #include "httpserver/http_utils.hpp" #include "httpserver/http_response.hpp" @@ -257,14 +256,14 @@ class create_webserver int _max_threads = 0; int _max_connections = 0; int _memory_limit = 0; - size_t _content_size_limit = std::numeric_limits::max(); + size_t _content_size_limit = static_cast(-1); int _connection_timeout = DEFAULT_WS_TIMEOUT; int _per_IP_connection_limit = 0; - log_access_ptr _log_access = nullptr; - log_error_ptr _log_error = nullptr; - validator_ptr _validator = nullptr; - unescaper_ptr _unescaper = nullptr; - const struct sockaddr* _bind_address = nullptr; + log_access_ptr _log_access = 0x0; + log_error_ptr _log_error = 0x0; + validator_ptr _validator = 0x0; + unescaper_ptr _unescaper = 0x0; + const struct sockaddr* _bind_address = 0x0; int _bind_socket = 0; int _max_thread_stack_size = 0; bool _use_ssl = false; @@ -287,9 +286,9 @@ class create_webserver bool _deferred_enabled = false; bool _single_resource = false; bool _tcp_nodelay = false; - render_ptr _not_found_resource = nullptr; - render_ptr _method_not_allowed_resource = nullptr; - render_ptr _internal_error_resource = nullptr; + render_ptr _not_found_resource = 0x0; + render_ptr _method_not_allowed_resource = 0x0; + render_ptr _internal_error_resource = 0x0; friend class webserver; }; diff --git a/src/httpserver/http_response.hpp b/src/httpserver/http_response.hpp index 9e35ca20..755d6c7a 100644 --- a/src/httpserver/http_response.hpp +++ b/src/httpserver/http_response.hpp @@ -150,7 +150,7 @@ class http_response std::map footers; std::map cookies; - friend std::ostream &operator<< (std::ostream &os, const http_response &r); + friend std::ostream &operator<< (std::ostream &os, const http_response &r); }; std::ostream &operator<< (std::ostream &os, const http_response &r); From 90f738a0afa2bce0b5175cb7a60fcfe29ac148dc Mon Sep 17 00:00:00 2001 From: bcsgh <33939446+bcsgh@users.noreply.github.com> Date: Mon, 24 Feb 2020 07:55:38 -0800 Subject: [PATCH 07/11] Revert some incedental changes for now (http_request). --- src/httpserver/http_request.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/httpserver/http_request.hpp b/src/httpserver/http_request.hpp index 7251676c..c96bebb6 100644 --- a/src/httpserver/http_request.hpp +++ b/src/httpserver/http_request.hpp @@ -25,7 +25,6 @@ #ifndef _HTTP_REQUEST_HPP_ #define _HTTP_REQUEST_HPP_ -#include #include #include #include @@ -239,12 +238,12 @@ class http_request std::string method; std::map args; std::string content = ""; - size_t content_size_limit = std::numeric_limits::max(); + size_t content_size_limit = static_cast(-1); std::string version; - struct MHD_Connection* underlying_connection = nullptr; + struct MHD_Connection* underlying_connection = 0x0; - unescaper_ptr unescaper = nullptr; + unescaper_ptr unescaper = 0x0; static int build_request_header(void *cls, enum MHD_ValueKind kind, const char *key, const char *value From 9fee8a8e1b703e6fafd3f1096edf06eedf6ddf39 Mon Sep 17 00:00:00 2001 From: bcsgh <33939446+bcsgh@users.noreply.github.com> Date: Mon, 24 Feb 2020 14:48:25 -0800 Subject: [PATCH 08/11] Refactor another class that got missed in the first pass. --- src/httpserver/details/modded_request.hpp | 79 ++++------------------- 1 file changed, 12 insertions(+), 67 deletions(-) diff --git a/src/httpserver/details/modded_request.hpp b/src/httpserver/details/modded_request.hpp index df99ce8e..07d5f814 100644 --- a/src/httpserver/details/modded_request.hpp +++ b/src/httpserver/details/modded_request.hpp @@ -33,80 +33,25 @@ namespace details struct modded_request { - struct MHD_PostProcessor *pp; - std::string* complete_uri; - std::string* standardized_url; - webserver* ws; + struct MHD_PostProcessor *pp = 0x0; + std::string* complete_uri = 0x0; + std::string* standardized_url = 0x0; + webserver* ws = 0x0; const std::shared_ptr (httpserver::http_resource::*callback)(const httpserver::http_request&); - http_request* dhr; + http_request* dhr = 0x0; std::shared_ptr dhrs; - bool second; - bool has_body; - - modded_request(): - pp(0x0), - complete_uri(0x0), - standardized_url(0x0), - ws(0x0), - dhr(0x0), - second(false), - has_body(false) - { - } - - modded_request(const modded_request& b): - pp(b.pp), - complete_uri(b.complete_uri), - standardized_url(b.standardized_url), - ws(b.ws), - dhr(b.dhr), - second(b.second), - has_body(b.has_body) - { - } + bool second = false; + bool has_body = false; - modded_request(modded_request&& b): - pp(std::move(b.pp)), - complete_uri(std::move(b.complete_uri)), - standardized_url(std::move(b.standardized_url)), - ws(std::move(b.ws)), - dhr(std::move(b.dhr)), - second(b.second), - has_body(b.has_body) - { - } + modded_request() = default; - modded_request& operator=(const modded_request& b) - { - if (this == &b) return *this; + modded_request(const modded_request& b) = default; + modded_request(modded_request&& b) = default; - this->pp = b.pp; - this->complete_uri = b.complete_uri; - this->standardized_url = b.standardized_url; - this->ws = b.ws; - this->dhr = b.dhr; - this->second = b.second; - this->has_body = b.has_body; - - return *this; - } - - modded_request& operator=(modded_request&& b) - { - if (this == &b) return *this; - - this->pp = std::move(b.pp); - this->complete_uri = std::move(b.complete_uri); - this->standardized_url = std::move(b.standardized_url); - this->ws = std::move(b.ws); - this->dhr = std::move(b.dhr); - this->second = b.second; - this->has_body = b.has_body; - - return *this; - } + modded_request& operator=(const modded_request& b) = default; + modded_request& operator=(modded_request&& b) = default; ~modded_request() { From 430058499f26d3db7e464a49310d1b9ffb232965 Mon Sep 17 00:00:00 2001 From: bcsgh <33939446+bcsgh@users.noreply.github.com> Date: Mon, 24 Feb 2020 20:15:37 -0800 Subject: [PATCH 09/11] Rename some variable so that all `this->` can be dropped, and do so. --- src/details/http_endpoint.cpp | 64 ++++++++++++------------ src/http_request.cpp | 20 ++++---- src/http_response.cpp | 2 +- src/http_utils.cpp | 12 ++--- src/httpserver/deferred_response.hpp | 2 +- src/httpserver/details/http_endpoint.hpp | 14 +++--- src/httpserver/http_request.hpp | 47 +++++++++-------- src/httpserver/http_resource.hpp | 16 +++--- src/httpserver/http_response.hpp | 16 +++--- src/httpserver/webserver.hpp | 8 +-- src/webserver.cpp | 56 ++++++++++----------- test/integ/basic.cpp | 8 +-- 12 files changed, 132 insertions(+), 133 deletions(-) diff --git a/src/details/http_endpoint.cpp b/src/details/http_endpoint.cpp index 6c2ae1e0..6bf2a6ef 100644 --- a/src/details/http_endpoint.cpp +++ b/src/details/http_endpoint.cpp @@ -36,7 +36,7 @@ http_endpoint::~http_endpoint() { if(reg_compiled) { - regfree(&(this->re_url_normalized)); + regfree(&re_url_normalized); } } @@ -50,7 +50,7 @@ http_endpoint::http_endpoint family_url(family), reg_compiled(false) { - this->url_normalized = use_regex ? "^/" : "/"; + url_normalized = use_regex ? "^/" : "/"; vector parts; #ifdef CASE_INSENSITIVE @@ -77,10 +77,10 @@ http_endpoint::http_endpoint { if(!registration) { - this->url_normalized += (first ? "" : "/") + parts[i]; + url_normalized += (first ? "" : "/") + parts[i]; first = false; - this->url_pieces.push_back(parts[i]); + url_pieces.push_back(parts[i]); continue; } @@ -89,14 +89,14 @@ http_endpoint::http_endpoint { if(first) { - this->url_normalized = (parts[i][0] == '^' ? "" : this->url_normalized) + parts[i]; + url_normalized = (parts[i][0] == '^' ? "" : url_normalized) + parts[i]; first = false; } else { - this->url_normalized += "/" + parts[i]; + url_normalized += "/" + parts[i]; } - this->url_pieces.push_back(parts[i]); + url_pieces.push_back(parts[i]); continue; } @@ -105,23 +105,23 @@ http_endpoint::http_endpoint throw std::invalid_argument("Bad URL format"); std::string::size_type bar = parts[i].find_first_of('|'); - this->url_pars.push_back(parts[i].substr(1, bar != string::npos ? bar - 1 : parts[i].size() - 2)); - this->url_normalized += (first ? "" : "/") + (bar != string::npos ? parts[i].substr(bar + 1, parts[i].size() - bar - 2) : "([^\\/]+)"); + url_pars.push_back(parts[i].substr(1, bar != string::npos ? bar - 1 : parts[i].size() - 2)); + url_normalized += (first ? "" : "/") + (bar != string::npos ? parts[i].substr(bar + 1, parts[i].size() - bar - 2) : "([^\\/]+)"); first = false; - this->chunk_positions.push_back(i); + chunk_positions.push_back(i); - this->url_pieces.push_back(parts[i]); + url_pieces.push_back(parts[i]); } if(use_regex) { - this->url_normalized += "$"; - regcomp(&(this->re_url_normalized), url_normalized.c_str(), + url_normalized += "$"; + regcomp(&re_url_normalized, url_normalized.c_str(), REG_EXTENDED|REG_ICASE|REG_NOSUB ); - this->reg_compiled = true; + reg_compiled = true; } } @@ -134,52 +134,52 @@ http_endpoint::http_endpoint(const http_endpoint& h): family_url(h.family_url), reg_compiled(h.reg_compiled) { - if(this->reg_compiled) - regcomp(&(this->re_url_normalized), url_normalized.c_str(), + if(reg_compiled) + regcomp(&re_url_normalized, url_normalized.c_str(), REG_EXTENDED|REG_ICASE|REG_NOSUB ); } http_endpoint& http_endpoint::operator =(const http_endpoint& h) { - this->url_complete = h.url_complete; - this->url_normalized = h.url_normalized; - this->family_url = h.family_url; - this->reg_compiled = h.reg_compiled; - if(this->reg_compiled) + url_complete = h.url_complete; + url_normalized = h.url_normalized; + family_url = h.family_url; + reg_compiled = h.reg_compiled; + if(reg_compiled) { - regfree(&(this->re_url_normalized)); + regfree(&re_url_normalized); - regcomp(&(this->re_url_normalized), url_normalized.c_str(), + regcomp(&re_url_normalized, url_normalized.c_str(), REG_EXTENDED|REG_ICASE|REG_NOSUB ); } - this->url_pars = h.url_pars; - this->url_pieces = h.url_pieces; - this->chunk_positions = h.chunk_positions; + url_pars = h.url_pars; + url_pieces = h.url_pieces; + chunk_positions = h.chunk_positions; return *this; } bool http_endpoint::operator <(const http_endpoint& b) const { - COMPARATOR(this->url_normalized, b.url_normalized, std::toupper); + COMPARATOR(url_normalized, b.url_normalized, std::toupper); } bool http_endpoint::match(const http_endpoint& url) const { - if (!this->reg_compiled) throw std::invalid_argument("Cannot run match. Regex suppressed."); + if (!reg_compiled) throw std::invalid_argument("Cannot run match. Regex suppressed."); - if(!this->family_url || url.url_pieces.size() < this->url_pieces.size()) - return regexec(&(this->re_url_normalized), url.url_complete.c_str(), 0, NULL, 0) == 0; + if(!family_url || url.url_pieces.size() < url_pieces.size()) + return regexec(&re_url_normalized, url.url_complete.c_str(), 0, NULL, 0) == 0; string nn = "/"; bool first = true; - for(unsigned int i = 0; i < this->url_pieces.size(); i++) + for(unsigned int i = 0; i < url_pieces.size(); i++) { nn += (first ? "" : "/") + url.url_pieces[i]; first = false; } - return regexec(&(this->re_url_normalized), nn.c_str(), 0, NULL, 0) == 0; + return regexec(&re_url_normalized, nn.c_str(), 0, NULL, 0) == 0; } }; diff --git a/src/http_request.cpp b/src/http_request.cpp index 973ab338..caff14e5 100644 --- a/src/http_request.cpp +++ b/src/http_request.cpp @@ -37,9 +37,9 @@ struct arguments_accumulator std::map* arguments; }; -void http_request::set_method(const std::string& method) +void http_request::set_method(const std::string& method_src) { - this->method = string_utilities::to_upper_copy(method); + method = string_utilities::to_upper_copy(method_src); } bool http_request::check_digest_auth( @@ -76,7 +76,7 @@ bool http_request::check_digest_auth( const std::string http_request::get_connection_value(const std::string& key, enum MHD_ValueKind kind) const { const char* header_c = MHD_lookup_connection_value( - this->underlying_connection, + underlying_connection, kind, key.c_str() ); @@ -103,7 +103,7 @@ const std::map http_request:: std::map headers; MHD_get_connection_values( - this->underlying_connection, + underlying_connection, kind, &build_request_header, (void*) &headers @@ -144,9 +144,9 @@ const std::map http_request:: const std::string http_request::get_arg(const std::string& key) const { - std::map::const_iterator it = this->args.find(key); + std::map::const_iterator it = args.find(key); - if(it != this->args.end()) + if(it != args.end()) { return it->second; } @@ -157,14 +157,14 @@ const std::string http_request::get_arg(const std::string& key) const const std::map http_request::get_args() const { std::map arguments; - arguments.insert(this->args.begin(), this->args.end()); + arguments.insert(args.begin(), args.end()); arguments_accumulator aa; - aa.unescaper = this->unescaper; + aa.unescaper = unescaper; aa.arguments = &arguments; MHD_get_connection_values( - this->underlying_connection, + underlying_connection, MHD_GET_ARGUMENT_KIND, &build_request_args, (void*) &aa @@ -178,7 +178,7 @@ const std::string http_request::get_querystring() const std::string querystring = ""; MHD_get_connection_values( - this->underlying_connection, + underlying_connection, MHD_GET_ARGUMENT_KIND, &build_request_querystring, (void*) &querystring diff --git a/src/http_response.cpp b/src/http_response.cpp index 35b83d50..2193d1f3 100644 --- a/src/http_response.cpp +++ b/src/http_response.cpp @@ -70,7 +70,7 @@ int http_response::enqueue_response(MHD_Connection* connection, MHD_Response* re void http_response::shoutCAST() { - this->response_code |= http::http_utils::shoutcast_response; + response_code |= http::http_utils::shoutcast_response; } std::ostream &operator<< (std::ostream &os, const http_response &r) diff --git a/src/http_utils.cpp b/src/http_utils.cpp index 0d00a05f..e549da99 100644 --- a/src/http_utils.cpp +++ b/src/http_utils.cpp @@ -517,16 +517,16 @@ bool ip_representation::operator <(const ip_representation& b) const { if (i == 10 || i == 11) continue; - if (CHECK_BIT(this->mask, i) && CHECK_BIT(b.mask, i)) + if (CHECK_BIT(mask, i) && CHECK_BIT(b.mask, i)) { - this_score += (16 - i) * this->pieces[i]; + this_score += (16 - i) * pieces[i]; b_score += (16 - i) * b.pieces[i]; } } if (this_score == b_score && - ((this->pieces[10] == 0x00 || this->pieces[10] == 0xFF) && (b.pieces[10] == 0x00 || b.pieces[10] == 0xFF)) && - ((this->pieces[11] == 0x00 || this->pieces[11] == 0xFF) && (b.pieces[11] == 0x00 || b.pieces[11] == 0xFF)) + ((pieces[10] == 0x00 || pieces[10] == 0xFF) && (b.pieces[10] == 0x00 || b.pieces[10] == 0xFF)) && + ((pieces[11] == 0x00 || pieces[11] == 0xFF) && (b.pieces[11] == 0x00 || b.pieces[11] == 0xFF)) ) { return false; @@ -534,9 +534,9 @@ bool ip_representation::operator <(const ip_representation& b) const for (int i = 10; i < 12; i++) { - if (CHECK_BIT(this->mask, i) && CHECK_BIT(b.mask, i)) + if (CHECK_BIT(mask, i) && CHECK_BIT(b.mask, i)) { - this_score += (16 - i) * this->pieces[i]; + this_score += (16 - i) * pieces[i]; b_score += (16 - i) * b.pieces[i]; } } diff --git a/src/httpserver/deferred_response.hpp b/src/httpserver/deferred_response.hpp index 02cc745d..02fc7bfe 100644 --- a/src/httpserver/deferred_response.hpp +++ b/src/httpserver/deferred_response.hpp @@ -95,7 +95,7 @@ class deferred_response : public string_response MHD_Response* get_raw_response() { - return details::get_raw_response_helper((void*) this, &(this->cb)); + return details::get_raw_response_helper((void*) this, &cb); } private: diff --git a/src/httpserver/details/http_endpoint.hpp b/src/httpserver/details/http_endpoint.hpp index 2527f66c..ff0b5f26 100644 --- a/src/httpserver/details/http_endpoint.hpp +++ b/src/httpserver/details/http_endpoint.hpp @@ -85,12 +85,12 @@ class http_endpoint **/ const std::string& get_url_complete() const { - return this->url_complete; + return url_complete; } const std::string& get_url_normalized() const { - return this->url_normalized; + return url_normalized; } /** @@ -99,7 +99,7 @@ class http_endpoint **/ const std::vector& get_url_pars() const { - return this->url_pars; + return url_pars; } /** @@ -108,7 +108,7 @@ class http_endpoint **/ const std::vector& get_url_pieces() const { - return this->url_pieces; + return url_pieces; } /** @@ -117,17 +117,17 @@ class http_endpoint **/ const std::vector& get_chunk_positions() const { - return this->chunk_positions; + return chunk_positions; } const bool is_family_url() const { - return this->family_url; + return family_url; } const bool is_regex_compiled() const { - return this->reg_compiled; + return reg_compiled; } /** diff --git a/src/httpserver/http_request.hpp b/src/httpserver/http_request.hpp index 632fe06d..6c416afd 100644 --- a/src/httpserver/http_request.hpp +++ b/src/httpserver/http_request.hpp @@ -76,7 +76,7 @@ class http_request **/ const std::string& get_path() const { - return this->path; + return path; } /** @@ -85,7 +85,7 @@ class http_request **/ const std::vector get_path_pieces() const { - return http::http_utils::tokenize_url(this->path); + return http::http_utils::tokenize_url(path); } /** @@ -95,7 +95,7 @@ class http_request **/ const std::string get_path_piece(int index) const { - std::vector post_path = this->get_path_pieces(); + std::vector post_path = get_path_pieces(); if(((int)(post_path.size())) > index) return post_path[index]; return EMPTY; @@ -107,7 +107,7 @@ class http_request **/ const std::string& get_method() const { - return this->method; + return method; } /** @@ -167,7 +167,7 @@ class http_request **/ const std::string& get_content() const { - return this->content; + return content; } /** @@ -190,7 +190,7 @@ class http_request **/ const std::string& get_version() const { - return this->version; + return version; } /** @@ -319,7 +319,7 @@ class http_request **/ void set_arg(const std::string& key, const std::string& value) { - this->args[key] = value.substr(0,content_size_limit); + args[key] = value.substr(0,content_size_limit); } /** @@ -330,26 +330,25 @@ class http_request **/ void set_arg(const char* key, const char* value, size_t size) { - this->args[key] = std::string(value, - std::min(size, content_size_limit)); + args[key] = std::string(value, std::min(size, content_size_limit)); } /** * Method used to set the content of the request * @param content The content to set. **/ - void set_content(const std::string& content) + void set_content(const std::string& content_src) { - this->content = content.substr(0,content_size_limit); + content = content_src.substr(0,content_size_limit); } /** * Method used to set the maximum size of the content * @param content_size_limit The limit on the maximum size of the content and arg's. **/ - void set_content_size_limit(size_t content_size_limit) + void set_content_size_limit(size_t content_size_limit_src) { - this->content_size_limit = content_size_limit; + content_size_limit = content_size_limit_src; } /** @@ -357,12 +356,12 @@ class http_request * @param content The content to append. * @param size The size of the data to append. **/ - void grow_content(const char* content, size_t size) + void grow_content(const char* content_ptr, size_t size) { - this->content.append(content, size); - if (this->content.size() > content_size_limit) + content.append(content_ptr, size); + if (content.size() > content_size_limit) { - this->content.resize (content_size_limit); + content.resize (content_size_limit); } } @@ -370,9 +369,9 @@ class http_request * Method used to set the path requested. * @param path The path searched by the request. **/ - void set_path(const std::string& path) + void set_path(const std::string& path_src) { - this->path = path; + path = path_src; } /** @@ -385,20 +384,20 @@ class http_request * Method used to set the request http version (ie http 1.1) * @param version The version to set in form of string **/ - void set_version(const std::string& version) + void set_version(const std::string& version_src) { - this->version = version; + version = version_src; } /** * Method used to set all arguments of the request. * @param args The args key-value map to set for the request. **/ - void set_args(const std::map& args) + void set_args(const std::map& args_src) { std::map::const_iterator it; - for(it = args.begin(); it != args.end(); ++it) - this->args[it->first] = it->second.substr(0,content_size_limit); + for(it = args_src.begin(); it != args_src.end(); ++it) + args[it->first] = it->second.substr(0,content_size_limit); } const std::string get_connection_value(const std::string& key, enum MHD_ValueKind kind) const; diff --git a/src/httpserver/http_resource.hpp b/src/httpserver/http_resource.hpp index ae5e78d4..3f7ad881 100644 --- a/src/httpserver/http_resource.hpp +++ b/src/httpserver/http_resource.hpp @@ -161,9 +161,9 @@ class http_resource **/ void set_allowing(const std::string& method, bool allowed) { - if(this->allowed_methods.count(method)) + if(allowed_methods.count(method)) { - this->allowed_methods[method] = allowed; + allowed_methods[method] = allowed; } } /** @@ -172,8 +172,8 @@ class http_resource void allow_all() { std::map::iterator it; - for ( it=this->allowed_methods.begin() ; it != this->allowed_methods.end(); ++it ) - this->allowed_methods[(*it).first] = true; + for ( it=allowed_methods.begin() ; it != allowed_methods.end(); ++it ) + allowed_methods[(*it).first] = true; } /** * Method used to implicitly disallow all methods @@ -181,8 +181,8 @@ class http_resource void disallow_all() { std::map::iterator it; - for ( it=this->allowed_methods.begin() ; it != this->allowed_methods.end(); ++it ) - this->allowed_methods[(*it).first] = false; + for ( it=allowed_methods.begin() ; it != allowed_methods.end(); ++it ) + allowed_methods[(*it).first] = false; } /** * Method used to discover if an http method is allowed or not for this resource @@ -191,9 +191,9 @@ class http_resource **/ bool is_allowed(const std::string& method) { - if(this->allowed_methods.count(method)) + if(allowed_methods.count(method)) { - return this->allowed_methods[method]; + return allowed_methods[method]; } else { diff --git a/src/httpserver/http_response.hpp b/src/httpserver/http_response.hpp index b7f9b9a9..cc67277b 100644 --- a/src/httpserver/http_response.hpp +++ b/src/httpserver/http_response.hpp @@ -53,7 +53,7 @@ class http_response explicit http_response(int response_code, const std::string& content_type): response_code(response_code) { - this->headers[http::http_utils::http_header_content_type] = content_type; + headers[http::http_utils::http_header_content_type] = content_type; } /** @@ -111,7 +111,7 @@ class http_response **/ const std::string& get_header(const std::string& key) { - return this->headers[key]; + return headers[key]; } /** @@ -121,12 +121,12 @@ class http_response **/ const std::string& get_footer(const std::string& key) { - return this->footers[key]; + return footers[key]; } const std::string& get_cookie(const std::string& key) { - return this->cookies[key]; + return cookies[key]; } /** @@ -135,7 +135,7 @@ class http_response **/ const std::map& get_headers() const { - return this->headers; + return headers; } /** @@ -144,12 +144,12 @@ class http_response **/ const std::map& get_footers() const { - return this->footers; + return footers; } const std::map& get_cookies() const { - return this->cookies; + return cookies; } /** @@ -158,7 +158,7 @@ class http_response **/ int get_response_code() const { - return this->response_code; + return response_code; } void with_header(const std::string& key, const std::string& value) diff --git a/src/httpserver/webserver.hpp b/src/httpserver/webserver.hpp index 93b2e8b5..dff0392c 100644 --- a/src/httpserver/webserver.hpp +++ b/src/httpserver/webserver.hpp @@ -110,22 +110,22 @@ class webserver log_access_ptr get_access_logger() const { - return this->log_access; + return log_access; } log_error_ptr get_error_logger() const { - return this->log_error; + return log_error; } validator_ptr get_request_validator() const { - return this->validator; + return validator; } unescaper_ptr get_unescaper() const { - return this->unescaper; + return unescaper; } /** diff --git a/src/webserver.cpp b/src/webserver.cpp index 9b4d03a1..939ed342 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -164,7 +164,7 @@ webserver::webserver(const create_webserver& params): webserver::~webserver() { - this->stop(); + stop(); pthread_mutex_destroy(&mutexwait); pthread_rwlock_destroy(&runguard); pthread_cond_destroy(&mutexcond); @@ -172,7 +172,7 @@ webserver::~webserver() void webserver::sweet_kill() { - this->stop(); + stop(); } void webserver::request_completed ( @@ -308,16 +308,16 @@ bool webserver::start(bool blocking) start_conf |= MHD_USE_TCP_FASTOPEN; #endif - this->daemon = NULL; + daemon = NULL; if(bind_address == 0x0) { - this->daemon = MHD_start_daemon + daemon = MHD_start_daemon ( - start_conf, this->port, &policy_callback, this, + start_conf, port, &policy_callback, this, &answer_to_connection, this, MHD_OPTION_ARRAY, &iov[0], MHD_OPTION_END ); } else { - this->daemon = MHD_start_daemon + daemon = MHD_start_daemon ( start_conf, 1, &policy_callback, this, &answer_to_connection, this, MHD_OPTION_ARRAY, @@ -325,14 +325,14 @@ bool webserver::start(bool blocking) ); } - if(this->daemon == NULL) + if(daemon == NULL) { - throw std::invalid_argument("Unable to connect daemon to port: " + std::to_string(this->port)); + throw std::invalid_argument("Unable to connect daemon to port: " + std::to_string(port)); } bool value_onclose = false; - this->running = true; + running = true; if(blocking) { @@ -347,19 +347,19 @@ bool webserver::start(bool blocking) bool webserver::is_running() { - return this->running; + return running; } bool webserver::stop() { - if(!this->running) return false; + if(!running) return false; pthread_mutex_lock(&mutexwait); - this->running = false; + running = false; pthread_cond_signal(&mutexcond); pthread_mutex_unlock(&mutexwait); - MHD_stop_daemon(this->daemon); + MHD_stop_daemon(daemon); shutdown(bind_socket, 2); @@ -369,45 +369,45 @@ bool webserver::stop() void webserver::unregister_resource(const string& resource) { details::http_endpoint he(resource); - this->registered_resources.erase(he); - this->registered_resources.erase(he.get_url_complete()); - this->registered_resources_str.erase(he.get_url_complete()); + registered_resources.erase(he); + registered_resources.erase(he.get_url_complete()); + registered_resources_str.erase(he.get_url_complete()); } void webserver::ban_ip(const string& ip) { ip_representation t_ip(ip); - set::iterator it = this->bans.find(t_ip); - if(it != this->bans.end() && (t_ip.weight() < (*it).weight())) + set::iterator it = bans.find(t_ip); + if(it != bans.end() && (t_ip.weight() < (*it).weight())) { - this->bans.erase(it); - this->bans.insert(t_ip); + bans.erase(it); + bans.insert(t_ip); } else - this->bans.insert(t_ip); + bans.insert(t_ip); } void webserver::allow_ip(const string& ip) { ip_representation t_ip(ip); - set::iterator it = this->allowances.find(t_ip); - if(it != this->allowances.end() && (t_ip.weight() < (*it).weight())) + set::iterator it = allowances.find(t_ip); + if(it != allowances.end() && (t_ip.weight() < (*it).weight())) { - this->allowances.erase(it); - this->allowances.insert(t_ip); + allowances.erase(it); + allowances.insert(t_ip); } else - this->allowances.insert(t_ip); + allowances.insert(t_ip); } void webserver::unban_ip(const string& ip) { - this->bans.erase(ip); + bans.erase(ip); } void webserver::disallow_ip(const string& ip) { - this->allowances.erase(ip); + allowances.erase(ip); } int policy_callback (void *cls, const struct sockaddr* addr, socklen_t addrlen) diff --git a/test/integ/basic.cpp b/test/integ/basic.cpp index 767a8ecd..339cc677 100644 --- a/test/integ/basic.cpp +++ b/test/integ/basic.cpp @@ -245,9 +245,9 @@ class error_resource : public http_resource class print_request_resource : public http_resource { public: - print_request_resource(std::stringstream* ss) + print_request_resource(std::stringstream* ss_src) { - this->ss = ss; + ss = ss_src; } const shared_ptr render_GET(const http_request& req) @@ -263,9 +263,9 @@ class print_request_resource : public http_resource class print_response_resource : public http_resource { public: - print_response_resource(std::stringstream* ss) + print_response_resource(std::stringstream* ss_src) { - this->ss = ss; + ss = ss_src; } const shared_ptr render_GET(const http_request& req) From 8393250c55ae5dc6c7fb1ab76dc51c6888eb437f Mon Sep 17 00:00:00 2001 From: bcsgh <33939446+bcsgh@users.noreply.github.com> Date: Mon, 24 Feb 2020 20:15:37 -0800 Subject: [PATCH 10/11] Rename some variable so that all `this->` can be dropped, and do so. --- src/details/http_endpoint.cpp | 64 ++++++++++++------------ src/http_request.cpp | 20 ++++---- src/http_response.cpp | 2 +- src/http_utils.cpp | 12 ++--- src/httpserver/deferred_response.hpp | 2 +- src/httpserver/details/http_endpoint.hpp | 14 +++--- src/httpserver/http_request.hpp | 47 +++++++++-------- src/httpserver/http_resource.hpp | 16 +++--- src/httpserver/http_response.hpp | 16 +++--- src/httpserver/webserver.hpp | 8 +-- src/webserver.cpp | 56 ++++++++++----------- test/integ/basic.cpp | 8 +-- 12 files changed, 132 insertions(+), 133 deletions(-) diff --git a/src/details/http_endpoint.cpp b/src/details/http_endpoint.cpp index 6c2ae1e0..6bf2a6ef 100644 --- a/src/details/http_endpoint.cpp +++ b/src/details/http_endpoint.cpp @@ -36,7 +36,7 @@ http_endpoint::~http_endpoint() { if(reg_compiled) { - regfree(&(this->re_url_normalized)); + regfree(&re_url_normalized); } } @@ -50,7 +50,7 @@ http_endpoint::http_endpoint family_url(family), reg_compiled(false) { - this->url_normalized = use_regex ? "^/" : "/"; + url_normalized = use_regex ? "^/" : "/"; vector parts; #ifdef CASE_INSENSITIVE @@ -77,10 +77,10 @@ http_endpoint::http_endpoint { if(!registration) { - this->url_normalized += (first ? "" : "/") + parts[i]; + url_normalized += (first ? "" : "/") + parts[i]; first = false; - this->url_pieces.push_back(parts[i]); + url_pieces.push_back(parts[i]); continue; } @@ -89,14 +89,14 @@ http_endpoint::http_endpoint { if(first) { - this->url_normalized = (parts[i][0] == '^' ? "" : this->url_normalized) + parts[i]; + url_normalized = (parts[i][0] == '^' ? "" : url_normalized) + parts[i]; first = false; } else { - this->url_normalized += "/" + parts[i]; + url_normalized += "/" + parts[i]; } - this->url_pieces.push_back(parts[i]); + url_pieces.push_back(parts[i]); continue; } @@ -105,23 +105,23 @@ http_endpoint::http_endpoint throw std::invalid_argument("Bad URL format"); std::string::size_type bar = parts[i].find_first_of('|'); - this->url_pars.push_back(parts[i].substr(1, bar != string::npos ? bar - 1 : parts[i].size() - 2)); - this->url_normalized += (first ? "" : "/") + (bar != string::npos ? parts[i].substr(bar + 1, parts[i].size() - bar - 2) : "([^\\/]+)"); + url_pars.push_back(parts[i].substr(1, bar != string::npos ? bar - 1 : parts[i].size() - 2)); + url_normalized += (first ? "" : "/") + (bar != string::npos ? parts[i].substr(bar + 1, parts[i].size() - bar - 2) : "([^\\/]+)"); first = false; - this->chunk_positions.push_back(i); + chunk_positions.push_back(i); - this->url_pieces.push_back(parts[i]); + url_pieces.push_back(parts[i]); } if(use_regex) { - this->url_normalized += "$"; - regcomp(&(this->re_url_normalized), url_normalized.c_str(), + url_normalized += "$"; + regcomp(&re_url_normalized, url_normalized.c_str(), REG_EXTENDED|REG_ICASE|REG_NOSUB ); - this->reg_compiled = true; + reg_compiled = true; } } @@ -134,52 +134,52 @@ http_endpoint::http_endpoint(const http_endpoint& h): family_url(h.family_url), reg_compiled(h.reg_compiled) { - if(this->reg_compiled) - regcomp(&(this->re_url_normalized), url_normalized.c_str(), + if(reg_compiled) + regcomp(&re_url_normalized, url_normalized.c_str(), REG_EXTENDED|REG_ICASE|REG_NOSUB ); } http_endpoint& http_endpoint::operator =(const http_endpoint& h) { - this->url_complete = h.url_complete; - this->url_normalized = h.url_normalized; - this->family_url = h.family_url; - this->reg_compiled = h.reg_compiled; - if(this->reg_compiled) + url_complete = h.url_complete; + url_normalized = h.url_normalized; + family_url = h.family_url; + reg_compiled = h.reg_compiled; + if(reg_compiled) { - regfree(&(this->re_url_normalized)); + regfree(&re_url_normalized); - regcomp(&(this->re_url_normalized), url_normalized.c_str(), + regcomp(&re_url_normalized, url_normalized.c_str(), REG_EXTENDED|REG_ICASE|REG_NOSUB ); } - this->url_pars = h.url_pars; - this->url_pieces = h.url_pieces; - this->chunk_positions = h.chunk_positions; + url_pars = h.url_pars; + url_pieces = h.url_pieces; + chunk_positions = h.chunk_positions; return *this; } bool http_endpoint::operator <(const http_endpoint& b) const { - COMPARATOR(this->url_normalized, b.url_normalized, std::toupper); + COMPARATOR(url_normalized, b.url_normalized, std::toupper); } bool http_endpoint::match(const http_endpoint& url) const { - if (!this->reg_compiled) throw std::invalid_argument("Cannot run match. Regex suppressed."); + if (!reg_compiled) throw std::invalid_argument("Cannot run match. Regex suppressed."); - if(!this->family_url || url.url_pieces.size() < this->url_pieces.size()) - return regexec(&(this->re_url_normalized), url.url_complete.c_str(), 0, NULL, 0) == 0; + if(!family_url || url.url_pieces.size() < url_pieces.size()) + return regexec(&re_url_normalized, url.url_complete.c_str(), 0, NULL, 0) == 0; string nn = "/"; bool first = true; - for(unsigned int i = 0; i < this->url_pieces.size(); i++) + for(unsigned int i = 0; i < url_pieces.size(); i++) { nn += (first ? "" : "/") + url.url_pieces[i]; first = false; } - return regexec(&(this->re_url_normalized), nn.c_str(), 0, NULL, 0) == 0; + return regexec(&re_url_normalized, nn.c_str(), 0, NULL, 0) == 0; } }; diff --git a/src/http_request.cpp b/src/http_request.cpp index 973ab338..caff14e5 100644 --- a/src/http_request.cpp +++ b/src/http_request.cpp @@ -37,9 +37,9 @@ struct arguments_accumulator std::map* arguments; }; -void http_request::set_method(const std::string& method) +void http_request::set_method(const std::string& method_src) { - this->method = string_utilities::to_upper_copy(method); + method = string_utilities::to_upper_copy(method_src); } bool http_request::check_digest_auth( @@ -76,7 +76,7 @@ bool http_request::check_digest_auth( const std::string http_request::get_connection_value(const std::string& key, enum MHD_ValueKind kind) const { const char* header_c = MHD_lookup_connection_value( - this->underlying_connection, + underlying_connection, kind, key.c_str() ); @@ -103,7 +103,7 @@ const std::map http_request:: std::map headers; MHD_get_connection_values( - this->underlying_connection, + underlying_connection, kind, &build_request_header, (void*) &headers @@ -144,9 +144,9 @@ const std::map http_request:: const std::string http_request::get_arg(const std::string& key) const { - std::map::const_iterator it = this->args.find(key); + std::map::const_iterator it = args.find(key); - if(it != this->args.end()) + if(it != args.end()) { return it->second; } @@ -157,14 +157,14 @@ const std::string http_request::get_arg(const std::string& key) const const std::map http_request::get_args() const { std::map arguments; - arguments.insert(this->args.begin(), this->args.end()); + arguments.insert(args.begin(), args.end()); arguments_accumulator aa; - aa.unescaper = this->unescaper; + aa.unescaper = unescaper; aa.arguments = &arguments; MHD_get_connection_values( - this->underlying_connection, + underlying_connection, MHD_GET_ARGUMENT_KIND, &build_request_args, (void*) &aa @@ -178,7 +178,7 @@ const std::string http_request::get_querystring() const std::string querystring = ""; MHD_get_connection_values( - this->underlying_connection, + underlying_connection, MHD_GET_ARGUMENT_KIND, &build_request_querystring, (void*) &querystring diff --git a/src/http_response.cpp b/src/http_response.cpp index 35b83d50..2193d1f3 100644 --- a/src/http_response.cpp +++ b/src/http_response.cpp @@ -70,7 +70,7 @@ int http_response::enqueue_response(MHD_Connection* connection, MHD_Response* re void http_response::shoutCAST() { - this->response_code |= http::http_utils::shoutcast_response; + response_code |= http::http_utils::shoutcast_response; } std::ostream &operator<< (std::ostream &os, const http_response &r) diff --git a/src/http_utils.cpp b/src/http_utils.cpp index 0d00a05f..e549da99 100644 --- a/src/http_utils.cpp +++ b/src/http_utils.cpp @@ -517,16 +517,16 @@ bool ip_representation::operator <(const ip_representation& b) const { if (i == 10 || i == 11) continue; - if (CHECK_BIT(this->mask, i) && CHECK_BIT(b.mask, i)) + if (CHECK_BIT(mask, i) && CHECK_BIT(b.mask, i)) { - this_score += (16 - i) * this->pieces[i]; + this_score += (16 - i) * pieces[i]; b_score += (16 - i) * b.pieces[i]; } } if (this_score == b_score && - ((this->pieces[10] == 0x00 || this->pieces[10] == 0xFF) && (b.pieces[10] == 0x00 || b.pieces[10] == 0xFF)) && - ((this->pieces[11] == 0x00 || this->pieces[11] == 0xFF) && (b.pieces[11] == 0x00 || b.pieces[11] == 0xFF)) + ((pieces[10] == 0x00 || pieces[10] == 0xFF) && (b.pieces[10] == 0x00 || b.pieces[10] == 0xFF)) && + ((pieces[11] == 0x00 || pieces[11] == 0xFF) && (b.pieces[11] == 0x00 || b.pieces[11] == 0xFF)) ) { return false; @@ -534,9 +534,9 @@ bool ip_representation::operator <(const ip_representation& b) const for (int i = 10; i < 12; i++) { - if (CHECK_BIT(this->mask, i) && CHECK_BIT(b.mask, i)) + if (CHECK_BIT(mask, i) && CHECK_BIT(b.mask, i)) { - this_score += (16 - i) * this->pieces[i]; + this_score += (16 - i) * pieces[i]; b_score += (16 - i) * b.pieces[i]; } } diff --git a/src/httpserver/deferred_response.hpp b/src/httpserver/deferred_response.hpp index 32a97bfc..41398ee2 100644 --- a/src/httpserver/deferred_response.hpp +++ b/src/httpserver/deferred_response.hpp @@ -62,7 +62,7 @@ class deferred_response : public string_response MHD_Response* get_raw_response() { - return details::get_raw_response_helper((void*) this, &(this->cb)); + return details::get_raw_response_helper((void*) this, &cb); } private: diff --git a/src/httpserver/details/http_endpoint.hpp b/src/httpserver/details/http_endpoint.hpp index 2527f66c..ff0b5f26 100644 --- a/src/httpserver/details/http_endpoint.hpp +++ b/src/httpserver/details/http_endpoint.hpp @@ -85,12 +85,12 @@ class http_endpoint **/ const std::string& get_url_complete() const { - return this->url_complete; + return url_complete; } const std::string& get_url_normalized() const { - return this->url_normalized; + return url_normalized; } /** @@ -99,7 +99,7 @@ class http_endpoint **/ const std::vector& get_url_pars() const { - return this->url_pars; + return url_pars; } /** @@ -108,7 +108,7 @@ class http_endpoint **/ const std::vector& get_url_pieces() const { - return this->url_pieces; + return url_pieces; } /** @@ -117,17 +117,17 @@ class http_endpoint **/ const std::vector& get_chunk_positions() const { - return this->chunk_positions; + return chunk_positions; } const bool is_family_url() const { - return this->family_url; + return family_url; } const bool is_regex_compiled() const { - return this->reg_compiled; + return reg_compiled; } /** diff --git a/src/httpserver/http_request.hpp b/src/httpserver/http_request.hpp index c96bebb6..79293b59 100644 --- a/src/httpserver/http_request.hpp +++ b/src/httpserver/http_request.hpp @@ -76,7 +76,7 @@ class http_request **/ const std::string& get_path() const { - return this->path; + return path; } /** @@ -85,7 +85,7 @@ class http_request **/ const std::vector get_path_pieces() const { - return http::http_utils::tokenize_url(this->path); + return http::http_utils::tokenize_url(path); } /** @@ -95,7 +95,7 @@ class http_request **/ const std::string get_path_piece(int index) const { - std::vector post_path = this->get_path_pieces(); + std::vector post_path = get_path_pieces(); if(((int)(post_path.size())) > index) return post_path[index]; return EMPTY; @@ -107,7 +107,7 @@ class http_request **/ const std::string& get_method() const { - return this->method; + return method; } /** @@ -167,7 +167,7 @@ class http_request **/ const std::string& get_content() const { - return this->content; + return content; } /** @@ -190,7 +190,7 @@ class http_request **/ const std::string& get_version() const { - return this->version; + return version; } /** @@ -264,7 +264,7 @@ class http_request **/ void set_arg(const std::string& key, const std::string& value) { - this->args[key] = value.substr(0,content_size_limit); + args[key] = value.substr(0,content_size_limit); } /** @@ -275,26 +275,25 @@ class http_request **/ void set_arg(const char* key, const char* value, size_t size) { - this->args[key] = std::string(value, - std::min(size, content_size_limit)); + args[key] = std::string(value, std::min(size, content_size_limit)); } /** * Method used to set the content of the request * @param content The content to set. **/ - void set_content(const std::string& content) + void set_content(const std::string& content_src) { - this->content = content.substr(0,content_size_limit); + content = content_src.substr(0,content_size_limit); } /** * Method used to set the maximum size of the content * @param content_size_limit The limit on the maximum size of the content and arg's. **/ - void set_content_size_limit(size_t content_size_limit) + void set_content_size_limit(size_t content_size_limit_src) { - this->content_size_limit = content_size_limit; + content_size_limit = content_size_limit_src; } /** @@ -302,12 +301,12 @@ class http_request * @param content The content to append. * @param size The size of the data to append. **/ - void grow_content(const char* content, size_t size) + void grow_content(const char* content_ptr, size_t size) { - this->content.append(content, size); - if (this->content.size() > content_size_limit) + content.append(content_ptr, size); + if (content.size() > content_size_limit) { - this->content.resize (content_size_limit); + content.resize (content_size_limit); } } @@ -315,9 +314,9 @@ class http_request * Method used to set the path requested. * @param path The path searched by the request. **/ - void set_path(const std::string& path) + void set_path(const std::string& path_src) { - this->path = path; + path = path_src; } /** @@ -330,20 +329,20 @@ class http_request * Method used to set the request http version (ie http 1.1) * @param version The version to set in form of string **/ - void set_version(const std::string& version) + void set_version(const std::string& version_src) { - this->version = version; + version = version_src; } /** * Method used to set all arguments of the request. * @param args The args key-value map to set for the request. **/ - void set_args(const std::map& args) + void set_args(const std::map& args_src) { std::map::const_iterator it; - for(it = args.begin(); it != args.end(); ++it) - this->args[it->first] = it->second.substr(0,content_size_limit); + for(it = args_src.begin(); it != args_src.end(); ++it) + args[it->first] = it->second.substr(0,content_size_limit); } const std::string get_connection_value(const std::string& key, enum MHD_ValueKind kind) const; diff --git a/src/httpserver/http_resource.hpp b/src/httpserver/http_resource.hpp index 42f73498..ba2ad750 100644 --- a/src/httpserver/http_resource.hpp +++ b/src/httpserver/http_resource.hpp @@ -158,9 +158,9 @@ class http_resource **/ void set_allowing(const std::string& method, bool allowed) { - if(this->allowed_methods.count(method)) + if(allowed_methods.count(method)) { - this->allowed_methods[method] = allowed; + allowed_methods[method] = allowed; } } /** @@ -169,8 +169,8 @@ class http_resource void allow_all() { std::map::iterator it; - for ( it=this->allowed_methods.begin() ; it != this->allowed_methods.end(); ++it ) - this->allowed_methods[(*it).first] = true; + for ( it=allowed_methods.begin() ; it != allowed_methods.end(); ++it ) + allowed_methods[(*it).first] = true; } /** * Method used to implicitly disallow all methods @@ -178,8 +178,8 @@ class http_resource void disallow_all() { std::map::iterator it; - for ( it=this->allowed_methods.begin() ; it != this->allowed_methods.end(); ++it ) - this->allowed_methods[(*it).first] = false; + for ( it=allowed_methods.begin() ; it != allowed_methods.end(); ++it ) + allowed_methods[(*it).first] = false; } /** * Method used to discover if an http method is allowed or not for this resource @@ -188,9 +188,9 @@ class http_resource **/ bool is_allowed(const std::string& method) { - if(this->allowed_methods.count(method)) + if(allowed_methods.count(method)) { - return this->allowed_methods[method]; + return allowed_methods[method]; } else { diff --git a/src/httpserver/http_response.hpp b/src/httpserver/http_response.hpp index 755d6c7a..9f247291 100644 --- a/src/httpserver/http_response.hpp +++ b/src/httpserver/http_response.hpp @@ -50,7 +50,7 @@ class http_response explicit http_response(int response_code, const std::string& content_type): response_code(response_code) { - this->headers[http::http_utils::http_header_content_type] = content_type; + headers[http::http_utils::http_header_content_type] = content_type; } /** @@ -72,7 +72,7 @@ class http_response **/ const std::string& get_header(const std::string& key) { - return this->headers[key]; + return headers[key]; } /** @@ -82,12 +82,12 @@ class http_response **/ const std::string& get_footer(const std::string& key) { - return this->footers[key]; + return footers[key]; } const std::string& get_cookie(const std::string& key) { - return this->cookies[key]; + return cookies[key]; } /** @@ -96,7 +96,7 @@ class http_response **/ const std::map& get_headers() const { - return this->headers; + return headers; } /** @@ -105,12 +105,12 @@ class http_response **/ const std::map& get_footers() const { - return this->footers; + return footers; } const std::map& get_cookies() const { - return this->cookies; + return cookies; } /** @@ -119,7 +119,7 @@ class http_response **/ int get_response_code() const { - return this->response_code; + return response_code; } void with_header(const std::string& key, const std::string& value) diff --git a/src/httpserver/webserver.hpp b/src/httpserver/webserver.hpp index 93b2e8b5..dff0392c 100644 --- a/src/httpserver/webserver.hpp +++ b/src/httpserver/webserver.hpp @@ -110,22 +110,22 @@ class webserver log_access_ptr get_access_logger() const { - return this->log_access; + return log_access; } log_error_ptr get_error_logger() const { - return this->log_error; + return log_error; } validator_ptr get_request_validator() const { - return this->validator; + return validator; } unescaper_ptr get_unescaper() const { - return this->unescaper; + return unescaper; } /** diff --git a/src/webserver.cpp b/src/webserver.cpp index 9b4d03a1..939ed342 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -164,7 +164,7 @@ webserver::webserver(const create_webserver& params): webserver::~webserver() { - this->stop(); + stop(); pthread_mutex_destroy(&mutexwait); pthread_rwlock_destroy(&runguard); pthread_cond_destroy(&mutexcond); @@ -172,7 +172,7 @@ webserver::~webserver() void webserver::sweet_kill() { - this->stop(); + stop(); } void webserver::request_completed ( @@ -308,16 +308,16 @@ bool webserver::start(bool blocking) start_conf |= MHD_USE_TCP_FASTOPEN; #endif - this->daemon = NULL; + daemon = NULL; if(bind_address == 0x0) { - this->daemon = MHD_start_daemon + daemon = MHD_start_daemon ( - start_conf, this->port, &policy_callback, this, + start_conf, port, &policy_callback, this, &answer_to_connection, this, MHD_OPTION_ARRAY, &iov[0], MHD_OPTION_END ); } else { - this->daemon = MHD_start_daemon + daemon = MHD_start_daemon ( start_conf, 1, &policy_callback, this, &answer_to_connection, this, MHD_OPTION_ARRAY, @@ -325,14 +325,14 @@ bool webserver::start(bool blocking) ); } - if(this->daemon == NULL) + if(daemon == NULL) { - throw std::invalid_argument("Unable to connect daemon to port: " + std::to_string(this->port)); + throw std::invalid_argument("Unable to connect daemon to port: " + std::to_string(port)); } bool value_onclose = false; - this->running = true; + running = true; if(blocking) { @@ -347,19 +347,19 @@ bool webserver::start(bool blocking) bool webserver::is_running() { - return this->running; + return running; } bool webserver::stop() { - if(!this->running) return false; + if(!running) return false; pthread_mutex_lock(&mutexwait); - this->running = false; + running = false; pthread_cond_signal(&mutexcond); pthread_mutex_unlock(&mutexwait); - MHD_stop_daemon(this->daemon); + MHD_stop_daemon(daemon); shutdown(bind_socket, 2); @@ -369,45 +369,45 @@ bool webserver::stop() void webserver::unregister_resource(const string& resource) { details::http_endpoint he(resource); - this->registered_resources.erase(he); - this->registered_resources.erase(he.get_url_complete()); - this->registered_resources_str.erase(he.get_url_complete()); + registered_resources.erase(he); + registered_resources.erase(he.get_url_complete()); + registered_resources_str.erase(he.get_url_complete()); } void webserver::ban_ip(const string& ip) { ip_representation t_ip(ip); - set::iterator it = this->bans.find(t_ip); - if(it != this->bans.end() && (t_ip.weight() < (*it).weight())) + set::iterator it = bans.find(t_ip); + if(it != bans.end() && (t_ip.weight() < (*it).weight())) { - this->bans.erase(it); - this->bans.insert(t_ip); + bans.erase(it); + bans.insert(t_ip); } else - this->bans.insert(t_ip); + bans.insert(t_ip); } void webserver::allow_ip(const string& ip) { ip_representation t_ip(ip); - set::iterator it = this->allowances.find(t_ip); - if(it != this->allowances.end() && (t_ip.weight() < (*it).weight())) + set::iterator it = allowances.find(t_ip); + if(it != allowances.end() && (t_ip.weight() < (*it).weight())) { - this->allowances.erase(it); - this->allowances.insert(t_ip); + allowances.erase(it); + allowances.insert(t_ip); } else - this->allowances.insert(t_ip); + allowances.insert(t_ip); } void webserver::unban_ip(const string& ip) { - this->bans.erase(ip); + bans.erase(ip); } void webserver::disallow_ip(const string& ip) { - this->allowances.erase(ip); + allowances.erase(ip); } int policy_callback (void *cls, const struct sockaddr* addr, socklen_t addrlen) diff --git a/test/integ/basic.cpp b/test/integ/basic.cpp index 767a8ecd..339cc677 100644 --- a/test/integ/basic.cpp +++ b/test/integ/basic.cpp @@ -245,9 +245,9 @@ class error_resource : public http_resource class print_request_resource : public http_resource { public: - print_request_resource(std::stringstream* ss) + print_request_resource(std::stringstream* ss_src) { - this->ss = ss; + ss = ss_src; } const shared_ptr render_GET(const http_request& req) @@ -263,9 +263,9 @@ class print_request_resource : public http_resource class print_response_resource : public http_resource { public: - print_response_resource(std::stringstream* ss) + print_response_resource(std::stringstream* ss_src) { - this->ss = ss; + ss = ss_src; } const shared_ptr render_GET(const http_request& req) From 4c80b6bdff89ffd33682060348f36ff8b35c5b95 Mon Sep 17 00:00:00 2001 From: bcsgh <33939446+bcsgh@users.noreply.github.com> Date: Sat, 29 Feb 2020 11:27:04 -0800 Subject: [PATCH 11/11] Re-add the `this->` for setter methods. --- src/http_request.cpp | 4 ++-- src/httpserver/http_request.hpp | 30 +++++++++++++++--------------- test/integ/basic.cpp | 8 ++++---- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/http_request.cpp b/src/http_request.cpp index caff14e5..b261f328 100644 --- a/src/http_request.cpp +++ b/src/http_request.cpp @@ -37,9 +37,9 @@ struct arguments_accumulator std::map* arguments; }; -void http_request::set_method(const std::string& method_src) +void http_request::set_method(const std::string& method) { - method = string_utilities::to_upper_copy(method_src); + this->method = string_utilities::to_upper_copy(method); } bool http_request::check_digest_auth( diff --git a/src/httpserver/http_request.hpp b/src/httpserver/http_request.hpp index 79293b59..c056db6e 100644 --- a/src/httpserver/http_request.hpp +++ b/src/httpserver/http_request.hpp @@ -282,18 +282,18 @@ class http_request * Method used to set the content of the request * @param content The content to set. **/ - void set_content(const std::string& content_src) + void set_content(const std::string& content) { - content = content_src.substr(0,content_size_limit); + this->content = content.substr(0,content_size_limit); } /** * Method used to set the maximum size of the content * @param content_size_limit The limit on the maximum size of the content and arg's. **/ - void set_content_size_limit(size_t content_size_limit_src) + void set_content_size_limit(size_t content_size_limit) { - content_size_limit = content_size_limit_src; + this->content_size_limit = content_size_limit; } /** @@ -301,12 +301,12 @@ class http_request * @param content The content to append. * @param size The size of the data to append. **/ - void grow_content(const char* content_ptr, size_t size) + void grow_content(const char* content, size_t size) { - content.append(content_ptr, size); - if (content.size() > content_size_limit) + this->content.append(content, size); + if (this->content.size() > content_size_limit) { - content.resize (content_size_limit); + this->content.resize (content_size_limit); } } @@ -314,9 +314,9 @@ class http_request * Method used to set the path requested. * @param path The path searched by the request. **/ - void set_path(const std::string& path_src) + void set_path(const std::string& path) { - path = path_src; + this->path = path; } /** @@ -329,20 +329,20 @@ class http_request * Method used to set the request http version (ie http 1.1) * @param version The version to set in form of string **/ - void set_version(const std::string& version_src) + void set_version(const std::string& version) { - version = version_src; + this->version = version; } /** * Method used to set all arguments of the request. * @param args The args key-value map to set for the request. **/ - void set_args(const std::map& args_src) + void set_args(const std::map& args) { std::map::const_iterator it; - for(it = args_src.begin(); it != args_src.end(); ++it) - args[it->first] = it->second.substr(0,content_size_limit); + for(it = args.begin(); it != args.end(); ++it) + this->args[it->first] = it->second.substr(0,content_size_limit); } const std::string get_connection_value(const std::string& key, enum MHD_ValueKind kind) const; diff --git a/test/integ/basic.cpp b/test/integ/basic.cpp index 339cc677..767a8ecd 100644 --- a/test/integ/basic.cpp +++ b/test/integ/basic.cpp @@ -245,9 +245,9 @@ class error_resource : public http_resource class print_request_resource : public http_resource { public: - print_request_resource(std::stringstream* ss_src) + print_request_resource(std::stringstream* ss) { - ss = ss_src; + this->ss = ss; } const shared_ptr render_GET(const http_request& req) @@ -263,9 +263,9 @@ class print_request_resource : public http_resource class print_response_resource : public http_resource { public: - print_response_resource(std::stringstream* ss_src) + print_response_resource(std::stringstream* ss) { - ss = ss_src; + this->ss = ss; } const shared_ptr render_GET(const http_request& req)