241 lines
9.5 KiB
Diff
241 lines
9.5 KiB
Diff
From cf8e8b94eb94e631b263706e24a363b69564fe55 Mon Sep 17 00:00:00 2001
|
|
From: Kelson <kelson@kiwix.org>
|
|
Date: Wed, 8 Jul 2020 11:38:57 +0200
|
|
Subject: [PATCH] Fix compilation with libmicrohttpd v0.97.1
|
|
|
|
---
|
|
src/microhttpd_wrapper.h | 24 +++++++++++++
|
|
src/server.cpp | 62 +++++++++++++++++-----------------
|
|
src/server/request_context.cpp | 8 ++---
|
|
src/server/request_context.h | 6 ++--
|
|
src/server/response.cpp | 6 ++--
|
|
src/server/response.h | 4 +--
|
|
6 files changed, 67 insertions(+), 43 deletions(-)
|
|
create mode 100644 src/microhttpd_wrapper.h
|
|
|
|
diff --git a/src/microhttpd_wrapper.h b/src/microhttpd_wrapper.h
|
|
new file mode 100644
|
|
index 0000000..f609f3d
|
|
--- /dev/null
|
|
+++ src/microhttpd_wrapper.h
|
|
@@ -0,0 +1,24 @@
|
|
+/*
|
|
+ * Copyright 2020 Emmanuel Engelhart <kelson@kiwix.org>
|
|
+ *
|
|
+ * 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 <microhttpd.h>
|
|
+
|
|
+#if MHD_VERSION < 0x00097002
|
|
+typedef int MHD_Result;
|
|
+#endif
|
|
diff --git a/src/server.cpp b/src/server.cpp
|
|
index 2547d2e..22bc17a 100644
|
|
--- src/server.cpp
|
|
+++ src/server.cpp
|
|
@@ -36,7 +36,7 @@
|
|
#endif
|
|
|
|
extern "C" {
|
|
-#include <microhttpd.h>
|
|
+#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<InternalServer*>(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 9ed28be..93fc60c 100644
|
|
--- src/server/request_context.cpp
|
|
+++ 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<RequestContext*>(__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<RequestContext*>(__this);
|
|
_this->arguments[key] = value == nullptr ? "" : value;
|
|
diff --git a/src/server/request_context.h b/src/server/request_context.h
|
|
index 4860fcf..7cb8f3d 100644
|
|
--- src/server/request_context.h
|
|
+++ src/server/request_context.h
|
|
@@ -30,7 +30,7 @@
|
|
#include "byte_range.h"
|
|
|
|
extern "C" {
|
|
-#include <microhttpd.h>
|
|
+#include "microhttpd_wrapper.h"
|
|
}
|
|
|
|
namespace kiwix {
|
|
@@ -98,8 +98,8 @@ class RequestContext {
|
|
std::map<std::string, std::string> 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 2f76ed1..41b1788 100644
|
|
--- src/server/response.cpp
|
|
+++ 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 49e346c..fa7fd46 100644
|
|
--- src/server/response.h
|
|
+++ src/server/response.h
|
|
@@ -29,7 +29,7 @@
|
|
#include "etag.h"
|
|
|
|
extern "C" {
|
|
-#include <microhttpd.h>
|
|
+#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);
|