| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 35dc94f commit dfe3664
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,14 +27,15 @@ | |||
| 27 | 27 | ||
| 28 | 28 | #include "httpserver/http_utils.hpp" | |
| 29 | 29 | ||
| 30 | + #define DEFAULT_WS_TIMEOUT 180 | ||
| 31 | + #define DEFAULT_WS_PORT 9898 | ||
| 32 | + | ||
| 30 | 33 | namespace httpserver { | |
| 31 | 34 | ||
| 32 | 35 | class webserver; | |
| 33 | 36 | class http_request; | |
| 34 | 37 | class http_response; | |
| 35 | 38 | ||
| 36 | - using namespace http; | ||
| 37 | - | ||
| 38 | 39 | typedef void(*render_ptr)(const http_request&, http_response**); | |
| 39 | 40 | typedef bool(*validator_ptr)(const std::string&); | |
| 40 | 41 | typedef void(*unescaper_ptr)(char*); | |
@@ -46,7 +47,7 @@ class create_webserver | |||
| 46 | 47 | public: | |
| 47 | 48 | create_webserver(): | |
| 48 | 49 | _port(DEFAULT_WS_PORT), | |
| 49 | - _start_method(http_utils::INTERNAL_SELECT), | ||
| 50 | + _start_method(http::http_utils::INTERNAL_SELECT), | ||
| 50 | 51 | _max_threads(0), | |
| 51 | 52 | _max_connections(0), | |
| 52 | 53 | _memory_limit(0), | |
@@ -67,10 +68,10 @@ class create_webserver | |||
| 67 | 68 | _https_mem_cert(""), | |
| 68 | 69 | _https_mem_trust(""), | |
| 69 | 70 | _https_priorities(""), | |
| 70 | - _cred_type(http_utils::NONE), | ||
| 71 | + _cred_type(http::http_utils::NONE), | ||
| 71 | 72 | _digest_auth_random(""), | |
| 72 | 73 | _nonce_nc_size(0), | |
| 73 | - _default_policy(http_utils::ACCEPT), | ||
| 74 | + _default_policy(http::http_utils::ACCEPT), | ||
| 74 | 75 | _basic_auth_enabled(true), | |
| 75 | 76 | _digest_auth_enabled(true), | |
| 76 | 77 | _regex_checking(true), | |
@@ -86,7 +87,7 @@ class create_webserver | |||
| 86 | 87 | ||
| 87 | 88 | explicit create_webserver(int port): | |
| 88 | 89 | _port(port), | |
| 89 | - _start_method(http_utils::INTERNAL_SELECT), | ||
| 90 | + _start_method(http::http_utils::INTERNAL_SELECT), | ||
| 90 | 91 | _max_threads(0), | |
| 91 | 92 | _max_connections(0), | |
| 92 | 93 | _memory_limit(0), | |
@@ -107,10 +108,10 @@ class create_webserver | |||
| 107 | 108 | _https_mem_cert(""), | |
| 108 | 109 | _https_mem_trust(""), | |
| 109 | 110 | _https_priorities(""), | |
| 110 | - _cred_type(http_utils::NONE), | ||
| 111 | + _cred_type(http::http_utils::NONE), | ||
| 111 | 112 | _digest_auth_random(""), | |
| 112 | 113 | _nonce_nc_size(0), | |
| 113 | - _default_policy(http_utils::ACCEPT), | ||
| 114 | + _default_policy(http::http_utils::ACCEPT), | ||
| 114 | 115 | _basic_auth_enabled(true), | |
| 115 | 116 | _digest_auth_enabled(true), | |
| 116 | 117 | _regex_checking(true), | |
@@ -126,7 +127,7 @@ class create_webserver | |||
| 126 | 127 | ||
| 127 | 128 | create_webserver& port(int port) { _port = port; return *this; } | |
| 128 | 129 | create_webserver& start_method( | |
| 129 | - const http_utils::start_method_T& start_method | ||
| 130 | + const http::http_utils::start_method_T& start_method | ||
| 130 | 131 | ) | |
| 131 | 132 | { | |
| 132 | 133 | _start_method = start_method; return *this; | |
@@ -226,7 +227,7 @@ class create_webserver | |||
| 226 | 227 | { | |
| 227 | 228 | _https_priorities = https_priorities; return *this; | |
| 228 | 229 | } | |
| 229 | - create_webserver& cred_type(const http_utils::cred_type_T& cred_type) | ||
| 230 | + create_webserver& cred_type(const http::http_utils::cred_type_T& cred_type) | ||
| 230 | 231 | { | |
| 231 | 232 | _cred_type = cred_type; return *this; | |
| 232 | 233 | } | |
@@ -241,7 +242,7 @@ class create_webserver | |||
| 241 | 242 | _nonce_nc_size = nonce_nc_size; return *this; | |
| 242 | 243 | } | |
| 243 | 244 | create_webserver& default_policy( | |
| 244 | - const http_utils::policy_T& default_policy | ||
| 245 | + const http::http_utils::policy_T& default_policy | ||
| 245 | 246 | ) | |
| 246 | 247 | { | |
| 247 | 248 | _default_policy = default_policy; return *this; | |
@@ -317,7 +318,7 @@ class create_webserver | |||
| 317 | 318 | ||
| 318 | 319 | private: | |
| 319 | 320 | int _port; | |
| 320 | - http_utils::start_method_T _start_method; | ||
| 321 | + http::http_utils::start_method_T _start_method; | ||
| 321 | 322 | int _max_threads; | |
| 322 | 323 | int _max_connections; | |
| 323 | 324 | int _memory_limit; | |
@@ -338,10 +339,10 @@ class create_webserver | |||
| 338 | 339 | std::string _https_mem_cert; | |
| 339 | 340 | std::string _https_mem_trust; | |
| 340 | 341 | std::string _https_priorities; | |
| 341 | - http_utils::cred_type_T _cred_type; | ||
| 342 | + http::http_utils::cred_type_T _cred_type; | ||
| 342 | 343 | std::string _digest_auth_random; | |
| 343 | 344 | int _nonce_nc_size; | |
| 344 | - http_utils::policy_T _default_policy; | ||
| 345 | + http::http_utils::policy_T _default_policy; | ||
| 345 | 346 | bool _basic_auth_enabled; | |
| 346 | 347 | bool _digest_auth_enabled; | |
| 347 | 348 | bool _regex_checking; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,8 +29,6 @@ | |||
| 29 | 29 | #define METHOD_ERROR "Method not Allowed" | |
| 30 | 30 | #define NOT_METHOD_ERROR "Method not Acceptable" | |
| 31 | 31 | #define GENERIC_ERROR "Internal Error" | |
| 32 | - #define DEFAULT_WS_PORT 9898 | ||
| 33 | - #define DEFAULT_WS_TIMEOUT 180 | ||
| 34 | 32 | ||
| 35 | 33 | #include <cstring> | |
| 36 | 34 | #include <map> | |
@@ -47,8 +45,6 @@ | |||
| 47 | 45 | ||
| 48 | 46 | #include <pthread.h> | |
| 49 | 47 | ||
| 50 | - #include "httpserver/details/http_resource_mirror.hpp" | ||
| 51 | - #include "httpserver/details/event_tuple.hpp" | ||
| 52 | 48 | #include "httpserver/create_webserver.hpp" | |
| 53 | 49 | ||
| 54 | 50 | namespace httpserver { | |
@@ -57,76 +53,27 @@ template<typename CHILD> class http_resource; | |||
| 57 | 53 | class http_response; | |
| 58 | 54 | struct cache_entry; | |
| 59 | 55 | template<typename CHILD> class event_supplier; | |
| 56 | + class create_webserver; | ||
| 60 | 57 | ||
| 61 | 58 | namespace http { | |
| 62 | 59 | struct ip_representation; | |
| 60 | + struct httpserver_ska; | ||
| 63 | 61 | }; | |
| 64 | 62 | ||
| 63 | + namespace details { | ||
| 64 | + class http_resource_mirror; | ||
| 65 | + class event_tuple; | ||
| 66 | + class http_endpoint; | ||
| 67 | + class daemon_item; | ||
| 68 | + class modded_request; | ||
| 69 | + } | ||
| 70 | + | ||
| 65 | 71 | /** | |
| 66 | 72 | * Class representing the webserver. Main class of the apis. | |
| 67 | 73 | **/ | |
| 68 | 74 | class webserver | |
| 69 | 75 | { | |
| 70 | 76 | public: | |
| 71 | - /** | ||
| 72 | - * Constructor of the class. | ||
| 73 | - * @param port Integer representing the port the webserver is listening on. | ||
| 74 | - * @param start_method | ||
| 75 | - * @param max_threads max number of serving threads (0 -> infty) | ||
| 76 | - * @param max_connections max number of allowed connections (0 -> infty). | ||
| 77 | - * @param memory_limit max memory allocated to serve requests (0 -> infty). | ||
| 78 | - * @param per_IP_connection_limit max number of connections allowed for a single IP (0 -> infty). | ||
| 79 | - * @param log_delegate logging_delegate object used to log | ||
| 80 | - * @param validator request_validator object used to validate requestors | ||
| 81 | - * @param unescaper unescaper object used to unescape urls. | ||
| 82 | - * @param max_thread_stack_size max dimesion of request stack | ||
| 83 | - * @param https_mem_key used with https. Private key used for requests. | ||
| 84 | - * @param https_mem_cert used with https. Certificate used for requests. | ||
| 85 | - * @param https_mem_trust used with https. CA Certificate used to trust request certificates. | ||
| 86 | - * @param https_priorities used with https. Determinates the SSL/TLS version to be used. | ||
| 87 | - * @param cred_type used with https. Daemon credential type. Can be NONE, certificate or anonymous. | ||
| 88 | - * @param digest_auth_random used with https. Digest authentication nonce's seed. | ||
| 89 | - * @param nonce_nc_size used with https. Size of an array of nonce and nonce counter map. | ||
| 90 | - **/ | ||
| 91 | - explicit webserver | ||
| 92 | - ( | ||
| 93 | - int port = DEFAULT_WS_PORT, | ||
| 94 | - const http_utils::start_method_T& start_method = http_utils::INTERNAL_SELECT, | ||
| 95 | - int max_threads = 0, | ||
| 96 | - int max_connections = 0, | ||
| 97 | - int memory_limit = 0, | ||
| 98 | - int connection_timeout = DEFAULT_WS_TIMEOUT, | ||
| 99 | - int per_IP_connection_limit = 0, | ||
| 100 | - log_access_ptr log_access = 0x0, | ||
| 101 | - log_error_ptr log_error = 0x0, | ||
| 102 | - validator_ptr validator = 0x0, | ||
| 103 | - unescaper_ptr unescaper = 0x0, | ||
| 104 | - const struct sockaddr* bind_address = 0x0, | ||
| 105 | - int bind_socket = 0, | ||
| 106 | - int max_thread_stack_size = 0, | ||
| 107 | - bool use_ssl = false, | ||
| 108 | - bool use_ipv6 = false, | ||
| 109 | - bool debug = false, | ||
| 110 | - bool pedantic = false, | ||
| 111 | - const std::string& https_mem_key = "", | ||
| 112 | - const std::string& https_mem_cert = "", | ||
| 113 | - const std::string& https_mem_trust = "", | ||
| 114 | - const std::string& https_priorities = "", | ||
| 115 | - const http_utils::cred_type_T& cred_type= http_utils::NONE, | ||
| 116 | - const std::string digest_auth_random = "", //IT'S CORRECT TO PASS THIS PARAMETER BY VALUE | ||
| 117 | - int nonce_nc_size = 0, | ||
| 118 | - const http_utils::policy_T& default_policy = http_utils::ACCEPT, | ||
| 119 | - bool basic_auth_enabled = true, | ||
| 120 | - bool digest_auth_enabled = true, | ||
| 121 | - bool regex_checking = true, | ||
| 122 | - bool ban_system_enabled = true, | ||
| 123 | - bool post_process_enabled = true, | ||
| 124 | - render_ptr single_resource = 0x0, | ||
| 125 | - render_ptr not_found_resource = 0x0, | ||
| 126 | - render_ptr method_not_allowed_resource = 0x0, | ||
| 127 | - render_ptr method_not_acceptable_resource = 0x0, | ||
| 128 | - render_ptr internal_error_resource = 0x0 | ||
| 129 | - ); | ||
| 130 | 77 | webserver(const create_webserver& params); | |
| 131 | 78 | /** | |
| 132 | 79 | * Destructor of the class | |
@@ -174,20 +121,20 @@ class webserver | |||
| 174 | 121 | void send_message_to_topic(const std::string& topic, | |
| 175 | 122 | const std::string& message | |
| 176 | 123 | ); | |
| 177 | - void send_message_to_consumer(const httpserver_ska& connection_id, | ||
| 124 | + void send_message_to_consumer(const http::httpserver_ska& connection_id, | ||
| 178 | 125 | const std::string& message, bool to_lock = true | |
| 179 | 126 | ); | |
| 180 | 127 | void register_to_topics(const std::vector<std::string>& topics, | |
| 181 | - const httpserver_ska& connection_id, int keepalive_secs = -1, | ||
| 128 | + const http::httpserver_ska& connection_id, int keepalive_secs = -1, | ||
| 182 | 129 | std::string keepalive_msg = "" | |
| 183 | 130 | ); | |
| 184 | - size_t read_message(const httpserver_ska& connection_id, | ||
| 131 | + size_t read_message(const http::httpserver_ska& connection_id, | ||
| 185 | 132 | std::string& message | |
| 186 | 133 | ); | |
| 187 | 134 | size_t get_topic_consumers(const std::string& topic, | |
| 188 | - std::set<httpserver_ska>& consumers | ||
| 135 | + std::set<http::httpserver_ska>& consumers | ||
| 189 | 136 | ); | |
| 190 | - bool pop_signaled(const httpserver_ska& consumer); | ||
| 137 | + bool pop_signaled(const http::httpserver_ska& consumer); | ||
| 191 | 138 | ||
| 192 | 139 | http_response* get_from_cache(const std::string& key, bool* valid, | |
| 193 | 140 | bool lock = false, bool write = false | |
@@ -250,13 +197,7 @@ class webserver | |||
| 250 | 197 | event_supplier<T>* ev_supplier | |
| 251 | 198 | ) | |
| 252 | 199 | { | |
| 253 | - pthread_rwlock_wrlock(&runguard); | ||
| 254 | - std::map<std::string, details::event_tuple>::iterator it = | ||
| 255 | - event_suppliers.find(id); | ||
| 256 | - if(it != event_suppliers.end()) | ||
| 257 | - delete it->second; | ||
| 258 | - event_suppliers[id] = details::event_tuple(&ev_supplier); | ||
| 259 | - pthread_rwlock_unlock(&runguard); | ||
| 200 | + //TODO: implement method | ||
| 260 | 201 | } | |
| 261 | 202 | ||
| 262 | 203 | void remove_event_supplier(const std::string& id); | |
@@ -267,7 +208,7 @@ class webserver | |||
| 267 | 208 | void sweet_kill(); | |
| 268 | 209 | private: | |
| 269 | 210 | const int port; | |
| 270 | - http_utils::start_method_T start_method; | ||
| 211 | + http::http_utils::start_method_T start_method; | ||
| 271 | 212 | const int max_threads; | |
| 272 | 213 | const int max_connections; | |
| 273 | 214 | const int memory_limit; | |
@@ -288,11 +229,11 @@ class webserver | |||
| 288 | 229 | const std::string https_mem_cert; | |
| 289 | 230 | const std::string https_mem_trust; | |
| 290 | 231 | const std::string https_priorities; | |
| 291 | - const http_utils::cred_type_T cred_type; | ||
| 232 | + const http::http_utils::cred_type_T cred_type; | ||
| 292 | 233 | const std::string digest_auth_random; | |
| 293 | 234 | const int nonce_nc_size; | |
| 294 | 235 | bool running; | |
| 295 | - const http_utils::policy_T default_policy; | ||
| 236 | + const http::http_utils::policy_T default_policy; | ||
| 296 | 237 | const bool basic_auth_enabled; | |
| 297 | 238 | const bool digest_auth_enabled; | |
| 298 | 239 | const bool regex_checking; | |
@@ -315,19 +256,19 @@ class webserver | |||
| 315 | 256 | int next_to_choose; | |
| 316 | 257 | pthread_rwlock_t cache_guard; | |
| 317 | 258 | #ifdef USE_CPP_ZEROX | |
| 318 | - std::unordered_set<ip_representation> bans; | ||
| 319 | - std::unordered_set<ip_representation> allowances; | ||
| 259 | + std::unordered_set<http::ip_representation> bans; | ||
| 260 | + std::unordered_set<http::ip_representation> allowances; | ||
| 320 | 261 | #else | |
| 321 | - std::set<ip_representation> bans; | ||
| 322 | - std::set<ip_representation> allowances; | ||
| 262 | + std::set<http::ip_representation> bans; | ||
| 263 | + std::set<http::ip_representation> allowances; | ||
| 323 | 264 | #endif | |
| 324 | 265 | ||
| 325 | - std::map<httpserver_ska, std::deque<std::string> > q_messages; | ||
| 326 | - std::map<std::string, std::set<httpserver_ska> > q_waitings; | ||
| 327 | - std::map<httpserver_ska, std::pair<pthread_mutex_t, pthread_cond_t> > q_blocks; | ||
| 328 | - std::set<httpserver_ska> q_signal; | ||
| 329 | - std::map<httpserver_ska, long> q_keepalives; | ||
| 330 | - std::map<httpserver_ska, std::pair<int, std::string> > q_keepalives_mem; | ||
| 266 | + std::map<http::httpserver_ska, std::deque<std::string> > q_messages; | ||
| 267 | + std::map<std::string, std::set<http::httpserver_ska> > q_waitings; | ||
| 268 | + std::map<http::httpserver_ska, std::pair<pthread_mutex_t, pthread_cond_t> > q_blocks; | ||
| 269 | + std::set<http::httpserver_ska> q_signal; | ||
| 270 | + std::map<http::httpserver_ska, long> q_keepalives; | ||
| 271 | + std::map<http::httpserver_ska, std::pair<int, std::string> > q_keepalives_mem; | ||
| 331 | 272 | pthread_rwlock_t comet_guard; | |
| 332 | 273 | ||
| 333 | 274 | std::vector<details::daemon_item*> daemons; | |
@@ -337,7 +278,6 @@ class webserver | |||
| 337 | 278 | ||
| 338 | 279 | webserver& operator=(const webserver& b); | |
| 339 | 280 | ||
| 340 | - void init(render_ptr single_resource); | ||
| 341 | 281 | static void* select(void* self); | |
| 342 | 282 | static void* cleaner(void* self); | |
| 343 | 283 | ||
@@ -432,7 +372,7 @@ class webserver | |||
| 432 | 372 | ||
| 433 | 373 | bool use_internal_select() | |
| 434 | 374 | { | |
| 435 | - return this->start_method == http_utils::INTERNAL_SELECT; | ||
| 375 | + return this->start_method == http::http_utils::INTERNAL_SELECT; | ||
| 436 | 376 | } | |
| 437 | 377 | ||
| 438 | 378 | friend int policy_callback (void *cls, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments