mhd_tls_choice.h (7633B)
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 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 /* ** Helper macros ** */ 55 56 /** 57 * Concatenate three arguments literally 58 */ 59 #define mhd_MACRO_CONCAT3_(a,b,c) a ## b ## c 60 /** 61 * Concatenate three arguments after expansion 62 */ 63 #define mhd_MACRO_CONCAT3(a,b,c) mhd_MACRO_CONCAT3_ (a,b,c) 64 65 66 /* ** Enumerate TLS backends ** */ 67 68 /* * GnuTLS * */ 69 70 #ifdef MHD_SUPPORT_GNUTLS 71 /** 72 * Defined to one if GnuTLS is enabled at build time or to zero if not enabled 73 */ 74 # define mhd_TLS_GNU_ENABLED (1) 75 #else 76 /** 77 * Defined to one if GnuTLS is enabled at build time or to zero if not enabled 78 */ 79 # define mhd_TLS_GNU_ENABLED (0) 80 #endif 81 82 /** 83 * Return non-zero if GnuTLS is supported 84 */ 85 #define mhd_TLS_GNU_IS_SUPPORTED() (! ! mhd_TLS_GNU_ENABLED) 86 87 /* * OpenSSL * */ 88 89 #ifdef MHD_SUPPORT_OPENSSL 90 /** 91 * Defined to one if OpenSSL is enabled at build time or to zero if not enabled 92 */ 93 # define mhd_TLS_OPEN_ENABLED (1) 94 #else 95 /** 96 * Defined to one if OpenSSL is enabled at build time or to zero if not enabled 97 */ 98 # define mhd_TLS_OPEN_ENABLED (0) 99 #endif 100 101 /** 102 * Return non-zero if OpenSSL is supported 103 */ 104 #define mhd_TLS_OPEN_IS_SUPPORTED() (! ! mhd_TLS_OPEN_ENABLED) 105 106 /* * MbedTLS * */ 107 108 #ifdef MHD_SUPPORT_MBEDTLS 109 /** 110 * Defined to one if MbedTLS is enabled at build time or to zero if not enabled 111 */ 112 # define mhd_TLS_MBED_ENABLED (1) 113 #else 114 /** 115 * Defined to one if MbedTLS is enabled at build time or to zero if not enabled 116 */ 117 # define mhd_TLS_MBED_ENABLED (0) 118 #endif 119 120 /** 121 * Return non-zero if OpenSSL is supported 122 */ 123 #define mhd_TLS_MBED_IS_SUPPORTED() (! ! mhd_TLS_MBED_ENABLED) 124 125 /** 126 * Defined to the number of enabled TLS backends 127 */ 128 #define mhd_TLS_NUM_BACKENDS \ 129 (mhd_TLS_GNU_ENABLED + mhd_TLS_OPEN_ENABLED + mhd_TLS_MBED_ENABLED) 130 131 #if mhd_TLS_NUM_BACKENDS == 0 132 #error At least one TLS backend must be enabled if this header is included 133 #endif 134 135 #if mhd_TLS_NUM_BACKENDS > 1 136 /** 137 * Defined to '1' if Multi-TLS should be used 138 */ 139 # define MHD_USE_MULTITLS 140 #endif 141 142 /* Sanity check */ 143 #if defined(MHD_USE_MULTITLS) && ! defined(mhd_HAVE_SEVERAL_TLS_BACKENDS) 144 #error several TLS backends set by configure, but only one available for code 145 #endif 146 #if ! defined(MHD_USE_MULTITLS) && defined(mhd_HAVE_SEVERAL_TLS_BACKENDS) 147 #error several TLS backends available for code, but ony one set by configure 148 #endif 149 150 #ifdef MHD_USE_MULTITLS 151 /** 152 * Defined to one if Multi-TLS is enabled at build time or 153 * to zero if not enabled 154 */ 155 # define mhd_TLS_MULTI_ENABLED (1) 156 #else 157 /** 158 * Defined to one if Multi-TLS is enabled at build time or 159 * to zero if not enabled 160 */ 161 # define mhd_TLS_MULTI_ENABLED (0) 162 #endif 163 /** 164 * Return non-zero if Multi-TLS is supported 165 */ 166 #define mhd_TLS_MULTI_IS_SUPPORTED() (! ! mhd_TLS_MULTI_ENABLED) 167 168 169 #if defined(MHD_USE_MULTITLS) 170 /** 171 * The TLS back-end identifier for function names 172 */ 173 # define mhd_TLS_FUNC_NAME_ID multi 174 /** 175 * The TLS back-end identifier for data names 176 */ 177 # define mhd_TLS_DATA_NAME_ID Multi 178 /** 179 * The TLS back-end identifier for macro names 180 */ 181 # define mhd_TLS_MACRO_NAME_ID MULTI 182 #elif defined(MHD_SUPPORT_GNUTLS) 183 /** 184 * The TLS back-end identifier for function names 185 */ 186 # define mhd_TLS_FUNC_NAME_ID gnu 187 /** 188 * The TLS back-end identifier for data names 189 */ 190 # define mhd_TLS_DATA_NAME_ID Gnu 191 /** 192 * The TLS back-end identifier for macro names 193 */ 194 # define mhd_TLS_MACRO_NAME_ID GNU 195 #elif defined(MHD_SUPPORT_OPENSSL) 196 /** 197 * The TLS back-end identifier for function names 198 */ 199 # define mhd_TLS_FUNC_NAME_ID open 200 /** 201 * The TLS back-end identifier for data names 202 */ 203 # define mhd_TLS_DATA_NAME_ID Open 204 /** 205 * The TLS back-end identifier for macro names 206 */ 207 # define mhd_TLS_MACRO_NAME_ID OPEN 208 #elif defined(MHD_SUPPORT_MBEDTLS) 209 /** 210 * The TLS back-end identifier for function names 211 */ 212 # define mhd_TLS_FUNC_NAME_ID mbed 213 /** 214 * The TLS back-end identifier for data names 215 */ 216 # define mhd_TLS_DATA_NAME_ID Mbed 217 /** 218 * The TLS back-end identifier for macro names 219 */ 220 # define mhd_TLS_MACRO_NAME_ID MBED 221 #endif 222 223 224 /* ** Functions replacement macros to simplify the code ** */ 225 226 #ifndef MHD_SUPPORT_GNUTLS 227 /** 228 * Check whether GnuTLS backend was successfully initialised globally 229 */ 230 # define mhd_tls_gnu_is_inited_fine() (! ! 0) 231 #endif 232 233 #ifndef MHD_SUPPORT_OPENSSL 234 /** 235 * Check whether OpenSSL backend was successfully initialised globally 236 */ 237 # define mhd_tls_open_is_inited_fine() (! ! 0) 238 #endif 239 240 #ifndef MHD_SUPPORT_MBEDTLS 241 /** 242 * Check whether MbedTLS backend was successfully initialised globally 243 */ 244 # define mhd_tls_mbed_is_inited_fine() (! ! 0) 245 #endif 246 247 248 /* ** Functions names and structures names macros ** */ 249 250 /** 251 * Form function name specific for the selected TLS backend 252 */ 253 #define mhd_TLS_DATA(name_suffix) \ 254 mhd_MACRO_CONCAT3 (mhd_Tls,mhd_TLS_DATA_NAME_ID,name_suffix) 255 256 /** 257 * Form name of the data specific for the selected TLS backend 258 */ 259 #define mhd_TLS_FUNC(name_suffix) \ 260 mhd_MACRO_CONCAT3 (mhd_tls_,mhd_TLS_FUNC_NAME_ID,name_suffix) 261 262 /** 263 * The name of the structure that holds daemon-specific TLS data 264 */ 265 #define mhd_TlsDaemonData mhd_TLS_DATA (DaemonData) 266 /** 267 * The name of the structure that holds connection-specific TLS data 268 */ 269 #define mhd_TlsConnData mhd_TLS_DATA (ConnData) 270 271 272 /* ** Forward declarations ** */ 273 274 /** 275 * The structure with daemon-specific TLS data 276 */ 277 struct mhd_TlsDaemonData; /* Forward declaration */ 278 279 /** 280 * The structure with connection-specific TLS data 281 */ 282 struct mhd_TlsConnData; /* Forward declaration */ 283 284 285 #endif /* ! MHD_TLS_CHOICE_H */