Skip to content

Commit 0dae021

Browse files
committed
more fixes from cpplint
1 parent 550a8d7 commit 0dae021

20 files changed

+484
-768
lines changed

CPPLINT.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
linelength=200
22
headers=hpp
33
extensions=cpp,hpp
4-
filter=-test/littletest.hpp,-build/c++11
4+
filter=-test/littletest.hpp

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ AC_SUBST(EXT_LIB_PATH)
270270
AC_SUBST(EXT_LIBS)
271271

272272
AC_CONFIG_FILES([test/test_content:test/test_content])
273+
AC_CONFIG_FILES([test/test_content_empty:test/test_content_empty])
273274
AC_CONFIG_FILES([test/cert.pem:test/cert.pem])
274275
AC_CONFIG_FILES([test/key.pem:test/key.pem])
275276
AC_CONFIG_FILES([test/test_root_ca.pem:test/test_root_ca.pem])

examples/deferred_with_accumulator.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
*/
2020

2121
#include <atomic>
22-
#include <chrono>
23-
#include <thread>
22+
// cpplint errors on chrono and thread because they are replaced (in Chromium) by other google libraries.
23+
// This is not an issue here.
24+
#include <chrono> // NOLINT [build/c++11]
25+
#include <thread> // NOLINT [build/c++11]
2426

2527
#include <httpserver.hpp>
2628

src/basic_auth_fail_response.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,10 @@
2525
struct MHD_Connection;
2626
struct MHD_Response;
2727

28-
using namespace std;
29-
30-
namespace httpserver
31-
{
32-
33-
int basic_auth_fail_response::enqueue_response(MHD_Connection* connection, MHD_Response* response)
34-
{
35-
return MHD_queue_basic_auth_fail_response(
36-
connection,
37-
realm.c_str(),
38-
response
39-
);
40-
}
28+
namespace httpserver {
4129

30+
int basic_auth_fail_response::enqueue_response(MHD_Connection* connection, MHD_Response* response) {
31+
return MHD_queue_basic_auth_fail_response(connection, realm.c_str(), response);
4232
}
33+
34+
} // namespace httpserver

src/deferred_response.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,14 @@
2424

2525
struct MHD_Response;
2626

27-
using namespace std;
27+
namespace httpserver {
2828

29-
namespace httpserver
30-
{
29+
namespace details {
3130

32-
namespace details
33-
{
34-
35-
MHD_Response* get_raw_response_helper(void* cls, ssize_t (*cb)(void*, uint64_t, char*, size_t))
36-
{
31+
MHD_Response* get_raw_response_helper(void* cls, ssize_t (*cb)(void*, uint64_t, char*, size_t)) {
3732
return MHD_create_response_from_callback(MHD_SIZE_UNKNOWN, 1024, cb, cls, NULL);
3833
}
3934

40-
}
35+
} // namespace details
4136

42-
}
37+
} // namespace httpserver

src/details/http_endpoint.cpp

Lines changed: 31 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
#include <algorithm>
2323
#include <map>
2424
#include <memory>
25-
#include <regex>
25+
// Disabling lint error on regex (the only reason it errors is because the Chromium team prefers google/re2)
26+
#include <regex> // NOLINT [build/c++11]
2627
#include <sstream>
2728
#include <stdexcept>
2829
#include <string>
@@ -31,32 +32,20 @@
3132
#include "httpserver/details/http_endpoint.hpp"
3233
#include "httpserver/http_utils.hpp"
3334

34-
using namespace std;
35+
using std::string;
36+
using std::vector;
3537

36-
namespace httpserver
37-
{
38+
namespace httpserver {
3839

39-
namespace details
40-
{
40+
namespace details {
4141

42-
using namespace http;
43-
44-
http_endpoint::~http_endpoint()
45-
{
42+
http_endpoint::~http_endpoint() {
4643
}
4744

48-
http_endpoint::http_endpoint
49-
(
50-
const string& url,
51-
bool family,
52-
bool registration,
53-
bool use_regex
54-
):
45+
http_endpoint::http_endpoint(const string& url, bool family, bool registration, bool use_regex):
5546
family_url(family),
56-
reg_compiled(false)
57-
{
58-
if (use_regex && !registration)
59-
{
47+
reg_compiled(false) {
48+
if (use_regex && !registration) {
6049
throw std::invalid_argument("Cannot use regex if not during registration");
6150
}
6251

@@ -69,24 +58,20 @@ http_endpoint::http_endpoint
6958
url_complete = url;
7059
#endif
7160

72-
if (url_complete[url_complete.size() - 1] == '/')
73-
{
61+
if (url_complete[url_complete.size() - 1] == '/') {
7462
url_complete = url_complete.substr(0, url_complete.size() - 1);
7563
}
7664

77-
if (url_complete[0] != '/')
78-
{
65+
if (url_complete[0] != '/') {
7966
url_complete = "/" + url_complete;
8067
}
8168

82-
parts = http_utils::tokenize_url(url);
69+
parts = httpserver::http::http_utils::tokenize_url(url);
8370
string buffered;
8471
bool first = true;
8572

86-
for (unsigned int i = 0; i < parts.size(); i++)
87-
{
88-
if(!registration)
89-
{
73+
for (unsigned int i = 0; i < parts.size(); i++) {
74+
if (!registration) {
9075
url_normalized += (first ? "" : "/") + parts[i];
9176
first = false;
9277

@@ -95,24 +80,21 @@ http_endpoint::http_endpoint
9580
continue;
9681
}
9782

98-
if((parts[i] != "") && (parts[i][0] != '{'))
99-
{
100-
if(first)
101-
{
83+
if ((parts[i] != "") && (parts[i][0] != '{')) {
84+
if (first) {
10285
url_normalized = (parts[i][0] == '^' ? "" : url_normalized) + parts[i];
10386
first = false;
104-
}
105-
else
106-
{
87+
} else {
10788
url_normalized += "/" + parts[i];
10889
}
10990
url_pieces.push_back(parts[i]);
11091

11192
continue;
11293
}
11394

114-
if((parts[i].size() < 3) || (parts[i][0] != '{') || (parts[i][parts[i].size() - 1] != '}'))
95+
if ((parts[i].size() < 3) || (parts[i][0] != '{') || (parts[i][parts[i].size() - 1] != '}')) {
11596
throw std::invalid_argument("Bad URL format");
97+
}
11698

11799
std::string::size_type bar = parts[i].find_first_of('|');
118100
url_pars.push_back(parts[i].substr(1, bar != string::npos ? bar - 1 : parts[i].size() - 2));
@@ -125,15 +107,11 @@ http_endpoint::http_endpoint
125107
url_pieces.push_back(parts[i]);
126108
}
127109

128-
if(use_regex)
129-
{
110+
if (use_regex) {
130111
url_normalized += "$";
131-
try
132-
{
112+
try {
133113
re_url_normalized = std::regex(url_normalized, std::regex::extended | std::regex::icase | std::regex::nosubs);
134-
}
135-
catch (std::regex_error& e)
136-
{
114+
} catch (std::regex_error& e) {
137115
throw std::invalid_argument("Not a valid regex in URL: " + url_normalized);
138116
}
139117
reg_compiled = true;
@@ -148,12 +126,10 @@ http_endpoint::http_endpoint(const http_endpoint& h):
148126
chunk_positions(h.chunk_positions),
149127
re_url_normalized(h.re_url_normalized),
150128
family_url(h.family_url),
151-
reg_compiled(h.reg_compiled)
152-
{
129+
reg_compiled(h.reg_compiled) {
153130
}
154131

155-
http_endpoint& http_endpoint::operator =(const http_endpoint& h)
156-
{
132+
http_endpoint& http_endpoint::operator =(const http_endpoint& h) {
157133
url_complete = h.url_complete;
158134
url_normalized = h.url_normalized;
159135
family_url = h.family_url;
@@ -165,30 +141,26 @@ http_endpoint& http_endpoint::operator =(const http_endpoint& h)
165141
return *this;
166142
}
167143

168-
bool http_endpoint::operator <(const http_endpoint& b) const
169-
{
144+
bool http_endpoint::operator <(const http_endpoint& b) const {
170145
COMPARATOR(url_normalized, b.url_normalized, std::toupper);
171146
}
172147

173-
bool http_endpoint::match(const http_endpoint& url) const
174-
{
148+
bool http_endpoint::match(const http_endpoint& url) const {
175149
if (!reg_compiled) throw std::invalid_argument("Cannot run match. Regex suppressed.");
176150

177-
if(!family_url || url.url_pieces.size() < url_pieces.size())
178-
{
151+
if (!family_url || url.url_pieces.size() < url_pieces.size()) {
179152
return regex_match(url.url_complete, re_url_normalized);
180153
}
181154

182155
string nn = "/";
183156
bool first = true;
184-
for(unsigned int i = 0; i < url_pieces.size(); i++)
185-
{
157+
for (unsigned int i = 0; i < url_pieces.size(); i++) {
186158
nn += (first ? "" : "/") + url.url_pieces[i];
187159
first = false;
188160
}
189161
return regex_match(nn, re_url_normalized);
190162
}
191163

192-
};
164+
}; // namespace details
193165

194-
};
166+
}; // namespace httpserver

src/digest_auth_fail_response.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,10 @@
2525
struct MHD_Connection;
2626
struct MHD_Response;
2727

28-
using namespace std;
29-
30-
namespace httpserver
31-
{
32-
33-
int digest_auth_fail_response::enqueue_response(MHD_Connection* connection, MHD_Response* response)
34-
{
35-
return MHD_queue_auth_fail_response(
36-
connection,
37-
realm.c_str(),
38-
opaque.c_str(),
39-
response,
40-
reload_nonce ? MHD_YES : MHD_NO
41-
);
42-
}
28+
namespace httpserver {
4329

30+
int digest_auth_fail_response::enqueue_response(MHD_Connection* connection, MHD_Response* response) {
31+
return MHD_queue_auth_fail_response(connection, realm.c_str(), opaque.c_str(), response, reload_nonce ? MHD_YES : MHD_NO);
4432
}
33+
34+
} // namespace httpserver

src/file_response.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,16 @@
2727

2828
struct MHD_Response;
2929

30-
using namespace std;
30+
namespace httpserver {
3131

32-
namespace httpserver
33-
{
34-
35-
MHD_Response* file_response::get_raw_response()
36-
{
32+
MHD_Response* file_response::get_raw_response() {
3733
int fd = open(filename.c_str(), O_RDONLY);
3834
size_t size = lseek(fd, 0, SEEK_END);
39-
if(size)
40-
{
35+
if (size) {
4136
return MHD_create_response_from_fd(size, fd);
42-
}
43-
else
44-
{
45-
return MHD_create_response_from_buffer(
46-
0,
47-
(void*) "",
48-
MHD_RESPMEM_PERSISTENT
49-
);
37+
} else {
38+
return MHD_create_response_from_buffer(0, 0x0, MHD_RESPMEM_PERSISTENT);
5039
}
5140
}
5241

53-
}
42+
} // namespace httpserver

0 commit comments

Comments
 (0)