Skip to content

Commit 6e25c8b

Browse files
committed
fix remaining errors
1 parent e0f72ed commit 6e25c8b

29 files changed

+1852
-2234
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Sun Mar 07 20:02:10 2021 -0800
2+
Cleaned code to support cpplint and extra warnings.
3+
Use pointers in place of non-const references.
4+
15
Thu Feb 25 20:27:12 2021 -0800
26
Simplified dependency management for libmicrohttpd
37

configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
AC_PREREQ(2.57)
2323
m4_define([libhttpserver_MAJOR_VERSION],[0])dnl
24-
m4_define([libhttpserver_MINOR_VERSION],[18])dnl
25-
m4_define([libhttpserver_REVISION],[2])dnl
24+
m4_define([libhttpserver_MINOR_VERSION],[19])dnl
25+
m4_define([libhttpserver_REVISION],[0])dnl
2626
m4_define([libhttpserver_PKG_VERSION],[libhttpserver_MAJOR_VERSION.libhttpserver_MINOR_VERSION.libhttpserver_REVISION])dnl
2727
m4_define([libhttpserver_LDF_VERSION],[libhttpserver_MAJOR_VERSION:libhttpserver_MINOR_VERSION:libhttpserver_REVISION])dnl
2828
AC_INIT([libhttpserver], libhttpserver_PKG_VERSION, [electrictwister2000@gmail.com])

examples/digest_authentication.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class digest_resource : public httpserver::http_resource {
2929
return std::shared_ptr<httpserver::digest_auth_fail_response>(new httpserver::digest_auth_fail_response("FAIL", "test@example.com", MY_OPAQUE, true));
3030
} else {
3131
bool reload_nonce = false;
32-
if (!req.check_digest_auth("test@example.com", "mypass", 300, reload_nonce)) {
32+
if (!req.check_digest_auth("test@example.com", "mypass", 300, &reload_nonce)) {
3333
return std::shared_ptr<httpserver::digest_auth_fail_response>(new httpserver::digest_auth_fail_response("FAIL", "test@example.com", MY_OPAQUE, reload_nonce));
3434
}
3535
}

src/http_request.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ void http_request::set_method(const std::string& method) {
3939
this->method = string_utilities::to_upper_copy(method);
4040
}
4141

42-
bool http_request::check_digest_auth(const std::string& realm, const std::string& password, int nonce_timeout, bool& reload_nonce) const {
42+
bool http_request::check_digest_auth(const std::string& realm, const std::string& password, int nonce_timeout, bool* reload_nonce) const {
4343
std::string digested_user = get_digested_user();
4444

4545
int val = MHD_digest_auth_check(underlying_connection, realm.c_str(), digested_user.c_str(), password.c_str(), nonce_timeout);
4646

4747
if (val == MHD_INVALID_NONCE) {
48-
reload_nonce = true;
48+
*reload_nonce = true;
4949
return false;
5050
} else if (val == MHD_NO) {
51-
reload_nonce = false;
51+
*reload_nonce = false;
5252
return false;
5353
}
54-
reload_nonce = false;
54+
*reload_nonce = false;
5555
return true;
5656
}
5757

src/httpserver/basic_auth_fail_response.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ class basic_auth_fail_response : public string_response {
4444
int response_code = http::http_utils::http_ok,
4545
const std::string& content_type = http::http_utils::text_plain):
4646
string_response(content, response_code, content_type),
47-
realm(realm) {
48-
}
47+
realm(realm) { }
4948

5049
basic_auth_fail_response(const basic_auth_fail_response& other) = default;
5150
basic_auth_fail_response(basic_auth_fail_response&& other) noexcept = default;

src/httpserver/create_webserver.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ class create_webserver {
5454
create_webserver& operator=(create_webserver&& b) = default;
5555

5656
explicit create_webserver(uint16_t port):
57-
_port(port) {
58-
}
57+
_port(port) { }
5958

6059
create_webserver& port(uint16_t port) {
6160
_port = port;

src/httpserver/deferred_response.hpp

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#error "Only <httpserver.hpp> or <httpserverpp> can be included directly."
2323
#endif
2424

25-
#ifndef _DEFERRED_RESPONSE_HPP_
26-
#define _DEFERRED_RESPONSE_HPP_
25+
#ifndef SRC_HTTPSERVER_DEFERRED_RESPONSE_HPP_
26+
#define SRC_HTTPSERVER_DEFERRED_RESPONSE_HPP_
2727

2828
#include <stddef.h>
2929
#include <stdint.h>
@@ -35,53 +35,45 @@
3535

3636
struct MHD_Response;
3737

38-
namespace httpserver
39-
{
38+
namespace httpserver {
4039

41-
namespace details
42-
{
40+
namespace details {
4341
MHD_Response* get_raw_response_helper(void* cls, ssize_t (*cb)(void*, uint64_t, char*, size_t));
4442
}
4543

4644
template <class T>
47-
class deferred_response : public string_response
48-
{
49-
public:
50-
explicit deferred_response(
51-
ssize_t(*cycle_callback)(std::shared_ptr<T>, char*, size_t),
52-
std::shared_ptr<T> closure_data,
53-
const std::string& content = "",
54-
int response_code = http::http_utils::http_ok,
55-
const std::string& content_type = http::http_utils::text_plain
56-
):
57-
string_response(content, response_code, content_type),
58-
cycle_callback(cycle_callback),
59-
closure_data(closure_data)
60-
{
61-
}
62-
63-
deferred_response(const deferred_response& other) = default;
64-
deferred_response(deferred_response&& other) noexcept = default;
65-
deferred_response& operator=(const deferred_response& b) = default;
66-
deferred_response& operator=(deferred_response&& b) = default;
67-
68-
~deferred_response() = default;
69-
70-
MHD_Response* get_raw_response()
71-
{
72-
return details::get_raw_response_helper((void*) this, &cb);
73-
}
74-
75-
private:
76-
ssize_t (*cycle_callback)(std::shared_ptr<T>, char*, size_t);
77-
std::shared_ptr<T> closure_data;
78-
79-
static ssize_t cb(void* cls, uint64_t, char* buf, size_t max)
80-
{
81-
deferred_response<T>* dfr = static_cast<deferred_response<T>*>(cls);
82-
return dfr->cycle_callback(dfr->closure_data, buf, max);
83-
}
45+
class deferred_response : public string_response {
46+
public:
47+
explicit deferred_response(
48+
ssize_t(*cycle_callback)(std::shared_ptr<T>, char*, size_t),
49+
std::shared_ptr<T> closure_data,
50+
const std::string& content = "",
51+
int response_code = http::http_utils::http_ok,
52+
const std::string& content_type = http::http_utils::text_plain):
53+
string_response(content, response_code, content_type),
54+
cycle_callback(cycle_callback),
55+
closure_data(closure_data) { }
56+
57+
deferred_response(const deferred_response& other) = default;
58+
deferred_response(deferred_response&& other) noexcept = default;
59+
deferred_response& operator=(const deferred_response& b) = default;
60+
deferred_response& operator=(deferred_response&& b) = default;
61+
62+
~deferred_response() = default;
63+
64+
MHD_Response* get_raw_response() {
65+
return details::get_raw_response_helper(reinterpret_cast<void*>(this), &cb);
66+
}
67+
68+
private:
69+
ssize_t (*cycle_callback)(std::shared_ptr<T>, char*, size_t);
70+
std::shared_ptr<T> closure_data;
71+
72+
static ssize_t cb(void* cls, uint64_t, char* buf, size_t max) {
73+
deferred_response<T>* dfr = static_cast<deferred_response<T>*>(cls);
74+
return dfr->cycle_callback(dfr->closure_data, buf, max);
75+
}
8476
};
8577

86-
}
87-
#endif // _DEFERRED_RESPONSE_HPP_
78+
} // namespace httpserver
79+
#endif // SRC_HTTPSERVER_DEFERRED_RESPONSE_HPP_

0 commit comments

Comments
 (0)