Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/microhttpd.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002      This file is part of libmicrohttpd
0003      Copyright (C) 2006-2021 Christian Grothoff (and other contributing authors)
0004      Copyright (C) 2014-2023 Evgeny Grin (Karlson2k)
0005 
0006      This library is free software; you can redistribute it and/or
0007      modify it under the terms of the GNU Lesser General Public
0008      License as published by the Free Software Foundation; either
0009      version 2.1 of the License, or (at your option) any later version.
0010 
0011      This library is distributed in the hope that it will be useful,
0012      but WITHOUT ANY WARRANTY; without even the implied warranty of
0013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014      Lesser General Public License for more details.
0015 
0016      You should have received a copy of the GNU Lesser General Public
0017      License along with this library; if not, write to the Free Software
0018      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0019 */
0020 
0021 /**
0022  * @file microhttpd.h
0023  * @brief public interface to libmicrohttpd
0024  * @author Christian Grothoff
0025  * @author Karlson2k (Evgeny Grin)
0026  * @author Chris GauthierDickey
0027  *
0028  * All symbols defined in this header start with MHD.  MHD is a small
0029  * HTTP daemon library.  As such, it does not have any API for logging
0030  * errors (you can only enable or disable logging to stderr).  Also,
0031  * it may not support all of the HTTP features directly, where
0032  * applicable, portions of HTTP may have to be handled by clients of
0033  * the library.
0034  *
0035  * The library is supposed to handle everything that it must handle
0036  * (because the API would not allow clients to do this), such as basic
0037  * connection management; however, detailed interpretations of headers
0038  * -- such as range requests -- and HTTP methods are left to clients.
0039  * The library does understand HEAD and will only send the headers of
0040  * the response and not the body, even if the client supplied a body.
0041  * The library also understands headers that control connection
0042  * management (specifically, "Connection: close" and "Expect: 100
0043  * continue" are understood and handled automatically).
0044  *
0045  * MHD understands POST data and is able to decode certain formats
0046  * (at the moment only "application/x-www-form-urlencoded" and
0047  * "multipart/formdata"). Unsupported encodings and large POST
0048  * submissions may require the application to manually process
0049  * the stream, which is provided to the main application (and thus can be
0050  * processed, just not conveniently by MHD).
0051  *
0052  * The header file defines various constants used by the HTTP protocol.
0053  * This does not mean that MHD actually interprets all of these
0054  * values.  The provided constants are exported as a convenience
0055  * for users of the library.  MHD does not verify that transmitted
0056  * HTTP headers are part of the standard specification; users of the
0057  * library are free to define their own extensions of the HTTP
0058  * standard and use those with MHD.
0059  *
0060  * All functions are guaranteed to be completely reentrant and
0061  * thread-safe (with the exception of #MHD_set_connection_value,
0062  * which must only be used in a particular context).
0063  *
0064  *
0065  * @defgroup event event-loop control
0066  * MHD API to start and stop the HTTP server and manage the event loop.
0067  * @defgroup response generation of responses
0068  * MHD API used to generate responses.
0069  * @defgroup request handling of requests
0070  * MHD API used to access information about requests.
0071  * @defgroup authentication HTTP authentication
0072  * MHD API related to basic and digest HTTP authentication.
0073  * @defgroup logging logging
0074  * MHD API to mange logging and error handling
0075  * @defgroup specialized misc. specialized functions
0076  * This group includes functions that do not fit into any particular
0077  * category and that are rarely used.
0078  */
0079 
0080 #ifndef MHD_MICROHTTPD_H
0081 #define MHD_MICROHTTPD_H
0082 
0083 #ifdef __cplusplus
0084 extern "C"
0085 {
0086 #if 0                           /* keep Emacsens' auto-indent happy */
0087 }
0088 #endif
0089 #endif
0090 
0091 
0092 /**
0093  * Current version of the library in packed BCD form.
0094  * @note Version number components are coded as Simple Binary-Coded Decimal
0095  * (also called Natural BCD or BCD 8421). While they are hexadecimal numbers,
0096  * they are parsed as decimal numbers.
0097  * Example: 0x01093001 = 1.9.30-1.
0098  */
0099 #define MHD_VERSION 0x01000100
0100 
0101 /* If generic headers don't work on your platform, include headers
0102    which define 'va_list', 'size_t', 'ssize_t', 'intptr_t', 'off_t',
0103    'uint8_t', 'uint16_t', 'int32_t', 'uint32_t', 'int64_t', 'uint64_t',
0104    'struct sockaddr', 'socklen_t', 'fd_set' and "#define MHD_PLATFORM_H" before
0105    including "microhttpd.h". Then the following "standard"
0106    includes won't be used (which might be a good idea, especially
0107    on platforms where they do not exist).
0108    */
0109 #ifndef MHD_PLATFORM_H
0110 #if defined(_WIN32) && ! defined(__CYGWIN__) && \
0111   ! defined(_CRT_DECLARE_NONSTDC_NAMES)
0112 /* Declare POSIX-compatible names */
0113 #define _CRT_DECLARE_NONSTDC_NAMES 1
0114 #endif /* _WIN32 && ! __CYGWIN__ && ! _CRT_DECLARE_NONSTDC_NAMES */
0115 #include <stdarg.h>
0116 #include <stdint.h>
0117 #include <sys/types.h>
0118 #if ! defined(_WIN32) || defined(__CYGWIN__)
0119 #include <unistd.h>
0120 #include <sys/time.h>
0121 #include <sys/socket.h>
0122 #else  /* _WIN32 && ! __CYGWIN__ */
0123 #include <ws2tcpip.h>
0124 #if defined(_MSC_FULL_VER) && ! defined(_SSIZE_T_DEFINED)
0125 #define _SSIZE_T_DEFINED
0126 typedef intptr_t ssize_t;
0127 #endif /* !_SSIZE_T_DEFINED */
0128 #endif /* _WIN32 && ! __CYGWIN__ */
0129 #endif
0130 
0131 #if defined(__CYGWIN__) && ! defined(_SYS_TYPES_FD_SET)
0132 /* Do not define __USE_W32_SOCKETS under Cygwin! */
0133 #error Cygwin with winsock fd_set is not supported
0134 #endif
0135 
0136 #ifdef __has_attribute
0137 #if __has_attribute (flag_enum)
0138 #define _MHD_FLAGS_ENUM __attribute__((flag_enum))
0139 #endif /* flag_enum */
0140 #if __has_attribute (enum_extensibility)
0141 #define _MHD_FIXED_ENUM __attribute__((enum_extensibility (closed)))
0142 #endif /* enum_extensibility */
0143 #endif /* __has_attribute */
0144 
0145 #ifndef _MHD_FLAGS_ENUM
0146 #define _MHD_FLAGS_ENUM
0147 #endif /* _MHD_FLAGS_ENUM */
0148 #ifndef _MHD_FIXED_ENUM
0149 #define _MHD_FIXED_ENUM
0150 #endif /* _MHD_FIXED_ENUM */
0151 
0152 #define _MHD_FIXED_FLAGS_ENUM _MHD_FIXED_ENUM _MHD_FLAGS_ENUM
0153 
0154 /**
0155  * Operational results from MHD calls.
0156  */
0157 enum MHD_Result
0158 {
0159   /**
0160    * MHD result code for "NO".
0161    */
0162   MHD_NO = 0,
0163 
0164   /**
0165    * MHD result code for "YES".
0166    */
0167   MHD_YES = 1
0168 
0169 } _MHD_FIXED_ENUM;
0170 
0171 /**
0172  * Constant used to indicate unknown size (use when
0173  * creating a response).
0174  */
0175 #ifdef UINT64_MAX
0176 #define MHD_SIZE_UNKNOWN UINT64_MAX
0177 #else
0178 #define MHD_SIZE_UNKNOWN  ((uint64_t) -1LL)
0179 #endif
0180 
0181 #define MHD_CONTENT_READER_END_OF_STREAM ((ssize_t) -1)
0182 #define MHD_CONTENT_READER_END_WITH_ERROR ((ssize_t) -2)
0183 
0184 #ifndef _MHD_EXTERN
0185 #if defined(_WIN32) && defined(MHD_W32LIB)
0186 #define _MHD_EXTERN extern
0187 #elif defined(_WIN32) && defined(MHD_W32DLL)
0188 /* Define MHD_W32DLL when using MHD as W32 .DLL to speed up linker a little */
0189 #define _MHD_EXTERN __declspec(dllimport)
0190 #else
0191 #define _MHD_EXTERN extern
0192 #endif
0193 #endif
0194 
0195 #ifndef MHD_SOCKET_DEFINED
0196 /**
0197  * MHD_socket is type for socket FDs
0198  */
0199 #if ! defined(_WIN32) || defined(_SYS_TYPES_FD_SET)
0200 #define MHD_POSIX_SOCKETS 1
0201 typedef int MHD_socket;
0202 #define MHD_INVALID_SOCKET (-1)
0203 #else /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */
0204 #define MHD_WINSOCK_SOCKETS 1
0205 #include <winsock2.h>
0206 typedef SOCKET MHD_socket;
0207 #define MHD_INVALID_SOCKET (INVALID_SOCKET)
0208 #endif /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */
0209 #define MHD_SOCKET_DEFINED 1
0210 #endif /* MHD_SOCKET_DEFINED */
0211 
0212 /**
0213  * Define MHD_NO_DEPRECATION before including "microhttpd.h" to disable deprecation messages
0214  */
0215 #ifdef MHD_NO_DEPRECATION
0216 #define _MHD_DEPR_MACRO(msg)
0217 #define _MHD_NO_DEPR_IN_MACRO 1
0218 #define _MHD_DEPR_IN_MACRO(msg)
0219 #define _MHD_NO_DEPR_FUNC 1
0220 #define _MHD_DEPR_FUNC(msg)
0221 #endif /* MHD_NO_DEPRECATION */
0222 
0223 #ifndef _MHD_DEPR_MACRO
0224 #if defined(_MSC_FULL_VER) && _MSC_VER + 0 >= 1500
0225 /* VS 2008 or later */
0226 /* Stringify macros */
0227 #define _MHD_INSTRMACRO(a) #a
0228 #define _MHD_STRMACRO(a) _MHD_INSTRMACRO (a)
0229 /* deprecation message */
0230 #define _MHD_DEPR_MACRO(msg) \
0231   __pragma(message (__FILE__ "(" _MHD_STRMACRO ( __LINE__) "): warning: " msg))
0232 #define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO (msg)
0233 #elif defined(__clang__) || defined(__GNUC_PATCHLEVEL__)
0234 /* clang or GCC since 3.0 */
0235 #define _MHD_GCC_PRAG(x) _Pragma(#x)
0236 #if (defined(__clang__) && \
0237   (__clang_major__ + 0 >= 5 || \
0238    (! defined(__apple_build_version__) && \
0239   (__clang_major__ + 0  > 3 || \
0240    (__clang_major__ + 0 == 3 && __clang_minor__ >=  3))))) || \
0241   __GNUC__ + 0 > 4 || (__GNUC__ + 0 == 4 && __GNUC_MINOR__ + 0 >= 8)
0242 /* clang >= 3.3 (or XCode's clang >= 5.0) or
0243    GCC >= 4.8 */
0244 #define _MHD_DEPR_MACRO(msg) _MHD_GCC_PRAG (GCC warning msg)
0245 #define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO (msg)
0246 #else /* older clang or GCC */
0247 /* clang < 3.3, XCode's clang < 5.0, 3.0 <= GCC < 4.8 */
0248 #define _MHD_DEPR_MACRO(msg) _MHD_GCC_PRAG (message msg)
0249 #if (defined(__clang__) && \
0250   (__clang_major__ + 0  > 2 || \
0251    (__clang_major__ + 0 == 2 && __clang_minor__ >= 9)))  /* clang >= 2.9 */
0252 /* clang handles inline pragmas better than GCC */
0253 #define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO (msg)
0254 #endif /* clang >= 2.9 */
0255 #endif  /* older clang or GCC */
0256 /* #elif defined(SOMEMACRO) */ /* add compiler-specific macros here if required */
0257 #endif /* clang || GCC >= 3.0 */
0258 #endif /* !_MHD_DEPR_MACRO */
0259 
0260 #ifndef _MHD_DEPR_MACRO
0261 #define _MHD_DEPR_MACRO(msg)
0262 #endif /* !_MHD_DEPR_MACRO */
0263 
0264 #ifndef _MHD_DEPR_IN_MACRO
0265 #define _MHD_NO_DEPR_IN_MACRO 1
0266 #define _MHD_DEPR_IN_MACRO(msg)
0267 #endif /* !_MHD_DEPR_IN_MACRO */
0268 
0269 #ifndef _MHD_DEPR_FUNC
0270 #if defined(_MSC_FULL_VER) && _MSC_VER + 0 >= 1400
0271 /* VS 2005 or later */
0272 #define _MHD_DEPR_FUNC(msg) __declspec(deprecated (msg))
0273 #elif defined(_MSC_FULL_VER) && _MSC_VER + 0 >= 1310
0274 /* VS .NET 2003 deprecation does not support custom messages */
0275 #define _MHD_DEPR_FUNC(msg) __declspec(deprecated)
0276 #elif (__GNUC__ + 0 >= 5) || (defined(__clang__) && \
0277   (__clang_major__ + 0 > 2 || \
0278    (__clang_major__ + 0 == 2 && __clang_minor__ >=  9)))
0279 /* GCC >= 5.0 or clang >= 2.9 */
0280 #define _MHD_DEPR_FUNC(msg) __attribute__((deprecated (msg)))
0281 #elif defined(__clang__) || __GNUC__ + 0 > 3 || \
0282   (__GNUC__ + 0 == 3 && __GNUC_MINOR__ + 0 >= 1)
0283 /* 3.1 <= GCC < 5.0 or clang < 2.9 */
0284 /* old GCC-style deprecation does not support custom messages */
0285 #define _MHD_DEPR_FUNC(msg) __attribute__((__deprecated__))
0286 /* #elif defined(SOMEMACRO) */ /* add compiler-specific macros here if required */
0287 #endif /* clang < 2.9 || GCC >= 3.1 */
0288 #endif /* !_MHD_DEPR_FUNC */
0289 
0290 #ifndef _MHD_DEPR_FUNC
0291 #define _MHD_NO_DEPR_FUNC 1
0292 #define _MHD_DEPR_FUNC(msg)
0293 #endif /* !_MHD_DEPR_FUNC */
0294 
0295 /**
0296  * Not all architectures and `printf()`'s support the `long long` type.
0297  * This gives the ability to replace `long long` with just a `long`,
0298  * standard `int` or a `short`.
0299  */
0300 #ifndef MHD_LONG_LONG
0301 /**
0302  * @deprecated use #MHD_UNSIGNED_LONG_LONG instead!
0303  */
0304 #define MHD_LONG_LONG long long
0305 #define MHD_UNSIGNED_LONG_LONG unsigned long long
0306 #else /* MHD_LONG_LONG */
0307 _MHD_DEPR_MACRO ( \
0308   "Macro MHD_LONG_LONG is deprecated, use MHD_UNSIGNED_LONG_LONG")
0309 #endif
0310 /**
0311  * Format string for printing a variable of type #MHD_LONG_LONG.
0312  * You should only redefine this if you also define #MHD_LONG_LONG.
0313  */
0314 #ifndef MHD_LONG_LONG_PRINTF
0315 /**
0316  * @deprecated use #MHD_UNSIGNED_LONG_LONG_PRINTF instead!
0317  */
0318 #define MHD_LONG_LONG_PRINTF "ll"
0319 #define MHD_UNSIGNED_LONG_LONG_PRINTF "%llu"
0320 #else /* MHD_LONG_LONG_PRINTF */
0321 _MHD_DEPR_MACRO ( \
0322   "Macro MHD_LONG_LONG_PRINTF is deprecated, use MHD_UNSIGNED_LONG_LONG_PRINTF")
0323 #endif
0324 
0325 
0326 /**
0327  * @defgroup httpcode HTTP response codes.
0328  * These are the status codes defined for HTTP responses.
0329  * See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
0330  * Registry export date: 2023-09-29
0331  * @{
0332  */
0333 
0334 /* 100 "Continue".            RFC9110, Section 15.2.1. */
0335 #define MHD_HTTP_CONTINUE                    100
0336 /* 101 "Switching Protocols". RFC9110, Section 15.2.2. */
0337 #define MHD_HTTP_SWITCHING_PROTOCOLS         101
0338 /* 102 "Processing".          RFC2518. */
0339 #define MHD_HTTP_PROCESSING                  102
0340 /* 103 "Early Hints".         RFC8297. */
0341 #define MHD_HTTP_EARLY_HINTS                 103
0342 
0343 /* 200 "OK".                  RFC9110, Section 15.3.1. */
0344 #define MHD_HTTP_OK                          200
0345 /* 201 "Created".             RFC9110, Section 15.3.2. */
0346 #define MHD_HTTP_CREATED                     201
0347 /* 202 "Accepted".            RFC9110, Section 15.3.3. */
0348 #define MHD_HTTP_ACCEPTED                    202
0349 /* 203 "Non-Authoritative Information". RFC9110, Section 15.3.4. */
0350 #define MHD_HTTP_NON_AUTHORITATIVE_INFORMATION 203
0351 /* 204 "No Content".          RFC9110, Section 15.3.5. */
0352 #define MHD_HTTP_NO_CONTENT                  204
0353 /* 205 "Reset Content".       RFC9110, Section 15.3.6. */
0354 #define MHD_HTTP_RESET_CONTENT               205
0355 /* 206 "Partial Content".     RFC9110, Section 15.3.7. */
0356 #define MHD_HTTP_PARTIAL_CONTENT             206
0357 /* 207 "Multi-Status".        RFC4918. */
0358 #define MHD_HTTP_MULTI_STATUS                207
0359 /* 208 "Already Reported".    RFC5842. */
0360 #define MHD_HTTP_ALREADY_REPORTED            208
0361 
0362 /* 226 "IM Used".             RFC3229. */
0363 #define MHD_HTTP_IM_USED                     226
0364 
0365 /* 300 "Multiple Choices".    RFC9110, Section 15.4.1. */
0366 #define MHD_HTTP_MULTIPLE_CHOICES            300
0367 /* 301 "Moved Permanently".   RFC9110, Section 15.4.2. */
0368 #define MHD_HTTP_MOVED_PERMANENTLY           301
0369 /* 302 "Found".               RFC9110, Section 15.4.3. */
0370 #define MHD_HTTP_FOUND                       302
0371 /* 303 "See Other".           RFC9110, Section 15.4.4. */
0372 #define MHD_HTTP_SEE_OTHER                   303
0373 /* 304 "Not Modified".        RFC9110, Section 15.4.5. */
0374 #define MHD_HTTP_NOT_MODIFIED                304
0375 /* 305 "Use Proxy".           RFC9110, Section 15.4.6. */
0376 #define MHD_HTTP_USE_PROXY                   305
0377 /* 306 "Switch Proxy".        Not used! RFC9110, Section 15.4.7. */
0378 #define MHD_HTTP_SWITCH_PROXY                306
0379 /* 307 "Temporary Redirect".  RFC9110, Section 15.4.8. */
0380 #define MHD_HTTP_TEMPORARY_REDIRECT          307
0381 /* 308 "Permanent Redirect".  RFC9110, Section 15.4.9. */
0382 #define MHD_HTTP_PERMANENT_REDIRECT          308
0383 
0384 /* 400 "Bad Request".         RFC9110, Section 15.5.1. */
0385 #define MHD_HTTP_BAD_REQUEST                 400
0386 /* 401 "Unauthorized".        RFC9110, Section 15.5.2. */
0387 #define MHD_HTTP_UNAUTHORIZED                401
0388 /* 402 "Payment Required".    RFC9110, Section 15.5.3. */
0389 #define MHD_HTTP_PAYMENT_REQUIRED            402
0390 /* 403 "Forbidden".           RFC9110, Section 15.5.4. */
0391 #define MHD_HTTP_FORBIDDEN                   403
0392 /* 404 "Not Found".           RFC9110, Section 15.5.5. */
0393 #define MHD_HTTP_NOT_FOUND                   404
0394 /* 405 "Method Not Allowed".  RFC9110, Section 15.5.6. */
0395 #define MHD_HTTP_METHOD_NOT_ALLOWED          405
0396 /* 406 "Not Acceptable".      RFC9110, Section 15.5.7. */
0397 #define MHD_HTTP_NOT_ACCEPTABLE              406
0398 /* 407 "Proxy Authentication Required". RFC9110, Section 15.5.8. */
0399 #define MHD_HTTP_PROXY_AUTHENTICATION_REQUIRED 407
0400 /* 408 "Request Timeout".     RFC9110, Section 15.5.9. */
0401 #define MHD_HTTP_REQUEST_TIMEOUT             408
0402 /* 409 "Conflict".            RFC9110, Section 15.5.10. */
0403 #define MHD_HTTP_CONFLICT                    409
0404 /* 410 "Gone".                RFC9110, Section 15.5.11. */
0405 #define MHD_HTTP_GONE                        410
0406 /* 411 "Length Required".     RFC9110, Section 15.5.12. */
0407 #define MHD_HTTP_LENGTH_REQUIRED             411
0408 /* 412 "Precondition Failed". RFC9110, Section 15.5.13. */
0409 #define MHD_HTTP_PRECONDITION_FAILED         412
0410 /* 413 "Content Too Large".   RFC9110, Section 15.5.14. */
0411 #define MHD_HTTP_CONTENT_TOO_LARGE           413
0412 /* 414 "URI Too Long".        RFC9110, Section 15.5.15. */
0413 #define MHD_HTTP_URI_TOO_LONG                414
0414 /* 415 "Unsupported Media Type". RFC9110, Section 15.5.16. */
0415 #define MHD_HTTP_UNSUPPORTED_MEDIA_TYPE      415
0416 /* 416 "Range Not Satisfiable". RFC9110, Section 15.5.17. */
0417 #define MHD_HTTP_RANGE_NOT_SATISFIABLE       416
0418 /* 417 "Expectation Failed".  RFC9110, Section 15.5.18. */
0419 #define MHD_HTTP_EXPECTATION_FAILED          417
0420 
0421 
0422 /* 421 "Misdirected Request". RFC9110, Section 15.5.20. */
0423 #define MHD_HTTP_MISDIRECTED_REQUEST         421
0424 /* 422 "Unprocessable Content". RFC9110, Section 15.5.21. */
0425 #define MHD_HTTP_UNPROCESSABLE_CONTENT       422
0426 /* 423 "Locked".              RFC4918. */
0427 #define MHD_HTTP_LOCKED                      423
0428 /* 424 "Failed Dependency".   RFC4918. */
0429 #define MHD_HTTP_FAILED_DEPENDENCY           424
0430 /* 425 "Too Early".           RFC8470. */
0431 #define MHD_HTTP_TOO_EARLY                   425
0432 /* 426 "Upgrade Required".    RFC9110, Section 15.5.22. */
0433 #define MHD_HTTP_UPGRADE_REQUIRED            426
0434 
0435 /* 428 "Precondition Required". RFC6585. */
0436 #define MHD_HTTP_PRECONDITION_REQUIRED       428
0437 /* 429 "Too Many Requests".   RFC6585. */
0438 #define MHD_HTTP_TOO_MANY_REQUESTS           429
0439 
0440 /* 431 "Request Header Fields Too Large". RFC6585. */
0441 #define MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE 431
0442 
0443 /* 451 "Unavailable For Legal Reasons". RFC7725. */
0444 #define MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS 451
0445 
0446 /* 500 "Internal Server Error". RFC9110, Section 15.6.1. */
0447 #define MHD_HTTP_INTERNAL_SERVER_ERROR       500
0448 /* 501 "Not Implemented".     RFC9110, Section 15.6.2. */
0449 #define MHD_HTTP_NOT_IMPLEMENTED             501
0450 /* 502 "Bad Gateway".         RFC9110, Section 15.6.3. */
0451 #define MHD_HTTP_BAD_GATEWAY                 502
0452 /* 503 "Service Unavailable". RFC9110, Section 15.6.4. */
0453 #define MHD_HTTP_SERVICE_UNAVAILABLE         503
0454 /* 504 "Gateway Timeout".     RFC9110, Section 15.6.5. */
0455 #define MHD_HTTP_GATEWAY_TIMEOUT             504
0456 /* 505 "HTTP Version Not Supported". RFC9110, Section 15.6.6. */
0457 #define MHD_HTTP_HTTP_VERSION_NOT_SUPPORTED  505
0458 /* 506 "Variant Also Negotiates". RFC2295. */
0459 #define MHD_HTTP_VARIANT_ALSO_NEGOTIATES     506
0460 /* 507 "Insufficient Storage". RFC4918. */
0461 #define MHD_HTTP_INSUFFICIENT_STORAGE        507
0462 /* 508 "Loop Detected".       RFC5842. */
0463 #define MHD_HTTP_LOOP_DETECTED               508
0464 
0465 /* 510 "Not Extended".        (OBSOLETED) RFC2774; status-change-http-experiments-to-historic. */
0466 #define MHD_HTTP_NOT_EXTENDED                510
0467 /* 511 "Network Authentication Required". RFC6585. */
0468 #define MHD_HTTP_NETWORK_AUTHENTICATION_REQUIRED 511
0469 
0470 
0471 /* Not registered non-standard codes */
0472 /* 449 "Reply With".          MS IIS extension. */
0473 #define MHD_HTTP_RETRY_WITH                  449
0474 
0475 /* 450 "Blocked by Windows Parental Controls". MS extension. */
0476 #define MHD_HTTP_BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS 450
0477 
0478 /* 509 "Bandwidth Limit Exceeded". Apache extension. */
0479 #define MHD_HTTP_BANDWIDTH_LIMIT_EXCEEDED    509
0480 
0481 /* Deprecated names and codes */
0482 /** @deprecated */
0483 #define MHD_HTTP_METHOD_NOT_ACCEPTABLE _MHD_DEPR_IN_MACRO (\
0484  "Value MHD_HTTP_METHOD_NOT_ACCEPTABLE is deprecated, use MHD_HTTP_NOT_ACCEPTABLE" \
0485  ) 406
0486 
0487 /** @deprecated */
0488 #define MHD_HTTP_REQUEST_ENTITY_TOO_LARGE _MHD_DEPR_IN_MACRO (\
0489  "Value MHD_HTTP_REQUEST_ENTITY_TOO_LARGE is deprecated, use MHD_HTTP_CONTENT_TOO_LARGE"\
0490  ) 413
0491 
0492 /** @deprecated */
0493 #define MHD_HTTP_PAYLOAD_TOO_LARGE _MHD_DEPR_IN_MACRO (\
0494   "Value MHD_HTTP_PAYLOAD_TOO_LARGE is deprecated use MHD_HTTP_CONTENT_TOO_LARGE" \
0495   ) 413
0496 
0497 /** @deprecated */
0498 #define MHD_HTTP_REQUEST_URI_TOO_LONG _MHD_DEPR_IN_MACRO (\
0499   "Value MHD_HTTP_REQUEST_URI_TOO_LONG is deprecated, use MHD_HTTP_URI_TOO_LONG" \
0500   ) 414
0501 
0502 /** @deprecated */
0503 #define MHD_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE _MHD_DEPR_IN_MACRO (\
0504  "Value MHD_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE is deprecated, use MHD_HTTP_RANGE_NOT_SATISFIABLE" \
0505  ) 416
0506 
0507 /** @deprecated */
0508 #define MHD_HTTP_UNPROCESSABLE_ENTITY _MHD_DEPR_IN_MACRO (\
0509  "Value MHD_HTTP_UNPROCESSABLE_ENTITY is deprecated, use MHD_HTTP_UNPROCESSABLE_CONTENT" \
0510  ) 422
0511 
0512 /** @deprecated */
0513 #define MHD_HTTP_UNORDERED_COLLECTION _MHD_DEPR_IN_MACRO (\
0514   "Value MHD_HTTP_UNORDERED_COLLECTION is deprecated as it was removed from RFC" \
0515   ) 425
0516 
0517 /** @deprecated */
0518 #define MHD_HTTP_NO_RESPONSE _MHD_DEPR_IN_MACRO (\
0519  "Value MHD_HTTP_NO_RESPONSE is deprecated as it is nginx internal code for logs only"\
0520  ) 444
0521 
0522 
0523 /** @} */ /* end of group httpcode */
0524 
0525 /**
0526  * Returns the string reason phrase for a response code.
0527  *
0528  * If message string is not available for a status code,
0529  * "Unknown" string will be returned.
0530  */
0531 _MHD_EXTERN const char *
0532 MHD_get_reason_phrase_for (unsigned int code);
0533 
0534 
0535 /**
0536  * Returns the length of the string reason phrase for a response code.
0537  *
0538  * If message string is not available for a status code,
0539  * 0 is returned.
0540  */
0541 _MHD_EXTERN size_t
0542 MHD_get_reason_phrase_len_for (unsigned int code);
0543 
0544 /**
0545  * Flag to be or-ed with MHD_HTTP status code for
0546  * SHOUTcast.  This will cause the response to begin
0547  * with the SHOUTcast "ICY" line instead of "HTTP/1.x".
0548  * @ingroup specialized
0549  */
0550 #define MHD_ICY_FLAG ((uint32_t) (((uint32_t) 1) << 31))
0551 
0552 /**
0553  * @defgroup headers HTTP headers
0554  * The standard headers found in HTTP requests and responses.
0555  * See: https://www.iana.org/assignments/http-fields/http-fields.xhtml
0556  * Registry export date: 2023-10-02
0557  * @{
0558  */
0559 
0560 /* Main HTTP headers. */
0561 /* Permanent.     RFC9110, Section 12.5.1: HTTP Semantics */
0562 #define MHD_HTTP_HEADER_ACCEPT       "Accept"
0563 /* Deprecated.    RFC9110, Section 12.5.2: HTTP Semantics */
0564 #define MHD_HTTP_HEADER_ACCEPT_CHARSET "Accept-Charset"
0565 /* Permanent.     RFC9110, Section 12.5.3: HTTP Semantics */
0566 #define MHD_HTTP_HEADER_ACCEPT_ENCODING "Accept-Encoding"
0567 /* Permanent.     RFC9110, Section 12.5.4: HTTP Semantics */
0568 #define MHD_HTTP_HEADER_ACCEPT_LANGUAGE "Accept-Language"
0569 /* Permanent.     RFC9110, Section 14.3: HTTP Semantics */
0570 #define MHD_HTTP_HEADER_ACCEPT_RANGES "Accept-Ranges"
0571 /* Permanent.     RFC9111, Section 5.1: HTTP Caching */
0572 #define MHD_HTTP_HEADER_AGE          "Age"
0573 /* Permanent.     RFC9110, Section 10.2.1: HTTP Semantics */
0574 #define MHD_HTTP_HEADER_ALLOW        "Allow"
0575 /* Permanent.     RFC9110, Section 11.6.3: HTTP Semantics */
0576 #define MHD_HTTP_HEADER_AUTHENTICATION_INFO "Authentication-Info"
0577 /* Permanent.     RFC9110, Section 11.6.2: HTTP Semantics */
0578 #define MHD_HTTP_HEADER_AUTHORIZATION "Authorization"
0579 /* Permanent.     RFC9111, Section 5.2 */
0580 #define MHD_HTTP_HEADER_CACHE_CONTROL "Cache-Control"
0581 /* Permanent.     RFC9112, Section 9.6: HTTP/1.1 */
0582 #define MHD_HTTP_HEADER_CLOSE        "Close"
0583 /* Permanent.     RFC9110, Section 7.6.1: HTTP Semantics */
0584 #define MHD_HTTP_HEADER_CONNECTION   "Connection"
0585 /* Permanent.     RFC9110, Section 8.4: HTTP Semantics */
0586 #define MHD_HTTP_HEADER_CONTENT_ENCODING "Content-Encoding"
0587 /* Permanent.     RFC9110, Section 8.5: HTTP Semantics */
0588 #define MHD_HTTP_HEADER_CONTENT_LANGUAGE "Content-Language"
0589 /* Permanent.     RFC9110, Section 8.6: HTTP Semantics */
0590 #define MHD_HTTP_HEADER_CONTENT_LENGTH "Content-Length"
0591 /* Permanent.     RFC9110, Section 8.7: HTTP Semantics */
0592 #define MHD_HTTP_HEADER_CONTENT_LOCATION "Content-Location"
0593 /* Permanent.     RFC9110, Section 14.4: HTTP Semantics */
0594 #define MHD_HTTP_HEADER_CONTENT_RANGE "Content-Range"
0595 /* Permanent.     RFC9110, Section 8.3: HTTP Semantics */
0596 #define MHD_HTTP_HEADER_CONTENT_TYPE "Content-Type"
0597 /* Permanent.     RFC9110, Section 6.6.1: HTTP Semantics */
0598 #define MHD_HTTP_HEADER_DATE         "Date"
0599 /* Permanent.     RFC9110, Section 8.8.3: HTTP Semantics */
0600 #define MHD_HTTP_HEADER_ETAG         "ETag"
0601 /* Permanent.     RFC9110, Section 10.1.1: HTTP Semantics */
0602 #define MHD_HTTP_HEADER_EXPECT       "Expect"
0603 /* Permanent.     RFC9111, Section 5.3: HTTP Caching */
0604 #define MHD_HTTP_HEADER_EXPIRES      "Expires"
0605 /* Permanent.     RFC9110, Section 10.1.2: HTTP Semantics */
0606 #define MHD_HTTP_HEADER_FROM         "From"
0607 /* Permanent.     RFC9110, Section 7.2: HTTP Semantics */
0608 #define MHD_HTTP_HEADER_HOST         "Host"
0609 /* Permanent.     RFC9110, Section 13.1.1: HTTP Semantics */
0610 #define MHD_HTTP_HEADER_IF_MATCH     "If-Match"
0611 /* Permanent.     RFC9110, Section 13.1.3: HTTP Semantics */
0612 #define MHD_HTTP_HEADER_IF_MODIFIED_SINCE "If-Modified-Since"
0613 /* Permanent.     RFC9110, Section 13.1.2: HTTP Semantics */
0614 #define MHD_HTTP_HEADER_IF_NONE_MATCH "If-None-Match"
0615 /* Permanent.     RFC9110, Section 13.1.5: HTTP Semantics */
0616 #define MHD_HTTP_HEADER_IF_RANGE     "If-Range"
0617 /* Permanent.     RFC9110, Section 13.1.4: HTTP Semantics */
0618 #define MHD_HTTP_HEADER_IF_UNMODIFIED_SINCE "If-Unmodified-Since"
0619 /* Permanent.     RFC9110, Section 8.8.2: HTTP Semantics */
0620 #define MHD_HTTP_HEADER_LAST_MODIFIED "Last-Modified"
0621 /* Permanent.     RFC9110, Section 10.2.2: HTTP Semantics */
0622 #define MHD_HTTP_HEADER_LOCATION     "Location"
0623 /* Permanent.     RFC9110, Section 7.6.2: HTTP Semantics */
0624 #define MHD_HTTP_HEADER_MAX_FORWARDS "Max-Forwards"
0625 /* Permanent.     RFC9112, Appendix B.1: HTTP/1.1 */
0626 #define MHD_HTTP_HEADER_MIME_VERSION "MIME-Version"
0627 /* Deprecated.    RFC9111, Section 5.4: HTTP Caching */
0628 #define MHD_HTTP_HEADER_PRAGMA       "Pragma"
0629 /* Permanent.     RFC9110, Section 11.7.1: HTTP Semantics */
0630 #define MHD_HTTP_HEADER_PROXY_AUTHENTICATE "Proxy-Authenticate"
0631 /* Permanent.     RFC9110, Section 11.7.3: HTTP Semantics */
0632 #define MHD_HTTP_HEADER_PROXY_AUTHENTICATION_INFO "Proxy-Authentication-Info"
0633 /* Permanent.     RFC9110, Section 11.7.2: HTTP Semantics */
0634 #define MHD_HTTP_HEADER_PROXY_AUTHORIZATION "Proxy-Authorization"
0635 /* Permanent.     RFC9110, Section 14.2: HTTP Semantics */
0636 #define MHD_HTTP_HEADER_RANGE        "Range"
0637 /* Permanent.     RFC9110, Section 10.1.3: HTTP Semantics */
0638 #define MHD_HTTP_HEADER_REFERER      "Referer"
0639 /* Permanent.     RFC9110, Section 10.2.3: HTTP Semantics */
0640 #define MHD_HTTP_HEADER_RETRY_AFTER  "Retry-After"
0641 /* Permanent.     RFC9110, Section 10.2.4: HTTP Semantics */
0642 #define MHD_HTTP_HEADER_SERVER       "Server"
0643 /* Permanent.     RFC9110, Section 10.1.4: HTTP Semantics */
0644 #define MHD_HTTP_HEADER_TE           "TE"
0645 /* Permanent.     RFC9110, Section 6.6.2: HTTP Semantics */
0646 #define MHD_HTTP_HEADER_TRAILER      "Trailer"
0647 /* Permanent.     RFC9112, Section 6.1: HTTP Semantics */
0648 #define MHD_HTTP_HEADER_TRANSFER_ENCODING "Transfer-Encoding"
0649 /* Permanent.     RFC9110, Section 7.8: HTTP Semantics */
0650 #define MHD_HTTP_HEADER_UPGRADE      "Upgrade"
0651 /* Permanent.     RFC9110, Section 10.1.5: HTTP Semantics */
0652 #define MHD_HTTP_HEADER_USER_AGENT   "User-Agent"
0653 /* Permanent.     RFC9110, Section 12.5.5: HTTP Semantics */
0654 #define MHD_HTTP_HEADER_VARY         "Vary"
0655 /* Permanent.     RFC9110, Section 7.6.3: HTTP Semantics */
0656 #define MHD_HTTP_HEADER_VIA          "Via"
0657 /* Permanent.     RFC9110, Section 11.6.1: HTTP Semantics */
0658 #define MHD_HTTP_HEADER_WWW_AUTHENTICATE "WWW-Authenticate"
0659 /* Permanent.     RFC9110, Section 12.5.5: HTTP Semantics */
0660 #define MHD_HTTP_HEADER_ASTERISK     "*"
0661 
0662 /* Additional HTTP headers. */
0663 /* Permanent.     RFC 3229: Delta encoding in HTTP */
0664 #define MHD_HTTP_HEADER_A_IM         "A-IM"
0665 /* Permanent.     RFC 2324: Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0) */
0666 #define MHD_HTTP_HEADER_ACCEPT_ADDITIONS "Accept-Additions"
0667 /* Permanent.     RFC 8942, Section 3.1: HTTP Client Hints */
0668 #define MHD_HTTP_HEADER_ACCEPT_CH    "Accept-CH"
0669 /* Permanent.     RFC 7089: HTTP Framework for Time-Based Access to Resource States -- Memento */
0670 #define MHD_HTTP_HEADER_ACCEPT_DATETIME "Accept-Datetime"
0671 /* Permanent.     RFC 2295: Transparent Content Negotiation in HTTP */
0672 #define MHD_HTTP_HEADER_ACCEPT_FEATURES "Accept-Features"
0673 /* Permanent.     RFC 5789: PATCH Method for HTTP */
0674 #define MHD_HTTP_HEADER_ACCEPT_PATCH "Accept-Patch"
0675 /* Permanent.     Linked Data Platform 1.0 */
0676 #define MHD_HTTP_HEADER_ACCEPT_POST  "Accept-Post"
0677 /* Permanent.     RFC-ietf-httpbis-message-signatures-19, Section 5.1: HTTP Message Signatures */
0678 #define MHD_HTTP_HEADER_ACCEPT_SIGNATURE "Accept-Signature"
0679 /* Permanent.     Fetch */
0680 #define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS \
0681   "Access-Control-Allow-Credentials"
0682 /* Permanent.     Fetch */
0683 #define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_HEADERS \
0684   "Access-Control-Allow-Headers"
0685 /* Permanent.     Fetch */
0686 #define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_METHODS \
0687   "Access-Control-Allow-Methods"
0688 /* Permanent.     Fetch */
0689 #define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN \
0690   "Access-Control-Allow-Origin"
0691 /* Permanent.     Fetch */
0692 #define MHD_HTTP_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS \
0693   "Access-Control-Expose-Headers"
0694 /* Permanent.     Fetch */
0695 #define MHD_HTTP_HEADER_ACCESS_CONTROL_MAX_AGE "Access-Control-Max-Age"
0696 /* Permanent.     Fetch */
0697 #define MHD_HTTP_HEADER_ACCESS_CONTROL_REQUEST_HEADERS \
0698   "Access-Control-Request-Headers"
0699 /* Permanent.     Fetch */
0700 #define MHD_HTTP_HEADER_ACCESS_CONTROL_REQUEST_METHOD \
0701   "Access-Control-Request-Method"
0702 /* Permanent.     RFC 7639, Section 2: The ALPN HTTP Header Field */
0703 #define MHD_HTTP_HEADER_ALPN         "ALPN"
0704 /* Permanent.     RFC 7838: HTTP Alternative Services */
0705 #define MHD_HTTP_HEADER_ALT_SVC      "Alt-Svc"
0706 /* Permanent.     RFC 7838: HTTP Alternative Services */
0707 #define MHD_HTTP_HEADER_ALT_USED     "Alt-Used"
0708 /* Permanent.     RFC 2295: Transparent Content Negotiation in HTTP */
0709 #define MHD_HTTP_HEADER_ALTERNATES   "Alternates"
0710 /* Permanent.     RFC 4437: Web Distributed Authoring and Versioning (WebDAV) Redirect Reference Resources */
0711 #define MHD_HTTP_HEADER_APPLY_TO_REDIRECT_REF "Apply-To-Redirect-Ref"
0712 /* Permanent.     RFC 8053, Section 4: HTTP Authentication Extensions for Interactive Clients */
0713 #define MHD_HTTP_HEADER_AUTHENTICATION_CONTROL "Authentication-Control"
0714 /* Permanent.     RFC9211: The Cache-Status HTTP Response Header Field */
0715 #define MHD_HTTP_HEADER_CACHE_STATUS "Cache-Status"
0716 /* Permanent.     RFC 8607, Section 5.1: Calendaring Extensions to WebDAV (CalDAV): Managed Attachments */
0717 #define MHD_HTTP_HEADER_CAL_MANAGED_ID "Cal-Managed-ID"
0718 /* Permanent.     RFC 7809, Section 7.1: Calendaring Extensions to WebDAV (CalDAV): Time Zones by Reference */
0719 #define MHD_HTTP_HEADER_CALDAV_TIMEZONES "CalDAV-Timezones"
0720 /* Permanent.     RFC9297 */
0721 #define MHD_HTTP_HEADER_CAPSULE_PROTOCOL "Capsule-Protocol"
0722 /* Permanent.     RFC9213: Targeted HTTP Cache Control */
0723 #define MHD_HTTP_HEADER_CDN_CACHE_CONTROL "CDN-Cache-Control"
0724 /* Permanent.     RFC 8586: Loop Detection in Content Delivery Networks (CDNs) */
0725 #define MHD_HTTP_HEADER_CDN_LOOP     "CDN-Loop"
0726 /* Permanent.     RFC 8739, Section 3.3: Support for Short-Term, Automatically Renewed (STAR) Certificates in the Automated Certificate Management Environment (ACME) */
0727 #define MHD_HTTP_HEADER_CERT_NOT_AFTER "Cert-Not-After"
0728 /* Permanent.     RFC 8739, Section 3.3: Support for Short-Term, Automatically Renewed (STAR) Certificates in the Automated Certificate Management Environment (ACME) */
0729 #define MHD_HTTP_HEADER_CERT_NOT_BEFORE "Cert-Not-Before"
0730 /* Permanent.     Clear Site Data */
0731 #define MHD_HTTP_HEADER_CLEAR_SITE_DATA "Clear-Site-Data"
0732 /* Permanent.     RFC9440, Section 2: Client-Cert HTTP Header Field */
0733 #define MHD_HTTP_HEADER_CLIENT_CERT  "Client-Cert"
0734 /* Permanent.     RFC9440, Section 2: Client-Cert HTTP Header Field */
0735 #define MHD_HTTP_HEADER_CLIENT_CERT_CHAIN "Client-Cert-Chain"
0736 /* Permanent.     RFC-ietf-httpbis-digest-headers-13, Section 2: Digest Fields */
0737 #define MHD_HTTP_HEADER_CONTENT_DIGEST "Content-Digest"
0738 /* Permanent.     RFC 6266: Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP) */
0739 #define MHD_HTTP_HEADER_CONTENT_DISPOSITION "Content-Disposition"
0740 /* Permanent.     The HTTP Distribution and Replication Protocol */
0741 #define MHD_HTTP_HEADER_CONTENT_ID   "Content-ID"
0742 /* Permanent.     Content Security Policy Level 3 */
0743 #define MHD_HTTP_HEADER_CONTENT_SECURITY_POLICY "Content-Security-Policy"
0744 /* Permanent.     Content Security Policy Level 3 */
0745 #define MHD_HTTP_HEADER_CONTENT_SECURITY_POLICY_REPORT_ONLY \
0746   "Content-Security-Policy-Report-Only"
0747 /* Permanent.     RFC 6265: HTTP State Management Mechanism */
0748 #define MHD_HTTP_HEADER_COOKIE       "Cookie"
0749 /* Permanent.     HTML */
0750 #define MHD_HTTP_HEADER_CROSS_ORIGIN_EMBEDDER_POLICY \
0751   "Cross-Origin-Embedder-Policy"
0752 /* Permanent.     HTML */
0753 #define MHD_HTTP_HEADER_CROSS_ORIGIN_EMBEDDER_POLICY_REPORT_ONLY \
0754   "Cross-Origin-Embedder-Policy-Report-Only"
0755 /* Permanent.     HTML */
0756 #define MHD_HTTP_HEADER_CROSS_ORIGIN_OPENER_POLICY "Cross-Origin-Opener-Policy"
0757 /* Permanent.     HTML */
0758 #define MHD_HTTP_HEADER_CROSS_ORIGIN_OPENER_POLICY_REPORT_ONLY \
0759   "Cross-Origin-Opener-Policy-Report-Only"
0760 /* Permanent.     Fetch */
0761 #define MHD_HTTP_HEADER_CROSS_ORIGIN_RESOURCE_POLICY \
0762   "Cross-Origin-Resource-Policy"
0763 /* Permanent.     RFC 5323: Web Distributed Authoring and Versioning (WebDAV) SEARCH */
0764 #define MHD_HTTP_HEADER_DASL         "DASL"
0765 /* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
0766 #define MHD_HTTP_HEADER_DAV          "DAV"
0767 /* Permanent.     RFC 3229: Delta encoding in HTTP */
0768 #define MHD_HTTP_HEADER_DELTA_BASE   "Delta-Base"
0769 /* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
0770 #define MHD_HTTP_HEADER_DEPTH        "Depth"
0771 /* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
0772 #define MHD_HTTP_HEADER_DESTINATION  "Destination"
0773 /* Permanent.     The HTTP Distribution and Replication Protocol */
0774 #define MHD_HTTP_HEADER_DIFFERENTIAL_ID "Differential-ID"
0775 /* Permanent.     RFC9449: OAuth 2.0 Demonstrating Proof of Possession (DPoP) */
0776 #define MHD_HTTP_HEADER_DPOP         "DPoP"
0777 /* Permanent.     RFC9449: OAuth 2.0 Demonstrating Proof of Possession (DPoP) */
0778 #define MHD_HTTP_HEADER_DPOP_NONCE   "DPoP-Nonce"
0779 /* Permanent.     RFC 8470: Using Early Data in HTTP */
0780 #define MHD_HTTP_HEADER_EARLY_DATA   "Early-Data"
0781 /* Permanent.     RFC9163: Expect-CT Extension for HTTP */
0782 #define MHD_HTTP_HEADER_EXPECT_CT    "Expect-CT"
0783 /* Permanent.     RFC 7239: Forwarded HTTP Extension */
0784 #define MHD_HTTP_HEADER_FORWARDED    "Forwarded"
0785 /* Permanent.     RFC 7486, Section 6.1.1: HTTP Origin-Bound Authentication (HOBA) */
0786 #define MHD_HTTP_HEADER_HOBAREG      "Hobareg"
0787 /* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
0788 #define MHD_HTTP_HEADER_IF           "If"
0789 /* Permanent.      RFC 6338: Scheduling Extensions to CalDAV */
0790 #define MHD_HTTP_HEADER_IF_SCHEDULE_TAG_MATCH "If-Schedule-Tag-Match"
0791 /* Permanent.     RFC 3229: Delta encoding in HTTP */
0792 #define MHD_HTTP_HEADER_IM           "IM"
0793 /* Permanent.     RFC 8473: Token Binding over HTTP */
0794 #define MHD_HTTP_HEADER_INCLUDE_REFERRED_TOKEN_BINDING_ID \
0795   "Include-Referred-Token-Binding-ID"
0796 /* Permanent.     RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */
0797 #define MHD_HTTP_HEADER_KEEP_ALIVE   "Keep-Alive"
0798 /* Permanent.     RFC 3253: Versioning Extensions to WebDAV: (Web Distributed Authoring and Versioning) */
0799 #define MHD_HTTP_HEADER_LABEL        "Label"
0800 /* Permanent.     HTML */
0801 #define MHD_HTTP_HEADER_LAST_EVENT_ID "Last-Event-ID"
0802 /* Permanent.     RFC 8288: Web Linking */
0803 #define MHD_HTTP_HEADER_LINK         "Link"
0804 /* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
0805 #define MHD_HTTP_HEADER_LOCK_TOKEN   "Lock-Token"
0806 /* Permanent.     RFC 7089: HTTP Framework for Time-Based Access to Resource States -- Memento */
0807 #define MHD_HTTP_HEADER_MEMENTO_DATETIME "Memento-Datetime"
0808 /* Permanent.     RFC 2227: Simple Hit-Metering and Usage-Limiting for HTTP */
0809 #define MHD_HTTP_HEADER_METER        "Meter"
0810 /* Permanent.     RFC 2295: Transparent Content Negotiation in HTTP */
0811 #define MHD_HTTP_HEADER_NEGOTIATE    "Negotiate"
0812 /* Permanent.     Network Error Logging */
0813 #define MHD_HTTP_HEADER_NEL          "NEL"
0814 /* Permanent.     OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */
0815 #define MHD_HTTP_HEADER_ODATA_ENTITYID "OData-EntityId"
0816 /* Permanent.     OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */
0817 #define MHD_HTTP_HEADER_ODATA_ISOLATION "OData-Isolation"
0818 /* Permanent.     OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */
0819 #define MHD_HTTP_HEADER_ODATA_MAXVERSION "OData-MaxVersion"
0820 /* Permanent.     OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */
0821 #define MHD_HTTP_HEADER_ODATA_VERSION "OData-Version"
0822 /* Permanent.     RFC 8053, Section 3: HTTP Authentication Extensions for Interactive Clients */
0823 #define MHD_HTTP_HEADER_OPTIONAL_WWW_AUTHENTICATE "Optional-WWW-Authenticate"
0824 /* Permanent.     RFC 3648: Web Distributed Authoring and Versioning (WebDAV) Ordered Collections Protocol */
0825 #define MHD_HTTP_HEADER_ORDERING_TYPE "Ordering-Type"
0826 /* Permanent.     RFC 6454: The Web Origin Concept */
0827 #define MHD_HTTP_HEADER_ORIGIN       "Origin"
0828 /* Permanent.     HTML */
0829 #define MHD_HTTP_HEADER_ORIGIN_AGENT_CLUSTER "Origin-Agent-Cluster"
0830 /* Permanent.     RFC 8613, Section 11.1: Object Security for Constrained RESTful Environments (OSCORE) */
0831 #define MHD_HTTP_HEADER_OSCORE       "OSCORE"
0832 /* Permanent.     OASIS Project Specification 01; OASIS; Chet_Ensign */
0833 #define MHD_HTTP_HEADER_OSLC_CORE_VERSION "OSLC-Core-Version"
0834 /* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
0835 #define MHD_HTTP_HEADER_OVERWRITE    "Overwrite"
0836 /* Permanent.     HTML */
0837 #define MHD_HTTP_HEADER_PING_FROM    "Ping-From"
0838 /* Permanent.     HTML */
0839 #define MHD_HTTP_HEADER_PING_TO      "Ping-To"
0840 /* Permanent.     RFC 3648: Web Distributed Authoring and Versioning (WebDAV) Ordered Collections Protocol */
0841 #define MHD_HTTP_HEADER_POSITION     "Position"
0842 /* Permanent.     RFC 7240: Prefer Header for HTTP */
0843 #define MHD_HTTP_HEADER_PREFER       "Prefer"
0844 /* Permanent.     RFC 7240: Prefer Header for HTTP */
0845 #define MHD_HTTP_HEADER_PREFERENCE_APPLIED "Preference-Applied"
0846 /* Permanent.     RFC9218: Extensible Prioritization Scheme for HTTP */
0847 #define MHD_HTTP_HEADER_PRIORITY     "Priority"
0848 /* Permanent.     RFC9209: The Proxy-Status HTTP Response Header Field */
0849 #define MHD_HTTP_HEADER_PROXY_STATUS "Proxy-Status"
0850 /* Permanent.     RFC 7469: Public Key Pinning Extension for HTTP */
0851 #define MHD_HTTP_HEADER_PUBLIC_KEY_PINS "Public-Key-Pins"
0852 /* Permanent.     RFC 7469: Public Key Pinning Extension for HTTP */
0853 #define MHD_HTTP_HEADER_PUBLIC_KEY_PINS_REPORT_ONLY \
0854   "Public-Key-Pins-Report-Only"
0855 /* Permanent.     RFC 4437: Web Distributed Authoring and Versioning (WebDAV) Redirect Reference Resources */
0856 #define MHD_HTTP_HEADER_REDIRECT_REF "Redirect-Ref"
0857 /* Permanent.     HTML */
0858 #define MHD_HTTP_HEADER_REFRESH      "Refresh"
0859 /* Permanent.     RFC 8555, Section 6.5.1: Automatic Certificate Management Environment (ACME) */
0860 #define MHD_HTTP_HEADER_REPLAY_NONCE "Replay-Nonce"
0861 /* Permanent.     RFC-ietf-httpbis-digest-headers-13, Section 3: Digest Fields */
0862 #define MHD_HTTP_HEADER_REPR_DIGEST  "Repr-Digest"
0863 /* Permanent.     RFC 6638: Scheduling Extensions to CalDAV */
0864 #define MHD_HTTP_HEADER_SCHEDULE_REPLY "Schedule-Reply"
0865 /* Permanent.     RFC 6338: Scheduling Extensions to CalDAV */
0866 #define MHD_HTTP_HEADER_SCHEDULE_TAG "Schedule-Tag"
0867 /* Permanent.     Fetch */
0868 #define MHD_HTTP_HEADER_SEC_PURPOSE  "Sec-Purpose"
0869 /* Permanent.     RFC 8473: Token Binding over HTTP */
0870 #define MHD_HTTP_HEADER_SEC_TOKEN_BINDING "Sec-Token-Binding"
0871 /* Permanent.     RFC 6455: The WebSocket Protocol */
0872 #define MHD_HTTP_HEADER_SEC_WEBSOCKET_ACCEPT "Sec-WebSocket-Accept"
0873 /* Permanent.     RFC 6455: The WebSocket Protocol */
0874 #define MHD_HTTP_HEADER_SEC_WEBSOCKET_EXTENSIONS "Sec-WebSocket-Extensions"
0875 /* Permanent.     RFC 6455: The WebSocket Protocol */
0876 #define MHD_HTTP_HEADER_SEC_WEBSOCKET_KEY "Sec-WebSocket-Key"
0877 /* Permanent.     RFC 6455: The WebSocket Protocol */
0878 #define MHD_HTTP_HEADER_SEC_WEBSOCKET_PROTOCOL "Sec-WebSocket-Protocol"
0879 /* Permanent.     RFC 6455: The WebSocket Protocol */
0880 #define MHD_HTTP_HEADER_SEC_WEBSOCKET_VERSION "Sec-WebSocket-Version"
0881 /* Permanent.     Server Timing */
0882 #define MHD_HTTP_HEADER_SERVER_TIMING "Server-Timing"
0883 /* Permanent.     RFC 6265: HTTP State Management Mechanism */
0884 #define MHD_HTTP_HEADER_SET_COOKIE   "Set-Cookie"
0885 /* Permanent.     RFC-ietf-httpbis-message-signatures-19, Section 4.2: HTTP Message Signatures */
0886 #define MHD_HTTP_HEADER_SIGNATURE    "Signature"
0887 /* Permanent.     RFC-ietf-httpbis-message-signatures-19, Section 4.1: HTTP Message Signatures */
0888 #define MHD_HTTP_HEADER_SIGNATURE_INPUT "Signature-Input"
0889 /* Permanent.     RFC 5023: The Atom Publishing Protocol */
0890 #define MHD_HTTP_HEADER_SLUG         "SLUG"
0891 /* Permanent.     Simple Object Access Protocol (SOAP) 1.1 */
0892 #define MHD_HTTP_HEADER_SOAPACTION   "SoapAction"
0893 /* Permanent.     RFC 2518: HTTP Extensions for Distributed Authoring -- WEBDAV */
0894 #define MHD_HTTP_HEADER_STATUS_URI   "Status-URI"
0895 /* Permanent.     RFC 6797: HTTP Strict Transport Security (HSTS) */
0896 #define MHD_HTTP_HEADER_STRICT_TRANSPORT_SECURITY "Strict-Transport-Security"
0897 /* Permanent.     RFC 8594: The Sunset HTTP Header Field */
0898 #define MHD_HTTP_HEADER_SUNSET       "Sunset"
0899 /* Permanent.     Edge Architecture Specification */
0900 #define MHD_HTTP_HEADER_SURROGATE_CAPABILITY "Surrogate-Capability"
0901 /* Permanent.     Edge Architecture Specification */
0902 #define MHD_HTTP_HEADER_SURROGATE_CONTROL "Surrogate-Control"
0903 /* Permanent.     RFC 2295: Transparent Content Negotiation in HTTP */
0904 #define MHD_HTTP_HEADER_TCN          "TCN"
0905 /* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
0906 #define MHD_HTTP_HEADER_TIMEOUT      "Timeout"
0907 /* Permanent.     RFC 8030, Section 5.4: Generic Event Delivery Using HTTP Push */
0908 #define MHD_HTTP_HEADER_TOPIC        "Topic"
0909 /* Permanent.     Trace Context */
0910 #define MHD_HTTP_HEADER_TRACEPARENT  "Traceparent"
0911 /* Permanent.     Trace Context */
0912 #define MHD_HTTP_HEADER_TRACESTATE   "Tracestate"
0913 /* Permanent.     RFC 8030, Section 5.2: Generic Event Delivery Using HTTP Push */
0914 #define MHD_HTTP_HEADER_TTL          "TTL"
0915 /* Permanent.     RFC 8030, Section 5.3: Generic Event Delivery Using HTTP Push */
0916 #define MHD_HTTP_HEADER_URGENCY      "Urgency"
0917 /* Permanent.     RFC 2295: Transparent Content Negotiation in HTTP */
0918 #define MHD_HTTP_HEADER_VARIANT_VARY "Variant-Vary"
0919 /* Permanent.     RFC-ietf-httpbis-digest-headers-13, Section 4: Digest Fields */
0920 #define MHD_HTTP_HEADER_WANT_CONTENT_DIGEST "Want-Content-Digest"
0921 /* Permanent.     RFC-ietf-httpbis-digest-headers-13, Section 4: Digest Fields */
0922 #define MHD_HTTP_HEADER_WANT_REPR_DIGEST "Want-Repr-Digest"
0923 /* Permanent.     Fetch */
0924 #define MHD_HTTP_HEADER_X_CONTENT_TYPE_OPTIONS "X-Content-Type-Options"
0925 /* Permanent.     HTML */
0926 #define MHD_HTTP_HEADER_X_FRAME_OPTIONS "X-Frame-Options"
0927 /* Provisional.   AMP-Cache-Transform HTTP request header */
0928 #define MHD_HTTP_HEADER_AMP_CACHE_TRANSFORM "AMP-Cache-Transform"
0929 /* Provisional.   OSLC Configuration Management Version 1.0. Part 3: Configuration Specification */
0930 #define MHD_HTTP_HEADER_CONFIGURATION_CONTEXT "Configuration-Context"
0931 /* Provisional.   RFC 6017: Electronic Data Interchange - Internet Integration (EDIINT) Features Header Field */
0932 #define MHD_HTTP_HEADER_EDIINT_FEATURES "EDIINT-Features"
0933 /* Provisional.   OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */
0934 #define MHD_HTTP_HEADER_ISOLATION    "Isolation"
0935 /* Provisional.   Permissions Policy */
0936 #define MHD_HTTP_HEADER_PERMISSIONS_POLICY "Permissions-Policy"
0937 /* Provisional.   Repeatable Requests Version 1.0; OASIS; Chet_Ensign */
0938 #define MHD_HTTP_HEADER_REPEATABILITY_CLIENT_ID "Repeatability-Client-ID"
0939 /* Provisional.   Repeatable Requests Version 1.0; OASIS; Chet_Ensign */
0940 #define MHD_HTTP_HEADER_REPEATABILITY_FIRST_SENT "Repeatability-First-Sent"
0941 /* Provisional.   Repeatable Requests Version 1.0; OASIS; Chet_Ensign */
0942 #define MHD_HTTP_HEADER_REPEATABILITY_REQUEST_ID "Repeatability-Request-ID"
0943 /* Provisional.   Repeatable Requests Version 1.0; OASIS; Chet_Ensign */
0944 #define MHD_HTTP_HEADER_REPEATABILITY_RESULT "Repeatability-Result"
0945 /* Provisional.   Reporting API */
0946 #define MHD_HTTP_HEADER_REPORTING_ENDPOINTS "Reporting-Endpoints"
0947 /* Provisional.   Global Privacy Control (GPC) */
0948 #define MHD_HTTP_HEADER_SEC_GPC      "Sec-GPC"
0949 /* Provisional.   Resource Timing Level 1 */
0950 #define MHD_HTTP_HEADER_TIMING_ALLOW_ORIGIN "Timing-Allow-Origin"
0951 /* Deprecated.    PEP - an Extension Mechanism for HTTP; status-change-http-experiments-to-historic */
0952 #define MHD_HTTP_HEADER_C_PEP_INFO   "C-PEP-Info"
0953 /* Deprecated.    White Paper: Joint Electronic Payment Initiative */
0954 #define MHD_HTTP_HEADER_PROTOCOL_INFO "Protocol-Info"
0955 /* Deprecated.    White Paper: Joint Electronic Payment Initiative */
0956 #define MHD_HTTP_HEADER_PROTOCOL_QUERY "Protocol-Query"
0957 /* Obsoleted.     Access Control for Cross-site Requests */
0958 #define MHD_HTTP_HEADER_ACCESS_CONTROL "Access-Control"
0959 /* Obsoleted.     RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
0960 #define MHD_HTTP_HEADER_C_EXT        "C-Ext"
0961 /* Obsoleted.     RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
0962 #define MHD_HTTP_HEADER_C_MAN        "C-Man"
0963 /* Obsoleted.     RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
0964 #define MHD_HTTP_HEADER_C_OPT        "C-Opt"
0965 /* Obsoleted.     PEP - an Extension Mechanism for HTTP; status-change-http-experiments-to-historic */
0966 #define MHD_HTTP_HEADER_C_PEP        "C-PEP"
0967 /* Obsoleted.     RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1; RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1 */
0968 #define MHD_HTTP_HEADER_CONTENT_BASE "Content-Base"
0969 /* Obsoleted.     RFC 2616, Section 14.15: Hypertext Transfer Protocol -- HTTP/1.1; RFC 7231, Appendix B: Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content */
0970 #define MHD_HTTP_HEADER_CONTENT_MD5  "Content-MD5"
0971 /* Obsoleted.     HTML 4.01 Specification */
0972 #define MHD_HTTP_HEADER_CONTENT_SCRIPT_TYPE "Content-Script-Type"
0973 /* Obsoleted.     HTML 4.01 Specification */
0974 #define MHD_HTTP_HEADER_CONTENT_STYLE_TYPE "Content-Style-Type"
0975 /* Obsoleted.     RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */
0976 #define MHD_HTTP_HEADER_CONTENT_VERSION "Content-Version"
0977 /* Obsoleted.     RFC 2965: HTTP State Management Mechanism; RFC 6265: HTTP State Management Mechanism */
0978 #define MHD_HTTP_HEADER_COOKIE2      "Cookie2"
0979 /* Obsoleted.     HTML 4.01 Specification */
0980 #define MHD_HTTP_HEADER_DEFAULT_STYLE "Default-Style"
0981 /* Obsoleted.     RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */
0982 #define MHD_HTTP_HEADER_DERIVED_FROM "Derived-From"
0983 /* Obsoleted.     RFC 3230: Instance Digests in HTTP; RFC-ietf-httpbis-digest-headers-13, Section 1.3: Digest Fields */
0984 #define MHD_HTTP_HEADER_DIGEST       "Digest"
0985 /* Obsoleted.     RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
0986 #define MHD_HTTP_HEADER_EXT          "Ext"
0987 /* Obsoleted.     Implementation of OPS Over HTTP */
0988 #define MHD_HTTP_HEADER_GETPROFILE   "GetProfile"
0989 /* Obsoleted.     RFC 7540, Section 3.2.1: Hypertext Transfer Protocol Version 2 (HTTP/2) */
0990 #define MHD_HTTP_HEADER_HTTP2_SETTINGS "HTTP2-Settings"
0991 /* Obsoleted.     RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
0992 #define MHD_HTTP_HEADER_MAN          "Man"
0993 /* Obsoleted.     Access Control for Cross-site Requests */
0994 #define MHD_HTTP_HEADER_METHOD_CHECK "Method-Check"
0995 /* Obsoleted.     Access Control for Cross-site Requests */
0996 #define MHD_HTTP_HEADER_METHOD_CHECK_EXPIRES "Method-Check-Expires"
0997 /* Obsoleted.     RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
0998 #define MHD_HTTP_HEADER_OPT          "Opt"
0999 /* Obsoleted.     The Platform for Privacy Preferences 1.0 (P3P1.0) Specification */
1000 #define MHD_HTTP_HEADER_P3P          "P3P"
1001 /* Obsoleted.     PEP - an Extension Mechanism for HTTP */
1002 #define MHD_HTTP_HEADER_PEP          "PEP"
1003 /* Obsoleted.     PEP - an Extension Mechanism for HTTP */
1004 #define MHD_HTTP_HEADER_PEP_INFO     "Pep-Info"
1005 /* Obsoleted.     PICS Label Distribution Label Syntax and Communication Protocols */
1006 #define MHD_HTTP_HEADER_PICS_LABEL   "PICS-Label"
1007 /* Obsoleted.     Implementation of OPS Over HTTP */
1008 #define MHD_HTTP_HEADER_PROFILEOBJECT "ProfileObject"
1009 /* Obsoleted.     PICS Label Distribution Label Syntax and Communication Protocols */
1010 #define MHD_HTTP_HEADER_PROTOCOL     "Protocol"
1011 /* Obsoleted.     PICS Label Distribution Label Syntax and Communication Protocols */
1012 #define MHD_HTTP_HEADER_PROTOCOL_REQUEST "Protocol-Request"
1013 /* Obsoleted.     Notification for Proxy Caches */
1014 #define MHD_HTTP_HEADER_PROXY_FEATURES "Proxy-Features"
1015 /* Obsoleted.     Notification for Proxy Caches */
1016 #define MHD_HTTP_HEADER_PROXY_INSTRUCTION "Proxy-Instruction"
1017 /* Obsoleted.     RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */
1018 #define MHD_HTTP_HEADER_PUBLIC       "Public"
1019 /* Obsoleted.     Access Control for Cross-site Requests */
1020 #define MHD_HTTP_HEADER_REFERER_ROOT "Referer-Root"
1021 /* Obsoleted.     RFC 2310: The Safe Response Header Field; status-change-http-experiments-to-historic */
1022 #define MHD_HTTP_HEADER_SAFE         "Safe"
1023 /* Obsoleted.     RFC 2660: The Secure HyperText Transfer Protocol; status-change-http-experiments-to-historic */
1024 #define MHD_HTTP_HEADER_SECURITY_SCHEME "Security-Scheme"
1025 /* Obsoleted.     RFC 2965: HTTP State Management Mechanism; RFC 6265: HTTP State Management Mechanism */
1026 #define MHD_HTTP_HEADER_SET_COOKIE2  "Set-Cookie2"
1027 /* Obsoleted.     Implementation of OPS Over HTTP */
1028 #define MHD_HTTP_HEADER_SETPROFILE   "SetProfile"
1029 /* Obsoleted.     RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */
1030 #define MHD_HTTP_HEADER_URI          "URI"
1031 /* Obsoleted.     RFC 3230: Instance Digests in HTTP; RFC-ietf-httpbis-digest-headers-13, Section 1.3: Digest Fields */
1032 #define MHD_HTTP_HEADER_WANT_DIGEST  "Want-Digest"
1033 /* Obsoleted.     RFC9111, Section 5.5: HTTP Caching */
1034 #define MHD_HTTP_HEADER_WARNING      "Warning"
1035 
1036 /* Headers removed from the registry. Do not use! */
1037 /* Obsoleted.     RFC4229 */
1038 #define MHD_HTTP_HEADER_COMPLIANCE   "Compliance"
1039 /* Obsoleted.     RFC4229 */
1040 #define MHD_HTTP_HEADER_CONTENT_TRANSFER_ENCODING "Content-Transfer-Encoding"
1041 /* Obsoleted.     RFC4229 */
1042 #define MHD_HTTP_HEADER_COST         "Cost"
1043 /* Obsoleted.     RFC4229 */
1044 #define MHD_HTTP_HEADER_MESSAGE_ID   "Message-ID"
1045 /* Obsoleted.     RFC4229 */
1046 #define MHD_HTTP_HEADER_NON_COMPLIANCE "Non-Compliance"
1047 /* Obsoleted.     RFC4229 */
1048 #define MHD_HTTP_HEADER_OPTIONAL     "Optional"
1049 /* Obsoleted.     RFC4229 */
1050 #define MHD_HTTP_HEADER_RESOLUTION_HINT "Resolution-Hint"
1051 /* Obsoleted.     RFC4229 */
1052 #define MHD_HTTP_HEADER_RESOLVER_LOCATION "Resolver-Location"
1053 /* Obsoleted.     RFC4229 */
1054 #define MHD_HTTP_HEADER_SUBOK        "SubOK"
1055 /* Obsoleted.     RFC4229 */
1056 #define MHD_HTTP_HEADER_SUBST        "Subst"
1057 /* Obsoleted.     RFC4229 */
1058 #define MHD_HTTP_HEADER_TITLE        "Title"
1059 /* Obsoleted.     RFC4229 */
1060 #define MHD_HTTP_HEADER_UA_COLOR     "UA-Color"
1061 /* Obsoleted.     RFC4229 */
1062 #define MHD_HTTP_HEADER_UA_MEDIA     "UA-Media"
1063 /* Obsoleted.     RFC4229 */
1064 #define MHD_HTTP_HEADER_UA_PIXELS    "UA-Pixels"
1065 /* Obsoleted.     RFC4229 */
1066 #define MHD_HTTP_HEADER_UA_RESOLUTION "UA-Resolution"
1067 /* Obsoleted.     RFC4229 */
1068 #define MHD_HTTP_HEADER_UA_WINDOWPIXELS "UA-Windowpixels"
1069 /* Obsoleted.     RFC4229 */
1070 #define MHD_HTTP_HEADER_VERSION      "Version"
1071 /* Obsoleted.     W3C Mobile Web Best Practices Working Group */
1072 #define MHD_HTTP_HEADER_X_DEVICE_ACCEPT "X-Device-Accept"
1073 /* Obsoleted.     W3C Mobile Web Best Practices Working Group */
1074 #define MHD_HTTP_HEADER_X_DEVICE_ACCEPT_CHARSET "X-Device-Accept-Charset"
1075 /* Obsoleted.     W3C Mobile Web Best Practices Working Group */
1076 #define MHD_HTTP_HEADER_X_DEVICE_ACCEPT_ENCODING "X-Device-Accept-Encoding"
1077 /* Obsoleted.     W3C Mobile Web Best Practices Working Group */
1078 #define MHD_HTTP_HEADER_X_DEVICE_ACCEPT_LANGUAGE "X-Device-Accept-Language"
1079 /* Obsoleted.     W3C Mobile Web Best Practices Working Group */
1080 #define MHD_HTTP_HEADER_X_DEVICE_USER_AGENT "X-Device-User-Agent"
1081 
1082 /** @} */ /* end of group headers */
1083 
1084 /**
1085  * @defgroup versions HTTP versions
1086  * These strings should be used to match against the first line of the
1087  * HTTP header.
1088  * @{
1089  */
1090 #define MHD_HTTP_VERSION_1_0 "HTTP/1.0"
1091 #define MHD_HTTP_VERSION_1_1 "HTTP/1.1"
1092 
1093 /** @} */ /* end of group versions */
1094 
1095 /**
1096  * @defgroup methods HTTP methods
1097  * HTTP methods (as strings).
1098  * See: https://www.iana.org/assignments/http-methods/http-methods.xml
1099  * Registry export date: 2023-10-02
1100  * @{
1101  */
1102 
1103 /* Main HTTP methods. */
1104 /* Safe.     Idempotent.     RFC9110, Section 9.3.1. */
1105 #define MHD_HTTP_METHOD_GET      "GET"
1106 /* Safe.     Idempotent.     RFC9110, Section 9.3.2. */
1107 #define MHD_HTTP_METHOD_HEAD     "HEAD"
1108 /* Not safe. Not idempotent. RFC9110, Section 9.3.3. */
1109 #define MHD_HTTP_METHOD_POST     "POST"
1110 /* Not safe. Idempotent.     RFC9110, Section 9.3.4. */
1111 #define MHD_HTTP_METHOD_PUT      "PUT"
1112 /* Not safe. Idempotent.     RFC9110, Section 9.3.5. */
1113 #define MHD_HTTP_METHOD_DELETE   "DELETE"
1114 /* Not safe. Not idempotent. RFC9110, Section 9.3.6. */
1115 #define MHD_HTTP_METHOD_CONNECT  "CONNECT"
1116 /* Safe.     Idempotent.     RFC9110, Section 9.3.7. */
1117 #define MHD_HTTP_METHOD_OPTIONS  "OPTIONS"
1118 /* Safe.     Idempotent.     RFC9110, Section 9.3.8. */
1119 #define MHD_HTTP_METHOD_TRACE    "TRACE"
1120 
1121 /* Additional HTTP methods. */
1122 /* Not safe. Idempotent.     RFC3744, Section 8.1. */
1123 #define MHD_HTTP_METHOD_ACL            "ACL"
1124 /* Not safe. Idempotent.     RFC3253, Section 12.6. */
1125 #define MHD_HTTP_METHOD_BASELINE_CONTROL "BASELINE-CONTROL"
1126 /* Not safe. Idempotent.     RFC5842, Section 4. */
1127 #define MHD_HTTP_METHOD_BIND           "BIND"
1128 /* Not safe. Idempotent.     RFC3253, Section 4.4, Section 9.4. */
1129 #define MHD_HTTP_METHOD_CHECKIN        "CHECKIN"
1130 /* Not safe. Idempotent.     RFC3253, Section 4.3, Section 8.8. */
1131 #define MHD_HTTP_METHOD_CHECKOUT       "CHECKOUT"
1132 /* Not safe. Idempotent.     RFC4918, Section 9.8. */
1133 #define MHD_HTTP_METHOD_COPY           "COPY"
1134 /* Not safe. Idempotent.     RFC3253, Section 8.2. */
1135 #define MHD_HTTP_METHOD_LABEL          "LABEL"
1136 /* Not safe. Idempotent.     RFC2068, Section 19.6.1.2. */
1137 #define MHD_HTTP_METHOD_LINK           "LINK"
1138 /* Not safe. Not idempotent. RFC4918, Section 9.10. */
1139 #define MHD_HTTP_METHOD_LOCK           "LOCK"
1140 /* Not safe. Idempotent.     RFC3253, Section 11.2. */
1141 #define MHD_HTTP_METHOD_MERGE          "MERGE"
1142 /* Not safe. Idempotent.     RFC3253, Section 13.5. */
1143 #define MHD_HTTP_METHOD_MKACTIVITY     "MKACTIVITY"
1144 /* Not safe. Idempotent.     RFC4791, Section 5.3.1; RFC8144, Section 2.3. */
1145 #define MHD_HTTP_METHOD_MKCALENDAR     "MKCALENDAR"
1146 /* Not safe. Idempotent.     RFC4918, Section 9.3; RFC5689, Section 3; RFC8144, Section 2.3. */
1147 #define MHD_HTTP_METHOD_MKCOL          "MKCOL"
1148 /* Not safe. Idempotent.     RFC4437, Section 6. */
1149 #define MHD_HTTP_METHOD_MKREDIRECTREF  "MKREDIRECTREF"
1150 /* Not safe. Idempotent.     RFC3253, Section 6.3. */
1151 #define MHD_HTTP_METHOD_MKWORKSPACE    "MKWORKSPACE"
1152 /* Not safe. Idempotent.     RFC4918, Section 9.9. */
1153 #define MHD_HTTP_METHOD_MOVE           "MOVE"
1154 /* Not safe. Idempotent.     RFC3648, Section 7. */
1155 #define MHD_HTTP_METHOD_ORDERPATCH     "ORDERPATCH"
1156 /* Not safe. Not idempotent. RFC5789, Section 2. */
1157 #define MHD_HTTP_METHOD_PATCH          "PATCH"
1158 /* Safe.     Idempotent.     RFC9113, Section 3.4. */
1159 #define MHD_HTTP_METHOD_PRI            "PRI"
1160 /* Safe.     Idempotent.     RFC4918, Section 9.1; RFC8144, Section 2.1. */
1161 #define MHD_HTTP_METHOD_PROPFIND       "PROPFIND"
1162 /* Not safe. Idempotent.     RFC4918, Section 9.2; RFC8144, Section 2.2. */
1163 #define MHD_HTTP_METHOD_PROPPATCH      "PROPPATCH"
1164 /* Not safe. Idempotent.     RFC5842, Section 6. */
1165 #define MHD_HTTP_METHOD_REBIND         "REBIND"
1166 /* Safe.     Idempotent.     RFC3253, Section 3.6; RFC8144, Section 2.1. */
1167 #define MHD_HTTP_METHOD_REPORT         "REPORT"
1168 /* Safe.     Idempotent.     RFC5323, Section 2. */
1169 #define MHD_HTTP_METHOD_SEARCH         "SEARCH"
1170 /* Not safe. Idempotent.     RFC5842, Section 5. */
1171 #define MHD_HTTP_METHOD_UNBIND         "UNBIND"
1172 /* Not safe. Idempotent.     RFC3253, Section 4.5. */
1173 #define MHD_HTTP_METHOD_UNCHECKOUT     "UNCHECKOUT"
1174 /* Not safe. Idempotent.     RFC2068, Section 19.6.1.3. */
1175 #define MHD_HTTP_METHOD_UNLINK         "UNLINK"
1176 /* Not safe. Idempotent.     RFC4918, Section 9.11. */
1177 #define MHD_HTTP_METHOD_UNLOCK         "UNLOCK"
1178 /* Not safe. Idempotent.     RFC3253, Section 7.1. */
1179 #define MHD_HTTP_METHOD_UPDATE         "UPDATE"
1180 /* Not safe. Idempotent.     RFC4437, Section 7. */
1181 #define MHD_HTTP_METHOD_UPDATEREDIRECTREF "UPDATEREDIRECTREF"
1182 /* Not safe. Idempotent.     RFC3253, Section 3.5. */
1183 #define MHD_HTTP_METHOD_VERSION_CONTROL "VERSION-CONTROL"
1184 /* Not safe. Not idempotent. RFC9110, Section 18.2. */
1185 #define MHD_HTTP_METHOD_ASTERISK       "*"
1186 
1187 /** @} */ /* end of group methods */
1188 
1189 /**
1190  * @defgroup postenc HTTP POST encodings
1191  * See also: http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4
1192  * @{
1193  */
1194 #define MHD_HTTP_POST_ENCODING_FORM_URLENCODED \
1195   "application/x-www-form-urlencoded"
1196 #define MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA "multipart/form-data"
1197 
1198 /** @} */ /* end of group postenc */
1199 
1200 
1201 /**
1202  * @brief Handle for the daemon (listening on a socket for HTTP traffic).
1203  * @ingroup event
1204  */
1205 struct MHD_Daemon;
1206 
1207 /**
1208  * @brief Handle for a connection / HTTP request.
1209  *
1210  * With HTTP/1.1, multiple requests can be run over the same
1211  * connection.  However, MHD will only show one request per TCP
1212  * connection to the client at any given time.
1213  * @ingroup request
1214  */
1215 struct MHD_Connection;
1216 
1217 /**
1218  * @brief Handle for a response.
1219  * @ingroup response
1220  */
1221 struct MHD_Response;
1222 
1223 /**
1224  * @brief Handle for POST processing.
1225  * @ingroup response
1226  */
1227 struct MHD_PostProcessor;
1228 
1229 
1230 /**
1231  * @brief Flags for the `struct MHD_Daemon`.
1232  *
1233  * Note that MHD will run automatically in background thread(s) only
1234  * if #MHD_USE_INTERNAL_POLLING_THREAD is used. Otherwise caller (application)
1235  * must use #MHD_run() or #MHD_run_from_select() to have MHD processed
1236  * network connections and data.
1237  *
1238  * Starting the daemon may also fail if a particular option is not
1239  * implemented or not supported on the target platform (i.e. no
1240  * support for TLS, epoll or IPv6).
1241  */
1242 enum MHD_FLAG
1243 {
1244   /**
1245    * No options selected.
1246    */
1247   MHD_NO_FLAG = 0,
1248 
1249   /**
1250    * Print errors messages to custom error logger or to `stderr` if
1251    * custom error logger is not set.
1252    * @sa ::MHD_OPTION_EXTERNAL_LOGGER
1253    */
1254   MHD_USE_ERROR_LOG = 1,
1255 
1256   /**
1257    * Run in debug mode.  If this flag is used, the library should
1258    * print error messages and warnings to `stderr`.
1259    */
1260   MHD_USE_DEBUG = 1,
1261 
1262   /**
1263    * Run in HTTPS mode.  The modern protocol is called TLS.
1264    */
1265   MHD_USE_TLS = 2,
1266 
1267   /** @deprecated */
1268   MHD_USE_SSL = 2,
1269 #if 0
1270   /* let's do this later once versions that define MHD_USE_TLS a more widely deployed. */
1271 #define MHD_USE_SSL \
1272   _MHD_DEPR_IN_MACRO ("Value MHD_USE_SSL is deprecated, use MHD_USE_TLS") \
1273   MHD_USE_TLS
1274 #endif
1275 
1276   /**
1277    * Run using one thread per connection.
1278    * Must be used only with #MHD_USE_INTERNAL_POLLING_THREAD.
1279    *
1280    * If #MHD_USE_ITC is also not used, closed and expired connections may only
1281    * be cleaned up internally when a new connection is received.
1282    * Consider adding of #MHD_USE_ITC flag to have faster internal cleanups
1283    * at very minor increase in system resources usage.
1284    */
1285   MHD_USE_THREAD_PER_CONNECTION = 4,
1286 
1287   /**
1288    * Run using an internal thread (or thread pool) for sockets sending
1289    * and receiving and data processing. Without this flag MHD will not
1290    * run automatically in background thread(s).
1291    * If this flag is set, #MHD_run() and #MHD_run_from_select() couldn't
1292    * be used.
1293    * This flag is set explicitly by #MHD_USE_POLL_INTERNAL_THREAD and
1294    * by #MHD_USE_EPOLL_INTERNAL_THREAD.
1295    * When this flag is not set, MHD run in "external" polling mode.
1296    */
1297   MHD_USE_INTERNAL_POLLING_THREAD = 8,
1298 
1299   /** @deprecated */
1300   MHD_USE_SELECT_INTERNALLY = 8,
1301 #if 0 /* Will be marked for real deprecation later. */
1302 #define MHD_USE_SELECT_INTERNALLY \
1303   _MHD_DEPR_IN_MACRO ( \
1304     "Value MHD_USE_SELECT_INTERNALLY is deprecated, use MHD_USE_INTERNAL_POLLING_THREAD instead") \
1305   MHD_USE_INTERNAL_POLLING_THREAD
1306 #endif /* 0 */
1307 
1308   /**
1309    * Run using the IPv6 protocol (otherwise, MHD will just support
1310    * IPv4).  If you want MHD to support IPv4 and IPv6 using a single
1311    * socket, pass #MHD_USE_DUAL_STACK, otherwise, if you only pass
1312    * this option, MHD will try to bind to IPv6-only (resulting in
1313    * no IPv4 support).
1314    */
1315   MHD_USE_IPv6 = 16,
1316 
1317   /**
1318    * Be pedantic about the protocol (as opposed to as tolerant as
1319    * possible).
1320    * This flag is equivalent to setting 1 as #MHD_OPTION_CLIENT_DISCIPLINE_LVL
1321    * value.
1322    * @sa #MHD_OPTION_CLIENT_DISCIPLINE_LVL
1323    */
1324   MHD_USE_PEDANTIC_CHECKS = 32,
1325 #if 0 /* Will be marked for real deprecation later. */
1326 #define MHD_USE_PEDANTIC_CHECKS \
1327   _MHD_DEPR_IN_MACRO ( \
1328     "Flag MHD_USE_PEDANTIC_CHECKS is deprecated, " \
1329     "use option MHD_OPTION_CLIENT_DISCIPLINE_LVL instead") \
1330   32
1331 #endif /* 0 */
1332 
1333   /**
1334    * Use `poll()` instead of `select()` for polling sockets.
1335    * This allows sockets with `fd >= FD_SETSIZE`.
1336    * This option is not compatible with an "external" polling mode
1337    * (as there is no API to get the file descriptors for the external
1338    * poll() from MHD) and must also not be used in combination
1339    * with #MHD_USE_EPOLL.
1340    * @sa ::MHD_FEATURE_POLL, #MHD_USE_POLL_INTERNAL_THREAD
1341    */
1342   MHD_USE_POLL = 64,
1343 
1344   /**
1345    * Run using an internal thread (or thread pool) doing `poll()`.
1346    * @sa ::MHD_FEATURE_POLL, #MHD_USE_POLL, #MHD_USE_INTERNAL_POLLING_THREAD
1347    */
1348   MHD_USE_POLL_INTERNAL_THREAD = MHD_USE_POLL | MHD_USE_INTERNAL_POLLING_THREAD,
1349 
1350   /** @deprecated */
1351   MHD_USE_POLL_INTERNALLY = MHD_USE_POLL | MHD_USE_INTERNAL_POLLING_THREAD,
1352 #if 0 /* Will be marked for real deprecation later. */
1353 #define MHD_USE_POLL_INTERNALLY \
1354   _MHD_DEPR_IN_MACRO ( \
1355     "Value MHD_USE_POLL_INTERNALLY is deprecated, use MHD_USE_POLL_INTERNAL_THREAD instead") \
1356   MHD_USE_POLL_INTERNAL_THREAD
1357 #endif /* 0 */
1358 
1359   /**
1360    * Suppress (automatically) adding the 'Date:' header to HTTP responses.
1361    * This option should ONLY be used on systems that do not have a clock
1362    * and that DO provide other mechanisms for cache control.  See also
1363    * RFC 2616, section 14.18 (exception 3).
1364    */
1365   MHD_USE_SUPPRESS_DATE_NO_CLOCK = 128,
1366 
1367   /** @deprecated */
1368   MHD_SUPPRESS_DATE_NO_CLOCK = 128,
1369 #if 0 /* Will be marked for real deprecation later. */
1370 #define MHD_SUPPRESS_DATE_NO_CLOCK \
1371   _MHD_DEPR_IN_MACRO ( \
1372     "Value MHD_SUPPRESS_DATE_NO_CLOCK is deprecated, use MHD_USE_SUPPRESS_DATE_NO_CLOCK instead") \
1373   MHD_USE_SUPPRESS_DATE_NO_CLOCK
1374 #endif /* 0 */
1375 
1376   /**
1377    * Run without a listen socket.  This option only makes sense if
1378    * #MHD_add_connection is to be used exclusively to connect HTTP
1379    * clients to the HTTP server.  This option is incompatible with
1380    * using a thread pool; if it is used, #MHD_OPTION_THREAD_POOL_SIZE
1381    * is ignored.
1382    */
1383   MHD_USE_NO_LISTEN_SOCKET = 256,
1384 
1385   /**
1386    * Use `epoll()` instead of `select()` or `poll()` for the event loop.
1387    * This option is only available on some systems; using the option on
1388    * systems without epoll will cause #MHD_start_daemon to fail.  Using
1389    * this option is not supported with #MHD_USE_THREAD_PER_CONNECTION.
1390    * @sa ::MHD_FEATURE_EPOLL
1391    */
1392   MHD_USE_EPOLL = 512,
1393 
1394   /** @deprecated */
1395   MHD_USE_EPOLL_LINUX_ONLY = 512,
1396 #if 0 /* Will be marked for real deprecation later. */
1397 #define MHD_USE_EPOLL_LINUX_ONLY \
1398   _MHD_DEPR_IN_MACRO ( \
1399     "Value MHD_USE_EPOLL_LINUX_ONLY is deprecated, use MHD_USE_EPOLL") \
1400   MHD_USE_EPOLL
1401 #endif /* 0 */
1402 
1403   /**
1404    * Run using an internal thread (or thread pool) doing `epoll` polling.
1405    * This option is only available on certain platforms; using the option on
1406    * platform without `epoll` support will cause #MHD_start_daemon to fail.
1407    * @sa ::MHD_FEATURE_EPOLL, #MHD_USE_EPOLL, #MHD_USE_INTERNAL_POLLING_THREAD
1408    */
1409   MHD_USE_EPOLL_INTERNAL_THREAD = MHD_USE_EPOLL
1410                                   | MHD_USE_INTERNAL_POLLING_THREAD,
1411 
1412   /** @deprecated */
1413   MHD_USE_EPOLL_INTERNALLY = MHD_USE_EPOLL | MHD_USE_INTERNAL_POLLING_THREAD,
1414   /** @deprecated */
1415   MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY = MHD_USE_EPOLL
1416                                         | MHD_USE_INTERNAL_POLLING_THREAD,
1417 #if 0 /* Will be marked for real deprecation later. */
1418 #define MHD_USE_EPOLL_INTERNALLY \
1419   _MHD_DEPR_IN_MACRO ( \
1420     "Value MHD_USE_EPOLL_INTERNALLY is deprecated, use MHD_USE_EPOLL_INTERNAL_THREAD") \
1421   MHD_USE_EPOLL_INTERNAL_THREAD
1422   /** @deprecated */
1423 #define MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY \
1424   _MHD_DEPR_IN_MACRO ( \
1425     "Value MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY is deprecated, use MHD_USE_EPOLL_INTERNAL_THREAD") \
1426   MHD_USE_EPOLL_INTERNAL_THREAD
1427 #endif /* 0 */
1428 
1429   /**
1430    * Use inter-thread communication channel.
1431    * #MHD_USE_ITC can be used with #MHD_USE_INTERNAL_POLLING_THREAD
1432    * and is ignored with any "external" sockets polling.
1433    * It's required for use of #MHD_quiesce_daemon
1434    * or #MHD_add_connection.
1435    * This option is enforced by #MHD_ALLOW_SUSPEND_RESUME or
1436    * #MHD_USE_NO_LISTEN_SOCKET.
1437    * #MHD_USE_ITC is always used automatically on platforms
1438    * where select()/poll()/other ignore shutdown of listen
1439    * socket.
1440    */
1441   MHD_USE_ITC = 1024,
1442 
1443   /** @deprecated */
1444   MHD_USE_PIPE_FOR_SHUTDOWN = 1024,
1445 #if 0 /* Will be marked for real deprecation later. */
1446 #define MHD_USE_PIPE_FOR_SHUTDOWN \
1447   _MHD_DEPR_IN_MACRO ( \
1448     "Value MHD_USE_PIPE_FOR_SHUTDOWN is deprecated, use MHD_USE_ITC") \
1449   MHD_USE_ITC
1450 #endif /* 0 */
1451 
1452   /**
1453    * Use a single socket for IPv4 and IPv6.
1454    */
1455   MHD_USE_DUAL_STACK = MHD_USE_IPv6 | 2048,
1456 
1457   /**
1458    * Enable `turbo`.  Disables certain calls to `shutdown()`,
1459    * enables aggressive non-blocking optimistic reads and
1460    * other potentially unsafe optimizations.
1461    * Most effects only happen with #MHD_USE_EPOLL.
1462    */
1463   MHD_USE_TURBO = 4096,
1464 
1465   /** @deprecated */
1466   MHD_USE_EPOLL_TURBO = 4096,
1467 #if 0 /* Will be marked for real deprecation later. */
1468 #define MHD_USE_EPOLL_TURBO \
1469   _MHD_DEPR_IN_MACRO ( \
1470     "Value MHD_USE_EPOLL_TURBO is deprecated, use MHD_USE_TURBO") \
1471   MHD_USE_TURBO
1472 #endif /* 0 */
1473 
1474   /**
1475    * Enable suspend/resume functions, which also implies setting up
1476    * ITC to signal resume.
1477    */
1478   MHD_ALLOW_SUSPEND_RESUME = 8192 | MHD_USE_ITC,
1479 
1480   /** @deprecated */
1481   MHD_USE_SUSPEND_RESUME = 8192 | MHD_USE_ITC,
1482 #if 0 /* Will be marked for real deprecation later. */
1483 #define MHD_USE_SUSPEND_RESUME \
1484   _MHD_DEPR_IN_MACRO ( \
1485     "Value MHD_USE_SUSPEND_RESUME is deprecated, use MHD_ALLOW_SUSPEND_RESUME instead") \
1486   MHD_ALLOW_SUSPEND_RESUME
1487 #endif /* 0 */
1488 
1489   /**
1490    * Enable TCP_FASTOPEN option.  This option is only available on Linux with a
1491    * kernel >= 3.6.  On other systems, using this option cases #MHD_start_daemon
1492    * to fail.
1493    */
1494   MHD_USE_TCP_FASTOPEN = 16384,
1495 
1496   /**
1497    * You need to set this option if you want to use HTTP "Upgrade".
1498    * "Upgrade" may require usage of additional internal resources,
1499    * which we do not want to use unless necessary.
1500    */
1501   MHD_ALLOW_UPGRADE = 32768,
1502 
1503   /**
1504    * Automatically use best available polling function.
1505    * Choice of polling function is also depend on other daemon options.
1506    * If #MHD_USE_INTERNAL_POLLING_THREAD is specified then epoll, poll() or
1507    * select() will be used (listed in decreasing preference order, first
1508    * function available on system will be used).
1509    * If #MHD_USE_THREAD_PER_CONNECTION is specified then poll() or select()
1510    * will be used.
1511    * If those flags are not specified then epoll or select() will be
1512    * used (as the only suitable for MHD_get_fdset())
1513    */
1514   MHD_USE_AUTO = 65536,
1515 
1516   /**
1517    * Run using an internal thread (or thread pool) with best available on
1518    * system polling function.
1519    * This is combination of #MHD_USE_AUTO and #MHD_USE_INTERNAL_POLLING_THREAD
1520    * flags.
1521    */
1522   MHD_USE_AUTO_INTERNAL_THREAD = MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD,
1523 
1524   /**
1525    * Flag set to enable post-handshake client authentication
1526    * (only useful in combination with #MHD_USE_TLS).
1527    */
1528   MHD_USE_POST_HANDSHAKE_AUTH_SUPPORT = 1U << 17,
1529 
1530   /**
1531    * Flag set to enable TLS 1.3 early data.  This has
1532    * security implications, be VERY careful when using this.
1533    */
1534   MHD_USE_INSECURE_TLS_EARLY_DATA = 1U << 18,
1535 
1536   /**
1537    * Indicates that MHD daemon will be used by application in single-threaded
1538    * mode only.  When this flag is set then application must call any MHD
1539    * function only within a single thread.
1540    * This flag turns off some internal thread-safety and allows MHD making
1541    * some of the internal optimisations suitable only for single-threaded
1542    * environment.
1543    * Not compatible with #MHD_USE_INTERNAL_POLLING_THREAD.
1544    * @note Available since #MHD_VERSION 0x00097707
1545    */
1546   MHD_USE_NO_THREAD_SAFETY = 1U << 19
1547 
1548 };
1549 
1550 
1551 /**
1552  * Type of a callback function used for logging by MHD.
1553  *
1554  * @param cls closure
1555  * @param fm format string (`printf()`-style)
1556  * @param ap arguments to @a fm
1557  * @ingroup logging
1558  */
1559 typedef void
1560 (*MHD_LogCallback)(void *cls,
1561                    const char *fm,
1562                    va_list ap);
1563 
1564 
1565 /**
1566  * Function called to lookup the pre shared key (@a psk) for a given
1567  * HTTP connection based on the @a username.
1568  *
1569  * @param cls closure
1570  * @param connection the HTTPS connection
1571  * @param username the user name claimed by the other side
1572  * @param[out] psk to be set to the pre-shared-key; should be allocated with malloc(),
1573  *                 will be freed by MHD
1574  * @param[out] psk_size to be set to the number of bytes in @a psk
1575  * @return 0 on success, -1 on errors
1576  */
1577 typedef int
1578 (*MHD_PskServerCredentialsCallback)(void *cls,
1579                                     const struct MHD_Connection *connection,
1580                                     const char *username,
1581                                     void **psk,
1582                                     size_t *psk_size);
1583 
1584 /**
1585  * Values for #MHD_OPTION_DIGEST_AUTH_NONCE_BIND_TYPE.
1586  *
1587  * These values can limit the scope of validity of MHD-generated nonces.
1588  * Values can be combined with bitwise OR.
1589  * Any value, except #MHD_DAUTH_BIND_NONCE_NONE, enforce function
1590  * #MHD_digest_auth_check3() (and similar functions) to check nonce by
1591  * re-generating it again with the same parameters, which is CPU-intensive
1592  * operation.
1593  * @note Available since #MHD_VERSION 0x00097701
1594  */
1595 enum MHD_DAuthBindNonce
1596 {
1597   /**
1598    * Generated nonces are valid for any request from any client until expired.
1599    * This is default and recommended value.
1600    * #MHD_digest_auth_check3() (and similar functions) would check only whether
1601    * the nonce value that is used by client has been generated by MHD and not
1602    * expired yet.
1603    * It is recommended because RFC 7616 allows clients to use the same nonce
1604    * for any request in the same "protection space".
1605    * When checking client's authorisation requests CPU is loaded less if this
1606    * value is used.
1607    * This mode gives MHD maximum flexibility for nonces generation and can
1608    * prevent possible nonce collisions (and corresponding log warning messages)
1609    * when clients' requests are intensive.
1610    * This value cannot be biwise-OR combined with other values.
1611    */
1612   MHD_DAUTH_BIND_NONCE_NONE = 0,
1613 
1614   /**
1615    * Generated nonces are valid only for the same realm.
1616    */
1617   MHD_DAUTH_BIND_NONCE_REALM = 1 << 0,
1618 
1619   /**
1620    * Generated nonces are valid only for the same URI (excluding parameters
1621    * after '?' in URI) and request method (GET, POST etc).
1622    * Not recommended unless "protection space" is limited to a single URI as
1623    * RFC 7616 allows clients to re-use server-generated nonces for any URI
1624    * in the same "protection space" which by default consists of all server
1625    * URIs.
1626    * Before #MHD_VERSION 0x00097701 this was default (and only supported)
1627    * nonce bind type.
1628    */
1629   MHD_DAUTH_BIND_NONCE_URI = 1 << 1,
1630 
1631   /**
1632    * Generated nonces are valid only for the same URI including URI parameters
1633    * and request method (GET, POST etc).
1634    * This value implies #MHD_DAUTH_BIND_NONCE_URI.
1635    * Not recommended for that same reasons as #MHD_DAUTH_BIND_NONCE_URI.
1636    */
1637   MHD_DAUTH_BIND_NONCE_URI_PARAMS = 1 << 2,
1638 
1639   /**
1640    * Generated nonces are valid only for the single client's IP.
1641    * While it looks like security improvement, in practice the same client may
1642    * jump from one IP to another (mobile or Wi-Fi handover, DHCP re-assignment,
1643    * Multi-NAT, different proxy chain and other reasons), while IP address
1644    * spoofing could be used relatively easily.
1645    */
1646   MHD_DAUTH_BIND_NONCE_CLIENT_IP = 1 << 3
1647 } _MHD_FLAGS_ENUM;
1648 
1649 /**
1650  * @brief MHD options.
1651  *
1652  * Passed in the varargs portion of #MHD_start_daemon.
1653  */
1654 enum MHD_OPTION
1655 {
1656 
1657   /**
1658    * No more options / last option.  This is used
1659    * to terminate the VARARGs list.
1660    */
1661   MHD_OPTION_END = 0,
1662 
1663   /**
1664    * Maximum memory size per connection (followed by a `size_t`).
1665    * Default is 32 kb (#MHD_POOL_SIZE_DEFAULT).
1666    * Values above 128k are unlikely to result in much benefit, as half
1667    * of the memory will be typically used for IO, and TCP buffers are
1668    * unlikely to support window sizes above 64k on most systems.
1669    * Values below 64 bytes are completely unusable.
1670    * Since #MHD_VERSION 0x00097710 silently ignored if followed by zero value.
1671    */
1672   MHD_OPTION_CONNECTION_MEMORY_LIMIT = 1,
1673 
1674   /**
1675    * Maximum number of concurrent connections to
1676    * accept (followed by an `unsigned int`).
1677    */
1678   MHD_OPTION_CONNECTION_LIMIT = 2,
1679 
1680   /**
1681    * After how many seconds of inactivity should a
1682    * connection automatically be timed out? (followed
1683    * by an `unsigned int`; use zero for no timeout).
1684    * Values larger than (UINT64_MAX / 2000 - 1) will
1685    * be clipped to this number.
1686    */
1687   MHD_OPTION_CONNECTION_TIMEOUT = 3,
1688 
1689   /**
1690    * Register a function that should be called whenever a request has
1691    * been completed (this can be used for application-specific clean
1692    * up).  Requests that have never been presented to the application
1693    * (via #MHD_AccessHandlerCallback) will not result in
1694    * notifications.
1695    *
1696    * This option should be followed by TWO pointers.  First a pointer
1697    * to a function of type #MHD_RequestCompletedCallback and second a
1698    * pointer to a closure to pass to the request completed callback.
1699    * The second pointer may be NULL.
1700    */
1701   MHD_OPTION_NOTIFY_COMPLETED = 4,
1702 
1703   /**
1704    * Limit on the number of (concurrent) connections made to the
1705    * server from the same IP address.  Can be used to prevent one
1706    * IP from taking over all of the allowed connections.  If the
1707    * same IP tries to establish more than the specified number of
1708    * connections, they will be immediately rejected.  The option
1709    * should be followed by an `unsigned int`.  The default is
1710    * zero, which means no limit on the number of connections
1711    * from the same IP address.
1712    */
1713   MHD_OPTION_PER_IP_CONNECTION_LIMIT = 5,
1714 
1715   /**
1716    * Bind daemon to the supplied `struct sockaddr`. This option should
1717    * be followed by a `struct sockaddr *`.  If #MHD_USE_IPv6 is
1718    * specified, the `struct sockaddr*` should point to a `struct
1719    * sockaddr_in6`, otherwise to a `struct sockaddr_in`.
1720    * Silently ignored if followed by NULL pointer.
1721    * @deprecated Use #MHD_OPTION_SOCK_ADDR_LEN
1722    */
1723   MHD_OPTION_SOCK_ADDR = 6,
1724 
1725   /**
1726    * Specify a function that should be called before parsing the URI from
1727    * the client.  The specified callback function can be used for processing
1728    * the URI (including the options) before it is parsed.  The URI after
1729    * parsing will no longer contain the options, which maybe inconvenient for
1730    * logging.  This option should be followed by two arguments, the first
1731    * one must be of the form
1732    *
1733    *     void * my_logger(void *cls, const char *uri, struct MHD_Connection *con)
1734    *
1735    * where the return value will be passed as
1736    * (`* req_cls`) in calls to the #MHD_AccessHandlerCallback
1737    * when this request is processed later; returning a
1738    * value of NULL has no special significance (however,
1739    * note that if you return non-NULL, you can no longer
1740    * rely on the first call to the access handler having
1741    * `NULL == *req_cls` on entry;)
1742    * "cls" will be set to the second argument following
1743    * #MHD_OPTION_URI_LOG_CALLBACK.  Finally, uri will
1744    * be the 0-terminated URI of the request.
1745    *
1746    * Note that during the time of this call, most of the connection's
1747    * state is not initialized (as we have not yet parsed the headers).
1748    * However, information about the connecting client (IP, socket)
1749    * is available.
1750    *
1751    * The specified function is called only once per request, therefore some
1752    * programmers may use it to instantiate their own request objects, freeing
1753    * them in the notifier #MHD_OPTION_NOTIFY_COMPLETED.
1754    */
1755   MHD_OPTION_URI_LOG_CALLBACK = 7,
1756 
1757   /**
1758    * Memory pointer for the private key (key.pem) to be used by the
1759    * HTTPS daemon.  This option should be followed by a
1760    * `const char *` argument.
1761    * This should be used in conjunction with #MHD_OPTION_HTTPS_MEM_CERT.
1762    */
1763   MHD_OPTION_HTTPS_MEM_KEY = 8,
1764 
1765   /**
1766    * Memory pointer for the certificate (cert.pem) to be used by the
1767    * HTTPS daemon.  This option should be followed by a
1768    * `const char *` argument.
1769    * This should be used in conjunction with #MHD_OPTION_HTTPS_MEM_KEY.
1770    */
1771   MHD_OPTION_HTTPS_MEM_CERT = 9,
1772 
1773   /**
1774    * Daemon credentials type.
1775    * Followed by an argument of type
1776    * `gnutls_credentials_type_t`.
1777    */
1778   MHD_OPTION_HTTPS_CRED_TYPE = 10,
1779 
1780   /**
1781    * Memory pointer to a `const char *` specifying the GnuTLS priorities string.
1782    * If this options is not specified, then MHD will try the following strings:
1783    * * "@LIBMICROHTTPD" (application-specific system-wide configuration)
1784    * * "@SYSTEM"        (system-wide configuration)
1785    * * default GnuTLS priorities string
1786    * * "NORMAL"
1787    * The first configuration accepted by GnuTLS will be used.
1788    * For more details see GnuTLS documentation for "Application-specific
1789    * priority strings".
1790    */
1791   MHD_OPTION_HTTPS_PRIORITIES = 11,
1792 
1793   /**
1794    * Pass a listen socket for MHD to use (systemd-style).  If this
1795    * option is used, MHD will not open its own listen socket(s). The
1796    * argument passed must be of type `MHD_socket` and refer to an
1797    * existing socket that has been bound to a port and is listening.
1798    * If followed by MHD_INVALID_SOCKET value, MHD ignores this option
1799    * and creates socket by itself.
1800    */
1801   MHD_OPTION_LISTEN_SOCKET = 12,
1802 
1803   /**
1804    * Use the given function for logging error messages.  This option
1805    * must be followed by two arguments; the first must be a pointer to
1806    * a function of type #MHD_LogCallback and the second a pointer
1807    * `void *` which will be passed as the first argument to the log
1808    * callback.
1809    * Should be specified as the first option, otherwise some messages
1810    * may be printed by standard MHD logger during daemon startup.
1811    *
1812    * Note that MHD will not generate any log messages
1813    * if it was compiled without the "--enable-messages"
1814    * flag being set.
1815    */
1816   MHD_OPTION_EXTERNAL_LOGGER = 13,
1817 
1818   /**
1819    * Number (`unsigned int`) of threads in thread pool. Enable
1820    * thread pooling by setting this value to to something
1821    * greater than 1.
1822    * Can be used only for daemons started with #MHD_USE_INTERNAL_POLLING_THREAD.
1823    * Ignored if followed by zero value.
1824    */
1825   MHD_OPTION_THREAD_POOL_SIZE = 14,
1826 
1827   /**
1828    * Additional options given in an array of `struct MHD_OptionItem`.
1829    * The array must be terminated with an entry `{MHD_OPTION_END, 0, NULL}`.
1830    * An example for code using #MHD_OPTION_ARRAY is:
1831    *
1832    *     struct MHD_OptionItem ops[] = {
1833    *       { MHD_OPTION_CONNECTION_LIMIT, 100, NULL },
1834    *       { MHD_OPTION_CONNECTION_TIMEOUT, 10, NULL },
1835    *       { MHD_OPTION_END, 0, NULL }
1836    *     };
1837    *     d = MHD_start_daemon (0, 8080, NULL, NULL, dh, NULL,
1838    *                           MHD_OPTION_ARRAY, ops,
1839    *                           MHD_OPTION_END);
1840    *
1841    * For options that expect a single pointer argument, the
1842    * 'value' member of the `struct MHD_OptionItem` is ignored.
1843    * For options that expect two pointer arguments, the first
1844    * argument must be cast to `intptr_t`.
1845    */
1846   MHD_OPTION_ARRAY = 15,
1847 
1848   /**
1849    * Specify a function that should be called for unescaping escape
1850    * sequences in URIs and URI arguments.  Note that this function
1851    * will NOT be used by the `struct MHD_PostProcessor`.  If this
1852    * option is not specified, the default method will be used which
1853    * decodes escape sequences of the form "%HH".  This option should
1854    * be followed by two arguments, the first one must be of the form
1855    *
1856    *     size_t my_unescaper(void *cls,
1857    *                         struct MHD_Connection *c,
1858    *                         char *s)
1859    *
1860    * where the return value must be the length of the value left in
1861    * "s" (without the 0-terminator) and "s" should be updated.  Note
1862    * that the unescape function must not lengthen "s" (the result must
1863    * be shorter than the input and must still be 0-terminated).
1864    * However, it may also include binary zeros before the
1865    * 0-termination.  "cls" will be set to the second argument
1866    * following #MHD_OPTION_UNESCAPE_CALLBACK.
1867    */
1868   MHD_OPTION_UNESCAPE_CALLBACK = 16,
1869 
1870   /**
1871    * Memory pointer for the random values to be used by the Digest
1872    * Auth module. This option should be followed by two arguments.
1873    * First an integer of type `size_t` which specifies the size
1874    * of the buffer pointed to by the second argument in bytes.
1875    * The recommended size is between 8 and 32. If size is four or less
1876    * then security could be lowered. Sizes more then 32 (or, probably
1877    * more than 16 - debatable) will not increase security.
1878    * Note that the application must ensure that the buffer of the
1879    * second argument remains allocated and unmodified while the
1880    * daemon is running.
1881    * @sa #MHD_OPTION_DIGEST_AUTH_RANDOM_COPY
1882    */
1883   MHD_OPTION_DIGEST_AUTH_RANDOM = 17,
1884 
1885   /**
1886    * Size of the internal array holding the map of the nonce and
1887    * the nonce counter. This option should be followed by an `unsigend int`
1888    * argument.
1889    * The map size is 4 by default, which is enough to communicate with
1890    * a single client at any given moment of time, but not enough to
1891    * handle several clients simultaneously.
1892    * If Digest Auth is not used, this option can be set to zero to minimise
1893    * memory allocation.
1894    */
1895   MHD_OPTION_NONCE_NC_SIZE = 18,
1896 
1897   /**
1898    * Desired size of the stack for threads created by MHD. Followed
1899    * by an argument of type `size_t`.  Use 0 for system default.
1900    */
1901   MHD_OPTION_THREAD_STACK_SIZE = 19,
1902 
1903   /**
1904    * Memory pointer for the certificate (ca.pem) to be used by the
1905    * HTTPS daemon for client authentication.
1906    * This option should be followed by a `const char *` argument.
1907    */
1908   MHD_OPTION_HTTPS_MEM_TRUST = 20,
1909 
1910   /**
1911    * Increment to use for growing the read buffer (followed by a
1912    * `size_t`).
1913    * Must not be higher than 1/4 of #MHD_OPTION_CONNECTION_MEMORY_LIMIT.
1914    * Since #MHD_VERSION 0x00097710 silently ignored if followed by zero value.
1915    */
1916   MHD_OPTION_CONNECTION_MEMORY_INCREMENT = 21,
1917 
1918   /**
1919    * Use a callback to determine which X.509 certificate should be
1920    * used for a given HTTPS connection.  This option should be
1921    * followed by a argument of type `gnutls_certificate_retrieve_function2 *`.
1922    * This option provides an
1923    * alternative to #MHD_OPTION_HTTPS_MEM_KEY,
1924    * #MHD_OPTION_HTTPS_MEM_CERT.  You must use this version if
1925    * multiple domains are to be hosted at the same IP address using
1926    * TLS's Server Name Indication (SNI) extension.  In this case,
1927    * the callback is expected to select the correct certificate
1928    * based on the SNI information provided.  The callback is expected
1929    * to access the SNI data using `gnutls_server_name_get()`.
1930    * Using this option requires GnuTLS 3.0 or higher.
1931    */
1932   MHD_OPTION_HTTPS_CERT_CALLBACK = 22,
1933 
1934   /**
1935    * When using #MHD_USE_TCP_FASTOPEN, this option changes the default TCP
1936    * fastopen queue length of 50.  Note that having a larger queue size can
1937    * cause resource exhaustion attack as the TCP stack has to now allocate
1938    * resources for the SYN packet along with its DATA.  This option should be
1939    * followed by an `unsigned int` argument.
1940    */
1941   MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE = 23,
1942 
1943   /**
1944    * Memory pointer for the Diffie-Hellman parameters (dh.pem) to be used by the
1945    * HTTPS daemon for key exchange.
1946    * This option must be followed by a `const char *` argument.
1947    */
1948   MHD_OPTION_HTTPS_MEM_DHPARAMS = 24,
1949 
1950   /**
1951    * If present and set to true, allow reusing address:port socket
1952    * (by using SO_REUSEPORT on most platform, or platform-specific ways).
1953    * If present and set to false, disallow reusing address:port socket
1954    * (does nothing on most platform, but uses SO_EXCLUSIVEADDRUSE on Windows).
1955    * This option must be followed by a `unsigned int` argument.
1956    */
1957   MHD_OPTION_LISTENING_ADDRESS_REUSE = 25,
1958 
1959   /**
1960    * Memory pointer for a password that decrypts the private key (key.pem)
1961    * to be used by the HTTPS daemon. This option should be followed by a
1962    * `const char *` argument.
1963    * This should be used in conjunction with #MHD_OPTION_HTTPS_MEM_KEY.
1964    * @sa ::MHD_FEATURE_HTTPS_KEY_PASSWORD
1965    */
1966   MHD_OPTION_HTTPS_KEY_PASSWORD = 26,
1967 
1968   /**
1969    * Register a function that should be called whenever a connection is
1970    * started or closed.
1971    *
1972    * This option should be followed by TWO pointers.  First a pointer
1973    * to a function of type #MHD_NotifyConnectionCallback and second a
1974    * pointer to a closure to pass to the request completed callback.
1975    * The second pointer may be NULL.
1976    */
1977   MHD_OPTION_NOTIFY_CONNECTION = 27,
1978 
1979   /**
1980    * Allow to change maximum length of the queue of pending connections on
1981    * listen socket. If not present than default platform-specific SOMAXCONN
1982    * value is used. This option should be followed by an `unsigned int`
1983    * argument.
1984    */
1985   MHD_OPTION_LISTEN_BACKLOG_SIZE = 28,
1986 
1987   /**
1988    * If set to 1 - be strict about the protocol.  Use -1 to be
1989    * as tolerant as possible.
1990    *
1991    * The more flexible option #MHD_OPTION_CLIENT_DISCIPLINE_LVL is recommended
1992    * instead of this option.
1993    *
1994    * The values mapping table:
1995    * #MHD_OPTION_STRICT_FOR_CLIENT | #MHD_OPTION_CLIENT_DISCIPLINE_LVL
1996    * -----------------------------:|:---------------------------------
1997    * 1                             | 1
1998    * 0                             | 0
1999    * -1                            | -3
2000    *
2001    * This option should be followed by an `int` argument.
2002    * @sa #MHD_OPTION_CLIENT_DISCIPLINE_LVL
2003    */
2004   MHD_OPTION_STRICT_FOR_CLIENT = 29,
2005 
2006   /**
2007    * This should be a pointer to callback of type
2008    * gnutls_psk_server_credentials_function that will be given to
2009    * gnutls_psk_set_server_credentials_function. It is used to
2010    * retrieve the shared key for a given username.
2011    */
2012   MHD_OPTION_GNUTLS_PSK_CRED_HANDLER = 30,
2013 
2014   /**
2015    * Use a callback to determine which X.509 certificate should be
2016    * used for a given HTTPS connection.  This option should be
2017    * followed by a argument of type `gnutls_certificate_retrieve_function3 *`.
2018    * This option provides an
2019    * alternative/extension to #MHD_OPTION_HTTPS_CERT_CALLBACK.
2020    * You must use this version if you want to use OCSP stapling.
2021    * Using this option requires GnuTLS 3.6.3 or higher.
2022    */
2023   MHD_OPTION_HTTPS_CERT_CALLBACK2 = 31,
2024 
2025   /**
2026    * Allows the application to disable certain sanity precautions
2027    * in MHD. With these, the client can break the HTTP protocol,
2028    * so this should never be used in production. The options are,
2029    * however, useful for testing HTTP clients against "broken"
2030    * server implementations.
2031    * This argument must be followed by an "unsigned int", corresponding
2032    * to an `enum MHD_DisableSanityCheck`.
2033    */
2034   MHD_OPTION_SERVER_INSANITY = 32,
2035 
2036   /**
2037    * If followed by value '1' informs MHD that SIGPIPE is suppressed or
2038    * handled by application. Allows MHD to use network functions that could
2039    * generate SIGPIPE, like `sendfile()`.
2040    * Valid only for daemons without #MHD_USE_INTERNAL_POLLING_THREAD as
2041    * MHD automatically suppresses SIGPIPE for threads started by MHD.
2042    * This option should be followed by an `int` argument.
2043    * @note Available since #MHD_VERSION 0x00097205
2044    */
2045   MHD_OPTION_SIGPIPE_HANDLED_BY_APP = 33,
2046 
2047   /**
2048    * If followed by 'int' with value '1' disables usage of ALPN for TLS
2049    * connections even if supported by TLS library.
2050    * Valid only for daemons with #MHD_USE_TLS.
2051    * This option should be followed by an `int` argument.
2052    * @note Available since #MHD_VERSION 0x00097207
2053    */
2054   MHD_OPTION_TLS_NO_ALPN = 34,
2055 
2056   /**
2057    * Memory pointer for the random values to be used by the Digest
2058    * Auth module. This option should be followed by two arguments.
2059    * First an integer of type `size_t` which specifies the size
2060    * of the buffer pointed to by the second argument in bytes.
2061    * The recommended size is between 8 and 32. If size is four or less
2062    * then security could be lowered. Sizes more then 32 (or, probably
2063    * more than 16 - debatable) will not increase security.
2064    * An internal copy of the buffer will be made, the data do not
2065    * need to be static.
2066    * @sa #MHD_OPTION_DIGEST_AUTH_RANDOM
2067    * @note Available since #MHD_VERSION 0x00097701
2068    */
2069   MHD_OPTION_DIGEST_AUTH_RANDOM_COPY = 35,
2070 
2071   /**
2072    * Allow to controls the scope of validity of MHD-generated nonces.
2073    * This regulates how "nonces" are generated and how "nonces" are checked by
2074    * #MHD_digest_auth_check3() and similar functions.
2075    * This option should be followed by an 'unsigned int` argument with value
2076    * formed as bitwise OR combination of #MHD_DAuthBindNonce values.
2077    * When not specified, default value #MHD_DAUTH_BIND_NONCE_NONE is used.
2078    * @note Available since #MHD_VERSION 0x00097701
2079    */
2080   MHD_OPTION_DIGEST_AUTH_NONCE_BIND_TYPE = 36,
2081 
2082   /**
2083    * Memory pointer to a `const char *` specifying the GnuTLS priorities to be
2084    * appended to default priorities.
2085    * This allow some specific options to be enabled/disabled, while leaving
2086    * the rest of the settings to their defaults.
2087    * The string does not have to start with a colon ':' character.
2088    * See #MHD_OPTION_HTTPS_PRIORITIES description for details of automatic
2089    * default priorities.
2090    * @note Available since #MHD_VERSION 0x00097701
2091    */
2092   MHD_OPTION_HTTPS_PRIORITIES_APPEND = 37,
2093 
2094   /**
2095    * Sets specified client discipline level (i.e. HTTP protocol parsing
2096    * strictness level).
2097    *
2098    * The following basic values are supported:
2099    *  0 - default MHD level, a balance between extra security and broader
2100    *      compatibility, as allowed by RFCs for HTTP servers;
2101    *  1 - more strict protocol interpretation, within the limits set by
2102    *      RFCs for HTTP servers;
2103    * -1 - more lenient protocol interpretation, within the limits set by
2104    *      RFCs for HTTP servers.
2105    * The following extended values could be used as well:
2106    *  2 - stricter protocol interpretation, even stricter then allowed
2107    *      by RFCs for HTTP servers, however it should be absolutely compatible
2108    *      with clients following at least RFCs' "MUST" type of requirements
2109    *      for HTTP clients;
2110    *  3 - strictest protocol interpretation, even stricter then allowed
2111    *      by RFCs for HTTP servers, however it should be absolutely compatible
2112    *      with clients following RFCs' "SHOULD" and "MUST" types of requirements
2113    *      for HTTP clients;
2114    * -2 - more relaxed protocol interpretation, violating RFCs' "SHOULD" type
2115    *      of requirements for HTTP servers;
2116    * -3 - the most flexible protocol interpretation, beyond RFCs' "MUST" type of
2117    *      requirements for HTTP server.
2118    * Values higher than "3" or lower than "-3" are interpreted as "3" or "-3"
2119    * respectively.
2120    *
2121    * Higher values are more secure, lower values are more compatible with
2122    * various HTTP clients.
2123    *
2124    * The default value ("0") could be used in most cases.
2125    * Value "1" is suitable for highly loaded public servers.
2126    * Values "2" and "3" are generally recommended only for testing of HTTP
2127    * clients against MHD.
2128    * Value "2" may be used for security-centric application, however it is
2129    * slight violation of RFCs' requirements.
2130    * Negative values are not recommended for public servers.
2131    * Values "-1" and "-2" could be used for servers in isolated environment.
2132    * Value "-3" is not recommended unless it is absolutely necessary to
2133    * communicate with some client(s) with badly broken HTTP implementation.
2134    *
2135    * This option should be followed by an `int` argument.
2136    * @note Available since #MHD_VERSION 0x00097701
2137    */
2138   MHD_OPTION_CLIENT_DISCIPLINE_LVL = 38,
2139 
2140   /**
2141    * Specifies value of FD_SETSIZE used by application.  Only For external
2142    * polling modes (without MHD internal threads).
2143    * Some platforms (FreeBSD, Solaris, W32 etc.) allow overriding of FD_SETSIZE
2144    * value.  When polling by select() is used, MHD rejects sockets with numbers
2145    * equal or higher than FD_SETSIZE.  If this option is used, MHD treats this
2146    * value as a limitation for socket number instead of FD_SETSIZE value which
2147    * was used for building MHD.
2148    * When external polling is used with #MHD_get_fdset2() (or #MHD_get_fdset()
2149    * macro) and #MHD_run_from_select() interfaces, it is recommended to always
2150    * use this option.
2151    * It is safe to use this option on platforms with fixed FD_SETSIZE (like
2152    * GNU/Linux) if system value of FD_SETSIZE is used as the argument.
2153    * Can be used only for daemons without #MHD_USE_INTERNAL_POLLING_THREAD, i.e.
2154    * only when external sockets polling is used.
2155    * On W32 it is silently ignored, as W32 does not limit the socket number in
2156    * fd_sets.
2157    * This option should be followed by a positive 'int' argument.
2158    * @note Available since #MHD_VERSION 0x00097705
2159    */
2160   MHD_OPTION_APP_FD_SETSIZE = 39,
2161 
2162   /**
2163    * Bind daemon to the supplied 'struct sockaddr'.  This option should
2164    * be followed by two parameters: 'socklen_t' the size of memory at the next
2165    * pointer and the pointer 'const struct sockaddr *'.
2166    * Note: the order of the arguments is not the same as for system bind() and
2167    * other network functions.
2168    * If #MHD_USE_IPv6 is specified, the 'struct sockaddr*' should
2169    * point to a 'struct sockaddr_in6'.
2170    * The socket domain (protocol family) is detected from provided
2171    * 'struct sockaddr'. IP, IPv6 and UNIX sockets are supported (if supported
2172    * by the platform). Other types may work occasionally.
2173    * Silently ignored if followed by zero size and NULL pointer.
2174    * @note Available since #MHD_VERSION 0x00097706
2175    */
2176   MHD_OPTION_SOCK_ADDR_LEN = 40
2177   ,
2178   /**
2179    * Default nonce timeout value used for Digest Auth.
2180    * This option should be followed by an 'unsigned int' argument.
2181    * Silently ignored if followed by zero value.
2182    * @see #MHD_digest_auth_check3(), MHD_digest_auth_check_digest3()
2183    * @note Available since #MHD_VERSION 0x00097709
2184    */
2185   MHD_OPTION_DIGEST_AUTH_DEFAULT_NONCE_TIMEOUT = 41
2186   ,
2187   /**
2188    * Default maximum nc (nonce count) value used for Digest Auth.
2189    * This option should be followed by an 'uint32_t' argument.
2190    * Silently ignored if followed by zero value.
2191    * @see #MHD_digest_auth_check3(), MHD_digest_auth_check_digest3()
2192    * @note Available since #MHD_VERSION 0x00097709
2193    */
2194   MHD_OPTION_DIGEST_AUTH_DEFAULT_MAX_NC = 42
2195 
2196 } _MHD_FIXED_ENUM;
2197 
2198 
2199 /**
2200  * Bitfield for the #MHD_OPTION_SERVER_INSANITY specifying
2201  * which santiy checks should be disabled.
2202  */
2203 enum MHD_DisableSanityCheck
2204 {
2205   /**
2206    * All sanity checks are enabled.
2207    */
2208   MHD_DSC_SANE = 0
2209 
2210 } _MHD_FIXED_FLAGS_ENUM;
2211 
2212 
2213 /**
2214  * Entry in an #MHD_OPTION_ARRAY.
2215  */
2216 struct MHD_OptionItem
2217 {
2218   /**
2219    * Which option is being given.  Use #MHD_OPTION_END
2220    * to terminate the array.
2221    */
2222   enum MHD_OPTION option;
2223 
2224   /**
2225    * Option value (for integer arguments, and for options requiring
2226    * two pointer arguments); should be 0 for options that take no
2227    * arguments or only a single pointer argument.
2228    */
2229   intptr_t value;
2230 
2231   /**
2232    * Pointer option value (use NULL for options taking no arguments
2233    * or only an integer option).
2234    */
2235   void *ptr_value;
2236 
2237 };
2238 
2239 
2240 /**
2241  * The `enum MHD_ValueKind` specifies the source of
2242  * the key-value pairs in the HTTP protocol.
2243  */
2244 enum MHD_ValueKind
2245 {
2246 
2247   /**
2248    * Response header
2249    * @deprecated
2250    */
2251   MHD_RESPONSE_HEADER_KIND = 0,
2252 #define MHD_RESPONSE_HEADER_KIND \
2253   _MHD_DEPR_IN_MACRO ( \
2254     "Value MHD_RESPONSE_HEADER_KIND is deprecated and not used") \
2255   MHD_RESPONSE_HEADER_KIND
2256 
2257   /**
2258    * HTTP header (request/response).
2259    */
2260   MHD_HEADER_KIND = 1,
2261 
2262   /**
2263    * Cookies.  Note that the original HTTP header containing
2264    * the cookie(s) will still be available and intact.
2265    */
2266   MHD_COOKIE_KIND = 2,
2267 
2268   /**
2269    * POST data.  This is available only if a content encoding
2270    * supported by MHD is used (currently only URL encoding),
2271    * and only if the posted content fits within the available
2272    * memory pool.  Note that in that case, the upload data
2273    * given to the #MHD_AccessHandlerCallback will be
2274    * empty (since it has already been processed).
2275    */
2276   MHD_POSTDATA_KIND = 4,
2277 
2278   /**
2279    * GET (URI) arguments.
2280    */
2281   MHD_GET_ARGUMENT_KIND = 8,
2282 
2283   /**
2284    * HTTP footer (only for HTTP 1.1 chunked encodings).
2285    */
2286   MHD_FOOTER_KIND = 16
2287 } _MHD_FIXED_ENUM;
2288 
2289 
2290 /**
2291  * The `enum MHD_RequestTerminationCode` specifies reasons
2292  * why a request has been terminated (or completed).
2293  * @ingroup request
2294  */
2295 enum MHD_RequestTerminationCode
2296 {
2297 
2298   /**
2299    * We finished sending the response.
2300    * @ingroup request
2301    */
2302   MHD_REQUEST_TERMINATED_COMPLETED_OK = 0,
2303 
2304   /**
2305    * Error handling the connection (resources
2306    * exhausted, application error accepting request,
2307    * decrypt error (for HTTPS), connection died when
2308    * sending the response etc.)
2309    * @ingroup request
2310    */
2311   MHD_REQUEST_TERMINATED_WITH_ERROR = 1,
2312 
2313   /**
2314    * No activity on the connection for the number
2315    * of seconds specified using
2316    * #MHD_OPTION_CONNECTION_TIMEOUT.
2317    * @ingroup request
2318    */
2319   MHD_REQUEST_TERMINATED_TIMEOUT_REACHED = 2,
2320 
2321   /**
2322    * We had to close the session since MHD was being
2323    * shut down.
2324    * @ingroup request
2325    */
2326   MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN = 3,
2327 
2328   /**
2329    * We tried to read additional data, but the connection became broken or
2330    * the other side hard closed the connection.
2331    * This error is similar to #MHD_REQUEST_TERMINATED_WITH_ERROR, but
2332    * specific to the case where the connection died before request completely
2333    * received.
2334    * @ingroup request
2335    */
2336   MHD_REQUEST_TERMINATED_READ_ERROR = 4,
2337 
2338   /**
2339    * The client terminated the connection by closing the socket
2340    * for writing (TCP half-closed) while still sending request.
2341    * @ingroup request
2342    */
2343   MHD_REQUEST_TERMINATED_CLIENT_ABORT = 5
2344 
2345 } _MHD_FIXED_ENUM;
2346 
2347 
2348 /**
2349  * The `enum MHD_ConnectionNotificationCode` specifies types
2350  * of connection notifications.
2351  * @ingroup request
2352  */
2353 enum MHD_ConnectionNotificationCode
2354 {
2355 
2356   /**
2357    * A new connection has been started.
2358    * @ingroup request
2359    */
2360   MHD_CONNECTION_NOTIFY_STARTED = 0,
2361 
2362   /**
2363    * A connection is closed.
2364    * @ingroup request
2365    */
2366   MHD_CONNECTION_NOTIFY_CLOSED = 1
2367 
2368 } _MHD_FIXED_ENUM;
2369 
2370 
2371 /**
2372  * Information about a connection.
2373  */
2374 union MHD_ConnectionInfo
2375 {
2376 
2377   /**
2378    * Cipher algorithm used, of type "enum gnutls_cipher_algorithm".
2379    */
2380   int /* enum gnutls_cipher_algorithm */ cipher_algorithm;
2381 
2382   /**
2383    * Protocol used, of type "enum gnutls_protocol".
2384    */
2385   int /* enum gnutls_protocol */ protocol;
2386 
2387   /**
2388    * The suspended status of a connection.
2389    */
2390   int /* MHD_YES or MHD_NO */ suspended;
2391 
2392   /**
2393    * Amount of second that connection could spend in idle state
2394    * before automatically disconnected.
2395    * Zero for no timeout (unlimited idle time).
2396    */
2397   unsigned int connection_timeout;
2398 
2399   /**
2400    * HTTP status queued with the response, for #MHD_CONNECTION_INFO_HTTP_STATUS.
2401    */
2402   unsigned int http_status;
2403 
2404   /**
2405    * Connect socket
2406    */
2407   MHD_socket connect_fd;
2408 
2409   /**
2410    * Size of the client's HTTP header.
2411    * It includes the request line, all request headers, the header section
2412    * terminating empty line, with all CRLF (or LF) characters.
2413    */
2414   size_t header_size;
2415 
2416   /**
2417    * GNUtls session handle, of type "gnutls_session_t".
2418    */
2419   void * /* gnutls_session_t */ tls_session;
2420 
2421   /**
2422    * GNUtls client certificate handle, of type "gnutls_x509_crt_t".
2423    */
2424   void * /* gnutls_x509_crt_t */ client_cert;
2425 
2426   /**
2427    * Address information for the client.
2428    */
2429   struct sockaddr *client_addr;
2430 
2431   /**
2432    * Which daemon manages this connection (useful in case there are many
2433    * daemons running).
2434    */
2435   struct MHD_Daemon *daemon;
2436 
2437   /**
2438    * Socket-specific client context.  Points to the same address as
2439    * the "socket_context" of the #MHD_NotifyConnectionCallback.
2440    */
2441   void *socket_context;
2442 };
2443 
2444 
2445 /**
2446  * I/O vector type. Provided for use with #MHD_create_response_from_iovec().
2447  * @note Available since #MHD_VERSION 0x00097204
2448  */
2449 struct MHD_IoVec
2450 {
2451   /**
2452    * The pointer to the memory region for I/O.
2453    */
2454   const void *iov_base;
2455 
2456   /**
2457    * The size in bytes of the memory region for I/O.
2458    */
2459   size_t iov_len;
2460 };
2461 
2462 
2463 /**
2464  * Values of this enum are used to specify what
2465  * information about a connection is desired.
2466  * @ingroup request
2467  */
2468 enum MHD_ConnectionInfoType
2469 {
2470   /**
2471    * What cipher algorithm is being used.
2472    * Takes no extra arguments.
2473    * @ingroup request
2474    */
2475   MHD_CONNECTION_INFO_CIPHER_ALGO,
2476 
2477   /**
2478    *
2479    * Takes no extra arguments.
2480    * @ingroup request
2481    */
2482   MHD_CONNECTION_INFO_PROTOCOL,
2483 
2484   /**
2485    * Obtain IP address of the client.  Takes no extra arguments.
2486    * Returns essentially a `struct sockaddr **` (since the API returns
2487    * a `union MHD_ConnectionInfo *` and that union contains a `struct
2488    * sockaddr *`).
2489    * @ingroup request
2490    */
2491   MHD_CONNECTION_INFO_CLIENT_ADDRESS,
2492 
2493   /**
2494    * Get the gnuTLS session handle.
2495    * @ingroup request
2496    */
2497   MHD_CONNECTION_INFO_GNUTLS_SESSION,
2498 
2499   /**
2500    * Get the gnuTLS client certificate handle.  Dysfunctional (never
2501    * implemented, deprecated).  Use #MHD_CONNECTION_INFO_GNUTLS_SESSION
2502    * to get the `gnutls_session_t` and then call
2503    * gnutls_certificate_get_peers().
2504    */
2505   MHD_CONNECTION_INFO_GNUTLS_CLIENT_CERT,
2506 
2507   /**
2508    * Get the `struct MHD_Daemon *` responsible for managing this connection.
2509    * @ingroup request
2510    */
2511   MHD_CONNECTION_INFO_DAEMON,
2512 
2513   /**
2514    * Request the file descriptor for the connection socket.
2515    * MHD sockets are always in non-blocking mode.
2516    * No extra arguments should be passed.
2517    * @ingroup request
2518    */
2519   MHD_CONNECTION_INFO_CONNECTION_FD,
2520 
2521   /**
2522    * Returns the client-specific pointer to a `void *` that was (possibly)
2523    * set during a #MHD_NotifyConnectionCallback when the socket was
2524    * first accepted.
2525    * Note that this is NOT the same as the "req_cls" argument of
2526    * the #MHD_AccessHandlerCallback. The "req_cls" is fresh for each
2527    * HTTP request, while the "socket_context" is fresh for each socket.
2528    */
2529   MHD_CONNECTION_INFO_SOCKET_CONTEXT,
2530 
2531   /**
2532    * Check whether the connection is suspended.
2533    * @ingroup request
2534    */
2535   MHD_CONNECTION_INFO_CONNECTION_SUSPENDED,
2536 
2537   /**
2538    * Get connection timeout
2539    * @ingroup request
2540    */
2541   MHD_CONNECTION_INFO_CONNECTION_TIMEOUT,
2542 
2543   /**
2544    * Return length of the client's HTTP request header.
2545    * @ingroup request
2546    */
2547   MHD_CONNECTION_INFO_REQUEST_HEADER_SIZE,
2548 
2549   /**
2550    * Return HTTP status queued with the response. NULL
2551    * if no HTTP response has been queued yet.
2552    */
2553   MHD_CONNECTION_INFO_HTTP_STATUS
2554 
2555 } _MHD_FIXED_ENUM;
2556 
2557 
2558 /**
2559  * Values of this enum are used to specify what
2560  * information about a daemon is desired.
2561  */
2562 enum MHD_DaemonInfoType
2563 {
2564   /**
2565    * No longer supported (will return NULL).
2566    */
2567   MHD_DAEMON_INFO_KEY_SIZE,
2568 
2569   /**
2570    * No longer supported (will return NULL).
2571    */
2572   MHD_DAEMON_INFO_MAC_KEY_SIZE,
2573 
2574   /**
2575    * Request the file descriptor for the listening socket.
2576    * No extra arguments should be passed.
2577    */
2578   MHD_DAEMON_INFO_LISTEN_FD,
2579 
2580   /**
2581    * Request the file descriptor for the "external" sockets polling
2582    * when 'epoll' mode is used.
2583    * No extra arguments should be passed.
2584    *
2585    * Waiting on epoll FD must not block longer than value
2586    * returned by #MHD_get_timeout() otherwise connections
2587    * will "hung" with unprocessed data in network buffers
2588    * and timed-out connections will not be closed.
2589    *
2590    * @sa #MHD_get_timeout(), #MHD_run()
2591    */
2592   MHD_DAEMON_INFO_EPOLL_FD_LINUX_ONLY,
2593   MHD_DAEMON_INFO_EPOLL_FD = MHD_DAEMON_INFO_EPOLL_FD_LINUX_ONLY,
2594 
2595   /**
2596    * Request the number of current connections handled by the daemon.
2597    * No extra arguments should be passed.
2598    * Note: when using MHD in "external" polling mode, this type of request
2599    * could be used only when #MHD_run()/#MHD_run_from_select is not
2600    * working in other thread at the same time.
2601    */
2602   MHD_DAEMON_INFO_CURRENT_CONNECTIONS,
2603 
2604   /**
2605    * Request the daemon flags.
2606    * No extra arguments should be passed.
2607    * Note: flags may differ from original 'flags' specified for
2608    * daemon, especially if #MHD_USE_AUTO was set.
2609    */
2610   MHD_DAEMON_INFO_FLAGS,
2611 
2612   /**
2613    * Request the port number of daemon's listen socket.
2614    * No extra arguments should be passed.
2615    * Note: if port '0' was specified for #MHD_start_daemon(), returned
2616    * value will be real port number.
2617    */
2618   MHD_DAEMON_INFO_BIND_PORT
2619 } _MHD_FIXED_ENUM;
2620 
2621 
2622 /**
2623  * Callback for serious error condition. The default action is to print
2624  * an error message and `abort()`.
2625  *
2626  * @param cls user specified value
2627  * @param file where the error occurred, may be NULL if MHD was built without
2628  *             messages support
2629  * @param line where the error occurred
2630  * @param reason error detail, may be NULL
2631  * @ingroup logging
2632  */
2633 typedef void
2634 (*MHD_PanicCallback) (void *cls,
2635                       const char *file,
2636                       unsigned int line,
2637                       const char *reason);
2638 
2639 /**
2640  * Allow or deny a client to connect.
2641  *
2642  * @param cls closure
2643  * @param addr address information from the client
2644  * @param addrlen length of @a addr
2645  * @return #MHD_YES if connection is allowed, #MHD_NO if not
2646  */
2647 typedef enum MHD_Result
2648 (*MHD_AcceptPolicyCallback)(void *cls,
2649                             const struct sockaddr *addr,
2650                             socklen_t addrlen);
2651 
2652 
2653 /**
2654  * A client has requested the given @a url using the given @a method
2655  * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT, #MHD_HTTP_METHOD_DELETE,
2656  * #MHD_HTTP_METHOD_POST, etc).
2657  *
2658  * The callback must call MHD function MHD_queue_response() to provide content
2659  * to give back to the client and return an HTTP status code (i.e.
2660  * #MHD_HTTP_OK, #MHD_HTTP_NOT_FOUND, etc.). The response can be created
2661  * in this callback or prepared in advance.
2662  * Alternatively, callback may call MHD_suspend_connection() to temporarily
2663  * suspend data processing for this connection.
2664  *
2665  * As soon as response is provided this callback will not be called anymore
2666  * for the current request.
2667  *
2668  * For each HTTP request this callback is called several times:
2669  * * after request headers are fully received and decoded,
2670  * * for each received part of request body (optional, if request has body),
2671  * * when request is fully received.
2672  *
2673  * If response is provided before request is fully received, the rest
2674  * of the request is discarded and connection is automatically closed
2675  * after sending response.
2676  *
2677  * If the request is fully received, but response hasn't been provided and
2678  * connection is not suspended, the callback can be called again immediately.
2679  *
2680  * The response cannot be queued when this callback is called to process
2681  * the client upload data (when @a upload_data is not NULL).
2682  *
2683  * @param cls argument given together with the function
2684  *        pointer when the handler was registered with MHD
2685  * @param connection the connection handle
2686  * @param url the requested url
2687  * @param method the HTTP method used (#MHD_HTTP_METHOD_GET,
2688  *        #MHD_HTTP_METHOD_PUT, etc.)
2689  * @param version the HTTP version string (i.e.
2690  *        #MHD_HTTP_VERSION_1_1)
2691  * @param upload_data the data being uploaded (excluding HEADERS,
2692  *        for a POST that fits into memory and that is encoded
2693  *        with a supported encoding, the POST data will NOT be
2694  *        given in upload_data and is instead available as
2695  *        part of #MHD_get_connection_values; very large POST
2696  *        data *will* be made available incrementally in
2697  *        @a upload_data)
2698  * @param[in,out] upload_data_size set initially to the size of the
2699  *        @a upload_data provided; the method must update this
2700  *        value to the number of bytes NOT processed;
2701  * @param[in,out] req_cls pointer that the callback can set to some
2702  *        address and that will be preserved by MHD for future
2703  *        calls for this request; since the access handler may
2704  *        be called many times (i.e., for a PUT/POST operation
2705  *        with plenty of upload data) this allows the application
2706  *        to easily associate some request-specific state.
2707  *        If necessary, this state can be cleaned up in the
2708  *        global #MHD_RequestCompletedCallback (which
2709  *        can be set with the #MHD_OPTION_NOTIFY_COMPLETED).
2710  *        Initially, `*req_cls` will be NULL.
2711  * @return #MHD_YES if the connection was handled successfully,
2712  *         #MHD_NO if the socket must be closed due to a serious
2713  *         error while handling the request
2714  *
2715  * @sa #MHD_queue_response()
2716  */
2717 typedef enum MHD_Result
2718 (*MHD_AccessHandlerCallback)(void *cls,
2719                              struct MHD_Connection *connection,
2720                              const char *url,
2721                              const char *method,
2722                              const char *version,
2723                              const char *upload_data,
2724                              size_t *upload_data_size,
2725                              void **req_cls);
2726 
2727 
2728 /**
2729  * Signature of the callback used by MHD to notify the
2730  * application about completed requests.
2731  *
2732  * @param cls client-defined closure
2733  * @param connection connection handle
2734  * @param req_cls value as set by the last call to
2735  *        the #MHD_AccessHandlerCallback
2736  * @param toe reason for request termination
2737  * @see #MHD_OPTION_NOTIFY_COMPLETED
2738  * @ingroup request
2739  */
2740 typedef void
2741 (*MHD_RequestCompletedCallback) (void *cls,
2742                                  struct MHD_Connection *connection,
2743                                  void **req_cls,
2744                                  enum MHD_RequestTerminationCode toe);
2745 
2746 
2747 /**
2748  * Signature of the callback used by MHD to notify the
2749  * application about started/stopped connections
2750  *
2751  * @param cls client-defined closure
2752  * @param connection connection handle
2753  * @param socket_context socket-specific pointer where the
2754  *                       client can associate some state specific
2755  *                       to the TCP connection; note that this is
2756  *                       different from the "req_cls" which is per
2757  *                       HTTP request.  The client can initialize
2758  *                       during #MHD_CONNECTION_NOTIFY_STARTED and
2759  *                       cleanup during #MHD_CONNECTION_NOTIFY_CLOSED
2760  *                       and access in the meantime using
2761  *                       #MHD_CONNECTION_INFO_SOCKET_CONTEXT.
2762  * @param toe reason for connection notification
2763  * @see #MHD_OPTION_NOTIFY_CONNECTION
2764  * @ingroup request
2765  */
2766 typedef void
2767 (*MHD_NotifyConnectionCallback) (void *cls,
2768                                  struct MHD_Connection *connection,
2769                                  void **socket_context,
2770                                  enum MHD_ConnectionNotificationCode toe);
2771 
2772 
2773 /**
2774  * Iterator over key-value pairs.  This iterator
2775  * can be used to iterate over all of the cookies,
2776  * headers, or POST-data fields of a request, and
2777  * also to iterate over the headers that have been
2778  * added to a response.
2779  *
2780  * @param cls closure
2781  * @param kind kind of the header we are looking at
2782  * @param key key for the value, can be an empty string
2783  * @param value corresponding value, can be NULL
2784  * @return #MHD_YES to continue iterating,
2785  *         #MHD_NO to abort the iteration
2786  * @ingroup request
2787  */
2788 typedef enum MHD_Result
2789 (*MHD_KeyValueIterator)(void *cls,
2790                         enum MHD_ValueKind kind,
2791                         const char *key,
2792                         const char *value);
2793 
2794 
2795 /**
2796  * Iterator over key-value pairs with size parameters.
2797  * This iterator can be used to iterate over all of
2798  * the cookies, headers, or POST-data fields of a
2799  * request, and also to iterate over the headers that
2800  * have been added to a response.
2801  * @note Available since #MHD_VERSION 0x00096303
2802  *
2803  * @param cls closure
2804  * @param kind kind of the header we are looking at
2805  * @param key key for the value, can be an empty string
2806  * @param value corresponding value, can be NULL
2807  * @param value_size number of bytes in @a value;
2808  *                   for C-strings, the length excludes the 0-terminator
2809  * @return #MHD_YES to continue iterating,
2810  *         #MHD_NO to abort the iteration
2811  * @ingroup request
2812  */
2813 typedef enum MHD_Result
2814 (*MHD_KeyValueIteratorN)(void *cls,
2815                          enum MHD_ValueKind kind,
2816                          const char *key,
2817                          size_t key_size,
2818                          const char *value,
2819                          size_t value_size);
2820 
2821 
2822 /**
2823  * Callback used by libmicrohttpd in order to obtain content.
2824  *
2825  * The callback is to copy at most @a max bytes of content into @a buf.
2826  * The total number of bytes that has been placed into @a buf should be
2827  * returned.
2828  *
2829  * Note that returning zero will cause libmicrohttpd to try again.
2830  * Thus, returning zero should only be used in conjunction
2831  * with MHD_suspend_connection() to avoid busy waiting.
2832  *
2833  * @param cls extra argument to the callback
2834  * @param pos position in the datastream to access;
2835  *        note that if a `struct MHD_Response` object is re-used,
2836  *        it is possible for the same content reader to
2837  *        be queried multiple times for the same data;
2838  *        however, if a `struct MHD_Response` is not re-used,
2839  *        libmicrohttpd guarantees that "pos" will be
2840  *        the sum of all non-negative return values
2841  *        obtained from the content reader so far.
2842  * @param buf where to copy the data
2843  * @param max maximum number of bytes to copy to @a buf (size of @a buf)
2844  * @return number of bytes written to @a buf;
2845  *  0 is legal unless MHD is started in "internal" sockets polling mode
2846  *    (since this would cause busy-waiting); 0 in "external" sockets
2847  *    polling mode will cause this function to be called again once
2848  *    any MHD_run*() function is called;
2849  *  #MHD_CONTENT_READER_END_OF_STREAM (-1) for the regular
2850  *    end of transmission (with chunked encoding, MHD will then
2851  *    terminate the chunk and send any HTTP footers that might be
2852  *    present; without chunked encoding and given an unknown
2853  *    response size, MHD will simply close the connection; note
2854  *    that while returning #MHD_CONTENT_READER_END_OF_STREAM is not technically
2855  *    legal if a response size was specified, MHD accepts this
2856  *    and treats it just as #MHD_CONTENT_READER_END_WITH_ERROR;
2857  *  #MHD_CONTENT_READER_END_WITH_ERROR (-2) to indicate a server
2858  *    error generating the response; this will cause MHD to simply
2859  *    close the connection immediately.  If a response size was
2860  *    given or if chunked encoding is in use, this will indicate
2861  *    an error to the client.  Note, however, that if the client
2862  *    does not know a response size and chunked encoding is not in
2863  *    use, then clients will not be able to tell the difference between
2864  *    #MHD_CONTENT_READER_END_WITH_ERROR and #MHD_CONTENT_READER_END_OF_STREAM.
2865  *    This is not a limitation of MHD but rather of the HTTP protocol.
2866  */
2867 typedef ssize_t
2868 (*MHD_ContentReaderCallback) (void *cls,
2869                               uint64_t pos,
2870                               char *buf,
2871                               size_t max);
2872 
2873 
2874 /**
2875  * This method is called by libmicrohttpd if we
2876  * are done with a content reader.  It should
2877  * be used to free resources associated with the
2878  * content reader.
2879  *
2880  * @param cls closure
2881  * @ingroup response
2882  */
2883 typedef void
2884 (*MHD_ContentReaderFreeCallback) (void *cls);
2885 
2886 
2887 /**
2888  * Iterator over key-value pairs where the value
2889  * may be made available in increments and/or may
2890  * not be zero-terminated.  Used for processing
2891  * POST data.
2892  *
2893  * @param cls user-specified closure
2894  * @param kind type of the value, always #MHD_POSTDATA_KIND when called from MHD
2895  * @param key 0-terminated key for the value, NULL if not known. This value
2896  *            is never NULL for url-encoded POST data.
2897  * @param filename name of the uploaded file, NULL if not known
2898  * @param content_type mime-type of the data, NULL if not known
2899  * @param transfer_encoding encoding of the data, NULL if not known
2900  * @param data pointer to @a size bytes of data at the
2901  *              specified offset
2902  * @param off offset of data in the overall value
2903  * @param size number of bytes in @a data available
2904  * @return #MHD_YES to continue iterating,
2905  *         #MHD_NO to abort the iteration
2906  */
2907 typedef enum MHD_Result
2908 (*MHD_PostDataIterator)(void *cls,
2909                         enum MHD_ValueKind kind,
2910                         const char *key,
2911                         const char *filename,
2912                         const char *content_type,
2913                         const char *transfer_encoding,
2914                         const char *data,
2915                         uint64_t off,
2916                         size_t size);
2917 
2918 /* **************** Daemon handling functions ***************** */
2919 
2920 /**
2921  * Start a webserver on the given port.
2922  *
2923  * @param flags combination of `enum MHD_FLAG` values
2924  * @param port port to bind to (in host byte order),
2925  *        use '0' to bind to random free port,
2926  *        ignored if MHD_OPTION_SOCK_ADDR or
2927  *        MHD_OPTION_LISTEN_SOCKET is provided
2928  *        or MHD_USE_NO_LISTEN_SOCKET is specified
2929  * @param apc callback to call to check which clients
2930  *        will be allowed to connect; you can pass NULL
2931  *        in which case connections from any IP will be
2932  *        accepted
2933  * @param apc_cls extra argument to apc
2934  * @param dh handler called for all requests (repeatedly)
2935  * @param dh_cls extra argument to @a dh
2936  * @param ap list of options (type-value pairs,
2937  *        terminated with #MHD_OPTION_END).
2938  * @return NULL on error, handle to daemon on success
2939  * @ingroup event
2940  */
2941 _MHD_EXTERN struct MHD_Daemon *
2942 MHD_start_daemon_va (unsigned int flags,
2943                      uint16_t port,
2944                      MHD_AcceptPolicyCallback apc, void *apc_cls,
2945                      MHD_AccessHandlerCallback dh, void *dh_cls,
2946                      va_list ap);
2947 
2948 
2949 /**
2950  * Start a webserver on the given port.  Variadic version of
2951  * #MHD_start_daemon_va.
2952  *
2953  * @param flags combination of `enum MHD_FLAG` values
2954  * @param port port to bind to (in host byte order),
2955  *        use '0' to bind to random free port,
2956  *        ignored if MHD_OPTION_SOCK_ADDR or
2957  *        MHD_OPTION_LISTEN_SOCKET is provided
2958  *        or MHD_USE_NO_LISTEN_SOCKET is specified
2959  * @param apc callback to call to check which clients
2960  *        will be allowed to connect; you can pass NULL
2961  *        in which case connections from any IP will be
2962  *        accepted
2963  * @param apc_cls extra argument to apc
2964  * @param dh handler called for all requests (repeatedly)
2965  * @param dh_cls extra argument to @a dh
2966  * @return NULL on error, handle to daemon on success
2967  * @ingroup event
2968  */
2969 _MHD_EXTERN struct MHD_Daemon *
2970 MHD_start_daemon (unsigned int flags,
2971                   uint16_t port,
2972                   MHD_AcceptPolicyCallback apc, void *apc_cls,
2973                   MHD_AccessHandlerCallback dh, void *dh_cls,
2974                   ...);
2975 
2976 
2977 /**
2978  * Stop accepting connections from the listening socket.  Allows
2979  * clients to continue processing, but stops accepting new
2980  * connections.  Note that the caller is responsible for closing the
2981  * returned socket; however, if MHD is run using threads (anything but
2982  * "external" sockets polling mode), it must not be closed until AFTER
2983  * #MHD_stop_daemon has been called (as it is theoretically possible
2984  * that an existing thread is still using it).
2985  *
2986  * Note that some thread modes require the caller to have passed
2987  * #MHD_USE_ITC when using this API.  If this daemon is
2988  * in one of those modes and this option was not given to
2989  * #MHD_start_daemon, this function will return #MHD_INVALID_SOCKET.
2990  *
2991  * @param daemon daemon to stop accepting new connections for
2992  * @return old listen socket on success, #MHD_INVALID_SOCKET if
2993  *         the daemon was already not listening anymore
2994  * @ingroup specialized
2995  */
2996 _MHD_EXTERN MHD_socket
2997 MHD_quiesce_daemon (struct MHD_Daemon *daemon);
2998 
2999 
3000 /**
3001  * Shutdown an HTTP daemon.
3002  *
3003  * @param daemon daemon to stop
3004  * @ingroup event
3005  */
3006 _MHD_EXTERN void
3007 MHD_stop_daemon (struct MHD_Daemon *daemon);
3008 
3009 
3010 /**
3011  * Add another client connection to the set of connections managed by
3012  * MHD.  This API is usually not needed (since MHD will accept inbound
3013  * connections on the server socket).  Use this API in special cases,
3014  * for example if your HTTP server is behind NAT and needs to connect
3015  * out to the HTTP client, or if you are building a proxy.
3016  *
3017  * If you use this API in conjunction with an "internal" socket polling,
3018  * you must set the option #MHD_USE_ITC to ensure that the freshly added
3019  * connection is immediately processed by MHD.
3020  *
3021  * The given client socket will be managed (and closed!) by MHD after
3022  * this call and must no longer be used directly by the application
3023  * afterwards.
3024  *
3025  * @param daemon daemon that manages the connection
3026  * @param client_socket socket to manage (MHD will expect
3027  *        to receive an HTTP request from this socket next).
3028  * @param addr IP address of the client
3029  * @param addrlen number of bytes in @a addr
3030  * @return #MHD_YES on success, #MHD_NO if this daemon could
3031  *        not handle the connection (i.e. `malloc()` failed, etc).
3032  *        The socket will be closed in any case; `errno` is
3033  *        set to indicate further details about the error.
3034  * @ingroup specialized
3035  */
3036 _MHD_EXTERN enum MHD_Result
3037 MHD_add_connection (struct MHD_Daemon *daemon,
3038                     MHD_socket client_socket,
3039                     const struct sockaddr *addr,
3040                     socklen_t addrlen);
3041 
3042 
3043 /**
3044  * Obtain the `select()` sets for this daemon.
3045  * Daemon's FDs will be added to fd_sets. To get only
3046  * daemon FDs in fd_sets, call FD_ZERO for each fd_set
3047  * before calling this function. FD_SETSIZE is assumed
3048  * to be platform's default.
3049  *
3050  * This function should be called only when MHD is configured to
3051  * use "external" sockets polling with 'select()' or with 'epoll'.
3052  * In the latter case, it will only add the single 'epoll' file
3053  * descriptor used by MHD to the sets.
3054  * It's necessary to use #MHD_get_timeout() to get maximum timeout
3055  * value for `select()`. Usage of `select()` with indefinite timeout
3056  * (or timeout larger than returned by #MHD_get_timeout()) will
3057  * violate MHD API and may results in pending unprocessed data.
3058  *
3059  * This function must be called only for daemon started
3060  * without #MHD_USE_INTERNAL_POLLING_THREAD flag.
3061  *
3062  * @param daemon daemon to get sets from
3063  * @param read_fd_set read set
3064  * @param write_fd_set write set
3065  * @param except_fd_set except set
3066  * @param max_fd increased to largest FD added (if larger
3067  *               than existing value); can be NULL
3068  * @return #MHD_YES on success, #MHD_NO if this
3069  *         daemon was not started with the right
3070  *         options for this call or any FD didn't
3071  *         fit fd_set.
3072  * @ingroup event
3073  */
3074 _MHD_EXTERN enum MHD_Result
3075 MHD_get_fdset (struct MHD_Daemon *daemon,
3076                fd_set *read_fd_set,
3077                fd_set *write_fd_set,
3078                fd_set *except_fd_set,
3079                MHD_socket *max_fd);
3080 
3081 
3082 /**
3083  * Obtain the `select()` sets for this daemon.
3084  * Daemon's FDs will be added to fd_sets. To get only
3085  * daemon FDs in fd_sets, call FD_ZERO for each fd_set
3086  * before calling this function.
3087  *
3088  * Passing custom FD_SETSIZE as @a fd_setsize allow usage of
3089  * larger/smaller than platform's default fd_sets.
3090  *
3091  * This function should be called only when MHD is configured to
3092  * use "external" sockets polling with 'select()' or with 'epoll'.
3093  * In the latter case, it will only add the single 'epoll' file
3094  * descriptor used by MHD to the sets.
3095  * It's necessary to use #MHD_get_timeout() to get maximum timeout
3096  * value for `select()`. Usage of `select()` with indefinite timeout
3097  * (or timeout larger than returned by #MHD_get_timeout()) will
3098  * violate MHD API and may results in pending unprocessed data.
3099  *
3100  * This function must be called only for daemon started
3101  * without #MHD_USE_INTERNAL_POLLING_THREAD flag.
3102  *
3103  * @param daemon daemon to get sets from
3104  * @param read_fd_set read set
3105  * @param write_fd_set write set
3106  * @param except_fd_set except set
3107  * @param max_fd increased to largest FD added (if larger
3108  *               than existing value); can be NULL
3109  * @param fd_setsize value of FD_SETSIZE
3110  * @return #MHD_YES on success, #MHD_NO if this
3111  *         daemon was not started with the right
3112  *         options for this call or any FD didn't
3113  *         fit fd_set.
3114  * @ingroup event
3115  */
3116 _MHD_EXTERN enum MHD_Result
3117 MHD_get_fdset2 (struct MHD_Daemon *daemon,
3118                 fd_set *read_fd_set,
3119                 fd_set *write_fd_set,
3120                 fd_set *except_fd_set,
3121                 MHD_socket *max_fd,
3122                 unsigned int fd_setsize);
3123 
3124 
3125 /**
3126  * Obtain the `select()` sets for this daemon.
3127  * Daemon's FDs will be added to fd_sets. To get only
3128  * daemon FDs in fd_sets, call FD_ZERO for each fd_set
3129  * before calling this function. Size of fd_set is
3130  * determined by current value of FD_SETSIZE.
3131  *
3132  * This function should be called only when MHD is configured to
3133  * use "external" sockets polling with 'select()' or with 'epoll'.
3134  * In the latter case, it will only add the single 'epoll' file
3135  * descriptor used by MHD to the sets.
3136  * It's necessary to use #MHD_get_timeout() to get maximum timeout
3137  * value for `select()`. Usage of `select()` with indefinite timeout
3138  * (or timeout larger than returned by #MHD_get_timeout()) will
3139  * violate MHD API and may results in pending unprocessed data.
3140  *
3141  * This function must be called only for daemon started
3142  * without #MHD_USE_INTERNAL_POLLING_THREAD flag.
3143  *
3144  * @param daemon daemon to get sets from
3145  * @param read_fd_set read set
3146  * @param write_fd_set write set
3147  * @param except_fd_set except set
3148  * @param max_fd increased to largest FD added (if larger
3149  *               than existing value); can be NULL
3150  * @return #MHD_YES on success, #MHD_NO if this
3151  *         daemon was not started with the right
3152  *         options for this call or any FD didn't
3153  *         fit fd_set.
3154  * @ingroup event
3155  */
3156 #define MHD_get_fdset(daemon,read_fd_set,write_fd_set,except_fd_set,max_fd) \
3157   MHD_get_fdset2 ((daemon),(read_fd_set),(write_fd_set),(except_fd_set), \
3158                   (max_fd),FD_SETSIZE)
3159 
3160 
3161 /**
3162  * Obtain timeout value for polling function for this daemon.
3163  *
3164  * This function set value to the amount of milliseconds for which polling
3165  * function (`select()`, `poll()` or epoll) should at most block, not the
3166  * timeout value set for connections.
3167  *
3168  * Any "external" sockets polling function must be called with the timeout
3169  * value provided by this function. Smaller timeout values can be used for
3170  * polling function if it is required for any reason, but using larger
3171  * timeout value or no timeout (indefinite timeout) when this function
3172  * return #MHD_YES will break MHD processing logic and result in "hung"
3173  * connections with data pending in network buffers and other problems.
3174  *
3175  * It is important to always use this function (or #MHD_get_timeout64(),
3176  * #MHD_get_timeout64s(), #MHD_get_timeout_i() functions) when "external"
3177  * polling is used.
3178  * If this function returns #MHD_YES then #MHD_run() (or #MHD_run_from_select())
3179  * must be called right after return from polling function, regardless of
3180  * the states of MHD FDs.
3181  *
3182  * In practice, if #MHD_YES is returned then #MHD_run() (or
3183  * #MHD_run_from_select()) must be called not later than @a timeout
3184  * millisecond even if no activity is detected on sockets by sockets
3185  * polling function.
3186  *
3187  * @param daemon daemon to query for timeout
3188  * @param[out] timeout set to the timeout (in milliseconds)
3189  * @return #MHD_YES on success, #MHD_NO if timeouts are
3190  *         not used and no data processing is pending.
3191  * @ingroup event
3192  */
3193 _MHD_EXTERN enum MHD_Result
3194 MHD_get_timeout (struct MHD_Daemon *daemon,
3195                  MHD_UNSIGNED_LONG_LONG *timeout);
3196 
3197 
3198 /**
3199  * Free the memory allocated by MHD.
3200  *
3201  * If any MHD function explicitly mentions that returned pointer must be
3202  * freed by this function, then no other method must be used to free
3203  * the memory.
3204  *
3205  * @param ptr the pointer to free.
3206  * @sa #MHD_digest_auth_get_username(), #MHD_basic_auth_get_username_password3()
3207  * @sa #MHD_basic_auth_get_username_password()
3208  * @note Available since #MHD_VERSION 0x00095600
3209  * @ingroup specialized
3210  */
3211 _MHD_EXTERN void
3212 MHD_free (void *ptr);
3213 
3214 /**
3215  * Obtain timeout value for external polling function for this daemon.
3216  *
3217  * This function set value to the amount of milliseconds for which polling
3218  * function (`select()`, `poll()` or epoll) should at most block, not the
3219  * timeout value set for connections.
3220  *
3221  * Any "external" sockets polling function must be called with the timeout
3222  * value provided by this function. Smaller timeout values can be used for
3223  * polling function if it is required for any reason, but using larger
3224  * timeout value or no timeout (indefinite timeout) when this function
3225  * return #MHD_YES will break MHD processing logic and result in "hung"
3226  * connections with data pending in network buffers and other problems.
3227  *
3228  * It is important to always use this function (or #MHD_get_timeout(),
3229  * #MHD_get_timeout64s(), #MHD_get_timeout_i() functions) when "external"
3230  * polling is used.
3231  * If this function returns #MHD_YES then #MHD_run() (or #MHD_run_from_select())
3232  * must be called right after return from polling function, regardless of
3233  * the states of MHD FDs.
3234  *
3235  * In practice, if #MHD_YES is returned then #MHD_run() (or
3236  * #MHD_run_from_select()) must be called not later than @a timeout
3237  * millisecond even if no activity is detected on sockets by sockets
3238  * polling function.
3239  *
3240  * @param daemon daemon to query for timeout
3241  * @param[out] timeout64 the pointer to the variable to be set to the
3242  *                  timeout (in milliseconds)
3243  * @return #MHD_YES if timeout value has been set,
3244  *         #MHD_NO if timeouts are not used and no data processing is pending.
3245  * @note Available since #MHD_VERSION 0x00097701
3246  * @ingroup event
3247  */
3248 _MHD_EXTERN enum MHD_Result
3249 MHD_get_timeout64 (struct MHD_Daemon *daemon,
3250                    uint64_t *timeout);
3251 
3252 
3253 /**
3254  * Obtain timeout value for external polling function for this daemon.
3255  *
3256  * This function set value to the amount of milliseconds for which polling
3257  * function (`select()`, `poll()` or epoll) should at most block, not the
3258  * timeout value set for connections.
3259  *
3260  * Any "external" sockets polling function must be called with the timeout
3261  * value provided by this function (if returned value is non-negative).
3262  * Smaller timeout values can be used for polling function if it is required
3263  * for any reason, but using larger timeout value or no timeout (indefinite
3264  * timeout) when this function returns non-negative value will break MHD
3265  * processing logic and result in "hung" connections with data pending in
3266  * network buffers and other problems.
3267  *
3268  * It is important to always use this function (or #MHD_get_timeout(),
3269  * #MHD_get_timeout64(), #MHD_get_timeout_i() functions) when "external"
3270  * polling is used.
3271  * If this function returns non-negative value then #MHD_run() (or
3272  * #MHD_run_from_select()) must be called right after return from polling
3273  * function, regardless of the states of MHD FDs.
3274  *
3275  * In practice, if zero or positive value is returned then #MHD_run() (or
3276  * #MHD_run_from_select()) must be called not later than returned amount of
3277  * millisecond even if no activity is detected on sockets by sockets
3278  * polling function.
3279  *
3280  * @param daemon the daemon to query for timeout
3281  * @return -1 if connections' timeouts are not set and no data processing
3282  *         is pending, so external polling function may wait for sockets
3283  *         activity for indefinite amount of time,
3284  *         otherwise returned value is the the maximum amount of millisecond
3285  *         that external polling function must wait for the activity of FDs.
3286  * @note Available since #MHD_VERSION 0x00097701
3287  * @ingroup event
3288  */
3289 _MHD_EXTERN int64_t
3290 MHD_get_timeout64s (struct MHD_Daemon *daemon);
3291 
3292 
3293 /**
3294  * Obtain timeout value for external polling function for this daemon.
3295  *
3296  * This function set value to the amount of milliseconds for which polling
3297  * function (`select()`, `poll()` or epoll) should at most block, not the
3298  * timeout value set for connections.
3299  *
3300  * Any "external" sockets polling function must be called with the timeout
3301  * value provided by this function (if returned value is non-negative).
3302  * Smaller timeout values can be used for polling function if it is required
3303  * for any reason, but using larger timeout value or no timeout (indefinite
3304  * timeout) when this function returns non-negative value will break MHD
3305  * processing logic and result in "hung" connections with data pending in
3306  * network buffers and other problems.
3307  *
3308  * It is important to always use this function (or #MHD_get_timeout(),
3309  * #MHD_get_timeout64(), #MHD_get_timeout64s() functions) when "external"
3310  * polling is used.
3311  * If this function returns non-negative value then #MHD_run() (or
3312  * #MHD_run_from_select()) must be called right after return from polling
3313  * function, regardless of the states of MHD FDs.
3314  *
3315  * In practice, if zero or positive value is returned then #MHD_run() (or
3316  * #MHD_run_from_select()) must be called not later than returned amount of
3317  * millisecond even if no activity is detected on sockets by sockets
3318  * polling function.
3319  *
3320  * @param daemon the daemon to query for timeout
3321  * @return -1 if connections' timeouts are not set and no data processing
3322  *         is pending, so external polling function may wait for sockets
3323  *         activity for indefinite amount of time,
3324  *         otherwise returned value is the the maximum amount of millisecond
3325  *         (capped at INT_MAX) that external polling function must wait
3326  *         for the activity of FDs.
3327  * @note Available since #MHD_VERSION 0x00097701
3328  * @ingroup event
3329  */
3330 _MHD_EXTERN int
3331 MHD_get_timeout_i (struct MHD_Daemon *daemon);
3332 
3333 
3334 /**
3335  * Run webserver operations (without blocking unless in client callbacks).
3336  *
3337  * This method should be called by clients in combination with
3338  * #MHD_get_fdset() (or #MHD_get_daemon_info() with MHD_DAEMON_INFO_EPOLL_FD
3339  * if epoll is used) and #MHD_get_timeout() if the client-controlled
3340  * connection polling method is used (i.e. daemon was started without
3341  * #MHD_USE_INTERNAL_POLLING_THREAD flag).
3342  *
3343  * This function is a convenience method, which is useful if the
3344  * fd_sets from #MHD_get_fdset were not directly passed to `select()`;
3345  * with this function, MHD will internally do the appropriate `select()`
3346  * call itself again.  While it is acceptable to call #MHD_run (if
3347  * #MHD_USE_INTERNAL_POLLING_THREAD is not set) at any moment, you should
3348  * call #MHD_run_from_select() if performance is important (as it saves an
3349  * expensive call to `select()`).
3350  *
3351  * If #MHD_get_timeout() returned #MHD_YES, than this function must be called
3352  * right after polling function returns regardless of detected activity on
3353  * the daemon's FDs.
3354  *
3355  * @param daemon daemon to run
3356  * @return #MHD_YES on success, #MHD_NO if this
3357  *         daemon was not started with the right
3358  *         options for this call.
3359  * @ingroup event
3360  */
3361 _MHD_EXTERN enum MHD_Result
3362 MHD_run (struct MHD_Daemon *daemon);
3363 
3364 
3365 /**
3366  * Run websever operation with possible blocking.
3367  *
3368  * This function does the following: waits for any network event not more than
3369  * specified number of milliseconds, processes all incoming and outgoing data,
3370  * processes new connections, processes any timed-out connection, and does
3371  * other things required to run webserver.
3372  * Once all connections are processed, function returns.
3373  *
3374  * This function is useful for quick and simple (lazy) webserver implementation
3375  * if application needs to run a single thread only and does not have any other
3376  * network activity.
3377  *
3378  * This function calls MHD_get_timeout() internally and use returned value as
3379  * maximum wait time if it less than value of @a millisec parameter.
3380  *
3381  * It is expected that the "external" socket polling function is not used in
3382  * conjunction with this function unless the @a millisec is set to zero.
3383  *
3384  * @param daemon the daemon to run
3385  * @param millisec the maximum time in milliseconds to wait for network and
3386  *                 other events. Note: there is no guarantee that function
3387  *                 blocks for the specified amount of time. The real processing
3388  *                 time can be shorter (if some data or connection timeout
3389  *                 comes earlier) or longer (if data processing requires more
3390  *                 time, especially in user callbacks).
3391  *                 If set to '0' then function does not block and processes
3392  *                 only already available data (if any).
3393  *                 If set to '-1' then function waits for events
3394  *                 indefinitely (blocks until next network activity or
3395  *                 connection timeout).
3396  * @return #MHD_YES on success, #MHD_NO if this
3397  *         daemon was not started with the right
3398  *         options for this call or some serious
3399  *         unrecoverable error occurs.
3400  * @note Available since #MHD_VERSION 0x00097206
3401  * @ingroup event
3402  */
3403 _MHD_EXTERN enum MHD_Result
3404 MHD_run_wait (struct MHD_Daemon *daemon,
3405               int32_t millisec);
3406 
3407 
3408 /**
3409  * Run webserver operations. This method should be called by clients
3410  * in combination with #MHD_get_fdset and #MHD_get_timeout() if the
3411  * client-controlled select method is used.
3412  *
3413  * You can use this function instead of #MHD_run if you called
3414  * `select()` on the result from #MHD_get_fdset.  File descriptors in
3415  * the sets that are not controlled by MHD will be ignored.  Calling
3416  * this function instead of #MHD_run is more efficient as MHD will
3417  * not have to call `select()` again to determine which operations are
3418  * ready.
3419  *
3420  * If #MHD_get_timeout() returned #MHD_YES, than this function must be
3421  * called right after `select()` returns regardless of detected activity
3422  * on the daemon's FDs.
3423  *
3424  * This function cannot be used with daemon started with
3425  * #MHD_USE_INTERNAL_POLLING_THREAD flag.
3426  *
3427  * @param daemon daemon to run select loop for
3428  * @param read_fd_set read set
3429  * @param write_fd_set write set
3430  * @param except_fd_set except set
3431  * @return #MHD_NO on serious errors, #MHD_YES on success
3432  * @ingroup event
3433  */
3434 _MHD_EXTERN enum MHD_Result
3435 MHD_run_from_select (struct MHD_Daemon *daemon,
3436                      const fd_set *read_fd_set,
3437                      const fd_set *write_fd_set,
3438                      const fd_set *except_fd_set);
3439 
3440 
3441 /**
3442  * Run webserver operations. This method should be called by clients
3443  * in combination with #MHD_get_fdset and #MHD_get_timeout() if the
3444  * client-controlled select method is used.
3445  * This function specifies FD_SETSIZE used when provided fd_sets were
3446  * created. It is important on platforms where FD_SETSIZE can be
3447  * overridden.
3448  *
3449  * You can use this function instead of #MHD_run if you called
3450  * 'select()' on the result from #MHD_get_fdset2().  File descriptors in
3451  * the sets that are not controlled by MHD will be ignored.  Calling
3452  * this function instead of #MHD_run() is more efficient as MHD will
3453  * not have to call 'select()' again to determine which operations are
3454  * ready.
3455  *
3456  * If #MHD_get_timeout() returned #MHD_YES, than this function must be
3457  * called right after 'select()' returns regardless of detected activity
3458  * on the daemon's FDs.
3459  *
3460  * This function cannot be used with daemon started with
3461  * #MHD_USE_INTERNAL_POLLING_THREAD flag.
3462  *
3463  * @param daemon the daemon to run select loop for
3464  * @param read_fd_set the read set
3465  * @param write_fd_set the write set
3466  * @param except_fd_set the except set
3467  * @param fd_setsize the value of FD_SETSIZE
3468  * @return #MHD_NO on serious errors, #MHD_YES on success
3469  * @sa #MHD_get_fdset2(), #MHD_OPTION_APP_FD_SETSIZE
3470  * @ingroup event
3471  */
3472 _MHD_EXTERN enum MHD_Result
3473 MHD_run_from_select2 (struct MHD_Daemon *daemon,
3474                       const fd_set *read_fd_set,
3475                       const fd_set *write_fd_set,
3476                       const fd_set *except_fd_set,
3477                       unsigned int fd_setsize);
3478 
3479 
3480 /**
3481  * Run webserver operations. This method should be called by clients
3482  * in combination with #MHD_get_fdset and #MHD_get_timeout() if the
3483  * client-controlled select method is used.
3484  * This macro automatically substitutes current FD_SETSIZE value.
3485  * It is important on platforms where FD_SETSIZE can be overridden.
3486  *
3487  * You can use this function instead of #MHD_run if you called
3488  * 'select()' on the result from #MHD_get_fdset2().  File descriptors in
3489  * the sets that are not controlled by MHD will be ignored.  Calling
3490  * this function instead of #MHD_run() is more efficient as MHD will
3491  * not have to call 'select()' again to determine which operations are
3492  * ready.
3493  *
3494  * If #MHD_get_timeout() returned #MHD_YES, than this function must be
3495  * called right after 'select()' returns regardless of detected activity
3496  * on the daemon's FDs.
3497  *
3498  * This function cannot be used with daemon started with
3499  * #MHD_USE_INTERNAL_POLLING_THREAD flag.
3500  *
3501  * @param daemon the daemon to run select loop for
3502  * @param read_fd_set the read set
3503  * @param write_fd_set the write set
3504  * @param except_fd_set the except set
3505  * @param fd_setsize the value of FD_SETSIZE
3506  * @return #MHD_NO on serious errors, #MHD_YES on success
3507  * @sa #MHD_get_fdset2(), #MHD_OPTION_APP_FD_SETSIZE
3508  * @ingroup event
3509  */
3510 #define MHD_run_from_select(d,r,w,e) \
3511   MHD_run_from_select2((d),(r),(w),(e),(unsigned int)(FD_SETSIZE))
3512 
3513 /* **************** Connection handling functions ***************** */
3514 
3515 /**
3516  * Get all of the headers from the request.
3517  *
3518  * @param connection connection to get values from
3519  * @param kind types of values to iterate over, can be a bitmask
3520  * @param iterator callback to call on each header;
3521  *        may be NULL (then just count headers)
3522  * @param iterator_cls extra argument to @a iterator
3523  * @return number of entries iterated over,
3524  *         -1 if connection is NULL.
3525  * @ingroup request
3526  */
3527 _MHD_EXTERN int
3528 MHD_get_connection_values (struct MHD_Connection *connection,
3529                            enum MHD_ValueKind kind,
3530                            MHD_KeyValueIterator iterator,
3531                            void *iterator_cls);
3532 
3533 
3534 /**
3535  * Get all of the headers from the request.
3536  *
3537  * @param connection connection to get values from
3538  * @param kind types of values to iterate over, can be a bitmask
3539  * @param iterator callback to call on each header;
3540  *        may be NULL (then just count headers)
3541  * @param iterator_cls extra argument to @a iterator
3542  * @return number of entries iterated over,
3543  *         -1 if connection is NULL.
3544  * @note Available since #MHD_VERSION 0x00096400
3545  * @ingroup request
3546  */
3547 _MHD_EXTERN int
3548 MHD_get_connection_values_n (struct MHD_Connection *connection,
3549                              enum MHD_ValueKind kind,
3550                              MHD_KeyValueIteratorN iterator,
3551                              void *iterator_cls);
3552 
3553 
3554 /**
3555  * This function can be used to add an entry to the HTTP headers of a
3556  * connection (so that the #MHD_get_connection_values function will
3557  * return them -- and the `struct MHD_PostProcessor` will also see
3558  * them).  This maybe required in certain situations (see Mantis
3559  * #1399) where (broken) HTTP implementations fail to supply values
3560  * needed by the post processor (or other parts of the application).
3561  *
3562  * This function MUST only be called from within the
3563  * #MHD_AccessHandlerCallback (otherwise, access maybe improperly
3564  * synchronized).  Furthermore, the client must guarantee that the key
3565  * and value arguments are 0-terminated strings that are NOT freed
3566  * until the connection is closed.  (The easiest way to do this is by
3567  * passing only arguments to permanently allocated strings.).
3568  *
3569  * @param connection the connection for which a
3570  *  value should be set
3571  * @param kind kind of the value
3572  * @param key key for the value
3573  * @param value the value itself
3574  * @return #MHD_NO if the operation could not be
3575  *         performed due to insufficient memory;
3576  *         #MHD_YES on success
3577  * @ingroup request
3578  */
3579 _MHD_EXTERN enum MHD_Result
3580 MHD_set_connection_value (struct MHD_Connection *connection,
3581                           enum MHD_ValueKind kind,
3582                           const char *key,
3583                           const char *value);
3584 
3585 
3586 /**
3587  * This function can be used to add an arbitrary entry to connection.
3588  * This function could add entry with binary zero, which is allowed
3589  * for #MHD_GET_ARGUMENT_KIND. For other kind on entries it is
3590  * recommended to use #MHD_set_connection_value.
3591  *
3592  * This function MUST only be called from within the
3593  * #MHD_AccessHandlerCallback (otherwise, access maybe improperly
3594  * synchronized).  Furthermore, the client must guarantee that the key
3595  * and value arguments are 0-terminated strings that are NOT freed
3596  * until the connection is closed.  (The easiest way to do this is by
3597  * passing only arguments to permanently allocated strings.).
3598  *
3599  * @param connection the connection for which a
3600  *  value should be set
3601  * @param kind kind of the value
3602  * @param key key for the value, must be zero-terminated
3603  * @param key_size number of bytes in @a key (excluding 0-terminator)
3604  * @param value the value itself, must be zero-terminated
3605  * @param value_size number of bytes in @a value (excluding 0-terminator)
3606  * @return #MHD_NO if the operation could not be
3607  *         performed due to insufficient memory;
3608  *         #MHD_YES on success
3609  * @note Available since #MHD_VERSION 0x00096400
3610  * @ingroup request
3611  */
3612 _MHD_EXTERN enum MHD_Result
3613 MHD_set_connection_value_n (struct MHD_Connection *connection,
3614                             enum MHD_ValueKind kind,
3615                             const char *key,
3616                             size_t key_size,
3617                             const char *value,
3618                             size_t value_size);
3619 
3620 
3621 /**
3622  * Sets the global error handler to a different implementation.
3623  *
3624  * @a cb will only be called in the case of typically fatal, serious internal
3625  * consistency issues or serious system failures like failed lock of mutex.
3626  *
3627  * These issues should only arise in the case of serious memory corruption or
3628  * similar problems with the architecture, there is no safe way to continue
3629  * even for closing of the application.
3630  *
3631  * The default implementation that is used if no panic function is set simply
3632  * prints an error message and calls `abort()`.
3633  * Alternative implementations might call `exit()` or other similar functions.
3634  *
3635  * @param cb new error handler or NULL to use default handler
3636  * @param cls passed to @a cb
3637  * @ingroup logging
3638  */
3639 _MHD_EXTERN void
3640 MHD_set_panic_func (MHD_PanicCallback cb, void *cls);
3641 
3642 
3643 /**
3644  * Process escape sequences ('%HH') Updates val in place; the
3645  * result cannot be larger than the input.
3646  * The result is still be 0-terminated.
3647  *
3648  * @param val value to unescape (modified in the process)
3649  * @return length of the resulting val (`strlen(val)` may be
3650  *  shorter afterwards due to elimination of escape sequences)
3651  */
3652 _MHD_EXTERN size_t
3653 MHD_http_unescape (char *val);
3654 
3655 
3656 /**
3657  * Get a particular header value.  If multiple
3658  * values match the kind, return any one of them.
3659  *
3660  * @param connection connection to get values from
3661  * @param kind what kind of value are we looking for
3662  * @param key the header to look for, NULL to lookup 'trailing' value without a key
3663  * @return NULL if no such item was found
3664  * @ingroup request
3665  */
3666 _MHD_EXTERN const char *
3667 MHD_lookup_connection_value (struct MHD_Connection *connection,
3668                              enum MHD_ValueKind kind,
3669                              const char *key);
3670 
3671 
3672 /**
3673  * Get a particular header value.  If multiple
3674  * values match the kind, return any one of them.
3675  * @note Since MHD_VERSION 0x00096304
3676  *
3677  * @param connection connection to get values from
3678  * @param kind what kind of value are we looking for
3679  * @param key the header to look for, NULL to lookup 'trailing' value without a key
3680  * @param key_size the length of @a key in bytes
3681  * @param[out] value_ptr the pointer to variable, which will be set to found value,
3682  *                       will not be updated if key not found,
3683  *                       could be NULL to just check for presence of @a key
3684  * @param[out] value_size_ptr the pointer variable, which will set to found value,
3685  *                            will not be updated if key not found,
3686  *                            could be NULL
3687  * @return #MHD_YES if key is found,
3688  *         #MHD_NO otherwise.
3689  * @ingroup request
3690  */
3691 _MHD_EXTERN enum MHD_Result
3692 MHD_lookup_connection_value_n (struct MHD_Connection *connection,
3693                                enum MHD_ValueKind kind,
3694                                const char *key,
3695                                size_t key_size,
3696                                const char **value_ptr,
3697                                size_t *value_size_ptr);
3698 
3699 
3700 /**
3701  * Queue a response to be transmitted to the client (as soon as
3702  * possible but after #MHD_AccessHandlerCallback returns).
3703  *
3704  * For any active connection this function must be called
3705  * only by #MHD_AccessHandlerCallback callback.
3706  *
3707  * For suspended connection this function can be called at any moment (this
3708  * behaviour is deprecated and will be removed!). Response  will be sent
3709  * as soon as connection is resumed.
3710  *
3711  * For single thread environment, when MHD is used in "external polling" mode
3712  * (without MHD_USE_SELECT_INTERNALLY) this function can be called any
3713  * time (this behaviour is deprecated and will be removed!).
3714  *
3715  * If HTTP specifications require use no body in reply, like @a status_code with
3716  * value 1xx, the response body is automatically not sent even if it is present
3717  * in the response. No "Content-Length" or "Transfer-Encoding" headers are
3718  * generated and added.
3719  *
3720  * When the response is used to respond HEAD request or used with @a status_code
3721  * #MHD_HTTP_NOT_MODIFIED, then response body is not sent, but "Content-Length"
3722  * header is added automatically based the size of the body in the response.
3723  * If body size it set to #MHD_SIZE_UNKNOWN or chunked encoding is enforced
3724  * then "Transfer-Encoding: chunked" header (for HTTP/1.1 only) is added instead
3725  * of "Content-Length" header. For example, if response with zero-size body is
3726  * used for HEAD request, then "Content-Length: 0" is added automatically to
3727  * reply headers.
3728  * @sa #MHD_RF_HEAD_ONLY_RESPONSE
3729  *
3730  * In situations, where reply body is required, like answer for the GET request
3731  * with @a status_code #MHD_HTTP_OK, headers "Content-Length" (for known body
3732  * size) or "Transfer-Encoding: chunked" (for #MHD_SIZE_UNKNOWN with HTTP/1.1)
3733  * are added automatically.
3734  * In practice, the same response object can be used to respond to both HEAD and
3735  * GET requests.
3736  *
3737  * @param connection the connection identifying the client
3738  * @param status_code HTTP status code (i.e. #MHD_HTTP_OK)
3739  * @param response response to transmit, the NULL is tolerated
3740  * @return #MHD_NO on error (reply already sent, response is NULL),
3741  *         #MHD_YES on success or if message has been queued
3742  * @ingroup response
3743  * @sa #MHD_AccessHandlerCallback
3744  */
3745 _MHD_EXTERN enum MHD_Result
3746 MHD_queue_response (struct MHD_Connection *connection,
3747                     unsigned int status_code,
3748                     struct MHD_Response *response);
3749 
3750 
3751 /**
3752  * Suspend handling of network data for a given connection.
3753  * This can be used to dequeue a connection from MHD's event loop
3754  * (not applicable to thread-per-connection!) for a while.
3755  *
3756  * If you use this API in conjunction with an "internal" socket polling,
3757  * you must set the option #MHD_USE_ITC to ensure that a resumed
3758  * connection is immediately processed by MHD.
3759  *
3760  * Suspended connections continue to count against the total number of
3761  * connections allowed (per daemon, as well as per IP, if such limits
3762  * are set).  Suspended connections will NOT time out; timeouts will
3763  * restart when the connection handling is resumed.  While a
3764  * connection is suspended, MHD will not detect disconnects by the
3765  * client.
3766  *
3767  * The only safe way to call this function is to call it from the
3768  * #MHD_AccessHandlerCallback or #MHD_ContentReaderCallback.
3769  *
3770  * Finally, it is an API violation to call #MHD_stop_daemon while
3771  * having suspended connections (this will at least create memory and
3772  * socket leaks or lead to undefined behavior).  You must explicitly
3773  * resume all connections before stopping the daemon.
3774  *
3775  * @param connection the connection to suspend
3776  *
3777  * @sa #MHD_AccessHandlerCallback
3778  */
3779 _MHD_EXTERN void
3780 MHD_suspend_connection (struct MHD_Connection *connection);
3781 
3782 
3783 /**
3784  * Resume handling of network data for suspended connection.  It is
3785  * safe to resume a suspended connection at any time.  Calling this
3786  * function on a connection that was not previously suspended will
3787  * result in undefined behavior.
3788  *
3789  * If you are using this function in "external" sockets polling mode, you must
3790  * make sure to run #MHD_run() and #MHD_get_timeout() afterwards (before
3791  * again calling #MHD_get_fdset()), as otherwise the change may not be
3792  * reflected in the set returned by #MHD_get_fdset() and you may end up
3793  * with a connection that is stuck until the next network activity.
3794  *
3795  * @param connection the connection to resume
3796  */
3797 _MHD_EXTERN void
3798 MHD_resume_connection (struct MHD_Connection *connection);
3799 
3800 
3801 /* **************** Response manipulation functions ***************** */
3802 
3803 
3804 /**
3805  * Flags for special handling of responses.
3806  */
3807 enum MHD_ResponseFlags
3808 {
3809   /**
3810    * Default: no special flags.
3811    * @note Available since #MHD_VERSION 0x00093701
3812    */
3813   MHD_RF_NONE = 0,
3814 
3815   /**
3816    * Only respond in conservative (dumb) HTTP/1.0-compatible mode.
3817    * Response still use HTTP/1.1 version in header, but always close
3818    * the connection after sending the response and do not use chunked
3819    * encoding for the response.
3820    * You can also set the #MHD_RF_HTTP_1_0_SERVER flag to force
3821    * HTTP/1.0 version in the response.
3822    * Responses are still compatible with HTTP/1.1.
3823    * This option can be used to communicate with some broken client, which
3824    * does not implement HTTP/1.1 features, but advertises HTTP/1.1 support.
3825    * @note Available since #MHD_VERSION 0x00097308
3826    */
3827   MHD_RF_HTTP_1_0_COMPATIBLE_STRICT = 1 << 0,
3828   /**
3829    * The same as #MHD_RF_HTTP_1_0_COMPATIBLE_STRICT
3830    * @note Available since #MHD_VERSION 0x00093701
3831    */
3832   MHD_RF_HTTP_VERSION_1_0_ONLY = 1 << 0,
3833 
3834   /**
3835    * Only respond in HTTP 1.0-mode.
3836    * Contrary to the #MHD_RF_HTTP_1_0_COMPATIBLE_STRICT flag, the response's
3837    * HTTP version will always be set to 1.0 and keep-alive connections
3838    * will be used if explicitly requested by the client.
3839    * The "Connection:" header will be added for both "close" and "keep-alive"
3840    * connections.
3841    * Chunked encoding will not be used for the response.
3842    * Due to backward compatibility, responses still can be used with
3843    * HTTP/1.1 clients.
3844    * This option can be used to emulate HTTP/1.0 server (for response part
3845    * only as chunked encoding in requests (if any) is processed by MHD).
3846    * @note Available since #MHD_VERSION 0x00097308
3847    */
3848   MHD_RF_HTTP_1_0_SERVER = 1 << 1,
3849   /**
3850    * The same as #MHD_RF_HTTP_1_0_SERVER
3851    * @note Available since #MHD_VERSION 0x00096000
3852    */
3853   MHD_RF_HTTP_VERSION_1_0_RESPONSE = 1 << 1,
3854 
3855   /**
3856    * Disable sanity check preventing clients from manually
3857    * setting the HTTP content length option.
3858    * Allow to set several "Content-Length" headers. These headers will
3859    * be used even with replies without body.
3860    * @note Available since #MHD_VERSION 0x00096702
3861    */
3862   MHD_RF_INSANITY_HEADER_CONTENT_LENGTH = 1 << 2,
3863 
3864   /**
3865    * Enable sending of "Connection: keep-alive" header even for
3866    * HTTP/1.1 clients when "Keep-Alive" connection is used.
3867    * Disabled by default for HTTP/1.1 clients as per RFC.
3868    * @note Available since #MHD_VERSION 0x00097310
3869    */
3870   MHD_RF_SEND_KEEP_ALIVE_HEADER = 1 << 3,
3871 
3872   /**
3873    * Enable special processing of the response as body-less (with undefined
3874    * body size). No automatic "Content-Length" or "Transfer-Encoding: chunked"
3875    * headers are added when the response is used with #MHD_HTTP_NOT_MODIFIED
3876    * code or to respond to HEAD request.
3877    * The flag also allow to set arbitrary "Content-Length" by
3878    * MHD_add_response_header() function.
3879    * This flag value can be used only with responses created without body
3880    * (zero-size body).
3881    * Responses with this flag enabled cannot be used in situations where
3882    * reply body must be sent to the client.
3883    * This flag is primarily intended to be used when automatic "Content-Length"
3884    * header is undesirable in response to HEAD requests.
3885    * @note Available since #MHD_VERSION 0x00097701
3886    */
3887   MHD_RF_HEAD_ONLY_RESPONSE = 1 << 4
3888 } _MHD_FIXED_FLAGS_ENUM;
3889 
3890 
3891 /**
3892  * MHD options (for future extensions).
3893  */
3894 enum MHD_ResponseOptions
3895 {
3896   /**
3897    * End of the list of options.
3898    */
3899   MHD_RO_END = 0
3900 } _MHD_FIXED_ENUM;
3901 
3902 
3903 /**
3904  * Set special flags and options for a response.
3905  *
3906  * @param response the response to modify
3907  * @param flags to set for the response
3908  * @param ... #MHD_RO_END terminated list of options
3909  * @return #MHD_YES on success, #MHD_NO on error
3910  */
3911 _MHD_EXTERN enum MHD_Result
3912 MHD_set_response_options (struct MHD_Response *response,
3913                           enum MHD_ResponseFlags flags,
3914                           ...);
3915 
3916 
3917 /**
3918  * Create a response object.
3919  * The response object can be extended with header information and then be used
3920  * any number of times.
3921  *
3922  * If response object is used to answer HEAD request then the body of the
3923  * response is not used, while all headers (including automatic headers) are
3924  * used.
3925  *
3926  * @param size size of the data portion of the response, #MHD_SIZE_UNKNOWN for unknown
3927  * @param block_size preferred block size for querying crc (advisory only,
3928  *                   MHD may still call @a crc using smaller chunks); this
3929  *                   is essentially the buffer size used for IO, clients
3930  *                   should pick a value that is appropriate for IO and
3931  *                   memory performance requirements
3932  * @param crc callback to use to obtain response data
3933  * @param crc_cls extra argument to @a crc
3934  * @param crfc callback to call to free @a crc_cls resources
3935  * @return NULL on error (i.e. invalid arguments, out of memory)
3936  * @ingroup response
3937  */
3938 _MHD_EXTERN struct MHD_Response *
3939 MHD_create_response_from_callback (uint64_t size,
3940                                    size_t block_size,
3941                                    MHD_ContentReaderCallback crc, void *crc_cls,
3942                                    MHD_ContentReaderFreeCallback crfc);
3943 
3944 
3945 /**
3946  * Create a response object.
3947  * The response object can be extended with header information and then be used
3948  * any number of times.
3949  *
3950  * If response object is used to answer HEAD request then the body of the
3951  * response is not used, while all headers (including automatic headers) are
3952  * used.
3953  *
3954  * @param size size of the @a data portion of the response
3955  * @param data the data itself
3956  * @param must_free libmicrohttpd should free data when done
3957  * @param must_copy libmicrohttpd must make a copy of @a data
3958  *        right away, the data may be released anytime after
3959  *        this call returns
3960  * @return NULL on error (i.e. invalid arguments, out of memory)
3961  * @deprecated use #MHD_create_response_from_buffer instead
3962  * @ingroup response
3963  */
3964 _MHD_DEPR_FUNC ("MHD_create_response_from_data() is deprecated, " \
3965                 "use MHD_create_response_from_buffer()") \
3966   _MHD_EXTERN struct MHD_Response *
3967 MHD_create_response_from_data (size_t size,
3968                                void *data,
3969                                int must_free,
3970                                int must_copy);
3971 
3972 
3973 /**
3974  * Specification for how MHD should treat the memory buffer
3975  * given for the response.
3976  * @ingroup response
3977  */
3978 enum MHD_ResponseMemoryMode
3979 {
3980 
3981   /**
3982    * Buffer is a persistent (static/global) buffer that won't change
3983    * for at least the lifetime of the response, MHD should just use
3984    * it, not free it, not copy it, just keep an alias to it.
3985    * @ingroup response
3986    */
3987   MHD_RESPMEM_PERSISTENT,
3988 
3989   /**
3990    * Buffer is heap-allocated with `malloc()` (or equivalent) and
3991    * should be freed by MHD after processing the response has
3992    * concluded (response reference counter reaches zero).
3993    * The more portable way to automatically free the buffer is function
3994    * MHD_create_response_from_buffer_with_free_callback() with '&free' as
3995    * crfc parameter as it does not require to use the same runtime library.
3996    * @warning It is critical to make sure that the same C-runtime library
3997    *          is used by both application and MHD (especially
3998    *          important for W32).
3999    * @ingroup response
4000    */
4001   MHD_RESPMEM_MUST_FREE,
4002 
4003   /**
4004    * Buffer is in transient memory, but not on the heap (for example,
4005    * on the stack or non-`malloc()` allocated) and only valid during the
4006    * call to #MHD_create_response_from_buffer.  MHD must make its
4007    * own private copy of the data for processing.
4008    * @ingroup response
4009    */
4010   MHD_RESPMEM_MUST_COPY
4011 
4012 } _MHD_FIXED_ENUM;
4013 
4014 
4015 /**
4016  * Create a response object with the content of provided buffer used as
4017  * the response body.
4018  *
4019  * The response object can be extended with header information and then
4020  * be used any number of times.
4021  *
4022  * If response object is used to answer HEAD request then the body
4023  * of the response is not used, while all headers (including automatic
4024  * headers) are used.
4025  *
4026  * @param size size of the data portion of the response
4027  * @param buffer size bytes containing the response's data portion
4028  * @param mode flags for buffer management
4029  * @return NULL on error (i.e. invalid arguments, out of memory)
4030  * @ingroup response
4031  */
4032 _MHD_EXTERN struct MHD_Response *
4033 MHD_create_response_from_buffer (size_t size,
4034                                  void *buffer,
4035                                  enum MHD_ResponseMemoryMode mode);
4036 
4037 
4038 /**
4039  * Create a response object with the content of provided statically allocated
4040  * buffer used as the response body.
4041  *
4042  * The buffer must be valid for the lifetime of the response. The easiest way
4043  * to achieve this is to use a statically allocated buffer.
4044  *
4045  * The response object can be extended with header information and then
4046  * be used any number of times.
4047  *
4048  * If response object is used to answer HEAD request then the body
4049  * of the response is not used, while all headers (including automatic
4050  * headers) are used.
4051  *
4052  * @param size the size of the data in @a buffer, can be zero
4053  * @param buffer the buffer with the data for the response body, can be NULL
4054  *               if @a size is zero
4055  * @return NULL on error (i.e. invalid arguments, out of memory)
4056  * @note Available since #MHD_VERSION 0x00097701
4057  * @ingroup response
4058  */
4059 _MHD_EXTERN struct MHD_Response *
4060 MHD_create_response_from_buffer_static (size_t size,
4061                                         const void *buffer);
4062 
4063 
4064 /**
4065  * Create a response object with the content of provided temporal buffer
4066  * used as the response body.
4067  *
4068  * An internal copy of the buffer will be made automatically, so buffer have
4069  * to be valid only during the call of this function (as a typical example:
4070  * buffer is a local (non-static) array).
4071  *
4072  * The response object can be extended with header information and then
4073  * be used any number of times.
4074  *
4075  * If response object is used to answer HEAD request then the body
4076  * of the response is not used, while all headers (including automatic
4077  * headers) are used.
4078  *
4079  * @param size the size of the data in @a buffer, can be zero
4080  * @param buffer the buffer with the data for the response body, can be NULL
4081  *               if @a size is zero
4082  * @return NULL on error (i.e. invalid arguments, out of memory)
4083  * @note Available since #MHD_VERSION 0x00097701
4084  * @ingroup response
4085  */
4086 _MHD_EXTERN struct MHD_Response *
4087 MHD_create_response_from_buffer_copy (size_t size,
4088                                       const void *buffer);
4089 
4090 
4091 /**
4092  * Create a response object with the content of provided buffer used as
4093  * the response body.
4094  *
4095  * The response object can be extended with header information and then
4096  * be used any number of times.
4097  *
4098  * If response object is used to answer HEAD request then the body
4099  * of the response is not used, while all headers (including automatic
4100  * headers) are used.
4101  *
4102  * @param size size of the data portion of the response
4103  * @param buffer size bytes containing the response's data portion
4104  * @param crfc function to call to free the @a buffer
4105  * @return NULL on error (i.e. invalid arguments, out of memory)
4106  * @note Available since #MHD_VERSION 0x00096000
4107  * @ingroup response
4108  */
4109 _MHD_EXTERN struct MHD_Response *
4110 MHD_create_response_from_buffer_with_free_callback (size_t size,
4111                                                     void *buffer,
4112                                                     MHD_ContentReaderFreeCallback
4113                                                     crfc);
4114 
4115 
4116 /**
4117  * Create a response object with the content of provided buffer used as
4118  * the response body.
4119  *
4120  * The response object can be extended with header information and then
4121  * be used any number of times.
4122  *
4123  * If response object is used to answer HEAD request then the body
4124  * of the response is not used, while all headers (including automatic
4125  * headers) are used.
4126  *
4127  * @param size size of the data portion of the response
4128  * @param buffer size bytes containing the response's data portion
4129  * @param crfc function to call to cleanup, if set to NULL then callback
4130  *             is not called
4131  * @param crfc_cls an argument for @a crfc
4132  * @return NULL on error (i.e. invalid arguments, out of memory)
4133  * @note Available since #MHD_VERSION 0x00097302
4134  * @note 'const' qualifier is used for @a buffer since #MHD_VERSION 0x00097701
4135  * @ingroup response
4136  */
4137 _MHD_EXTERN struct MHD_Response *
4138 MHD_create_response_from_buffer_with_free_callback_cls (size_t size,
4139                                                         const void *buffer,
4140                                                         MHD_ContentReaderFreeCallback
4141                                                         crfc,
4142                                                         void *crfc_cls);
4143 
4144 
4145 /**
4146  * Create a response object with the content of provided file used as
4147  * the response body.
4148  *
4149  * The response object can be extended with header information and then
4150  * be used any number of times.
4151  *
4152  * If response object is used to answer HEAD request then the body
4153  * of the response is not used, while all headers (including automatic
4154  * headers) are used.
4155  *
4156  * @param size size of the data portion of the response
4157  * @param fd file descriptor referring to a file on disk with the
4158  *        data; will be closed when response is destroyed;
4159  *        fd should be in 'blocking' mode
4160  * @return NULL on error (i.e. invalid arguments, out of memory)
4161  * @ingroup response
4162  */
4163 _MHD_EXTERN struct MHD_Response *
4164 MHD_create_response_from_fd (size_t size,
4165                              int fd);
4166 
4167 
4168 /**
4169  * Create a response object with the response body created by reading
4170  * the provided pipe.
4171  *
4172  * The response object can be extended with header information and
4173  * then be used ONLY ONCE.
4174  *
4175  * If response object is used to answer HEAD request then the body
4176  * of the response is not used, while all headers (including automatic
4177  * headers) are used.
4178  *
4179  * @param fd file descriptor referring to a read-end of a pipe with the
4180  *        data; will be closed when response is destroyed;
4181  *        fd should be in 'blocking' mode
4182  * @return NULL on error (i.e. invalid arguments, out of memory)
4183  * @note Available since #MHD_VERSION 0x00097102
4184  * @ingroup response
4185  */
4186 _MHD_EXTERN struct MHD_Response *
4187 MHD_create_response_from_pipe (int fd);
4188 
4189 
4190 /**
4191  * Create a response object with the content of provided file used as
4192  * the response body.
4193  *
4194  * The response object can be extended with header information and then
4195  * be used any number of times.
4196  *
4197  * If response object is used to answer HEAD request then the body
4198  * of the response is not used, while all headers (including automatic
4199  * headers) are used.
4200  *
4201  * @param size size of the data portion of the response;
4202  *        sizes larger than 2 GiB may be not supported by OS or
4203  *        MHD build; see ::MHD_FEATURE_LARGE_FILE
4204  * @param fd file descriptor referring to a file on disk with the
4205  *        data; will be closed when response is destroyed;
4206  *        fd should be in 'blocking' mode
4207  * @return NULL on error (i.e. invalid arguments, out of memory)
4208  * @ingroup response
4209  */
4210 _MHD_EXTERN struct MHD_Response *
4211 MHD_create_response_from_fd64 (uint64_t size,
4212                                int fd);
4213 
4214 
4215 /**
4216  * Create a response object with the content of provided file with
4217  * specified offset used as the response body.
4218  *
4219  * The response object can be extended with header information and then
4220  * be used any number of times.
4221  *
4222  * If response object is used to answer HEAD request then the body
4223  * of the response is not used, while all headers (including automatic
4224  * headers) are used.
4225  *
4226  * @param size size of the data portion of the response
4227  * @param fd file descriptor referring to a file on disk with the
4228  *        data; will be closed when response is destroyed;
4229  *        fd should be in 'blocking' mode
4230  * @param offset offset to start reading from in the file;
4231  *        Be careful! `off_t` may have been compiled to be a
4232  *        64-bit variable for MHD, in which case your application
4233  *        also has to be compiled using the same options! Read
4234  *        the MHD manual for more details.
4235  * @return NULL on error (i.e. invalid arguments, out of memory)
4236  * @ingroup response
4237  */
4238 _MHD_DEPR_FUNC ("Function MHD_create_response_from_fd_at_offset() is " \
4239                 "deprecated, use MHD_create_response_from_fd_at_offset64()") \
4240   _MHD_EXTERN struct MHD_Response *
4241 MHD_create_response_from_fd_at_offset (size_t size,
4242                                        int fd,
4243                                        off_t offset);
4244 
4245 #if ! defined(_MHD_NO_DEPR_IN_MACRO) || defined(_MHD_NO_DEPR_FUNC)
4246 /* Substitute MHD_create_response_from_fd_at_offset64() instead of MHD_create_response_from_fd_at_offset()
4247    to minimize potential problems with different off_t sizes */
4248 #define MHD_create_response_from_fd_at_offset(size,fd,offset) \
4249   _MHD_DEPR_IN_MACRO ( \
4250     "Usage of MHD_create_response_from_fd_at_offset() is deprecated, use MHD_create_response_from_fd_at_offset64()") \
4251   MHD_create_response_from_fd_at_offset64 ((size),(fd),(offset))
4252 #endif /* !_MHD_NO_DEPR_IN_MACRO || _MHD_NO_DEPR_FUNC */
4253 
4254 
4255 /**
4256  * Create a response object with the content of provided file with
4257  * specified offset used as the response body.
4258  *
4259  * The response object can be extended with header information and then
4260  * be used any number of times.
4261  *
4262  * If response object is used to answer HEAD request then the body
4263  * of the response is not used, while all headers (including automatic
4264  * headers) are used.
4265  *
4266  * @param size size of the data portion of the response;
4267  *        sizes larger than 2 GiB may be not supported by OS or
4268  *        MHD build; see ::MHD_FEATURE_LARGE_FILE
4269  * @param fd file descriptor referring to a file on disk with the
4270  *        data; will be closed when response is destroyed;
4271  *        fd should be in 'blocking' mode
4272  * @param offset offset to start reading from in the file;
4273  *        reading file beyond 2 GiB may be not supported by OS or
4274  *        MHD build; see ::MHD_FEATURE_LARGE_FILE
4275  * @return NULL on error (i.e. invalid arguments, out of memory)
4276  * @ingroup response
4277  */
4278 _MHD_EXTERN struct MHD_Response *
4279 MHD_create_response_from_fd_at_offset64 (uint64_t size,
4280                                          int fd,
4281                                          uint64_t offset);
4282 
4283 
4284 /**
4285  * Create a response object with an array of memory buffers
4286  * used as the response body.
4287  *
4288  * The response object can be extended with header information and then
4289  * be used any number of times.
4290  *
4291  * If response object is used to answer HEAD request then the body
4292  * of the response is not used, while all headers (including automatic
4293  * headers) are used.
4294  *
4295  * @param iov the array for response data buffers, an internal copy of this
4296  *        will be made
4297  * @param iovcnt the number of elements in @a iov
4298  * @param free_cb the callback to clean up any data associated with @a iov when
4299  *        the response is destroyed.
4300  * @param cls the argument passed to @a free_cb
4301  * @return NULL on error (i.e. invalid arguments, out of memory)
4302  * @note Available since #MHD_VERSION 0x00097204
4303  * @ingroup response
4304  */
4305 _MHD_EXTERN struct MHD_Response *
4306 MHD_create_response_from_iovec (const struct MHD_IoVec *iov,
4307                                 unsigned int iovcnt,
4308                                 MHD_ContentReaderFreeCallback free_cb,
4309                                 void *cls);
4310 
4311 
4312 /**
4313  * Create a response object with empty (zero size) body.
4314  *
4315  * The response object can be extended with header information and then be used
4316  * any number of times.
4317  *
4318  * This function is a faster equivalent of #MHD_create_response_from_buffer call
4319  * with zero size combined with call of #MHD_set_response_options.
4320  *
4321  * @param flags the flags for the new response object
4322  * @return NULL on error (i.e. invalid arguments, out of memory),
4323  *         the pointer to the created response object otherwise
4324  * @note Available since #MHD_VERSION 0x00097701
4325  * @ingroup response
4326  */
4327 _MHD_EXTERN struct MHD_Response *
4328 MHD_create_response_empty (enum MHD_ResponseFlags flags);
4329 
4330 
4331 /**
4332  * Enumeration for actions MHD should perform on the underlying socket
4333  * of the upgrade.  This API is not finalized, and in particular
4334  * the final set of actions is yet to be decided. This is just an
4335  * idea for what we might want.
4336  */
4337 enum MHD_UpgradeAction
4338 {
4339 
4340   /**
4341    * Close the socket, the application is done with it.
4342    *
4343    * Takes no extra arguments.
4344    */
4345   MHD_UPGRADE_ACTION_CLOSE = 0,
4346 
4347   /**
4348    * Enable CORKing on the underlying socket.
4349    */
4350   MHD_UPGRADE_ACTION_CORK_ON = 1,
4351 
4352   /**
4353    * Disable CORKing on the underlying socket.
4354    */
4355   MHD_UPGRADE_ACTION_CORK_OFF = 2
4356 
4357 } _MHD_FIXED_ENUM;
4358 
4359 
4360 /**
4361  * Handle given to the application to manage special
4362  * actions relating to MHD responses that "upgrade"
4363  * the HTTP protocol (i.e. to WebSockets).
4364  */
4365 struct MHD_UpgradeResponseHandle;
4366 
4367 
4368 /**
4369  * This connection-specific callback is provided by MHD to
4370  * applications (unusual) during the #MHD_UpgradeHandler.
4371  * It allows applications to perform 'special' actions on
4372  * the underlying socket from the upgrade.
4373  *
4374  * @param urh the handle identifying the connection to perform
4375  *            the upgrade @a action on.
4376  * @param action which action should be performed
4377  * @param ... arguments to the action (depends on the action)
4378  * @return #MHD_NO on error, #MHD_YES on success
4379  */
4380 _MHD_EXTERN enum MHD_Result
4381 MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh,
4382                     enum MHD_UpgradeAction action,
4383                     ...);
4384 
4385 
4386 /**
4387  * Function called after a protocol "upgrade" response was sent
4388  * successfully and the socket should now be controlled by some
4389  * protocol other than HTTP.
4390  *
4391  * Any data already received on the socket will be made available in
4392  * @e extra_in.  This can happen if the application sent extra data
4393  * before MHD send the upgrade response.  The application should
4394  * treat data from @a extra_in as if it had read it from the socket.
4395  *
4396  * Note that the application must not close() @a sock directly,
4397  * but instead use #MHD_upgrade_action() for special operations
4398  * on @a sock.
4399  *
4400  * Data forwarding to "upgraded" @a sock will be started as soon
4401  * as this function return.
4402  *
4403  * Except when in 'thread-per-connection' mode, implementations
4404  * of this function should never block (as it will still be called
4405  * from within the main event loop).
4406  *
4407  * @param cls closure, whatever was given to #MHD_create_response_for_upgrade().
4408  * @param connection original HTTP connection handle,
4409  *                   giving the function a last chance
4410  *                   to inspect the original HTTP request
4411  * @param req_cls last value left in `req_cls` of the `MHD_AccessHandlerCallback`
4412  * @param extra_in if we happened to have read bytes after the
4413  *                 HTTP header already (because the client sent
4414  *                 more than the HTTP header of the request before
4415  *                 we sent the upgrade response),
4416  *                 these are the extra bytes already read from @a sock
4417  *                 by MHD.  The application should treat these as if
4418  *                 it had read them from @a sock.
4419  * @param extra_in_size number of bytes in @a extra_in
4420  * @param sock socket to use for bi-directional communication
4421  *        with the client.  For HTTPS, this may not be a socket
4422  *        that is directly connected to the client and thus certain
4423  *        operations (TCP-specific setsockopt(), getsockopt(), etc.)
4424  *        may not work as expected (as the socket could be from a
4425  *        socketpair() or a TCP-loopback).  The application is expected
4426  *        to perform read()/recv() and write()/send() calls on the socket.
4427  *        The application may also call shutdown(), but must not call
4428  *        close() directly.
4429  * @param urh argument for #MHD_upgrade_action()s on this @a connection.
4430  *        Applications must eventually use this callback to (indirectly)
4431  *        perform the close() action on the @a sock.
4432  */
4433 typedef void
4434 (*MHD_UpgradeHandler)(void *cls,
4435                       struct MHD_Connection *connection,
4436                       void *req_cls,
4437                       const char *extra_in,
4438                       size_t extra_in_size,
4439                       MHD_socket sock,
4440                       struct MHD_UpgradeResponseHandle *urh);
4441 
4442 
4443 /**
4444  * Create a response object that can be used for 101 UPGRADE
4445  * responses, for example to implement WebSockets.  After sending the
4446  * response, control over the data stream is given to the callback (which
4447  * can then, for example, start some bi-directional communication).
4448  * If the response is queued for multiple connections, the callback
4449  * will be called for each connection.  The callback
4450  * will ONLY be called after the response header was successfully passed
4451  * to the OS; if there are communication errors before, the usual MHD
4452  * connection error handling code will be performed.
4453  *
4454  * Setting the correct HTTP code (i.e. MHD_HTTP_SWITCHING_PROTOCOLS)
4455  * and setting correct HTTP headers for the upgrade must be done
4456  * manually (this way, it is possible to implement most existing
4457  * WebSocket versions using this API; in fact, this API might be useful
4458  * for any protocol switch, not just WebSockets).  Note that
4459  * draft-ietf-hybi-thewebsocketprotocol-00 cannot be implemented this
4460  * way as the header "HTTP/1.1 101 WebSocket Protocol Handshake"
4461  * cannot be generated; instead, MHD will always produce "HTTP/1.1 101
4462  * Switching Protocols" (if the response code 101 is used).
4463  *
4464  * As usual, the response object can be extended with header
4465  * information and then be used any number of times (as long as the
4466  * header information is not connection-specific).
4467  *
4468  * @param upgrade_handler function to call with the "upgraded" socket
4469  * @param upgrade_handler_cls closure for @a upgrade_handler
4470  * @return NULL on error (i.e. invalid arguments, out of memory)
4471  */
4472 _MHD_EXTERN struct MHD_Response *
4473 MHD_create_response_for_upgrade (MHD_UpgradeHandler upgrade_handler,
4474                                  void *upgrade_handler_cls);
4475 
4476 
4477 /**
4478  * Destroy a response object and associated resources.  Note that
4479  * libmicrohttpd may keep some of the resources around if the response
4480  * is still in the queue for some clients, so the memory may not
4481  * necessarily be freed immediately.
4482  *
4483  * @param response response to destroy
4484  * @ingroup response
4485  */
4486 _MHD_EXTERN void
4487 MHD_destroy_response (struct MHD_Response *response);
4488 
4489 
4490 /**
4491  * Add a header line to the response.
4492  *
4493  * When reply is generated with queued response, some headers are generated
4494  * automatically. Automatically generated headers are only sent to the client,
4495  * but not added back to the response object.
4496  *
4497  * The list of automatic headers:
4498  * + "Date" header is added automatically unless already set by
4499  *   this function
4500  *   @see #MHD_USE_SUPPRESS_DATE_NO_CLOCK
4501  * + "Content-Length" is added automatically when required, attempt to set
4502  *   it manually by this function is ignored.
4503  *   @see #MHD_RF_INSANITY_HEADER_CONTENT_LENGTH
4504  * + "Transfer-Encoding" with value "chunked" is added automatically,
4505  *   when chunked transfer encoding is used automatically. Same header with
4506  *   the same value can be set manually by this function to enforce chunked
4507  *   encoding, however for HTTP/1.0 clients chunked encoding will not be used
4508  *   and manually set "Transfer-Encoding" header is automatically removed
4509  *   for HTTP/1.0 clients
4510  * + "Connection" may be added automatically with value "Keep-Alive" (only
4511  *   for HTTP/1.0 clients) or "Close". The header "Connection" with value
4512  *   "Close" could be set by this function to enforce closure of
4513  *   the connection after sending this response. "Keep-Alive" cannot be
4514  *   enforced and will be removed automatically.
4515  *   @see #MHD_RF_SEND_KEEP_ALIVE_HEADER
4516  *
4517  * Some headers are pre-processed by this function:
4518  * * "Connection" headers are combined into single header entry, value is
4519  *   normilised, "Keep-Alive" tokens are removed.
4520  * * "Transfer-Encoding" header: the only one header is allowed, the only
4521  *   allowed value is "chunked".
4522  * * "Date" header: the only one header is allowed, the second added header
4523  *   replaces the first one.
4524  * * "Content-Length" application-defined header is not allowed.
4525  *   @see #MHD_RF_INSANITY_HEADER_CONTENT_LENGTH
4526  *
4527  * Headers are used in order as they were added.
4528  *
4529  * @param response the response to add a header to
4530  * @param header the header name to add, no need to be static, an internal copy
4531  *               will be created automatically
4532  * @param content the header value to add, no need to be static, an internal
4533  *                copy will be created automatically
4534  * @return #MHD_YES on success,
4535  *         #MHD_NO on error (i.e. invalid header or content format),
4536  *         or out of memory
4537  * @ingroup response
4538  */
4539 _MHD_EXTERN enum MHD_Result
4540 MHD_add_response_header (struct MHD_Response *response,
4541                          const char *header,
4542                          const char *content);
4543 
4544 
4545 /**
4546  * Add a footer line to the response.
4547  *
4548  * @param response response to remove a header from
4549  * @param footer the footer to delete
4550  * @param content value to delete
4551  * @return #MHD_NO on error (i.e. invalid footer or content format).
4552  * @ingroup response
4553  */
4554 _MHD_EXTERN enum MHD_Result
4555 MHD_add_response_footer (struct MHD_Response *response,
4556                          const char *footer,
4557                          const char *content);
4558 
4559 
4560 /**
4561  * Delete a header (or footer) line from the response.
4562  *
4563  * For "Connection" headers this function remove all tokens from existing
4564  * value. Successful result means that at least one token has been removed.
4565  * If all tokens are removed from "Connection" header, the empty "Connection"
4566  * header removed.
4567  *
4568  * @param response response to remove a header from
4569  * @param header the header to delete
4570  * @param content value to delete
4571  * @return #MHD_NO on error (no such header known)
4572  * @ingroup response
4573  */
4574 _MHD_EXTERN enum MHD_Result
4575 MHD_del_response_header (struct MHD_Response *response,
4576                          const char *header,
4577                          const char *content);
4578 
4579 
4580 /**
4581  * Get all of the headers (and footers) added to a response.
4582  *
4583  * @param response response to query
4584  * @param iterator callback to call on each header;
4585  *        may be NULL (then just count headers)
4586  * @param iterator_cls extra argument to @a iterator
4587  * @return number of entries iterated over
4588  * @ingroup response
4589  */
4590 _MHD_EXTERN int
4591 MHD_get_response_headers (struct MHD_Response *response,
4592                           MHD_KeyValueIterator iterator,
4593                           void *iterator_cls);
4594 
4595 
4596 /**
4597  * Get a particular header (or footer) from the response.
4598  *
4599  * @param response response to query
4600  * @param key which header to get
4601  * @return NULL if header does not exist
4602  * @ingroup response
4603  */
4604 _MHD_EXTERN const char *
4605 MHD_get_response_header (struct MHD_Response *response,
4606                          const char *key);
4607 
4608 
4609 /* ********************** PostProcessor functions ********************** */
4610 
4611 /**
4612  * Create a `struct MHD_PostProcessor`.
4613  *
4614  * A `struct MHD_PostProcessor` can be used to (incrementally) parse
4615  * the data portion of a POST request.  Note that some buggy browsers
4616  * fail to set the encoding type.  If you want to support those, you
4617  * may have to call #MHD_set_connection_value with the proper encoding
4618  * type before creating a post processor (if no supported encoding
4619  * type is set, this function will fail).
4620  *
4621  * @param connection the connection on which the POST is
4622  *        happening (used to determine the POST format)
4623  * @param buffer_size maximum number of bytes to use for
4624  *        internal buffering (used only for the parsing,
4625  *        specifically the parsing of the keys).  A
4626  *        tiny value (256-1024) should be sufficient.
4627  *        Do NOT use a value smaller than 256.  For good
4628  *        performance, use 32 or 64k (i.e. 65536).
4629  * @param iter iterator to be called with the parsed data,
4630  *        Must NOT be NULL.
4631  * @param iter_cls first argument to @a iter
4632  * @return NULL on error (out of memory, unsupported encoding),
4633  *         otherwise a PP handle
4634  * @ingroup request
4635  */
4636 _MHD_EXTERN struct MHD_PostProcessor *
4637 MHD_create_post_processor (struct MHD_Connection *connection,
4638                            size_t buffer_size,
4639                            MHD_PostDataIterator iter, void *iter_cls);
4640 
4641 
4642 /**
4643  * Parse and process POST data.  Call this function when POST data is
4644  * available (usually during an #MHD_AccessHandlerCallback) with the
4645  * "upload_data" and "upload_data_size".  Whenever possible, this will
4646  * then cause calls to the #MHD_PostDataIterator.
4647  *
4648  * @param pp the post processor
4649  * @param post_data @a post_data_len bytes of POST data
4650  * @param post_data_len length of @a post_data
4651  * @return #MHD_YES on success, #MHD_NO on error
4652  *         (out-of-memory, iterator aborted, parse error)
4653  * @ingroup request
4654  */
4655 _MHD_EXTERN enum MHD_Result
4656 MHD_post_process (struct MHD_PostProcessor *pp,
4657                   const char *post_data,
4658                   size_t post_data_len);
4659 
4660 
4661 /**
4662  * Release PostProcessor resources.
4663  *
4664  * @param pp the PostProcessor to destroy
4665  * @return #MHD_YES if processing completed nicely,
4666  *         #MHD_NO if there were spurious characters / formatting
4667  *                problems; it is common to ignore the return
4668  *                value of this function
4669  * @ingroup request
4670  */
4671 _MHD_EXTERN enum MHD_Result
4672 MHD_destroy_post_processor (struct MHD_PostProcessor *pp);
4673 
4674 
4675 /* ********************* Digest Authentication functions *************** */
4676 
4677 
4678 /**
4679  * Length of the binary output of the MD5 hash function.
4680  * @sa #MHD_digest_get_hash_size()
4681  * @ingroup authentication
4682  */
4683 #define MHD_MD5_DIGEST_SIZE 16
4684 
4685 /**
4686  * Length of the binary output of the SHA-256 hash function.
4687  * @sa #MHD_digest_get_hash_size()
4688  * @ingroup authentication
4689  */
4690 #define MHD_SHA256_DIGEST_SIZE 32
4691 
4692 /**
4693  * Length of the binary output of the SHA-512/256 hash function.
4694  * @warning While this value is the same as the #MHD_SHA256_DIGEST_SIZE,
4695  *          the calculated digests for SHA-256 and SHA-512/256 are different.
4696  * @sa #MHD_digest_get_hash_size()
4697  * @note Available since #MHD_VERSION 0x00097701
4698  * @ingroup authentication
4699  */
4700 #define MHD_SHA512_256_DIGEST_SIZE 32
4701 
4702 /**
4703  * Base type of hash calculation.
4704  * Used as part of #MHD_DigestAuthAlgo3 values.
4705  *
4706  * @warning Not used directly by MHD API.
4707  * @note Available since #MHD_VERSION 0x00097701
4708  */
4709 enum MHD_DigestBaseAlgo
4710 {
4711   /**
4712    * Invalid hash algorithm value
4713    */
4714   MHD_DIGEST_BASE_ALGO_INVALID = 0,
4715 
4716   /**
4717    * MD5 hash algorithm.
4718    * As specified by RFC1321
4719    */
4720   MHD_DIGEST_BASE_ALGO_MD5 = (1 << 0),
4721 
4722   /**
4723    * SHA-256 hash algorithm.
4724    * As specified by FIPS PUB 180-4
4725    */
4726   MHD_DIGEST_BASE_ALGO_SHA256 = (1 << 1),
4727 
4728   /**
4729    * SHA-512/256 hash algorithm.
4730    * As specified by FIPS PUB 180-4
4731    */
4732   MHD_DIGEST_BASE_ALGO_SHA512_256 = (1 << 2)
4733 } _MHD_FIXED_FLAGS_ENUM;
4734 
4735 /**
4736  * The flag indicating non-session algorithm types,
4737  * like 'MD5', 'SHA-256' or 'SHA-512-256'.
4738  * @note Available since #MHD_VERSION 0x00097701
4739  */
4740 #define MHD_DIGEST_AUTH_ALGO3_NON_SESSION    (1 << 6)
4741 
4742 /**
4743  * The flag indicating session algorithm types,
4744  * like 'MD5-sess', 'SHA-256-sess' or 'SHA-512-256-sess'.
4745  * @note Available since #MHD_VERSION 0x00097701
4746  */
4747 #define MHD_DIGEST_AUTH_ALGO3_SESSION        (1 << 7)
4748 
4749 /**
4750  * Digest algorithm identification
4751  * @warning Do not be confused with #MHD_DigestAuthAlgorithm,
4752  *          which uses other values!
4753  * @note Available since #MHD_VERSION 0x00097701
4754  */
4755 enum MHD_DigestAuthAlgo3
4756 {
4757   /**
4758    * Unknown or wrong algorithm type.
4759    * Used in struct MHD_DigestAuthInfo to indicate client value that
4760    * cannot by identified.
4761    */
4762   MHD_DIGEST_AUTH_ALGO3_INVALID = 0,
4763 
4764   /**
4765    * The 'MD5' algorithm, non-session version.
4766    */
4767   MHD_DIGEST_AUTH_ALGO3_MD5 =
4768     MHD_DIGEST_BASE_ALGO_MD5 | MHD_DIGEST_AUTH_ALGO3_NON_SESSION,
4769 
4770   /**
4771    * The 'MD5-sess' algorithm.
4772    * Not supported by MHD for authentication.
4773    */
4774   MHD_DIGEST_AUTH_ALGO3_MD5_SESSION =
4775     MHD_DIGEST_BASE_ALGO_MD5 | MHD_DIGEST_AUTH_ALGO3_SESSION,
4776 
4777   /**
4778    * The 'SHA-256' algorithm, non-session version.
4779    */
4780   MHD_DIGEST_AUTH_ALGO3_SHA256 =
4781     MHD_DIGEST_BASE_ALGO_SHA256 | MHD_DIGEST_AUTH_ALGO3_NON_SESSION,
4782 
4783   /**
4784    * The 'SHA-256-sess' algorithm.
4785    * Not supported by MHD for authentication.
4786    */
4787   MHD_DIGEST_AUTH_ALGO3_SHA256_SESSION =
4788     MHD_DIGEST_BASE_ALGO_SHA256 | MHD_DIGEST_AUTH_ALGO3_SESSION,
4789 
4790   /**
4791    * The 'SHA-512-256' (SHA-512/256) algorithm.
4792    */
4793   MHD_DIGEST_AUTH_ALGO3_SHA512_256 =
4794     MHD_DIGEST_BASE_ALGO_SHA512_256 | MHD_DIGEST_AUTH_ALGO3_NON_SESSION,
4795 
4796   /**
4797    * The 'SHA-512-256-sess' (SHA-512/256 session) algorithm.
4798    * Not supported by MHD for authentication.
4799    */
4800   MHD_DIGEST_AUTH_ALGO3_SHA512_256_SESSION =
4801     MHD_DIGEST_BASE_ALGO_SHA512_256 | MHD_DIGEST_AUTH_ALGO3_SESSION
4802 };
4803 
4804 
4805 /**
4806  * Get digest size for specified algorithm.
4807  *
4808  * The size of the digest specifies the size of the userhash, userdigest
4809  * and other parameters which size depends on used hash algorithm.
4810  * @param algo3 the algorithm to check
4811  * @return the size of the digest (either #MHD_MD5_DIGEST_SIZE or
4812  *         #MHD_SHA256_DIGEST_SIZE/MHD_SHA512_256_DIGEST_SIZE)
4813  *         or zero if the input value is not supported or not valid
4814  * @sa #MHD_digest_auth_calc_userdigest()
4815  * @sa #MHD_digest_auth_calc_userhash(), #MHD_digest_auth_calc_userhash_hex()
4816  * @note Available since #MHD_VERSION 0x00097701
4817  * @ingroup authentication
4818  */
4819 _MHD_EXTERN size_t
4820 MHD_digest_get_hash_size (enum MHD_DigestAuthAlgo3 algo3);
4821 
4822 /**
4823  * Digest algorithm identification, allow multiple selection.
4824  *
4825  * #MHD_DigestAuthAlgo3 always can be casted to #MHD_DigestAuthMultiAlgo3, but
4826  * not vice versa.
4827  *
4828  * @note Available since #MHD_VERSION 0x00097701
4829  */
4830 enum MHD_DigestAuthMultiAlgo3
4831 {
4832   /**
4833    * Unknown or wrong algorithm type.
4834    */
4835   MHD_DIGEST_AUTH_MULT_ALGO3_INVALID = MHD_DIGEST_AUTH_ALGO3_INVALID,
4836 
4837   /**
4838    * The 'MD5' algorithm, non-session version.
4839    */
4840   MHD_DIGEST_AUTH_MULT_ALGO3_MD5 = MHD_DIGEST_AUTH_ALGO3_MD5,
4841 
4842   /**
4843    * The 'MD5-sess' algorithm.
4844    * Not supported by MHD for authentication.
4845    * Reserved value.
4846    */
4847   MHD_DIGEST_AUTH_MULT_ALGO3_MD5_SESSION = MHD_DIGEST_AUTH_ALGO3_MD5_SESSION,
4848 
4849   /**
4850    * The 'SHA-256' algorithm, non-session version.
4851    */
4852   MHD_DIGEST_AUTH_MULT_ALGO3_SHA256 = MHD_DIGEST_AUTH_ALGO3_SHA256,
4853 
4854   /**
4855    * The 'SHA-256-sess' algorithm.
4856    * Not supported by MHD for authentication.
4857    * Reserved value.
4858    */
4859   MHD_DIGEST_AUTH_MULT_ALGO3_SHA256_SESSION =
4860     MHD_DIGEST_AUTH_ALGO3_SHA256_SESSION,
4861 
4862   /**
4863    * The 'SHA-512-256' (SHA-512/256) algorithm, non-session version.
4864    */
4865   MHD_DIGEST_AUTH_MULT_ALGO3_SHA512_256 = MHD_DIGEST_AUTH_ALGO3_SHA512_256,
4866 
4867   /**
4868    * The 'SHA-512-256-sess' (SHA-512/256 session) algorithm.
4869    * Not supported by MHD for authentication.
4870    * Reserved value.
4871    */
4872   MHD_DIGEST_AUTH_MULT_ALGO3_SHA512_256_SESSION =
4873     MHD_DIGEST_AUTH_ALGO3_SHA512_256_SESSION,
4874 
4875   /**
4876    * SHA-256 or SHA-512/256 non-session algorithm, MHD will choose
4877    * the preferred or the matching one.
4878    */
4879   MHD_DIGEST_AUTH_MULT_ALGO3_SHA_ANY_NON_SESSION =
4880     MHD_DIGEST_AUTH_ALGO3_SHA256 | MHD_DIGEST_AUTH_ALGO3_SHA512_256,
4881 
4882   /**
4883    * Any non-session algorithm, MHD will choose the preferred or
4884    * the matching one.
4885    */
4886   MHD_DIGEST_AUTH_MULT_ALGO3_ANY_NON_SESSION =
4887     (0x3F) | MHD_DIGEST_AUTH_ALGO3_NON_SESSION,
4888 
4889   /**
4890    * The SHA-256 or SHA-512/256 session algorithm.
4891    * Not supported by MHD.
4892    * Reserved value.
4893    */
4894   MHD_DIGEST_AUTH_MULT_ALGO3_SHA_ANY_SESSION =
4895     MHD_DIGEST_AUTH_ALGO3_SHA256_SESSION
4896     | MHD_DIGEST_AUTH_ALGO3_SHA512_256_SESSION,
4897 
4898   /**
4899    * Any session algorithm.
4900    * Not supported by MHD.
4901    * Reserved value.
4902    */
4903   MHD_DIGEST_AUTH_MULT_ALGO3_ANY_SESSION =
4904     (0x3F) | MHD_DIGEST_AUTH_ALGO3_SESSION,
4905 
4906   /**
4907    * The MD5 algorithm, session or non-session.
4908    * Currently supported as non-session only.
4909    */
4910   MHD_DIGEST_AUTH_MULT_ALGO3_MD5_ANY =
4911     MHD_DIGEST_AUTH_MULT_ALGO3_MD5 | MHD_DIGEST_AUTH_MULT_ALGO3_MD5_SESSION,
4912 
4913   /**
4914    * The SHA-256 algorithm, session or non-session.
4915    * Currently supported as non-session only.
4916    */
4917   MHD_DIGEST_AUTH_MULT_ALGO3_SHA256_ANY =
4918     MHD_DIGEST_AUTH_MULT_ALGO3_SHA256
4919     | MHD_DIGEST_AUTH_MULT_ALGO3_SHA256_SESSION,
4920 
4921   /**
4922    * The SHA-512/256 algorithm, session or non-session.
4923    * Currently supported as non-session only.
4924    */
4925   MHD_DIGEST_AUTH_MULT_ALGO3_SHA512_256_ANY =
4926     MHD_DIGEST_AUTH_MULT_ALGO3_SHA512_256
4927     | MHD_DIGEST_AUTH_MULT_ALGO3_SHA512_256_SESSION,
4928 
4929   /**
4930    * The SHA-256 or SHA-512/256 algorithm, session or non-session.
4931    * Currently supported as non-session only.
4932    */
4933   MHD_DIGEST_AUTH_MULT_ALGO3_SHA_ANY_ANY =
4934     MHD_DIGEST_AUTH_MULT_ALGO3_SHA_ANY_NON_SESSION
4935     | MHD_DIGEST_AUTH_MULT_ALGO3_SHA_ANY_SESSION,
4936 
4937   /**
4938    * Any algorithm, MHD will choose the preferred or the matching one.
4939    */
4940   MHD_DIGEST_AUTH_MULT_ALGO3_ANY =
4941     (0x3F) | MHD_DIGEST_AUTH_ALGO3_NON_SESSION | MHD_DIGEST_AUTH_ALGO3_SESSION
4942 };
4943 
4944 
4945 /**
4946  * Calculate "userhash", return it as binary data.
4947  *
4948  * The "userhash" is the hash of the string "username:realm".
4949  *
4950  * The "userhash" could be used to avoid sending username in cleartext in Digest
4951  * Authorization client's header.
4952  *
4953  * Userhash is not designed to hide the username in local database or files,
4954  * as username in cleartext is required for #MHD_digest_auth_check3() function
4955  * to check the response, but it can be used to hide username in HTTP headers.
4956  *
4957  * This function could be used when the new username is added to the username
4958  * database to save the "userhash" alongside with the username (preferably) or
4959  * when loading list of the usernames to generate the userhash for every loaded
4960  * username (this will cause delays at the start with the long lists).
4961  *
4962  * Once "userhash" is generated it could be used to identify users by clients
4963  * with "userhash" support.
4964  * Avoid repetitive usage of this function for the same username/realm
4965  * combination as it will cause excessive CPU load; save and re-use the result
4966  * instead.
4967  *
4968  * @param algo3 the algorithm for userhash calculations
4969  * @param username the username
4970  * @param realm the realm
4971  * @param[out] userhash_bin the output buffer for userhash as binary data;
4972  *                          if this function succeeds, then this buffer has
4973  *                          #MHD_digest_get_hash_size(algo3) bytes of userhash
4974  *                          upon return
4975  * @param bin_buf_size the size of the @a userhash_bin buffer, must be
4976  *                     at least #MHD_digest_get_hash_size(algo3) bytes long
4977  * @return MHD_YES on success,
4978  *         MHD_NO if @a bin_buf_size is too small or if @a algo3 algorithm is
4979  *         not supported (or external error has occurred,
4980  *         see #MHD_FEATURE_EXTERN_HASH)
4981  * @sa #MHD_digest_auth_calc_userhash_hex()
4982  * @note Available since #MHD_VERSION 0x00097701
4983  * @ingroup authentication
4984  */
4985 _MHD_EXTERN enum MHD_Result
4986 MHD_digest_auth_calc_userhash (enum MHD_DigestAuthAlgo3 algo3,
4987                                const char *username,
4988                                const char *realm,
4989                                void *userhash_bin,
4990                                size_t bin_buf_size);
4991 
4992 
4993 /**
4994  * Calculate "userhash", return it as hexadecimal string.
4995  *
4996  * The "userhash" is the hash of the string "username:realm".
4997  *
4998  * The "userhash" could be used to avoid sending username in cleartext in Digest
4999  * Authorization client's header.
5000  *
5001  * Userhash is not designed to hide the username in local database or files,
5002  * as username in cleartext is required for #MHD_digest_auth_check3() function
5003  * to check the response, but it can be used to hide username in HTTP headers.
5004  *
5005  * This function could be used when the new username is added to the username
5006  * database to save the "userhash" alongside with the username (preferably) or
5007  * when loading list of the usernames to generate the userhash for every loaded
5008  * username (this will cause delays at the start with the long lists).
5009  *
5010  * Once "userhash" is generated it could be used to identify users by clients
5011  * with "userhash" support.
5012  * Avoid repetitive usage of this function for the same username/realm
5013  * combination as it will cause excessive CPU load; save and re-use the result
5014  * instead.
5015  *
5016  * @param algo3 the algorithm for userhash calculations
5017  * @param username the username
5018  * @param realm the realm
5019  * @param[out] userhash_hex the output buffer for userhash as hex string;
5020  *                          if this function succeeds, then this buffer has
5021  *                          #MHD_digest_get_hash_size(algo3)*2 chars long
5022  *                          userhash zero-terminated string
5023  * @param bin_buf_size the size of the @a userhash_bin buffer, must be
5024  *                     at least #MHD_digest_get_hash_size(algo3)*2+1 chars long
5025  * @return MHD_YES on success,
5026  *         MHD_NO if @a bin_buf_size is too small or if @a algo3 algorithm is
5027  *         not supported (or external error has occurred,
5028  *         see #MHD_FEATURE_EXTERN_HASH).
5029  * @sa #MHD_digest_auth_calc_userhash()
5030  * @note Available since #MHD_VERSION 0x00097701
5031  * @ingroup authentication
5032  */
5033 _MHD_EXTERN enum MHD_Result
5034 MHD_digest_auth_calc_userhash_hex (enum MHD_DigestAuthAlgo3 algo3,
5035                                    const char *username,
5036                                    const char *realm,
5037                                    char *userhash_hex,
5038                                    size_t hex_buf_size);
5039 
5040 
5041 /**
5042  * The type of username used by client in Digest Authorization header
5043  *
5044  * Values are sorted so simplified checks could be used.
5045  * For example:
5046  * * (value <= MHD_DIGEST_AUTH_UNAME_TYPE_INVALID) is true if no valid username
5047  *   is provided by the client
5048  * * (value >= MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH) is true if username is
5049  *   provided in any form
5050  * * (value >= MHD_DIGEST_AUTH_UNAME_TYPE_STANDARD) is true if username is
5051  *   provided in clear text (no userhash matching is needed)
5052  *
5053  * @note Available since #MHD_VERSION 0x00097701
5054  */
5055 enum MHD_DigestAuthUsernameType
5056 {
5057   /**
5058    * No username parameter in in Digest Authorization header.
5059    * This should be treated as an error.
5060    */
5061   MHD_DIGEST_AUTH_UNAME_TYPE_MISSING = 0,
5062 
5063   /**
5064    * The 'username' parameter is used to specify the username.
5065    */
5066   MHD_DIGEST_AUTH_UNAME_TYPE_STANDARD = (1 << 2),
5067 
5068   /**
5069    * The username is specified by 'username*' parameter with
5070    * the extended notation (see RFC 5987 #section-3.2.1).
5071    * The only difference between standard and extended types is
5072    * the way how username value is encoded in the header.
5073    */
5074   MHD_DIGEST_AUTH_UNAME_TYPE_EXTENDED = (1 << 3),
5075 
5076   /**
5077    * The username provided in form of 'userhash' as
5078    * specified by RFC 7616 #section-3.4.4.
5079    * @sa #MHD_digest_auth_calc_userhash_hex(), #MHD_digest_auth_calc_userhash()
5080    */
5081   MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH = (1 << 1),
5082 
5083   /**
5084    * The invalid combination of username parameters are used by client.
5085    * Either:
5086    * * both 'username' and 'username*' are used
5087    * * 'username*' is used with 'userhash=true'
5088    * * 'username*' used with invalid extended notation
5089    * * 'username' is not hexadecimal string, while 'userhash' set to 'true'
5090    */
5091   MHD_DIGEST_AUTH_UNAME_TYPE_INVALID = (1 << 0)
5092 } _MHD_FIXED_ENUM;
5093 
5094 /**
5095  * The QOP ('quality of protection') types.
5096  * @note Available since #MHD_VERSION 0x00097701
5097  */
5098 enum MHD_DigestAuthQOP
5099 {
5100   /**
5101    * Invalid/unknown QOP.
5102    * Used in struct MHD_DigestAuthInfo to indicate client value that
5103    * cannot by identified.
5104    */
5105   MHD_DIGEST_AUTH_QOP_INVALID = 0,
5106 
5107   /**
5108    * No QOP parameter.
5109    * As described in old RFC 2069 original specification.
5110    * This mode is not allowed by latest RFCs and should be used only to
5111    * communicate with clients that do not support more modern modes (with QOP
5112    * parameter).
5113    * This mode is less secure than other modes and inefficient.
5114    */
5115   MHD_DIGEST_AUTH_QOP_NONE = 1 << 0,
5116 
5117   /**
5118    * The 'auth' QOP type.
5119    */
5120   MHD_DIGEST_AUTH_QOP_AUTH = 1 << 1,
5121 
5122   /**
5123    * The 'auth-int' QOP type.
5124    * Not supported by MHD for authentication.
5125    */
5126   MHD_DIGEST_AUTH_QOP_AUTH_INT = 1 << 2
5127 } _MHD_FIXED_FLAGS_ENUM;
5128 
5129 /**
5130  * The QOP ('quality of protection') types, multiple selection.
5131  *
5132  * #MHD_DigestAuthQOP always can be casted to #MHD_DigestAuthMultiQOP, but
5133  * not vice versa.
5134  *
5135  * @note Available since #MHD_VERSION 0x00097701
5136  */
5137 enum MHD_DigestAuthMultiQOP
5138 {
5139   /**
5140    * Invalid/unknown QOP.
5141    */
5142   MHD_DIGEST_AUTH_MULT_QOP_INVALID = MHD_DIGEST_AUTH_QOP_INVALID,
5143 
5144   /**
5145    * No QOP parameter.
5146    * As described in old RFC 2069 original specification.
5147    * This mode is not allowed by latest RFCs and should be used only to
5148    * communicate with clients that do not support more modern modes (with QOP
5149    * parameter).
5150    * This mode is less secure than other modes and inefficient.
5151    */
5152   MHD_DIGEST_AUTH_MULT_QOP_NONE = MHD_DIGEST_AUTH_QOP_NONE,
5153 
5154   /**
5155    * The 'auth' QOP type.
5156    */
5157   MHD_DIGEST_AUTH_MULT_QOP_AUTH = MHD_DIGEST_AUTH_QOP_AUTH,
5158 
5159   /**
5160    * The 'auth-int' QOP type.
5161    * Not supported by MHD.
5162    * Reserved value.
5163    */
5164   MHD_DIGEST_AUTH_MULT_QOP_AUTH_INT = MHD_DIGEST_AUTH_QOP_AUTH_INT,
5165 
5166   /**
5167    * The 'auth' QOP type OR the old RFC2069 (no QOP) type.
5168    * In other words: any types except 'auth-int'.
5169    * RFC2069-compatible mode is allowed, thus this value should be used only
5170    * when it is really necessary.
5171    */
5172   MHD_DIGEST_AUTH_MULT_QOP_ANY_NON_INT =
5173     MHD_DIGEST_AUTH_QOP_NONE | MHD_DIGEST_AUTH_QOP_AUTH,
5174 
5175   /**
5176    * Any 'auth' QOP type ('auth' or 'auth-int').
5177    * Currently supported as 'auth' QOP type only.
5178    */
5179   MHD_DIGEST_AUTH_MULT_QOP_AUTH_ANY =
5180     MHD_DIGEST_AUTH_QOP_AUTH | MHD_DIGEST_AUTH_QOP_AUTH_INT
5181 } _MHD_FIXED_ENUM;
5182 
5183 /**
5184  * The invalid value of 'nc' parameter in client Digest Authorization header.
5185  * @note Available since #MHD_VERSION 0x00097701
5186  */
5187 #define MHD_DIGEST_AUTH_INVALID_NC_VALUE        (0)
5188 
5189 /**
5190  * Information from Digest Authorization client's header.
5191  *
5192  * All buffers pointed by any struct members are freed when #MHD_free() is
5193  * called for pointer to this structure.
5194  *
5195  * Application may modify buffers as needed until #MHD_free() is called for
5196  * pointer to this structure
5197  * @note Available since #MHD_VERSION 0x00097701
5198  */
5199 struct MHD_DigestAuthInfo
5200 {
5201   /**
5202    * The algorithm as defined by client.
5203    * Set automatically to MD5 if not specified by client.
5204    * @warning Do not be confused with #MHD_DigestAuthAlgorithm,
5205    *          which uses other values!
5206    */
5207   enum MHD_DigestAuthAlgo3 algo3;
5208 
5209   /**
5210    * The type of username used by client.
5211    */
5212   enum MHD_DigestAuthUsernameType uname_type;
5213 
5214   /**
5215    * The username string.
5216    * Used only if username type is standard or extended, always NULL otherwise.
5217    * If extended notation is used, this string is pct-decoded string
5218    * with charset and language tag removed (i.e. it is original username
5219    * extracted from the extended notation).
5220    * When userhash is used by the client, this member is NULL and
5221    * @a userhash_hex and @a userhash_bin are set.
5222    * The buffer pointed by the @a username becomes invalid when the pointer
5223    * to the structure is freed by #MHD_free().
5224    */
5225   char *username;
5226 
5227   /**
5228    * The length of the @a username.
5229    * When the @a username is NULL, this member is always zero.
5230    */
5231   size_t username_len;
5232 
5233   /**
5234    * The userhash string.
5235    * Valid only if username type is userhash.
5236    * This is unqoted string without decoding of the hexadecimal
5237    * digits (as provided by the client).
5238    * The buffer pointed by the @a userhash_hex becomes invalid when the pointer
5239    * to the structure is freed by #MHD_free().
5240    * @sa #MHD_digest_auth_calc_userhash_hex()
5241    */
5242   char *userhash_hex;
5243 
5244   /**
5245    * The length of the @a userhash_hex in characters.
5246    * The valid size should be #MHD_digest_get_hash_size(algo3) * 2 characters.
5247    * When the @a userhash_hex is NULL, this member is always zero.
5248    */
5249   size_t userhash_hex_len;
5250 
5251   /**
5252    * The userhash decoded to binary form.
5253    * Used only if username type is userhash, always NULL otherwise.
5254    * When not NULL, this points to binary sequence @a userhash_hex_len /2 bytes
5255    * long.
5256    * The valid size should be #MHD_digest_get_hash_size(algo3) bytes.
5257    * The buffer pointed by the @a userhash_bin becomes invalid when the pointer
5258    * to the structure is freed by #MHD_free().
5259    * @warning This is a binary data, no zero termination.
5260    * @warning To avoid buffer overruns, always check the size of the data before
5261    *          use, because @a userhash_bin can point even to zero-sized
5262    *          data.
5263    * @sa #MHD_digest_auth_calc_userhash()
5264    */
5265   uint8_t *userhash_bin;
5266 
5267   /**
5268    * The 'opaque' parameter value, as specified by client.
5269    * NULL if not specified by client.
5270    * The buffer pointed by the @a opaque becomes invalid when the pointer
5271    * to the structure is freed by #MHD_free().
5272    */
5273   char *opaque;
5274 
5275   /**
5276    * The length of the @a opaque.
5277    * When the @a opaque is NULL, this member is always zero.
5278    */
5279   size_t opaque_len;
5280 
5281   /**
5282    * The 'realm' parameter value, as specified by client.
5283    * NULL if not specified by client.
5284    * The buffer pointed by the @a realm becomes invalid when the pointer
5285    * to the structure is freed by #MHD_free().
5286    */
5287   char *realm;
5288 
5289   /**
5290    * The length of the @a realm.
5291    * When the @a realm is NULL, this member is always zero.
5292    */
5293   size_t realm_len;
5294 
5295   /**
5296    * The 'qop' parameter value.
5297    */
5298   enum MHD_DigestAuthQOP qop;
5299 
5300   /**
5301    * The length of the 'cnonce' parameter value, including possible
5302    * backslash-escape characters.
5303    * 'cnonce' is used in hash calculation, which is CPU-intensive procedure.
5304    * An application may want to reject too large cnonces to limit the CPU load.
5305    * A few kilobytes is a reasonable limit, typically cnonce is just 32-160
5306    * characters long.
5307    */
5308   size_t cnonce_len;
5309 
5310   /**
5311    * The nc parameter value.
5312    * Can be used by application to limit the number of nonce re-uses. If @a nc
5313    * is higher than application wants to allow, then "auth required" response
5314    * with 'stale=true' could be used to force client to retry with the fresh
5315    * 'nonce'.
5316    * If not specified by client or does not have hexadecimal digits only, the
5317    * value is #MHD_DIGEST_AUTH_INVALID_NC_VALUE.
5318    */
5319   uint32_t nc;
5320 };
5321 
5322 
5323 /**
5324  * Get information about Digest Authorization client's header.
5325  *
5326  * @param connection The MHD connection structure
5327  * @return NULL if no valid Digest Authorization header is used in the request;
5328  *         a pointer to the structure with information if the valid request
5329  *         header found, free using #MHD_free().
5330  * @sa #MHD_digest_auth_get_username3()
5331  * @note Available since #MHD_VERSION 0x00097701
5332  * @ingroup authentication
5333  */
5334 _MHD_EXTERN struct MHD_DigestAuthInfo *
5335 MHD_digest_auth_get_request_info3 (struct MHD_Connection *connection);
5336 
5337 
5338 /**
5339  * Information from Digest Authorization client's header.
5340  *
5341  * All buffers pointed by any struct members are freed when #MHD_free() is
5342  * called for pointer to this structure.
5343  *
5344  * Application may modify buffers as needed until #MHD_free() is called for
5345  * pointer to this structure
5346  * @note Available since #MHD_VERSION 0x00097701
5347  */
5348 struct MHD_DigestAuthUsernameInfo
5349 {
5350   /**
5351    * The algorithm as defined by client.
5352    * Set automatically to MD5 if not specified by client.
5353    * @warning Do not be confused with #MHD_DigestAuthAlgorithm,
5354    *          which uses other values!
5355    */
5356   enum MHD_DigestAuthAlgo3 algo3;
5357 
5358   /**
5359    * The type of username used by client.
5360    * The 'invalid' and 'missing' types are not used in this structure,
5361    * instead NULL is returned by #MHD_digest_auth_get_username3().
5362    */
5363   enum MHD_DigestAuthUsernameType uname_type;
5364 
5365   /**
5366    * The username string.
5367    * Used only if username type is standard or extended, always NULL otherwise.
5368    * If extended notation is used, this string is pct-decoded string
5369    * with charset and language tag removed (i.e. it is original username
5370    * extracted from the extended notation).
5371    * When userhash is used by the client, this member is NULL and
5372    * @a userhash_hex and @a userhash_bin are set.
5373    * The buffer pointed by the @a username becomes invalid when the pointer
5374    * to the structure is freed by #MHD_free().
5375    */
5376   char *username;
5377 
5378   /**
5379    * The length of the @a username.
5380    * When the @a username is NULL, this member is always zero.
5381    */
5382   size_t username_len;
5383 
5384   /**
5385    * The userhash string.
5386    * Valid only if username type is userhash.
5387    * This is unqoted string without decoding of the hexadecimal
5388    * digits (as provided by the client).
5389    * The buffer pointed by the @a userhash_hex becomes invalid when the pointer
5390    * to the structure is freed by #MHD_free().
5391    * @sa #MHD_digest_auth_calc_userhash_hex()
5392    */
5393   char *userhash_hex;
5394 
5395   /**
5396    * The length of the @a userhash_hex in characters.
5397    * The valid size should be #MHD_digest_get_hash_size(algo3) * 2 characters.
5398    * When the @a userhash_hex is NULL, this member is always zero.
5399    */
5400   size_t userhash_hex_len;
5401 
5402   /**
5403    * The userhash decoded to binary form.
5404    * Used only if username type is userhash, always NULL otherwise.
5405    * When not NULL, this points to binary sequence @a userhash_hex_len /2 bytes
5406    * long.
5407    * The valid size should be #MHD_digest_get_hash_size(algo3) bytes.
5408    * The buffer pointed by the @a userhash_bin becomes invalid when the pointer
5409    * to the structure is freed by #MHD_free().
5410    * @warning This is a binary data, no zero termination.
5411    * @warning To avoid buffer overruns, always check the size of the data before
5412    *          use, because @a userhash_bin can point even to zero-sized
5413    *          data.
5414    * @sa #MHD_digest_auth_calc_userhash()
5415    */
5416   uint8_t *userhash_bin;
5417 };
5418 
5419 
5420 /**
5421  * Get the username from Digest Authorization client's header.
5422  *
5423  * @param connection The MHD connection structure
5424  * @return NULL if no valid Digest Authorization header is used in the request,
5425  *         or no username parameter is present in the header, or username is
5426  *         provided incorrectly by client (see description for
5427  *         #MHD_DIGEST_AUTH_UNAME_TYPE_INVALID);
5428  *         a pointer structure with information if the valid request header
5429  *         found, free using #MHD_free().
5430  * @sa #MHD_digest_auth_get_request_info3() provides more complete information
5431  * @note Available since #MHD_VERSION 0x00097701
5432  * @ingroup authentication
5433  */
5434 _MHD_EXTERN struct MHD_DigestAuthUsernameInfo *
5435 MHD_digest_auth_get_username3 (struct MHD_Connection *connection);
5436 
5437 
5438 /**
5439  * The result of digest authentication of the client.
5440  *
5441  * All error values are zero or negative.
5442  *
5443  * @note Available since #MHD_VERSION 0x00097701
5444  */
5445 enum MHD_DigestAuthResult
5446 {
5447   /**
5448    * Authentication OK.
5449    */
5450   MHD_DAUTH_OK = 1,
5451 
5452   /**
5453    * General error, like "out of memory".
5454    */
5455   MHD_DAUTH_ERROR = 0,
5456 
5457   /**
5458    * No "Authorization" header or wrong format of the header.
5459    * Also may be returned if required parameters in client Authorisation header
5460    * are missing or broken (in invalid format).
5461    */
5462   MHD_DAUTH_WRONG_HEADER = -1,
5463 
5464   /**
5465    * Wrong 'username'.
5466    */
5467   MHD_DAUTH_WRONG_USERNAME = -2,
5468 
5469   /**
5470    * Wrong 'realm'.
5471    */
5472   MHD_DAUTH_WRONG_REALM = -3,
5473 
5474   /**
5475    * Wrong 'URI' (or URI parameters).
5476    */
5477   MHD_DAUTH_WRONG_URI = -4,
5478 
5479   /**
5480    * Wrong 'qop'.
5481    */
5482   MHD_DAUTH_WRONG_QOP = -5,
5483 
5484   /**
5485    * Wrong 'algorithm'.
5486    */
5487   MHD_DAUTH_WRONG_ALGO = -6,
5488 
5489   /**
5490    * Too large (>64 KiB) Authorization parameter value.
5491    */
5492   MHD_DAUTH_TOO_LARGE = -15,
5493 
5494   /* The different form of naming is intentionally used for the results below,
5495    * as they are more important */
5496 
5497   /**
5498    * The 'nonce' is too old. Suggest the client to retry with the same
5499    * username and password to get the fresh 'nonce'.
5500    * The validity of the 'nonce' may be not checked.
5501    */
5502   MHD_DAUTH_NONCE_STALE = -17,
5503 
5504   /**
5505    * The 'nonce' was generated by MHD for other conditions.
5506    * This value is only returned if #MHD_OPTION_DIGEST_AUTH_NONCE_BIND_TYPE
5507    * is set to anything other than #MHD_DAUTH_BIND_NONCE_NONE.
5508    * The interpretation of this code could be different. For example, if
5509    * #MHD_DAUTH_BIND_NONCE_URI is set and client just used the same 'nonce' for
5510    * another URI, the code could be handled as #MHD_DAUTH_NONCE_STALE as
5511    * RFCs allow nonces re-using for other URIs in the same "protection
5512    * space". However, if only #MHD_DAUTH_BIND_NONCE_CLIENT_IP bit is set and
5513    * it is know that clients have fixed IP addresses, this return code could
5514    * be handled like #MHD_DAUTH_NONCE_WRONG.
5515    */
5516   MHD_DAUTH_NONCE_OTHER_COND = -18,
5517 
5518   /**
5519    * The 'nonce' is wrong. May indicate an attack attempt.
5520    */
5521   MHD_DAUTH_NONCE_WRONG = -33,
5522 
5523   /**
5524    * The 'response' is wrong. Typically it means that wrong password used.
5525    * May indicate an attack attempt.
5526    */
5527   MHD_DAUTH_RESPONSE_WRONG = -34
5528 };
5529 
5530 
5531 /**
5532  * Authenticates the authorization header sent by the client.
5533  *
5534  * If RFC2069 mode is allowed by setting bit #MHD_DIGEST_AUTH_QOP_NONE in
5535  * @a mqop and the client uses this mode, then server generated nonces are
5536  * used as one-time nonces because nonce-count is not supported in this old RFC.
5537  * Communication in this mode is very inefficient, especially if the client
5538  * requests several resources one-by-one as for every request a new nonce must
5539  * be generated and client repeats all requests twice (first time to get a new
5540  * nonce and second time to perform an authorised request).
5541  *
5542  * @param connection the MHD connection structure
5543  * @param realm the realm for authorization of the client
5544  * @param username the username to be authenticated, must be in clear text
5545  *                 even if userhash is used by the client
5546  * @param password the password matching the @a username (and the @a realm)
5547  * @param nonce_timeout the period of seconds since nonce generation, when
5548  *                      the nonce is recognised as valid and not stale;
5549  *                      if zero is specified then daemon default value is used.
5550  * @param max_nc the maximum allowed nc (Nonce Count) value, if client's nc
5551  *               exceeds the specified value then MHD_DAUTH_NONCE_STALE is
5552  *               returned;
5553  *               if zero is specified then daemon default value is used.
5554  * @param mqop the QOP to use
5555  * @param malgo3 digest algorithms allowed to use, fail if algorithm used
5556  *               by the client is not allowed by this parameter
5557  * @return #MHD_DAUTH_OK if authenticated,
5558  *         the error code otherwise
5559  * @note Available since #MHD_VERSION 0x00097708
5560  * @ingroup authentication
5561  */
5562 _MHD_EXTERN enum MHD_DigestAuthResult
5563 MHD_digest_auth_check3 (struct MHD_Connection *connection,
5564                         const char *realm,
5565                         const char *username,
5566                         const char *password,
5567                         unsigned int nonce_timeout,
5568                         uint32_t max_nc,
5569                         enum MHD_DigestAuthMultiQOP mqop,
5570                         enum MHD_DigestAuthMultiAlgo3 malgo3);
5571 
5572 
5573 /**
5574  * Calculate userdigest, return it as a binary data.
5575  *
5576  * The "userdigest" is the hash of the "username:realm:password" string.
5577  *
5578  * The "userdigest" can be used to avoid storing the password in clear text
5579  * in database/files
5580  *
5581  * This function is designed to improve security of stored credentials,
5582  * the "userdigest" does not improve security of the authentication process.
5583  *
5584  * The results can be used to store username & userdigest pairs instead of
5585  * username & password pairs. To further improve security, application may
5586  * store username & userhash & userdigest triplets.
5587  *
5588  * @param algo3 the digest algorithm
5589  * @param username the username
5590  * @param realm the realm
5591  * @param password the password
5592  * @param[out] userdigest_bin the output buffer for userdigest;
5593  *                            if this function succeeds, then this buffer has
5594  *                            #MHD_digest_get_hash_size(algo3) bytes of
5595  *                            userdigest upon return
5596  * @param bin_buf_size the size of the @a userdigest_bin buffer, must be
5597  *                     at least #MHD_digest_get_hash_size(algo3) bytes long
5598  * @return MHD_YES on success,
5599  *         MHD_NO if @a userdigest_bin is too small or if @a algo3 algorithm is
5600  *         not supported (or external error has occurred,
5601  *         see #MHD_FEATURE_EXTERN_HASH).
5602  * @sa #MHD_digest_auth_check_digest3()
5603  * @note Available since #MHD_VERSION 0x00097701
5604  * @ingroup authentication
5605  */
5606 _MHD_EXTERN enum MHD_Result
5607 MHD_digest_auth_calc_userdigest (enum MHD_DigestAuthAlgo3 algo3,
5608                                  const char *username,
5609                                  const char *realm,
5610                                  const char *password,
5611                                  void *userdigest_bin,
5612                                  size_t bin_buf_size);
5613 
5614 
5615 /**
5616  * Authenticates the authorization header sent by the client by using
5617  * hash of "username:realm:password".
5618  *
5619  * If RFC2069 mode is allowed by setting bit #MHD_DIGEST_AUTH_QOP_NONE in
5620  * @a mqop and the client uses this mode, then server generated nonces are
5621  * used as one-time nonces because nonce-count is not supported in this old RFC.
5622  * Communication in this mode is very inefficient, especially if the client
5623  * requests several resources one-by-one as for every request a new nonce must
5624  * be generated and client repeats all requests twice (first time to get a new
5625  * nonce and second time to perform an authorised request).
5626  *
5627  * @param connection the MHD connection structure
5628  * @param realm the realm for authorization of the client
5629  * @param username the username to be authenticated, must be in clear text
5630  *                 even if userhash is used by the client
5631  * @param userdigest the precalculated binary hash of the string
5632  *                   "username:realm:password",
5633  *                   see #MHD_digest_auth_calc_userdigest()
5634  * @param userdigest_size the size of the @a userdigest in bytes, must match the
5635  *                        hashing algorithm (see #MHD_MD5_DIGEST_SIZE,
5636  *                        #MHD_SHA256_DIGEST_SIZE, #MHD_SHA512_256_DIGEST_SIZE,
5637  *                        #MHD_digest_get_hash_size())
5638  * @param nonce_timeout the period of seconds since nonce generation, when
5639  *                      the nonce is recognised as valid and not stale;
5640  *                      if zero is specified then daemon default value is used.
5641  * @param max_nc the maximum allowed nc (Nonce Count) value, if client's nc
5642  *               exceeds the specified value then MHD_DAUTH_NONCE_STALE is
5643  *               returned;
5644  *               if zero is specified then daemon default value is used.
5645  * @param mqop the QOP to use
5646  * @param malgo3 digest algorithms allowed to use, fail if algorithm used
5647  *               by the client is not allowed by this parameter;
5648  *               more than one base algorithms (MD5, SHA-256, SHA-512/256)
5649  *               cannot be used at the same time for this function
5650  *               as @a userdigest must match specified algorithm
5651  * @return #MHD_DAUTH_OK if authenticated,
5652  *         the error code otherwise
5653  * @sa #MHD_digest_auth_calc_userdigest()
5654  * @note Available since #MHD_VERSION 0x00097701
5655  * @ingroup authentication
5656  */
5657 _MHD_EXTERN enum MHD_DigestAuthResult
5658 MHD_digest_auth_check_digest3 (struct MHD_Connection *connection,
5659                                const char *realm,
5660                                const char *username,
5661                                const void *userdigest,
5662                                size_t userdigest_size,
5663                                unsigned int nonce_timeout,
5664                                uint32_t max_nc,
5665                                enum MHD_DigestAuthMultiQOP mqop,
5666                                enum MHD_DigestAuthMultiAlgo3 malgo3);
5667 
5668 
5669 /**
5670  * Queues a response to request authentication from the client
5671  *
5672  * This function modifies provided @a response. The @a response must not be
5673  * reused and should be destroyed (by #MHD_destroy_response()) after call of
5674  * this function.
5675  *
5676  * If @a mqop allows both RFC 2069 (MHD_DIGEST_AUTH_QOP_NONE) and QOP with
5677  * value, then response is formed like if MHD_DIGEST_AUTH_QOP_NONE bit was
5678  * not set, because such response should be backward-compatible with RFC 2069.
5679  *
5680  * If @a mqop allows only MHD_DIGEST_AUTH_MULT_QOP_NONE, then the response is
5681  * formed in strict accordance with RFC 2069 (no 'qop', no 'userhash', no
5682  * 'charset'). For better compatibility with clients, it is recommended (but
5683  * not required) to set @a domain to NULL in this mode.
5684  *
5685  * @param connection the MHD connection structure
5686  * @param realm the realm presented to the client
5687  * @param opaque the string for opaque value, can be NULL, but NULL is
5688  *               not recommended for better compatibility with clients;
5689  *               the recommended format is hex or Base64 encoded string
5690  * @param domain the optional space-separated list of URIs for which the
5691  *               same authorisation could be used, URIs can be in form
5692  *               "path-absolute" (the path for the same host with initial slash)
5693  *               or in form "absolute-URI" (the full path with protocol), in
5694  *               any case client may assume that URI is in the same "protection
5695  *               space" if it starts with any of values specified here;
5696  *               could be NULL (clients typically assume that the same
5697  *               credentials could be used for any URI on the same host);
5698  *               this list provides information for the client only and does
5699  *               not actually restrict anything on the server side
5700  * @param response the reply to send; should contain the "access denied"
5701  *                 body;
5702  *                 note: this function sets the "WWW Authenticate" header and
5703  *                 the caller should not set this header;
5704  *                 the NULL is tolerated
5705  * @param signal_stale if set to #MHD_YES then indication of stale nonce used in
5706  *                     the client's request is signalled by adding 'stale=true'
5707  *                     to the authentication header, this instructs the client
5708  *                     to retry immediately with the new nonce and the same
5709  *                     credentials, without asking user for the new password
5710  * @param mqop the QOP to use
5711  * @param malgo3 digest algorithm to use; if several algorithms are allowed
5712  *               then MD5 is preferred (currently, may be changed in next
5713  *               versions)
5714  * @param userhash_support if set to non-zero value (#MHD_YES) then support of
5715  *                         userhash is indicated, allowing client to provide
5716  *                         hash("username:realm") instead of the username in
5717  *                         clear text;
5718  *                         note that clients are allowed to provide the username
5719  *                         in cleartext even if this parameter set to non-zero;
5720  *                         when userhash is used, application must be ready to
5721  *                         identify users by provided userhash value instead of
5722  *                         username; see #MHD_digest_auth_calc_userhash() and
5723  *                         #MHD_digest_auth_calc_userhash_hex()
5724  * @param prefer_utf8 if not set to #MHD_NO, parameter 'charset=UTF-8' is
5725  *                    added, indicating for the client that UTF-8 encoding for
5726  *                    the username is preferred
5727  * @return #MHD_YES on success, #MHD_NO otherwise
5728  * @note Available since #MHD_VERSION 0x00097701
5729  * @ingroup authentication
5730  */
5731 _MHD_EXTERN enum MHD_Result
5732 MHD_queue_auth_required_response3 (struct MHD_Connection *connection,
5733                                    const char *realm,
5734                                    const char *opaque,
5735                                    const char *domain,
5736                                    struct MHD_Response *response,
5737                                    int signal_stale,
5738                                    enum MHD_DigestAuthMultiQOP mqop,
5739                                    enum MHD_DigestAuthMultiAlgo3 algo,
5740                                    int userhash_support,
5741                                    int prefer_utf8);
5742 
5743 
5744 /**
5745  * Constant to indicate that the nonce of the provided
5746  * authentication code was wrong.
5747  * Used as return code by #MHD_digest_auth_check(), #MHD_digest_auth_check2(),
5748  * #MHD_digest_auth_check_digest(), #MHD_digest_auth_check_digest2().
5749  * @ingroup authentication
5750  */
5751 #define MHD_INVALID_NONCE -1
5752 
5753 
5754 /**
5755  * Get the username from the authorization header sent by the client
5756  *
5757  * This function supports username in standard and extended notations.
5758  * "userhash" is not supported by this function.
5759  *
5760  * @param connection The MHD connection structure
5761  * @return NULL if no username could be found, username provided as
5762  *         "userhash", extended notation broken or memory allocation error
5763  *         occurs;
5764  *         a pointer to the username if found, free using #MHD_free().
5765  * @warning Returned value must be freed by #MHD_free().
5766  * @sa #MHD_digest_auth_get_username3()
5767  * @ingroup authentication
5768  */
5769 _MHD_EXTERN char *
5770 MHD_digest_auth_get_username (struct MHD_Connection *connection);
5771 
5772 
5773 /**
5774  * Which digest algorithm should MHD use for HTTP digest authentication?
5775  * Used as parameter for #MHD_digest_auth_check2(),
5776  * #MHD_digest_auth_check_digest2(), #MHD_queue_auth_fail_response2().
5777  */
5778 enum MHD_DigestAuthAlgorithm
5779 {
5780 
5781   /**
5782    * MHD should pick (currently defaults to MD5).
5783    */
5784   MHD_DIGEST_ALG_AUTO = 0,
5785 
5786   /**
5787    * Force use of MD5.
5788    */
5789   MHD_DIGEST_ALG_MD5,
5790 
5791   /**
5792    * Force use of SHA-256.
5793    */
5794   MHD_DIGEST_ALG_SHA256
5795 
5796 } _MHD_FIXED_ENUM;
5797 
5798 
5799 /**
5800  * Authenticates the authorization header sent by the client.
5801  *
5802  * @param connection The MHD connection structure
5803  * @param realm The realm presented to the client
5804  * @param username The username needs to be authenticated
5805  * @param password The password used in the authentication
5806  * @param nonce_timeout The amount of time for a nonce to be
5807  *      invalid in seconds
5808  * @param algo digest algorithms allowed for verification
5809  * @return #MHD_YES if authenticated, #MHD_NO if not,
5810  *         #MHD_INVALID_NONCE if nonce is invalid or stale
5811  * @note Available since #MHD_VERSION 0x00096200
5812  * @deprecated use MHD_digest_auth_check3()
5813  * @ingroup authentication
5814  */
5815 _MHD_EXTERN int
5816 MHD_digest_auth_check2 (struct MHD_Connection *connection,
5817                         const char *realm,
5818                         const char *username,
5819                         const char *password,
5820                         unsigned int nonce_timeout,
5821                         enum MHD_DigestAuthAlgorithm algo);
5822 
5823 
5824 /**
5825  * Authenticates the authorization header sent by the client.
5826  * Uses #MHD_DIGEST_ALG_MD5 (for now, for backwards-compatibility).
5827  * Note that this MAY change to #MHD_DIGEST_ALG_AUTO in the future.
5828  * If you want to be sure you get MD5, use #MHD_digest_auth_check2()
5829  * and specify MD5 explicitly.
5830  *
5831  * @param connection The MHD connection structure
5832  * @param realm The realm presented to the client
5833  * @param username The username needs to be authenticated
5834  * @param password The password used in the authentication
5835  * @param nonce_timeout The amount of time for a nonce to be
5836  *      invalid in seconds
5837  * @return #MHD_YES if authenticated, #MHD_NO if not,
5838  *         #MHD_INVALID_NONCE if nonce is invalid or stale
5839  * @deprecated use MHD_digest_auth_check3()
5840  * @ingroup authentication
5841  */
5842 _MHD_EXTERN int
5843 MHD_digest_auth_check (struct MHD_Connection *connection,
5844                        const char *realm,
5845                        const char *username,
5846                        const char *password,
5847                        unsigned int nonce_timeout);
5848 
5849 
5850 /**
5851  * Authenticates the authorization header sent by the client.
5852  *
5853  * @param connection The MHD connection structure
5854  * @param realm The realm presented to the client
5855  * @param username The username needs to be authenticated
5856  * @param digest An `unsigned char *' pointer to the binary MD5 sum
5857  *      for the precalculated hash value "username:realm:password"
5858  *      of @a digest_size bytes
5859  * @param digest_size number of bytes in @a digest (size must match @a algo!)
5860  * @param nonce_timeout The amount of time for a nonce to be
5861  *      invalid in seconds
5862  * @param algo digest algorithms allowed for verification
5863  * @return #MHD_YES if authenticated, #MHD_NO if not,
5864  *         #MHD_INVALID_NONCE if nonce is invalid or stale
5865  * @note Available since #MHD_VERSION 0x00096200
5866  * @deprecated use MHD_digest_auth_check_digest3()
5867  * @ingroup authentication
5868  */
5869 _MHD_EXTERN int
5870 MHD_digest_auth_check_digest2 (struct MHD_Connection *connection,
5871                                const char *realm,
5872                                const char *username,
5873                                const uint8_t *digest,
5874                                size_t digest_size,
5875                                unsigned int nonce_timeout,
5876                                enum MHD_DigestAuthAlgorithm algo);
5877 
5878 
5879 /**
5880  * Authenticates the authorization header sent by the client
5881  * Uses #MHD_DIGEST_ALG_MD5 (required, as @a digest is of fixed
5882  * size).
5883  *
5884  * @param connection The MHD connection structure
5885  * @param realm The realm presented to the client
5886  * @param username The username needs to be authenticated
5887  * @param digest An `unsigned char *' pointer to the binary hash
5888  *    for the precalculated hash value "username:realm:password";
5889  *    length must be #MHD_MD5_DIGEST_SIZE bytes
5890  * @param nonce_timeout The amount of time for a nonce to be
5891  *      invalid in seconds
5892  * @return #MHD_YES if authenticated, #MHD_NO if not,
5893  *         #MHD_INVALID_NONCE if nonce is invalid or stale
5894  * @note Available since #MHD_VERSION 0x00096000
5895  * @deprecated use #MHD_digest_auth_check_digest3()
5896  * @ingroup authentication
5897  */
5898 _MHD_EXTERN int
5899 MHD_digest_auth_check_digest (struct MHD_Connection *connection,
5900                               const char *realm,
5901                               const char *username,
5902                               const uint8_t digest[MHD_MD5_DIGEST_SIZE],
5903                               unsigned int nonce_timeout);
5904 
5905 
5906 /**
5907  * Queues a response to request authentication from the client
5908  *
5909  * This function modifies provided @a response. The @a response must not be
5910  * reused and should be destroyed after call of this function.
5911  *
5912  * @param connection The MHD connection structure
5913  * @param realm the realm presented to the client
5914  * @param opaque string to user for opaque value
5915  * @param response reply to send; should contain the "access denied"
5916  *        body; note that this function will set the "WWW Authenticate"
5917  *        header and that the caller should not do this; the NULL is tolerated
5918  * @param signal_stale #MHD_YES if the nonce is stale to add
5919  *        'stale=true' to the authentication header
5920  * @param algo digest algorithm to use
5921  * @return #MHD_YES on success, #MHD_NO otherwise
5922  * @note Available since #MHD_VERSION 0x00096200
5923  * @deprecated use MHD_queue_auth_required_response3()
5924  * @ingroup authentication
5925  */
5926 _MHD_EXTERN enum MHD_Result
5927 MHD_queue_auth_fail_response2 (struct MHD_Connection *connection,
5928                                const char *realm,
5929                                const char *opaque,
5930                                struct MHD_Response *response,
5931                                int signal_stale,
5932                                enum MHD_DigestAuthAlgorithm algo);
5933 
5934 
5935 /**
5936  * Queues a response to request authentication from the client.
5937  * For now uses MD5 (for backwards-compatibility). Still, if you
5938  * need to be sure, use #MHD_queue_auth_fail_response2().
5939  *
5940  * This function modifies provided @a response. The @a response must not be
5941  * reused and should be destroyed after call of this function.
5942  *
5943  * @param connection The MHD connection structure
5944  * @param realm the realm presented to the client
5945  * @param opaque string to user for opaque value
5946  * @param response reply to send; should contain the "access denied"
5947  *        body; note that this function will set the "WWW Authenticate"
5948  *        header and that the caller should not do this; the NULL is tolerated
5949  * @param signal_stale #MHD_YES if the nonce is stale to add
5950  *        'stale=true' to the authentication header
5951  * @return #MHD_YES on success, #MHD_NO otherwise
5952  * @deprecated use MHD_queue_auth_required_response3()
5953  * @ingroup authentication
5954  */
5955 _MHD_EXTERN enum MHD_Result
5956 MHD_queue_auth_fail_response (struct MHD_Connection *connection,
5957                               const char *realm,
5958                               const char *opaque,
5959                               struct MHD_Response *response,
5960                               int signal_stale);
5961 
5962 
5963 /* ********************* Basic Authentication functions *************** */
5964 
5965 
5966 /**
5967  * Information decoded from Basic Authentication client's header.
5968  *
5969  * The username and the password are technically allowed to have binary zeros,
5970  * username_len and password_len could be used to detect such situations.
5971  *
5972  * The buffers pointed by username and password members are freed
5973  * when #MHD_free() is called for pointer to this structure.
5974  *
5975  * Application may modify buffers as needed until #MHD_free() is called for
5976  * pointer to this structure
5977  */
5978 struct MHD_BasicAuthInfo
5979 {
5980   /**
5981    * The username, cannot be NULL.
5982    * The buffer pointed by the @a username becomes invalid when the pointer
5983    * to the structure is freed by #MHD_free().
5984    */
5985   char *username;
5986 
5987   /**
5988    * The length of the @a username, not including zero-termination
5989    */
5990   size_t username_len;
5991 
5992   /**
5993    * The password, may be NULL if password is not encoded by the client.
5994    * The buffer pointed by the @a password becomes invalid when the pointer
5995    * to the structure is freed by #MHD_free().
5996    */
5997   char *password;
5998 
5999   /**
6000    * The length of the @a password, not including zero-termination;
6001    * when the @a password is NULL, the length is always zero.
6002    */
6003   size_t password_len;
6004 };
6005 
6006 /**
6007  * Get the username and password from the Basic Authorisation header
6008  * sent by the client
6009  *
6010  * @param connection the MHD connection structure
6011  * @return NULL if no valid Basic Authentication header is present in
6012  *         current request, or
6013  *         pointer to structure with username and password, which must be
6014  *         freed by #MHD_free().
6015  * @note Available since #MHD_VERSION 0x00097701
6016  * @ingroup authentication
6017  */
6018 _MHD_EXTERN struct MHD_BasicAuthInfo *
6019 MHD_basic_auth_get_username_password3 (struct MHD_Connection *connection);
6020 
6021 /**
6022  * Queues a response to request basic authentication from the client.
6023  *
6024  * The given response object is expected to include the payload for
6025  * the response; the "WWW-Authenticate" header will be added and the
6026  * response queued with the 'UNAUTHORIZED' status code.
6027  *
6028  * See RFC 7617#section-2 for details.
6029  *
6030  * The @a response is modified by this function. The modified response object
6031  * can be used to respond subsequent requests by #MHD_queue_response()
6032  * function with status code #MHD_HTTP_UNAUTHORIZED and must not be used again
6033  * with MHD_queue_basic_auth_required_response3() function. The response could
6034  * be destroyed right after call of this function.
6035  *
6036  * @param connection the MHD connection structure
6037  * @param realm the realm presented to the client
6038  * @param prefer_utf8 if not set to #MHD_NO, parameter'charset="UTF-8"' will
6039  *                    be added, indicating for client that UTF-8 encoding
6040  *                    is preferred
6041  * @param response the response object to modify and queue; the NULL
6042  *                 is tolerated
6043  * @return #MHD_YES on success, #MHD_NO otherwise
6044  * @note Available since #MHD_VERSION 0x00097704
6045  * @ingroup authentication
6046  */
6047 _MHD_EXTERN enum MHD_Result
6048 MHD_queue_basic_auth_required_response3 (struct MHD_Connection *connection,
6049                                          const char *realm,
6050                                          int prefer_utf8,
6051                                          struct MHD_Response *response);
6052 
6053 /**
6054  * Get the username and password from the basic authorization header sent by the client
6055  *
6056  * @param connection The MHD connection structure
6057  * @param[out] password a pointer for the password, free using #MHD_free().
6058  * @return NULL if no username could be found, a pointer
6059  *      to the username if found, free using #MHD_free().
6060  * @deprecated use #MHD_basic_auth_get_username_password3()
6061  * @ingroup authentication
6062  */
6063 _MHD_EXTERN char *
6064 MHD_basic_auth_get_username_password (struct MHD_Connection *connection,
6065                                       char **password);
6066 
6067 
6068 /**
6069  * Queues a response to request basic authentication from the client
6070  * The given response object is expected to include the payload for
6071  * the response; the "WWW-Authenticate" header will be added and the
6072  * response queued with the 'UNAUTHORIZED' status code.
6073  *
6074  * @param connection The MHD connection structure
6075  * @param realm the realm presented to the client
6076  * @param response response object to modify and queue; the NULL is tolerated
6077  * @return #MHD_YES on success, #MHD_NO otherwise
6078  * @deprecated use MHD_queue_basic_auth_required_response3()
6079  * @ingroup authentication
6080  */
6081 _MHD_EXTERN enum MHD_Result
6082 MHD_queue_basic_auth_fail_response (struct MHD_Connection *connection,
6083                                     const char *realm,
6084                                     struct MHD_Response *response);
6085 
6086 /* ********************** generic query functions ********************** */
6087 
6088 
6089 /**
6090  * Obtain information about the given connection.
6091  * The returned pointer is invalidated with the next call of this function or
6092  * when the connection is closed.
6093  *
6094  * @param connection what connection to get information about
6095  * @param info_type what information is desired?
6096  * @param ... depends on @a info_type
6097  * @return NULL if this information is not available
6098  *         (or if the @a info_type is unknown)
6099  * @ingroup specialized
6100  */
6101 _MHD_EXTERN const union MHD_ConnectionInfo *
6102 MHD_get_connection_info (struct MHD_Connection *connection,
6103                          enum MHD_ConnectionInfoType info_type,
6104                          ...);
6105 
6106 
6107 /**
6108  * MHD connection options.  Given to #MHD_set_connection_option to
6109  * set custom options for a particular connection.
6110  */
6111 enum MHD_CONNECTION_OPTION
6112 {
6113 
6114   /**
6115    * Set a custom timeout for the given connection.  Specified
6116    * as the number of seconds, given as an `unsigned int`.  Use
6117    * zero for no timeout.
6118    * If timeout was set to zero (or unset) before, setup of new value by
6119    * MHD_set_connection_option() will reset timeout timer.
6120    * Values larger than (UINT64_MAX / 2000 - 1) will
6121    * be clipped to this number.
6122    */
6123   MHD_CONNECTION_OPTION_TIMEOUT
6124 
6125 } _MHD_FIXED_ENUM;
6126 
6127 
6128 /**
6129  * Set a custom option for the given connection, overriding defaults.
6130  *
6131  * @param connection connection to modify
6132  * @param option option to set
6133  * @param ... arguments to the option, depending on the option type
6134  * @return #MHD_YES on success, #MHD_NO if setting the option failed
6135  * @ingroup specialized
6136  */
6137 _MHD_EXTERN enum MHD_Result
6138 MHD_set_connection_option (struct MHD_Connection *connection,
6139                            enum MHD_CONNECTION_OPTION option,
6140                            ...);
6141 
6142 
6143 /**
6144  * Information about an MHD daemon.
6145  */
6146 union MHD_DaemonInfo
6147 {
6148   /**
6149    * Size of the key, no longer supported.
6150    * @deprecated
6151    */
6152   size_t key_size;
6153 
6154   /**
6155    * Size of the mac key, no longer supported.
6156    * @deprecated
6157    */
6158   size_t mac_key_size;
6159 
6160   /**
6161    * Socket, returned for #MHD_DAEMON_INFO_LISTEN_FD.
6162    */
6163   MHD_socket listen_fd;
6164 
6165   /**
6166    * Bind port number, returned for #MHD_DAEMON_INFO_BIND_PORT.
6167    */
6168   uint16_t port;
6169 
6170   /**
6171    * epoll FD, returned for #MHD_DAEMON_INFO_EPOLL_FD.
6172    */
6173   int epoll_fd;
6174 
6175   /**
6176    * Number of active connections, for #MHD_DAEMON_INFO_CURRENT_CONNECTIONS.
6177    */
6178   unsigned int num_connections;
6179 
6180   /**
6181    * Combination of #MHD_FLAG values, for #MHD_DAEMON_INFO_FLAGS.
6182    * This value is actually a bitfield.
6183    * Note: flags may differ from original 'flags' specified for
6184    * daemon, especially if #MHD_USE_AUTO was set.
6185    */
6186   enum MHD_FLAG flags;
6187 };
6188 
6189 
6190 /**
6191  * Obtain information about the given daemon.
6192  * The returned pointer is invalidated with the next call of this function or
6193  * when the daemon is stopped.
6194  *
6195  * @param daemon what daemon to get information about
6196  * @param info_type what information is desired?
6197  * @param ... depends on @a info_type
6198  * @return NULL if this information is not available
6199  *         (or if the @a info_type is unknown)
6200  * @ingroup specialized
6201  */
6202 _MHD_EXTERN const union MHD_DaemonInfo *
6203 MHD_get_daemon_info (struct MHD_Daemon *daemon,
6204                      enum MHD_DaemonInfoType info_type,
6205                      ...);
6206 
6207 
6208 /**
6209  * Obtain the version of this library
6210  *
6211  * @return static version string, e.g. "0.9.9"
6212  * @ingroup specialized
6213  */
6214 _MHD_EXTERN const char *
6215 MHD_get_version (void);
6216 
6217 
6218 /**
6219  * Obtain the version of this library as a binary value.
6220  *
6221  * @return version binary value, e.g. "0x00090900" (#MHD_VERSION of
6222  *         compiled MHD binary)
6223  * @note Available since #MHD_VERSION 0x00097601
6224  * @ingroup specialized
6225  */
6226 _MHD_EXTERN uint32_t
6227 MHD_get_version_bin (void);
6228 
6229 
6230 /**
6231  * Types of information about MHD features,
6232  * used by #MHD_is_feature_supported().
6233  */
6234 enum MHD_FEATURE
6235 {
6236   /**
6237    * Get whether messages are supported. If supported then in debug
6238    * mode messages can be printed to stderr or to external logger.
6239    */
6240   MHD_FEATURE_MESSAGES = 1,
6241 
6242   /**
6243    * Get whether HTTPS is supported.  If supported then flag
6244    * #MHD_USE_TLS and options #MHD_OPTION_HTTPS_MEM_KEY,
6245    * #MHD_OPTION_HTTPS_MEM_CERT, #MHD_OPTION_HTTPS_MEM_TRUST,
6246    * #MHD_OPTION_HTTPS_MEM_DHPARAMS, #MHD_OPTION_HTTPS_CRED_TYPE,
6247    * #MHD_OPTION_HTTPS_PRIORITIES can be used.
6248    */
6249   MHD_FEATURE_TLS = 2,
6250   MHD_FEATURE_SSL = 2,
6251 
6252   /**
6253    * Get whether option #MHD_OPTION_HTTPS_CERT_CALLBACK is
6254    * supported.
6255    */
6256   MHD_FEATURE_HTTPS_CERT_CALLBACK = 3,
6257 
6258   /**
6259    * Get whether IPv6 is supported. If supported then flag
6260    * #MHD_USE_IPv6 can be used.
6261    */
6262   MHD_FEATURE_IPv6 = 4,
6263 
6264   /**
6265    * Get whether IPv6 without IPv4 is supported. If not supported
6266    * then IPv4 is always enabled in IPv6 sockets and
6267    * flag #MHD_USE_DUAL_STACK is always used when #MHD_USE_IPv6 is
6268    * specified.
6269    */
6270   MHD_FEATURE_IPv6_ONLY = 5,
6271 
6272   /**
6273    * Get whether `poll()` is supported. If supported then flag
6274    * #MHD_USE_POLL can be used.
6275    */
6276   MHD_FEATURE_POLL = 6,
6277 
6278   /**
6279    * Get whether `epoll()` is supported. If supported then Flags
6280    * #MHD_USE_EPOLL and
6281    * #MHD_USE_EPOLL_INTERNAL_THREAD can be used.
6282    */
6283   MHD_FEATURE_EPOLL = 7,
6284 
6285   /**
6286    * Get whether shutdown on listen socket to signal other
6287    * threads is supported. If not supported flag
6288    * #MHD_USE_ITC is automatically forced.
6289    */
6290   MHD_FEATURE_SHUTDOWN_LISTEN_SOCKET = 8,
6291 
6292   /**
6293    * Get whether socketpair is used internally instead of pipe to
6294    * signal other threads.
6295    */
6296   MHD_FEATURE_SOCKETPAIR = 9,
6297 
6298   /**
6299    * Get whether TCP Fast Open is supported. If supported then
6300    * flag #MHD_USE_TCP_FASTOPEN and option
6301    * #MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE can be used.
6302    */
6303   MHD_FEATURE_TCP_FASTOPEN = 10,
6304 
6305   /**
6306    * Get whether HTTP Basic authorization is supported. If supported
6307    * then functions #MHD_basic_auth_get_username_password and
6308    * #MHD_queue_basic_auth_fail_response can be used.
6309    */
6310   MHD_FEATURE_BASIC_AUTH = 11,
6311 
6312   /**
6313    * Get whether HTTP Digest authorization is supported. If
6314    * supported then options #MHD_OPTION_DIGEST_AUTH_RANDOM,
6315    * #MHD_OPTION_NONCE_NC_SIZE and
6316    * #MHD_digest_auth_check() can be used.
6317    */
6318   MHD_FEATURE_DIGEST_AUTH = 12,
6319 
6320   /**
6321    * Get whether postprocessor is supported. If supported then
6322    * functions #MHD_create_post_processor(), #MHD_post_process() and
6323    * #MHD_destroy_post_processor() can
6324    * be used.
6325    */
6326   MHD_FEATURE_POSTPROCESSOR = 13,
6327 
6328   /**
6329   * Get whether password encrypted private key for HTTPS daemon is
6330   * supported. If supported then option
6331   * ::MHD_OPTION_HTTPS_KEY_PASSWORD can be used.
6332   */
6333   MHD_FEATURE_HTTPS_KEY_PASSWORD = 14,
6334 
6335   /**
6336    * Get whether reading files beyond 2 GiB boundary is supported.
6337    * If supported then #MHD_create_response_from_fd(),
6338    * #MHD_create_response_from_fd64 #MHD_create_response_from_fd_at_offset()
6339    * and #MHD_create_response_from_fd_at_offset64() can be used with sizes and
6340    * offsets larger than 2 GiB. If not supported value of size+offset is
6341    * limited to 2 GiB.
6342    */
6343   MHD_FEATURE_LARGE_FILE = 15,
6344 
6345   /**
6346    * Get whether MHD set names on generated threads.
6347    */
6348   MHD_FEATURE_THREAD_NAMES = 16,
6349   MHD_THREAD_NAMES = 16,
6350 
6351   /**
6352    * Get whether HTTP "Upgrade" is supported.
6353    * If supported then #MHD_ALLOW_UPGRADE, #MHD_upgrade_action() and
6354    * #MHD_create_response_for_upgrade() can be used.
6355    */
6356   MHD_FEATURE_UPGRADE = 17,
6357 
6358   /**
6359    * Get whether it's safe to use same FD for multiple calls of
6360    * #MHD_create_response_from_fd() and whether it's safe to use single
6361    * response generated by #MHD_create_response_from_fd() with multiple
6362    * connections at same time.
6363    * If #MHD_is_feature_supported() return #MHD_NO for this feature then
6364    * usage of responses with same file FD in multiple parallel threads may
6365    * results in incorrect data sent to remote client.
6366    * It's always safe to use same file FD in multiple responses if MHD
6367    * is run in any single thread mode.
6368    */
6369   MHD_FEATURE_RESPONSES_SHARED_FD = 18,
6370 
6371   /**
6372    * Get whether MHD support automatic detection of bind port number.
6373    * @sa #MHD_DAEMON_INFO_BIND_PORT
6374    */
6375   MHD_FEATURE_AUTODETECT_BIND_PORT = 19,
6376 
6377   /**
6378    * Get whether MHD supports automatic SIGPIPE suppression.
6379    * If SIGPIPE suppression is not supported, application must handle
6380    * SIGPIPE signal by itself.
6381    */
6382   MHD_FEATURE_AUTOSUPPRESS_SIGPIPE = 20,
6383 
6384   /**
6385    * Get whether MHD use system's sendfile() function to send
6386    * file-FD based responses over non-TLS connections.
6387    * @note Since v0.9.56
6388    */
6389   MHD_FEATURE_SENDFILE = 21,
6390 
6391   /**
6392    * Get whether MHD supports threads.
6393    */
6394   MHD_FEATURE_THREADS = 22,
6395 
6396   /**
6397    * Get whether option #MHD_OPTION_HTTPS_CERT_CALLBACK2 is
6398    * supported.
6399    */
6400   MHD_FEATURE_HTTPS_CERT_CALLBACK2 = 23,
6401 
6402   /**
6403    * Get whether automatic parsing of HTTP Cookie header is supported.
6404    * If disabled, no MHD_COOKIE_KIND will be generated by MHD.
6405    * MHD versions before 0x00097701 always support cookie parsing.
6406    * @note Available since #MHD_VERSION 0x00097701
6407    */
6408   MHD_FEATURE_HTTPS_COOKIE_PARSING = 24,
6409 
6410   /**
6411    * Get whether the early version the Digest Authorization (RFC 2069) is
6412    * supported (digest authorisation without QOP parameter).
6413    * Since #MHD_VERSION 0x00097701 it is always supported if Digest Auth
6414    * module is built.
6415    * @note Available since #MHD_VERSION 0x00097701
6416    */
6417   MHD_FEATURE_DIGEST_AUTH_RFC2069 = 25,
6418 
6419   /**
6420    * Get whether the MD5-based hashing algorithms are supported for Digest
6421    * Authorization.
6422    * Currently it is always supported if Digest Auth module is built
6423    * unless manually disabled in a custom build.
6424    * @note Available since #MHD_VERSION 0x00097701
6425    */
6426   MHD_FEATURE_DIGEST_AUTH_MD5 = 26,
6427 
6428   /**
6429    * Get whether the SHA-256-based hashing algorithms are supported for Digest
6430    * Authorization.
6431    * It is always supported since #MHD_VERSION 0x00096200 if Digest Auth
6432    * module is built unless manually disabled in a custom build.
6433    * @note Available since #MHD_VERSION 0x00097701
6434    */
6435   MHD_FEATURE_DIGEST_AUTH_SHA256 = 27,
6436 
6437   /**
6438    * Get whether the SHA-512/256-based hashing algorithms are supported
6439    * for Digest Authorization.
6440    * It it always supported since #MHD_VERSION 0x00097701 if Digest Auth
6441    * module is built unless manually disabled in a custom build.
6442    * @note Available since #MHD_VERSION 0x00097701
6443    */
6444   MHD_FEATURE_DIGEST_AUTH_SHA512_256 = 28,
6445 
6446   /**
6447    * Get whether QOP with value 'auth-int' (authentication with integrity
6448    * protection) is supported for Digest Authorization.
6449    * Currently it is always not supported.
6450    * @note Available since #MHD_VERSION 0x00097701
6451    */
6452   MHD_FEATURE_DIGEST_AUTH_AUTH_INT = 29,
6453 
6454   /**
6455    * Get whether 'session' algorithms (like 'MD5-sess') are supported for Digest
6456    * Authorization.
6457    * Currently it is always not supported.
6458    * @note Available since #MHD_VERSION 0x00097701
6459    */
6460   MHD_FEATURE_DIGEST_AUTH_ALGO_SESSION = 30,
6461 
6462   /**
6463    * Get whether 'userhash' is supported for Digest Authorization.
6464    * It is always supported since #MHD_VERSION 0x00097701 if Digest Auth
6465    * module is built.
6466    * @note Available since #MHD_VERSION 0x00097701
6467    */
6468   MHD_FEATURE_DIGEST_AUTH_USERHASH = 31,
6469 
6470   /**
6471    * Get whether any of hashing algorithms is implemented by external
6472    * function (like TLS library) and may fail due to external conditions,
6473    * like "out-of-memory".
6474    *
6475    * If result is #MHD_YES then functions which use hash calculations
6476    * like #MHD_digest_auth_calc_userhash(), #MHD_digest_auth_check3() and others
6477    * potentially may fail even with valid input because of out-of-memory error
6478    * or crypto accelerator device failure, however in practice such fails are
6479    * unlikely.
6480    * @note Available since #MHD_VERSION 0x00097701
6481    */
6482   MHD_FEATURE_EXTERN_HASH = 32,
6483 
6484   /**
6485    * Get whether MHD was built with asserts enabled.
6486    * For debug builds the error log is always enabled even if #MHD_USE_ERROR_LOG
6487    * is not specified for daemon.
6488    * @note Available since #MHD_VERSION 0x00097701
6489    */
6490   MHD_FEATURE_DEBUG_BUILD = 33,
6491 
6492   /**
6493    * Get whether MHD was build with support for overridable FD_SETSIZE.
6494    * This feature should be always available when the relevant platform ability
6495    * is detected.
6496    * @sa #MHD_OPTION_APP_FD_SETSIZE
6497    * @note Available since #MHD_VERSION 0x00097705
6498    */
6499   MHD_FEATURE_FLEXIBLE_FD_SETSIZE = 34
6500 };
6501 
6502 
6503 /**
6504  * Get information about supported MHD features.
6505  * Indicate that MHD was compiled with or without support for
6506  * particular feature. Some features require additional support
6507  * by kernel. Kernel support is not checked by this function.
6508  *
6509  * @param feature type of requested information
6510  * @return #MHD_YES if feature is supported by MHD, #MHD_NO if
6511  * feature is not supported or feature is unknown.
6512  * @ingroup specialized
6513  */
6514 _MHD_EXTERN enum MHD_Result
6515 MHD_is_feature_supported (enum MHD_FEATURE feature);
6516 
6517 
6518 #ifdef __cplusplus
6519 #if 0                           /* keep Emacsens' auto-indent happy */
6520 {
6521 #endif
6522 }
6523 #endif
6524 
6525 #endif