From 07d7f0c3d8f50598144625c29a93e0aacfd996d7 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 8 Jul 2020 20:49:21 +0200 Subject: [PATCH] Unbreak compilation with libmicrohttpd 0.9.71. --- shared/httpd.cpp | 24 ++++++++++++------------ shared/httpd.h | 28 +++++++++++++++++++--------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/shared/httpd.cpp b/shared/httpd.cpp index 74d0c26..006ba65 100644 --- a/shared/httpd.cpp +++ b/shared/httpd.cpp @@ -85,19 +85,19 @@ void HTTPD::add_data_locked(StreamID stream_id, const char *buf, size_t size, St } } -int HTTPD::answer_to_connection_thunk(void *cls, MHD_Connection *connection, - const char *url, const char *method, - const char *version, const char *upload_data, - size_t *upload_data_size, void **con_cls) +HTTPD::MHD_Result HTTPD::answer_to_connection_thunk(void *cls, MHD_Connection *connection, + const char *url, const char *method, + const char *version, const char *upload_data, + size_t *upload_data_size, void **con_cls) { HTTPD *httpd = (HTTPD *)cls; return httpd->answer_to_connection(connection, url, method, version, upload_data, upload_data_size, con_cls); } -int HTTPD::answer_to_connection(MHD_Connection *connection, - const char *url, const char *method, - const char *version, const char *upload_data, - size_t *upload_data_size, void **con_cls) +HTTPD::MHD_Result HTTPD::answer_to_connection(MHD_Connection *connection, + const char *url, const char *method, + const char *version, const char *upload_data, + size_t *upload_data_size, void **con_cls) { // See if the URL ends in “.metacube”. HTTPD::Stream::Framing framing; @@ -123,7 +123,7 @@ int HTTPD::answer_to_connection(MHD_Connection *connection, MHD_Response *response = MHD_create_response_from_buffer( contents.size(), &contents[0], MHD_RESPMEM_MUST_COPY); MHD_add_response_header(response, "Content-type", "text/plain"); - int ret = MHD_queue_response(connection, MHD_HTTP_OK, response); + MHD_Result ret = MHD_queue_response(connection, MHD_HTTP_OK, response); MHD_destroy_response(response); // Only decreases the refcount; actual free is after the request is done. return ret; } @@ -135,7 +135,7 @@ int HTTPD::answer_to_connection(MHD_Connection *connection, if (endpoints[url].cors_policy == ALLOW_ALL_ORIGINS) { MHD_add_response_header(response, "Access-Control-Allow-Origin", "*"); } - int ret = MHD_queue_response(connection, MHD_HTTP_OK, response); + MHD_Result ret = MHD_queue_response(connection, MHD_HTTP_OK, response); MHD_destroy_response(response); // Only decreases the refcount; actual free is after the request is done. return ret; } @@ -146,7 +146,7 @@ int HTTPD::answer_to_connection(MHD_Connection *connection, MHD_Response *response = MHD_create_response_from_buffer( contents.size(), &contents[0], MHD_RESPMEM_MUST_COPY); MHD_add_response_header(response, "Content-type", "text/plain"); - int ret = MHD_queue_response(connection, MHD_HTTP_NOT_FOUND, response); + MHD_Result ret = MHD_queue_response(connection, MHD_HTTP_NOT_FOUND, response); MHD_destroy_response(response); // Only decreases the refcount; actual free is after the request is done. return ret; } @@ -175,7 +175,7 @@ int HTTPD::answer_to_connection(MHD_Connection *connection, MHD_add_response_header(response, "Content-encoding", "metacube"); } - int ret = MHD_queue_response(connection, MHD_HTTP_OK, response); + MHD_Result ret = MHD_queue_response(connection, MHD_HTTP_OK, response); MHD_destroy_response(response); // Only decreases the refcount; actual free is after the request is done. return ret; diff --git a/shared/httpd.h b/shared/httpd.h index dae5cad..8d2a05e 100644 --- a/shared/httpd.h +++ b/shared/httpd.h @@ -22,6 +22,8 @@ extern "C" { #include } +#include + #include "shared/shared_defs.h" struct MHD_Connection; @@ -81,15 +83,23 @@ public: } private: - static int answer_to_connection_thunk(void *cls, MHD_Connection *connection, - const char *url, const char *method, - const char *version, const char *upload_data, - size_t *upload_data_size, void **con_cls); - - int answer_to_connection(MHD_Connection *connection, - const char *url, const char *method, - const char *version, const char *upload_data, - size_t *upload_data_size, void **con_cls); + // libmicrohttpd 0.9.71 broke the type of MHD_YES/MHD_NO, causing + // compilation errors for C++ and undefined behavior for C. +#if MHD_VERSION >= 0x00097002 + using MHD_Result = ::MHD_Result; +#else + using MHD_Result = int; +#endif + + static MHD_Result answer_to_connection_thunk(void *cls, MHD_Connection *connection, + const char *url, const char *method, + const char *version, const char *upload_data, + size_t *upload_data_size, void **con_cls); + + MHD_Result answer_to_connection(MHD_Connection *connection, + const char *url, const char *method, + const char *version, const char *upload_data, + size_t *upload_data_size, void **con_cls); static void free_stream(void *cls); -- 2.39.2