@@ -39,7 +39,7 @@ void error_log(void*, const char*, va_list);
3939void * uri_log (void *, const char *);
4040void access_log (Webserver*, string);
4141size_t unescaper_func (void *, struct MHD_Connection *, char *);
42- size_t internal_unescaper (void *, struct MHD_Connection *, char *);
42+ size_t internal_unescaper (void *, char *);
4343
4444static void catcher (int sig)
4545{
@@ -81,7 +81,7 @@ HttpEndpoint::HttpEndpoint(const string& url, bool family, bool registration):
8181 bool first = true ;
8282 if (registration)
8383 {
84- for (int i = 0 ; i< parts.size (); i++)
84+ for (unsigned int i = 0 ; i< parts.size (); i++)
8585 {
8686 if ((parts[i] != " " ) && (parts[i][0 ] != ' {' ))
8787 {
@@ -107,7 +107,7 @@ HttpEndpoint::HttpEndpoint(const string& url, bool family, bool registration):
107107 if (( parts[i].size () >= 3 ) && (parts[i][0 ] == ' {' ) && (parts[i][parts[i].size () - 1 ] == ' }' ) )
108108 {
109109 int bar = parts[i].find_first_of (' |' );
110- if (bar != string::npos)
110+ if (bar != ( int ) string::npos)
111111 {
112112 this ->url_pars .push_back (parts[i].substr (1 , bar - 1 ));
113113 if (first)
@@ -147,7 +147,7 @@ HttpEndpoint::HttpEndpoint(const string& url, bool family, bool registration):
147147 }
148148 else
149149 {
150- for (int i = 0 ; i< parts.size (); i++)
150+ for (unsigned int i = 0 ; i< parts.size (); i++)
151151 {
152152 if (first)
153153 {
@@ -212,7 +212,7 @@ bool HttpEndpoint::match(const HttpEndpoint& url) const
212212 {
213213 string nn = " /" ;
214214 bool first = true ;
215- for (int i = 0 ; i < this ->url_pieces .size (); i++)
215+ for (unsigned int i = 0 ; i < this ->url_pieces .size (); i++)
216216 {
217217 if (first)
218218 {
@@ -481,7 +481,7 @@ void HttpRequest::setPath(const string& path)
481481 // this->path = boost::to_lower_copy(path);
482482 this ->path = path;
483483 vector<string> complete_path = HttpUtils::tokenizeUrl (this ->path );
484- for (int i = 0 ; i < complete_path.size (); i++)
484+ for (unsigned int i = 0 ; i < complete_path.size (); i++)
485485 {
486486 this ->post_path .push_back (complete_path[i]);
487487 }
@@ -821,7 +821,7 @@ RequestValidator::RequestValidator() {}
821821
822822RequestValidator::~RequestValidator () {}
823823
824- bool RequestValidator::validate (const string& address) const {}
824+ bool RequestValidator::validate (const string& address) const { return true ; }
825825
826826// UNESCAPER
827827Unescaper::Unescaper () {}
@@ -859,6 +859,7 @@ Webserver::Webserver
859859 int nonceNcSize
860860) :
861861 port (port),
862+ startMethod(startMethod),
862863 maxThreads(maxThreads),
863864 maxConnections(maxConnections),
864865 memoryLimit(memoryLimit),
@@ -888,6 +889,7 @@ Webserver::Webserver
888889
889890Webserver::Webserver (const CreateWebserver& params):
890891 port(params._port),
892+ startMethod(params._startMethod),
891893 maxThreads(params._maxThreads),
892894 maxConnections(params._maxConnections),
893895 memoryLimit(params._memoryLimit),
@@ -936,7 +938,8 @@ void Webserver::requestCompleted (void *cls, struct MHD_Connection *connection,
936938 {
937939 MHD_destroy_post_processor (mr->pp );
938940 }
939- delete mr->dhr ;
941+ if (mr->second )
942+ delete mr->dhr ; // TODO: verify. It could be an error
940943 delete mr->completeUri ;
941944 free (mr);
942945}
@@ -988,7 +991,7 @@ bool Webserver::start(bool blocking)
988991 iov.push_back (gen (MHD_OPTION_END, 0 , NULL ));
989992
990993 struct MHD_OptionItem ops[iov.size ()];
991- for (int i = 0 ; i < iov.size (); i++)
994+ for (unsigned int i = 0 ; i < iov.size (); i++)
992995 {
993996 ops[i] = iov[i];
994997 }
@@ -1015,13 +1018,14 @@ bool Webserver::start(bool blocking)
10151018 return false ;
10161019 }
10171020 this ->running = true ;
1021+ bool value_onclose = false ;
10181022 if (blocking)
10191023 {
10201024 while (blocking && running)
10211025 sleep (1 );
1022- this ->stop ();
1026+ value_onclose = this ->stop ();
10231027 }
1024- return true ;
1028+ return value_onclose ;
10251029}
10261030
10271031bool Webserver::isRunning ()
@@ -1036,6 +1040,7 @@ bool Webserver::stop()
10361040 MHD_stop_daemon (this ->daemon );
10371041 this ->running = false ;
10381042 }
1043+ return true ;
10391044}
10401045
10411046void Webserver::registerResource (const string& resource, HttpResource* http_resource, bool family)
@@ -1066,9 +1071,9 @@ int Webserver::buildRequestFooter (void *cls, enum MHD_ValueKind kind, const cha
10661071
10671072int Webserver::buildRequestArgs (void *cls, enum MHD_ValueKind kind, const char *key, const char *value)
10681073{
1069- HttpRequest* dhr = (HttpRequest *)(cls);
1070- int size = http_unescape ( (char *) value);
1071- dhr->setArg (key, string (value, size));
1074+ ModdedRequest* mr = (ModdedRequest *)(cls);
1075+ int size = internal_unescaper (( void *)mr-> ws , (char *) value);
1076+ mr-> dhr ->setArg (key, string (value, size));
10721077 return MHD_YES;
10731078}
10741079
@@ -1120,7 +1125,7 @@ size_t unescaper_func(void * cls, struct MHD_Connection *c, char *s)
11201125 return strlen (s);
11211126}
11221127
1123- size_t internal_unescaper (void * cls, struct MHD_Connection *c, char * s)
1128+ size_t internal_unescaper (void * cls, char * s)
11241129{
11251130 Webserver* dws = (Webserver*) cls;
11261131 if (dws->unescaper != 0x0 )
@@ -1134,7 +1139,6 @@ size_t internal_unescaper(void* cls, struct MHD_Connection *c, char* s)
11341139 }
11351140}
11361141
1137-
11381142int Webserver::post_iterator (void *cls, enum MHD_ValueKind kind,
11391143 const char *key,
11401144 const char *filename,
@@ -1199,23 +1203,22 @@ int Webserver::answerToConnection(void* cls, MHD_Connection* connection,
11991203 int ret;
12001204 HttpRequest supportReq;
12011205 Webserver* dws = (Webserver*)(cls);
1202- http_unescape ( (char *) url);
1206+ internal_unescaper (cls, (char *) url);
12031207 string st_url = HttpUtils::standardizeUrl (url);
12041208
12051209 mr = (struct ModdedRequest *) *con_cls;
12061210 access_log (dws, *(mr->completeUri ) + " METHOD: " + method);
1211+ mr->ws = dws;
12071212 if (0 == strcmp (method, MHD_HTTP_METHOD_POST) || 0 == strcmp (method, MHD_HTTP_METHOD_PUT))
12081213 {
12091214 if (mr->second == false )
12101215 {
12111216 mr->second = true ;
12121217 mr->dhr = new HttpRequest ();
1213- mr->dhr ->setPath (st_url);
1214- mr->dhr ->setMethod (method);
12151218 const char *encoding = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, HttpUtils::http_header_content_type.c_str ());
1219+ // mr->dhr->setHeader(HttpUtils::http_header_content_type, string(encoding));
12161220 if ( 0x0 != encoding && 0 == strcmp (method, MHD_HTTP_METHOD_POST) && ((0 == strncasecmp (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, encoding, strlen (MHD_HTTP_POST_ENCODING_FORM_URLENCODED)))))
12171221 {
1218- mr->dhr ->setHeader (HttpUtils::http_header_content_type, string (encoding));
12191222 mr->pp = MHD_create_post_processor (connection, 1024 , &post_iterator, mr);
12201223 }
12211224 else
@@ -1228,25 +1231,16 @@ int Webserver::answerToConnection(void* cls, MHD_Connection* connection,
12281231 else
12291232 {
12301233 supportReq = HttpRequest ();
1231- supportReq.setMethod (string (method));
1232- supportReq.setPath (string (st_url));
1233- const char *encoding = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, HttpUtils::http_header_content_type.c_str ());
1234- if (encoding != 0x0 )
1235- supportReq.setHeader (HttpUtils::http_header_content_type, string (encoding));
1234+ mr->dhr = &supportReq;
12361235 }
12371236
1238- if (0 == strcmp (method, MHD_HTTP_METHOD_POST) || 0 == strcmp (method, MHD_HTTP_METHOD_PUT))
1239- {
1240- MHD_get_connection_values (connection, MHD_HEADER_KIND, &buildRequestHeader, (void *) mr->dhr );
1241- MHD_get_connection_values (connection, MHD_FOOTER_KIND, &buildRequestFooter, (void *) mr->dhr );
1242- MHD_get_connection_values (connection, MHD_COOKIE_KIND, &buildRequestCookie, (void *) mr->dhr );
1243- }
1244- else
1245- {
1246- MHD_get_connection_values (connection, MHD_HEADER_KIND, &buildRequestHeader, (void *) &supportReq);
1247- MHD_get_connection_values (connection, MHD_FOOTER_KIND, &buildRequestFooter, (void *) &supportReq);
1248- MHD_get_connection_values (connection, MHD_COOKIE_KIND, &buildRequestCookie, (void *) &supportReq);
1249- }
1237+ mr->dhr ->setPath (string (st_url));
1238+ mr->dhr ->setMethod (string (method));
1239+
1240+ MHD_get_connection_values (connection, MHD_HEADER_KIND, &buildRequestHeader, (void *) mr->dhr );
1241+ MHD_get_connection_values (connection, MHD_FOOTER_KIND, &buildRequestFooter, (void *) mr->dhr );
1242+ MHD_get_connection_values (connection, MHD_COOKIE_KIND, &buildRequestCookie, (void *) mr->dhr );
1243+
12501244 if ( 0 == strcmp (method, MHD_HTTP_METHOD_DELETE) ||
12511245 0 == strcmp (method, MHD_HTTP_METHOD_GET) ||
12521246 0 == strcmp (method, MHD_HTTP_METHOD_HEAD) ||
@@ -1255,7 +1249,7 @@ int Webserver::answerToConnection(void* cls, MHD_Connection* connection,
12551249 0 == strcmp (method, MHD_HTTP_METHOD_TRACE)
12561250 )
12571251 {
1258- MHD_get_connection_values (connection, MHD_GET_ARGUMENT_KIND, &buildRequestArgs, (void *) &supportReq );
1252+ MHD_get_connection_values (connection, MHD_GET_ARGUMENT_KIND, &buildRequestArgs, (void *) mr );
12591253 }
12601254 else if (0 == strcmp (method, MHD_HTTP_METHOD_POST) || 0 == strcmp (method, MHD_HTTP_METHOD_PUT))
12611255 {
@@ -1335,7 +1329,7 @@ int Webserver::answerToConnection(void* cls, MHD_Connection* connection,
13351329 HttpEndpoint matchingEndpoint;
13361330 for (it=dws->registeredResources .begin (); it!=dws->registeredResources .end (); it++)
13371331 {
1338- if (len == -1 || (*it).first .get_url_pieces ().size () > len)
1332+ if (len == -1 || (( int )(( *it).first .get_url_pieces ().size ()) ) > len)
13391333 {
13401334 if ((*it).first .match (endpoint))
13411335 {
@@ -1359,7 +1353,7 @@ int Webserver::answerToConnection(void* cls, MHD_Connection* connection,
13591353 vector<string> url_pars = matchingEndpoint.get_url_pars ();
13601354 vector<string> url_pieces = endpoint.get_url_pieces ();
13611355 vector<int > chunkes = matchingEndpoint.get_chunk_positions ();
1362- for (int i = 0 ; i < url_pars.size (); i++)
1356+ for (unsigned int i = 0 ; i < url_pars.size (); i++)
13631357 {
13641358 supportReq.setArg (url_pars[i], url_pieces[chunkes[i]]);
13651359 }
0 commit comments