commit 0b1474f85b01b99dede7881c71a89c6748b0fd61
parent c327ce593eef5ed9a9cb7f3b1fb5427ed6a395d8
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Mon, 1 Dec 2025 15:54:59 +0100
TLS: moved common function to special .h/.c files
Diffstat:
6 files changed, 179 insertions(+), 121 deletions(-)
diff --git a/src/mhd2/Makefile.am b/src/mhd2/Makefile.am
@@ -244,9 +244,9 @@ upgrade_OPTSOURCES = \
upgraded_net.c
tls_common_OPTSOURCES = \
- mhd_tls_choice.h \
- mhd_tls_funcs.c mhd_tls_funcs.h mhd_tls_enums.h \
- mhd_tls_ver_stct.h tls_dh_params.h \
+ mhd_tls_enums.h mhd_tls_ver_stct.h tls_dh_params.h \
+ mhd_tls_common.c mhd_tls_common.h \
+ mhd_tls_choice.h mhd_tls_funcs.h \
conn_tls_check.c conn_tls_check.h
tls_multi_OPTSOURCES = \
diff --git a/src/mhd2/daemon_start.c b/src/mhd2/daemon_start.c
@@ -99,6 +99,7 @@
#include "daemon_logger.h"
#ifdef MHD_SUPPORT_HTTPS
+# include "mhd_tls_common.h"
# include "mhd_tls_funcs.h"
#endif
diff --git a/src/mhd2/mhd_tls_common.c b/src/mhd2/mhd_tls_common.c
@@ -0,0 +1,86 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
+/*
+ This file is part of GNU libmicrohttpd.
+ Copyright (C) 2024-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.
+
+ Alternatively, you can redistribute GNU libmicrohttpd and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version, together
+ with the eCos exception, as follows:
+
+ As a special exception, if other files instantiate templates or
+ use macros or inline functions from this file, or you compile this
+ file and link it with other works to produce a work based on this
+ file, this file does not by itself cause the resulting work to be
+ covered by the GNU General Public License. However the source code
+ for this file must still be made available in accordance with
+ section (3) of the GNU General Public License v2.
+
+ This exception does not invalidate any other reasons why a work
+ based on this file might be covered by the GNU General Public
+ License.
+
+ You should have received copies of the GNU Lesser General Public
+ License and the GNU General Public License along with this library;
+ if not, see <https://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file src/mhd2/mhd_tls_funcs.c
+ * @brief The TLS backend generic functions implementation
+ * @author Karlson2k (Evgeny Grin)
+ */
+
+#include "mhd_sys_options.h"
+
+#include "mhd_assert.h"
+
+#include "mhd_tls_funcs.h"
+
+/* Include all supported TLS backends headers */
+#if defined(MHD_SUPPORT_GNUTLS)
+# include "tls_gnu_funcs.h"
+#endif
+#if defined(MHD_SUPPORT_OPENSSL)
+# include "tls_open_funcs.h"
+#endif
+
+#include "daemon_options.h"
+
+#include "mhd_tls_common.h"
+
+MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ MHD_FN_MUST_CHECK_RESULT_
+enum mhd_TlsBackendAvailable
+mhd_tls_is_backend_available (struct DaemonOptions *s)
+{
+ mhd_assert (MHD_TLS_BACKEND_NONE != s->tls);
+ if (MHD_TLS_BACKEND_ANY == s->tls)
+ return (mhd_tls_gnu_is_inited_fine ()
+ || mhd_tls_open_is_inited_fine ()) ?
+ mhd_TLS_BACKEND_AVAIL_OK :
+ mhd_TLS_BACKEND_AVAIL_NOT_AVAILABLE;
+#ifdef MHD_SUPPORT_GNUTLS
+ if (MHD_TLS_BACKEND_GNUTLS == s->tls)
+ return mhd_tls_gnu_is_inited_fine () ?
+ mhd_TLS_BACKEND_AVAIL_OK :
+ mhd_TLS_BACKEND_AVAIL_NOT_AVAILABLE;
+#endif
+#ifdef MHD_SUPPORT_OPENSSL
+ if (MHD_TLS_BACKEND_OPENSSL == s->tls)
+ return mhd_tls_open_is_inited_fine () ?
+ mhd_TLS_BACKEND_AVAIL_OK :
+ mhd_TLS_BACKEND_AVAIL_NOT_AVAILABLE;
+#endif
+ return mhd_TLS_BACKEND_AVAIL_NOT_SUPPORTED;
+}
diff --git a/src/mhd2/mhd_tls_common.h b/src/mhd2/mhd_tls_common.h
@@ -0,0 +1,89 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
+/*
+ This file is part of GNU libmicrohttpd.
+ Copyright (C) 2024-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.
+
+ Alternatively, you can redistribute GNU libmicrohttpd and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version, together
+ with the eCos exception, as follows:
+
+ As a special exception, if other files instantiate templates or
+ use macros or inline functions from this file, or you compile this
+ file and link it with other works to produce a work based on this
+ file, this file does not by itself cause the resulting work to be
+ covered by the GNU General Public License. However the source code
+ for this file must still be made available in accordance with
+ section (3) of the GNU General Public License v2.
+
+ This exception does not invalidate any other reasons why a work
+ based on this file might be covered by the GNU General Public
+ License.
+
+ You should have received copies of the GNU Lesser General Public
+ License and the GNU General Public License along with this library;
+ if not, see <https://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file src/mhd2/mhd_tls_common.h
+ * @brief The TLS functions and data common for all TLS backends
+ * @author Karlson2k (Evgeny Grin)
+ */
+
+#ifndef MHD_TLS_COMMON_H
+#define MHD_TLS_COMMON_H 1
+
+#include "mhd_sys_options.h"
+
+#ifndef MHD_SUPPORT_HTTPS
+#error This header should be used only if HTTPS is enabled
+#endif
+
+struct DaemonOptions; /* Forward declaration */
+
+/* ** General information function ** */
+
+/**
+ * Result of TLS backend availability check
+ */
+enum mhd_TlsBackendAvailable
+{
+ /**
+ * The TLS backend is available and can be used
+ */
+ mhd_TLS_BACKEND_AVAIL_OK = 0
+ ,
+ /**
+ * The TLS backend support is not enabled in this MHD build
+ */
+ mhd_TLS_BACKEND_AVAIL_NOT_SUPPORTED
+ ,
+ /**
+ * The TLS backend supported, but not available
+ */
+ mhd_TLS_BACKEND_AVAIL_NOT_AVAILABLE
+};
+
+/**
+ * Check whether the requested TLS backend is available
+ * @param s the daemon settings
+ * @return 'mhd_TLS_BACKEND_AVAIL_OK' if requested backend is available,
+ * error code otherwise
+ */
+MHD_INTERNAL enum mhd_TlsBackendAvailable
+mhd_tls_is_backend_available (struct DaemonOptions *s)
+MHD_FN_PAR_NONNULL_ALL_ MHD_FN_MUST_CHECK_RESULT_;
+
+#endif /* ! MHD_TLS_COMMON_H */
diff --git a/src/mhd2/mhd_tls_funcs.c b/src/mhd2/mhd_tls_funcs.c
@@ -1,85 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
-/*
- This file is part of GNU libmicrohttpd.
- Copyright (C) 2024 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.
-
- Alternatively, you can redistribute GNU libmicrohttpd and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version, together
- with the eCos exception, as follows:
-
- As a special exception, if other files instantiate templates or
- use macros or inline functions from this file, or you compile this
- file and link it with other works to produce a work based on this
- file, this file does not by itself cause the resulting work to be
- covered by the GNU General Public License. However the source code
- for this file must still be made available in accordance with
- section (3) of the GNU General Public License v2.
-
- This exception does not invalidate any other reasons why a work
- based on this file might be covered by the GNU General Public
- License.
-
- You should have received copies of the GNU Lesser General Public
- License and the GNU General Public License along with this library;
- if not, see <https://www.gnu.org/licenses/>.
-*/
-
-/**
- * @file src/mhd2/mhd_tls_funcs.c
- * @brief The TLS backend generic functions implementation
- * @author Karlson2k (Evgeny Grin)
- */
-
-#include "mhd_sys_options.h"
-
-#include "mhd_tls_funcs.h"
-
-/* Include all supported TLS backends headers */
-#if defined(MHD_SUPPORT_GNUTLS)
-# include "tls_gnu_funcs.h"
-#endif
-#if defined(MHD_SUPPORT_OPENSSL)
-# include "tls_open_funcs.h"
-#endif
-
-#include "mhd_assert.h"
-
-#include "mhd_public_api.h"
-#include "daemon_options.h"
-
-MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ MHD_FN_MUST_CHECK_RESULT_
-enum mhd_TlsBackendAvailable
-mhd_tls_is_backend_available (struct DaemonOptions *s)
-{
- mhd_assert (MHD_TLS_BACKEND_NONE != s->tls);
- if (MHD_TLS_BACKEND_ANY == s->tls)
- return (mhd_tls_gnu_is_inited_fine ()
- || mhd_tls_open_is_inited_fine ()) ?
- mhd_TLS_BACKEND_AVAIL_OK :
- mhd_TLS_BACKEND_AVAIL_NOT_AVAILABLE;
-#ifdef MHD_SUPPORT_GNUTLS
- if (MHD_TLS_BACKEND_GNUTLS == s->tls)
- return mhd_tls_gnu_is_inited_fine () ?
- mhd_TLS_BACKEND_AVAIL_OK :
- mhd_TLS_BACKEND_AVAIL_NOT_AVAILABLE;
-#endif
-#ifdef MHD_SUPPORT_OPENSSL
- if (MHD_TLS_BACKEND_OPENSSL == s->tls)
- return mhd_tls_open_is_inited_fine () ?
- mhd_TLS_BACKEND_AVAIL_OK :
- mhd_TLS_BACKEND_AVAIL_NOT_AVAILABLE;
-#endif
- return mhd_TLS_BACKEND_AVAIL_NOT_SUPPORTED;
-}
diff --git a/src/mhd2/mhd_tls_funcs.h b/src/mhd2/mhd_tls_funcs.h
@@ -232,37 +232,4 @@
#define mhd_tls_conn_get_alpn_prot(c_tls) \
mhd_TLS_FUNC (_conn_get_alpn_prot)((c_tls))
-/* ** General information function ** */
-
-/**
- * Result of TLS backend availability check
- */
-enum mhd_TlsBackendAvailable
-{
- /**
- * The TLS backend is available and can be used
- */
- mhd_TLS_BACKEND_AVAIL_OK = 0
- ,
- /**
- * The TLS backend support is not enabled in this MHD build
- */
- mhd_TLS_BACKEND_AVAIL_NOT_SUPPORTED
- ,
- /**
- * The TLS backend supported, but not available
- */
- mhd_TLS_BACKEND_AVAIL_NOT_AVAILABLE
-};
-
-/**
- * Check whether the requested TLS backend is available
- * @param s the daemon settings
- * @return 'mhd_TLS_BACKEND_AVAIL_OK' if requested backend is available,
- * error code otherwise
- */
-MHD_INTERNAL enum mhd_TlsBackendAvailable
-mhd_tls_is_backend_available (struct DaemonOptions *s)
-MHD_FN_PAR_NONNULL_ALL_ MHD_FN_MUST_CHECK_RESULT_;
-
#endif /* ! MHD_TLS_FUNCS_H */