commit 7149d813ece800a0bfe37d0c23dcb8e9a913bddc
parent f31cb129e8433dc52ab400fe93eb734508db8475
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Wed, 23 Apr 2025 14:50:38 +0200
Fixed compatibility with non-GCC compilers
Diffstat:
9 files changed, 97 insertions(+), 39 deletions(-)
diff --git a/src/mhd2/Makefile.am b/src/mhd2/Makefile.am
@@ -167,7 +167,7 @@ upgrade_OPTSOURCES = \
tls_common_OPTSOURCES = \
mhd_tls_choice.h \
mhd_tls_funcs.c mhd_tls_funcs.h mhd_tls_enums.h \
- tls_dh_params.h \
+ mhd_tls_ver_stct.h tls_dh_params.h \
conn_tls_check.c conn_tls_check.h
tls_multi_OPTSOURCES = \
diff --git a/src/mhd2/conn_get_info.c b/src/mhd2/conn_get_info.c
@@ -33,6 +33,7 @@
#include "daemon_funcs.h"
#ifdef MHD_SUPPORT_HTTPS
# include "mhd_tls_funcs.h"
+# include "mhd_tls_ver_stct.h"
#endif
#include "mhd_public_api.h"
@@ -140,9 +141,11 @@ MHD_connection_get_info_dynamic_sz (
else
{
#ifdef MHD_SUPPORT_HTTPS
+ struct mhd_StctTlsVersion stct_tls_ver;
if (! mhd_tls_conn_get_tls_ver (connection->tls, \
- &(output_buf->v_tls_ver)))
+ &stct_tls_ver))
return MHD_SC_INFO_GET_TYPE_UNOBTAINABLE;
+ output_buf->v_tls_ver = stct_tls_ver.tls_ver;
#else /* ! MHD_SUPPORT_HTTPS */
mhd_UNREACHABLE ();
#endif /* ! MHD_SUPPORT_HTTPS */
diff --git a/src/mhd2/mhd_tls_ver_stct.h b/src/mhd2/mhd_tls_ver_stct.h
@@ -0,0 +1,52 @@
+/*
+ This file is part of GNU libmicrohttpd
+ Copyright (C) 2025 Evgeny Grin (Karlson2k)
+
+ GNU libmicrohttpd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ GNU libmicrohttpd 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with GNU libmicrohttpd; if not, see
+ <https://www.gnu.org/licenses/>.
+
+*/
+
+/**
+ * @file src/mhd2/mhd_tls_ver_stct.h
+ * @brief The definition of the structure for TLS version
+ * @author Karlson2k (Evgeny Grin)
+ */
+
+#ifndef MHD_TLS_VER_STCT_H
+#define MHD_TLS_VER_STCT_H 1
+
+#include "mhd_sys_options.h"
+
+#include "mhd_public_api.h"
+
+/*
+ * C does not allow forward declarations of enums.
+ * To avoid including large headers when a function declaration only needs
+ * a pointer to an enum, wrap the enum in a struct.
+ * Structs can be forward-declared.
+ */
+
+/**
+ * Struct embedding a single enum MHD_TlsVersion
+ */
+struct mhd_StctTlsVersion
+{
+ /**
+ * TLS version
+ */
+ enum MHD_TlsVersion tls_ver;
+};
+
+#endif /* ! MHD_TLS_VER_STCT_H */
diff --git a/src/mhd2/tls_gnu_funcs.c b/src/mhd2/tls_gnu_funcs.c
@@ -29,22 +29,28 @@
#include "sys_bool_type.h"
#include "sys_base_types.h"
+#include "compat_calloc.h"
+#include "sys_malloc.h"
#include <string.h>
+#ifdef mhd_USE_TLS_DEBUG_MESSAGES
+# include <stdio.h> /* For TLS debug printing */
+#endif
+
+#include "mhd_assert.h"
+
#include "mhd_socket_type.h"
#include "mhd_str_types.h"
#include "mhd_str_macros.h"
#include "mhd_arr_num_elems.h"
-#include "compat_calloc.h"
-#include "sys_malloc.h"
-#include "mhd_assert.h"
-
#include "mhd_conn_socket.h"
#include "tls_gnu_tls_lib.h"
+#include "mhd_tls_ver_stct.h"
+
#include "tls_gnu_daemon_data.h"
#include "tls_gnu_conn_data.h"
#include "tls_gnu_funcs.h"
@@ -56,10 +62,6 @@
# include "tls_dh_params.h"
#endif
-#ifdef mhd_USE_TLS_DEBUG_MESSAGES
-# include <stdio.h> /* For TLS debug printing */
-#endif
-
#include "mhd_public_api.h"
#ifdef mhd_USE_TLS_DEBUG_MESSAGES
@@ -800,7 +802,7 @@ mhd_tls_gnu_conn_get_tls_sess (
MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_
MHD_FN_PAR_OUT_ (2) bool
mhd_tls_gnu_conn_get_tls_ver (struct mhd_TlsGnuConnData *restrict c_tls,
- enum MHD_TlsVersion *restrict tls_ver_out)
+ struct mhd_StctTlsVersion *restrict tls_ver_out)
{
gnutls_protocol_t gtls_tls_ver;
@@ -809,20 +811,20 @@ mhd_tls_gnu_conn_get_tls_ver (struct mhd_TlsGnuConnData *restrict c_tls,
gtls_tls_ver = gnutls_protocol_get_version (c_tls->sess);
#if GNUTLS_VERSION_NUMBER >= 0x030603
if (GNUTLS_TLS1_3 == gtls_tls_ver)
- *tls_ver_out = MHD_TLS_VERSION_1_3;
+ tls_ver_out->tls_ver = MHD_TLS_VERSION_1_3;
else
#endif
if (GNUTLS_TLS1_2 == gtls_tls_ver)
- *tls_ver_out = MHD_TLS_VERSION_1_2;
+ tls_ver_out->tls_ver = MHD_TLS_VERSION_1_2;
else if (GNUTLS_TLS1_1 == gtls_tls_ver)
- *tls_ver_out = MHD_TLS_VERSION_1_1;
+ tls_ver_out->tls_ver = MHD_TLS_VERSION_1_1;
else if (GNUTLS_TLS1_0 == gtls_tls_ver)
- *tls_ver_out = MHD_TLS_VERSION_1_0;
+ tls_ver_out->tls_ver = MHD_TLS_VERSION_1_0;
else if (GNUTLS_VERSION_UNKNOWN == gtls_tls_ver)
- return false;
+ return false; /* The TLS version cannot be detected */
else
/* The TLS version is know for GnuTLS, but cannot be mapped */
- *tls_ver_out = MHD_TLS_VERSION_UNKNOWN;
+ tls_ver_out->tls_ver = MHD_TLS_VERSION_UNKNOWN;
return true;
}
diff --git a/src/mhd2/tls_gnu_funcs.h b/src/mhd2/tls_gnu_funcs.h
@@ -53,7 +53,7 @@ struct mhd_TlsGnuConnData; /* Forward declaration */
union MHD_ConnInfoDynamicTlsSess; /* Forward declaration */
-enum MHD_TlsVersion; /* Forward declaration */
+struct mhd_StctTlsVersion; /* Forward declaration */
/* ** Global initialisation / de-initialisation ** */
@@ -275,7 +275,7 @@ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_ (2);
*/
MHD_INTERNAL bool
mhd_tls_gnu_conn_get_tls_ver (struct mhd_TlsGnuConnData *restrict c_tls,
- enum MHD_TlsVersion *restrict tls_ver_out)
+ struct mhd_StctTlsVersion *restrict tls_ver_out)
MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_ (2);
#endif /* ! MHD_TLS_GNU_FUNCS_H */
diff --git a/src/mhd2/tls_multi_funcs.c b/src/mhd2/tls_multi_funcs.c
@@ -664,7 +664,7 @@ mhd_tls_multi_conn_get_tls_sess (
MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_
MHD_FN_PAR_OUT_ (2) bool
mhd_tls_multi_conn_get_tls_ver (struct mhd_TlsMultiConnData *restrict c_tls,
- enum MHD_TlsVersion *restrict tls_ver_out)
+ struct mhd_StctTlsVersion *restrict tls_ver_out)
{
switch (c_tls->choice)
{
diff --git a/src/mhd2/tls_multi_funcs.h b/src/mhd2/tls_multi_funcs.h
@@ -55,7 +55,7 @@ struct mhd_TlsMultiConnData; /* Forward declaration */
union MHD_ConnInfoDynamicTlsSess; /* Forward declaration */
-enum MHD_TlsVersion; /* Forward declaration */
+struct mhd_StctTlsVersion; /* Forward declaration */
/* ** Global initialisation / de-initialisation ** */
@@ -254,7 +254,7 @@ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_ (2);
*/
MHD_INTERNAL bool
mhd_tls_multi_conn_get_tls_ver (struct mhd_TlsMultiConnData *restrict c_tls,
- enum MHD_TlsVersion *restrict tls_ver_out)
+ struct mhd_StctTlsVersion *restrict tls_ver_out)
MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_ (2);
#endif /* ! MHD_TLS_MULTI_FUNCS_H */
diff --git a/src/mhd2/tls_open_funcs.c b/src/mhd2/tls_open_funcs.c
@@ -29,18 +29,23 @@
#include "sys_bool_type.h"
#include "sys_base_types.h"
-#include "mhd_assert.h"
-#include "mhd_unreachable.h"
-
-#include <string.h>
-
#include "compat_calloc.h"
#include "sys_malloc.h"
+#include <string.h>
+
+#ifdef mhd_USE_TLS_DEBUG_MESSAGES
+# include <stdio.h> /* For TLS debug printing */
+#endif
+
+#include "mhd_assert.h"
+#include "mhd_unreachable.h"
#include "mhd_conn_socket.h"
#include "tls_open_tls_lib.h"
+#include "mhd_tls_ver_stct.h"
+
#include "tls_open_daemon_data.h"
#include "tls_open_conn_data.h"
#include "tls_open_funcs.h"
@@ -49,10 +54,6 @@
#include "daemon_logger.h"
-#ifdef mhd_USE_TLS_DEBUG_MESSAGES
-# include <stdio.h> /* For TLS debug printing */
-#endif
-
#include "mhd_public_api.h"
#ifdef mhd_USE_TLS_DEBUG_MESSAGES
@@ -1203,7 +1204,7 @@ mhd_tls_open_conn_get_tls_sess (
MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_
MHD_FN_PAR_OUT_ (2) bool
mhd_tls_open_conn_get_tls_ver (struct mhd_TlsOpenConnData *restrict c_tls,
- enum MHD_TlsVersion *restrict tls_ver_out)
+ struct mhd_StctTlsVersion *restrict tls_ver_out)
{
int openssl_tls_ver;
@@ -1213,20 +1214,20 @@ mhd_tls_open_conn_get_tls_ver (struct mhd_TlsOpenConnData *restrict c_tls,
switch (openssl_tls_ver)
{
case TLS1_VERSION:
- *tls_ver_out = MHD_TLS_VERSION_1_0;
+ tls_ver_out->tls_ver = MHD_TLS_VERSION_1_0;
break;
case TLS1_1_VERSION:
- *tls_ver_out = MHD_TLS_VERSION_1_1;
+ tls_ver_out->tls_ver = MHD_TLS_VERSION_1_1;
break;
case TLS1_2_VERSION:
- *tls_ver_out = MHD_TLS_VERSION_1_2;
+ tls_ver_out->tls_ver = MHD_TLS_VERSION_1_2;
break;
case TLS1_3_VERSION:
- *tls_ver_out = MHD_TLS_VERSION_1_3;
+ tls_ver_out->tls_ver = MHD_TLS_VERSION_1_3;
break;
case SSL3_VERSION:
default:
- *tls_ver_out = MHD_TLS_VERSION_UNKNOWN;
+ tls_ver_out->tls_ver = MHD_TLS_VERSION_UNKNOWN;
break;
}
diff --git a/src/mhd2/tls_open_funcs.h b/src/mhd2/tls_open_funcs.h
@@ -53,7 +53,7 @@ struct mhd_TlsOpenConnData; /* Forward declaration */
union MHD_ConnInfoDynamicTlsSess; /* Forward declaration */
-enum MHD_TlsVersion; /* Forward declaration */
+struct mhd_StctTlsVersion; /* Forward declaration */
/* ** Global initialisation / de-initialisation ** */
@@ -258,7 +258,7 @@ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_ (2);
*/
MHD_INTERNAL bool
mhd_tls_open_conn_get_tls_ver (struct mhd_TlsOpenConnData *restrict c_tls,
- enum MHD_TlsVersion *restrict tls_ver_out)
+ struct mhd_StctTlsVersion *restrict tls_ver_out)
MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_ (2);
#endif /* ! MHD_TLS_OPEN_FUNCS_H */