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..b261f328 100644 --- a/src/http_request.cpp +++ b/src/http_request.cpp @@ -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..c056db6e 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,8 +275,7 @@ 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)); } /** 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)