mhd_options.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. This file is part of libmicrohttpd
  3. Copyright (C) 2016-2021 Karlson2k (Evgeny Grin)
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  15. */
  16. /**
  17. * @file include/mhd_options.h
  18. * @brief additional automatic macros for MHD_config.h
  19. * @author Karlson2k (Evgeny Grin)
  20. *
  21. * This file includes MHD_config.h and adds automatic macros based on values
  22. * in MHD_config.h, compiler built-in macros and commandline-defined macros
  23. * (but not based on values defined in other headers). Works also as a guard
  24. * to prevent double inclusion of MHD_config.h
  25. */
  26. #ifndef MHD_OPTIONS_H
  27. #define MHD_OPTIONS_H 1
  28. #include "MHD_config.h"
  29. /**
  30. * Macro to make it easy to mark text for translation. Note that
  31. * we do not actually call gettext() in MHD, but we do make it
  32. * easy to create a ".po" file so that applications that do want
  33. * to translate error messages can do so.
  34. */
  35. #define _(String) (String)
  36. #if defined(_MHD_EXTERN) && ! defined(BUILDING_MHD_LIB)
  37. #undef _MHD_EXTERN
  38. #endif /* _MHD_EXTERN && ! BUILDING_MHD_LIB */
  39. #ifndef _MHD_EXTERN
  40. #if defined(BUILDING_MHD_LIB) && defined(_WIN32) && \
  41. (defined(DLL_EXPORT) || defined(MHD_W32DLL))
  42. #define _MHD_EXTERN __declspec(dllexport) extern
  43. #else /* !BUILDING_MHD_LIB || !_WIN32 || (!DLL_EXPORT && !MHD_W32DLL) */
  44. #define _MHD_EXTERN extern
  45. #endif /* !BUILDING_MHD_LIB || !_WIN32 || (!DLL_EXPORT && !MHD_W32DLL) */
  46. #endif /* ! _MHD_EXTERN */
  47. /* Some platforms (FreeBSD, Solaris, W32) allow to override
  48. default FD_SETSIZE by defining it before including
  49. headers. */
  50. #ifdef FD_SETSIZE
  51. /* FD_SETSIZE defined in command line or in MHD_config.h */
  52. #elif defined(_WIN32) || defined(__CYGWIN__)
  53. /* Platform with WinSock and without overridden FD_SETSIZE */
  54. #define FD_SETSIZE 2048 /* Override default small value (64) */
  55. #else /* !FD_SETSIZE && !W32 */
  56. /* System default value of FD_SETSIZE is used */
  57. #define _MHD_FD_SETSIZE_IS_DEFAULT 1
  58. #endif /* !FD_SETSIZE && !W32 */
  59. #if defined(HAVE_LINUX_SENDFILE) || defined(HAVE_FREEBSD_SENDFILE) || \
  60. defined(HAVE_DARWIN_SENDFILE) || defined(HAVE_SOLARIS_SENDFILE)
  61. /* Have any supported sendfile() function. */
  62. #define _MHD_HAVE_SENDFILE
  63. #endif /* HAVE_LINUX_SENDFILE || HAVE_FREEBSD_SENDFILE ||
  64. HAVE_DARWIN_SENDFILE || HAVE_SOLARIS_SENDFILE */
  65. #if defined(HAVE_LINUX_SENDFILE) || defined(HAVE_SOLARIS_SENDFILE)
  66. #define MHD_LINUX_SOLARIS_SENDFILE 1
  67. #endif /* HAVE_LINUX_SENDFILE || HAVE_SOLARIS_SENDFILE */
  68. #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
  69. # ifndef MHD_USE_THREADS
  70. # define MHD_USE_THREADS 1
  71. # endif
  72. #endif /* MHD_USE_POSIX_THREADS || MHD_USE_W32_THREADS */
  73. #if defined(OS390)
  74. #define _OPEN_THREADS
  75. #define _OPEN_SYS_SOCK_IPV6
  76. #define _OPEN_MSGQ_EXT
  77. #define _LP64
  78. #endif
  79. #if defined(_WIN32) && ! defined(__CYGWIN__)
  80. /* Declare POSIX-compatible names */
  81. #define _CRT_DECLARE_NONSTDC_NAMES 1
  82. /* Do not warn about POSIX name usage */
  83. #define _CRT_NONSTDC_NO_WARNINGS 1
  84. #ifndef _WIN32_WINNT
  85. #define _WIN32_WINNT 0x0600
  86. #else /* _WIN32_WINNT */
  87. #if _WIN32_WINNT < 0x0501
  88. #error "Headers for Windows XP or later are required"
  89. #endif /* _WIN32_WINNT < 0x0501 */
  90. #endif /* _WIN32_WINNT */
  91. #ifndef WIN32_LEAN_AND_MEAN
  92. /* Do not include unneeded parts of W32 headers. */
  93. #define WIN32_LEAN_AND_MEAN 1
  94. #endif /* !WIN32_LEAN_AND_MEAN */
  95. #endif /* _WIN32 && ! __CYGWIN__ */
  96. #if defined(__VXWORKS__) || defined(__vxworks) || defined(OS_VXWORKS)
  97. #define RESTRICT __restrict__
  98. #endif /* __VXWORKS__ || __vxworks || OS_VXWORKS */
  99. #if defined(LINUX) && (defined(HAVE_SENDFILE64) || defined(HAVE_LSEEK64)) && \
  100. ! defined(_LARGEFILE64_SOURCE)
  101. /* On Linux, special macro is required to enable definitions of some xxx64 functions */
  102. #define _LARGEFILE64_SOURCE 1
  103. #endif
  104. #ifdef HAVE_C11_GMTIME_S
  105. /* Special macro is required to enable C11 definition of gmtime_s() function */
  106. #define __STDC_WANT_LIB_EXT1__ 1
  107. #endif /* HAVE_C11_GMTIME_S */
  108. #if defined(MHD_FAVOR_FAST_CODE) && defined(MHD_FAVOR_SMALL_CODE)
  109. #error \
  110. MHD_FAVOR_FAST_CODE and MHD_FAVOR_SMALL_CODE are both defined. Cannot favor speed and size at the same time.
  111. #endif /* MHD_FAVOR_FAST_CODE && MHD_FAVOR_SMALL_CODE */
  112. /* Define MHD_FAVOR_FAST_CODE to force fast code path or
  113. define MHD_FAVOR_SMALL_CODE to choose compact code path */
  114. #if ! defined(MHD_FAVOR_FAST_CODE) && ! defined(MHD_FAVOR_SMALL_CODE)
  115. /* Try to detect user preferences */
  116. /* Defined by GCC and many compatible compilers */
  117. #if defined(__OPTIMIZE_SIZE__)
  118. #define MHD_FAVOR_SMALL_CODE 1
  119. #elif defined(__OPTIMIZE__)
  120. #define MHD_FAVOR_FAST_CODE 1
  121. #endif /* __OPTIMIZE__ */
  122. #endif /* !MHD_FAVOR_FAST_CODE && !MHD_FAVOR_SMALL_CODE */
  123. #if ! defined(MHD_FAVOR_FAST_CODE) && ! defined(MHD_FAVOR_SMALL_CODE)
  124. /* Use faster code by default */
  125. #define MHD_FAVOR_FAST_CODE 1
  126. #endif /* !MHD_FAVOR_FAST_CODE && !MHD_FAVOR_SMALL_CODE */
  127. #ifndef MHD_ASAN_ACTIVE
  128. #if (defined(__GNUC__) || defined(_MSC_VER)) && defined(__SANITIZE_ADDRESS__)
  129. #define MHD_ASAN_ACTIVE 1
  130. #elif defined(__has_feature)
  131. #if __has_feature (address_sanitizer)
  132. #define MHD_ASAN_ACTIVE 1
  133. #endif /* __has_feature(address_sanitizer) */
  134. #endif /* __has_feature */
  135. #endif /* MHD_ASAN_ACTIVE */
  136. #if defined(MHD_ASAN_ACTIVE) && defined(HAVE_SANITIZER_ASAN_INTERFACE_H) && \
  137. (defined(FUNC_PTRCOMPARE_CAST_WORKAROUND_WORKS) || \
  138. (defined(FUNC_ATTR_PTRCOMPARE_WORKS) && \
  139. defined(FUNC_ATTR_PTRSUBTRACT_WORKS)) || \
  140. defined(FUNC_ATTR_NOSANITIZE_WORKS))
  141. #ifndef MHD_ASAN_POISON_ACTIVE
  142. /* User ASAN poisoning could be used */
  143. #warning User memory poisoning is not active
  144. #endif /* ! MHD_ASAN_POISON_ACTIVE */
  145. #else /* ! (MHD_ASAN_ACTIVE && HAVE_SANITIZER_ASAN_INTERFACE_H &&
  146. (FUNC_ATTR_PTRCOMPARE_WORKS || FUNC_ATTR_NOSANITIZE_WORKS)) */
  147. #ifdef MHD_ASAN_POISON_ACTIVE
  148. #error User memory poisoning is active, but conditions are not suitable
  149. #endif /* MHD_ASAN_POISON_ACTIVE */
  150. #endif /* ! (MHD_ASAN_ACTIVE && HAVE_SANITIZER_ASAN_INTERFACE_H &&
  151. (FUNC_ATTR_PTRCOMPARE_WORKS || FUNC_ATTR_NOSANITIZE_WORKS)) */
  152. #ifndef _MSC_FULL_VER
  153. # define MHD_DATA_TRUNCATION_RUNTIME_CHECK_DISABLE_ /* empty */
  154. # define MHD_DATA_TRUNCATION_RUNTIME_CHECK_RESTORE_ /* empty */
  155. #else /* _MSC_FULL_VER */
  156. # define MHD_DATA_TRUNCATION_RUNTIME_CHECK_DISABLE_ \
  157. __pragma(runtime_checks("c", off))
  158. # define MHD_DATA_TRUNCATION_RUNTIME_CHECK_RESTORE_ \
  159. __pragma(runtime_checks("c", restore))
  160. #endif /* _MSC_FULL_VER */
  161. /**
  162. * Automatic string with the name of the current function
  163. */
  164. #if defined(HAVE___FUNC__)
  165. #define MHD_FUNC_ __func__
  166. #define MHD_HAVE_MHD_FUNC_ 1
  167. #elif defined(HAVE___FUNCTION__)
  168. #define MHD_FUNC_ __FUNCTION__
  169. #define MHD_HAVE_MHD_FUNC_ 1
  170. #elif defined(HAVE___PRETTY_FUNCTION__)
  171. #define MHD_FUNC_ __PRETTY_FUNCTION__
  172. #define MHD_HAVE_MHD_FUNC_ 1
  173. #else
  174. #define MHD_FUNC_ "**name unavailable**"
  175. #ifdef MHD_HAVE_MHD_FUNC_
  176. #undef MHD_HAVE_MHD_FUNC_
  177. #endif /* MHD_HAVE_MHD_FUNC_ */
  178. #endif
  179. /* Un-define some HAVE_DECL_* macro if they equal zero.
  180. This should allow safely use #ifdef in the code.
  181. Define HAS_DECL_* macros only if matching HAVE_DECL_* macro
  182. has non-zero value. Unlike HAVE_DECL_*, macros HAS_DECL_*
  183. cannot have zero value. */
  184. #ifdef HAVE_DECL__SC_NPROCESSORS_ONLN
  185. # if 0 == HAVE_DECL__SC_NPROCESSORS_ONLN
  186. # undef HAVE_DECL__SC_NPROCESSORS_ONLN
  187. # else /* 0 != HAVE_DECL__SC_NPROCESSORS_ONLN */
  188. # define HAS_DECL__SC_NPROCESSORS_ONLN 1
  189. # endif /* 0 != HAVE_DECL__SC_NPROCESSORS_ONLN */
  190. #endif /* HAVE_DECL__SC_NPROCESSORS_ONLN */
  191. #ifdef HAVE_DECL__SC_NPROCESSORS_CONF
  192. # if 0 == HAVE_DECL__SC_NPROCESSORS_CONF
  193. # undef HAVE_DECL__SC_NPROCESSORS_CONF
  194. # else /* 0 != HAVE_DECL__SC_NPROCESSORS_CONF */
  195. # define HAS_DECL__SC_NPROCESSORS_CONF 1
  196. # endif /* 0 != HAVE_DECL__SC_NPROCESSORS_CONF */
  197. #endif /* HAVE_DECL__SC_NPROCESSORS_CONF */
  198. #ifdef HAVE_DECL__SC_NPROC_ONLN
  199. # if 0 == HAVE_DECL__SC_NPROC_ONLN
  200. # undef HAVE_DECL__SC_NPROC_ONLN
  201. # else /* 0 != HAVE_DECL__SC_NPROC_ONLN */
  202. # define HAS_DECL__SC_NPROC_ONLN 1
  203. # endif /* 0 != HAVE_DECL__SC_NPROC_ONLN */
  204. #endif /* HAVE_DECL__SC_NPROC_ONLN */
  205. #ifdef HAVE_DECL__SC_CRAY_NCPU
  206. # if 0 == HAVE_DECL__SC_CRAY_NCPU
  207. # undef HAVE_DECL__SC_CRAY_NCPU
  208. # else /* 0 != HAVE_DECL__SC_CRAY_NCPU */
  209. # define HAS_DECL__SC_CRAY_NCPU 1
  210. # endif /* 0 != HAVE_DECL__SC_CRAY_NCPU */
  211. #endif /* HAVE_DECL__SC_CRAY_NCPU */
  212. #ifdef HAVE_DECL_CTL_HW
  213. # if 0 == HAVE_DECL_CTL_HW
  214. # undef HAVE_DECL_CTL_HW
  215. # else /* 0 != HAVE_DECL_CTL_HW */
  216. # define HAS_DECL_CTL_HW 1
  217. # endif /* 0 != HAVE_DECL_CTL_HW */
  218. #endif /* HAVE_DECL_CTL_HW */
  219. #ifdef HAVE_DECL_HW_NCPUONLINE
  220. # if 0 == HAVE_DECL_HW_NCPUONLINE
  221. # undef HAVE_DECL_HW_NCPUONLINE
  222. # else /* 0 != HAVE_DECL_HW_NCPUONLINE */
  223. # define HAS_DECL_HW_NCPUONLINE 1
  224. # endif /* 0 != HAVE_DECL_HW_NCPUONLINE */
  225. #endif /* HAVE_DECL_HW_NCPUONLINE */
  226. #ifdef HAVE_DECL_HW_AVAILCPU
  227. # if 0 == HAVE_DECL_HW_AVAILCPU
  228. # undef HAVE_DECL_HW_AVAILCPU
  229. # else /* 0 != HAVE_DECL_HW_AVAILCPU */
  230. # define HAS_DECL_HW_AVAILCPU 1
  231. # endif /* 0 != HAVE_DECL_HW_AVAILCPU */
  232. #endif /* HAVE_DECL_HW_AVAILCPU */
  233. #ifdef HAVE_DECL_HW_NCPU
  234. # if 0 == HAVE_DECL_HW_NCPU
  235. # undef HAVE_DECL_HW_NCPU
  236. # else /* 0 != HAVE_DECL_HW_NCPU */
  237. # define HAS_DECL_HW_NCPU 1
  238. # endif /* 0 != HAVE_DECL_HW_NCPU */
  239. #endif /* HAVE_DECL_HW_NCPU */
  240. #ifdef HAVE_DECL_CPU_SETSIZE
  241. # if 0 == HAVE_DECL_CPU_SETSIZE
  242. # undef HAVE_DECL_CPU_SETSIZE
  243. # else /* 0 != HAVE_DECL_CPU_SETSIZE */
  244. # define HAS_DECL_CPU_SETSIZE 1
  245. # endif /* 0 != HAVE_DECL_CPU_SETSIZE */
  246. #endif /* HAVE_DECL_CPU_SETSIZE */
  247. #ifndef MHD_DAUTH_DEF_TIMEOUT_
  248. # define MHD_DAUTH_DEF_TIMEOUT_ 90
  249. #endif /* ! MHD_DAUTH_DEF_TIMEOUT_ */
  250. #ifndef MHD_DAUTH_DEF_MAX_NC_
  251. # define MHD_DAUTH_DEF_MAX_NC_ 1000
  252. #endif /* ! MHD_DAUTH_DEF_MAX_NC_ */
  253. #endif /* MHD_OPTIONS_H */