libmicrohttpd2

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

mhd_sys_options.h (27511B)


      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) 2016-2025 Karlson2k (Evgeny Grin)
      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/include/mhd_sys_options.h
     41  * @brief  additional automatic macros for mhd_config.h
     42  * @author Karlson2k (Evgeny Grin)
     43  *
     44  * This file includes mhd_config.h and adds automatic macros based on values
     45  * in mhd_config.h, compiler built-in macros and commandline-defined macros
     46  * (but not based on values defined in other headers). Works also as a guard
     47  * to prevent double inclusion of mhd_config.h
     48  *
     49  * This file must be included always before other headers as this header
     50  * defines macros that control behaviour of other included headers.
     51  */
     52 
     53 #ifndef MHD_SYS_OPTIONS_H
     54 #define MHD_SYS_OPTIONS_H 1
     55 
     56 #if defined(MICROHTTPD2_H) || defined(MICROHTTPD2_PORTABILITY_H)
     57 #  error the header "mhd_sys_options.h" must be included before any other header
     58 #endif
     59 
     60 #ifndef HAVE_CONFIG_H
     61 #  ifndef _MSC_VER
     62 #    error HAVE_CONFIG_H must be defined
     63 #  endif
     64 #endif
     65 
     66 #ifdef _WIN64
     67 /* workaround for some broken compilers */
     68 #  ifndef _WIN32
     69 #    define _WIN32 1
     70 #  endif
     71 #endif
     72 
     73 #include "mhd_config.h"
     74 
     75 #ifdef HAVE_ATTR_VISIBILITY_DEFAULT
     76 #  define MHD_VISIBILITY_EXTERN __attribute__((visibility ("default")))
     77 #else
     78 #  define MHD_VISIBILITY_EXTERN         /* empty */
     79 #endif
     80 
     81 #if !defined(_WIN32) || \
     82   (!defined(DLL_EXPORT)     /* Defined by libtool for shared version */ \
     83   && !defined(MHD_W32DLL) /* Defined by MS VS projects for MHD DLL */)
     84 #  define MHD_EXPORTED  /* empty */
     85 #else
     86 #  define MHD_EXPORTED __declspec(dllexport)
     87 #endif
     88 
     89 #if defined(HAVE_ATTR_USED) \
     90   && (defined(PIC) || defined(DLL_EXPORT) || defined(MHD_W32DLL))
     91 /* Used externally, only for functions in shared library */
     92 #  define MHD_EXTERN_USED __attribute__((used))
     93 #else
     94 #  define MHD_EXTERN_USED       /* empty */
     95 #endif
     96 
     97 #if defined(HAVE_ATTR_EXTERN_VISIBLE) \
     98   && (defined(PIC) || defined(DLL_EXPORT) || defined(MHD_W32DLL))
     99 #  define mhd_EXTERNALLY_ACCESSIBLE __attribute__ ((externally_visible))
    100 #else
    101 #  define mhd_EXTERNALLY_ACCESSIBLE     /* empty */
    102 #endif
    103 
    104 #if defined(MHD_EXTERN_) && defined(BUILDING_MHD_LIB)
    105 #  undef MHD_EXTERN_
    106 #endif /* MHD_EXTERN_ && BUILDING_MHD_LIB */
    107 
    108 #ifndef MHD_EXTERN_
    109 #  ifdef BUILDING_MHD_LIB
    110 /* Building MHD itself */
    111 #    define MHD_EXTERN_ \
    112             extern MHD_VISIBILITY_EXTERN MHD_EXPORTED \
    113             mhd_EXTERNALLY_ACCESSIBLE MHD_EXTERN_USED
    114 #  else  /* ! BUILDING_MHD_LIB */
    115 /* Test or example code, using MHD as a library */
    116 #    define MHD_EXTERN_ extern
    117 #  endif /* ! BUILDING_MHD_LIB */
    118 #endif  /* ! MHD_EXTERN_ */
    119 
    120 #ifdef HAVE_ATTR_VISIBILITY_HIDDEN
    121 /* To be used with internal non-static functions, that can be potentially used
    122  * externally via function pointers */
    123 #  define MHD_VISIBILITY_HIDDEN __attribute__((visibility ("hidden")))
    124 #else
    125 /* To be used with internal non-static functions, that can be potentially used
    126  * externally via function pointers */
    127 #  define MHD_VISIBILITY_HIDDEN         /* empty */
    128 #endif
    129 
    130 #ifdef HAVE_ATTR_VISIBILITY_INTERNAL
    131 /* To be used with internal non-static functions */
    132 #  define MHD_VISIBILITY_INTERNAL __attribute__((visibility ("internal")))
    133 #else
    134 /* To be used with internal non-static functions */
    135 #  define MHD_VISIBILITY_INTERNAL MHD_VISIBILITY_HIDDEN
    136 #endif
    137 
    138 /* To be used with internal non-static functions */
    139 #define MHD_INTERNAL MHD_VISIBILITY_INTERNAL
    140 
    141 #ifdef HAVE_ATTR_PURE
    142 #  define MHD_FN_PURE_ __attribute__((pure))
    143 #else
    144 #  define MHD_FN_PURE_  /* empty */
    145 #endif
    146 
    147 #ifdef HAVE_ATTR_CONST
    148 #  define MHD_FN_CONST_ __attribute__((const))
    149 #else
    150 #  define MHD_FN_CONST_ MHD_FN_PURE_
    151 #endif
    152 
    153 #ifdef HAVE_ATTR_WARN_UNUSED_RES
    154 #  define MHD_FN_MUST_CHECK_RESULT_ __attribute__ ((warn_unused_result))
    155 #else
    156 #  define MHD_FN_MUST_CHECK_RESULT_     /* empty */
    157 #endif
    158 
    159 #ifdef HAVE_ATTR_RET_NONNULL
    160 #  define MHD_FN_RETURNS_NONNULL_ __attribute__ ((returns_nonnull))
    161 #else
    162 #  define MHD_FN_RETURNS_NONNULL_       /* empty */
    163 #endif
    164 
    165 #ifdef HAVE_ATTR_NONNULL_NUM
    166 #  define MHD_FN_PAR_NONNULL_(param_num) __attribute__ ((nonnull (param_num)))
    167 #else
    168 #  define MHD_FN_PAR_NONNULL_(param_num)        /* empty */
    169 #endif
    170 
    171 #ifdef HAVE_ATTR_NONNULL
    172 #  define MHD_FN_PAR_NONNULL_ALL_ __attribute__ ((nonnull))
    173 #else
    174 #  define MHD_FN_PAR_NONNULL_ALL_       /* empty */
    175 #endif
    176 
    177 #ifdef HAVE_ATTR_NONNULL_IF_NONZERO
    178 #  define MHD_FN_PAR_NONNULL_IF_NONZERO_(ptr_num, size_num) \
    179           __attribute__ ((nonnull_if_nonzero (ptr_num, size_num)))
    180 #else
    181 #  define MHD_FN_PAR_NONNULL_IF_NONZERO_(ptr_num, size_num)     /* empty */
    182 #endif
    183 
    184 #ifdef HAVE_ATTR_ACCESS_READ
    185 #  define MHD_FN_PAR_IN_(param_num) \
    186           __attribute__ ((access (read_only,param_num)))
    187 #else
    188 #  define MHD_FN_PAR_IN_(param_num)     /* empty */
    189 #endif
    190 
    191 #ifdef HAVE_ATTR_ACCESS_READ_SIZE
    192 #  define MHD_FN_PAR_IN_SIZE_(param_num, size_num) \
    193           __attribute__ ((access (read_only,param_num,size_num)))
    194 #else
    195 #  define MHD_FN_PAR_IN_SIZE_(param_num, size_num)      /* empty */
    196 #endif
    197 
    198 #ifdef HAVE_ATTR_ACCESS_READ_WRITE
    199 #  define MHD_FN_PAR_OUT_(param_num) \
    200           __attribute__ ((access (write_only,param_num)))
    201 #else
    202 #  define MHD_FN_PAR_OUT_(param_num)    /* empty */
    203 #endif
    204 
    205 #ifdef HAVE_ATTR_ACCESS_WRITE
    206 #  define MHD_FN_PAR_OUT_SIZE_(param_num, size_num) \
    207           __attribute__ ((access (write_only,param_num,size_num)))
    208 #else
    209 #  define MHD_FN_PAR_OUT_SIZE_(param_num, size_num)     /* empty */
    210 #endif
    211 
    212 #ifdef HAVE_ATTR_ACCESS_READ_WRITE
    213 #  define MHD_FN_PAR_INOUT_(param_num) \
    214           __attribute__ ((access (read_write,param_num)))
    215 #else
    216 #  define MHD_FN_PAR_INOUT_(param_num)  /* empty */
    217 #endif
    218 
    219 #ifdef HAVE_ATTR_ACCESS_READ_WRITE_SIZE
    220 #  define MHD_FN_PAR_INOUT_SIZE_(param_num, size_num) \
    221           __attribute__ ((access (read_write,param_num,size_num)))
    222 #else
    223 #  define MHD_FN_PAR_INOUT_SIZE_(param_num, size_num)   /* empty */
    224 #endif
    225 
    226 #ifdef HAVE_ATTR_FD_ARG_READ
    227 #  define MHD_FN_PAR_FD_READ_(param_num) \
    228           __attribute__ ((fd_arg_read (param_num)))
    229 #else
    230 #  define MHD_FN_PAR_FD_READ_(param_num)        /* empty */
    231 #endif
    232 
    233 #ifdef HAVE_ATTR_NULL_TERM_STR
    234 #  define MHD_FN_PAR_CSTR_(param_num) \
    235           __attribute__ ((null_terminated_string_arg (param_num)))
    236 #else
    237 #  define MHD_FN_PAR_CSTR_(param_num)   /* empty */
    238 #endif
    239 
    240 #ifdef HAVE_FUNC_PARAM_ARR_STATIC_FIXED
    241 #  define MHD_FN_PAR_FIX_ARR_SIZE_(size)  static (size)
    242 #else
    243 #  define MHD_FN_PAR_FIX_ARR_SIZE_(size)  size
    244 #endif
    245 
    246 #ifdef HAVE_FUNC_PARAM_ARR_STATIC_VAR
    247 #  define MHD_FN_PAR_DYN_ARR_SIZE_(size)  static (size)
    248 #else
    249 #  define MHD_FN_PAR_DYN_ARR_SIZE_(size)  1
    250 #endif
    251 
    252 #ifdef HAVE_ATTR_FUNC_ASSUME_ALIGNED
    253 #  define mhd_FN_RET_ALIGNED(align) __attribute__((assume_aligned (align)))
    254 #else
    255 #  define mhd_FN_RET_ALIGNED(align)     /* empty */
    256 #endif
    257 
    258 #ifdef HAVE_ATTR_FUNC_ALLOC_SIZE
    259 /**
    260  * Indicates that returned pointer points to object with the size specified
    261  * by parameter number @a param_num.
    262  */
    263 #  define mhd_FN_RET_SIZED(param_num) __attribute__((alloc_size (param_num)))
    264 #else
    265 /**
    266  * Indicates that returned pointer points to object with the size specified
    267  * by parameter number @a param_num.
    268  */
    269 #  define mhd_FN_RET_SIZED(param_num)   /* empty */
    270 #endif
    271 
    272 #ifdef HAVE_ATTR_FUNC_MALLOC
    273 /**
    274  * Indicates that returned pointer is unique and does not alias any other
    275  * pointers.
    276  */
    277 #  define mhd_FN_RET_UNALIASED __attribute__((malloc))
    278 #else
    279 /**
    280  * Indicates that returned pointer is unique and does not alias any other
    281  * pointers.
    282  */
    283 #  define mhd_FN_RET_UNALIASED  /* empty */
    284 #endif
    285 
    286 #ifdef HAVE_ATTR_FUNC_MALLOC_DEALLOC
    287 /**
    288  * Indicates that function creates the object that must be destructed by
    289  * another function @a destructor.
    290  */
    291 #  define mhd_FN_OBJ_CONSTRUCTOR(destructor) \
    292           __attribute__((malloc (destructor)))
    293 #else
    294 /**
    295  * Indicates that function creates the object that must be destructed by
    296  * another function @a destructor.
    297  */
    298 #  define mhd_FN_OBJ_CONSTRUCTOR(destructor)    /* empty */
    299 #endif
    300 
    301 #ifdef HAVE_ATTR_ENUM_EXTNS_CLOSED
    302 #  define MHD_FIXED_ENUM_ __attribute__((enum_extensibility (closed)))
    303 #else
    304 #  define MHD_FIXED_ENUM_       /* empty */
    305 #endif
    306 
    307 #ifdef HAVE_ATTR_FLAG_ENUM
    308 #  define MHD_FLAGS_ENUM_ __attribute__((flag_enum))
    309 #else
    310 #  define MHD_FLAGS_ENUM_       /* empty */
    311 #endif /* MHD_FLAGS_ENUM_ */
    312 
    313 #define MHD_FIXED_FLAGS_ENUM_ MHD_FIXED_ENUM_ MHD_FLAGS_ENUM_
    314 
    315 /* 'inline' and 'restrict' are defined in mhd_config.h if needed */
    316 #define MHD_INLINE inline
    317 
    318 #define MHD_RESTRICT restrict
    319 
    320 #ifdef BUILDING_MHD_LIB
    321 #  define MHD_FIXED_ENUM_APP_SET_ /* empty */ /* handle unknown values set by the app */
    322 #else
    323 #  define MHD_FIXED_ENUM_APP_SET_ MHD_FIXED_ENUM_
    324 #endif
    325 
    326 #ifdef BUILDING_MHD_LIB
    327 #  define MHD_FLAGS_ENUM_APP_SET_ MHD_FLAGS_ENUM_
    328 #else
    329 #  define MHD_FLAGS_ENUM_APP_SET_ MHD_FLAGS_ENUM_
    330 #endif
    331 
    332 #ifdef BUILDING_MHD_LIB
    333 #  define MHD_FIXED_FLAGS_ENUM_APP_SET_ MHD_FLAGS_ENUM_ /* handle unknown values set by the app */
    334 #else
    335 #  define MHD_FIXED_FLAGS_ENUM_APP_SET_ MHD_FIXED_FLAGS_ENUM_
    336 #endif
    337 
    338 #ifdef BUILDING_MHD_LIB
    339 #  define MHD_FIXED_ENUM_MHD_SET_ MHD_FIXED_ENUM_
    340 #else
    341 #  define MHD_FIXED_ENUM_MHD_SET_ /* empty */ /* enum can be extended in next MHD versions */
    342 #endif
    343 
    344 #ifdef BUILDING_MHD_LIB
    345 #  define MHD_FLAGS_ENUM_MHD_SET_ MHD_FLAGS_ENUM_
    346 #else
    347 #  define MHD_FLAGS_ENUM_MHD_SET_ MHD_FLAGS_ENUM_
    348 #endif
    349 
    350 #ifdef BUILDING_MHD_LIB
    351 #  define MHD_FIXED_FLAGS_ENUM_MHD_SET_ MHD_FIXED_FLAGS_ENUM_
    352 #else
    353 #  define MHD_FIXED_FLAGS_ENUM_MHD_SET_ MHD_FLAGS_ENUM_ /* enum can be extended in next MHD versions */
    354 #endif
    355 
    356 #ifdef BUILDING_MHD_LIB
    357 #  define MHD_FIXED_ENUM_MHD_APP_SET_ /* empty */ /* handle unknown values set by the app */
    358 #else
    359 #  define MHD_FIXED_ENUM_MHD_APP_SET_ /* empty */ /* enum can be extended in next MHD versions */
    360 #endif
    361 
    362 #ifdef BUILDING_MHD_LIB
    363 #  define MHD_FLAGS_ENUM_MHD_APP_SET_ MHD_FLAGS_ENUM_
    364 #else
    365 #  define MHD_FLAGS_ENUM_MHD_APP_SET_ MHD_FLAGS_ENUM_
    366 #endif
    367 
    368 #ifdef BUILDING_MHD_LIB
    369 #  define MHD_FIXED_FLAGS_ENUM_MHD_APP_SET_ MHD_FLAGS_ENUM_ /* handle unknown values set by the app */
    370 #else
    371 #  define MHD_FIXED_FLAGS_ENUM_MHD_APP_SET_ MHD_FLAGS_ENUM_ /* enum can be extended in next MHD versions */
    372 #endif
    373 
    374 // TODO: support warnings mute
    375 #ifdef HAVE_ENUM_BASE_TYPE_WARNLESS
    376 #  define mhd_USE_ENUM_BASE_T   1
    377 #endif
    378 #ifdef mhd_USE_ENUM_BASE_T
    379 #  define mhd_ENUM_BASE_T(fixed_type) : fixed_type
    380 #else
    381 #  define mhd_ENUM_BASE_T(fixed_type) /* empty */
    382 #endif
    383 
    384 /**
    385  * Automatic string with the name of the current function
    386  */
    387 #if defined(HAVE___FUNC__)
    388 #  define MHD_FUNC_       __func__
    389 #  define MHD_HAVE_MHD_FUNC_ 1
    390 #elif defined(HAVE___FUNCTION__)
    391 #  define MHD_FUNC_       __FUNCTION__
    392 #  define MHD_HAVE_MHD_FUNC_ 1
    393 #elif defined(HAVE___PRETTY_FUNCTION__)
    394 #  define MHD_FUNC_       __PRETTY_FUNCTION__
    395 #  define MHD_HAVE_MHD_FUNC_ 1
    396 #else
    397 #  define MHD_FUNC_       "**name unavailable**"
    398 #  ifdef MHD_HAVE_MHD_FUNC_
    399 #    undef MHD_HAVE_MHD_FUNC_
    400 #  endif /* MHD_HAVE_MHD_FUNC_ */
    401 #endif
    402 
    403 /* Some platforms (FreeBSD, Solaris, W32) allow to override
    404    default FD_SETSIZE by defining it before including
    405    headers. */
    406 #ifdef FD_SETSIZE
    407 /* FD_SETSIZE defined in command line or in mhd_config.h */
    408 #elif defined(_WIN32) || defined(__CYGWIN__)
    409 /* Platform with WinSock and without overridden FD_SETSIZE */
    410 #  ifdef _WIN64
    411 #    define FD_SETSIZE 4096 /* Override default small value (64) */
    412 #  else
    413 #    define FD_SETSIZE 1024 /* Override default small value (64) */
    414 #  endif
    415 #else  /* !FD_SETSIZE && !W32 */
    416 /* System default value of FD_SETSIZE is used */
    417 #  define MHD_FD_SETSIZE_IS_DEFAULT_ 1
    418 #endif /* !FD_SETSIZE && !W32 */
    419 
    420 #if defined(HAVE_LINUX_SENDFILE) || defined(HAVE_FREEBSD_SENDFILE) || \
    421   defined(HAVE_DARWIN_SENDFILE)
    422 /* Have any supported sendfile() function. */
    423 #  define mhd_USE_SENDFILE 1
    424 #endif /* HAVE_LINUX_SENDFILE || HAVE_FREEBSD_SENDFILE
    425           || HAVE_DARWIN_SENDFILE */
    426 
    427 #if defined(mhd_THREADS_KIND_POSIX) || defined(mhd_THREADS_KIND_W32)
    428 #  ifndef MHD_SUPPORT_THREADS
    429 #    define MHD_SUPPORT_THREADS 1
    430 #  endif
    431 #endif /* mhd_THREADS_KIND_POSIX || mhd_THREADS_KIND_W32 */
    432 
    433 #if defined(_WIN32) && !defined(__CYGWIN__)
    434 /**
    435  * Defined if the platform is native W32.
    436  * Not define on Cygwin.
    437  */
    438 #  define mhd_W32_NATIVE        1
    439 #endif
    440 /**
    441  * Macro to drop 'const' qualifier from pointer.
    442  * Try to avoid compiler warning.
    443  * To be used *only* to deal with broken external APIs, which require non-const
    444  * pointer to unmodifiable data.
    445  * Must not be used to transform pointers for internal MHD needs.
    446  */
    447 #ifdef HAVE_UINTPTR_T
    448 #  define mhd_DROP_CONST(ptr)  ((void *) ((uintptr_t) ((const void *) (ptr))))
    449 #elif defined(HAVE_INTPTR_T)
    450 #  define mhd_DROP_CONST(ptr)  ((void *) ((intptr_t) ((const void *) (ptr))))
    451 #else
    452 #  define mhd_DROP_CONST(ptr)  ((void *) ((const void *) (ptr)))
    453 #endif
    454 
    455 /**
    456  * Cast signed integer to pointer
    457  */
    458 #if defined(HAVE_INTPTR_T)
    459 #  define mhd_INT_TO_PTR(i)  ((void *) ((intptr_t) (i)))
    460 #else
    461 #  define mhd_INT_TO_PTR(i)  ((void *) (i))
    462 #endif
    463 
    464 /**
    465  * Cast unsigned integer to pointer
    466  */
    467 #if defined(HAVE_UINTPTR_T)
    468 #  define mhd_UINT_TO_PTR(i)  ((void *) ((uintptr_t) (i)))
    469 #else
    470 #  define mhd_UINT_TO_PTR(i)  ((void *) (i))
    471 #endif
    472 
    473 /**
    474  * Cast a pointer to an integer
    475  *
    476  * The result type is platform-dependent and may be signed.
    477  */
    478 #if defined(HAVE_UINTPTR_T)
    479 #  define mhd_PTR_TO_INT(p)  ((uintptr_t)    ((const void*)(p)))
    480 #elif defined(HAVE_INTPTR_T)
    481 #  define mhd_PTR_TO_INT(p)  ((intptr_t)     ((const void*)(p)))
    482 #elif (0 != SIZEOF_VOIDP) && (SIZEOF_VOIDP == SIZEOF_UNSIGNED_LONG)
    483 #  define mhd_PTR_TO_INT(p)  ((unsigned long)((const void*)(p)))
    484 #elif (0 != SIZEOF_VOIDP) && (SIZEOF_VOIDP == SIZEOF_UNSIGNED_INT)
    485 #  define mhd_PTR_TO_INT(p)  ((unsigned int) ((const void*)(p)))
    486 #else
    487 #  define mhd_PTR_TO_INT(p)  ((unsigned long long)((const void*)(p)))
    488 #endif
    489 
    490 
    491 /* *************************************************************** *
    492  *     Macros to enable various features in the system headers     *
    493  * *************************************************************** */
    494 
    495 
    496 #if defined(OS390)
    497 #  define _OPEN_THREADS
    498 #  define _OPEN_SYS_SOCK_IPV6
    499 #  define _OPEN_MSGQ_EXT
    500 #  define _LP64
    501 #endif
    502 
    503 #if defined(_WIN32) && !defined(__CYGWIN__)
    504 /* Declare POSIX-compatible names */
    505 #  define _CRT_DECLARE_NONSTDC_NAMES 1
    506 /* Do not warn about POSIX name usage */
    507 #  define _CRT_NONSTDC_NO_WARNINGS 1
    508 #  ifndef _WIN32_WINNT
    509 #    define _WIN32_WINNT 0x0600
    510 #  else /* _WIN32_WINNT */
    511 #    if _WIN32_WINNT < 0x0501
    512 #      error "Headers for Windows XP or later are required"
    513 #    endif /* _WIN32_WINNT < 0x0501 */
    514 #  endif /* _WIN32_WINNT */
    515 #  ifndef WIN32_LEAN_AND_MEAN
    516 /* Do not include unneeded parts of W32 headers. */
    517 #    define WIN32_LEAN_AND_MEAN 1
    518 #  endif /* !WIN32_LEAN_AND_MEAN */
    519 #endif /* _WIN32 && ! __CYGWIN__ */
    520 
    521 #if defined(__MINGW32__)
    522 #  ifndef __USE_MINGW_ANSI_STDIO
    523 #    define __USE_MINGW_ANSI_STDIO 0 /* Force use native printf, the code is well-adapted */
    524 #  endif
    525 #endif
    526 
    527 #if defined(__VXWORKS__) || defined(__vxworks) || defined(OS_VXWORKS)
    528 #  define RESTRICT __restrict__
    529 #endif /* __VXWORKS__ || __vxworks || OS_VXWORKS */
    530 
    531 #if defined(__linux__) && \
    532   (defined(HAVE_SENDFILE64) || defined(HAVE_LSEEK64) || defined(HAVE_PREAD64))
    533 #  if !defined(_LARGEFILE64_SOURCE)
    534 /* On Linux, special macro is required to enable definitions of some xxx64 functions */
    535 #    define _LARGEFILE64_SOURCE 1
    536 #  endif
    537 #endif
    538 
    539 #ifdef HAVE_C11_GMTIME_S
    540 /* Special macro is required to enable C11 definition of gmtime_s() function */
    541 #  define __STDC_WANT_LIB_EXT1__ 1
    542 #endif /* HAVE_C11_GMTIME_S */
    543 
    544 #if defined(__sun) || defined(__illumos__)
    545 #  ifndef _REENTRANT
    546 #    define _REENTRANT  1 /* Could be optional, given that POSIX_C_SOURCE is defined */
    547 #  endif
    548 #endif
    549 
    550 #ifndef _MSC_FULL_VER
    551 #  define mhd_DATA_TRUNCATION_RUNTIME_CHECK_DISABLE /* empty */
    552 #  define mhd_DATA_TRUNCATION_RUNTIME_CHECK_RESTORE /* empty */
    553 #else  /* _MSC_FULL_VER */
    554 #  define mhd_DATA_TRUNCATION_RUNTIME_CHECK_DISABLE \
    555           __pragma(runtime_checks("c", off))
    556 #  define mhd_DATA_TRUNCATION_RUNTIME_CHECK_RESTORE \
    557           __pragma(runtime_checks("c", restore))
    558 #endif /* _MSC_FULL_VER */
    559 
    560 
    561 /* *************************************************************** *
    562  *             Additional automatic configuration macros           *
    563  * *************************************************************** */
    564 
    565 
    566 /* Ensure that exactly one of the two macros is always defined */
    567 #if defined(NDEBUG) && defined(_DEBUG)
    568 #  error Both _DEBUG and NDEBUG are defined
    569 #elif !defined(_DEBUG) && !defined(NDEBUG)
    570 #  ifndef DEBUG /* Used by some toolchains */
    571 #    define NDEBUG 1 /* Use NDEBUG by default */
    572 #  else  /* DEBUG */
    573 #    define _DEBUG 1 /* Non-standard macro */
    574 #  endif /* DEBUG */
    575 #endif /* !_DEBUG && !NDEBUG */
    576 
    577 #if !defined(MHD_CC_OPTIMISE_FOR_SIZE) \
    578   && !defined(MHD_CC_OPTIMISE_FOR_SPEED)
    579 #  if defined(__OPTIMIZE_SIZE__) || defined(__OPTIMISE_SPACE)
    580 #    define MHD_CC_OPTIMISE_FOR_SIZE   1
    581 #  elif defined(__OPTIMIZE__) || defined(__OPTIMISE_TIME)
    582 #    define MHD_CC_OPTIMISE_FOR_SPEED   1
    583 #  endif /* __OPTIMIZE__ */
    584 #elif defined(MHD_CC_OPTIMISE_FOR_SIZE) && defined(MHD_CC_OPTIMISE_FOR_SPEED)
    585 #  error MHD_CC_OPTIMISE_FOR_SIZE and MHD_CC_OPTIMISE_FOR_SPEED both defined.
    586 #endif
    587 
    588 #if defined(MHD_FAVOR_FAST_CODE) && defined(MHD_FAVOR_SMALL_CODE)
    589 #  error MHD_FAVOR_FAST_CODE and MHD_FAVOR_SMALL_CODE are both defined.
    590 #  error Cannot favor speed and size at the same time.
    591 #endif /* MHD_FAVOR_FAST_CODE && MHD_FAVOR_SMALL_CODE */
    592 
    593 /* Define MHD_FAVOR_FAST_CODE to force fast code path or
    594    define MHD_FAVOR_SMALL_CODE to choose compact code path */
    595 #if !defined(MHD_FAVOR_FAST_CODE) && !defined(MHD_FAVOR_SMALL_CODE)
    596 /* Try to guess automatically user preferences */
    597 #  if defined(MHD_CC_OPTIMISE_FOR_SPEED)
    598 #    define MHD_FAVOR_FAST_CODE         1
    599 #  elif defined(MHD_CC_OPTIMISE_FOR_SIZE)
    600 #    define MHD_FAVOR_SMALL_CODE        1
    601 #  endif /* __OPTIMIZE__ */
    602 #endif /* !MHD_FAVOR_FAST_CODE && !MHD_FAVOR_SMALL_CODE */
    603 
    604 #if !defined(MHD_FAVOR_FAST_CODE) && !defined(MHD_FAVOR_SMALL_CODE)
    605 /* Use faster code by default */
    606 #  define MHD_FAVOR_FAST_CODE 1
    607 #endif /* !MHD_FAVOR_FAST_CODE && !MHD_FAVOR_SMALL_CODE */
    608 
    609 #if defined(MHD_FAVOR_SMALL_CODE) && defined(mhd_static_inline)
    610 #  undef mhd_static_inline
    611 #  define mhd_static_inline static inline /* give compiler more freedom */
    612 #endif
    613 
    614 #ifndef MHD_ASAN_ACTIVE
    615 #  ifdef __SANITIZE_ADDRESS__
    616 #    define MHD_ASAN_ACTIVE 1
    617 #  elif defined(__has_feature)
    618 #    if __has_feature (address_sanitizer)
    619 #      define MHD_ASAN_ACTIVE 1
    620 #    endif /* __has_feature(address_sanitizer) */
    621 #  endif /* __has_feature */
    622 #endif /* ! MHD_ASAN_ACTIVE */
    623 
    624 #if defined(MHD_ASAN_ACTIVE) && defined(HAVE_SANITIZER_ASAN_INTERFACE_H) && \
    625   (defined(FUNC_PTRCOMPARE_CAST_WORKAROUND_WORKS) || \
    626   (defined(FUNC_ATTR_PTRCOMPARE_WORKS) && \
    627   defined(FUNC_ATTR_PTRSUBTRACT_WORKS)) || \
    628   defined(FUNC_ATTR_NOSANITIZE_WORKS))
    629 #  ifndef MHD_ASAN_POISON_ACTIVE
    630 /* User ASAN poisoning could be used */
    631 #    warning User memory poisoning is not active
    632 #  endif /* ! MHD_ASAN_POISON_ACTIVE */
    633 #else  /* ! (MHD_ASAN_ACTIVE && HAVE_SANITIZER_ASAN_INTERFACE_H &&
    634            (FUNC_ATTR_PTRCOMPARE_WORKS || FUNC_ATTR_NOSANITIZE_WORKS))   */
    635 #  ifdef MHD_ASAN_POISON_ACTIVE
    636 #    error User memory poisoning is active, but conditions are not suitable
    637 #  endif /* MHD_ASAN_POISON_ACTIVE */
    638 #endif /* ! (MHD_ASAN_ACTIVE && HAVE_SANITIZER_ASAN_INTERFACE_H &&
    639            (FUNC_ATTR_PTRCOMPARE_WORKS || FUNC_ATTR_NOSANITIZE_WORKS))   */
    640 
    641 #if !defined(mhd_W32_NATIVE)
    642 /**
    643  * Indicate that suppression of SIGPIPE is required for some network
    644  * system calls.
    645  */
    646 #  define mhd_SEND_SPIPE_SUPPRESS_NEEDED     1
    647 #endif
    648 
    649 #ifndef NDEBUG
    650 #  ifndef MHD_NO_TLS_DEBUG_MESSAGES
    651 #    ifndef mhd_USE_TLS_DEBUG_MESSAGES
    652 /**
    653  * Enable debugging output on TLS library (if possible)
    654  */
    655 #      define mhd_USE_TLS_DEBUG_MESSAGES    1
    656 #    endif
    657 #  endif
    658 #endif
    659 
    660 /* Manual overrides for debug-printing */
    661 
    662 #ifndef MHD_USE_TRACE_POLLING_FDS
    663 /* Use debug-print for FDs polling */
    664 /* #  define MHD_USE_TRACE_POLLING_FDS 1 */
    665 #endif
    666 
    667 #ifndef MHD_USE_TRACE_CONN_ADD_CLOSE
    668 /* Use debug-print for adding and closing of the connections */
    669 /* #  define MHD_USE_TRACE_CONN_ADD_CLOSE 1 */
    670 #endif
    671 
    672 #ifndef MHD_USE_TRACE_SUSPEND_RESUME
    673 /* Use debug-print for suspending and resuming of the requests */
    674 /* #  define MHD_USE_TRACE_SUSPEND_RESUME 1 */
    675 #endif
    676 
    677 #ifndef MHD_AUTH_DIGEST_DEF_TIMEOUT
    678 #  define MHD_AUTH_DIGEST_DEF_TIMEOUT 90
    679 #endif /* ! MHD_AUTH_DIGEST_DEF_TIMEOUT */
    680 #ifndef MHD_AUTH_DIGEST_DEF_MAX_NC
    681 #  define MHD_AUTH_DIGEST_DEF_MAX_NC 1000
    682 #endif /* ! MHD_AUTH_DIGEST_DEF_MAX_NC */
    683 
    684 #ifdef MHD_SUPPORT_HTTP2
    685 /* Note: HTTP/1.x support is mandatory in the current code */
    686 
    687 /**
    688  * Defined if more than one HTTP protocol family is supported by this build
    689  * and therefore the protocol kind of the handles must be detected in run-time.
    690  */
    691 #  define mhd_MULTI_HTTP_VER_BUILD            1
    692 #endif /* MHD_SUPPORT_HTTP2 */
    693 
    694 #ifndef mhd_HAVE_TLS_THREAD_CLEANUP
    695 #  ifdef MHD_SUPPORT_OPENSSL
    696 /**
    697  * If defined then mhd_tls_thread_cleanup() is a real function.
    698  * If not defined then mhd_tls_thread_cleanup() is an empty macro
    699  */
    700 #    define mhd_HAVE_TLS_THREAD_CLEANUP         1
    701 #  endif
    702 #endif
    703 
    704 #ifdef MHD_SUPPORT_HTTPS
    705 #  ifdef MHD_SUPPORT_ACME
    706 #    ifdef MHD_SUPPORT_GNUTLS
    707 #      ifdef HAVE_GNUTLS_HANDSHAKE_SET_HOOK_FUNCTION
    708 /**
    709  * Indicate that ACME ALPN challenge support is available in the GnuTLS backend
    710  */
    711 #        define mhd_HAVE_GNUTLS_ACME      1
    712 /* define MHD_FORCE_USE_MHD_CLIENTHELLO_BODY_PARSE to always use MHD internal
    713    parser for ClientHello body instead of all TLS backend parsers */
    714 /* define MHD_FORCE_USE_GNUTLS_MHD_CLIENTHELLO_BODY_PARSE to use MHD internal
    715    parser for ClientHello body instead of GnuTLS parser */
    716 #        if defined(MHD_FORCE_USE_MHD_CLIENTHELLO_BODY_PARSE) \
    717   && !defined(MHD_FORCE_USE_GNUTLS_MHD_CLIENTHELLO_BODY_PARSE)
    718 /**
    719  * Use MHD internal parser for ClientHello body instead of GnuTLS parser
    720  */
    721 #          define MHD_FORCE_USE_GNUTLS_MHD_CLIENTHELLO_BODY_PARSE 1
    722 #        endif
    723 #        if !defined(HAVE_GNUTLS_EXT_RAW_PARSE) || \
    724   defined(MHD_FORCE_USE_GNUTLS_MHD_CLIENTHELLO_BODY_PARSE)
    725 #          ifndef mhd_HAVE_TLS_MHD_CLIENTHELLO_BODY_PARSE
    726 /**
    727  * MHD internal parser for ClientHello body is available
    728  */
    729 #            define mhd_HAVE_TLS_MHD_CLIENTHELLO_BODY_PARSE  1
    730 #          endif /* ! mhd_HAVE_TLS_MHD_CLIENTHELLO_BODY_PARSE */
    731 #        else  /* HAVE_GNUTLS_EXT_RAW_PARSE
    732                   && ! MHD_FORCE_USE_GNUTLS_MHD_CLIENTHELLO_BODY_PARSE */
    733 /**
    734  * Use GnuTLS parser for ClientHello body
    735  */
    736 #          define mhd_USE_GNUTLS_EXT_RAW_PARSE 1
    737 #        endif /* HAVE_GNUTLS_EXT_RAW_PARSE
    738                   && ! MHD_FORCE_USE_GNUTLS_MHD_CLIENTHELLO_BODY_PARSE */
    739 #      endif /* HAVE_GNUTLS_HANDSHAKE_SET_HOOK_FUNCTION */
    740 #    endif /* MHD_SUPPORT_GNUTLS */
    741 #    ifdef MHD_SUPPORT_OPENSSL
    742 #      ifndef MHD_NO_OPENSSL_ACME_ALPN
    743 /**
    744  * Indicate that ACME ALPN challenge support is available in the OpenSSL backend
    745  */
    746 #        define mhd_HAVE_OPENSSL_ACME      1
    747 /* define MHD_FORCE_USE_MHD_CLIENTHELLO_BODY_PARSE to always use MHD internal
    748    parser for ClientHello body instead of all TLS backend parsers */
    749 /* define MHD_FORCE_USE_OPENSSL_MHD_CLIENTHELLO_BODY_PARSE to use MHD internal
    750    parser for ClientHello body instead of OpenSSL parser */
    751 #        if defined(MHD_FORCE_USE_MHD_CLIENTHELLO_BODY_PARSE) \
    752   && !defined(MHD_FORCE_USE_OPENSSL_MHD_CLIENTHELLO_BODY_PARSE)
    753 /**
    754  * Use MHD internal parser for ClientHello body instead of OpenSSL parser
    755  */
    756 #          define MHD_FORCE_USE_OPENSSL_MHD_CLIENTHELLO_BODY_PARSE 1
    757 #        endif
    758 #        ifndef MHD_FORCE_USE_OPENSSL_MHD_CLIENTHELLO_BODY_PARSE
    759 #          define mhd_USE_OPENSSL_CLIENT_HELLO_GET0_EXT 1
    760 #        endif /* ! MHD_FORCE_USE_OPENSSL_MHD_CLIENTHELLO_BODY_PARSE */
    761 #        ifndef mhd_USE_OPENSSL_CLIENT_HELLO_GET0_EXT
    762 #          ifndef mhd_HAVE_TLS_MHD_CLIENTHELLO_BODY_PARSE
    763 #            define mhd_HAVE_TLS_MHD_CLIENTHELLO_BODY_PARSE  1
    764 #          endif /* ! mhd_HAVE_TLS_MHD_CLIENTHELLO_BODY_PARSE */
    765 #        endif /* MHD_FORCE_USE_OPENSSL_MHD_CLIENTHELLO_BODY_PARSE */
    766 #      endif /* MHD_NO_OPENSSL_ACME_ALPN */
    767 #    endif /* MHD_SUPPORT_OPENSSL */
    768 #  else  /* ! MHD_SUPPORT_ACME */
    769 #    ifdef MHD_FORCE_USE_MHD_CLIENTHELLO_BODY_PARSE
    770 #      undef MHD_FORCE_USE_MHD_CLIENTHELLO_BODY_PARSE
    771 #    endif
    772 #    ifdef MHD_FORCE_USE_GNUTLS_MHD_CLIENTHELLO_BODY_PARSE
    773 #      undef MHD_FORCE_USE_GNUTLS_MHD_CLIENTHELLO_BODY_PARSE
    774 #    endif
    775 #    ifdef MHD_FORCE_USE_OPENSSL_MHD_CLIENTHELLO_BODY_PARSE
    776 #      undef MHD_FORCE_USE_OPENSSL_MHD_CLIENTHELLO_BODY_PARSE
    777 #    endif
    778 #  endif /* ! MHD_SUPPORT_ACME */
    779 #endif /* MHD_SUPPORT_HTTPS */
    780 
    781 #if defined(MHD_SUPPORT_HTTPS) && defined(MHD_SUPPORT_ACME) && \
    782   (defined(mhd_HAVE_GNUTLS_ACME) || defined(mhd_HAVE_OPENSSL_ACME))
    783 /**
    784  * Have support for ACME ALPN challenge
    785  * @warning If MHD_SUPPORT_ACME is enabled but this macros is not defined then
    786  *          application API for ACME ALPN is available but it will fail
    787  *          at runtime
    788  */
    789 #  define mhd_HAVE_TLS_ACME  1
    790 #endif
    791 
    792 
    793 /* Eclipse parse compatibility */
    794 #ifdef __CDT_PARSER__
    795 #  undef MHD_NORETURN_
    796 #  define MHD_NORETURN_ __attribute__((__noreturn__))
    797 #  undef mhd_FALLTHROUGH
    798 #  define mhd_FALLTHROUGH ((void) 0)
    799 #  undef _Atomic
    800 #  define _Atomic /* empty */
    801 #  undef MHD_HAVE_C_CONSTEXPR
    802 #  if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311)
    803 #    define bool    _Bool
    804 #    define true    1
    805 #    define false   0
    806 #  elif defined __has_include
    807 #    if __has_include (<stdbool.h>)
    808 #      define HAVE_STDBOOL_H    1
    809 #    endif
    810 #  endif
    811 #  define mhd_ENUM_BASE_T(base) /* nothing */
    812 #  if ((__STDC_VERSION__ + 0) >= 202311)
    813 #    define alignof _Alignof
    814 #  endif
    815 #  define __auto_type auto
    816 #endif
    817 
    818 /* Avoid interference with third-party headers */
    819 #ifdef HAVE_CONFIG_H
    820 #  undef HAVE_CONFIG_H
    821 #endif
    822 
    823 #endif /* MHD_SYS_OPTIONS_H */