libmicrohttpd2

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

microhttpd2.h (395387B)


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