libmicrohttpd2

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

microhttpd2.h (396250B)


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