From 8547143da77b0bae392758040313762eb60d7e86 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 9 Apr 2020 00:29:16 +0200 Subject: adapt code to work with latest MHD API --- src/gns/gnunet-bcd.c | 5 ++-- src/gns/gnunet-gns-proxy.c | 4 +-- src/include/Makefile.am | 1 + src/include/gnunet_mhd_compat.h | 43 ++++++++++++++++++++++++++++ src/namestore/gnunet-namestore-fcfsd.c | 11 +++---- src/pq/pq_result_helper.c | 2 +- src/rest/gnunet-rest-server.c | 22 ++++++++------ src/transport/plugin_transport_http_server.c | 12 ++++---- 8 files changed, 75 insertions(+), 25 deletions(-) create mode 100644 src/include/gnunet_mhd_compat.h (limited to 'src') diff --git a/src/gns/gnunet-bcd.c b/src/gns/gnunet-bcd.c index d6de86fa0..6ceff4a9a 100644 --- a/src/gns/gnunet-bcd.c +++ b/src/gns/gnunet-bcd.c @@ -27,6 +27,7 @@ #include "platform.h" #include #include "gnunet_util_lib.h" +#include "gnunet_mhd_compat.h" /** * Error page to display if submitted GNS key is invalid. @@ -91,7 +92,7 @@ struct Entry /** * Main request handler. */ -static int +static MHD_RESULT access_handler_callback (void *cls, struct MHD_Connection *connection, const char *url, @@ -153,7 +154,7 @@ access_handler_callback (void *cls, struct stat st; struct MHD_Response *response; int fd; - int ret; + MHD_RESULT ret; const char *gpg_fp = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c index 5b8348d43..c0572fe40 100644 --- a/src/gns/gnunet-gns-proxy.c +++ b/src/gns/gnunet-gns-proxy.c @@ -43,7 +43,7 @@ #include "gnunet_gns_service.h" #include "gnunet_identity_service.h" #include "gns.h" - +#include "gnunet_mhd_compat.h" /** * Default Socks5 listen port. @@ -1827,7 +1827,7 @@ con_val_iter (void *cls, * #MHD_NO if the socket must be closed due to a serious * error while handling the request */ -static int +static MHD_RESULT create_response (void *cls, struct MHD_Connection *con, const char *url, diff --git a/src/include/Makefile.am b/src/include/Makefile.am index 5c57b5be2..d2c254ae6 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am @@ -62,6 +62,7 @@ gnunetinclude_HEADERS = \ gnunet_json_lib.h \ gnunet_load_lib.h \ gnunet_cadet_service.h \ + gnunet_mhd_compat.h \ gnunet_microphone_lib.h \ gnunet_mst_lib.h \ gnunet_mq_lib.h \ diff --git a/src/include/gnunet_mhd_compat.h b/src/include/gnunet_mhd_compat.h new file mode 100644 index 000000000..0cfcc6445 --- /dev/null +++ b/src/include/gnunet_mhd_compat.h @@ -0,0 +1,43 @@ +/* + This file is part of GNUnet. + Copyright (C) 2020 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet 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 + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + SPDX-License-Identifier: AGPL3.0-or-later + */ + +/** + * @author Christian Grothoff + * + * @file + * MHD compatibility definitions for warning-less compile of + * our code against MHD before and after #MHD_VERSION 0x00097002. + */ +#include + +#if MHD_VERSION >= 0x00097002 +/** + * Data type to use for functions return an "MHD result". + */ +#define MHD_RESULT enum MHD_Result + +#else + +/** + * Data type to use for functions return an "MHD result". + */ +#define MHD_RESULT int + +#endif diff --git a/src/namestore/gnunet-namestore-fcfsd.c b/src/namestore/gnunet-namestore-fcfsd.c index fa0f835d1..67fc5bdf4 100644 --- a/src/namestore/gnunet-namestore-fcfsd.c +++ b/src/namestore/gnunet-namestore-fcfsd.c @@ -36,6 +36,7 @@ #include "gnunet_identity_service.h" #include "gnunet_gnsrecord_lib.h" #include "gnunet_namestore_service.h" +#include "gnunet_mhd_compat.h" /** * Invalid method page. @@ -507,10 +508,10 @@ fill_s_reply (const char *info, * specified offset * @param off offset of data in the overall value * @param size number of bytes in data available - * @return MHD_YES to continue iterating, - * MHD_NO to abort the iteration + * @return #MHD_YES to continue iterating, + * #MHD_NO to abort the iteration */ -static int +static MHD_RESULT post_iterator (void *cls, enum MHD_ValueKind kind, const char *key, @@ -754,7 +755,7 @@ lookup_it_finished (void *cls) * #MHD_NO if the socket must be closed due to a serious * error while handling the request */ -static int +static MHD_RESULT create_response (void *cls, struct MHD_Connection *connection, const char *url, @@ -767,7 +768,7 @@ create_response (void *cls, struct MHD_Response *response; struct Request *request; struct GNUNET_CRYPTO_EcdsaPublicKey pub; - int ret; + MHD_RESULT ret; (void) cls; (void) version; diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c index 1fb1e71c0..dc64597f8 100644 --- a/src/pq/pq_result_helper.c +++ b/src/pq/pq_result_helper.c @@ -345,7 +345,7 @@ extract_rsa_signature (void *cls, { struct GNUNET_CRYPTO_RsaSignature **sig = dst; size_t len; - const char *res; + const void *res; int fnum; (void) cls; diff --git a/src/rest/gnunet-rest-server.c b/src/rest/gnunet-rest-server.c index 02a2c6daf..30eade623 100644 --- a/src/rest/gnunet-rest-server.c +++ b/src/rest/gnunet-rest-server.c @@ -27,7 +27,7 @@ #include #include "gnunet_util_lib.h" #include "gnunet_rest_plugin.h" - +#include "gnunet_mhd_compat.h" /** * Default Socks5 listen port. @@ -302,7 +302,7 @@ url_iterator (void *cls, } -static int +static MHD_RESULT post_data_iter (void *cls, enum MHD_ValueKind kind, const char *key, @@ -359,11 +359,11 @@ post_data_iter (void *cls, * @a upload_data provided; the method must update this * value to the number of bytes NOT processed; * @param con_cls pointer to location where we store the 'struct Request' - * @return MHD_YES if the connection was handled successfully, - * MHD_NO if the socket must be closed due to a serious + * @return #MHD_YES if the connection was handled successfully, + * #MHD_NO if the socket must be closed due to a serious * error while handling the request */ -static int +static MHD_RESULT create_response (void *cls, struct MHD_Connection *con, const char *url, @@ -430,7 +430,7 @@ create_response (void *cls, rest_conndata_handle); con_handle->pp = MHD_create_post_processor (con, 65536, - post_data_iter, + &post_data_iter, rest_conndata_handle); if (*upload_data_size) { @@ -509,9 +509,13 @@ create_response (void *cls, allow_headers); } run_mhd_now (); - int ret = MHD_queue_response (con, con_handle->status, con_handle->response); - cleanup_handle (con_handle); - return ret; + { + MHD_RESULT ret = MHD_queue_response (con, + con_handle->status, + con_handle->response); + cleanup_handle (con_handle); + return ret; + } } diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index 20bdb6273..eef83b29d 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c @@ -33,7 +33,7 @@ #include "plugin_transport_http_common.h" #include #include - +#include "gnunet_mhd_compat.h" #if BUILD_HTTPS #define PLUGIN_NAME "https_server" @@ -1741,9 +1741,9 @@ add_cors_headers (struct MHD_Response *response) * @param upload_data upload data * @param upload_data_size size of @a upload_data * @param httpSessionCache the session cache to remember the connection - * @return MHD_YES if connection is accepted, MHD_NO on reject + * @return #MHD_YES if connection is accepted, #MHD_NO on reject */ -static int +static MHD_RESULT server_access_cb (void *cls, struct MHD_Connection *mhd_connection, const char *url, @@ -1757,7 +1757,7 @@ server_access_cb (void *cls, struct ServerRequest *sc = *httpSessionCache; struct GNUNET_ATS_Session *s; struct MHD_Response *response; - int res = MHD_YES; + MHD_RESULT res = MHD_YES; LOG (GNUNET_ERROR_TYPE_DEBUG, _ ( @@ -2025,9 +2025,9 @@ server_connection_cb (void *cls, * @param cls plugin as closure * @param addr address of incoming connection * @param addr_len number of bytes in @a addr - * @return MHD_YES if connection is accepted, MHD_NO if connection is rejected + * @return #MHD_YES if connection is accepted, #MHD_NO if connection is rejected */ -static int +static MHD_RESULT server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len) -- cgit v1.2.3