Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ int main(int argc, char **argv) {
while ((c = getopt(argc, argv, "p:k:c:sv?")) != EOF) {
switch (c) {
case 'p':
port = strtoul(optarg, NULL, 10);
port = strtoul(optarg, nullptr, 10);
break;
case 'k':
key = optarg;
Expand Down
2 changes: 1 addition & 1 deletion src/deferred_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace httpserver {
namespace details {

MHD_Response* get_raw_response_helper(void* cls, ssize_t (*cb)(void*, uint64_t, char*, size_t)) {
return MHD_create_response_from_callback(MHD_SIZE_UNKNOWN, 1024, cb, cls, NULL);
return MHD_create_response_from_callback(MHD_SIZE_UNKNOWN, 1024, cb, cls, nullptr);
}

} // namespace details
Expand Down
2 changes: 1 addition & 1 deletion src/file_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ MHD_Response* file_response::get_raw_response() {
if (size) {
return MHD_create_response_from_fd(size, fd);
} else {
return MHD_create_response_from_buffer(0, 0x0, MHD_RESPMEM_PERSISTENT);
return MHD_create_response_from_buffer(0, nullptr, MHD_RESPMEM_PERSISTENT);
}
}

Expand Down
26 changes: 13 additions & 13 deletions src/http_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool http_request::check_digest_auth(const std::string& realm, const std::string
const std::string http_request::get_connection_value(const std::string& key, enum MHD_ValueKind kind) const {
const char* header_c = MHD_lookup_connection_value(underlying_connection, kind, key.c_str());

if (header_c == NULL) return EMPTY;
if (header_c == nullptr) return EMPTY;

return header_c;
}
Expand Down Expand Up @@ -140,7 +140,7 @@ MHD_Result http_request::build_request_args(void *cls, enum MHD_ValueKind kind,
std::ignore = kind;

arguments_accumulator* aa = static_cast<arguments_accumulator*>(cls);
std::string value = ((arg_value == NULL) ? "" : arg_value);
std::string value = ((arg_value == nullptr) ? "" : arg_value);

http::base_unescaper(&value, aa->unescaper);
(*aa->arguments)[key] = value;
Expand All @@ -152,7 +152,7 @@ MHD_Result http_request::build_request_querystring(void *cls, enum MHD_ValueKind
std::ignore = kind;

std::string* querystring = static_cast<std::string*>(cls);
std::string value = ((arg_value == NULL) ? "" : arg_value);
std::string value = ((arg_value == nullptr) ? "" : arg_value);

int buffer_size = std::string(key).size() + value.size() + 3;
char* buf = new char[buffer_size];
Expand All @@ -170,41 +170,41 @@ MHD_Result http_request::build_request_querystring(void *cls, enum MHD_ValueKind
}

const std::string http_request::get_user() const {
char* username = 0x0;
char* password = 0x0;
char* username = nullptr;
char* password = nullptr;

username = MHD_basic_auth_get_username_password(underlying_connection, &password);
if (password != 0x0) free(password);
if (password != nullptr) free(password);

std::string user;
if (username != 0x0) user = username;
if (username != nullptr) user = username;

free(username);

return user;
}

const std::string http_request::get_pass() const {
char* username = 0x0;
char* password = 0x0;
char* username = nullptr;
char* password = nullptr;

username = MHD_basic_auth_get_username_password(underlying_connection, &password);
if (username != 0x0) free(username);
if (username != nullptr) free(username);

std::string pass;
if (password != 0x0) pass = password;
if (password != nullptr) pass = password;

free(password);

return pass;
}

const std::string http_request::get_digested_user() const {
char* digested_user_c = 0x0;
char* digested_user_c = nullptr;
digested_user_c = MHD_digest_auth_get_username(underlying_connection);

std::string digested_user = EMPTY;
if (digested_user_c != 0x0) {
if (digested_user_c != nullptr) {
digested_user = digested_user_c;
free(digested_user_c);
}
Expand Down
2 changes: 1 addition & 1 deletion src/http_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
namespace httpserver {

MHD_Response* http_response::get_raw_response() {
return MHD_create_response_from_buffer(0, 0x0, MHD_RESPMEM_PERSISTENT);
return MHD_create_response_from_buffer(0, nullptr, MHD_RESPMEM_PERSISTENT);
}

void http_response::decorate_response(MHD_Response* response) {
Expand Down
10 changes: 5 additions & 5 deletions src/http_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ ip_representation::ip_representation(const std::string& ip) {
}

if (parts[i].size() == 4) {
pieces[y] = strtol((parts[i].substr(0, 2)).c_str(), NULL, 16);
pieces[y+1] = strtol((parts[i].substr(2, 2)).c_str(), NULL, 16);
pieces[y] = strtol((parts[i].substr(0, 2)).c_str(), nullptr, 16);
pieces[y+1] = strtol((parts[i].substr(2, 2)).c_str(), nullptr, 16);

y += 2;
} else {
Expand All @@ -371,7 +371,7 @@ ip_representation::ip_representation(const std::string& ip) {

for (unsigned int ii = 0; ii < subparts.size(); ii++) {
if (subparts[ii] != "*") {
pieces[y+ii] = strtol(subparts[ii].c_str(), NULL, 10);
pieces[y+ii] = strtol(subparts[ii].c_str(), nullptr, 10);
if (pieces[y+ii] > 255) throw std::invalid_argument("IP is badly formatted. 255 is max value for ip part.");
} else {
CLEAR_BIT(mask, y+ii);
Expand All @@ -396,7 +396,7 @@ ip_representation::ip_representation(const std::string& ip) {
if (parts.size() == 4) {
for (unsigned int i = 0; i < parts.size(); i++) {
if (parts[i] != "*") {
pieces[12+i] = strtol(parts[i].c_str(), NULL, 10);
pieces[12+i] = strtol(parts[i].c_str(), nullptr, 10);
if (pieces[12+i] > 255) throw std::invalid_argument("IP is badly formatted. 255 is max value for ip part.");
} else {
CLEAR_BIT(mask, 12+i);
Expand Down Expand Up @@ -481,7 +481,7 @@ void dump_arg_map(std::ostream &os, const std::string &prefix, const std::map<st
size_t base_unescaper(std::string* s, unescaper_ptr unescaper) {
if ((*s)[0] == 0) return 0;

if (unescaper != 0x0) {
if (unescaper != nullptr) {
unescaper(*s);
return s->size();
}
Expand Down
16 changes: 8 additions & 8 deletions src/httpserver/create_webserver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,11 @@ class create_webserver {
size_t _content_size_limit = static_cast<size_t>(-1);
int _connection_timeout = DEFAULT_WS_TIMEOUT;
int _per_IP_connection_limit = 0;
log_access_ptr _log_access = 0x0;
log_error_ptr _log_error = 0x0;
validator_ptr _validator = 0x0;
unescaper_ptr _unescaper = 0x0;
const struct sockaddr* _bind_address = 0x0;
log_access_ptr _log_access = nullptr;
log_error_ptr _log_error = nullptr;
validator_ptr _validator = nullptr;
unescaper_ptr _unescaper = nullptr;
const struct sockaddr* _bind_address = nullptr;
int _bind_socket = 0;
int _max_thread_stack_size = 0;
bool _use_ssl = false;
Expand All @@ -363,9 +363,9 @@ class create_webserver {
bool _deferred_enabled = false;
bool _single_resource = false;
bool _tcp_nodelay = false;
render_ptr _not_found_resource = 0x0;
render_ptr _method_not_allowed_resource = 0x0;
render_ptr _internal_error_resource = 0x0;
render_ptr _not_found_resource = nullptr;
render_ptr _method_not_allowed_resource = nullptr;
render_ptr _internal_error_resource = nullptr;

friend class webserver;
};
Expand Down
12 changes: 6 additions & 6 deletions src/httpserver/details/modded_request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ namespace httpserver {
namespace details {

struct modded_request {
struct MHD_PostProcessor *pp = 0x0;
std::string* complete_uri = 0x0;
std::string* standardized_url = 0x0;
webserver* ws = 0x0;
struct MHD_PostProcessor *pp = nullptr;
std::string* complete_uri = nullptr;
std::string* standardized_url = nullptr;
webserver* ws = nullptr;

const std::shared_ptr<http_response> (httpserver::http_resource::*callback)(const httpserver::http_request&);

http_request* dhr = 0x0;
http_request* dhr = nullptr;
std::shared_ptr<http_response> dhrs;
bool second = false;
bool has_body = false;
Expand All @@ -56,7 +56,7 @@ struct modded_request {
modded_request& operator=(modded_request&& b) = default;

~modded_request() {
if (NULL != pp) {
if (nullptr != pp) {
MHD_destroy_post_processor(pp);
}
if (second) {
Expand Down
4 changes: 2 additions & 2 deletions src/httpserver/http_request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ class http_request {
size_t content_size_limit = static_cast<size_t>(-1);
std::string version;

struct MHD_Connection* underlying_connection = 0x0;
struct MHD_Connection* underlying_connection = nullptr;

unescaper_ptr unescaper = 0x0;
unescaper_ptr unescaper = nullptr;

static MHD_Result build_request_header(void *cls, enum MHD_ValueKind kind, const char *key, const char *value);

Expand Down
36 changes: 18 additions & 18 deletions src/webserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ webserver::webserver(const create_webserver& params):
method_not_allowed_resource(params._method_not_allowed_resource),
internal_error_resource(params._internal_error_resource) {
ignore_sigpipe();
pthread_mutex_init(&mutexwait, NULL);
pthread_cond_init(&mutexcond, NULL);
pthread_mutex_init(&mutexwait, nullptr);
pthread_cond_init(&mutexcond, nullptr);
}

webserver::~webserver() {
Expand All @@ -180,10 +180,10 @@ void webserver::request_completed(void *cls, struct MHD_Connection *connection,
std::ignore = toe;

details::modded_request* mr = static_cast<details::modded_request*>(*con_cls);
if (mr == 0x0) return;
if (mr == nullptr) return;

delete mr;
mr = 0x0;
mr = nullptr;
}

bool webserver::register_resource(const std::string& resource, http_resource* hrm, bool family) {
Expand All @@ -204,14 +204,14 @@ bool webserver::register_resource(const std::string& resource, http_resource* hr

bool webserver::start(bool blocking) {
struct {
MHD_OptionItem operator ()(enum MHD_OPTION opt, intptr_t val, void *ptr = 0) {
MHD_OptionItem operator ()(enum MHD_OPTION opt, intptr_t val, void *ptr = nullptr) {
MHD_OptionItem x = {opt, val, ptr};
return x;
}
} gen;
vector<struct MHD_OptionItem> iov;

iov.push_back(gen(MHD_OPTION_NOTIFY_COMPLETED, (intptr_t) &request_completed, NULL));
iov.push_back(gen(MHD_OPTION_NOTIFY_COMPLETED, (intptr_t) &request_completed, nullptr));
iov.push_back(gen(MHD_OPTION_URI_LOG_CALLBACK, (intptr_t) &uri_log, this));
iov.push_back(gen(MHD_OPTION_EXTERNAL_LOGGER, (intptr_t) &error_log, this));
iov.push_back(gen(MHD_OPTION_UNESCAPE_CALLBACK, (intptr_t) &unescaper_func, this));
Expand Down Expand Up @@ -279,7 +279,7 @@ bool webserver::start(bool blocking) {
}
#endif // HAVE_GNUTLS

iov.push_back(gen(MHD_OPTION_END, 0, NULL));
iov.push_back(gen(MHD_OPTION_END, 0, nullptr));

int start_conf = start_method;

Expand Down Expand Up @@ -310,8 +310,8 @@ bool webserver::start(bool blocking) {
start_conf |= MHD_USE_TCP_FASTOPEN;
#endif

daemon = NULL;
if (bind_address == 0x0) {
daemon = nullptr;
if (bind_address == nullptr) {
daemon = MHD_start_daemon(start_conf, port, &policy_callback, this,
&answer_to_connection, this, MHD_OPTION_ARRAY,
&iov[0], MHD_OPTION_END);
Expand All @@ -321,7 +321,7 @@ bool webserver::start(bool blocking) {
&iov[0], MHD_OPTION_SOCK_ADDR, bind_address, MHD_OPTION_END);
}

if (daemon == NULL) {
if (daemon == nullptr) {
throw std::invalid_argument("Unable to connect daemon to port: " + std::to_string(port));
}

Expand Down Expand Up @@ -430,11 +430,11 @@ void error_log(void* cls, const char* fmt, va_list ap) {
std::ignore = ap;

webserver* dws = static_cast<webserver*>(cls);
if (dws->log_error != 0x0) dws->log_error(fmt);
if (dws->log_error != nullptr) dws->log_error(fmt);
}

void access_log(webserver* dws, string uri) {
if (dws->log_access != 0x0) dws->log_access(uri);
if (dws->log_access != nullptr) dws->log_access(uri);
}

size_t unescaper_func(void * cls, struct MHD_Connection *c, char *s) {
Expand Down Expand Up @@ -472,23 +472,23 @@ void webserver::upgrade_handler(void *cls, struct MHD_Connection* connection, vo
}

const std::shared_ptr<http_response> webserver::not_found_page(details::modded_request* mr) const {
if (not_found_resource != 0x0) {
if (not_found_resource != nullptr) {
return not_found_resource(*mr->dhr);
} else {
return std::shared_ptr<http_response>(new string_response(NOT_FOUND_ERROR, http_utils::http_not_found));
}
}

const std::shared_ptr<http_response> webserver::method_not_allowed_page(details::modded_request* mr) const {
if (method_not_allowed_resource != 0x0) {
if (method_not_allowed_resource != nullptr) {
return method_not_allowed_resource(*mr->dhr);
} else {
return std::shared_ptr<http_response>(new string_response(METHOD_ERROR, http_utils::http_method_not_allowed));
}
}

const std::shared_ptr<http_response> webserver::internal_error_page(details::modded_request* mr, bool force_our) const {
if (internal_error_resource != 0x0 && !force_our) {
if (internal_error_resource != nullptr && !force_our) {
return internal_error_resource(*mr->dhr);
} else {
return std::shared_ptr<http_response>(new string_response(GENERIC_ERROR, http_utils::http_internal_server_error, "text/plain"));
Expand All @@ -507,13 +507,13 @@ MHD_Result webserver::requests_answer_first_step(MHD_Connection* connection, str
const char *encoding = MHD_lookup_connection_value(connection, MHD_HEADER_KIND, http_utils::http_header_content_type);

if (post_process_enabled &&
(0x0 != encoding &&
(nullptr != encoding &&
((0 == strncasecmp(http_utils::http_post_encoding_form_urlencoded, encoding, strlen(http_utils::http_post_encoding_form_urlencoded))) ||
(0 == strncasecmp(http_utils::http_post_encoding_multipart_formdata, encoding, strlen(http_utils::http_post_encoding_multipart_formdata)))))) {
const size_t post_memory_limit(32 * 1024); // Same as #MHD_POOL_SIZE_DEFAULT
mr->pp = MHD_create_post_processor(connection, post_memory_limit, &post_iterator, mr);
} else {
mr->pp = NULL;
mr->pp = nullptr;
}
return MHD_YES;
}
Expand All @@ -529,7 +529,7 @@ MHD_Result webserver::requests_answer_second_step(MHD_Connection* connection, co
#endif // DEBUG
mr->dhr->grow_content(upload_data, *upload_data_size);

if (mr->pp != NULL) MHD_post_process(mr->pp, upload_data, *upload_data_size);
if (mr->pp != nullptr) MHD_post_process(mr->pp, upload_data, *upload_data_size);
}

*upload_data_size = 0;
Expand Down
Loading