libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

libmicrohttpd.texi (179350B)


      1 \input texinfo
      2 @setfilename libmicrohttpd.info
      3 @documentencoding UTF-8
      4 @include version.texi
      5 @settitle The GNU libmicrohttpd Reference Manual
      6 @c Unify all the indices into concept index.
      7 @syncodeindex vr cp
      8 @syncodeindex ky cp
      9 @syncodeindex pg cp
     10 @copying
     11 This manual is for GNU libmicrohttpd
     12 (version @value{VERSION}, @value{UPDATED}), a library for embedding
     13 an HTTP(S) server into C applications.
     14 
     15 Copyright @copyright{} 2007--2019 Christian Grothoff
     16 
     17 @quotation
     18 Permission is granted to copy, distribute and/or modify this document
     19 under the terms of the GNU Free Documentation License, Version 1.3
     20 or any later version published by the Free Software Foundation;
     21 with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
     22 Texts.  A copy of the license is included in the section entitled "GNU
     23 Free Documentation License".
     24 @end quotation
     25 @end copying
     26 
     27 @dircategory Software libraries
     28 @direntry
     29 * libmicrohttpd: (libmicrohttpd).       Embedded HTTP server library.
     30 @end direntry
     31 
     32 @c
     33 @c Titlepage
     34 @c
     35 @titlepage
     36 @title The GNU libmicrohttpd Reference Manual
     37 @subtitle Version @value{VERSION}
     38 @subtitle @value{UPDATED}
     39 @author Marco Maggi (@email{marco.maggi-ipsu@@poste.it})
     40 @author Christian Grothoff (@email{christian@@grothoff.org})
     41 @page
     42 @vskip 0pt plus 1filll
     43 @insertcopying
     44 @end titlepage
     45 
     46 @summarycontents
     47 @contents
     48 
     49 @c ------------------------------------------------------------
     50 @ifnottex
     51 @node Top
     52 @top The GNU libmicrohttpd Library
     53 @insertcopying
     54 @end ifnottex
     55 
     56 @menu
     57 * microhttpd-intro::            Introduction.
     58 * microhttpd-const::            Constants.
     59 * microhttpd-struct::           Structures type definition.
     60 * microhttpd-cb::               Callback functions definition.
     61 * microhttpd-init::             Starting and stopping the server.
     62 * microhttpd-inspect::          Implementing external @code{select}.
     63 * microhttpd-requests::         Handling requests.
     64 * microhttpd-responses::        Building responses to requests.
     65 * microhttpd-flow::             Flow control.
     66 * microhttpd-dauth::            Utilizing Authentication.
     67 * microhttpd-post::             Adding a @code{POST} processor.
     68 * microhttpd-info::             Obtaining and modifying status information.
     69 * microhttpd-util::             Utilities.
     70 * microhttpd-websocket::        Websockets.
     71 
     72 Appendices
     73 
     74 * GNU-LGPL::                    The GNU Lesser General Public License says how you
     75                                  can copy and share almost all of `libmicrohttpd'.
     76 * eCos License::                The eCos License says how you can copy and share some parts of `libmicrohttpd'.
     77 * GNU-GPL::                     The GNU General Public License (with eCos extension) says how you can copy and share some parts of `libmicrohttpd'.
     78 * GNU-FDL::                     The GNU Free Documentation License says how you
     79                                 can copy and share the documentation of `libmicrohttpd'.
     80 
     81 Indices
     82 
     83 * Concept Index::               Index of concepts and programs.
     84 * Function and Data Index::     Index of functions, variables and data types.
     85 * Type Index::                  Index of data types.
     86 @end menu
     87 
     88 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     89 
     90 @c ------------------------------------------------------------
     91 @node microhttpd-intro
     92 @chapter Introduction
     93 
     94 
     95 @noindent
     96 All symbols defined in the public API start with @code{MHD_}.  MHD
     97 is a small HTTP daemon library.  As such, it does not have any API
     98 for logging errors (you can only enable or disable logging to stderr).
     99 Also, it may not support all of the HTTP features directly, where
    100 applicable, portions of HTTP may have to be handled by clients of the
    101 library.
    102 
    103 The library is supposed to handle everything that it must handle
    104 (because the API would not allow clients to do this), such as basic
    105 connection management. However, detailed interpretations of headers,
    106 such as range requests, are left to the main application.  In
    107 particular, if an application developer wants to support range
    108 requests, he needs to explicitly indicate support in responses and
    109 also explicitly parse the range header and generate a response (for
    110 example, using the @code{MHD_create_response_from_fd_at_offset} call
    111 to serve ranges from a file).  MHD does understands headers that
    112 control connection management (specifically, @code{Connection: close}
    113 and @code{Expect: 100 continue} are understood and handled
    114 automatically).  @code{Connection: upgrade} is supported by passing
    115 control over the socket (or something that behaves like the real
    116 socket in the case of TLS) to the application (after sending the
    117 desired HTTP response header).
    118 
    119 MHD largely ignores the semantics of the different HTTP methods,
    120 so clients are left to handle those.  One exception is that MHD does
    121 understand @code{HEAD} and will only send the headers of the response
    122 and not the body, even if the client supplied a body.  (In fact,
    123 clients do need to construct a response with the correct length, even
    124 for @code{HEAD} request.)
    125 
    126 MHD understands @code{POST} data and is able to decode certain
    127 formats (at the moment only @code{application/x-www-form-urlencoded}
    128 and @code{multipart/form-data}) using the post processor API.  The
    129 data stream of a POST is also provided directly to the main
    130 application, so unsupported encodings could still be processed, just
    131 not conveniently by MHD.
    132 
    133 The header file defines various constants used by the HTTP protocol.
    134 This does not mean that MHD actually interprets all of these values.
    135 The provided constants are exported as a convenience for users of the
    136 library.  MHD does not verify that transmitted HTTP headers are
    137 part of the standard specification; users of the library are free to
    138 define their own extensions of the HTTP standard and use those with
    139 MHD.
    140 
    141 All functions are guaranteed to be completely reentrant and
    142 thread-safe.  MHD checks for allocation failures and tries to
    143 recover gracefully (for example, by closing the connection).
    144 Additionally, clients can specify resource limits on the overall
    145 number of connections, number of connections per IP address and memory
    146 used per connection to avoid resource exhaustion.
    147 
    148 @section Scope
    149 
    150 MHD is currently used in a wide range of implementations.
    151 Examples based on reports we've received from developers include:
    152 @itemize
    153 @item Embedded HTTP server on a cortex M3 (128 KB code space)
    154 @item Large-scale multimedia server (reportedly serving at the
    155       simulator limit of 7.5 GB/s)
    156 @item Administrative console (via HTTP/HTTPS) for network appliances
    157 @c If you have other interesting examples, please let us know
    158 @end itemize
    159 
    160 @section Thread modes and event loops
    161 @cindex poll
    162 @cindex epoll
    163 @cindex select
    164 
    165 MHD supports four basic thread modes and up to three event loop
    166 styles.
    167 
    168 The four basic thread modes are external sockets polling (MHD creates
    169 no threads, event loop is fully managed by the application), internal
    170 polling (MHD creates one thread for all connections), polling in
    171 thread pool (MHD creates a thread pool which is used to process all
    172 connections) and thread-per-connection (MHD creates one thread for
    173 listen sockets and then one thread per accepted connection).
    174 
    175 These thread modes are then combined with the evet loop styles
    176 (polling function type).  MHD support select, poll and epoll. select
    177 is available on all platforms, epoll and poll may not be available on
    178 some platforms.  Note that it is possible to combine MHD using epoll
    179 with an external select-based event loop.
    180 
    181 The default (if no other option is passed) is ``external select''.
    182 The highest performance can typically be obtained with a thread pool
    183 using @code{epoll}.  Apache Benchmark (ab) was used to compare the
    184 performance of @code{select} and @code{epoll} when using a thread pool
    185 and a large number of connections. @ref{fig:performance} shows the
    186 resulting plot from the @code{benchmark.c} example, which measures the
    187 latency between an incoming request and the completion of the
    188 transmission of the response.  In this setting, the @code{epoll}
    189 thread pool with four threads was able to handle more than 45,000
    190 connections per second on loopback (with Apache Benchmark running
    191 three processes on the same machine).
    192 @cindex performance
    193 
    194 
    195 @float Figure,fig:performance
    196 @image{libmicrohttpd_performance_data,400pt,300pt,Data,.png}
    197 @caption{Performance measurements for select vs. epoll (with thread-pool).}
    198 @end float
    199 
    200 
    201 Not all combinations of thread modes and event loop styles are
    202 supported.  This is partially to keep the API simple, and partially
    203 because some combinations simply make no sense as others are strictly
    204 superior.  Note that the choice of style depends first of all on the
    205 application logic, and then on the performance requirements.
    206 Applications that perform a blocking operation while handling a
    207 request within the callbacks from MHD must use a thread per
    208 connection.  This is typically rather costly.  Applications that do
    209 not support threads or that must run on embedded devices without
    210 thread-support must use the external mode.  Using @code{epoll} is only
    211 supported on some platform, thus portable applications must at least
    212 have a fallback option available.  @ref{tbl:supported} lists the sane
    213 combinations.
    214 
    215 @float Table,tbl:supported
    216 @multitable {@b{thread-per-connection}} {@b{select}} {@b{poll}} {@b{epoll}}
    217 @item                           @tab @b{select} @tab @b{poll} @tab @b{epoll}
    218 @item @b{external}              @tab  yes       @tab no       @tab yes
    219 @item @b{internal}              @tab  yes       @tab yes      @tab yes
    220 @item @b{thread pool}           @tab  yes       @tab yes      @tab yes
    221 @item @b{thread-per-connection} @tab  yes       @tab yes      @tab no
    222 @end multitable
    223 @caption{Supported combinations of event styles and thread modes.}
    224 @end float
    225 
    226 
    227 @section Compiling GNU libmicrohttpd
    228 @cindex compilation
    229 @cindex embedded systems
    230 @cindex portability
    231 
    232 MHD uses the standard GNU system where the usual build process
    233 involves running
    234 @verbatim
    235 $ ./configure
    236 $ make
    237 $ make install
    238 @end verbatim
    239 
    240 MHD supports various options to be given to configure to tailor the
    241 binary to a specific situation.  Note that some of these options will
    242 remove portions of the MHD code that are required for
    243 binary-compatibility.  They should only be used on embedded systems
    244 with tight resource constraints and no concerns about library
    245 versioning.  Standard distributions including MHD are expected to
    246 always ship with all features enabled, otherwise unexpected
    247 incompatibilities can arise!
    248 
    249 Here is a list of MHD-specific options that can be given to configure
    250 (canonical configure options such as ``--prefix'' are also supported, for a
    251 full list of options run ``./configure --help''):
    252 
    253 @table @code
    254 @item ``--disable-curl''
    255 disable running testcases using libcurl
    256 
    257 @item ``--disable-largefile''
    258 disable support for 64-bit files
    259 
    260 @item ``--disable-messages''
    261 disable logging of error messages (smaller binary size, not so much fun for debugging)
    262 
    263 @item ``--disable-https''
    264 disable HTTPS support, even if GNUtls is found; this option must be used if eCOS license is desired as an option (in all cases the resulting binary falls under a GNU LGPL-only license)
    265 
    266 @item ``--disable-postprocessor''
    267 do not include the post processor API (results in binary incompatibility)
    268 
    269 @item ``--disable-dauth''
    270 do not include the authentication APIs (results in binary incompatibility)
    271 
    272 @item ``--disable-httpupgrade''
    273 do not build code for HTTP ``Upgrade'' (smaller binary size, binary incompatible library)
    274 
    275 @item ``--disable-epoll''
    276 do not include epoll support, even if it supported (minimally smaller binary size, good for portability testing)
    277 
    278 @item ``--enable-coverage''
    279 set flags for analysis of code-coverage with gcc/gcov (results in slow, large binaries)
    280 
    281 @item ``--with-threads=posix,w32,none,auto''
    282 sets threading library to use. With use ``none'' to not support threads. In this case, MHD will only support the ``external'' threading modes and not perform any locking of data structures! Use @code{MHD_is_feature_supported(MHD_FEATURE_THREADS)} to test if threads are available. Default is ``auto''.
    283 
    284 @item ``--with-gcrypt=PATH''
    285 specifies path to libgcrypt installation
    286 
    287 @item ``--with-gnutls=PATH''
    288 specifies path to libgnutls installation
    289 
    290 @end table
    291 
    292 To cross-compile MHD for Android, install the Android NDK and use:
    293 @verbatim
    294 ./configure --target=arm-linux-androideabi --host=arm-linux-androideabi --disable-doc --disable-examples
    295 make
    296 @end verbatim
    297 
    298 Similar build commands should work for cross-compilation to other platforms.
    299 Note that you may have to first cross-compile GnuTLS to get MHD with TLS support.
    300 
    301 
    302 @section Validity of pointers
    303 
    304 MHD will give applications access to its internal data structures
    305 via pointers via arguments and return values from its API.  This
    306 creates the question as to how long those pointers are assured to
    307 stay valid.
    308 
    309 Most MHD data structures are associated with the connection of an
    310 HTTP client.  Thus, pointers associated with a connection are
    311 typically valid until the connection is finished, at which point
    312 MHD will call the @code{MHD_RequestCompletedCallback} if one is
    313 registered.  Applications that have such a callback registered
    314 may assume that keys and values from the
    315 @code{MHD_KeyValueIterator}, return values from
    316 @code{MHD_lookup_connection_value} and the @code{url},
    317 @code{method} and @code{version} arguments to the
    318 @code{MHD_AccessHandlerCallback} will remain valid until the
    319 respective @code{MHD_RequestCompletedCallback} is invoked.
    320 
    321 In contrast, the @code{upload_data} argument of
    322 @code{MHD_RequestCompletedCallback} as well as all pointers
    323 from the @code{MHD_PostDataIterator} are only valid for the
    324 duration of the callback.
    325 
    326 Pointers returned from @code{MHD_get_response_header} are
    327 valid as long as the response itself is valid.
    328 
    329 
    330 @section Including the microhttpd.h header
    331 @cindex portability
    332 @cindex microhttpd.h
    333 
    334 Ideally, before including "microhttpd.h" you should add the necessary
    335 includes to define the @code{va_list}, @code{size_t}, @code{ssize_t},
    336 @code{intptr_t}, @code{off_t}, @code{uint8_t}, @code{uint16_t},
    337 @code{int32_t}, @code{uint32_t}, @code{int64_t}, @code{uint64_t},
    338 @code{fd_set}, @code{socklen_t} and @code{struct sockaddr} data types.
    339 Which specific headers are needed may depend on your platform and your
    340 build system might include some tests to provide you with the
    341 necessary conditional operations.  For possible suggestions consult
    342 @code{platform.h} and @code{configure.ac} in the MHD distribution.
    343 
    344 Once you have ensured that you manually (!) included the right headers
    345 for your platform before "microhttpd.h", you should also add a line
    346 with @code{#define MHD_PLATFORM_H} which will prevent the
    347 "microhttpd.h" header from trying (and, depending on your platform,
    348 failing) to include the right headers.
    349 
    350 If you do not define MHD_PLATFORM_H, the "microhttpd.h" header will
    351 automatically include headers needed on GNU/Linux systems (possibly
    352 causing problems when porting to other platforms).
    353 
    354 @section SIGPIPE
    355 @cindex signals
    356 MHD does not install a signal handler for SIGPIPE.  On platforms where
    357 this is possible (such as GNU/Linux), it disables SIGPIPE for its I/O
    358 operations (by passing MSG_NOSIGNAL or similar).  On other platforms,
    359 SIGPIPE signals may be generated from network operations by MHD and
    360 will cause the process to die unless the developer explicitly installs
    361 a signal handler for SIGPIPE.
    362 
    363 Hence portable code using MHD must install a SIGPIPE handler or
    364 explicitly block the SIGPIPE signal.  MHD does not do so in order to
    365 avoid messing with other parts of the application that may need to
    366 handle SIGPIPE in a particular way.  You can make your application
    367 handle SIGPIPE by calling the following function in @code{main}:
    368 
    369 @verbatim
    370 static void
    371 catcher (int sig)
    372 {
    373 }
    374 
    375 static void
    376 ignore_sigpipe ()
    377 {
    378   struct sigaction oldsig;
    379   struct sigaction sig;
    380 
    381   sig.sa_handler = &catcher;
    382   sigemptyset (&sig.sa_mask);
    383 #ifdef SA_INTERRUPT
    384   sig.sa_flags = SA_INTERRUPT;  /* SunOS */
    385 #else
    386   sig.sa_flags = SA_RESTART;
    387 #endif
    388   if (0 != sigaction (SIGPIPE, &sig, &oldsig))
    389     fprintf (stderr,
    390              "Failed to install SIGPIPE handler: %s\n", strerror (errno));
    391 }
    392 @end verbatim
    393 
    394 @section MHD_UNSIGNED_LONG_LONG
    395 @cindex long long
    396 @cindex MHD_LONG_LONG
    397 @cindex IAR
    398 @cindex ARM
    399 @cindex cortex m3
    400 @cindex embedded systems
    401 
    402 Some platforms do not support @code{long long}.  Hence MHD defines a
    403 macro @code{MHD_UNSIGNED LONG_LONG} which will default to
    404 @code{unsigned long long}.  For standard desktop operating systems,
    405 this is all you need to know.
    406 
    407 However, if your platform does not support @code{unsigned long long},
    408 you should change "platform.h" to define @code{MHD_LONG_LONG} and
    409 @code{MHD_UNSIGNED_LONG_LONG} to an appropriate alternative type and
    410 also define @code{MHD_LONG_LONG_PRINTF} and
    411 @code{MHD_UNSIGNED_LONG_LONG_PRINTF} to the corresponding format
    412 string for printing such a data type.  Note that the ``signed''
    413 versions are deprecated.  Also, for historical reasons,
    414 @code{MHD_LONG_LONG_PRINTF} is without the percent sign, whereas
    415 @code{MHD_UNSIGNED_LONG_LONG_PRINTF} is with the percent sign.  Newly
    416 written code should only use the unsigned versions.  However, you need
    417 to define both in "platform.h" if you need to change the definition
    418 for the specific platform.
    419 
    420 
    421 @section Portability to W32
    422 
    423 libmicrohttpd in general ported well to W32. Most libmicrohttpd features
    424 are supported. W32 do not support some functions, like epoll and
    425 corresponding MHD features are not available on W32.
    426 
    427 
    428 @section Portability to z/OS
    429 
    430 To compile MHD on z/OS, extract the archive and run
    431 
    432 @verbatim
    433 iconv -f UTF-8 -t IBM-1047 contrib/ascebc > /tmp/ascebc.sh
    434 chmod +x /tmp/ascebc.sh
    435 for n in `find * -type f`
    436 do
    437   /tmp/ascebc.sh $n
    438 done
    439 @end verbatim
    440 to convert all source files to EBCDIC.  Note that you must run
    441 @code{configure} from the directory where the configure script is
    442 located.   Otherwise, configure will fail to find the
    443 @code{contrib/xcc} script (which is a wrapper around the z/OS c89
    444 compiler).
    445 
    446 
    447 
    448 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    449 
    450 @c ------------------------------------------------------------
    451 @node microhttpd-const
    452 @chapter Constants
    453 
    454 
    455 @deftp {Enumeration} MHD_FLAG
    456 Options for the MHD daemon.
    457 
    458 Note that MHD will run automatically in background thread(s) only if
    459 @code{MHD_USE_INTERNAL_POLLING_THREAD} is used. Otherwise caller
    460 (application) must use @code{MHD_run} or @code{MHD_run_from_select} to
    461 have MHD processed network connections and data.
    462 
    463 Starting the daemon may also fail if a particular option is not
    464 implemented or not supported on the target platform (i.e. no support
    465 for @acronym{TLS}, threads or IPv6). TLS support generally depends on
    466 options given during MHD compilation.
    467 
    468 @table @code
    469 @item MHD_NO_FLAG
    470 No options selected.
    471 
    472 @item MHD_USE_ERROR_LOG
    473 If this flag is used, the library should print error messages and
    474 warnings to stderr (or to custom error printer if it's specified by
    475 options).  Note that for this run-time option to have any effect, MHD
    476 needs to be compiled with messages enabled. This is done by default
    477 except you ran configure with the @code{--disable-messages} flag set.
    478 
    479 @item MHD_USE_DEBUG
    480 @cindex debugging
    481 Currently the same as @code{MHD_USE_ERROR_LOG}.
    482 
    483 @item MHD_USE_TLS
    484 @cindex TLS
    485 @cindex SSL
    486 Run in HTTPS-mode.  If you specify @code{MHD_USE_TLS} and MHD was
    487 compiled without SSL support, @code{MHD_start_daemon} will return
    488 NULL.
    489 
    490 @item MHD_USE_THREAD_PER_CONNECTION
    491 Run using one thread per connection.
    492 
    493 @item MHD_USE_INTERNAL_POLLING_THREAD
    494 Run using an internal thread doing @code{SELECT}.
    495 
    496 @item MHD_USE_IPv6
    497 @cindex IPv6
    498 Run using the IPv6 protocol (otherwise, MHD will just support IPv4).
    499 If you specify @code{MHD_USE_IPV6} and the local platform does not
    500 support it, @code{MHD_start_daemon} will return NULL.
    501 
    502 If you want MHD to support IPv4 and IPv6 using a single socket, pass
    503 MHD_USE_DUAL_STACK, otherwise, if you only pass this option, MHD will
    504 try to bind to IPv6-only (resulting in no IPv4 support).
    505 
    506 @item MHD_USE_DUAL_STACK
    507 @cindex IPv6
    508 Use a single socket for IPv4 and IPv6.  Note that this will mean
    509 that IPv4 addresses are returned by MHD in the IPv6-mapped format
    510 (the 'struct sockaddr_in6' format will be used for IPv4 and IPv6).
    511 
    512 @item MHD_USE_PEDANTIC_CHECKS
    513 @cindex deprecated
    514 Deprecated (use @code{MHD_OPTION_STRICT_FOR_CLIENT}).
    515 Be pedantic about the protocol.
    516 Specifically, at the moment, this flag causes MHD to reject HTTP
    517 1.1 connections without a @code{Host} header.  This is required by the
    518 standard, but of course in violation of the ``be as liberal as possible
    519 in what you accept'' norm.  It is recommended to turn this @strong{ON}
    520 if you are testing clients against MHD, and @strong{OFF} in
    521 production.
    522 
    523 @item MHD_USE_POLL
    524 @cindex FD_SETSIZE
    525 @cindex poll
    526 @cindex select
    527 Use @code{poll()} instead of @code{select()}. This allows sockets with
    528 descriptors @code{>= FD_SETSIZE}.  This option currently only works in
    529 conjunction with @code{MHD_USE_INTERNAL_POLLING_THREAD} (at this point).
    530 If you specify @code{MHD_USE_POLL} and the local platform does not
    531 support it, @code{MHD_start_daemon} will return NULL.
    532 
    533 @item MHD_USE_EPOLL
    534 @cindex FD_SETSIZE
    535 @cindex epoll
    536 @cindex select
    537 Use @code{epoll()} instead of @code{poll()} or @code{select()}. This
    538 allows sockets with descriptors @code{>= FD_SETSIZE}.  This option is
    539 only available on some systems and does not work in conjunction with
    540 @code{MHD_USE_THREAD_PER_CONNECTION} (at this point).  If you specify
    541 @code{MHD_USE_EPOLL} and the local platform does not support it,
    542 @code{MHD_start_daemon} will return NULL.  Using @code{epoll()}
    543 instead of @code{select()} or @code{poll()} can in some situations
    544 result in significantly higher performance as the system call has
    545 fundamentally lower complexity (O(1) for @code{epoll()} vs. O(n) for
    546 @code{select()}/@code{poll()} where n is the number of open
    547 connections).
    548 
    549 @item MHD_USE_TURBO
    550 @cindex performance
    551 Enable optimizations to aggressively improve performance.
    552 
    553 Currently, the optimizations this option enables are based on
    554 opportunistic reads and writes.  Basically, MHD will simply try to
    555 read or write or accept on a socket before checking that the socket is
    556 ready for IO using the event loop mechanism.  As the sockets are
    557 non-blocking, this may fail (at a loss of performance), but generally
    558 MHD does this in situations where the operation is likely to succeed,
    559 in which case performance is improved.  Setting the flag should generally
    560 be safe (even though the code is slightly more experimental).  You may
    561 want to benchmark your application to see if this makes any difference
    562 for you.
    563 
    564 
    565 @item MHD_USE_SUPPRESS_DATE_NO_CLOCK
    566 @cindex date
    567 @cindex clock
    568 @cindex embedded systems
    569 Suppress (automatically) adding the 'Date:' header to HTTP responses.
    570 This option should ONLY be used on systems that do not have a clock
    571 and that DO provide other mechanisms for cache control.  See also
    572 RFC 2616, section 14.18 (exception 3).
    573 
    574 
    575 @item MHD_USE_NO_LISTEN_SOCKET
    576 @cindex listen
    577 @cindex proxy
    578 @cindex embedded systems
    579 Run the HTTP server without any listen socket.  This option only makes
    580 sense if @code{MHD_add_connection} is going to be used exclusively to
    581 connect HTTP clients to the HTTP server.  This option is incompatible
    582 with using a thread pool; if it is used,
    583 @code{MHD_OPTION_THREAD_POOL_SIZE} is ignored.
    584 
    585 
    586 @item MHD_USE_ITC
    587 @cindex quiesce
    588 Force MHD to use a signal inter-thread communication channel to notify
    589 the event loop (of threads) of our shutdown and other events.  This is
    590 required if an application uses @code{MHD_USE_INTERNAL_POLLING_THREAD}
    591 and then performs @code{MHD_quiesce_daemon} (which eliminates our
    592 ability to signal termination via the listen socket).  In these modes,
    593 @code{MHD_quiesce_daemon} will fail if this option was not set.  Also,
    594 use of this option is automatic (as in, you do not even have to
    595 specify it), if @code{MHD_USE_NO_LISTEN_SOCKET} is specified.  In
    596 "external" select mode, this option is always simply ignored.
    597 
    598 Using this option also guarantees that MHD will not call
    599 @code{shutdown()} on the listen socket, which means a parent
    600 process can continue to use the socket.
    601 
    602 @item MHD_ALLOW_SUSPEND_RESUME
    603 Enables using @code{MHD_suspend_connection} and
    604 @code{MHD_resume_connection}, as performing these calls requires some
    605 additional inter-thred communication channels to be created, and code
    606 not using these calls should not pay the cost.
    607 
    608 @item MHD_USE_TCP_FASTOPEN
    609 @cindex listen
    610 Enable TCP_FASTOPEN on the listen socket.  TCP_FASTOPEN is currently
    611 supported on Linux >= 3.6.  On other systems using this option with
    612 cause @code{MHD_start_daemon} to fail.
    613 
    614 
    615 @item MHD_ALLOW_UPGRADE
    616 @cindex upgrade
    617 This option must be set if you want to upgrade connections
    618 (via ``101 Switching Protocols'' responses).  This requires MHD to
    619 allocate additional resources, and hence we require this
    620 special flag so we only use the resources that are really needed.
    621 
    622 
    623 @item MHD_USE_AUTO
    624 Automatically select best event loop style (polling function)
    625 depending on requested mode by other MHD flags and functions available
    626 on platform.  If application doesn't have requirements for any
    627 specific polling function, it's recommended to use this flag.  This
    628 flag is very convenient for multiplatform applications.
    629 
    630 @item MHD_USE_POST_HANDSHAKE_AUTH_SUPPORT
    631 Tell the TLS library to support post handshake client authentication.
    632 Only useful in combination with @code{MHD_USE_TLS}.
    633 
    634 This option will only work if the underlying TLS library
    635 supports it (i.e. GnuTLS after 3.6.3). If the TLS library
    636 does not support it, MHD may ignore the option and proceed
    637 without supporting this features.
    638 
    639 @item MHD_USE_INSECURE_TLS_EARLY_DATA
    640 Tell the TLS library to support TLS v1.3 early data (0-RTT) with the
    641 resulting security drawbacks. Only enable this if you really know what
    642 you are doing. MHD currently does NOT enforce that this only affects
    643 GET requests! You have been warned.
    644 
    645 This option will only work if the underlying TLS library
    646 supports it (i.e. GnuTLS after 3.6.3). If the TLS library
    647 does not support it, MHD may ignore the option and proceed
    648 without supporting this features.
    649 
    650 @end table
    651 @end deftp
    652 
    653 
    654 @deftp {Enumeration} MHD_OPTION
    655 MHD options.  Passed in the varargs portion of
    656 @code{MHD_start_daemon()}.
    657 
    658 @table @code
    659 @item MHD_OPTION_END
    660 No more options / last option.  This is used to terminate the VARARGs
    661 list.
    662 
    663 @item MHD_OPTION_CONNECTION_MEMORY_LIMIT
    664 @cindex memory, limiting memory utilization
    665 Maximum memory size per connection (followed by a @code{size_t}).  The
    666 default is 32 kB (32*1024 bytes) as defined by the internal constant
    667 @code{MHD_POOL_SIZE_DEFAULT}.  Values above 128k are unlikely to
    668 result in much benefit, as half of the memory will be typically used
    669 for IO, and TCP buffers are unlikely to support window sizes above 64k
    670 on most systems.
    671 
    672 @item MHD_OPTION_CONNECTION_MEMORY_INCREMENT
    673 @cindex memory
    674 Increment to use for growing the read buffer (followed by a
    675 @code{size_t}).  The default is 1024 (bytes).  Increasing this value
    676 will make MHD use memory for reading more aggressively, which can
    677 reduce the number of @code{recvfrom} calls but may increase the number
    678 of @code{sendto} calls.  The given value must fit within
    679 MHD_OPTION_CONNECTION_MEMORY_LIMIT.
    680 
    681 @item MHD_OPTION_CONNECTION_LIMIT
    682 @cindex connection, limiting number of connections
    683 Maximum number of concurrent connections to accept (followed by an
    684 @code{unsigned int}).  The default is @code{FD_SETSIZE - 4} (the
    685 maximum number of file descriptors supported by @code{select} minus
    686 four for @code{stdin}, @code{stdout}, @code{stderr} and the server
    687 socket).  In other words, the default is as large as possible.
    688 
    689 If the connection limit is reached, MHD's behavior depends a bit on
    690 other options.  If @code{MHD_USE_ITC} was given, MHD
    691 will stop accepting connections on the listen socket.  This will cause
    692 the operating system to queue connections (up to the @code{listen()}
    693 limit) above the connection limit.  Those connections will be held
    694 until MHD is done processing at least one of the active connections.
    695 If @code{MHD_USE_ITC} is not set, then MHD will continue
    696 to @code{accept()} and immediately @code{close()} these connections.
    697 
    698 Note that if you set a low connection limit, you can easily get into
    699 trouble with browsers doing request pipelining.  For example, if your
    700 connection limit is ``1'', a browser may open a first connection to
    701 access your ``index.html'' file, keep it open but use a second
    702 connection to retrieve CSS files, images and the like.  In fact, modern
    703 browsers are typically by default configured for up to 15 parallel
    704 connections to a single server.  If this happens, MHD will refuse to
    705 even accept the second connection until the first connection is
    706 closed --- which does not happen until timeout.  As a result, the
    707 browser will fail to render the page and seem to hang.  If you expect
    708 your server to operate close to the connection limit, you should
    709 first consider using a lower timeout value and also possibly add
    710 a ``Connection: close'' header to your response to ensure that
    711 request pipelining is not used and connections are closed immediately
    712 after the request has completed:
    713 @example
    714 MHD_add_response_header (response,
    715                          MHD_HTTP_HEADER_CONNECTION,
    716                          "close");
    717 @end example
    718 
    719 @item MHD_OPTION_CONNECTION_TIMEOUT
    720 @cindex timeout
    721 After how many seconds of inactivity should a connection automatically
    722 be timed out? (followed by an @code{unsigned int}; use zero for no
    723 timeout).  The default is zero (no timeout).
    724 
    725 @item MHD_OPTION_NOTIFY_COMPLETED
    726 Register a function that should be called whenever a request has been
    727 completed (this can be used for application-specific clean up).
    728 Requests that have never been presented to the application (via
    729 @code{MHD_AccessHandlerCallback()}) will not result in
    730 notifications.
    731 
    732 This option should be followed by @strong{TWO} pointers.  First a
    733 pointer to a function of type @code{MHD_RequestCompletedCallback()}
    734 and second a pointer to a closure to pass to the request completed
    735 callback.  The second pointer maybe @code{NULL}.
    736 
    737 @item MHD_OPTION_NOTIFY_CONNECTION
    738 Register a function that should be called when the TCP connection to a
    739 client is opened or closed. The registered callback is called twice per
    740 TCP connection, with @code{MHD_CONNECTION_NOTIFY_STARTED} and
    741 @code{MHD_CONNECTION_NOTIFY_CLOSED} respectively. An additional
    742 argument can be used to store TCP connection specific information,
    743 which can be retrieved using @code{MHD_CONNECTION_INFO_SOCKET_CONTEXT}
    744 during the lifetime of the TCP connection. 
    745 Note @code{MHD_OPTION_NOTIFY_COMPLETED} and the @code{req_cls} argument
    746 to the @code{MHD_AccessHandlerCallback} are per HTTP request (and there
    747 can be multiple HTTP requests per TCP connection). 
    748 
    749 This option should be followed by @strong{TWO} pointers.  First a
    750 pointer to a function of type @code{MHD_NotifyConnectionCallback()}
    751 and second a pointer to a closure to pass to the request completed
    752 callback.  The second pointer maybe @code{NULL}.
    753 
    754 @item MHD_OPTION_PER_IP_CONNECTION_LIMIT
    755 Limit on the number of (concurrent) connections made to the
    756 server from the same IP address.  Can be used to prevent one
    757 IP from taking over all of the allowed connections.  If the
    758 same IP tries to establish more than the specified number of
    759 connections, they will be immediately rejected.  The option
    760 should be followed by an @code{unsigned int}.  The default is
    761 zero, which means no limit on the number of connections
    762 from the same IP address.
    763 
    764 @item MHD_OPTION_LISTEN_BACKLOG_SIZE
    765 Set the size of the @code{listen()} back log queue of the TCP socket.
    766 Takes an @code{unsigned int} as the argument.  Default is the
    767 platform-specific value of @code{SOMAXCONN}.
    768 
    769 @item MHD_OPTION_STRICT_FOR_CLIENT
    770 Specify how strict we should enforce the HTTP protocol.
    771 Takes an @code{int} as the argument.  Default is zero.
    772 
    773 If set to 1, MHD will be strict about the protocol.  Specifically, at
    774 the moment, this flag uses MHD to reject HTTP 1.1 connections without
    775 a "Host" header.  This is required by the standard, but of course in
    776 violation of the "be as liberal as possible in what you accept" norm.
    777 It is recommended to set this to 1 if you are testing clients against
    778 MHD, and 0 in production.
    779 
    780 If set to -1 MHD will be permissive about the protocol, allowing
    781 slight deviations that are technically not allowed by the
    782 RFC. Specifically, at the moment, this flag causes MHD to allow spaces
    783 in header field names. This is disallowed by the standard.
    784 
    785 It is not recommended to set it to -1 on publicly available servers as
    786 it may potentially lower level of protection.
    787 
    788 @item MHD_OPTION_SERVER_INSANITY
    789 @cindex testing
    790 Allows the application to disable certain sanity precautions in MHD. With
    791 these, the client can break the HTTP protocol, so this should never be used in
    792 production. The options are, however, useful for testing HTTP clients against
    793 "broken" server implementations.  This argument must be followed by an
    794 @code{unsigned int}, corresponding to an @code{enum MHD_DisableSanityCheck}.
    795 
    796 Right now, no sanity checks can be disabled.
    797 
    798 @item MHD_OPTION_SOCK_ADDR
    799 @cindex bind, restricting bind
    800 Bind daemon to the supplied socket address. This option should be followed by a
    801 @code{struct sockaddr *}.  If @code{MHD_USE_IPv6} is specified,
    802 the @code{struct sockaddr*} should point to a @code{struct sockaddr_in6},
    803 otherwise to a @code{struct sockaddr_in}.  If this option is not specified,
    804 the daemon will listen to incoming connections from anywhere.  If you use this
    805 option, the 'port' argument from @code{MHD_start_daemon} is ignored and the port
    806 from the given @code{struct sockaddr *} will be used instead.
    807 
    808 @item MHD_OPTION_URI_LOG_CALLBACK
    809 @cindex debugging
    810 @cindex logging
    811 @cindex query string
    812 Specify a function that should be called before parsing the URI from
    813 the client.  The specified callback function can be used for processing
    814 the URI (including the options) before it is parsed.  The URI after
    815 parsing will no longer contain the options, which maybe inconvenient for
    816 logging.  This option should be followed by two arguments, the first
    817 one must be of the form
    818 @example
    819  void * my_logger(void * cls, const char * uri, struct MHD_Connection *con)
    820 @end example
    821 where the return value will be passed as
    822 @code{*req_cls} in calls to the @code{MHD_AccessHandlerCallback}
    823 when this request is processed later; returning a
    824 value of @code{NULL} has no special significance; (however,
    825 note that if you return non-@code{NULL}, you can no longer
    826 rely on the first call to the access handler having
    827 @code{NULL == *req_cls} on entry)
    828 @code{cls} will be set to the second argument following
    829 MHD_OPTION_URI_LOG_CALLBACK.  Finally, @code{uri} will
    830 be the 0-terminated URI of the request.
    831 
    832 Note that during the time of this call, most of the connection's state
    833 is not initialized (as we have not yet parsed he headers).  However,
    834 information about the connecting client (IP, socket) is available.
    835 
    836 @item MHD_OPTION_HTTPS_MEM_KEY
    837 @cindex SSL
    838 @cindex TLS
    839 Memory pointer to the private key to be used by the
    840 HTTPS daemon.  This option should be followed by an
    841 "const char*" argument.
    842 This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_CERT'.
    843 
    844 @item MHD_OPTION_HTTPS_KEY_PASSWORD
    845 @cindex SSL
    846 @cindex TLS
    847 Memory pointer to the password that decrypts the
    848 private key to be used by the HTTPS daemon.
    849 This option should be followed by an
    850 "const char*" argument.
    851 This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_KEY'.
    852 
    853 The password (or passphrase) is only used immediately during
    854 @code{MHD_start_daemon()}.  Thus, the application may want to
    855 erase it from memory afterwards for additional security.
    856 
    857 @item MHD_OPTION_HTTPS_MEM_CERT
    858 @cindex SSL
    859 @cindex TLS
    860 Memory pointer to the certificate to be used by the
    861 HTTPS daemon.  This option should be followed by an
    862 "const char*" argument.
    863 This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_KEY'.
    864 
    865 @item MHD_OPTION_HTTPS_MEM_TRUST
    866 @cindex SSL
    867 @cindex TLS
    868 Memory pointer to the CA certificate to be used by the
    869 HTTPS daemon to authenticate and trust clients certificates.
    870 This option should be followed by an "const char*" argument.
    871 The presence of this option activates the request of certificate
    872 to the client. The request to the client is marked optional, and
    873 it is the responsibility of the server to check the presence
    874 of the certificate if needed.
    875 Note that most browsers will only present a client certificate
    876 only if they have one matching the specified CA, not sending
    877 any certificate otherwise.
    878 
    879 @item MHD_OPTION_HTTPS_CRED_TYPE
    880 @cindex SSL
    881 @cindex TLS
    882 Daemon credentials type.  Either certificate or anonymous,
    883 this option should be followed by one of the values listed in
    884 "enum gnutls_credentials_type_t".
    885 
    886 @item MHD_OPTION_HTTPS_PRIORITIES
    887 @cindex SSL
    888 @cindex TLS
    889 @cindex cipher
    890 SSL/TLS protocol version and ciphers.
    891 This option must be followed by an "const char *" argument
    892 specifying the SSL/TLS protocol versions and ciphers that
    893 are acceptable for the application.  The string is passed
    894 unchanged to gnutls_priority_init.  If this option is not
    895 specified, ``NORMAL'' is used.
    896 
    897 @item MHD_OPTION_HTTPS_CERT_CALLBACK
    898 @cindex SSL
    899 @cindex TLS
    900 @cindex SNI
    901 Use a callback to determine which X.509 certificate should be used for
    902 a given HTTPS connection.  This option should be followed by a
    903 argument of type "gnutls_certificate_retrieve_function2 *".  This
    904 option provides an alternative to MHD_OPTION_HTTPS_MEM_KEY and
    905 MHD_OPTION_HTTPS_MEM_CERT.  You must use this version if multiple
    906 domains are to be hosted at the same IP address using TLS's Server
    907 Name Indication (SNI) extension.  In this case, the callback is
    908 expected to select the correct certificate based on the SNI
    909 information provided.  The callback is expected to access the SNI data
    910 using gnutls_server_name_get().  Using this option requires GnuTLS 3.0
    911 or higher.
    912 
    913 @item MHD_OPTION_HTTPS_CERT_CALLBACK2
    914 @cindex SSL
    915 @cindex TLS
    916 @cindex SNI
    917 @cindex OCSP
    918 Use a callback to determine which X.509 certificate should be
    919 used for a given HTTPS connection.  This option should be
    920 followed by a argument of type `gnutls_certificate_retrieve_function3 *`.
    921 This option provides an
    922 alternative/extension to #MHD_OPTION_HTTPS_CERT_CALLBACK.
    923 You must use this version if you want to use OCSP stapling.
    924 Using this option requires GnuTLS 3.6.3 or higher.
    925 
    926 @item MHD_OPTION_GNUTLS_PSK_CRED_HANDLER
    927 @cindex SSL
    928 @cindex TLS
    929 @cindex PSK
    930 Use pre-shared key for TLS credentials.
    931 Pass a pointer to callback of type
    932 @code{MHD_PskServerCredentialsCallback} and a closure.
    933 The function will be called to
    934 retrieve the shared key for a given username.
    935 
    936 @item MHD_OPTION_DIGEST_AUTH_RANDOM
    937 @cindex digest auth
    938 @cindex random
    939 Digest Authentication nonce's seed.
    940 
    941 This option should be followed by two arguments.  First an integer of
    942 type "size_t" which specifies the size of the buffer pointed to by the
    943 second argument in bytes.  Note that the application must ensure that
    944 the buffer of the second argument remains allocated and unmodified
    945 while the daemon is running.  For security, you SHOULD provide a fresh
    946 random nonce when using MHD with Digest Authentication.
    947 
    948 @item MHD_OPTION_NONCE_NC_SIZE
    949 @cindex digest auth
    950 @cindex replay attack
    951 
    952 Size of an array of nonce and nonce counter map.  This option must be
    953 followed by an "unsigned int" argument that have the size (number of
    954 elements) of a map of a nonce and a nonce-counter.  If this option
    955 is not specified, a default value of 4 will be used (which might be
    956 too small for servers handling many requests).  If you do not use
    957 digest authentication at all, you can specify a value of zero to
    958 save some memory.
    959 
    960 You should calculate the value of NC_SIZE based on the number of
    961 connections per second multiplied by your expected session duration
    962 plus a factor of about two for hash table collisions.  For example, if
    963 you expect 100 digest-authenticated connections per second and the
    964 average user to stay on your site for 5 minutes, then you likely need
    965 a value of about 60000.  On the other hand, if you can only expect
    966 only 10 digest-authenticated connections per second, tolerate browsers
    967 getting a fresh nonce for each request and expect a HTTP request
    968 latency of 250 ms, then a value of about 5 should be fine.
    969 
    970 
    971 @item MHD_OPTION_LISTEN_SOCKET
    972 @cindex systemd
    973 Listen socket to use.  Pass a listen socket for MHD to use
    974 (systemd-style).  If this option is used, MHD will not open its own
    975 listen socket(s). The argument passed must be of type "int" and refer
    976 to an existing socket that has been bound to a port and is listening.
    977 
    978 @item MHD_OPTION_EXTERNAL_LOGGER
    979 @cindex logging
    980 Use the given function for logging error messages.
    981 This option must be followed by two arguments; the
    982 first must be a pointer to a function
    983 of type 'void fun(void * arg, const char * fmt, va_list ap)'
    984 and the second a pointer of type 'void*' which will
    985 be passed as the "arg" argument to "fun".
    986 
    987 Note that MHD will not generate any log messages without
    988 the MHD_USE_ERROR_LOG flag set and if MHD was compiled
    989 with the "--disable-messages" flag.
    990 
    991 @item MHD_OPTION_THREAD_POOL_SIZE
    992 @cindex performance
    993 Number (unsigned int) of threads in thread pool. Enable
    994 thread pooling by setting this value to to something
    995 greater than 1. Currently, thread mode must be
    996 MHD_USE_INTERNAL_POLLING_THREAD if thread pooling is enabled
    997 (@code{MHD_start_daemon} returns @code{NULL} for an unsupported thread
    998 mode).
    999 
   1000 @item MHD_OPTION_ARRAY
   1001 @cindex options
   1002 @cindex foreign-function interface
   1003 This option can be used for initializing MHD using options from an
   1004 array.  A common use for this is writing an FFI for MHD.  The actual
   1005 options given are in an array of 'struct MHD_OptionItem', so this
   1006 option requires a single argument of type 'struct MHD_OptionItem'.
   1007 The array must be terminated with an entry @code{MHD_OPTION_END}.
   1008 
   1009 An example for code using MHD_OPTION_ARRAY is:
   1010 @example
   1011 struct MHD_OptionItem ops[] = @{
   1012  @{ MHD_OPTION_CONNECTION_LIMIT, 100, NULL @},
   1013  @{ MHD_OPTION_CONNECTION_TIMEOUT, 10, NULL @},
   1014  @{ MHD_OPTION_END, 0, NULL @}
   1015 @};
   1016 d = MHD_start_daemon(0, 8080, NULL, NULL, dh, NULL,
   1017                      MHD_OPTION_ARRAY, ops,
   1018                      MHD_OPTION_END);
   1019 @end example
   1020 For options that expect a single pointer argument, the
   1021 second member of the @code{struct MHD_OptionItem} is ignored.
   1022 For options that expect two pointer arguments, the first
   1023 argument must be cast to @code{intptr_t}.
   1024 
   1025 @item MHD_OPTION_UNESCAPE_CALLBACK
   1026 @cindex internationalization
   1027 @cindex escaping
   1028 
   1029 Specify a function that should be called for unescaping escape
   1030 sequences in URIs and URI arguments.  Note that this function will NOT
   1031 be used by the MHD_PostProcessor.  If this option is not specified,
   1032 the default method will be used which decodes escape sequences of the
   1033 form "%HH".  This option should be followed by two arguments, the
   1034 first one must be of the form
   1035 
   1036 @example
   1037   size_t my_unescaper(void * cls, struct MHD_Connection *c, char *s)
   1038 @end example
   1039 
   1040 where the return value must be @code{strlen(s)} and @code{s} should be
   1041 updated.  Note that the unescape function must not lengthen @code{s}
   1042 (the result must be shorter than the input and still be 0-terminated).
   1043 @code{cls} will be set to the second argument following
   1044 MHD_OPTION_UNESCAPE_CALLBACK.
   1045 
   1046 
   1047 @item MHD_OPTION_THREAD_STACK_SIZE
   1048 @cindex stack
   1049 @cindex thread
   1050 @cindex pthread
   1051 @cindex embedded systems
   1052 Maximum stack size for threads created by MHD.  This option must be
   1053 followed by a @code{size_t}).  Not specifying this option or using
   1054 a value of zero means using the system default (which is likely to
   1055 differ based on your platform).
   1056 
   1057 @item MHD_OPTION_TCP_FASTQUEUE_QUEUE_SIZE
   1058 @cindex listen
   1059 When the flag @code{MHD_USE_TCP_FASTOPEN} is used, this option sets the
   1060 connection handshake queue size for the TCP FASTOPEN connections.  Note
   1061 that a TCP FASTOPEN connection handshake occupies more resources than a
   1062 TCP handshake as the SYN packets also contain DATA which is kept in the
   1063 associate state until handshake is completed.  If this option is not
   1064 given the queue size is set to a default value of 10.  This option must
   1065 be followed by a @code{unsigned int}.
   1066 
   1067 @item MHD_OPTION_HTTPS_MEM_DHPARAMS
   1068 @cindex TLS
   1069 @cindex SSL
   1070 @cindex DH
   1071 Memory pointer for the Diffie-Hellman parameters (dh.pem) to be used
   1072 by the HTTPS daemon for key exchange.  This option must be followed by
   1073 a @code{const char *} argument.  The argument would be a zero-terminated
   1074 string with a PEM encoded PKCS3 DH parameters structure suitable
   1075 for passing to @code{gnutls_dh_parms_import_pkcs3}.
   1076 
   1077 @item MHD_OPTION_LISTENING_ADDRESS_REUSE
   1078 @cindex bind, restricting bind
   1079 @cindex reusing listening address
   1080 This option must be followed by a @code{unsigned int} argument.
   1081 If this option is present and true (nonzero) parameter is given, allow reusing
   1082 the address:port of the listening socket (using @code{SO_REUSEPORT} on most
   1083 platforms, and @code{SO_REUSEADDR} on Windows).  If a false (zero) parameter is
   1084 given, disallow reusing the the address:port of the listening socket (this
   1085 usually requires no special action, but @code{SO_EXCLUSIVEADDRUSE} is needed on
   1086 Windows).  If this option is not present @code{SO_REUSEADDR} is used on all
   1087 platforms except Windows so reusing of address:port is disallowed.
   1088 
   1089 @end table
   1090 @end deftp
   1091 
   1092 
   1093 @deftp {C Struct} MHD_OptionItem
   1094 Entry in an MHD_OPTION_ARRAY.  See the @code{MHD_OPTION_ARRAY} option
   1095 argument for its use.
   1096 
   1097 The @code{option} member is used to specify which option is specified
   1098 in the array.  The other members specify the respective argument.
   1099 
   1100 Note that for options taking only a single pointer, the
   1101 @code{ptr_value} member should be set.  For options taking two pointer
   1102 arguments, the first pointer must be cast to @code{intptr_t} and both
   1103 the @code{value} and the @code{ptr_value} members should be used to
   1104 pass the two pointers.
   1105 @end deftp
   1106 
   1107 
   1108 @deftp {Enumeration} MHD_ValueKind
   1109 The @code{MHD_ValueKind} specifies the source of the key-value pairs in
   1110 the HTTP protocol.
   1111 
   1112 @table @code
   1113 @item MHD_HEADER_KIND
   1114 HTTP header.
   1115 
   1116 @item MHD_COOKIE_KIND
   1117 @cindex cookie
   1118 Cookies.  Note that the original HTTP header containing the cookie(s)
   1119 will still be available and intact.
   1120 
   1121 @item MHD_POSTDATA_KIND
   1122 @cindex POST method
   1123 @code{POST} data.  This is available only if a content encoding
   1124 supported by MHD is used (currently only @acronym{URL} encoding), and
   1125 only if the posted content fits within the available memory pool.  Note
   1126 that in that case, the upload data given to the
   1127 @code{MHD_AccessHandlerCallback()} will be empty (since it has
   1128 already been processed).
   1129 
   1130 @item MHD_GET_ARGUMENT_KIND
   1131 @code{GET} (URI) arguments.
   1132 
   1133 @item MHD_FOOTER_KIND
   1134 HTTP footer (only for http 1.1 chunked encodings).
   1135 
   1136 @end table
   1137 @end deftp
   1138 
   1139 
   1140 @deftp {Enumeration} MHD_RequestTerminationCode
   1141 The @code{MHD_RequestTerminationCode} specifies reasons why a request
   1142 has been terminated (or completed).
   1143 
   1144 @table @code
   1145 @item MHD_REQUEST_TERMINATED_COMPLETED_OK
   1146 We finished sending the response.
   1147 
   1148 @item MHD_REQUEST_TERMINATED_WITH_ERROR
   1149 Error handling the connection (resources exhausted, other side closed
   1150 connection, application error accepting request, etc.)
   1151 
   1152 @item MHD_REQUEST_TERMINATED_TIMEOUT_REACHED
   1153 No activity on the connection for the number of seconds specified using
   1154 @code{MHD_OPTION_CONNECTION_TIMEOUT}.
   1155 
   1156 @item MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN
   1157 We had to close the session since MHD was being shut down.
   1158 @end table
   1159 @end deftp
   1160 
   1161 
   1162 @deftp {Enumeration} MHD_ResponseMemoryMode
   1163 The @code{MHD_ResponeMemoryMode} specifies how MHD should treat
   1164 the memory buffer given for the response in
   1165 @code{MHD_create_response_from_buffer}.
   1166 
   1167 @table @code
   1168 @item MHD_RESPMEM_PERSISTENT
   1169 Buffer is a persistent (static/global) buffer that won't change
   1170 for at least the lifetime of the response, MHD should just use
   1171 it, not free it, not copy it, just keep an alias to it.
   1172 
   1173 @item MHD_RESPMEM_MUST_FREE
   1174 Buffer is heap-allocated with @code{malloc} (or equivalent) and
   1175 should be freed by MHD after processing the response has
   1176 concluded (response reference counter reaches zero).
   1177 
   1178 @item MHD_RESPMEM_MUST_COPY
   1179 Buffer is in transient memory, but not on the heap (for example,
   1180 on the stack or non-malloc allocated) and only valid during the
   1181 call to @code{MHD_create_response_from_buffer}.  MHD must make its
   1182 own private copy of the data for processing.
   1183 
   1184 @end table
   1185 @end deftp
   1186 
   1187 
   1188 @deftp {Enumeration} MHD_ResponseFlags
   1189 Response-specific flags.  Passed as an argument to
   1190 @code{MHD_set_response_options()}.
   1191 
   1192 @table @code
   1193 @item MHD_RF_NONE
   1194 No special handling.
   1195 
   1196 @item MHD_RF_HTTP_VERSION_1_0_ONLY
   1197 Only respond in conservative HTTP 1.0-mode.   In particular,
   1198 do not (automatically) sent "Connection" headers and always
   1199 close the connection after generating the response.
   1200 
   1201 By default, MHD will respond using the same HTTP version which
   1202 was set in the request. You can also set the
   1203 @code{MHD_RF_HTTP_VERSION_1_0_RESPONSE} flag to force version 1.0
   1204 in the response.
   1205 
   1206 @item MHD_RF_HTTP_VERSION_1_0_RESPONSE
   1207 Only respond in HTTP 1.0-mode. Contrary to the
   1208 @code{MHD_RF_HTTP_VERSION_1_0_ONLY} flag, the response's HTTP version will
   1209 always be set to 1.0 and ``Connection'' headers are still supported.
   1210 
   1211 You can even combine this option with MHD_RF_HTTP_VERSION_1_0_ONLY to
   1212 change the response's HTTP version while maintaining strict compliance
   1213 with HTTP 1.0 regarding connection management.
   1214 
   1215 This solution is not perfect as this flag is set on the response which
   1216 is created after header processing. So MHD will behave as a HTTP 1.1
   1217 server until the response is queued. It means that an invalid HTTP 1.1
   1218 request will fail even if the response is sent with HTTP 1.0 and the
   1219 request would be valid if interpreted with this version. For example,
   1220 this request will fail in strict mode:
   1221 
   1222 @verbatim
   1223 GET / HTTP/1.1
   1224 @end verbatim
   1225 
   1226 as the ``Host'' header is missing and is mandatory in HTTP 1.1, but it
   1227 should succeed when interpreted with HTTP 1.0.
   1228 
   1229 @item MHD_RF_INSANITY_HEADER_CONTENT_LENGTH
   1230 Disable sanity check preventing clients from manually
   1231 setting the HTTP content length option.
   1232 
   1233 @end table
   1234 @end deftp
   1235 
   1236 
   1237 @deftp {Enumeration} MHD_ResponseOptions
   1238 Response-specific options.  Passed in the varargs portion of
   1239 @code{MHD_set_response_options()}.
   1240 
   1241 @table @code
   1242 @item MHD_RO_END
   1243 No more options / last option.  This is used to terminate the VARARGs
   1244 list.
   1245 @end table
   1246 @end deftp
   1247 
   1248 
   1249 @deftp {Enumeration} MHD_WEBSOCKET_FLAG
   1250 @cindex websocket
   1251 Options for the MHD websocket stream.
   1252 
   1253 This is used for initialization of a websocket stream when calling
   1254 @code{MHD_websocket_stream_init} or @code{MHD_websocket_stream_init2} and
   1255 alters the behavior of the websocket stream.
   1256 
   1257 Note that websocket streams are only available if you include the header file
   1258 @code{microhttpd_ws.h} and compiled @emph{libmicrohttpd} with websockets.
   1259 
   1260 @table @code
   1261 @item MHD_WEBSOCKET_FLAG_SERVER
   1262 The websocket stream is initialized in server mode (default).
   1263 Thus all outgoing payload will not be masked.
   1264 All incoming payload must be masked.
   1265 
   1266 This flag cannot be used together with @code{MHD_WEBSOCKET_FLAG_CLIENT}.
   1267 
   1268 @item MHD_WEBSOCKET_FLAG_CLIENT
   1269 The websocket stream is initialized in client mode.
   1270 You will usually never use that mode in combination with @emph{libmicrohttpd},
   1271 because @emph{libmicrohttpd} provides a server and not a client.
   1272 In client mode all outgoing payload will be masked
   1273 (XOR-ed with random values).
   1274 All incoming payload must be unmasked.
   1275 If you use this mode, you must always call @code{MHD_websocket_stream_init2}
   1276 instead of @code{MHD_websocket_stream_init}, because you need
   1277 to pass a random number generator callback function for masking.
   1278 
   1279 This flag cannot be used together with @code{MHD_WEBSOCKET_FLAG_SERVER}.
   1280 
   1281 @item MHD_WEBSOCKET_FLAG_NO_FRAGMENTS
   1282 You don't want to get fragmented data while decoding (default).
   1283 Fragmented frames will be internally put together until
   1284 they are complete.
   1285 Whether or not data is fragmented is decided
   1286 by the sender of the data during encoding.
   1287 
   1288 This cannot be used together with @code{MHD_WEBSOCKET_FLAG_WANT_FRAGMENTS}.
   1289 
   1290 @item MHD_WEBSOCKET_FLAG_WANT_FRAGMENTS
   1291 You want fragmented data, if it appears while decoding.
   1292 You will receive the content of the fragmented frame,
   1293 but if you are decoding text, you will never get an unfinished
   1294 UTF-8 sequence (if the sequence appears between two fragments).
   1295 Instead the text will end before the unfinished UTF-8 sequence.
   1296 With the next fragment, which finishes the UTF-8 sequence,
   1297 you will get the complete UTF-8 sequence.
   1298 
   1299 This cannot be used together with @code{MHD_WEBSOCKET_FLAG_NO_FRAGMENTS}.
   1300 
   1301 @item MHD_WEBSOCKET_FLAG_GENERATE_CLOSE_FRAMES_ON_ERROR
   1302 If the websocket stream becomes invalid during decoding due to
   1303 protocol errors, a matching close frame will automatically
   1304 be generated.
   1305 The close frame will be returned via the parameters
   1306 @code{payload} and @code{payload_len} of @code{MHD_websocket_decode} and
   1307 the return value is negative (a value of @code{enum MHD_WEBSOCKET_STATUS}).
   1308 
   1309 The generated close frame must be freed by the caller
   1310 with @code{MHD_websocket_free}.
   1311 
   1312 @end table
   1313 @end deftp
   1314 
   1315 
   1316 @deftp {Enumeration} MHD_WEBSOCKET_FRAGMENTATION
   1317 @cindex websocket
   1318 This enumeration is used to specify the fragmentation behavior
   1319 when encoding of data (text/binary) for a websocket stream.
   1320 This is used with @code{MHD_websocket_encode_text} or
   1321 @code{MHD_websocket_encode_binary}.
   1322 
   1323 Note that websocket streams are only available if you include the header file
   1324 @code{microhttpd_ws.h} and compiled @emph{libmicrohttpd} with websockets.
   1325 
   1326 @table @code
   1327 @item MHD_WEBSOCKET_FRAGMENTATION_NONE
   1328 You don't want to use fragmentation.
   1329 The encoded frame consists of only one frame.
   1330 
   1331 @item MHD_WEBSOCKET_FRAGMENTATION_FIRST
   1332 You want to use fragmentation.
   1333 The encoded frame is the first frame of
   1334 a series of data frames of the same type
   1335 (text or binary).
   1336 You may send control frames (ping, pong or close)
   1337 between these data frames.
   1338 
   1339 @item MHD_WEBSOCKET_FRAGMENTATION_FOLLOWING
   1340 You want to use fragmentation.
   1341 The encoded frame is not the first frame of
   1342 the series of data frames, but also not the last one.
   1343 You may send control frames (ping, pong or close)
   1344 between these data frames.
   1345 
   1346 @item MHD_WEBSOCKET_FRAGMENTATION_LAST
   1347 You want to use fragmentation.
   1348 The encoded frame is the last frame of
   1349 the series of data frames, but also not the first one.
   1350 After this frame, you may send all types of frames again.
   1351 
   1352 @end table
   1353 @end deftp
   1354 
   1355 
   1356 @deftp {Enumeration} MHD_WEBSOCKET_STATUS
   1357 @cindex websocket
   1358 This enumeration is used for the return value of almost
   1359 every websocket stream function.
   1360 Errors are negative and values equal to or above zero mean a success.
   1361 Positive values are only used by @code{MHD_websocket_decode}.
   1362 
   1363 Note that websocket streams are only available if you include the header file
   1364 @code{microhttpd_ws.h} and compiled @emph{libmicrohttpd} with websockets.
   1365 
   1366 @table @code
   1367 @item MHD_WEBSOCKET_STATUS_OK
   1368 The call succeeded.
   1369 Especially for @code{MHD_websocket_decode} this means that no error occurred,
   1370 but also no frame has been completed yet.
   1371 For other functions this means simply a success.
   1372 
   1373 @item MHD_WEBSOCKET_STATUS_TEXT_FRAME
   1374 @code{MHD_websocket_decode} has decoded a text frame.
   1375 The parameters @code{payload} and @code{payload_len} are filled with
   1376 the decoded text (if any).
   1377 You must free the returned @code{payload} after use with
   1378 @code{MHD_websocket_free}.
   1379 
   1380 @item MHD_WEBSOCKET_STATUS_BINARY_FRAME
   1381 @code{MHD_websocket_decode} has decoded a binary frame.
   1382 The parameters @code{payload} and @code{payload_len} are filled with
   1383 the decoded binary data (if any).
   1384 You must free the returned @code{payload} after use with
   1385 @code{MHD_websocket_free}.
   1386 
   1387 @item MHD_WEBSOCKET_STATUS_CLOSE_FRAME
   1388 @code{MHD_websocket_decode} has decoded a close frame.
   1389 This means you must close the socket using @code{MHD_upgrade_action}
   1390 with @code{MHD_UPGRADE_ACTION_CLOSE}.
   1391 You may respond with a close frame before closing.
   1392 The parameters @code{payload} and @code{payload_len} are filled with
   1393 the close reason (if any).
   1394 The close reason starts with a two byte sequence of close code
   1395 in network byte order (see @code{enum MHD_WEBSOCKET_CLOSEREASON}).
   1396 After these two bytes a UTF-8 encoded close reason may follow.
   1397 You can call @code{MHD_websocket_split_close_reason} to split that
   1398 close reason.
   1399 You must free the returned @code{payload} after use with
   1400 @code{MHD_websocket_free}.
   1401 
   1402 @item MHD_WEBSOCKET_STATUS_PING_FRAME
   1403 @code{MHD_websocket_decode} has decoded a ping frame.
   1404 You should respond to this with a pong frame.
   1405 The pong frame must contain the same binary data as
   1406 the corresponding ping frame (if it had any).
   1407 The parameters @code{payload} and @code{payload_len} are filled with
   1408 the binary ping data (if any).
   1409 You must free the returned @code{payload} after use with
   1410 @code{MHD_websocket_free}.
   1411 
   1412 @item MHD_WEBSOCKET_STATUS_PONG_FRAME
   1413 @code{MHD_websocket_decode} has decoded a pong frame.
   1414 You should usually only receive pong frames if you sent
   1415 a ping frame before.
   1416 The binary data should be equal to your ping frame and can be
   1417 used to distinguish the response if you sent multiple ping frames.
   1418 The parameters @code{payload} and @code{payload_len} are filled with
   1419 the binary pong data (if any).
   1420 You must free the returned @code{payload} after use with
   1421 @code{MHD_websocket_free}.
   1422 
   1423 @item MHD_WEBSOCKET_STATUS_TEXT_FIRST_FRAGMENT
   1424 @code{MHD_websocket_decode} has decoded a text frame fragment.
   1425 The parameters @code{payload} and @code{payload_len} are filled with
   1426 the decoded text (if any).
   1427 This is like @code{MHD_WEBSOCKET_STATUS_TEXT_FRAME}, but it can only
   1428 appear if you specified @code{MHD_WEBSOCKET_FLAG_WANT_FRAGMENTS} during
   1429 the call of @code{MHD_websocket_stream_init} or
   1430 @code{MHD_websocket_stream_init2}.
   1431 You must free the returned @code{payload} after use with
   1432 @code{MHD_websocket_free}.
   1433 
   1434 @item MHD_WEBSOCKET_STATUS_TEXT_FIRST_FRAGMENT
   1435 @code{MHD_websocket_decode} has decoded a binary frame fragment.
   1436 The parameters @code{payload} and @code{payload_len} are filled with
   1437 the decoded binary data (if any).
   1438 This is like @code{MHD_WEBSOCKET_STATUS_BINARY_FRAME}, but it can only
   1439 appear if you specified @code{MHD_WEBSOCKET_FLAG_WANT_FRAGMENTS} during
   1440 the call of @code{MHD_websocket_stream_init} or
   1441 @code{MHD_websocket_stream_init2}.
   1442 You must free the returned @code{payload} after use with
   1443 @code{MHD_websocket_free}.
   1444 
   1445 @item MHD_WEBSOCKET_STATUS_TEXT_NEXT_FRAGMENT
   1446 @code{MHD_websocket_decode} has decoded the next text frame fragment.
   1447 The parameters @code{payload} and @code{payload_len} are filled with
   1448 the decoded text (if any).
   1449 This is like @code{MHD_WEBSOCKET_STATUS_TEXT_FIRST_FRAGMENT}, but it appears
   1450 only after the first and before the last fragment of a series of fragments.
   1451 It can only appear if you specified @code{MHD_WEBSOCKET_FLAG_WANT_FRAGMENTS}
   1452 during the call of @code{MHD_websocket_stream_init} or
   1453 @code{MHD_websocket_stream_init2}.
   1454 You must free the returned @code{payload} after use with
   1455 @code{MHD_websocket_free}.
   1456 
   1457 @item MHD_WEBSOCKET_STATUS_BINARY_NEXT_FRAGMENT
   1458 @code{MHD_websocket_decode} has decoded the next binary frame fragment.
   1459 The parameters @code{payload} and @code{payload_len} are filled with
   1460 the decoded binary data (if any).
   1461 This is like @code{MHD_WEBSOCKET_STATUS_BINARY_FIRST_FRAGMENT}, but it appears
   1462 only after the first and before the last fragment of a series of fragments.
   1463 It can only appear if you specified @code{MHD_WEBSOCKET_FLAG_WANT_FRAGMENTS}
   1464 during the call of @code{MHD_websocket_stream_init} or
   1465 @code{MHD_websocket_stream_init2}.
   1466 You must free the returned @code{payload} after use with
   1467 @code{MHD_websocket_free}.
   1468 
   1469 @item MHD_WEBSOCKET_STATUS_TEXT_LAST_FRAGMENT
   1470 @code{MHD_websocket_decode} has decoded the last text frame fragment.
   1471 The parameters @code{payload} and @code{payload_len} are filled with
   1472 the decoded text (if any).
   1473 This is like @code{MHD_WEBSOCKET_STATUS_TEXT_FIRST_FRAGMENT}, but it appears
   1474 only for the last fragment of a series of fragments.
   1475 It can only appear if you specified @code{MHD_WEBSOCKET_FLAG_WANT_FRAGMENTS}
   1476 during the call of @code{MHD_websocket_stream_init} or
   1477 @code{MHD_websocket_stream_init2}.
   1478 You must free the returned @code{payload} after use with
   1479 @code{MHD_websocket_free}.
   1480 
   1481 @item MHD_WEBSOCKET_STATUS_BINARY_LAST_FRAGMENT
   1482 @code{MHD_websocket_decode} has decoded the last binary frame fragment.
   1483 The parameters @code{payload} and @code{payload_len} are filled with
   1484 the decoded binary data (if any).
   1485 This is like @code{MHD_WEBSOCKET_STATUS_BINARY_FIRST_FRAGMENT}, but it appears
   1486 only for the last fragment of a series of fragments.
   1487 It can only appear if you specified @code{MHD_WEBSOCKET_FLAG_WANT_FRAGMENTS}
   1488 during the call of @code{MHD_websocket_stream_init} or
   1489 @code{MHD_websocket_stream_init2}.
   1490 You must free the returned @code{payload} after use with
   1491 @code{MHD_websocket_free}.
   1492 
   1493 @item MHD_WEBSOCKET_STATUS_PROTOCOL_ERROR
   1494 The call failed and the stream is invalid now for decoding.
   1495 You must close the websocket now using @code{MHD_upgrade_action}
   1496 with @code{MHD_UPGRADE_ACTION_CLOSE}.
   1497 You may send a close frame before closing.
   1498 This is only used by @code{MHD_websocket_decode} and happens
   1499 if the stream contains errors (i. e. invalid byte data).
   1500 
   1501 @item MHD_WEBSOCKET_STATUS_STREAM_BROKEN
   1502 You tried to decode something, but the stream has already
   1503 been marked invalid.
   1504 You must close the websocket now using @code{MHD_upgrade_action}
   1505 with @code{MHD_UPGRADE_ACTION_CLOSE}.
   1506 You may send a close frame before closing.
   1507 This is only used by @code{MHD_websocket_decode} and happens
   1508 if you call @code{MDM_websocket_decode} again after
   1509 has been invalidated.
   1510 You can call @code{MHD_websocket_stream_is_valid} at any time
   1511 to check whether a stream is invalid or not.
   1512 
   1513 @item MHD_WEBSOCKET_STATUS_MEMORY_ERROR
   1514 A memory allocation failed. The stream remains valid.
   1515 If this occurred while decoding, the decoding could be
   1516 possible later if enough memory is available.
   1517 This could happen while decoding if you received a too big data frame.
   1518 You could try to specify max_payload_size during the call of
   1519 @code{MHD_websocket_stream_init} or @code{MHD_websocket_stream_init2} to
   1520 avoid this and close the websocket instead.
   1521 
   1522 @item MHD_WEBSOCKET_STATUS_PARAMETER_ERROR
   1523 You passed invalid parameters during the function call
   1524 (i. e. a NULL pointer for a required parameter).
   1525 The stream remains valid.
   1526 
   1527 @item MHD_WEBSOCKET_STATUS_MAXIMUM_SIZE_EXCEEDED
   1528 The maximum payload size has been exceeded.
   1529 If you got this return code from @code{MHD_websocket_decode} then
   1530 the stream becomes invalid and the websocket must be closed
   1531 using @code{MHD_upgrade_action} with @code{MHD_UPGRADE_ACTION_CLOSE}.
   1532 You may send a close frame before closing.
   1533 The maximum payload size is specified during the call of
   1534 @code{MHD_websocket_stream_init} or @code{MHD_websocket_stream_init2}.
   1535 This can also appear if you specified 0 as maximum payload size
   1536 when the message is greater than the maximum allocatable memory size
   1537 (i. e. more than 4 GiB on 32 bit systems).
   1538 If you got this return code from @code{MHD_websocket_encode_close},
   1539 @code{MHD_websocket_encode_ping} or @code{MHD_websocket_encode_pong} then
   1540 you passed to much payload data. The stream remains valid then.
   1541 
   1542 @item MHD_WEBSOCKET_STATUS_UTF8_ENCODING_ERROR
   1543 An UTF-8 sequence is invalid.
   1544 If you got this return code from @code{MHD_websocket_decode} then
   1545 the stream becomes invalid and you must close the websocket
   1546 using @code{MHD_upgrade_action} with @code{MHD_UPGRADE_ACTION_CLOSE}.
   1547 You may send a close frame before closing.
   1548 If you got this from @code{MHD_websocket_encode_text} or
   1549 @code{MHD_websocket_encode_close} then you passed invalid UTF-8 text.
   1550 The stream remains valid then.
   1551 
   1552 @item MHD_WEBSOCKET_STATUS_NO_WEBSOCKET_HANDSHAKE_HEADER
   1553 A check routine for the HTTP headers came to the conclusion that
   1554 the header value isn't valid for a websocket handshake request.
   1555 This value can only be returned from the following functions:
   1556 @code{MHD_websocket_check_http_version},
   1557 @code{MHD_websocket_check_connection_header},
   1558 @code{MHD_websocket_check_upgrade_header},
   1559 @code{MHD_websocket_check_version_header},
   1560 @code{MHD_websocket_create_accept_header}
   1561 
   1562 @end table
   1563 @end deftp
   1564 
   1565 
   1566 @deftp {Enumeration} MHD_WEBSOCKET_CLOSEREASON
   1567 @cindex websocket
   1568 Enumeration of possible close reasons for websocket close frames.
   1569 
   1570 The possible values are specified in RFC 6455 7.4.1
   1571 These close reasons here are the default set specified by RFC 6455,
   1572 but also other close reasons could be used.
   1573 
   1574 The definition is for short:
   1575 @itemize @bullet
   1576 @item 0-999 are never used (if you pass 0 in
   1577 @code{MHD_websocket_encode_close} then no close reason is used).
   1578 @item 1000-2999 are specified by RFC 6455.
   1579 @item 3000-3999 are specified by libraries, etc. but must be registered by IANA.
   1580 @item 4000-4999 are reserved for private use.
   1581 @end itemize
   1582 
   1583 Note that websocket streams are only available if you include the header file
   1584 @code{microhttpd_ws.h} and compiled @emph{libmicrohttpd} with websockets.
   1585 
   1586 @table @code
   1587 @item MHD_WEBSOCKET_CLOSEREASON_NO_REASON
   1588 This value is used as placeholder for @code{MHD_websocket_encode_close}
   1589 to tell that you don't want to specify any reason.
   1590 If you use this value then no reason text may be used.
   1591 This value cannot be a result of decoding, because this value
   1592 is not a valid close reason for the websocket protocol.
   1593 
   1594 @item MHD_WEBSOCKET_CLOSEREASON_REGULAR
   1595 You close the websocket because it fulfilled its purpose and shall
   1596 now be closed in a normal, planned way.
   1597 
   1598 @item MHD_WEBSOCKET_CLOSEREASON_GOING_AWAY
   1599 You close the websocket because you are shutting down the server or
   1600 something similar.
   1601 
   1602 @item MHD_WEBSOCKET_CLOSEREASON_PROTOCOL_ERROR
   1603 You close the websocket because a protocol error occurred
   1604 during decoding (i. e. invalid byte data).
   1605 
   1606 @item MHD_WEBSOCKET_CLOSEREASON_UNSUPPORTED_DATATYPE
   1607 You close the websocket because you received data which you don't accept.
   1608 For example if you received a binary frame,
   1609 but your application only expects text frames.
   1610 
   1611 @item MHD_WEBSOCKET_CLOSEREASON_MALFORMED_UTF8
   1612 You close the websocket because it contains malformed UTF-8.
   1613 The UTF-8 validity is automatically checked by @code{MHD_websocket_decode},
   1614 so you don't need to check it on your own.
   1615 UTF-8 is specified in RFC 3629.
   1616 
   1617 @item MHD_WEBSOCKET_CLOSEREASON_POLICY_VIOLATED
   1618 You close the websocket because you received a frame which is too big
   1619 to process.
   1620 You can specify the maximum allowed payload size during the call of
   1621 @code{MHD_websocket_stream_init} or @code{MHD_websocket_stream_init2}.
   1622 
   1623 @item MHD_WEBSOCKET_CLOSEREASON_MISSING_EXTENSION
   1624 This status code can be sent by the client if it
   1625 expected a specific extension, but this extension hasn't been negotiated.
   1626 
   1627 @item MHD_WEBSOCKET_CLOSEREASON_UNEXPECTED_CONDITION
   1628 The server closes the websocket because it encountered
   1629 an unexpected condition that prevented it from fulfilling the request.
   1630 
   1631 @end table
   1632 @end deftp
   1633 
   1634 
   1635 @deftp {Enumeration} MHD_WEBSOCKET_UTF8STEP
   1636 @cindex websocket
   1637 Enumeration of possible UTF-8 check steps for websocket functions
   1638 
   1639 These values are used during the encoding of fragmented text frames
   1640 or for error analysis while encoding text frames.
   1641 Its values specify the next step of the UTF-8 check.
   1642 UTF-8 sequences consist of one to four bytes.
   1643 This enumeration just says how long the current UTF-8 sequence is
   1644 and what is the next expected byte.
   1645 
   1646 Note that websocket streams are only available if you include the header file
   1647 @code{microhttpd_ws.h} and compiled @emph{libmicrohttpd} with websockets.
   1648 
   1649 @table @code
   1650 @item MHD_WEBSOCKET_UTF8STEP_NORMAL
   1651 There is no open UTF-8 sequence.
   1652 The next byte must be 0x00-0x7F or 0xC2-0xF4.
   1653 
   1654 @item MHD_WEBSOCKET_UTF8STEP_UTF2TAIL_1OF1
   1655 The second byte of a two byte UTF-8 sequence.
   1656 The first byte was 0xC2-0xDF.
   1657 The next byte must be 0x80-0xBF.
   1658 
   1659 @item MHD_WEBSOCKET_UTF8STEP_UTF3TAIL1_1OF2
   1660 The second byte of a three byte UTF-8 sequence.
   1661 The first byte was 0xE0.
   1662 The next byte must be 0xA0-0xBF.
   1663 
   1664 @item MHD_WEBSOCKET_UTF8STEP_UTF3TAIL2_1OF2
   1665 The second byte of a three byte UTF-8 sequence.
   1666 The first byte was 0xED.
   1667 The next byte must by 0x80-0x9F.
   1668 
   1669 @item MHD_WEBSOCKET_UTF8STEP_UTF3TAIL_1OF2
   1670 The second byte of a three byte UTF-8 sequence.
   1671 The first byte was 0xE1-0xEC or 0xEE-0xEF.
   1672 The next byte must be 0x80-0xBF.
   1673 
   1674 @item MHD_WEBSOCKET_UTF8STEP_UTF3TAIL_2OF2
   1675 The third byte of a three byte UTF-8 sequence.
   1676 The next byte must be 0x80-0xBF.
   1677 
   1678 @item MHD_WEBSOCKET_UTF8STEP_UTF4TAIL1_1OF3
   1679 The second byte of a four byte UTF-8 sequence.
   1680 The first byte was 0xF0.
   1681 The next byte must be 0x90-0xBF.
   1682 
   1683 @item MHD_WEBSOCKET_UTF8STEP_UTF4TAIL2_1OF3
   1684 The second byte of a four byte UTF-8 sequence.
   1685 The first byte was 0xF4.
   1686 The next byte must be 0x80-0x8F.
   1687 
   1688 @item MHD_WEBSOCKET_UTF8STEP_UTF4TAIL_1OF3
   1689 The second byte of a four byte UTF-8 sequence.
   1690 The first byte was 0xF1-0xF3.
   1691 The next byte must be 0x80-0xBF.
   1692 
   1693 @item MHD_WEBSOCKET_UTF8STEP_UTF4TAIL_2OF3
   1694 The third byte of a four byte UTF-8 sequence.
   1695 The next byte must be 0x80-0xBF.
   1696 
   1697 @item MHD_WEBSOCKET_UTF8STEP_UTF4TAIL_3OF3
   1698 The fourth byte of a four byte UTF-8 sequence.
   1699 The next byte must be 0x80-0xBF.
   1700 
   1701 @end table
   1702 @end deftp
   1703 
   1704 
   1705 @deftp {Enumeration} MHD_WEBSOCKET_VALIDITY
   1706 @cindex websocket
   1707 Enumeration of validity values of a websocket stream
   1708 
   1709 These values are used for @code{MHD_websocket_stream_is_valid}
   1710 and specify the validity status.
   1711 
   1712 Note that websocket streams are only available if you include the header file
   1713 @code{microhttpd_ws.h} and compiled @emph{libmicrohttpd} with websockets.
   1714 
   1715 @table @code
   1716 @item MHD_WEBSOCKET_VALIDITY_INVALID
   1717 The stream is invalid.
   1718 It cannot be used for decoding anymore.
   1719 
   1720 @item MHD_WEBSOCKET_VALIDITY_VALID
   1721 The stream is valid.
   1722 Decoding works as expected.
   1723 
   1724 @item MHD_WEBSOCKET_VALIDITY_ONLY_VALID_FOR_CONTROL_FRAMES
   1725 The stream has received a close frame and
   1726 is partly invalid.
   1727 You can still use the stream for decoding,
   1728 but if a data frame is received an error will be reported.
   1729 After a close frame has been sent, no data frames
   1730 may follow from the sender of the close frame.
   1731 
   1732 @end table
   1733 @end deftp
   1734 
   1735 
   1736 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   1737 
   1738 @c ------------------------------------------------------------
   1739 @node microhttpd-struct
   1740 @chapter Structures type definition
   1741 
   1742 
   1743 @deftp {C Struct} MHD_Daemon
   1744 Handle for the daemon (listening on a socket for HTTP traffic).
   1745 @end deftp
   1746 
   1747 
   1748 @deftp {C Struct} MHD_Connection
   1749 Handle for a connection / HTTP request.  With HTTP/1.1, multiple
   1750 requests can be run over the same connection.  However, MHD will only
   1751 show one request per TCP connection to the client at any given time.
   1752 @end deftp
   1753 
   1754 
   1755 @deftp {C Struct} MHD_Response
   1756 Handle for a response.
   1757 @end deftp
   1758 
   1759 
   1760 @deftp {C Struct} MHD_IoVec
   1761 An element of an array of memory buffers.
   1762 @end deftp
   1763 
   1764 
   1765 @deftp {C Struct} MHD_PostProcessor
   1766 @cindex POST method
   1767 Handle for @code{POST} processing.
   1768 @end deftp
   1769 
   1770 
   1771 @deftp {C Union} MHD_ConnectionInfo
   1772 Information about a connection.
   1773 @end deftp
   1774 
   1775 
   1776 @deftp {C Union} MHD_DaemonInfo
   1777 Information about an MHD daemon.
   1778 @end deftp
   1779 
   1780 
   1781 @deftp {C Struct} MHD_WebSocketStream
   1782 @cindex websocket
   1783 Information about a MHD websocket stream.
   1784 @end deftp
   1785 
   1786 
   1787 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   1788 
   1789 @c ------------------------------------------------------------
   1790 @node microhttpd-cb
   1791 @chapter Callback functions definition
   1792 
   1793 
   1794 @deftypefn {Function Pointer} enum MHD_Result {*MHD_AcceptPolicyCallback} (void *cls, const struct sockaddr * addr, socklen_t addrlen)
   1795 Invoked in the context of a connection to allow or deny a client to
   1796 connect.  This callback return @code{MHD_YES} if connection is allowed,
   1797 @code{MHD_NO} if not.
   1798 
   1799 @table @var
   1800 @item cls
   1801 custom value selected at callback registration time;
   1802 @item addr
   1803 address information from the client;
   1804 @item addrlen
   1805 length of the address information.
   1806 @end table
   1807 @end deftypefn
   1808 
   1809 
   1810 @deftypefn {Function Pointer} enum MHD_Result {*MHD_AccessHandlerCallback} (void *cls, struct MHD_Connection * connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **req_cls)
   1811 Invoked in the context of a connection to answer a request from the
   1812 client.  This callback must call MHD functions (example: the
   1813 @code{MHD_Response} ones) to provide content to give back to the client
   1814 and return an HTTP status code (i.e. @code{200} for OK, @code{404},
   1815 etc.).
   1816 
   1817 @ref{microhttpd-post}, for details on how to code this callback.
   1818 
   1819 Must return @code{MHD_YES} if the connection was handled successfully,
   1820 @code{MHD_NO} if the socket must be closed due to a serious error while
   1821 handling the request
   1822 
   1823 @table @var
   1824 @item cls
   1825 custom value selected at callback registration time;
   1826 
   1827 @item url
   1828 the URL requested by the client;
   1829 
   1830 @item method
   1831 the HTTP method used by the client (@code{GET}, @code{PUT},
   1832 @code{DELETE}, @code{POST}, etc.);
   1833 
   1834 @item version
   1835 the HTTP version string (i.e. @code{HTTP/1.1});
   1836 
   1837 @item upload_data
   1838 the data being uploaded (excluding headers):
   1839 @cindex POST method
   1840 @cindex PUT method
   1841 
   1842 @code{POST} data @strong{will} be made available
   1843 incrementally in @var{upload_data}; even if @code{POST}
   1844 data is available, the first time the callback is
   1845 invoked there won't be upload data, as this is done
   1846 just after MHD parses the headers.  If supported by
   1847 the client and the HTTP version, the application can
   1848 at this point queue an error response to possibly
   1849 avoid the upload entirely. If no response is generated,
   1850 MHD will (if required) automatically send a 100 CONTINUE
   1851 reply to the client.
   1852 
   1853 Afterwards, POST data will be passed to the callback
   1854 to be processed incrementally by the application. The
   1855 application may return @code{MHD_NO} to forcefully
   1856 terminate the TCP connection without generating a
   1857 proper HTTP response. Once all of the upload data has
   1858 been provided to the application, the application
   1859 will be called again with 0 bytes of upload data.
   1860 At this point, a response should be queued to complete
   1861 the handling of the request.
   1862 
   1863 @item upload_data_size
   1864 set initially to the size of the @var{upload_data} provided; this
   1865 callback must update this value to the number of bytes @strong{NOT}
   1866 processed; unless external select is used, the callback maybe
   1867 required to process at least some data.  If the callback fails to
   1868 process data in multi-threaded or internal-select mode and if the
   1869 read-buffer is already at the maximum size that MHD is willing to
   1870 use for reading (about half of the maximum amount of memory allowed
   1871 for the connection), then MHD will abort handling the connection
   1872 and return an internal server error to the client.  In order to
   1873 avoid this, clients must be able to process upload data incrementally
   1874 and reduce the value of @code{upload_data_size}.
   1875 
   1876 @item req_cls
   1877 reference to a pointer, initially set to @code{NULL}, that this callback can
   1878 set to some address and that will be preserved by MHD for future
   1879 calls for this request;
   1880 
   1881 since the access handler may be called many times (i.e., for a
   1882 @code{PUT}/@code{POST} operation with plenty of upload data) this allows
   1883 the application to easily associate some request-specific state;
   1884 
   1885 if necessary, this state can be cleaned up in the global
   1886 @code{MHD_RequestCompletedCallback} (which can be set with the
   1887 @code{MHD_OPTION_NOTIFY_COMPLETED}).
   1888 @end table
   1889 @end deftypefn
   1890 
   1891 
   1892 @deftypefn {Function Pointer} void {*MHD_RequestCompletedCallback} (void *cls, struct MHD_Connectionconnection, void **req_cls, enum MHD_RequestTerminationCode toe)
   1893 Signature of the callback used by MHD to notify the application about
   1894 completed requests.
   1895 
   1896 @table @var
   1897 @item cls
   1898 custom value selected at callback registration time;
   1899 
   1900 @item connection
   1901 connection handle;
   1902 
   1903 @item req_cls
   1904 value as set by the last call to the
   1905 @code{MHD_AccessHandlerCallback};
   1906 
   1907 @item toe
   1908 reason for request termination see @code{MHD_OPTION_NOTIFY_COMPLETED}.
   1909 @end table
   1910 @end deftypefn
   1911 
   1912 
   1913 @deftypefn {Function Pointer} enum MHD_Result {*MHD_KeyValueIterator} (void *cls, enum MHD_ValueKind kind, const char *key, const char *value, size_t value_size)
   1914 Iterator over key-value pairs.  This iterator can be used to iterate
   1915 over all of the cookies, headers, or @code{POST}-data fields of a
   1916 request, and also to iterate over the headers that have been added to a
   1917 response.
   1918 
   1919 @table @var
   1920 @item cls
   1921 custom value specified when iteration was triggered;
   1922 
   1923 @item kind
   1924 kind of the header we are looking at
   1925 
   1926 @item key
   1927 key for the value, can be an empty string
   1928 
   1929 @item value
   1930 value corresponding value, can be NULL
   1931 
   1932 @item value_size
   1933 number of bytes in @code{value}. This argument was introduced in
   1934 @code{MHD_VERSION} 0x00096301 to allow applications to use binary
   1935 zeros in values.  Applications using this argument must ensure that
   1936 they are using a sufficiently recent version of MHD, i.e. by testing
   1937 @code{MHD_get_version()} for values above or equal to 0.9.64.
   1938 Applications that do not need zeros in values and that want to compile
   1939 without warnings against newer versions of MHD should not declare this
   1940 argument and cast the function pointer argument to
   1941 @code{MHD_KeyValueIterator}.
   1942 
   1943 @end table
   1944 
   1945 Return @code{MHD_YES} to continue iterating, @code{MHD_NO} to abort the
   1946 iteration.
   1947 @end deftypefn
   1948 
   1949 
   1950 @deftypefn {Function Pointer} ssize_t {*MHD_ContentReaderCallback} (void *cls, uint64_t pos, char *buf, size_t max)
   1951 Callback used by MHD in order to obtain content.  The callback has to
   1952 copy at most @var{max} bytes of content into @var{buf}.  The total
   1953 number of bytes that has been placed into @var{buf} should be returned.
   1954 
   1955 Note that returning zero will cause MHD to try again.
   1956 Thus, returning zero should only be used in conjunction
   1957 with @code{MHD_suspend_connection()} to avoid busy waiting.
   1958 
   1959 While usually the callback simply returns the number of bytes written
   1960 into @var{buf}, there are two special return value:
   1961 
   1962 @code{MHD_CONTENT_READER_END_OF_STREAM} (-1) should be returned
   1963 for the regular end of transmission (with chunked encoding, MHD will then
   1964 terminate the chunk and send any HTTP footers that might be
   1965 present; without chunked encoding and given an unknown
   1966 response size, MHD will simply close the connection; note
   1967 that while returning @code{MHD_CONTENT_READER_END_OF_STREAM} is not technically
   1968 legal if a response size was specified, MHD accepts this
   1969 and treats it just as @code{MHD_CONTENT_READER_END_WITH_ERROR}.
   1970 
   1971 @code{MHD_CONTENT_READER_END_WITH_ERROR} (-2) is used to indicate a server
   1972 error generating the response; this will cause MHD to simply
   1973 close the connection immediately.  If a response size was
   1974 given or if chunked encoding is in use, this will indicate
   1975 an error to the client.  Note, however, that if the client
   1976 does not know a response size and chunked encoding is not in
   1977 use, then clients will not be able to tell the difference between
   1978 @code{MHD_CONTENT_READER_END_WITH_ERROR} and
   1979 @code{MHD_CONTENT_READER_END_OF_STREAM}.
   1980 This is not a limitation of MHD but rather of the HTTP protocol.
   1981 
   1982 @table @var
   1983 @item cls
   1984 custom value selected at callback registration time;
   1985 
   1986 @item pos
   1987 position in the datastream to access; note that if an
   1988 @code{MHD_Response} object is re-used, it is possible for the same
   1989 content reader to be queried multiple times for the same data; however,
   1990 if an @code{MHD_Response} is not re-used, MHD guarantees that
   1991 @var{pos} will be the sum of all non-negative return values obtained
   1992 from the content reader so far.
   1993 @end table
   1994 
   1995 Return @code{-1} on error (MHD will no longer try to read content and
   1996 instead close the connection with the client).
   1997 @end deftypefn
   1998 
   1999 
   2000 @deftypefn {Function Pointer} void {*MHD_ContentReaderFreeCallback} (void *cls)
   2001 This method is called by MHD if we are done with a content reader.
   2002 It should be used to free resources associated with the content reader.
   2003 @end deftypefn
   2004 
   2005 
   2006 @deftypefn {Function Pointer} enum MHD_Result {*MHD_PostDataIterator} (void *cls, enum MHD_ValueKind kind, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size)
   2007 Iterator over key-value pairs where the value maybe made available in
   2008 increments and/or may not be zero-terminated.  Used for processing
   2009 @code{POST} data.
   2010 
   2011 @table @var
   2012 @item cls
   2013 custom value selected at callback registration time;
   2014 
   2015 @item kind
   2016 type of the value;
   2017 
   2018 @item key
   2019 zero-terminated key for the value;
   2020 
   2021 @item filename
   2022 name of the uploaded file, @code{NULL} if not known;
   2023 
   2024 @item content_type
   2025 mime-type of the data, @code{NULL} if not known;
   2026 
   2027 @item transfer_encoding
   2028 encoding of the data, @code{NULL} if not known;
   2029 
   2030 @item data
   2031 pointer to size bytes of data at the specified offset;
   2032 
   2033 @item off
   2034 offset of data in the overall value;
   2035 
   2036 @item size
   2037 number of bytes in data available.
   2038 @end table
   2039 
   2040 Return @code{MHD_YES} to continue iterating, @code{MHD_NO} to abort the
   2041 iteration.
   2042 @end deftypefn
   2043 
   2044 
   2045 @deftypefn {Function Pointer} void* {*MHD_WebSocketMallocCallback} (size_t buf_len)
   2046 @cindex websocket
   2047 This callback function is used internally by many websocket functions
   2048 for allocating data.
   2049 By default @code{malloc} is used.
   2050 You can use your own allocation function with @code{MHD_websocket_stream_init2}
   2051 if you wish to.
   2052 This can be useful for operating systems like Windows
   2053 where @code{malloc}, @code{realloc} and @code{free} are compiler-dependent.
   2054 You can call the associated @code{malloc} callback of
   2055 a websocket stream with @code{MHD_websocket_malloc}.
   2056 
   2057 @table @var
   2058 @item buf_len
   2059 size of the buffer to allocate in bytes.
   2060 @end table
   2061 
   2062 Return the pointer of the allocated buffer or @code{NULL} on failure.
   2063 @end deftypefn
   2064 
   2065 
   2066 @deftypefn {Function Pointer} void* {*MHD_WebSocketReallocCallback} (void *buf, size_t new_buf_len)
   2067 @cindex websocket
   2068 This callback function is used internally by many websocket
   2069 functions for reallocating data.
   2070 By default @code{realloc} is used.
   2071 You can use your own reallocation function with
   2072 @code{MHD_websocket_stream_init2} if you wish to.
   2073 This can be useful for operating systems like Windows
   2074 where @code{malloc}, @code{realloc} and @code{free} are compiler-dependent.
   2075 You can call the associated @code{realloc} callback of
   2076 a websocket stream with @code{MHD_websocket_realloc}.
   2077 
   2078 @table @var
   2079 @item buf
   2080 current buffer, may be @code{NULL};
   2081 
   2082 @item new_buf_len
   2083 new size of the buffer in bytes.
   2084 @end table
   2085 
   2086 Return the pointer of the reallocated buffer or @code{NULL} on failure.
   2087 On failure the old pointer must remain valid.
   2088 @end deftypefn
   2089 
   2090 
   2091 @deftypefn {Function Pointer} void {*MHD_WebSocketFreeCallback} (void *buf)
   2092 @cindex websocket
   2093 This callback function is used internally by many websocket
   2094 functions for freeing data.
   2095 By default @code{free} is used.
   2096 You can use your own free function with
   2097 @code{MHD_websocket_stream_init2} if you wish to.
   2098 This can be useful for operating systems like Windows
   2099 where @code{malloc}, @code{realloc} and @code{free} are compiler-dependent.
   2100 You can call the associated @code{free} callback of
   2101 a websocket stream with @code{MHD_websocket_free}.
   2102 
   2103 @table @var
   2104 @item cls
   2105 current buffer to free, this may be @code{NULL} then nothing happens.
   2106 @end table
   2107 @end deftypefn
   2108 
   2109 
   2110 @deftypefn {Function Pointer} size_t {*MHD_WebSocketRandomNumberGenerator} (void *cls, void* buf, size_t buf_len)
   2111 @cindex websocket
   2112 This callback function is used for generating random numbers
   2113 for masking payload data in client mode.
   2114 If you use websockets in server mode with @emph{libmicrohttpd} then
   2115 you don't need a random number generator, because
   2116 the server doesn't mask its outgoing messages.
   2117 However if you wish to use a websocket stream in client mode,
   2118 you must pass this callback function to @code{MHD_websocket_stream_init2}.
   2119 
   2120 @table @var
   2121 @item cls
   2122 closure specified in @code{MHD_websocket_stream_init2};
   2123 @item buf
   2124 buffer to fill with random values;
   2125 @item buf_len
   2126 size of buffer in bytes.
   2127 @end table
   2128 
   2129 Return the number of generated random bytes.
   2130 The return value should usually equal to buf_len.
   2131 @end deftypefn
   2132 
   2133 
   2134 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   2135 
   2136 @c ------------------------------------------------------------
   2137 @node microhttpd-init
   2138 @chapter Starting and stopping the server
   2139 
   2140 @deftypefun {void} MHD_set_panic_func (MHD_PanicCallback cb, void *cls)
   2141 Set a handler for fatal errors.
   2142 
   2143 @table @var
   2144 @item cb
   2145 function to call if MHD encounters a fatal internal error.  If no handler was set explicitly, MHD will call @code{abort}.
   2146 
   2147 @item cls
   2148 closure argument for cb; the other arguments are the name of the source file, line number and a string describing the nature of the fatal error (which can be @code{NULL})
   2149 @end table
   2150 @end deftypefun
   2151 
   2152 @deftypefun {struct MHD_Daemon *} MHD_start_daemon (unsigned int flags, unsigned short port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls, ...)
   2153 Start a webserver on the given port.
   2154 
   2155 @table @var
   2156 @item flags
   2157 OR-ed combination of @code{MHD_FLAG} values;
   2158 
   2159 @item port
   2160 port to bind to;
   2161 
   2162 @item apc
   2163 callback to call to check which clients will be allowed to connect; you
   2164 can pass @code{NULL} in which case connections from any @acronym{IP} will be
   2165 accepted;
   2166 
   2167 @item apc_cls
   2168 extra argument to @var{apc};
   2169 
   2170 @item dh
   2171 default handler for all URIs;
   2172 
   2173 @item dh_cls
   2174 extra argument to @var{dh}.
   2175 @end table
   2176 
   2177 Additional arguments are a list of options (type-value pairs,
   2178 terminated with @code{MHD_OPTION_END}). It is mandatory to use
   2179 @code{MHD_OPTION_END} as last argument, even when there are no
   2180 additional arguments.
   2181 
   2182 Return @code{NULL} on error, handle to daemon on success.
   2183 @end deftypefun
   2184 
   2185 
   2186 @deftypefun MHD_socket MHD_quiesce_daemon (struct MHD_Daemon *daemon)
   2187 @cindex quiesce
   2188 Stop accepting connections from the listening socket.  Allows clients
   2189 to continue processing, but stops accepting new connections.  Note
   2190 that the caller is responsible for closing the returned socket;
   2191 however, if MHD is run using threads (anything but external select
   2192 mode), it must not be closed until AFTER @code{MHD_stop_daemon} has
   2193 been called (as it is theoretically possible that an existing thread
   2194 is still using it).
   2195 
   2196 This function is useful in the special case that a listen socket
   2197 is to be migrated to another process (i.e. a newer version of the
   2198 HTTP server) while existing connections should continue to be
   2199 processed until they are finished.
   2200 
   2201 Return @code{-1} on error (daemon not listening), the handle to the
   2202 listen socket otherwise.
   2203 
   2204 @end deftypefun
   2205 
   2206 
   2207 @deftypefun void MHD_stop_daemon (struct MHD_Daemon *daemon)
   2208 Shutdown an HTTP daemon.
   2209 @end deftypefun
   2210 
   2211 
   2212 @deftypefun enum MHD_Result MHD_run (struct MHD_Daemon *daemon)
   2213 Run webserver operations (without blocking unless in client callbacks).
   2214 This method should be called by clients in combination with
   2215 @code{MHD_get_fdset()} if the client-controlled @code{select}-method is used.
   2216 @cindex select
   2217 @cindex poll
   2218 
   2219 This function will work for external @code{poll} and @code{select} mode.
   2220 However, if using external @code{select} mode, you may want to
   2221 instead use @code{MHD_run_from_select}, as it is more efficient.
   2222 
   2223 @table @var
   2224 @item daemon
   2225 daemon to process connections of
   2226 @end table
   2227 
   2228 Return @code{MHD_YES} on success, @code{MHD_NO} if this daemon was not
   2229 started with the right options for this call.
   2230 @end deftypefun
   2231 
   2232 
   2233 @deftypefun enum MHD_Result MHD_run_from_select (struct MHD_Daemon *daemon, const fd_set *read_fd_set, const fd_set *write_fd_set, const fd_set *except_fd_set)
   2234 Run webserver operations given sets of ready socket handles.
   2235 @cindex select
   2236 
   2237 This method should be called by clients in combination with
   2238 @code{MHD_get_fdset} if the client-controlled (external)
   2239 select method is used.
   2240 
   2241 You can use this function instead of @code{MHD_run} if you called
   2242 @code{select} on the result from @code{MHD_get_fdset}.  File descriptors in
   2243 the sets that are not controlled by MHD will be ignored.  Calling
   2244 this function instead of @code{MHD_run} is more efficient as MHD will
   2245 not have to call @code{select} again to determine which operations are
   2246 ready.
   2247 
   2248 @table @var
   2249 @item daemon
   2250 daemon to process connections of
   2251 @item read_fd_set
   2252 set of descriptors that must be ready for reading without blocking
   2253 @item write_fd_set
   2254 set of descriptors that must be ready for writing without blocking
   2255 @item except_fd_set
   2256 ignored, can be NULL
   2257 @end table
   2258 
   2259 Return @code{MHD_YES} on success, @code{MHD_NO} on serious internal
   2260 errors.
   2261 
   2262 @end deftypefun
   2263 
   2264 
   2265 
   2266 @deftypefun void MHD_add_connection (struct MHD_Daemon *daemon, int client_socket, const struct sockaddr *addr, socklen_t addrlen)
   2267 Add another client connection to the set of connections
   2268 managed by MHD.  This API is usually not needed (since
   2269 MHD will accept inbound connections on the server socket).
   2270 Use this API in special cases, for example if your HTTP
   2271 server is behind NAT and needs to connect out to the
   2272 HTTP client, or if you are building a proxy.
   2273 
   2274 If you use this API in conjunction with a internal select or a thread
   2275 pool, you must set the option @code{MHD_USE_ITC} to
   2276 ensure that the freshly added connection is immediately processed by
   2277 MHD.
   2278 
   2279 The given client socket will be managed (and closed!) by MHD after
   2280 this call and must no longer be used directly by the application
   2281 afterwards.
   2282 
   2283 @table @var
   2284 @item daemon
   2285 daemon that manages the connection
   2286 @item client_socket
   2287 socket to manage (MHD will expect to receive an HTTP request from this socket next).
   2288 @item addr
   2289 IP address of the client
   2290 @item addrlen
   2291 number of bytes in addr
   2292 @end table
   2293 
   2294 This function will return @code{MHD_YES} on success,
   2295 @code{MHD_NO} if this daemon could
   2296 not handle the connection (i.e. malloc failed, etc).
   2297 The socket will be closed in any case; 'errno' is set
   2298 to indicate further details about the error.
   2299 @end deftypefun
   2300 
   2301 
   2302 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   2303 
   2304 @c -----------------------------------------------------------
   2305 @node microhttpd-inspect
   2306 @chapter Implementing external @code{select}
   2307 
   2308 
   2309 @deftypefun enum MHD_Result MHD_get_fdset (struct MHD_Daemon *daemon, fd_set * read_fd_set, fd_set * write_fd_set, fd_set * except_fd_set, int *max_fd)
   2310 Obtain the @code{select()} sets for this daemon. The daemon's socket
   2311 is added to @var{read_fd_set}. The list of currently existent
   2312 connections is scanned and their file descriptors added to the correct
   2313 set.
   2314 
   2315 When calling this function, FD_SETSIZE is assumed to be platform's
   2316 default.  If you changed FD_SETSIZE for your application,
   2317 you should use @code{MHD_get_fdset2()} instead.
   2318 
   2319 This function should only be called in when MHD is configured to use
   2320 external select with @code{select()} or with @code{epoll()}.  In
   2321 the latter case, it will only add the single @code{epoll()} file
   2322 descriptor used by MHD to the sets.
   2323 
   2324 After the call completed successfully: the variable referenced by
   2325 @var{max_fd} references the file descriptor with highest integer
   2326 identifier. The variable must be set to zero before invoking this
   2327 function.
   2328 
   2329 Return @code{MHD_YES} on success, @code{MHD_NO} if: the arguments are
   2330 invalid (example: @code{NULL} pointers); this daemon was not started with
   2331 the right options for this call.
   2332 @end deftypefun
   2333 
   2334 
   2335 @deftypefun enum MHD_Result MHD_get_fdset2 (struct MHD_Daemon *daemon, fd_set * read_fd_set, fd_set * write_fd_set, fd_set * except_fd_set, int *max_fd, unsigned int fd_setsize)
   2336 Like @code{MHD_get_fdset()}, except that you can manually specify the value of FD_SETSIZE used by your application.
   2337 @end deftypefun
   2338 
   2339 
   2340 @deftypefun enum MHD_Result MHD_get_timeout (struct MHD_Daemon *daemon, unsigned long long *timeout)
   2341 @cindex timeout
   2342 Obtain timeout value for select for this daemon (only needed if
   2343 connection timeout is used).  The returned value is how many
   2344 milliseconds @code{select} should at most block, not the timeout value
   2345 set for connections.  This function must not be called if the
   2346 @code{MHD_USE_THREAD_PER_CONNECTION} mode is in use (since then it is
   2347 not meaningful to ask for a timeout, after all, there is concurrenct
   2348 activity).  The function must also not be called by user-code if
   2349 @code{MHD_USE_INTERNAL_POLLING_THREAD} is in use.  In the latter case, the
   2350 behavior is undefined.
   2351 
   2352 @table @var
   2353 @item daemon
   2354 which daemon to obtain the timeout from.
   2355 @item timeout
   2356 will be set to the timeout (in milliseconds).
   2357 @end table
   2358 
   2359 Return @code{MHD_YES} on success, @code{MHD_NO} if timeouts are not used
   2360 (or no connections exist that would necessitate the use of a timeout
   2361 right now).
   2362 @end deftypefun
   2363 
   2364 
   2365 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   2366 
   2367 @c -----------------------------------------------------------
   2368 @node microhttpd-requests
   2369 @chapter Handling requests
   2370 
   2371 
   2372 @deftypefun int MHD_get_connection_values (struct MHD_Connection *connection, enum MHD_ValueKind kind, MHD_KeyValueIterator iterator, void *iterator_cls)
   2373 Get all the headers matching @var{kind} from the request.  The @var{kind}
   2374 argument can be a bitmask, ORing the various header kinds that are
   2375 requested.
   2376 
   2377 The @var{iterator} callback is invoked once for each header, with
   2378 @var{iterator_cls} as first argument.  After version 0.9.19, the
   2379 headers are iterated in the same order as they were received from
   2380 the network; previous versions iterated over the headers in reverse
   2381 order.
   2382 
   2383 @code{MHD_get_connection_values} returns the number of entries
   2384 iterated over; this can be less than the number of headers if, while
   2385 iterating, @var{iterator} returns @code{MHD_NO}.
   2386 
   2387 @var{iterator} can be @code{NULL}: in this case this function just counts
   2388 and returns the number of headers.
   2389 
   2390 In the case of @code{MHD_GET_ARGUMENT_KIND}, the @var{value} argument
   2391 will be @code{NULL} if the URL contained a key without an equals operator.
   2392 For example, for a HTTP request to the URL ``http://foo/bar?key'', the
   2393 @var{value} argument is @code{NULL}; in contrast, a HTTP request to the URL
   2394 ``http://foo/bar?key='', the @var{value} argument is the empty string.
   2395 The normal case is that the URL contains ``http://foo/bar?key=value''
   2396 in which case @var{value} would be the string ``value'' and @var{key}
   2397 would contain the string ``key''.
   2398 @end deftypefun
   2399 
   2400 
   2401 @deftypefun enum MHD_Result MHD_set_connection_value (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key, const char *value)
   2402 This function can be used to append an entry to
   2403 the list of HTTP headers of a connection (so that the
   2404 @code{MHD_get_connection_values function} will return
   2405 them -- and the MHD PostProcessor will also
   2406 see them).  This maybe required in certain
   2407 situations (see Mantis #1399) where (broken)
   2408 HTTP implementations fail to supply values needed
   2409 by the post processor (or other parts of the
   2410 application).
   2411 
   2412 This function MUST only be called from within
   2413 the MHD_AccessHandlerCallback (otherwise, access
   2414 maybe improperly synchronized).  Furthermore,
   2415 the client must guarantee that the key and
   2416 value arguments are 0-terminated strings that
   2417 are NOT freed until the connection is closed.
   2418 (The easiest way to do this is by passing only
   2419 arguments to permanently allocated strings.).
   2420 
   2421 @var{connection} is the connection for which
   2422 the entry for @var{key} of the given @var{kind}
   2423 should be set to the given @var{value}.
   2424 
   2425 The function returns @code{MHD_NO} if the operation
   2426 could not be performed due to insufficient memory
   2427 and @code{MHD_YES} on success.
   2428 @end deftypefun
   2429 
   2430 
   2431 @deftypefun {const char *} MHD_lookup_connection_value (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key)
   2432 Get a particular header value.  If multiple values match the
   2433 @var{kind}, return one of them (the ``first'', whatever that means).
   2434 @var{key} must reference a zero-terminated ASCII-coded string
   2435 representing the header to look for: it is compared against the
   2436 headers using (basically) @code{strcasecmp()}, so case is ignored.
   2437 @end deftypefun
   2438 
   2439 @deftypefun {const char *} MHD_lookup_connection_value_n (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key, size_t key_size, const char **value_ptr, size_t *value_size_ptr)
   2440 Get a particular header value.  If multiple values match the
   2441 @var{kind}, return one of them (the ``first'', whatever that means).
   2442 @var{key} must reference an ASCII-coded string
   2443 representing the header to look for: it is compared against the
   2444 headers using (basically) @code{strncasecmp()}, so case is ignored.
   2445 The @var{value_ptr} is set to the address of the value found,
   2446 and @var{value_size_ptr} is set to the number of bytes in the
   2447 value.
   2448 @end deftypefun
   2449 
   2450 
   2451 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   2452 
   2453 @c ------------------------------------------------------------
   2454 @node microhttpd-responses
   2455 @chapter Building responses to requests
   2456 
   2457 
   2458 @noindent
   2459 Response objects handling by MHD is asynchronous with respect to the
   2460 application execution flow. Instances of the @code{MHD_Response}
   2461 structure are not associated to a daemon and neither to a client
   2462 connection: they are managed with reference counting.
   2463 
   2464 In the simplest case: we allocate a new @code{MHD_Response} structure
   2465 for each response, we use it once and finally we destroy it.
   2466 
   2467 MHD allows more efficient resources usages.
   2468 
   2469 Example: we allocate a new @code{MHD_Response} structure for each
   2470 response @strong{kind}, we use it every time we have to give that
   2471 response and we finally destroy it only when the daemon shuts down.
   2472 
   2473 @menu
   2474 * microhttpd-response enqueue:: Enqueuing a response.
   2475 * microhttpd-response create::  Creating a response object.
   2476 * microhttpd-response headers:: Adding headers to a response.
   2477 * microhttpd-response options:: Setting response options.
   2478 * microhttpd-response inspect:: Inspecting a response object.
   2479 * microhttpd-response upgrade:: Creating a response for protocol upgrades.
   2480 @end menu
   2481 
   2482 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   2483 
   2484 @c ------------------------------------------------------------
   2485 @node microhttpd-response enqueue
   2486 @section Enqueuing a response
   2487 
   2488 
   2489 @deftypefun enum MHD_Result MHD_queue_response (struct MHD_Connection *connection, unsigned int status_code, struct MHD_Response *response)
   2490 Queue a response to be transmitted to the client as soon as possible
   2491 but only after MHD_AccessHandlerCallback returns.  This function
   2492 checks that it is legal to queue a response at this time for the
   2493 given connection.  It also increments the internal reference
   2494 counter for the response object (the counter will be decremented
   2495 automatically once the response has been transmitted).
   2496 
   2497 @table @var
   2498 @item connection
   2499 the connection identifying the client;
   2500 
   2501 @item status_code
   2502 HTTP status code (i.e. @code{200} for OK);
   2503 
   2504 @item response
   2505 response to transmit.
   2506 @end table
   2507 
   2508 Return @code{MHD_YES} on success or if message has been queued.  Return
   2509 @code{MHD_NO}: if arguments are invalid (example: @code{NULL} pointer); on
   2510 error (i.e. reply already sent).
   2511 @end deftypefun
   2512 
   2513 
   2514 @deftypefun void MHD_destroy_response (struct MHD_Response *response)
   2515 Destroy a response object and associated resources (decrement the
   2516 reference counter).  Note that MHD may keep some of the resources
   2517 around if the response is still in the queue for some clients, so the
   2518 memory may not necessarily be freed immediately.
   2519 @end deftypefun
   2520 
   2521 
   2522 An explanation of reference counting@footnote{Note to readers acquainted
   2523 to the Tcl API: reference counting on @code{MHD_Connection}
   2524 structures is handled in the same way as Tcl handles @code{Tcl_Obj}
   2525 structures through @code{Tcl_IncrRefCount()} and
   2526 @code{Tcl_DecrRefCount()}.}:
   2527 
   2528 @enumerate
   2529 @item
   2530 a @code{MHD_Response} object is allocated:
   2531 
   2532 @example
   2533 struct MHD_Response * response = MHD_create_response_from_buffer(...);
   2534 /* here: reference counter = 1 */
   2535 @end example
   2536 
   2537 @item
   2538 the @code{MHD_Response} object is enqueued in a @code{MHD_Connection}:
   2539 
   2540 @example
   2541 MHD_queue_response(connection, , response);
   2542 /* here: reference counter = 2 */
   2543 @end example
   2544 
   2545 @item
   2546 the creator of the response object discharges responsibility for it:
   2547 
   2548 @example
   2549 MHD_destroy_response(response);
   2550 /* here: reference counter = 1 */
   2551 @end example
   2552 
   2553 @item
   2554 the daemon handles the connection sending the response's data to the
   2555 client then decrements the reference counter by calling
   2556 @code{MHD_destroy_response()}: the counter's value drops to zero and
   2557 the @code{MHD_Response} object is released.
   2558 @end enumerate
   2559 
   2560 
   2561 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   2562 
   2563 @c ------------------------------------------------------------
   2564 @node microhttpd-response create
   2565 @section Creating a response object
   2566 
   2567 
   2568 @deftypefun {struct MHD_Response *} MHD_create_response_from_callback (uint64_t size, size_t block_size, MHD_ContentReaderCallback crc, void *crc_cls, MHD_ContentReaderFreeCallback crfc)
   2569 Create a response object.  The response object can be extended with
   2570 header information and then it can be used any number of times.
   2571 
   2572 @table @var
   2573 @item size
   2574 size of the data portion of the response, @code{-1} for unknown;
   2575 
   2576 @item block_size
   2577 preferred block size for querying @var{crc} (advisory only, MHD may
   2578 still call @var{crc} using smaller chunks); this is essentially the
   2579 buffer size used for @acronym{IO}, clients should pick a value that is
   2580 appropriate for @acronym{IO} and memory performance requirements;
   2581 
   2582 @item crc
   2583 callback to use to obtain response data;
   2584 
   2585 @item crc_cls
   2586 extra argument to @var{crc};
   2587 
   2588 @item crfc
   2589 callback to call to free @var{crc_cls} resources.
   2590 @end table
   2591 
   2592 Return @code{NULL} on error (i.e. invalid arguments, out of memory).
   2593 @end deftypefun
   2594 
   2595 
   2596 
   2597 @deftypefun {struct MHD_Response *} MHD_create_response_from_fd (uint64_t size, int fd)
   2598 Create a response object.  The response object can be extended with
   2599 header information and then it can be used any number of times.
   2600 
   2601 @table @var
   2602 @item size
   2603 size of the data portion of the response (should be smaller or equal to the
   2604 size of the file)
   2605 
   2606 @item fd
   2607 file descriptor referring to a file on disk with the data; will be
   2608 closed when response is destroyed; note that 'fd' must be an actual
   2609 file descriptor (not a pipe or socket) since MHD might use 'sendfile'
   2610 or 'seek' on it.  The descriptor should be in blocking-IO mode.
   2611 @end table
   2612 
   2613 Return @code{NULL} on error (i.e. invalid arguments, out of memory).
   2614 @end deftypefun
   2615 
   2616 
   2617 @deftypefun {struct MHD_Response *} MHD_create_response_from_pipe (int fd)
   2618 Create a response object.  The response object can be extended with
   2619 header information and then it can be used ONLY ONCE.
   2620 
   2621 @table @var
   2622 @item fd
   2623 file descriptor of the read-end of the pipe; will be
   2624 closed when response is destroyed.
   2625 The descriptor should be in blocking-IO mode.
   2626 @end table
   2627 
   2628 Return @code{NULL} on error (i.e. out of memory).
   2629 @end deftypefun
   2630 
   2631 
   2632 @deftypefun {struct MHD_Response *} MHD_create_response_from_fd_at_offset (size_t size, int fd, off_t offset)
   2633 Create a response object.  The response object can be extended with
   2634 header information and then it can be used any number of times.
   2635 Note that you need to be a bit careful about @code{off_t} when
   2636 writing this code.  Depending on your platform, MHD is likely
   2637 to have been compiled with support for 64-bit files.  When you
   2638 compile your own application, you must make sure that @code{off_t}
   2639 is also a 64-bit value.  If not, your compiler may pass a 32-bit
   2640 value as @code{off_t}, which will result in 32-bits of garbage.
   2641 
   2642 If you use the autotools, use the @code{AC_SYS_LARGEFILE} autoconf
   2643 macro and make sure to include the generated @file{config.h} file
   2644 before @file{microhttpd.h} to avoid problems.  If you do not have a
   2645 build system and only want to run on a GNU/Linux system, you could
   2646 also use
   2647 @verbatim
   2648 #define _FILE_OFFSET_BITS 64
   2649 #include <sys/types.h>
   2650 #include <sys/stat.h>
   2651 #include <fcntl.h>
   2652 #include <microhttpd.h>
   2653 @end verbatim
   2654 to ensure 64-bit @code{off_t}.  Note that if your operating system
   2655 does not support 64-bit files, MHD will be compiled with a 32-bit
   2656 @code{off_t} (in which case the above would be wrong).
   2657 
   2658 @table @var
   2659 @item size
   2660 size of the data portion of the response (number of bytes to transmit from the
   2661 file starting at offset).
   2662 
   2663 @item fd
   2664 file descriptor referring to a file on disk with the data; will be
   2665 closed when response is destroyed; note that 'fd' must be an actual
   2666 file descriptor (not a pipe or socket) since MHD might use 'sendfile'
   2667 or 'seek' on it.    The descriptor should be in blocking-IO mode.
   2668 
   2669 @item offset
   2670 offset to start reading from in the file
   2671 @end table
   2672 
   2673 Return @code{NULL} on error (i.e. invalid arguments, out of memory).
   2674 @end deftypefun
   2675 
   2676 
   2677 @deftypefun {struct MHD_Response *} MHD_create_response_from_buffer (size_t size, void *data, enum MHD_ResponseMemoryMode mode)
   2678 Create a response object.  The response object can be extended with
   2679 header information and then it can be used any number of times.
   2680 
   2681 @table @var
   2682 @item size
   2683 size of the data portion of the response;
   2684 
   2685 @item buffer
   2686 the data itself;
   2687 
   2688 @item mode
   2689 memory management options for buffer; use
   2690 MHD_RESPMEM_PERSISTENT if the buffer is static/global memory,
   2691 use MHD_RESPMEM_MUST_FREE if the buffer is heap-allocated and
   2692 should be freed by MHD and MHD_RESPMEM_MUST_COPY if the
   2693 buffer is in transient memory (i.e. on the stack) and must
   2694 be copied by MHD;
   2695 @end table
   2696 
   2697 Return @code{NULL} on error (i.e. invalid arguments, out of memory).
   2698 @end deftypefun
   2699 
   2700 
   2701 @deftypefun {struct MHD_Response *} MHD_create_response_from_buffer_with_free_callback (size_t size, void *data,  MHD_ContentReaderFreeCallback crfc)
   2702 Create a response object.  The buffer at the end must be free'd
   2703 by calling the @var{crfc} function.
   2704 
   2705 @table @var
   2706 @item size
   2707 size of the data portion of the response;
   2708 
   2709 @item buffer
   2710 the data itself;
   2711 
   2712 @item crfc
   2713 function to call at the end to free memory allocated at @var{buffer}.
   2714 @end table
   2715 
   2716 Return @code{NULL} on error (i.e. invalid arguments, out of memory).
   2717 @end deftypefun
   2718 
   2719 @deftypefun {struct MHD_Response *} MHD_create_response_from_data (size_t size, void *data, int must_free, int must_copy)
   2720 Create a response object.  The response object can be extended with
   2721 header information and then it can be used any number of times.
   2722 This function is deprecated, use @code{MHD_create_response_from_buffer} instead.
   2723 
   2724 @table @var
   2725 @item size
   2726 size of the data portion of the response;
   2727 
   2728 @item data
   2729 the data itself;
   2730 
   2731 @item must_free
   2732 if true: MHD should free data when done;
   2733 
   2734 @item must_copy
   2735 if true: MHD allocates a block of memory and use it to make a copy of
   2736 @var{data} embedded in the returned @code{MHD_Response} structure;
   2737 handling of the embedded memory is responsibility of MHD; @var{data}
   2738 can be released anytime after this call returns.
   2739 @end table
   2740 
   2741 Return @code{NULL} on error (i.e. invalid arguments, out of memory).
   2742 @end deftypefun
   2743 
   2744 
   2745 Example: create a response from a statically allocated string:
   2746 
   2747 @example
   2748 const char * data = "<html><body><p>Error!</p></body></html>";
   2749 
   2750 struct MHD_Connection * connection = ...;
   2751 struct MHD_Response *   response;
   2752 
   2753 response = MHD_create_response_from_buffer (strlen(data), data,
   2754                                             MHD_RESPMEM_PERSISTENT);
   2755 MHD_queue_response(connection, 404, response);
   2756 MHD_destroy_response(response);
   2757 @end example
   2758 
   2759 
   2760 @deftypefun {struct MHD_Response *} MHD_create_response_from_iovec (const struct MHD_IoVec *iov, int iovcnt, MHD_ContentReaderFreeCallback crfc, void *cls)
   2761 Create a response object from an array of memory buffers.
   2762 The response object can be extended with header information and then be used
   2763 any number of times.
   2764 @table @var
   2765 @item iov
   2766 the array for response data buffers, an internal copy of this will be made; however, note that the data pointed to by the @var{iov} is not copied and must be preserved unchanged at the given locations until the response is no longer in use and the @var{crfc} is called;
   2767 
   2768 @item iovcnt
   2769 the number of elements in @var{iov};
   2770 
   2771 @item crfc
   2772 the callback to call to free resources associated with @var{iov};
   2773 
   2774 @item cls
   2775 the argument to @var{crfc};
   2776 @end table
   2777 
   2778 Return @code{NULL} on error (i.e. invalid arguments, out of memory).
   2779 @end deftypefun
   2780 
   2781 
   2782 
   2783 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   2784 
   2785 @c ------------------------------------------------------------
   2786 @node microhttpd-response headers
   2787 @section Adding headers to a response
   2788 
   2789 
   2790 @deftypefun enum MHD_Result MHD_add_response_header (struct MHD_Response *response, const char *header, const char *content)
   2791 Add a header line to the response. The strings referenced by
   2792 @var{header} and @var{content} must be zero-terminated and they are
   2793 duplicated into memory blocks embedded in @var{response}.
   2794 
   2795 Notice that the strings must not hold newlines, carriage returns or tab
   2796 chars.
   2797 
   2798 MHD_add_response_header() prevents applications from setting a
   2799 ``Transfer-Encoding'' header to values other than ``identity'' or
   2800 ``chunked'' as other transfer encodings are not supported by MHD. Note
   2801 that usually MHD will pick the transfer encoding correctly
   2802 automatically, but applications can use the header to force a
   2803 particular behavior.
   2804 
   2805 MHD_add_response_header() also prevents applications from setting a
   2806 ``Content-Length'' header. MHD will automatically set a correct
   2807 ``Content-Length'' header if it is possible and allowed.
   2808 
   2809 Return @code{MHD_NO} on error (i.e. invalid header or content format or
   2810 memory allocation error).
   2811 @end deftypefun
   2812 
   2813 
   2814 @deftypefun enum MHD_Result MHD_add_response_footer (struct MHD_Response *response, const char *footer, const char *content)
   2815 Add a footer line to the response. The strings referenced by
   2816 @var{footer} and @var{content} must be zero-terminated and they are
   2817 duplicated into memory blocks embedded in @var{response}.
   2818 
   2819 Notice that the strings must not hold newlines, carriage returns or tab
   2820 chars.  You can add response footers at any time before signalling the
   2821 end of the response to MHD (not just before calling 'MHD_queue_response').
   2822 Footers are useful for adding cryptographic checksums to the reply or to
   2823 signal errors encountered during data generation.  This call was introduced
   2824 in MHD 0.9.3.
   2825 
   2826 Return @code{MHD_NO} on error (i.e. invalid header or content format or
   2827 memory allocation error).
   2828 @end deftypefun
   2829 
   2830 
   2831 
   2832 @deftypefun enum MHD_Result MHD_del_response_header (struct MHD_Response *response, const char *header, const char *content)
   2833 Delete a header (or footer) line from the response.  Return @code{MHD_NO} on error
   2834 (arguments are invalid or no such header known).
   2835 @end deftypefun
   2836 
   2837 
   2838 @c ------------------------------------------------------------
   2839 @node microhttpd-response options
   2840 @section Setting response options
   2841 
   2842 
   2843 @deftypefun enum MHD_Result MHD_set_response_options (struct MHD_Response *response, enum MHD_ResponseFlags flags, ...)
   2844 Set special flags and options for a response.
   2845 
   2846 Calling this functions sets the given flags and options for the response.
   2847 
   2848 @table @var
   2849 @item response
   2850 which response should be modified;
   2851 
   2852 @item flags
   2853 flags to set for the response;
   2854 
   2855 @end table
   2856 
   2857 Additional arguments are a list of options (type-value pairs,
   2858 terminated with @code{MHD_RO_END}). It is mandatory to use
   2859 @code{MHD_RO_END} as last argument, even when there are no
   2860 additional arguments.
   2861 
   2862 Return @code{MHD_NO} on error, @code{MHD_YES} on success.
   2863 @end deftypefun
   2864 
   2865 
   2866 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   2867 
   2868 @c ------------------------------------------------------------
   2869 @node microhttpd-response inspect
   2870 @section Inspecting a response object
   2871 
   2872 
   2873 @deftypefun int MHD_get_response_headers (struct MHD_Response *response, MHD_KeyValueIterator iterator, void *iterator_cls)
   2874 Get all of the headers added to a response.
   2875 
   2876 Invoke the @var{iterator} callback for each header in the response,
   2877 using @var{iterator_cls} as first argument. Return number of entries
   2878 iterated over.  @var{iterator} can be @code{NULL}: in this case the function
   2879 just counts headers.
   2880 
   2881 @var{iterator} should not modify the its key and value arguments, unless
   2882 we know what we are doing.
   2883 @end deftypefun
   2884 
   2885 
   2886 @deftypefun {const char *} MHD_get_response_header (struct MHD_Response *response, const char *key)
   2887 Find and return a pointer to the value of a particular header from the
   2888 response.  @var{key} must reference a zero-terminated string
   2889 representing the header to look for. The search is case sensitive.
   2890 Return @code{NULL} if header does not exist or @var{key} is @code{NULL}.
   2891 
   2892 We should not modify the value, unless we know what we are doing.
   2893 @end deftypefun
   2894 
   2895 
   2896 @c ------------------------------------------------------------
   2897 @node microhttpd-response upgrade
   2898 @section Creating a response for protocol upgrades
   2899 @cindex WebSockets
   2900 @cindex Upgrade
   2901 @cindex HTTP2
   2902 @cindex RFC2817
   2903 
   2904 With RFC 2817 a mechanism to switch protocols within HTTP was
   2905 introduced.  Here, a client sends a request with a ``Connection:
   2906 Upgrade'' header.  The server responds with a ``101 Switching
   2907 Protocols'' response header, after which the two parties begin to
   2908 speak a different (non-HTTP) protocol over the TCP connection.
   2909 
   2910 This mechanism is used for upgrading HTTP 1.1 connections to HTTP2 or
   2911 HTTPS, as well as for implementing WebSockets.  Which protocol
   2912 upgrade is performed is negotiated between server and client in
   2913 additional headers, in particular the ``Upgrade'' header.
   2914 
   2915 MHD supports switching protocols using this mechanism only if the
   2916 @code{MHD_ALLOW_SUSPEND_RESUME} flag has been set when starting
   2917 the daemon.  If this flag has been set, applications can upgrade
   2918 a connection by queueing a response (using the
   2919 @code{MHD_HTTP_SWITCHING_PROTOCOLS} status code) which must
   2920 have been created with the following function:
   2921 
   2922 
   2923 @deftypefun enum MHD_Result MHD_create_response_for_upgrade (MHD_UpgradeHandler upgrade_handler, void *upgrade_handler_cls)
   2924 Create a response suitable for switching protocols.  Returns @code{MHD_YES} on success.  @code{upgrade_handler} must not be @code{NULL}.
   2925 
   2926 When creating this type of response, the ``Connection: Upgrade''
   2927 header will be set automatically for you.  MHD requires that you
   2928 additionally set an ``Upgrade:'' header.  The ``Upgrade'' header
   2929 must simply exist, the specific value is completely up to the
   2930 application.
   2931 
   2932 @end deftypefun
   2933 
   2934 The @code{upgrade_handler} argument to the above has the following type:
   2935 
   2936 
   2937 @deftypefn {Function Pointer} void {*MHD_UpgradeHandler} (void *cls, struct MHD_Connection *connection, const char *extra_in, size_t extra_in_size, MHD_socket sock, struct MHD_UpgradeResponseHandle *urh)
   2938 This function will be called once MHD has transmitted the header of the response to the connection that is being upgraded.  At this point, the application is expected to take over the socket @code{sock} and speak the non-HTTP protocol to which the connection was upgraded.  MHD will no longer use the socket; this includes handling timeouts.  The application must call @code{MHD_upgrade_action} with an upgrade action of @code{MHD_UPGRADE_ACTION_CLOSE} when it is done processing the connection to close the socket.  The application must not call @code{MHD_stop_daemon} on the respective daemon as long as it is still handling the connection.  The arguments given to the @code{upgrade_handler} have the following meaning:
   2939 
   2940 @table @var
   2941 @item cls
   2942 matches the @code{upgrade_handler_cls} that was given to @code{MHD_create_response_for_upgrade}
   2943 @item connection
   2944 identifies the connection that is being upgraded;
   2945 
   2946 @item req_cls
   2947 last value left in `*req_cls` in the `MHD_AccessHandlerCallback`
   2948 
   2949 @item extra_in
   2950 buffer of bytes MHD read ``by accident'' from the socket already.  This can happen if the client eagerly transmits more than just the HTTP request.   The application should treat these as if it had read them from the socket.
   2951 
   2952 @item extra_in_size
   2953 number of bytes in @code{extra_in}
   2954 
   2955 @item sock
   2956 the socket which the application can now use directly for some bi-directional communication with the client. The application can henceforth use @code{recv()} and @code{send()} or @code{read()} and @code{write()} system calls on the socket.  However, @code{ioctl()} and @code{setsockopt()} functions will not work as expected when using HTTPS.  Such operations may be supported in the future via @code{MHD_upgrade_action}.   Most importantly, the application must never call @code{close()} on this socket.  Closing the socket must be done using @code{MHD_upgrade_action}.  However, while close is forbidden, the application may call @code{shutdown()} on the socket.
   2957 
   2958 @item urh
   2959 argument for calls to @code{MHD_upgrade_action}.  Applications must eventually use this function to perform the @code{close()} action on the socket.
   2960 @end table
   2961 
   2962 @end deftypefn
   2963 
   2964 @deftypefun enum MHD_Result MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh, enum MHD_UpgradeAction action, ...)
   2965 Perform special operations related to upgraded connections.
   2966 
   2967 @table @var
   2968 @item urh
   2969 identifies the upgraded connection to perform an action on
   2970 
   2971 @item action
   2972 specifies the action to perform; further arguments to the function depend on the specifics of the action.
   2973 @end table
   2974 
   2975 @end deftypefun
   2976 
   2977 
   2978 @deftp {Enumeration} MHD_UpgradeAction
   2979 Set of actions to be performed on upgraded connections.  Passed as an argument to
   2980 @code{MHD_upgrade_action()}.
   2981 
   2982 @table @code
   2983 @item MHD_UPGRADE_ACTION_CLOSE
   2984 Closes the connection.  Must be called once the application is done with the client.  Takes no additional arguments.
   2985 @item MHD_UPGRADE_ACTION_CORK_ON
   2986 Enable corking on the underlying socket.
   2987 @item MHD_UPGRADE_ACTION_CORK_OFF
   2988 Disable corking on the underlying socket.
   2989 
   2990 @end table
   2991 @end deftp
   2992 
   2993 
   2994 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   2995 
   2996 @c ------------------------------------------------------------
   2997 @node microhttpd-flow
   2998 @chapter Flow control.
   2999 
   3000 @noindent
   3001 Sometimes it may be possible that clients upload data faster
   3002 than an application can process it, or that an application
   3003 needs an extended period of time to generate a response.
   3004 If @code{MHD_USE_THREAD_PER_CONNECTION} is used, applications
   3005 can simply deal with this by performing their logic within the
   3006 thread and thus effectively blocking connection processing
   3007 by MHD.  In all other modes, blocking logic must not be
   3008 placed within the callbacks invoked by MHD as this would also
   3009 block processing of other requests, as a single thread may be
   3010 responsible for tens of thousands of connections.
   3011 
   3012 Instead, applications using thread modes other than
   3013 @code{MHD_USE_THREAD_PER_CONNECTION} should use the
   3014 following functions to perform flow control.
   3015 
   3016 @deftypefun enum MHD_Result MHD_suspend_connection (struct MHD_Connection *connection)
   3017 Suspend handling of network data for a given connection.  This can
   3018 be used to dequeue a connection from MHD's event loop (external
   3019 select, internal select or thread pool; not applicable to
   3020 thread-per-connection!) for a while.
   3021 
   3022 If you use this API in conjunction with a internal select or a
   3023 thread pool, you must set the option @code{MHD_ALLOW_SUSPEND_RESUME} to
   3024 ensure that a resumed connection is immediately processed by MHD.
   3025 
   3026 Suspended connections continue to count against the total number of
   3027 connections allowed (per daemon, as well as per IP, if such limits
   3028 are set).  Suspended connections will NOT time out; timeouts will
   3029 restart when the connection handling is resumed.  While a
   3030 connection is suspended, MHD will not detect disconnects by the
   3031 client.
   3032 
   3033 The only safe time to suspend a connection is from the
   3034 @code{MHD_AccessHandlerCallback} or from the respective
   3035 @code{MHD_ContentReaderCallback} (but in this case the
   3036 response object must not be shared among multiple
   3037 connections).
   3038 
   3039 When suspending from the @code{MHD_AccessHandlerCallback}
   3040 you MUST afterwards return @code{MHD_YES} from the access handler
   3041 callback (as MHD_NO would imply to both close and suspend
   3042 the connection, which is not allowed).
   3043 
   3044 Finally, it is an API violation to call @code{MHD_stop_daemon} while
   3045 having suspended connections (this will at least create memory and
   3046 socket leaks or lead to undefined behavior).  You must explicitly
   3047 resume all connections before stopping the daemon.
   3048 
   3049 @table @var
   3050 @item connection
   3051 the connection to suspend
   3052 @end table
   3053 @end deftypefun
   3054 
   3055 @deftypefun enum MHD_Result MHD_resume_connection (struct MHD_Connection *connection)
   3056 Resume handling of network data for suspended connection.  It is safe
   3057 to resume a suspended connection at any time.  Calling this function
   3058 on a connection that was not previously suspended will result in
   3059 undefined behavior.
   3060 
   3061 If you are using this function in ``external'' select mode, you must
   3062 make sure to run @code{MHD_run} afterwards (before again calling
   3063 @code{MHD_get_fdset}), as otherwise the change may not be reflected in
   3064 the set returned by @code{MHD_get_fdset} and you may end up with a
   3065 connection that is stuck until the next network activity.
   3066 
   3067 You can check whether a connection is currently suspended using
   3068 @code{MHD_get_connection_info} by querying for
   3069 @code{MHD_CONNECTION_INFO_CONNECTION_SUSPENDED}.
   3070 
   3071 @table @var
   3072 @item connection
   3073 the connection to resume
   3074 @end table
   3075 @end deftypefun
   3076 
   3077 
   3078 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   3079 
   3080 @c ------------------------------------------------------------
   3081 @node microhttpd-dauth
   3082 @chapter Utilizing Authentication
   3083 
   3084 @noindent
   3085 MHD support three types of client authentication.
   3086 
   3087 Basic authentication uses a simple authentication method based
   3088 on BASE64 algorithm. Username and password are exchanged in clear
   3089 between the client and the server, so this method must only be used
   3090 for non-sensitive content or when the session is protected with https.
   3091 When using basic authentication MHD will have access to the clear
   3092 password, possibly allowing to create a chained authentication
   3093 toward an external authentication server.
   3094 
   3095 Digest authentication uses a one-way authentication method based
   3096 on MD5 hash algorithm. Only the hash will transit over the network,
   3097 hence protecting the user password. The nonce will prevent replay
   3098 attacks. This method is appropriate for general use, especially
   3099 when https is not used to encrypt the session.
   3100 
   3101 Client certificate authentication uses a X.509 certificate from
   3102 the client. This is the strongest authentication mechanism but it
   3103 requires the use of HTTPS. Client certificate authentication can
   3104 be used simultaneously with Basic or Digest Authentication in order
   3105 to provide a two levels authentication (like for instance separate
   3106 machine and user authentication).  A code example for using
   3107 client certificates is presented in the MHD tutorial.
   3108 
   3109 @menu
   3110 * microhttpd-dauth basic::      Using Basic Authentication.
   3111 * microhttpd-dauth digest::     Using Digest Authentication.
   3112 @end menu
   3113 
   3114 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   3115 
   3116 @c ------------------------------------------------------------
   3117 @node microhttpd-dauth basic
   3118 @section Using Basic Authentication
   3119 
   3120 @deftypefun {void} MHD_free (void *ptr)
   3121 Free the memory given at @code{ptr}.  Used to free data structures allocated by MHD. Calls @code{free(ptr)}.
   3122 @end deftypefun
   3123 
   3124 @deftypefun {char *} MHD_basic_auth_get_username_password3 (struct MHD_Connection *connection)
   3125 Get the username and password from the basic authorization header sent by the client.
   3126 Return @code{NULL} if no Basic Authorization header set by the client or if Base64
   3127 encoding is invalid; a pointer to the structure with username and password
   3128 if found values set by the client.
   3129 If returned value is not @code{NULL}, the value must be @code{MHD_free()}'ed.
   3130 @end deftypefun
   3131 
   3132 @deftypefun {enum MHD_Result} MHD_queue_basic_auth_fail_response3 (struct MHD_Connection *connection, const char *realm, int prefer_utf8, struct MHD_Response *response)
   3133 Queues a response to request basic authentication from the client.
   3134 Return @code{MHD_YES} if successful, otherwise @code{MHD_NO}.
   3135 
   3136 @var{realm} must reference to a zero-terminated string representing the realm.
   3137 
   3138 @var{prefer_utf8} if set to @code{MHD_YES} then parameter @code{charset} with value
   3139 @code{UTF-8} will be added to the response authentication header which indicates
   3140 that UTF-8 encoding is preferred for username and password.
   3141 
   3142 @var{response} a response structure to specify what shall be presented to the
   3143 client with a 401 HTTP status.
   3144 @end deftypefun
   3145 
   3146 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   3147 
   3148 @c ------------------------------------------------------------
   3149 @node microhttpd-dauth digest
   3150 @section Using Digest Authentication
   3151 
   3152 MHD supports MD5 (deprecated by IETF) and SHA-256 hash algorithms
   3153 for digest authentication. The @code{MHD_DigestAuthAlgorithm} enumeration
   3154 is used to specify which algorithm should be used.
   3155 
   3156 @deftp {Enumeration} MHD_DigestAuthAlgorithm
   3157 Which digest algorithm should be used. Must be used consistently.
   3158 
   3159 @table @code
   3160 @item MHD_DIGEST_ALG_AUTO
   3161 Have MHD pick an algorithm currently considered secure.  For now defaults to SHA-256.
   3162 
   3163 @item MHD_DIGEST_ALG_MD5
   3164 Force use of (deprecated, ancient, insecure) MD5.
   3165 
   3166 @item MHD_DIGEST_ALG_SHA256
   3167 Force use of SHA-256.
   3168 
   3169 @end table
   3170 @end deftp
   3171 
   3172 @deftp {Enumeration} MHD_DigestAuthResult
   3173 The result of digest authentication of the client.
   3174 
   3175 @table @code
   3176 @item MHD_DAUTH_OK
   3177 Authentication OK.
   3178 
   3179 @item MHD_DAUTH_ERROR
   3180 General error, like ``out of memory''.
   3181 
   3182 @item MHD_DAUTH_WRONG_HEADER
   3183 No ``Authorization'' header or wrong format of the header.
   3184 
   3185 @item MHD_DAUTH_WRONG_USERNAME
   3186 Wrong ``username''.
   3187 
   3188 @item MHD_DAUTH_WRONG_REALM
   3189 Wrong ``realm''.
   3190 
   3191 @item MHD_DAUTH_WRONG_URI
   3192 Wrong ``URI'' (or URI parameters).
   3193 
   3194 @item MHD_DAUTH_NONCE_STALE
   3195 The ``nonce'' is too old. Suggest the client to retry with the same username and
   3196 password to get the fresh ``nonce''.
   3197 The validity of the ``nonce'' may not be checked.
   3198 
   3199 @item MHD_DAUTH_NONCE_WRONG
   3200 The ``nonce'' is wrong. May indicate an attack attempt.
   3201 
   3202 @item MHD_DAUTH_RESPONSE_WRONG
   3203 The ``response'' is wrong. May indicate an attack attempt.
   3204 
   3205 @end table
   3206 @end deftp
   3207 
   3208 
   3209 @deftypefun {char *} MHD_digest_auth_get_username (struct MHD_Connection *connection)
   3210 Find and return a pointer to the username value from the request header.
   3211 Return @code{NULL} if the value is not found or header does not exist.
   3212 If returned value is not @code{NULL}, the value must be @code{MHD_free()}'ed.
   3213 @end deftypefun
   3214 
   3215 @deftypefun enum MHD_DigestAuthResult MHD_digest_auth_check3 (struct MHD_Connection *connection, const char *realm, const char *username, const char *password, unsigned int nonce_timeout, enum MHD_DigestAuthAlgorithm algo)
   3216 Checks if the provided values in the WWW-Authenticate header are valid
   3217 and sound according to RFC7616. If valid return @code{MHD_DAUTH_OK}, otherwise return the error code.
   3218 
   3219 @var{realm} must reference to a zero-terminated string representing the realm.
   3220 
   3221 @var{username} must reference to a zero-terminated string representing the username,
   3222 it is usually the returned value from MHD_digest_auth_get_username.
   3223 
   3224 @var{password} must reference to a zero-terminated string representing the password,
   3225 most probably it will be the result of a lookup of the username against a local database.
   3226 
   3227 @var{nonce_timeout} the nonce validity duration in seconds.
   3228 Most of the time it is sound to specify 300 seconds as its values.
   3229 
   3230 @var{algo} which digest algorithm should we use.
   3231 @end deftypefun
   3232 
   3233 @deftypefun int MHD_digest_auth_check2 (struct MHD_Connection *connection, const char *realm, const char *username, const char *password, unsigned int nonce_timeout, enum MHD_DigestAuthAlgorithm algo)
   3234 Checks if the provided values in the WWW-Authenticate header are valid
   3235 and sound according to RFC2716. If valid return @code{MHD_YES}, otherwise return @code{MHD_NO}.
   3236 
   3237 @var{realm} must reference to a zero-terminated string representing the realm.
   3238 
   3239 @var{username} must reference to a zero-terminated string representing the username,
   3240 it is usually the returned value from MHD_digest_auth_get_username.
   3241 
   3242 @var{password} must reference to a zero-terminated string representing the password,
   3243 most probably it will be the result of a lookup of the username against a local database.
   3244 
   3245 @var{nonce_timeout} is the amount of time in seconds for a nonce to be invalid.
   3246 Most of the time it is sound to specify 300 seconds as its values.
   3247 
   3248 @var{algo} which digest algorithm should we use.
   3249 @end deftypefun
   3250 
   3251 
   3252 @deftypefun int MHD_digest_auth_check (struct MHD_Connection *connection, const char *realm, const char *username, const char *password, unsigned int nonce_timeout)
   3253 Checks if the provided values in the WWW-Authenticate header are valid
   3254 and sound according to RFC2716. If valid return @code{MHD_YES}, otherwise return @code{MHD_NO}.
   3255 Deprecated, use @code{MHD_digest_auth_check2} instead.
   3256 
   3257 
   3258 @var{realm} must reference to a zero-terminated string representing the realm.
   3259 
   3260 @var{username} must reference to a zero-terminated string representing the username,
   3261 it is usually the returned value from MHD_digest_auth_get_username.
   3262 
   3263 @var{password} must reference to a zero-terminated string representing the password,
   3264 most probably it will be the result of a lookup of the username against a local database.
   3265 
   3266 @var{nonce_timeout} is the amount of time in seconds for a nonce to be invalid.
   3267 Most of the time it is sound to specify 300 seconds as its values.
   3268 @end deftypefun
   3269 
   3270 
   3271 
   3272 @deftypefun enum MHD_DigestAuthResult MHD_digest_auth_check_digest3 (struct MHD_Connection *connection, const char *realm, const char *username, const uint8_t *digest, unsigned int nonce_timeout, enum MHD_DigestAuthAlgorithm algo)
   3273 Checks if the provided values in the WWW-Authenticate header are valid
   3274 and sound according to RFC7616. If valid return @code{MHD_DAUTH_OK}, otherwise return the error code.
   3275 
   3276 @var{realm} must reference to a zero-terminated string representing the realm.
   3277 
   3278 @var{username} must reference to a zero-terminated string representing the username,
   3279 it is usually the returned value from MHD_digest_auth_get_username.
   3280 
   3281 @var{digest} the pointer to the binary digest for the precalculated hash value ``username:realm:password'' with specified @var{algo}.
   3282 
   3283 @var{digest_size} the number of bytes in @var{digest} (the size must match @var{algo}!)
   3284 
   3285 @var{nonce_timeout} the nonce validity duration in seconds.
   3286 Most of the time it is sound to specify 300 seconds as its values.
   3287 
   3288 @var{algo} digest authentication algorithm to use.
   3289 @end deftypefun
   3290 
   3291 @deftypefun int MHD_digest_auth_check_digest2 (struct MHD_Connection *connection, const char *realm, const char *username, const uint8_t *digest, unsigned int nonce_timeout, enum MHD_DigestAuthAlgorithm algo)
   3292 Checks if the provided values in the WWW-Authenticate header are valid
   3293 and sound according to RFC2716. If valid return @code{MHD_YES}, otherwise return @code{MHD_NO}.
   3294 
   3295 @var{realm} must reference to a zero-terminated string representing the realm.
   3296 
   3297 @var{username} must reference to a zero-terminated string representing the username,
   3298 it is usually the returned value from MHD_digest_auth_get_username.
   3299 
   3300 @var{digest} pointer to the binary MD5 sum for the precalculated hash value ``userame:realm:password''. The size must match the selected @var{algo}!
   3301 
   3302 @var{nonce_timeout} is the amount of time in seconds for a nonce to be invalid.
   3303 Most of the time it is sound to specify 300 seconds as its values.
   3304 
   3305 @var{algo} digest authentication algorithm to use.
   3306 @end deftypefun
   3307 
   3308 @deftypefun int MHD_digest_auth_check_digest (struct MHD_Connection *connection, const char *realm, const char *username, const unsigned char digest[MHD_MD5_DIGEST_SIZE], unsigned int nonce_timeout)
   3309 Checks if the provided values in the WWW-Authenticate header are valid
   3310 and sound according to RFC2716. If valid return @code{MHD_YES}, otherwise return @code{MHD_NO}.
   3311 Deprecated, use @code{MHD_digest_auth_check_digest2} instead.
   3312 
   3313 @var{realm} must reference to a zero-terminated string representing the realm.
   3314 
   3315 @var{username} must reference to a zero-terminated string representing the username,
   3316 it is usually the returned value from MHD_digest_auth_get_username.
   3317 
   3318 @var{digest} pointer to the binary MD5 sum for the precalculated hash value ``userame:realm:password'' of @code{MHD_MD5_DIGEST_SIZE} bytes.
   3319 
   3320 @var{nonce_timeout} is the amount of time in seconds for a nonce to be invalid.
   3321 Most of the time it is sound to specify 300 seconds as its values.
   3322 @end deftypefun
   3323 
   3324 
   3325 @deftypefun enum MHD_Result MHD_queue_auth_fail_response2 (struct MHD_Connection *connection, const char *realm, const char *opaque, struct MHD_Response *response, int signal_stale, enum MHD_DigestAuthAlgorithm algo)
   3326 Queues a response to request authentication from the client,
   3327 return @code{MHD_YES} if successful, otherwise @code{MHD_NO}.
   3328 
   3329 @var{realm} must reference to a zero-terminated string representing the realm.
   3330 
   3331 @var{opaque} must reference to a zero-terminated string representing a value
   3332 that gets passed to the client and expected to be passed again to the server
   3333 as-is. This value can be a hexadecimal or base64 string.
   3334 
   3335 @var{response} a response structure to specify what shall be presented to the
   3336 client with a 401 HTTP status.
   3337 
   3338 @var{signal_stale} a value that signals "stale=true" in the response header to
   3339 indicate the invalidity of the nonce and no need to ask for authentication
   3340 parameters and only a new nonce gets generated. @code{MHD_YES} to generate a new
   3341 nonce, @code{MHD_NO} to ask for authentication parameters.
   3342 
   3343 @var{algo} which digest algorithm should we use.  The same algorithm
   3344 must then be selected when checking digests received from clients!
   3345 
   3346 @end deftypefun
   3347 
   3348 
   3349 @deftypefun enum MHD_Result MHD_queue_auth_fail_response (struct MHD_Connection *connection, const char *realm, const char *opaque, struct MHD_Response *response, int signal_stale)
   3350 Queues a response to request authentication from the client,
   3351 return @code{MHD_YES} if successful, otherwise @code{MHD_NO}.
   3352 
   3353 @var{realm} must reference to a zero-terminated string representing the realm.
   3354 
   3355 @var{opaque} must reference to a zero-terminated string representing a value
   3356 that gets passed to the client and expected to be passed again to the server
   3357 as-is. This value can be a hexadecimal or base64 string.
   3358 
   3359 @var{response} a response structure to specify what shall be presented to the
   3360 client with a 401 HTTP status.
   3361 
   3362 @var{signal_stale} a value that signals "stale=true" in the response header to
   3363 indicate the invalidity of the nonce and no need to ask for authentication
   3364 parameters and only a new nonce gets generated. @code{MHD_YES} to generate a new
   3365 nonce, @code{MHD_NO} to ask for authentication parameters.
   3366 @end deftypefun
   3367 
   3368 Example: handling digest authentication requests and responses.
   3369 
   3370 @example
   3371 #define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>"
   3372 #define DENIED "<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>"
   3373 #define OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4"
   3374 
   3375 static int
   3376 ahc_echo (void *cls,
   3377           struct MHD_Connection *connection,
   3378           const char *url,
   3379           const char *method,
   3380           const char *version,
   3381           const char *upload_data, size_t *upload_data_size, void **ptr)
   3382 @{
   3383   struct MHD_Response *response;
   3384   char *username;
   3385   const char *password = "testpass";
   3386   const char *realm = "test@@example.com";
   3387   int ret;
   3388   static int already_called_marker;
   3389 
   3390   if (&already_called_marker != *req_cls)
   3391     @{ /* Called for the first time, request not fully read yet */
   3392       *req_cls = &already_called_marker;
   3393       /* Wait for complete request */
   3394       return MHD_YES;
   3395     @}
   3396 
   3397   username = MHD_digest_auth_get_username (connection);
   3398   if (username == NULL)
   3399     @{
   3400       response = MHD_create_response_from_buffer(strlen (DENIED),
   3401 					         DENIED,
   3402 					         MHD_RESPMEM_PERSISTENT);
   3403       ret = MHD_queue_auth_fail_response2 (connection,
   3404                                            realm,
   3405 					   OPAQUE,
   3406 					   response,
   3407 					   MHD_NO,
   3408                                            MHD_DIGEST_ALG_SHA256);
   3409       MHD_destroy_response(response);
   3410       return ret;
   3411     @}
   3412   ret = MHD_digest_auth_check2 (connection,
   3413                                 realm,
   3414 			        username,
   3415 			        password,
   3416 			        300,
   3417                                 MHD_DIGEST_ALG_SHA256);
   3418   MHD_free(username);
   3419   if ( (ret == MHD_INVALID_NONCE) ||
   3420        (ret == MHD_NO) )
   3421     @{
   3422       response = MHD_create_response_from_buffer(strlen (DENIED),
   3423 					         DENIED,
   3424 					         MHD_RESPMEM_PERSISTENT);
   3425       if (NULL == response)
   3426 	return MHD_NO;
   3427       ret = MHD_queue_auth_fail_response2 (connection,
   3428                                            realm,
   3429 					   OPAQUE,
   3430 					   response,
   3431 					   (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO,
   3432                                            MHD_DIGEST_ALG_SHA256);
   3433       MHD_destroy_response(response);
   3434       return ret;
   3435     @}
   3436   response = MHD_create_response_from_buffer (strlen(PAGE),
   3437                                               PAGE,
   3438  					      MHD_RESPMEM_PERSISTENT);
   3439   ret = MHD_queue_response (connection,
   3440                             MHD_HTTP_OK,
   3441                             response);
   3442   MHD_destroy_response(response);
   3443   return ret;
   3444 @}
   3445 @end example
   3446 
   3447 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   3448 
   3449 @c ------------------------------------------------------------
   3450 @node microhttpd-post
   3451 @chapter Adding a @code{POST} processor
   3452 @cindex POST method
   3453 
   3454 @menu
   3455 * microhttpd-post api::         Programming interface for the
   3456                                 @code{POST} processor.
   3457 @end menu
   3458 
   3459 
   3460 @noindent
   3461 MHD provides the post processor API to make it easier for applications to
   3462 parse the data of a client's @code{POST} request: the
   3463 @code{MHD_AccessHandlerCallback} will be invoked multiple times to
   3464 process data as it arrives; at each invocation a new chunk of data must
   3465 be processed. The arguments @var{upload_data} and @var{upload_data_size}
   3466 are used to reference the chunk of data.
   3467 
   3468 When @code{MHD_AccessHandlerCallback} is invoked for a new request:
   3469 its @code{*@var{req_cls}} argument is set to @code{NULL}. When @code{POST}
   3470 data comes in the upload buffer it is @strong{mandatory} to use the
   3471 @var{req_cls} to store a reference to per-request data.  The fact
   3472 that the pointer was initially @code{NULL} can be used to detect that
   3473 this is a new request.
   3474 
   3475 One method to detect that a new request was started is
   3476 to set @code{*req_cls} to an unused integer:
   3477 
   3478 @example
   3479 int
   3480 access_handler (void *cls,
   3481                 struct MHD_Connection * connection,
   3482                 const char *url,
   3483                 const char *method, const char *version,
   3484                 const char *upload_data, size_t *upload_data_size,
   3485                 void **req_cls)
   3486 @{
   3487   static int old_connection_marker;
   3488   int new_connection = (NULL == *req_cls);
   3489 
   3490   if (new_connection)
   3491     @{
   3492       /* new connection with POST */
   3493       *req_cls = &old_connection_marker;
   3494     @}
   3495 
   3496   ...
   3497 @}
   3498 @end example
   3499 
   3500 @noindent
   3501 In contrast to the previous example, for @code{POST} requests in particular,
   3502 it is more common to use the value of @code{*req_cls} to keep track of
   3503 actual state used during processing, such as the post processor (or a
   3504 struct containing a post processor):
   3505 
   3506 @example
   3507 int
   3508 access_handler (void *cls,
   3509                 struct MHD_Connection * connection,
   3510                 const char *url,
   3511                 const char *method, const char *version,
   3512                 const char *upload_data, size_t *upload_data_size,
   3513                 void **req_cls)
   3514 @{
   3515   struct MHD_PostProcessor * pp = *req_cls;
   3516 
   3517   if (pp == NULL)
   3518     @{
   3519       pp = MHD_create_post_processor(connection, ...);
   3520       *req_cls = pp;
   3521       return MHD_YES;
   3522     @}
   3523   if (*upload_data_size)
   3524     @{
   3525       MHD_post_process(pp, upload_data, *upload_data_size);
   3526       *upload_data_size = 0;
   3527       return MHD_YES;
   3528     @}
   3529   else
   3530     @{
   3531       MHD_destroy_post_processor(pp);
   3532       return MHD_queue_response(...);
   3533     @}
   3534 @}
   3535 @end example
   3536 
   3537 Note that the callback from @code{MHD_OPTION_NOTIFY_COMPLETED}
   3538 should be used to destroy the post processor.  This cannot be
   3539 done inside of the access handler since the connection may not
   3540 always terminate normally.
   3541 
   3542 
   3543 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   3544 
   3545 @c ------------------------------------------------------------
   3546 @node microhttpd-post api
   3547 @section Programming interface for the @code{POST} processor
   3548 @cindex POST method
   3549 
   3550 @deftypefun {struct MHD_PostProcessor *} MHD_create_post_processor (struct MHD_Connection *connection, size_t buffer_size, MHD_PostDataIterator iterator, void *iterator_cls)
   3551 Create a PostProcessor.  A PostProcessor can be used to (incrementally)
   3552 parse the data portion of a @code{POST} request.
   3553 
   3554 @table @var
   3555 @item connection
   3556 the connection on which the @code{POST} is happening (used to determine
   3557 the @code{POST} format);
   3558 
   3559 @item buffer_size
   3560 maximum number of bytes to use for internal buffering (used only for the
   3561 parsing, specifically the parsing of the keys).  A tiny value (256-1024)
   3562 should be sufficient; do @strong{NOT} use a value smaller than 256;
   3563 for good performance, use 32k or 64k (i.e. 65536).
   3564 
   3565 @item iterator
   3566 iterator to be called with the parsed data; must @strong{NOT} be
   3567 @code{NULL};
   3568 
   3569 @item iterator_cls
   3570 custom value to be used as first argument to @var{iterator}.
   3571 @end table
   3572 
   3573 Return @code{NULL} on error (out of memory, unsupported encoding), otherwise
   3574 a PP handle.
   3575 @end deftypefun
   3576 
   3577 
   3578 @deftypefun enum MHD_Result MHD_post_process (struct MHD_PostProcessor *pp, const char *post_data, size_t post_data_len)
   3579 Parse and process @code{POST} data.  Call this function when @code{POST}
   3580 data is available (usually during an @code{MHD_AccessHandlerCallback})
   3581 with the @var{upload_data} and @var{upload_data_size}.  Whenever
   3582 possible, this will then cause calls to the
   3583 @code{MHD_IncrementalKeyValueIterator}.
   3584 
   3585 @table @var
   3586 @item pp
   3587 the post processor;
   3588 
   3589 @item post_data
   3590 @var{post_data_len} bytes of @code{POST} data;
   3591 
   3592 @item post_data_len
   3593 length of @var{post_data}.
   3594 @end table
   3595 
   3596 Return @code{MHD_YES} on success, @code{MHD_NO} on error
   3597 (out-of-memory, iterator aborted, parse error).
   3598 @end deftypefun
   3599 
   3600 
   3601 @deftypefun enum MHD_Result MHD_destroy_post_processor (struct MHD_PostProcessor *pp)
   3602 Release PostProcessor resources.  After this function is being called,
   3603 the PostProcessor is guaranteed to no longer call its iterator.  There
   3604 is no special call to the iterator to indicate the end of the post processing
   3605 stream.  After destroying the PostProcessor, the programmer should
   3606 perform any necessary work to complete the processing of the iterator.
   3607 
   3608 Return @code{MHD_YES} if processing completed nicely, @code{MHD_NO}
   3609 if there were spurious characters or formatting problems with
   3610 the post request.  It is common to ignore the return value
   3611 of this function.
   3612 
   3613 
   3614 @end deftypefun
   3615 
   3616 
   3617 
   3618 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   3619 
   3620 @c ------------------------------------------------------------
   3621 @node microhttpd-info
   3622 @chapter Obtaining and modifying status information.
   3623 
   3624 
   3625 @menu
   3626 * microhttpd-info daemon::      State information about an MHD daemon
   3627 * microhttpd-info conn::        State information about a connection
   3628 * microhttpd-option conn::      Modify per-connection options
   3629 @end menu
   3630 
   3631 
   3632 @c ------------------------------------------------------------
   3633 @node microhttpd-info daemon
   3634 @section Obtaining state information about an MHD daemon
   3635 
   3636 @deftypefun {const union MHD_DaemonInfo *} MHD_get_daemon_info (struct MHD_Daemon *daemon, enum MHD_DaemonInfoType infoType, ...)
   3637 Obtain information about the given daemon.  This function
   3638 is currently not fully implemented.
   3639 
   3640 @table @var
   3641 @item daemon
   3642 the daemon about which information is desired;
   3643 
   3644 @item infoType
   3645 type of information that is desired
   3646 
   3647 @item ...
   3648 additional arguments about the desired information (depending on
   3649 infoType)
   3650 @end table
   3651 
   3652 Returns a union with the respective member (depending on
   3653 infoType) set to the desired information), or @code{NULL}
   3654 in case the desired information is not available or
   3655 applicable.
   3656 @end deftypefun
   3657 
   3658 
   3659 @deftp {Enumeration} MHD_DaemonInfoType
   3660 Values of this enum are used to specify what
   3661 information about a daemon is desired.
   3662 @table @code
   3663 @item MHD_DAEMON_INFO_KEY_SIZE
   3664 Request information about the key size for a particular cipher
   3665 algorithm.  The cipher algorithm should be passed as an extra argument
   3666 (of type 'enum MHD_GNUTLS_CipherAlgorithm').  No longer supported,
   3667 using this value will cause @code{MHD_get_daemon_info} to return NULL.
   3668 
   3669 @item MHD_DAEMON_INFO_MAC_KEY_SIZE
   3670 Request information about the key size for a particular cipher
   3671 algorithm.  The cipher algorithm should be passed as an extra argument
   3672 (of type 'enum MHD_GNUTLS_HashAlgorithm').  No longer supported,
   3673 using this value will cause @code{MHD_get_daemon_info} to return NULL.
   3674 
   3675 @item MHD_DAEMON_INFO_LISTEN_FD
   3676 @cindex listen
   3677 Request the file-descriptor number that MHD is using to listen to the
   3678 server socket.  This can be useful if no port
   3679 was specified and a client needs to learn what port
   3680 is actually being used by MHD.
   3681 No extra arguments should be passed.
   3682 
   3683 @item MHD_DAEMON_INFO_EPOLL_FD
   3684 @cindex epoll
   3685 Request the file-descriptor number that MHD is using for epoll.  If
   3686 the build is not supporting epoll, NULL is returned; if we are using a
   3687 thread pool or this daemon was not started with
   3688 @code{MHD_USE_EPOLL}, (a pointer to) -1 is returned.  If we are
   3689 using @code{MHD_USE_INTERNAL_POLLING_THREAD} or are in 'external' select mode, the
   3690 internal epoll FD is returned.  This function must be used in external
   3691 select mode with epoll to obtain the FD to call epoll on.  No extra
   3692 arguments should be passed.
   3693 
   3694 @item MHD_DAEMON_INFO_CURRENT_CONNECTIONS
   3695 @cindex connection, limiting number of connections
   3696 Request the number of current connections handled by the daemon.  No
   3697 extra arguments should be passed and a pointer to a @code{union
   3698 MHD_DaemonInfo} value is returned, with the @code{num_connections}
   3699 member of type @code{unsigned int} set to the number of active
   3700 connections.
   3701 
   3702 Note that in multi-threaded or internal-select mode, the real number of current
   3703 connections may already be different when @code{MHD_get_daemon_info} returns.
   3704 The number of current connections can be used (even in multi-threaded and
   3705 internal-select mode) after @code{MHD_quiesce_daemon} to detect whether all
   3706 connections have been handled.
   3707 
   3708 @end table
   3709 @end deftp
   3710 
   3711 
   3712 
   3713 @c ------------------------------------------------------------
   3714 @node microhttpd-info conn
   3715 @section Obtaining state information about a connection
   3716 
   3717 
   3718 @deftypefun {const union MHD_ConnectionInfo *} MHD_get_connection_info (struct MHD_Connection *connection, enum MHD_ConnectionInfoType infoType, ...)
   3719 Obtain information about the given connection.
   3720 
   3721 @table @var
   3722 @item connection
   3723 the connection about which information is desired;
   3724 
   3725 @item infoType
   3726 type of information that is desired
   3727 
   3728 @item ...
   3729 additional arguments about the desired information (depending on
   3730 infoType)
   3731 @end table
   3732 
   3733 Returns a union with the respective member (depending on
   3734 infoType) set to the desired information), or @code{NULL}
   3735 in case the desired information is not available or
   3736 applicable.
   3737 @end deftypefun
   3738 
   3739 @deftp {Enumeration} MHD_ConnectionInfoType
   3740 Values of this enum are used to specify what information about a
   3741 connection is desired.
   3742 
   3743 @table @code
   3744 
   3745 @item MHD_CONNECTION_INFO_CIPHER_ALGO
   3746 What cipher algorithm is being used (HTTPS connections only).
   3747 @code{NULL} is returned for non-HTTPS connections.
   3748 
   3749 Takes no extra arguments.
   3750 
   3751 @item MHD_CONNECTION_INFO_PROTOCOL,
   3752 Allows finding out the TLS/SSL protocol used
   3753 (HTTPS connections only).
   3754 @code{NULL} is returned for non-HTTPS connections.
   3755 
   3756 Takes no extra arguments.
   3757 
   3758 @item MHD_CONNECTION_INFO_CLIENT_ADDRESS
   3759 Returns information about the address of the client.  Returns
   3760 essentially a @code{struct sockaddr **} (since the API returns
   3761 a @code{union MHD_ConnectionInfo *} and that union contains
   3762 a @code{struct sockaddr *}).
   3763 
   3764 Takes no extra arguments.
   3765 
   3766 @item MHD_CONNECTION_INFO_GNUTLS_SESSION,
   3767 Takes no extra arguments.  Allows access to the underlying GNUtls session,
   3768 including access to the underlying GNUtls client certificate
   3769 (HTTPS connections only).  Takes no extra arguments.
   3770 @code{NULL} is returned for non-HTTPS connections.
   3771 
   3772 Takes no extra arguments.
   3773 
   3774 @item MHD_CONNECTION_INFO_GNUTLS_CLIENT_CERT,
   3775 Dysfunctional (never implemented, deprecated).  Use
   3776 MHD_CONNECTION_INFO_GNUTLS_SESSION to get the @code{gnutls_session_t}
   3777 and then call @code{gnutls_certificate_get_peers()}.
   3778 
   3779 @item MHD_CONNECTION_INFO_DAEMON
   3780 Returns information about @code{struct MHD_Daemon} which manages
   3781 this connection.
   3782 
   3783 Takes no extra arguments.
   3784 
   3785 @item MHD_CONNECTION_INFO_CONNECTION_FD
   3786 Returns the file descriptor (usually a TCP socket) associated with
   3787 this connection (in the ``connect-fd'' member of the returned struct).
   3788 Note that manipulating the descriptor directly can have problematic
   3789 consequences (as in, break HTTP).  Applications might use this access
   3790 to manipulate TCP options, for example to set the ``TCP-NODELAY''
   3791 option for COMET-like applications.  Note that MHD will set TCP-CORK
   3792 after sending the HTTP header and clear it after finishing the footers
   3793 automatically (if the platform supports it).  As the connection
   3794 callbacks are invoked in between, those might be used to set different
   3795 values for TCP-CORK and TCP-NODELAY in the meantime.
   3796 
   3797 Takes no extra arguments.
   3798 
   3799 @item MHD_CONNECTION_INFO_CONNECTION_SUSPENDED
   3800 Returns pointer to an integer that is @code{MHD_YES} if the connection
   3801 is currently suspended (and thus can be safely resumed) and
   3802 @code{MHD_NO} otherwise.
   3803 
   3804 Takes no extra arguments.
   3805 
   3806 @item MHD_CONNECTION_INFO_SOCKET_CONTEXT
   3807 Returns the client-specific pointer to a @code{void *} that was
   3808 (possibly) set during a @code{MHD_NotifyConnectionCallback} when the
   3809 socket was first accepted.  Note that this is NOT the same as the
   3810 @code{req_cls} argument of the @code{MHD_AccessHandlerCallback}.  The
   3811 @code{req_cls} is fresh for each HTTP request, while the
   3812 @code{socket_context} is fresh for each socket.
   3813 
   3814 Takes no extra arguments.
   3815 
   3816 @item MHD_CONNECTION_INFO_CONNECTION_TIMEOUT
   3817 Returns pointer to an @code{unsigned int} that is the current timeout
   3818 used for the connection (in seconds, 0 for no timeout).  Note that
   3819 while suspended connections will not timeout, the timeout value
   3820 returned for suspended connections will be the timeout that the
   3821 connection will use after it is resumed, and thus might not be zero.
   3822 
   3823 Takes no extra arguments.
   3824 
   3825 @item MHD_CONNECTION_INFO_REQUEST_HEADER_SIZE
   3826 @cindex performance
   3827 Returns pointer to an @code{size_t} that represents the size of the
   3828 HTTP header received from the client. Only valid after the first callback
   3829 to the access handler.
   3830 
   3831 Takes no extra arguments.
   3832 
   3833 @item MHD_CONNECTION_INFO_HTTP_STATUS
   3834 Returns the HTTP status code of the response that was
   3835 queued. Returns NULL if no response was queued yet.
   3836 
   3837 Takes no extra arguments.
   3838 
   3839 @end table
   3840 @end deftp
   3841 
   3842 
   3843 
   3844 @c ------------------------------------------------------------
   3845 @node microhttpd-option conn
   3846 @section Setting custom options for an individual connection
   3847 @cindex timeout
   3848 
   3849 
   3850 
   3851 @deftypefun {int} MHD_set_connection_option (struct MHD_Connection *daemon, enum MHD_CONNECTION_OPTION option, ...)
   3852 Set a custom option for the given connection.
   3853 
   3854 @table @var
   3855 @item connection
   3856 the connection for which an option should be set or modified;
   3857 
   3858 @item option
   3859 option to set
   3860 
   3861 @item ...
   3862 additional arguments for the option (depending on option)
   3863 @end table
   3864 
   3865 Returns @code{MHD_YES} on success, @code{MHD_NO} for errors
   3866 (i.e. option argument invalid or option unknown).
   3867 @end deftypefun
   3868 
   3869 
   3870 @deftp {Enumeration} MHD_CONNECTION_OPTION
   3871 Values of this enum are used to specify which option for a
   3872 connection should be changed.
   3873 
   3874 @table @code
   3875 
   3876 @item MHD_CONNECTION_OPTION_TIMEOUT
   3877 Set a custom timeout for the given connection.   Specified
   3878 as the number of seconds, given as an @code{unsigned int}.  Use
   3879 zero for no timeout.
   3880 
   3881 @end table
   3882 @end deftp
   3883 
   3884 
   3885 
   3886 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   3887 
   3888 @c ------------------------------------------------------------
   3889 @node microhttpd-util
   3890 @chapter Utility functions.
   3891 
   3892 
   3893 @menu
   3894 * microhttpd-util feature::     Test supported MHD features
   3895 * microhttpd-util unescape::    Unescape strings
   3896 @end menu
   3897 
   3898 
   3899 @c ------------------------------------------------------------
   3900 @node microhttpd-util feature
   3901 @section Testing for supported MHD features
   3902 
   3903 
   3904 @deftp {Enumeration} MHD_FEATURE
   3905 Values of this enum are used to specify what
   3906 information about a daemon is desired.
   3907 @table @code
   3908 @item MHD_FEATURE_MESSAGES
   3909 Get whether messages are supported. If supported then in debug
   3910 mode messages can be printed to stderr or to external logger.
   3911 
   3912 @item MHD_FEATURE_SSL
   3913 Get whether HTTPS is supported.  If supported then flag
   3914 MHD_USE_SSL and options MHD_OPTION_HTTPS_MEM_KEY,
   3915 MHD_OPTION_HTTPS_MEM_CERT, MHD_OPTION_HTTPS_MEM_TRUST,
   3916 MHD_OPTION_HTTPS_MEM_DHPARAMS, MHD_OPTION_HTTPS_CRED_TYPE,
   3917 MHD_OPTION_HTTPS_PRIORITIES can be used.
   3918 
   3919 @item MHD_FEATURE_HTTPS_CERT_CALLBACK
   3920 Get whether option #MHD_OPTION_HTTPS_CERT_CALLBACK is
   3921 supported.
   3922 
   3923 @item MHD_FEATURE_IPv6
   3924 Get whether IPv6 is supported. If supported then flag
   3925 MHD_USE_IPv6 can be used.
   3926 
   3927 @item MHD_FEATURE_IPv6_ONLY
   3928 Get whether IPv6 without IPv4 is supported. If not supported
   3929 then IPv4 is always enabled in IPv6 sockets and
   3930 flag MHD_USE_DUAL_STACK if always used when MHD_USE_IPv6 is
   3931 specified.
   3932 
   3933 @item MHD_FEATURE_POLL
   3934 Get whether @code{poll()} is supported. If supported then flag
   3935 MHD_USE_POLL can be used.
   3936 
   3937 @item MHD_FEATURE_EPOLL
   3938 Get whether @code{epoll()} is supported. If supported then Flags
   3939 MHD_USE_EPOLL and
   3940 MHD_USE_EPOLL_INTERNAL_THREAD can be used.
   3941 
   3942 @item MHD_FEATURE_SHUTDOWN_LISTEN_SOCKET
   3943 Get whether shutdown on listen socket to signal other
   3944 threads is supported. If not supported flag
   3945 MHD_USE_ITC is automatically forced.
   3946 
   3947 @item MHD_FEATURE_SOCKETPAIR
   3948 Get whether a @code{socketpair()} is used internally instead of
   3949 a @code{pipe()} to signal other threads.
   3950 
   3951 @item MHD_FEATURE_TCP_FASTOPEN
   3952 Get whether TCP Fast Open is supported. If supported then
   3953 flag MHD_USE_TCP_FASTOPEN and option
   3954 MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE can be used.
   3955 
   3956 @item MHD_FEATURE_BASIC_AUTH
   3957 Get whether HTTP Basic authorization is supported. If supported
   3958 then functions @code{MHD_basic_auth_get_username_password()} and
   3959 @code{MHD_queue_basic_auth_fail_response()} can be used.
   3960 
   3961 @item MHD_FEATURE_DIGEST_AUTH
   3962 Get whether HTTP Digest authorization is supported. If
   3963 supported then options MHD_OPTION_DIGEST_AUTH_RANDOM,
   3964 MHD_OPTION_NONCE_NC_SIZE and functions @code{MHD_digest_auth_check()},
   3965 can be used.
   3966 
   3967 @item MHD_FEATURE_POSTPROCESSOR
   3968 Get whether postprocessor is supported. If supported then
   3969 functions @code{MHD_create_post_processor()},
   3970 @code{MHD_post_process()}, @code{MHD_destroy_post_processor()}
   3971 can be used.
   3972 
   3973 @item MHD_FEATURE_SENDFILE
   3974 Get whether @code{sendfile()} is supported.
   3975 
   3976 @end table
   3977 @end deftp
   3978 
   3979 
   3980 
   3981 @deftypefun {int} MHD_is_feature_supported (enum MHD_FEATURE feature)
   3982 Get information about supported MHD features.  Indicate that MHD was
   3983 compiled with or without support for particular feature. Some features
   3984 require additional support by the kernel.  However, kernel support is not
   3985 checked by this function.
   3986 
   3987 @table @var
   3988 @item feature
   3989 type of requested information
   3990 @end table
   3991 
   3992 Returns @code{MHD_YES} if the feature is supported,
   3993 and @code{MHD_NO} if not.
   3994 @end deftypefun
   3995 
   3996 
   3997 @c ------------------------------------------------------------
   3998 @node microhttpd-util unescape
   3999 @section Unescape strings
   4000 
   4001 @deftypefun {size_t} MHD_http_unescape (char *val)
   4002 Process escape sequences ('%HH') Updates val in place; the result
   4003 should be UTF-8 encoded and cannot be larger than the input.  The
   4004 result must also still be 0-terminated.
   4005 
   4006 @table @var
   4007 @item val
   4008 value to unescape (modified in the process), must be
   4009 a 0-terminated UTF-8 string.
   4010 @end table
   4011 
   4012 Returns length of the resulting val (@code{strlen(val)} may be
   4013 shorter afterwards due to elimination of escape sequences).
   4014 
   4015 @end deftypefun
   4016 
   4017 
   4018 
   4019 
   4020 
   4021 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   4022 
   4023 @c ------------------------------------------------------------
   4024 @node microhttpd-websocket
   4025 @chapter Websocket functions.
   4026 
   4027 @noindent
   4028 Websocket functions provide what you need to use an upgraded connection
   4029 as a websocket.
   4030 These functions are only available if you include the header file
   4031 @code{microhttpd_ws.h} and compiled @emph{libmicrohttpd} with websockets.
   4032 
   4033 @menu
   4034 * microhttpd-websocket handshake::    Websocket handshake functions
   4035 * microhttpd-websocket stream::       Websocket stream functions
   4036 * microhttpd-websocket decode::       Websocket decode functions
   4037 * microhttpd-websocket encode::       Websocket encode functions
   4038 * microhttpd-websocket memory::       Websocket memory functions
   4039 @end menu
   4040 
   4041 @c ------------------------------------------------------------
   4042 @node microhttpd-websocket handshake
   4043 @section Websocket handshake functions
   4044 
   4045 
   4046 @deftypefun {enum MHD_WEBSOCKET_STATUS} MHD_websocket_check_http_version (const char* http_version)
   4047 @cindex websocket
   4048 Checks the HTTP version of the incoming request.
   4049 Websocket requests are only allowed for HTTP/1.1 or above.
   4050 
   4051 @table @var
   4052 @item http_version
   4053 The value of the @code{version} parameter of your
   4054 @code{access_handler} callback.
   4055 If you pass @code{NULL} then this is handled like a not
   4056 matching HTTP version.
   4057 @end table
   4058 
   4059 Returns 0 when the HTTP version is
   4060 valid for a websocket request and
   4061 a value less than zero when the HTTP version isn't
   4062 valid for a websocket request.
   4063 Can be compared with @code{enum MHD_WEBSOCKET_STATUS}.
   4064 @end deftypefun
   4065 
   4066 
   4067 @deftypefun {enum MHD_WEBSOCKET_STATUS} MHD_websocket_check_connection_header (const char* connection_header)
   4068 @cindex websocket
   4069 Checks the value of the @code{Connection} HTTP request header.
   4070 Websocket requests require the token @code{Upgrade} in
   4071 the @code{Connection} HTTP request header.
   4072 
   4073 @table @var
   4074 @item connection_header
   4075 Value of the @code{Connection} request header.
   4076 You can get this request header value by passing
   4077 @code{MHD_HTTP_HEADER_CONNECTION} to
   4078 @code{MHD_lookup_connection_value()}.
   4079 If you pass @code{NULL} then this is handled like a not
   4080 matching @code{Connection} header value.
   4081 @end table
   4082 
   4083 Returns 0 when the @code{Connection} header is
   4084 valid for a websocket request and
   4085 a value less than zero when the @code{Connection} header isn't
   4086 valid for a websocket request.
   4087 Can be compared with @code{enum MHD_WEBSOCKET_STATUS}.
   4088 @end deftypefun
   4089 
   4090 
   4091 @deftypefun {enum MHD_WEBSOCKET_STATUS} MHD_websocket_check_upgrade_header (const char* upgrade_header)
   4092 @cindex websocket
   4093 Checks the value of the @code{Upgrade} HTTP request header.
   4094 Websocket requests require the value @code{websocket} in
   4095 the @code{Upgrade} HTTP request header.
   4096 
   4097 @table @var
   4098 @item upgrade_header
   4099 Value of the @code{Upgrade} request header.
   4100 You can get this request header value by passing
   4101 @code{MHD_HTTP_HEADER_UPGRADE} to
   4102 @code{MHD_lookup_connection_value()}.
   4103 If you pass @code{NULL} then this is handled like a not
   4104 matching @code{Upgrade} header value.
   4105 @end table
   4106 
   4107 Returns 0 when the @code{Upgrade} header is
   4108 valid for a websocket request and
   4109 a value less than zero when the @code{Upgrade} header isn't
   4110 valid for a websocket request.
   4111 Can be compared with @code{enum MHD_WEBSOCKET_STATUS}.
   4112 @end deftypefun
   4113 
   4114 
   4115 @deftypefun {enum MHD_WEBSOCKET_STATUS} MHD_websocket_check_version_header (const char* version_header)
   4116 @cindex websocket
   4117 Checks the value of the @code{Sec-WebSocket-Version} HTTP request header.
   4118 Websocket requests require the value @code{13} in
   4119 the @code{Sec-WebSocket-Version} HTTP request header.
   4120 
   4121 @table @var
   4122 @item version_header
   4123 Value of the @code{Sec-WebSocket-Version} request header.
   4124 You can get this request header value by passing
   4125 @code{MHD_HTTP_HEADER_SEC_WEBSOCKET_VERSION} to
   4126 @code{MHD_lookup_connection_value()}.
   4127 If you pass @code{NULL} then this is handled like a not
   4128 matching @code{Sec-WebSocket-Version} header value.
   4129 @end table
   4130 
   4131 Returns 0 when the @code{Sec-WebSocket-Version} header is
   4132 valid for a websocket request and
   4133 a value less than zero when the @code{Sec-WebSocket-Version} header isn't
   4134 valid for a websocket request.
   4135 Can be compared with @code{enum MHD_WEBSOCKET_STATUS}.
   4136 @end deftypefun
   4137 
   4138 
   4139 @deftypefun {enum MHD_WEBSOCKET_STATUS} MHD_websocket_create_accept_header (const char* sec_websocket_key, char* sec_websocket_accept)
   4140 @cindex websocket
   4141 Checks the value of the @code{Sec-WebSocket-Key}
   4142 HTTP request header and generates the value for
   4143 the @code{Sec-WebSocket-Accept} HTTP response header.
   4144 The generated value must be sent to the client.
   4145 
   4146 @table @var
   4147 @item sec_websocket_key
   4148 Value of the @code{Sec-WebSocket-Key} request header.
   4149 You can get this request header value by passing
   4150 @code{MHD_HTTP_HEADER_SEC_WEBSOCKET_KEY} to
   4151 @code{MHD_lookup_connection_value()}.
   4152 If you pass @code{NULL} then this is handled like a not
   4153 matching @code{Sec-WebSocket-Key} header value.
   4154 
   4155 @item sec_websocket_accept
   4156 Response buffer, which will receive
   4157 the generated value for the @code{Sec-WebSocket-Accept}
   4158 HTTP response header.
   4159 This buffer must be at least 29 bytes long and
   4160 will contain the response value plus a terminating @code{NUL}
   4161 character on success.
   4162 Must not be @code{NULL}.
   4163 You can add this HTTP header to your response by passing
   4164 @code{MHD_HTTP_HEADER_SEC_WEBSOCKET_ACCEPT} to
   4165 @code{MHD_add_response_header()}.
   4166 @end table
   4167 
   4168 Returns 0 when the @code{Sec-WebSocket-Key} header was
   4169 not empty and a result value for the @code{Sec-WebSocket-Accept}
   4170 was calculated.
   4171 A value less than zero is returned when the @code{Sec-WebSocket-Key}
   4172 header isn't valid for a websocket request or when any
   4173 error occurred.
   4174 Can be compared with @code{enum MHD_WEBSOCKET_STATUS}.
   4175 @end deftypefun
   4176 
   4177 
   4178 @c ------------------------------------------------------------
   4179 @node microhttpd-websocket stream
   4180 @section Websocket stream functions
   4181 
   4182 @deftypefun {enum MHD_WEBSOCKET_STATUS} MHD_websocket_stream_init (struct MHD_WebSocketStream **ws, int flags, size_t max_payload_size)
   4183 @cindex websocket
   4184 Creates a new websocket stream, used for decoding/encoding.
   4185 
   4186 @table @var
   4187 @item ws
   4188 pointer a variable to fill with the newly created
   4189 @code{struct MHD_WebSocketStream},
   4190 receives @code{NULL} on error. May not be @code{NULL}.
   4191 
   4192 If not required anymore, free the created websocket stream with
   4193 @code{MHD_websocket_stream_free()}.
   4194 
   4195 @item flags
   4196 combination of @code{enum MHD_WEBSOCKET_FLAG} values to
   4197 modify the behavior of the websocket stream.
   4198 
   4199 @item max_payload_size
   4200 maximum size for incoming payload data in bytes. Use 0 to allow each size.
   4201 @end table
   4202 
   4203 Returns 0 on success, negative values on error.
   4204 Can be compared with @code{enum MHD_WEBSOCKET_STATUS}.
   4205 @end deftypefun
   4206 
   4207 
   4208 @deftypefun {enum MHD_WEBSOCKET_STATUS} MHD_websocket_stream_init2 (struct MHD_WebSocketStream **ws, int flags, size_t max_payload_size, MHD_WebSocketMallocCallback callback_malloc, MHD_WebSocketReallocCallback callback_realloc, MHD_WebSocketFreeCallback callback_free, void* cls_rng, MHD_WebSocketRandomNumberGenerator callback_rng)
   4209 @cindex websocket
   4210 Creates a new websocket stream, used for decoding/encoding,
   4211 but with custom memory functions for malloc, realloc and free.
   4212 Also a random number generator can be specified for client mode.
   4213 
   4214 @table @var
   4215 @item ws
   4216 pointer a variable to fill with the newly created
   4217 @code{struct MHD_WebSocketStream},
   4218 receives @code{NULL} on error. Must not be @code{NULL}.
   4219 
   4220 If not required anymore, free the created websocket stream with
   4221 @code{MHD_websocket_stream_free}.
   4222 
   4223 @item flags
   4224 combination of @code{enum MHD_WEBSOCKET_FLAG} values to
   4225 modify the behavior of the websocket stream.
   4226 
   4227 @item max_payload_size
   4228 maximum size for incoming payload data in bytes. Use 0 to allow each size.
   4229 
   4230 @item callback_malloc
   4231 callback function for allocating memory. Must not be @code{NULL}.
   4232 The shorter @code{MHD_websocket_stream_init()} passes a reference to @code{malloc} here.
   4233 
   4234 @item callback_realloc
   4235 callback function for reallocating memory. Must not be @code{NULL}.
   4236 The shorter @code{MHD_websocket_stream_init()} passes a reference to @code{realloc} here.
   4237 
   4238 @item callback_free
   4239 callback function for freeing memory. Must not be @code{NULL}.
   4240 The shorter @code{MHD_websocket_stream_init()} passes a reference to @code{free} here.
   4241 
   4242 @item cls_rng
   4243 closure for the random number generator.
   4244 This is only required when
   4245 @code{MHD_WEBSOCKET_FLAG_CLIENT} is passed in @code{flags}.
   4246 The given value is passed to the random number generator callback.
   4247 May be @code{NULL} if not needed.
   4248 Should be @code{NULL} when you are not using @code{MHD_WEBSOCKET_FLAG_CLIENT}.
   4249 The shorter @code{MHD_websocket_stream_init} passes @code{NULL} here.
   4250 
   4251 @item callback_rng
   4252 callback function for a secure random number generator.
   4253 This is only required when @code{MHD_WEBSOCKET_FLAG_CLIENT} is
   4254 passed in @code{flags} and must not be @code{NULL} then.
   4255 Should be @code{NULL} otherwise.
   4256 The shorter @code{MHD_websocket_stream_init()} passes @code{NULL} here.
   4257 @end table
   4258 
   4259 Returns 0 on success, negative values on error.
   4260 Can be compared with @code{enum MHD_WEBSOCKET_STATUS}.
   4261 @end deftypefun
   4262 
   4263 
   4264 @deftypefun {enum MHD_WEBSOCKET_STATUS} MHD_websocket_stream_free (struct MHD_WebSocketStream *ws)
   4265 @cindex websocket
   4266 Frees a previously allocated websocket stream
   4267 
   4268 @table @var
   4269 @item ws
   4270 websocket stream to free, this value may be @code{NULL}.
   4271 @end table
   4272 
   4273 Returns 0 on success, negative values on error.
   4274 Can be compared with @code{enum MHD_WEBSOCKET_STATUS}.
   4275 @end deftypefun
   4276 
   4277 
   4278 @deftypefun {enum MHD_WEBSOCKET_STATUS} MHD_websocket_stream_invalidate (struct MHD_WebSocketStream *ws)
   4279 @cindex websocket
   4280 Invalidates a websocket stream.
   4281 After invalidation a websocket stream cannot be used for decoding anymore.
   4282 Encoding is still possible.
   4283 
   4284 @table @var
   4285 @item ws
   4286 websocket stream to invalidate.
   4287 @end table
   4288 
   4289 Returns 0 on success, negative values on error.
   4290 Can be compared with @code{enum MHD_WEBSOCKET_STATUS}.
   4291 @end deftypefun
   4292 
   4293 
   4294 @deftypefun {enum MHD_WEBSOCKET_VALIDITY} MHD_websocket_stream_is_valid (struct MHD_WebSocketStream *ws)
   4295 @cindex websocket
   4296 Queries whether a websocket stream is valid.
   4297 Invalidated websocket streams cannot be used for decoding anymore.
   4298 Encoding is still possible.
   4299 
   4300 @table @var
   4301 @item ws
   4302 websocket stream to invalidate.
   4303 @end table
   4304 
   4305 Returns 0 if invalid, 1 if valid for all types or
   4306 2 if valid only for control frames.
   4307 Can be compared with @code{enum MHD_WEBSOCKET_VALIDITY}.
   4308 @end deftypefun
   4309 
   4310 
   4311 @c ------------------------------------------------------------
   4312 @node microhttpd-websocket decode
   4313 @section Websocket decode functions
   4314 
   4315 
   4316 @deftypefun {enum MHD_WEBSOCKET_STATUS} MHD_websocket_decode (struct MHD_WebSocketStream* ws, const char* streambuf, size_t streambuf_len, size_t* streambuf_read_len, char** payload, size_t* payload_len)
   4317 @cindex websocket
   4318 Decodes a byte sequence for a websocket stream.
   4319 Decoding is done until either a frame is complete or
   4320 the end of the byte sequence is reached.
   4321 
   4322 @table @var
   4323 @item ws
   4324 websocket stream for decoding.
   4325 
   4326 @item streambuf
   4327 byte sequence for decoding.
   4328 This is what you typically received via @code{recv()}.
   4329 
   4330 @item streambuf_len
   4331 length of the byte sequence in parameter @code{streambuf}.
   4332 
   4333 @item streambuf_read_len
   4334 pointer to a variable, which receives the number of bytes,
   4335 that has been processed by this call.
   4336 This value may be less than the value of @code{streambuf_len} when
   4337 a frame is decoded before the end of the buffer is reached.
   4338 The remaining bytes of @code{buf} must be passed to
   4339 the next call of this function.
   4340 
   4341 @item payload
   4342 pointer to a variable, which receives the allocated buffer with the payload
   4343 data of the decoded frame. Must not be @code{NULL}.
   4344 If no decoded data is available or an error occurred @code{NULL} is returned.
   4345 When the returned value is not @code{NULL} then the buffer contains always
   4346 @code{payload_len} bytes plus one terminating @code{NUL} character
   4347 (regardless of the frame type).
   4348 
   4349 The caller must free this buffer using @code{MHD_websocket_free()}.
   4350 
   4351 If you passed the flag @code{MHD_WEBSOCKET_FLAG_GENERATE_CLOSE_FRAMES_ON_ERROR}
   4352 upon creation of the websocket stream and a decoding error occurred
   4353 (function return value less than 0), then this buffer contains
   4354 a generated close frame, which must be sent via the socket to the recipient.
   4355 
   4356 If you passed the flag @code{MHD_WEBSOCKET_FLAG_WANT_FRAGMENTS}
   4357 upon creation of the websocket stream then
   4358 this payload may only be a part of the complete message.
   4359 Only complete UTF-8 sequences are returned for fragmented text frames.
   4360 If necessary the UTF-8 sequence will be completed with the next text fragment.
   4361 
   4362 @item payload_len
   4363 pointer to a variable, which receives length of the result
   4364 @code{payload} buffer in bytes.
   4365 Must not be @code{NULL}.
   4366 This receives 0 when no data is available, when the decoded payload
   4367 has a length of zero or when an error occurred.
   4368 @end table
   4369 
   4370 Returns a value greater than zero when a frame is complete.
   4371 Compare with @code{enum MHD_WEBSOCKET_STATUS} to distinguish the frame type.
   4372 Returns 0 when the call succeeded, but no frame is available.
   4373 Returns a value less than zero on errors.
   4374 @end deftypefun
   4375 
   4376 
   4377 @deftypefun {enum MHD_WEBSOCKET_STATUS} MHD_websocket_split_close_reason (const char* payload, size_t payload_len, unsigned short* reason_code, const char** reason_utf8, size_t* reason_utf8_len)
   4378 @cindex websocket
   4379 Splits the payload of a decoded close frame.
   4380 
   4381 @table @var
   4382 @item payload
   4383 payload of the close frame.
   4384 This parameter may only be @code{NULL} if @code{payload_len} is 0.
   4385 
   4386 @item payload_len
   4387 length of @code{payload}.
   4388 
   4389 @item reason_code
   4390 pointer to a variable, which receives the numeric close reason.
   4391 If there was no close reason, this is 0.
   4392 This value can be compared with @code{enum MHD_WEBSOCKET_CLOSEREASON}.
   4393 May be @code{NULL}.
   4394 
   4395 @item reason_utf8
   4396 pointer to a variable, which receives the literal close reason.
   4397 If there was no literal close reason, this will be @code{NULL}.
   4398 May be @code{NULL}.
   4399 
   4400 Please note that no memory is allocated in this function.
   4401 If not @code{NULL} the returned value of this parameter
   4402 points to a position in the specified @code{payload}.
   4403 
   4404 @item reason_utf8_len
   4405 pointer to a variable, which receives the length of the literal close reason.
   4406 If there was no literal close reason, this is 0.
   4407 May be @code{NULL}.
   4408 @end table
   4409 
   4410 Returns 0 on success or a value less than zero on errors.
   4411 Can be compared with @code{enum MHD_WEBSOCKET_STATUS}.
   4412 @end deftypefun
   4413 
   4414 
   4415 @c ------------------------------------------------------------
   4416 @node microhttpd-websocket encode
   4417 @section Websocket encode functions
   4418 
   4419 
   4420 @deftypefun {enum MHD_WEBSOCKET_STATUS} MHD_websocket_encode_text (struct MHD_WebSocketStream* ws, const char* payload_utf8, size_t payload_utf8_len, int fragmentation, char** frame, size_t* frame_len, int* utf8_step)
   4421 @cindex websocket
   4422 Encodes an UTF-8 encoded text into websocket text frame
   4423 
   4424 @table @var
   4425 @item ws
   4426 websocket stream;
   4427 
   4428 @item payload_utf8
   4429 text to send. This must be UTF-8 encoded.
   4430 If you don't want UTF-8 then send a binary frame
   4431 with @code{MHD_websocket_encode_binary()} instead.
   4432 May be be @code{NULL} if @code{payload_utf8_len} is 0,
   4433 must not be @code{NULL} otherwise.
   4434 
   4435 @item payload_utf8_len
   4436 length of @code{payload_utf8} in bytes.
   4437 
   4438 @item fragmentation
   4439 A value of @code{enum MHD_WEBSOCKET_FRAGMENTATION}
   4440 to specify the fragmentation behavior.
   4441 Specify @code{MHD_WEBSOCKET_FRAGMENTATION_NONE} or just 0
   4442 if you don't want to use fragmentation (default).
   4443 
   4444 @item frame
   4445 pointer to a variable, which receives a buffer with the encoded text frame.
   4446 Must not be @code{NULL}.
   4447 The buffer contains what you typically send via @code{send()} to the recipient.
   4448 If no encoded data is available the variable receives @code{NULL}.
   4449 
   4450 If the variable is not @code{NULL} then the buffer contains always
   4451 @code{frame_len} bytes plus one terminating @code{NUL} character.
   4452 The caller must free this buffer using @code{MHD_websocket_free()}.
   4453 
   4454 @item frame_len
   4455 pointer to a variable, which receives the length of the encoded frame in bytes.
   4456 Must not be @code{NULL}.
   4457 
   4458 @item utf8_step
   4459 If fragmentation is used (the parameter @code{fragmentation} is not 0)
   4460 then is parameter is required and must not be @code{NULL}.
   4461 If no fragmentation is used, this parameter is optional and
   4462 should be @code{NULL}.
   4463 
   4464 This parameter is a pointer to a variable which contains the last check status
   4465 of the UTF-8 sequence. It is required to continue a previous
   4466 UTF-8 sequence check when fragmentation is used, because a UTF-8 sequence
   4467 could be split upon fragments.
   4468 
   4469 @code{enum MHD_WEBSOCKET_UTF8STEP} is used for this value.
   4470 If you start a new fragment using
   4471 @code{MHD_WEBSOCKET_FRAGMENTATION_NONE} or
   4472 @code{MHD_WEBSOCKET_FRAGMENTATION_FIRST} the old value of this variable
   4473 will be discarded and the value of this variable will be initialized
   4474 to @code{MHD_WEBSOCKET_UTF8STEP_NORMAL}.
   4475 On all other fragmentation modes the previous value of the pointed variable
   4476 will be used to continue the UTF-8 sequence check.
   4477 @end table
   4478 
   4479 Returns 0 on success or a value less than zero on errors.
   4480 Can be compared with @code{enum MHD_WEBSOCKET_STATUS}.
   4481 @end deftypefun
   4482 
   4483 
   4484 @deftypefun {enum MHD_WEBSOCKET_STATUS} MHD_websocket_encode_binary (struct MHD_WebSocketStream* ws, const char* payload, size_t payload_len, int fragmentation, char** frame, size_t* frame_len)
   4485 @cindex websocket
   4486 Encodes binary data into websocket binary frame
   4487 
   4488 @table @var
   4489 @item ws
   4490 websocket stream;
   4491 
   4492 @item payload
   4493 binary data to send.
   4494 May be be @code{NULL} if @code{payload_len} is 0,
   4495 must not be @code{NULL} otherwise.
   4496 
   4497 @item payload_len
   4498 length of @code{payload} in bytes.
   4499 
   4500 @item fragmentation
   4501 A value of @code{enum MHD_WEBSOCKET_FRAGMENTATION}
   4502 to specify the fragmentation behavior.
   4503 Specify @code{MHD_WEBSOCKET_FRAGMENTATION_NONE} or just 0
   4504 if you don't want to use fragmentation (default).
   4505 
   4506 @item frame
   4507 pointer to a variable, which receives a buffer with the encoded binary frame.
   4508 Must not be @code{NULL}.
   4509 The buffer contains what you typically send via @code{send()} to the recipient.
   4510 If no encoded data is available the variable receives @code{NULL}.
   4511 
   4512 If the variable is not @code{NULL} then the buffer contains always
   4513 @code{frame_len} bytes plus one terminating @code{NUL} character.
   4514 The caller must free this buffer using @code{MHD_websocket_free()}.
   4515 
   4516 @item frame_len
   4517 pointer to a variable, which receives the length of the encoded frame in bytes.
   4518 Must not be @code{NULL}.
   4519 @end table
   4520 
   4521 Returns 0 on success or a value less than zero on errors.
   4522 Can be compared with @code{enum MHD_WEBSOCKET_STATUS}.
   4523 @end deftypefun
   4524 
   4525 
   4526 @deftypefun {enum MHD_WEBSOCKET_STATUS} MHD_websocket_encode_ping (struct MHD_WebSocketStream* ws, const char* payload, size_t payload_len, char** frame, size_t* frame_len)
   4527 @cindex websocket
   4528 Encodes a websocket ping frame.
   4529 Ping frames are used to check whether a recipient is still available
   4530 and what latency the websocket connection has.
   4531 
   4532 @table @var
   4533 @item ws
   4534 websocket stream;
   4535 
   4536 @item payload
   4537 binary ping data to send.
   4538 May be @code{NULL} if @code{payload_len} is 0.
   4539 
   4540 @item payload_len
   4541 length of @code{payload} in bytes.
   4542 This may not exceed 125 bytes.
   4543 
   4544 @item frame
   4545 pointer to a variable, which receives a buffer with the encoded ping frame.
   4546 Must not be @code{NULL}.
   4547 The buffer contains what you typically send via @code{send()} to the recipient.
   4548 If no encoded data is available the variable receives @code{NULL}.
   4549 
   4550 If the variable is not @code{NULL} then the buffer contains always
   4551 @code{frame_len} bytes plus one terminating @code{NUL} character.
   4552 The caller must free this buffer using @code{MHD_websocket_free()}.
   4553 
   4554 @item frame_len
   4555 pointer to a variable, which receives the length of the encoded frame in bytes.
   4556 Must not be @code{NULL}.
   4557 @end table
   4558 
   4559 Returns 0 on success or a value less than zero on errors.
   4560 Can be compared with @code{enum MHD_WEBSOCKET_STATUS}.
   4561 @end deftypefun
   4562 
   4563 
   4564 @deftypefun {enum MHD_WEBSOCKET_STATUS} MHD_websocket_encode_pong (struct MHD_WebSocketStream* ws, const char* payload, size_t payload_len, char** frame, size_t* frame_len)
   4565 @cindex websocket
   4566 Encodes a websocket pong frame.
   4567 Pong frames are used to answer a previously received websocket ping frame.
   4568 
   4569 @table @var
   4570 @item ws
   4571 websocket stream;
   4572 
   4573 @item payload
   4574 binary pong data to send, which should be
   4575 the decoded payload from the received ping frame.
   4576 May be @code{NULL} if @code{payload_len} is 0.
   4577 
   4578 @item payload_len
   4579 length of @code{payload} in bytes.
   4580 This may not exceed 125 bytes.
   4581 
   4582 @item frame
   4583 pointer to a variable, which receives a buffer with the encoded pong frame.
   4584 Must not be @code{NULL}.
   4585 The buffer contains what you typically send via @code{send()} to the recipient.
   4586 If no encoded data is available the variable receives @code{NULL}.
   4587 
   4588 If the variable is not @code{NULL} then the buffer contains always
   4589 @code{frame_len} bytes plus one terminating @code{NUL} character.
   4590 The caller must free this buffer using @code{MHD_websocket_free()}.
   4591 
   4592 @item frame_len
   4593 pointer to a variable, which receives the length of the encoded frame in bytes.
   4594 Must not be @code{NULL}.
   4595 @end table
   4596 
   4597 Returns 0 on success or a value less than zero on errors.
   4598 Can be compared with @code{enum MHD_WEBSOCKET_STATUS}.
   4599 @end deftypefun
   4600 
   4601 
   4602 @deftypefun {enum MHD_WEBSOCKET_STATUS} MHD_websocket_encode_close (struct MHD_WebSocketStream* ws, unsigned short reason_code, const char* reason_utf8, size_t reason_utf8_len, char** frame, size_t* frame_len)
   4603 @cindex websocket
   4604 Encodes a websocket close frame.
   4605 Close frames are used to close a websocket connection in a formal way.
   4606 
   4607 @table @var
   4608 @item ws
   4609 websocket stream;
   4610 
   4611 @item reason_code
   4612 reason for close.
   4613 You can use @code{enum MHD_WEBSOCKET_CLOSEREASON} for typical reasons,
   4614 but you are not limited to these values.
   4615 The allowed values are specified in RFC 6455 7.4.
   4616 If you don't want to enter a reason, you can specify
   4617 @code{MHD_WEBSOCKET_CLOSEREASON_NO_REASON} (or just 0) then
   4618 no reason is encoded.
   4619 
   4620 @item reason_utf8
   4621 An UTF-8 encoded text reason why the connection is closed.
   4622 This may be @code{NULL} if @code{reason_utf8_len} is 0.
   4623 This must be @code{NULL} if @code{reason_code} equals to zero
   4624 (@code{MHD_WEBSOCKET_CLOSEREASON_NO_REASON}).
   4625 
   4626 @item reason_utf8_len
   4627 length of the UTF-8 encoded text reason in bytes.
   4628 This may not exceed 123 bytes.
   4629 
   4630 @item frame
   4631 pointer to a variable, which receives a buffer with the encoded close frame.
   4632 Must not be @code{NULL}.
   4633 The buffer contains what you typically send via @code{send()} to the recipient.
   4634 If no encoded data is available the variable receives @code{NULL}.
   4635 
   4636 If the variable is not @code{NULL} then the buffer contains always
   4637 @code{frame_len} bytes plus one terminating @code{NUL} character.
   4638 The caller must free this buffer using @code{MHD_websocket_free()}.
   4639 
   4640 @item frame_len
   4641 pointer to a variable, which receives the length of the encoded frame in bytes.
   4642 Must not be @code{NULL}.
   4643 @end table
   4644 
   4645 Returns 0 on success or a value less than zero on errors.
   4646 Can be compared with @code{enum MHD_WEBSOCKET_STATUS}.
   4647 @end deftypefun
   4648 
   4649 
   4650 @c ------------------------------------------------------------
   4651 @node microhttpd-websocket memory
   4652 @section Websocket memory functions
   4653 
   4654 
   4655 @deftypefun {void*} MHD_websocket_malloc (struct MHD_WebSocketStream* ws, size_t buf_len)
   4656 @cindex websocket
   4657 Allocates memory with the associated @code{malloc()} function
   4658 of the websocket stream.
   4659 The memory allocation function could be different for a websocket stream if
   4660 @code{MHD_websocket_stream_init2()} has been used for initialization.
   4661 
   4662 @table @var
   4663 @item ws
   4664 websocket stream;
   4665 
   4666 @item buf_len
   4667 size of the buffer to allocate in bytes.
   4668 @end table
   4669 
   4670 Returns the pointer of the allocated buffer or @code{NULL} on failure.
   4671 @end deftypefun
   4672 
   4673 
   4674 @deftypefun {void*} MHD_websocket_realloc (struct MHD_WebSocketStream* ws, void* buf, size_t new_buf_len)
   4675 @cindex websocket
   4676 Reallocates memory with the associated @code{realloc()} function
   4677 of the websocket stream.
   4678 The memory reallocation function could be different for a websocket stream if
   4679 @code{MHD_websocket_stream_init2()} has been used for initialization.
   4680 
   4681 @table @var
   4682 @item ws
   4683 websocket stream;
   4684 
   4685 @item buf
   4686 current buffer, may be @code{NULL};
   4687 
   4688 @item new_buf_len
   4689 new size of the buffer in bytes.
   4690 @end table
   4691 
   4692 Return the pointer of the reallocated buffer or @code{NULL} on failure.
   4693 On failure the old pointer remains valid.
   4694 @end deftypefun
   4695 
   4696 
   4697 @deftypefun {void} MHD_websocket_free (struct MHD_WebSocketStream* ws, void* buf)
   4698 @cindex websocket
   4699 Frees memory with the associated @code{free()} function
   4700 of the websocket stream.
   4701 The memory free function could be different for a websocket stream if
   4702 @code{MHD_websocket_stream_init2()} has been used for initialization.
   4703 
   4704 @table @var
   4705 @item ws
   4706 websocket stream;
   4707 
   4708 @item buf
   4709 buffer to free, this may be @code{NULL} then nothing happens.
   4710 @end table
   4711 
   4712 @end deftypefun
   4713 
   4714 
   4715 
   4716 
   4717 
   4718 @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   4719 
   4720 
   4721 @c **********************************************************
   4722 @c *******************  Appendices  *************************
   4723 @c **********************************************************
   4724 
   4725 @node GNU-LGPL
   4726 @unnumbered GNU-LGPL
   4727 @cindex license
   4728 @include lgpl.texi
   4729 
   4730 @node eCos License
   4731 @unnumbered eCos License
   4732 @cindex license
   4733 @include ecos.texi
   4734 
   4735 @node GNU-GPL
   4736 @unnumbered GNU General Public License
   4737 @cindex license
   4738 @include gpl-2.0.texi
   4739 
   4740 @node GNU-FDL
   4741 @unnumbered GNU-FDL
   4742 @cindex license
   4743 @include fdl-1.3.texi
   4744 
   4745 @node Concept Index
   4746 @unnumbered Concept Index
   4747 
   4748 @printindex cp
   4749 
   4750 @node Function and Data Index
   4751 @unnumbered Function and Data Index
   4752 
   4753 @printindex fn
   4754 
   4755 @node Type Index
   4756 @unnumbered Type Index
   4757 
   4758 @printindex tp
   4759 
   4760 @bye