libmicrohttpd2

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

microhttpd2.h (397410B)


      1 /* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
      2 /*
      3   This file is part of GNU libmicrohttpd.
      4   Copyright (C) 2006-2026 Christian Grothoff, Karlson2k (Evgeny Grin)
      5   (and other contributing authors)
      6 
      7   GNU libmicrohttpd is free software; you can redistribute it and/or
      8   modify it under the terms of the GNU Lesser General Public
      9   License as published by the Free Software Foundation; either
     10   version 2.1 of the License, or (at your option) any later version.
     11 
     12   GNU libmicrohttpd is distributed in the hope that it will be useful,
     13   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15   Lesser General Public License for more details.
     16 
     17   Alternatively, you can redistribute GNU libmicrohttpd and/or
     18   modify it under the terms of the GNU General Public License as
     19   published by the Free Software Foundation; either version 2 of
     20   the License, or (at your option) any later version, together
     21   with the eCos exception, as follows:
     22 
     23     As a special exception, if other files instantiate templates or
     24     use macros or inline functions from this file, or you compile this
     25     file and link it with other works to produce a work based on this
     26     file, this file does not by itself cause the resulting work to be
     27     covered by the GNU General Public License. However the source code
     28     for this file must still be made available in accordance with
     29     section (3) of the GNU General Public License v2.
     30 
     31     This exception does not invalidate any other reasons why a work
     32     based on this file might be covered by the GNU General Public
     33     License.
     34 
     35   You should have received copies of the GNU Lesser General Public
     36   License and the GNU General Public License along with this library;
     37   if not, see <https://www.gnu.org/licenses/>.
     38 */
     39 
     40 /*
     41   Main goals for the libmicrohttpd 2.0 API:
     42 
     43   - simplify application callbacks by splitting header/upload/post
     44     functionality currently provided by calling the same
     45     MHD_AccessHandlerCallback 3+ times into separate callbacks.
     46   - keep the API very simple for simple requests, but allow
     47     more complex logic to be incrementally introduced
     48     (via new struct MHD_Action construction)
     49   - avoid repeated scans for URL matches via the new
     50     struct MHD_Action construction
     51   - better types, in particular avoid varargs for options
     52   - make it harder to pass inconsistent options
     53   - combine options and flags into more uniform API (at least
     54     exterally!)
     55   - simplify API use by using sane defaults (benefiting from
     56     breaking backwards compatibility) and making all options
     57     really optional, and where applicable avoid having options
     58     where the default works if nothing is specified
     59   - simplify API by moving rarely used http_version into
     60     MHD_request_get_info_fixed()
     61   - avoid 'int' for MHD_YES/MHD_NO by introducing `enum MHD_Bool`
     62   - improve terminology by eliminating confusion between
     63     'request' and 'connection'; add 'session' for HTTP2/3;
     64     use clear separation between connection and request. Do not mix the kind
     65     data in the callbacks.  Currently we are mixing things in
     66     MHD_AccessHandlerCallback and MHD_RequestCompletedCallback. Instead of
     67     pointers to struct MHD_Connection we should use pointers to (new) struct
     68     MHD_Request.
     69   - prepare API for having multiple TLS backends
     70   - use more consistent prefixes for related functions
     71     by using MHD_subject_verb_object naming convention, also
     72     at the same time avoid symbol conflict with legacy names
     73     (so we can have one binary implementing old and new
     74     library API at the same time via compatibility layer).
     75   - make it impossible to queue a response at the wrong time
     76   - make it impossible to suspend a connection/request at the
     77     wrong time (improves thread-safety)
     78   - make it clear which response status codes are "properly"
     79     supported (include the descriptive string) by using an enum;
     80   - simplify API for common-case of one-shot responses by
     81     eliminating need for destroy response in most cases;
     82   - avoid fixed types, like uint32_t. They may not exist on some
     83     platforms. Instead use uint_fast32_t.
     84     It is also better for future-proof.
     85   - check portability for embedded platforms. Some of them support
     86     64 bits, but 'int' could be just 16 bits resulting of silently
     87     dropping enum values higher than 65535.
     88     => in general, more functions, fewer enums for setup
     89   - Avoid returning pointers to internal members. It is not thread-safe and
     90     even in single thread the value could change over the time. Prefer pointers to
     91     app-allocated memory with the size, like MHD_daemon_get_static_info(enum
     92     MHD_enum_name info_type, void *buf, size_t buf_size).
     93     => Except in cases where zero-copy matters.
     94   - Use separate app calls/functions for data the will not change for the
     95     lifetime of the object and dynamic data. The only difference should be the
     96     name. Like MHD_daemon_get_static_info(enum MHD_enum_name info_type, void *buf,
     97     size_t buf_size) MHD_daemon_get_dynamic_info(enum MHD_enum_name info_type,
     98     void *buf, size_t buf_size) Examples of static data: listen socket, number of
     99     workers, daemon flags.  Examples of dynamic data: number of connections,
    100     quiesce status.  It should give a clear idea whether the data could be changed
    101     over the time (could be not obvious for some data) and thus may change the
    102     approach how to use the data in app.  The same for: library, daemon,
    103     connection, request. Not sure that dynamic data makes sense for the library.
    104   - Define response code in response object. There are a very little
    105     chance that response body designed for 404 or 403 codes will be used with
    106     200 code. However, the responses body for 307 and 308 could be the same. So:
    107     Add default response code in response object.
    108   - Make responses unmodifiable after first use. It is not thread-safe.
    109     MHD-generated headers (Date, Connection/Keep-Alive) are again
    110     part of the *request* and do not count as part of the "response" here.
    111   - Remove "footers" from responses. With unmodifiable responses everything should
    112     be "headers". Add footers to *requests* instead.
    113   - Add API for adding request-specific response headers and footers. To
    114     simplify the things it should just copy the strings (to avoid dealing with
    115     complicated deinit of possible dynamic strings).  After this change it should
    116     be possible to simplify DAuth handling as response could be reused (currently
    117     403 responses are modified for each reply).
    118   - Control response behaviour mainly by response flags, not by additional
    119     headers (like MHD_RF_FORCE_CLOSE instead of "Connection: close").
    120     It is easier&faster for both: app and MHD.
    121   - Move response codes from MHD_HTTP_xxx namespace to MHD_HTTP_CODE_xxx
    122     namespace. It already may clash with other HTTP values.
    123   - Postprocessor is unusable night-mare when doing "stream processing"
    124     for tiny values where the application basically has to copy together
    125     the stream back into a single compact heap value, just making the
    126     parsing highly more complicated (see examples in Challenger)
    127   - non-stream processing variant for request bodies, give apps a
    128     way to request the full body in one buffer; give apps a way
    129     to request a 'large new allocation' for such buffers; give apps
    130     a way to specify a global quota for large allocations to ensure
    131     memory usage has a hard bound
    132 
    133   - Internals: carefully check where locking is really required. Probably
    134     separate locks. Check out-of-thread value reading. Currently code assumes
    135     atomic reading of values used in other threads, which mostly true on x86,
    136     but not OK on other arches. Probably use read/write locking to minimize
    137     the threads interference.
    138   - Internals: figure out how to do portable variant of cork/uncork
    139   - Internals: remove request data from memory pool when response is queued
    140     (IF no callbacks and thus data cannot be used anymore, or IF
    141      application permits explicitly per daemon) to get more space
    142     for building response;
    143   - Internals: Fix TCP FIN graceful closure issue for upgraded
    144     connections (API implications?)
    145 
    146 */
    147 
    148 #ifndef MICROHTTPD2_H
    149 #define MICROHTTPD2_H
    150 
    151 #ifndef __cplusplus
    152 #  define MHD_C_DECLARATIONS_START_HERE_   /* Empty */
    153 #  define MHD_C_DECLARATIONS_FINISH_HERE_  /* Empty */
    154 #else  /* __cplusplus */
    155 /* *INDENT-OFF* */
    156 #  define MHD_C_DECLARATIONS_START_HERE_   extern "C" {
    157 #  define MHD_C_DECLARATIONS_FINISH_HERE_  }
    158 /* *INDENT-ON* */
    159 #endif /* __cplusplus */
    160 
    161 MHD_C_DECLARATIONS_START_HERE_
    162 
    163 /**
    164  * Current version of the library in packed BCD form.
    165  * (For example, version 1.9.30-1 would be 0x01093001)
    166  */
    167 #define MHD_VERSION 0x01990001
    168 
    169 #include "microhttpd2_portability.h"
    170 
    171 /* If generic headers do not work on your platform, include headers that
    172    define 'va_list', 'size_t', 'uint_least16_t', 'uint_fast32_t',
    173    'uint_fast64_t', and 'struct sockaddr', and then
    174    add "#define MHD_HAVE_SYS_HEADERS_INCLUDED" before including "microhttpd2.h".
    175    When 'MHD_HAVE_SYS_HEADERS_INCLUDED' is defined, the following "standard"
    176    includes will not be used (which might be a good idea, especially on
    177    platforms where they do not exist).
    178    */
    179 #ifndef MHD_HAVE_SYS_HEADERS_INCLUDED
    180 #  include <stdarg.h>
    181 #  ifndef MHD_SYS_BASE_TYPES_H
    182 /* Headers for uint_fastXX_t, size_t */
    183 #    include <stdint.h>
    184 #    include <stddef.h>
    185 #    include <sys/types.h> /* This header is actually optional */
    186 #  endif
    187 #  ifndef MHD_SYS_SOCKET_TYPES_H
    188 /* Headers for 'struct sockaddr' */
    189 #    if !defined(_WIN32) || defined(__CYGWIN__)
    190 #      include <sys/socket.h>
    191 #    else
    192 /* Prevent conflict of <winsock.h> and <winsock2.h> */
    193 #      if !defined(_WINSOCK2API_) && !defined(_WINSOCKAPI_)
    194 #        ifndef WIN32_LEAN_AND_MEAN
    195 /* Do not use unneeded parts of W32 headers. */
    196 #          define WIN32_LEAN_AND_MEAN 1
    197 #        endif /* !WIN32_LEAN_AND_MEAN */
    198 #        include <winsock2.h>
    199 #      endif
    200 #    endif
    201 #  endif
    202 #endif
    203 
    204 #ifndef MHD_BOOL_DEFINED
    205 
    206 /**
    207  * Representation of 'bool' in the public API as stdbool.h may not
    208  * always be available and presence of 'bool' keyword may depend on
    209  * used C version.
    210  * It is always safe to cast 'MHD_Bool' variable to 'bool' and vice versa.
    211  * Note: it may be UNSAFE to cast pointers 'MHD_Bool*' to 'bool*' and
    212  *       vice versa.
    213  */
    214 enum MHD_Bool
    215 {
    216 
    217   /**
    218    * MHD-internal return code for "NO".
    219    */
    220   MHD_NO = 0
    221   ,
    222   /**
    223    * MHD-internal return code for "YES".  All non-zero values
    224    * will be interpreted as "YES", but MHD will only ever
    225    * return #MHD_YES or #MHD_NO.
    226    */
    227   MHD_YES = 1
    228 };
    229 
    230 
    231 #  define MHD_BOOL_DEFINED 1
    232 #endif /* ! MHD_BOOL_DEFINED */
    233 
    234 #ifndef MHD_STRINGS_DEFINED
    235 
    236 
    237 /**
    238  * String with length data.
    239  * This type should always have valid @a cstr pointer.
    240  */
    241 struct MHD_String
    242 {
    243   /**
    244    * Number of characters in @e str, not counting 0-termination.
    245    */
    246   size_t len;
    247 
    248   /**
    249    * 0-terminated C-string.
    250    * Must not be NULL.
    251    */
    252   const char *cstr;
    253 };
    254 
    255 /**
    256  * String with length data.
    257  * This type of data may have NULL as the @a cstr pointer.
    258  */
    259 struct MHD_StringNullable
    260 {
    261   /**
    262    * Number of characters in @e cstr, not counting 0-termination.
    263    * If @a cstr is NULL, it must be zero.
    264    */
    265   size_t len;
    266 
    267   /**
    268    * 0-terminated C-string.
    269    * In some cases it could be NULL.
    270    */
    271   const char *cstr;
    272 };
    273 
    274 #  define MHD_STRINGS_DEFINED 1
    275 #endif /* ! MHD_STRINGS_DEFINED */
    276 
    277 
    278 #ifndef MHD_INVALID_SOCKET
    279 #  if !defined(_WIN32) || defined(_SYS_TYPES_FD_SET)
    280 #    define MHD_SOCKETS_KIND_POSIX 1
    281 /**
    282  * MHD_Socket is a type for socket FDs
    283  */
    284 typedef int MHD_Socket;
    285 #    define MHD_INVALID_SOCKET (-1)
    286 #  else /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */
    287 #    define MHD_SOCKETS_KIND_WINSOCK 1
    288 /**
    289  * MHD_Socket is a type for socket FDs
    290  */
    291 typedef SOCKET MHD_Socket;
    292 #    define MHD_INVALID_SOCKET (INVALID_SOCKET)
    293 #  endif /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */
    294 #endif /* MHD_INVALID_SOCKET */
    295 
    296 
    297 /**
    298  * Constant used to indicate unknown size (use when creating a response).
    299  * Any possible larger sizes are interpreted as the same value.
    300  */
    301 #ifdef UINT64_MAX
    302 #  define MHD_SIZE_UNKNOWN UINT64_MAX
    303 #else
    304 #  define MHD_SIZE_UNKNOWN \
    305           MHD_STATIC_CAST_ (uint_fast64_t,0xffffffffffffffffU)
    306 #endif
    307 
    308 
    309 /**
    310  * Constant used to indicate unlimited wait time.
    311  * Any possible larger values are interpreted as this value.
    312  */
    313 #ifdef UINT64_MAX
    314 #  define MHD_WAIT_INDEFINITELY UINT64_MAX
    315 #else
    316 #  define MHD_WAIT_INDEFINITELY \
    317           MHD_STATIC_CAST_ (uint_fast64_t,0xffffffffffffffffU)
    318 #endif
    319 
    320 
    321 /* ********** (a) Core HTTP Processing ************ */
    322 
    323 
    324 /**
    325  * @brief Handle for a daemon that listens for requests.
    326  *
    327  * Manages the listen socket, event loop, optional threads and server
    328  * settings.
    329  *
    330  * @defgroup daemon HTTP server handling client connections
    331  */
    332 struct MHD_Daemon;
    333 
    334 
    335 /**
    336  * @brief Handle/identifier of a network connection abstraction.
    337  *
    338  * A single network (i.e. TCP) connection can be used for
    339  * a single (in HTTP/1.1) data stream.
    340  *
    341  * @defgroup connection client connection with streams
    342  */
    343 struct MHD_Connection;
    344 
    345 
    346 /**
    347  * @brief Handle/identifier of a data stream over network
    348  * connection.
    349  *
    350  * A data stream may be used for multiple requests, which
    351  * in HTTP/1.1 must be processed sequentially.
    352  *
    353  * @defgroup stream stream of HTTP requests
    354  */
    355 struct MHD_Stream;
    356 
    357 /**
    358  * @brief Handle representing an HTTP request.
    359  *
    360  * With HTTP/1.1, multiple requests can be run over the same
    361  * stream.  However, MHD will only show one request per data
    362  * stream to the client at any given time.
    363  *
    364  * Replaces `struct MHD_Connection` in the API prior to version 2.0.0,
    365  * renamed to better reflect what this object truly represents to
    366  * the application using MHD.
    367  *
    368  * @defgroup request HTTP requests
    369  */
    370 struct MHD_Request;
    371 
    372 
    373 /**
    374  * @brief Actions are returned by the application when processed client header
    375  * to drive the request handling of MHD.
    376  *
    377  * @defgroup action Request actions
    378  */
    379 struct MHD_Action;
    380 
    381 
    382 /**
    383  * @brief Actions are returned by the application when processing client upload
    384  * to drive the request handling of MHD.
    385  *
    386  * @defgroup action Request actions
    387  */
    388 struct MHD_UploadAction;
    389 
    390 /**
    391  * @defgroup general Primary MHD functions and data
    392  */
    393 
    394 /**
    395  * @defgroup specialized Introspection and other special control
    396  */
    397 
    398 /**
    399  * @defgroup authentication Digest and other HTTP authentications
    400  */
    401 
    402 
    403 /**
    404  * Status codes returned by API functions, also used for logging.
    405  *
    406  * As a return value, zero (#MHD_SC_OK) always indicates success.
    407  * Values 00001-09999 must be handled explicitly by the application.
    408  * Values 10000-19999 are informational events.
    409  * Values 20000-29999 indicate successful operations.
    410  * Values 30000-39999 indicate unsuccessful but normal operations.
    411  * Values 40000-49999 indicate client (or network) errors.
    412  * Values 50000-59999 indicate MHD-internal (or platform) errors.
    413  * Values 60000-65535 indicate application errors.
    414  *
    415  * @ingroup general
    416  */
    417 enum MHD_FIXED_ENUM_MHD_SET_ MHD_StatusCode
    418 {
    419 
    420   /* 00000-level codes are return values the application must handle.
    421      The zero code always means success. */
    422 
    423   /**
    424    * Successful operation (not used for logging).
    425    * The code is guaranteed to be always zero.
    426    */
    427   MHD_SC_OK = 0
    428   ,
    429 
    430   /* 10000-level codes are purely informational events. */
    431 
    432   /**
    433    * Informational event, MHD started.
    434    */
    435   MHD_SC_DAEMON_STARTED = 10000
    436   ,
    437   /**
    438    * Informational event, we accepted a connection.
    439    */
    440   MHD_SC_CONNECTION_ACCEPTED = 10001
    441   ,
    442   /**
    443    * Informational event, thread processing connection terminates.
    444    */
    445   MHD_SC_THREAD_TERMINATING = 10002
    446   ,
    447   /**
    448    * Informational event, state machine status for a connection.
    449    */
    450   MHD_SC_STATE_MACHINE_STATUS_REPORT = 10003
    451   ,
    452   /**
    453    * accept() returned transient error.
    454    */
    455   MHD_SC_ACCEPT_FAILED_EAGAIN = 10004
    456   ,
    457   /**
    458    * Accepted socket is unknown type (probably non-IP).
    459    */
    460   MHD_SC_ACCEPTED_UNKNOWN_TYPE = 10040
    461   ,
    462   /**
    463    * The sockaddr for the accepted socket does not fit the buffer.
    464    * (Strange)
    465    */
    466   MHD_SC_ACCEPTED_SOCKADDR_TOO_LARGE = 10041
    467   ,
    468 
    469   /* 20000-level codes indicate successful operations. */
    470   /* Examples: a connection has been closed normally, the response data
    471      generation has been completed. */
    472 
    473   /**
    474    * MHD is closing a connection after the client closed it
    475    * (perfectly normal end).
    476    */
    477   MHD_SC_CONNECTION_CLOSED = 20000
    478   ,
    479   /**
    480    * MHD is closing a connection because the application
    481    * logic to generate the response data completed.
    482    */
    483   MHD_SC_APPLICATION_DATA_GENERATION_FINISHED = 20001
    484   ,
    485   /**
    486    * The request does not contain a particular type of Authentication
    487    * credentials
    488    */
    489   MHD_SC_AUTH_ABSENT = 20060
    490   ,
    491 
    492   /* 30000-level codes indicate unsuccessful but normal operations. */
    493   /* Examples: a connections limit has been reached, the accept policy
    494      callback has rejected a connection, a memory pool is exhausted. */
    495 
    496 
    497   /**
    498    * Resource limit in terms of number of parallel connections
    499    * hit.
    500    */
    501   MHD_SC_LIMIT_CONNECTIONS_REACHED = 30000
    502   ,
    503   /**
    504    * The operation failed because the respective
    505    * daemon is already too deep inside of the shutdown
    506    * activity.
    507    */
    508   MHD_SC_DAEMON_ALREADY_SHUTDOWN = 30020
    509   ,
    510   /**
    511    * Failed to start new thread because of system limits.
    512    */
    513   MHD_SC_CONNECTION_THREAD_SYS_LIMITS_REACHED = 30030
    514   ,
    515   /**
    516    * Failed to start a thread.
    517    */
    518   MHD_SC_CONNECTION_THREAD_LAUNCH_FAILURE = 30031
    519   ,
    520   /**
    521    * The operation failed because we either have no
    522    * listen socket or were already quiesced.
    523    */
    524   MHD_SC_DAEMON_ALREADY_QUIESCED = 30040
    525   ,
    526   /**
    527    * The operation failed because client disconnected
    528    * faster than we could accept().
    529    */
    530   MHD_SC_ACCEPT_FAST_DISCONNECT = 30050
    531   ,
    532   /**
    533    * Operating resource limits hit on accept().
    534    */
    535   MHD_SC_ACCEPT_SYSTEM_LIMIT_REACHED = 30060
    536   ,
    537   /**
    538    * Connection was refused by accept policy callback.
    539    */
    540   MHD_SC_ACCEPT_POLICY_REJECTED = 30070
    541   ,
    542   /**
    543    * Failed to allocate memory for the daemon resources.
    544    * TODO: combine similar error codes for daemon
    545    */
    546   MHD_SC_DAEMON_MEM_ALLOC_FAILURE = 30081
    547   ,
    548   /**
    549    * We failed to allocate memory for the connection.
    550    * (May be transient.)
    551    */
    552   MHD_SC_CONNECTION_MEM_ALLOC_FAILURE = 30082
    553   ,
    554   /**
    555    * We failed to allocate memory for the connection's memory pool.
    556    * (May be transient.)
    557    */
    558   MHD_SC_POOL_MEM_ALLOC_FAILURE = 30083
    559   ,
    560   /**
    561    * We failed to allocate memory for the HTTP/2 connection's resources.
    562    * (May be transient.)
    563    */
    564   MHD_SC_H2_CONN_MEM_ALLOC_FAILURE = 30084
    565   ,
    566   /**
    567    * We failed to forward data from a Web socket to the
    568    * application to the remote side due to the socket
    569    * being closed prematurely. (May be transient.)
    570    */
    571   MHD_SC_UPGRADE_FORWARD_INCOMPLETE = 30100
    572   ,
    573   /**
    574    * Failed to allocate memory from our memory pool for processing
    575    * the request.  Likely the request fields are too large to leave
    576    * enough room.
    577    */
    578   MHD_SC_CONNECTION_POOL_NO_MEM_REQ = 30130
    579   ,
    580   /**
    581    * Failed to allocate memory from our memory pool to store GET parameter.
    582    * Likely the request URI or header fields are too large to leave enough room.
    583    */
    584   MHD_SC_CONNECTION_POOL_NO_MEM_GET_PARAM = 30131
    585   ,
    586   /**
    587    * Failed to allocate memory from our memory pool to store parsed cookie.
    588    */
    589   MHD_SC_CONNECTION_POOL_NO_MEM_COOKIE = 30132
    590   ,
    591   /**
    592    * Failed to allocate memory from connection memory pool to store
    593    * parsed Authentication data.
    594    */
    595   MHD_SC_CONNECTION_POOL_NO_MEM_AUTH_DATA = 30133
    596   ,
    597   /**
    598    * Detected jump back of system clock
    599    */
    600   MHD_SC_SYS_CLOCK_JUMP_BACK_LARGE = 30140
    601   ,
    602   /**
    603    * Detected correctable jump back of system clock
    604    */
    605   MHD_SC_SYS_CLOCK_JUMP_BACK_CORRECTED = 30141
    606   ,
    607   /**
    608    * Timeout waiting for communication operation for HTTP-Upgraded connection
    609    */
    610   MHD_SC_UPGRADED_NET_TIMEOUT = 30161
    611   ,
    612   /**
    613    * Not enough system resources
    614    */
    615   MHD_SC_NO_SYS_RESOURCES = 30180
    616   ,
    617 
    618   /* 40000-level errors are caused by the HTTP client or the network. */
    619 
    620   /**
    621    * MHD is closing a connection because parsing the
    622    * request failed.
    623    */
    624   MHD_SC_CONNECTION_PARSE_FAIL_CLOSED = 40000
    625   ,
    626   /**
    627    * MHD is returning an error because the header provided
    628    * by the client is too big.
    629    */
    630   MHD_SC_CLIENT_HEADER_TOO_BIG = 40020
    631   ,
    632   /**
    633    * An HTTP/1.1 request was sent without the "Host:" header.
    634    */
    635   MHD_SC_HOST_HEADER_MISSING = 40060
    636   ,
    637   /**
    638    * Request has more than one "Host:" header.
    639    */
    640   MHD_SC_HOST_HEADER_SEVERAL = 40061
    641   ,
    642   /**
    643    * The value of the "Host:" header is invalid.
    644    */
    645   MHD_SC_HOST_HEADER_MALFORMED = 40062
    646   ,
    647   /**
    648    * The given content length was not a number.
    649    */
    650   MHD_SC_CONTENT_LENGTH_MALFORMED = 40065
    651   ,
    652   /**
    653    * Request has more than one "Content-Length:" header with the same value.
    654    */
    655   MHD_SC_CONTENT_LENGTH_SEVERAL_SAME = 40066
    656   ,
    657   /**
    658    * Request has more than one "Content-Length:" header with the different
    659    * values.
    660    */
    661   MHD_SC_CONTENT_LENGTH_SEVERAL_DIFFERENT = 40067
    662   ,
    663   /**
    664    * The BOTH Content-Length and Transfer-Encoding headers are used.
    665    */
    666   MHD_SC_CONTENT_LENGTH_AND_TR_ENC = 40068
    667   ,
    668   /**
    669    * The Content-Length is too large to be handled.
    670    */
    671   MHD_SC_CONTENT_LENGTH_TOO_LARGE = 40069
    672   ,
    673   /**
    674    * Transfer encoding in request is unsupported or invalid.
    675    */
    676   MHD_SC_TRANSFER_ENCODING_UNSUPPORTED = 40075
    677   ,
    678   /**
    679    * "Expect:" value in request is unsupported or invalid.
    680    */
    681   MHD_SC_EXPECT_HEADER_VALUE_UNSUPPORTED = 40076
    682   ,
    683   /**
    684    * The given uploaded, chunked-encoded body was malformed.
    685    */
    686   MHD_SC_CHUNKED_ENCODING_MALFORMED = 40080
    687   ,
    688   /**
    689    * The first header line has whitespace at the start
    690    */
    691   MHD_SC_REQ_FIRST_HEADER_LINE_SPACE_PREFIXED = 40100
    692   ,
    693   /**
    694    * The request target (URI) has whitespace character
    695    */
    696   MHD_SC_REQ_TARGET_HAS_WHITESPACE = 40101
    697   ,
    698   /**
    699    * Wrong bare CR characters has been replaced with space.
    700    */
    701   MHD_SC_REQ_HEADER_CR_REPLACED = 40120
    702   ,
    703   /**
    704    * Header line has not colon and skipped.
    705    */
    706   MHD_SC_REQ_HEADER_LINE_NO_COLON = 40121
    707   ,
    708   /**
    709    * Wrong bare CR characters has been replaced with space.
    710    */
    711   MHD_SC_REQ_FOOTER_CR_REPLACED = 40140
    712   ,
    713   /**
    714    * Footer line has not colon and skipped.
    715    */
    716   MHD_SC_REQ_FOOTER_LINE_NO_COLON = 40141
    717   ,
    718   /**
    719    * The request is malformed.
    720    */
    721   MHD_SC_REQ_MALFORMED = 40155
    722   ,
    723   /**
    724    * The cookie string has been parsed, but it is not fully compliant with
    725    * specifications
    726    */
    727   MHD_SC_REQ_COOKIE_PARSED_NOT_COMPLIANT = 40160
    728   ,
    729   /**
    730    * The cookie string has been parsed only partially
    731    */
    732   MHD_SC_REQ_COOKIE_PARSED_PARTIALLY = 40161
    733   ,
    734   /**
    735    * The cookie string is ignored, as it is not fully compliant with
    736    * specifications
    737    */
    738   MHD_SC_REQ_COOKIE_IGNORED_NOT_COMPLIANT = 40162
    739   ,
    740   /**
    741    * The cookie string has been ignored as it is invalid
    742    */
    743   MHD_SC_REQ_COOKIE_INVALID = 40163
    744   ,
    745   /**
    746    * The POST data parsed successfully, but has missing or incorrect
    747    * termination.
    748    * The last parsed field may have incorrect data.
    749    */
    750   MHD_SC_REQ_POST_PARSE_OK_BAD_TERMINATION = 40202
    751   ,
    752   /**
    753    * Parsing of the POST data is incomplete because client used incorrect
    754    * format of POST encoding.
    755    * Some POST data is available or has been provided via callback.
    756    */
    757   MHD_SC_REQ_POST_PARSE_PARTIAL_INVALID_POST_FORMAT = 40203
    758   ,
    759   /**
    760    * The request does not have "Content-Type:" header and POST data cannot
    761    * be parsed
    762    */
    763   MHD_SC_REQ_POST_PARSE_FAILED_NO_CNTN_TYPE = 40280
    764   ,
    765   /**
    766    * The request has unknown POST encoding specified by "Content-Type:" header
    767    */
    768   MHD_SC_REQ_POST_PARSE_FAILED_UNKNOWN_CNTN_TYPE = 40281
    769   ,
    770   /**
    771    * The request has "Content-Type: multipart/form-data" header without
    772    * "boundary" parameter
    773    */
    774   MHD_SC_REQ_POST_PARSE_FAILED_HEADER_NO_BOUNDARY = 40282
    775   ,
    776   /**
    777    * The request has "Content-Type: multipart/form-data" header with misformed
    778    * data
    779    */
    780   MHD_SC_REQ_POST_PARSE_FAILED_HEADER_MISFORMED = 40283
    781   ,
    782   /**
    783    * The POST data cannot be parsed because client used incorrect format
    784    * of POST encoding.
    785    */
    786   MHD_SC_REQ_POST_PARSE_FAILED_INVALID_POST_FORMAT = 40290
    787   ,
    788   /**
    789    * The data in Auth request header has invalid format.
    790    * For example, for Basic Authentication base64 decoding failed.
    791    */
    792   MHD_SC_REQ_AUTH_DATA_BROKEN = 40320
    793   ,
    794   /**
    795    * The request cannot be processed. Sending error reply.
    796    */
    797   MHD_SC_REQ_PROCESSING_ERR_REPLY = 41000
    798   ,
    799   /**
    800    * MHD is closing a connection because of timeout.
    801    */
    802   MHD_SC_CONNECTION_TIMEOUT = 42000
    803   ,
    804   /**
    805    * MHD is closing a connection because receiving the
    806    * request failed.
    807    */
    808   MHD_SC_CONNECTION_RECV_FAIL_CLOSED = 42020
    809   ,
    810   /**
    811    * MHD is closing a connection because sending the response failed.
    812    */
    813   MHD_SC_CONNECTION_SEND_FAIL_CLOSED = 42021
    814   ,
    815   /**
    816    * MHD is closing a connection because remote client shut down its sending
    817    * side before full request was sent.
    818    */
    819   MHD_SC_CLIENT_SHUTDOWN_EARLY = 42040
    820   ,
    821   /**
    822    * MHD is closing a connection because remote client closed connection
    823    * early.
    824    */
    825   MHD_SC_CLIENT_CLOSED_CONN_EARLY = 42041
    826   ,
    827   /**
    828    * MHD is closing a connection connection has been (remotely) aborted.
    829    */
    830   MHD_SC_CONNECTION_ABORTED = 42042
    831   ,
    832   /**
    833    * MHD is closing a connection because it was reset.
    834    */
    835   MHD_SC_CONNECTION_RESET = 42060
    836   ,
    837   /**
    838    * MHD is closing a connection connection (or connection socket) has
    839    * been broken.
    840    */
    841   MHD_SC_CONNECTION_BROKEN = 42061
    842   ,
    843   /**
    844    * ALPN in TLS connection selected HTTP/2 (as advertised by the client),
    845    * but the client did not send a valid HTTP/2 connection preface.
    846    */
    847   MHD_SC_ALPN_H2_NO_PREFACE = 43001
    848   ,
    849 
    850   /* 50000-level errors are internal MHD or platform failures,
    851      not caused by the application (see 60000-level). */
    852   /* Examples: a socket error on a broken connection, a read failure for
    853      a file-backed response, an unexpected accept() error. */
    854 
    855   /**
    856    * This build of MHD does not support TLS, but the application
    857    * requested TLS.
    858    */
    859   MHD_SC_TLS_DISABLED = 50000
    860   ,
    861   /**
    862    * The selected TLS backend does not yet support this operation.
    863    */
    864   MHD_SC_TLS_BACKEND_OPERATION_UNSUPPORTED = 50004
    865   ,
    866   /**
    867    * Failed to setup ITC channel.
    868    */
    869   MHD_SC_ITC_INITIALIZATION_FAILED = 50005
    870   ,
    871   /**
    872    * File descriptor for ITC cannot be used because the FD number is higher
    873    * than the limit set by FD_SETSIZE (if internal polling with select is used)
    874    * or by application.
    875    */
    876   MHD_SC_ITC_FD_OUTSIDE_OF_SET_RANGE = 50006
    877   ,
    878   /**
    879    * The specified value for the NC length is way too large
    880    * for this platform (integer overflow on `size_t`).
    881    */
    882   MHD_SC_DIGEST_AUTH_NC_LENGTH_TOO_BIG = 50010
    883   ,
    884   /**
    885    * We failed to allocate memory for the specified nonce
    886    * counter array.  The option was not set.
    887    */
    888   MHD_SC_DIGEST_AUTH_NC_ALLOCATION_FAILURE = 50011
    889   ,
    890   /**
    891    * This build of the library does not support
    892    * digest authentication.
    893    */
    894   MHD_SC_DIGEST_AUTH_NOT_SUPPORTED_BY_BUILD = 50012
    895   ,
    896   /**
    897    * IPv6 requested but not supported by this build.
    898    * @sa #MHD_SC_AF_NOT_SUPPORTED_BY_BUILD
    899    */
    900   MHD_SC_IPV6_NOT_SUPPORTED_BY_BUILD = 50020
    901   ,
    902   /**
    903    * Specified address/protocol family is not supported by this build.
    904    * @sa MHD_SC_IPV6_NOT_SUPPORTED_BY_BUILD
    905    */
    906   MHD_SC_AF_NOT_SUPPORTED_BY_BUILD = 50021
    907   ,
    908   /**
    909    * The requested address/protocol family is rejected by the OS.
    910    * @sa #MHD_SC_AF_NOT_SUPPORTED_BY_BUILD
    911    */
    912   MHD_SC_AF_NOT_AVAILABLE = 50022
    913   ,
    914   /**
    915    * We failed to open the listen socket.
    916    */
    917   MHD_SC_FAILED_TO_OPEN_LISTEN_SOCKET = 50040
    918   ,
    919   /**
    920    * Failed to enable listen port reuse.
    921    */
    922   MHD_SC_LISTEN_PORT_REUSE_ENABLE_FAILED = 50041
    923   ,
    924   /**
    925    * Failed to enable listen port reuse.
    926    */
    927   MHD_SC_LISTEN_PORT_REUSE_ENABLE_NOT_SUPPORTED = 50042
    928   ,
    929   /**
    930    * Failed to enable listen address reuse.
    931    */
    932   MHD_SC_LISTEN_ADDRESS_REUSE_ENABLE_FAILED = 50043
    933   ,
    934   /**
    935    * Enabling listen address reuse is not supported by this platform.
    936    */
    937   MHD_SC_LISTEN_ADDRESS_REUSE_ENABLE_NOT_SUPPORTED = 50044
    938   ,
    939   /**
    940    * Failed to enable exclusive use of listen address.
    941    */
    942   MHD_SC_LISTEN_ADDRESS_EXCLUSIVE_ENABLE_FAILED = 50045
    943   ,
    944   /**
    945    * Dual stack configuration is not possible for provided sockaddr.
    946    */
    947   MHD_SC_LISTEN_DUAL_STACK_NOT_SUITABLE = 50046
    948   ,
    949   /**
    950    * Failed to enable or disable dual stack for the IPv6 listen socket.
    951    * The OS default dual-stack setting is different from what is requested.
    952    */
    953   MHD_SC_LISTEN_DUAL_STACK_CONFIGURATION_REJECTED = 50047
    954   ,
    955   /**
    956    * Failed to enable or disable dual stack for the IPv6 listen socket.
    957    * The socket will be used in whatever the default is the OS uses.
    958    */
    959   MHD_SC_LISTEN_DUAL_STACK_CONFIGURATION_UNKNOWN = 50048
    960   ,
    961   /**
    962    * On this platform, MHD does not support explicitly configuring
    963    * dual stack behaviour.
    964    */
    965   MHD_SC_LISTEN_DUAL_STACK_CONFIGURATION_NOT_SUPPORTED = 50049
    966   ,
    967   /**
    968    * Failed to enable TCP FAST OPEN option.
    969    */
    970   MHD_SC_LISTEN_FAST_OPEN_FAILURE = 50050
    971   ,
    972   /**
    973    * TCP FAST OPEN is not supported by the platform or by this MHD build.
    974    */
    975   MHD_SC_FAST_OPEN_NOT_SUPPORTED = 50051
    976   ,
    977   /**
    978    * We failed to set the listen socket to non-blocking.
    979    */
    980   MHD_SC_LISTEN_SOCKET_NONBLOCKING_FAILURE = 50052
    981   ,
    982   /**
    983    * Failed to configure listen socket to be non-inheritable.
    984    */
    985   MHD_SC_LISTEN_SOCKET_NOINHERIT_FAILED = 50053
    986   ,
    987   /**
    988    * Listen socket FD cannot be used because the FD number is higher than
    989    * the limit set by FD_SETSIZE (if internal polling with select is used) or
    990    * by application.
    991    */
    992   MHD_SC_LISTEN_FD_OUTSIDE_OF_SET_RANGE = 50054
    993   ,
    994   /**
    995    * We failed to bind the listen socket.
    996    */
    997   MHD_SC_LISTEN_SOCKET_BIND_FAILED = 50055
    998   ,
    999   /**
   1000    * Failed to start listening on listen socket.
   1001    */
   1002   MHD_SC_LISTEN_FAILURE = 50056
   1003   ,
   1004   /**
   1005    * Failed to detect the port number on the listening socket
   1006    */
   1007   MHD_SC_LISTEN_PORT_DETECT_FAILURE = 50057
   1008   ,
   1009   /**
   1010    * We failed to create control socket for the epoll().
   1011    */
   1012   MHD_SC_EPOLL_CTL_CREATE_FAILED = 50060
   1013   ,
   1014   /**
   1015    * We failed to configure control socket for the epoll()
   1016    * to be non-inheritable.
   1017    */
   1018   MHD_SC_EPOLL_CTL_CONFIGURE_NOINHERIT_FAILED = 50061
   1019   ,
   1020   /**
   1021    * The epoll() control FD cannot be used because the FD number is higher
   1022    * than the limit set by application.
   1023    */
   1024   MHD_SC_EPOLL_CTL_OUTSIDE_OF_SET_RANGE = 50062
   1025   ,
   1026   /**
   1027    * Failed to allocate memory for daemon's events data, like fd_sets,
   1028    * poll, epoll or kqueue structures.
   1029    */
   1030   MHD_SC_EVENTS_MEMORY_ALLOCATE_FAILURE = 50063
   1031   ,
   1032   /**
   1033    * Failed to add daemon's FDs (ITC and/or listening) to the internal events
   1034    * monitoring
   1035    */
   1036   MHD_SC_EVENTS_REG_DAEMON_FDS_FAILURE = 50065
   1037   ,
   1038   /**
   1039    * Failed to register daemon's FDs (ITC or listening) in the application
   1040    * (external event) monitoring
   1041    */
   1042   MHD_SC_EXT_EVENT_REG_DAEMON_FDS_FAILURE = 50066
   1043   ,
   1044   /**
   1045    * Failed to create kqueue FD
   1046    */
   1047   MHD_SC_KQUEUE_FD_CREATE_FAILED = 50067
   1048   ,
   1049   /**
   1050    * Failed to configure kqueue FD to be non-inheritable.
   1051    */
   1052   MHD_SC_KQUEUE_FD_SET_NOINHERIT_FAILED = 50068
   1053   ,
   1054   /**
   1055    * The kqueue FD cannot be used because the FD number is higher
   1056    * than the limit set by application.
   1057    */
   1058   MHD_SC_KQUEUE_FD_OUTSIDE_OF_SET_RANGE = 50069
   1059   ,
   1060   /**
   1061    * The select() syscall is not available on this platform or in this MHD
   1062    * build.
   1063    */
   1064   MHD_SC_SELECT_SYSCALL_NOT_AVAILABLE = 50070
   1065   ,
   1066   /**
   1067    * The poll() syscall is not available on this platform or in this MHD
   1068    * build.
   1069    */
   1070   MHD_SC_POLL_SYSCALL_NOT_AVAILABLE = 50071
   1071   ,
   1072   /**
   1073    * The epoll syscalls are not available on this platform or in this MHD
   1074    * build.
   1075    */
   1076   MHD_SC_EPOLL_SYSCALL_NOT_AVAILABLE = 50072
   1077   ,
   1078   /**
   1079    * The kqueue syscalls are not available on this platform or in this MHD
   1080    * build.
   1081    */
   1082   MHD_SC_KQUEUE_SYSCALL_NOT_AVAILABLE = 50073
   1083   ,
   1084   /**
   1085    * Failed to obtain our listen port via introspection.
   1086    * FIXME: remove?
   1087    */
   1088   MHD_SC_LISTEN_PORT_INTROSPECTION_FAILURE = 50080
   1089   ,
   1090   /**
   1091    * Failed to obtain our listen port via introspection
   1092    * due to unsupported address family being used.
   1093    */
   1094   MHD_SC_LISTEN_PORT_INTROSPECTION_UNKNOWN_AF = 50081
   1095   ,
   1096   /**
   1097    * Failed to initialise mutex.
   1098    */
   1099   MHD_SC_MUTEX_INIT_FAILURE = 50085
   1100   ,
   1101   /**
   1102    * Failed to allocate memory for the thread pool.
   1103    */
   1104   MHD_SC_THREAD_POOL_MEM_ALLOC_FAILURE = 50090
   1105   ,
   1106   /**
   1107    * We failed to allocate mutex for thread pool worker.
   1108    */
   1109   MHD_SC_THREAD_POOL_CREATE_MUTEX_FAILURE = 50093
   1110   ,
   1111   /**
   1112    * Failed to start the main daemon thread.
   1113    */
   1114   MHD_SC_THREAD_MAIN_LAUNCH_FAILURE = 50095
   1115   ,
   1116   /**
   1117    * Failed to start the daemon thread for listening.
   1118    */
   1119   MHD_SC_THREAD_LISTENING_LAUNCH_FAILURE = 50096
   1120   ,
   1121   /**
   1122    * Failed to start the worker thread for the thread pool.
   1123    */
   1124   MHD_SC_THREAD_WORKER_LAUNCH_FAILURE = 50097
   1125   ,
   1126   /**
   1127    * There was an attempt to upgrade a connection on
   1128    * a daemon where upgrades are disallowed.
   1129    */
   1130   MHD_SC_UPGRADE_ON_DAEMON_WITH_UPGRADE_DISALLOWED = 50100
   1131   ,
   1132   /**
   1133    * Failed to signal via ITC channel.
   1134    */
   1135   MHD_SC_ITC_USE_FAILED = 50101
   1136   ,
   1137   /**
   1138    * Failed to check for the signal on the ITC channel.
   1139    */
   1140   MHD_SC_ITC_CHECK_FAILED = 50102
   1141   ,
   1142   /**
   1143    * System reported error conditions on the ITC FD.
   1144    */
   1145   MHD_SC_ITC_STATUS_ERROR = 50104
   1146   ,
   1147   /**
   1148    * Failed to add a socket to the epoll set.
   1149    */
   1150   MHD_SC_EPOLL_CTL_ADD_FAILED = 50110
   1151   ,
   1152   /**
   1153    * Socket FD cannot be used because the FD number is higher than the limit set
   1154    * by FD_SETSIZE (if internal polling with select is used) or by application.
   1155    */
   1156   MHD_SC_SOCKET_OUTSIDE_OF_SET_RANGE = 50111
   1157   ,
   1158   /**
   1159    * The daemon cannot be started with the specified settings as no space
   1160    * left for the connections sockets within limits set by FD_SETSIZE.
   1161    * Consider use another sockets polling syscall (only select() has such
   1162    * limitations)
   1163    */
   1164   MHD_SC_SYS_FD_SETSIZE_TOO_STRICT = 50112
   1165   ,
   1166   /**
   1167    * This daemon was not configured with options that
   1168    * would allow us to obtain a meaningful timeout.
   1169    */
   1170   MHD_SC_CONFIGURATION_MISMATCH_FOR_GET_TIMEOUT = 50113
   1171   ,
   1172   /**
   1173    * This daemon was not configured with options that
   1174    * would allow us to run with select() data.
   1175    */
   1176   MHD_SC_CONFIGURATION_MISMATCH_FOR_RUN_SELECT = 50114
   1177   ,
   1178   /**
   1179    * This daemon was not configured to run with an
   1180    * external event loop.
   1181    */
   1182   MHD_SC_CONFIGURATION_MISMATCH_FOR_RUN_EXTERNAL = 50115
   1183   ,
   1184   /**
   1185    * Encountered an unexpected error from select()
   1186    * (should never happen).
   1187    */
   1188   MHD_SC_UNEXPECTED_SELECT_ERROR = 50116
   1189   ,
   1190   /**
   1191    * Failed to remove a connection socket to the epoll or kqueue monitoring.
   1192    */
   1193   MHD_SC_EVENTS_CONN_REMOVE_FAILED = 50117
   1194   ,
   1195   /**
   1196    * poll() is not supported.
   1197    */
   1198   MHD_SC_POLL_NOT_SUPPORTED = 50120
   1199   ,
   1200   /**
   1201    * Encountered a (potentially) recoverable error from poll().
   1202    */
   1203   MHD_SC_POLL_SOFT_ERROR = 50121
   1204   ,
   1205   /**
   1206    * Encountered an unrecoverable error from poll().
   1207    */
   1208   MHD_SC_POLL_HARD_ERROR = 50122
   1209   ,
   1210   /**
   1211    * Encountered a (potentially) recoverable error from select().
   1212    */
   1213   MHD_SC_SELECT_SOFT_ERROR = 50123
   1214   ,
   1215   /**
   1216    * Encountered an unrecoverable error from select().
   1217    */
   1218   MHD_SC_SELECT_HARD_ERROR = 50124
   1219   ,
   1220   /**
   1221    * System reported error conditions on the listening socket.
   1222    */
   1223   MHD_SC_LISTEN_STATUS_ERROR = 50129
   1224   ,
   1225   /**
   1226    * Encountered an unrecoverable error from epoll function.
   1227    */
   1228   MHD_SC_EPOLL_HARD_ERROR = 50130
   1229   ,
   1230   /**
   1231    * Encountered an unrecoverable error from kevent() function.
   1232    */
   1233   MHD_SC_KQUEUE_HARD_ERROR = 50131
   1234   ,
   1235   /**
   1236    * We failed to configure accepted socket
   1237    * to not use a SIGPIPE.
   1238    */
   1239   MHD_SC_ACCEPT_CONFIGURE_NOSIGPIPE_FAILED = 50140
   1240   ,
   1241   /**
   1242    * We failed to configure accepted socket
   1243    * to be non-inheritable.
   1244    */
   1245   MHD_SC_ACCEPT_CONFIGURE_NOINHERIT_FAILED = 50141
   1246   ,
   1247   /**
   1248    * We failed to configure accepted socket
   1249    * to be non-blocking.
   1250    */
   1251   MHD_SC_ACCEPT_CONFIGURE_NONBLOCKING_FAILED = 50142
   1252   ,
   1253   /**
   1254    * The accepted socket FD value is too large.
   1255    */
   1256   MHD_SC_ACCEPT_OUTSIDE_OF_SET_RANGE = 50143
   1257   ,
   1258   /**
   1259    * accept() returned unexpected error.
   1260    */
   1261   MHD_SC_ACCEPT_FAILED_UNEXPECTEDLY = 50144
   1262   ,
   1263   /**
   1264    * Operating resource limits hit on accept() while
   1265    * zero connections are active. Oopsie.
   1266    */
   1267   MHD_SC_ACCEPT_SYSTEM_LIMIT_REACHED_INSTANTLY = 50145
   1268   ,
   1269   /**
   1270    * The daemon sockets polling mode requires non-blocking sockets.
   1271    */
   1272   MHD_SC_NONBLOCKING_REQUIRED = 50146
   1273   ,
   1274   /**
   1275    * Encountered an unexpected error from epoll_wait()
   1276    * (should never happen).
   1277    */
   1278   MHD_SC_UNEXPECTED_EPOLL_WAIT_ERROR = 50150
   1279   ,
   1280   /**
   1281    * epoll file descriptor is invalid (strange)
   1282    */
   1283   MHD_SC_EPOLL_FD_INVALID = 50151
   1284   ,
   1285   /**
   1286    * Unexpected socket error (strange)
   1287    */
   1288   MHD_SC_UNEXPECTED_SOCKET_ERROR = 50152
   1289   ,
   1290   /**
   1291    * Failed to add IP address to per-IP counter for
   1292    * some reason.
   1293    */
   1294   MHD_SC_IP_COUNTER_FAILURE = 50160
   1295   ,
   1296   /**
   1297    * Application violated our API by calling shutdown
   1298    * while having an upgrade connection still open.
   1299    */
   1300   MHD_SC_SHUTDOWN_WITH_OPEN_UPGRADED_CONNECTION = 50180
   1301   ,
   1302   /**
   1303    * Due to an unexpected internal error with the
   1304    * state machine, we closed the connection.
   1305    */
   1306   MHD_SC_STATEMACHINE_FAILURE_CONNECTION_CLOSED = 50200
   1307   ,
   1308   /**
   1309    * Failed to allocate memory in connection's pool
   1310    * to parse the cookie header.
   1311    */
   1312   MHD_SC_COOKIE_POOL_ALLOCATION_FAILURE = 50220
   1313   ,
   1314   /**
   1315    * MHD failed to build the reply header.
   1316    */
   1317   MHD_SC_REPLY_HEADER_GENERATION_FAILED = 50230
   1318   ,
   1319   /**
   1320    * Failed to allocate memory in connection's pool for the reply.
   1321    */
   1322   MHD_SC_REPLY_POOL_ALLOCATION_FAILURE = 50231
   1323   ,
   1324   /**
   1325    * Failed to read the file for file-backed response.
   1326    */
   1327   MHD_SC_REPLY_FILE_READ_ERROR = 50232
   1328   ,
   1329   /**
   1330    * Failed to generate the nonce for the Digest Auth.
   1331    */
   1332   MHD_SC_REPLY_NONCE_ERROR = 50233
   1333   ,
   1334   /**
   1335    * Failed to allocate memory in connection's pool for the reply.
   1336    */
   1337   MHD_SC_REPLY_ALLOCATION_FAILED = 50250
   1338   ,
   1339   /**
   1340    * The request POST data cannot be parsed because stream has not enough
   1341    * pool memory free.
   1342    */
   1343   MHD_SC_REQ_POST_PARSE_FAILED_NO_POOL_MEM = 50260
   1344   ,
   1345   /**
   1346    * The POST data cannot be parsed completely because no "large shared buffer"
   1347    * space is available.
   1348    * Some POST data may be parsed.
   1349    */
   1350   MHD_SC_REQ_POST_PARSE_FAILED_NO_LARGE_BUF_MEM = 50261
   1351   ,
   1352   /**
   1353    * The application set POST encoding to "multipart/form-data", but the request
   1354    * has no "Content-Type: multipart/form-data" header which is required
   1355    * to find "boundary" used in this encoding
   1356    */
   1357   MHD_SC_REQ_POST_PARSE_FAILED_HEADER_NOT_MPART = 50284
   1358   ,
   1359   /**
   1360    * The feature is not supported by this MHD build (either
   1361    * disabled by configure parameters or build platform
   1362    * did not support it, because headers are missing or
   1363    * so kernel does not have such feature).
   1364    * The feature will not be enabled if the same MHD binary
   1365    * will be run on another kernel, computer or system
   1366    * configuration.
   1367    */
   1368   MHD_SC_FEATURE_DISABLED = 50300
   1369   ,
   1370   /**
   1371    * The feature is not supported by this platform, while
   1372    * supported by MHD build.
   1373    * The feature can be enabled by changing the kernel or
   1374    * running on another computer or with other system
   1375    * configuration.
   1376    */
   1377   MHD_SC_FEATURE_NOT_AVAILABLE = 50320
   1378   ,
   1379   /**
   1380    * Failed to stop the thread
   1381    */
   1382   MHD_SC_DAEMON_THREAD_STOP_ERROR = 50350
   1383   ,
   1384   /**
   1385    * Unexpected reasons for thread stop
   1386    */
   1387   MHD_SC_DAEMON_THREAD_STOP_UNEXPECTED = 50351
   1388   ,
   1389   /**
   1390    * Daemon system data is broken (like listen socket was unexpectedly closed).
   1391    * The daemon needs to be closed.
   1392    * A new daemon can be started as a replacement after closing the current
   1393    * daemon.
   1394    */
   1395   MHD_SC_DAEMON_SYS_DATA_BROKEN = 50370
   1396   ,
   1397   /**
   1398    * Failed to acquire response mutex lock
   1399    */
   1400   MHD_SC_RESP_MUTEX_LOCK_FAILED = 50500
   1401   ,
   1402   /**
   1403    * Failed to initialise response mutex
   1404    */
   1405   MHD_SC_RESP_MUTEX_INIT_FAILED = 50501
   1406   ,
   1407   /**
   1408    * Unable to allocate memory for the response header
   1409    */
   1410   MHD_SC_RESP_HEADER_MEM_ALLOC_FAILED = 50540
   1411   ,
   1412   /**
   1413    * Failed to switch TCP_NODELAY option for the socket
   1414    */
   1415   MHD_SC_SOCKET_TCP_NODELAY_FAILED = 50600
   1416   ,
   1417   /**
   1418    * Failed to switch TCP_CORK or TCP_NOPUSH option for the socket
   1419    */
   1420   MHD_SC_SOCKET_TCP_CORK_NOPUSH_FAILED = 50601
   1421   ,
   1422   /**
   1423    * Failed to force flush the last part of the response header or
   1424    * the response content
   1425    */
   1426   MHD_SC_SOCKET_FLUSH_LAST_PART_FAILED = 50620
   1427   ,
   1428   /**
   1429    * Failed to push buffered data by zero-sized send()
   1430    */
   1431   MHD_SC_SOCKET_ZERO_SEND_FAILED = 50621
   1432   ,
   1433   /**
   1434    * The HTTP-Upgraded network connection has been closed / disconnected
   1435    */
   1436   MHD_SC_UPGRADED_NET_CONN_CLOSED = 50800
   1437   ,
   1438   /**
   1439    * The HTTP-Upgraded network connection has been broken
   1440    */
   1441   MHD_SC_UPGRADED_NET_CONN_BROKEN = 50801
   1442   ,
   1443   /**
   1444    * The TLS communication error on HTTP-Upgraded connection
   1445    */
   1446   MHD_SC_UPGRADED_TLS_ERROR = 50802
   1447   ,
   1448   /**
   1449    * Unrecoverable sockets communication error on HTTP-Upgraded connection
   1450    */
   1451   MHD_SC_UPGRADED_NET_HARD_ERROR = 50840
   1452   ,
   1453   /**
   1454    * MHD cannot wait for the data on the HTTP-Upgraded connection, because
   1455    * current build or the platform does not support required functionality.
   1456    * Communication with zero timeout is fully supported.
   1457    */
   1458   MHD_SC_UPGRADED_WAITING_NOT_SUPPORTED = 50860
   1459   ,
   1460   /**
   1461    * Global initialisation of MHD library failed
   1462    */
   1463   MHD_SC_LIB_INIT_GLOBAL_FAILED = 51000
   1464   ,
   1465   /**
   1466    * Failed to initialise TLS context for the daemon
   1467    */
   1468   MHD_SC_TLS_DAEMON_INIT_FAILED = 51200
   1469   ,
   1470   /**
   1471    * Failed to initialise TLS context for the new connection
   1472    */
   1473   MHD_SC_TLS_CONNECTION_INIT_FAILED = 51201
   1474   ,
   1475   /**
   1476    * Warning about TLS backend configuration
   1477    */
   1478   MHD_SC_TLS_LIB_CONF_WARNING = 51202
   1479   ,
   1480   /**
   1481    * Failed to perform TLS handshake
   1482    */
   1483   MHD_SC_TLS_CONNECTION_HANDSHAKED_FAILED = 51220
   1484   ,
   1485   /**
   1486    * Hashing failed.
   1487    * Internal hashing function can never fail (and this code is never returned
   1488    * for them). External hashing function (like TLS backend-based) may fail
   1489    * for various reasons, like failure of hardware acccelerated hashing.
   1490    */
   1491   MHD_SC_HASH_FAILED = 51260
   1492   ,
   1493   /**
   1494    * Something wrong in the internal MHD logic.
   1495    * This error should be never returned if MHD works as expected.
   1496    * If this code is ever returned, please report to MHD maintainers.
   1497    */
   1498   MHD_SC_INTERNAL_ERROR = 59900
   1499   ,
   1500 
   1501   /* 60000-level errors are caused by the application
   1502      (callbacks, settings or API misuse). */
   1503 
   1504   /**
   1505    * The application called function too early.
   1506    * For example, a header value was requested before the headers
   1507    * had been received.
   1508    */
   1509   MHD_SC_TOO_EARLY = 60000
   1510   ,
   1511   /**
   1512    * The application called this function too late.
   1513    * For example, MHD has already started sending reply.
   1514    */
   1515   MHD_SC_TOO_LATE = 60001
   1516   ,
   1517   /**
   1518    * MHD does not support the requested combination of
   1519    * the sockets polling syscall and the work mode.
   1520    */
   1521   MHD_SC_SYSCALL_WORK_MODE_COMBINATION_INVALID = 60010
   1522   ,
   1523   /**
   1524    * MHD does not support quiescing if ITC was disabled
   1525    * and threads are used.
   1526    */
   1527   MHD_SC_SYSCALL_QUIESCE_REQUIRES_ITC = 60011
   1528   ,
   1529   /**
   1530    * The option provided or function called can be used only with "external
   1531    * events" modes.
   1532    */
   1533   MHD_SC_EXTERNAL_EVENT_ONLY = 60012
   1534   ,
   1535   /**
   1536    * MHD is closing a connection because the application
   1537    * logic to generate the response data failed.
   1538    */
   1539   MHD_SC_APPLICATION_DATA_GENERATION_FAILURE_CLOSED = 60015
   1540   ,
   1541   /**
   1542    * MHD is closing a connection because the application
   1543    * callback told it to do so.
   1544    */
   1545   MHD_SC_APPLICATION_CALLBACK_ABORT_ACTION = 60016
   1546   ,
   1547   /**
   1548    * Application only partially processed upload and did
   1549    * not suspend connection. This may result in a hung
   1550    * connection.
   1551    */
   1552   MHD_SC_APPLICATION_HUNG_CONNECTION = 60017
   1553   ,
   1554   /**
   1555    * Application only partially processed upload and did
   1556    * not suspend connection and the read buffer was maxxed
   1557    * out, so MHD closed the connection.
   1558    */
   1559   MHD_SC_APPLICATION_HUNG_CONNECTION_CLOSED = 60018
   1560   ,
   1561   /**
   1562    * Attempted to set an option that conflicts with another option
   1563    * already set.
   1564    */
   1565   MHD_SC_OPTIONS_CONFLICT = 60020
   1566   ,
   1567   /**
   1568    * Attempted to set an option that not recognised by MHD.
   1569    */
   1570   MHD_SC_OPTION_UNKNOWN = 60021
   1571   ,
   1572   /**
   1573    * Parameter specified unknown work mode.
   1574    */
   1575   MHD_SC_CONFIGURATION_UNEXPECTED_WM = 60022
   1576   ,
   1577   /**
   1578    * Parameter specified unknown Sockets Polling Syscall (SPS).
   1579    */
   1580   MHD_SC_CONFIGURATION_UNEXPECTED_SPS = 60023
   1581   ,
   1582   /**
   1583    * The size of the provided sockaddr does not match address family.
   1584    */
   1585   MHD_SC_CONFIGURATION_WRONG_SA_SIZE = 60024
   1586   ,
   1587   /**
   1588    * The number set by #MHD_D_O_FD_NUMBER_LIMIT is too strict to run
   1589    * the daemon
   1590    */
   1591   MHD_SC_MAX_FD_NUMBER_LIMIT_TOO_STRICT = 60025
   1592   ,
   1593   /**
   1594    * The number set by #MHD_D_O_GLOBAL_CONNECTION_LIMIT is too for the daemon
   1595    * configuration
   1596    */
   1597   MHD_SC_CONFIGURATION_CONN_LIMIT_TOO_SMALL = 60026
   1598   ,
   1599   /**
   1600    * The provided configuration parameter is NULL, but it must be non-NULL
   1601    */
   1602   MHD_SC_CONFIGURATION_PARAM_NULL = 60027
   1603   ,
   1604   /**
   1605    * The size of the provided configuration parameter is too large
   1606    */
   1607   MHD_SC_CONFIGURATION_PARAM_TOO_LARGE = 60028
   1608   ,
   1609   /**
   1610    * The application requested an unsupported TLS backend to be used.
   1611    */
   1612   MHD_SC_TLS_BACKEND_UNSUPPORTED = 60030
   1613   ,
   1614   /**
   1615    * The application attempted to setup TLS parameters before
   1616    * enabling TLS.
   1617    */
   1618   MHD_SC_TLS_BACKEND_UNINITIALIZED = 60031
   1619   ,
   1620   /**
   1621    * The application requested a TLS backend which cannot be used due
   1622    * to missing TLS dynamic library or backend initialisation problem.
   1623    */
   1624   MHD_SC_TLS_BACKEND_UNAVAILABLE = 60032
   1625   ,
   1626   /**
   1627    * Provided TLS certificate and/or private key are incorrect
   1628    */
   1629   MHD_SC_TLS_CONF_BAD_CERT = 60033
   1630   ,
   1631   /**
   1632    * The application requested a daemon setting that cannot be used with
   1633    * selected TLS backend
   1634    */
   1635   MHD_SC_TLS_BACKEND_DAEMON_INCOMPATIBLE_SETTINGS = 60034
   1636   ,
   1637   /**
   1638    * The pointer to the response object is NULL
   1639    */
   1640   MHD_SC_RESP_POINTER_NULL = 60060
   1641   ,
   1642   /**
   1643    * The response HTTP status code is not suitable
   1644    */
   1645   MHD_SC_RESP_HTTP_CODE_NOT_SUITABLE = 60061
   1646   ,
   1647   /**
   1648    * The provided MHD_Action is invalid
   1649    */
   1650   MHD_SC_ACTION_INVALID = 60080
   1651   ,
   1652   /**
   1653    * The provided MHD_UploadAction is invalid
   1654    */
   1655   MHD_SC_UPLOAD_ACTION_INVALID = 60081
   1656   ,
   1657   /**
   1658    * The provided Dynamic Content Creator action is invalid
   1659    */
   1660   MHD_SC_DCC_ACTION_INVALID = 60082
   1661   ,
   1662   /**
   1663    * The response must be empty
   1664    */
   1665   MHD_SC_REPLY_NOT_EMPTY_RESPONSE = 60101
   1666   ,
   1667   /**
   1668    * The "Content-Length" header is not allowed in the reply
   1669    */
   1670   MHD_SC_REPLY_CONTENT_LENGTH_NOT_ALLOWED = 60102
   1671   ,
   1672   /**
   1673    * The provided reply headers do not fit the connection buffer
   1674    */
   1675   MHD_SC_REPLY_HEADERS_TOO_LARGE = 60103
   1676   ,
   1677   /**
   1678    * Specified offset in file-backed response is too large and not supported
   1679    * by the platform
   1680    */
   1681   MHD_SC_REPLY_FILE_OFFSET_TOO_LARGE = 60104
   1682   ,
   1683   /**
   1684    * File-backed response has file smaller than specified combination of
   1685    * the file offset and the response size.
   1686    */
   1687   MHD_SC_REPLY_FILE_TOO_SHORT = 60105
   1688   ,
   1689   /**
   1690    * The new connection cannot be used because the FD number is higher than
   1691    * the limit set by FD_SETSIZE (if internal polling with select is used) or
   1692    * by application.
   1693    */
   1694   MHD_SC_NEW_CONN_FD_OUTSIDE_OF_SET_RANGE = 60140
   1695   ,
   1696   /**
   1697    * The daemon is being destroyed, while not all HTTP-Upgraded connections
   1698    * has been closed.
   1699    */
   1700   MHD_SC_DAEMON_DESTROYED_WITH_UNCLOSED_UPGRADED = 60160
   1701   ,
   1702   /**
   1703    * The provided pointer to 'struct MHD_UpgradedHandle' is invalid
   1704    */
   1705   MHD_SC_UPGRADED_HANDLE_INVALID = 60161
   1706   ,
   1707   /**
   1708    * The provided output buffer is too small.
   1709    */
   1710   MHD_SC_OUT_BUFF_TOO_SMALL = 60180
   1711   ,
   1712   /**
   1713    * The requested type of information is not recognised.
   1714    */
   1715   MHD_SC_INFO_GET_TYPE_UNKNOWN = 60200
   1716   ,
   1717   /**
   1718    * The information of the requested type is too large to fit into
   1719    * the provided buffer.
   1720    */
   1721   MHD_SC_INFO_GET_BUFF_TOO_SMALL = 60201
   1722   ,
   1723   /**
   1724    * The type of the information is not supported by this MHD build.
   1725    * It can be information not supported on the current platform or related
   1726    * to feature disabled for this build.
   1727    */
   1728   MHD_SC_INFO_GET_TYPE_NOT_SUPP_BY_BUILD = 60202
   1729   ,
   1730   /**
   1731    * The type of the information is not available due to configuration
   1732    * or state of the object.
   1733    */
   1734   MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE = 60203
   1735   ,
   1736   /**
   1737    * The type of the information should be available for the object, but
   1738    * cannot be provided due to some error or other reasons.
   1739    */
   1740   MHD_SC_INFO_GET_TYPE_UNOBTAINABLE = 60204
   1741   ,
   1742   /**
   1743    * The type of the Digest Auth algorithm is unknown or not supported.
   1744    */
   1745   MHD_SC_AUTH_DIGEST_ALGO_NOT_SUPPORTED = 60240
   1746   ,
   1747   /**
   1748    * The Digest Auth QOP value is unknown or not supported.
   1749    */
   1750   MHD_SC_AUTH_DIGEST_QOP_NOT_SUPPORTED = 60241
   1751   ,
   1752   /**
   1753    * The Digest Auth is not supported due to configuration
   1754    */
   1755   MHD_SC_AUTH_DIGEST_UNSUPPORTED = 60242
   1756   ,
   1757   /**
   1758    * The application failed to register FD for the external events monitoring
   1759    */
   1760   MHD_SC_EXTR_EVENT_REG_FAILED = 60243
   1761   ,
   1762   /**
   1763    * The application failed to de-register FD for the external events monitoring
   1764    */
   1765   MHD_SC_EXTR_EVENT_DEREG_FAILED = 60244
   1766   ,
   1767   /**
   1768    * The application called #MHD_daemon_event_update() with broken data
   1769    */
   1770   MHD_SC_EXTR_EVENT_BROKEN_DATA = 60250
   1771   ,
   1772   /**
   1773    * The application called #MHD_daemon_event_update() with status that
   1774    * has not been requested
   1775    */
   1776   MHD_SC_EXTR_EVENT_UNEXPECTED_STATUS = 60251
   1777   ,
   1778   /**
   1779    * Unable to clear "reusable" flag.
   1780    * Once this flag is set, it cannot be removed for the response lifetime.
   1781    */
   1782   MHD_SC_RESP_REUSABLE_CANNOT_CLEAR = 60300
   1783   ,
   1784   /**
   1785    * The response header name has forbidden characters or token
   1786    */
   1787   MHD_SC_RESP_HEADER_NAME_INVALID = 60320
   1788   ,
   1789   /**
   1790    * The response header value has forbidden characters or token
   1791    */
   1792   MHD_SC_RESP_HEADER_VALUE_INVALID = 60321
   1793   ,
   1794   /**
   1795    * An attempt to add header conflicting with other response header
   1796    */
   1797   MHD_SC_RESP_HEADERS_CONFLICT = 60330
   1798   ,
   1799   /**
   1800    * The application tried to add second DATE header.
   1801    */
   1802   MHD_SC_RESP_HEADER_DATE_DUPLICATE = 60340
   1803   ,
   1804   /**
   1805    * The application tried to add second CONNECTION header.
   1806    */
   1807   MHD_SC_RESP_HEADER_CONNECTION_DUPLICATE = 60341
   1808 };
   1809 
   1810 /**
   1811  * Get text description for the MHD error code.
   1812  *
   1813  * This function works for @b MHD error codes, not for @b HTTP status codes.
   1814  * @param code the MHD code to get description for
   1815  * @return the pointer to the text description,
   1816  *         NULL if MHD code in not known.
   1817  *
   1818  * @ingroup general
   1819  */
   1820 MHD_EXTERN_ const struct MHD_String *
   1821 MHD_status_code_to_string (enum MHD_StatusCode code)
   1822 MHD_FN_CONST_;
   1823 
   1824 /**
   1825  * Get the pointer to the C string for the MHD error code, never NULL.
   1826  */
   1827 #define MHD_status_code_to_string_lazy(code) \
   1828         (MHD_status_code_to_string ((code)) ? \
   1829          ((MHD_status_code_to_string (code))->cstr) : ("[No code]") )
   1830 
   1831 #ifndef MHD_HTTP_METHOD_DEFINED
   1832 
   1833 /**
   1834  * @brief HTTP request methods
   1835  *
   1836  * @defgroup methods HTTP methods
   1837  *
   1838  * See: https://www.iana.org/assignments/http-methods/http-methods.xml
   1839  * Registry export date: 2023-10-02
   1840  * @{
   1841  */
   1842 
   1843 /**
   1844  * HTTP methods explicitly supported by MHD.  Note that for non-canonical
   1845  * methods, MHD will return #MHD_HTTP_METHOD_OTHER and you can use
   1846  * #MHD_REQUEST_INFO_FIXED_HTTP_METHOD to get the original string.
   1847  *
   1848  * However, applications must check for #MHD_HTTP_METHOD_OTHER *or* any enum-value
   1849  * above those in this list, as future versions of MHD may add additional
   1850  * methods (as per IANA registry), thus even if the API returns
   1851  * #MHD_HTTP_METHOD_OTHER today, it may return a method-specific header in the
   1852  * future!
   1853  */
   1854 enum MHD_FIXED_ENUM_MHD_SET_ MHD_HTTP_Method
   1855 {
   1856 
   1857   /**
   1858    * Method did not match any of the methods given below.
   1859    */
   1860   MHD_HTTP_METHOD_OTHER = 255
   1861   ,
   1862   /* Main HTTP methods. */
   1863 
   1864   /**
   1865    * "GET"
   1866    * Safe.     Idempotent.     RFC9110, Section 9.3.1.
   1867    */
   1868   MHD_HTTP_METHOD_GET = 1
   1869   ,
   1870   /**
   1871    * "HEAD"
   1872    * Safe.     Idempotent.     RFC9110, Section 9.3.2.
   1873    */
   1874   MHD_HTTP_METHOD_HEAD = 2
   1875   ,
   1876   /**
   1877    * "POST"
   1878    * Not safe. Not idempotent. RFC9110, Section 9.3.3.
   1879    */
   1880   MHD_HTTP_METHOD_POST = 3
   1881   ,
   1882   /**
   1883    * "PUT"
   1884    * Not safe. Idempotent.     RFC9110, Section 9.3.4.
   1885    */
   1886   MHD_HTTP_METHOD_PUT = 4
   1887   ,
   1888   /**
   1889    * "DELETE"
   1890    * Not safe. Idempotent.     RFC9110, Section 9.3.5.
   1891    */
   1892   MHD_HTTP_METHOD_DELETE = 5
   1893   ,
   1894   /**
   1895    * "CONNECT"
   1896    * Not safe. Not idempotent. RFC9110, Section 9.3.6.
   1897    */
   1898   MHD_HTTP_METHOD_CONNECT = 6
   1899   ,
   1900   /**
   1901    * "OPTIONS"
   1902    * Safe.     Idempotent.     RFC9110, Section 9.3.7.
   1903    */
   1904   MHD_HTTP_METHOD_OPTIONS = 7
   1905   ,
   1906   /**
   1907    * "TRACE"
   1908    * Safe.     Idempotent.     RFC9110, Section 9.3.8.
   1909    */
   1910   MHD_HTTP_METHOD_TRACE = 8
   1911   ,
   1912   /**
   1913    * "*"
   1914    * Not safe. Not idempotent. RFC9110, Section 18.2.
   1915    */
   1916   MHD_HTTP_METHOD_ASTERISK = 9
   1917 };
   1918 
   1919 #  define MHD_HTTP_METHOD_DEFINED 1
   1920 #endif /* ! MHD_HTTP_METHOD_DEFINED */
   1921 
   1922 /**
   1923  * Get text version of the method name.
   1924  * @param method the method to get the text version
   1925  * @return the pointer to the text version,
   1926  *         NULL if method is MHD_HTTP_METHOD_OTHER
   1927  *         or not known.
   1928  */
   1929 MHD_EXTERN_ const struct MHD_String *
   1930 MHD_http_method_to_string (enum MHD_HTTP_Method method)
   1931 MHD_FN_CONST_;
   1932 
   1933 
   1934 /* Main HTTP methods. */
   1935 /* Safe.     Idempotent.     RFC9110, Section 9.3.1. */
   1936 #define MHD_HTTP_METHOD_STR_GET      "GET"
   1937 /* Safe.     Idempotent.     RFC9110, Section 9.3.2. */
   1938 #define MHD_HTTP_METHOD_STR_HEAD     "HEAD"
   1939 /* Not safe. Not idempotent. RFC9110, Section 9.3.3. */
   1940 #define MHD_HTTP_METHOD_STR_POST     "POST"
   1941 /* Not safe. Idempotent.     RFC9110, Section 9.3.4. */
   1942 #define MHD_HTTP_METHOD_STR_PUT      "PUT"
   1943 /* Not safe. Idempotent.     RFC9110, Section 9.3.5. */
   1944 #define MHD_HTTP_METHOD_STR_DELETE   "DELETE"
   1945 /* Not safe. Not idempotent. RFC9110, Section 9.3.6. */
   1946 #define MHD_HTTP_METHOD_STR_CONNECT  "CONNECT"
   1947 /* Safe.     Idempotent.     RFC9110, Section 9.3.7. */
   1948 #define MHD_HTTP_METHOD_STR_OPTIONS  "OPTIONS"
   1949 /* Safe.     Idempotent.     RFC9110, Section 9.3.8. */
   1950 #define MHD_HTTP_METHOD_STR_TRACE    "TRACE"
   1951 /* Not safe. Not idempotent. RFC9110, Section 18.2. */
   1952 #define MHD_HTTP_METHOD_STR_ASTERISK  "*"
   1953 
   1954 /* Additional HTTP methods. */
   1955 /* Not safe. Idempotent.     RFC3744, Section 8.1. */
   1956 #define MHD_HTTP_METHOD_STR_ACL            "ACL"
   1957 /* Not safe. Idempotent.     RFC3253, Section 12.6. */
   1958 #define MHD_HTTP_METHOD_STR_BASELINE_CONTROL "BASELINE-CONTROL"
   1959 /* Not safe. Idempotent.     RFC5842, Section 4. */
   1960 #define MHD_HTTP_METHOD_STR_BIND           "BIND"
   1961 /* Not safe. Idempotent.     RFC3253, Section 4.4, Section 9.4. */
   1962 #define MHD_HTTP_METHOD_STR_CHECKIN        "CHECKIN"
   1963 /* Not safe. Idempotent.     RFC3253, Section 4.3, Section 8.8. */
   1964 #define MHD_HTTP_METHOD_STR_CHECKOUT       "CHECKOUT"
   1965 /* Not safe. Idempotent.     RFC4918, Section 9.8. */
   1966 #define MHD_HTTP_METHOD_STR_COPY           "COPY"
   1967 /* Not safe. Idempotent.     RFC3253, Section 8.2. */
   1968 #define MHD_HTTP_METHOD_STR_LABEL          "LABEL"
   1969 /* Not safe. Idempotent.     RFC2068, Section 19.6.1.2. */
   1970 #define MHD_HTTP_METHOD_STR_LINK           "LINK"
   1971 /* Not safe. Not idempotent. RFC4918, Section 9.10. */
   1972 #define MHD_HTTP_METHOD_STR_LOCK           "LOCK"
   1973 /* Not safe. Idempotent.     RFC3253, Section 11.2. */
   1974 #define MHD_HTTP_METHOD_STR_MERGE          "MERGE"
   1975 /* Not safe. Idempotent.     RFC3253, Section 13.5. */
   1976 #define MHD_HTTP_METHOD_STR_MKACTIVITY     "MKACTIVITY"
   1977 /* Not safe. Idempotent.     RFC4791, Section 5.3.1; RFC8144, Section 2.3. */
   1978 #define MHD_HTTP_METHOD_STR_MKCALENDAR     "MKCALENDAR"
   1979 /* Not safe. Idempotent.     RFC4918, Section 9.3; RFC5689, Section 3; RFC8144, Section 2.3. */
   1980 #define MHD_HTTP_METHOD_STR_MKCOL          "MKCOL"
   1981 /* Not safe. Idempotent.     RFC4437, Section 6. */
   1982 #define MHD_HTTP_METHOD_STR_MKREDIRECTREF  "MKREDIRECTREF"
   1983 /* Not safe. Idempotent.     RFC3253, Section 6.3. */
   1984 #define MHD_HTTP_METHOD_STR_MKWORKSPACE    "MKWORKSPACE"
   1985 /* Not safe. Idempotent.     RFC4918, Section 9.9. */
   1986 #define MHD_HTTP_METHOD_STR_MOVE           "MOVE"
   1987 /* Not safe. Idempotent.     RFC3648, Section 7. */
   1988 #define MHD_HTTP_METHOD_STR_ORDERPATCH     "ORDERPATCH"
   1989 /* Not safe. Not idempotent. RFC5789, Section 2. */
   1990 #define MHD_HTTP_METHOD_STR_PATCH          "PATCH"
   1991 /* Safe.     Idempotent.     RFC9113, Section 3.4. */
   1992 #define MHD_HTTP_METHOD_STR_PRI            "PRI"
   1993 /* Safe.     Idempotent.     RFC4918, Section 9.1; RFC8144, Section 2.1. */
   1994 #define MHD_HTTP_METHOD_STR_PROPFIND       "PROPFIND"
   1995 /* Not safe. Idempotent.     RFC4918, Section 9.2; RFC8144, Section 2.2. */
   1996 #define MHD_HTTP_METHOD_STR_PROPPATCH      "PROPPATCH"
   1997 /* Not safe. Idempotent.     RFC5842, Section 6. */
   1998 #define MHD_HTTP_METHOD_STR_REBIND         "REBIND"
   1999 /* Safe.     Idempotent.     RFC3253, Section 3.6; RFC8144, Section 2.1. */
   2000 #define MHD_HTTP_METHOD_STR_REPORT         "REPORT"
   2001 /* Safe.     Idempotent.     RFC5323, Section 2. */
   2002 #define MHD_HTTP_METHOD_STR_SEARCH         "SEARCH"
   2003 /* Not safe. Idempotent.     RFC5842, Section 5. */
   2004 #define MHD_HTTP_METHOD_STR_UNBIND         "UNBIND"
   2005 /* Not safe. Idempotent.     RFC3253, Section 4.5. */
   2006 #define MHD_HTTP_METHOD_STR_UNCHECKOUT     "UNCHECKOUT"
   2007 /* Not safe. Idempotent.     RFC2068, Section 19.6.1.3. */
   2008 #define MHD_HTTP_METHOD_STR_UNLINK         "UNLINK"
   2009 /* Not safe. Idempotent.     RFC4918, Section 9.11. */
   2010 #define MHD_HTTP_METHOD_STR_UNLOCK         "UNLOCK"
   2011 /* Not safe. Idempotent.     RFC3253, Section 7.1. */
   2012 #define MHD_HTTP_METHOD_STR_UPDATE         "UPDATE"
   2013 /* Not safe. Idempotent.     RFC4437, Section 7. */
   2014 #define MHD_HTTP_METHOD_STR_UPDATEREDIRECTREF "UPDATEREDIRECTREF"
   2015 /* Not safe. Idempotent.     RFC3253, Section 3.5. */
   2016 #define MHD_HTTP_METHOD_STR_VERSION_CONTROL "VERSION-CONTROL"
   2017 
   2018 /** @} */ /* end of group methods */
   2019 
   2020 #ifndef MHD_HTTP_POSTENCODING_DEFINED
   2021 
   2022 
   2023 /**
   2024  * @brief Possible encodings for HTML forms submitted as HTTP POST requests
   2025  *
   2026  * @defgroup postenc HTTP POST encodings
   2027  * See also: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#form-submission-2
   2028  * @{
   2029  */
   2030 enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_HTTP_PostEncoding
   2031 {
   2032   /**
   2033    * No post encoding / broken data / unknown encoding
   2034    */
   2035   MHD_HTTP_POST_ENCODING_OTHER = 0
   2036   ,
   2037   /**
   2038    * "application/x-www-form-urlencoded"
   2039    * See https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#url-encoded-form-data
   2040    * See https://url.spec.whatwg.org/#application/x-www-form-urlencoded
   2041    * See https://datatracker.ietf.org/doc/html/rfc3986#section-2
   2042    */
   2043   MHD_HTTP_POST_ENCODING_FORM_URLENCODED = 1
   2044   ,
   2045   /**
   2046    * "multipart/form-data"
   2047    * See https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data
   2048    * See https://www.rfc-editor.org/rfc/rfc7578.html
   2049    */
   2050   MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA = 2
   2051   ,
   2052   /**
   2053    * "text/plain"
   2054    * Introduced by HTML5
   2055    * See https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#plain-text-form-data
   2056    * @warning Format is ambiguous. Do not use unless there is a very strong reason.
   2057    */
   2058   MHD_HTTP_POST_ENCODING_TEXT_PLAIN = 3
   2059 };
   2060 
   2061 
   2062 /** @} */ /* end of group postenc */
   2063 
   2064 #  define MHD_HTTP_POSTENCODING_DEFINED 1
   2065 #endif /* ! MHD_HTTP_POSTENCODING_DEFINED */
   2066 
   2067 
   2068 /**
   2069  * @brief Standard headers found in HTTP requests and responses.
   2070  *
   2071  * See: https://www.iana.org/assignments/http-fields/http-fields.xhtml
   2072  *
   2073  * @defgroup headers HTTP headers
   2074  * Registry export date: 2023-10-02
   2075  * @{
   2076  */
   2077 
   2078 /* Main HTTP headers. */
   2079 /* Permanent.     RFC9110, Section 12.5.1: HTTP Semantics */
   2080 #define MHD_HTTP_HEADER_ACCEPT       "Accept"
   2081 /* Deprecated.    RFC9110, Section 12.5.2: HTTP Semantics */
   2082 #define MHD_HTTP_HEADER_ACCEPT_CHARSET "Accept-Charset"
   2083 /* Permanent.     RFC9110, Section 12.5.3: HTTP Semantics */
   2084 #define MHD_HTTP_HEADER_ACCEPT_ENCODING "Accept-Encoding"
   2085 /* Permanent.     RFC9110, Section 12.5.4: HTTP Semantics */
   2086 #define MHD_HTTP_HEADER_ACCEPT_LANGUAGE "Accept-Language"
   2087 /* Permanent.     RFC9110, Section 14.3: HTTP Semantics */
   2088 #define MHD_HTTP_HEADER_ACCEPT_RANGES "Accept-Ranges"
   2089 /* Permanent.     RFC9111, Section 5.1: HTTP Caching */
   2090 #define MHD_HTTP_HEADER_AGE          "Age"
   2091 /* Permanent.     RFC9110, Section 10.2.1: HTTP Semantics */
   2092 #define MHD_HTTP_HEADER_ALLOW        "Allow"
   2093 /* Permanent.     RFC9110, Section 11.6.3: HTTP Semantics */
   2094 #define MHD_HTTP_HEADER_AUTHENTICATION_INFO "Authentication-Info"
   2095 /* Permanent.     RFC9110, Section 11.6.2: HTTP Semantics */
   2096 #define MHD_HTTP_HEADER_AUTHORIZATION "Authorization"
   2097 /* Permanent.     RFC9111, Section 5.2 */
   2098 #define MHD_HTTP_HEADER_CACHE_CONTROL "Cache-Control"
   2099 /* Permanent.     RFC9112, Section 9.6: HTTP/1.1 */
   2100 #define MHD_HTTP_HEADER_CLOSE        "Close"
   2101 /* Permanent.     RFC9110, Section 7.6.1: HTTP Semantics */
   2102 #define MHD_HTTP_HEADER_CONNECTION   "Connection"
   2103 /* Permanent.     RFC9110, Section 8.4: HTTP Semantics */
   2104 #define MHD_HTTP_HEADER_CONTENT_ENCODING "Content-Encoding"
   2105 /* Permanent.     RFC9110, Section 8.5: HTTP Semantics */
   2106 #define MHD_HTTP_HEADER_CONTENT_LANGUAGE "Content-Language"
   2107 /* Permanent.     RFC9110, Section 8.6: HTTP Semantics */
   2108 #define MHD_HTTP_HEADER_CONTENT_LENGTH "Content-Length"
   2109 /* Permanent.     RFC9110, Section 8.7: HTTP Semantics */
   2110 #define MHD_HTTP_HEADER_CONTENT_LOCATION "Content-Location"
   2111 /* Permanent.     RFC9110, Section 14.4: HTTP Semantics */
   2112 #define MHD_HTTP_HEADER_CONTENT_RANGE "Content-Range"
   2113 /* Permanent.     RFC9110, Section 8.3: HTTP Semantics */
   2114 #define MHD_HTTP_HEADER_CONTENT_TYPE "Content-Type"
   2115 /* Permanent.     RFC9110, Section 6.6.1: HTTP Semantics */
   2116 #define MHD_HTTP_HEADER_DATE         "Date"
   2117 /* Permanent.     RFC9110, Section 8.8.3: HTTP Semantics */
   2118 #define MHD_HTTP_HEADER_ETAG         "ETag"
   2119 /* Permanent.     RFC9110, Section 10.1.1: HTTP Semantics */
   2120 #define MHD_HTTP_HEADER_EXPECT       "Expect"
   2121 /* Permanent.     RFC9111, Section 5.3: HTTP Caching */
   2122 #define MHD_HTTP_HEADER_EXPIRES      "Expires"
   2123 /* Permanent.     RFC9110, Section 10.1.2: HTTP Semantics */
   2124 #define MHD_HTTP_HEADER_FROM         "From"
   2125 /* Permanent.     RFC9110, Section 7.2: HTTP Semantics */
   2126 #define MHD_HTTP_HEADER_HOST         "Host"
   2127 /* Permanent.     RFC9110, Section 13.1.1: HTTP Semantics */
   2128 #define MHD_HTTP_HEADER_IF_MATCH     "If-Match"
   2129 /* Permanent.     RFC9110, Section 13.1.3: HTTP Semantics */
   2130 #define MHD_HTTP_HEADER_IF_MODIFIED_SINCE "If-Modified-Since"
   2131 /* Permanent.     RFC9110, Section 13.1.2: HTTP Semantics */
   2132 #define MHD_HTTP_HEADER_IF_NONE_MATCH "If-None-Match"
   2133 /* Permanent.     RFC9110, Section 13.1.5: HTTP Semantics */
   2134 #define MHD_HTTP_HEADER_IF_RANGE     "If-Range"
   2135 /* Permanent.     RFC9110, Section 13.1.4: HTTP Semantics */
   2136 #define MHD_HTTP_HEADER_IF_UNMODIFIED_SINCE "If-Unmodified-Since"
   2137 /* Permanent.     RFC9110, Section 8.8.2: HTTP Semantics */
   2138 #define MHD_HTTP_HEADER_LAST_MODIFIED "Last-Modified"
   2139 /* Permanent.     RFC9110, Section 10.2.2: HTTP Semantics */
   2140 #define MHD_HTTP_HEADER_LOCATION     "Location"
   2141 /* Permanent.     RFC9110, Section 7.6.2: HTTP Semantics */
   2142 #define MHD_HTTP_HEADER_MAX_FORWARDS "Max-Forwards"
   2143 /* Permanent.     RFC9112, Appendix B.1: HTTP/1.1 */
   2144 #define MHD_HTTP_HEADER_MIME_VERSION "MIME-Version"
   2145 /* Deprecated.    RFC9111, Section 5.4: HTTP Caching */
   2146 #define MHD_HTTP_HEADER_PRAGMA       "Pragma"
   2147 /* Permanent.     RFC9110, Section 11.7.1: HTTP Semantics */
   2148 #define MHD_HTTP_HEADER_PROXY_AUTHENTICATE "Proxy-Authenticate"
   2149 /* Permanent.     RFC9110, Section 11.7.3: HTTP Semantics */
   2150 #define MHD_HTTP_HEADER_PROXY_AUTHENTICATION_INFO "Proxy-Authentication-Info"
   2151 /* Permanent.     RFC9110, Section 11.7.2: HTTP Semantics */
   2152 #define MHD_HTTP_HEADER_PROXY_AUTHORIZATION "Proxy-Authorization"
   2153 /* Permanent.     RFC9110, Section 14.2: HTTP Semantics */
   2154 #define MHD_HTTP_HEADER_RANGE        "Range"
   2155 /* Permanent.     RFC9110, Section 10.1.3: HTTP Semantics */
   2156 #define MHD_HTTP_HEADER_REFERER      "Referer"
   2157 /* Permanent.     RFC9110, Section 10.2.3: HTTP Semantics */
   2158 #define MHD_HTTP_HEADER_RETRY_AFTER  "Retry-After"
   2159 /* Permanent.     RFC9110, Section 10.2.4: HTTP Semantics */
   2160 #define MHD_HTTP_HEADER_SERVER       "Server"
   2161 /* Permanent.     RFC9110, Section 10.1.4: HTTP Semantics */
   2162 #define MHD_HTTP_HEADER_TE           "TE"
   2163 /* Permanent.     RFC9110, Section 6.6.2: HTTP Semantics */
   2164 #define MHD_HTTP_HEADER_TRAILER      "Trailer"
   2165 /* Permanent.     RFC9112, Section 6.1: HTTP Semantics */
   2166 #define MHD_HTTP_HEADER_TRANSFER_ENCODING "Transfer-Encoding"
   2167 /* Permanent.     RFC9110, Section 7.8: HTTP Semantics */
   2168 #define MHD_HTTP_HEADER_UPGRADE      "Upgrade"
   2169 /* Permanent.     RFC9110, Section 10.1.5: HTTP Semantics */
   2170 #define MHD_HTTP_HEADER_USER_AGENT   "User-Agent"
   2171 /* Permanent.     RFC9110, Section 12.5.5: HTTP Semantics */
   2172 #define MHD_HTTP_HEADER_VARY         "Vary"
   2173 /* Permanent.     RFC9110, Section 7.6.3: HTTP Semantics */
   2174 #define MHD_HTTP_HEADER_VIA          "Via"
   2175 /* Permanent.     RFC9110, Section 11.6.1: HTTP Semantics */
   2176 #define MHD_HTTP_HEADER_WWW_AUTHENTICATE "WWW-Authenticate"
   2177 /* Permanent.     RFC9110, Section 12.5.5: HTTP Semantics */
   2178 #define MHD_HTTP_HEADER_ASTERISK     "*"
   2179 
   2180 /* Additional HTTP headers. */
   2181 /* Permanent.     RFC 3229: Delta encoding in HTTP */
   2182 #define MHD_HTTP_HEADER_A_IM         "A-IM"
   2183 /* Permanent.     RFC 2324: Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0) */
   2184 #define MHD_HTTP_HEADER_ACCEPT_ADDITIONS "Accept-Additions"
   2185 /* Permanent.     RFC 8942, Section 3.1: HTTP Client Hints */
   2186 #define MHD_HTTP_HEADER_ACCEPT_CH    "Accept-CH"
   2187 /* Permanent.     RFC 7089: HTTP Framework for Time-Based Access to Resource States -- Memento */
   2188 #define MHD_HTTP_HEADER_ACCEPT_DATETIME "Accept-Datetime"
   2189 /* Permanent.     RFC 2295: Transparent Content Negotiation in HTTP */
   2190 #define MHD_HTTP_HEADER_ACCEPT_FEATURES "Accept-Features"
   2191 /* Permanent.     RFC 5789: PATCH Method for HTTP */
   2192 #define MHD_HTTP_HEADER_ACCEPT_PATCH "Accept-Patch"
   2193 /* Permanent.     Linked Data Platform 1.0 */
   2194 #define MHD_HTTP_HEADER_ACCEPT_POST  "Accept-Post"
   2195 /* Permanent.     RFC-ietf-httpbis-message-signatures-19, Section 5.1: HTTP Message Signatures */
   2196 #define MHD_HTTP_HEADER_ACCEPT_SIGNATURE "Accept-Signature"
   2197 /* Permanent.     Fetch */
   2198 #define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS \
   2199         "Access-Control-Allow-Credentials"
   2200 /* Permanent.     Fetch */
   2201 #define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_HEADERS \
   2202         "Access-Control-Allow-Headers"
   2203 /* Permanent.     Fetch */
   2204 #define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_METHODS \
   2205         "Access-Control-Allow-Methods"
   2206 /* Permanent.     Fetch */
   2207 #define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN \
   2208         "Access-Control-Allow-Origin"
   2209 /* Permanent.     Fetch */
   2210 #define MHD_HTTP_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS \
   2211         "Access-Control-Expose-Headers"
   2212 /* Permanent.     Fetch */
   2213 #define MHD_HTTP_HEADER_ACCESS_CONTROL_MAX_AGE "Access-Control-Max-Age"
   2214 /* Permanent.     Fetch */
   2215 #define MHD_HTTP_HEADER_ACCESS_CONTROL_REQUEST_HEADERS \
   2216         "Access-Control-Request-Headers"
   2217 /* Permanent.     Fetch */
   2218 #define MHD_HTTP_HEADER_ACCESS_CONTROL_REQUEST_METHOD \
   2219         "Access-Control-Request-Method"
   2220 /* Permanent.     RFC 7639, Section 2: The ALPN HTTP Header Field */
   2221 #define MHD_HTTP_HEADER_ALPN         "ALPN"
   2222 /* Permanent.     RFC 7838: HTTP Alternative Services */
   2223 #define MHD_HTTP_HEADER_ALT_SVC      "Alt-Svc"
   2224 /* Permanent.     RFC 7838: HTTP Alternative Services */
   2225 #define MHD_HTTP_HEADER_ALT_USED     "Alt-Used"
   2226 /* Permanent.     RFC 2295: Transparent Content Negotiation in HTTP */
   2227 #define MHD_HTTP_HEADER_ALTERNATES   "Alternates"
   2228 /* Permanent.     RFC 4437: Web Distributed Authoring and Versioning (WebDAV) Redirect Reference Resources */
   2229 #define MHD_HTTP_HEADER_APPLY_TO_REDIRECT_REF "Apply-To-Redirect-Ref"
   2230 /* Permanent.     RFC 8053, Section 4: HTTP Authentication Extensions for Interactive Clients */
   2231 #define MHD_HTTP_HEADER_AUTHENTICATION_CONTROL "Authentication-Control"
   2232 /* Permanent.     RFC9211: The Cache-Status HTTP Response Header Field */
   2233 #define MHD_HTTP_HEADER_CACHE_STATUS "Cache-Status"
   2234 /* Permanent.     RFC 8607, Section 5.1: Calendaring Extensions to WebDAV (CalDAV): Managed Attachments */
   2235 #define MHD_HTTP_HEADER_CAL_MANAGED_ID "Cal-Managed-ID"
   2236 /* Permanent.     RFC 7809, Section 7.1: Calendaring Extensions to WebDAV (CalDAV): Time Zones by Reference */
   2237 #define MHD_HTTP_HEADER_CALDAV_TIMEZONES "CalDAV-Timezones"
   2238 /* Permanent.     RFC9297 */
   2239 #define MHD_HTTP_HEADER_CAPSULE_PROTOCOL "Capsule-Protocol"
   2240 /* Permanent.     RFC9213: Targeted HTTP Cache Control */
   2241 #define MHD_HTTP_HEADER_CDN_CACHE_CONTROL "CDN-Cache-Control"
   2242 /* Permanent.     RFC 8586: Loop Detection in Content Delivery Networks (CDNs) */
   2243 #define MHD_HTTP_HEADER_CDN_LOOP     "CDN-Loop"
   2244 /* Permanent.     RFC 8739, Section 3.3: Support for Short-Term, Automatically Renewed (STAR) Certificates in the Automated Certificate Management Environment (ACME) */
   2245 #define MHD_HTTP_HEADER_CERT_NOT_AFTER "Cert-Not-After"
   2246 /* Permanent.     RFC 8739, Section 3.3: Support for Short-Term, Automatically Renewed (STAR) Certificates in the Automated Certificate Management Environment (ACME) */
   2247 #define MHD_HTTP_HEADER_CERT_NOT_BEFORE "Cert-Not-Before"
   2248 /* Permanent.     Clear Site Data */
   2249 #define MHD_HTTP_HEADER_CLEAR_SITE_DATA "Clear-Site-Data"
   2250 /* Permanent.     RFC9440, Section 2: Client-Cert HTTP Header Field */
   2251 #define MHD_HTTP_HEADER_CLIENT_CERT  "Client-Cert"
   2252 /* Permanent.     RFC9440, Section 2: Client-Cert HTTP Header Field */
   2253 #define MHD_HTTP_HEADER_CLIENT_CERT_CHAIN "Client-Cert-Chain"
   2254 /* Permanent.     RFC-ietf-httpbis-digest-headers-13, Section 2: Digest Fields */
   2255 #define MHD_HTTP_HEADER_CONTENT_DIGEST "Content-Digest"
   2256 /* Permanent.     RFC 6266: Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP) */
   2257 #define MHD_HTTP_HEADER_CONTENT_DISPOSITION "Content-Disposition"
   2258 /* Permanent.     The HTTP Distribution and Replication Protocol */
   2259 #define MHD_HTTP_HEADER_CONTENT_ID   "Content-ID"
   2260 /* Permanent.     Content Security Policy Level 3 */
   2261 #define MHD_HTTP_HEADER_CONTENT_SECURITY_POLICY "Content-Security-Policy"
   2262 /* Permanent.     Content Security Policy Level 3 */
   2263 #define MHD_HTTP_HEADER_CONTENT_SECURITY_POLICY_REPORT_ONLY \
   2264         "Content-Security-Policy-Report-Only"
   2265 /* Permanent.     RFC 6265: HTTP State Management Mechanism */
   2266 #define MHD_HTTP_HEADER_COOKIE       "Cookie"
   2267 /* Permanent.     HTML */
   2268 #define MHD_HTTP_HEADER_CROSS_ORIGIN_EMBEDDER_POLICY \
   2269         "Cross-Origin-Embedder-Policy"
   2270 /* Permanent.     HTML */
   2271 #define MHD_HTTP_HEADER_CROSS_ORIGIN_EMBEDDER_POLICY_REPORT_ONLY \
   2272         "Cross-Origin-Embedder-Policy-Report-Only"
   2273 /* Permanent.     HTML */
   2274 #define MHD_HTTP_HEADER_CROSS_ORIGIN_OPENER_POLICY "Cross-Origin-Opener-Policy"
   2275 /* Permanent.     HTML */
   2276 #define MHD_HTTP_HEADER_CROSS_ORIGIN_OPENER_POLICY_REPORT_ONLY \
   2277         "Cross-Origin-Opener-Policy-Report-Only"
   2278 /* Permanent.     Fetch */
   2279 #define MHD_HTTP_HEADER_CROSS_ORIGIN_RESOURCE_POLICY \
   2280         "Cross-Origin-Resource-Policy"
   2281 /* Permanent.     RFC 5323: Web Distributed Authoring and Versioning (WebDAV) SEARCH */
   2282 #define MHD_HTTP_HEADER_DASL         "DASL"
   2283 /* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
   2284 #define MHD_HTTP_HEADER_DAV          "DAV"
   2285 /* Permanent.     RFC 3229: Delta encoding in HTTP */
   2286 #define MHD_HTTP_HEADER_DELTA_BASE   "Delta-Base"
   2287 /* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
   2288 #define MHD_HTTP_HEADER_DEPTH        "Depth"
   2289 /* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
   2290 #define MHD_HTTP_HEADER_DESTINATION  "Destination"
   2291 /* Permanent.     The HTTP Distribution and Replication Protocol */
   2292 #define MHD_HTTP_HEADER_DIFFERENTIAL_ID "Differential-ID"
   2293 /* Permanent.     RFC9449: OAuth 2.0 Demonstrating Proof of Possession (DPoP) */
   2294 #define MHD_HTTP_HEADER_DPOP         "DPoP"
   2295 /* Permanent.     RFC9449: OAuth 2.0 Demonstrating Proof of Possession (DPoP) */
   2296 #define MHD_HTTP_HEADER_DPOP_NONCE   "DPoP-Nonce"
   2297 /* Permanent.     RFC 8470: Using Early Data in HTTP */
   2298 #define MHD_HTTP_HEADER_EARLY_DATA   "Early-Data"
   2299 /* Permanent.     RFC9163: Expect-CT Extension for HTTP */
   2300 #define MHD_HTTP_HEADER_EXPECT_CT    "Expect-CT"
   2301 /* Permanent.     RFC 7239: Forwarded HTTP Extension */
   2302 #define MHD_HTTP_HEADER_FORWARDED    "Forwarded"
   2303 /* Permanent.     RFC 7486, Section 6.1.1: HTTP Origin-Bound Authentication (HOBA) */
   2304 #define MHD_HTTP_HEADER_HOBAREG      "Hobareg"
   2305 /* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
   2306 #define MHD_HTTP_HEADER_IF           "If"
   2307 /* Permanent.      RFC 6338: Scheduling Extensions to CalDAV */
   2308 #define MHD_HTTP_HEADER_IF_SCHEDULE_TAG_MATCH "If-Schedule-Tag-Match"
   2309 /* Permanent.     RFC 3229: Delta encoding in HTTP */
   2310 #define MHD_HTTP_HEADER_IM           "IM"
   2311 /* Permanent.     RFC 8473: Token Binding over HTTP */
   2312 #define MHD_HTTP_HEADER_INCLUDE_REFERRED_TOKEN_BINDING_ID \
   2313         "Include-Referred-Token-Binding-ID"
   2314 /* Permanent.     RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */
   2315 #define MHD_HTTP_HEADER_KEEP_ALIVE   "Keep-Alive"
   2316 /* Permanent.     RFC 3253: Versioning Extensions to WebDAV: (Web Distributed Authoring and Versioning) */
   2317 #define MHD_HTTP_HEADER_LABEL        "Label"
   2318 /* Permanent.     HTML */
   2319 #define MHD_HTTP_HEADER_LAST_EVENT_ID "Last-Event-ID"
   2320 /* Permanent.     RFC 8288: Web Linking */
   2321 #define MHD_HTTP_HEADER_LINK         "Link"
   2322 /* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
   2323 #define MHD_HTTP_HEADER_LOCK_TOKEN   "Lock-Token"
   2324 /* Permanent.     RFC 7089: HTTP Framework for Time-Based Access to Resource States -- Memento */
   2325 #define MHD_HTTP_HEADER_MEMENTO_DATETIME "Memento-Datetime"
   2326 /* Permanent.     RFC 2227: Simple Hit-Metering and Usage-Limiting for HTTP */
   2327 #define MHD_HTTP_HEADER_METER        "Meter"
   2328 /* Permanent.     RFC 2295: Transparent Content Negotiation in HTTP */
   2329 #define MHD_HTTP_HEADER_NEGOTIATE    "Negotiate"
   2330 /* Permanent.     Network Error Logging */
   2331 #define MHD_HTTP_HEADER_NEL          "NEL"
   2332 /* Permanent.     OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */
   2333 #define MHD_HTTP_HEADER_ODATA_ENTITYID "OData-EntityId"
   2334 /* Permanent.     OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */
   2335 #define MHD_HTTP_HEADER_ODATA_ISOLATION "OData-Isolation"
   2336 /* Permanent.     OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */
   2337 #define MHD_HTTP_HEADER_ODATA_MAXVERSION "OData-MaxVersion"
   2338 /* Permanent.     OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */
   2339 #define MHD_HTTP_HEADER_ODATA_VERSION "OData-Version"
   2340 /* Permanent.     RFC 8053, Section 3: HTTP Authentication Extensions for Interactive Clients */
   2341 #define MHD_HTTP_HEADER_OPTIONAL_WWW_AUTHENTICATE "Optional-WWW-Authenticate"
   2342 /* Permanent.     RFC 3648: Web Distributed Authoring and Versioning (WebDAV) Ordered Collections Protocol */
   2343 #define MHD_HTTP_HEADER_ORDERING_TYPE "Ordering-Type"
   2344 /* Permanent.     RFC 6454: The Web Origin Concept */
   2345 #define MHD_HTTP_HEADER_ORIGIN       "Origin"
   2346 /* Permanent.     HTML */
   2347 #define MHD_HTTP_HEADER_ORIGIN_AGENT_CLUSTER "Origin-Agent-Cluster"
   2348 /* Permanent.     RFC 8613, Section 11.1: Object Security for Constrained RESTful Environments (OSCORE) */
   2349 #define MHD_HTTP_HEADER_OSCORE       "OSCORE"
   2350 /* Permanent.     OASIS Project Specification 01; OASIS; Chet_Ensign */
   2351 #define MHD_HTTP_HEADER_OSLC_CORE_VERSION "OSLC-Core-Version"
   2352 /* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
   2353 #define MHD_HTTP_HEADER_OVERWRITE    "Overwrite"
   2354 /* Permanent.     HTML */
   2355 #define MHD_HTTP_HEADER_PING_FROM    "Ping-From"
   2356 /* Permanent.     HTML */
   2357 #define MHD_HTTP_HEADER_PING_TO      "Ping-To"
   2358 /* Permanent.     RFC 3648: Web Distributed Authoring and Versioning (WebDAV) Ordered Collections Protocol */
   2359 #define MHD_HTTP_HEADER_POSITION     "Position"
   2360 /* Permanent.     RFC 7240: Prefer Header for HTTP */
   2361 #define MHD_HTTP_HEADER_PREFER       "Prefer"
   2362 /* Permanent.     RFC 7240: Prefer Header for HTTP */
   2363 #define MHD_HTTP_HEADER_PREFERENCE_APPLIED "Preference-Applied"
   2364 /* Permanent.     RFC9218: Extensible Prioritization Scheme for HTTP */
   2365 #define MHD_HTTP_HEADER_PRIORITY     "Priority"
   2366 /* Permanent.     RFC9209: The Proxy-Status HTTP Response Header Field */
   2367 #define MHD_HTTP_HEADER_PROXY_STATUS "Proxy-Status"
   2368 /* Permanent.     RFC 7469: Public Key Pinning Extension for HTTP */
   2369 #define MHD_HTTP_HEADER_PUBLIC_KEY_PINS "Public-Key-Pins"
   2370 /* Permanent.     RFC 7469: Public Key Pinning Extension for HTTP */
   2371 #define MHD_HTTP_HEADER_PUBLIC_KEY_PINS_REPORT_ONLY \
   2372         "Public-Key-Pins-Report-Only"
   2373 /* Permanent.     RFC 4437: Web Distributed Authoring and Versioning (WebDAV) Redirect Reference Resources */
   2374 #define MHD_HTTP_HEADER_REDIRECT_REF "Redirect-Ref"
   2375 /* Permanent.     HTML */
   2376 #define MHD_HTTP_HEADER_REFRESH      "Refresh"
   2377 /* Permanent.     RFC 8555, Section 6.5.1: Automatic Certificate Management Environment (ACME) */
   2378 #define MHD_HTTP_HEADER_REPLAY_NONCE "Replay-Nonce"
   2379 /* Permanent.     RFC-ietf-httpbis-digest-headers-13, Section 3: Digest Fields */
   2380 #define MHD_HTTP_HEADER_REPR_DIGEST  "Repr-Digest"
   2381 /* Permanent.     RFC 6638: Scheduling Extensions to CalDAV */
   2382 #define MHD_HTTP_HEADER_SCHEDULE_REPLY "Schedule-Reply"
   2383 /* Permanent.     RFC 6338: Scheduling Extensions to CalDAV */
   2384 #define MHD_HTTP_HEADER_SCHEDULE_TAG "Schedule-Tag"
   2385 /* Permanent.     Fetch */
   2386 #define MHD_HTTP_HEADER_SEC_PURPOSE  "Sec-Purpose"
   2387 /* Permanent.     RFC 8473: Token Binding over HTTP */
   2388 #define MHD_HTTP_HEADER_SEC_TOKEN_BINDING "Sec-Token-Binding"
   2389 /* Permanent.     RFC 6455: The WebSocket Protocol */
   2390 #define MHD_HTTP_HEADER_SEC_WEBSOCKET_ACCEPT "Sec-WebSocket-Accept"
   2391 /* Permanent.     RFC 6455: The WebSocket Protocol */
   2392 #define MHD_HTTP_HEADER_SEC_WEBSOCKET_EXTENSIONS "Sec-WebSocket-Extensions"
   2393 /* Permanent.     RFC 6455: The WebSocket Protocol */
   2394 #define MHD_HTTP_HEADER_SEC_WEBSOCKET_KEY "Sec-WebSocket-Key"
   2395 /* Permanent.     RFC 6455: The WebSocket Protocol */
   2396 #define MHD_HTTP_HEADER_SEC_WEBSOCKET_PROTOCOL "Sec-WebSocket-Protocol"
   2397 /* Permanent.     RFC 6455: The WebSocket Protocol */
   2398 #define MHD_HTTP_HEADER_SEC_WEBSOCKET_VERSION "Sec-WebSocket-Version"
   2399 /* Permanent.     Server Timing */
   2400 #define MHD_HTTP_HEADER_SERVER_TIMING "Server-Timing"
   2401 /* Permanent.     RFC 6265: HTTP State Management Mechanism */
   2402 #define MHD_HTTP_HEADER_SET_COOKIE   "Set-Cookie"
   2403 /* Permanent.     RFC-ietf-httpbis-message-signatures-19, Section 4.2: HTTP Message Signatures */
   2404 #define MHD_HTTP_HEADER_SIGNATURE    "Signature"
   2405 /* Permanent.     RFC-ietf-httpbis-message-signatures-19, Section 4.1: HTTP Message Signatures */
   2406 #define MHD_HTTP_HEADER_SIGNATURE_INPUT "Signature-Input"
   2407 /* Permanent.     RFC 5023: The Atom Publishing Protocol */
   2408 #define MHD_HTTP_HEADER_SLUG         "SLUG"
   2409 /* Permanent.     Simple Object Access Protocol (SOAP) 1.1 */
   2410 #define MHD_HTTP_HEADER_SOAPACTION   "SoapAction"
   2411 /* Permanent.     RFC 2518: HTTP Extensions for Distributed Authoring -- WEBDAV */
   2412 #define MHD_HTTP_HEADER_STATUS_URI   "Status-URI"
   2413 /* Permanent.     RFC 6797: HTTP Strict Transport Security (HSTS) */
   2414 #define MHD_HTTP_HEADER_STRICT_TRANSPORT_SECURITY "Strict-Transport-Security"
   2415 /* Permanent.     RFC 8594: The Sunset HTTP Header Field */
   2416 #define MHD_HTTP_HEADER_SUNSET       "Sunset"
   2417 /* Permanent.     Edge Architecture Specification */
   2418 #define MHD_HTTP_HEADER_SURROGATE_CAPABILITY "Surrogate-Capability"
   2419 /* Permanent.     Edge Architecture Specification */
   2420 #define MHD_HTTP_HEADER_SURROGATE_CONTROL "Surrogate-Control"
   2421 /* Permanent.     RFC 2295: Transparent Content Negotiation in HTTP */
   2422 #define MHD_HTTP_HEADER_TCN          "TCN"
   2423 /* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
   2424 #define MHD_HTTP_HEADER_TIMEOUT      "Timeout"
   2425 /* Permanent.     RFC 8030, Section 5.4: Generic Event Delivery Using HTTP Push */
   2426 #define MHD_HTTP_HEADER_TOPIC        "Topic"
   2427 /* Permanent.     Trace Context */
   2428 #define MHD_HTTP_HEADER_TRACEPARENT  "Traceparent"
   2429 /* Permanent.     Trace Context */
   2430 #define MHD_HTTP_HEADER_TRACESTATE   "Tracestate"
   2431 /* Permanent.     RFC 8030, Section 5.2: Generic Event Delivery Using HTTP Push */
   2432 #define MHD_HTTP_HEADER_TTL          "TTL"
   2433 /* Permanent.     RFC 8030, Section 5.3: Generic Event Delivery Using HTTP Push */
   2434 #define MHD_HTTP_HEADER_URGENCY      "Urgency"
   2435 /* Permanent.     RFC 2295: Transparent Content Negotiation in HTTP */
   2436 #define MHD_HTTP_HEADER_VARIANT_VARY "Variant-Vary"
   2437 /* Permanent.     RFC-ietf-httpbis-digest-headers-13, Section 4: Digest Fields */
   2438 #define MHD_HTTP_HEADER_WANT_CONTENT_DIGEST "Want-Content-Digest"
   2439 /* Permanent.     RFC-ietf-httpbis-digest-headers-13, Section 4: Digest Fields */
   2440 #define MHD_HTTP_HEADER_WANT_REPR_DIGEST "Want-Repr-Digest"
   2441 /* Permanent.     Fetch */
   2442 #define MHD_HTTP_HEADER_X_CONTENT_TYPE_OPTIONS "X-Content-Type-Options"
   2443 /* Permanent.     HTML */
   2444 #define MHD_HTTP_HEADER_X_FRAME_OPTIONS "X-Frame-Options"
   2445 /* Provisional.   AMP-Cache-Transform HTTP request header */
   2446 #define MHD_HTTP_HEADER_AMP_CACHE_TRANSFORM "AMP-Cache-Transform"
   2447 /* Provisional.   OSLC Configuration Management Version 1.0. Part 3: Configuration Specification */
   2448 #define MHD_HTTP_HEADER_CONFIGURATION_CONTEXT "Configuration-Context"
   2449 /* Provisional.   RFC 6017: Electronic Data Interchange - Internet Integration (EDIINT) Features Header Field */
   2450 #define MHD_HTTP_HEADER_EDIINT_FEATURES "EDIINT-Features"
   2451 /* Provisional.   OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */
   2452 #define MHD_HTTP_HEADER_ISOLATION    "Isolation"
   2453 /* Provisional.   Permissions Policy */
   2454 #define MHD_HTTP_HEADER_PERMISSIONS_POLICY "Permissions-Policy"
   2455 /* Provisional.   Repeatable Requests Version 1.0; OASIS; Chet_Ensign */
   2456 #define MHD_HTTP_HEADER_REPEATABILITY_CLIENT_ID "Repeatability-Client-ID"
   2457 /* Provisional.   Repeatable Requests Version 1.0; OASIS; Chet_Ensign */
   2458 #define MHD_HTTP_HEADER_REPEATABILITY_FIRST_SENT "Repeatability-First-Sent"
   2459 /* Provisional.   Repeatable Requests Version 1.0; OASIS; Chet_Ensign */
   2460 #define MHD_HTTP_HEADER_REPEATABILITY_REQUEST_ID "Repeatability-Request-ID"
   2461 /* Provisional.   Repeatable Requests Version 1.0; OASIS; Chet_Ensign */
   2462 #define MHD_HTTP_HEADER_REPEATABILITY_RESULT "Repeatability-Result"
   2463 /* Provisional.   Reporting API */
   2464 #define MHD_HTTP_HEADER_REPORTING_ENDPOINTS "Reporting-Endpoints"
   2465 /* Provisional.   Global Privacy Control (GPC) */
   2466 #define MHD_HTTP_HEADER_SEC_GPC      "Sec-GPC"
   2467 /* Provisional.   Resource Timing Level 1 */
   2468 #define MHD_HTTP_HEADER_TIMING_ALLOW_ORIGIN "Timing-Allow-Origin"
   2469 /* Deprecated.    PEP - an Extension Mechanism for HTTP; status-change-http-experiments-to-historic */
   2470 #define MHD_HTTP_HEADER_C_PEP_INFO   "C-PEP-Info"
   2471 /* Deprecated.    White Paper: Joint Electronic Payment Initiative */
   2472 #define MHD_HTTP_HEADER_PROTOCOL_INFO "Protocol-Info"
   2473 /* Deprecated.    White Paper: Joint Electronic Payment Initiative */
   2474 #define MHD_HTTP_HEADER_PROTOCOL_QUERY "Protocol-Query"
   2475 /* Obsoleted.     Access Control for Cross-site Requests */
   2476 #define MHD_HTTP_HEADER_ACCESS_CONTROL "Access-Control"
   2477 /* Obsoleted.     RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
   2478 #define MHD_HTTP_HEADER_C_EXT        "C-Ext"
   2479 /* Obsoleted.     RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
   2480 #define MHD_HTTP_HEADER_C_MAN        "C-Man"
   2481 /* Obsoleted.     RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
   2482 #define MHD_HTTP_HEADER_C_OPT        "C-Opt"
   2483 /* Obsoleted.     PEP - an Extension Mechanism for HTTP; status-change-http-experiments-to-historic */
   2484 #define MHD_HTTP_HEADER_C_PEP        "C-PEP"
   2485 /* Obsoleted.     RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1; RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1 */
   2486 #define MHD_HTTP_HEADER_CONTENT_BASE "Content-Base"
   2487 /* 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 */
   2488 #define MHD_HTTP_HEADER_CONTENT_MD5  "Content-MD5"
   2489 /* Obsoleted.     HTML 4.01 Specification */
   2490 #define MHD_HTTP_HEADER_CONTENT_SCRIPT_TYPE "Content-Script-Type"
   2491 /* Obsoleted.     HTML 4.01 Specification */
   2492 #define MHD_HTTP_HEADER_CONTENT_STYLE_TYPE "Content-Style-Type"
   2493 /* Obsoleted.     RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */
   2494 #define MHD_HTTP_HEADER_CONTENT_VERSION "Content-Version"
   2495 /* Obsoleted.     RFC 2965: HTTP State Management Mechanism; RFC 6265: HTTP State Management Mechanism */
   2496 #define MHD_HTTP_HEADER_COOKIE2      "Cookie2"
   2497 /* Obsoleted.     HTML 4.01 Specification */
   2498 #define MHD_HTTP_HEADER_DEFAULT_STYLE "Default-Style"
   2499 /* Obsoleted.     RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */
   2500 #define MHD_HTTP_HEADER_DERIVED_FROM "Derived-From"
   2501 /* Obsoleted.     RFC 3230: Instance Digests in HTTP; RFC-ietf-httpbis-digest-headers-13, Section 1.3: Digest Fields */
   2502 #define MHD_HTTP_HEADER_DIGEST       "Digest"
   2503 /* Obsoleted.     RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
   2504 #define MHD_HTTP_HEADER_EXT          "Ext"
   2505 /* Obsoleted.     Implementation of OPS Over HTTP */
   2506 #define MHD_HTTP_HEADER_GETPROFILE   "GetProfile"
   2507 /* Obsoleted.     RFC 7540, Section 3.2.1: Hypertext Transfer Protocol Version 2 (HTTP/2) */
   2508 #define MHD_HTTP_HEADER_HTTP2_SETTINGS "HTTP2-Settings"
   2509 /* Obsoleted.     RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
   2510 #define MHD_HTTP_HEADER_MAN          "Man"
   2511 /* Obsoleted.     Access Control for Cross-site Requests */
   2512 #define MHD_HTTP_HEADER_METHOD_CHECK "Method-Check"
   2513 /* Obsoleted.     Access Control for Cross-site Requests */
   2514 #define MHD_HTTP_HEADER_METHOD_CHECK_EXPIRES "Method-Check-Expires"
   2515 /* Obsoleted.     RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
   2516 #define MHD_HTTP_HEADER_OPT          "Opt"
   2517 /* Obsoleted.     The Platform for Privacy Preferences 1.0 (P3P1.0) Specification */
   2518 #define MHD_HTTP_HEADER_P3P          "P3P"
   2519 /* Obsoleted.     PEP - an Extension Mechanism for HTTP */
   2520 #define MHD_HTTP_HEADER_PEP          "PEP"
   2521 /* Obsoleted.     PEP - an Extension Mechanism for HTTP */
   2522 #define MHD_HTTP_HEADER_PEP_INFO     "Pep-Info"
   2523 /* Obsoleted.     PICS Label Distribution Label Syntax and Communication Protocols */
   2524 #define MHD_HTTP_HEADER_PICS_LABEL   "PICS-Label"
   2525 /* Obsoleted.     Implementation of OPS Over HTTP */
   2526 #define MHD_HTTP_HEADER_PROFILEOBJECT "ProfileObject"
   2527 /* Obsoleted.     PICS Label Distribution Label Syntax and Communication Protocols */
   2528 #define MHD_HTTP_HEADER_PROTOCOL     "Protocol"
   2529 /* Obsoleted.     PICS Label Distribution Label Syntax and Communication Protocols */
   2530 #define MHD_HTTP_HEADER_PROTOCOL_REQUEST "Protocol-Request"
   2531 /* Obsoleted.     Notification for Proxy Caches */
   2532 #define MHD_HTTP_HEADER_PROXY_FEATURES "Proxy-Features"
   2533 /* Obsoleted.     Notification for Proxy Caches */
   2534 #define MHD_HTTP_HEADER_PROXY_INSTRUCTION "Proxy-Instruction"
   2535 /* Obsoleted.     RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */
   2536 #define MHD_HTTP_HEADER_PUBLIC       "Public"
   2537 /* Obsoleted.     Access Control for Cross-site Requests */
   2538 #define MHD_HTTP_HEADER_REFERER_ROOT "Referer-Root"
   2539 /* Obsoleted.     RFC 2310: The Safe Response Header Field; status-change-http-experiments-to-historic */
   2540 #define MHD_HTTP_HEADER_SAFE         "Safe"
   2541 /* Obsoleted.     RFC 2660: The Secure HyperText Transfer Protocol; status-change-http-experiments-to-historic */
   2542 #define MHD_HTTP_HEADER_SECURITY_SCHEME "Security-Scheme"
   2543 /* Obsoleted.     RFC 2965: HTTP State Management Mechanism; RFC 6265: HTTP State Management Mechanism */
   2544 #define MHD_HTTP_HEADER_SET_COOKIE2  "Set-Cookie2"
   2545 /* Obsoleted.     Implementation of OPS Over HTTP */
   2546 #define MHD_HTTP_HEADER_SETPROFILE   "SetProfile"
   2547 /* Obsoleted.     RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */
   2548 #define MHD_HTTP_HEADER_URI          "URI"
   2549 /* Obsoleted.     RFC 3230: Instance Digests in HTTP; RFC-ietf-httpbis-digest-headers-13, Section 1.3: Digest Fields */
   2550 #define MHD_HTTP_HEADER_WANT_DIGEST  "Want-Digest"
   2551 /* Obsoleted.     RFC9111, Section 5.5: HTTP Caching */
   2552 #define MHD_HTTP_HEADER_WARNING      "Warning"
   2553 
   2554 /* Headers removed from the registry. Do not use! */
   2555 /* Obsoleted.     RFC4229 */
   2556 #define MHD_HTTP_HEADER_COMPLIANCE   "Compliance"
   2557 /* Obsoleted.     RFC4229 */
   2558 #define MHD_HTTP_HEADER_CONTENT_TRANSFER_ENCODING "Content-Transfer-Encoding"
   2559 /* Obsoleted.     RFC4229 */
   2560 #define MHD_HTTP_HEADER_COST         "Cost"
   2561 /* Obsoleted.     RFC4229 */
   2562 #define MHD_HTTP_HEADER_MESSAGE_ID   "Message-ID"
   2563 /* Obsoleted.     RFC4229 */
   2564 #define MHD_HTTP_HEADER_NON_COMPLIANCE "Non-Compliance"
   2565 /* Obsoleted.     RFC4229 */
   2566 #define MHD_HTTP_HEADER_OPTIONAL     "Optional"
   2567 /* Obsoleted.     RFC4229 */
   2568 #define MHD_HTTP_HEADER_RESOLUTION_HINT "Resolution-Hint"
   2569 /* Obsoleted.     RFC4229 */
   2570 #define MHD_HTTP_HEADER_RESOLVER_LOCATION "Resolver-Location"
   2571 /* Obsoleted.     RFC4229 */
   2572 #define MHD_HTTP_HEADER_SUBOK        "SubOK"
   2573 /* Obsoleted.     RFC4229 */
   2574 #define MHD_HTTP_HEADER_SUBST        "Subst"
   2575 /* Obsoleted.     RFC4229 */
   2576 #define MHD_HTTP_HEADER_TITLE        "Title"
   2577 /* Obsoleted.     RFC4229 */
   2578 #define MHD_HTTP_HEADER_UA_COLOR     "UA-Color"
   2579 /* Obsoleted.     RFC4229 */
   2580 #define MHD_HTTP_HEADER_UA_MEDIA     "UA-Media"
   2581 /* Obsoleted.     RFC4229 */
   2582 #define MHD_HTTP_HEADER_UA_PIXELS    "UA-Pixels"
   2583 /* Obsoleted.     RFC4229 */
   2584 #define MHD_HTTP_HEADER_UA_RESOLUTION "UA-Resolution"
   2585 /* Obsoleted.     RFC4229 */
   2586 #define MHD_HTTP_HEADER_UA_WINDOWPIXELS "UA-Windowpixels"
   2587 /* Obsoleted.     RFC4229 */
   2588 #define MHD_HTTP_HEADER_VERSION      "Version"
   2589 /* Obsoleted.     W3C Mobile Web Best Practices Working Group */
   2590 #define MHD_HTTP_HEADER_X_DEVICE_ACCEPT "X-Device-Accept"
   2591 /* Obsoleted.     W3C Mobile Web Best Practices Working Group */
   2592 #define MHD_HTTP_HEADER_X_DEVICE_ACCEPT_CHARSET "X-Device-Accept-Charset"
   2593 /* Obsoleted.     W3C Mobile Web Best Practices Working Group */
   2594 #define MHD_HTTP_HEADER_X_DEVICE_ACCEPT_ENCODING "X-Device-Accept-Encoding"
   2595 /* Obsoleted.     W3C Mobile Web Best Practices Working Group */
   2596 #define MHD_HTTP_HEADER_X_DEVICE_ACCEPT_LANGUAGE "X-Device-Accept-Language"
   2597 /* Obsoleted.     W3C Mobile Web Best Practices Working Group */
   2598 #define MHD_HTTP_HEADER_X_DEVICE_USER_AGENT "X-Device-User-Agent"
   2599 
   2600 
   2601 /**
   2602  * Predefined list of headers
   2603  * To be filled with HPACK static data
   2604  */
   2605 enum MHD_PredefinedHeader
   2606 {
   2607   MHD_PREDEF_ACCEPT_CHARSET = 15,
   2608   MHD_PREDEF_ACCEPT_LANGUAGE = 17
   2609 };
   2610 
   2611 
   2612 /** @} */ /* end of group headers */
   2613 
   2614 /**
   2615  * A client has requested the given url using the given method
   2616  * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT,
   2617  * #MHD_HTTP_METHOD_DELETE, #MHD_HTTP_METHOD_POST, etc).
   2618  * If @a upload_size is not zero and response action is provided by this
   2619  * callback, then upload will be discarded and the stream (the connection for
   2620  * HTTP/1.1) will be closed after sending the response.
   2621  *
   2622  * @param cls argument given together with the function
   2623  *        pointer when the handler was registered with MHD
   2624  * @param request the request object
   2625  * @param path the requested uri (without arguments after "?")
   2626  * @param method the HTTP method used (#MHD_HTTP_METHOD_GET,
   2627  *        #MHD_HTTP_METHOD_PUT, etc.)
   2628  * @param upload_size the size of the message upload content payload,
   2629  *                    #MHD_SIZE_UNKNOWN for chunked uploads (if the
   2630  *                    final chunk has not been processed yet)
   2631  * @return action how to proceed, NULL
   2632  *         if the request must be aborted due to a serious
   2633  *         error while handling the request (implies closure
   2634  *         of underling data stream, for HTTP/1.1 it means
   2635  *         socket closure).
   2636  */
   2637 typedef const struct MHD_Action *
   2638 (MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_NONNULL_ (3)
   2639  *MHD_RequestCallback)(void *cls,
   2640                        struct MHD_Request *MHD_RESTRICT request,
   2641                        const struct MHD_String *MHD_RESTRICT path,
   2642                        enum MHD_HTTP_Method method,
   2643                        uint_fast64_t upload_size);
   2644 
   2645 
   2646 /**
   2647  * Create (but do not yet start) an MHD daemon.
   2648  * Usually, various options are set before
   2649  * starting the daemon with #MHD_daemon_start().
   2650  *
   2651  * @param req_cb the function to be called for incoming requests
   2652  * @param req_cb_cls the closure for @a cb
   2653  * @return the pointer to the new object on success,
   2654  *         NULL on error (like out-of-memory)
   2655  */
   2656 MHD_EXTERN_ struct MHD_Daemon *
   2657 MHD_daemon_create (MHD_RequestCallback req_cb,
   2658                    void *req_cb_cls)
   2659 MHD_FN_MUST_CHECK_RESULT_;
   2660 
   2661 
   2662 /**
   2663  * Start a webserver.
   2664  * This function:
   2665  * + checks the combination of set options,
   2666  * + initialises the TLS library (if TLS is requested),
   2667  * + creates the listen socket (if not provided and if allowed),
   2668  * + starts the daemon internal threads (if allowed)
   2669  *
   2670  * @param[in,out] daemon daemon to start; you can no longer set
   2671  *        options on this daemon after this call!
   2672  * @return #MHD_SC_OK on success
   2673  * @ingroup daemon
   2674  */
   2675 MHD_EXTERN_ enum MHD_StatusCode
   2676 MHD_daemon_start (struct MHD_Daemon *daemon)
   2677 MHD_FN_PAR_NONNULL_ (1) MHD_FN_MUST_CHECK_RESULT_;
   2678 
   2679 
   2680 /**
   2681  * Stop accepting connections from the listening socket.  Allows
   2682  * clients to continue processing, but stops accepting new
   2683  * connections.  Note that the caller is responsible for closing the
   2684  * returned socket; however, if MHD is run using threads (anything but
   2685  * external select mode), it must not be closed until AFTER
   2686  * #MHD_daemon_destroy() has been called (as it is theoretically possible
   2687  * that an existing thread is still using it).
   2688  *
   2689  * @param[in,out] daemon the daemon to stop accepting new connections for
   2690  * @return the old listen socket on success, #MHD_INVALID_SOCKET if
   2691  *         the daemon was already not listening anymore, or
   2692  *         was never started, or has no listen socket.
   2693  * @ingroup daemon
   2694  */
   2695 MHD_EXTERN_ MHD_Socket
   2696 MHD_daemon_quiesce (struct MHD_Daemon *daemon)
   2697 MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (1);
   2698 
   2699 
   2700 /**
   2701  * Shutdown and destroy an HTTP daemon.
   2702  *
   2703  * @param[in] daemon daemon to stop
   2704  * @ingroup daemon
   2705  */
   2706 MHD_EXTERN_ void
   2707 MHD_daemon_destroy (struct MHD_Daemon *daemon)
   2708 MHD_FN_PAR_NONNULL_ALL_;
   2709 
   2710 /* ******************* External event loop ************************ */
   2711 
   2712 /**
   2713  * @defgroup event External network events processing
   2714  */
   2715 
   2716 /**
   2717  * The network status of the socket.
   2718  * When set by MHD (by #MHD_SocketRegistrationUpdateCallback or
   2719  * similar) it indicates a request to watch for specific socket state:
   2720  * watch for readiness for receiving the data, watch for readiness for sending
   2721  * the data and/or watch for exception state of the socket.
   2722  * When set by application (and provided for #MHD_daemon_event_update() and
   2723  * similar) it must indicate the actual status of the socket.
   2724  *
   2725  * Any actual state is a bitwise OR combination of #MHD_FD_STATE_RECV,
   2726  * #MHD_FD_STATE_SEND, #MHD_FD_STATE_EXCEPT.
   2727  * @ingroup event
   2728  */
   2729 enum MHD_FIXED_ENUM_ MHD_FdState
   2730 {
   2731   /**
   2732    * The socket is not ready for receiving or sending and
   2733    * does not have any exceptional state.
   2734    * The state never set by MHD, except de-registration of the sockets
   2735    * in a #MHD_SocketRegistrationUpdateCallback.
   2736    */
   2737   MHD_FD_STATE_NONE = 0
   2738   ,
   2739   /* ** Three bit-flags ** */
   2740 
   2741   /**
   2742    * Indicates that socket should be watched for incoming data
   2743    * (when set by #MHD_SocketRegistrationUpdateCallback)
   2744    * / socket has incoming data ready to read (when used for
   2745    * #MHD_daemon_event_update())
   2746    */
   2747   MHD_FD_STATE_RECV = 1 << 0
   2748   ,
   2749   /**
   2750    * Indicates that socket should be watched for availability for sending
   2751    * (when set by #MHD_SocketRegistrationUpdateCallback)
   2752    * / socket has ability to send data (when used for
   2753    * #MHD_daemon_event_update())
   2754    */
   2755   MHD_FD_STATE_SEND = 1 << 1
   2756   ,
   2757   /**
   2758    * Indicates that socket should be watched for disconnect, out-of-band
   2759    * data available or high priority data available (when set by
   2760    * #MHD_SocketRegistrationUpdateCallback)
   2761    * / socket has been disconnected, has out-of-band data available or
   2762    * has high priority data available (when used for
   2763    * #MHD_daemon_event_update()). This status must not include "remote
   2764    * peer shut down writing" status.
   2765    * Note: #MHD_SocketRegistrationUpdateCallback() always set it as exceptions
   2766    * must be always watched.
   2767    */
   2768   MHD_FD_STATE_EXCEPT = 1 << 2
   2769   ,
   2770 
   2771   /* The rest of the list is a bit-wise combination of three main
   2772    * states. Application may use three main states directly as
   2773    * a bit-mask instead of using of the following values
   2774    */
   2775 
   2776   /**
   2777    * Combination of #MHD_FD_STATE_RECV and #MHD_FD_STATE_SEND states.
   2778    */
   2779   MHD_FD_STATE_RECV_SEND = MHD_FD_STATE_RECV | MHD_FD_STATE_SEND
   2780   ,
   2781   /**
   2782    * Combination of #MHD_FD_STATE_RECV and #MHD_FD_STATE_EXCEPT states.
   2783    */
   2784   MHD_FD_STATE_RECV_EXCEPT = MHD_FD_STATE_RECV | MHD_FD_STATE_EXCEPT
   2785   ,
   2786   /**
   2787    * Combination of #MHD_FD_STATE_RECV and #MHD_FD_STATE_EXCEPT states.
   2788    */
   2789   MHD_FD_STATE_SEND_EXCEPT = MHD_FD_STATE_RECV | MHD_FD_STATE_EXCEPT
   2790   ,
   2791   /**
   2792    * Combination of #MHD_FD_STATE_RECV, #MHD_FD_STATE_SEND and
   2793    * #MHD_FD_STATE_EXCEPT states.
   2794    */
   2795   MHD_FD_STATE_RECV_SEND_EXCEPT = \
   2796     MHD_FD_STATE_RECV | MHD_FD_STATE_SEND | MHD_FD_STATE_EXCEPT
   2797 };
   2798 
   2799 /**
   2800  * Checks whether specific @a state is enabled/set in the @a var
   2801  */
   2802 #define MHD_FD_STATE_IS_SET(var, state)              \
   2803         (MHD_FD_STATE_NONE !=                        \
   2804          ((enum MHD_FdState) (((unsigned int) (var)) \
   2805                               & ((unsigned int) (state)))))
   2806 
   2807 /**
   2808  * Checks whether RECV is enabled/set in the @a var
   2809  */
   2810 #define MHD_FD_STATE_IS_SET_RECV(var) \
   2811         MHD_FD_STATE_IS_SET ((var),MHD_FD_STATE_RECV)
   2812 /**
   2813  * Checks whether SEND is enabled/set in the @a var
   2814  */
   2815 #define MHD_FD_STATE_IS_SET_SEND(var) \
   2816         MHD_FD_STATE_IS_SET ((var),MHD_FD_STATE_SEND)
   2817 /**
   2818  * Checks whether EXCEPT is enabled/set in the @a var
   2819  */
   2820 #define MHD_FD_STATE_IS_SET_EXCEPT(var) \
   2821         MHD_FD_STATE_IS_SET ((var),MHD_FD_STATE_EXCEPT)
   2822 
   2823 
   2824 /**
   2825  * Set/enable specific @a state in the @a var
   2826  */
   2827 #define MHD_FD_STATE_SET(var, state) \
   2828         ((var) =                     \
   2829            (enum MHD_FdState) (((unsigned int) var) | ((unsigned int) state)))
   2830 /**
   2831  * Set/enable RECV state in the @a var
   2832  */
   2833 #define MHD_FD_STATE_SET_RECV(var) MHD_FD_STATE_SET ((var),MHD_FD_STATE_RECV)
   2834 /**
   2835  * Set/enable SEND state in the @a var
   2836  */
   2837 #define MHD_FD_STATE_SET_SEND(var) MHD_FD_STATE_SET ((var),MHD_FD_STATE_SEND)
   2838 /**
   2839  * Set/enable EXCEPT state in the @a var
   2840  */
   2841 #define MHD_FD_STATE_SET_EXCEPT(var) \
   2842         MHD_FD_STATE_SET ((var),MHD_FD_STATE_EXCEPT)
   2843 
   2844 /**
   2845  * Clear/disable specific @a state in the @a var
   2846  */
   2847 #define MHD_FD_STATE_CLEAR(var, state) \
   2848         ( (var) =                      \
   2849             (enum MHD_FdState)         \
   2850             (((unsigned int) var)      \
   2851              & ((enum MHD_FdState) (~((unsigned int) state)))) \
   2852         )
   2853 /**
   2854  * Clear/disable RECV state in the @a var
   2855  */
   2856 #define MHD_FD_STATE_CLEAR_RECV(var) \
   2857         MHD_FD_STATE_CLEAR ((var),MHD_FD_STATE_RECV)
   2858 /**
   2859  * Clear/disable SEND state in the @a var
   2860  */
   2861 #define MHD_FD_STATE_CLEAR_SEND(var) \
   2862         MHD_FD_STATE_CLEAR ((var),MHD_FD_STATE_SEND)
   2863 /**
   2864  * Clear/disable EXCEPT state in the @a var
   2865  */
   2866 #define MHD_FD_STATE_CLEAR_EXCEPT(var) \
   2867         MHD_FD_STATE_CLEAR ((var),MHD_FD_STATE_EXCEPT)
   2868 
   2869 
   2870 /**
   2871  * The context data to be used for updates of the socket state
   2872  */
   2873 struct MHD_EventUpdateContext;
   2874 
   2875 
   2876 /* Define MHD_APP_SOCKET_CNTX_TYPE to the socket context type before
   2877  * including this header.
   2878  * This is optional, but improves the types safety.
   2879  * For example:
   2880  * #define MHD_APP_SOCKET_CNTX_TYPE struct my_structure
   2881  */
   2882 #ifndef MHD_APP_SOCKET_CNTX_TYPE
   2883 #  define MHD_APP_SOCKET_CNTX_TYPE void
   2884 #endif
   2885 
   2886 /**
   2887  * The callback for registration/de-registration of the sockets to watch.
   2888  *
   2889  * This callback must not call #MHD_daemon_destroy(), #MHD_daemon_quiesce(),
   2890  * #MHD_daemon_add_connection().
   2891  *
   2892  * @param cls the closure
   2893  * @param fd the socket to watch
   2894  * @param watch_for the states of the @a fd to watch, if set to
   2895  *                  #MHD_FD_STATE_NONE the socket must be de-registred
   2896  * @param app_cntx_old the old application defined context for the socket,
   2897  *                     NULL if @a fd socket was not registered before
   2898  * @param ecb_cntx the context handle to be used
   2899  *                 with #MHD_daemon_event_update()
   2900  * @return must be NULL for the removed (de-registred) sockets,
   2901  *         for new and updated sockets: NULL in case of error (the connection
   2902  *         will be aborted or daemon failed to start if FD does not belong to
   2903  *         connection)
   2904  *         or the new socket context (opaque for MHD, must be non-NULL)
   2905  * @sa #MHD_D_OPTION_REREGISTER_ALL
   2906  * @ingroup event
   2907  */
   2908 typedef MHD_APP_SOCKET_CNTX_TYPE *
   2909 (MHD_FN_PAR_NONNULL_ (5)
   2910  *MHD_SocketRegistrationUpdateCallback)(
   2911   void *cls,
   2912   MHD_Socket fd,
   2913   enum MHD_FdState watch_for,
   2914   MHD_APP_SOCKET_CNTX_TYPE *app_cntx_old,
   2915   struct MHD_EventUpdateContext *ecb_cntx);
   2916 
   2917 
   2918 /**
   2919  * Update the sockets state.
   2920  * Must be called for every socket that got state updated.
   2921  * For #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL() mode
   2922  * this function must be called for each socket between any two calls of
   2923  * #MHD_daemon_process_reg_events() function.
   2924  * Available only for daemons started in
   2925  * #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL or
   2926  * #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_EDGE modes.
   2927  * @param daemon the daemon handle
   2928  * @param ecb_cntx the context handle provided
   2929  *                 for #MHD_SocketRegistrationUpdateCallback
   2930  * @param fd_current_state the current state of the socket
   2931  * @ingroup event
   2932  */
   2933 MHD_EXTERN_ void
   2934 MHD_daemon_event_update (
   2935   struct MHD_Daemon *MHD_RESTRICT daemon,
   2936   struct MHD_EventUpdateContext *MHD_RESTRICT ecb_cntx,
   2937   enum MHD_FdState fd_current_state)
   2938 MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (2);
   2939 
   2940 
   2941 /**
   2942  * Perform all daemon activities based on FDs events provided earlier by
   2943  * application via #MHD_daemon_event_update().
   2944  *
   2945  * This function accepts new connections (if any), performs HTTP communications
   2946  * on all active connections, closes connections as needed and performs FDs
   2947  * registration updates by calling #MHD_SocketRegistrationUpdateCallback
   2948  * callback for every socket that needs to be added/updated/removed.
   2949  *
   2950  * Available only for daemons started in #MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL or
   2951  * #MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE modes.
   2952  *
   2953  * When used in #MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL mode, application must
   2954  * provide all updates by calling #MHD_daemon_event_update() for every
   2955  * registered FD between any two calls of this function.
   2956  *
   2957  * @param daemon the daemon handle
   2958  * @param[out] next_max_wait_milsec the optional pointer to receive the
   2959                                     next maximum wait time in milliseconds
   2960                                     to be used for the sockets polling
   2961                                     function, can be NULL
   2962  * @return #MHD_SC_OK on success,
   2963  *         error code otherwise
   2964  * @sa #MHD_D_OPTION_REREGISTER_ALL
   2965  * @ingroup event
   2966  */
   2967 MHD_EXTERN_ enum MHD_StatusCode
   2968 MHD_daemon_process_reg_events (
   2969   struct MHD_Daemon *MHD_RESTRICT daemon,
   2970   uint_fast64_t *MHD_RESTRICT next_max_wait_milsec)
   2971 MHD_FN_PAR_NONNULL_ (1);
   2972 
   2973 /* ********************* daemon options ************** */
   2974 
   2975 
   2976 /**
   2977  * Which threading and polling mode should be used by MHD?
   2978  */
   2979 enum MHD_FIXED_ENUM_APP_SET_ MHD_WorkMode
   2980 {
   2981   /**
   2982    * Work mode with no internal threads.
   2983    * The application periodically calls #MHD_daemon_process_blocking(), where
   2984    * MHD internally checks all sockets automatically.
   2985    * This is the default mode.
   2986    * Use helper macro #MHD_D_OPTION_WM_EXTERNAL_PERIODIC() to enable
   2987    * this mode.
   2988    */
   2989   MHD_WM_EXTERNAL_PERIODIC = 0
   2990   ,
   2991   /**
   2992    * Work mode with an external event loop with level triggers.
   2993    * MHD provides registration of all FDs to be monitored by using
   2994    * #MHD_SocketRegistrationUpdateCallback, application performs level triggered
   2995    * FDs polling (like select() or poll()), calls function
   2996    * #MHD_daemon_event_update() for every registered FD and then calls main
   2997    * function MHD_daemon_process_reg_events() to process the data.
   2998    * Use helper macro #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL() to enable
   2999    * this mode.
   3000    * @sa #MHD_D_OPTION_REREGISTER_ALL
   3001    */
   3002   MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL = 8
   3003   ,
   3004   /**
   3005    * Work mode with an external event loop with edge triggers.
   3006    * MHD provides registration of all FDs to be monitored by using
   3007    * #MHD_SocketRegistrationUpdateCallback, application performs edge triggered
   3008    * sockets polling (like epoll with EPOLLET), calls function
   3009    * #MHD_daemon_event_update() for FDs with updated states and then calls main
   3010    * function MHD_daemon_process_reg_events() to process the data.
   3011    * Use helper macro #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_EDGE() to enable
   3012    * this mode.
   3013    * @sa #MHD_D_OPTION_REREGISTER_ALL
   3014    */
   3015   MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE = 9
   3016   ,
   3017   /**
   3018    * Work mode with no internal threads and aggregate watch FD.
   3019    * Application uses #MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD to get single FD
   3020    * that gets triggered by any MHD event.
   3021    * This FD can be watched as an aggregate indicator for all MHD events.
   3022    * This mode is available only on selected platforms (currently
   3023    * GNU/Linux and OpenIndiana only), see #MHD_LIB_INFO_FIXED_HAS_AGGREGATE_FD.
   3024    * When the FD is triggered, #MHD_daemon_process_nonblocking() should
   3025    * be called.
   3026    * Use helper macro #MHD_D_OPTION_WM_EXTERNAL_SINGLE_FD_WATCH() to enable
   3027    * this mode.
   3028    */
   3029   MHD_WM_EXTERNAL_SINGLE_FD_WATCH = 16
   3030   ,
   3031   /**
   3032    * Work mode with one or more worker threads.
   3033    * If specified number of threads is one, then daemon starts with single
   3034    * worker thread that handles all connections.
   3035    * If number of threads is larger than one, then that number of worker
   3036    * threads, and handling of connection is distributed among the workers.
   3037    * Use helper macro #MHD_D_OPTION_WM_WORKER_THREADS() to enable
   3038    * this mode.
   3039    */
   3040   MHD_WM_WORKER_THREADS = 24
   3041   ,
   3042   /**
   3043    * Work mode with one internal thread for listening and additional threads
   3044    * per every connection.  Use this if handling requests is CPU-intensive or
   3045    * blocking, your application is thread-safe and you have plenty of
   3046    * memory (per connection).
   3047    * Use helper macro #MHD_D_OPTION_WM_THREAD_PER_CONNECTION() to enable
   3048    * this mode.
   3049    */
   3050   MHD_WM_THREAD_PER_CONNECTION = 32
   3051 };
   3052 
   3053 /**
   3054  * Work mode parameters for #MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL and
   3055  * #MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE modes
   3056  */
   3057 struct MHD_WorkModeExternalEventLoopCBParam
   3058 {
   3059   /**
   3060    * Socket registration callback
   3061    */
   3062   MHD_SocketRegistrationUpdateCallback reg_cb;
   3063   /**
   3064    * Closure for the @a reg_cb
   3065    */
   3066   void *reg_cb_cls;
   3067 };
   3068 
   3069 /**
   3070  * MHD work mode parameters
   3071  */
   3072 union MHD_WorkModeParam
   3073 {
   3074   /**
   3075    * Work mode parameters for #MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL and
   3076    * #MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE modes
   3077    */
   3078   struct MHD_WorkModeExternalEventLoopCBParam v_external_event_loop_cb;
   3079   /**
   3080    * Number of worker threads for #MHD_WM_WORKER_THREADS.
   3081    * If set to one, then daemon starts with single worker thread that process
   3082    * all connections.
   3083    * If set to value larger than one, then that number of worker threads
   3084    * and distributed handling of requests among the workers.
   3085    * Zero is treated as one.
   3086    */
   3087   unsigned int num_worker_threads;
   3088 };
   3089 
   3090 /**
   3091  * Parameter for #MHD_D_O_WORK_MODE().
   3092  * Not recommended to be used directly, better use macro/functions to create it:
   3093  * #MHD_WM_OPTION_EXTERNAL_PERIODIC(),
   3094  * #MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(),
   3095  * #MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(),
   3096  * #MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH(),
   3097  * #MHD_WM_OPTION_WORKER_THREADS(),
   3098  * #MHD_WM_OPTION_THREAD_PER_CONNECTION()
   3099  */
   3100 struct MHD_WorkModeWithParam
   3101 {
   3102   /**
   3103    * The work mode for MHD
   3104    */
   3105   enum MHD_WorkMode mode;
   3106   /**
   3107    * The parameters used for specified work mode
   3108    */
   3109   union MHD_WorkModeParam params;
   3110 };
   3111 
   3112 
   3113 #if defined(MHD_USE_COMPOUND_LITERALS) && defined(MHD_USE_DESIG_NEST_INIT)
   3114 /**
   3115  * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
   3116  * no internal threads.
   3117  * The application periodically calls #MHD_daemon_process_blocking(), where
   3118  * MHD internally checks all sockets automatically.
   3119  * This is the default mode.
   3120  * @return the object of struct MHD_WorkModeWithParam with requested values
   3121  */
   3122 #  define MHD_WM_OPTION_EXTERNAL_PERIODIC()      \
   3123           MHD_NOWARN_COMPOUND_LITERALS_          \
   3124             (const struct MHD_WorkModeWithParam) \
   3125           {                                      \
   3126             .mode = (MHD_WM_EXTERNAL_PERIODIC)   \
   3127           }                                      \
   3128           MHD_RESTORE_WARN_COMPOUND_LITERALS_
   3129 
   3130 /**
   3131  * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
   3132  * an external event loop with level triggers.
   3133  * Application uses #MHD_SocketRegistrationUpdateCallback, level triggered
   3134  * sockets polling (like select() or poll()) and #MHD_daemon_event_update().
   3135  * @param cb_val the callback for sockets registration
   3136  * @param cb_cls_val the closure for the @a cv_val callback
   3137  * @return the object of struct MHD_WorkModeWithParam with requested values
   3138  */
   3139 #  define MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(cb_val, cb_cls_val) \
   3140           MHD_NOWARN_COMPOUND_LITERALS_                                  \
   3141             (const struct MHD_WorkModeWithParam)                         \
   3142           {                                                              \
   3143             .mode = (MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL),               \
   3144             .params.v_external_event_loop_cb.reg_cb = (cb_val),          \
   3145             .params.v_external_event_loop_cb.reg_cb_cls = (cb_cls_val)   \
   3146           }                                                              \
   3147           MHD_RESTORE_WARN_COMPOUND_LITERALS_
   3148 
   3149 /**
   3150  * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
   3151  * an external event loop with edge triggers.
   3152  * Application uses #MHD_SocketRegistrationUpdateCallback, edge triggered
   3153  * sockets polling (like epoll with EPOLLET) and #MHD_daemon_event_update().
   3154  * @param cb_val the callback for sockets registration
   3155  * @param cb_cls_val the closure for the @a cv_val callback
   3156  * @return the object of struct MHD_WorkModeWithParam with requested values
   3157  */
   3158 #  define MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(cb_val, cb_cls_val) \
   3159           MHD_NOWARN_COMPOUND_LITERALS_                                 \
   3160             (const struct MHD_WorkModeWithParam)                        \
   3161           {                                                             \
   3162             .mode = (MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE),               \
   3163             .params.v_external_event_loop_cb.reg_cb = (cb_val),         \
   3164             .params.v_external_event_loop_cb.reg_cb_cls = (cb_cls_val)  \
   3165           }                                                             \
   3166           MHD_RESTORE_WARN_COMPOUND_LITERALS_
   3167 
   3168 /**
   3169  * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
   3170  * no internal threads and aggregate watch FD.
   3171  * Application uses #MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD to get single FD
   3172  * that gets triggered by any MHD event.
   3173  * This FD can be watched as an aggregate indicator for all MHD events.
   3174  * This mode is available only on selected platforms (currently
   3175  * GNU/Linux only), see #MHD_LIB_INFO_FIXED_HAS_AGGREGATE_FD.
   3176  * When the FD is triggered, #MHD_daemon_process_nonblocking() should
   3177  * be called.
   3178  * @return the object of struct MHD_WorkModeWithParam with requested values
   3179  */
   3180 #  define MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()    \
   3181           MHD_NOWARN_COMPOUND_LITERALS_               \
   3182             (const struct MHD_WorkModeWithParam)      \
   3183           {                                           \
   3184             .mode = (MHD_WM_EXTERNAL_SINGLE_FD_WATCH) \
   3185           }                                           \
   3186           MHD_RESTORE_WARN_COMPOUND_LITERALS_
   3187 
   3188 /**
   3189  * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
   3190  * one or more worker threads.
   3191  * If number of threads is one, then daemon starts with single worker thread
   3192  * that handles all connections.
   3193  * If number of threads is larger than one, then that number of worker threads,
   3194  * and handling of connection is distributed among the workers.
   3195  * @param num_workers the number of worker threads, zero is treated as one
   3196  * @return the object of struct MHD_WorkModeWithParam with requested values
   3197  */
   3198 #  define MHD_WM_OPTION_WORKER_THREADS(num_workers)    \
   3199           MHD_NOWARN_COMPOUND_LITERALS_                \
   3200             (const struct MHD_WorkModeWithParam)       \
   3201           {                                            \
   3202             .mode = (MHD_WM_WORKER_THREADS),           \
   3203             .params.num_worker_threads = (num_workers) \
   3204           }                                            \
   3205           MHD_RESTORE_WARN_COMPOUND_LITERALS_
   3206 
   3207 /**
   3208  * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
   3209  * one internal thread for listening and additional threads per every
   3210  * connection.  Use this if handling requests is CPU-intensive or blocking,
   3211  * your application is thread-safe and you have plenty of memory (per
   3212  * connection).
   3213  * @return the object of struct MHD_WorkModeWithParam with requested values
   3214  */
   3215 #  define MHD_WM_OPTION_THREAD_PER_CONNECTION()    \
   3216           MHD_NOWARN_COMPOUND_LITERALS_            \
   3217             (const struct MHD_WorkModeWithParam)   \
   3218           {                                        \
   3219             .mode = (MHD_WM_THREAD_PER_CONNECTION) \
   3220           }                                        \
   3221           MHD_RESTORE_WARN_COMPOUND_LITERALS_
   3222 
   3223 #else  /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */
   3224 MHD_NOWARN_UNUSED_FUNC_
   3225 
   3226 /**
   3227  * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
   3228  * no internal threads.
   3229  * The application periodically calls #MHD_daemon_process_blocking(), where
   3230  * MHD internally checks all sockets automatically.
   3231  * This is the default mode.
   3232  * @return the object of struct MHD_WorkModeWithParam with requested values
   3233  */
   3234 static MHD_INLINE struct MHD_WorkModeWithParam
   3235 MHD_WM_OPTION_EXTERNAL_PERIODIC (void)
   3236 {
   3237   struct MHD_WorkModeWithParam wm_val;
   3238 
   3239   wm_val.mode = MHD_WM_EXTERNAL_PERIODIC;
   3240 
   3241   return wm_val;
   3242 }
   3243 
   3244 
   3245 /**
   3246  * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
   3247  * an external event loop with level triggers.
   3248  * Application uses #MHD_SocketRegistrationUpdateCallback, level triggered
   3249  * sockets polling (like select() or poll()) and #MHD_daemon_event_update().
   3250  * @param cb_val the callback for sockets registration
   3251  * @param cb_cls_val the closure for the @a cv_val callback
   3252  * @return the object of struct MHD_WorkModeWithParam with requested values
   3253  */
   3254 static MHD_INLINE struct MHD_WorkModeWithParam
   3255 MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL (
   3256   MHD_SocketRegistrationUpdateCallback cb_val,
   3257   void *cb_cls_val)
   3258 {
   3259   struct MHD_WorkModeWithParam wm_val;
   3260 
   3261   wm_val.mode = MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL;
   3262   wm_val.params.v_external_event_loop_cb.reg_cb = cb_val;
   3263   wm_val.params.v_external_event_loop_cb.reg_cb_cls = cb_cls_val;
   3264 
   3265   return wm_val;
   3266 }
   3267 
   3268 
   3269 /**
   3270  * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
   3271  * an external event loop with edge triggers.
   3272  * Application uses #MHD_SocketRegistrationUpdateCallback, edge triggered
   3273  * sockets polling (like epoll with EPOLLET) and #MHD_daemon_event_update().
   3274  * @param cb_val the callback for sockets registration
   3275  * @param cb_cls_val the closure for the @a cv_val callback
   3276  * @return the object of struct MHD_WorkModeWithParam with requested values
   3277  */
   3278 static MHD_INLINE struct MHD_WorkModeWithParam
   3279 MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE (
   3280   MHD_SocketRegistrationUpdateCallback cb_val,
   3281   void *cb_cls_val)
   3282 {
   3283   struct MHD_WorkModeWithParam wm_val;
   3284 
   3285   wm_val.mode = MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE;
   3286   wm_val.params.v_external_event_loop_cb.reg_cb = cb_val;
   3287   wm_val.params.v_external_event_loop_cb.reg_cb_cls = cb_cls_val;
   3288 
   3289   return wm_val;
   3290 }
   3291 
   3292 
   3293 /**
   3294  * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
   3295  * no internal threads and aggregate watch FD.
   3296  * Application uses #MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD to get single FD
   3297  * that gets triggered by any MHD event.
   3298  * This FD can be watched as an aggregate indicator for all MHD events.
   3299  * This mode is available only on selected platforms (currently
   3300  * GNU/Linux only), see #MHD_LIB_INFO_FIXED_HAS_AGGREGATE_FD.
   3301  * When the FD is triggered, #MHD_daemon_process_nonblocking() should
   3302  * be called.
   3303  * @return the object of struct MHD_WorkModeWithParam with requested values
   3304  */
   3305 static MHD_INLINE struct MHD_WorkModeWithParam
   3306 MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH (void)
   3307 {
   3308   struct MHD_WorkModeWithParam wm_val;
   3309 
   3310   wm_val.mode = MHD_WM_EXTERNAL_SINGLE_FD_WATCH;
   3311 
   3312   return wm_val;
   3313 }
   3314 
   3315 
   3316 /**
   3317  * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
   3318  * one or more worker threads.
   3319  * If number of threads is one, then daemon starts with single worker thread
   3320  * that handles all connections.
   3321  * If number of threads is larger than one, then that number of worker threads,
   3322  * and handling of connection is distributed among the workers.
   3323  * @param num_workers the number of worker threads, zero is treated as one
   3324  * @return the object of struct MHD_WorkModeWithParam with requested values
   3325  */
   3326 static MHD_INLINE struct MHD_WorkModeWithParam
   3327 MHD_WM_OPTION_WORKER_THREADS (unsigned int num_workers)
   3328 {
   3329   struct MHD_WorkModeWithParam wm_val;
   3330 
   3331   wm_val.mode = MHD_WM_WORKER_THREADS;
   3332   wm_val.params.num_worker_threads = num_workers;
   3333 
   3334   return wm_val;
   3335 }
   3336 
   3337 
   3338 /**
   3339  * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
   3340  * one internal thread for listening and additional threads per every
   3341  * connection.  Use this if handling requests is CPU-intensive or blocking,
   3342  * your application is thread-safe and you have plenty of memory (per
   3343  * connection).
   3344  * @return the object of struct MHD_WorkModeWithParam with requested values
   3345  */
   3346 static MHD_INLINE struct MHD_WorkModeWithParam
   3347 MHD_WM_OPTION_THREAD_PER_CONNECTION (void)
   3348 {
   3349   struct MHD_WorkModeWithParam wm_val;
   3350 
   3351   wm_val.mode = MHD_WM_THREAD_PER_CONNECTION;
   3352 
   3353   return wm_val;
   3354 }
   3355 
   3356 
   3357 MHD_RESTORE_WARN_UNUSED_FUNC_
   3358 #endif /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */
   3359 
   3360 /**
   3361  * @defgroup logging Log events and control
   3362  */
   3363 
   3364 
   3365 /**
   3366  * Type of a callback function used for logging by MHD.
   3367  *
   3368  * @param cls closure
   3369  * @param sc status code of the event
   3370  * @param fm format string (`printf()`-style)
   3371  * @param ap arguments to @a fm
   3372  * @ingroup logging
   3373  */
   3374 typedef void
   3375 (MHD_FN_PAR_NONNULL_ (3)
   3376  MHD_FN_PAR_CSTR_ (3)
   3377  *MHD_LoggingCallback)(void *cls,
   3378                        enum MHD_StatusCode sc,
   3379                        const char *fm,
   3380                        va_list ap);
   3381 
   3382 /**
   3383  * Parameter for listen socket binding type
   3384  */
   3385 enum MHD_FIXED_ENUM_APP_SET_ MHD_DaemonOptionBindType
   3386 {
   3387   /**
   3388    * The listen socket bind to the networks address with sharing the address.
   3389    * Several sockets can bind to the same address.
   3390    */
   3391   MHD_D_OPTION_BIND_TYPE_SHARED = -1
   3392   ,
   3393   /**
   3394    * The listen socket bind to the networks address without sharing the address,
   3395    * except allowing binding to port/address which has TIME_WAIT state (the
   3396    * state after closing connection).
   3397    * On some platforms it may also allow to bind to specific address if other
   3398    * socket already bond to the same port of wildcard address (or bind to
   3399    * wildcard address when other socket already bond to specific address
   3400    * with the same port).
   3401    * Typically achieved by enabling 'SO_REUSEADDR' socket option.
   3402    * Default.
   3403    */
   3404   MHD_D_OPTION_BIND_TYPE_NOT_SHARED = 0
   3405   ,
   3406   /**
   3407    * The listen socket bind to the networks address without sharing the address.
   3408    * The daemon way fail to start when any sockets still in "TIME_WAIT" state
   3409    * on the same port, which effectively prevents quick restart of the daemon
   3410    * on the same port.
   3411    * On W32 systems it works like #MHD_D_OPTION_BIND_TYPE_NOT_SHARED due to
   3412    * the OS limitations.
   3413    */
   3414   MHD_D_OPTION_BIND_TYPE_NOT_SHARED_STRICTER = 1
   3415   ,
   3416   /**
   3417    * The list socket bind to the networks address in explicit exclusive mode.
   3418    * Works as #MHD_D_OPTION_BIND_TYPE_NOT_SHARED_STRICTER on platforms without
   3419    * support for the explicit exclusive socket use.
   3420    */
   3421   MHD_D_OPTION_BIND_TYPE_EXCLUSIVE = 2
   3422 };
   3423 
   3424 
   3425 /**
   3426  * Possible levels of enforcement for TCP_FASTOPEN.
   3427  */
   3428 enum MHD_FIXED_ENUM_APP_SET_ MHD_TCPFastOpenType
   3429 {
   3430   /**
   3431    * Disable use of TCP_FASTOPEN.
   3432    */
   3433   MHD_FOM_DISABLE = -1
   3434   ,
   3435   /**
   3436    * Enable TCP_FASTOPEN where supported.
   3437    * On GNU/Linux it works with a kernel >= 3.6.
   3438    * This is the default.
   3439    */
   3440   MHD_FOM_AUTO = 0
   3441   ,
   3442   /**
   3443    * Require TCP_FASTOPEN.
   3444    * Also causes #MHD_daemon_start() to fail if TCP_FASTOPEN cannot be enabled.
   3445    */
   3446   MHD_FOM_REQUIRE = 1
   3447 };
   3448 
   3449 
   3450 /**
   3451  * Address family to be used by MHD.
   3452  */
   3453 enum MHD_FIXED_ENUM_APP_SET_ MHD_AddressFamily
   3454 {
   3455   /**
   3456    * Option not given, do not listen at all
   3457    * (unless listen socket or address specified by
   3458    * other means).
   3459    */
   3460   MHD_AF_NONE = 0
   3461   ,
   3462   /**
   3463    * Pick "best" available method automatically.
   3464    */
   3465   MHD_AF_AUTO = 1
   3466   ,
   3467   /**
   3468    * Use IPv4 only.
   3469    */
   3470   MHD_AF_INET4 = 2
   3471   ,
   3472   /**
   3473    * Use IPv6 only.
   3474    */
   3475   MHD_AF_INET6 = 3
   3476   ,
   3477   /**
   3478    * Use dual stack (IPv4 and IPv6 on the same socket).
   3479    */
   3480   MHD_AF_DUAL = 4
   3481   ,
   3482   /**
   3483    * Use dual stack (IPv4 and IPv6 on the same socket),
   3484    * fallback to pure IPv6 if dual stack is not possible.
   3485    */
   3486   MHD_AF_DUAL_v4_OPTIONAL = 5
   3487   ,
   3488   /**
   3489    * Use dual stack (IPv4 and IPv6 on the same socket),
   3490    * fallback to pure IPv4 if dual stack is not possible.
   3491    */
   3492   MHD_AF_DUAL_v6_OPTIONAL = 6
   3493 
   3494 };
   3495 
   3496 
   3497 /**
   3498  * Sockets polling internal syscalls used by MHD.
   3499  */
   3500 enum MHD_FIXED_ENUM_APP_SET_ MHD_SockPollSyscall
   3501 {
   3502   /**
   3503    * Automatic selection of best-available method. This is also the
   3504    * default.
   3505    */
   3506   MHD_SPS_AUTO = 0
   3507   ,
   3508   /**
   3509    * Use select().
   3510    */
   3511   MHD_SPS_SELECT = 1
   3512   ,
   3513   /**
   3514    * Use poll().
   3515    */
   3516   MHD_SPS_POLL = 2
   3517   ,
   3518   /**
   3519    * Use epoll.
   3520    */
   3521   MHD_SPS_EPOLL = 3
   3522   ,
   3523   /**
   3524    * Use kqueue.
   3525    */
   3526   MHD_SPS_KQUEUE = 4
   3527 };
   3528 
   3529 
   3530 /**
   3531  * Protocol strictness levels enforced by MHD on clients.
   3532  * Each level applies different parsing settings for HTTP headers and other
   3533  * protocol elements.
   3534  */
   3535 enum MHD_FIXED_ENUM_APP_SET_ MHD_ProtocolStrictLevel
   3536 {
   3537 
   3538   /* * Basic levels * */
   3539   /**
   3540    * A sane default level of protocol enforcement for production use.
   3541    * Provides a balance between enhanced security and broader compatibility,
   3542    * as permitted by RFCs for HTTP servers.
   3543    */
   3544   MHD_PSL_DEFAULT = 0
   3545   ,
   3546   /**
   3547    * Apply stricter protocol interpretation while remaining within
   3548    * RFC-defined limits for HTTP servers.
   3549    *
   3550    * At this level (and stricter), using a bare LF instead of CRLF is forbidden,
   3551    * and requests that include both a "Transfer-Encoding:" and
   3552    * a "Content-Length:" headers are rejected.
   3553    *
   3554    * Suitable for public servers.
   3555    */
   3556   MHD_PSL_STRICT = 1
   3557   ,
   3558   /**
   3559    * Be more permissive in interpreting the protocol, while still
   3560    * operating within the RFC-defined limits for HTTP servers.
   3561    */
   3562   MHD_PSL_PERMISSIVE = -1
   3563   ,
   3564   /* * Special levels * */
   3565   /**
   3566    * A stricter protocol interpretation than what is allowed by RFCs for HTTP
   3567    * servers. However, it should remain fully compatible with clients correctly
   3568    * following all RFC "MUST" requirements for HTTP clients.
   3569    *
   3570    * For chunked encoding, this level (and more restrictive ones) forbids
   3571    * whitespace in chunk extensions.
   3572    * For cookie parsing, this level (and more restrictive ones) rejects
   3573    * the entire cookie if even a single value within it is incorrectly encoded.
   3574    *
   3575    * Recommended for testing clients against MHD. Can also be used for
   3576    * security-centric applications, though doing so slightly violates
   3577    * relevant RFC requirements for HTTP servers.
   3578    */
   3579   MHD_PSL_VERY_STRICT = 2
   3580   ,
   3581   /**
   3582    * The strictest interpretation of the HTTP protocol, even stricter than
   3583    * allowed by RFCs for HTTP servers.
   3584    * However, it should remain fully compatible with clients complying with both
   3585    * RFC "SHOULD" and "MUST" requirements for HTTP clients.
   3586    *
   3587    * This level can be used for testing clients against MHD.
   3588    * It is not recommended for public services, as it may reject legitimate
   3589    * clients that do not follow RFC "SHOULD" requirements.
   3590    */
   3591   MHD_PSL_EXTRA_STRICT = 3
   3592   ,
   3593   /**
   3594    * A more relaxed protocol interpretation that violates some RFC "SHOULD"
   3595    * restrictions for HTTP servers.
   3596    * For cookie parsing, this level (and more permissive levels) allows
   3597    * whitespace in cookie values.
   3598    *
   3599    * This level may be used in isolated environments.
   3600    */
   3601   MHD_PSL_VERY_PERMISSIVE = -2
   3602   ,
   3603   /**
   3604    * The most flexible protocol interpretation, going beyond RFC "MUST"
   3605    * requirements for HTTP servers.
   3606    *
   3607    * This level allows HTTP/1.1 requests without a "Host:" header.
   3608    * For cookie parsing, whitespace is allowed before and after
   3609    * the '=' character.
   3610    *
   3611    * Not recommended unless absolutely necessary to communicate with clients
   3612    * that have severely broken HTTP implementations.
   3613    */
   3614   MHD_PSL_EXTRA_PERMISSIVE = -3
   3615 };
   3616 
   3617 /**
   3618  * The way Strict Level is enforced.
   3619  * MHD can be compiled with limited set of strictness levels.
   3620  * These values instructs MHD how to apply the request level.
   3621  */
   3622 enum MHD_FIXED_ENUM_APP_SET_ MHD_UseStictLevel
   3623 {
   3624   /**
   3625    * Use requested level if available or the nearest stricter
   3626    * level.
   3627    * Fail if only more permissive levels available.
   3628    * Recommended value.
   3629    */
   3630   MHD_USL_THIS_OR_STRICTER = 0
   3631   ,
   3632   /**
   3633    * Use requested level only.
   3634    * Fail if this level is not available.
   3635    */
   3636   MHD_USL_PRECISE = 1
   3637   ,
   3638   /**
   3639    * Use requested level if available or the nearest level (stricter
   3640    * or more permissive).
   3641    */
   3642   MHD_USL_NEAREST = 2
   3643 };
   3644 
   3645 
   3646 /**
   3647  * Connection memory buffer zeroing mode.
   3648  * Works as a hardening measure.
   3649  */
   3650 enum MHD_FIXED_ENUM_APP_SET_ MHD_ConnBufferZeroingMode
   3651 {
   3652   /**
   3653    * Do not perform zeroing of connection memory buffer.
   3654    * Default mode.
   3655    */
   3656   MHD_CONN_BUFFER_ZEROING_DISABLED = 0
   3657   ,
   3658   /**
   3659    * Perform connection memory buffer zeroing before processing request.
   3660    */
   3661   MHD_CONN_BUFFER_ZEROING_BASIC = 1
   3662   ,
   3663   /**
   3664    * Perform connection memory buffer zeroing before processing request and
   3665    * when reusing buffer memory areas during processing request.
   3666    */
   3667   MHD_CONN_BUFFER_ZEROING_HEAVY = 2
   3668 };
   3669 
   3670 
   3671 /* ********************** (d) TLS support ********************** */
   3672 
   3673 /**
   3674  * The TLS backend choice
   3675  */
   3676 enum MHD_FIXED_ENUM_APP_SET_ MHD_TlsBackend
   3677 {
   3678   /**
   3679    * Disable TLS, use plain TCP connections (default)
   3680    */
   3681   MHD_TLS_BACKEND_NONE = 0
   3682   ,
   3683   /**
   3684    * Use best available TLS backend.
   3685    */
   3686   MHD_TLS_BACKEND_ANY = 1
   3687   ,
   3688   /**
   3689    * Use GnuTLS as TLS backend.
   3690    */
   3691   MHD_TLS_BACKEND_GNUTLS = 2
   3692   ,
   3693   /**
   3694    * Use OpenSSL as TLS backend.
   3695    */
   3696   MHD_TLS_BACKEND_OPENSSL = 3
   3697   ,
   3698   /**
   3699    * Use MbedTLS as TLS backend.
   3700    */
   3701   MHD_TLS_BACKEND_MBEDTLS = 4
   3702 };
   3703 
   3704 /**
   3705  * Values for #MHD_D_O_DAUTH_NONCE_BIND_TYPE.
   3706  *
   3707  * These values can limit the scope of validity of MHD-generated nonces.
   3708  * Values can be combined with bitwise OR.
   3709  * Any value, except #MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_NONE, enforce function
   3710  * #MHD_digest_auth_check() (and similar functions) to check nonce by
   3711  * re-generating it again with the same parameters, which is CPU-intensive
   3712  * operation.
   3713  */
   3714 enum MHD_FIXED_FLAGS_ENUM_APP_SET_ MHD_DaemonOptionValueDAuthBindNonce
   3715 {
   3716   /**
   3717    * Generated nonces are valid for any request from any client until expired.
   3718    * This is default and recommended value.
   3719    * #MHD_digest_auth_check() (and similar functions) would check only whether
   3720    * the nonce value that is used by client has been generated by MHD and not
   3721    * expired yet.
   3722    * It is recommended because RFC 7616 allows clients to use the same nonce
   3723    * for any request in the same "protection space".
   3724    * When checking client's authorisation requests CPU is loaded less if this
   3725    * value is used.
   3726    * This mode gives MHD maximum flexibility for nonces generation and can
   3727    * prevent possible nonce collisions (and corresponding log warning messages)
   3728    * when clients' requests are intensive.
   3729    * This value cannot be biwise-OR combined with other values.
   3730    */
   3731   MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_NONE = 0
   3732   ,
   3733   /**
   3734    * Generated nonces are valid only for the same realm.
   3735    */
   3736   MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_REALM = (1 << 0)
   3737   ,
   3738   /**
   3739    * Generated nonces are valid only for the same URI (excluding parameters
   3740    * after '?' in URI) and request method (GET, POST etc).
   3741    * Not recommended unless "protection space" is limited to a single URI as
   3742    * RFC 7616 allows clients to reuse server-generated nonces for any URI
   3743    * in the same "protection space" which by default consists of all server
   3744    * URIs.
   3745    */
   3746   MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_URI = (1 << 1)
   3747   ,
   3748 
   3749   /**
   3750    * Generated nonces are valid only for the same URI including URI parameters
   3751    * and request method (GET, POST etc).
   3752    * This value implies #MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_URI.
   3753    * Not recommended for that same reasons as
   3754    * #MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_URI.
   3755    */
   3756   MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_URI_PARAMS = (1 << 2)
   3757   ,
   3758 
   3759   /**
   3760    * Generated nonces are valid only for the single client's IP.
   3761    * While it looks like security improvement, in practice the same client may
   3762    * jump from one IP to another (mobile or Wi-Fi handover, DHCP re-assignment,
   3763    * Multi-NAT, different proxy chain and other reasons), while IP address
   3764    * spoofing could be used relatively easily.
   3765    */
   3766   MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_CLIENT_IP = (1 << 3)
   3767 };
   3768 
   3769 
   3770 struct MHD_ServerCredentialsContext;
   3771 
   3772 
   3773 /**
   3774  * Context required to provide a pre-shared key to the
   3775  * server.
   3776  *
   3777  * @param mscc the context
   3778  * @param psk_size the number of bytes in @a psk
   3779  * @param psk the pre-shared-key; should be allocated with malloc(),
   3780  *                 will be freed by MHD
   3781  */
   3782 MHD_EXTERN_ enum MHD_StatusCode
   3783 MHD_connection_set_psk (
   3784   struct MHD_ServerCredentialsContext *mscc,
   3785   size_t psk_size,
   3786   const /*void? */ char psk[MHD_FN_PAR_DYN_ARR_SIZE_ (psk_size)]);
   3787 
   3788 #define MHD_connection_set_psk_unavailable(mscc) \
   3789         MHD_connection_set_psk (mscc, 0, NULL)
   3790 
   3791 
   3792 /**
   3793  * Function called to lookup the pre-shared key (PSK) for a given
   3794  * HTTP connection based on the @a username.  MHD will suspend handling of
   3795  * the @a connection until the application calls #MHD_connection_set_psk().
   3796  * If looking up the PSK fails, the application must still call
   3797  * #MHD_connection_set_psk_unavailable().
   3798  *
   3799  * @param cls closure
   3800  * @param connection the HTTPS connection
   3801  * @param username the user name claimed by the other side
   3802  * @param mscc context to pass to #MHD_connection_set_psk().
   3803  */
   3804 typedef void
   3805 (*MHD_PskServerCredentialsCallback)(
   3806   void *cls,
   3807   const struct MHD_Connection *MHD_RESTRICT connection,
   3808   const struct MHD_String *MHD_RESTRICT username,
   3809   struct MHD_ServerCredentialsContext *mscc);
   3810 
   3811 
   3812 /**
   3813  * The specified callback will be called one time,
   3814  * after network initialisation, TLS pre-initialisation, but before
   3815  * the start of the internal threads (if allowed).
   3816  *
   3817  * This callback may use introspection call to retrieve and adjust
   3818  * some of the daemon aspects. For example, TLS backend handler can be used
   3819  * to configure some TLS aspects.
   3820  * @param cls the callback closure
   3821  */
   3822 typedef void
   3823 (*MHD_DaemonReadyCallback)(void *cls);
   3824 
   3825 
   3826 /**
   3827  * Allow or deny a client to connect.
   3828  *
   3829  * @param cls closure
   3830  * @param addr_len length of @a addr
   3831  * @param addr address information from the client
   3832  * @see #MHD_D_OPTION_ACCEPT_POLICY()
   3833  * @return #MHD_YES if connection is allowed, #MHD_NO if not
   3834  */
   3835 typedef enum MHD_Bool
   3836 (*MHD_AcceptPolicyCallback)(void *cls,
   3837                             size_t addr_len,
   3838                             const struct sockaddr *addr);
   3839 
   3840 
   3841 /**
   3842  * The data for the #MHD_EarlyUriLogCallback
   3843  */
   3844 struct MHD_EarlyUriCbData
   3845 {
   3846   /**
   3847    * The request handle.
   3848    * Headers are not yet available.
   3849    */
   3850   struct MHD_Request *request;
   3851 
   3852   /**
   3853    * The full URI ("request target") from the HTTP request, including URI
   3854    * parameters (the part after '?')
   3855    */
   3856   struct MHD_String full_uri;
   3857 
   3858   /**
   3859    * The request HTTP method
   3860    */
   3861   enum MHD_HTTP_Method method;
   3862 };
   3863 
   3864 /**
   3865  * Function called by MHD to allow the application to log the @a full_uri
   3866  * of the new request.
   3867  * This is the only moment when unmodified URI is provided.
   3868  * After this callback MHD parses the URI and modifies it by extracting
   3869  * GET parameters in-place.
   3870  *
   3871  * If this callback is set then it is the first application function called
   3872  * for the new request.
   3873  *
   3874  * If #MHD_RequestEndedCallback is also set then it is guaranteed that
   3875  * #MHD_RequestEndedCallback is called for the same request. Application
   3876  * may allocate request specific data in this callback and de-allocate
   3877  * the data in #MHD_RequestEndedCallback.
   3878  *
   3879  * @param cls client-defined closure
   3880  * @param req_data the request data
   3881  * @param request_app_context_ptr the pointer to variable that can be set to
   3882  *                                the application context for the request;
   3883  *                                initially the variable set to NULL
   3884  */
   3885 typedef void
   3886 (MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (3)
   3887  *MHD_EarlyUriLogCallback)(void *cls,
   3888                            const struct MHD_EarlyUriCbData *req_data,
   3889                            void **request_app_context_ptr);
   3890 
   3891 
   3892 /**
   3893  * The `enum MHD_ConnectionNotificationCode` specifies types
   3894  * of connection notifications.
   3895  * @ingroup request
   3896  */
   3897 enum MHD_FIXED_ENUM_MHD_SET_ MHD_ConnectionNotificationCode
   3898 {
   3899 
   3900   /**
   3901    * A new connection has been started.
   3902    * @ingroup request
   3903    */
   3904   MHD_CONNECTION_NOTIFY_STARTED = 0
   3905   ,
   3906   /**
   3907    * A connection is closed.
   3908    * @ingroup request
   3909    */
   3910   MHD_CONNECTION_NOTIFY_CLOSED = 1
   3911 
   3912 };
   3913 
   3914 /**
   3915  * Extra details for connection notifications.
   3916  * Currently not used
   3917  */
   3918 union MHD_ConnectionNotificationDetails
   3919 {
   3920   /**
   3921    * Unused
   3922    */
   3923   int reserved1;
   3924 };
   3925 
   3926 
   3927 /**
   3928  * The connection notification data structure
   3929  */
   3930 struct MHD_ConnectionNotificationData
   3931 {
   3932   /**
   3933    * The connection handle
   3934    */
   3935   struct MHD_Connection *connection;
   3936   /**
   3937    * The connection-specific application context data (opaque for MHD).
   3938    * Initially set to NULL (for connections added by MHD) or set by
   3939    * @a connection_cntx parameter for connections added by
   3940    * #MHD_daemon_add_connection().
   3941    */
   3942   void *application_context;
   3943   /**
   3944    * The code of the event
   3945    */
   3946   enum MHD_ConnectionNotificationCode code;
   3947   /**
   3948    * Event details
   3949    */
   3950   union MHD_ConnectionNotificationDetails details;
   3951 };
   3952 
   3953 
   3954 /**
   3955  * Signature of the callback used by MHD to notify the
   3956  * application about started/stopped network connections
   3957  *
   3958  * @param cls client-defined closure
   3959  * @param[in,out]  data the details about the event
   3960  * @see #MHD_D_OPTION_NOTIFY_CONNECTION()
   3961  * @ingroup request
   3962  */
   3963 typedef void
   3964 (MHD_FN_PAR_NONNULL_ (2)
   3965  *MHD_NotifyConnectionCallback)(void *cls,
   3966                                 struct MHD_ConnectionNotificationData *data);
   3967 
   3968 
   3969 /**
   3970  * The type of stream notifications.
   3971  * @ingroup request
   3972  */
   3973 enum MHD_FIXED_ENUM_MHD_SET_ MHD_StreamNotificationCode
   3974 {
   3975   /**
   3976    * A new stream has been started.
   3977    * @ingroup request
   3978    */
   3979   MHD_STREAM_NOTIFY_STARTED = 0
   3980   ,
   3981   /**
   3982    * A stream is closed.
   3983    * @ingroup request
   3984    */
   3985   MHD_STREAM_NOTIFY_CLOSED = 1
   3986 };
   3987 
   3988 /**
   3989  * Additional information about stream started event
   3990  */
   3991 struct MHD_StreamNotificationDetailStarted
   3992 {
   3993   /**
   3994    * Set to #MHD_YES of the stream was started by client
   3995    */
   3996   enum MHD_Bool by_client;
   3997 };
   3998 
   3999 /**
   4000  * Additional information about stream events
   4001  */
   4002 union MHD_StreamNotificationDetail
   4003 {
   4004   /**
   4005    * Information for event #MHD_STREAM_NOTIFY_STARTED
   4006    */
   4007   struct MHD_StreamNotificationDetailStarted started;
   4008 };
   4009 
   4010 /**
   4011  * Stream notification data structure
   4012  */
   4013 struct MHD_StreamNotificationData
   4014 {
   4015   /**
   4016    * The handle of the stream
   4017    */
   4018   struct MHD_Stream *stream;
   4019   /**
   4020    * The code of the event
   4021    */
   4022   enum MHD_StreamNotificationCode code;
   4023   /**
   4024    * Detailed information about notification event
   4025    */
   4026   union MHD_StreamNotificationDetail details;
   4027 };
   4028 
   4029 
   4030 /**
   4031  * Signature of the callback used by MHD to notify the
   4032  * application about started/stopped data stream
   4033  * For HTTP/1.1 it is the same like network connection
   4034  * with 1:1 match.
   4035  *
   4036  * @param cls client-defined closure
   4037  * @param data the details about the event
   4038  * @see #MHD_D_OPTION_NOTIFY_STREAM()
   4039  * @ingroup request
   4040  */
   4041 typedef void
   4042 (MHD_FN_PAR_NONNULL_ (2)
   4043  *MHD_NotifyStreamCallback)(
   4044   void *cls,
   4045   const struct MHD_StreamNotificationData *data);
   4046 
   4047 #include "microhttpd2_generated_daemon_options.h"
   4048 
   4049 
   4050 /**
   4051  * The `enum MHD_RequestEndedCode` specifies reasons
   4052  * why a request has been ended.
   4053  * @ingroup request
   4054  */
   4055 enum MHD_FIXED_ENUM_MHD_SET_ MHD_RequestEndedCode
   4056 {
   4057 
   4058   /**
   4059    * The response was successfully sent.
   4060    * @ingroup request
   4061    */
   4062   MHD_REQUEST_ENDED_COMPLETED_OK = 0
   4063   ,
   4064   /**
   4065    * The response was successfully sent and connection is being switched
   4066    * to another protocol.
   4067    * @ingroup request
   4068    */
   4069   MHD_REQUEST_ENDED_COMPLETED_OK_UPGRADE = 1
   4070   ,
   4071   /**
   4072    * No activity on the connection for the number of seconds specified using
   4073    * #MHD_C_OPTION_TIMEOUT().
   4074    * @ingroup request
   4075    */
   4076   MHD_REQUEST_ENDED_TIMEOUT_REACHED = 10
   4077   ,
   4078   /**
   4079    * The connection was broken or TLS protocol error.
   4080    * @ingroup request
   4081    */
   4082   MHD_REQUEST_ENDED_CONNECTION_ERROR = 20
   4083   ,
   4084   /**
   4085    * The client terminated the connection by closing the socket either
   4086    * completely or for writing (TCP half-closed) before sending complete
   4087    * request.
   4088    * @ingroup request
   4089    */
   4090   MHD_REQUEST_ENDED_CLIENT_ABORT = 30
   4091   ,
   4092   /**
   4093    * The request is not valid according to HTTP specifications.
   4094    * @ingroup request
   4095    */
   4096   MHD_REQUEST_ENDED_HTTP_PROTOCOL_ERROR = 31
   4097   ,
   4098   /**
   4099    * The application aborted request without response.
   4100    * @ingroup request
   4101    */
   4102   MHD_REQUEST_ENDED_BY_APP_ABORT = 40
   4103   ,
   4104   /**
   4105    * The request was aborted due to the application failed to provide a valid
   4106    * response.
   4107    * @ingroup request
   4108    */
   4109   MHD_REQUEST_ENDED_BY_APP_ERROR = 41
   4110   ,
   4111   /**
   4112    * The request was aborted due to the application failed to register external
   4113    * event monitoring for the connection.
   4114    * @ingroup request
   4115    */
   4116   MHD_REQUEST_ENDED_BY_EXT_EVENT_ERROR = 42
   4117   ,
   4118   /**
   4119    * Error handling the connection due to resources exhausted.
   4120    * @ingroup request
   4121    */
   4122   MHD_REQUEST_ENDED_NO_RESOURCES = 50
   4123   ,
   4124   /**
   4125    * The request was aborted due to error reading file for file-backed response
   4126    * @ingroup request
   4127    */
   4128   MHD_REQUEST_ENDED_FILE_ERROR = 51
   4129   ,
   4130   /**
   4131    * The request was aborted due to error generating valid nonce for Digest Auth
   4132    * @ingroup request
   4133    */
   4134   MHD_REQUEST_ENDED_NONCE_ERROR = 52
   4135   ,
   4136   /**
   4137    * Closing the session since MHD is being shut down.
   4138    * @ingroup request
   4139    */
   4140   MHD_REQUEST_ENDED_DAEMON_SHUTDOWN = 60
   4141 };
   4142 
   4143 /**
   4144  * Additional information about request ending
   4145  */
   4146 union MHD_RequestEndedDetail
   4147 {
   4148   /**
   4149    * Reserved member.
   4150    * Do not use.
   4151    */
   4152   void *reserved;
   4153 };
   4154 
   4155 /**
   4156  * Request termination data structure
   4157  */
   4158 struct MHD_RequestEndedData
   4159 {
   4160   /**
   4161    * The request handle.
   4162    * Note that most of the request data may be already unvailable.
   4163    */
   4164   struct MHD_Request *req;
   4165   /**
   4166    * The code of the event
   4167    */
   4168   enum MHD_RequestEndedCode code;
   4169   /**
   4170    * Detailed information about the event
   4171    */
   4172   union MHD_RequestEndedDetail details;
   4173 };
   4174 
   4175 
   4176 /**
   4177  * Signature of the callback used by MHD to notify the application
   4178  * about completed requests.
   4179  *
   4180  * This is the last callback called for any request (if provided by
   4181  * the application).
   4182  *
   4183  * @param cls client-defined closure
   4184  * @param data the details about the event
   4185  * @param request_app_context the application request context, as possibly set
   4186                               by the #MHD_EarlyUriLogCallback
   4187  * @see #MHD_R_OPTION_TERMINATION_CALLBACK()
   4188  * @ingroup request
   4189  */
   4190 typedef void
   4191 (*MHD_RequestEndedCallback)(void *cls,
   4192                             const struct MHD_RequestEndedData *data,
   4193                             void *request_app_context);
   4194 
   4195 
   4196 #include "microhttpd2_generated_response_options.h"
   4197 /* Beginning of generated code documenting how to use options.
   4198    You should treat the following functions *as if* they were
   4199    part of the header/API. The actual declarations are more
   4200    complex, so these here are just for documentation!
   4201    We do not actually *build* this code... */
   4202 #if 0
   4203 
   4204 /**
   4205  * Set MHD work (threading and polling) mode.
   4206  * Consider use of #MHD_D_OPTION_WM_EXTERNAL_PERIODIC(), #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL(), #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_EDGE(), #MHD_D_OPTION_WM_EXTERNAL_SINGLE_FD_WATCH(), #MHD_D_OPTION_WM_WORKER_THREADS() or #MHD_D_OPTION_WM_THREAD_PER_CONNECTION() instead of direct use of this parameter.
   4207  * @param wmp the object created by one of the next functions/macros: #MHD_WM_OPTION_EXTERNAL_PERIODIC(), #MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(), #MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(), #MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH(), #MHD_WM_OPTION_WORKER_THREADS(), #MHD_WM_OPTION_THREAD_PER_CONNECTION()
   4208  * @return structure with the requested setting
   4209  */
   4210 struct MHD_DaemonOptionAndValue
   4211 MHD_D_OPTION_WORK_MODE (
   4212   struct MHD_WorkModeWithParam wmp
   4213   );
   4214 
   4215 /**
   4216  * Select a sockets watch system call used for internal polling.
   4217  * @param els FIXME
   4218  * @return structure with the requested setting
   4219  */
   4220 struct MHD_DaemonOptionAndValue
   4221 MHD_D_OPTION_POLL_SYSCALL (
   4222   enum MHD_SockPollSyscall els
   4223   );
   4224 
   4225 /**
   4226  * Instruct MHD to register all sockets every processing round.
   4227  *
   4228 By default (this options is not enabled) every processing round (every time
   4229  * when #MHD_daemon_event_update() is called) MHD calls
   4230  * #MHD_SocketRegistrationUpdateCallback only for the new sockets, for
   4231  * the removed sockets and for the updated sockets.
   4232  * Some sockets are registered when #MHD_daemon_start() is called.
   4233  *
   4234 If this options is enabled, then #MHD_SocketRegistrationUpdateCallback is
   4235  * called for every socket each processing round. No sockets are registered when
   4236  * the daemon is being started.
   4237  * @param value the value of the parameter * @return structure with the requested setting
   4238  */
   4239 struct MHD_DaemonOptionAndValue
   4240 MHD_D_OPTION_REREGISTER_ALL (
   4241   enum MHD_Bool value
   4242   );
   4243 
   4244 /**
   4245  * Set a callback to use for logging
   4246  * @param log_cb the callback to use for logging,
   4247  *   NULL to disable logging.
   4248  *   The logging to stderr is enabled by default.
   4249  * @param log_cb_cls the closure for the logging callback
   4250  * @return structure with the requested setting
   4251  */
   4252 struct MHD_DaemonOptionAndValue
   4253 MHD_D_OPTION_LOG_CALLBACK (
   4254   MHD_LoggingCallback log_cb,
   4255   void *log_cb_cls
   4256   );
   4257 
   4258 /**
   4259  * Bind to the given TCP port and address family.
   4260  *
   4261 Does not work with #MHD_D_OPTION_BIND_SA() or #MHD_D_OPTION_LISTEN_SOCKET().
   4262  *
   4263 If no listen socket optins (#MHD_D_OPTION_BIND_PORT(), #MHD_D_OPTION_BIND_SA(), #MHD_D_OPTION_LISTEN_SOCKET()) are used, MHD does not listen for incoming connection.
   4264  * @param af the address family to use,
   4265  *   the #MHD_AF_NONE to disable listen socket (the same effect as if this option is not used)
   4266  * @param port port to use, 0 to let system assign any free port,
   4267  *   ignored if @a af is #MHD_AF_NONE
   4268  * @return structure with the requested setting
   4269  */
   4270 struct MHD_DaemonOptionAndValue
   4271 MHD_D_OPTION_BIND_PORT (
   4272   enum MHD_AddressFamily af,
   4273   uint_least16_t port
   4274   );
   4275 
   4276 /**
   4277  * Bind to the given socket address.
   4278  *
   4279 Does not work with #MHD_D_OPTION_BIND_PORT() or #MHD_D_OPTION_LISTEN_SOCKET().
   4280  *
   4281 If no listen socket optins (#MHD_D_OPTION_BIND_PORT(), #MHD_D_OPTION_BIND_SA(), #MHD_D_OPTION_LISTEN_SOCKET()) are used, MHD does not listen for incoming connection.
   4282  * @param sa_len the size of the socket address pointed by @a sa.
   4283  * @param sa the address to bind to; can be IPv4 (AF_INET), IPv6 (AF_INET6) or even a UNIX domain socket (AF_UNIX)
   4284  * @param dual When a previous version of the protocol exist (like IPv4 when @a v_sa is IPv6) bind to both protocols (IPv6 and IPv4).
   4285  * @return structure with the requested setting
   4286  */
   4287 struct MHD_DaemonOptionAndValue
   4288 MHD_D_OPTION_BIND_SA (
   4289   size_t sa_len,
   4290   /* const */ struct sockaddr *sa,
   4291   enum MHD_Bool dual
   4292   );
   4293 
   4294 /**
   4295  * Accept connections from the given socket.  Socket
   4296  * must be a TCP or UNIX domain (SOCK_STREAM) socket.
   4297  *
   4298 Does not work with #MHD_D_OPTION_BIND_PORT() or #MHD_D_OPTION_BIND_SA().
   4299  *
   4300 If no listen socket optins (#MHD_D_OPTION_BIND_PORT(), #MHD_D_OPTION_BIND_SA(), #MHD_D_OPTION_LISTEN_SOCKET()) are used, MHD does not listen for incoming connection.
   4301  * @param listen_fd the listen socket to use, ignored if set to #MHD_INVALID_SOCKET
   4302  * @return structure with the requested setting
   4303  */
   4304 struct MHD_DaemonOptionAndValue
   4305 MHD_D_OPTION_LISTEN_SOCKET (
   4306   MHD_Socket listen_fd
   4307   );
   4308 
   4309 /**
   4310  * Select mode of reusing address:port listen address.
   4311  *
   4312 Works only when #MHD_D_OPTION_BIND_PORT() or #MHD_D_OPTION_BIND_SA() are used.
   4313  * @param reuse_type FIXME
   4314  * @return structure with the requested setting
   4315  */
   4316 struct MHD_DaemonOptionAndValue
   4317 MHD_D_OPTION_LISTEN_ADDR_REUSE (
   4318   enum MHD_DaemonOptionBindType reuse_type
   4319   );
   4320 
   4321 /**
   4322  * Configure TCP_FASTOPEN option, including setting a
   4323  * custom @a queue_length.
   4324  *
   4325 Note that having a larger queue size can cause resource exhaustion
   4326  * attack as the TCP stack has to now allocate resources for the SYN
   4327  * packet along with its DATA.
   4328  *
   4329 Works only when #MHD_D_OPTION_BIND_PORT() or #MHD_D_OPTION_BIND_SA() are used.
   4330  * @param option the type use of of TCP FastOpen
   4331  * @param queue_length the length of the queue, zero to use system or MHD default,
   4332  *   silently ignored on platforms without support for custom queue size
   4333  * @return structure with the requested setting
   4334  */
   4335 struct MHD_DaemonOptionAndValue
   4336 MHD_D_OPTION_TCP_FASTOPEN (
   4337   enum MHD_TCPFastOpenType option,
   4338   unsigned int queue_length
   4339   );
   4340 
   4341 /**
   4342  * Use the given backlog for the listen() call.
   4343  *
   4344 Works only when #MHD_D_OPTION_BIND_PORT() or #MHD_D_OPTION_BIND_SA() are used.
   4345  * Zero parameter treated as MHD/system default.
   4346  * @param backlog_size FIXME
   4347  * @return structure with the requested setting
   4348  */
   4349 struct MHD_DaemonOptionAndValue
   4350 MHD_D_OPTION_LISTEN_BACKLOG (
   4351   unsigned int backlog_size
   4352   );
   4353 
   4354 /**
   4355  * Inform that SIGPIPE is suppressed or handled by application.
   4356  * If suppressed/handled, MHD uses network functions that could generate SIGPIPE, like `sendfile()`.
   4357  * Silently ignored when MHD creates internal threads as for them SIGPIPE is suppressed automatically.
   4358  * @param value the value of the parameter * @return structure with the requested setting
   4359  */
   4360 struct MHD_DaemonOptionAndValue
   4361 MHD_D_OPTION_SIGPIPE_SUPPRESSED (
   4362   enum MHD_Bool value
   4363   );
   4364 
   4365 /**
   4366  * Enable TLS (HTTPS) and select TLS backend
   4367  * @param backend the TLS backend to use,
   4368  *   #MHD_TLS_BACKEND_NONE for non-TLS (plain TCP) connections
   4369  * @return structure with the requested setting
   4370  */
   4371 struct MHD_DaemonOptionAndValue
   4372 MHD_D_OPTION_TLS (
   4373   enum MHD_TlsBackend backend
   4374   );
   4375 
   4376 /**
   4377  * Provide TLS key and certificate data in-memory.
   4378  * Works only if TLS mode is enabled.
   4379  * @param mem_cert The X.509 certificates chain in PEM format loaded into memory (not a filename).
   4380  *   The first certificate must be the server certificate, following by the chain of signing
   4381  *   certificates up to (but not including) CA root certificate.
   4382  * @param mem_key the private key in PEM format loaded into memory (not a filename)
   4383  * @param mem_pass the option passphrase phrase to decrypt the private key,
   4384  *   could be NULL if private key does not need a password
   4385  * @return structure with the requested setting
   4386  */
   4387 struct MHD_DaemonOptionAndValue
   4388 MHD_D_OPTION_TLS_CERT_KEY (
   4389   /* const */ char *mem_cert,
   4390   const char *mem_key,
   4391   const char *mem_pass
   4392   );
   4393 
   4394 /**
   4395  * Provide the certificate of the certificate authority (CA) to be used by the MHD daemon for client authentication.
   4396  * Works only if TLS mode is enabled.
   4397  * @param mem_client_ca the CA certificate in memory (not a filename)
   4398  * @return structure with the requested setting
   4399  */
   4400 struct MHD_DaemonOptionAndValue
   4401 MHD_D_OPTION_TLS_CLIENT_CA (
   4402   const char *mem_client_ca
   4403   );
   4404 
   4405 /**
   4406  * Configure PSK to use for the TLS key exchange.
   4407  * @param psk_cb the function to call to obtain pre-shared key
   4408  * @param psk_cb_cls the closure for @a psk_cb
   4409  * @return structure with the requested setting
   4410  */
   4411 struct MHD_DaemonOptionAndValue
   4412 MHD_D_OPTION_TLS_PSK_CALLBACK (
   4413   MHD_PskServerCredentialsCallback psk_cb,
   4414   void *psk_cb_cls
   4415   );
   4416 
   4417 /**
   4418  * Control ALPN for TLS connection.
   4419  * Silently ignored for non-TLS.
   4420  * By default ALPN is automatically used for TLS connections.
   4421  * @param value the value of the parameter * @return structure with the requested setting
   4422  */
   4423 struct MHD_DaemonOptionAndValue
   4424 MHD_D_OPTION_NO_ALPN (
   4425   enum MHD_Bool value
   4426   );
   4427 
   4428 /**
   4429  * Provide application name to load dedicated section in TLS backend's configuration file.
   4430  * Search for "System-wide configuration of the library" for GnuTLS documentation or
   4431  * for "config, OPENSSL LIBRARY CONFIGURATION" for OpenSSL documentation.
   4432  * If not specified the default backend configuration is used:
   4433  * "@LIBMICROHTTPD" (if available), then "@SYSTEM" (if available) then default priorities, then "NORMAL" for GnuTLS;
   4434  * "libmicrohttpd" (if available), then default name ("openssl_conf") for OpenSSL.
   4435  * Ignored when MbedTLS is used as daemon's TLS backend.
   4436  * @param app_name the name of the application, used as converted to
   4437  *   uppercase (with '@'-prefixed) for GnuTLS and as converted to
   4438  *   lowercase for OpenSSL; must not be longer than 127 characters
   4439  * @param disable_fallback forbid use fallback/default configuration if specified
   4440  *   configuration is not found; also forbid ignoring errors in the
   4441  *   configuration on TLS backends, which may ignoring configuration
   4442  *   errors
   4443  * @return structure with the requested setting
   4444  */
   4445 struct MHD_DaemonOptionAndValue
   4446 MHD_D_OPTION_TLS_APP_NAME (
   4447   char *app_name,
   4448   enum MHD_Bool disable_fallback
   4449   );
   4450 
   4451 /**
   4452  * Set the configuration pathname for OpenSSL configuration file
   4453  * Ignored OpenSSL is not used as daemon's TLS backend.
   4454  * @param pathname the path and the name of the OpenSSL configuration file,
   4455  *   if only the name is provided then standard path for
   4456  *   configuration files is used,
   4457  *   could be NULL to use default configuration file pathname
   4458  *   or an empty (zero-size) string to disable file loading
   4459  * @param disable_fallback forbid use of fallback/default location and name of
   4460  *   the OpenSSL configuration file; also forbid initialisation without
   4461  *   configuration file
   4462  * @return structure with the requested setting
   4463  */
   4464 struct MHD_DaemonOptionAndValue
   4465 MHD_D_OPTION_TLS_OPENSSL_DEF_FILE (
   4466   char *pathname,
   4467   enum MHD_Bool disable_fallback
   4468   );
   4469 
   4470 /**
   4471  * Specify the inactivity timeout for a connection in milliseconds.
   4472  * If a connection remains idle (no activity) for this many
   4473  * milliseconds, it is closed automatically.
   4474  * Use zero for no timeout; this is also the (unsafe!)
   4475  * default.
   4476  * Values larger than 1209600000 (two weeks) are silently
   4477  * clamped to 1209600000.
   4478  * Precise closing time is not guaranteed and depends on
   4479  * system clock granularity and amount of time spent on
   4480  * processing other connections. Typical precision is
   4481  * within +/- 30 milliseconds, while the worst case could
   4482  * be greater than +/- 1 second.
   4483  * Values below 1500 milliseconds are risky as they
   4484  * may cause valid connections to be aborted and may
   4485  * increase load the server load due to clients' repetitive
   4486  * automatic retries.
   4487  * @param timeout the timeout in milliseconds, zero for no timeout
   4488  * @return structure with the requested setting
   4489  */
   4490 struct MHD_DaemonOptionAndValue
   4491 MHD_D_OPTION_DEFAULT_TIMEOUT_MILSEC (
   4492   uint_fast32_t timeout
   4493   );
   4494 
   4495 /**
   4496  * Maximum number of (concurrent) network connections served by daemon.
   4497  * @note The real maximum number of network connections could be smaller
   4498  *       than requested due to the system limitations, like FD_SETSIZE when
   4499  *       polling by select() is used.
   4500  * @param glob_limit FIXME
   4501  * @return structure with the requested setting
   4502  */
   4503 struct MHD_DaemonOptionAndValue
   4504 MHD_D_OPTION_GLOBAL_CONNECTION_LIMIT (
   4505   unsigned int glob_limit
   4506   );
   4507 
   4508 /**
   4509  * Limit on the number of (concurrent) network connections made to the server from the same IP address.
   4510  * Can be used to prevent one IP from taking over all of the allowed connections. If the same IP tries to establish more than the specified number of connections, they will be immediately rejected.
   4511  * @param limit FIXME
   4512  * @return structure with the requested setting
   4513  */
   4514 struct MHD_DaemonOptionAndValue
   4515 MHD_D_OPTION_PER_IP_LIMIT (
   4516   unsigned int limit
   4517   );
   4518 
   4519 /**
   4520  * Set a policy callback that accepts/rejects connections based on the client's IP address.  The callbeck function will be called before servicing any new incoming connection.
   4521  * @param apc the accept policy callback
   4522  * @param apc_cls the closure for the callback
   4523  * @return structure with the requested setting
   4524  */
   4525 struct MHD_DaemonOptionAndValue
   4526 MHD_D_OPTION_ACCEPT_POLICY (
   4527   MHD_AcceptPolicyCallback apc,
   4528   void *apc_cls
   4529   );
   4530 
   4531 /**
   4532  * Set mode of connection memory buffer zeroing
   4533  * @param buff_zeroing buffer zeroing mode
   4534  * @return structure with the requested setting
   4535  */
   4536 struct MHD_DaemonOptionAndValue
   4537 MHD_D_OPTION_CONN_BUFF_ZEROING (
   4538   enum MHD_ConnBufferZeroingMode buff_zeroing
   4539   );
   4540 
   4541 /**
   4542  * Set how strictly MHD will enforce the HTTP protocol.
   4543  * @param sl the level of strictness
   4544  * @param how the way how to use the requested level
   4545  * @return structure with the requested setting
   4546  */
   4547 struct MHD_DaemonOptionAndValue
   4548 MHD_D_OPTION_PROTOCOL_STRICT_LEVEL (
   4549   enum MHD_ProtocolStrictLevel sl,
   4550   enum MHD_UseStictLevel how
   4551   );
   4552 
   4553 /**
   4554  * Set a callback to be called first for every request when the request line is received (before any parsing of the header).
   4555  * This callback is the only way to get raw (unmodified) request URI as URI is parsed and modified by MHD in-place.
   4556  * Mandatory URI modification may apply before this call, like binary zero replacement, as required by RFCs.
   4557  * @param cb the early URI callback
   4558  * @param cls the closure for the callback
   4559  * @return structure with the requested setting
   4560  */
   4561 struct MHD_DaemonOptionAndValue
   4562 MHD_D_OPTION_EARLY_URI_LOGGER (
   4563   MHD_EarlyUriLogCallback cb,
   4564   void *cls
   4565   );
   4566 
   4567 /**
   4568  * Disable converting plus ('+') character to space in GET parameters (URI part after '?').
   4569  * Plus conversion is not required by HTTP RFCs, however it required by HTML specifications, see https://url.spec.whatwg.org/#application/x-www-form-urlencoded for details.
   4570  * By default plus is converted to space in the query part of URI.
   4571  * @param value the value of the parameter * @return structure with the requested setting
   4572  */
   4573 struct MHD_DaemonOptionAndValue
   4574 MHD_D_OPTION_DISABLE_URI_QUERY_PLUS_AS_SPACE (
   4575   enum MHD_Bool value
   4576   );
   4577 
   4578 /**
   4579  * Suppresse use of 'Date:' header.
   4580  * According to RFC should be suppressed only if the system has no RTC.
   4581  * The 'Date:' is not suppressed (the header is enabled) by default.
   4582  * @param value the value of the parameter * @return structure with the requested setting
   4583  */
   4584 struct MHD_DaemonOptionAndValue
   4585 MHD_D_OPTION_SUPPRESS_DATE_HEADER (
   4586   enum MHD_Bool value
   4587   );
   4588 
   4589 /**
   4590  * Use SHOUTcast for responses.
   4591  * This will cause *all* responses to begin with the SHOUTcast 'ICY' line instead of 'HTTP'.
   4592  * @param value the value of the parameter * @return structure with the requested setting
   4593  */
   4594 struct MHD_DaemonOptionAndValue
   4595 MHD_D_OPTION_ENABLE_SHOUTCAST (
   4596   enum MHD_Bool value
   4597   );
   4598 
   4599 /**
   4600  * Maximum memory size per connection.
   4601  * Default is 32kb.
   4602  * Values above 128kb are unlikely to result in much performance benefit, as half of the memory will be typically used for IO, and TCP buffers are unlikely to support window sizes above 64k on most systems.
   4603  * The size should be large enough to fit all request headers (together with internal parsing information).
   4604  * @param value the value of the parameter * @return structure with the requested setting
   4605  */
   4606 struct MHD_DaemonOptionAndValue
   4607 MHD_D_OPTION_CONN_MEMORY_LIMIT (
   4608   size_t value
   4609   );
   4610 
   4611 /**
   4612  * The size of the shared memory pool for accamulated upload processing.
   4613  * The same large pool is shared for all connections server by MHD and used when application requests avoiding of incremental upload processing to accamulate complete content upload before giving it to the application.
   4614  * Default is 8Mb.
   4615  * Can be set to zero to disable share pool.
   4616  * @param value the value of the parameter * @return structure with the requested setting
   4617  */
   4618 struct MHD_DaemonOptionAndValue
   4619 MHD_D_OPTION_LARGE_POOL_SIZE (
   4620   size_t value
   4621   );
   4622 
   4623 /**
   4624  * Desired size of the stack for the threads started by MHD.
   4625  * Use 0 for system default, which is also MHD default.
   4626  * Works only with #MHD_D_OPTION_WM_WORKER_THREADS() or #MHD_D_OPTION_WM_THREAD_PER_CONNECTION().
   4627  * @param value the value of the parameter * @return structure with the requested setting
   4628  */
   4629 struct MHD_DaemonOptionAndValue
   4630 MHD_D_OPTION_STACK_SIZE (
   4631   size_t value
   4632   );
   4633 
   4634 /**
   4635  * The the maximum FD value.
   4636  * The limit is applied to all sockets used by MHD.
   4637  * If listen socket FD is equal or higher that specified value, the daemon fail to start.
   4638  * If new connection FD is equal or higher that specified value, the connection is rejected.
   4639  * Useful if application uses select() for polling the sockets, system FD_SETSIZE is good value for this option in such case.
   4640  * Silently ignored on W32 (WinSock sockets).
   4641  * @param max_fd FIXME
   4642  * @return structure with the requested setting
   4643  */
   4644 struct MHD_DaemonOptionAndValue
   4645 MHD_D_OPTION_FD_NUMBER_LIMIT (
   4646   MHD_Socket max_fd
   4647   );
   4648 
   4649 /**
   4650  * Enable `turbo`.
   4651  * Disables certain calls to `shutdown()`, enables aggressive non-blocking optimistic reads and other potentially unsafe optimisations.
   4652  * Most effects only happen with internal threads with epoll.
   4653  * The 'turbo' mode is not enabled (mode is disabled) by default.
   4654  * @param value the value of the parameter * @return structure with the requested setting
   4655  */
   4656 struct MHD_DaemonOptionAndValue
   4657 MHD_D_OPTION_TURBO (
   4658   enum MHD_Bool value
   4659   );
   4660 
   4661 /**
   4662  * Disable some internal thread safety.
   4663  * Indicates that MHD daemon will be used by application in single-threaded mode only.  When this flag is set then application must call any MHD function only within a single thread.
   4664  * This flag turns off some internal thread-safety and allows MHD making some of the internal optimisations suitable only for single-threaded environment.
   4665  * Not compatible with any internal threads modes.
   4666  * If MHD is compiled with custom configuration for embedded projects without threads support, this option is mandatory.
   4667  * Thread safety is not disabled (safety is enabled) by default.
   4668  * @param value the value of the parameter * @return structure with the requested setting
   4669  */
   4670 struct MHD_DaemonOptionAndValue
   4671 MHD_D_OPTION_DISABLE_THREAD_SAFETY (
   4672   enum MHD_Bool value
   4673   );
   4674 
   4675 /**
   4676  * You need to set this option if you want to disable use of HTTP Upgrade.
   4677  * Upgrade may require usage of additional internal resources, which we can avoid providing if they will not be used.
   4678  * You should only use this option if you do not use upgrade functionality and need a generally minor boost in performance and resources saving.
   4679  * The upgrade is not disallowed (upgrade is allowed) by default.
   4680  * @param value the value of the parameter * @return structure with the requested setting
   4681  */
   4682 struct MHD_DaemonOptionAndValue
   4683 MHD_D_OPTION_DISALLOW_UPGRADE (
   4684   enum MHD_Bool value
   4685   );
   4686 
   4687 /**
   4688  * Disable #MHD_action_suspend() functionality.
   4689  *
   4690 You should only use this function if you do not use suspend functionality and need a generally minor boost in performance.
   4691  * The suspend is not disallowed (suspend is allowed) by default.
   4692  * @param value the value of the parameter * @return structure with the requested setting
   4693  */
   4694 struct MHD_DaemonOptionAndValue
   4695 MHD_D_OPTION_DISALLOW_SUSPEND_RESUME (
   4696   enum MHD_Bool value
   4697   );
   4698 
   4699 /**
   4700  * Disable cookies parsing.
   4701  *
   4702 Disable automatic cookies processing if cookies are not used.
   4703  * Cookies are automatically parsed by default.
   4704  * @param value the value of the parameter * @return structure with the requested setting
   4705  */
   4706 struct MHD_DaemonOptionAndValue
   4707 MHD_D_OPTION_DISABLE_COOKIES (
   4708   enum MHD_Bool value
   4709   );
   4710 
   4711 /**
   4712  * Set a callback to be called for pre-start finalisation.
   4713  *
   4714 The specified callback will be called one time, after network initialisation, TLS pre-initialisation, but before the start of the internal threads (if allowed)
   4715  * @param cb the pre-start callback
   4716  * @param cb_cls the closure for the callback
   4717  * @return structure with the requested setting
   4718  */
   4719 struct MHD_DaemonOptionAndValue
   4720 MHD_D_OPTION_DAEMON_READY_CALLBACK (
   4721   MHD_DaemonReadyCallback cb,
   4722   void *cb_cls
   4723   );
   4724 
   4725 /**
   4726  * Set a function that should be called whenever a connection is started or closed.
   4727  * @param ncc the callback for notifications
   4728  * @param cls the closure for the callback
   4729  * @return structure with the requested setting
   4730  */
   4731 struct MHD_DaemonOptionAndValue
   4732 MHD_D_OPTION_NOTIFY_CONNECTION (
   4733   MHD_NotifyConnectionCallback ncc,
   4734   void *cls
   4735   );
   4736 
   4737 /**
   4738  * Register a function that should be called whenever a stream is started or closed.
   4739  * For HTTP/1.1 this callback is called one time for every connection.
   4740  * @param nsc the callback for notifications
   4741  * @param cls the closure for the callback
   4742  * @return structure with the requested setting
   4743  */
   4744 struct MHD_DaemonOptionAndValue
   4745 MHD_D_OPTION_NOTIFY_STREAM (
   4746   MHD_NotifyStreamCallback nsc,
   4747   void *cls
   4748   );
   4749 
   4750 /**
   4751  * Set strong random data to be used by MHD.
   4752  * Currently the data is only needed for Digest Auth module.
   4753  * Daemon support for Digest Auth is enabled automatically if this option is used.
   4754  * The recommended size is between 8 and 32 bytes. Security can be lower for sizes less or equal four.
   4755  * Sizes larger then 32 (or, probably, larger than 16 - debatable) will not increase the security.
   4756  * @param buf_size the size of the buffer
   4757  * @param buf the buffer with strong random data, the content will be copied by MHD
   4758  * @return structure with the requested setting
   4759  */
   4760 struct MHD_DaemonOptionAndValue
   4761 MHD_D_OPTION_RANDOM_ENTROPY (
   4762   size_t buf_size,
   4763   /* const */ void *buf
   4764   );
   4765 
   4766 /**
   4767  * Specify the size of the internal hash map array that tracks generated digest nonces usage.
   4768  * When the size of the map is too small then need to handle concurrent DAuth requests, a lot of stale nonce results will be produced.
   4769  * By default the size is 1000 entries.
   4770  * @param size the size of the map array
   4771  * @return structure with the requested setting
   4772  */
   4773 struct MHD_DaemonOptionAndValue
   4774 MHD_D_OPTION_AUTH_DIGEST_MAP_SIZE (
   4775   size_t size
   4776   );
   4777 
   4778 /**
   4779  * Nonce validity time (in seconds) used for Digest Auth.
   4780  * If followed by zero value the value is silently ignored.
   4781  * @see #MHD_digest_auth_check(), MHD_digest_auth_check_digest()
   4782  * @param timeout FIXME
   4783  * @return structure with the requested setting
   4784  */
   4785 struct MHD_DaemonOptionAndValue
   4786 MHD_D_OPTION_AUTH_DIGEST_NONCE_TIMEOUT (
   4787   unsigned int timeout
   4788   );
   4789 
   4790 /**
   4791  * Default maximum nc (nonce count) value used for Digest Auth.
   4792  * If followed by zero value the value is silently ignored.
   4793  * @see #MHD_digest_auth_check(), MHD_digest_auth_check_digest()
   4794  * @param max_nc FIXME
   4795  * @return structure with the requested setting
   4796  */
   4797 struct MHD_DaemonOptionAndValue
   4798 MHD_D_OPTION_AUTH_DIGEST_DEF_MAX_NC (
   4799   uint_fast32_t max_nc
   4800   );
   4801 
   4802 /* End of generated code documenting how to use options */
   4803 #endif
   4804 
   4805 /* Beginning of generated code documenting how to use options.
   4806    You should treat the following functions *as if* they were
   4807    part of the header/API. The actual declarations are more
   4808    complex, so these here are just for documentation!
   4809    We do not actually *build* this code... */
   4810 #if 0
   4811 
   4812 /**
   4813  * Make the response object re-usable.
   4814  * The response will not be consumed by MHD_action_from_response() and must be destroyed by MHD_response_destroy().
   4815  * Useful if the same response is often used to reply.
   4816  * @param value the value of the parameter * @return structure with the requested setting
   4817  */
   4818 struct MHD_ResponseOptionAndValue
   4819 MHD_R_OPTION_REUSABLE (
   4820   enum MHD_Bool value
   4821   );
   4822 
   4823 /**
   4824  * Enable special processing of the response as body-less (with undefined body size). No automatic 'Content-Length' or 'Transfer-Encoding: chunked' headers are added when the response is used with #MHD_HTTP_STATUS_NOT_MODIFIED code or to respond to HEAD request.
   4825  * The flag also allow to set arbitrary 'Content-Length' by #MHD_response_add_header() function.
   4826  * This flag value can be used only with responses created without body (zero-size body).
   4827  * Responses with this flag enabled cannot be used in situations where reply body must be sent to the client.
   4828  * This flag is primarily intended to be used when automatic 'Content-Length' header is undesirable in response to HEAD requests.
   4829  * @param value the value of the parameter * @return structure with the requested setting
   4830  */
   4831 struct MHD_ResponseOptionAndValue
   4832 MHD_R_OPTION_HEAD_ONLY_RESPONSE (
   4833   enum MHD_Bool value
   4834   );
   4835 
   4836 /**
   4837  * Force use of chunked encoding even if the response content size is known.
   4838  * Ignored when the reply cannot have body/content.
   4839  * @param value the value of the parameter * @return structure with the requested setting
   4840  */
   4841 struct MHD_ResponseOptionAndValue
   4842 MHD_R_OPTION_CHUNKED_ENC (
   4843   enum MHD_Bool value
   4844   );
   4845 
   4846 /**
   4847  * Force close connection after sending the response, prevents keep-alive connections and adds 'Connection: close' header.
   4848  * @param value the value of the parameter * @return structure with the requested setting
   4849  */
   4850 struct MHD_ResponseOptionAndValue
   4851 MHD_R_OPTION_CONN_CLOSE (
   4852   enum MHD_Bool value
   4853   );
   4854 
   4855 /**
   4856  * Only respond in conservative (dumb) HTTP/1.0-compatible mode.
   4857  * Response still use HTTP/1.1 version in header, but always close the connection after sending the response and do not use chunked encoding for the response.
   4858  * You can also set the #MHD_R_O_HTTP_1_0_SERVER flag to force HTTP/1.0 version in the response.
   4859  * Responses are still compatible with HTTP/1.1.
   4860  * Summary:
   4861  * + declared reply version: HTTP/1.1
   4862  * + keep-alive: no
   4863  * + chunked: no
   4864  *
   4865 This option can be used to communicate with some broken client, which does not implement HTTP/1.1 features, but advertises HTTP/1.1 support.
   4866  * @param value the value of the parameter * @return structure with the requested setting
   4867  */
   4868 struct MHD_ResponseOptionAndValue
   4869 MHD_R_OPTION_HTTP_1_0_COMPATIBLE_STRICT (
   4870   enum MHD_Bool value
   4871   );
   4872 
   4873 /**
   4874  * Only respond in HTTP/1.0-mode.
   4875  * Contrary to the #MHD_R_O_HTTP_1_0_COMPATIBLE_STRICT flag, the response's HTTP version will always be set to 1.0 and keep-alive connections will be used if explicitly requested by the client.
   4876  * The 'Connection:' header will be added for both 'close' and 'keep-alive' connections.
   4877  * Chunked encoding will not be used for the response.
   4878  * Due to backward compatibility, responses still can be used with HTTP/1.1 clients.
   4879  * This option can be used to emulate HTTP/1.0 server (for response part only as chunked encoding in requests (if any) is processed by MHD).
   4880  * Summary:
   4881  * + declared reply version: HTTP/1.0
   4882  * + keep-alive: possible
   4883  * + chunked: no
   4884  *
   4885 With this option HTTP/1.0 server is emulated (with support for 'keep-alive' connections).
   4886  * @param value the value of the parameter * @return structure with the requested setting
   4887  */
   4888 struct MHD_ResponseOptionAndValue
   4889 MHD_R_OPTION_HTTP_1_0_SERVER (
   4890   enum MHD_Bool value
   4891   );
   4892 
   4893 /**
   4894  * Disable sanity check preventing clients from manually setting the HTTP content length option.
   4895  * Allow to set several 'Content-Length' headers. These headers will be used even with replies without body.
   4896  * @param value the value of the parameter * @return structure with the requested setting
   4897  */
   4898 struct MHD_ResponseOptionAndValue
   4899 MHD_R_OPTION_INSANITY_HEADER_CONTENT_LENGTH (
   4900   enum MHD_Bool value
   4901   );
   4902 
   4903 /**
   4904  * Set a function to be called once MHD is finished with the request.
   4905  * @param ended_cb the function to call,
   4906  *   NULL to not use the callback
   4907  * @param ended_cb_cls the closure for the callback
   4908  * @return structure with the requested setting
   4909  */
   4910 struct MHD_ResponseOptionAndValue
   4911 MHD_R_OPTION_TERMINATION_CALLBACK (
   4912   MHD_RequestEndedCallback ended_cb,
   4913   void *ended_cb_cls
   4914   );
   4915 
   4916 /* End of generated code documenting how to use options */
   4917 #endif
   4918 
   4919 /**
   4920  * Create parameter for #MHD_daemon_set_options() for work mode with
   4921  * no internal threads.
   4922  * The application periodically calls #MHD_daemon_process_blocking(), where
   4923  * MHD internally checks all sockets automatically.
   4924  * This is the default mode.
   4925  * @return the object of struct MHD_DaemonOptionAndValue with requested values
   4926  */
   4927 #define MHD_D_OPTION_WM_EXTERNAL_PERIODIC() \
   4928         MHD_D_OPTION_WORK_MODE (MHD_WM_OPTION_EXTERNAL_PERIODIC ())
   4929 
   4930 /**
   4931 * Create parameter for #MHD_daemon_set_options() for work mode with
   4932 * an external event loop with level triggers.
   4933 * Application uses #MHD_SocketRegistrationUpdateCallback, level triggered
   4934 * sockets polling (like select() or poll()) and #MHD_daemon_event_update().
   4935 * @param cb_val the callback for sockets registration
   4936 * @param cb_cls_val the closure for the @a cv_val callback
   4937 * @return the object of struct MHD_DaemonOptionAndValue with requested values
   4938 */
   4939 #define MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL(cb_val, cb_cls_val) \
   4940         MHD_D_OPTION_WORK_MODE ( \
   4941           MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL ((cb_val),(cb_cls_val)))
   4942 
   4943 /**
   4944  * Create parameter for #MHD_daemon_set_options() for work mode with
   4945  * an external event loop with edge triggers.
   4946  * Application uses #MHD_SocketRegistrationUpdateCallback, edge triggered
   4947  * sockets polling (like epoll with EPOLLET) and #MHD_daemon_event_update().
   4948  * @param cb_val the callback for sockets registration
   4949  * @param cb_cls_val the closure for the @a cv_val callback
   4950  * @return the object of struct MHD_DaemonOptionAndValue with requested values
   4951  */
   4952 #define MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_EDGE(cb_val, cb_cls_val) \
   4953         MHD_D_OPTION_WORK_MODE ( \
   4954           MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE ((cb_val),(cb_cls_val)))
   4955 
   4956 /**
   4957  * Create parameter for #MHD_daemon_set_options() for work mode with
   4958  * no internal threads and aggregate watch FD.
   4959  * Application uses #MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD to get single FD
   4960  * that gets triggered by any MHD event.
   4961  * This FD can be watched as an aggregate indicator for all MHD events.
   4962  * This mode is available only on selected platforms (currently
   4963  * GNU/Linux only), see #MHD_LIB_INFO_FIXED_HAS_AGGREGATE_FD.
   4964  * When the FD is triggered, #MHD_daemon_process_nonblocking() should
   4965  * be called.
   4966  * @return the object of struct MHD_DaemonOptionAndValue with requested values
   4967  */
   4968 #define MHD_D_OPTION_WM_EXTERNAL_SINGLE_FD_WATCH() \
   4969         MHD_D_OPTION_WORK_MODE (MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH ())
   4970 
   4971 /**
   4972  * Create parameter for #MHD_daemon_set_options() for work mode with
   4973  * one or more worker threads.
   4974  * If number of threads is one, then daemon starts with single worker thread
   4975  * that handles all connections.
   4976  * If number of threads is larger than one, then that number of worker threads,
   4977  * and handling of connection is distributed among the workers.
   4978  * @param num_workers the number of worker threads, zero is treated as one
   4979  * @return the object of struct MHD_DaemonOptionAndValue with requested values
   4980  */
   4981 #define MHD_D_OPTION_WM_WORKER_THREADS(num_workers) \
   4982         MHD_D_OPTION_WORK_MODE (MHD_WM_OPTION_WORKER_THREADS (num_workers))
   4983 
   4984 /**
   4985  * Create parameter for #MHD_daemon_set_options() for work mode with
   4986  * one internal thread for listening and additional threads per every
   4987  * connection.  Use this if handling requests is CPU-intensive or blocking,
   4988  * your application is thread-safe and you have plenty of memory (per
   4989  * connection).
   4990  * @return the object of struct MHD_DaemonOptionAndValue with requested values
   4991  */
   4992 #define MHD_D_OPTION_WM_THREAD_PER_CONNECTION() \
   4993         MHD_D_OPTION_WORK_MODE (MHD_WM_OPTION_THREAD_PER_CONNECTION ())
   4994 
   4995 /**
   4996  * Set the requested options for the daemon.
   4997  *
   4998  * If any option fail other options may be or may be not applied.
   4999  * @param daemon the daemon to set the options
   5000  * @param[in] options the pointer to the array with the options;
   5001  *                    the array processing stops at the first ::MHD_D_O_END
   5002  *                    option, but not later than after processing
   5003  *                    @a options_max_num entries
   5004  * @param options_max_num the maximum number of entries in the @a options,
   5005  *                        use #MHD_OPTIONS_ARRAY_MAX_SIZE if options processing
   5006  *                        must stop only at zero-termination option
   5007  * @return ::MHD_SC_OK on success,
   5008  *         error code otherwise
   5009  */
   5010 MHD_EXTERN_ enum MHD_StatusCode
   5011 MHD_daemon_set_options (
   5012   struct MHD_Daemon *MHD_RESTRICT daemon,
   5013   const struct MHD_DaemonOptionAndValue *MHD_RESTRICT options,
   5014   size_t options_max_num)
   5015 MHD_FN_PAR_NONNULL_ALL_;
   5016 
   5017 
   5018 /**
   5019  * Set the requested single option for the daemon.
   5020  *
   5021  * @param daemon the daemon to set the option
   5022  * @param[in] option_ptr the pointer to the option
   5023  * @return ::MHD_SC_OK on success,
   5024  *         error code otherwise
   5025  */
   5026 #define MHD_daemon_set_option(daemon, option_ptr) \
   5027         MHD_daemon_set_options (daemon, option_ptr, 1)
   5028 
   5029 
   5030 /* *INDENT-OFF* */
   5031 #ifdef MHD_USE_VARARG_MACROS
   5032 MHD_NOWARN_VARIADIC_MACROS_
   5033 #  if defined(MHD_USE_COMPOUND_LITERALS) && \
   5034   defined(MHD_USE_COMP_LIT_FUNC_PARAMS)
   5035 /**
   5036  * Set the requested options for the daemon.
   5037  *
   5038  * If any option fail other options may be or may be not applied.
   5039  *
   5040  * It should be used with helpers that creates required options, for example:
   5041  *
   5042  * MHD_DAEMON_SET_OPTIONS(d, MHD_D_OPTION_SUPPRESS_DATE_HEADER(MHD_YES),
   5043  *                        MHD_D_OPTION_SOCK_ADDR(sa_len, sa))
   5044  *
   5045  * @param daemon the daemon to set the options
   5046  * @param ... the list of the options, each option must be created
   5047  *            by helpers MHD_D_OPTION_NameOfOption(option_value)
   5048  * @return ::MHD_SC_OK on success,
   5049  *         error code otherwise
   5050  */
   5051 #    define MHD_DAEMON_SET_OPTIONS(daemon,...)          \
   5052             MHD_NOWARN_COMPOUND_LITERALS_                   \
   5053             MHD_NOWARN_AGGR_DYN_INIT_                       \
   5054             MHD_daemon_set_options (                        \
   5055               daemon,                                       \
   5056               ((const struct MHD_DaemonOptionAndValue[])    \
   5057                {__VA_ARGS__, MHD_D_OPTION_TERMINATE ()}),   \
   5058               MHD_OPTIONS_ARRAY_MAX_SIZE)                   \
   5059             MHD_RESTORE_WARN_AGGR_DYN_INIT_                 \
   5060             MHD_RESTORE_WARN_COMPOUND_LITERALS_
   5061 #  elif defined(MHD_USE_CPP_INIT_LIST)
   5062 MHD_C_DECLARATIONS_FINISH_HERE_
   5063 #    include <vector>
   5064 MHD_C_DECLARATIONS_START_HERE_
   5065 /**
   5066  * Set the requested options for the daemon.
   5067  *
   5068  * If any option fail other options may be or may be not applied.
   5069  *
   5070  * It should be used with helpers that creates required options, for example:
   5071  *
   5072  * MHD_DAEMON_SET_OPTIONS(d, MHD_D_OPTION_SUPPRESS_DATE_HEADER(MHD_YES),
   5073  *                        MHD_D_OPTION_SOCK_ADDR(sa_len, sa))
   5074  *
   5075  * @param daemon the daemon to set the options
   5076  * @param ... the list of the options, each option must be created
   5077  *            by helpers MHD_D_OPTION_NameOfOption(option_value)
   5078  * @return ::MHD_SC_OK on success,
   5079  *         error code otherwise
   5080  */
   5081 #    define MHD_DAEMON_SET_OPTIONS(daemon,...)                  \
   5082             MHD_NOWARN_CPP_INIT_LIST_                               \
   5083             MHD_daemon_set_options (                                \
   5084               daemon,                                               \
   5085               (std::vector<struct MHD_DaemonOptionAndValue>         \
   5086                {__VA_ARGS__,MHD_D_OPTION_TERMINATE ()}).data (),    \
   5087               MHD_OPTIONS_ARRAY_MAX_SIZE)                           \
   5088             MHD_RESTORE_WARN_CPP_INIT_LIST_
   5089 #  endif
   5090 MHD_RESTORE_WARN_VARIADIC_MACROS_
   5091 #endif /* MHD_USE_VARARG_MACROS && MHD_USE_COMP_LIT_FUNC_PARAMS */
   5092 /* *INDENT-ON* */
   5093 
   5094 
   5095 /* ******************* Event loop ************************ */
   5096 
   5097 
   5098 /**
   5099  * Run websever operation with possible blocking.
   5100  *
   5101  * Supported only in #MHD_WM_EXTERNAL_PERIODIC and
   5102  * #MHD_WM_EXTERNAL_SINGLE_FD_WATCH modes.
   5103  *
   5104  * This function does the following: waits for any network event not more than
   5105  * specified number of microseconds, processes all incoming and outgoing data,
   5106  * processes new connections, processes any timed-out connection, and does
   5107  * other things required to run webserver.
   5108  * Once all connections are processed, function returns.
   5109  *
   5110  * This function is useful for quick and simple (lazy) webserver implementation
   5111  * if application needs to run a single thread only and does not have any other
   5112  * network activity.
   5113  *
   5114  * In #MHD_WM_EXTERNAL_PERIODIC mode if @a microsec parameter is not zero
   5115  * this function determines the internal daemon timeout and use returned value
   5116  * as maximum wait time if it less than value of @a microsec parameter.
   5117  *
   5118  * @param daemon the daemon to run
   5119  * @param microsec the maximum time in microseconds to wait for network and
   5120  *                 other events. Note: there is no guarantee that function
   5121  *                 blocks for the specified amount of time. The real processing
   5122  *                 time can be shorter (if some data or connection timeout
   5123  *                 comes earlier) or longer (if data processing requires more
   5124  *                 time, especially in user callbacks).
   5125  *                 If set to '0' then function does not block and processes
   5126  *                 only already available data (if any). Zero value is
   5127  *                 recommended when used in #MHD_WM_EXTERNAL_SINGLE_FD_WATCH
   5128  *                 and the watched FD has been triggered.
   5129  *                 If set to #MHD_WAIT_INDEFINITELY then function waits
   5130  *                 for events indefinitely (blocks until next network activity
   5131  *                 or connection timeout).
   5132  *                 Always used as zero value in
   5133  *                 #MHD_WM_EXTERNAL_SINGLE_FD_WATCH mode.
   5134  * @return #MHD_SC_OK on success, otherwise
   5135  *         an error code
   5136  * @ingroup event
   5137  */
   5138 MHD_EXTERN_ enum MHD_StatusCode
   5139 MHD_daemon_process_blocking (struct MHD_Daemon *daemon,
   5140                              uint_fast64_t microsec)
   5141 MHD_FN_PAR_NONNULL_ (1);
   5142 
   5143 /**
   5144  * Run webserver operations (without blocking unless in client
   5145  * callbacks).
   5146  *
   5147  * Supported only in #MHD_WM_EXTERNAL_SINGLE_FD_WATCH mode.
   5148  *
   5149  * This function does the following: processes all incoming and outgoing data,
   5150  * processes new connections, processes any timed-out connection, and does
   5151  * other things required to run webserver.
   5152  * Once all connections are processed, function returns.
   5153  *
   5154  * @param daemon the daemon to run
   5155  * @return #MHD_SC_OK on success, otherwise
   5156  *         an error code
   5157  * @ingroup event
   5158  */
   5159 #define MHD_daemon_process_nonblocking(daemon) \
   5160         MHD_daemon_process_blocking (daemon, 0)
   5161 
   5162 
   5163 /**
   5164  * Add another client connection to the set of connections managed by
   5165  * MHD.  This API is usually not needed (since MHD will accept inbound
   5166  * connections on the server socket).  Use this API in special cases,
   5167  * for example if your HTTP server is behind NAT and needs to connect
   5168  * out to the HTTP client, or if you are building a proxy.
   5169  *
   5170  * The given client socket will be managed (and closed!) by MHD after
   5171  * this call and must no longer be used directly by the application
   5172  * afterwards.
   5173  * The client socket will be closed by MHD even if error returned.
   5174  *
   5175  * @param daemon daemon that manages the connection
   5176  * @param new_socket socket to manage (MHD will expect to receive an
   5177                      HTTP request from this socket next).
   5178  * @param addr_size number of bytes in @a addr
   5179  * @param addr IP address of the client, ignored when @a addrlen is zero
   5180  * @param connection_cntx meta data the application wants to
   5181  *        associate with the new connection object
   5182  * @return #MHD_SC_OK on success,
   5183  *         error on failure (the @a new_socket is closed)
   5184  * @ingroup specialized
   5185  */
   5186 MHD_EXTERN_ enum MHD_StatusCode
   5187 MHD_daemon_add_connection (struct MHD_Daemon *MHD_RESTRICT daemon,
   5188                            MHD_Socket new_socket,
   5189                            size_t addr_size,
   5190                            const struct sockaddr *MHD_RESTRICT addr,
   5191                            void *connection_cntx)
   5192 MHD_FN_PAR_NONNULL_ (1)
   5193 MHD_FN_PAR_IN_ (4);
   5194 
   5195 
   5196 /* ********************* connection options ************** */
   5197 
   5198 enum MHD_FIXED_ENUM_APP_SET_ MHD_ConnectionOption
   5199 {
   5200   /**
   5201    * Not a real option.
   5202    * Should not be used directly.
   5203    * This value indicates the end of the list of the options.
   5204    */
   5205   MHD_C_O_END = 0
   5206   ,
   5207   /**
   5208    * Set custom timeout for the given connection.
   5209    * Specified as the number of seconds.  Use zero for no timeout.
   5210    * Setting this option resets connection timeout timer.
   5211    */
   5212   MHD_C_O_TIMEOUT = 1
   5213   ,
   5214 
   5215 
   5216   /* * Sentinel * */
   5217   /**
   5218    * The sentinel value.
   5219    * This value enforces specific underlying integer type for the enum.
   5220    * Do not use.
   5221    */
   5222   MHD_C_O_SENTINEL = 65535
   5223 };
   5224 
   5225 
   5226 /**
   5227  * Dummy-struct for space allocation.
   5228  * Do not use in application logic.
   5229  */
   5230 struct MHD_ReservedStruct
   5231 {
   5232   uint_fast64_t reserved1;
   5233   void *reserved2;
   5234 };
   5235 
   5236 
   5237 /**
   5238  * Parameters for MHD connection options
   5239  */
   5240 union MHD_ConnectionOptionValue
   5241 {
   5242   /**
   5243    * Value for #MHD_C_O_TIMEOUT
   5244    */
   5245   unsigned int v_timeout;
   5246   /**
   5247    * Reserved member. Do not use.
   5248    */
   5249   struct MHD_ReservedStruct reserved;
   5250 };
   5251 
   5252 /**
   5253  * Combination of MHD connection option with parameters values
   5254  */
   5255 struct MHD_ConnectionOptionAndValue
   5256 {
   5257   /**
   5258    * The connection configuration option
   5259    */
   5260   enum MHD_ConnectionOption opt;
   5261   /**
   5262    * The value for the @a opt option
   5263    */
   5264   union MHD_ConnectionOptionValue val;
   5265 };
   5266 
   5267 #if defined(MHD_USE_COMPOUND_LITERALS) && defined(MHD_USE_DESIG_NEST_INIT)
   5268 /**
   5269  * Set custom timeout for the given connection.
   5270  * Specified as the number of seconds.  Use zero for no timeout.
   5271  * Setting this option resets connection timeout timer.
   5272  * @param timeout the in seconds, zero for no timeout
   5273  * @return the object of struct MHD_ConnectionOptionAndValue with the requested
   5274  *         values
   5275  */
   5276 #  define MHD_C_OPTION_TIMEOUT(timeout)         \
   5277           MHD_NOWARN_COMPOUND_LITERALS_                 \
   5278             (const struct MHD_ConnectionOptionAndValue) \
   5279           {                                             \
   5280             .opt = (MHD_C_O_TIMEOUT),                   \
   5281             .val.v_timeout = (timeout)                  \
   5282           }                                             \
   5283           MHD_RESTORE_WARN_COMPOUND_LITERALS_
   5284 
   5285 /**
   5286  * Terminate the list of the options
   5287  * @return the terminating object of struct MHD_ConnectionOptionAndValue
   5288  */
   5289 #  define MHD_C_OPTION_TERMINATE()              \
   5290           MHD_NOWARN_COMPOUND_LITERALS_                 \
   5291             (const struct MHD_ConnectionOptionAndValue) \
   5292           {                                             \
   5293             .opt = (MHD_C_O_END)                        \
   5294           }                                             \
   5295           MHD_RESTORE_WARN_COMPOUND_LITERALS_
   5296 
   5297 #else  /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */
   5298 MHD_NOWARN_UNUSED_FUNC_
   5299 
   5300 /**
   5301  * Set custom timeout for the given connection.
   5302  * Specified as the number of seconds.  Use zero for no timeout.
   5303  * Setting this option resets connection timeout timer.
   5304  * @param timeout the in seconds, zero for no timeout
   5305  * @return the object of struct MHD_ConnectionOptionAndValue with the requested
   5306  *         values
   5307  */
   5308 static MHD_INLINE struct MHD_ConnectionOptionAndValue
   5309 MHD_C_OPTION_TIMEOUT (unsigned int timeout)
   5310 {
   5311   struct MHD_ConnectionOptionAndValue opt_val;
   5312 
   5313   opt_val.opt = MHD_C_O_TIMEOUT;
   5314   opt_val.val.v_timeout = timeout;
   5315 
   5316   return opt_val;
   5317 }
   5318 
   5319 
   5320 /**
   5321  * Terminate the list of the options
   5322  * @return the terminating object of struct MHD_ConnectionOptionAndValue
   5323  */
   5324 static MHD_INLINE struct MHD_ConnectionOptionAndValue
   5325 MHD_C_OPTION_TERMINATE (void)
   5326 {
   5327   struct MHD_ConnectionOptionAndValue opt_val;
   5328 
   5329   opt_val.opt = MHD_C_O_END;
   5330 
   5331   return opt_val;
   5332 }
   5333 
   5334 
   5335 MHD_RESTORE_WARN_UNUSED_FUNC_
   5336 #endif /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */
   5337 
   5338 /**
   5339  * Set the requested options for the connection.
   5340  *
   5341  * If any option fail other options may be or may be not applied.
   5342  * @param connection the connection to set the options
   5343  * @param[in] options the pointer to the array with the options;
   5344  *                    the array processing stops at the first ::MHD_D_O_END
   5345  *                    option, but not later than after processing
   5346  *                    @a options_max_num entries
   5347  * @param options_max_num the maximum number of entries in the @a options,
   5348  *                        use #MHD_OPTIONS_ARRAY_MAX_SIZE if options processing
   5349  *                        must stop only at zero-termination option
   5350  * @return ::MHD_SC_OK on success,
   5351  *         error code otherwise
   5352  */
   5353 MHD_EXTERN_ enum MHD_StatusCode
   5354 MHD_connection_set_options (
   5355   struct MHD_Connection *MHD_RESTRICT connection,
   5356   const struct MHD_ConnectionOptionAndValue *MHD_RESTRICT options,
   5357   size_t options_max_num)
   5358 MHD_FN_PAR_NONNULL_ALL_;
   5359 
   5360 
   5361 /**
   5362  * Set the requested single option for the connection.
   5363  *
   5364  * @param connection the connection to set the options
   5365  * @param[in] option_ptr the pointer to the option
   5366  * @return ::MHD_SC_OK on success,
   5367  *         error code otherwise
   5368  */
   5369 #define MHD_connection_set_option(connection, option_ptr) \
   5370         MHD_connection_set_options (connection, options_ptr, 1)
   5371 
   5372 
   5373 /* *INDENT-OFF* */
   5374 #ifdef MHD_USE_VARARG_MACROS
   5375 MHD_NOWARN_VARIADIC_MACROS_
   5376 #  if defined(MHD_USE_COMPOUND_LITERALS) && defined(MHD_USE_COMP_LIT_FUNC_PARAMS \
   5377                                                     )
   5378 /**
   5379  * Set the requested options for the connection.
   5380  *
   5381  * If any option fail other options may be or may be not applied.
   5382  *
   5383  * It should be used with helpers that creates required options, for example:
   5384  *
   5385  * MHD_CONNECTION_SET_OPTIONS(d, MHD_C_OPTION_TIMEOUT(30))
   5386  *
   5387  * @param connection the connection to set the options
   5388  * @param ... the list of the options, each option must be created
   5389  *            by helpers MHD_C_OPTION_NameOfOption(option_value)
   5390  * @return ::MHD_SC_OK on success,
   5391  *         error code otherwise
   5392  */
   5393 #    define MHD_CONNECTION_SET_OPTIONS(connection,...)          \
   5394             MHD_NOWARN_COMPOUND_LITERALS_                           \
   5395             MHD_connection_set_options (                            \
   5396               daemon,                                               \
   5397               ((const struct MHD_ConnectionOptionAndValue [])       \
   5398                {__VA_ARGS__, MHD_C_OPTION_TERMINATE ()}),           \
   5399               MHD_OPTIONS_ARRAY_MAX_SIZE)                           \
   5400             MHD_RESTORE_WARN_COMPOUND_LITERALS_
   5401 #  elif defined(MHD_USE_CPP_INIT_LIST)
   5402 MHD_C_DECLARATIONS_FINISH_HERE_
   5403 #    include <vector>
   5404 MHD_C_DECLARATIONS_START_HERE_
   5405 /**
   5406  * Set the requested options for the connection.
   5407  *
   5408  * If any option fail other options may be or may be not applied.
   5409  *
   5410  * It should be used with helpers that creates required options, for example:
   5411  *
   5412  * MHD_CONNECTION_SET_OPTIONS(d, MHD_C_OPTION_TIMEOUT(30))
   5413  *
   5414  * @param connection the connection to set the options
   5415  * @param ... the list of the options, each option must be created
   5416  *            by helpers MHD_C_OPTION_NameOfOption(option_value)
   5417  * @return ::MHD_SC_OK on success,
   5418  *         error code otherwise
   5419  */
   5420 #    define MHD_CONNECTION_SET_OPTIONS(daemon,...)              \
   5421             MHD_NOWARN_CPP_INIT_LIST_                               \
   5422             MHD_daemon_set_options (                                \
   5423               daemon,                                               \
   5424               (std::vector<struct MHD_ConnectionOptionAndValue>     \
   5425                {__VA_ARGS__,MHD_C_OPTION_TERMINATE ()}).data (),    \
   5426               MHD_OPTIONS_ARRAY_MAX_SIZE)                           \
   5427             MHD_RESTORE_WARN_CPP_INIT_LIST_
   5428 #  endif
   5429 MHD_RESTORE_WARN_VARIADIC_MACROS_
   5430 #endif /* MHD_USE_VARARG_MACROS && MHD_USE_COMP_LIT_FUNC_PARAMS */
   5431 /* *INDENT-ON* */
   5432 
   5433 
   5434 /* **************** Request handling functions ***************** */
   5435 
   5436 
   5437 /**
   5438  * The `enum MHD_ValueKind` specifies the source of
   5439  * the name-value pairs in the HTTP protocol.
   5440  */
   5441 enum MHD_FLAGS_ENUM_ MHD_ValueKind
   5442 {
   5443 
   5444   /**
   5445    * HTTP header.
   5446    * The 'value' for this kind is mandatory.
   5447    */
   5448   MHD_VK_HEADER = (1u << 0)
   5449   ,
   5450   /**
   5451    * Cookies.  Note that the original HTTP header containing
   5452    * the cookie(s) will still be available and intact.
   5453    * The 'value' for this kind is optional.
   5454    */
   5455   MHD_VK_COOKIE = (1u << 1)
   5456   ,
   5457   /**
   5458    * URI query parameter.
   5459    * The 'value' for this kind is optional.
   5460    */
   5461   MHD_VK_URI_QUERY_PARAM = (1u << 2)
   5462   ,
   5463   /**
   5464    * POST data.
   5465    * This is available only if #MHD_action_parse_post() action is used,
   5466    * a content encoding is supported by MHD, and only if the posted content
   5467    * fits within the specified memory buffers.
   5468    *
   5469    * @warning The encoding "multipart/form-data" has more fields than just
   5470    * "name" and "value". See #MHD_request_get_post_data_cb() and
   5471    * #MHD_request_get_post_data_list(). In particular it could be important
   5472    * to check used "Transfer-Encoding". While it is deprecated and not used
   5473    * by modern clients, formally it can be used.
   5474    */
   5475   MHD_VK_POSTDATA = (1u << 3)
   5476   ,
   5477   /**
   5478    * HTTP trailer (only for HTTP 1.1 chunked encodings, "footer").
   5479    * The 'value' for this kind is mandatory.
   5480    */
   5481   MHD_VK_TRAILER = (1u << 4)
   5482   ,
   5483   /**
   5484    * Header and trailer values.
   5485    */
   5486   MHD_VK_HEADER_TRAILER = MHD_VK_HEADER | MHD_VK_TRAILER
   5487   ,
   5488   /**
   5489    * Values from URI query parameters or post data.
   5490    */
   5491   MHD_VK_URI_QUERY_POST = MHD_VK_POSTDATA | MHD_VK_URI_QUERY_PARAM
   5492 };
   5493 
   5494 /**
   5495  * Name with value pair
   5496  */
   5497 struct MHD_NameAndValue
   5498 {
   5499   /**
   5500    * The name (key) of the field.
   5501    * The pointer to the C string must never be NULL.
   5502    * Some types (kinds) allow empty strings.
   5503    */
   5504   struct MHD_String name;
   5505   /**
   5506    * The value of the field.
   5507    * Some types (kinds) allow absence of the value. The absence is indicated
   5508    * by NULL pointer to the C string.
   5509    */
   5510   struct MHD_StringNullable value;
   5511 };
   5512 
   5513 /**
   5514  * Name, value and kind (type) of data
   5515  */
   5516 struct MHD_NameValueKind
   5517 {
   5518   /**
   5519    * The name and the value of the field
   5520    */
   5521   struct MHD_NameAndValue nv;
   5522   /**
   5523    * The kind (type) of the field
   5524    */
   5525   enum MHD_ValueKind kind;
   5526 };
   5527 
   5528 /**
   5529  * Iterator over name-value pairs.  This iterator can be used to
   5530  * iterate over all of the cookies, headers, footers or POST-data fields
   5531  * of a request.
   5532  *
   5533  * The @a nv pointer is valid only until return from this function.
   5534  *
   5535  * The strings in @a nv are valid until any MHD_Action or MHD_UploadAction
   5536  * is provided.
   5537  * If the data is needed beyond this point, it should be copied.
   5538  *
   5539  * @param cls closure
   5540  * @param nv the name and the value of the element, the pointer is valid only until
   5541  *           return from this function
   5542  * @param kind the type (kind) of the element
   5543  * @return #MHD_YES to continue iterating,
   5544  *         #MHD_NO to abort the iteration
   5545  * @ingroup request
   5546  */
   5547 typedef enum MHD_Bool
   5548 (MHD_FN_PAR_NONNULL_ (3)
   5549  *MHD_NameValueIterator)(void *cls,
   5550                          enum MHD_ValueKind kind,
   5551                          const struct MHD_NameAndValue *nv);
   5552 
   5553 
   5554 /**
   5555  * Get all of the headers (or other kind of request data) via callback.
   5556  *
   5557  * @param[in,out] request request to get values from
   5558  * @param kind types of values to iterate over, can be a bitmask
   5559  * @param iterator callback to call on each header;
   5560  *        maybe NULL (then just count headers)
   5561  * @param iterator_cls extra argument to @a iterator
   5562  * @return number of entries iterated over
   5563  * @ingroup request
   5564  */
   5565 MHD_EXTERN_ size_t
   5566 MHD_request_get_values_cb (struct MHD_Request *request,
   5567                            enum MHD_ValueKind kind,
   5568                            MHD_NameValueIterator iterator,
   5569                            void *iterator_cls)
   5570 MHD_FN_PAR_NONNULL_ (1);
   5571 
   5572 
   5573 /**
   5574  * Get all of the headers (or other kind of request data) from the request.
   5575  *
   5576  * The pointers to the strings in @a elements are valid until any
   5577  * MHD_Action or MHD_UploadAction is provided. If the data is needed beyond
   5578  * this point, it should be copied.
   5579  *
   5580  * @param[in] request request to get values from
   5581  * @param kind the types of values to get, can be a bitmask
   5582  * @param num_elements the number of elements in @a elements array
   5583  * @param[out] elements the array of @a num_elements strings to be filled with
   5584  *                      the key-value pairs; if @a request has more elements
   5585  *                      than @a num_elements than any @a num_elements are
   5586  *                      stored
   5587  * @return the number of elements stored in @a elements, the
   5588  *         number cannot be larger then @a num_elements,
   5589  *         zero if there is no such values or any error occurs
   5590  */
   5591 MHD_EXTERN_ size_t
   5592 MHD_request_get_values_list (
   5593   struct MHD_Request *request,
   5594   enum MHD_ValueKind kind,
   5595   size_t num_elements,
   5596   struct MHD_NameValueKind elements[MHD_FN_PAR_DYN_ARR_SIZE_ (num_elements)])
   5597 MHD_FN_PAR_NONNULL_ (1)
   5598 MHD_FN_PAR_NONNULL_ (4) MHD_FN_PAR_OUT_SIZE_ (4, 3);
   5599 
   5600 
   5601 /**
   5602  * Get a particular header (or other kind of request data) value.
   5603  * If multiple values match the kind, return any one of them.
   5604  *
   5605  * The data in the @a value_out is valid until any MHD_Action or
   5606  * MHD_UploadAction is provided. If the data is needed beyond this point,
   5607  * it should be copied.
   5608  *
   5609  * @param request request to get values from
   5610  * @param kind what kind of value are we looking for
   5611  * @param key the name of the value looking for (used for case-insensetive
   5612  *            match), empty to lookup 'trailing' value without a key
   5613  * @param[out] value_out set to the value of the header if succeed,
   5614  *                       the @a cstr pointer could be NULL even if succeed
   5615  *                       if the requested item found, but has no value
   5616  * @return #MHD_YES if succeed, the @a value_out is set;
   5617  *         #MHD_NO if no such item was found, the @a value_out string pointer
   5618  *                 set to NULL
   5619  * @ingroup request
   5620  */
   5621 MHD_EXTERN_ enum MHD_Bool
   5622 MHD_request_get_value (struct MHD_Request *MHD_RESTRICT request,
   5623                        enum MHD_ValueKind kind,
   5624                        const char *MHD_RESTRICT key,
   5625                        struct MHD_StringNullable *MHD_RESTRICT value_out)
   5626 MHD_FN_PAR_NONNULL_ (1)
   5627 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_CSTR_ (3)
   5628 MHD_FN_PAR_OUT_ (4);
   5629 
   5630 
   5631 /**
   5632  * @brief Status codes defined for HTTP responses.
   5633  *
   5634  * @defgroup httpcode HTTP response codes
   5635  * @{
   5636  */
   5637 /* Registry export date: 2023-09-29 */
   5638 /* See http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml */
   5639 enum MHD_FIXED_ENUM_APP_SET_ MHD_HTTP_StatusCode
   5640 {
   5641   /* 100 "Continue".            RFC9110, Section 15.2.1. */
   5642   MHD_HTTP_STATUS_CONTINUE =                    100
   5643   ,
   5644   /* 101 "Switching Protocols". RFC9110, Section 15.2.2. */
   5645   MHD_HTTP_STATUS_SWITCHING_PROTOCOLS =         101
   5646   ,
   5647   /* 102 "Processing".          RFC2518. */
   5648   MHD_HTTP_STATUS_PROCESSING =                  102
   5649   ,
   5650   /* 103 "Early Hints".         RFC8297. */
   5651   MHD_HTTP_STATUS_EARLY_HINTS =                 103
   5652   ,
   5653 
   5654   /* 200 "OK".                  RFC9110, Section 15.3.1. */
   5655   MHD_HTTP_STATUS_OK =                          200
   5656   ,
   5657   /* 201 "Created".             RFC9110, Section 15.3.2. */
   5658   MHD_HTTP_STATUS_CREATED =                     201
   5659   ,
   5660   /* 202 "Accepted".            RFC9110, Section 15.3.3. */
   5661   MHD_HTTP_STATUS_ACCEPTED =                    202
   5662   ,
   5663   /* 203 "Non-Authoritative Information". RFC9110, Section 15.3.4. */
   5664   MHD_HTTP_STATUS_NON_AUTHORITATIVE_INFORMATION = 203
   5665   ,
   5666   /* 204 "No Content".          RFC9110, Section 15.3.5. */
   5667   MHD_HTTP_STATUS_NO_CONTENT =                  204
   5668   ,
   5669   /* 205 "Reset Content".       RFC9110, Section 15.3.6. */
   5670   MHD_HTTP_STATUS_RESET_CONTENT =               205
   5671   ,
   5672   /* 206 "Partial Content".     RFC9110, Section 15.3.7. */
   5673   MHD_HTTP_STATUS_PARTIAL_CONTENT =             206
   5674   ,
   5675   /* 207 "Multi-Status".        RFC4918. */
   5676   MHD_HTTP_STATUS_MULTI_STATUS =                207
   5677   ,
   5678   /* 208 "Already Reported".    RFC5842. */
   5679   MHD_HTTP_STATUS_ALREADY_REPORTED =            208
   5680   ,
   5681 
   5682   /* 226 "IM Used".             RFC3229. */
   5683   MHD_HTTP_STATUS_IM_USED =                     226
   5684   ,
   5685 
   5686   /* 300 "Multiple Choices".    RFC9110, Section 15.4.1. */
   5687   MHD_HTTP_STATUS_MULTIPLE_CHOICES =            300
   5688   ,
   5689   /* 301 "Moved Permanently".   RFC9110, Section 15.4.2. */
   5690   MHD_HTTP_STATUS_MOVED_PERMANENTLY =           301
   5691   ,
   5692   /* 302 "Found".               RFC9110, Section 15.4.3. */
   5693   MHD_HTTP_STATUS_FOUND =                       302
   5694   ,
   5695   /* 303 "See Other".           RFC9110, Section 15.4.4. */
   5696   MHD_HTTP_STATUS_SEE_OTHER =                   303
   5697   ,
   5698   /* 304 "Not Modified".        RFC9110, Section 15.4.5. */
   5699   MHD_HTTP_STATUS_NOT_MODIFIED =                304
   5700   ,
   5701   /* 305 "Use Proxy".           RFC9110, Section 15.4.6. */
   5702   MHD_HTTP_STATUS_USE_PROXY =                   305
   5703   ,
   5704   /* 306 "Switch Proxy".        Not used! RFC9110, Section 15.4.7. */
   5705   MHD_HTTP_STATUS_SWITCH_PROXY =                306
   5706   ,
   5707   /* 307 "Temporary Redirect".  RFC9110, Section 15.4.8. */
   5708   MHD_HTTP_STATUS_TEMPORARY_REDIRECT =          307
   5709   ,
   5710   /* 308 "Permanent Redirect".  RFC9110, Section 15.4.9. */
   5711   MHD_HTTP_STATUS_PERMANENT_REDIRECT =          308
   5712   ,
   5713 
   5714   /* 400 "Bad Request".         RFC9110, Section 15.5.1. */
   5715   MHD_HTTP_STATUS_BAD_REQUEST =                 400
   5716   ,
   5717   /* 401 "Unauthorized".        RFC9110, Section 15.5.2. */
   5718   MHD_HTTP_STATUS_UNAUTHORIZED =                401
   5719   ,
   5720   /* 402 "Payment Required".    RFC9110, Section 15.5.3. */
   5721   MHD_HTTP_STATUS_PAYMENT_REQUIRED =            402
   5722   ,
   5723   /* 403 "Forbidden".           RFC9110, Section 15.5.4. */
   5724   MHD_HTTP_STATUS_FORBIDDEN =                   403
   5725   ,
   5726   /* 404 "Not Found".           RFC9110, Section 15.5.5. */
   5727   MHD_HTTP_STATUS_NOT_FOUND =                   404
   5728   ,
   5729   /* 405 "Method Not Allowed".  RFC9110, Section 15.5.6. */
   5730   MHD_HTTP_STATUS_METHOD_NOT_ALLOWED =          405
   5731   ,
   5732   /* 406 "Not Acceptable".      RFC9110, Section 15.5.7. */
   5733   MHD_HTTP_STATUS_NOT_ACCEPTABLE =              406
   5734   ,
   5735   /* 407 "Proxy Authentication Required". RFC9110, Section 15.5.8. */
   5736   MHD_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED = 407
   5737   ,
   5738   /* 408 "Request Timeout".     RFC9110, Section 15.5.9. */
   5739   MHD_HTTP_STATUS_REQUEST_TIMEOUT =             408
   5740   ,
   5741   /* 409 "Conflict".            RFC9110, Section 15.5.10. */
   5742   MHD_HTTP_STATUS_CONFLICT =                    409
   5743   ,
   5744   /* 410 "Gone".                RFC9110, Section 15.5.11. */
   5745   MHD_HTTP_STATUS_GONE =                        410
   5746   ,
   5747   /* 411 "Length Required".     RFC9110, Section 15.5.12. */
   5748   MHD_HTTP_STATUS_LENGTH_REQUIRED =             411
   5749   ,
   5750   /* 412 "Precondition Failed". RFC9110, Section 15.5.13. */
   5751   MHD_HTTP_STATUS_PRECONDITION_FAILED =         412
   5752   ,
   5753   /* 413 "Content Too Large".   RFC9110, Section 15.5.14. */
   5754   MHD_HTTP_STATUS_CONTENT_TOO_LARGE =           413
   5755   ,
   5756   /* 414 "URI Too Long".        RFC9110, Section 15.5.15. */
   5757   MHD_HTTP_STATUS_URI_TOO_LONG =                414
   5758   ,
   5759   /* 415 "Unsupported Media Type". RFC9110, Section 15.5.16. */
   5760   MHD_HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE =      415
   5761   ,
   5762   /* 416 "Range Not Satisfiable". RFC9110, Section 15.5.17. */
   5763   MHD_HTTP_STATUS_RANGE_NOT_SATISFIABLE =       416
   5764   ,
   5765   /* 417 "Expectation Failed".  RFC9110, Section 15.5.18. */
   5766   MHD_HTTP_STATUS_EXPECTATION_FAILED =          417
   5767   ,
   5768 
   5769 
   5770   /* 421 "Misdirected Request". RFC9110, Section 15.5.20. */
   5771   MHD_HTTP_STATUS_MISDIRECTED_REQUEST =         421
   5772   ,
   5773   /* 422 "Unprocessable Content". RFC9110, Section 15.5.21. */
   5774   MHD_HTTP_STATUS_UNPROCESSABLE_CONTENT =       422
   5775   ,
   5776   /* 423 "Locked".              RFC4918. */
   5777   MHD_HTTP_STATUS_LOCKED =                      423
   5778   ,
   5779   /* 424 "Failed Dependency".   RFC4918. */
   5780   MHD_HTTP_STATUS_FAILED_DEPENDENCY =           424
   5781   ,
   5782   /* 425 "Too Early".           RFC8470. */
   5783   MHD_HTTP_STATUS_TOO_EARLY =                   425
   5784   ,
   5785   /* 426 "Upgrade Required".    RFC9110, Section 15.5.22. */
   5786   MHD_HTTP_STATUS_UPGRADE_REQUIRED =            426
   5787   ,
   5788 
   5789   /* 428 "Precondition Required". RFC6585. */
   5790   MHD_HTTP_STATUS_PRECONDITION_REQUIRED =       428
   5791   ,
   5792   /* 429 "Too Many Requests".   RFC6585. */
   5793   MHD_HTTP_STATUS_TOO_MANY_REQUESTS =           429
   5794   ,
   5795 
   5796   /* 431 "Request Header Fields Too Large". RFC6585. */
   5797   MHD_HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE = 431
   5798   ,
   5799 
   5800   /* 451 "Unavailable For Legal Reasons". RFC7725. */
   5801   MHD_HTTP_STATUS_UNAVAILABLE_FOR_LEGAL_REASONS = 451
   5802   ,
   5803 
   5804   /* 500 "Internal Server Error". RFC9110, Section 15.6.1. */
   5805   MHD_HTTP_STATUS_INTERNAL_SERVER_ERROR =       500
   5806   ,
   5807   /* 501 "Not Implemented".     RFC9110, Section 15.6.2. */
   5808   MHD_HTTP_STATUS_NOT_IMPLEMENTED =             501
   5809   ,
   5810   /* 502 "Bad Gateway".         RFC9110, Section 15.6.3. */
   5811   MHD_HTTP_STATUS_BAD_GATEWAY =                 502
   5812   ,
   5813   /* 503 "Service Unavailable". RFC9110, Section 15.6.4. */
   5814   MHD_HTTP_STATUS_SERVICE_UNAVAILABLE =         503
   5815   ,
   5816   /* 504 "Gateway Timeout".     RFC9110, Section 15.6.5. */
   5817   MHD_HTTP_STATUS_GATEWAY_TIMEOUT =             504
   5818   ,
   5819   /* 505 "HTTP Version Not Supported". RFC9110, Section 15.6.6. */
   5820   MHD_HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED =  505
   5821   ,
   5822   /* 506 "Variant Also Negotiates". RFC2295. */
   5823   MHD_HTTP_STATUS_VARIANT_ALSO_NEGOTIATES =     506
   5824   ,
   5825   /* 507 "Insufficient Storage". RFC4918. */
   5826   MHD_HTTP_STATUS_INSUFFICIENT_STORAGE =        507
   5827   ,
   5828   /* 508 "Loop Detected".       RFC5842. */
   5829   MHD_HTTP_STATUS_LOOP_DETECTED =               508
   5830   ,
   5831 
   5832   /* 510 "Not Extended".        (OBSOLETED) RFC2774; status-change-http-experiments-to-historic. */
   5833   MHD_HTTP_STATUS_NOT_EXTENDED =                510
   5834   ,
   5835   /* 511 "Network Authentication Required". RFC6585. */
   5836   MHD_HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED = 511
   5837   ,
   5838 
   5839 
   5840   /* Not registered non-standard codes */
   5841   /* 449 "Reply With".          MS IIS extension. */
   5842   MHD_HTTP_STATUS_RETRY_WITH =                  449
   5843   ,
   5844 
   5845   /* 450 "Blocked by Windows Parental Controls". MS extension. */
   5846   MHD_HTTP_STATUS_BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS = 450
   5847   ,
   5848 
   5849   /* 509 "Bandwidth Limit Exceeded". Apache extension. */
   5850   MHD_HTTP_STATUS_BANDWIDTH_LIMIT_EXCEEDED =    509
   5851 };
   5852 
   5853 
   5854 /**
   5855  * Returns the string status for a response code.
   5856  *
   5857  * This function works for @b HTTP status code, not for @b MHD error codes/
   5858  * @param code the HTTP code to get text representation for
   5859  * @return the pointer to the text representation,
   5860  *         NULL if HTTP status code in not known.
   5861  */
   5862 MHD_EXTERN_ const struct MHD_String *
   5863 MHD_HTTP_status_code_to_string (enum MHD_HTTP_StatusCode code)
   5864 MHD_FN_CONST_;
   5865 
   5866 /**
   5867  * Get the pointer to the C string for the HTTP response code, never NULL.
   5868  */
   5869 #define MHD_HTTP_status_code_to_string_lazy(code) \
   5870         (MHD_HTTP_status_code_to_string ((code)) ? \
   5871          ((MHD_HTTP_status_code_to_string (code))->cstr) : ("[No status]") )
   5872 
   5873 
   5874 /** @} */ /* end of group httpcode */
   5875 
   5876 #ifndef MHD_HTTP_PROTOCOL_VER_DEFINED
   5877 
   5878 /**
   5879  * @brief HTTP protocol versions
   5880  * @defgroup versions HTTP versions
   5881  * @{
   5882  */
   5883 enum MHD_FIXED_ENUM_MHD_SET_ MHD_HTTP_ProtocolVersion
   5884 {
   5885   MHD_HTTP_VERSION_INVALID = 0  /**< Invalid/unrecognised HTTP version */
   5886   ,
   5887   MHD_HTTP_VERSION_1_0 = 10     /**< HTTP/1.0 */
   5888   ,
   5889   MHD_HTTP_VERSION_1_1 = 11     /**< HTTP/1.1 */
   5890   ,
   5891   MHD_HTTP_VERSION_1_2P = 19    /**< HTTP/1.2 - HTTP/1.9 */
   5892   ,
   5893   MHD_HTTP_VERSION_2 = 20       /**< HTTP/2 */
   5894   ,
   5895   MHD_HTTP_VERSION_3 = 30       /**< HTTP/3 */
   5896   ,
   5897   MHD_HTTP_VERSION_FUTURE = 255 /**< Future HTTP version */
   5898 };
   5899 
   5900 #  define MHD_HTTP_PROTOCOL_VER_DEFINED 1
   5901 #endif /* ! MHD_HTTP_PROTOCOL_VER_DEFINED */
   5902 
   5903 /**
   5904  * Return the string representation of the requested HTTP version.
   5905  * Note: this is suitable mainly for logging and similar purposes as
   5906  * HTTP/2 (and later) is not used inside the HTTP protocol.
   5907  * @param pv the protocol version
   5908  * @return the string representation of the protocol version,
   5909  *         NULL for invalid values
   5910  */
   5911 MHD_EXTERN_ const struct MHD_String *
   5912 MHD_protocol_version_to_string (enum MHD_HTTP_ProtocolVersion pv)
   5913 MHD_FN_CONST_;
   5914 
   5915 /**
   5916  * HTTP/1.0 identification string
   5917  */
   5918 #define MHD_HTTP_VERSION_1_0_STR "HTTP/1.0"
   5919 /**
   5920  * HTTP/1.1 identification string
   5921  */
   5922 #define MHD_HTTP_VERSION_1_1_STR "HTTP/1.1"
   5923 /**
   5924  * Identification string for clients claiming HTTP/1.2 - HTTP/1.9
   5925  * Not used by the HTTP protocol, useful for logs and similar purposes.
   5926  */
   5927 #define MHD_HTTP_VERSION_1_2P_STR "HTTP/1.2+"
   5928 /**
   5929  * HTTP/2 identification string.
   5930  * Not used by the HTTP protocol (except non-TLS handshake), useful for logs and
   5931  * similar purposes.
   5932  */
   5933 #define MHD_HTTP_VERSION_2_STR "HTTP/2"
   5934 /**
   5935  * HTTP/3 identification string.
   5936  * Not used by the HTTP protocol, useful for logs and similar purposes.
   5937  */
   5938 #define MHD_HTTP_VERSION_3_STR "HTTP/3"
   5939 
   5940 /** @} */ /* end of group versions */
   5941 
   5942 
   5943 /**
   5944  * Resume handling of network data for suspended request.
   5945  * It is safe to resume a suspended request at any time.
   5946  * Calling this function on a request that was not previously suspended will
   5947  * result in undefined behaviour.
   5948  *
   5949  * @param[in,out] request the request to resume
   5950  */
   5951 MHD_EXTERN_ void
   5952 MHD_request_resume (struct MHD_Request *request)
   5953 MHD_FN_PAR_NONNULL_ALL_;
   5954 
   5955 
   5956 /* ************** Action and Response manipulation functions **************** */
   5957 
   5958 /**
   5959  * @defgroup response Response objects control
   5960  */
   5961 
   5962 
   5963 /**
   5964  * Name with value pair as C strings
   5965  */
   5966 struct MHD_NameValueCStr
   5967 {
   5968   /**
   5969    * The name (key) of the field.
   5970    * Must never be NULL.
   5971    * Some types (kinds) allow empty strings.
   5972    */
   5973   const char *name;
   5974   /**
   5975    * The value of the field.
   5976    * Some types (kinds) allow absence of the value. The absence is indicated
   5977    * by NULL pointer.
   5978    */
   5979   const char *value;
   5980 };
   5981 
   5982 /**
   5983  * Data transmitted in response to an HTTP request.
   5984  * Usually the final action taken in response to
   5985  * receiving a request.
   5986  */
   5987 struct MHD_Response;
   5988 
   5989 
   5990 /**
   5991  * Suspend handling of network data for a given request.  This can
   5992  * be used to dequeue a request from MHD's event loop for a while.
   5993  *
   5994  * Suspended requests continue to count against the total number of
   5995  * requests allowed (per daemon, as well as per IP, if such limits
   5996  * are set).  Suspended requests will NOT time out; timeouts will
   5997  * restart when the request handling is resumed.  While a
   5998  * request is suspended, MHD may not detect disconnects by the
   5999  * client.
   6000  *
   6001  * At most one action can be created for any request.
   6002  *
   6003  * @param[in,out] request the request for which the action is generated
   6004  * @return action to cause a request to be suspended,
   6005  *         NULL if any action has been already created for the @a request
   6006  * @ingroup action
   6007  */
   6008 MHD_EXTERN_ const struct MHD_Action *
   6009 MHD_action_suspend (struct MHD_Request *request)
   6010 MHD_FN_PAR_NONNULL_ALL_;
   6011 
   6012 
   6013 /**
   6014  * Converts a @a response to an action.  If #MHD_R_O_REUSABLE
   6015  * is not set, the reference to the @a response is consumed
   6016  * by the conversion. If #MHD_R_O_REUSABLE is #MHD_YES,
   6017  * then the @a response can be used again to create actions in
   6018  * the future.
   6019  * However, the @a response is frozen by this step and
   6020  * must no longer be modified (i.e. by setting headers).
   6021  *
   6022  * At most one action can be created for any request.
   6023  *
   6024  * @param request the request to create the action for
   6025  * @param[in] response the response to convert,
   6026  *                     if NULL then this function is equivalent to
   6027  *                     #MHD_action_abort_connection() call
   6028  * @return pointer to the action, the action must be consumed
   6029  *         otherwise response object may leak;
   6030  *         NULL if failed (no memory) or if any action has been already
   6031  *         created for the @a request;
   6032  *         when failed the response object is consumed and need not
   6033  *         to be "destroyed"
   6034  * @ingroup action
   6035  */
   6036 MHD_EXTERN_ const struct MHD_Action *
   6037 MHD_action_from_response (struct MHD_Request *MHD_RESTRICT request,
   6038                           struct MHD_Response *MHD_RESTRICT response)
   6039 MHD_FN_PAR_NONNULL_ (1);
   6040 
   6041 
   6042 /**
   6043  * Action telling MHD to close the connection hard
   6044  * (kind-of breaking HTTP specification).
   6045  *
   6046  * @param req the request to make an action
   6047  * @return action operation, always NULL
   6048  * @ingroup action
   6049  */
   6050 #define MHD_action_abort_request(req) \
   6051         MHD_STATIC_CAST_ (const struct MHD_Action *, NULL)
   6052 
   6053 
   6054 /**
   6055  * Set the requested options for the response.
   6056  *
   6057  * If any option fail other options may be or may be not applied.
   6058  * @param response the response to set the options
   6059  * @param[in] options the pointer to the array with the options;
   6060  *                    the array processing stops at the first ::MHD_D_O_END
   6061  *                    option, but not later than after processing
   6062  *                    @a options_max_num entries
   6063  * @param options_max_num the maximum number of entries in the @a options,
   6064  *                        use #MHD_OPTIONS_ARRAY_MAX_SIZE if options processing
   6065  *                        must stop only at zero-termination option
   6066  * @return ::MHD_SC_OK on success,
   6067  *         error code otherwise
   6068  */
   6069 MHD_EXTERN_ enum MHD_StatusCode
   6070 MHD_response_set_options (
   6071   struct MHD_Response *MHD_RESTRICT response,
   6072   const struct MHD_ResponseOptionAndValue *MHD_RESTRICT options,
   6073   size_t options_max_num)
   6074 MHD_FN_PAR_NONNULL_ALL_;
   6075 
   6076 
   6077 /**
   6078  * Set the requested single option for the response.
   6079  *
   6080  * @param response the response to set the option
   6081  * @param[in] option_ptr the pointer to the option
   6082  * @return ::MHD_SC_OK on success,
   6083  *         error code otherwise
   6084  * @ingroup response
   6085  */
   6086 #define MHD_response_set_option(response, option_ptr) \
   6087         MHD_response_set_options (response,option_ptr,1)
   6088 
   6089 
   6090 /* *INDENT-OFF* */
   6091 #ifdef MHD_USE_VARARG_MACROS
   6092 MHD_NOWARN_VARIADIC_MACROS_
   6093 #  if defined(MHD_USE_COMPOUND_LITERALS) && \
   6094   defined(MHD_USE_COMP_LIT_FUNC_PARAMS)
   6095 /**
   6096  * Set the requested options for the response.
   6097  *
   6098  * If any option fail other options may be or may be not applied.
   6099  *
   6100  * It should be used with helpers that creates required options, for example:
   6101  *
   6102  * MHD_RESPONSE_SET_OPTIONS(r, MHD_R_OPTION_REUSABLE(MHD_YES),
   6103  *                          MHD_R_OPTION_TERMINATION_CALLBACK(func, cls))
   6104  *
   6105  * @param response the response to set the option
   6106  * @param ... the list of the options, each option must be created
   6107  *            by helpers MHD_RESPONSE_OPTION_NameOfOption(option_value)
   6108  * @return ::MHD_SC_OK on success,
   6109  *         error code otherwise
   6110  */
   6111 #    define MHD_RESPONSE_SET_OPTIONS(response,...)              \
   6112             MHD_NOWARN_COMPOUND_LITERALS_                           \
   6113             MHD_response_set_options (                              \
   6114               response,                                             \
   6115               ((const struct MHD_ResponseOptionAndValue[])          \
   6116                {__VA_ARGS__, MHD_R_OPTION_TERMINATE ()}),           \
   6117               MHD_OPTIONS_ARRAY_MAX_SIZE)                           \
   6118             MHD_RESTORE_WARN_COMPOUND_LITERALS_
   6119 #  elif defined(MHD_USE_CPP_INIT_LIST)
   6120 MHD_C_DECLARATIONS_FINISH_HERE_
   6121 #    include <vector>
   6122 MHD_C_DECLARATIONS_START_HERE_
   6123 /**
   6124  * Set the requested options for the response.
   6125  *
   6126  * If any option fail other options may be or may be not applied.
   6127  *
   6128  * It should be used with helpers that creates required options, for example:
   6129  *
   6130  * MHD_RESPONSE_SET_OPTIONS(r, MHD_R_OPTION_REUSABLE(MHD_YES),
   6131  *                          MHD_R_OPTION_TERMINATION_CALLBACK(func, cls))
   6132  *
   6133  * @param response the response to set the option
   6134  * @param ... the list of the options, each option must be created
   6135  *            by helpers MHD_RESPONSE_OPTION_NameOfOption(option_value)
   6136  * @return ::MHD_SC_OK on success,
   6137  *         error code otherwise
   6138  */
   6139 #    define MHD_RESPONSE_SET_OPTIONS(response,...)              \
   6140             MHD_NOWARN_CPP_INIT_LIST_                               \
   6141             MHD_response_set_options (                              \
   6142               response,                                             \
   6143               (std::vector<struct MHD_ResponseOptionAndValue>       \
   6144                {__VA_ARGS__,MHD_R_OPTION_TERMINATE ()}).data (),    \
   6145               MHD_OPTIONS_ARRAY_MAX_SIZE)                           \
   6146             MHD_RESTORE_WARN_CPP_INIT_LIST_
   6147 #  endif
   6148 MHD_RESTORE_WARN_VARIADIC_MACROS_
   6149 #endif /* MHD_USE_VARARG_MACROS && MHD_USE_COMP_LIT_FUNC_PARAMS */
   6150 /* *INDENT-ON* */
   6151 
   6152 #ifndef MHD_FREECALLBACK_DEFINED
   6153 
   6154 /**
   6155  * This method is called by libmicrohttpd when response with dynamic content
   6156  * is being destroyed.  It should be used to free resources associated
   6157  * with the dynamic content.
   6158  *
   6159  * @param[in] free_cls closure
   6160  * @ingroup response
   6161  */
   6162 typedef void
   6163 (*MHD_FreeCallback)(void *free_cls);
   6164 
   6165 #  define MHD_FREECALLBACK_DEFINED 1
   6166 #endif /* ! MHD_FREECALLBACK_DEFINED */
   6167 #ifndef MHD_DYNCONTENTZCIOVEC_DEFINED
   6168 
   6169 
   6170 /**
   6171  * Structure for iov type of the response.
   6172  * Used for zero-copy response content data.
   6173  */
   6174 struct MHD_DynContentZCIoVec
   6175 {
   6176   /**
   6177    * The number of elements in @a iov
   6178    */
   6179   unsigned int iov_count;
   6180   /**
   6181    * The pointer to the array with @a iov_count elements.
   6182    */
   6183   const struct MHD_IoVec *iov;
   6184   /**
   6185    * The callback to free resources.
   6186    * It is called once the full array of iov elements is sent.
   6187    * No callback is called if NULL.
   6188    */
   6189   MHD_FreeCallback iov_fcb;
   6190   /**
   6191    * The parameter for @a iov_fcb
   6192    */
   6193   void *iov_fcb_cls;
   6194 };
   6195 
   6196 #  define MHD_DYNCONTENTZCIOVEC_DEFINED 1
   6197 #endif /* ! MHD_DYNCONTENTZCIOVEC_DEFINED */
   6198 
   6199 /**
   6200  * The action type returned by Dynamic Content Creator callback
   6201  */
   6202 struct MHD_DynamicContentCreatorAction;
   6203 
   6204 /**
   6205  * The context used for Dynamic Content Creator callback
   6206  */
   6207 struct MHD_DynamicContentCreatorContext;
   6208 
   6209 
   6210 /**
   6211  * Create "continue processing" action with optional chunk-extension.
   6212  * The data is provided in the buffer and/or in the zero-copy @a iov_data.
   6213  *
   6214  * If data is provided both in the buffer and @a ivo_data then
   6215  * data in the buffer sent first, following the iov data.
   6216  * The total size of the data in the buffer and in @a iov_data must
   6217  * be non-zero.
   6218  * If response content size is known and total size of content provided earlier
   6219  * for this request combined with the size provided by this action is larger
   6220  * then known response content size, then NULL is returned.
   6221  *
   6222  * At most one DCC action can be created for one content callback.
   6223  *
   6224  * @param[in,out] ctx the pointer the context as provided to the callback
   6225  * @param data_size the amount of the data placed to the provided buffer,
   6226  *                  cannot be larger than provided buffer size,
   6227  *                  must be non-zero if @a iov_data is NULL or has no data,
   6228  * @param iov_data the optional pointer to the iov data,
   6229  *                 must not be NULL and have non-zero size data if @a data_size
   6230  *                 is zero,
   6231  * @param chunk_ext the optional pointer to chunk extension string,
   6232  *                  can be NULL to not use chunk extension,
   6233  *                  ignored if chunked encoding is not used
   6234  * @return the pointer to the action if succeed,
   6235  *         NULL (equivalent of MHD_DCC_action_abort())in case of any error
   6236  */
   6237 MHD_EXTERN_ const struct MHD_DynamicContentCreatorAction *
   6238 MHD_DCC_action_continue_zc (
   6239   struct MHD_DynamicContentCreatorContext *ctx,
   6240   size_t data_size,
   6241   const struct MHD_DynContentZCIoVec *iov_data,
   6242   const char *MHD_RESTRICT chunk_ext)
   6243 MHD_FN_PAR_NONNULL_ (1)
   6244 MHD_FN_PAR_CSTR_ (4);
   6245 
   6246 
   6247 /**
   6248  * Create "continue processing" action with optional chunk-extension.
   6249  * The data is provided in the buffer.
   6250  *
   6251  * At most one DCC action can be created for one content callback.
   6252  *
   6253  * @param[in,out] ctx the pointer the context as provided to the callback
   6254  * @param data_size the amount of the data placed to the provided buffer (not @a iov_data),
   6255  *                  cannot be larger than provided buffer size,
   6256  *                  must be non-zero.
   6257  * @param chunk_ext the optional pointer to chunk extension string,
   6258  *                  can be NULL to not use chunk extension,
   6259  *                  ignored if chunked encoding is not used
   6260  * @return the pointer to the action if succeed,
   6261  *         NULL (equivalent of MHD_DCC_action_abort())in case of any error
   6262  */
   6263 #define MHD_DCC_action_continue_ce(ctx, data_size, chunk_ext) \
   6264         MHD_DCC_action_continue_zc ((ctx), (data_size), NULL, (chunk_ext))
   6265 
   6266 
   6267 /**
   6268  * Create "continue processing" action, the data is provided in the buffer.
   6269  *
   6270  * At most one DCC action can be created for one content callback.
   6271  *
   6272  * @param[in,out] ctx the pointer the context as provided to the callback
   6273  * @param data_size the amount of the data placed to the provided buffer;
   6274  *                  cannot be larger than provided buffer size,
   6275  *                  must be non-zero.
   6276  *
   6277  * @return the pointer to the action if succeed,
   6278  *         NULL (equivalent of MHD_DCC_action_abort())in case of any error
   6279  */
   6280 #define MHD_DCC_action_continue(ctx, data_size) \
   6281         MHD_DCC_action_continue_ce ((ctx), (data_size), NULL)
   6282 
   6283 
   6284 /**
   6285  * Create "finished" action with optional footers.
   6286  * If function failed for any reason, the action is automatically
   6287  * set to "stop with error".
   6288  *
   6289  * At most one DCC action can be created for one content callback.
   6290  *
   6291  * @param[in,out] ctx the pointer the context as provided to the callback
   6292  * @param num_footers number of elements in the @a footers array,
   6293  *                    must be zero if @a footers is NULL
   6294  * @param footers the optional pointer to the array of the footers (the strings
   6295  *                are copied and does not need to be valid after return from
   6296  *                this function),
   6297  *                can be NULL if @a num_footers is zero
   6298  * @return the pointer to the action if succeed,
   6299  *         NULL (equivalent of MHD_DCC_action_abort())in case of any error
   6300  */
   6301 MHD_EXTERN_ const struct MHD_DynamicContentCreatorAction *
   6302 MHD_DCC_action_finish_with_footer (
   6303   struct MHD_DynamicContentCreatorContext *ctx,
   6304   size_t num_footers,
   6305   const struct MHD_NameValueCStr *MHD_RESTRICT footers)
   6306 MHD_FN_PAR_NONNULL_ (1);
   6307 
   6308 
   6309 /**
   6310  * Create "finished" action.
   6311  * If function failed for any reason, the action is automatically
   6312  * set to "stop with error".
   6313  *
   6314  * At most one DCC action can be created for one content callback.
   6315  *
   6316  * @param[in,out] ctx the pointer the context as provided to the callback
   6317  * @return the pointer to the action if succeed,
   6318  *         NULL (equivalent of MHD_DCC_action_abort())in case of any error
   6319  */
   6320 #define MHD_DCC_action_finish(ctx) \
   6321         MHD_DCC_action_finish_with_footer ((ctx), 0, NULL)
   6322 
   6323 
   6324 /**
   6325  * Create "suspend" action.
   6326  * If function failed for any reason, the action is automatically
   6327  * set to "stop with error".
   6328  *
   6329  * At most one DCC action can be created for one content callback.
   6330  *
   6331  * @param[in,out] ctx the pointer the context as provided to the callback
   6332  * @return the pointer to the action if succeed,
   6333  *         NULL (equivalent of MHD_DCC_action_abort())in case of any error
   6334  */
   6335 MHD_EXTERN_ const struct MHD_DynamicContentCreatorAction *
   6336 MHD_DCC_action_suspend (struct MHD_DynamicContentCreatorContext *ctx)
   6337 MHD_FN_PAR_NONNULL_ (1);
   6338 
   6339 /**
   6340  * Create "stop with error" action.
   6341  * @param[in,out] ctx the pointer the context as provided to the callback
   6342  * @return always NULL (the action "stop with error")
   6343  */
   6344 #define MHD_DCC_action_abort(ctx) \
   6345         MHD_STATIC_CAST_ (const struct MHD_DynamicContentCreatorAction *, NULL)
   6346 
   6347 /**
   6348  * Callback used by libmicrohttpd in order to obtain content.  The
   6349  * callback is to copy at most @a max bytes of content into @a buf or
   6350  * provide zero-copy data for #MHD_DCC_action_continue_zc().
   6351  *
   6352  * @param dyn_cont_cls closure argument to the callback
   6353  * @param ctx the context to produce the action to return,
   6354  *            the pointer is only valid until the callback returns
   6355  * @param pos position in the datastream to access;
   6356  *        note that if a `struct MHD_Response` object is re-used,
   6357  *        it is possible for the same content reader to
   6358  *        be queried multiple times for the same data;
   6359  *        however, if a `struct MHD_Response` is not re-used,
   6360  *        libmicrohttpd guarantees that "pos" will be
   6361  *        the sum of all data sizes provided by this callback
   6362  * @param[out] buf where to copy the data
   6363  * @param max maximum number of bytes to copy to @a buf (size of @a buf),
   6364               if the size of the content of the response is known then size
   6365               of the buffer is never larger than amount of the content left
   6366  * @return action to use,
   6367  *         NULL in case of any error (the response will be aborted)
   6368  */
   6369 typedef const struct MHD_DynamicContentCreatorAction *
   6370 (MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_NONNULL_ (4)
   6371  *MHD_DynamicContentCreator)(void *dyn_cont_cls,
   6372                              struct MHD_DynamicContentCreatorContext *ctx,
   6373                              uint_fast64_t pos,
   6374                              void *buf,
   6375                              size_t max);
   6376 
   6377 
   6378 /**
   6379  * Create a response.  The response object can be extended with
   6380  * header information.
   6381  *
   6382  * @param sc status code to return
   6383  * @param size size of the data portion of the response, #MHD_SIZE_UNKNOWN for unknown
   6384  * @param dyn_cont callback to use to obtain response data
   6385  * @param dyn_cont_cls extra argument to @p dyn_cont
   6386  * @param free_cb callback to call to free @p dyn_cont_cls resources,
   6387  *                can be NULL
   6388  * @param free_cb_cls the parameter for @p free_cb
   6389  * @return new response object on success,
   6390  *         NULL on failure (i.e. invalid arguments, out of memory),
   6391  *         @p free_cb is called automatically in case of failure
   6392  * @ingroup response
   6393  */
   6394 MHD_EXTERN_ struct MHD_Response *
   6395 MHD_response_from_callback_2cls (enum MHD_HTTP_StatusCode sc,
   6396                                  uint_fast64_t size,
   6397                                  MHD_DynamicContentCreator dyn_cont,
   6398                                  void *dyn_cont_cls,
   6399                                  MHD_FreeCallback free_cb,
   6400                                  void *free_cb_cls);
   6401 
   6402 
   6403 /**
   6404  * Create a response.  The response object can be extended with
   6405  * header information.
   6406  *
   6407  * @param sc status code to return
   6408  * @param s size of the data portion of the response, #MHD_SIZE_UNKNOWN for unknown
   6409  * @param d callback to use to obtain response data
   6410  * @param dc extra argument to @p d, evaluated twice!
   6411  * @param f callback to call to free @p dc resources
   6412  * @return new response object on success,
   6413  *         NULL on failure (i.e. invalid arguments, out of memory),
   6414  *         the cleanup callback @p f is called automatically in case
   6415  *         of failure
   6416  * @warning The @p dc parameter is evaluated twice; avoid expressions
   6417  *          with side effects. Alternatively, just call function
   6418  *          #MHD_response_from_callback_2cls() directly.
   6419  * @ingroup response
   6420  */
   6421 #define MHD_response_from_callback(sc, s, d, dc, f) \
   6422         MHD_response_from_callback_2cls((sc),(s),(d),(dc),(f),(dc))
   6423 
   6424 
   6425 /**
   6426  * Create a response object.  The response object can be extended with
   6427  * header information.
   6428  *
   6429  * @param sc status code to use for the response;
   6430  *           #MHD_HTTP_STATUS_NO_CONTENT is only valid if @a size is 0;
   6431  * @param buffer_size the size of the data portion of the response
   6432  * @param buffer the @a size bytes containing the response's data portion,
   6433  *               needs to be valid while the response is used
   6434  * @param free_cb the callback to free any allocated data, called
   6435  *                when response is being destroyed, can be NULL
   6436  *                to skip the free/cleanup callback;
   6437  * @param free_cb_cls the parameter for @a free_cb
   6438  * @return new response object on success,
   6439  *         NULL on failure (i.e. invalid arguments, out of memory),
   6440  *         @p free_cb is called automatically in case of failure
   6441  * @ingroup response
   6442  */
   6443 MHD_EXTERN_ struct MHD_Response *
   6444 MHD_response_from_buffer (
   6445   enum MHD_HTTP_StatusCode sc,
   6446   size_t buffer_size,
   6447   const char *buffer,
   6448   MHD_FreeCallback free_cb,
   6449   void *free_cb_cls)
   6450 MHD_FN_PAR_IN_SIZE_ (3, 2);
   6451 
   6452 
   6453 /**
   6454  * Create a response object with body that is a
   6455  * statically allocated buffer that never needs to
   6456  * be freed as its lifetime exceeds that of the
   6457  * daemon.
   6458  *
   6459  * The response object can be extended with header information and then be used
   6460  * any number of times.
   6461  * @param sc status code to use for the response
   6462  * @param len number of bytes in @a buf
   6463  * @param buf buffer with response payload
   6464  * @return new response object on success,
   6465  *         NULL on failure (i.e. invalid arguments, out of memory)
   6466  */
   6467 #define MHD_response_from_buffer_static(sc, len, buf)       \
   6468         MHD_response_from_buffer (sc, len, buf, NULL, NULL)
   6469 
   6470 
   6471 /**
   6472  * Create a response object with empty (zero size) body.
   6473  *
   6474  * The response object can be extended with header information and then be used
   6475  * any number of times.
   6476  * @param sc status code to use for the response
   6477  * @return new response object on success,
   6478  *         NULL on failure (i.e. invalid arguments, out of memory)
   6479  */
   6480 #define MHD_response_from_empty(sc) \
   6481         MHD_response_from_buffer_static (sc, 0, "")
   6482 
   6483 
   6484 /**
   6485  * Create a response object.  The response object can be extended with
   6486  * header information.
   6487  *
   6488  * @param sc status code to use for the response
   6489  * @param buffer_size the size of the data portion of the response
   6490  * @param buffer the @a size bytes containing the response's data portion,
   6491  *               an internal copy will be made, there is no need to
   6492  *               keep this data after return from this function
   6493  * @return new response object on success,
   6494  *         NULL on failure (i.e. invalid arguments, out of memory)
   6495  * @ingroup response
   6496  */
   6497 MHD_EXTERN_ struct MHD_Response *
   6498 MHD_response_from_buffer_copy (
   6499   enum MHD_HTTP_StatusCode sc,
   6500   size_t buffer_size,
   6501   const char buffer[MHD_FN_PAR_DYN_ARR_SIZE_ (buffer_size)])
   6502 MHD_FN_PAR_IN_SIZE_ (3, 2);
   6503 
   6504 
   6505 /**
   6506  * I/O vector type. Provided for use with #MHD_response_from_iovec().
   6507  * @ingroup response
   6508  */
   6509 struct MHD_IoVec
   6510 {
   6511   /**
   6512    * The pointer to the memory region for I/O.
   6513    */
   6514   const void *iov_base;
   6515 
   6516   /**
   6517    * The size in bytes of the memory region for I/O.
   6518    */
   6519   size_t iov_len;
   6520 };
   6521 
   6522 
   6523 /**
   6524  * Create a response object with an array of memory buffers
   6525  * used as the response body.
   6526  *
   6527  * The response object can be extended with header information.
   6528  *
   6529  * If response object is used to answer HEAD request then the body
   6530  * of the response is not used, while all headers (including automatic
   6531  * headers) are used.
   6532  *
   6533  * @param sc status code to use for the response
   6534  * @param iov_count the number of elements in @a iov
   6535  * @param iov the array for response data buffers, an internal copy of this
   6536  *        will be made
   6537  * @param free_cb the callback to clean up any data associated with @a iov when
   6538  *        the response is destroyed.
   6539  * @param free_cb_cls the argument passed to @a free_cb
   6540  * @return new response object on success,
   6541  *         NULL on failure (i.e. invalid arguments, out of memory),
   6542  *         @p free_cb is called automatically in case of failure
   6543  * @ingroup response
   6544  */
   6545 MHD_EXTERN_ struct MHD_Response *
   6546 MHD_response_from_iovec (
   6547   enum MHD_HTTP_StatusCode sc,
   6548   unsigned int iov_count,
   6549   const struct MHD_IoVec iov[MHD_FN_PAR_DYN_ARR_SIZE_ (iov_count)],
   6550   MHD_FreeCallback free_cb,
   6551   void *free_cb_cls);
   6552 
   6553 
   6554 /**
   6555  * Create a response object based on an @a fd from which
   6556  * data is read.  The response object can be extended with
   6557  * header information.
   6558  *
   6559  * @param sc status code to return
   6560  * @param fd file descriptor referring to a file on disk with the
   6561  *        data; will be closed when response is destroyed;
   6562  *        fd should be in 'blocking' mode
   6563  * @param offset offset to start reading from in the file;
   6564  *        reading file beyond 2 GiB may be not supported by OS or
   6565  *        MHD build; see #MHD_LIB_INFO_FIXED_HAS_LARGE_FILE
   6566  * @param size size of the data portion of the response;
   6567  *        sizes larger than 2 GiB may be not supported by OS or
   6568  *        MHD build; see #MHD_LIB_INFO_FIXED_HAS_LARGE_FILE
   6569  * @return new response object on success,
   6570  *         NULL on failure (i.e. invalid arguments, out of memory),
   6571  *         @p fd is closed automatically in case of failure
   6572  * @ingroup response
   6573  */
   6574 MHD_EXTERN_ struct MHD_Response *
   6575 MHD_response_from_fd (enum MHD_HTTP_StatusCode sc,
   6576                       int fd,
   6577                       uint_fast64_t offset,
   6578                       uint_fast64_t size)
   6579 MHD_FN_PAR_FD_READ_ (2);
   6580 
   6581 /**
   6582  * Create a response object with the response body created by reading
   6583  * the provided pipe.
   6584  *
   6585  * The response object can be extended with header information and
   6586  * then be used ONLY ONCE.
   6587  *
   6588  * If response object is used to answer HEAD request then the body
   6589  * of the response is not used, while all headers (including automatic
   6590  * headers) are used.
   6591  *
   6592  * @param sc status code to use for the response
   6593  * @param fd file descriptor referring to a read-end of a pipe with the
   6594  *        data; will be closed when response is destroyed;
   6595  *        fd should be in 'blocking' mode
   6596  * @return new response object on success,
   6597  *         NULL on failure (i.e. invalid arguments, out of memory),
   6598  *         @p fd is closed automatically in case of failure
   6599  * @ingroup response
   6600  */
   6601 MHD_EXTERN_ struct MHD_Response *
   6602 MHD_response_from_pipe (enum MHD_HTTP_StatusCode sc,
   6603                         int fd)
   6604 MHD_FN_PAR_FD_READ_ (2);
   6605 
   6606 
   6607 /**
   6608  * Destroy response.
   6609  * Should be called if response was created but not consumed.
   6610  * Also must be called if response has #MHD_R_O_REUSABLE set.
   6611  * The actual destroy can be happen later, if the response
   6612  * is still being used in any request.
   6613  * The function does not block.
   6614  *
   6615  * @param[in] response the response to destroy
   6616  * @ingroup response
   6617  */
   6618 MHD_EXTERN_ void
   6619 MHD_response_destroy (struct MHD_Response *response)
   6620 MHD_FN_PAR_NONNULL_ (1);
   6621 
   6622 
   6623 /**
   6624  * Add a header line to the response.
   6625  *
   6626  * @param response response to add a header to, NULL is tolerated
   6627  * @param name the name of the header to add,
   6628  *             an internal copy of the string will be made
   6629  * @param value the value of the header to add,
   6630  *              an internal copy of the string will be made
   6631  * @return #MHD_SC_OK on success,
   6632  *         error code otherwise
   6633  * @ingroup response
   6634  */
   6635 MHD_EXTERN_ enum MHD_StatusCode
   6636 MHD_response_add_header (struct MHD_Response *MHD_RESTRICT response,
   6637                          const char *MHD_RESTRICT name,
   6638                          const char *MHD_RESTRICT value)
   6639 MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2)
   6640 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_CSTR_ (3);
   6641 
   6642 
   6643 /**
   6644  * Add a header with predefined (standard) name to the response.
   6645  *
   6646  * @param response response to add a header to
   6647  * @param stk the code of the predefined header
   6648  * @param content the value of the header to add,
   6649  *              an internal copy of the string will be made
   6650  * @return #MHD_SC_OK on success,
   6651  *         error code otherwise
   6652  * @ingroup response
   6653  */
   6654 MHD_EXTERN_ enum MHD_StatusCode
   6655 MHD_response_add_predef_header (struct MHD_Response *MHD_RESTRICT response,
   6656                                 enum MHD_PredefinedHeader stk,
   6657                                 const char *MHD_RESTRICT content)
   6658 MHD_FN_PAR_NONNULL_ (1)
   6659 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_CSTR_ (3);
   6660 
   6661 
   6662 /* ************ (b) Upload and PostProcessor functions ********************** */
   6663 
   6664 
   6665 /**
   6666  * Suspend handling of network data for a given request.  This can
   6667  * be used to dequeue a request from MHD's event loop for a while.
   6668  *
   6669  * Suspended requests continue to count against the total number of
   6670  * requests allowed (per daemon, as well as per IP, if such limits
   6671  * are set).  Suspended requests will NOT time out; timeouts will
   6672  * restart when the request handling is resumed.  While a
   6673  * request is suspended, MHD may not detect disconnects by the
   6674  * client.
   6675  *
   6676  * At most one upload action can be created for one upload callback.
   6677  *
   6678  * @param[in,out] request the request for which the action is generated
   6679  * @return action to cause a request to be suspended,
   6680  *         NULL if any action has been already created for the @a request
   6681  * @ingroup action
   6682  */
   6683 MHD_EXTERN_ const struct MHD_UploadAction *
   6684 MHD_upload_action_suspend (struct MHD_Request *request)
   6685 MHD_FN_PAR_NONNULL_ALL_;
   6686 
   6687 /**
   6688  * Converts a @a response to an action.  If #MHD_R_O_REUSABLE
   6689  * is not set, the reference to the @a response is consumed
   6690  * by the conversion. If #MHD_R_O_REUSABLE is #MHD_YES,
   6691  * then the @a response can be used again to create actions in
   6692  * the future.
   6693  * However, the @a response is frozen by this step and
   6694  * must no longer be modified (i.e. by setting headers).
   6695  *
   6696  * At most one upload action can be created for one upload callback.
   6697  *
   6698  * @param request the request to create the action for
   6699  * @param[in] response the response to convert,
   6700  *                     if NULL then this function is equivalent to
   6701  *                     #MHD_upload_action_abort_request() call
   6702  * @return pointer to the action, the action must be consumed
   6703  *         otherwise response object may leak;
   6704  *         NULL if failed (no memory) or if any action has been already
   6705  *         created for the @a request;
   6706  *         when failed the response object is consumed and need not
   6707  *         to be "destroyed"
   6708  * @ingroup action
   6709  */
   6710 MHD_EXTERN_ const struct MHD_UploadAction *
   6711 MHD_upload_action_from_response (struct MHD_Request *MHD_RESTRICT request,
   6712                                  struct MHD_Response *MHD_RESTRICT response)
   6713 MHD_FN_PAR_NONNULL_ (1);
   6714 
   6715 /**
   6716  * Action telling MHD to continue processing the upload.
   6717  * Valid only for incremental upload processing.
   6718  * Works as #MHD_upload_action_abort_request() if used for full upload callback
   6719  * or for the final (with zero data) incremental callback.
   6720  *
   6721  * At most one upload action can be created for one upload callback.
   6722  *
   6723  * @param request the request to make an action
   6724  * @return action operation,
   6725  *         NULL if any action has been already created for the @a request
   6726  * @ingroup action
   6727  */
   6728 MHD_EXTERN_ const struct MHD_UploadAction *
   6729 MHD_upload_action_continue (struct MHD_Request *request)
   6730 MHD_FN_PAR_NONNULL_ (1);
   6731 
   6732 
   6733 /**
   6734  * Action telling MHD to close the connection hard
   6735  * (kind-of breaking HTTP specification).
   6736  *
   6737  * @param req the request to make an action
   6738  * @return action operation, always NULL
   6739  * @ingroup action
   6740  */
   6741 #define MHD_upload_action_abort_request(req) \
   6742         MHD_STATIC_CAST_ (const struct MHD_UploadAction *, NULL)
   6743 
   6744 #ifndef MHD_UPLOADCALLBACK_DEFINED
   6745 
   6746 /**
   6747  * Function to process data uploaded by a client.
   6748  *
   6749  * @param upload_cls the argument given together with the function
   6750  *                   pointer when the handler was registered with MHD
   6751  * @param request the request is being processed
   6752  * @param content_data_size the size of the @a content_data,
   6753  *                          zero when all data have been processed
   6754  * @param[in] content_data the uploaded content data,
   6755  *                         may be modified in the callback,
   6756  *                         valid only until return from the callback,
   6757  *                         NULL when all data have been processed
   6758  * @return action specifying how to proceed:
   6759  *         #MHD_upload_action_continue() to continue upload (for incremental
   6760  *         upload processing only),
   6761  *         #MHD_upload_action_suspend() to stop reading the upload until
   6762  *         the request is resumed,
   6763  *         #MHD_upload_action_abort_request() to close the socket,
   6764  *         or a response to discard the rest of the upload and transmit
   6765  *         the response
   6766  * @ingroup action
   6767  */
   6768 typedef const struct MHD_UploadAction *
   6769 (MHD_FN_PAR_NONNULL_ (2)  MHD_FN_PAR_INOUT_SIZE_ (4, 3)
   6770  *MHD_UploadCallback)(void *upload_cls,
   6771                       struct MHD_Request *request,
   6772                       size_t content_data_size,
   6773                       void *content_data);
   6774 
   6775 #  define MHD_UPLOADCALLBACK_DEFINED 1
   6776 #endif /* ! MHD_UPLOADCALLBACK_DEFINED */
   6777 
   6778 /**
   6779  * Create an action that handles an upload.
   6780  *
   6781  * If @a uc_inc is NULL and upload cannot fit the allocated buffer
   6782  * then request is aborted without response.
   6783  *
   6784  * At most one action can be created for any request.
   6785  *
   6786  * @param request the request to create action for
   6787  * @param large_buffer_size how large should the upload buffer be.
   6788  *                          May allocate memory from the shared "large"
   6789  *                          memory pool if necessary and non-zero is given.
   6790  *                          Must be zero if @a uc_full is NULL.
   6791  * @param uc_full the function to call when complete upload
   6792  *                is received (only if fit @a upload_buffer_size),
   6793  *                can be NULL if uc_inc is not NULL,
   6794  *                must be NULL is @a upload_buffer_size is zero.
   6795  * @param uc_full_cls closure for @a uc_full
   6796  * @param uc_inc the function to incrementally process the upload data
   6797  *               if the upload if larger than @a upload_buffer_size or
   6798  *               @a upload_buffer_size cannot be allocated or
   6799  *               @a uc_full is NULL,
   6800  *               can be NULL if uc_full is not NULL
   6801  * @param uc_inc_cls closure for @a uc_inc
   6802  * @return NULL on error (out of memory, invalid parameters)
   6803  * @return pointer to the action,
   6804  *         NULL if failed (no memory) or if any action has been already
   6805  *         created for the @a request.
   6806  * @sa #MHD_D_OPTION_LARGE_POOL_SIZE()
   6807  * @ingroup action
   6808  */
   6809 MHD_EXTERN_ const struct MHD_Action *
   6810 MHD_action_process_upload (
   6811   struct MHD_Request *request,
   6812   size_t large_buffer_size,
   6813   MHD_UploadCallback uc_full,
   6814   void *uc_full_cls,
   6815   MHD_UploadCallback uc_inc,
   6816   void *uc_inc_cls)
   6817 MHD_FN_PAR_NONNULL_ (1);
   6818 
   6819 /**
   6820  * Create an action that handles an upload as full upload data.
   6821  *
   6822  * @param request the request to create action for
   6823  * @param buff_size how large should the upload buffer be. May allocate memory
   6824  *                  from the large memory pool if necessary. Must not be zero.
   6825  * @param uc the function to call when complete upload
   6826  *           is received (only if fit @a upload_buffer_size)
   6827  * @param uc_cls closure for @a uc
   6828  * @return NULL on error (out of memory. both @a uc is NULL)
   6829  * @ingroup action
   6830  */
   6831 #define MHD_action_process_upload_full(request, buff_size, uc, uc_cls) \
   6832         MHD_action_process_upload (request, buff_size, uc, uc_cls, NULL, NULL)
   6833 
   6834 /**
   6835  * Create an action that handles an upload incrementally.
   6836  *
   6837  * @param request the request to create action for
   6838  * @param uc the function to incrementally process the upload data
   6839  * @param uc_cls closure for @a uc
   6840  * @return NULL on error (out of memory. both @a uc is NULL)
   6841  * @ingroup action
   6842  */
   6843 #define MHD_action_process_upload_inc(request, uc, uc_cls) \
   6844         MHD_action_process_upload (request, 0, NULL, NULL, uc, uc_cls)
   6845 
   6846 #ifndef MHD_POST_PARSE_RESULT_DEFINED
   6847 
   6848 /**
   6849  * The result of POST data parsing
   6850  */
   6851 enum MHD_FIXED_ENUM_MHD_SET_ MHD_PostParseResult
   6852 {
   6853   /**
   6854    * The POST data parsed successfully and completely.
   6855    */
   6856   MHD_POST_PARSE_RES_OK = 0
   6857   ,
   6858   /**
   6859    * The POST request has no content or zero-length content.
   6860    */
   6861   MHD_POST_PARSE_RES_REQUEST_EMPTY = 1
   6862   ,
   6863   /**
   6864    * The POST data parsed successfully, but has missing or incorrect
   6865    * termination.
   6866    * The last parsed field may have incorrect data.
   6867    */
   6868   MHD_POST_PARSE_RES_OK_BAD_TERMINATION = 2
   6869   ,
   6870   /**
   6871    * Parsing of the POST data is incomplete because client used incorrect
   6872    * format of POST encoding.
   6873    * The last parsed field may have incorrect data.
   6874    * Some POST data is available or has been provided via callback.
   6875    */
   6876   MHD_POST_PARSE_RES_PARTIAL_INVALID_POST_FORMAT = 3
   6877   ,
   6878   /**
   6879    * The POST data cannot be parsed completely because the stream has
   6880    * no free pool memory.
   6881    * Some POST data may be parsed.
   6882    */
   6883   MHD_POST_PARSE_RES_FAILED_NO_POOL_MEM = 60
   6884   ,
   6885   /**
   6886    * The POST data cannot be parsed completely because no "large shared buffer"
   6887    * space is available.
   6888    * Some POST data may be parsed.
   6889    */
   6890   MHD_POST_PARSE_RES_FAILED_NO_LARGE_BUF_MEM = 61
   6891   ,
   6892   /**
   6893    * The POST data cannot be parsed because 'Content-Type:' is unknown.
   6894    */
   6895   MHD_POST_PARSE_RES_FAILED_UNKNOWN_CNTN_TYPE = 80
   6896   ,
   6897   /**
   6898    * The POST data cannot be parsed because 'Content-Type:' header is not set.
   6899    */
   6900   MHD_POST_PARSE_RES_FAILED_NO_CNTN_TYPE = 81
   6901   ,
   6902   /**
   6903    * The POST data cannot be parsed because "Content-Type:" request header has
   6904    * no "boundary" parameter for "multipart/form-data"
   6905    */
   6906   MHD_POST_PARSE_RES_FAILED_HEADER_NO_BOUNDARY = 82
   6907   ,
   6908   /**
   6909    * The POST data cannot be parsed because "Content-Type: multipart/form-data"
   6910    * request header is misformed
   6911    */
   6912   MHD_POST_PARSE_RES_FAILED_HEADER_MISFORMED = 83
   6913   ,
   6914   /**
   6915    * The application set POST encoding to "multipart/form-data", but the request
   6916    * has no "Content-Type: multipart/form-data" header which is required
   6917    * to find "boundary" used in this encoding
   6918    */
   6919   MHD_POST_PARSE_RES_FAILED_HEADER_NOT_MPART = 84
   6920   ,
   6921   /**
   6922    * The POST data cannot be parsed because client used incorrect format
   6923    * of POST encoding.
   6924    */
   6925   MHD_POST_PARSE_RES_FAILED_INVALID_POST_FORMAT = 90
   6926 
   6927 };
   6928 
   6929 #  define MHD_POST_PARSE_RESULT_DEFINED 1
   6930 #endif /* ! MHD_POST_PARSE_RESULT_DEFINED */
   6931 
   6932 #ifndef MHD_POST_DATA_READER_DEFINED
   6933 
   6934 /**
   6935  * "Stream" reader for POST data.
   6936  * This callback is called to incrementally process parsed POST data sent by
   6937  * the client.
   6938  * The pointers to the MHD_String and MHD_StringNullable are valid only until
   6939  * return from this callback.
   6940  * The pointers to the strings and the @a data are valid only until return from
   6941  * this callback.
   6942  *
   6943  * @param req the request
   6944  * @param cls user-specified closure
   6945  * @param name the name of the POST field
   6946  * @param filename the name of the uploaded file, @a cstr member is NULL if not
   6947  *                 known / not provided
   6948  * @param content_type the mime-type of the data, cstr member is NULL if not
   6949  *                     known / not provided
   6950  * @param encoding the encoding of the data, cstr member is NULL if not known /
   6951  *                 not provided
   6952  * @param size the number of bytes in @a data available, may be zero if
   6953  *             the @a final_data is #MHD_YES
   6954  * @param data the pointer to @a size bytes of data at the specified
   6955  *             @a off offset, NOT zero-terminated
   6956  * @param off the offset of @a data in the overall value, always equal to
   6957  *            the sum of sizes of previous calls for the same field / file;
   6958  *            client may provide more than one field with the same name and
   6959  *            the same filename, the new filed (or file) is indicated by zero
   6960  *            value of @a off (and the end is indicated by @a final_data)
   6961  * @param final_data if set to #MHD_YES then full field data is provided,
   6962  *                   if set to #MHD_NO then more field data may be provided
   6963  * @return action specifying how to proceed:
   6964  *         #MHD_upload_action_continue() if all is well,
   6965  *         #MHD_upload_action_suspend() to stop reading the upload until
   6966  *         the request is resumed,
   6967  *         #MHD_upload_action_abort_request() to close the socket,
   6968  *         or a response to discard the rest of the upload and transmit
   6969  *         the response
   6970  * @ingroup action
   6971  */
   6972 typedef const struct MHD_UploadAction *
   6973 (MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_NONNULL_ (4)
   6974  MHD_FN_PAR_NONNULL_ (5) MHD_FN_PAR_NONNULL_ (6)
   6975  *MHD_PostDataReader) (struct MHD_Request *req,
   6976                        void *cls,
   6977                        const struct MHD_String *name,
   6978                        const struct MHD_StringNullable *filename,
   6979                        const struct MHD_StringNullable *content_type,
   6980                        const struct MHD_StringNullable *encoding,
   6981                        size_t size,
   6982                        const void *data,
   6983                        uint_fast64_t off,
   6984                        enum MHD_Bool final_data);
   6985 
   6986 
   6987 /**
   6988  * The callback to be called when finished with processing
   6989  * of the postprocessor upload data.
   6990  * @param req the request
   6991  * @param cls the closure
   6992  * @param parsing_result the result of POST data parsing
   6993  * @return the action to proceed
   6994  */
   6995 typedef const struct MHD_UploadAction *
   6996 (MHD_FN_PAR_NONNULL_ (1)
   6997  *MHD_PostDataFinished) (struct MHD_Request *req,
   6998                          void *cls,
   6999                          enum MHD_PostParseResult parsing_result);
   7000 
   7001 #  define MHD_POST_DATA_READER_DEFINED 1
   7002 #endif /* ! MHD_POST_DATA_READER_DEFINED */
   7003 
   7004 /**
   7005  * Create an action to parse the POSTed content from the client.
   7006  *
   7007  * The action starts parsing of the POST data. Any value that does not fit
   7008  * @a buffer_size or larger that @a auto_stream_size is given to
   7009  * @a stream_reader (if it is not NULL).
   7010  *
   7011  * If @a buffer_size is zero, then buffers will be limited to the connection's
   7012  * memory pool. To force all POST data process via @a stream_reader
   7013  * set @a auto_stream_size to zero.
   7014  *
   7015  * At most one action can be created for any request.
   7016  *
   7017  * @param request the request to create action for
   7018  * @param buffer_size the maximum size allowed for the buffers to parse this
   7019  *                    request POST data. Within the set limit the buffer is
   7020  *                    allocated automatically from the "large" shared memory
   7021  *                    pool if necessary.
   7022  * @param max_nonstream_size the size of the field (in encoded form) above which
   7023  *                           values are not buffered and provided for
   7024  *                           the @a steam_reader automatically;
   7025  *                           useful to have large data (like file uploads)
   7026  *                           processed incrementally, while keeping buffer space
   7027  *                           for small fields only;
   7028  *                           ignored if @a stream_reader is NULL
   7029  * @param enc the data encoding to use,
   7030  *            use #MHD_HTTP_POST_ENCODING_OTHER to detect automatically
   7031  * @param stream_reader the function to call for "oversize" values in
   7032  *                      the stream; can be NULL if @a auto_stream_size is
   7033  *                      not zero
   7034  * @param reader_cls the closure for the @a stream_reader
   7035  * @param done_cb called once all data has been processed for
   7036  *   the final action; values smaller than @a auto_stream_size that
   7037  *   fit into @a buffer_size will be available via
   7038  *   #MHD_request_get_values_cb(), #MHD_request_get_values_list() and
   7039  *   #MHD_request_get_post_data_cb(), #MHD_request_get_post_data_list()
   7040  * @param done_cb_cls the closure for the @a done_cb
   7041  * @return pointer to the action,
   7042  *         NULL if failed (no memory) or if any action has been already
   7043  *         created for the @a request.
   7044  * @sa #MHD_D_OPTION_LARGE_POOL_SIZE()
   7045  * @ingroup action
   7046  */
   7047 MHD_EXTERN_ const struct MHD_Action *
   7048 MHD_action_parse_post (struct MHD_Request *request,
   7049                        size_t buffer_size,
   7050                        size_t max_nonstream_size,
   7051                        enum MHD_HTTP_PostEncoding enc,
   7052                        MHD_PostDataReader stream_reader,
   7053                        void *reader_cls,
   7054                        MHD_PostDataFinished done_cb,
   7055                        void *done_cb_cls)
   7056 MHD_FN_PAR_NONNULL_ (1);
   7057 
   7058 
   7059 #ifndef MHD_POSTFILED_DEFINED
   7060 
   7061 /**
   7062  * Post data element.
   7063  * If any member is not provided/set then pointer to C string is NULL.
   7064  * If any member is set to empty string then pointer to C string not NULL,
   7065  * but the length is zero.
   7066  */
   7067 struct MHD_PostField
   7068 {
   7069   /**
   7070    * The name of the field
   7071    */
   7072   struct MHD_String name;
   7073   /**
   7074    * The field data
   7075    * If not set or defined then to C string is NULL.
   7076    * If set to empty string then pointer to C string not NULL,
   7077    * but the length is zero.
   7078    */
   7079   struct MHD_StringNullable value;
   7080   /**
   7081    * The filename if provided (only for "multipart/form-data")
   7082    * If not set or defined then to C string is NULL.
   7083    * If set to empty string then pointer to C string not NULL,
   7084    * but the length is zero.
   7085    */
   7086   struct MHD_StringNullable filename;
   7087   /**
   7088    * The Content-Type if provided (only for "multipart/form-data")
   7089    * If not set or defined then to C string is NULL.
   7090    * If set to empty string then pointer to C string not NULL,
   7091    * but the length is zero.
   7092    */
   7093   struct MHD_StringNullable content_type;
   7094   /**
   7095    * The Transfer-Encoding if provided (only for "multipart/form-data")
   7096    * If not set or defined then to C string is NULL.
   7097    * If set to empty string then pointer to C string not NULL,
   7098    * but the length is zero.
   7099    */
   7100   struct MHD_StringNullable transfer_encoding;
   7101 };
   7102 
   7103 #  define MHD_POSTFILED_DEFINED 1
   7104 #endif /* ! MHD_POSTFILED_DEFINED */
   7105 
   7106 
   7107 /**
   7108  * Iterator over POST data.
   7109  *
   7110  * The @a data pointer is valid only until return from this function.
   7111  *
   7112  * The pointers to the strings in @a data are valid until any MHD_UploadAction
   7113  * is provided. If the data is needed beyond this point, it should be copied.
   7114  *
   7115  * @param cls closure
   7116  * @param data the element of the post data, the pointer is valid only until
   7117  *             return from this function
   7118  * @return #MHD_YES to continue iterating,
   7119  *         #MHD_NO to abort the iteration
   7120  * @ingroup request
   7121  */
   7122 typedef enum MHD_Bool
   7123 (MHD_FN_PAR_NONNULL_ (2)
   7124  *MHD_PostDataIterator)(void *cls,
   7125                         const struct MHD_PostField *data);
   7126 
   7127 /**
   7128  * Get all of the post data from the request via request.
   7129  *
   7130  * @param request the request to get data for
   7131  * @param iterator callback to call on each header;
   7132  *        maybe NULL (then just count headers)
   7133  * @param iterator_cls extra argument to @a iterator
   7134  * @return number of entries iterated over
   7135  * @ingroup request
   7136  */
   7137 MHD_EXTERN_ size_t
   7138 MHD_request_get_post_data_cb (struct MHD_Request *request,
   7139                               MHD_PostDataIterator iterator,
   7140                               void *iterator_cls)
   7141 MHD_FN_PAR_NONNULL_ (1);
   7142 
   7143 /**
   7144  * Get all of the post data from the request.
   7145  *
   7146  * The pointers to the strings in @a elements are valid until any
   7147  * MHD_UploadAction is provided. If the data is needed beyond this point,
   7148  * it should be copied.
   7149  * @param request the request to get data for
   7150  * @param num_elements the number of elements in @a elements array
   7151  * @param[out] elements the array of @a num_elements to get the data
   7152  * @return the number of elements stored in @a elements,
   7153  *         zero if no data or postprocessor was not used.
   7154  * @ingroup request
   7155  */
   7156 MHD_EXTERN_ size_t
   7157 MHD_request_get_post_data_list (
   7158   struct MHD_Request *request,
   7159   size_t num_elements,
   7160   struct MHD_PostField elements[MHD_FN_PAR_DYN_ARR_SIZE_ (num_elements)])
   7161 MHD_FN_PAR_NONNULL_ (1)
   7162 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_SIZE_ (3, 2);
   7163 
   7164 /* ***************** (c) WebSocket support ********** */
   7165 
   7166 /**
   7167  * Handle given to the application to manage special
   7168  * actions relating to MHD responses that "upgrade"
   7169  * the HTTP protocol (i.e. to WebSockets).
   7170  */
   7171 struct MHD_UpgradedHandle;
   7172 
   7173 
   7174 #ifndef MHD_UPGRADEHANDLER_DEFINED
   7175 
   7176 /**
   7177  * Function called after a protocol "upgrade" response was sent successfully
   7178  * and the connection is being switched to other protocol.
   7179  *
   7180  * The newly provided handle @a urh can be used to send and receive the data
   7181  * by #MHD_upgraded_send() and #MHD_upgraded_recv(). The handle must be closed
   7182  * by #MHD_upgraded_close() before destroying the daemon.
   7183  *
   7184  * "Upgraded" connection will not time out, but still counted for daemon
   7185  * global connections limit and for per-IP limit (if set).
   7186  *
   7187  * Except when in 'thread-per-connection' mode, implementations
   7188  * of this function should never block (as it will still be called
   7189  * from within the main event loop).
   7190  *
   7191  * @param cls closure, whatever was given to #MHD_action_upgrade().
   7192  * @param request original HTTP request handle,
   7193  *                giving the function a last chance
   7194  *                to inspect the original HTTP request
   7195  * @param urh argument for #MHD_upgrade_operation() on this @a response.
   7196  *        Applications must eventually use this callback to (indirectly)
   7197  *        perform the close() action on the @a sock.
   7198  */
   7199 typedef void
   7200 (MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_NONNULL_ (3)
   7201  *MHD_UpgradeHandler)(void *cls,
   7202                       struct MHD_Request *MHD_RESTRICT request,
   7203                       struct MHD_UpgradedHandle *MHD_RESTRICT urh);
   7204 
   7205 #  define MHD_UPGRADEHANDLER_DEFINED 1
   7206 #endif /* ! MHD_UPGRADEHANDLER_DEFINED */
   7207 
   7208 
   7209 /**
   7210  * Create a action object that can be used for 101 Upgrade
   7211  * responses, for example to implement WebSockets.  After sending the
   7212  * response, control over the data stream is given to the callback (which
   7213  * can then, for example, start some bi-directional communication).
   7214  * The callback will ONLY be called after the response header was successfully
   7215  * passed to the OS; if there are communication errors before, the usual MHD
   7216  * connection error handling code will be performed.
   7217  *
   7218  * At most one action can be created for any request.
   7219  *
   7220  * @param request the request to create action for
   7221  * @param upgrade_hdr_value the value of the "Upgrade:" header, mandatory
   7222                             string
   7223  * @param upgrade_handler function to call with the "upgraded" socket
   7224  * @param upgrade_handler_cls closure for @a upgrade_handler
   7225  * @param num_headers number of elements in the @a headers array,
   7226  *                    must be zero if @a headers is NULL
   7227  * @param headers the optional pointer to the array of the headers (the strings
   7228  *                are copied and does not need to be valid after return from
   7229  *                this function),
   7230  *                can be NULL if @a num_headers is zero
   7231  * @return NULL on error (i.e. invalid arguments, out of memory)
   7232  * @ingroup action
   7233  */
   7234 MHD_EXTERN_ const struct MHD_Action *
   7235 MHD_action_upgrade (struct MHD_Request *MHD_RESTRICT request,
   7236                     const char *MHD_RESTRICT upgrade_hdr_value,
   7237                     MHD_UpgradeHandler upgrade_handler,
   7238                     void *upgrade_handler_cls,
   7239                     size_t num_headers,
   7240                     const struct MHD_NameValueCStr *MHD_RESTRICT headers)
   7241 MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2)
   7242 MHD_FN_PAR_IN_SIZE_ (6, 5);
   7243 
   7244 
   7245 /**
   7246  * Create a action object that can be used for 101 Upgrade
   7247  * responses, for example to implement WebSockets.  After sending the
   7248  * response, control over the data stream is given to the callback (which
   7249  * can then, for example, start some bi-directional communication).
   7250  * The callback will ONLY be called after the response header was successfully
   7251  * passed to the OS; if there are communication errors before, the usual MHD
   7252  * connection error handling code will be performed.
   7253  *
   7254  * At most one action can be created for any request.
   7255  *
   7256  * @param request the request to create action for
   7257  * @param upgrade_hdr_value the value of the "Upgrade:" header, mandatory
   7258                             string
   7259  * @param upgrade_handler function to call with the "upgraded" socket
   7260  * @param upgrade_handler_cls closure for @a upgrade_handler
   7261  * @param num_headers number of elements in the @a headers array,
   7262  *                    must be zero if @a headers is NULL
   7263  * @param headers the optional pointer to the array of the headers (the strings
   7264  *                are copied and does not need to be valid after return from
   7265  *                this function),
   7266  *                can be NULL if @a num_headers is zero
   7267  * @return NULL on error (i.e. invalid arguments, out of memory)
   7268  * @ingroup action
   7269  */
   7270 MHD_EXTERN_ const struct MHD_UploadAction *
   7271 MHD_upload_action_upgrade (
   7272   struct MHD_Request *MHD_RESTRICT request,
   7273   const char *MHD_RESTRICT upgrade_hdr_value,
   7274   MHD_UpgradeHandler upgrade_handler,
   7275   void *upgrade_handler_cls,
   7276   size_t num_headers,
   7277   const struct MHD_NameValueCStr *MHD_RESTRICT headers)
   7278 MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2)
   7279 MHD_FN_PAR_IN_SIZE_ (6, 5);
   7280 
   7281 
   7282 /**
   7283  * Receive data on the HTTP-Upgraded connection.
   7284  *
   7285  * The function finished if one of the following happens:
   7286  * + ANY amount of data has been received,
   7287  * + timeout reached,
   7288  * + network error occurs
   7289  *
   7290  * @param urh the HTTP-Upgraded handle
   7291  * @param recv_buf_size the size of the @a recv_buf
   7292  * @param recv_buf the buffer to receive the data
   7293  * @param received_size the pointer to variable to get amount of received data
   7294  * @param max_wait_millisec the maximum wait time for the data,
   7295  *                          non-blocking operation if set to zero,
   7296  *                          wait indefinitely if larger or equal to
   7297  *                          #MHD_WAIT_INDEFINITELY,
   7298  *                          the function may return earlier if waiting is
   7299  *                          interrupted or by other reasons
   7300  * @return #MHD_SC_OK if ANY data received (check the @a received_size) or
   7301  *                    remote shut down send side (indicated by @a received_size
   7302  *                    set to zero),
   7303  *         #MHD_SC_UPGRADED_NET_TIMEOUT if NO data received but timeout expired,
   7304  *         #MHD_SC_UPGRADED_NET_CONN_CLOSED if network connection has been
   7305  *                                          closed,
   7306  *         #MHD_SC_UPGRADED_NET_CONN_BROKEN if broken network connection has
   7307  *                                          been detected,
   7308  *         #MHD_SC_UPGRADED_TLS_ERROR if TLS error occurs (only for TLS),
   7309  *         #MHD_SC_UPGRADED_NET_HARD_ERROR if any other network or sockets
   7310  *                                         unrecoverable error occurs,
   7311  *         #MHD_SC_UPGRADED_HANDLE_INVALID if @a urh is invalid,
   7312  *         #MHD_SC_UPGRADED_WAITING_NOT_SUPPORTED if timed wait is not supported
   7313  *                                                by this MHD build or platform
   7314  */
   7315 MHD_EXTERN_ enum MHD_StatusCode
   7316 MHD_upgraded_recv (struct MHD_UpgradedHandle *MHD_RESTRICT urh,
   7317                    size_t recv_buf_size,
   7318                    void *MHD_RESTRICT recv_buf,
   7319                    size_t *MHD_RESTRICT received_size,
   7320                    uint_fast64_t max_wait_millisec)
   7321 MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3, 2)
   7322 MHD_FN_PAR_OUT_ (4);
   7323 
   7324 
   7325 /**
   7326  * Send data on the HTTP-Upgraded connection.
   7327  *
   7328  * The function finished if one of the following happens:
   7329  * + ALL provided data has been sent,
   7330  * + timeout reached,
   7331  * + network error occurs
   7332  *
   7333  * Parameter @a more_data_to_come controls network buffering. When set to
   7334  * #MHD_YES, the OS waits shortly for additional data and tries to use
   7335  * the network more effeciently delaying the last network packet, if it is
   7336  * incomplete, to combine it with the next data provided.
   7337  *
   7338  * @param urh the HTTP-Upgraded handle
   7339  * @param send_buf_size the amount of data in the @a send_buf
   7340  * @param send_buf the buffer with the data to send
   7341  * @param sent_size the pointer to get the amout of sent data
   7342  * @param max_wait_millisec the maximum wait time for the data,
   7343  *                          non-blocking operation if set to zero,
   7344  *                          wait indefinitely if larger or equal to
   7345  *                          #MHD_WAIT_INDEFINITELY
   7346  * @param more_data_to_come set to #MHD_YES if the provided data in
   7347  *                          the @a send_buf is part of a larger data package,
   7348  *                          like an incomplete message or streamed
   7349  *                          (not the final) part of some file, and more data
   7350  *                          expected to be sent soon over the same connection,
   7351  *                          set to #MHD_NO the data in the @a send_buf is
   7352  *                          the complete message or the final part of
   7353  *                          the message (or file) and it should be pushed
   7354  *                          to the network (and to the client) as soon
   7355  *                          as possible
   7356  * @return #MHD_SC_OK if ANY data sent (check the @a sent_size),
   7357  *         #MHD_SC_UPGRADED_NET_TIMEOUT if NO data sent but timeout expired,
   7358  *         #MHD_SC_UPGRADED_NET_CONN_CLOSED if network connection has been
   7359  *                                          closed,
   7360  *         #MHD_SC_UPGRADED_NET_CONN_BROKEN if broken network connection has
   7361  *                                          been detected,
   7362  *         #MHD_SC_UPGRADED_TLS_ERROR if TLS error occurs (only for TLS),
   7363  *         #MHD_SC_UPGRADED_NET_HARD_ERROR if any other network or sockets
   7364  *                                         unrecoverable error occurs,
   7365  *         #MHD_SC_UPGRADED_HANDLE_INVALID if @a urh is invalid,
   7366  *         #MHD_SC_UPGRADED_WAITING_NOT_SUPPORTED if timed wait is not supported
   7367  *                                                by this MHD build or platform
   7368  */
   7369 MHD_EXTERN_ enum MHD_StatusCode
   7370 MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh,
   7371                    size_t send_buf_size,
   7372                    const void *MHD_RESTRICT send_buf,
   7373                    size_t *MHD_RESTRICT sent_size,
   7374                    uint_fast64_t max_wait_millisec,
   7375                    enum MHD_Bool more_data_to_come)
   7376 MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3, 2)
   7377 MHD_FN_PAR_OUT_ (4);
   7378 
   7379 
   7380 /**
   7381  * Close HTTP-Upgraded connection handle.
   7382  *
   7383  * The handle cannot be used after successful return from this function.
   7384  *
   7385  * The function cannot fail if called correctly (the daemon is not destroyed
   7386  * and the upgraded connection has not been closed yet).
   7387  *
   7388  * @param urh the handle to close
   7389  * @return #MHD_SC_OK on success,
   7390  *         error code otherwise
   7391  */
   7392 MHD_EXTERN_ enum MHD_StatusCode
   7393 MHD_upgraded_close (struct MHD_UpgradedHandle *urh)
   7394 MHD_FN_PAR_NONNULL_ (1);
   7395 
   7396 
   7397 /* ********************** (e) Client auth ********************** */
   7398 
   7399 
   7400 /**
   7401  * Length of the binary output of the MD5 hash function.
   7402  * @sa #MHD_digest_get_hash_size()
   7403  * @ingroup authentication
   7404  */
   7405 #define MHD_MD5_DIGEST_SIZE 16
   7406 
   7407 /**
   7408  * Length of the binary output of the SHA-256 hash function.
   7409  * @sa #MHD_digest_get_hash_size()
   7410  * @ingroup authentication
   7411  */
   7412 #define MHD_SHA256_DIGEST_SIZE 32
   7413 
   7414 /**
   7415  * Length of the binary output of the SHA-512/256 hash function.
   7416  * @warning While this value is the same as the #MHD_SHA256_DIGEST_SIZE,
   7417  *          the calculated digests for SHA-256 and SHA-512/256 are different.
   7418  * @sa #MHD_digest_get_hash_size()
   7419  * @ingroup authentication
   7420  */
   7421 #define MHD_SHA512_256_DIGEST_SIZE 32
   7422 
   7423 /**
   7424  * Base type of hash calculation.
   7425  * Used as part of #MHD_DigestAuthAlgo values.
   7426  *
   7427  * @warning Not used directly by MHD API.
   7428  */
   7429 enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_DigestBaseAlgo
   7430 {
   7431   /**
   7432    * Invalid hash algorithm value
   7433    */
   7434   MHD_DIGEST_BASE_ALGO_INVALID = 0
   7435   ,
   7436   /**
   7437    * MD5 hash algorithm.
   7438    * As specified by RFC1321
   7439    */
   7440   MHD_DIGEST_BASE_ALGO_MD5 = (1u << 0)
   7441   ,
   7442   /**
   7443    * SHA-256 hash algorithm.
   7444    * As specified by FIPS PUB 180-4
   7445    */
   7446   MHD_DIGEST_BASE_ALGO_SHA256 = (1u << 1)
   7447   ,
   7448   /**
   7449    * SHA-512/256 hash algorithm.
   7450    * As specified by FIPS PUB 180-4
   7451    */
   7452   MHD_DIGEST_BASE_ALGO_SHA512_256 = (1u << 2)
   7453 };
   7454 
   7455 /**
   7456  * The flag indicating non-session algorithm types,
   7457  * like 'MD5', 'SHA-256' or 'SHA-512-256'.
   7458  */
   7459 #define MHD_DIGEST_AUTH_ALGO_NON_SESSION    (1u << 6)
   7460 
   7461 /**
   7462  * The flag indicating session algorithm types,
   7463  * like 'MD5-sess', 'SHA-256-sess' or 'SHA-512-256-sess'.
   7464  */
   7465 #define MHD_DIGEST_AUTH_ALGO_SESSION        (1u << 7)
   7466 
   7467 /**
   7468  * Digest algorithm identification
   7469  */
   7470 enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_DigestAuthAlgo
   7471 {
   7472   /**
   7473    * Unknown or wrong algorithm type.
   7474    * Used in struct MHD_AuthDigestInfo to indicate client value that
   7475    * cannot by identified.
   7476    */
   7477   MHD_DIGEST_AUTH_ALGO_INVALID = 0
   7478   ,
   7479   /**
   7480    * The 'MD5' algorithm, non-session version.
   7481    */
   7482   MHD_DIGEST_AUTH_ALGO_MD5 =
   7483     MHD_DIGEST_BASE_ALGO_MD5 | MHD_DIGEST_AUTH_ALGO_NON_SESSION
   7484   ,
   7485   /**
   7486    * The 'MD5-sess' algorithm.
   7487    * Not supported by MHD for authentication.
   7488    */
   7489   MHD_DIGEST_AUTH_ALGO_MD5_SESSION =
   7490     MHD_DIGEST_BASE_ALGO_MD5 | MHD_DIGEST_AUTH_ALGO_SESSION
   7491   ,
   7492   /**
   7493    * The 'SHA-256' algorithm, non-session version.
   7494    */
   7495   MHD_DIGEST_AUTH_ALGO_SHA256 =
   7496     MHD_DIGEST_BASE_ALGO_SHA256 | MHD_DIGEST_AUTH_ALGO_NON_SESSION
   7497   ,
   7498   /**
   7499    * The 'SHA-256-sess' algorithm.
   7500    * Not supported by MHD for authentication.
   7501    */
   7502   MHD_DIGEST_AUTH_ALGO_SHA256_SESSION =
   7503     MHD_DIGEST_BASE_ALGO_SHA256 | MHD_DIGEST_AUTH_ALGO_SESSION
   7504   ,
   7505   /**
   7506    * The 'SHA-512-256' (SHA-512/256) algorithm.
   7507    */
   7508   MHD_DIGEST_AUTH_ALGO_SHA512_256 =
   7509     MHD_DIGEST_BASE_ALGO_SHA512_256 | MHD_DIGEST_AUTH_ALGO_NON_SESSION
   7510   ,
   7511   /**
   7512    * The 'SHA-512-256-sess' (SHA-512/256 session) algorithm.
   7513    * Not supported by MHD for authentication.
   7514    */
   7515   MHD_DIGEST_AUTH_ALGO_SHA512_256_SESSION =
   7516     MHD_DIGEST_BASE_ALGO_SHA512_256 | MHD_DIGEST_AUTH_ALGO_SESSION
   7517 };
   7518 
   7519 
   7520 /**
   7521  * Get digest size in bytes for specified algorithm.
   7522  *
   7523  * The size of the digest specifies the size of the userhash, userdigest
   7524  * and other parameters which size depends on used hash algorithm.
   7525  * @param algo the algorithm to check
   7526  * @return the size (in bytes) of the digest (either #MHD_MD5_DIGEST_SIZE or
   7527  *         #MHD_SHA256_DIGEST_SIZE/MHD_SHA512_256_DIGEST_SIZE)
   7528  *         or zero if the input value is not supported or not valid
   7529  * @sa #MHD_digest_auth_calc_userdigest()
   7530  * @sa #MHD_digest_auth_calc_userhash(), #MHD_digest_auth_calc_userhash_hex()
   7531  * @ingroup authentication
   7532  */
   7533 MHD_EXTERN_ size_t
   7534 MHD_digest_get_hash_size (enum MHD_DigestAuthAlgo algo)
   7535 MHD_FN_CONST_;
   7536 
   7537 /**
   7538  * Digest algorithm identification, allow multiple selection.
   7539  *
   7540  * #MHD_DigestAuthAlgo always can be casted to #MHD_DigestAuthMultiAlgo, but
   7541  * not vice versa.
   7542  */
   7543 enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_DigestAuthMultiAlgo
   7544 {
   7545   /**
   7546    * Unknown or wrong algorithm type.
   7547    */
   7548   MHD_DIGEST_AUTH_MULT_ALGO_INVALID = MHD_DIGEST_AUTH_ALGO_INVALID
   7549   ,
   7550   /**
   7551    * The 'MD5' algorithm, non-session version.
   7552    */
   7553   MHD_DIGEST_AUTH_MULT_ALGO_MD5 = MHD_DIGEST_AUTH_ALGO_MD5
   7554   ,
   7555   /**
   7556    * The 'MD5-sess' algorithm.
   7557    * Not supported by MHD for authentication.
   7558    * Reserved value.
   7559    */
   7560   MHD_DIGEST_AUTH_MULT_ALGO_MD5_SESSION = MHD_DIGEST_AUTH_ALGO_MD5_SESSION
   7561   ,
   7562   /**
   7563    * The 'SHA-256' algorithm, non-session version.
   7564    */
   7565   MHD_DIGEST_AUTH_MULT_ALGO_SHA256 = MHD_DIGEST_AUTH_ALGO_SHA256
   7566   ,
   7567   /**
   7568    * The 'SHA-256-sess' algorithm.
   7569    * Not supported by MHD for authentication.
   7570    * Reserved value.
   7571    */
   7572   MHD_DIGEST_AUTH_MULT_ALGO_SHA256_SESSION =
   7573     MHD_DIGEST_AUTH_ALGO_SHA256_SESSION
   7574   ,
   7575   /**
   7576    * The 'SHA-512-256' (SHA-512/256) algorithm, non-session version.
   7577    */
   7578   MHD_DIGEST_AUTH_MULT_ALGO_SHA512_256 = MHD_DIGEST_AUTH_ALGO_SHA512_256
   7579   ,
   7580   /**
   7581    * The 'SHA-512-256-sess' (SHA-512/256 session) algorithm.
   7582    * Not supported by MHD for authentication.
   7583    * Reserved value.
   7584    */
   7585   MHD_DIGEST_AUTH_MULT_ALGO_SHA512_256_SESSION =
   7586     MHD_DIGEST_AUTH_ALGO_SHA512_256_SESSION
   7587   ,
   7588   /**
   7589    * SHA-256 or SHA-512/256 non-session algorithm, MHD will choose
   7590    * the preferred or the matching one.
   7591    */
   7592   MHD_DIGEST_AUTH_MULT_ALGO_SHA_ANY_NON_SESSION =
   7593     MHD_DIGEST_AUTH_ALGO_SHA256 | MHD_DIGEST_AUTH_ALGO_SHA512_256
   7594   ,
   7595   /**
   7596    * Any non-session algorithm, MHD will choose the preferred or
   7597    * the matching one.
   7598    */
   7599   MHD_DIGEST_AUTH_MULT_ALGO_ANY_NON_SESSION =
   7600     (0x3F) | MHD_DIGEST_AUTH_ALGO_NON_SESSION
   7601   ,
   7602   /**
   7603    * The SHA-256 or SHA-512/256 session algorithm.
   7604    * Not supported by MHD.
   7605    * Reserved value.
   7606    */
   7607   MHD_DIGEST_AUTH_MULT_ALGO_SHA_ANY_SESSION =
   7608     MHD_DIGEST_AUTH_ALGO_SHA256_SESSION
   7609     | MHD_DIGEST_AUTH_ALGO_SHA512_256_SESSION
   7610   ,
   7611   /**
   7612    * Any session algorithm.
   7613    * Not supported by MHD.
   7614    * Reserved value.
   7615    */
   7616   MHD_DIGEST_AUTH_MULT_ALGO_ANY_SESSION =
   7617     (0x3F) | MHD_DIGEST_AUTH_ALGO_SESSION
   7618   ,
   7619   /**
   7620    * The MD5 algorithm, session or non-session.
   7621    * Currently supported as non-session only.
   7622    */
   7623   MHD_DIGEST_AUTH_MULT_ALGO_MD5_ANY =
   7624     MHD_DIGEST_AUTH_MULT_ALGO_MD5 | MHD_DIGEST_AUTH_MULT_ALGO_MD5_SESSION
   7625   ,
   7626   /**
   7627    * The SHA-256 algorithm, session or non-session.
   7628    * Currently supported as non-session only.
   7629    */
   7630   MHD_DIGEST_AUTH_MULT_ALGO_SHA256_ANY =
   7631     MHD_DIGEST_AUTH_MULT_ALGO_SHA256
   7632     | MHD_DIGEST_AUTH_MULT_ALGO_SHA256_SESSION
   7633   ,
   7634   /**
   7635    * The SHA-512/256 algorithm, session or non-session.
   7636    * Currently supported as non-session only.
   7637    */
   7638   MHD_DIGEST_AUTH_MULT_ALGO_SHA512_256_ANY =
   7639     MHD_DIGEST_AUTH_MULT_ALGO_SHA512_256
   7640     | MHD_DIGEST_AUTH_MULT_ALGO_SHA512_256_SESSION
   7641   ,
   7642   /**
   7643    * The SHA-256 or SHA-512/256 algorithm, session or non-session.
   7644    * Currently supported as non-session only.
   7645    */
   7646   MHD_DIGEST_AUTH_MULT_ALGO_SHA_ANY_ANY =
   7647     MHD_DIGEST_AUTH_MULT_ALGO_SHA_ANY_NON_SESSION
   7648     | MHD_DIGEST_AUTH_MULT_ALGO_SHA_ANY_SESSION
   7649   ,
   7650   /**
   7651    * Any algorithm, MHD will choose the preferred or the matching one.
   7652    */
   7653   MHD_DIGEST_AUTH_MULT_ALGO_ANY =
   7654     (0x3F) | MHD_DIGEST_AUTH_ALGO_NON_SESSION | MHD_DIGEST_AUTH_ALGO_SESSION
   7655 };
   7656 
   7657 
   7658 /**
   7659  * Calculate "userhash", return it as binary data.
   7660  *
   7661  * The "userhash" is the hash of the string "username:realm".
   7662  *
   7663  * The "userhash" could be used to avoid sending username in cleartext in Digest
   7664  * Authorization client's header.
   7665  *
   7666  * Userhash is not designed to hide the username in local database or files,
   7667  * as username in cleartext is required for #MHD_digest_auth_check() function
   7668  * to check the response, but it can be used to hide username in HTTP headers.
   7669  *
   7670  * This function could be used when the new username is added to the username
   7671  * database to save the "userhash" alongside with the username (preferably) or
   7672  * when loading list of the usernames to generate the userhash for every loaded
   7673  * username (this will cause delays at the start with the long lists).
   7674  *
   7675  * Once "userhash" is generated it could be used to identify users by clients
   7676  * with "userhash" support.
   7677  * Avoid repetitive usage of this function for the same username/realm
   7678  * combination as it will cause excessive CPU load; save and reuse the result
   7679  * instead.
   7680  *
   7681  * @param algo the algorithm for userhash calculations
   7682  * @param username the username
   7683  * @param realm the realm
   7684  * @param[out] userhash_bin the output buffer for userhash as binary data;
   7685  *                          if this function succeeds, then this buffer has
   7686  *                          #MHD_digest_get_hash_size() bytes of userhash
   7687  *                          upon return
   7688  * @param bin_buf_size the size of the @a userhash_bin buffer, must be
   7689  *                     at least #MHD_digest_get_hash_size() bytes long
   7690  * @return #MHD_SC_OK on success,
   7691  *         #MHD_SC_OUT_BUFF_TOO_SMALL if @a bin_buf_size is too small,
   7692  *         #MHD_SC_HASH_FAILED if hashing failed,
   7693  *         #MHD_SC_AUTH_DIGEST_ALGO_NOT_SUPPORTED if requested @a algo is
   7694  *                                                unknown or unsupported.
   7695  * @sa #MHD_digest_auth_calc_userhash_hex()
   7696  * @ingroup authentication
   7697  */
   7698 MHD_EXTERN_ enum MHD_StatusCode
   7699 MHD_digest_auth_calc_userhash (enum MHD_DigestAuthAlgo algo,
   7700                                const char *MHD_RESTRICT username,
   7701                                const char *MHD_RESTRICT realm,
   7702                                size_t bin_buf_size,
   7703                                void *MHD_RESTRICT userhash_bin)
   7704 MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_CSTR_ (2)
   7705 MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_OUT_SIZE_ (5, 4);
   7706 
   7707 
   7708 /**
   7709  * Calculate "userhash", return it as hexadecimal string.
   7710  *
   7711  * The "userhash" is the hash of the string "username:realm".
   7712  *
   7713  * The "userhash" could be used to avoid sending username in cleartext in Digest
   7714  * Authorization client's header.
   7715  *
   7716  * Userhash is not designed to hide the username in local database or files,
   7717  * as username in cleartext is required for #MHD_digest_auth_check() function
   7718  * to check the response, but it can be used to hide username in HTTP headers.
   7719  *
   7720  * This function could be used when the new username is added to the username
   7721  * database to save the "userhash" alongside with the username (preferably) or
   7722  * when loading list of the usernames to generate the userhash for every loaded
   7723  * username (this will cause delays at the start with the long lists).
   7724  *
   7725  * Once "userhash" is generated it could be used to identify users by clients
   7726  * with "userhash" support.
   7727  * Avoid repetitive usage of this function for the same username/realm
   7728  * combination as it will cause excessive CPU load; save and reuse the result
   7729  * instead.
   7730  *
   7731  * @param algo the algorithm for userhash calculations
   7732  * @param username the username
   7733  * @param realm the realm
   7734  * @param hex_buf_size the size of the @a userhash_hex buffer, must be
   7735  *                     at least #MHD_digest_get_hash_size()*2+1 chars long
   7736  * @param[out] userhash_hex the output buffer for userhash as hex string;
   7737  *                          if this function succeeds, then this buffer has
   7738  *                          #MHD_digest_get_hash_size()*2 chars long
   7739  *                          userhash string plus one zero-termination char
   7740  * @return #MHD_SC_OK on success,
   7741  *         #MHD_SC_OUT_BUFF_TOO_SMALL if @a bin_buf_size is too small,
   7742  *         #MHD_SC_HASH_FAILED if hashing failed,
   7743  *         #MHD_SC_AUTH_DIGEST_ALGO_NOT_SUPPORTED if requested @a algo is
   7744  *                                                unknown or unsupported.
   7745  * @sa #MHD_digest_auth_calc_userhash()
   7746  * @ingroup authentication
   7747  */
   7748 MHD_EXTERN_ enum MHD_StatusCode
   7749 MHD_digest_auth_calc_userhash_hex (
   7750   enum MHD_DigestAuthAlgo algo,
   7751   const char *MHD_RESTRICT username,
   7752   const char *MHD_RESTRICT realm,
   7753   size_t hex_buf_size,
   7754   char userhash_hex[MHD_FN_PAR_DYN_ARR_SIZE_ (hex_buf_size)])
   7755 MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_CSTR_ (2)
   7756 MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_OUT_SIZE_ (5, 4);
   7757 
   7758 
   7759 /**
   7760  * The type of username used by client in Digest Authorization header
   7761  *
   7762  * Values are sorted so simplified checks could be used.
   7763  * For example:
   7764  * * (value <= MHD_DIGEST_AUTH_UNAME_TYPE_INVALID) is true if no valid username
   7765  *   is provided by the client (not used currently)
   7766  * * (value >= MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH) is true if username is
   7767  *   provided in any form
   7768  * * (value >= MHD_DIGEST_AUTH_UNAME_TYPE_STANDARD) is true if username is
   7769  *   provided in clear text (no userhash matching is needed)
   7770  */
   7771 enum MHD_FIXED_ENUM_MHD_SET_ MHD_DigestAuthUsernameType
   7772 {
   7773   /**
   7774    * No username parameter is in Digest Authorization header.
   7775    * Not used currently. Value #MHD_SC_REQ_AUTH_DATA_BROKEN is returned
   7776    * by #MHD_request_get_info_dynamic_sz() if the request has no username.
   7777    */
   7778   MHD_DIGEST_AUTH_UNAME_TYPE_MISSING = 0
   7779   ,
   7780   /**
   7781    * The 'username' parameter is used to specify the username.
   7782    */
   7783   MHD_DIGEST_AUTH_UNAME_TYPE_STANDARD = (1u << 2)
   7784   ,
   7785   /**
   7786    * The username is specified by 'username*' parameter with
   7787    * the extended notation (see RFC 5987, section-3.2.1).
   7788    * The only difference between standard and extended types is
   7789    * the way how username value is encoded in the header.
   7790    */
   7791   MHD_DIGEST_AUTH_UNAME_TYPE_EXTENDED = (1u << 3)
   7792   ,
   7793   /**
   7794    * The username provided in form of 'userhash' as
   7795    * specified by RFC 7616, section-3.4.4.
   7796    * @sa #MHD_digest_auth_calc_userhash_hex(), #MHD_digest_auth_calc_userhash()
   7797    */
   7798   MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH = (1u << 1)
   7799   ,
   7800   /**
   7801    * The invalid combination of username parameters are used by client.
   7802    * Either:
   7803    * + both 'username' and 'username*' are used
   7804    * + 'username*' is used with 'userhash=true'
   7805    * + 'username*' used with invalid extended notation
   7806    * + 'username' is not hexadecimal string, while 'userhash' set to 'true'
   7807    * Not used currently. Value #MHD_SC_REQ_AUTH_DATA_BROKEN is returned
   7808    * by #MHD_request_get_info_dynamic_sz() if the request has broken username.
   7809    */
   7810   MHD_DIGEST_AUTH_UNAME_TYPE_INVALID = (1u << 0)
   7811 };
   7812 
   7813 /**
   7814  * The QOP ('quality of protection') types.
   7815  */
   7816 enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_DigestAuthQOP
   7817 {
   7818   /**
   7819    * Invalid/unknown QOP.
   7820    * Used in struct MHD_AuthDigestInfo to indicate client value that
   7821    * cannot by identified.
   7822    */
   7823   MHD_DIGEST_AUTH_QOP_INVALID = 0
   7824   ,
   7825   /**
   7826    * No QOP parameter.
   7827    * As described in old RFC 2069 original specification.
   7828    * This mode is not allowed by latest RFCs and should be used only to
   7829    * communicate with clients that do not support more modern modes (with QOP
   7830    * parameter).
   7831    * This mode is less secure than other modes and inefficient.
   7832    */
   7833   MHD_DIGEST_AUTH_QOP_NONE = (1u << 0)
   7834   ,
   7835   /**
   7836    * The 'auth' QOP type.
   7837    */
   7838   MHD_DIGEST_AUTH_QOP_AUTH = (1u << 1)
   7839   ,
   7840   /**
   7841    * The 'auth-int' QOP type.
   7842    * Not supported by MHD for authentication.
   7843    */
   7844   MHD_DIGEST_AUTH_QOP_AUTH_INT = (1u << 2)
   7845 };
   7846 
   7847 /**
   7848  * The QOP ('quality of protection') types, multiple selection.
   7849  *
   7850  * #MHD_DigestAuthQOP always can be casted to #MHD_DigestAuthMultiQOP, but
   7851  * not vice versa.
   7852  */
   7853 enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_DigestAuthMultiQOP
   7854 {
   7855   /**
   7856    * Invalid/unknown QOP.
   7857    */
   7858   MHD_DIGEST_AUTH_MULT_QOP_INVALID = MHD_DIGEST_AUTH_QOP_INVALID
   7859   ,
   7860   /**
   7861    * No QOP parameter.
   7862    * As described in old RFC 2069 original specification.
   7863    * This mode is not allowed by latest RFCs and should be used only to
   7864    * communicate with clients that do not support more modern modes (with QOP
   7865    * parameter).
   7866    * This mode is less secure than other modes and inefficient.
   7867    */
   7868   MHD_DIGEST_AUTH_MULT_QOP_NONE = MHD_DIGEST_AUTH_QOP_NONE
   7869   ,
   7870   /**
   7871    * The 'auth' QOP type.
   7872    */
   7873   MHD_DIGEST_AUTH_MULT_QOP_AUTH = MHD_DIGEST_AUTH_QOP_AUTH
   7874   ,
   7875   /**
   7876    * The 'auth-int' QOP type.
   7877    * Not supported by MHD.
   7878    * Reserved value.
   7879    */
   7880   MHD_DIGEST_AUTH_MULT_QOP_AUTH_INT = MHD_DIGEST_AUTH_QOP_AUTH_INT
   7881   ,
   7882   /**
   7883    * The 'auth' QOP type OR the old RFC2069 (no QOP) type.
   7884    * In other words: any types except 'auth-int'.
   7885    * RFC2069-compatible mode is allowed, thus this value should be used only
   7886    * when it is really necessary.
   7887    */
   7888   MHD_DIGEST_AUTH_MULT_QOP_ANY_NON_INT =
   7889     MHD_DIGEST_AUTH_QOP_NONE | MHD_DIGEST_AUTH_QOP_AUTH
   7890   ,
   7891   /**
   7892    * Any 'auth' QOP type ('auth' or 'auth-int').
   7893    * Currently supported as 'auth' QOP type only.
   7894    */
   7895   MHD_DIGEST_AUTH_MULT_QOP_AUTH_ANY =
   7896     MHD_DIGEST_AUTH_QOP_AUTH | MHD_DIGEST_AUTH_QOP_AUTH_INT
   7897 };
   7898 
   7899 /**
   7900  * The type of 'nc' (nonce count) value provided in the request
   7901  */
   7902 enum MHD_FIXED_ENUM_MHD_SET_ MHD_DigestAuthNC
   7903 {
   7904   /**
   7905    * Readable hexdecimal non-zero number.
   7906    * The decoded value is placed in @a nc member of struct MHD_AuthDigestInfo
   7907    */
   7908   MHD_DIGEST_AUTH_NC_NUMBER = 1
   7909   ,
   7910   /**
   7911    * Readable zero number.
   7912    * Compliant clients should not use such values.
   7913    * Can be treated as invalid request.
   7914    */
   7915   MHD_DIGEST_AUTH_NC_ZERO = 2
   7916   ,
   7917   /**
   7918    * 'nc' value is not provided by the client.
   7919    * Unless old RFC 2069 mode is allowed, this should be treated as invalid
   7920    * request.
   7921    */
   7922   MHD_DIGEST_AUTH_NC_NONE = 3
   7923   ,
   7924   /**
   7925    * 'nc' value is too long to be decoded.
   7926    * Compliant clients should not use such values.
   7927    * Can be treated as invalid request.
   7928    */
   7929   MHD_DIGEST_AUTH_NC_TOO_LONG = 4
   7930   ,
   7931   /**
   7932    * 'nc' value is too large for uint32_t.
   7933    * Compliant clients should not use such values.
   7934    * Can be treated as request with a stale nonce or as invalid request.
   7935    */
   7936   MHD_DIGEST_AUTH_NC_TOO_LARGE = 5
   7937 };
   7938 
   7939 
   7940 /**
   7941  * Information from Digest Authorization client's header.
   7942  *
   7943  * @see #MHD_REQUEST_INFO_DYNAMIC_AUTH_DIGEST_INFO
   7944  */
   7945 struct MHD_AuthDigestInfo
   7946 {
   7947   /**
   7948    * The algorithm as defined by client.
   7949    * Set automatically to MD5 if not specified by client.
   7950    */
   7951   enum MHD_DigestAuthAlgo algo;
   7952 
   7953   /**
   7954    * The type of username used by client.
   7955    */
   7956   enum MHD_DigestAuthUsernameType uname_type;
   7957 
   7958   /**
   7959    * The username string.
   7960    * Used only if username type is standard or extended, always NULL otherwise.
   7961    * If extended notation is used, this string is pct-decoded string
   7962    * with charset and language tag removed (i.e. it is original username
   7963    * extracted from the extended notation).
   7964    * When userhash is used by the client, the string pointer is NULL and
   7965    * @a userhash_hex and @a userhash_bin are set.
   7966    */
   7967   struct MHD_StringNullable username;
   7968 
   7969   /**
   7970    * The userhash string.
   7971    * Valid only if username type is userhash.
   7972    * This is unqoted string without decoding of the hexadecimal
   7973    * digits (as provided by the client).
   7974    * @sa #MHD_digest_auth_calc_userhash_hex()
   7975    */
   7976   struct MHD_StringNullable userhash_hex;
   7977 
   7978   /**
   7979    * The userhash decoded to binary form.
   7980    * Used only if username type is userhash, always NULL otherwise.
   7981    * When not NULL, this points to binary sequence @a userhash_bin_size bytes
   7982    * long.
   7983    * The valid size should be #MHD_digest_get_hash_size() bytes.
   7984    * @warning This is a binary data, no zero termination.
   7985    * @warning To avoid buffer overruns, always check the size of the data before
   7986    *          use, because @a userhash_bin can point even to zero-sized
   7987    *          data.
   7988    * @sa #MHD_digest_auth_calc_userhash()
   7989    */
   7990   const uint8_t *userhash_bin;
   7991 
   7992   /**
   7993    * The size of the data pointed by @a userhash_bin.
   7994    * Always zero when @a userhash_bin is NULL.
   7995    */
   7996   size_t userhash_bin_size;
   7997 
   7998   /**
   7999    * The 'opaque' parameter value, as specified by client.
   8000    * If not specified by client then string pointer is NULL.
   8001    */
   8002   struct MHD_StringNullable opaque;
   8003 
   8004   /**
   8005    * The 'realm' parameter value, as specified by client.
   8006    * If not specified by client then string pointer is NULL.
   8007    */
   8008   struct MHD_StringNullable realm;
   8009 
   8010   /**
   8011    * The 'qop' parameter value.
   8012    */
   8013   enum MHD_DigestAuthQOP qop;
   8014 
   8015   /**
   8016    * The length of the 'cnonce' parameter value, including possible
   8017    * backslash-escape characters.
   8018    * 'cnonce' is used in hash calculation, which is CPU-intensive procedure.
   8019    * An application may want to reject too large cnonces to limit the CPU load.
   8020    * A few kilobytes is a reasonable limit, typically cnonce is just 32-160
   8021    * characters long.
   8022    */
   8023   size_t cnonce_len;
   8024 
   8025   /**
   8026    * The type of 'nc' (nonce count) value provided in the request.
   8027    */
   8028   enum MHD_DigestAuthNC nc_type;
   8029 
   8030   /**
   8031    * The nc (nonce count) parameter value.
   8032    * Can be used by application to limit the number of nonce re-uses. If @a nc
   8033    * is higher than application wants to allow, then "auth required" response
   8034    * with 'stale=true' could be used to force client to retry with the fresh
   8035    * 'nonce'.
   8036    * Set to zero when @a nc_type is not set to #MHD_DIGEST_AUTH_NC_NUMBER.
   8037    */
   8038   uint_fast32_t nc;
   8039 };
   8040 
   8041 /**
   8042  * The result of digest authentication of the client.
   8043  *
   8044  * All error values are zero or negative.
   8045  */
   8046 enum MHD_FIXED_ENUM_MHD_SET_ MHD_DigestAuthResult
   8047 {
   8048   /**
   8049    * Authentication OK.
   8050    */
   8051   MHD_DAUTH_OK = 1
   8052   ,
   8053   /**
   8054    * General error, like "out of memory".
   8055    * Authentication may be valid, but cannot be checked.
   8056    */
   8057   MHD_DAUTH_ERROR = 0
   8058   ,
   8059   /**
   8060    * No "Authorization" header for Digest Authentication.
   8061    */
   8062   MHD_DAUTH_HEADER_MISSING = -1
   8063   ,
   8064   /**
   8065    * Wrong format of the header.
   8066    * Also returned if required parameters in Authorization header are missing
   8067    * or broken (in invalid format).
   8068    */
   8069   MHD_DAUTH_HEADER_BROKEN = -9
   8070   ,
   8071   /**
   8072    * Unsupported algorithm.
   8073    */
   8074   MHD_DAUTH_UNSUPPORTED_ALGO = -10
   8075   ,
   8076   /**
   8077    * Unsupported 'qop'.
   8078    */
   8079   MHD_DAUTH_UNSUPPORTED_QOP = -11
   8080   ,
   8081   /**
   8082    * Incorrect userdigest size.
   8083    */
   8084   MHD_DAUTH_INVALID_USERDIGEST_SIZE = -15
   8085   ,
   8086   /**
   8087    * Wrong 'username'.
   8088    */
   8089   MHD_DAUTH_WRONG_USERNAME = -17
   8090   ,
   8091   /**
   8092    * Wrong 'realm'.
   8093    */
   8094   MHD_DAUTH_WRONG_REALM = -18
   8095   ,
   8096   /**
   8097    * Wrong 'URI' (or URI parameters).
   8098    */
   8099   MHD_DAUTH_WRONG_URI = -19
   8100   ,
   8101   /**
   8102    * Wrong 'qop'.
   8103    */
   8104   MHD_DAUTH_WRONG_QOP = -20
   8105   ,
   8106   /**
   8107    * Wrong 'algorithm'.
   8108    */
   8109   MHD_DAUTH_WRONG_ALGO = -21
   8110   ,
   8111   /**
   8112    * Too large (>64 KiB) Authorization parameter value.
   8113    */
   8114   MHD_DAUTH_TOO_LARGE = -22
   8115   ,
   8116   /* The different form of naming is intentionally used for the results below,
   8117    * as they are more important */
   8118 
   8119   /**
   8120    * The 'nonce' is too old. Suggest the client to retry with the same
   8121    * username and password to get the fresh 'nonce'.
   8122    * The validity of the 'nonce' may be not checked.
   8123    */
   8124   MHD_DAUTH_NONCE_STALE = -25
   8125   ,
   8126   /**
   8127    * The 'nonce' is wrong. May indicate an attack attempt.
   8128    */
   8129   MHD_DAUTH_NONCE_WRONG = -33
   8130   ,
   8131   /**
   8132    * The 'response' is wrong. May indicate a wrong password used or
   8133    * an attack attempt.
   8134    */
   8135   MHD_DAUTH_RESPONSE_WRONG = -34
   8136 };
   8137 
   8138 
   8139 /**
   8140  * Authenticates the authorization header sent by the client.
   8141  *
   8142  * If RFC2069 mode is allowed by setting bit #MHD_DIGEST_AUTH_QOP_NONE in
   8143  * @a mqop and the client uses this mode, then server generated nonces are
   8144  * used as one-time nonces because nonce-count is not supported in this old RFC.
   8145  * Communication in this mode is very inefficient, especially if the client
   8146  * requests several resources one-by-one as for every request a new nonce must
   8147  * be generated and client repeats all requests twice (first time to get a new
   8148  * nonce and second time to perform an authorised request).
   8149  *
   8150  * @param request the request
   8151  * @param realm the realm for authorization of the client
   8152  * @param username the username to be authenticated, must be in clear text
   8153  *                 even if userhash is used by the client
   8154  * @param password the password matching the @a username (and the @a realm)
   8155  * @param max_nc the maximum allowed nc (Nonce Count) value, if client's nc
   8156  *               exceeds the specified value then MHD_DAUTH_NONCE_STALE is
   8157  *               returned;
   8158  *               if zero is specified then daemon default value is used.
   8159  * @param mqop the QOP to use
   8160  * @param malgo digest algorithms allowed to use, fail if algorithm used
   8161  *               by the client is not allowed by this parameter
   8162  * @return #MHD_DAUTH_OK if authenticated,
   8163  *         the error code otherwise
   8164  * @ingroup authentication
   8165  */
   8166 MHD_EXTERN_ enum MHD_DigestAuthResult
   8167 MHD_digest_auth_check (struct MHD_Request *MHD_RESTRICT request,
   8168                        const char *MHD_RESTRICT realm,
   8169                        const char *MHD_RESTRICT username,
   8170                        const char *MHD_RESTRICT password,
   8171                        uint_fast32_t max_nc,
   8172                        enum MHD_DigestAuthMultiQOP mqop,
   8173                        enum MHD_DigestAuthMultiAlgo malgo)
   8174 MHD_FN_PAR_NONNULL_ALL_
   8175 MHD_FN_PAR_CSTR_ (2) MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_CSTR_ (4);
   8176 
   8177 
   8178 /**
   8179  * Calculate userdigest, return it as a binary data.
   8180  *
   8181  * The "userdigest" is the hash of the "username:realm:password" string.
   8182  *
   8183  * The "userdigest" can be used to avoid storing the password in clear text
   8184  * in database/files
   8185  *
   8186  * This function is designed to improve security of stored credentials,
   8187  * the "userdigest" does not improve security of the authentication process.
   8188  *
   8189  * The results can be used to store username & userdigest pairs instead of
   8190  * username & password pairs. To further improve security, application may
   8191  * store username & userhash & userdigest triplets.
   8192  *
   8193  * @param algo the digest algorithm
   8194  * @param username the username
   8195  * @param realm the realm
   8196  * @param password the password
   8197  * @param bin_buf_size the size of the @a userdigest_bin buffer, must be
   8198  *                     at least #MHD_digest_get_hash_size() bytes long
   8199  * @param[out] userdigest_bin the output buffer for userdigest;
   8200  *                            if this function succeeds, then this buffer has
   8201  *                            #MHD_digest_get_hash_size() bytes of
   8202  *                            userdigest upon return
   8203  * @return #MHD_SC_OK on success,
   8204  *         #MHD_SC_OUT_BUFF_TOO_SMALL if @a bin_buf_size is too small,
   8205  *         #MHD_SC_HASH_FAILED if hashing failed,
   8206  *         #MHD_SC_AUTH_DIGEST_ALGO_NOT_SUPPORTED if requested @a algo is
   8207  *                                                unknown or unsupported.
   8208  * @sa #MHD_digest_auth_check_digest()
   8209  * @ingroup authentication
   8210  */
   8211 MHD_EXTERN_ enum MHD_StatusCode
   8212 MHD_digest_auth_calc_userdigest (enum MHD_DigestAuthAlgo algo,
   8213                                  const char *MHD_RESTRICT username,
   8214                                  const char *MHD_RESTRICT realm,
   8215                                  const char *MHD_RESTRICT password,
   8216                                  size_t bin_buf_size,
   8217                                  void *MHD_RESTRICT userdigest_bin)
   8218 MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_
   8219 MHD_FN_PAR_CSTR_ (2)
   8220 MHD_FN_PAR_CSTR_ (3)
   8221 MHD_FN_PAR_CSTR_ (4)
   8222 MHD_FN_PAR_OUT_SIZE_ (6, 5);
   8223 
   8224 
   8225 /**
   8226  * Authenticates the authorization header sent by the client by using
   8227  * hash of "username:realm:password".
   8228  *
   8229  * If RFC2069 mode is allowed by setting bit #MHD_DIGEST_AUTH_QOP_NONE in
   8230  * @a mqop and the client uses this mode, then server generated nonces are
   8231  * used as one-time nonces because nonce-count is not supported in this old RFC.
   8232  * Communication in this mode is very inefficient, especially if the client
   8233  * requests several resources one-by-one as for every request a new nonce must
   8234  * be generated and client repeats all requests twice (first time to get a new
   8235  * nonce and second time to perform an authorised request).
   8236  *
   8237  * @param request the request
   8238  * @param realm the realm for authorization of the client
   8239  * @param username the username to be authenticated, must be in clear text
   8240  *                 even if userhash is used by the client
   8241  * @param userdigest_size the size of the @a userdigest in bytes, must match the
   8242  *                        hashing algorithm (see #MHD_MD5_DIGEST_SIZE,
   8243  *                        #MHD_SHA256_DIGEST_SIZE, #MHD_SHA512_256_DIGEST_SIZE,
   8244  *                        #MHD_digest_get_hash_size())
   8245  * @param userdigest the precalculated binary hash of the string
   8246  *                   "username:realm:password",
   8247  *                   see #MHD_digest_auth_calc_userdigest()
   8248  * @param max_nc the maximum allowed nc (Nonce Count) value, if client's nc
   8249  *               exceeds the specified value then MHD_DAUTH_NONCE_STALE is
   8250  *               returned;
   8251  *               if zero is specified then daemon default value is used.
   8252  * @param mqop the QOP to use
   8253  * @param malgo digest algorithms allowed to use, fail if algorithm used
   8254  *              by the client is not allowed by this parameter;
   8255  *              more than one base algorithms (MD5, SHA-256, SHA-512/256)
   8256  *              cannot be used at the same time for this function
   8257  *              as @a userdigest must match specified algorithm
   8258  * @return #MHD_DAUTH_OK if authenticated,
   8259  *         the error code otherwise
   8260  * @sa #MHD_digest_auth_calc_userdigest()
   8261  * @ingroup authentication
   8262  */
   8263 MHD_EXTERN_ enum MHD_DigestAuthResult
   8264 MHD_digest_auth_check_digest (struct MHD_Request *MHD_RESTRICT request,
   8265                               const char *MHD_RESTRICT realm,
   8266                               const char *MHD_RESTRICT username,
   8267                               size_t userdigest_size,
   8268                               const void *MHD_RESTRICT userdigest,
   8269                               uint_fast32_t max_nc,
   8270                               enum MHD_DigestAuthMultiQOP mqop,
   8271                               enum MHD_DigestAuthMultiAlgo malgo)
   8272 MHD_FN_PAR_NONNULL_ALL_
   8273 MHD_FN_PAR_CSTR_ (2)
   8274 MHD_FN_PAR_CSTR_ (3)
   8275 MHD_FN_PAR_IN_SIZE_ (5, 4);
   8276 
   8277 
   8278 /**
   8279  * Add Digest Authentication "challenge" to the response.
   8280  *
   8281  * The response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code.
   8282  *
   8283  * If @a mqop allows both RFC 2069 (#MHD_DIGEST_AUTH_QOP_NONE) and other QOP
   8284  * values, then the "challenge" is formed like if MHD_DIGEST_AUTH_QOP_NONE bit
   8285  * was not set, because such "challenge" should be backward-compatible with
   8286  * RFC 2069.
   8287  *
   8288  * If @a mqop allows only MHD_DIGEST_AUTH_MULT_QOP_NONE, then the response is
   8289  * formed in strict accordance with RFC 2069 (no 'qop', no 'userhash', no
   8290  * 'charset'). For better compatibility with clients, it is recommended (but
   8291  * not required) to set @a domain to NULL in this mode.
   8292  *
   8293  * New nonces are generated each time when the resulting response is used.
   8294  *
   8295  * See RFC 7616, section 3.3 for details.
   8296  *
   8297  * @param response the response to update; should contain the "access denied"
   8298  *                 body;
   8299  *                 note: this function sets the "WWW Authenticate" header and
   8300  *                 the caller should not set this header;
   8301  *                 the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status
   8302  *                 code;
   8303  *                 the NULL is tolerated (the result is
   8304  *                 #MHD_SC_RESP_POINTER_NULL)
   8305  * @param realm the realm presented to the client
   8306  * @param opaque the string for opaque value, can be NULL, but NULL is
   8307  *               not recommended for better compatibility with clients;
   8308  *               the recommended format is hex or Base64 encoded string
   8309  * @param domain the optional space-separated list of URIs for which the
   8310  *               same authorisation could be used, URIs can be in form
   8311  *               "path-absolute" (the path for the same host with initial slash)
   8312  *               or in form "absolute-URI" (the full path with protocol), in
   8313  *               any case client may assume that URI is in the same "protection
   8314  *               space" if it starts with any of values specified here;
   8315  *               could be NULL (clients typically assume that the same
   8316  *               credentials could be used for any URI on the same host);
   8317  *               this list provides information for the client only and does
   8318  *               not actually restrict anything on the server side
   8319  * @param indicate_stale if set to #MHD_YES then indication of stale nonce used
   8320  *                       in the client's request is indicated by adding
   8321  *                       'stale=true' to the authentication header, this
   8322  *                       instructs the client to retry immediately with the new
   8323  *                       nonce and the same credentials, without asking user
   8324  *                       for the new password
   8325  * @param mqop the QOP to use
   8326  * @param malgo digest algorithm to use; if several algorithms are allowed
   8327  *              then one challenge for each allowed algorithm is added
   8328  * @param userhash_support if set to #MHD_YES then support of userhash is
   8329  *                         indicated, allowing client to provide
   8330  *                         hash("username:realm") instead of the username in
   8331  *                         clear text;
   8332  *                         note that clients are allowed to provide the username
   8333  *                         in cleartext even if this parameter set to non-zero;
   8334  *                         when userhash is used, application must be ready to
   8335  *                         identify users by provided userhash value instead of
   8336  *                         username; see #MHD_digest_auth_calc_userhash() and
   8337  *                         #MHD_digest_auth_calc_userhash_hex()
   8338  * @param prefer_utf8 if not set to #MHD_NO, parameter 'charset=UTF-8' is
   8339  *                    added, indicating for the client that UTF-8 encoding for
   8340  *                    the username is preferred
   8341  * @return #MHD_SC_OK if succeed,
   8342  *         #MHD_SC_TOO_LATE if the response has been already "frozen" (used to
   8343  *         create an action),
   8344  *         #MHD_SC_RESP_HEADERS_CONFLICT if Digest Authentication "challenge"
   8345  *         has been added already,
   8346  *         #MHD_SC_RESP_POINTER_NULL if @a response is NULL,
   8347  *         #MHD_SC_RESP_HTTP_CODE_NOT_SUITABLE is response status code is wrong,
   8348  *         #MHD_SC_RESP_HEADER_VALUE_INVALID if @a realm, @a opaque or @a domain
   8349  *         have wrong characters or zero length (for @a realm),
   8350  *         #MHD_SC_RESP_HEADER_MEM_ALLOC_FAILED if memory allocation failed,
   8351  *         or other error code if failed
   8352  * @ingroup authentication
   8353  */
   8354 MHD_EXTERN_ enum MHD_StatusCode
   8355 MHD_response_add_auth_digest_challenge (
   8356   struct MHD_Response *MHD_RESTRICT response,
   8357   const char *MHD_RESTRICT realm,
   8358   const char *MHD_RESTRICT opaque,
   8359   const char *MHD_RESTRICT domain,
   8360   enum MHD_Bool indicate_stale,
   8361   enum MHD_DigestAuthMultiQOP mqop,
   8362   enum MHD_DigestAuthMultiAlgo malgo,
   8363   enum MHD_Bool userhash_support,
   8364   enum MHD_Bool prefer_utf8)
   8365 MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2)
   8366 MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_CSTR_ (4);
   8367 
   8368 
   8369 /* Application may define MHD_NO_STATIC_INLINE macro before including
   8370    libmicrohttpd headers to disable static inline functions in the headers. */
   8371 #ifndef MHD_NO_STATIC_INLINE
   8372 
   8373 /**
   8374  * Create action to reply with Digest Authentication "challenge".
   8375  *
   8376  * The @a response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code.
   8377  *
   8378  * See RFC 7616, section 3.3 for details.
   8379  *
   8380  * @param request the request to create the action for
   8381  * @param realm the realm presented to the client
   8382  * @param opaque the string for opaque value, can be NULL, but NULL is
   8383  *               not recommended for better compatibility with clients;
   8384  *               the recommended format is hex or Base64 encoded string
   8385  * @param domain the optional space-separated list of URIs for which the
   8386  *               same authorisation could be used, URIs can be in form
   8387  *               "path-absolute" (the path for the same host with initial slash)
   8388  *               or in form "absolute-URI" (the full path with protocol), in
   8389  *               any case client may assume that URI is in the same "protection
   8390  *               space" if it starts with any of values specified here;
   8391  *               could be NULL (clients typically assume that the same
   8392  *               credentials could be used for any URI on the same host);
   8393  *               this list provides information for the client only and does
   8394  *               not actually restrict anything on the server side
   8395  * @param indicate_stale if set to #MHD_YES then indication of stale nonce used
   8396  *                       in the client's request is indicated by adding
   8397  *                       'stale=true' to the authentication header, this
   8398  *                       instructs the client to retry immediately with the new
   8399  *                       nonce and the same credentials, without asking user
   8400  *                       for the new password
   8401  * @param mqop the QOP to use
   8402  * @param malgo digest algorithm to use; if several algorithms are allowed
   8403  *              then one challenge for each allowed algorithm is added
   8404  * @param userhash_support if set to #MHD_YES then support of userhash is
   8405  *                         indicated, allowing client to provide
   8406  *                         hash("username:realm") instead of the username in
   8407  *                         clear text;
   8408  *                         note that clients are allowed to provide the username
   8409  *                         in cleartext even if this parameter set to non-zero;
   8410  *                         when userhash is used, application must be ready to
   8411  *                         identify users by provided userhash value instead of
   8412  *                         username; see #MHD_digest_auth_calc_userhash() and
   8413  *                         #MHD_digest_auth_calc_userhash_hex()
   8414  * @param prefer_utf8 if not set to #MHD_NO, parameter 'charset=UTF-8' is
   8415  *                    added, indicating for the client that UTF-8 encoding for
   8416  *                    the username is preferred
   8417  * @param response the response to update; should contain the "access denied"
   8418  *                 body;
   8419  *                 note: this function sets the "WWW Authenticate" header and
   8420  *                 the caller should not set this header;
   8421  *                 the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status
   8422  *                 code;
   8423  *                 the NULL is tolerated (the result is
   8424  *                 #MHD_SC_RESP_POINTER_NULL)
   8425  * @param abort_if_failed if set to #MHD_NO the response will be used even if
   8426  *                        failed to add Basic Authentication "challenge",
   8427  *                        if not set to #MHD_NO the request will be aborted
   8428  *                        if the "challenge" could not be added.
   8429  * @return pointer to the action, the action must be consumed
   8430  *         otherwise response object may leak;
   8431  *         NULL if failed or if any action has been already created for
   8432  *         the @a request;
   8433  *         when failed the response object is consumed and need not
   8434  *         to be "destroyed"
   8435  * @ingroup authentication
   8436  */
   8437 MHD_STATIC_INLINE_
   8438 MHD_FN_PAR_NONNULL_ (1)
   8439 MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2)
   8440 const struct MHD_Action *
   8441 MHD_action_digest_auth_challenge (struct MHD_Request *MHD_RESTRICT request,
   8442                                   const char *MHD_RESTRICT realm,
   8443                                   const char *MHD_RESTRICT opaque,
   8444                                   const char *MHD_RESTRICT domain,
   8445                                   enum MHD_Bool indicate_stale,
   8446                                   enum MHD_DigestAuthMultiQOP mqop,
   8447                                   enum MHD_DigestAuthMultiAlgo malgo,
   8448                                   enum MHD_Bool userhash_support,
   8449                                   enum MHD_Bool prefer_utf8,
   8450                                   struct MHD_Response *MHD_RESTRICT response,
   8451                                   enum MHD_Bool abort_if_failed)
   8452 {
   8453   if ((MHD_SC_OK !=
   8454        MHD_response_add_auth_digest_challenge (response, realm, opaque, domain,
   8455                                                indicate_stale, mqop, malgo,
   8456                                                userhash_support, prefer_utf8))
   8457       && (MHD_NO != abort_if_failed))
   8458   {
   8459     MHD_response_destroy (response);
   8460     return MHD_action_abort_request (request);
   8461   }
   8462   return MHD_action_from_response (request, response);
   8463 }
   8464 
   8465 
   8466 MHD_STATIC_INLINE_END_
   8467 
   8468 /**
   8469  * Create action to reply with Digest Authentication "challenge".
   8470  *
   8471  * The @a r response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code.
   8472  *
   8473  * If the @a r response object cannot be extended with the "challenge",
   8474  * the @a r response is used to reply without the "challenge".
   8475  *
   8476  * @param rq the request to create the action for
   8477  * @param l the realm presented to the client
   8478  * @param o the string for opaque value, can be NULL, but NULL is
   8479  *          not recommended for better compatibility with clients;
   8480  *          the recommended format is hex or Base64 encoded string
   8481  * @param d the optional space-separated list of URIs for which the
   8482  *          same authorisation could be used, URIs can be in form
   8483  *          "path-absolute" (the path for the same host with initial slash)
   8484  *          or in form "absolute-URI" (the full path with protocol), in
   8485  *          any case client may assume that URI is in the same "protection
   8486  *          space" if it starts with any of values specified here;
   8487  *          could be NULL (clients typically assume that the same
   8488  *          credentials could be used for any URI on the same host);
   8489  *          this list provides information for the client only and does
   8490  *          not actually restrict anything on the server side
   8491  * @param s if set to #MHD_YES then indication of stale nonce used
   8492  *          in the client's request is indicated by adding
   8493  *          'stale=true' to the authentication header, this
   8494  *          instructs the client to retry immediately with the new
   8495  *          nonce and the same credentials, without asking user
   8496  *          for the new password
   8497  * @param q the QOP to use
   8498  * @param a digest algorithm to use; if several algorithms are allowed
   8499  *          then one challenge for each allowed algorithm is added
   8500  * @param h if set to #MHD_YES then support of userhash is
   8501  *          indicated, allowing client to provide
   8502  *          hash("username:realm") instead of the username in
   8503  *          clear text;
   8504  *          note that clients are allowed to provide the username
   8505  *          in cleartext even if this parameter set to non-zero;
   8506  *          when userhash is used, application must be ready to
   8507  *          identify users by provided userhash value instead of
   8508  *          username; see #MHD_digest_auth_calc_userhash() and
   8509  *          #MHD_digest_auth_calc_userhash_hex()
   8510  * @param u if not set to #MHD_NO, parameter 'charset=UTF-8' is
   8511  *          added, indicating for the client that UTF-8 encoding for
   8512  *          the username is preferred
   8513  * @param r the response to update; should contain the "access denied"
   8514  *          body;
   8515  *          note: this function sets the "WWW Authenticate" header and
   8516  *          the caller should not set this header;
   8517  *          the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status
   8518  *          code;
   8519  *          the NULL is tolerated (the result is
   8520  *          #MHD_SC_RESP_POINTER_NULL)
   8521  * @return pointer to the action, the action must be consumed
   8522  *         otherwise response object may leak;
   8523  *         NULL if failed or if any action has been already created for
   8524  *         the @a rq request;
   8525  *         when failed the response object is consumed and need not
   8526  *         to be "destroyed"
   8527  * @ingroup authentication
   8528  */
   8529 #  define MHD_action_digest_auth_challenge_p(rq, l, o, d, s, q, a, h, u, r) \
   8530           MHD_action_digest_auth_challenge ((rq),(l),(o),(d),(s),(q), \
   8531                                             (a),(h),(u),(r),MHD_NO)
   8532 
   8533 
   8534 /**
   8535  * Create action to reply with Digest Authentication "challenge".
   8536  *
   8537  * The @a r response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code.
   8538  *
   8539  * If the @a r response object cannot be extended with the "challenge",
   8540  * the @a r response is aborted.
   8541  *
   8542  * @param rq the request to create the action for
   8543  * @param l the realm presented to the client
   8544  * @param o the string for opaque value, can be NULL, but NULL is
   8545  *          not recommended for better compatibility with clients;
   8546  *          the recommended format is hex or Base64 encoded string
   8547  * @param d the optional space-separated list of URIs for which the
   8548  *          same authorisation could be used, URIs can be in form
   8549  *          "path-absolute" (the path for the same host with initial slash)
   8550  *          or in form "absolute-URI" (the full path with protocol), in
   8551  *          any case client may assume that URI is in the same "protection
   8552  *          space" if it starts with any of values specified here;
   8553  *          could be NULL (clients typically assume that the same
   8554  *          credentials could be used for any URI on the same host);
   8555  *          this list provides information for the client only and does
   8556  *          not actually restrict anything on the server side
   8557  * @param s if set to #MHD_YES then indication of stale nonce used
   8558  *          in the client's request is indicated by adding
   8559  *          'stale=true' to the authentication header, this
   8560  *          instructs the client to retry immediately with the new
   8561  *          nonce and the same credentials, without asking user
   8562  *          for the new password
   8563  * @param q the QOP to use
   8564  * @param a digest algorithm to use; if several algorithms are allowed
   8565  *          then one challenge for each allowed algorithm is added
   8566  * @param h if set to #MHD_YES then support of userhash is
   8567  *          indicated, allowing client to provide
   8568  *          hash("username:realm") instead of the username in
   8569  *          clear text;
   8570  *          note that clients are allowed to provide the username
   8571  *          in cleartext even if this parameter set to non-zero;
   8572  *          when userhash is used, application must be ready to
   8573  *          identify users by provided userhash value instead of
   8574  *          username; see #MHD_digest_auth_calc_userhash() and
   8575  *          #MHD_digest_auth_calc_userhash_hex()
   8576  * @param u if not set to #MHD_NO, parameter 'charset=UTF-8' is
   8577  *          added, indicating for the client that UTF-8 encoding for
   8578  *          the username is preferred
   8579  * @param r the response to update; should contain the "access denied"
   8580  *          body;
   8581  *          note: this function sets the "WWW Authenticate" header and
   8582  *          the caller should not set this header;
   8583  *          the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status
   8584  *          code;
   8585  *          the NULL is tolerated (the result is
   8586  *          #MHD_SC_RESP_POINTER_NULL)
   8587  * @return pointer to the action, the action must be consumed
   8588  *         otherwise response object may leak;
   8589  *         NULL if failed or if any action has been already created for
   8590  *         the @a rq request;
   8591  *         when failed the response object is consumed and need not
   8592  *         to be "destroyed"
   8593  * @ingroup authentication
   8594  */
   8595 #  define MHD_action_digest_auth_challenge_a(rq, l, o, d, s, q, a, h, u, r) \
   8596           MHD_action_digest_auth_challenge ((rq),(l),(o),(d),(s),(q), \
   8597                                             (a),(h),(u),(r),MHD_YES)
   8598 
   8599 #endif /* ! MHD_NO_STATIC_INLINE */
   8600 
   8601 
   8602 /**
   8603  * Add Basic Authentication "challenge" to the response.
   8604  *
   8605  * The response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code.
   8606  *
   8607  * If access to any resource should be limited to specific users, authenticated
   8608  * by Basic Authentication mechanism, and the request for this resource does not
   8609  * have Basic Authentication information (see #MHD_AuthBasicCreds), then response
   8610  * with Basic Authentication "challenge" should be sent. This works as
   8611  * an indication that Basic Authentication should be used for the access.
   8612  *
   8613  * See RFC 7617, section-2 for details.
   8614  *
   8615  * @param response the reply to send; should contain the "access denied"
   8616  *                 body;
   8617  *                 note: this function sets the "WWW Authenticate" header and
   8618  *                 the caller should not set this header;
   8619  *                 the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status
   8620  *                 code;
   8621  *                 the NULL is tolerated (the result is
   8622  *                 #MHD_SC_RESP_POINTER_NULL)
   8623  * @param realm the realm presented to the client
   8624  * @param prefer_utf8 if not set to #MHD_NO, parameter'charset="UTF-8"' will
   8625  *                    be added, indicating for client that UTF-8 encoding
   8626  *                    is preferred
   8627  * @return #MHD_SC_OK if succeed,
   8628  *         #MHD_SC_TOO_LATE if the response has been already "frozen" (used to
   8629  *         create an action),
   8630  *         #MHD_SC_RESP_HEADERS_CONFLICT if Basic Authentication "challenge"
   8631  *         has been added already,
   8632  *         #MHD_SC_RESP_POINTER_NULL if @a response is NULL,
   8633  *         #MHD_SC_RESP_HTTP_CODE_NOT_SUITABLE is response status code is wrong,
   8634  *         #MHD_SC_RESP_HEADER_VALUE_INVALID if realm is zero-length or has CR
   8635  *         or LF characters,
   8636  *         #MHD_SC_RESP_HEADER_MEM_ALLOC_FAILED if memory allocation failed,
   8637  *         or other error code if failed
   8638  * @ingroup authentication
   8639  */
   8640 MHD_EXTERN_ enum MHD_StatusCode
   8641 MHD_response_add_auth_basic_challenge (
   8642   struct MHD_Response *MHD_RESTRICT response,
   8643   const char *MHD_RESTRICT realm,
   8644   enum MHD_Bool prefer_utf8)
   8645 MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2);
   8646 
   8647 /* Application may define MHD_NO_STATIC_INLINE macro before including
   8648    libmicrohttpd headers to disable static inline functions in the headers. */
   8649 #ifndef MHD_NO_STATIC_INLINE
   8650 
   8651 /**
   8652  * Create action to reply with Basic Authentication "challenge".
   8653  *
   8654  * The @a response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code.
   8655  *
   8656  * If access to any resource should be limited to specific users, authenticated
   8657  * by Basic Authentication mechanism, and the request for this resource does not
   8658  * have Basic Authentication information (see #MHD_AuthBasicCreds), then response
   8659  * with Basic Authentication "challenge" should be sent. This works as
   8660  * an indication that Basic Authentication should be used for the access.
   8661  *
   8662  * See RFC 7617, section-2 for details.
   8663  *
   8664  * @param request the request to create the action for
   8665  * @param realm the realm presented to the client
   8666  * @param prefer_utf8 if not set to #MHD_NO, parameter'charset="UTF-8"' will
   8667  *                    be added, indicating for client that UTF-8 encoding
   8668  *                    is preferred
   8669  * @param response the reply to send; should contain the "access denied"
   8670  *                 body;
   8671  *                 note: this function adds the "WWW Authenticate" header in
   8672  *                 the response and the caller should not set this header;
   8673  *                 the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status
   8674  *                 code;
   8675  *                 the NULL is tolerated (the result is
   8676  *                 #MHD_action_abort_request())
   8677  * @param abort_if_failed if set to #MHD_NO the response will be used even if
   8678  *                        failed to add Basic Authentication "challenge",
   8679  *                        if not set to #MHD_NO the request will be aborted
   8680  *                        if the "challenge" could not be added.
   8681  * @return pointer to the action, the action must be consumed
   8682  *         otherwise response object may leak;
   8683  *         NULL if failed or if any action has been already created for
   8684  *         the @a request;
   8685  *         when failed the response object is consumed and need not
   8686  *         to be "destroyed"
   8687  * @ingroup authentication
   8688  */
   8689 MHD_STATIC_INLINE_
   8690 MHD_FN_PAR_NONNULL_ (1)
   8691 MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2)
   8692 const struct MHD_Action *
   8693 MHD_action_basic_auth_challenge (struct MHD_Request *MHD_RESTRICT request,
   8694                                  const char *MHD_RESTRICT realm,
   8695                                  enum MHD_Bool prefer_utf8,
   8696                                  struct MHD_Response *MHD_RESTRICT response,
   8697                                  enum MHD_Bool abort_if_failed)
   8698 {
   8699   if ((MHD_SC_OK !=
   8700        MHD_response_add_auth_basic_challenge (response, realm, prefer_utf8))
   8701       && (MHD_NO != abort_if_failed))
   8702   {
   8703     MHD_response_destroy (response);
   8704     return MHD_action_abort_request (request);
   8705   }
   8706   return MHD_action_from_response (request, response);
   8707 }
   8708 
   8709 
   8710 MHD_STATIC_INLINE_END_
   8711 
   8712 
   8713 /**
   8714  * Create action to reply with Basic Authentication "challenge".
   8715  *
   8716  * The @a r response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code.
   8717  *
   8718  * If the @a r response object cannot be extended with the "challenge",
   8719  * the @a r response will be used to reply without the "challenge".
   8720  *
   8721  * @param rq the request to create the action for
   8722  * @param l the realm presented to the client
   8723  * @param u if not set to #MHD_NO, parameter'charset="UTF-8"' will
   8724  *          be added, indicating for client that UTF-8 encoding
   8725  *          is preferred
   8726  * @param r the reply to send; should contain the "access denied"
   8727  *          body;
   8728  *          note: this function adds the "WWW Authenticate" header in
   8729  *          the response and the caller should not set this header;
   8730  *          the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status
   8731  *          code;
   8732  *          the NULL is tolerated (the result is
   8733  *          #MHD_action_abort_request())
   8734  * @return pointer to the action, the action must be consumed
   8735  *         otherwise response object may leak;
   8736  *         NULL if failed or if any action has been already created for
   8737  *         the @a rq request;
   8738  *         when failed the response object is consumed and need not
   8739  *         to be "destroyed"
   8740  * @ingroup authentication
   8741  */
   8742 #  define MHD_action_basic_auth_challenge_p(rq, l, u, r) \
   8743           MHD_action_basic_auth_challenge ((rq), (l), (u), (r), MHD_NO)
   8744 
   8745 /**
   8746  * Create action to reply with Basic Authentication "challenge".
   8747  *
   8748  * The @a r response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code.
   8749  *
   8750  * If the @a r response object cannot be extended with the "challenge",
   8751  * the request will be aborted.
   8752  *
   8753  * @param rq the request to create the action for
   8754  * @param l the realm presented to the client
   8755  * @param u if not set to #MHD_NO, parameter'charset="UTF-8"' will
   8756  *          be added, indicating for client that UTF-8 encoding
   8757  *          is preferred
   8758  * @param r the reply to send; should contain the "access denied"
   8759  *          body;
   8760  *          note: this function adds the "WWW Authenticate" header in
   8761  *          the response and the caller should not set this header;
   8762  *          the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status
   8763  *          code;
   8764  *          the NULL is tolerated (the result is
   8765  *          #MHD_action_abort_request())
   8766  * @return pointer to the action, the action must be consumed
   8767  *         otherwise response object may leak;
   8768  *         NULL if failed or if any action has been already created for
   8769  *         the @a rq request;
   8770  *         when failed the response object is consumed and need not
   8771  *         to be "destroyed"
   8772  * @ingroup authentication
   8773  */
   8774 #  define MHD_action_basic_auth_challenge_a(rq, l, u, r) \
   8775           MHD_action_basic_auth_challenge ((rq), (l), (u), (r), MHD_YES)
   8776 
   8777 #endif /* ! MHD_NO_STATIC_INLINE */
   8778 
   8779 
   8780 /**
   8781  * Information decoded from Basic Authentication client's header.
   8782  *
   8783  * @see #MHD_REQUEST_INFO_DYNAMIC_AUTH_BASIC_CREDS
   8784  */
   8785 struct MHD_AuthBasicCreds
   8786 {
   8787   /**
   8788    * The username
   8789    */
   8790   struct MHD_String username;
   8791 
   8792   /**
   8793    * The password, string pointer may be NULL if password is not encoded
   8794    * by the client.
   8795    */
   8796   struct MHD_StringNullable password;
   8797 };
   8798 
   8799 /* ********************** (f) Introspection ********************** */
   8800 
   8801 
   8802 /**
   8803  * Types of information about MHD, used by #MHD_lib_get_info_fixed_sz().
   8804  * This information is not changed at run-time.
   8805  */
   8806 enum MHD_FIXED_ENUM_APP_SET_ MHD_LibInfoFixed
   8807 {
   8808   /* * Basic MHD information * */
   8809 
   8810   /**
   8811    * Get the MHD version as a number.
   8812    * The result is placed in @a v_version_num_uint32 member.
   8813    */
   8814   MHD_LIB_INFO_FIXED_VERSION_NUM = 0
   8815   ,
   8816   /**
   8817    * Get the MHD version as a string.
   8818    * The result is placed in @a v_version_string member.
   8819    */
   8820   MHD_LIB_INFO_FIXED_VERSION_STRING = 1
   8821   ,
   8822 
   8823   /* * Basic MHD features, buid-time configurable * */
   8824   /* These features should be always available unless the library was
   8825    * not compiled specifically for some embedded project.
   8826    * Exceptions are marked explicitly in the description. */
   8827 
   8828   /**
   8829    * Get whether messages are supported. If supported then messages can be
   8830    * printed to stderr or to an external logger.
   8831    * The result is placed in @a v_support_log_messages_bool member.
   8832    */
   8833   MHD_LIB_INFO_FIXED_SUPPORT_LOG_MESSAGES = 11
   8834   ,
   8835   /**
   8836    * Get whether detailed automatic HTTP reply messages are supported.
   8837    * If supported then automatic responses have bodies with text explaining
   8838    * the error details.
   8839    * Automatic responses are sent by MHD automatically when client is violating
   8840    * HTTP specification, for example, the request header has whitespace in
   8841    * header name or request's "Content-Length" header has non-number value.
   8842    * The result is placed in @a v_support_auto_replies_bodies_bool member.
   8843    */
   8844   MHD_LIB_INFO_FIXED_SUPPORT_AUTO_REPLIES_BODIES = 12
   8845   ,
   8846   /**
   8847    * Get whether MHD was built with debug asserts disabled.
   8848    * These asserts enabled only on special debug builds.
   8849    * For debug builds the error log is always enabled.
   8850    * The result is placed in @a v_is_non_debug_bool member.
   8851    */
   8852   MHD_LIB_INFO_FIXED_IS_NON_DEBUG = 13
   8853   ,
   8854   /**
   8855    * Get whether MHD supports threads.
   8856    * The result is placed in @a v_support_threads_bool member.
   8857    */
   8858   MHD_LIB_INFO_FIXED_SUPPORT_THREADS = 14
   8859   ,
   8860   /**
   8861    * Get whether automatic parsing of HTTP Cookie header is supported.
   8862    * If disabled, no #MHD_VK_COOKIE will be generated by MHD.
   8863    * The result is placed in @a v_support_cookie_parser_bool member.
   8864    */
   8865   MHD_LIB_INFO_FIXED_SUPPORT_COOKIE_PARSER = 15
   8866   ,
   8867   /**
   8868    * Get whether postprocessor is supported. If supported then
   8869    * #MHD_action_post_processor() can be used.
   8870    * The result is placed in @a v_support_post_parser_bool member.
   8871    */
   8872   MHD_LIB_INFO_FIXED_SUPPORT_POST_PARSER = 16
   8873   ,
   8874   /**
   8875    * Get whether HTTP "Upgrade" is supported.
   8876    * If supported then #MHD_action_upgrade() can be used.
   8877    * The result is placed in @a v_support_upgrade_bool member.
   8878    */
   8879   MHD_LIB_INFO_FIXED_SUPPORT_UPGRADE = 17
   8880   ,
   8881   /**
   8882    * Get whether HTTP Basic authorization is supported. If supported
   8883    * then functions #MHD_action_basic_auth_required_response ()
   8884    * and #MHD_REQUEST_INFO_DYNAMIC_AUTH_BASIC_CREDS can be used.
   8885    * The result is placed in @a v_support_auth_basic_bool member.
   8886    */
   8887   MHD_LIB_INFO_FIXED_SUPPORT_AUTH_BASIC = 20
   8888   ,
   8889   /**
   8890    * Get whether HTTP Digest authorization is supported. If
   8891    * supported then options #MHD_D_O_RANDOM_ENTROPY,
   8892    * #MHD_D_O_DAUTH_MAP_SIZE and functions
   8893    * #MHD_action_digest_auth_required_response () and
   8894    * #MHD_digest_auth_check() can be used.
   8895    * The result is placed in @a v_support_auth_digest_bool member.
   8896    */
   8897   MHD_LIB_INFO_FIXED_SUPPORT_AUTH_DIGEST = 21
   8898   ,
   8899   /**
   8900    * Get whether the early version the Digest Authorization (RFC 2069) is
   8901    * supported (digest authorisation without QOP parameter).
   8902    * Currently it is always supported if Digest Auth module is built.
   8903    * The result is placed in @a v_support_digest_auth_rfc2069_bool member.
   8904    */
   8905   MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_RFC2069 = 22
   8906   ,
   8907   /**
   8908    * Get whether the MD5-based hashing algorithms are supported for Digest
   8909    * Authorization and the type of the implementation if supported.
   8910    * Currently it is always supported if Digest Auth module is built
   8911    * unless manually disabled in a custom build.
   8912    * The result is placed in @a v_type_digest_auth_md5_algo_type member.
   8913    */
   8914   MHD_LIB_INFO_FIXED_TYPE_DIGEST_AUTH_MD5 = 23
   8915   ,
   8916   /**
   8917    * Get whether the SHA-256-based hashing algorithms are supported for Digest
   8918    * Authorization and the type of the implementation if supported.
   8919    * Currently it is always supported if Digest Auth module is built
   8920    * unless manually disabled in a custom build.
   8921    * The result is placed in @a v_type_digest_auth_sha256_algo_type member.
   8922    */
   8923   MHD_LIB_INFO_FIXED_TYPE_DIGEST_AUTH_SHA256 = 24
   8924   ,
   8925   /**
   8926    * Get whether the SHA-512/256-based hashing algorithms are supported
   8927    * Authorization and the type of the implementation if supported.
   8928    * Currently it is always supported if Digest Auth module is built
   8929    * unless manually disabled in a custom build.
   8930    * The result is placed in @a v_type_digest_auth_sha512_256_algo_type member.
   8931    */
   8932   MHD_LIB_INFO_FIXED_TYPE_DIGEST_AUTH_SHA512_256 = 25
   8933   ,
   8934   /**
   8935    * Get whether QOP with value 'auth-int' (authentication with integrity
   8936    * protection) is supported for Digest Authorization.
   8937    * Currently it is always not supported.
   8938    * The result is placed in @a v_support_digest_auth_auth_int_bool member.
   8939    */
   8940   MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_AUTH_INT = 28
   8941   ,
   8942   /**
   8943    * Get whether 'session' algorithms (like 'MD5-sess') are supported for Digest
   8944    * Authorization.
   8945    * Currently it is always not supported.
   8946    * The result is placed in @a v_support_digest_auth_algo_session_bool member.
   8947    */
   8948   MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_ALGO_SESSION = 29
   8949   ,
   8950   /**
   8951    * Get whether 'userhash' is supported for Digest Authorization.
   8952    * Currently it is always supported if Digest Auth module is built.
   8953    * The result is placed in @a v_support_digest_auth_userhash_bool member.
   8954    */
   8955   MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_USERHASH = 30
   8956   ,
   8957 
   8958   /* * Platform-dependent features, some are configurable at build-time * */
   8959   /* These features depends on the platform, third-party libraries and
   8960    * the toolchain.
   8961    * Some of the features can be disabled or selected at build-time. */
   8962   /**
   8963    * Get sockets polling functions/techniques supported by this MHD build.
   8964    * Some functions can be disabled (like epoll) in kernel, this is not
   8965    * checked.
   8966    * The result is placed in @a v_types_sockets_polling member.
   8967    */
   8968   MHD_LIB_INFO_FIXED_TYPES_SOCKETS_POLLING = 60
   8969   ,
   8970   /**
   8971    * Get whether aggregate FD external polling is supported.
   8972    * The result is placed in @a v_support_aggregate_fd_bool member.
   8973    */
   8974   MHD_LIB_INFO_FIXED_SUPPORT_AGGREGATE_FD = 61
   8975   ,
   8976   /**
   8977    * Get whether IPv6 is supported on the platform and IPv6-only listen socket
   8978    * can be used.
   8979    * The result is placed in @a v_ipv6 member.
   8980    * @note The platform may have disabled IPv6 at run-time, it is not checked
   8981    *       by this information type.
   8982    */
   8983   MHD_LIB_INFO_FIXED_TYPE_IPV6 = 62
   8984   ,
   8985   /**
   8986    * Get whether TCP Fast Open is supported by MHD build.
   8987    * If supported then option #MHD_D_O_TCP_FASTOPEN can be used.
   8988    * The result is placed in @a v_support_tcp_fastopen_bool member.
   8989    */
   8990   MHD_LIB_INFO_FIXED_SUPPORT_TCP_FASTOPEN = 64
   8991   ,
   8992   /**
   8993    * Get whether MHD support automatic detection of bind port number.
   8994    * @sa #MHD_D_O_BIND_PORT
   8995    * The result is placed in @a v_has_autodetect_bind_port_bool member.
   8996    */
   8997   MHD_LIB_INFO_FIXED_HAS_AUTODETECT_BIND_PORT = 65
   8998   ,
   8999   /**
   9000    * Get whether MHD use system's sendfile() function to send
   9001    * file-FD based responses over non-TLS connections.
   9002    * The result is placed in @a v_has_sendfile_bool member.
   9003    */
   9004   MHD_LIB_INFO_FIXED_HAS_SENDFILE = 66
   9005   ,
   9006   /**
   9007    * Get whether MHD supports automatic SIGPIPE suppression within internal
   9008    * events loop (MHD's managed threads).
   9009    * If SIGPIPE suppression is not supported, application must handle
   9010    * SIGPIPE signal by itself whem using MHD with internal events loop.
   9011    * If the platform does not have SIGPIPE the result is #MHD_YES.
   9012    * The result is placed in @a v_has_autosuppress_sigpipe_int_bool member.
   9013    */
   9014   MHD_LIB_INFO_FIXED_HAS_AUTOSUPPRESS_SIGPIPE_INT = 80
   9015   ,
   9016   /**
   9017    * Get whether MHD supports automatic SIGPIPE suppression when used with
   9018    * extenal events loop (in application thread).
   9019    * If SIGPIPE suppression is not supported, application must handle
   9020    * SIGPIPE signal by itself whem using MHD with external events loop.
   9021    * If the platform does not have SIGPIPE the result is #MHD_YES.
   9022    * The result is placed in @a v_has_autosuppress_sigpipe_ext_bool member.
   9023    */
   9024   MHD_LIB_INFO_FIXED_HAS_AUTOSUPPRESS_SIGPIPE_EXT = 81
   9025   ,
   9026   /**
   9027    * Get whether MHD sets names on generated threads.
   9028    * The result is placed in @a v_has_thread_names_bool member.
   9029    */
   9030   MHD_LIB_INFO_FIXED_HAS_THREAD_NAMES = 82
   9031   ,
   9032   /**
   9033    * Get the type of supported inter-thread communication.
   9034    * The result is placed in @a v_type_itc member.
   9035    */
   9036   MHD_LIB_INFO_FIXED_TYPE_ITC = 83
   9037   ,
   9038   /**
   9039    * Get whether reading files beyond 2 GiB boundary is supported.
   9040    * If supported then #MHD_response_from_fd() can be used with sizes and
   9041    * offsets larger than 2 GiB. If not supported value of size+offset could be
   9042    * limited to 2 GiB.
   9043    * The result is placed in @a v_support_large_file_bool member.
   9044    */
   9045   MHD_LIB_INFO_FIXED_SUPPORT_LARGE_FILE = 84
   9046   ,
   9047 
   9048   /* * Platform-dependent features, some set on startup and some are
   9049    *   configurable at build-time * */
   9050   /* These features depends on the platform, third-party libraries availability
   9051    * and configuration. The features can be enabled/disabled during startup
   9052    * of the library depending on conditions.
   9053    * Some of the features can be disabled or selected at build-time. */
   9054   /**
   9055    * Get whether HTTPS and which types of TLS backend(s) supported by
   9056    * this build.
   9057    * The result is placed in @a v_tls_backends member.
   9058    */
   9059   MHD_LIB_INFO_FIXED_TLS_BACKENDS = 100
   9060   ,
   9061   /**
   9062   * Get whether password encrypted private key for HTTPS daemon is
   9063   * supported by TLS backends.
   9064   * If supported then option #MHD_D_OPTION_TLS_KEY_CERT can be used with
   9065   * non-NULL @a mem_pass.
   9066   * The result is placed in @a v_tls_key_password_backends member.
   9067   */
   9068   MHD_LIB_INFO_FIXED_TLS_KEY_PASSWORD_BACKENDS = 102
   9069   ,
   9070 
   9071   /* * Sentinel * */
   9072   /**
   9073    * The sentinel value.
   9074    * This value enforces specific underlying integer type for the enum.
   9075    * Do not use.
   9076    */
   9077   MHD_LIB_INFO_FIXED_SENTINEL = 65535
   9078 };
   9079 
   9080 /**
   9081  * The type of the data for digest algorithm implementations.
   9082  */
   9083 enum MHD_FIXED_ENUM_MHD_SET_ MHD_LibInfoFixedDigestAlgoType
   9084 {
   9085   /**
   9086    * The algorithm is not implemented or disabled at the build time.
   9087    */
   9088   MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_NOT_AVAILABLE = 0
   9089   ,
   9090   /**
   9091    * The algorithm is implemented by MHD internal code.
   9092    * MHD implementation of hashing can never fail.
   9093    */
   9094   MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_BUILT_IN = 1
   9095   ,
   9096   /**
   9097    * The algorithm is implemented by external code that never fails.
   9098    */
   9099   MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_EXTERNAL_NEVER_FAIL = 2
   9100   ,
   9101   /**
   9102    * The algorithm is implemented by external code that may hypothetically fail.
   9103    */
   9104   MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_EXTERNAL_MAY_FAIL = 3
   9105 };
   9106 
   9107 /**
   9108  * The types of the sockets polling functions/techniques supported
   9109  */
   9110 struct MHD_LibInfoFixedPollingFunc
   9111 {
   9112   /**
   9113    * select() function for sockets polling
   9114    */
   9115   enum MHD_Bool func_select;
   9116   /**
   9117    * poll() function for sockets polling
   9118    */
   9119   enum MHD_Bool func_poll;
   9120   /**
   9121    * epoll technique for sockets polling
   9122    */
   9123   enum MHD_Bool tech_epoll;
   9124   /**
   9125    * kqueue technique for sockets polling
   9126    */
   9127   enum MHD_Bool tech_kqueue;
   9128 };
   9129 
   9130 /**
   9131  * The types of IPv6 supported
   9132  */
   9133 enum MHD_FIXED_ENUM_MHD_SET_ MHD_LibInfoFixedIPv6Type
   9134 {
   9135   /**
   9136    * IPv6 is not supported by this MHD build
   9137    */
   9138   MHD_LIB_INFO_FIXED_IPV6_TYPE_NONE = 0
   9139   ,
   9140   /**
   9141    * IPv6 is supported only as "dual stack".
   9142    * IPv4 connections can be received by IPv6 listen socket.
   9143    */
   9144   MHD_LIB_INFO_FIXED_IPV6_TYPE_DUAL_ONLY = 1
   9145   ,
   9146   /**
   9147    * IPv6 can be used as IPv6-only (without getting IPv4 incoming connections).
   9148    * The platform may support "dual stack" too.
   9149    */
   9150   MHD_LIB_INFO_FIXED_IPV6_TYPE_IPV6_PURE = 2
   9151 };
   9152 
   9153 /**
   9154  * The types of inter-thread communication
   9155  * @note the enum can be extended in future versions with new values
   9156  */
   9157 enum MHD_FIXED_ENUM_MHD_SET_ MHD_LibInfoFixedITCType
   9158 {
   9159   /**
   9160    * No ITC used.
   9161    * This value is returned if MHD is built without threads support
   9162    */
   9163   MHD_LIB_INFO_FIXED_ITC_TYPE_NONE = 0
   9164   ,
   9165   /**
   9166    * The pair of sockets are used as inter-thread communication.
   9167    * The is the least efficient method of communication.
   9168    */
   9169   MHD_LIB_INFO_FIXED_ITC_TYPE_SOCKETPAIR = 1
   9170   ,
   9171   /**
   9172    * The pipe is used as inter-thread communication.
   9173    */
   9174   MHD_LIB_INFO_FIXED_ITC_TYPE_PIPE = 2
   9175   ,
   9176   /**
   9177    * The EventFD is used as inter-thread communication.
   9178    * This is the most efficient method of communication.
   9179    */
   9180   MHD_LIB_INFO_FIXED_ITC_TYPE_EVENTFD = 3
   9181 };
   9182 
   9183 
   9184 /**
   9185  * The types of the TLS (or TLS feature) backend supported/available/enabled
   9186  * @note the enum can be extended in future versions with new members
   9187  */
   9188 struct MHD_LibInfoTLSType
   9189 {
   9190   /**
   9191    * The TLS (or TLS feature) is supported/enabled.
   9192    * Set to #MHD_YES if any other member is #MHD_YES.
   9193    */
   9194   enum MHD_Bool tls_supported;
   9195   /**
   9196    * The GnuTLS backend is supported/available/enabled.
   9197    */
   9198   enum MHD_Bool backend_gnutls;
   9199   /**
   9200    * The OpenSSL backend is supported/available/enabled.
   9201    */
   9202   enum MHD_Bool backend_openssl;
   9203   /**
   9204    * The MbedTLS backend is supported/available/enabled.
   9205    */
   9206   enum MHD_Bool backend_mbedtls;
   9207 };
   9208 
   9209 /**
   9210  * The data provided by #MHD_lib_get_info_fixed_sz()
   9211  */
   9212 union MHD_LibInfoFixedData
   9213 {
   9214   /**
   9215    * The data for the #MHD_LIB_INFO_FIXED_VERSION_NUM query
   9216    */
   9217   uint_fast32_t v_version_num_uint32;
   9218   /**
   9219    * The data for the #MHD_LIB_INFO_FIXED_VERSION_STR query
   9220    */
   9221   struct MHD_String v_version_string;
   9222   /**
   9223    * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_LOG_MESSAGES query
   9224    */
   9225   enum MHD_Bool v_support_log_messages_bool;
   9226   /**
   9227    * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_AUTO_REPLIES_BODIES query
   9228    */
   9229   enum MHD_Bool v_support_auto_replies_bodies_bool;
   9230   /**
   9231    * The data for the #MHD_LIB_INFO_FIXED_IS_NON_DEBUG query
   9232    */
   9233   enum MHD_Bool v_is_non_debug_bool;
   9234   /**
   9235    * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_THREADS query
   9236    */
   9237   enum MHD_Bool v_support_threads_bool;
   9238   /**
   9239    * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_COOKIE_PARSER query
   9240    */
   9241   enum MHD_Bool v_support_cookie_parser_bool;
   9242   /**
   9243    * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_POST_PARSER query
   9244    */
   9245   enum MHD_Bool v_support_post_parser_bool;
   9246   /**
   9247    * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_UPGRADE query
   9248    */
   9249   enum MHD_Bool v_support_upgrade_bool;
   9250   /**
   9251    * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_AUTH_BASIC query
   9252    */
   9253   enum MHD_Bool v_support_auth_basic_bool;
   9254   /**
   9255    * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_AUTH_DIGEST query
   9256    */
   9257   enum MHD_Bool v_support_auth_digest_bool;
   9258   /**
   9259    * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_RFC2069 query
   9260    */
   9261   enum MHD_Bool v_support_digest_auth_rfc2069_bool;
   9262   /**
   9263    * The data for the #MHD_LIB_INFO_FIXED_TYPE_DIGEST_AUTH_MD5 query
   9264    */
   9265   enum MHD_LibInfoFixedDigestAlgoType v_type_digest_auth_md5_algo_type;
   9266   /**
   9267    * The data for the #MHD_LIB_INFO_FIXED_TYPE_DIGEST_AUTH_SHA256 query
   9268    */
   9269   enum MHD_LibInfoFixedDigestAlgoType v_type_digest_auth_sha256_algo_type;
   9270   /**
   9271    * The data for the #MHD_LIB_INFO_FIXED_TYPE_DIGEST_AUTH_SHA512_256 query
   9272    */
   9273   enum MHD_LibInfoFixedDigestAlgoType v_type_digest_auth_sha512_256_algo_type;
   9274   /**
   9275    * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_AUTH_INT query
   9276    */
   9277   enum MHD_Bool v_support_digest_auth_auth_int_bool;
   9278   /**
   9279    * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_ALGO_SESSION query
   9280    */
   9281   enum MHD_Bool v_support_digest_auth_algo_session_bool;
   9282   /**
   9283    * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_USERHASH query
   9284    */
   9285   enum MHD_Bool v_support_digest_auth_userhash_bool;
   9286   /**
   9287    * The data for the #MHD_LIB_INFO_FIXED_TYPES_SOCKETS_POLLING query
   9288    */
   9289   struct MHD_LibInfoFixedPollingFunc v_types_sockets_polling;
   9290   /**
   9291    * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_AGGREGATE_FD query
   9292    */
   9293   enum MHD_Bool v_support_aggregate_fd_bool;
   9294   /**
   9295    * The data for the #MHD_LIB_INFO_FIXED_TYPE_IPV6 query
   9296    */
   9297   enum MHD_LibInfoFixedIPv6Type v_ipv6;
   9298   /**
   9299    * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_TCP_FASTOPEN query
   9300    */
   9301   enum MHD_Bool v_support_tcp_fastopen_bool;
   9302   /**
   9303    * The data for the #MHD_LIB_INFO_FIXED_HAS_AUTODETECT_BIND_PORT query
   9304    */
   9305   enum MHD_Bool v_has_autodetect_bind_port_bool;
   9306   /**
   9307    * The data for the #MHD_LIB_INFO_FIXED_HAS_SENDFILE query
   9308    */
   9309   enum MHD_Bool v_has_sendfile_bool;
   9310   /**
   9311    * The data for the #MHD_LIB_INFO_FIXED_HAS_AUTOSUPPRESS_SIGPIPE_INT query
   9312    */
   9313   enum MHD_Bool v_has_autosuppress_sigpipe_int_bool;
   9314   /**
   9315    * The data for the #MHD_LIB_INFO_FIXED_HAS_AUTOSUPPRESS_SIGPIPE_EXT query
   9316    */
   9317   enum MHD_Bool v_has_autosuppress_sigpipe_ext_bool;
   9318   /**
   9319    * The data for the #MHD_LIB_INFO_FIXED_HAS_THREAD_NAMES query
   9320    */
   9321   enum MHD_Bool v_has_thread_names_bool;
   9322   /**
   9323    * The data for the #MHD_LIB_INFO_FIXED_TYPE_ITC query
   9324    */
   9325   enum MHD_LibInfoFixedITCType v_type_itc;
   9326   /**
   9327    * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_LARGE_FILE query
   9328    */
   9329   enum MHD_Bool v_support_large_file_bool;
   9330   /**
   9331    * The data for the #MHD_LIB_INFO_FIXED_TLS_BACKENDS query
   9332    */
   9333   struct MHD_LibInfoTLSType v_tls_backends;
   9334   /**
   9335    * The data for the #MHD_LIB_INFO_FIXED_TLS_KEY_PASSWORD_BACKENDS query
   9336    */
   9337   struct MHD_LibInfoTLSType v_tls_key_password_backends;
   9338 };
   9339 
   9340 /**
   9341  * Get fixed information about MHD that is not changed at run-time.
   9342  * The returned information can be cached by application as it will be not
   9343  * changed at run-time.
   9344  *
   9345  * For any valid @a info_type the only possible returned error value is
   9346  * #MHD_SC_INFO_GET_BUFF_TOO_SMALL. If the buffer is large enough and
   9347  * the requested type of information is valid, the function always succeeds
   9348  * and returns #MHD_SC_OK.
   9349  *
   9350  * The wrapper macro #MHD_lib_get_info_fixed() may be more convenient.
   9351  *
   9352  * @param info_type the type of requested information
   9353  * @param[out] output_buf the pointer to union to be set to the requested
   9354  *                        information
   9355  * @param output_buf_size the size of the memory area pointed by @a output_buf
   9356  *                        (provided by the caller for storing the requested
   9357  *                        information), in bytes
   9358  * @return #MHD_SC_OK if succeed,
   9359  *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
   9360  *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small
   9361  * @ingroup specialized
   9362  */
   9363 MHD_EXTERN_ enum MHD_StatusCode
   9364 MHD_lib_get_info_fixed_sz (enum MHD_LibInfoFixed info_type,
   9365                            union MHD_LibInfoFixedData *MHD_RESTRICT output_buf,
   9366                            size_t output_buf_size)
   9367 MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_OUT_ (2);
   9368 
   9369 /**
   9370  * Get fixed information about MHD that is not changed at run-time.
   9371  * The returned information can be cached by application as it will be not
   9372  * changed at run-time.
   9373  *
   9374  * @param info the type of requested information
   9375  * @param[out] output_buf the pointer to union to be set to the requested
   9376  *                        information
   9377  * @return #MHD_SC_OK if succeed,
   9378  *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
   9379  *         or other error code
   9380  * @ingroup specialized
   9381  */
   9382 #define MHD_lib_get_info_fixed(info, output_buf) \
   9383         MHD_lib_get_info_fixed_sz ((info),(output_buf),sizeof(*(output_buf)))
   9384 
   9385 /* Application may define MHD_NO_STATIC_INLINE macro before including
   9386    libmicrohttpd headers to disable static inline functions in the headers. */
   9387 #ifndef MHD_NO_STATIC_INLINE
   9388 
   9389 /*
   9390  * A helper below can be used in a simple check preventing use of downgraded
   9391  * library version.
   9392  * As new library version may introduce new functionality, and the application
   9393  * may detect some functionality available at application build-time, use of
   9394  * previous versions may lead to run-time failures.
   9395  * To prevent run-time failures, application may use a check like:
   9396 
   9397  if (MHD_lib_get_info_ver_num() < ((uint_fast32_t) MHD_VERSION))
   9398    handle_init_failure();
   9399 
   9400  */
   9401 /**
   9402  * Get the library version number.
   9403  * @return the library version number.
   9404  */
   9405 MHD_STATIC_INLINE_ MHD_FN_PURE_ uint_fast32_t
   9406 MHD_lib_get_info_ver_num (void)
   9407 {
   9408   union MHD_LibInfoFixedData data;
   9409   data.v_version_num_uint32 = 0; /* Not really necessary */
   9410   (void)MHD_lib_get_info_fixed (MHD_LIB_INFO_FIXED_VERSION_NUM, \
   9411                                 &data);  /* Never fail */
   9412   return data.v_version_num_uint32;
   9413 }
   9414 
   9415 
   9416 MHD_STATIC_INLINE_END_
   9417 
   9418 #endif /* ! MHD_NO_STATIC_INLINE */
   9419 
   9420 /**
   9421  * Types of information about MHD, used by #MHD_lib_get_info_dynamic_sz().
   9422  * This information may vary over time.
   9423  */
   9424 enum MHD_FIXED_ENUM_APP_SET_ MHD_LibInfoDynamic
   9425 {
   9426   /* * Basic MHD information * */
   9427 
   9428   /**
   9429    * Get whether MHD has been successfully fully initialised.
   9430    * MHD uses lazy initialisation: a minimal initialisation is performed at
   9431    * startup, complete initialisation is performed when any daemon is created
   9432    * (or when called some function which requires full initialisation).
   9433    * The result is #MHD_NO when the library has been not yet initialised
   9434    * completely since startup.
   9435    * The result is placed in @a v_inited_fully_once_bool member.
   9436    */
   9437   MHD_LIB_INFO_DYNAMIC_INITED_FULLY_ONCE = 0
   9438   ,
   9439   /**
   9440    * Get whether MHD is fully initialised.
   9441    * MHD uses lazy initialisation: a minimal initialisation is performed at
   9442    * startup, complete initialisation is perfromed when any daemon is created
   9443    * (or when called some function which requires full initialisation).
   9444    * The result is #MHD_YES if library is initialised state now (meaning
   9445    * that at least one daemon is created and not destroyed or some function
   9446    * required full initialisation is running).
   9447    * The result is placed in @a v_inited_fully_now_bool member.
   9448    */
   9449   MHD_LIB_INFO_DYNAMIC_INITED_FULLY_NOW = 1
   9450   ,
   9451 
   9452   /**
   9453    * Get whether HTTPS and which types of TLS backend(s) currently available.
   9454    * If any MHD daemons active (created and not destroyed, not necessary
   9455    * running) the result reflects the current backends availability.
   9456    * If no MHD daemon is active, then this function would try to temporarily
   9457    * enable backends to check for their availability.
   9458    * If global library initialisation failed, the function returns
   9459    * #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE error code.
   9460    * The result is placed in @a v_tls_backends member.
   9461    */
   9462   MHD_LIB_INFO_DYNAMIC_TYPE_TLS = 100
   9463   ,
   9464 
   9465   /* * Sentinel * */
   9466   /**
   9467    * The sentinel value.
   9468    * This value enforces specific underlying integer type for the enum.
   9469    * Do not use.
   9470    */
   9471   MHD_LIB_INFO_DYNAMIC_SENTINEL = 65535
   9472 };
   9473 
   9474 
   9475 /**
   9476  * The data provided by #MHD_lib_get_info_dynamic_sz().
   9477  * The resulting value may vary over time.
   9478  */
   9479 union MHD_LibInfoDynamicData
   9480 {
   9481   /**
   9482    * The data for the #MHD_LIB_INFO_DYNAMIC_INITED_FULLY_ONCE query
   9483    */
   9484   enum MHD_Bool v_inited_fully_once_bool;
   9485 
   9486   /**
   9487    * The data for the #MHD_LIB_INFO_DYNAMIC_INITED_FULLY_NOW query
   9488    */
   9489   enum MHD_Bool v_inited_fully_now_bool;
   9490 
   9491   /**
   9492    * The data for the #MHD_LIB_INFO_DYNAMIC_TYPE_TLS query
   9493    */
   9494   struct MHD_LibInfoTLSType v_tls_backends;
   9495 
   9496   /**
   9497    * Unused member.
   9498    * Help enforcing future-proof alignment of the union.
   9499    * Do not use.
   9500    */
   9501   void *reserved;
   9502 };
   9503 
   9504 /**
   9505  * Get dynamic information about MHD that may be changed at run-time.
   9506  * The wrapper macro #MHD_lib_get_info_dynamic() could be more convenient.
   9507  *
   9508  * @param info_type the type of requested information
   9509  * @param[out] output_buf the pointer to union to be set to the requested
   9510  *                        information
   9511  * @param output_buf_size the size of the memory area pointed by @a output_buf
   9512  *                        (provided by the caller for storing the requested
   9513  *                        information), in bytes
   9514  * @return #MHD_SC_OK if succeed,
   9515  *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
   9516  *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
   9517  *         or other error code
   9518  * @ingroup specialized
   9519  */
   9520 MHD_EXTERN_ enum MHD_StatusCode
   9521 MHD_lib_get_info_dynamic_sz (
   9522   enum MHD_LibInfoDynamic info_type,
   9523   union MHD_LibInfoDynamicData *MHD_RESTRICT output_buf,
   9524   size_t output_buf_size)
   9525 MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_OUT_ (2);
   9526 
   9527 /**
   9528  * Get dynamic information about MHD that may be changed at run-time.
   9529  *
   9530  * @param info the type of requested information
   9531  * @param[out] output_buf the pointer to union to be set to the requested
   9532  *                        information
   9533  * @return #MHD_SC_OK if succeed,
   9534  *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
   9535  *         or other error code
   9536  * @ingroup specialized
   9537  */
   9538 #define MHD_lib_get_info_dynamic(info, output_buf) \
   9539         MHD_lib_get_info_dynamic_sz ((info),(output_buf),sizeof(*(output_buf)))
   9540 
   9541 
   9542 /**
   9543  * Values of this enum are used to specify what information about a daemon is
   9544  * requested.
   9545  * These types of information do not change after the start of the daemon
   9546  * until the daemon is destroyed.
   9547  */
   9548 enum MHD_DaemonInfoFixedType
   9549 {
   9550 
   9551   /**
   9552    * Get the type of system call used for sockets polling.
   9553    * The value #MHD_SPS_AUTO is never set in the returned data.
   9554    * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon
   9555    * does not use internal sockets polling.
   9556    * The result is placed in @a v_poll_syscall member.
   9557    */
   9558   MHD_DAEMON_INFO_FIXED_POLL_SYSCALL = 41
   9559   ,
   9560   /**
   9561    * Get the file descriptor for the single FD that triggered when
   9562    * any MHD event happens.
   9563    * This FD can be watched as aggregate indicator for all MHD events.
   9564    * The provided socket must be used as 'read-only': only select() or similar
   9565    * functions should be used. Any modifications (changing socket attributes,
   9566    * calling accept(), closing it etc.) will lead to undefined behaviour.
   9567    * The function returns #MHD_SC_INFO_GET_TYPE_NOT_SUPP_BY_BUILD if the library
   9568    * does not support mode with agregate FD.
   9569    * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon
   9570    * is not configured to use this mode.
   9571    * The result is placed in @a v_aggreagate_fd member.
   9572    */
   9573   MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD = 46
   9574   ,
   9575   /**
   9576    * Get the number of worker threads when used in MHD_WM_WORKER_THREADS mode.
   9577    * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon
   9578    * does not use worker threads mode.
   9579    * The result is placed in @a v_num_work_threads_uint member.
   9580    */
   9581   MHD_DAEMON_INFO_FIXED_NUM_WORK_THREADS = 47
   9582   ,
   9583   /**
   9584    * Get the port number of daemon's listen socket.
   9585    * Note: if port '0' (auto port) was specified for #MHD_D_OPTION_BIND_PORT(),
   9586    * returned value will be the real port number.
   9587    * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon
   9588    * does not have listening socket or if listening socket is non-IP.
   9589    * The function returns #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the port number
   9590    * detection failed or not supported by the platform.
   9591    * If the function succeed, the returned port number is never zero.
   9592    * The result is placed in @a v_bind_port_uint16 member.
   9593    */
   9594   MHD_DAEMON_INFO_FIXED_BIND_PORT = 80
   9595   ,
   9596   /**
   9597    * Get the file descriptor for the listening socket.
   9598    * The provided socket must be used as 'read-only': only select() or similar
   9599    * functions should be used. Any modifications (changing socket attributes,
   9600    * calling accept(), closing it etc.) will lead to undefined behaviour.
   9601    * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon
   9602    * does not have listening socket.
   9603    * The result is placed in @a v_listen_socket member.
   9604    */
   9605   MHD_DAEMON_INFO_FIXED_LISTEN_SOCKET = 82
   9606   ,
   9607   /**
   9608    * Get the TLS backend used by the daemon.
   9609    * The value #MHD_TLS_BACKEND_ANY is never set in the returned data.
   9610    * The value #MHD_TLS_BACKEND_NONE is set if the daemon does not use TLS.
   9611    * If MHD built without TLS support then #MHD_TLS_BACKEND_NONE is always set.
   9612    * The result is placed in @a v_tls_backend member.
   9613    */
   9614   MHD_DAEMON_INFO_FIXED_TLS_BACKEND = 120
   9615   ,
   9616   /**
   9617    * Get the default inactivity timeout for connections in milliseconds.
   9618    * The result is placed in @a v_default_timeout_milsec_uint32 member.
   9619    */
   9620   MHD_DAEMON_INFO_FIXED_DEFAULT_TIMEOUT_MILSEC = 160
   9621   ,
   9622   /**
   9623    * Get the limit of number of simutaneous network connections served by
   9624    * the daemon.
   9625    * The result is placed in @a v_global_connection_limit_uint member.
   9626    */
   9627   MHD_DAEMON_INFO_FIXED_GLOBAL_CONNECTION_LIMIT = 161
   9628   ,
   9629   /**
   9630    * Get the limit of number of simutaneous network connections served by
   9631    * the daemon for any single IP address.
   9632    * The result is placed in @a v_per_ip_limit_uint member.
   9633    */
   9634   MHD_DAEMON_INFO_FIXED_PER_IP_LIMIT = 162
   9635   ,
   9636   /**
   9637    * Get the setting for suppression of the 'Date:' header in replies.
   9638    * The result is placed in @a v_suppress_date_header_bool member.
   9639    */
   9640   MHD_DAEMON_INFO_FIXED_SUPPRESS_DATE_HEADER = 240
   9641   ,
   9642   /**
   9643    * Get the size of buffer unsed per connection.
   9644    * The result is placed in @a v_conn_memory_limit_sizet member.
   9645    */
   9646   MHD_DAEMON_INFO_FIXED_CONN_MEMORY_LIMIT = 280
   9647   ,
   9648   /**
   9649    * Get the limit of maximum FD value for the daemon.
   9650    * The daemon rejects (closes) any sockets with FD equal or higher
   9651    * the resulting number.
   9652    * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon
   9653    * is built for W32.
   9654    * The result is placed in @a v_fd_number_limit_uint member.
   9655    */
   9656   MHD_DAEMON_INFO_FIXED_FD_NUMBER_LIMIT = 283
   9657   ,
   9658 
   9659   /* * Sentinel * */
   9660   /**
   9661    * The sentinel value.
   9662    * This value enforces specific underlying integer type for the enum.
   9663    * Do not use.
   9664    */
   9665   MHD_DAEMON_INFO_FIXED_SENTINEL = 65535
   9666 
   9667 };
   9668 
   9669 
   9670 /**
   9671  * Information about an MHD daemon.
   9672  */
   9673 union MHD_DaemonInfoFixedData
   9674 {
   9675   /**
   9676    * The data for the #MHD_DAEMON_INFO_FIXED_POLL_SYSCALL query
   9677    */
   9678   enum MHD_SockPollSyscall v_poll_syscall;
   9679 
   9680   /**
   9681    * The data for the #MHD_DAEMON_INFO_FIXED_NUM_WORK_THREADS query
   9682    */
   9683   unsigned int v_num_work_threads_uint;
   9684 
   9685   /**
   9686    * The data for the #MHD_DAEMON_INFO_FIXED_BIND_PORT query
   9687    */
   9688   uint_least16_t v_bind_port_uint16;
   9689 
   9690   /**
   9691    * The data for the #MHD_DAEMON_INFO_FIXED_LISTEN_SOCKET query
   9692    */
   9693   MHD_Socket v_listen_socket;
   9694 
   9695   /**
   9696    * The data for the #MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD query
   9697    */
   9698   int v_aggreagate_fd;
   9699 
   9700   /**
   9701    * The data for the #MHD_DAEMON_INFO_FIXED_TLS_BACKEND query
   9702    */
   9703   enum MHD_TlsBackend v_tls_backend;
   9704 
   9705   /**
   9706    * The data for the #MHD_DAEMON_INFO_FIXED_DEFAULT_TIMEOUT_MILSEC query
   9707    */
   9708   uint_fast32_t v_default_timeout_milsec_uint32;
   9709 
   9710   /**
   9711    * The data for the #MHD_DAEMON_INFO_FIXED_GLOBAL_CONNECTION_LIMIT query
   9712    */
   9713   unsigned int v_global_connection_limit_uint;
   9714 
   9715   /**
   9716    * The data for the #MHD_DAEMON_INFO_FIXED_PER_IP_LIMIT query
   9717    */
   9718   unsigned int v_per_ip_limit_uint;
   9719 
   9720   /**
   9721    * The data for the #MHD_DAEMON_INFO_FIXED_SUPPRESS_DATE_HEADER query
   9722    */
   9723   enum MHD_Bool v_suppress_date_header_bool;
   9724 
   9725   /**
   9726    * The data for the #MHD_DAEMON_INFO_FIXED_CONN_MEMORY_LIMIT query
   9727    */
   9728   size_t v_conn_memory_limit_sizet;
   9729 
   9730   /**
   9731    * The data for the #MHD_DAEMON_INFO_FIXED_FD_NUMBER_LIMIT query
   9732    */
   9733   MHD_Socket v_fd_number_limit_socket;
   9734 
   9735   /**
   9736    * Unused member.
   9737    * Help enforcing future-proof alignment of the union.
   9738    * Do not use.
   9739    */
   9740   void *reserved;
   9741 };
   9742 
   9743 
   9744 /**
   9745  * Obtain fixed information about the given daemon.
   9746  * This information is not changed at after start of the daemon until
   9747  * the daemon is destroyed.
   9748  * The wrapper macro #MHD_daemon_get_info_fixed() may be more convenient.
   9749  *
   9750  * @param daemon the daemon to get information about
   9751  * @param info_type the type of information requested
   9752  * @param[out] output_buf pointer to union where requested information will
   9753  *                        be stored
   9754  * @param output_buf_size the size of the memory area pointed by @a output_buf
   9755  *                        (provided by the caller for storing the requested
   9756  *                        information), in bytes
   9757  * @return #MHD_SC_OK if succeed,
   9758  *         #MHD_SC_TOO_EARLY if the daemon has not been started yet,
   9759  *         #MHD_SC_TOO_LATE if the daemon is being stopped or has failed,
   9760  *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
   9761  *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
   9762  *                                              is not available for this
   9763  *                                              daemon due to the daemon
   9764  *                                              configuration/mode,
   9765  *         #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information
   9766  *                                            should be available for
   9767  *                                            the daemon, but cannot be provided
   9768  *                                            due to some error or other
   9769  *                                            reasons,
   9770  *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
   9771  *         other error codes in case of other errors
   9772  * @ingroup specialized
   9773  */
   9774 MHD_EXTERN_ enum MHD_StatusCode
   9775 MHD_daemon_get_info_fixed_sz (
   9776   struct MHD_Daemon *MHD_RESTRICT daemon,
   9777   enum MHD_DaemonInfoFixedType info_type,
   9778   union MHD_DaemonInfoFixedData *MHD_RESTRICT output_buf,
   9779   size_t output_buf_size)
   9780 MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1)
   9781 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3);
   9782 
   9783 /**
   9784  * Obtain fixed information about the given daemon.
   9785  * This types of information are not changed at after start of the daemon until
   9786  * the daemon is destroyed.
   9787  *
   9788  * @param daemon the daemon to get information about
   9789  * @param info_type the type of information requested
   9790  * @param[out] output_buf pointer to union where requested information will
   9791  *                          be stored
   9792  * @return #MHD_SC_OK if succeed,
   9793  *         #MHD_SC_TOO_EARLY if the daemon has not been started yet,
   9794  *         #MHD_SC_TOO_LATE if the daemon is being stopped or has failed,
   9795  *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
   9796  *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
   9797  *                                              is not available for this
   9798  *                                              daemon due to the daemon
   9799  *                                              configuration/mode,
   9800  *         #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information
   9801  *                                            should be available for
   9802  *                                            the daemon, but cannot be provided
   9803  *                                            due to some error or other
   9804  *                                            reasons,
   9805  *         other error codes in case of other errors
   9806  * @ingroup specialized
   9807  */
   9808 #define MHD_daemon_get_info_fixed(daemon, info_type, output_buf) \
   9809         MHD_daemon_get_info_fixed_sz ((daemon), (info_type), (output_buf), \
   9810                                       sizeof(*(output_buf)))
   9811 
   9812 
   9813 /**
   9814  * Values of this enum are used to specify what
   9815  * information about a daemon is desired.
   9816  * This types of information may be changed after the start of the daemon.
   9817  */
   9818 enum MHD_DaemonInfoDynamicType
   9819 {
   9820   /**
   9821    * The the maximum number of millisecond from the current moment until
   9822    * the mandatory call of the daemon data processing function (like
   9823    * #MHD_daemon_process_reg_events(), #MHD_daemon_process_blocking()).
   9824    * If resulting value is zero then daemon data processing function should be
   9825    * called as soon as possible as some data processing is already pending.
   9826    * The data processing function can also be called earlier as well.
   9827    * Available only for daemons stated in #MHD_WM_EXTERNAL_PERIODIC,
   9828    * #MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL, #MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE
   9829    * or #MHD_WM_EXTERNAL_SINGLE_FD_WATCH modes.
   9830    * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon has
   9831    * internal handling of events (internal threads).
   9832    * The result is placed in @a v_max_time_to_wait_uint64 member.
   9833    */
   9834   MHD_DAEMON_INFO_DYNAMIC_MAX_TIME_TO_WAIT = 1
   9835   ,
   9836   /**
   9837    * Check whether the daemon has any connected network clients.
   9838    * The result is placed in @a v_has_connections_bool member.
   9839    */
   9840   MHD_DAEMON_INFO_DYNAMIC_HAS_CONNECTIONS = 20
   9841   ,
   9842   /* * Sentinel * */
   9843   /**
   9844    * The sentinel value.
   9845    * This value enforces specific underlying integer type for the enum.
   9846    * Do not use.
   9847    */
   9848   MHD_DAEMON_INFO_DYNAMIC_SENTINEL = 65535
   9849 };
   9850 
   9851 
   9852 /**
   9853  * Information about an MHD daemon.
   9854  */
   9855 union MHD_DaemonInfoDynamicData
   9856 {
   9857   /**
   9858    * The data for the #MHD_DAEMON_INFO_DYNAMIC_MAX_TIME_TO_WAIT query
   9859    */
   9860   uint_fast64_t v_max_time_to_wait_uint64;
   9861 
   9862   /**
   9863    * The data for the #MHD_DAEMON_INFO_DYNAMIC_HAS_CONNECTIONS query
   9864    */
   9865   enum MHD_Bool v_has_connections_bool;
   9866 
   9867   /**
   9868    * Unused member.
   9869    * Help enforcing future-proof alignment of the union.
   9870    * Do not use.
   9871    */
   9872   void *reserved;
   9873 };
   9874 
   9875 
   9876 /**
   9877  * Obtain dynamic information about the given daemon.
   9878  * This information may be changed after the start of the daemon.
   9879  * The wrapper macro #MHD_daemon_get_info_dynamic() could be more convenient.
   9880  *
   9881  * @param daemon the daemon to get information about
   9882  * @param info_type the type of information requested
   9883  * @param[out] output_buf the pointer to union to be set to the requested
   9884  *                        information
   9885  * @param output_buf_size the size of the memory area pointed by @a output_buf
   9886  *                        (provided by the caller for storing the requested
   9887  *                        information), in bytes
   9888  * @return #MHD_SC_OK if succeed,
   9889  *         #MHD_SC_TOO_EARLY if the daemon has not been started yet,
   9890  *         #MHD_SC_TOO_LATE if the daemon is being stopped or has failed,
   9891  *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
   9892  *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
   9893  *                                              is not available for this
   9894  *                                              daemon due to the daemon
   9895  *                                              configuration/mode,
   9896  *         #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information
   9897  *                                            should be available for
   9898  *                                            the daemon, but cannot be provided
   9899  *                                            due to some error or other
   9900  *                                            reasons,
   9901  *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
   9902  *         other error codes in case of other errors
   9903  * @ingroup specialized
   9904  */
   9905 MHD_EXTERN_ enum MHD_StatusCode
   9906 MHD_daemon_get_info_dynamic_sz (
   9907   struct MHD_Daemon *MHD_RESTRICT daemon,
   9908   enum MHD_DaemonInfoDynamicType info_type,
   9909   union MHD_DaemonInfoDynamicData *MHD_RESTRICT output_buf,
   9910   size_t output_buf_size)
   9911 MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1)
   9912 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3);
   9913 
   9914 /**
   9915  * Obtain dynamic information about the given daemon.
   9916  * This types of information may be changed after the start of the daemon.
   9917  *
   9918  * @param daemon the daemon to get information about
   9919  * @param info_type the type of information requested
   9920  * @param[out] output_buf the pointer to union to be set to the requested
   9921  *                        information
   9922  * @return #MHD_SC_OK if succeed,
   9923  *         #MHD_SC_TOO_EARLY if the daemon has not been started yet,
   9924  *         #MHD_SC_TOO_LATE if the daemon is being stopped or has failed,
   9925  *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
   9926  *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
   9927  *                                              is not available for this
   9928  *                                              daemon due to the daemon
   9929  *                                              configuration/mode,
   9930  *         #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information
   9931  *                                            should be available for
   9932  *                                            the daemon, but cannot be provided
   9933  *                                            due to some error or other
   9934  *                                            reasons,
   9935  *         other error codes in case of other errors
   9936  * @ingroup specialized
   9937  */
   9938 #define MHD_daemon_get_info_dynamic(daemon, info_type, output_buf) \
   9939         MHD_daemon_get_info_dynamic_sz ((daemon), (info_type), (output_buf), \
   9940                                         sizeof(*(output_buf)))
   9941 
   9942 
   9943 /**
   9944  * Select which fixed information about connection is desired.
   9945  * This information is not changed during the lifetime of the connection.
   9946  */
   9947 enum MHD_ConnectionInfoFixedType
   9948 {
   9949   /**
   9950    * Get the network address of the client.
   9951    * If the connection does not have known remote address (was not provided
   9952    * by the system or by the application in case of externally added
   9953    * connection) then error code #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE is
   9954    * returned if connection is IP type or unknown type or error code
   9955    * #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if connection type is non-IP.
   9956    * The @a sa pointer is never NULL if the function succeed (#MHD_SC_OK
   9957    * returned).
   9958    * The result is placed in @a v_client_address_sa_info member.
   9959    * @ingroup request
   9960    */
   9961   MHD_CONNECTION_INFO_FIXED_CLIENT_ADDRESS = 1
   9962   ,
   9963   /**
   9964    * Get the file descriptor for the connection socket.
   9965    * The provided socket must be used as 'read-only': only select() or similar
   9966    * functions should be used. Any modifications (changing socket attributes,
   9967    * calling send() or recv(), closing it etc.) will lead to undefined
   9968    * behaviour.
   9969    * The result is placed in @a v_connection_socket member.
   9970    * @ingroup request
   9971    */
   9972   MHD_CONNECTION_INFO_FIXED_CONNECTION_SOCKET = 2
   9973   ,
   9974   /**
   9975    * Get the `struct MHD_Daemon *` responsible for managing this connection.
   9976    * The result is placed in @a v_daemon member.
   9977    * @ingroup request
   9978    */
   9979   MHD_CONNECTION_INFO_FIXED_DAEMON = 20
   9980   ,
   9981   /**
   9982    * Returns the pointer to a variable pointing to connection-specific
   9983    * application context data that was (possibly) set during
   9984    * a #MHD_NotifyConnectionCallback or provided via @a connection_cntx
   9985    * parameter of #MHD_daemon_add_connection().
   9986    * By using provided pointer application may get or set the pointer to
   9987    * any data specific for the particular connection.
   9988    * Note: resulting data is NOT the context pointer itself.
   9989    * The result is placed in @a v_app_context_ppvoid member.
   9990    * @ingroup request
   9991    */
   9992   MHD_CONNECTION_INFO_FIXED_APP_CONTEXT = 30
   9993   ,
   9994 
   9995   /* * Sentinel * */
   9996   /**
   9997    * The sentinel value.
   9998    * This value enforces specific underlying integer type for the enum.
   9999    * Do not use.
  10000    */
  10001   MHD_CONNECTION_INFO_FIXED_SENTINEL = 65535
  10002 };
  10003 
  10004 /**
  10005  * Socket address information data
  10006  */
  10007 struct MHD_ConnInfoFixedSockAddr
  10008 {
  10009   /**
  10010    * The size of the @a sa
  10011    */
  10012   size_t sa_size;
  10013 
  10014   /**
  10015    * Socket Address type
  10016    */
  10017   const struct sockaddr *sa;
  10018 };
  10019 
  10020 /**
  10021  * Information about a connection.
  10022  */
  10023 union MHD_ConnectionInfoFixedData
  10024 {
  10025 
  10026   /**
  10027    * The data for the #MHD_CONNECTION_INFO_FIXED_CLIENT_ADDRESS query
  10028    */
  10029   struct MHD_ConnInfoFixedSockAddr v_client_address_sa_info;
  10030 
  10031   /**
  10032    * The data for the #MHD_CONNECTION_INFO_FIXED_CONNECTION_SOCKET query
  10033    */
  10034   MHD_Socket v_connection_socket;
  10035 
  10036   /**
  10037    * The data for the #MHD_CONNECTION_INFO_FIXED_DAEMON query
  10038    */
  10039   struct MHD_Daemon *v_daemon;
  10040 
  10041   /**
  10042    * The data for the #MHD_CONNECTION_INFO_FIXED_APP_CONTEXT query
  10043    */
  10044   void **v_app_context_ppvoid;
  10045 };
  10046 
  10047 
  10048 /**
  10049  * Obtain fixed information about the given connection.
  10050  * This information is not changed for the lifetime of the connection.
  10051  * The wrapper macro #MHD_connection_get_info_fixed() may be more convenient.
  10052  *
  10053  * @param connection the connection to get information about
  10054  * @param info_type the type of information requested
  10055  * @param[out] output_buf the pointer to union to be set to the requested
  10056  *                        information
  10057  * @param output_buf_size the size of the memory area pointed by @a output_buf
  10058  *                        (provided by the caller for storing the requested
  10059  *                        information), in bytes
  10060  * @return #MHD_SC_OK if succeed,
  10061  *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
  10062  *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
  10063  *                                              is not available for this
  10064  *                                              connection due to the connection
  10065  *                                              configuration/mode,
  10066  *         #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information
  10067  *                                            should be available for
  10068  *                                            the connection, but cannot be
  10069  *                                            provided due to some error or
  10070  *                                            other reasons,
  10071  *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
  10072  *         other error codes in case of other errors
  10073  * @ingroup specialized
  10074  */
  10075 MHD_EXTERN_ enum MHD_StatusCode
  10076 MHD_connection_get_info_fixed_sz (
  10077   struct MHD_Connection *MHD_RESTRICT connection,
  10078   enum MHD_ConnectionInfoFixedType info_type,
  10079   union MHD_ConnectionInfoFixedData *MHD_RESTRICT output_buf,
  10080   size_t output_buf_size)
  10081 MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1)
  10082 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3);
  10083 
  10084 
  10085 /**
  10086  * Obtain fixed information about the given connection.
  10087  * This information is not changed for the lifetime of the connection.
  10088  *
  10089  * @param connection the connection to get information about
  10090  * @param info_type the type of information requested
  10091  * @param[out] output_buf the pointer to union to be set to the requested
  10092  *                        information
  10093  * @return #MHD_SC_OK if succeed,
  10094  *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
  10095  *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
  10096  *                                              is not available for this
  10097  *                                              connection due to the connection
  10098  *                                              configuration/mode,
  10099  *         #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information
  10100  *                                            should be available for
  10101  *                                            the connection, but cannot be
  10102  *                                            provided due to some error or
  10103  *                                            other reasons,
  10104  *         other error codes in case of other errors
  10105  * @ingroup specialized
  10106  */
  10107 #define MHD_connection_get_info_fixed(connection, info_type, output_buf) \
  10108         MHD_connection_get_info_fixed_sz ((connection),(info_type), \
  10109                                           (output_buf), sizeof(*(output_buf)))
  10110 
  10111 
  10112 /**
  10113  * Select which dynamic information about connection is desired.
  10114  * This information may be changed during the lifetime of the connection.
  10115  */
  10116 enum MHD_ConnectionInfoDynamicType
  10117 {
  10118   /**
  10119    * Get current version of HTTP protocol used for connection.
  10120    * If connection is handling HTTP/1.x requests the function may return
  10121    * error code #MHD_SC_TOO_EARLY if the full request line has not been received
  10122    * yet for the current request.
  10123    * The result is placed in @a v_http_ver member.
  10124    * @ingroup request
  10125    */
  10126   MHD_CONNECTION_INFO_DYNAMIC_HTTP_VER = 1
  10127   ,
  10128   /**
  10129    * Get connection timeout value.
  10130    * This is the total number of milliseconds after which the idle
  10131    * connection is automatically disconnected.
  10132    * Note: the value set is NOT the number of milliseconds left before
  10133    * automatic disconnection.
  10134    * The result is placed in @a v_connection_timeout_uint32 member.
  10135    * @ingroup request
  10136    */
  10137   MHD_CONNECTION_INFO_DYNAMIC_CONNECTION_TIMEOUT_MILSEC = 10
  10138   ,
  10139   /**
  10140    * Check whether the connection is suspended.
  10141    * The result is placed in @a v_connection_suspended_bool member.
  10142    * @ingroup request
  10143    */
  10144   MHD_CONNECTION_INFO_DYNAMIC_CONNECTION_SUSPENDED = 11
  10145   ,
  10146   /**
  10147    * Get current version of TLS transport protocol used for connection
  10148    * If plain TCP connection is used then #MHD_TLS_VERSION_NO_TLS set in
  10149    * the data.
  10150    * It TLS handshake is not yet finished then error code #MHD_SC_TOO_EARLY is
  10151    * returned. If TLS has failed or being closed then #MHD_SC_TOO_LATE error
  10152    * code is returned.
  10153    * If TLS version cannot be detected for any reason then error code
  10154    * #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE is returned.
  10155    * The result is placed in @a v_tls_ver member.
  10156    * @ingroup request
  10157    */
  10158   MHD_CONNECTION_INFO_DYNAMIC_TLS_VER = 105
  10159   ,
  10160   /**
  10161    * Get the TLS backend session handle.
  10162    * If plain TCP connection is used then the function returns error code
  10163    * #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE.
  10164    * The resulting union has only one valid member.
  10165    * The result is placed in @a v_tls_session member.
  10166    * @ingroup request
  10167    */
  10168   MHD_CONNECTION_INFO_DYNAMIC_TLS_SESSION = 140
  10169   ,
  10170 
  10171   /* * Sentinel * */
  10172   /**
  10173    * The sentinel value.
  10174    * This value enforces specific underlying integer type for the enum.
  10175    * Do not use.
  10176    */
  10177   MHD_CONNECTION_INFO_DYNAMIC_SENTINEL = 65535
  10178 };
  10179 
  10180 
  10181 /**
  10182  * The versions of TLS protocol
  10183  */
  10184 enum MHD_FIXED_ENUM_MHD_SET_ MHD_TlsVersion
  10185 {
  10186 
  10187   /**
  10188    * No TLS / plain socket connection
  10189    */
  10190   MHD_TLS_VERSION_NO_TLS = 0
  10191   ,
  10192   /**
  10193    * Not supported/failed to negotiate/failed to handshake TLS
  10194    */
  10195   MHD_TLS_VERSION_BROKEN = 1
  10196   ,
  10197   /**
  10198    * TLS version 1.0
  10199    */
  10200   MHD_TLS_VERSION_1_0 = 2
  10201   ,
  10202   /**
  10203    * TLS version 1.1
  10204    */
  10205   MHD_TLS_VERSION_1_1 = 3
  10206   ,
  10207   /**
  10208    * TLS version 1.2
  10209    */
  10210   MHD_TLS_VERSION_1_2 = 4
  10211   ,
  10212   /**
  10213    * TLS version 1.3
  10214    */
  10215   MHD_TLS_VERSION_1_3 = 5
  10216   ,
  10217   /**
  10218    * Some unknown TLS version.
  10219    * The TLS version is supported by TLS backend, but unknown to MHD.
  10220    */
  10221   MHD_TLS_VERSION_UNKNOWN = 1999
  10222 };
  10223 
  10224 /**
  10225  * Connection TLS session information.
  10226  * Only one member is valid. Use #MHD_DAEMON_INFO_FIXED_TLS_TYPE to find out
  10227  * which member should be used.
  10228  */
  10229 union MHD_ConnInfoDynamicTlsSess
  10230 {
  10231   /* Include <gnutls/gnutls.h> before this header to get a better type safety */
  10232   /**
  10233    * GnuTLS session handle, of type "gnutls_session_t".
  10234    */
  10235 #if defined(GNUTLS_VERSION_MAJOR) && GNUTLS_VERSION_MAJOR >= 3
  10236   gnutls_session_t v_gnutls_session;
  10237 #else
  10238   void * /* gnutls_session_t */ v_gnutls_session;
  10239 #endif
  10240 
  10241   /* Include <openssl/types.h> or <openssl/crypto.h> before this header to get
  10242      a better type safety */
  10243   /**
  10244    * OpenSSL session handle, of type "SSL*".
  10245    */
  10246 #if defined(OPENSSL_TYPES_H) && OPENSSL_VERSION_MAJOR >= 3
  10247   SSL *v_openssl_session;
  10248 #else
  10249   void /* SSL */ *v_openssl_session;
  10250 #endif
  10251 
  10252   /* Include <mbedtls/ssl.h> before this header to get a better type safety */
  10253   /**
  10254    * MbedTLS session handle, of type "mbedtls_ssl_context*".
  10255    */
  10256 #if defined(MBEDTLS_SSL_H)
  10257   mbedtls_ssl_context *v_mbedtls_session;
  10258 #else
  10259   void /* mbedtls_ssl_context */ *v_mbedtls_session;
  10260 #endif
  10261 };
  10262 
  10263 /**
  10264  * Information about a connection.
  10265  */
  10266 union MHD_ConnectionInfoDynamicData
  10267 {
  10268   /**
  10269    * The data for the #MHD_CONNECTION_INFO_DYNAMIC_HTTP_VER query
  10270    */
  10271   enum MHD_HTTP_ProtocolVersion v_http_ver;
  10272 
  10273   /**
  10274    * The data for the #MHD_CONNECTION_INFO_DYNAMIC_CONNECTION_TIMEOUT_MILSEC
  10275    * query
  10276    */
  10277   uint_fast32_t v_connection_timeout_uint32;
  10278 
  10279   /**
  10280    * The data for the #MHD_CONNECTION_INFO_DYNAMIC_CONNECTION_SUSPENDED query
  10281    */
  10282   enum MHD_Bool v_connection_suspended_bool;
  10283 
  10284   /**
  10285    * The data for the #MHD_CONNECTION_INFO_DYNAMIC_CONNECTION_SUSPENDED query
  10286    */
  10287   enum MHD_TlsVersion v_tls_ver;
  10288 
  10289   /**
  10290    * Connection TLS session information.
  10291    * Only one member is valid. Use #MHD_DAEMON_INFO_FIXED_TLS_TYPE to find out
  10292    * which member should be used.
  10293    */
  10294   union MHD_ConnInfoDynamicTlsSess v_tls_session;
  10295 };
  10296 
  10297 /**
  10298  * Obtain dynamic information about the given connection.
  10299  * This information may be changed during the lifetime of the connection.
  10300  *
  10301  * The wrapper macro #MHD_connection_get_info_dynamic() may be more convenient.
  10302  *
  10303  * @param connection the connection to get information about
  10304  * @param info_type the type of information requested
  10305  * @param[out] output_buf the pointer to union to be set to the requested
  10306  *                        information
  10307  * @param output_buf_size the size of the memory area pointed by @a output_buf
  10308  *                        (provided by the caller for storing the requested
  10309  *                        information), in bytes
  10310  * @return #MHD_SC_OK if succeed,
  10311  *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
  10312  *         #MHD_SC_TOO_EARLY if the connection has not reached yet required
  10313  *                           state,
  10314  *         #MHD_SC_TOO_LATE if the connection is already in state where
  10315  *                          the requested information is not available,
  10316  *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
  10317  *                                              is not available for this
  10318  *                                              connection due to the connection
  10319  *                                              configuration/mode,
  10320  *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
  10321  *         #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information
  10322  *                                            should be available for
  10323  *                                            the connection, but cannot be
  10324  *                                            provided due to some error or
  10325  *                                            other reasons,
  10326  *         other error codes in case of other errors
  10327  * @ingroup specialized
  10328  */
  10329 MHD_EXTERN_ enum MHD_StatusCode
  10330 MHD_connection_get_info_dynamic_sz (
  10331   struct MHD_Connection *MHD_RESTRICT connection,
  10332   enum MHD_ConnectionInfoDynamicType info_type,
  10333   union MHD_ConnectionInfoDynamicData *MHD_RESTRICT output_buf,
  10334   size_t output_buf_size)
  10335 MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1)
  10336 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3);
  10337 
  10338 
  10339 /**
  10340  * Obtain dynamic information about the given connection.
  10341  * This information may be changed during the lifetime of the connection.
  10342  *
  10343  * @param connection the connection to get information about
  10344  * @param info_type the type of information requested
  10345  * @param[out] output_buf the pointer to union to be set to the requested
  10346  *                        information
  10347  * @return #MHD_SC_OK if succeed,
  10348  *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
  10349  *         #MHD_SC_TOO_EARLY if the connection has not reached yet required
  10350  *                           state,
  10351  *         #MHD_SC_TOO_LATE if the connection is already in state where
  10352  *                          the requested information is not available,
  10353  *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
  10354  *                                              is not available for this
  10355  *                                              connection due to the connection
  10356  *                                              configuration/mode,
  10357  *         #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information
  10358  *                                            should be available for
  10359  *                                            the connection, but cannot be
  10360  *                                            provided due to some error or
  10361  *                                            other reasons,
  10362  *         other error codes in case of other errors
  10363  * @ingroup specialized
  10364  */
  10365 #define MHD_connection_get_info_dynamic(connection, info_type, output_buf) \
  10366         MHD_connection_get_info_dynamic_sz ((connection),(info_type), \
  10367                                             (output_buf),sizeof(*(output_buf)))
  10368 
  10369 
  10370 /**
  10371  * Select which fixed information about stream is desired.
  10372  * This information is not changed during the lifetime of the connection.
  10373  */
  10374 enum MHD_FIXED_ENUM_APP_SET_ MHD_StreamInfoFixedType
  10375 {
  10376   /**
  10377    * Get the `struct MHD_Daemon *` responsible for managing connection which
  10378    * is responsible for this stream.
  10379    * The result is placed in @a v_daemon member.
  10380    * @ingroup request
  10381    */
  10382   MHD_STREAM_INFO_FIXED_DAEMON = 20
  10383   ,
  10384   /**
  10385    * Get the `struct MHD_Connection *` responsible for managing this stream.
  10386    * The result is placed in @a v_connection member.
  10387    * @ingroup request
  10388    */
  10389   MHD_STREAM_INFO_FIXED_CONNECTION = 21
  10390   ,
  10391 
  10392   /* * Sentinel * */
  10393   /**
  10394    * The sentinel value.
  10395    * This value enforces specific underlying integer type for the enum.
  10396    * Do not use.
  10397    */
  10398   MHD_STREAM_INFO_FIXED_SENTINEL = 65535
  10399 };
  10400 
  10401 
  10402 /**
  10403  * Fixed information about a stream.
  10404  */
  10405 union MHD_StreamInfoFixedData
  10406 {
  10407   /**
  10408    * The data for the #MHD_STREAM_INFO_FIXED_DAEMON query
  10409    */
  10410   struct MHD_Daemon *v_daemon;
  10411   /**
  10412    * The data for the #MHD_STREAM_INFO_FIXED_CONNECTION query
  10413    */
  10414   struct MHD_Connection *v_connection;
  10415 };
  10416 
  10417 
  10418 /**
  10419  * Obtain fixed information about the given stream.
  10420  * This information is not changed for the lifetime of the stream.
  10421  *
  10422  * The wrapper macro #MHD_stream_get_info_fixed() may be more convenient.
  10423  *
  10424  * @param stream the stream to get information about
  10425  * @param info_type the type of information requested
  10426  * @param[out] output_buf the pointer to union to be set to the requested
  10427  *                        information
  10428  * @param output_buf_size the size of the memory area pointed by @a output_buf
  10429  *                        (provided by the caller for storing the requested
  10430  *                        information), in bytes
  10431  * @return #MHD_SC_OK if succeed,
  10432  *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
  10433  *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
  10434  *         other error codes in case of other errors
  10435  * @ingroup specialized
  10436  */
  10437 MHD_EXTERN_ enum MHD_StatusCode
  10438 MHD_stream_get_info_fixed_sz (
  10439   struct MHD_Stream *MHD_RESTRICT stream,
  10440   enum MHD_StreamInfoFixedType info_type,
  10441   union MHD_StreamInfoFixedData *MHD_RESTRICT output_buf,
  10442   size_t output_buf_size)
  10443 MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1)
  10444 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3);
  10445 
  10446 
  10447 /**
  10448  * Obtain fixed information about the given stream.
  10449  * This information is not changed for the lifetime of the tream.
  10450  *
  10451  * @param stream the stream to get information about
  10452  * @param info_type the type of information requested
  10453  * @param[out] output_buf the pointer to union to be set to the requested
  10454  *                        information
  10455  * @return #MHD_SC_OK if succeed,
  10456  *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
  10457  *         other error codes in case of other errors
  10458  * @ingroup specialized
  10459  */
  10460 #define MHD_stream_get_info_fixed(stream, info_type, output_buf) \
  10461         MHD_stream_get_info_fixed_sz ((stream),(info_type),(output_buf), \
  10462                                       sizeof(*(output_buf)))
  10463 
  10464 
  10465 /**
  10466  * Select which fixed information about stream is desired.
  10467  * This information may be changed during the lifetime of the stream.
  10468  */
  10469 enum MHD_FIXED_ENUM_APP_SET_ MHD_StreamInfoDynamicType
  10470 {
  10471   /**
  10472    * Get the `struct MHD_Request *` for current request processed by the stream.
  10473    * If no request is being processed, the error code #MHD_SC_TOO_EARLY is
  10474    * returned.
  10475    * The result is placed in @a v_request member.
  10476    * @ingroup request
  10477    */
  10478   MHD_STREAM_INFO_DYNAMIC_REQUEST = 20
  10479   ,
  10480 
  10481   /* * Sentinel * */
  10482   /**
  10483    * The sentinel value.
  10484    * This value enforces specific underlying integer type for the enum.
  10485    * Do not use.
  10486    */
  10487   MHD_STREAM_INFO_DYNAMIC_SENTINEL = 65535
  10488 };
  10489 
  10490 
  10491 /**
  10492  * Dynamic information about stream.
  10493  * This information may be changed during the lifetime of the connection.
  10494  */
  10495 union MHD_StreamInfoDynamicData
  10496 {
  10497   /**
  10498    * The data for the #MHD_STREAM_INFO_DYNAMIC_REQUEST query
  10499    */
  10500   struct MHD_Request *v_request;
  10501 };
  10502 
  10503 /**
  10504  * Obtain dynamic information about the given stream.
  10505  * This information may be changed during the lifetime of the stream.
  10506  *
  10507  * The wrapper macro #MHD_stream_get_info_dynamic() may be more convenient.
  10508  *
  10509  * @param stream the stream to get information about
  10510  * @param info_type the type of information requested
  10511  * @param[out] output_buf the pointer to union to be set to the requested
  10512  *                        information
  10513  * @param output_buf_size the size of the memory area pointed by @a output_buf
  10514  *                        (provided by the caller for storing the requested
  10515  *                        information), in bytes
  10516  * @return #MHD_SC_OK if succeed,
  10517  *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
  10518  *         #MHD_SC_TOO_EARLY if the stream has not reached yet required state,
  10519  *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
  10520  *         other error codes in case of other errors
  10521  * @ingroup specialized
  10522  */
  10523 MHD_EXTERN_ enum MHD_StatusCode
  10524 MHD_stream_get_info_dynamic_sz (
  10525   struct MHD_Stream *MHD_RESTRICT stream,
  10526   enum MHD_StreamInfoDynamicType info_type,
  10527   union MHD_StreamInfoDynamicData *MHD_RESTRICT output_buf,
  10528   size_t output_buf_size)
  10529 MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1)
  10530 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3);
  10531 
  10532 
  10533 /**
  10534  * Obtain dynamic information about the given stream.
  10535  * This information may be changed during the lifetime of the stream.
  10536  *
  10537  * @param stream the stream to get information about
  10538  * @param info_type the type of information requested
  10539  * @param[out] output_buf the pointer to union to be set to the requested
  10540  *                        information
  10541  * @return #MHD_SC_OK if succeed,
  10542  *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
  10543  *         #MHD_SC_TOO_EARLY if the stream has not reached yet required state,
  10544  *         other error codes in case of other errors
  10545  * @ingroup specialized
  10546  */
  10547 #define MHD_stream_get_info_dynamic(stream, info_type, output_buf) \
  10548         MHD_stream_get_info_dynamic_sz ((stream),(info_type),(output_buf), \
  10549                                         sizeof(*(output_buf)))
  10550 
  10551 
  10552 /**
  10553  * Select which fixed information about request is desired.
  10554  * This information is not changed during the lifetime of the request.
  10555  */
  10556 enum MHD_FIXED_ENUM_APP_SET_ MHD_RequestInfoFixedType
  10557 {
  10558   /**
  10559    * Get the version of HTTP protocol used for the request.
  10560    * If request line has not been fully received yet then #MHD_SC_TOO_EARLY
  10561    * error code is returned.
  10562    * The result is placed in @a v_http_ver member.
  10563    * @ingroup request
  10564    */
  10565   MHD_REQUEST_INFO_FIXED_HTTP_VER = 1
  10566   ,
  10567   /**
  10568    * Get the HTTP method used for the request (as a enum).
  10569    * The result is placed in @a v_http_method member.
  10570    * @sa #MHD_REQUEST_INFO_DYNAMIC_HTTP_METHOD_STR
  10571    * @ingroup request
  10572    */
  10573   MHD_REQUEST_INFO_FIXED_HTTP_METHOD = 2
  10574   ,
  10575   /**
  10576    * Return MHD daemon to which the request belongs to.
  10577    * The result is placed in @a v_daemon member.
  10578    */
  10579   MHD_REQUEST_INFO_FIXED_DAEMON = 20
  10580   ,
  10581   /**
  10582    * Return which connection is associated with the stream which is associated
  10583    * with the request.
  10584    * The result is placed in @a v_connection member.
  10585    */
  10586   MHD_REQUEST_INFO_FIXED_CONNECTION = 21
  10587   ,
  10588   /**
  10589    * Return which stream the request is associated with.
  10590    * The result is placed in @a v_stream member.
  10591    */
  10592   MHD_REQUEST_INFO_FIXED_STREAM = 22
  10593   ,
  10594   /**
  10595    * Returns the pointer to a variable pointing to request-specific
  10596    * application context data. The same data is provided for
  10597    * #MHD_EarlyUriLogCallback and #MHD_RequestTerminationCallback.
  10598    * By using provided pointer application may get or set the pointer to
  10599    * any data specific for the particular request.
  10600    * Note: resulting data is NOT the context pointer itself.
  10601    * The result is placed in @a v_app_context_ppvoid member.
  10602    * @ingroup request
  10603    */
  10604   MHD_REQUEST_INFO_FIXED_APP_CONTEXT = 30
  10605   ,
  10606 
  10607   /* * Sentinel * */
  10608   /**
  10609    * The sentinel value.
  10610    * This value enforces specific underlying integer type for the enum.
  10611    * Do not use.
  10612    */
  10613   MHD_REQUEST_INFO_FIXED_SENTINEL = 65535
  10614 };
  10615 
  10616 
  10617 /**
  10618  * Fixed information about a request.
  10619  */
  10620 union MHD_RequestInfoFixedData
  10621 {
  10622 
  10623   /**
  10624    * The data for the #MHD_REQUEST_INFO_FIXED_HTTP_VER query
  10625    */
  10626   enum MHD_HTTP_ProtocolVersion v_http_ver;
  10627 
  10628   /**
  10629    * The data for the #MHD_REQUEST_INFO_FIXED_HTTP_METHOD query
  10630    */
  10631   enum MHD_HTTP_Method v_http_method;
  10632 
  10633   /**
  10634    * The data for the #MHD_REQUEST_INFO_FIXED_DAEMON query
  10635    */
  10636   struct MHD_Daemon *v_daemon;
  10637 
  10638   /**
  10639    * The data for the #MHD_REQUEST_INFO_FIXED_CONNECTION query
  10640    */
  10641   struct MHD_Connection *v_connection;
  10642 
  10643   /**
  10644    * The data for the #MHD_REQUEST_INFO_FIXED_STREAM query
  10645    */
  10646   struct MHD_Stream *v_stream;
  10647 
  10648   /**
  10649    * The data for the #MHD_REQUEST_INFO_FIXED_APP_CONTEXT query
  10650    */
  10651   void **v_app_context_ppvoid;
  10652 };
  10653 
  10654 /**
  10655  * Obtain fixed information about the given request.
  10656  * This information is not changed for the lifetime of the request.
  10657  *
  10658  * The wrapper macro #MHD_request_get_info_fixed() may be more convenient.
  10659  *
  10660  * @param request the request to get information about
  10661  * @param info_type the type of information requested
  10662  * @param[out] output_buf the pointer to union to be set to the requested
  10663  *                        information
  10664  * @param output_buf_size the size of the memory area pointed by @a output_buf
  10665  *                        (provided by the caller for storing the requested
  10666  *                        information), in bytes
  10667  * @return #MHD_SC_OK if succeed,
  10668  *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
  10669  *         #MHD_SC_TOO_EARLY if the request processing has not reached yet
  10670  *                           the required state,
  10671  *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
  10672  *         other error codes in case of other errors
  10673  * @ingroup specialized
  10674  */
  10675 MHD_EXTERN_ enum MHD_StatusCode
  10676 MHD_request_get_info_fixed_sz (
  10677   struct MHD_Request *MHD_RESTRICT request,
  10678   enum MHD_RequestInfoFixedType info_type,
  10679   union MHD_RequestInfoFixedData *MHD_RESTRICT output_buf,
  10680   size_t output_buf_size)
  10681 MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1)
  10682 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3);
  10683 
  10684 
  10685 /**
  10686  * Obtain fixed information about the given request.
  10687  * This information is not changed for the lifetime of the request.
  10688  *
  10689  * @param request the request to get information about
  10690  * @param info_type the type of information requested
  10691  * @param[out] output_buf the pointer to union to be set to the requested
  10692  *                        information
  10693  * @return #MHD_SC_OK if succeed,
  10694  *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
  10695  *         #MHD_SC_TOO_EARLY if the request processing has not reached yet
  10696  *                           the required state,
  10697  *         other error codes in case of other errors
  10698  * @ingroup specialized
  10699  */
  10700 #define MHD_request_get_info_fixed(request, info_type, output_buf) \
  10701         MHD_request_get_info_fixed_sz ((request), (info_type), (output_buf), \
  10702                                        sizeof(*(output_buf)))
  10703 
  10704 
  10705 /**
  10706  * Select which dynamic information about request is desired.
  10707  * This information may be changed during the lifetime of the request.
  10708  * Any returned string pointers are valid only until a response is provided.
  10709  */
  10710 enum MHD_FIXED_ENUM_APP_SET_ MHD_RequestInfoDynamicType
  10711 {
  10712   /**
  10713    * Get the HTTP method used for the request (as a MHD_String).
  10714    * The resulting string pointer in valid only until a response is provided.
  10715    * The result is placed in @a v_http_method_string member.
  10716    * @sa #MHD_REQUEST_INFO_FIXED_HTTP_METHOD
  10717    * @ingroup request
  10718    */
  10719   MHD_REQUEST_INFO_DYNAMIC_HTTP_METHOD_STRING = 1
  10720   ,
  10721   /**
  10722    * Get the URI used for the request (as a MHD_String), excluding
  10723    * the parameter part (anything after '?').
  10724    * The resulting string pointer in valid only until a response is provided.
  10725    * The result is placed in @a v_uri_string member.
  10726    * @ingroup request
  10727    */
  10728   MHD_REQUEST_INFO_DYNAMIC_URI = 2
  10729   ,
  10730   /**
  10731    * Get the number of URI parameters (the decoded part of the original
  10732    * URI string after '?'). Sometimes it is called "GET parameters".
  10733    * The result is placed in @a v_number_uri_params_sizet member.
  10734    * @ingroup request
  10735    */
  10736   MHD_REQUEST_INFO_DYNAMIC_NUMBER_URI_PARAMS = 3
  10737   ,
  10738   /**
  10739    * Get the number of cookies in the request.
  10740    * The result is placed in @a v_number_cookies_sizet member.
  10741    * If cookies parsing is disabled in MHD build then the function returns
  10742    * error code #MHD_SC_FEATURE_DISABLED.
  10743    * If cookies parsing is disabled this daemon then the function returns
  10744    * error code #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE.
  10745    * @ingroup request
  10746    */
  10747   MHD_REQUEST_INFO_DYNAMIC_NUMBER_COOKIES = 4
  10748   ,
  10749   /**
  10750    * Return length of the client's HTTP request header.
  10751    * This is a total raw size of the header (after TLS decipher if any)
  10752    * The result is placed in @a v_header_size_sizet member.
  10753    * @ingroup request
  10754    */
  10755   MHD_REQUEST_INFO_DYNAMIC_HEADER_SIZE = 5
  10756   ,
  10757   /**
  10758    * Get the number of decoded POST entries in the request.
  10759    * The result is placed in @a v_number_post_params_sizet member.
  10760    * @ingroup request
  10761    */
  10762   MHD_REQUEST_INFO_DYNAMIC_NUMBER_POST_PARAMS = 6
  10763   ,
  10764   /**
  10765    * Get whether the upload content is present in the request.
  10766    * The result is #MHD_YES if any upload content is present, even
  10767    * if the upload content size is zero.
  10768    * The result is placed in @a v_upload_present_bool member.
  10769    * @ingroup request
  10770    */
  10771   MHD_REQUEST_INFO_DYNAMIC_UPLOAD_PRESENT = 10
  10772   ,
  10773   /**
  10774    * Get whether the chunked upload content is present in the request.
  10775    * The result is #MHD_YES if chunked upload content is present.
  10776    * The result is placed in @a v_upload_chunked_bool member.
  10777    * @ingroup request
  10778    */
  10779   MHD_REQUEST_INFO_DYNAMIC_UPLOAD_CHUNKED = 11
  10780   ,
  10781   /**
  10782    * Get the total content upload size.
  10783    * Resulted in zero if no content upload or upload content size is zero,
  10784    * #MHD_SIZE_UNKNOWN if size is not known (chunked upload).
  10785    * The result is placed in @a v_upload_size_total_uint64 member.
  10786    * @ingroup request
  10787    */
  10788   MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_TOTAL = 12
  10789   ,
  10790   /**
  10791    * Get the total size of the content upload already received from the client.
  10792    * This is the total size received, could be not yet fully processed by the
  10793    * application.
  10794    * The result is placed in @a v_upload_size_recieved_uint64 member.
  10795    * @ingroup request
  10796    */
  10797   MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_RECIEVED = 13
  10798   ,
  10799   /**
  10800    * Get the total size of the content upload left to be received from
  10801    * the client.
  10802    * Resulted in #MHD_SIZE_UNKNOWN if total size is not known (chunked upload).
  10803    * The result is placed in @a v_upload_size_to_recieve_uint64 member.
  10804    * @ingroup request
  10805    */
  10806   MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_TO_RECIEVE = 14
  10807   ,
  10808   /**
  10809    * Get the total size of the content upload already processed (upload callback
  10810    * called and completed (if any)).
  10811    * If the value is requested from #MHD_UploadCallback, then result does NOT
  10812    * include the current data being processed by the callback.
  10813    * The result is placed in @a v_upload_size_processed_uint64 member.
  10814    * @ingroup request
  10815    */
  10816   MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_PROCESSED = 15
  10817   ,
  10818   /**
  10819    * Get the total size of the content upload left to be processed.
  10820    * The resulting value includes the size of the data not yet received from
  10821    * the client.
  10822    * If the value is requested from #MHD_UploadCallback, then result includes
  10823    * the current data being processed by the callback.
  10824    * Resulted in #MHD_SIZE_UNKNOWN if total size is not known (chunked upload).
  10825    * The result is placed in @a v_upload_size_to_process_uint64 member.
  10826    * @ingroup request
  10827    */
  10828   MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_TO_PROCESS = 16
  10829   ,
  10830   /**
  10831    * Returns pointer to information about digest auth in client request.
  10832    * The resulting pointer is NULL if no digest auth header is set by
  10833    * the client or the format of the digest auth header is broken.
  10834    * Pointers in the returned structure (if any) are valid until response
  10835    * is provided for the request.
  10836    * The result is placed in @a v_auth_digest_info member.
  10837    */
  10838   MHD_REQUEST_INFO_DYNAMIC_AUTH_DIGEST_INFO = 42
  10839   ,
  10840   /**
  10841    * Returns information about Basic Authentication credentials in the request.
  10842    * Pointers in the returned structure (if any) are valid until any MHD_Action
  10843    * or MHD_UploadAction is provided. If the data is needed beyond this point,
  10844    * it should be copied.
  10845    * If #MHD_request_get_info_dynamic_sz() returns #MHD_SC_OK then
  10846    * @a v_auth_basic_creds is NOT NULL and at least the username data
  10847    * is provided.
  10848    * The result is placed in @a v_auth_basic_creds member.
  10849    */
  10850   MHD_REQUEST_INFO_DYNAMIC_AUTH_BASIC_CREDS = 51
  10851   ,
  10852   /* * Sentinel * */
  10853   /**
  10854    * The sentinel value.
  10855    * This value enforces specific underlying integer type for the enum.
  10856    * Do not use.
  10857    */
  10858   MHD_REQUEST_INFO_DYNAMIC_SENTINEL = 65535
  10859 };
  10860 
  10861 
  10862 /**
  10863  * Dynamic information about a request.
  10864  */
  10865 union MHD_RequestInfoDynamicData
  10866 {
  10867 
  10868   /**
  10869    * The data for the #MHD_REQUEST_INFO_DYNAMIC_HTTP_METHOD_STRING query
  10870    */
  10871   struct MHD_String v_http_method_string;
  10872 
  10873   /**
  10874    * The data for the #MHD_REQUEST_INFO_DYNAMIC_URI query
  10875    */
  10876   struct MHD_String v_uri_string;
  10877 
  10878   /**
  10879    * The data for the #MHD_REQUEST_INFO_DYNAMIC_NUMBER_URI_PARAMS query
  10880    */
  10881   size_t v_number_uri_params_sizet;
  10882 
  10883   /**
  10884    * The data for the #MHD_REQUEST_INFO_DYNAMIC_NUMBER_COOKIES query
  10885    */
  10886   size_t v_number_cookies_sizet;
  10887 
  10888   /**
  10889    * The data for the #MHD_REQUEST_INFO_DYNAMIC_HEADER_SIZE query
  10890    */
  10891   size_t v_header_size_sizet;
  10892 
  10893   /**
  10894    * The data for the #MHD_REQUEST_INFO_DYNAMIC_NUMBER_POST_PARAMS query
  10895    */
  10896   size_t v_number_post_params_sizet;
  10897 
  10898   /**
  10899    * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_PRESENT query
  10900    */
  10901   enum MHD_Bool v_upload_present_bool;
  10902 
  10903   /**
  10904    * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_CHUNKED query
  10905    */
  10906   enum MHD_Bool v_upload_chunked_bool;
  10907 
  10908   /**
  10909    * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_TOTAL query
  10910    */
  10911   uint_fast64_t v_upload_size_total_uint64;
  10912 
  10913   /**
  10914    * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_RECIEVED query
  10915    */
  10916   uint_fast64_t v_upload_size_recieved_uint64;
  10917 
  10918   /**
  10919    * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_TO_RECIEVE query
  10920    */
  10921   uint_fast64_t v_upload_size_to_recieve_uint64;
  10922 
  10923   /**
  10924    * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_PROCESSED query
  10925    */
  10926   uint_fast64_t v_upload_size_processed_uint64;
  10927 
  10928   /**
  10929    * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_TO_PROCESS query
  10930    */
  10931   uint_fast64_t v_upload_size_to_process_uint64;
  10932 
  10933   /**
  10934    * The data for the #MHD_REQUEST_INFO_DYNAMIC_AUTH_DIGEST_INFO query
  10935    */
  10936   const struct MHD_AuthDigestInfo *v_auth_digest_info;
  10937 
  10938   /**
  10939    * The data for the #MHD_REQUEST_INFO_DYNAMIC_AUTH_BASIC_CREDS query
  10940    */
  10941   const struct MHD_AuthBasicCreds *v_auth_basic_creds;
  10942 };
  10943 
  10944 
  10945 /**
  10946  * Obtain dynamic information about the given request.
  10947  * This information may be changed during the lifetime of the request.
  10948  * Most of the data provided is available only when the request line or complete
  10949  * request headers are processed and not available if responding has been
  10950  * started.
  10951  *
  10952  * The wrapper macro #MHD_request_get_info_dynamic() may be more convenient.
  10953  *
  10954  * Any pointers in the returned data are valid until any MHD_Action or
  10955  * MHD_UploadAction is provided. If the data is needed beyond this point,
  10956  * it should be copied.
  10957  *
  10958  * @param request the request to get information about
  10959  * @param info_type the type of information requested
  10960  * @param[out] output_buf the pointer to union to be set to the requested
  10961  *                        information
  10962  * @param output_buf_size the size of the memory area pointed by @a output_buf
  10963  *                        (provided by the caller for storing the requested
  10964  *                        information), in bytes
  10965  * @return #MHD_SC_OK if succeed,
  10966  *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if requested information type is
  10967  *                                       not recognized by MHD,
  10968  *         #MHD_SC_TOO_LATE if request is already being closed or the response
  10969  *                          is being sent
  10970  *         #MHD_SC_TOO_EARLY if requested data is not yet ready (for example,
  10971  *                           headers are not yet received),
  10972  *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information is
  10973  *                                              not available for this request
  10974  *                                              due to used configuration/mode,
  10975  *         #MHD_SC_FEATURE_DISABLED if requested functionality is not supported
  10976  *                                  by this MHD build,
  10977  *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
  10978  *         #MHD_SC_AUTH_ABSENT if request does not have particular Auth data,
  10979  *         #MHD_SC_CONNECTION_POOL_NO_MEM_AUTH_DATA if connection memory pool
  10980  *                                                  has no space to put decoded
  10981  *                                                  authentication data,
  10982  *         #MHD_SC_REQ_AUTH_DATA_BROKEN if the format of authentication data is
  10983  *                                      incorrect or broken,
  10984  *         other error codes in case of other errors
  10985  * @ingroup specialized
  10986  */
  10987 MHD_EXTERN_ enum MHD_StatusCode
  10988 MHD_request_get_info_dynamic_sz (
  10989   struct MHD_Request *MHD_RESTRICT request,
  10990   enum MHD_RequestInfoDynamicType info_type,
  10991   union MHD_RequestInfoDynamicData *MHD_RESTRICT output_buf,
  10992   size_t output_buf_size)
  10993 MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1)
  10994 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3);
  10995 
  10996 
  10997 /**
  10998  * Obtain dynamic information about the given request.
  10999  * This information may be changed during the lifetime of the request.
  11000  * Most of the data provided is available only when the request line or complete
  11001  * request headers are processed and not available if responding has been
  11002  * started.
  11003  *
  11004  * Any pointers in the returned data are valid until any MHD_Action or
  11005  * MHD_UploadAction is provided. If the data is needed beyond this point,
  11006  * it should be copied.
  11007  *
  11008  * @param request the request to get information about
  11009  * @param info_type the type of information requested
  11010  * @param[out] output_buf the pointer to union to be set to the requested
  11011  *                        information
  11012  * @return #MHD_SC_OK if succeed,
  11013  *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if requested information type is
  11014  *                                       not recognized by MHD,
  11015  *         #MHD_SC_TOO_LATE if request is already being closed or the response
  11016  *                          is being sent
  11017  *         #MHD_SC_TOO_EARLY if requested data is not yet ready (for example,
  11018  *                           headers are not yet received),
  11019  *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information is
  11020  *                                              not available for this request
  11021  *                                              due to used configuration/mode,
  11022  *         #MHD_SC_FEATURE_DISABLED if requested functionality is not supported
  11023  *                                  by this MHD build,
  11024  *         #MHD_SC_AUTH_ABSENT if request does not have particular Auth data,
  11025  *         #MHD_SC_CONNECTION_POOL_NO_MEM_AUTH_DATA if connection memory pool
  11026  *                                                  has no space to put decoded
  11027  *                                                  authentication data,
  11028  *         #MHD_SC_REQ_AUTH_DATA_BROKEN if the format of authentication data is
  11029  *                                      incorrect or broken,
  11030  *         other error codes in case of other errors
  11031  * @ingroup specialized
  11032  */
  11033 #define MHD_request_get_info_dynamic(request, info_type, output_buf) \
  11034         MHD_request_get_info_dynamic_sz ((request), (info_type), \
  11035                                          (output_buf), \
  11036                                          sizeof(*(output_buf)))
  11037 
  11038 /**
  11039  * Callback for serious error condition. The default action is to print
  11040  * an error message and `abort()`.
  11041  * The callback should not return.
  11042  * Some parameters could be empty strings (the strings with zero-termination at
  11043  * zero position) if MHD built without log messages (only for embedded
  11044  * projects).
  11045  *
  11046  * @param cls user specified value
  11047  * @param file where the error occurred, could be empty
  11048  * @param func the name of the function, where the error occurred, may be empty
  11049  * @param line where the error occurred
  11050  * @param message the error details, could be empty
  11051  * @ingroup logging
  11052  */
  11053 typedef void
  11054 (*MHD_PanicCallback)(void *cls,
  11055                      const char *file,
  11056                      const char *func,
  11057                      unsigned int line,
  11058                      const char *message);
  11059 
  11060 
  11061 /**
  11062  * Sets the global error handler to a different implementation.
  11063  * The @a cb will only be called in the case of typically fatal, serious
  11064  * internal consistency issues.
  11065  * These issues should only arise in the case of serious memory corruption or
  11066  * similar problems with the architecture.
  11067  * The @a cb should not return.
  11068  *
  11069  * The default implementation that is used if no panic function is set
  11070  * simply prints an error message and calls `abort()`.  Alternative
  11071  * implementations might call `exit()` or other similar functions.
  11072  *
  11073  * @param cb new error handler, NULL to reset to default handler
  11074  * @param cls passed to @a cb
  11075  * @ingroup logging
  11076  */
  11077 MHD_EXTERN_ void
  11078 MHD_lib_set_panic_func (MHD_PanicCallback cb,
  11079                         void *cls);
  11080 
  11081 #define MHD_lib_set_panic_func_default() \
  11082         MHD_lib_set_panic_func (MHD_STATIC_CAST_ (MHD_PanicCallback,NULL),NULL)
  11083 MHD_C_DECLARATIONS_FINISH_HERE_
  11084 
  11085 #endif /* ! MICROHTTPD2_H */