Skip to content

Commit 107c3ce

Browse files
author
Sebastiano Merlino
committed
Solved some performance and style issues
1 parent d67334b commit 107c3ce

File tree

8 files changed

+47
-45
lines changed

8 files changed

+47
-45
lines changed

src/http_request.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const std::vector<std::pair<std::string, std::string> > http_request::get_header
5252
{
5353
std::vector<std::pair<std::string, std::string> > to_ret;
5454
std::map<std::string, std::string, header_comparator>::const_iterator it;
55-
for(it = headers.begin(); it != headers.end(); it++)
55+
for(it = headers.begin(); it != headers.end(); ++it)
5656
#ifdef USE_CPP_ZEROX
5757
to_ret.push_back(std::make_pair((*it).first,(*it).second));
5858
#else
@@ -63,7 +63,7 @@ const std::vector<std::pair<std::string, std::string> > http_request::get_header
6363
size_t http_request::get_headers(std::vector<std::pair<std::string, std::string> >& result) const
6464
{
6565
std::map<std::string, std::string, header_comparator>::const_iterator it;
66-
for(it = headers.begin(); it != headers.end(); it++)
66+
for(it = headers.begin(); it != headers.end(); ++it)
6767
#ifdef USE_CPP_ZEROX
6868
result.push_back(std::make_pair((*it).first,(*it).second));
6969
#else
@@ -84,7 +84,7 @@ const std::vector<std::pair<std::string, std::string> > http_request::get_footer
8484
{
8585
std::vector<std::pair<std::string, std::string> > to_ret;
8686
std::map<std::string, std::string, header_comparator>::const_iterator it;
87-
for(it = footers.begin(); it != footers.end(); it++)
87+
for(it = footers.begin(); it != footers.end(); ++it)
8888
#ifdef USE_CPP_ZEROX
8989
to_ret.push_back(std::make_pair((*it).first,(*it).second));
9090
#else
@@ -95,7 +95,7 @@ const std::vector<std::pair<std::string, std::string> > http_request::get_footer
9595
size_t http_request::get_footers(std::vector<std::pair<std::string, std::string> >& result) const
9696
{
9797
std::map<std::string, std::string, header_comparator>::const_iterator it;
98-
for(it = footers.begin(); it != footers.end(); it++)
98+
for(it = footers.begin(); it != footers.end(); ++it)
9999
#ifdef USE_CPP_ZEROX
100100
result.push_back(std::make_pair((*it).first,(*it).second));
101101
#else
@@ -116,7 +116,7 @@ const std::vector<std::pair<std::string, std::string> > http_request::get_cookie
116116
{
117117
std::vector<std::pair<std::string, std::string> > to_ret;
118118
std::map<std::string, std::string, header_comparator>::const_iterator it;
119-
for(it = cookies.begin(); it != cookies.end(); it++)
119+
for(it = cookies.begin(); it != cookies.end(); ++it)
120120
#ifdef USE_CPP_ZEROX
121121
to_ret.push_back(std::make_pair((*it).first,(*it).second));
122122
#else
@@ -128,7 +128,7 @@ const std::vector<std::pair<std::string, std::string> > http_request::get_cookie
128128
size_t http_request::get_cookies(std::vector<std::pair<std::string, std::string> >& result) const
129129
{
130130
std::map<std::string, std::string, header_comparator>::const_iterator it;
131-
for(it = cookies.begin(); it != cookies.end(); it++)
131+
for(it = cookies.begin(); it != cookies.end(); ++it)
132132
#ifdef USE_CPP_ZEROX
133133
result.push_back(std::make_pair((*it).first,(*it).second));
134134
#else
@@ -149,7 +149,7 @@ const std::vector<std::pair<std::string, std::string> > http_request::get_args()
149149
{
150150
std::vector<std::pair<std::string, std::string> > to_ret;
151151
std::map<std::string, std::string, arg_comparator>::const_iterator it;
152-
for(it = args.begin(); it != args.end(); it++)
152+
for(it = args.begin(); it != args.end(); ++it)
153153
#ifdef USE_CPP_ZEROX
154154
to_ret.push_back(std::make_pair((*it).first,(*it).second));
155155
#else
@@ -161,7 +161,7 @@ const std::vector<std::pair<std::string, std::string> > http_request::get_args()
161161
size_t http_request::get_args(std::vector<std::pair<std::string, std::string> >& result) const
162162
{
163163
std::map<std::string, std::string, header_comparator>::const_iterator it;
164-
for(it = args.begin(); it != args.end(); it++)
164+
for(it = args.begin(); it != args.end(); ++it)
165165
#ifdef USE_CPP_ZEROX
166166
result.push_back(std::make_pair((*it).first,(*it).second));
167167
#else

src/http_resource.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ http_resource::http_resource()
4141
this->allowed_methods[MHD_HTTP_METHOD_OPTIONS] = true;
4242
#ifdef DEBUG
4343
std::map<std::string, bool>::iterator it;
44-
for(it = allowed_methods.begin(); it != allowed_methods.end(); it++)
44+
for(it = allowed_methods.begin(); it != allowed_methods.end(); ++it)
4545
{
4646
std::cout << (*it).first << " -> " << (*it).second << std::endl;
4747
}

src/http_response.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const std::vector<std::pair<std::string, std::string> > http_response::get_heade
3333
{
3434
std::vector<std::pair<std::string, std::string> > to_ret;
3535
std::map<std::string, std::string, header_comparator>::const_iterator it;
36-
for(it = headers.begin(); it != headers.end(); it++)
36+
for(it = headers.begin(); it != headers.end(); ++it)
3737
#ifdef USE_CPP_ZEROX
3838
to_ret.push_back(std::make_pair((*it).first,(*it).second));
3939
#else
@@ -44,7 +44,7 @@ const std::vector<std::pair<std::string, std::string> > http_response::get_heade
4444
size_t http_response::get_headers(std::vector<std::pair<std::string, std::string> >& result)
4545
{
4646
std::map<std::string, std::string, header_comparator>::const_iterator it;
47-
for(it = headers.begin(); it != headers.end(); it++)
47+
for(it = headers.begin(); it != headers.end(); ++it)
4848
#ifdef USE_CPP_ZEROX
4949
result.push_back(std::make_pair((*it).first,(*it).second));
5050
#else
@@ -62,7 +62,7 @@ const std::vector<std::pair<std::string, std::string> > http_response::get_foote
6262
{
6363
std::vector<std::pair<std::string, std::string> > to_ret;
6464
std::map<std::string, std::string, header_comparator>::const_iterator it;
65-
for(it = footers.begin(); it != footers.end(); it++)
65+
for(it = footers.begin(); it != footers.end(); ++it)
6666
#ifdef USE_CPP_ZEROX
6767
to_ret.push_back(std::make_pair((*it).first,(*it).second));
6868
#else
@@ -73,7 +73,7 @@ const std::vector<std::pair<std::string, std::string> > http_response::get_foote
7373
size_t http_response::get_footers(std::vector<std::pair<std::string, std::string> >& result)
7474
{
7575
std::map<std::string, std::string, arg_comparator>::const_iterator it;
76-
for(it = footers.begin(); it != footers.end(); it++)
76+
for(it = footers.begin(); it != footers.end(); ++it)
7777
#ifdef USE_CPP_ZEROX
7878
result.push_back(std::make_pair((*it).first,(*it).second));
7979
#else

src/httpserver/http_request.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ class http_request
503503
void set_headers(const std::map<std::string, std::string>& headers)
504504
{
505505
std::map<std::string, std::string>::const_iterator it;
506-
for(it = headers.begin(); it != headers.end(); it++)
506+
for(it = headers.begin(); it != headers.end(); ++it)
507507
this->headers[it->first] = it->second;
508508
}
509509
/**
@@ -513,7 +513,7 @@ class http_request
513513
void set_footers(const std::map<std::string, std::string>& footers)
514514
{
515515
std::map<std::string, std::string>::const_iterator it;
516-
for(it = footers.begin(); it != footers.end(); it++)
516+
for(it = footers.begin(); it != footers.end(); ++it)
517517
this->footers[it->first] = it->second;
518518
}
519519
/**
@@ -523,7 +523,7 @@ class http_request
523523
void set_cookies(const std::map<std::string, std::string>& cookies)
524524
{
525525
std::map<std::string, std::string>::const_iterator it;
526-
for(it = cookies.begin(); it != cookies.end(); it++)
526+
for(it = cookies.begin(); it != cookies.end(); ++it)
527527
this->cookies[it->first] = it->second;
528528
}
529529
/**
@@ -533,7 +533,7 @@ class http_request
533533
void set_args(const std::map<std::string, std::string>& args)
534534
{
535535
std::map<std::string, std::string>::const_iterator it;
536-
for(it = args.begin(); it != args.end(); it++)
536+
for(it = args.begin(); it != args.end(); ++it)
537537
this->args[it->first] = it->second;
538538
}
539539
/**

src/httpserver/http_resource.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class http_resource
136136
void allow_all()
137137
{
138138
std::map<std::string,bool>::iterator it;
139-
for ( it=this->allowed_methods.begin() ; it != this->allowed_methods.end(); it++ )
139+
for ( it=this->allowed_methods.begin() ; it != this->allowed_methods.end(); ++it )
140140
this->allowed_methods[(*it).first] = true;
141141
}
142142
/**
@@ -145,7 +145,7 @@ class http_resource
145145
void disallow_all()
146146
{
147147
std::map<std::string,bool>::iterator it;
148-
for ( it=this->allowed_methods.begin() ; it != this->allowed_methods.end(); it++ )
148+
for ( it=this->allowed_methods.begin() ; it != this->allowed_methods.end(); ++it )
149149
this->allowed_methods[(*it).first] = false;
150150
}
151151
/**
@@ -163,7 +163,7 @@ class http_resource
163163
{
164164
#ifdef DEBUG
165165
std::map<std::string, bool>::iterator it;
166-
for(it = allowed_methods.begin(); it != allowed_methods.end(); it++)
166+
for(it = allowed_methods.begin(); it != allowed_methods.end(); ++it)
167167
{
168168
std::cout << (*it).first << " -> " << (*it).second << std::endl;
169169
}
@@ -181,9 +181,10 @@ class http_resource
181181
**/
182182
http_resource(const http_resource& b) : allowed_methods(b.allowed_methods) { }
183183

184-
void operator = (const http_resource& b)
184+
http_resource& operator = (const http_resource& b)
185185
{
186186
allowed_methods = b.allowed_methods;
187+
return (*this);
187188
}
188189

189190
private:

src/httpserver/http_response.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class http_response
204204
void set_headers(const std::map<std::string, std::string>& headers)
205205
{
206206
std::map<std::string, std::string>::const_iterator it;
207-
for(it = headers.begin(); it != headers.end(); it ++)
207+
for(it = headers.begin(); it != headers.end(); ++it)
208208
this->headers[it->first] = it->second;
209209
}
210210
/**
@@ -214,7 +214,7 @@ class http_response
214214
void set_footers(const std::map<std::string, std::string>& footers)
215215
{
216216
std::map<std::string, std::string>::const_iterator it;
217-
for(it = footers.begin(); it != footers.end(); it ++)
217+
for(it = footers.begin(); it != footers.end(); ++it)
218218
this->footers[it->first] = it->second;
219219
}
220220
/**

src/httpserver/webserver.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ class create_webserver
326326
_log_delegate(0x0),
327327
_validator(0x0),
328328
_unescaper_pointer(0x0),
329+
_bind_address(0x0),
330+
_bind_socket(0),
329331
_max_thread_stack_size(0),
330332
_use_ssl(false),
331333
_use_ipv6(false),

src/webserver.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,8 @@ void webserver::unregister_resource(const string& resource)
421421
void webserver::ban_ip(const string& ip)
422422
{
423423
ip_representation t_ip(ip);
424-
set<ip_representation>::iterator it = bans.find(t_ip);
425-
if(it != bans.end() && (t_ip.weight() < (*it).weight()))
424+
set<ip_representation>::iterator it = this->bans.find(t_ip);
425+
if(it != this->bans.end() && (t_ip.weight() < (*it).weight()))
426426
{
427427
this->bans.erase(it);
428428
this->bans.insert(t_ip);
@@ -434,8 +434,8 @@ void webserver::ban_ip(const string& ip)
434434
void webserver::allow_ip(const string& ip)
435435
{
436436
ip_representation t_ip(ip);
437-
set<ip_representation>::iterator it = allowances.find(t_ip);
438-
if(it != allowances.end() && (t_ip.weight() < (*it).weight()))
437+
set<ip_representation>::iterator it = this->allowances.find(t_ip);
438+
if(it != this->allowances.end() && (t_ip.weight() < (*it).weight()))
439439
{
440440
this->allowances.erase(it);
441441
this->allowances.insert(t_ip);
@@ -456,44 +456,44 @@ void webserver::disallow_ip(const string& ip)
456456

457457
int webserver::build_request_header (void *cls, enum MHD_ValueKind kind, const char *key, const char *value)
458458
{
459-
http_request* dhr = (http_request*)(cls);
459+
http_request* dhr = static_cast<http_request*>(cls);
460460
dhr->set_header(key, value);
461461
return MHD_YES;
462462
}
463463

464464
int webserver::build_request_cookie (void *cls, enum MHD_ValueKind kind, const char *key, const char *value)
465465
{
466-
http_request* dhr = (http_request*)(cls);
466+
http_request* dhr = static_cast<http_request*>(cls);
467467
dhr->set_cookie(key, value);
468468
return MHD_YES;
469469
}
470470

471471
int webserver::build_request_footer (void *cls, enum MHD_ValueKind kind, const char *key, const char *value)
472472
{
473-
http_request* dhr = (http_request*)(cls);
473+
http_request* dhr = static_cast<http_request*>(cls);
474474
dhr->set_footer(key, value);
475475
return MHD_YES;
476476
}
477477

478478
int webserver::build_request_args (void *cls, enum MHD_ValueKind kind, const char *key, const char *value)
479479
{
480-
modded_request* mr = (modded_request*)(cls);
480+
modded_request* mr = static_cast<modded_request*>(cls);
481481
int size = internal_unescaper((void*)mr->ws, (char*) value);
482482
mr->dhr->set_arg(key, string(value, size));
483483
return MHD_YES;
484484
}
485485

486486
int policy_callback (void *cls, const struct sockaddr* addr, socklen_t addrlen)
487487
{
488-
if(((webserver*)cls)->ban_system_enabled)
488+
if((static_cast<webserver*>(cls))->ban_system_enabled)
489489
{
490-
if(((((webserver*)cls)->default_policy == http_utils::ACCEPT) &&
491-
(((webserver*)cls)->bans.count(addr)) &&
492-
(!((webserver*)cls)->allowances.count(addr))
490+
if((((static_cast<webserver*>(cls))->default_policy == http_utils::ACCEPT) &&
491+
((static_cast<webserver*>(cls))->bans.count(addr)) &&
492+
(!(static_cast<webserver*>(cls))->allowances.count(addr))
493493
) ||
494-
((((webserver*)cls)->default_policy == http_utils::REJECT) &&
495-
((!((webserver*)cls)->allowances.count(addr)) ||
496-
(((webserver*)cls)->bans.count(addr)))
494+
(((static_cast<webserver*>(cls))->default_policy == http_utils::REJECT) &&
495+
((!(static_cast<webserver*>(cls))->allowances.count(addr)) ||
496+
((static_cast<webserver*>(cls))->bans.count(addr)))
497497
))
498498
return MHD_NO;
499499
}
@@ -510,7 +510,7 @@ void* uri_log(void* cls, const char* uri)
510510

511511
void error_log(void* cls, const char* fmt, va_list ap)
512512
{
513-
webserver* dws = (webserver*) cls;
513+
webserver* dws = static_cast<webserver*>(cls);
514514
if(dws->log_delegate != 0x0)
515515
{
516516
dws->log_delegate->log_error(fmt);
@@ -544,7 +544,7 @@ size_t unescaper_func(void * cls, struct MHD_Connection *c, char *s)
544544

545545
size_t internal_unescaper(void* cls, char* s)
546546
{
547-
webserver* dws = (webserver*) cls;
547+
webserver* dws = static_cast<webserver*>(cls);
548548
if(dws->unescaper_pointer != 0x0)
549549
{
550550
dws->unescaper_pointer->unescape(s);
@@ -624,7 +624,7 @@ int webserver::answer_to_connection(void* cls, MHD_Connection* connection,
624624
struct MHD_Response *response = 0x0;
625625
struct modded_request *mr;
626626
http_request support_req;
627-
webserver* dws = (webserver*)(cls);
627+
webserver* dws = static_cast<webserver*>(cls);
628628
internal_unescaper(cls, (char*) url);
629629
string st_url;
630630
http_utils::standardize_url(url, st_url);
@@ -667,7 +667,6 @@ int webserver::answer_to_connection(void* cls, MHD_Connection* connection,
667667

668668
if ( 0 == strcmp(method, MHD_HTTP_METHOD_DELETE) ||
669669
0 == strcmp(method, MHD_HTTP_METHOD_GET) ||
670-
0 == strcmp(method, MHD_HTTP_METHOD_HEAD) ||
671670
0 == strcmp(method, MHD_HTTP_METHOD_CONNECT) ||
672671
0 == strcmp(method, MHD_HTTP_METHOD_HEAD) ||
673672
0 == strcmp(method, MHD_HTTP_METHOD_TRACE)
@@ -749,7 +748,7 @@ int webserver::answer_to_connection(void* cls, MHD_Connection* connection,
749748
map<http_endpoint, http_resource* >::iterator it;
750749
int len = -1;
751750
int tot_len = -1;
752-
for(it=dws->registered_resources.begin(); it!=dws->registered_resources.end(); it++)
751+
for(it=dws->registered_resources.begin(); it!=dws->registered_resources.end(); ++it)
753752
{
754753
int endpoint_pieces_len = (*it).first.get_url_pieces_num();
755754
int endpoint_tot_len = (*it).first.get_url_complete_size();
@@ -842,9 +841,9 @@ int webserver::answer_to_connection(void* cls, MHD_Connection* connection,
842841
vector<pair<string,string> > response_footers;
843842
dhrs.get_footers(response_footers);
844843
vector<pair<string,string> >::iterator it;
845-
for (it=response_headers.begin() ; it != response_headers.end(); it++)
844+
for (it=response_headers.begin() ; it != response_headers.end(); ++it)
846845
MHD_add_response_header(response, (*it).first.c_str(), (*it).second.c_str());
847-
for (it=response_footers.begin() ; it != response_footers.end(); it++)
846+
for (it=response_footers.begin() ; it != response_footers.end(); ++it)
848847
MHD_add_response_footer(response, (*it).first.c_str(), (*it).second.c_str());
849848
if(dhrs.response_type == http_response::DIGEST_AUTH_FAIL)
850849
to_ret = MHD_queue_auth_fail_response(connection, dhrs.get_realm().c_str(), dhrs.get_opaque().c_str(), response, dhrs.need_nonce_reload() ? MHD_YES : MHD_NO);

0 commit comments

Comments
 (0)