Skip to content

Commit 31759d8

Browse files
committed
Improve style
1 parent 5122b01 commit 31759d8

File tree

7 files changed

+20
-20
lines changed

7 files changed

+20
-20
lines changed

src/config/Config.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ std::string isListen(std::string const &value, size_t index) {
9696
port = value.substr(pos + 1);
9797
}
9898
if (isNumeric(port, index) != "") return "Invalid listen port";
99-
if (ipv6 && address.empty()) return "Invalid listen ipv6 address";
100-
if (!ipv6 && address.empty()) return "Invalid listen ipv4 address";
99+
if (ipv6 == true && address.empty()) return "Invalid listen ipv6 address";
100+
if (ipv6 == false && address.empty()) return "Invalid listen ipv4 address";
101101
return "";
102102
}
103103

src/http/Http.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ void Http::OnRequestRecv(std::string msg) {
3636
parseRet |= _request.getUri().decode();
3737
accessLog_g.write("Decoded URI: " + _request.getUri().generate(), DEBUG);
3838

39-
bool validPath = !_request.getUri().resolveDots();
39+
bool validPath = (_request.getUri().resolveDots() == false);
4040
accessLog_g.write("Resolved URI: " + _request.getUri().generate(), DEBUG);
4141

4242
const Uri &uriRef = _request.getUri();
4343
validPath &= startsWith(uriRef.getPath(), "/") ||
4444
(_request.isMethod("OPTIONS") && uriRef.getPath() == "*");
4545

46-
if (parseRet || !validPath)
46+
if (parseRet || validPath == false)
4747
processError("400", "Bad Request", true);
4848
else if (isHttpVersionValid(_request.getVersion()) == false) {
4949
processError("505", "HTTP Version Not Supported", true);
@@ -116,7 +116,8 @@ void Http::OnTrailerRecv(std::string msg) {
116116

117117
void Http::OnBodyRecv(std::string msg) {
118118
if (_request.hasHeaderFieldValue("Transfer-Encoding", "chunked")) {
119-
if (!endsWith(msg, "\r\n")) return processError("400", "Bad Request", true);
119+
if (endsWith(msg, "\r\n") == false)
120+
return processError("400", "Bad Request", true);
120121
msg.erase(msg.size() - 2, 2);
121122
}
122123
accessLog_g.write("HTTP body: '" + msg + "'", VERBOSE);
@@ -245,13 +246,13 @@ void Http::processFile(std::string uri) {
245246

246247
// Set mime type
247248
std::string mimeType = VirtualHost::getMimeType(file.getExtension());
248-
if (!mimeType.empty()) _response.setHeader("Content-Type", mimeType);
249+
if (mimeType.empty() == false) _response.setHeader("Content-Type", mimeType);
249250
_response.setReady();
250251
}
251252

252253
void Http::processCgi(std::string contentLength) {
253254
std::string pathname(cgiFilePathname);
254-
if (!startsWith(pathname, "/")) pathname.insert(0, cwd_g);
255+
if (startsWith(pathname, "/") == false) pathname.insert(0, cwd_g);
255256

256257
std::vector<std::string> env;
257258
// const values:
@@ -328,7 +329,7 @@ void Http::processBodyRequest() {
328329
return processFile(_uri);
329330
else if (_request.isMethod("PUT")) {
330331
std::string path = _context->getDirective("root", true)[0][0] + _uri;
331-
_newFile = !File(path).exists();
332+
_newFile = (File(path).exists() == false);
332333

333334
if (!File(File(path).getDir()).exists())
334335
return processError("404", "Not found");
@@ -504,14 +505,15 @@ void Http::addIndexToPath(File &file, std::string &uri) {
504505
}
505506

506507
void Http::checkResourceValidity(const File &file, const std::string &uri) {
507-
if (!file.exists()) return processError("404", "Not Found");
508+
if (file.exists() == false) return processError("404", "Not Found");
508509
if (file.dir()) {
509-
if (!endsWith(file.getPath(), "/")) return processRedirect(uri + "/");
510+
if (endsWith(file.getPath(), "/") == false)
511+
return processRedirect(uri + "/");
510512
if (_context->exists("autoindex", true) &&
511513
_context->getDirective("autoindex", true)[0][0] == "on")
512514
return processAutoindex(uri);
513515
return processError("403", "Forbidden");
514-
} else if (!file.readable())
516+
} else if (file.readable() == false)
515517
return processError("403", "Forbidden");
516518
}
517519

@@ -622,7 +624,7 @@ bool Http::isBodySizeValid(size_t size) const {
622624
}
623625

624626
std::string Http::getCgiPath(std::string extension) const {
625-
if (!_context->exists("cgi", true)) return "";
627+
if (_context->exists("cgi", true) == false) return "";
626628
std::vector<std::vector<std::string> > &cgis =
627629
_context->getDirective("cgi", true);
628630
for (size_t i = 0; i < cgis.size(); i++)

src/http/Request.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ int Request::parseRequestLine(std::string line) {
8080
if (_method.find_first_of(WHITESPACE) != std::string::npos ||
8181
_version.find_first_of(WHITESPACE) != std::string::npos)
8282
return 1;
83-
if (!startsWith(_version, "HTTP/")) return 1;
83+
if (startsWith(_version, "HTTP/") == false) return 1;
8484
return _uri.load(requestLineTokens[1]);
8585
}
8686

src/http/Uri.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ std::string Uri::generate() const {
117117
return uri;
118118
}
119119

120-
#include <iostream>
121120
int Uri::resolveDots() {
122121
std::list<std::string> blocks =
123122
split<std::list<std::string> >(_path, "/", true);

src/main.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
static void initGlobals() {
1010
cwd_g = getcwd();
1111
if (cwd_g.empty()) throw std::runtime_error("getcwd(): Failed to init cwd");
12-
if (!endsWith(cwd_g, "/")) cwd_g.append("/");
12+
if (endsWith(cwd_g, "/") == false) cwd_g.append("/");
1313
try {
1414
accessLog_g.init(LOG_PATH);
1515
errorLog_g.init(LOG_ERROR_PATH);
@@ -44,12 +44,11 @@ int main(int argc, char** argv) {
4444
if (ret) return 0;
4545
Init::init(context);
4646
while (true) {
47-
if (!Poll::poll()) break;
47+
if (Poll::poll() == false) break;
4848
}
4949
} catch (const std::exception& e) {
5050
try {
51-
if (errorLog_g.getLogToFile() == false)
52-
Log::setLogToTerminal(true, true);
51+
if (errorLog_g.getLogToFile() == false) Log::setLogToTerminal(true, true);
5352
errorLog_g.write(e.what(), ERROR);
5453
printHelp(PRINT);
5554
} catch (...) {

src/poll/Address.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ static std::ostream &operator<<(std::ostream &os, in6_addr const &src) {
257257
bool first = (i % 2 == 0);
258258

259259
if (zeroField.second == 0 || i < zeroField.first || i > zeroField.second) {
260-
if (!first) {
260+
if (first == false) {
261261
if (addr[i - 1] != 0) os << std::setw(2) << std::setfill('0');
262262
os << (int)addr[i];
263263
if (i != 15) os << ':';

src/utils/utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ std::string getTime(std::string format, const time_t* timer) {
161161
std::time(&rawtime);
162162
timer = &rawtime;
163163
}
164-
if (!endsWith(format, " GMT")) format += " GMT";
164+
if (endsWith(format, " GMT") == false) format += " GMT";
165165
while (true) {
166166
std::string buffer(size, '\0');
167167
timeinfo = std::gmtime(timer);

0 commit comments

Comments
 (0)