GeezerVison is showing github.com — Changed http_endpoint to be an inner class of webserver. · icgilca/libhttpserver@b5f5ef9
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: ChangeLog +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +Sun Nov 04 19:28:00 2018 -0800 | | 2 | + Moved http_endpoint as a sub-class of webserver. This avoids usage of friends. | | 3 | + | 1 | 4 | Wed Feb 26 21:31:00 2017 +0000 | 2 | 5 | Fixed problem with segfault when copying http_response object | 3 | 6 |
| |
Collapse file Copy file name to clipboardExpand all lines: configure.ac +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 21 | 21 |
| 22 | 22 | AC_PREREQ(2.57) | 23 | 23 | m4_define([libhttpserver_MAJOR_VERSION],[0])dnl | 24 | | -m4_define([libhttpserver_MINOR_VERSION],[13])dnl | | 24 | +m4_define([libhttpserver_MINOR_VERSION],[14])dnl | 25 | 25 | m4_define([libhttpserver_REVISION],[0])dnl | 26 | 26 | m4_define([libhttpserver_PKG_VERSION],[libhttpserver_MAJOR_VERSION.libhttpserver_MINOR_VERSION.libhttpserver_REVISION])dnl | 27 | 27 | m4_define([libhttpserver_LDF_VERSION],[libhttpserver_MAJOR_VERSION:libhttpserver_MINOR_VERSION:libhttpserver_REVISION])dnl | |
Collapse file Copy file name to clipboardExpand all lines: src/Makefile.am +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 19 | 19 | AM_CPPFLAGS = -I../ -I$(srcdir)/httpserver/ | 20 | 20 | METASOURCES = AUTO | 21 | 21 | lib_LTLIBRARIES = libhttpserver.la | 22 | | -libhttpserver_la_SOURCES = string_utilities.cpp webserver.cpp http_utils.cpp http_request.cpp http_response.cpp http_resource.cpp details/comet_manager.cpp details/http_endpoint.cpp | | 22 | +libhttpserver_la_SOURCES = string_utilities.cpp webserver.cpp http_utils.cpp http_request.cpp http_response.cpp http_resource.cpp details/comet_manager.cpp http_endpoint.cpp | 23 | 23 | noinst_HEADERS = httpserver/string_utilities.hpp httpserver/details/modded_request.hpp httpserver/details/http_response_ptr.hpp httpserver/details/cache_entry.hpp httpserver/details/comet_manager.hpp gettext.h | 24 | | -nobase_include_HEADERS = httpserver.hpp httpserver/create_webserver.hpp httpserver/webserver.hpp httpserver/http_utils.hpp httpserver/details/http_endpoint.hpp httpserver/http_request.hpp httpserver/http_response.hpp httpserver/http_resource.hpp httpserver/binders.hpp httpserver/http_response_builder.hpp | | 24 | +nobase_include_HEADERS = httpserver.hpp httpserver/create_webserver.hpp httpserver/webserver.hpp httpserver/http_utils.hpp httpserver/http_endpoint.hpp httpserver/http_request.hpp httpserver/http_response.hpp httpserver/http_resource.hpp httpserver/binders.hpp httpserver/http_response_builder.hpp | 25 | 25 |
| 26 | 26 | AM_CXXFLAGS += -fPIC -Wall | 27 | 27 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/http_endpoint.cpp +8-12Lines changed: 8 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 18 | 18 | USA | 19 | 19 | */ | 20 | 20 |
| 21 | | -#include "details/http_endpoint.hpp" | | 21 | +#include "http_endpoint.hpp" | 22 | 22 | #include "http_utils.hpp" | 23 | 23 | #include "string_utilities.hpp" | 24 | 24 |
| @@ -29,18 +29,15 @@ namespace httpserver | 29 | 29 |
| 30 | 30 | using namespace http; | 31 | 31 |
| 32 | | -namespace details | 33 | | -{ | 34 | | - | 35 | | -http_endpoint::~http_endpoint() | | 32 | +webserver::http_endpoint::~http_endpoint() | 36 | 33 | { | 37 | 34 | if(reg_compiled) | 38 | 35 | { | 39 | 36 | regfree(&(this->re_url_modded)); | 40 | 37 | } | 41 | 38 | } | 42 | 39 |
| 43 | | -http_endpoint::http_endpoint | | 40 | +webserver::http_endpoint::http_endpoint | 44 | 41 | ( | 45 | 42 | const string& url, | 46 | 43 | bool family, | @@ -95,7 +92,7 @@ http_endpoint::http_endpoint | 95 | 92 | } | 96 | 93 |
| 97 | 94 | if((parts[i].size() < 3) || (parts[i][0] != '{') || (parts[i][parts[i].size() - 1] != '}')) | 98 | | - throw bad_http_endpoint(); | | 95 | + throw webserver::http_endpoint::bad_http_endpoint(); | 99 | 96 |
| 100 | 97 | std::string::size_type bar = parts[i].find_first_of('|'); | 101 | 98 | this->url_pars.push_back(parts[i].substr(1, bar != string::npos ? bar - 1 : parts[i].size() - 2)); | @@ -118,7 +115,7 @@ http_endpoint::http_endpoint | 118 | 115 | } | 119 | 116 | } | 120 | 117 |
| 121 | | -http_endpoint::http_endpoint(const http_endpoint& h): | | 118 | +webserver::http_endpoint::http_endpoint(const webserver::http_endpoint& h): | 122 | 119 | url_complete(h.url_complete), | 123 | 120 | url_modded(h.url_modded), | 124 | 121 | url_pars(h.url_pars), | @@ -133,7 +130,7 @@ http_endpoint::http_endpoint(const http_endpoint& h): | 133 | 130 | ); | 134 | 131 | } | 135 | 132 |
| 136 | | -http_endpoint& http_endpoint::operator =(const http_endpoint& h) | | 133 | +webserver::http_endpoint& webserver::http_endpoint::operator =(const webserver::http_endpoint& h) | 137 | 134 | { | 138 | 135 | this->url_complete = h.url_complete; | 139 | 136 | this->url_modded = h.url_modded; | @@ -149,12 +146,12 @@ http_endpoint& http_endpoint::operator =(const http_endpoint& h) | 149 | 146 | return *this; | 150 | 147 | } | 151 | 148 |
| 152 | | -bool http_endpoint::operator <(const http_endpoint& b) const | | 149 | +bool webserver::http_endpoint::operator <(const webserver::http_endpoint& b) const | 153 | 150 | { | 154 | 151 | COMPARATOR(this->url_modded, b.url_modded, std::toupper); | 155 | 152 | } | 156 | 153 |
| 157 | | -bool http_endpoint::match(const http_endpoint& url) const | | 154 | +bool webserver::http_endpoint::match(const webserver::http_endpoint& url) const | 158 | 155 | { | 159 | 156 |
| 160 | 157 | if(!this->family_url || url.url_pieces.size() < this->url_pieces.size()) | @@ -172,4 +169,3 @@ bool http_endpoint::match(const http_endpoint& url) const | 172 | 169 |
| 173 | 170 | }; | 174 | 171 |
| 175 | | -}; |
Collapse file Copy file name to clipboardExpand all lines: src/httpserver.hpp +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 24 | 24 | #define _HTTPSERVER_HPP_INSIDE_ | 25 | 25 |
| 26 | 26 | #include "httpserver/http_utils.hpp" | 27 | | -#include "httpserver/details/http_endpoint.hpp" | | 27 | +#include "httpserver/http_endpoint.hpp" | 28 | 28 | #include "httpserver/http_resource.hpp" | 29 | 29 | #include "httpserver/http_response.hpp" | 30 | 30 | #include "httpserver/http_response_builder.hpp" | |
Collapse file Copy file name to clipboardExpand all lines: src/httpserver/http_endpoint.hpp +17-23Lines changed: 17 additions & 23 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 30 | 30 | #include <regex.h> | 31 | 31 | #include <string> | 32 | 32 |
| | 33 | +#include "webserver.hpp" | | 34 | + | 33 | 35 | namespace httpserver | 34 | 36 | { | 35 | 37 |
| @@ -42,24 +44,27 @@ namespace details | 42 | 44 | /** | 43 | 45 | * Exception class throwed when a bad formatted http url is used | 44 | 46 | **/ | 45 | | -class bad_http_endpoint : public std::exception | 46 | | -{ | 47 | | - /** | 48 | | - * Method used to see error details | 49 | | - * @return a const char* containing the error message | 50 | | - **/ | 51 | | - virtual const char* what() const throw() | 52 | | - { | 53 | | - return "Bad url format!"; | 54 | | - } | | 47 | + | 55 | 48 | }; | 56 | 49 |
| 57 | 50 | /** | 58 | 51 | * Class representing an Http Endpoint. It is an abstraction used by the APIs. | 59 | 52 | **/ | 60 | | -class http_endpoint | | 53 | +class webserver::http_endpoint | 61 | 54 | { | 62 | | - private: | | 55 | + public: | | 56 | + class bad_http_endpoint : public std::exception | | 57 | + { | | 58 | + /** | | 59 | + * Method used to see error details | | 60 | + * @return a const char* containing the error message | | 61 | + **/ | | 62 | + virtual const char* what() const throw() | | 63 | + { | | 64 | + return "Bad url format!"; | | 65 | + } | | 66 | + }; | | 67 | + | 63 | 68 | /** | 64 | 69 | * Copy constructor. It is useful expecially to copy regex_t structure that contains dinamically allocated data. | 65 | 70 | * @param h The http_endpoint to copy | @@ -232,17 +237,6 @@ class http_endpoint | 232 | 237 | * Boolean indicating if the regex is compiled | 233 | 238 | **/ | 234 | 239 | bool reg_compiled; | 235 | | - friend class httpserver::webserver; | 236 | | - friend void _register_resource( | 237 | | - webserver*, | 238 | | - const std::string&, | 239 | | - const http_resource&, | 240 | | - bool | 241 | | - ); | 242 | | - template<typename, typename> friend struct std::pair; | 243 | | - template<typename> friend struct std::less; | 244 | | -}; | 245 | | - | 246 | 240 | }; | 247 | 241 |
| 248 | 242 | }; | |
Collapse file Copy file name to clipboardExpand all lines: src/httpserver/webserver.hpp +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -57,7 +57,6 @@ struct httpserver_ska; | 57 | 57 | }; | 58 | 58 |
| 59 | 59 | namespace details { | 60 | | - class http_endpoint; | 61 | 60 | struct daemon_item; | 62 | 61 | struct modded_request; | 63 | 62 | struct cache_entry; | @@ -174,6 +173,8 @@ class webserver | 174 | 173 | webserver& operator=(const webserver& other); | 175 | 174 |
| 176 | 175 | private: | | 176 | + class http_endpoint; | | 177 | + | 177 | 178 | const uint16_t port; | 178 | 179 | http::http_utils::start_method_T start_method; | 179 | 180 | const int max_threads; | @@ -218,7 +219,7 @@ class webserver | 218 | 219 | render_ptr method_not_allowed_resource; | 219 | 220 | render_ptr method_not_acceptable_resource; | 220 | 221 | render_ptr internal_error_resource; | 221 | | - std::map<details::http_endpoint, http_resource*> registered_resources; | | 222 | + std::map<http_endpoint, http_resource*> registered_resources; | 222 | 223 | std::map<std::string, http_resource*> registered_resources_str; | 223 | 224 |
| 224 | 225 | std::map<std::string, details::cache_entry*> response_cache; | |
Collapse file Copy file name to clipboardExpand all lines: src/webserver.cpp +8-8Lines changed: 8 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 48 | 48 | #include "http_response.hpp" | 49 | 49 | #include "http_request.hpp" | 50 | 50 | #include "http_response_builder.hpp" | 51 | | -#include "details/http_endpoint.hpp" | | 51 | +#include "http_endpoint.hpp" | 52 | 52 | #include "string_utilities.hpp" | 53 | 53 | #include "create_webserver.hpp" | 54 | 54 | #include "details/comet_manager.hpp" | @@ -224,10 +224,10 @@ void webserver::request_completed ( | 224 | 224 |
| 225 | 225 | bool webserver::register_resource(const std::string& resource, http_resource* hrm, bool family) | 226 | 226 | { | 227 | | - details::http_endpoint idx(resource, family, true, regex_checking); | | 227 | + http_endpoint idx(resource, family, true, regex_checking); | 228 | 228 |
| 229 | | - pair<map<details::http_endpoint, http_resource*>::iterator, bool> result = registered_resources.insert( | 230 | | - map<details::http_endpoint, http_resource*>::value_type(idx, hrm) | | 229 | + pair<map<http_endpoint, http_resource*>::iterator, bool> result = registered_resources.insert( | | 230 | + map<http_endpoint, http_resource*>::value_type(idx, hrm) | 231 | 231 | ); | 232 | 232 |
| 233 | 233 | if(result.second) | @@ -435,7 +435,7 @@ bool webserver::stop() | 435 | 435 |
| 436 | 436 | void webserver::unregister_resource(const string& resource) | 437 | 437 | { | 438 | | - details::http_endpoint he(resource); | | 438 | + http_endpoint he(resource); | 439 | 439 | this->registered_resources.erase(he); | 440 | 440 | this->registered_resources.erase(he.url_complete); | 441 | 441 | } | @@ -813,11 +813,11 @@ int webserver::finalize_answer( | 813 | 813 | if(regex_checking) | 814 | 814 | { | 815 | 815 |
| 816 | | - map<details::http_endpoint, http_resource*>::iterator found_endpoint; | | 816 | + map<http_endpoint, http_resource*>::iterator found_endpoint; | 817 | 817 |
| 818 | | - details::http_endpoint endpoint(st_url, false, false, regex_checking); | | 818 | + http_endpoint endpoint(st_url, false, false, regex_checking); | 819 | 819 |
| 820 | | - map<details::http_endpoint, http_resource*>::iterator it; | | 820 | + map<http_endpoint, http_resource*>::iterator it; | 821 | 821 |
| 822 | 822 | size_t len = 0; | 823 | 823 | size_t tot_len = 0; | |
|