libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

mhd_tls_choice.h (7422B)


      1 /* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
      2 /*
      3   This file is part of GNU libmicrohttpd.
      4   Copyright (C) 2024-2026 Evgeny Grin (Karlson2k)
      5 
      6   GNU libmicrohttpd is free software; you can redistribute it and/or
      7   modify it under the terms of the GNU Lesser General Public
      8   License as published by the Free Software Foundation; either
      9   version 2.1 of the License, or (at your option) any later version.
     10 
     11   GNU libmicrohttpd is distributed in the hope that it will be useful,
     12   but WITHOUT ANY WARRANTY; without even the implied warranty of
     13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14   Lesser General Public License for more details.
     15 
     16   Alternatively, you can redistribute GNU libmicrohttpd and/or
     17   modify it under the terms of the GNU General Public License as
     18   published by the Free Software Foundation; either version 2 of
     19   the License, or (at your option) any later version, together
     20   with the eCos exception, as follows:
     21 
     22     As a special exception, if other files instantiate templates or
     23     use macros or inline functions from this file, or you compile this
     24     file and link it with other works to produce a work based on this
     25     file, this file does not by itself cause the resulting work to be
     26     covered by the GNU General Public License. However the source code
     27     for this file must still be made available in accordance with
     28     section (3) of the GNU General Public License v2.
     29 
     30     This exception does not invalidate any other reasons why a work
     31     based on this file might be covered by the GNU General Public
     32     License.
     33 
     34   You should have received copies of the GNU Lesser General Public
     35   License and the GNU General Public License along with this library;
     36   if not, see <https://www.gnu.org/licenses/>.
     37 */
     38 
     39 /**
     40  * @file src/mhd2/mhd_tls_choice.h
     41  * @brief  The TLS backend compile-time selection header
     42  * @author Karlson2k (Evgeny Grin)
     43  */
     44 
     45 #ifndef MHD_TLS_CHOICE_H
     46 #define MHD_TLS_CHOICE_H 1
     47 
     48 #include "mhd_sys_options.h"
     49 
     50 #ifndef MHD_SUPPORT_HTTPS
     51 #  error This header should be used only if HTTPS is enabled
     52 #endif
     53 
     54 #include "mhd_macro_concat.h"
     55 
     56 
     57 /* ** Enumerate TLS backends ** */
     58 
     59 /* * GnuTLS * */
     60 
     61 #ifdef MHD_SUPPORT_GNUTLS
     62 /**
     63  * Defined to one if GnuTLS is enabled at build time or to zero if not enabled
     64  */
     65 #  define mhd_TLS_GNU_ENABLED   (1)
     66 #else
     67 /**
     68  * Defined to one if GnuTLS is enabled at build time or to zero if not enabled
     69  */
     70 #  define mhd_TLS_GNU_ENABLED   (0)
     71 #endif
     72 
     73 /**
     74  * Return non-zero if GnuTLS is supported
     75  */
     76 #define mhd_TLS_GNU_IS_SUPPORTED()     (! ! mhd_TLS_GNU_ENABLED)
     77 
     78 /* * OpenSSL * */
     79 
     80 #ifdef MHD_SUPPORT_OPENSSL
     81 /**
     82  * Defined to one if OpenSSL is enabled at build time or to zero if not enabled
     83  */
     84 #  define mhd_TLS_OPEN_ENABLED   (1)
     85 #else
     86 /**
     87  * Defined to one if OpenSSL is enabled at build time or to zero if not enabled
     88  */
     89 #  define mhd_TLS_OPEN_ENABLED   (0)
     90 #endif
     91 
     92 /**
     93  * Return non-zero if OpenSSL is supported
     94  */
     95 #define mhd_TLS_OPEN_IS_SUPPORTED()     (! ! mhd_TLS_OPEN_ENABLED)
     96 
     97 /* * MbedTLS * */
     98 
     99 #ifdef MHD_SUPPORT_MBEDTLS
    100 /**
    101  * Defined to one if MbedTLS is enabled at build time or to zero if not enabled
    102  */
    103 #  define mhd_TLS_MBED_ENABLED   (1)
    104 #else
    105 /**
    106  * Defined to one if MbedTLS is enabled at build time or to zero if not enabled
    107  */
    108 #  define mhd_TLS_MBED_ENABLED   (0)
    109 #endif
    110 
    111 /**
    112  * Return non-zero if OpenSSL is supported
    113  */
    114 #define mhd_TLS_MBED_IS_SUPPORTED()     (! ! mhd_TLS_MBED_ENABLED)
    115 
    116 /**
    117  * Defined to the number of enabled TLS backends
    118  */
    119 #define mhd_TLS_NUM_BACKENDS \
    120         (mhd_TLS_GNU_ENABLED + mhd_TLS_OPEN_ENABLED + mhd_TLS_MBED_ENABLED)
    121 
    122 #if mhd_TLS_NUM_BACKENDS == 0
    123 #  error At least one TLS backend must be enabled if this header is included
    124 #endif
    125 
    126 #if mhd_TLS_NUM_BACKENDS > 1
    127 /**
    128  * Defined to '1' if Multi-TLS should be used
    129  */
    130 #  define MHD_USE_MULTITLS
    131 #endif
    132 
    133 /* Sanity check */
    134 #if defined(MHD_USE_MULTITLS) && !defined(mhd_HAVE_SEVERAL_TLS_BACKENDS)
    135 #  error several TLS backends set by configure, but only one available for code
    136 #endif
    137 #if !defined(MHD_USE_MULTITLS) && defined(mhd_HAVE_SEVERAL_TLS_BACKENDS)
    138 #  error several TLS backends available for code, but ony one set by configure
    139 #endif
    140 
    141 #ifdef MHD_USE_MULTITLS
    142 /**
    143  * Defined to one if Multi-TLS is enabled at build time or
    144  * to zero if not enabled
    145  */
    146 #  define mhd_TLS_MULTI_ENABLED         (1)
    147 #else
    148 /**
    149  * Defined to one if Multi-TLS is enabled at build time or
    150  * to zero if not enabled
    151  */
    152 #  define mhd_TLS_MULTI_ENABLED         (0)
    153 #endif
    154 /**
    155  * Return non-zero if Multi-TLS is supported
    156  */
    157 #define mhd_TLS_MULTI_IS_SUPPORTED()    (! ! mhd_TLS_MULTI_ENABLED)
    158 
    159 
    160 #if defined(MHD_USE_MULTITLS)
    161 /**
    162  * The TLS back-end identifier for function names
    163  */
    164 #  define mhd_TLS_FUNC_NAME_ID multi
    165 /**
    166  * The TLS back-end identifier for data names
    167  */
    168 #  define mhd_TLS_DATA_NAME_ID Multi
    169 /**
    170  * The TLS back-end identifier for macro names
    171  */
    172 #  define mhd_TLS_MACRO_NAME_ID MULTI
    173 #elif defined(MHD_SUPPORT_GNUTLS)
    174 /**
    175  * The TLS back-end identifier for function names
    176  */
    177 #  define mhd_TLS_FUNC_NAME_ID gnu
    178 /**
    179  * The TLS back-end identifier for data names
    180  */
    181 #  define mhd_TLS_DATA_NAME_ID Gnu
    182 /**
    183  * The TLS back-end identifier for macro names
    184  */
    185 #  define mhd_TLS_MACRO_NAME_ID GNU
    186 #elif defined(MHD_SUPPORT_OPENSSL)
    187 /**
    188  * The TLS back-end identifier for function names
    189  */
    190 #  define mhd_TLS_FUNC_NAME_ID open
    191 /**
    192  * The TLS back-end identifier for data names
    193  */
    194 #  define mhd_TLS_DATA_NAME_ID Open
    195 /**
    196  * The TLS back-end identifier for macro names
    197  */
    198 #  define mhd_TLS_MACRO_NAME_ID OPEN
    199 #elif defined(MHD_SUPPORT_MBEDTLS)
    200 /**
    201  * The TLS back-end identifier for function names
    202  */
    203 #  define mhd_TLS_FUNC_NAME_ID mbed
    204 /**
    205  * The TLS back-end identifier for data names
    206  */
    207 #  define mhd_TLS_DATA_NAME_ID Mbed
    208 /**
    209  * The TLS back-end identifier for macro names
    210  */
    211 #  define mhd_TLS_MACRO_NAME_ID MBED
    212 #endif
    213 
    214 
    215 /* ** Functions replacement macros to simplify the code ** */
    216 
    217 #ifndef MHD_SUPPORT_GNUTLS
    218 /**
    219  * Check whether GnuTLS backend was successfully initialised globally
    220  */
    221 #  define mhd_tls_gnu_is_inited_fine()   (! ! 0)
    222 #endif
    223 
    224 #ifndef MHD_SUPPORT_OPENSSL
    225 /**
    226  * Check whether OpenSSL backend was successfully initialised globally
    227  */
    228 #  define mhd_tls_open_is_inited_fine() (! ! 0)
    229 #endif
    230 
    231 #ifndef MHD_SUPPORT_MBEDTLS
    232 /**
    233  * Check whether MbedTLS backend was successfully initialised globally
    234  */
    235 #  define mhd_tls_mbed_is_inited_fine() (! ! 0)
    236 #endif
    237 
    238 
    239 /* ** Functions names and structures names macros ** */
    240 
    241 /**
    242  * Form function name specific for the selected TLS backend
    243  */
    244 #define mhd_TLS_DATA(name_suffix)    \
    245         mhd_MACRO_CONCAT3 (mhd_Tls,mhd_TLS_DATA_NAME_ID,name_suffix)
    246 
    247 /**
    248  * Form name of the data specific for the selected TLS backend
    249  */
    250 #define mhd_TLS_FUNC(name_suffix)    \
    251         mhd_MACRO_CONCAT3 (mhd_tls_,mhd_TLS_FUNC_NAME_ID,name_suffix)
    252 
    253 /**
    254  * The name of the structure that holds daemon-specific TLS data
    255  */
    256 #define mhd_TlsDaemonData       mhd_TLS_DATA (DaemonData)
    257 /**
    258  * The name of the structure that holds connection-specific TLS data
    259  */
    260 #define mhd_TlsConnData         mhd_TLS_DATA (ConnData)
    261 
    262 
    263 /* ** Forward declarations ** */
    264 
    265 /**
    266  * The structure with daemon-specific TLS data
    267  */
    268 struct mhd_TlsDaemonData;       /* Forward declaration */
    269 
    270 /**
    271  * The structure with connection-specific TLS data
    272  */
    273 struct mhd_TlsConnData;         /* Forward declaration */
    274 
    275 
    276 #endif /* ! MHD_TLS_CHOICE_H */