Skip to content

Commit de61c3a

Browse files
author
Sebastiano Merlino
committed
Cleaned some code to avoid lines to be longer than 80 chars
1 parent accbad7 commit de61c3a

13 files changed

+1213
-361
lines changed

src/http_endpoint.cpp

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
1515
You should have received a copy of the GNU Lesser General Public
1616
License along with this library; if not, write to the Free Software
17-
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18-
17+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18+
USA
1919
*/
20+
2021
#include "http_endpoint.hpp"
2122
#include "http_utils.hpp"
2223
#include "string_utilities.hpp"
@@ -31,15 +32,21 @@ using namespace http;
3132
namespace details
3233
{
3334

34-
//ENDPOINT
3535
http_endpoint::~http_endpoint()
3636
{
3737
if(reg_compiled)
3838
{
3939
regfree(&(this->re_url_modded));
4040
}
4141
}
42-
http_endpoint::http_endpoint(const string& url, bool family, bool registration, bool use_regex):
42+
43+
http_endpoint::http_endpoint
44+
(
45+
const string& url,
46+
bool family,
47+
bool registration,
48+
bool use_regex
49+
):
4350
family_url(family),
4451
reg_compiled(false)
4552
{
@@ -77,25 +84,35 @@ http_endpoint::http_endpoint(const string& url, bool family, bool registration,
7784
}
7885
else
7986
{
80-
if(( parts[i].size() >= 3) && (parts[i][0] == '{') && (parts[i][parts[i].size() - 1] == '}') )
87+
if(
88+
(parts[i].size() >= 3) &&
89+
(parts[i][0] == '{') &&
90+
(parts[i][parts[i].size() - 1] == '}')
91+
)
8192
{
8293
int bar = parts[i].find_first_of('|');
8394
if(bar != (int)string::npos)
8495
{
8596
this->url_pars.push_back(parts[i].substr(1, bar - 1));
8697
if(first)
8798
{
88-
this->url_modded += parts[i].substr(bar + 1, parts[i].size() - bar - 2);
99+
this->url_modded += parts[i].substr(
100+
bar + 1, parts[i].size() - bar - 2
101+
);
89102
first = false;
90103
}
91104
else
92105
{
93-
this->url_modded += "/"+parts[i].substr(bar + 1, parts[i].size() - bar - 2);
106+
this->url_modded += "/"+parts[i].substr(
107+
bar + 1, parts[i].size() - bar - 2
108+
);
94109
}
95110
}
96111
else
97112
{
98-
this->url_pars.push_back(parts[i].substr(1,parts[i].size() - 2));
113+
this->url_pars.push_back(
114+
parts[i].substr(1,parts[i].size() - 2)
115+
);
99116
if(first)
100117
{
101118
this->url_modded += "([^\\/]+)";
@@ -135,7 +152,9 @@ http_endpoint::http_endpoint(const string& url, bool family, bool registration,
135152
if(use_regex)
136153
{
137154
this->url_modded += "$";
138-
regcomp(&(this->re_url_modded), url_modded.c_str(), REG_EXTENDED|REG_ICASE|REG_NOSUB);
155+
regcomp(&(this->re_url_modded), url_modded.c_str(),
156+
REG_EXTENDED|REG_ICASE|REG_NOSUB
157+
);
139158
reg_compiled = true;
140159
}
141160
}
@@ -150,7 +169,9 @@ http_endpoint::http_endpoint(const http_endpoint& h):
150169
reg_compiled(h.reg_compiled)
151170
{
152171
if(this->reg_compiled)
153-
regcomp(&(this->re_url_modded), url_modded.c_str(), REG_EXTENDED|REG_ICASE|REG_NOSUB);
172+
regcomp(&(this->re_url_modded), url_modded.c_str(),
173+
REG_EXTENDED|REG_ICASE|REG_NOSUB
174+
);
154175
}
155176

156177
http_endpoint& http_endpoint::operator =(const http_endpoint& h)
@@ -160,7 +181,9 @@ http_endpoint& http_endpoint::operator =(const http_endpoint& h)
160181
this->family_url = h.family_url;
161182
this->reg_compiled = h.reg_compiled;
162183
if(this->reg_compiled)
163-
regcomp(&(this->re_url_modded), url_modded.c_str(), REG_EXTENDED|REG_ICASE|REG_NOSUB);
184+
regcomp(&(this->re_url_modded), url_modded.c_str(),
185+
REG_EXTENDED|REG_ICASE|REG_NOSUB
186+
);
164187
this->url_pars = h.url_pars;
165188
this->url_pieces = h.url_pieces;
166189
this->chunk_positions = h.chunk_positions;
@@ -197,7 +220,8 @@ bool http_endpoint::match(const http_endpoint& url) const
197220
return regexec(&(this->re_url_modded), nn.c_str(), 0, NULL, 0) == 0;
198221
}
199222
else
200-
return regexec(&(this->re_url_modded), url.url_modded.c_str(), 0, NULL, 0) == 0;
223+
return regexec(&(this->re_url_modded),
224+
url.url_modded.c_str(), 0, NULL, 0) == 0;
201225
}
202226

203227
};

src/http_request.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
1515
You should have received a copy of the GNU Lesser General Public
1616
License along with this library; if not, write to the Free Software
17-
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18+
USA
1819
1920
*/
21+
2022
#include "http_utils.hpp"
2123
#include "http_request.hpp"
2224
#include "string_utilities.hpp"
@@ -25,15 +27,26 @@ using namespace std;
2527

2628
namespace httpserver
2729
{
28-
//REQUEST
30+
2931
void http_request::set_method(const std::string& method)
3032
{
3133
string_utilities::to_upper_copy(method, this->method);
3234
}
3335

34-
bool http_request::check_digest_auth(const std::string& realm, const std::string& password, int nonce_timeout, bool& reload_nonce) const
36+
bool http_request::check_digest_auth(
37+
const std::string& realm,
38+
const std::string& password,
39+
int nonce_timeout,
40+
bool& reload_nonce
41+
) const
3542
{
36-
int val = MHD_digest_auth_check(underlying_connection, realm.c_str(), digested_user.c_str(), password.c_str(), nonce_timeout);
43+
int val = MHD_digest_auth_check(
44+
underlying_connection,
45+
realm.c_str(),
46+
digested_user.c_str(),
47+
password.c_str(),
48+
nonce_timeout
49+
);
3750
if(val == MHD_INVALID_NONCE)
3851
{
3952
reload_nonce = true;

src/http_response.cpp

Lines changed: 118 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
1515
You should have received a copy of the GNU Lesser General Public
1616
License along with this library; if not, write to the Free Software
17-
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18-
17+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18+
USA
1919
*/
20+
2021
#include <cstdio>
2122
#include <functional>
2223
#include <iostream>
@@ -107,7 +108,12 @@ shoutCAST_response::shoutCAST_response
107108
const std::string& content_type,
108109
bool autodelete
109110
):
110-
http_response(this, content, response_code | http_utils::shoutcast_response, content_type, autodelete)
111+
http_response(
112+
this,
113+
content,
114+
response_code | http_utils::shoutcast_response,
115+
content_type,autodelete
116+
)
111117
{
112118
}
113119

@@ -119,21 +125,42 @@ ssize_t deferred_response::cycle_callback(const std::string& buf)
119125
void http_response::get_raw_response_str(MHD_Response** response, webserver* ws)
120126
{
121127
size_t size = &(*content.end()) - &(*content.begin());
122-
*response = MHD_create_response_from_buffer(size, (void*) content.c_str(), MHD_RESPMEM_PERSISTENT);
128+
*response = MHD_create_response_from_buffer(
129+
size,
130+
(void*) content.c_str(),
131+
MHD_RESPMEM_PERSISTENT
132+
);
123133
}
124134

125135
void http_response::decorate_response_str(MHD_Response* response)
126136
{
127137
map<string, string, header_comparator>::iterator it;
138+
128139
for (it=headers.begin() ; it != headers.end(); ++it)
129-
MHD_add_response_header(response, (*it).first.c_str(), (*it).second.c_str());
140+
MHD_add_response_header(
141+
response,
142+
(*it).first.c_str(),
143+
(*it).second.c_str()
144+
);
145+
130146
for (it=footers.begin() ; it != footers.end(); ++it)
131-
MHD_add_response_footer(response, (*it).first.c_str(), (*it).second.c_str());
147+
MHD_add_response_footer(response,
148+
(*it).first.c_str(),
149+
(*it).second.c_str()
150+
);
151+
132152
for (it=cookies.begin(); it != cookies.end(); ++it)
133-
MHD_add_response_header(response, "Set-Cookie", ((*it).first + "=" + (*it).second).c_str());
153+
MHD_add_response_header(
154+
response,
155+
"Set-Cookie",
156+
((*it).first + "=" + (*it).second).c_str()
157+
);
134158
}
135159

136-
int http_response::enqueue_response_str(MHD_Connection* connection, MHD_Response* response)
160+
int http_response::enqueue_response_str(
161+
MHD_Connection* connection,
162+
MHD_Response* response
163+
)
137164
{
138165
return MHD_queue_response(connection, response_code, response);
139166
}
@@ -142,27 +169,57 @@ void http_response::decorate_response_cache(MHD_Response* response)
142169
{
143170
}
144171

145-
int http_response::enqueue_response_basic(MHD_Connection* connection, MHD_Response* response)
172+
int http_response::enqueue_response_basic(
173+
MHD_Connection* connection,
174+
MHD_Response* response
175+
)
146176
{
147-
return MHD_queue_basic_auth_fail_response(connection, realm.c_str(), response);
177+
return MHD_queue_basic_auth_fail_response(
178+
connection,
179+
realm.c_str(),
180+
response
181+
);
148182
}
149183

150-
int http_response::enqueue_response_digest(MHD_Connection* connection, MHD_Response* response)
184+
int http_response::enqueue_response_digest(
185+
MHD_Connection* connection,
186+
MHD_Response* response
187+
)
151188
{
152-
return MHD_queue_auth_fail_response(connection, realm.c_str(), opaque.c_str(), response, reload_nonce ? MHD_YES : MHD_NO);
189+
return MHD_queue_auth_fail_response(
190+
connection,
191+
realm.c_str(),
192+
opaque.c_str(),
193+
response,
194+
reload_nonce ? MHD_YES : MHD_NO
195+
);
153196
}
154197

155-
void http_response::get_raw_response_file(MHD_Response** response, webserver* ws)
198+
void http_response::get_raw_response_file(
199+
MHD_Response** response,
200+
webserver* ws
201+
)
156202
{
157203
char* page = NULL;
158204
size_t size = http::load_file(filename.c_str(), &page);
159205
if(size)
160-
*response = MHD_create_response_from_buffer(size, page, MHD_RESPMEM_MUST_FREE);
206+
*response = MHD_create_response_from_buffer(
207+
size,
208+
page,
209+
MHD_RESPMEM_MUST_FREE
210+
);
161211
else
162-
*response = MHD_create_response_from_buffer(size, (void*) "", MHD_RESPMEM_PERSISTENT);
212+
*response = MHD_create_response_from_buffer(
213+
size,
214+
(void*) "",
215+
MHD_RESPMEM_PERSISTENT
216+
);
163217
}
164218

165-
void http_response::get_raw_response_cache(MHD_Response** response, webserver* ws)
219+
void http_response::get_raw_response_cache(
220+
MHD_Response** response,
221+
webserver* ws
222+
)
166223
{
167224
bool valid;
168225
http_response* r;
@@ -189,10 +246,19 @@ ssize_t cb(void* cls, uint64_t pos, char* buf, size_t max)
189246

190247
}
191248

192-
void http_response::get_raw_response_deferred(MHD_Response** response, webserver* ws)
249+
void http_response::get_raw_response_deferred(
250+
MHD_Response** response,
251+
webserver* ws
252+
)
193253
{
194254
if(!completed)
195-
*response = MHD_create_response_from_callback(MHD_SIZE_UNKNOWN, 1024, &details::cb, this, NULL);
255+
*response = MHD_create_response_from_callback(
256+
MHD_SIZE_UNKNOWN,
257+
1024,
258+
&details::cb,
259+
this,
260+
NULL
261+
);
196262
else
197263
static_cast<http_response*>(this)->get_raw_response(response, ws);
198264
}
@@ -203,23 +269,48 @@ void http_response::decorate_response_deferred(MHD_Response* response)
203269
static_cast<http_response*>(this)->decorate_response(response);
204270
}
205271

206-
void http_response::get_raw_response_lp_receive(MHD_Response** response, webserver* ws)
272+
void http_response::get_raw_response_lp_receive(
273+
MHD_Response** response,
274+
webserver* ws
275+
)
207276
{
277+
208278
#ifdef USE_COMET
209279
this->ws = ws;
210-
this->connection_id = MHD_get_connection_info(this->underlying_connection, MHD_CONNECTION_INFO_FD)->socket_fd;
280+
this->connection_id = MHD_get_connection_info(
281+
this->underlying_connection,
282+
MHD_CONNECTION_INFO_FD
283+
)->socket_fd;
284+
211285
*response = MHD_create_response_from_callback(MHD_SIZE_UNKNOWN, 80,
212286
&long_polling_receive_response::data_generator, (void*) this, NULL);
213-
ws->register_to_topics(topics, connection_id, keepalive_secs, keepalive_msg);
287+
288+
ws->register_to_topics(
289+
topics,
290+
connection_id,
291+
keepalive_secs,
292+
keepalive_msg
293+
);
294+
214295
#else //USE_COMET
296+
215297
http_response::get_raw_response(response, ws);
298+
216299
#endif //USE_COMET
300+
217301
}
218302

219-
ssize_t long_polling_receive_response::data_generator (void* cls, uint64_t pos, char* buf, size_t max)
303+
ssize_t long_polling_receive_response::data_generator(
304+
void* cls,
305+
uint64_t pos,
306+
char* buf,
307+
size_t max
308+
)
220309
{
221310
#ifdef USE_COMET
222-
long_polling_receive_response* _this = static_cast<long_polling_receive_response*>(cls);
311+
long_polling_receive_response* _this =
312+
static_cast<long_polling_receive_response*>(cls);
313+
223314
if(_this->ws->pop_signaled(_this->connection_id))
224315
{
225316
string message;
@@ -234,7 +325,10 @@ ssize_t long_polling_receive_response::data_generator (void* cls, uint64_t pos,
234325
#endif //USE_COMET
235326
}
236327

237-
void http_response::get_raw_response_lp_send(MHD_Response** response, webserver* ws)
328+
void http_response::get_raw_response_lp_send(
329+
MHD_Response** response,
330+
webserver* ws
331+
)
238332
{
239333
http_response::get_raw_response(response, ws);
240334
#ifdef USE_COMET

0 commit comments

Comments
 (0)