2929#define METHOD_ERROR " Method not Allowed"
3030#define NOT_METHOD_ERROR " Method not Acceptable"
3131#define GENERIC_ERROR " Internal Error"
32- #define DEFAULT_WS_PORT 9898
33- #define DEFAULT_WS_TIMEOUT 180
3432
3533#include < cstring>
3634#include < map>
4745
4846#include < pthread.h>
4947
50- #include " httpserver/details/http_resource_mirror.hpp"
51- #include " httpserver/details/event_tuple.hpp"
5248#include " httpserver/create_webserver.hpp"
5349
5450namespace httpserver {
@@ -57,76 +53,27 @@ template<typename CHILD> class http_resource;
5753class http_response ;
5854struct cache_entry ;
5955template <typename CHILD> class event_supplier ;
56+ class create_webserver ;
6057
6158namespace http {
6259struct ip_representation ;
60+ struct httpserver_ska ;
6361};
6462
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+
6571/* *
6672 * Class representing the webserver. Main class of the apis.
6773**/
6874class webserver
6975{
7076 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- );
13077 webserver (const create_webserver& params);
13178 /* *
13279 * Destructor of the class
@@ -174,20 +121,20 @@ class webserver
174121 void send_message_to_topic (const std::string& topic,
175122 const std::string& message
176123 );
177- void send_message_to_consumer (const httpserver_ska& connection_id,
124+ void send_message_to_consumer (const http:: httpserver_ska& connection_id,
178125 const std::string& message, bool to_lock = true
179126 );
180127 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 ,
182129 std::string keepalive_msg = " "
183130 );
184- size_t read_message (const httpserver_ska& connection_id,
131+ size_t read_message (const http:: httpserver_ska& connection_id,
185132 std::string& message
186133 );
187134 size_t get_topic_consumers (const std::string& topic,
188- std::set<httpserver_ska>& consumers
135+ std::set<http:: httpserver_ska>& consumers
189136 );
190- bool pop_signaled (const httpserver_ska& consumer);
137+ bool pop_signaled (const http:: httpserver_ska& consumer);
191138
192139 http_response* get_from_cache (const std::string& key, bool * valid,
193140 bool lock = false , bool write = false
@@ -250,13 +197,7 @@ class webserver
250197 event_supplier<T>* ev_supplier
251198 )
252199 {
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
260201 }
261202
262203 void remove_event_supplier (const std::string& id);
@@ -267,7 +208,7 @@ class webserver
267208 void sweet_kill ();
268209 private:
269210 const int port;
270- http_utils::start_method_T start_method;
211+ http:: http_utils::start_method_T start_method;
271212 const int max_threads;
272213 const int max_connections;
273214 const int memory_limit;
@@ -288,11 +229,11 @@ class webserver
288229 const std::string https_mem_cert;
289230 const std::string https_mem_trust;
290231 const std::string https_priorities;
291- const http_utils::cred_type_T cred_type;
232+ const http:: http_utils::cred_type_T cred_type;
292233 const std::string digest_auth_random;
293234 const int nonce_nc_size;
294235 bool running;
295- const http_utils::policy_T default_policy;
236+ const http:: http_utils::policy_T default_policy;
296237 const bool basic_auth_enabled;
297238 const bool digest_auth_enabled;
298239 const bool regex_checking;
@@ -315,19 +256,19 @@ class webserver
315256 int next_to_choose;
316257 pthread_rwlock_t cache_guard;
317258#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;
320261#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;
323264#endif
324265
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;
331272 pthread_rwlock_t comet_guard;
332273
333274 std::vector<details::daemon_item*> daemons;
@@ -337,7 +278,6 @@ class webserver
337278
338279 webserver& operator =(const webserver& b);
339280
340- void init (render_ptr single_resource);
341281 static void * select (void * self);
342282 static void * cleaner (void * self);
343283
@@ -432,7 +372,7 @@ class webserver
432372
433373 bool use_internal_select ()
434374 {
435- return this ->start_method == http_utils::INTERNAL_SELECT;
375+ return this ->start_method == http:: http_utils::INTERNAL_SELECT;
436376 }
437377
438378 friend int policy_callback (void *cls,
0 commit comments