diff --git a/src/microhttpd_wrapper.h b/src/microhttpd_wrapper.h new file mode 100644 index 000000000..f609f3d71 --- /dev/null +++ b/src/microhttpd_wrapper.h @@ -0,0 +1,24 @@ +/* + * Copyright 2020 Emmanuel Engelhart + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#include + +#if MHD_VERSION < 0x00097002 +typedef int MHD_Result; +#endif diff --git a/src/server.cpp b/src/server.cpp index 2547d2e11..22bc17a07 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -36,7 +36,7 @@ #endif extern "C" { -#include +#include "microhttpd_wrapper.h" } #include "tools/otherTools.h" @@ -77,14 +77,14 @@ static IdNameMapper defaultNameMapper; typedef kainjow::mustache::data MustacheData; -static int staticHandlerCallback(void* cls, - struct MHD_Connection* connection, - const char* url, - const char* method, - const char* version, - const char* upload_data, - size_t* upload_data_size, - void** cont_cls); +static MHD_Result staticHandlerCallback(void* cls, + struct MHD_Connection* connection, + const char* url, + const char* method, + const char* version, + const char* upload_data, + size_t* upload_data_size, + void** cont_cls); class InternalServer { @@ -101,13 +101,13 @@ class InternalServer { bool blockExternalLinks); virtual ~InternalServer() = default; - int handlerCallback(struct MHD_Connection* connection, - const char* url, - const char* method, - const char* version, - const char* upload_data, - size_t* upload_data_size, - void** cont_cls); + MHD_Result handlerCallback(struct MHD_Connection* connection, + const char* url, + const char* method, + const char* version, + const char* upload_data, + size_t* upload_data_size, + void** cont_cls); bool start(); void stop(); @@ -267,14 +267,14 @@ void InternalServer::stop() MHD_stop_daemon(mp_daemon); } -static int staticHandlerCallback(void* cls, - struct MHD_Connection* connection, - const char* url, - const char* method, - const char* version, - const char* upload_data, - size_t* upload_data_size, - void** cont_cls) +static MHD_Result staticHandlerCallback(void* cls, + struct MHD_Connection* connection, + const char* url, + const char* method, + const char* version, + const char* upload_data, + size_t* upload_data_size, + void** cont_cls) { InternalServer* _this = static_cast(cls); @@ -287,13 +287,13 @@ static int staticHandlerCallback(void* cls, cont_cls); } -int InternalServer::handlerCallback(struct MHD_Connection* connection, - const char* url, - const char* method, - const char* version, - const char* upload_data, - size_t* upload_data_size, - void** cont_cls) +MHD_Result InternalServer::handlerCallback(struct MHD_Connection* connection, + const char* url, + const char* method, + const char* version, + const char* upload_data, + size_t* upload_data_size, + void** cont_cls) { auto start_time = std::chrono::steady_clock::now(); if (m_verbose.load() ) { diff --git a/src/server/request_context.cpp b/src/server/request_context.cpp index 9ed28be84..93fc60cdf 100644 --- a/src/server/request_context.cpp +++ b/src/server/request_context.cpp @@ -92,16 +92,16 @@ RequestContext::RequestContext(struct MHD_Connection* connection, RequestContext::~RequestContext() {} -int RequestContext::fill_header(void *__this, enum MHD_ValueKind kind, - const char *key, const char *value) +MHD_Result RequestContext::fill_header(void *__this, enum MHD_ValueKind kind, + const char *key, const char *value) { RequestContext *_this = static_cast(__this); _this->headers[key] = value; return MHD_YES; } -int RequestContext::fill_argument(void *__this, enum MHD_ValueKind kind, - const char *key, const char* value) +MHD_Result RequestContext::fill_argument(void *__this, enum MHD_ValueKind kind, + const char *key, const char* value) { RequestContext *_this = static_cast(__this); _this->arguments[key] = value == nullptr ? "" : value; diff --git a/src/server/request_context.h b/src/server/request_context.h index 4860fcf6e..7cb8f3da5 100644 --- a/src/server/request_context.h +++ b/src/server/request_context.h @@ -30,7 +30,7 @@ #include "byte_range.h" extern "C" { -#include +#include "microhttpd_wrapper.h" } namespace kiwix { @@ -98,8 +98,8 @@ class RequestContext { std::map arguments; private: // functions - static int fill_header(void *, enum MHD_ValueKind, const char*, const char*); - static int fill_argument(void *, enum MHD_ValueKind, const char*, const char*); + static MHD_Result fill_header(void *, enum MHD_ValueKind, const char*, const char*); + static MHD_Result fill_argument(void *, enum MHD_ValueKind, const char*, const char*); }; template<> std::string RequestContext::get_argument(const std::string& name) const; diff --git a/src/server/response.cpp b/src/server/response.cpp index 2f76ed15e..41b178816 100644 --- a/src/server/response.cpp +++ b/src/server/response.cpp @@ -57,8 +57,8 @@ Response::Response(const std::string& root, bool verbose, bool withTaskbar, bool } -static int print_key_value (void *cls, enum MHD_ValueKind kind, - const char *key, const char *value) +static MHD_Result print_key_value (void *cls, enum MHD_ValueKind kind, + const char *key, const char *value) { printf (" - %s: '%s'\n", key, value); return MHD_YES; @@ -288,7 +288,7 @@ Response::create_mhd_response(const RequestContext& request) return nullptr; } -int Response::send(const RequestContext& request, MHD_Connection* connection) +MHD_Result Response::send(const RequestContext& request, MHD_Connection* connection) { MHD_Response* response = create_mhd_response(request); diff --git a/src/server/response.h b/src/server/response.h index 49e346c02..fa7fd4600 100644 --- a/src/server/response.h +++ b/src/server/response.h @@ -29,7 +29,7 @@ #include "etag.h" extern "C" { -#include +#include "microhttpd_wrapper.h" } namespace kiwix { @@ -48,7 +48,7 @@ class Response { Response(const std::string& root, bool verbose, bool withTaskbar, bool withLibraryButton, bool blockExternalLinks); ~Response() = default; - int send(const RequestContext& request, MHD_Connection* connection); + MHD_Result send(const RequestContext& request, MHD_Connection* connection); void set_template(const std::string& template_str, kainjow::mustache::data data); void set_content(const std::string& content);