Blame doc/libmicrohttpd.texi

Packit 875988
\input texinfo
Packit 875988
@setfilename libmicrohttpd.info
Packit 875988
@documentencoding UTF-8
Packit 875988
@include version.texi
Packit 875988
@settitle The GNU libmicrohttpd Reference Manual
Packit 875988
@c Unify all the indices into concept index.
Packit 875988
@syncodeindex vr cp
Packit 875988
@syncodeindex ky cp
Packit 875988
@syncodeindex pg cp
Packit 875988
@copying
Packit 875988
This manual is for GNU libmicrohttpd
Packit 875988
(version @value{VERSION}, @value{UPDATED}), a library for embedding
Packit 875988
an HTTP(S) server into C applications.
Packit 875988
Packit 875988
Copyright @copyright{} 2007--2017 Christian Grothoff
Packit 875988
Packit 875988
@quotation
Packit 875988
Permission is granted to copy, distribute and/or modify this document
Packit 875988
under the terms of the GNU Free Documentation License, Version 1.3
Packit 875988
or any later version published by the Free Software Foundation;
Packit 875988
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
Packit 875988
Texts.  A copy of the license is included in the section entitled "GNU
Packit 875988
Free Documentation License".
Packit 875988
@end quotation
Packit 875988
@end copying
Packit 875988
Packit 875988
@dircategory Software libraries
Packit 875988
@direntry
Packit 875988
* libmicrohttpd: (libmicrohttpd).       Embedded HTTP server library.
Packit 875988
@end direntry
Packit 875988
Packit 875988
@c
Packit 875988
@c Titlepage
Packit 875988
@c
Packit 875988
@titlepage
Packit 875988
@title The GNU libmicrohttpd Reference Manual
Packit 875988
@subtitle Version @value{VERSION}
Packit 875988
@subtitle @value{UPDATED}
Packit 875988
@author Marco Maggi (@email{marco.maggi-ipsu@@poste.it})
Packit 875988
@author Christian Grothoff (@email{christian@@grothoff.org})
Packit 875988
@page
Packit 875988
@vskip 0pt plus 1filll
Packit 875988
@insertcopying
Packit 875988
@end titlepage
Packit 875988
Packit 875988
@summarycontents
Packit 875988
@contents
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@ifnottex
Packit 875988
@node Top
Packit 875988
@top The GNU libmicrohttpd Library
Packit 875988
@insertcopying
Packit 875988
@end ifnottex
Packit 875988
Packit 875988
@menu
Packit 875988
* microhttpd-intro::            Introduction.
Packit 875988
* microhttpd-const::            Constants.
Packit 875988
* microhttpd-struct::           Structures type definition.
Packit 875988
* microhttpd-cb::               Callback functions definition.
Packit 875988
* microhttpd-init::             Starting and stopping the server.
Packit 875988
* microhttpd-inspect::          Implementing external @code{select}.
Packit 875988
* microhttpd-requests::         Handling requests.
Packit 875988
* microhttpd-responses::        Building responses to requests.
Packit 875988
* microhttpd-flow::             Flow control.
Packit 875988
* microhttpd-dauth::            Utilizing Authentication.
Packit 875988
* microhttpd-post::             Adding a @code{POST} processor.
Packit 875988
* microhttpd-info::             Obtaining and modifying status information.
Packit 875988
* microhttpd-util::             Utilities.
Packit 875988
Packit 875988
Appendices
Packit 875988
Packit 875988
* GNU-LGPL::                     The GNU Lesser General Public License says how you
Packit 875988
                                 can copy and share almost all of `libmicrohttpd'.
Packit 875988
* GNU GPL with eCos Extension::  The GNU General Public License with eCos extension says how you
Packit 875988
                                 can copy and share some parts of `libmicrohttpd'.
Packit 875988
* GNU-FDL::                     The GNU Free Documentation License says how you
Packit 875988
                                can copy and share the documentation of `libmicrohttpd'.
Packit 875988
Packit 875988
Indices
Packit 875988
Packit 875988
* Concept Index::               Index of concepts and programs.
Packit 875988
* Function and Data Index::     Index of functions, variables and data types.
Packit 875988
* Type Index::                  Index of data types.
Packit 875988
@end menu
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-intro
Packit 875988
@chapter Introduction
Packit 875988
Packit 875988
Packit 875988
@noindent
Packit 875988
All symbols defined in the public API start with @code{MHD_}.  MHD
Packit 875988
is a small HTTP daemon library.  As such, it does not have any API
Packit 875988
for logging errors (you can only enable or disable logging to stderr).
Packit 875988
Also, it may not support all of the HTTP features directly, where
Packit 875988
applicable, portions of HTTP may have to be handled by clients of the
Packit 875988
library.
Packit 875988
Packit 875988
The library is supposed to handle everything that it must handle
Packit 875988
(because the API would not allow clients to do this), such as basic
Packit 875988
connection management. However, detailed interpretations of headers,
Packit 875988
such as range requests, are left to the main application.  In
Packit 875988
particular, if an application developer wants to support range
Packit 875988
requests, he needs to explicitly indicate support in responses and
Packit 875988
also explicitly parse the range header and generate a response (for
Packit 875988
example, using the @code{MHD_create_response_from_fd_at_offset} call
Packit 875988
to serve ranges from a file).  MHD does understands headers that
Packit 875988
control connection management (specifically, @code{Connection: close}
Packit 875988
and @code{Expect: 100 continue} are understood and handled
Packit 875988
automatically).  @code{Connection: upgrade} is supported by passing
Packit 875988
control over the socket (or something that behaves like the real
Packit 875988
socket in the case of TLS) to the application (after sending the
Packit 875988
desired HTTP response header).
Packit 875988
Packit 875988
MHD largely ignores the semantics of the different HTTP methods,
Packit 875988
so clients are left to handle those.  One exception is that MHD does
Packit 875988
understand @code{HEAD} and will only send the headers of the response
Packit 875988
and not the body, even if the client supplied a body.  (In fact,
Packit 875988
clients do need to construct a response with the correct length, even
Packit 875988
for @code{HEAD} request.)
Packit 875988
Packit 875988
MHD understands @code{POST} data and is able to decode certain
Packit 875988
formats (at the moment only @code{application/x-www-form-urlencoded}
Packit 875988
and @code{multipart/form-data}) using the post processor API.  The
Packit 875988
data stream of a POST is also provided directly to the main
Packit 875988
application, so unsupported encodings could still be processed, just
Packit 875988
not conveniently by MHD.
Packit 875988
Packit 875988
The header file defines various constants used by the HTTP protocol.
Packit 875988
This does not mean that MHD actually interprets all of these values.
Packit 875988
The provided constants are exported as a convenience for users of the
Packit 875988
library.  MHD does not verify that transmitted HTTP headers are
Packit 875988
part of the standard specification; users of the library are free to
Packit 875988
define their own extensions of the HTTP standard and use those with
Packit 875988
MHD.
Packit 875988
Packit 875988
All functions are guaranteed to be completely reentrant and
Packit 875988
thread-safe.  MHD checks for allocation failures and tries to
Packit 875988
recover gracefully (for example, by closing the connection).
Packit 875988
Additionally, clients can specify resource limits on the overall
Packit 875988
number of connections, number of connections per IP address and memory
Packit 875988
used per connection to avoid resource exhaustion.
Packit 875988
Packit 875988
@section Scope
Packit 875988
Packit 875988
MHD is currently used in a wide range of implementations.
Packit 875988
Examples based on reports we've received from developers include:
Packit 875988
@itemize
Packit 875988
@item Embedded HTTP server on a cortex M3 (128 KB code space)
Packit 875988
@item Large-scale multimedia server (reportedly serving at the
Packit 875988
      simulator limit of 7.5 GB/s)
Packit 875988
@item Administrative console (via HTTP/HTTPS) for network appliances
Packit 875988
@c If you have other interesting examples, please let us know
Packit 875988
@end itemize
Packit 875988
Packit 875988
@section Thread modes and event loops
Packit 875988
@cindex poll
Packit 875988
@cindex epoll
Packit 875988
@cindex select
Packit 875988
Packit 875988
MHD supports four basic thread modes and up to three event loop
Packit 875988
styles.
Packit 875988
Packit 875988
The four basic thread modes are external sockets polling (MHD creates
Packit 875988
no threads, event loop is fully managed by the application), internal
Packit 875988
polling (MHD creates one thread for all connections), polling in
Packit 875988
thread pool (MHD creates a thread pool which is used to process all
Packit 875988
connections) and thread-per-connection (MHD creates one thread for
Packit 875988
listen sockets and then one thread per accepted connection).
Packit 875988
Packit 875988
These thread modes are then combined with the evet loop styles
Packit 875988
(polling function type).  MHD support select, poll and epoll. select
Packit 875988
is available on all platforms, epoll and poll may not be available on
Packit 875988
some platforms.  Note that it is possible to combine MHD using epoll
Packit 875988
with an external select-based event loop.
Packit 875988
Packit 875988
The default (if no other option is passed) is ``external select''.
Packit 875988
The highest performance can typically be obtained with a thread pool
Packit 875988
using @code{epoll}.  Apache Benchmark (ab) was used to compare the
Packit 875988
performance of @code{select} and @code{epoll} when using a thread pool
Packit 875988
and a large number of connections. @ref{fig:performance} shows the
Packit 875988
resulting plot from the @code{benchmark.c} example, which measures the
Packit 875988
latency between an incoming request and the completion of the
Packit 875988
transmission of the response.  In this setting, the @code{epoll}
Packit 875988
thread pool with four threads was able to handle more than 45,000
Packit 875988
connections per second on loopback (with Apache Benchmark running
Packit 875988
three processes on the same machine).
Packit 875988
@cindex performance
Packit 875988
Packit 875988
Packit 875988
@float Figure,fig:performance
Packit 875988
@image{libmicrohttpd_performance_data,400pt,300pt,Data,.png}
Packit 875988
@caption{Performance measurements for select vs. epoll (with thread-pool).}
Packit 875988
@end float
Packit 875988
Packit 875988
Packit 875988
Not all combinations of thread modes and event loop styles are
Packit 875988
supported.  This is partially to keep the API simple, and partially
Packit 875988
because some combinations simply make no sense as others are strictly
Packit 875988
superior.  Note that the choice of style depends first of all on the
Packit 875988
application logic, and then on the performance requirements.
Packit 875988
Applications that perform a blocking operation while handling a
Packit 875988
request within the callbacks from MHD must use a thread per
Packit 875988
connection.  This is typically rather costly.  Applications that do
Packit 875988
not support threads or that must run on embedded devices without
Packit 875988
thread-support must use the external mode.  Using @code{epoll} is only
Packit 875988
supported on some platform, thus portable applications must at least
Packit 875988
have a fallback option available.  @ref{tbl:supported} lists the sane
Packit 875988
combinations.
Packit 875988
Packit 875988
@float Table,tbl:supported
Packit 875988
@multitable {@b{thread-per-connection}} {@b{select}} {@b{poll}} {@b{epoll}}
Packit 875988
@item                           @tab @b{select} @tab @b{poll} @tab @b{epoll}
Packit 875988
@item @b{external}              @tab  yes       @tab no       @tab yes
Packit 875988
@item @b{internal}              @tab  yes       @tab yes      @tab yes
Packit 875988
@item @b{thread pool}           @tab  yes       @tab yes      @tab yes
Packit 875988
@item @b{thread-per-connection} @tab  yes       @tab yes      @tab no
Packit 875988
@end multitable
Packit 875988
@caption{Supported combinations of event styles and thread modes.}
Packit 875988
@end float
Packit 875988
Packit 875988
Packit 875988
@section Compiling GNU libmicrohttpd
Packit 875988
@cindex compilation
Packit 875988
@cindex embedded systems
Packit 875988
@cindex portability
Packit 875988
Packit 875988
MHD uses the standard GNU system where the usual build process
Packit 875988
involves running
Packit 875988
@verbatim
Packit 875988
$ ./configure
Packit 875988
$ make
Packit 875988
$ make install
Packit 875988
@end verbatim
Packit 875988
Packit 875988
MHD supports various options to be given to configure to tailor the
Packit 875988
binary to a specific situation.  Note that some of these options will
Packit 875988
remove portions of the MHD code that are required for
Packit 875988
binary-compatibility.  They should only be used on embedded systems
Packit 875988
with tight resource constraints and no concerns about library
Packit 875988
versioning.  Standard distributions including MHD are expected to
Packit 875988
always ship with all features enabled, otherwise unexpected
Packit 875988
incompatibilities can arise!
Packit 875988
Packit 875988
Here is a list of MHD-specific options that can be given to configure
Packit 875988
(canonical configure options such as ``--prefix'' are also supported, for a
Packit 875988
full list of options run ``./configure --help''):
Packit 875988
Packit 875988
@table @code
Packit 875988
@item ``--disable-curl''
Packit 875988
disable running testcases using libcurl
Packit 875988
Packit 875988
@item ``--disable-largefile''
Packit 875988
disable support for 64-bit files
Packit 875988
Packit 875988
@item ``--disable-messages''
Packit 875988
disable logging of error messages (smaller binary size, not so much fun for debugging)
Packit 875988
Packit 875988
@item ``--disable-https''
Packit 875988
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)
Packit 875988
Packit 875988
@item ``--disable-postprocessor''
Packit 875988
do not include the post processor API (results in binary incompatibility)
Packit 875988
Packit 875988
@item ``--disable-dauth''
Packit 875988
do not include the authentication APIs (results in binary incompatibility)
Packit 875988
Packit 875988
@item ``--disable-httpupgrade''
Packit 875988
do not build code for HTTP ``Upgrade'' (smaller binary size, binary incompatible library)
Packit 875988
Packit 875988
@item ``--disable-epoll''
Packit 875988
do not include epoll support, even if it supported (minimally smaller binary size, good for portability testing)
Packit 875988
Packit 875988
@item ``--enable-coverage''
Packit 875988
set flags for analysis of code-coverage with gcc/gcov (results in slow, large binaries)
Packit 875988
Packit 875988
@item ``--with-gcrypt=PATH''
Packit 875988
specifies path to libgcrypt installation
Packit 875988
Packit 875988
@item ``--with-gnutls=PATH''
Packit 875988
specifies path to libgnutls installation
Packit 875988
Packit 875988
Packit 875988
@end table
Packit 875988
Packit 875988
@section Validity of pointers
Packit 875988
Packit 875988
MHD will give applications access to its internal data structures
Packit 875988
via pointers via arguments and return values from its API.  This
Packit 875988
creates the question as to how long those pointers are assured to
Packit 875988
stay valid.
Packit 875988
Packit 875988
Most MHD data structures are associated with the connection of an
Packit 875988
HTTP client.  Thus, pointers associated with a connection are
Packit 875988
typically valid until the connection is finished, at which point
Packit 875988
MHD will call the @code{MHD_RequestCompletedCallback} if one is
Packit 875988
registered.  Applications that have such a callback registered
Packit 875988
may assume that keys and values from the
Packit 875988
@code{MHD_KeyValueIterator}, return values from
Packit 875988
@code{MHD_lookup_connection_value} and the @code{url},
Packit 875988
@code{method} and @code{version} arguments to the
Packit 875988
@code{MHD_AccessHandlerCallback} will remain valid until the
Packit 875988
respective @code{MHD_RequestCompletedCallback} is invoked.
Packit 875988
Packit 875988
In contrast, the @code{upload_data} argument of
Packit 875988
@code{MHD_RequestCompletedCallback} as well as all pointers
Packit 875988
from the @code{MHD_PostDataIterator} are only valid for the
Packit 875988
duration of the callback.
Packit 875988
Packit 875988
Pointers returned from @code{MHD_get_response_header} are
Packit 875988
valid as long as the response itself is valid.
Packit 875988
Packit 875988
Packit 875988
@section Including the microhttpd.h header
Packit 875988
@cindex portability
Packit 875988
@cindex microhttpd.h
Packit 875988
Packit 875988
Ideally, before including "microhttpd.h" you should add the necessary
Packit 875988
includes to define the @code{uint64_t}, @code{size_t}, @code{fd_set},
Packit 875988
@code{socklen_t} and @code{struct sockaddr} data types.  Which
Packit 875988
specific headers are needed may depend on your platform and your build
Packit 875988
system might include some tests to provide you with the necessary
Packit 875988
conditional operations.  For possible suggestions consult
Packit 875988
@code{platform.h} and @code{configure.ac} in the MHD distribution.
Packit 875988
Packit 875988
Once you have ensured that you manually (!) included the right headers
Packit 875988
for your platform before "microhttpd.h", you should also add a line
Packit 875988
with @code{#define MHD_PLATFORM_H} which will prevent the
Packit 875988
"microhttpd.h" header from trying (and, depending on your platform,
Packit 875988
failing) to include the right headers.
Packit 875988
Packit 875988
If you do not define MHD_PLATFORM_H, the "microhttpd.h" header will
Packit 875988
automatically include headers needed on GNU/Linux systems (possibly
Packit 875988
causing problems when porting to other platforms).
Packit 875988
Packit 875988
@section SIGPIPE
Packit 875988
@cindex signals
Packit 875988
MHD does not install a signal handler for SIGPIPE.  On platforms where
Packit 875988
this is possible (such as GNU/Linux), it disables SIGPIPE for its I/O
Packit 875988
operations (by passing MSG_NOSIGNAL or similar).  On other platforms,
Packit 875988
SIGPIPE signals may be generated from network operations by MHD and
Packit 875988
will cause the process to die unless the developer explicitly installs
Packit 875988
a signal handler for SIGPIPE.
Packit 875988
Packit 875988
Hence portable code using MHD must install a SIGPIPE handler or
Packit 875988
explicitly block the SIGPIPE signal.  MHD does not do so in order to
Packit 875988
avoid messing with other parts of the application that may need to
Packit 875988
handle SIGPIPE in a particular way.  You can make your application
Packit 875988
handle SIGPIPE by calling the following function in @code{main}:
Packit 875988
Packit 875988
@verbatim
Packit 875988
static void
Packit 875988
catcher (int sig)
Packit 875988
{
Packit 875988
}
Packit 875988
Packit 875988
static void
Packit 875988
ignore_sigpipe ()
Packit 875988
{
Packit 875988
  struct sigaction oldsig;
Packit 875988
  struct sigaction sig;
Packit 875988
Packit 875988
  sig.sa_handler = &catcher;
Packit 875988
  sigemptyset (&sig.sa_mask);
Packit 875988
#ifdef SA_INTERRUPT
Packit 875988
  sig.sa_flags = SA_INTERRUPT;  /* SunOS */
Packit 875988
#else
Packit 875988
  sig.sa_flags = SA_RESTART;
Packit 875988
#endif
Packit 875988
  if (0 != sigaction (SIGPIPE, &sig, &oldsig))
Packit 875988
    fprintf (stderr,
Packit 875988
             "Failed to install SIGPIPE handler: %s\n", strerror (errno));
Packit 875988
}
Packit 875988
@end verbatim
Packit 875988
Packit 875988
@section MHD_UNSIGNED_LONG_LONG
Packit 875988
@cindex long long
Packit 875988
@cindex MHD_LONG_LONG
Packit 875988
@cindex IAR
Packit 875988
@cindex ARM
Packit 875988
@cindex cortex m3
Packit 875988
@cindex embedded systems
Packit 875988
Packit 875988
Some platforms do not support @code{long long}.  Hence MHD defines a
Packit 875988
macro @code{MHD_UNSIGNED LONG_LONG} which will default to
Packit 875988
@code{unsigned long long}.  For standard desktop operating systems,
Packit 875988
this is all you need to know.
Packit 875988
Packit 875988
However, if your platform does not support @code{unsigned long long},
Packit 875988
you should change "platform.h" to define @code{MHD_LONG_LONG} and
Packit 875988
@code{MHD_UNSIGNED_LONG_LONG} to an appropriate alternative type and
Packit 875988
also define @code{MHD_LONG_LONG_PRINTF} and
Packit 875988
@code{MHD_UNSIGNED_LONG_LONG_PRINTF} to the corresponding format
Packit 875988
string for printing such a data type.  Note that the ``signed''
Packit 875988
versions are deprecated.  Also, for historical reasons,
Packit 875988
@code{MHD_LONG_LONG_PRINTF} is without the percent sign, whereas
Packit 875988
@code{MHD_UNSIGNED_LONG_LONG_PRINTF} is with the percent sign.  Newly
Packit 875988
written code should only use the unsigned versions.  However, you need
Packit 875988
to define both in "platform.h" if you need to change the definition
Packit 875988
for the specific platform.
Packit 875988
Packit 875988
Packit 875988
@section Portability to W32
Packit 875988
Packit 875988
libmicrohttpd in general ported well to W32. Most libmicrohttpd features
Packit 875988
are supported. W32 do not support some functions, like epoll and
Packit 875988
corresponding MHD features are not available on W32.
Packit 875988
Packit 875988
Packit 875988
@section Portability to z/OS
Packit 875988
Packit 875988
To compile MHD on z/OS, extract the archive and run
Packit 875988
Packit 875988
@verbatim
Packit 875988
iconv -f UTF-8 -t IBM-1047 contrib/ascebc > /tmp/ascebc.sh
Packit 875988
chmod +x /tmp/ascebc.sh
Packit 875988
for n in `find * -type f`
Packit 875988
do
Packit 875988
  /tmp/ascebc.sh $n
Packit 875988
done
Packit 875988
@end verbatim
Packit 875988
to convert all source files to EBCDIC.  Note that you must run
Packit 875988
@code{configure} from the directory where the configure script is
Packit 875988
located.   Otherwise, configure will fail to find the
Packit 875988
@code{contrib/xcc} script (which is a wrapper around the z/OS c89
Packit 875988
compiler).
Packit 875988
Packit 875988
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-const
Packit 875988
@chapter Constants
Packit 875988
Packit 875988
Packit 875988
@deftp {Enumeration} MHD_FLAG
Packit 875988
Options for the MHD daemon.
Packit 875988
Packit 875988
Note that MHD will run automatically in background thread(s) only if
Packit 875988
@code{MHD_USE_INTERNAL_POLLING_THREAD} is used. Otherwise caller
Packit 875988
(application) must use @code{MHD_run} or @code{MHD_run_from_select} to
Packit 875988
have MHD processed network connections and data.
Packit 875988
Packit 875988
Starting the daemon may also fail if a particular option is not
Packit 875988
implemented or not supported on the target platform (i.e. no support
Packit 875988
for @acronym{TLS}, threads or IPv6). TLS support generally depends on
Packit 875988
options given during MHD compilation.
Packit 875988
Packit 875988
@table @code
Packit 875988
@item MHD_NO_FLAG
Packit 875988
No options selected.
Packit 875988
Packit 875988
@item MHD_USE_ERROR_LOG
Packit 875988
If this flag is used, the library should print error messages and
Packit 875988
warnings to stderr (or to custom error printer if it's specified by
Packit 875988
options).  Note that for this run-time option to have any effect, MHD
Packit 875988
needs to be compiled with messages enabled. This is done by default
Packit 875988
except you ran configure with the @code{--disable-messages} flag set.
Packit 875988
Packit 875988
@item MHD_USE_DEBUG
Packit 875988
@cindex debugging
Packit 875988
Currently the same as @code{MHD_USE_ERROR_LOG}.
Packit 875988
Packit 875988
@item MHD_USE_TLS
Packit 875988
@cindex TLS
Packit 875988
@cindex SSL
Packit 875988
Run in HTTPS-mode.  If you specify @code{MHD_USE_TLS} and MHD was
Packit 875988
compiled without SSL support, @code{MHD_start_daemon} will return
Packit 875988
NULL.
Packit 875988
Packit 875988
@item MHD_USE_THREAD_PER_CONNECTION
Packit 875988
Run using one thread per connection.
Packit 875988
Packit 875988
@item MHD_USE_INTERNAL_POLLING_THREAD
Packit 875988
Run using an internal thread doing @code{SELECT}.
Packit 875988
Packit 875988
@item MHD_USE_IPv6
Packit 875988
@cindex IPv6
Packit 875988
Run using the IPv6 protocol (otherwise, MHD will just support IPv4).
Packit 875988
If you specify @code{MHD_USE_IPV6} and the local platform does not
Packit 875988
support it, @code{MHD_start_daemon} will return NULL.
Packit 875988
Packit 875988
If you want MHD to support IPv4 and IPv6 using a single socket, pass
Packit 875988
MHD_USE_DUAL_STACK, otherwise, if you only pass this option, MHD will
Packit 875988
try to bind to IPv6-only (resulting in no IPv4 support).
Packit 875988
Packit 875988
@item MHD_USE_DUAL_STACK
Packit 875988
@cindex IPv6
Packit 875988
Use a single socket for IPv4 and IPv6.  Note that this will mean
Packit 875988
that IPv4 addresses are returned by MHD in the IPv6-mapped format
Packit 875988
(the 'struct sockaddr_in6' format will be used for IPv4 and IPv6).
Packit 875988
Packit 875988
@item MHD_USE_PEDANTIC_CHECKS
Packit 875988
@cindex deprecated
Packit 875988
Deprecated (use @code{MHD_OPTION_STRICT_FOR_CLIENT}).
Packit 875988
Be pedantic about the protocol.
Packit 875988
Specifically, at the moment, this flag causes MHD to reject HTTP
Packit 875988
1.1 connections without a @code{Host} header.  This is required by the
Packit 875988
standard, but of course in violation of the ``be as liberal as possible
Packit 875988
in what you accept'' norm.  It is recommended to turn this @strong{ON}
Packit 875988
if you are testing clients against MHD, and @strong{OFF} in
Packit 875988
production.
Packit 875988
Packit 875988
@item MHD_USE_POLL
Packit 875988
@cindex FD_SETSIZE
Packit 875988
@cindex poll
Packit 875988
@cindex select
Packit 875988
Use @code{poll()} instead of @code{select()}. This allows sockets with
Packit 875988
descriptors @code{>= FD_SETSIZE}.  This option currently only works in
Packit 875988
conjunction with @code{MHD_USE_INTERNAL_POLLING_THREAD} (at this point).
Packit 875988
If you specify @code{MHD_USE_POLL} and the local platform does not
Packit 875988
support it, @code{MHD_start_daemon} will return NULL.
Packit 875988
Packit 875988
@item MHD_USE_EPOLL
Packit 875988
@cindex FD_SETSIZE
Packit 875988
@cindex epoll
Packit 875988
@cindex select
Packit 875988
Use @code{epoll()} instead of @code{poll()} or @code{select()}. This
Packit 875988
allows sockets with descriptors @code{>= FD_SETSIZE}.  This option is
Packit 875988
only available on some systems and does not work in conjunction with
Packit 875988
@code{MHD_USE_THREAD_PER_CONNECTION} (at this point).  If you specify
Packit 875988
@code{MHD_USE_EPOLL} and the local platform does not support it,
Packit 875988
@code{MHD_start_daemon} will return NULL.  Using @code{epoll()}
Packit 875988
instead of @code{select()} or @code{poll()} can in some situations
Packit 875988
result in significantly higher performance as the system call has
Packit 875988
fundamentally lower complexity (O(1) for @code{epoll()} vs. O(n) for
Packit 875988
@code{select()}/@code{poll()} where n is the number of open
Packit 875988
connections).
Packit 875988
Packit 875988
@item MHD_USE_TURBO
Packit 875988
@cindex performance
Packit 875988
Enable optimizations to aggressively improve performance.
Packit 875988
Packit 875988
Currently, the optimizations this option enables are based on
Packit 875988
opportunistic reads and writes.  Bascially, MHD will simply try to
Packit 875988
read or write or accept on a socket before checking that the socket is
Packit 875988
ready for IO using the event loop mechanism.  As the sockets are
Packit 875988
non-blocking, this may fail (at a loss of performance), but generally
Packit 875988
MHD does this in situations where the operation is likely to succeed,
Packit 875988
in which case performance is improved.  Setting the flag should generally
Packit 875988
be safe (even though the code is slightly more experimental).  You may
Packit 875988
want to benchmark your application to see if this makes any difference
Packit 875988
for you.
Packit 875988
Packit 875988
Packit 875988
@item MHD_USE_SUPPRESS_DATE_NO_CLOCK
Packit 875988
@cindex date
Packit 875988
@cindex clock
Packit 875988
@cindex embedded systems
Packit 875988
Suppress (automatically) adding the 'Date:' header to HTTP responses.
Packit 875988
This option should ONLY be used on systems that do not have a clock
Packit 875988
and that DO provide other mechanisms for cache control.  See also
Packit 875988
RFC 2616, section 14.18 (exception 3).
Packit 875988
Packit 875988
Packit 875988
@item MHD_USE_NO_LISTEN_SOCKET
Packit 875988
@cindex listen
Packit 875988
@cindex proxy
Packit 875988
@cindex embedded systems
Packit 875988
Run the HTTP server without any listen socket.  This option only makes
Packit 875988
sense if @code{MHD_add_connection} is going to be used exclusively to
Packit 875988
connect HTTP clients to the HTTP server.  This option is incompatible
Packit 875988
with using a thread pool; if it is used,
Packit 875988
@code{MHD_OPTION_THREAD_POOL_SIZE} is ignored.
Packit 875988
Packit 875988
Packit 875988
@item MHD_USE_ITC
Packit 875988
@cindex quiesce
Packit 875988
Force MHD to use a signal inter-thread communication channel to notify
Packit 875988
the event loop (of threads) of our shutdown and other events.  This is
Packit 875988
required if an application uses @code{MHD_USE_INTERNAL_POLLING_THREAD}
Packit 875988
and then performs @code{MHD_quiesce_daemon} (which eliminates our
Packit 875988
ability to signal termination via the listen socket).  In these modes,
Packit 875988
@code{MHD_quiesce_daemon} will fail if this option was not set.  Also,
Packit 875988
use of this option is automatic (as in, you do not even have to
Packit 875988
specify it), if @code{MHD_USE_NO_LISTEN_SOCKET} is specified.  In
Packit 875988
"external" select mode, this option is always simply ignored.
Packit 875988
Packit 875988
Using this option also guarantees that MHD will not call
Packit 875988
@code{shutdown()} on the listen socket, which means a parent
Packit 875988
process can continue to use the socket.
Packit 875988
Packit 875988
@item MHD_ALLOW_SUSPEND_RESUME
Packit 875988
Enables using @code{MHD_suspend_connection} and
Packit 875988
@code{MHD_resume_connection}, as performing these calls requires some
Packit 875988
additional inter-thred communication channels to be created, and code
Packit 875988
not using these calls should not pay the cost.
Packit 875988
Packit 875988
@item MHD_USE_TCP_FASTOPEN
Packit 875988
@cindex listen
Packit 875988
Enable TCP_FASTOPEN on the listen socket.  TCP_FASTOPEN is currently
Packit 875988
supported on Linux >= 3.6.  On other systems using this option with
Packit 875988
cause @code{MHD_start_daemon} to fail.
Packit 875988
Packit 875988
Packit 875988
@item MHD_ALLOW_UPGRADE
Packit 875988
@cindex upgrade
Packit 875988
This option must be set if you want to upgrade connections
Packit 875988
(via ``101 Switching Protocols'' responses).  This requires MHD to
Packit 875988
allocate additional resources, and hence we require this
Packit 875988
special flag so we only use the resources that are really needed.
Packit 875988
Packit 875988
Packit 875988
@item MHD_USE_AUTO
Packit 875988
Automatically select best event loop style (polling function)
Packit 875988
depending on requested mode by other MHD flags and functions available
Packit 875988
on platform.  If application doesn't have requirements for any
Packit 875988
specific polling function, it's recommended to use this flag.  This
Packit 875988
flag is very convenient for multiplatform applications.
Packit 875988
Packit 875988
@end table
Packit 875988
@end deftp
Packit 875988
Packit 875988
Packit 875988
@deftp {Enumeration} MHD_OPTION
Packit 875988
MHD options.  Passed in the varargs portion of
Packit 875988
@code{MHD_start_daemon()}.
Packit 875988
Packit 875988
@table @code
Packit 875988
@item MHD_OPTION_END
Packit 875988
No more options / last option.  This is used to terminate the VARARGs
Packit 875988
list.
Packit 875988
Packit 875988
@item MHD_OPTION_CONNECTION_MEMORY_LIMIT
Packit 875988
@cindex memory, limiting memory utilization
Packit 875988
Maximum memory size per connection (followed by a @code{size_t}).  The
Packit 875988
default is 32 kB (32*1024 bytes) as defined by the internal constant
Packit 875988
@code{MHD_POOL_SIZE_DEFAULT}.  Values above 128k are unlikely to
Packit 875988
result in much benefit, as half of the memory will be typically used
Packit 875988
for IO, and TCP buffers are unlikely to support window sizes above 64k
Packit 875988
on most systems.
Packit 875988
Packit 875988
@item MHD_OPTION_CONNECTION_MEMORY_INCREMENT
Packit 875988
@cindex memory
Packit 875988
Increment to use for growing the read buffer (followed by a
Packit 875988
@code{size_t}).  The default is 1024 (bytes).  Increasing this value
Packit 875988
will make MHD use memory for reading more aggressively, which can
Packit 875988
reduce the number of @code{recvfrom} calls but may increase the number
Packit 875988
of @code{sendto} calls.  The given value must fit within
Packit 875988
MHD_OPTION_CONNECTION_MEMORY_LIMIT.
Packit 875988
Packit 875988
@item MHD_OPTION_CONNECTION_LIMIT
Packit 875988
@cindex connection, limiting number of connections
Packit 875988
Maximum number of concurrent connections to accept (followed by an
Packit 875988
@code{unsigned int}).  The default is @code{FD_SETSIZE - 4} (the
Packit 875988
maximum number of file descriptors supported by @code{select} minus
Packit 875988
four for @code{stdin}, @code{stdout}, @code{stderr} and the server
Packit 875988
socket).  In other words, the default is as large as possible.
Packit 875988
Packit 875988
If the connection limit is reached, MHD's behavior depends a bit on
Packit 875988
other options.  If @code{MHD_USE_ITC} was given, MHD
Packit 875988
will stop accepting connections on the listen socket.  This will cause
Packit 875988
the operating system to queue connections (up to the @code{listen()}
Packit 875988
limit) above the connection limit.  Those connections will be held
Packit 875988
until MHD is done processing at least one of the active connections.
Packit 875988
If @code{MHD_USE_ITC} is not set, then MHD will continue
Packit 875988
to @code{accept()} and immediately @code{close()} these connections.
Packit 875988
Packit 875988
Note that if you set a low connection limit, you can easily get into
Packit 875988
trouble with browsers doing request pipelining.  For example, if your
Packit 875988
connection limit is ``1'', a browser may open a first connection to
Packit 875988
access your ``index.html'' file, keep it open but use a second
Packit 875988
connection to retrieve CSS files, images and the like.  In fact, modern
Packit 875988
browsers are typically by default configured for up to 15 parallel
Packit 875988
connections to a single server.  If this happens, MHD will refuse to
Packit 875988
even accept the second connection until the first connection is
Packit 875988
closed --- which does not happen until timeout.  As a result, the
Packit 875988
browser will fail to render the page and seem to hang.  If you expect
Packit 875988
your server to operate close to the connection limit, you should
Packit 875988
first consider using a lower timeout value and also possibly add
Packit 875988
a ``Connection: close'' header to your response to ensure that
Packit 875988
request pipelining is not used and connections are closed immediately
Packit 875988
after the request has completed:
Packit 875988
@example
Packit 875988
MHD_add_response_header (response,
Packit 875988
                         MHD_HTTP_HEADER_CONNECTION,
Packit 875988
                         "close");
Packit 875988
@end example
Packit 875988
Packit 875988
@item MHD_OPTION_CONNECTION_TIMEOUT
Packit 875988
@cindex timeout
Packit 875988
After how many seconds of inactivity should a connection automatically
Packit 875988
be timed out? (followed by an @code{unsigned int}; use zero for no
Packit 875988
timeout).  The default is zero (no timeout).
Packit 875988
Packit 875988
@item MHD_OPTION_NOTIFY_COMPLETED
Packit 875988
Register a function that should be called whenever a request has been
Packit 875988
completed (this can be used for application-specific clean up).
Packit 875988
Requests that have never been presented to the application (via
Packit 875988
@code{MHD_AccessHandlerCallback()}) will not result in
Packit 875988
notifications.
Packit 875988
Packit 875988
This option should be followed by @strong{TWO} pointers.  First a
Packit 875988
pointer to a function of type @code{MHD_RequestCompletedCallback()}
Packit 875988
and second a pointer to a closure to pass to the request completed
Packit 875988
callback.  The second pointer maybe @code{NULL}.
Packit 875988
Packit 875988
@item MHD_OPTION_NOTIFY_CONNECTION
Packit 875988
Register a function that should be called when the TCP connection to a
Packit 875988
client is opened or closed.  Note that
Packit 875988
@code{MHD_OPTION_NOTIFY_COMPLETED} and the @code{con_cls} argument to
Packit 875988
the @code{MHD_AccessHandlerCallback} are per HTTP request (and there
Packit 875988
can be multiple HTTP requests per TCP connection).  The registered
Packit 875988
callback is called twice per TCP connection, with
Packit 875988
@code{MHD_CONNECTION_NOTIFY_STARTED} and
Packit 875988
@code{MHD_CONNECTION_NOTIFY_CLOSED} respectively.  An additional
Packit 875988
argument can be used to store TCP connection specific information,
Packit 875988
which can be retrieved using @code{MHD_CONNECTION_INFO_SOCKET_CONTEXT}
Packit 875988
during the lifetime of the TCP connection.  The respective location is
Packit 875988
not the same as the HTTP-request-specific @code{con_cls} from the
Packit 875988
@code{MHD_AccessHandlerCallback}.
Packit 875988
Packit 875988
This option should be followed by @strong{TWO} pointers.  First a
Packit 875988
pointer to a function of type @code{MHD_NotifyConnectionCallback()}
Packit 875988
and second a pointer to a closure to pass to the request completed
Packit 875988
callback.  The second pointer maybe @code{NULL}.
Packit 875988
Packit 875988
@item MHD_OPTION_PER_IP_CONNECTION_LIMIT
Packit 875988
Limit on the number of (concurrent) connections made to the
Packit 875988
server from the same IP address.  Can be used to prevent one
Packit 875988
IP from taking over all of the allowed connections.  If the
Packit 875988
same IP tries to establish more than the specified number of
Packit 875988
connections, they will be immediately rejected.  The option
Packit 875988
should be followed by an @code{unsigned int}.  The default is
Packit 875988
zero, which means no limit on the number of connections
Packit 875988
from the same IP address.
Packit 875988
Packit 875988
@item MHD_OPTION_LISTEN_BACKLOG_SIZE
Packit 875988
Set the size of the @code{listen()} back log queue of the TCP socket.
Packit 875988
Takes an @code{unsigned int} as the argument.  Default is the
Packit 875988
platform-specific value of @code{SOMAXCONN}.
Packit 875988
Packit 875988
@item MHD_OPTION_STRICT_FOR_CLIENT
Packit 875988
Specify how strict we should enforce the HTTP protocol.
Packit 875988
Takes an @code{int} as the argument.  Default is zero.
Packit 875988
Packit 875988
If set to 1, MHD will be strict about the protocol.  Specifically, at
Packit 875988
the moment, this flag uses MHD to reject HTTP 1.1 connections without
Packit 875988
a "Host" header.  This is required by the standard, but of course in
Packit 875988
violation of the "be as liberal as possible in what you accept" norm.
Packit 875988
It is recommended to set this to 1 if you are testing clients against
Packit 875988
MHD, and 0 in production.
Packit 875988
Packit 875988
If set to -1 MHD will be permissive about the protocol, allowing
Packit 875988
slight deviations that are technically not allowed by the
Packit 875988
RFC. Specifically, at the moment, this flag causes MHD to allow spaces
Packit 875988
in header field names. This is disallowed by the standard.
Packit 875988
Packit 875988
It is not recommended to set it to -1 on publicly available servers as
Packit 875988
it may potentially lower level of protection.
Packit 875988
Packit 875988
Packit 875988
@item MHD_OPTION_SOCK_ADDR
Packit 875988
@cindex bind, restricting bind
Packit 875988
Bind daemon to the supplied socket address. This option should be followed by a
Packit 875988
@code{struct sockaddr *}.  If @code{MHD_USE_IPv6} is specified,
Packit 875988
the @code{struct sockaddr*} should point to a @code{struct sockaddr_in6},
Packit 875988
otherwise to a @code{struct sockaddr_in}.  If this option is not specified,
Packit 875988
the daemon will listen to incoming connections from anywhere.  If you use this
Packit 875988
option, the 'port' argument from @code{MHD_start_daemon} is ignored and the port
Packit 875988
from the given @code{struct sockaddr *} will be used instead.
Packit 875988
Packit 875988
@item MHD_OPTION_URI_LOG_CALLBACK
Packit 875988
@cindex debugging
Packit 875988
@cindex logging
Packit 875988
@cindex query string
Packit 875988
Specify a function that should be called before parsing the URI from
Packit 875988
the client.  The specified callback function can be used for processing
Packit 875988
the URI (including the options) before it is parsed.  The URI after
Packit 875988
parsing will no longer contain the options, which maybe inconvenient for
Packit 875988
logging.  This option should be followed by two arguments, the first
Packit 875988
one must be of the form
Packit 875988
@example
Packit 875988
 void * my_logger(void * cls, const char * uri, struct MHD_Connection *con)
Packit 875988
@end example
Packit 875988
where the return value will be passed as
Packit 875988
@code{*con_cls} in calls to the @code{MHD_AccessHandlerCallback}
Packit 875988
when this request is processed later; returning a
Packit 875988
value of @code{NULL} has no special significance; (however,
Packit 875988
note that if you return non-@code{NULL}, you can no longer
Packit 875988
rely on the first call to the access handler having
Packit 875988
@code{NULL == *con_cls} on entry)
Packit 875988
@code{cls} will be set to the second argument following
Packit 875988
MHD_OPTION_URI_LOG_CALLBACK.  Finally, @code{uri} will
Packit 875988
be the 0-terminated URI of the request.
Packit 875988
Packit 875988
Note that during the time of this call, most of the connection's state
Packit 875988
is not initialized (as we have not yet parsed he headers).  However,
Packit 875988
information about the connecting client (IP, socket) is available.
Packit 875988
Packit 875988
@item MHD_OPTION_HTTPS_MEM_KEY
Packit 875988
@cindex SSL
Packit 875988
@cindex TLS
Packit 875988
Memory pointer to the private key to be used by the
Packit 875988
HTTPS daemon.  This option should be followed by an
Packit 875988
"const char*" argument.
Packit 875988
This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_CERT'.
Packit 875988
Packit 875988
@item MHD_OPTION_HTTPS_KEY_PASSWORD
Packit 875988
@cindex SSL
Packit 875988
@cindex TLS
Packit 875988
Memory pointer to the password that decrypts the
Packit 875988
private key to be used by the HTTPS daemon.
Packit 875988
This option should be followed by an
Packit 875988
"const char*" argument.
Packit 875988
This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_KEY'.
Packit 875988
Packit 875988
The password (or passphrase) is only used immediately during
Packit 875988
@code{MHD_start_daemon()}.  Thus, the application may want to
Packit 875988
erase it from memory afterwards for additional security.
Packit 875988
Packit 875988
@item MHD_OPTION_HTTPS_MEM_CERT
Packit 875988
@cindex SSL
Packit 875988
@cindex TLS
Packit 875988
Memory pointer to the certificate to be used by the
Packit 875988
HTTPS daemon.  This option should be followed by an
Packit 875988
"const char*" argument.
Packit 875988
This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_KEY'.
Packit 875988
Packit 875988
@item MHD_OPTION_HTTPS_MEM_TRUST
Packit 875988
@cindex SSL
Packit 875988
@cindex TLS
Packit 875988
Memory pointer to the CA certificate to be used by the
Packit 875988
HTTPS daemon to authenticate and trust clients certificates.
Packit 875988
This option should be followed by an "const char*" argument.
Packit 875988
The presence of this option activates the request of certificate
Packit 875988
to the client. The request to the client is marked optional, and
Packit 875988
it is the responsibility of the server to check the presence
Packit 875988
of the certificate if needed.
Packit 875988
Note that most browsers will only present a client certificate
Packit 875988
only if they have one matching the specified CA, not sending
Packit 875988
any certificate otherwise.
Packit 875988
Packit 875988
@item MHD_OPTION_HTTPS_CRED_TYPE
Packit 875988
@cindex SSL
Packit 875988
@cindex TLS
Packit 875988
Daemon credentials type.  Either certificate or anonymous,
Packit 875988
this option should be followed by one of the values listed in
Packit 875988
"enum gnutls_credentials_type_t".
Packit 875988
Packit 875988
@item MHD_OPTION_HTTPS_PRIORITIES
Packit 875988
@cindex SSL
Packit 875988
@cindex TLS
Packit 875988
@cindex cipher
Packit 875988
SSL/TLS protocol version and ciphers.
Packit 875988
This option must be followed by an "const char *" argument
Packit 875988
specifying the SSL/TLS protocol versions and ciphers that
Packit 875988
are acceptable for the application.  The string is passed
Packit 875988
unchanged to gnutls_priority_init.  If this option is not
Packit 875988
specified, ``NORMAL'' is used.
Packit 875988
Packit 875988
@item MHD_OPTION_HTTPS_CERT_CALLBACK
Packit 875988
@cindex SSL
Packit 875988
@cindex TLS
Packit 875988
@cindex SNI
Packit 875988
Use a callback to determine which X.509 certificate should be used for
Packit 875988
a given HTTPS connection.  This option should be followed by a
Packit 875988
argument of type "gnutls_certificate_retrieve_function2 *".  This
Packit 875988
option provides an alternative to MHD_OPTION_HTTPS_MEM_KEY and
Packit 875988
MHD_OPTION_HTTPS_MEM_CERT.  You must use this version if multiple
Packit 875988
domains are to be hosted at the same IP address using TLS's Server
Packit 875988
Name Indication (SNI) extension.  In this case, the callback is
Packit 875988
expected to select the correct certificate based on the SNI
Packit 875988
information provided.  The callback is expected to access the SNI data
Packit 875988
using gnutls_server_name_get().  Using this option requires GnuTLS 3.0
Packit 875988
or higher.
Packit 875988
Packit 875988
@item MHD_OPTION_DIGEST_AUTH_RANDOM
Packit 875988
@cindex digest auth
Packit 875988
@cindex random
Packit 875988
Digest Authentication nonce's seed.
Packit 875988
Packit 875988
This option should be followed by two arguments.  First an integer of
Packit 875988
type "size_t" which specifies the size of the buffer pointed to by the
Packit 875988
second argument in bytes.  Note that the application must ensure that
Packit 875988
the buffer of the second argument remains allocated and unmodified
Packit 875988
while the daemon is running.  For security, you SHOULD provide a fresh
Packit 875988
random nonce when using MHD with Digest Authentication.
Packit 875988
Packit 875988
@item MHD_OPTION_NONCE_NC_SIZE
Packit 875988
@cindex digest auth
Packit 875988
@cindex replay attack
Packit 875988
Packit 875988
Size of an array of nonce and nonce counter map.  This option must be
Packit 875988
followed by an "unsigned int" argument that have the size (number of
Packit 875988
elements) of a map of a nonce and a nonce-counter.  If this option
Packit 875988
is not specified, a default value of 4 will be used (which might be
Packit 875988
too small for servers handling many requests).  If you do not use
Packit 875988
digest authentication at all, you can specify a value of zero to
Packit 875988
save some memory.
Packit 875988
Packit 875988
You should calculate the value of NC_SIZE based on the number of
Packit 875988
connections per second multiplied by your expected session duration
Packit 875988
plus a factor of about two for hash table collisions.  For example, if
Packit 875988
you expect 100 digest-authenticated connections per second and the
Packit 875988
average user to stay on your site for 5 minutes, then you likely need
Packit 875988
a value of about 60000.  On the other hand, if you can only expect
Packit 875988
only 10 digest-authenticated connections per second, tolerate browsers
Packit 875988
getting a fresh nonce for each request and expect a HTTP request
Packit 875988
latency of 250 ms, then a value of about 5 should be fine.
Packit 875988
Packit 875988
Packit 875988
@item MHD_OPTION_LISTEN_SOCKET
Packit 875988
@cindex systemd
Packit 875988
Listen socket to use.  Pass a listen socket for MHD to use
Packit 875988
(systemd-style).  If this option is used, MHD will not open its own
Packit 875988
listen socket(s). The argument passed must be of type "int" and refer
Packit 875988
to an existing socket that has been bound to a port and is listening.
Packit 875988
Packit 875988
@item MHD_OPTION_EXTERNAL_LOGGER
Packit 875988
@cindex logging
Packit 875988
Use the given function for logging error messages.
Packit 875988
This option must be followed by two arguments; the
Packit 875988
first must be a pointer to a function
Packit 875988
of type 'void fun(void * arg, const char * fmt, va_list ap)'
Packit 875988
and the second a pointer of type 'void*' which will
Packit 875988
be passed as the "arg" argument to "fun".
Packit 875988
Packit 875988
Note that MHD will not generate any log messages without
Packit 875988
the MHD_USE_ERROR_LOG flag set and if MHD was compiled
Packit 875988
with the "--disable-messages" flag.
Packit 875988
Packit 875988
@item MHD_OPTION_THREAD_POOL_SIZE
Packit 875988
@cindex performance
Packit 875988
Number (unsigned int) of threads in thread pool. Enable
Packit 875988
thread pooling by setting this value to to something
Packit 875988
greater than 1. Currently, thread model must be
Packit 875988
MHD_USE_INTERNAL_POLLING_THREAD if thread pooling is enabled
Packit 875988
(@code{MHD_start_daemon} returns @code{NULL} for an unsupported thread
Packit 875988
model).
Packit 875988
Packit 875988
@item MHD_OPTION_ARRAY
Packit 875988
@cindex options
Packit 875988
@cindex foreign-function interface
Packit 875988
This option can be used for initializing MHD using options from an
Packit 875988
array.  A common use for this is writing an FFI for MHD.  The actual
Packit 875988
options given are in an array of 'struct MHD_OptionItem', so this
Packit 875988
option requires a single argument of type 'struct MHD_OptionItem'.
Packit 875988
The array must be terminated with an entry @code{MHD_OPTION_END}.
Packit 875988
Packit 875988
An example for code using MHD_OPTION_ARRAY is:
Packit 875988
@example
Packit 875988
struct MHD_OptionItem ops[] = @{
Packit 875988
 @{ MHD_OPTION_CONNECTION_LIMIT, 100, NULL @},
Packit 875988
 @{ MHD_OPTION_CONNECTION_TIMEOUT, 10, NULL @},
Packit 875988
 @{ MHD_OPTION_END, 0, NULL @}
Packit 875988
@};
Packit 875988
d = MHD_start_daemon(0, 8080, NULL, NULL, dh, NULL,
Packit 875988
                     MHD_OPTION_ARRAY, ops,
Packit 875988
                     MHD_OPTION_END);
Packit 875988
@end example
Packit 875988
For options that expect a single pointer argument, the
Packit 875988
second member of the @code{struct MHD_OptionItem} is ignored.
Packit 875988
For options that expect two pointer arguments, the first
Packit 875988
argument must be cast to @code{intptr_t}.
Packit 875988
Packit 875988
@item MHD_OPTION_UNESCAPE_CALLBACK
Packit 875988
@cindex internationalization
Packit 875988
@cindex escaping
Packit 875988
Packit 875988
Specify a function that should be called for unescaping escape
Packit 875988
sequences in URIs and URI arguments.  Note that this function will NOT
Packit 875988
be used by the MHD_PostProcessor.  If this option is not specified,
Packit 875988
the default method will be used which decodes escape sequences of the
Packit 875988
form "%HH".  This option should be followed by two arguments, the
Packit 875988
first one must be of the form
Packit 875988
Packit 875988
@example
Packit 875988
  size_t my_unescaper(void * cls, struct MHD_Connection *c, char *s)
Packit 875988
@end example
Packit 875988
Packit 875988
where the return value must be @code{strlen(s)} and @code{s} should be
Packit 875988
updated.  Note that the unescape function must not lengthen @code{s}
Packit 875988
(the result must be shorter than the input and still be 0-terminated).
Packit 875988
@code{cls} will be set to the second argument following
Packit 875988
MHD_OPTION_UNESCAPE_CALLBACK.
Packit 875988
Packit 875988
Packit 875988
@item MHD_OPTION_THREAD_STACK_SIZE
Packit 875988
@cindex stack
Packit 875988
@cindex thread
Packit 875988
@cindex pthread
Packit 875988
@cindex embedded systems
Packit 875988
Maximum stack size for threads created by MHD.  This option must be
Packit 875988
followed by a @code{size_t}).  Not specifying this option or using
Packit 875988
a value of zero means using the system default (which is likely to
Packit 875988
differ based on your platform).
Packit 875988
Packit 875988
@item MHD_OPTION_TCP_FASTQUEUE_QUEUE_SIZE
Packit 875988
@cindex listen
Packit 875988
When the flag @code{MHD_USE_TCP_FASTOPEN} is used, this option sets the
Packit 875988
connection handshake queue size for the TCP FASTOPEN connections.  Note
Packit 875988
that a TCP FASTOPEN connection handshake occupies more resources than a
Packit 875988
TCP handshake as the SYN packets also contain DATA which is kept in the
Packit 875988
associate state until handshake is completed.  If this option is not
Packit 875988
given the queue size is set to a default value of 10.  This option must
Packit 875988
be followed by a @code{unsigned int}.
Packit 875988
Packit 875988
@item MHD_OPTION_HTTPS_MEM_DHPARAMS
Packit 875988
@cindex TLS
Packit 875988
@cindex SSL
Packit 875988
@cindex DH
Packit 875988
Memory pointer for the Diffie-Hellman parameters (dh.pem) to be used
Packit 875988
by the HTTPS daemon for key exchange.  This option must be followed by
Packit 875988
a @code{const char *} argument.  The argument would be a zero-terminated
Packit 875988
string with a PEM encoded PKCS3 DH parameters structure suitable
Packit 875988
for passing to @code{gnutls_dh_parms_import_pkcs3}.
Packit 875988
Packit 875988
@item MHD_OPTION_LISTENING_ADDRESS_REUSE
Packit 875988
@cindex bind, restricting bind
Packit 875988
@cindex reusing listening address
Packit 875988
This option must be followed by a @code{unsigned int} argument.
Packit 875988
If this option is present and true (nonzero) parameter is given, allow reusing
Packit 875988
the address:port of the listening socket (using @code{SO_REUSEPORT} on most
Packit 875988
platforms, and @code{SO_REUSEADDR} on Windows).  If a false (zero) parameter is
Packit 875988
given, disallow reusing the the address:port of the listening socket (this
Packit 875988
usually requires no special action, but @code{SO_EXCLUSIVEADDRUSE} is needed on
Packit 875988
Windows).  If this option is not present @code{SO_REUSEADDR} is used on all
Packit 875988
platforms except Windows so reusing of address:port is disallowed.
Packit 875988
Packit 875988
@end table
Packit 875988
@end deftp
Packit 875988
Packit 875988
Packit 875988
@deftp {C Struct} MHD_OptionItem
Packit 875988
Entry in an MHD_OPTION_ARRAY.  See the @code{MHD_OPTION_ARRAY} option
Packit 875988
argument for its use.
Packit 875988
Packit 875988
The @code{option} member is used to specify which option is specified
Packit 875988
in the array.  The other members specify the respective argument.
Packit 875988
Packit 875988
Note that for options taking only a single pointer, the
Packit 875988
@code{ptr_value} member should be set.  For options taking two pointer
Packit 875988
arguments, the first pointer must be cast to @code{intptr_t} and both
Packit 875988
the @code{value} and the @code{ptr_value} members should be used to
Packit 875988
pass the two pointers.
Packit 875988
@end deftp
Packit 875988
Packit 875988
Packit 875988
@deftp {Enumeration} MHD_ValueKind
Packit 875988
The @code{MHD_ValueKind} specifies the source of the key-value pairs in
Packit 875988
the HTTP protocol.
Packit 875988
Packit 875988
@table @code
Packit 875988
@item MHD_HEADER_KIND
Packit 875988
HTTP header.
Packit 875988
Packit 875988
@item MHD_COOKIE_KIND
Packit 875988
@cindex cookie
Packit 875988
Cookies.  Note that the original HTTP header containing the cookie(s)
Packit 875988
will still be available and intact.
Packit 875988
Packit 875988
@item MHD_POSTDATA_KIND
Packit 875988
@cindex POST method
Packit 875988
@code{POST} data.  This is available only if a content encoding
Packit 875988
supported by MHD is used (currently only @acronym{URL} encoding), and
Packit 875988
only if the posted content fits within the available memory pool.  Note
Packit 875988
that in that case, the upload data given to the
Packit 875988
@code{MHD_AccessHandlerCallback()} will be empty (since it has
Packit 875988
already been processed).
Packit 875988
Packit 875988
@item MHD_GET_ARGUMENT_KIND
Packit 875988
@code{GET} (URI) arguments.
Packit 875988
Packit 875988
@item MHD_FOOTER_KIND
Packit 875988
HTTP footer (only for http 1.1 chunked encodings).
Packit 875988
Packit 875988
@end table
Packit 875988
@end deftp
Packit 875988
Packit 875988
Packit 875988
@deftp {Enumeration} MHD_RequestTerminationCode
Packit 875988
The @code{MHD_RequestTerminationCode} specifies reasons why a request
Packit 875988
has been terminated (or completed).
Packit 875988
Packit 875988
@table @code
Packit 875988
@item MHD_REQUEST_TERMINATED_COMPLETED_OK
Packit 875988
We finished sending the response.
Packit 875988
Packit 875988
@item MHD_REQUEST_TERMINATED_WITH_ERROR
Packit 875988
Error handling the connection (resources exhausted, other side closed
Packit 875988
connection, application error accepting request, etc.)
Packit 875988
Packit 875988
@item MHD_REQUEST_TERMINATED_TIMEOUT_REACHED
Packit 875988
No activity on the connection for the number of seconds specified using
Packit 875988
@code{MHD_OPTION_CONNECTION_TIMEOUT}.
Packit 875988
Packit 875988
@item MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN
Packit 875988
We had to close the session since MHD was being shut down.
Packit 875988
@end table
Packit 875988
@end deftp
Packit 875988
Packit 875988
Packit 875988
@deftp {Enumeration} MHD_ResponseMemoryMode
Packit 875988
The @code{MHD_ResponeMemoryMode} specifies how MHD should treat
Packit 875988
the memory buffer given for the response in
Packit 875988
@code{MHD_create_response_from_buffer}.
Packit 875988
Packit 875988
@table @code
Packit 875988
@item MHD_RESPMEM_PERSISTENT
Packit 875988
Buffer is a persistent (static/global) buffer that won't change
Packit 875988
for at least the lifetime of the response, MHD should just use
Packit 875988
it, not free it, not copy it, just keep an alias to it.
Packit 875988
Packit 875988
@item MHD_RESPMEM_MUST_FREE
Packit 875988
Buffer is heap-allocated with @code{malloc} (or equivalent) and
Packit 875988
should be freed by MHD after processing the response has
Packit 875988
concluded (response reference counter reaches zero).
Packit 875988
Packit 875988
@item MHD_RESPMEM_MUST_COPY
Packit 875988
Buffer is in transient memory, but not on the heap (for example,
Packit 875988
on the stack or non-malloc allocated) and only valid during the
Packit 875988
call to @code{MHD_create_response_from_buffer}.  MHD must make its
Packit 875988
own private copy of the data for processing.
Packit 875988
Packit 875988
@end table
Packit 875988
@end deftp
Packit 875988
Packit 875988
Packit 875988
@deftp {Enumeration} MHD_ResponseFlags
Packit 875988
Response-specific flags.  Passed as an argument to
Packit 875988
@code{MHD_set_response_options()}.
Packit 875988
Packit 875988
@table @code
Packit 875988
@item MHD_RF_NONE
Packit 875988
No special handling.
Packit 875988
Packit 875988
@item MHD_RF_HTTP_VERSION_1_0_ONLY
Packit 875988
Only respond in conservative HTTP 1.0-mode.   In particular,
Packit 875988
do not (automatically) sent "Connection" headers and always
Packit 875988
close the connection after generating the response.
Packit 875988
Packit 875988
@end table
Packit 875988
@end deftp
Packit 875988
Packit 875988
Packit 875988
@deftp {Enumeration} MHD_ResponseOptions
Packit 875988
Response-specific options.  Passed in the varargs portion of
Packit 875988
@code{MHD_set_response_options()}.
Packit 875988
Packit 875988
@table @code
Packit 875988
@item MHD_RO_END
Packit 875988
No more options / last option.  This is used to terminate the VARARGs
Packit 875988
list.
Packit 875988
@end table
Packit 875988
@end deftp
Packit 875988
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-struct
Packit 875988
@chapter Structures type definition
Packit 875988
Packit 875988
Packit 875988
@deftp {C Struct} MHD_Daemon
Packit 875988
Handle for the daemon (listening on a socket for HTTP traffic).
Packit 875988
@end deftp
Packit 875988
Packit 875988
Packit 875988
@deftp {C Struct} MHD_Connection
Packit 875988
Handle for a connection / HTTP request.  With HTTP/1.1, multiple
Packit 875988
requests can be run over the same connection.  However, MHD will only
Packit 875988
show one request per TCP connection to the client at any given time.
Packit 875988
@end deftp
Packit 875988
Packit 875988
Packit 875988
@deftp {C Struct} MHD_Response
Packit 875988
Handle for a response.
Packit 875988
@end deftp
Packit 875988
Packit 875988
Packit 875988
@deftp {C Struct} MHD_PostProcessor
Packit 875988
@cindex POST method
Packit 875988
Handle for @code{POST} processing.
Packit 875988
@end deftp
Packit 875988
Packit 875988
Packit 875988
@deftp {C Union} MHD_ConnectionInfo
Packit 875988
Information about a connection.
Packit 875988
@end deftp
Packit 875988
Packit 875988
Packit 875988
@deftp {C Union} MHD_DaemonInfo
Packit 875988
Information about an MHD daemon.
Packit 875988
@end deftp
Packit 875988
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-cb
Packit 875988
@chapter Callback functions definition
Packit 875988
Packit 875988
Packit 875988
@deftypefn {Function Pointer} int {*MHD_AcceptPolicyCallback} (void *cls, const struct sockaddr * addr, socklen_t addrlen)
Packit 875988
Invoked in the context of a connection to allow or deny a client to
Packit 875988
connect.  This callback return @code{MHD_YES} if connection is allowed,
Packit 875988
@code{MHD_NO} if not.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item cls
Packit 875988
custom value selected at callback registration time;
Packit 875988
@item addr
Packit 875988
address information from the client;
Packit 875988
@item addrlen
Packit 875988
length of the address information.
Packit 875988
@end table
Packit 875988
@end deftypefn
Packit 875988
Packit 875988
Packit 875988
@deftypefn {Function Pointer} int {*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 **con_cls)
Packit 875988
Invoked in the context of a connection to answer a request from the
Packit 875988
client.  This callback must call MHD functions (example: the
Packit 875988
@code{MHD_Response} ones) to provide content to give back to the client
Packit 875988
and return an HTTP status code (i.e. @code{200} for OK, @code{404},
Packit 875988
etc.).
Packit 875988
Packit 875988
@ref{microhttpd-post}, for details on how to code this callback.
Packit 875988
Packit 875988
Must return @code{MHD_YES} if the connection was handled successfully,
Packit 875988
@code{MHD_NO} if the socket must be closed due to a serious error while
Packit 875988
handling the request
Packit 875988
Packit 875988
@table @var
Packit 875988
@item cls
Packit 875988
custom value selected at callback registration time;
Packit 875988
Packit 875988
@item url
Packit 875988
the URL requested by the client;
Packit 875988
Packit 875988
@item method
Packit 875988
the HTTP method used by the client (@code{GET}, @code{PUT},
Packit 875988
@code{DELETE}, @code{POST}, etc.);
Packit 875988
Packit 875988
@item version
Packit 875988
the HTTP version string (i.e. @code{HTTP/1.1});
Packit 875988
Packit 875988
@item upload_data
Packit 875988
the data being uploaded (excluding headers):
Packit 875988
@cindex POST method
Packit 875988
@cindex PUT method
Packit 875988
Packit 875988
@code{POST} data @strong{will} be made available
Packit 875988
incrementally in @var{upload_data}; even if @code{POST}
Packit 875988
data is available, the first time the callback is
Packit 875988
invoked there won't be upload data, as this is done
Packit 875988
just after MHD parses the headers.  If supported by
Packit 875988
the client and the HTTP version, the application can
Packit 875988
at this point queue an error response to possibly
Packit 875988
avoid the upload entirely. If no response is generated,
Packit 875988
MHD will (if required) automatically send a 100 CONTINUE
Packit 875988
reply to the client.
Packit 875988
Packit 875988
Afterwards, POST data will be passed to the callback
Packit 875988
to be processed incrementally by the application. The
Packit 875988
application may return @code{MHD_NO} to forcefully
Packit 875988
terminate the TCP connection without generating a
Packit 875988
proper HTTP response. Once all of the upload data has
Packit 875988
been provided to the application, the application
Packit 875988
will be called again with 0 bytes of upload data.
Packit 875988
At this point, a response should be queued to complete
Packit 875988
the handling of the request.
Packit 875988
Packit 875988
@item upload_data_size
Packit 875988
set initially to the size of the @var{upload_data} provided; this
Packit 875988
callback must update this value to the number of bytes @strong{NOT}
Packit 875988
processed; unless external select is used, the callback maybe
Packit 875988
required to process at least some data.  If the callback fails to
Packit 875988
process data in multi-threaded or internal-select mode and if the
Packit 875988
read-buffer is already at the maximum size that MHD is willing to
Packit 875988
use for reading (about half of the maximum amount of memory allowed
Packit 875988
for the connection), then MHD will abort handling the connection
Packit 875988
and return an internal server error to the client.  In order to
Packit 875988
avoid this, clients must be able to process upload data incrementally
Packit 875988
and reduce the value of @code{upload_data_size}.
Packit 875988
Packit 875988
@item con_cls
Packit 875988
reference to a pointer, initially set to @code{NULL}, that this callback can
Packit 875988
set to some address and that will be preserved by MHD for future
Packit 875988
calls for this request;
Packit 875988
Packit 875988
since the access handler may be called many times (i.e., for a
Packit 875988
@code{PUT}/@code{POST} operation with plenty of upload data) this allows
Packit 875988
the application to easily associate some request-specific state;
Packit 875988
Packit 875988
if necessary, this state can be cleaned up in the global
Packit 875988
@code{MHD_RequestCompletedCallback} (which can be set with the
Packit 875988
@code{MHD_OPTION_NOTIFY_COMPLETED}).
Packit 875988
@end table
Packit 875988
@end deftypefn
Packit 875988
Packit 875988
Packit 875988
@deftypefn {Function Pointer} void {*MHD_RequestCompletedCallback} (void *cls, struct MHD_Connectionconnection, void **con_cls, enum MHD_RequestTerminationCode toe)
Packit 875988
Signature of the callback used by MHD to notify the application about
Packit 875988
completed requests.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item cls
Packit 875988
custom value selected at callback registration time;
Packit 875988
Packit 875988
@item connection
Packit 875988
connection handle;
Packit 875988
Packit 875988
@item con_cls
Packit 875988
value as set by the last call to the
Packit 875988
@code{MHD_AccessHandlerCallback};
Packit 875988
Packit 875988
@item toe
Packit 875988
reason for request termination see @code{MHD_OPTION_NOTIFY_COMPLETED}.
Packit 875988
@end table
Packit 875988
@end deftypefn
Packit 875988
Packit 875988
Packit 875988
@deftypefn {Function Pointer} int {*MHD_KeyValueIterator} (void *cls, enum MHD_ValueKind kind, const char *key, const char *value)
Packit 875988
Iterator over key-value pairs.  This iterator can be used to iterate
Packit 875988
over all of the cookies, headers, or @code{POST}-data fields of a
Packit 875988
request, and also to iterate over the headers that have been added to a
Packit 875988
response.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item cls
Packit 875988
custom value specified when iteration was triggered;
Packit 875988
Packit 875988
@item kind
Packit 875988
kind of the header we are looking at
Packit 875988
Packit 875988
@item key
Packit 875988
key for the value, can be an empty string
Packit 875988
Packit 875988
@item value
Packit 875988
value corresponding value, can be NULL
Packit 875988
Packit 875988
@end table
Packit 875988
Packit 875988
Return @code{MHD_YES} to continue iterating, @code{MHD_NO} to abort the
Packit 875988
iteration.
Packit 875988
@end deftypefn
Packit 875988
Packit 875988
Packit 875988
@deftypefn {Function Pointer} int {*MHD_ContentReaderCallback} (void *cls, uint64_t pos, char *buf, size_t max)
Packit 875988
Callback used by MHD in order to obtain content.  The callback has to
Packit 875988
copy at most @var{max} bytes of content into @var{buf}.  The total
Packit 875988
number of bytes that has been placed into @var{buf} should be returned.
Packit 875988
Packit 875988
Note that returning zero will cause MHD to try again.
Packit 875988
Thus, returning zero should only be used in conjunction
Packit 875988
with @code{MHD_suspend_connection()} to avoid busy waiting.
Packit 875988
Packit 875988
While usually the callback simply returns the number of bytes written
Packit 875988
into @var{buf}, there are two special return value:
Packit 875988
Packit 875988
@code{MHD_CONTENT_READER_END_OF_STREAM} (-1) should be returned
Packit 875988
for the regular end of transmission (with chunked encoding, MHD will then
Packit 875988
terminate the chunk and send any HTTP footers that might be
Packit 875988
present; without chunked encoding and given an unknown
Packit 875988
response size, MHD will simply close the connection; note
Packit 875988
that while returning @code{MHD_CONTENT_READER_END_OF_STREAM} is not technically
Packit 875988
legal if a response size was specified, MHD accepts this
Packit 875988
and treats it just as @code{MHD_CONTENT_READER_END_WITH_ERROR}.
Packit 875988
Packit 875988
@code{MHD_CONTENT_READER_END_WITH_ERROR} (-2) is used to indicate a server
Packit 875988
error generating the response; this will cause MHD to simply
Packit 875988
close the connection immediately.  If a response size was
Packit 875988
given or if chunked encoding is in use, this will indicate
Packit 875988
an error to the client.  Note, however, that if the client
Packit 875988
does not know a response size and chunked encoding is not in
Packit 875988
use, then clients will not be able to tell the difference between
Packit 875988
@code{MHD_CONTENT_READER_END_WITH_ERROR} and
Packit 875988
@code{MHD_CONTENT_READER_END_OF_STREAM}.
Packit 875988
This is not a limitation of MHD but rather of the HTTP protocol.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item cls
Packit 875988
custom value selected at callback registration time;
Packit 875988
Packit 875988
@item pos
Packit 875988
position in the datastream to access; note that if an
Packit 875988
@code{MHD_Response} object is re-used, it is possible for the same
Packit 875988
content reader to be queried multiple times for the same data; however,
Packit 875988
if an @code{MHD_Response} is not re-used, MHD guarantees that
Packit 875988
@var{pos} will be the sum of all non-negative return values obtained
Packit 875988
from the content reader so far.
Packit 875988
@end table
Packit 875988
Packit 875988
Return @code{-1} on error (MHD will no longer try to read content and
Packit 875988
instead close the connection with the client).
Packit 875988
@end deftypefn
Packit 875988
Packit 875988
Packit 875988
@deftypefn {Function Pointer} void {*MHD_ContentReaderFreeCallback} (void *cls)
Packit 875988
This method is called by MHD if we are done with a content reader.
Packit 875988
It should be used to free resources associated with the content reader.
Packit 875988
@end deftypefn
Packit 875988
Packit 875988
Packit 875988
@deftypefn {Function Pointer} int {*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)
Packit 875988
Iterator over key-value pairs where the value maybe made available in
Packit 875988
increments and/or may not be zero-terminated.  Used for processing
Packit 875988
@code{POST} data.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item cls
Packit 875988
custom value selected at callback registration time;
Packit 875988
Packit 875988
@item kind
Packit 875988
type of the value;
Packit 875988
Packit 875988
@item key
Packit 875988
zero-terminated key for the value;
Packit 875988
Packit 875988
@item filename
Packit 875988
name of the uploaded file, @code{NULL} if not known;
Packit 875988
Packit 875988
@item content_type
Packit 875988
mime-type of the data, @code{NULL} if not known;
Packit 875988
Packit 875988
@item transfer_encoding
Packit 875988
encoding of the data, @code{NULL} if not known;
Packit 875988
Packit 875988
@item data
Packit 875988
pointer to size bytes of data at the specified offset;
Packit 875988
Packit 875988
@item off
Packit 875988
offset of data in the overall value;
Packit 875988
Packit 875988
@item size
Packit 875988
number of bytes in data available.
Packit 875988
@end table
Packit 875988
Packit 875988
Return @code{MHD_YES} to continue iterating, @code{MHD_NO} to abort the
Packit 875988
iteration.
Packit 875988
@end deftypefn
Packit 875988
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-init
Packit 875988
@chapter Starting and stopping the server
Packit 875988
Packit 875988
@deftypefun {void} MHD_set_panic_func (MHD_PanicCallback cb, void *cls)
Packit 875988
Set a handler for fatal errors.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item cb
Packit 875988
function to call if MHD encounters a fatal internal error.  If no handler was set explicitly, MHD will call @code{abort}.
Packit 875988
Packit 875988
@item cls
Packit 875988
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})
Packit 875988
@end table
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
@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, ...)
Packit 875988
Start a webserver on the given port.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item flags
Packit 875988
OR-ed combination of @code{MHD_FLAG} values;
Packit 875988
Packit 875988
@item port
Packit 875988
port to bind to;
Packit 875988
Packit 875988
@item apc
Packit 875988
callback to call to check which clients will be allowed to connect; you
Packit 875988
can pass @code{NULL} in which case connections from any @acronym{IP} will be
Packit 875988
accepted;
Packit 875988
Packit 875988
@item apc_cls
Packit 875988
extra argument to @var{apc};
Packit 875988
Packit 875988
@item dh
Packit 875988
default handler for all URIs;
Packit 875988
Packit 875988
@item dh_cls
Packit 875988
extra argument to @var{dh}.
Packit 875988
@end table
Packit 875988
Packit 875988
Additional arguments are a list of options (type-value pairs,
Packit 875988
terminated with @code{MHD_OPTION_END}). It is mandatory to use
Packit 875988
@code{MHD_OPTION_END} as last argument, even when there are no
Packit 875988
additional arguments.
Packit 875988
Packit 875988
Return @code{NULL} on error, handle to daemon on success.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@deftypefun int MHD_quiesce_daemon (struct MHD_Daemon *daemon)
Packit 875988
@cindex quiesce
Packit 875988
Stop accepting connections from the listening socket.  Allows clients
Packit 875988
to continue processing, but stops accepting new connections.  Note
Packit 875988
that the caller is responsible for closing the returned socket;
Packit 875988
however, if MHD is run using threads (anything but external select
Packit 875988
mode), it must not be closed until AFTER @code{MHD_stop_daemon} has
Packit 875988
been called (as it is theoretically possible that an existing thread
Packit 875988
is still using it).
Packit 875988
Packit 875988
This function is useful in the special case that a listen socket
Packit 875988
is to be migrated to another process (i.e. a newer version of the
Packit 875988
HTTP server) while existing connections should continue to be
Packit 875988
processed until they are finished.
Packit 875988
Packit 875988
Return @code{-1} on error (daemon not listening), the handle to the
Packit 875988
listen socket otherwise.
Packit 875988
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@deftypefun void MHD_stop_daemon (struct MHD_Daemon *daemon)
Packit 875988
Shutdown an HTTP daemon.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@deftypefun int MHD_run (struct MHD_Daemon *daemon)
Packit 875988
Run webserver operations (without blocking unless in client callbacks).
Packit 875988
This method should be called by clients in combination with
Packit 875988
@code{MHD_get_fdset()} if the client-controlled @code{select}-method is used.
Packit 875988
@cindex select
Packit 875988
@cindex poll
Packit 875988
Packit 875988
This function will work for external @code{poll} and @code{select} mode.
Packit 875988
However, if using external @code{select} mode, you may want to
Packit 875988
instead use @code{MHD_run_from_select}, as it is more efficient.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item daemon
Packit 875988
daemon to process connections of
Packit 875988
@end table
Packit 875988
Packit 875988
Return @code{MHD_YES} on success, @code{MHD_NO} if this daemon was not
Packit 875988
started with the right options for this call.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@deftypefun int 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)
Packit 875988
Run webserver operations given sets of ready socket handles.
Packit 875988
@cindex select
Packit 875988
Packit 875988
This method should be called by clients in combination with
Packit 875988
@code{MHD_get_fdset} if the client-controlled (external)
Packit 875988
select method is used.
Packit 875988
Packit 875988
You can use this function instead of @code{MHD_run} if you called
Packit 875988
@code{select} on the result from @code{MHD_get_fdset}.  File descriptors in
Packit 875988
the sets that are not controlled by MHD will be ignored.  Calling
Packit 875988
this function instead of @code{MHD_run} is more efficient as MHD will
Packit 875988
not have to call @code{select} again to determine which operations are
Packit 875988
ready.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item daemon
Packit 875988
daemon to process connections of
Packit 875988
@item read_fd_set
Packit 875988
set of descriptors that must be ready for reading without blocking
Packit 875988
@item write_fd_set
Packit 875988
set of descriptors that must be ready for writing without blocking
Packit 875988
@item except_fd_set
Packit 875988
ignored, can be NULL
Packit 875988
@end table
Packit 875988
Packit 875988
Return @code{MHD_YES} on success, @code{MHD_NO} on serious internal
Packit 875988
errors.
Packit 875988
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
Packit 875988
@deftypefun void MHD_add_connection (struct MHD_Daemon *daemon, int client_socket, const struct sockaddr *addr, socklen_t addrlen)
Packit 875988
Add another client connection to the set of connections
Packit 875988
managed by MHD.  This API is usually not needed (since
Packit 875988
MHD will accept inbound connections on the server socket).
Packit 875988
Use this API in special cases, for example if your HTTP
Packit 875988
server is behind NAT and needs to connect out to the
Packit 875988
HTTP client, or if you are building a proxy.
Packit 875988
Packit 875988
If you use this API in conjunction with a internal select or a thread
Packit 875988
pool, you must set the option @code{MHD_USE_ITC} to
Packit 875988
ensure that the freshly added connection is immediately processed by
Packit 875988
MHD.
Packit 875988
Packit 875988
The given client socket will be managed (and closed!) by MHD after
Packit 875988
this call and must no longer be used directly by the application
Packit 875988
afterwards.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item daemon
Packit 875988
daemon that manages the connection
Packit 875988
@item client_socket
Packit 875988
socket to manage (MHD will expect to receive an HTTP request from this socket next).
Packit 875988
@item addr
Packit 875988
IP address of the client
Packit 875988
@item addrlen
Packit 875988
number of bytes in addr
Packit 875988
@end table
Packit 875988
Packit 875988
This function will return @code{MHD_YES} on success,
Packit 875988
@code{MHD_NO} if this daemon could
Packit 875988
not handle the connection (i.e. malloc failed, etc).
Packit 875988
The socket will be closed in any case; 'errno' is set
Packit 875988
to indicate further details about the error.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
@c -----------------------------------------------------------
Packit 875988
@node microhttpd-inspect
Packit 875988
@chapter Implementing external @code{select}
Packit 875988
Packit 875988
Packit 875988
@deftypefun int 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)
Packit 875988
Obtain the @code{select()} sets for this daemon. The daemon's socket
Packit 875988
is added to @var{read_fd_set}. The list of currently existent
Packit 875988
connections is scanned and their file descriptors added to the correct
Packit 875988
set.
Packit 875988
Packit 875988
When calling this function, FD_SETSIZE is assumed to be platform's
Packit 875988
default.  If you changed FD_SETSIZE for your application,
Packit 875988
you should use @code{MHD_get_fdset2()} instead.
Packit 875988
Packit 875988
This function should only be called in when MHD is configured to use
Packit 875988
external select with @code{select()} or with @code{epoll()}.  In
Packit 875988
the latter case, it will only add the single @code{epoll()} file
Packit 875988
descriptor used by MHD to the sets.
Packit 875988
Packit 875988
After the call completed successfully: the variable referenced by
Packit 875988
@var{max_fd} references the file descriptor with highest integer
Packit 875988
identifier. The variable must be set to zero before invoking this
Packit 875988
function.
Packit 875988
Packit 875988
Return @code{MHD_YES} on success, @code{MHD_NO} if: the arguments are
Packit 875988
invalid (example: @code{NULL} pointers); this daemon was not started with
Packit 875988
the right options for this call.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@deftypefun int 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)
Packit 875988
Like @code{MHD_get_fdset()}, except that you can manually specify the value of FD_SETSIZE used by your application.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@deftypefun int MHD_get_timeout (struct MHD_Daemon *daemon, unsigned long long *timeout)
Packit 875988
@cindex timeout
Packit 875988
Obtain timeout value for select for this daemon (only needed if
Packit 875988
connection timeout is used).  The returned value is how many
Packit 875988
milliseconds @code{select} should at most block, not the timeout value
Packit 875988
set for connections.  This function must not be called if the
Packit 875988
@code{MHD_USE_THREAD_PER_CONNECTION} mode is in use (since then it is
Packit 875988
not meaningful to ask for a timeout, after all, there is concurrenct
Packit 875988
activity).  The function must also not be called by user-code if
Packit 875988
@code{MHD_USE_INTERNAL_POLLING_THREAD} is in use.  In the latter case, the
Packit 875988
behavior is undefined.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item daemon
Packit 875988
which daemon to obtain the timeout from.
Packit 875988
@item timeout
Packit 875988
will be set to the timeout (in milliseconds).
Packit 875988
@end table
Packit 875988
Packit 875988
Return @code{MHD_YES} on success, @code{MHD_NO} if timeouts are not used
Packit 875988
(or no connections exist that would necessiate the use of a timeout
Packit 875988
right now).
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
@c -----------------------------------------------------------
Packit 875988
@node microhttpd-requests
Packit 875988
@chapter Handling requests
Packit 875988
Packit 875988
Packit 875988
@deftypefun int MHD_get_connection_values (struct MHD_Connection *connection, enum MHD_ValueKind kind, MHD_KeyValueIterator iterator, void *iterator_cls)
Packit 875988
Get all the headers matching @var{kind} from the request.  The @var{kind}
Packit 875988
argument can be a bitmask, ORing the various header kinds that are
Packit 875988
requested.
Packit 875988
Packit 875988
The @var{iterator} callback is invoked once for each header, with
Packit 875988
@var{iterator_cls} as first argument.  After version 0.9.19, the
Packit 875988
headers are iterated in the same order as they were received from
Packit 875988
the network; previous versions iterated over the headers in reverse
Packit 875988
order.
Packit 875988
Packit 875988
@code{MHD_get_connection_values} returns the number of entries
Packit 875988
iterated over; this can be less than the number of headers if, while
Packit 875988
iterating, @var{iterator} returns @code{MHD_NO}.
Packit 875988
Packit 875988
@var{iterator} can be @code{NULL}: in this case this function just counts
Packit 875988
and returns the number of headers.
Packit 875988
Packit 875988
In the case of @code{MHD_GET_ARGUMENT_KIND}, the @var{value} argument
Packit 875988
will be @code{NULL} if the URL contained a key without an equals operator.
Packit 875988
For example, for a HTTP request to the URL ``http://foo/bar?key'', the
Packit 875988
@var{value} argument is @code{NULL}; in contrast, a HTTP request to the URL
Packit 875988
``http://foo/bar?key='', the @var{value} argument is the empty string.
Packit 875988
The normal case is that the URL contains ``http://foo/bar?key=value''
Packit 875988
in which case @var{value} would be the string ``value'' and @var{key}
Packit 875988
would contain the string ``key''.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@deftypefun int MHD_set_connection_value (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key, const char *value)
Packit 875988
This function can be used to append an entry to
Packit 875988
the list of HTTP headers of a connection (so that the
Packit 875988
@code{MHD_get_connection_values function} will return
Packit 875988
them -- and the MHD PostProcessor will also
Packit 875988
see them).  This maybe required in certain
Packit 875988
situations (see Mantis #1399) where (broken)
Packit 875988
HTTP implementations fail to supply values needed
Packit 875988
by the post processor (or other parts of the
Packit 875988
application).
Packit 875988
Packit 875988
This function MUST only be called from within
Packit 875988
the MHD_AccessHandlerCallback (otherwise, access
Packit 875988
maybe improperly synchronized).  Furthermore,
Packit 875988
the client must guarantee that the key and
Packit 875988
value arguments are 0-terminated strings that
Packit 875988
are NOT freed until the connection is closed.
Packit 875988
(The easiest way to do this is by passing only
Packit 875988
arguments to permanently allocated strings.).
Packit 875988
Packit 875988
@var{connection} is the connection for which
Packit 875988
the entry for @var{key} of the given @var{kind}
Packit 875988
should be set to the given @var{value}.
Packit 875988
Packit 875988
The function returns @code{MHD_NO} if the operation
Packit 875988
could not be performed due to insufficient memory
Packit 875988
and @code{MHD_YES} on success.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@deftypefun {const char *} MHD_lookup_connection_value (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key)
Packit 875988
Get a particular header value.  If multiple values match the
Packit 875988
@var{kind}, return one of them (the ``first'', whatever that means).
Packit 875988
@var{key} must reference a zero-terminated ASCII-coded string
Packit 875988
representing the header to look for: it is compared against the
Packit 875988
headers using @code{strcasecmp()}, so case is ignored.  A value of
Packit 875988
@code{NULL} for @var{key} can be used to lookup 'trailing' values without a
Packit 875988
key, for example if a URI is of the form
Packit 875988
``http://example.com/?trailer'', a @var{key} of @code{NULL} can be used to
Packit 875988
access ``tailer" The function returns @code{NULL} if no matching item
Packit 875988
was found.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-responses
Packit 875988
@chapter Building responses to requests
Packit 875988
Packit 875988
Packit 875988
@noindent
Packit 875988
Response objects handling by MHD is asynchronous with respect to the
Packit 875988
application execution flow. Instances of the @code{MHD_Response}
Packit 875988
structure are not associated to a daemon and neither to a client
Packit 875988
connection: they are managed with reference counting.
Packit 875988
Packit 875988
In the simplest case: we allocate a new @code{MHD_Response} structure
Packit 875988
for each response, we use it once and finally we destroy it.
Packit 875988
Packit 875988
MHD allows more efficient resources usages.
Packit 875988
Packit 875988
Example: we allocate a new @code{MHD_Response} structure for each
Packit 875988
response @strong{kind}, we use it every time we have to give that
Packit 875988
response and we finally destroy it only when the daemon shuts down.
Packit 875988
Packit 875988
@menu
Packit 875988
* microhttpd-response enqueue:: Enqueuing a response.
Packit 875988
* microhttpd-response create::  Creating a response object.
Packit 875988
* microhttpd-response headers:: Adding headers to a response.
Packit 875988
* microhttpd-response options:: Setting response options.
Packit 875988
* microhttpd-response inspect:: Inspecting a response object.
Packit 875988
* microhttpd-response upgrade:: Creating a response for protocol upgrades.
Packit 875988
@end menu
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-response enqueue
Packit 875988
@section Enqueuing a response
Packit 875988
Packit 875988
Packit 875988
@deftypefun int MHD_queue_response (struct MHD_Connection *connection, unsigned int status_code, struct MHD_Response *response)
Packit 875988
Queue a response to be transmitted to the client as soon as possible
Packit 875988
but only after MHD_AccessHandlerCallback returns.  This function
Packit 875988
checks that it is legal to queue a response at this time for the
Packit 875988
given connection.  It also increments the internal reference
Packit 875988
counter for the response object (the counter will be decremented
Packit 875988
automatically once the response has been transmitted).
Packit 875988
Packit 875988
@table @var
Packit 875988
@item connection
Packit 875988
the connection identifying the client;
Packit 875988
Packit 875988
@item status_code
Packit 875988
HTTP status code (i.e. @code{200} for OK);
Packit 875988
Packit 875988
@item response
Packit 875988
response to transmit.
Packit 875988
@end table
Packit 875988
Packit 875988
Return @code{MHD_YES} on success or if message has been queued.  Return
Packit 875988
@code{MHD_NO}: if arguments are invalid (example: @code{NULL} pointer); on
Packit 875988
error (i.e. reply already sent).
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@deftypefun void MHD_destroy_response (struct MHD_Response *response)
Packit 875988
Destroy a response object and associated resources (decrement the
Packit 875988
reference counter).  Note that MHD may keep some of the resources
Packit 875988
around if the response is still in the queue for some clients, so the
Packit 875988
memory may not necessarily be freed immediately.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
An explanation of reference counting@footnote{Note to readers acquainted
Packit 875988
to the Tcl API: reference counting on @code{MHD_Connection}
Packit 875988
structures is handled in the same way as Tcl handles @code{Tcl_Obj}
Packit 875988
structures through @code{Tcl_IncrRefCount()} and
Packit 875988
@code{Tcl_DecrRefCount()}.}:
Packit 875988
Packit 875988
@enumerate
Packit 875988
@item
Packit 875988
a @code{MHD_Response} object is allocated:
Packit 875988
Packit 875988
@example
Packit 875988
struct MHD_Response * response = MHD_create_response_from_buffer(...);
Packit 875988
/* here: reference counter = 1 */
Packit 875988
@end example
Packit 875988
Packit 875988
@item
Packit 875988
the @code{MHD_Response} object is enqueued in a @code{MHD_Connection}:
Packit 875988
Packit 875988
@example
Packit 875988
MHD_queue_response(connection, , response);
Packit 875988
/* here: reference counter = 2 */
Packit 875988
@end example
Packit 875988
Packit 875988
@item
Packit 875988
the creator of the response object discharges responsibility for it:
Packit 875988
Packit 875988
@example
Packit 875988
MHD_destroy_response(response);
Packit 875988
/* here: reference counter = 1 */
Packit 875988
@end example
Packit 875988
Packit 875988
@item
Packit 875988
the daemon handles the connection sending the response's data to the
Packit 875988
client then decrements the reference counter by calling
Packit 875988
@code{MHD_destroy_response()}: the counter's value drops to zero and
Packit 875988
the @code{MHD_Response} object is released.
Packit 875988
@end enumerate
Packit 875988
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-response create
Packit 875988
@section Creating a response object
Packit 875988
Packit 875988
Packit 875988
@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)
Packit 875988
Create a response object.  The response object can be extended with
Packit 875988
header information and then it can be used any number of times.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item size
Packit 875988
size of the data portion of the response, @code{-1} for unknown;
Packit 875988
Packit 875988
@item block_size
Packit 875988
preferred block size for querying @var{crc} (advisory only, MHD may
Packit 875988
still call @var{crc} using smaller chunks); this is essentially the
Packit 875988
buffer size used for @acronym{IO}, clients should pick a value that is
Packit 875988
appropriate for @acronym{IO} and memory performance requirements;
Packit 875988
Packit 875988
@item crc
Packit 875988
callback to use to obtain response data;
Packit 875988
Packit 875988
@item crc_cls
Packit 875988
extra argument to @var{crc};
Packit 875988
Packit 875988
@item crfc
Packit 875988
callback to call to free @var{crc_cls} resources.
Packit 875988
@end table
Packit 875988
Packit 875988
Return @code{NULL} on error (i.e. invalid arguments, out of memory).
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
Packit 875988
@deftypefun {struct MHD_Response *} MHD_create_response_from_fd (uint64_t size, int fd)
Packit 875988
Create a response object.  The response object can be extended with
Packit 875988
header information and then it can be used any number of times.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item size
Packit 875988
size of the data portion of the response (should be smaller or equal to the
Packit 875988
size of the file)
Packit 875988
Packit 875988
@item fd
Packit 875988
file descriptor referring to a file on disk with the data; will be
Packit 875988
closed when response is destroyed; note that 'fd' must be an actual
Packit 875988
file descriptor (not a pipe or socket) since MHD might use 'sendfile'
Packit 875988
or 'seek' on it.  The descriptor should be in blocking-IO mode.
Packit 875988
@end table
Packit 875988
Packit 875988
Return @code{NULL} on error (i.e. invalid arguments, out of memory).
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@deftypefun {struct MHD_Response *} MHD_create_response_from_fd_at_offset (size_t size, int fd, off_t offset)
Packit 875988
Create a response object.  The response object can be extended with
Packit 875988
header information and then it can be used any number of times.
Packit 875988
Note that you need to be a bit careful about @code{off_t} when
Packit 875988
writing this code.  Depending on your platform, MHD is likely
Packit 875988
to have been compiled with support for 64-bit files.  When you
Packit 875988
compile your own application, you must make sure that @code{off_t}
Packit 875988
is also a 64-bit value.  If not, your compiler may pass a 32-bit
Packit 875988
value as @code{off_t}, which will result in 32-bits of garbage.
Packit 875988
Packit 875988
If you use the autotools, use the @code{AC_SYS_LARGEFILE} autoconf
Packit 875988
macro and make sure to include the generated @file{config.h} file
Packit 875988
before @file{microhttpd.h} to avoid problems.  If you do not have a
Packit 875988
build system and only want to run on a GNU/Linux system, you could
Packit 875988
also use
Packit 875988
@verbatim
Packit 875988
#define _FILE_OFFSET_BITS 64
Packit 875988
#include <sys/types.h>
Packit 875988
#include <sys/stat.h>
Packit 875988
#include <fcntl.h>
Packit 875988
#include <microhttpd.h>
Packit 875988
@end verbatim
Packit 875988
to ensure 64-bit @code{off_t}.  Note that if your operating system
Packit 875988
does not support 64-bit files, MHD will be compiled with a 32-bit
Packit 875988
@code{off_t} (in which case the above would be wrong).
Packit 875988
Packit 875988
@table @var
Packit 875988
@item size
Packit 875988
size of the data portion of the response (number of bytes to transmit from the
Packit 875988
file starting at offset).
Packit 875988
Packit 875988
@item fd
Packit 875988
file descriptor referring to a file on disk with the data; will be
Packit 875988
closed when response is destroyed; note that 'fd' must be an actual
Packit 875988
file descriptor (not a pipe or socket) since MHD might use 'sendfile'
Packit 875988
or 'seek' on it.    The descriptor should be in blocking-IO mode.
Packit 875988
Packit 875988
@item offset
Packit 875988
offset to start reading from in the file
Packit 875988
@end table
Packit 875988
Packit 875988
Return @code{NULL} on error (i.e. invalid arguments, out of memory).
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@deftypefun {struct MHD_Response *} MHD_create_response_from_buffer (size_t size, void *data, enum MHD_ResponseMemoryMode mode)
Packit 875988
Create a response object.  The response object can be extended with
Packit 875988
header information and then it can be used any number of times.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item size
Packit 875988
size of the data portion of the response;
Packit 875988
Packit 875988
@item buffer
Packit 875988
the data itself;
Packit 875988
Packit 875988
@item mode
Packit 875988
memory management options for buffer; use
Packit 875988
MHD_RESPMEM_PERSISTENT if the buffer is static/global memory,
Packit 875988
use MHD_RESPMEM_MUST_FREE if the buffer is heap-allocated and
Packit 875988
should be freed by MHD and MHD_RESPMEM_MUST_COPY if the
Packit 875988
buffer is in transient memory (i.e. on the stack) and must
Packit 875988
be copied by MHD;
Packit 875988
@end table
Packit 875988
Packit 875988
Return @code{NULL} on error (i.e. invalid arguments, out of memory).
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@deftypefun {struct MHD_Response *} MHD_create_response_from_data (size_t size, void *data, int must_free, int must_copy)
Packit 875988
Create a response object.  The response object can be extended with
Packit 875988
header information and then it can be used any number of times.
Packit 875988
This function is deprecated, use @code{MHD_create_response_from_buffer} instead.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item size
Packit 875988
size of the data portion of the response;
Packit 875988
Packit 875988
@item data
Packit 875988
the data itself;
Packit 875988
Packit 875988
@item must_free
Packit 875988
if true: MHD should free data when done;
Packit 875988
Packit 875988
@item must_copy
Packit 875988
if true: MHD allocates a block of memory and use it to make a copy of
Packit 875988
@var{data} embedded in the returned @code{MHD_Response} structure;
Packit 875988
handling of the embedded memory is responsibility of MHD; @var{data}
Packit 875988
can be released anytime after this call returns.
Packit 875988
@end table
Packit 875988
Packit 875988
Return @code{NULL} on error (i.e. invalid arguments, out of memory).
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
Example: create a response from a statically allocated string:
Packit 875988
Packit 875988
@example
Packit 875988
const char * data = "<html><body>

Error!

</body></html>";
Packit 875988
Packit 875988
struct MHD_Connection * connection = ...;
Packit 875988
struct MHD_Response *   response;
Packit 875988
Packit 875988
response = MHD_create_response_from_buffer (strlen(data), data,
Packit 875988
                                            MHD_RESPMEM_PERSISTENT);
Packit 875988
MHD_queue_response(connection, 404, response);
Packit 875988
MHD_destroy_response(response);
Packit 875988
@end example
Packit 875988
Packit 875988
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-response headers
Packit 875988
@section Adding headers to a response
Packit 875988
Packit 875988
Packit 875988
@deftypefun int MHD_add_response_header (struct MHD_Response *response, const char *header, const char *content)
Packit 875988
Add a header line to the response. The strings referenced by
Packit 875988
@var{header} and @var{content} must be zero-terminated and they are
Packit 875988
duplicated into memory blocks embedded in @var{response}.
Packit 875988
Packit 875988
Notice that the strings must not hold newlines, carriage returns or tab
Packit 875988
chars.
Packit 875988
Packit 875988
Return @code{MHD_NO} on error (i.e. invalid header or content format or
Packit 875988
memory allocation error).
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@deftypefun int MHD_add_response_footer (struct MHD_Response *response, const char *footer, const char *content)
Packit 875988
Add a footer line to the response. The strings referenced by
Packit 875988
@var{footer} and @var{content} must be zero-terminated and they are
Packit 875988
duplicated into memory blocks embedded in @var{response}.
Packit 875988
Packit 875988
Notice that the strings must not hold newlines, carriage returns or tab
Packit 875988
chars.  You can add response footers at any time before signalling the
Packit 875988
end of the response to MHD (not just before calling 'MHD_queue_response').
Packit 875988
Footers are useful for adding cryptographic checksums to the reply or to
Packit 875988
signal errors encountered during data generation.  This call was introduced
Packit 875988
in MHD 0.9.3.
Packit 875988
Packit 875988
Return @code{MHD_NO} on error (i.e. invalid header or content format or
Packit 875988
memory allocation error).
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
Packit 875988
@deftypefun int MHD_del_response_header (struct MHD_Response *response, const char *header, const char *content)
Packit 875988
Delete a header (or footer) line from the response.  Return @code{MHD_NO} on error
Packit 875988
(arguments are invalid or no such header known).
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-response options
Packit 875988
@section Setting response options
Packit 875988
Packit 875988
Packit 875988
@deftypefun int MHD_set_response_options (struct MHD_Response *response, enum MHD_ResponseFlags flags, ...)
Packit 875988
Set special flags and options for a response.
Packit 875988
Packit 875988
Calling this functions sets the given flags and options for the response.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item response
Packit 875988
which response should be modified;
Packit 875988
Packit 875988
@item flags
Packit 875988
flags to set for the response;
Packit 875988
Packit 875988
@end table
Packit 875988
Packit 875988
Additional arguments are a list of options (type-value pairs,
Packit 875988
terminated with @code{MHD_RO_END}). It is mandatory to use
Packit 875988
@code{MHD_RO_END} as last argument, even when there are no
Packit 875988
additional arguments.
Packit 875988
Packit 875988
Return @code{MHD_NO} on error, @code{MHD_YES} on success.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-response inspect
Packit 875988
@section Inspecting a response object
Packit 875988
Packit 875988
Packit 875988
@deftypefun int MHD_get_response_headers (struct MHD_Response *response, MHD_KeyValueIterator iterator, void *iterator_cls)
Packit 875988
Get all of the headers added to a response.
Packit 875988
Packit 875988
Invoke the @var{iterator} callback for each header in the response,
Packit 875988
using @var{iterator_cls} as first argument. Return number of entries
Packit 875988
iterated over.  @var{iterator} can be @code{NULL}: in this case the function
Packit 875988
just counts headers.
Packit 875988
Packit 875988
@var{iterator} should not modify the its key and value arguments, unless
Packit 875988
we know what we are doing.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@deftypefun {const char *} MHD_get_response_header (struct MHD_Response *response, const char *key)
Packit 875988
Find and return a pointer to the value of a particular header from the
Packit 875988
response.  @var{key} must reference a zero-terminated string
Packit 875988
representing the header to look for. The search is case sensitive.
Packit 875988
Return @code{NULL} if header does not exist or @var{key} is @code{NULL}.
Packit 875988
Packit 875988
We should not modify the value, unless we know what we are doing.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-response upgrade
Packit 875988
@section Creating a response for protocol upgrades
Packit 875988
@cindex WebSockets
Packit 875988
@cindex Upgrade
Packit 875988
@cindex HTTP2
Packit 875988
@cindex RFC2817
Packit 875988
Packit 875988
With RFC 2817 a mechanism to switch protocols within HTTP was
Packit 875988
introduced.  Here, a client sends a request with a ``Connection:
Packit 875988
Upgrade'' header.  The server responds with a ``101 Switching
Packit 875988
Protocols'' response header, after which the two parties begin to
Packit 875988
speak a different (non-HTTP) protocol over the TCP connection.
Packit 875988
Packit 875988
This mechanism is used for upgrading HTTP 1.1 connections to HTTP2 or
Packit 875988
HTTPS, as well as for implementing WebSockets.  Which protocol
Packit 875988
upgrade is performed is negotiated between server and client in
Packit 875988
additional headers, in particular the ``Upgrade'' header.
Packit 875988
Packit 875988
MHD supports switching protocols using this mechanism only if the
Packit 875988
@code{MHD_ALLOW_SUSPEND_RESUME} flag has been set when starting
Packit 875988
the daemon.  If this flag has been set, applications can upgrade
Packit 875988
a connection by queueing a response (using the
Packit 875988
@code{MHD_HTTP_SWITCHING_PROTOCOLS} status code) which must
Packit 875988
have been created with the following function:
Packit 875988
Packit 875988
Packit 875988
@deftypefun int MHD_create_response_for_upgrade (MHD_UpgradeHandler upgrade_handler, void *upgrade_handler_cls)
Packit 875988
Create a response suitable for switching protocols.  Returns @code{MHD_YES} on success.  @code{upgrade_handler} must not be @code{NULL}.
Packit 875988
Packit 875988
When creating this type of response, the ``Connection: Upgrade''
Packit 875988
header will be set automatically for you.  MHD requires that you
Packit 875988
additionally set an ``Upgrade:'' header.  The ``Upgrade'' header
Packit 875988
must simply exist, the specific value is completely up to the
Packit 875988
application.
Packit 875988
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
The @code{upgrade_handler} argument to the above has the following type:
Packit 875988
Packit 875988
Packit 875988
@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)
Packit 875988
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:
Packit 875988
Packit 875988
@table @var
Packit 875988
@item cls
Packit 875988
matches the @code{upgrade_handler_cls} that was given to @code{MHD_create_response_for_upgrade}
Packit 875988
@item connection
Packit 875988
identifies the connection that is being upgraded;
Packit 875988
Packit 875988
@item con_cls
Packit 875988
last value left in `*con_cls` in the `MHD_AccessHandlerCallback`
Packit 875988
Packit 875988
@item extra_in
Packit 875988
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.
Packit 875988
Packit 875988
@item extra_in_size
Packit 875988
number of bytes in @code{extra_in}
Packit 875988
Packit 875988
@item sock
Packit 875988
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.
Packit 875988
Packit 875988
@item urh
Packit 875988
argument for calls to @code{MHD_upgrade_action}.  Applications must eventually use this function to perform the @code{close()} action on the socket.
Packit 875988
@end table
Packit 875988
Packit 875988
@end deftypefn
Packit 875988
Packit 875988
@deftypefun int MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh, enum MHD_UpgradeAction action, ...)
Packit 875988
Perform special operations related to upgraded connections.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item urh
Packit 875988
identifies the upgraded connection to perform an action on
Packit 875988
Packit 875988
@item action
Packit 875988
specifies the action to perform; further arguments to the function depend on the specifics of the action.
Packit 875988
@end table
Packit 875988
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@deftp {Enumeration} MHD_UpgradeAction
Packit 875988
Set of actions to be performed on upgraded connections.  Passed as an argument to
Packit 875988
@code{MHD_upgrade_action()}.
Packit 875988
Packit 875988
@table @code
Packit 875988
@item MHD_UPGRADE_ACTION_CLOSE
Packit 875988
Closes the connection.  Must be called once the application is done with the client.  Takes no additional arguments.
Packit 875988
Packit 875988
@end table
Packit 875988
@end deftp
Packit 875988
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-flow
Packit 875988
@chapter Flow control.
Packit 875988
Packit 875988
@noindent
Packit 875988
Sometimes it may be possible that clients upload data faster
Packit 875988
than an application can process it, or that an application
Packit 875988
needs an extended period of time to generate a response.
Packit 875988
If @code{MHD_USE_THREAD_PER_CONNECTION} is used, applications
Packit 875988
can simply deal with this by performing their logic within the
Packit 875988
thread and thus effectively blocking connection processing
Packit 875988
by MHD.  In all other modes, blocking logic must not be
Packit 875988
placed within the callbacks invoked by MHD as this would also
Packit 875988
block processing of other requests, as a single thread may be
Packit 875988
responsible for tens of thousands of connections.
Packit 875988
Packit 875988
Instead, applications using thread modes other than
Packit 875988
@code{MHD_USE_THREAD_PER_CONNECTION} should use the
Packit 875988
following functions to perform flow control.
Packit 875988
Packit 875988
@deftypefun int MHD_suspend_connection (struct MHD_Connection *connection)
Packit 875988
Suspend handling of network data for a given connection.  This can
Packit 875988
be used to dequeue a connection from MHD's event loop (external
Packit 875988
select, internal select or thread pool; not applicable to
Packit 875988
thread-per-connection!) for a while.
Packit 875988
Packit 875988
If you use this API in conjunction with a internal select or a
Packit 875988
thread pool, you must set the option @code{MHD_ALLOW_SUSPEND_RESUME} to
Packit 875988
ensure that a resumed connection is immediately processed by MHD.
Packit 875988
Packit 875988
Suspended connections continue to count against the total number of
Packit 875988
connections allowed (per daemon, as well as per IP, if such limits
Packit 875988
are set).  Suspended connections will NOT time out; timeouts will
Packit 875988
restart when the connection handling is resumed.  While a
Packit 875988
connection is suspended, MHD will not detect disconnects by the
Packit 875988
client.
Packit 875988
Packit 875988
The only safe time to suspend a connection is from the
Packit 875988
@code{MHD_AccessHandlerCallback} or from the respective
Packit 875988
@code{MHD_ContentReaderCallback} (but in this case the
Packit 875988
response object must not be shared among multiple
Packit 875988
connections).
Packit 875988
Packit 875988
Finally, it is an API violation to call @code{MHD_stop_daemon} while
Packit 875988
having suspended connections (this will at least create memory and
Packit 875988
socket leaks or lead to undefined behavior).  You must explicitly
Packit 875988
resume all connections before stopping the daemon.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item connection
Packit 875988
the connection to suspend
Packit 875988
@end table
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
@deftypefun int MHD_resume_connection (struct MHD_Connection *connection)
Packit 875988
Resume handling of network data for suspended connection.  It is safe
Packit 875988
to resume a suspended connection at any time.  Calling this function
Packit 875988
on a connection that was not previously suspended will result in
Packit 875988
undefined behavior.
Packit 875988
Packit 875988
If you are using this function in ``external'' select mode, you must
Packit 875988
make sure to run @code{MHD_run} afterwards (before again calling
Packit 875988
@code{MHD_get_fdset}), as otherwise the change may not be reflected in
Packit 875988
the set returned by @code{MHD_get_fdset} and you may end up with a
Packit 875988
connection that is stuck until the next network activity.
Packit 875988
Packit 875988
You can check whether a connection is currently suspended using
Packit 875988
@code{MHD_get_connection_info} by querying for
Packit 875988
@code{MHD_CONNECTION_INFO_CONNECTION_SUSPENDED}.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item connection
Packit 875988
the connection to resume
Packit 875988
@end table
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-dauth
Packit 875988
@chapter Utilizing Authentication
Packit 875988
Packit 875988
@noindent
Packit 875988
MHD support three types of client authentication.
Packit 875988
Packit 875988
Basic authentication uses a simple authentication method based
Packit 875988
on BASE64 algorithm. Username and password are exchanged in clear
Packit 875988
between the client and the server, so this method must only be used
Packit 875988
for non-sensitive content or when the session is protected with https.
Packit 875988
When using basic authentication MHD will have access to the clear
Packit 875988
password, possibly allowing to create a chained authentication
Packit 875988
toward an external authentication server.
Packit 875988
Packit 875988
Digest authentication uses a one-way authentication method based
Packit 875988
on MD5 hash algorithm. Only the hash will transit over the network,
Packit 875988
hence protecting the user password. The nonce will prevent replay
Packit 875988
attacks. This method is appropriate for general use, especially
Packit 875988
when https is not used to encrypt the session.
Packit 875988
Packit 875988
Client certificate authentication uses a X.509 certificate from
Packit 875988
the client. This is the strongest authentication mechanism but it
Packit 875988
requires the use of HTTPS. Client certificate authentication can
Packit 875988
be used simultaneously with Basic or Digest Authentication in order
Packit 875988
to provide a two levels authentication (like for instance separate
Packit 875988
machine and user authentication).  A code example for using
Packit 875988
client certificates is presented in the MHD tutorial.
Packit 875988
Packit 875988
@menu
Packit 875988
* microhttpd-dauth basic:: Using Basic Authentication.
Packit 875988
* microhttpd-dauth digest:: Using Digest Authentication.
Packit 875988
@end menu
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-dauth basic
Packit 875988
@section Using Basic Authentication
Packit 875988
Packit 875988
@deftypefun {void} MHD_free (void *ptr)
Packit 875988
Free the memory given at @code{ptr}.  Used to free data structures allocated by MHD. Calls @code{free(ptr)}.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
@deftypefun {char *} MHD_basic_auth_get_username_password (struct MHD_Connection *connection, char** password)
Packit 875988
Get the username and password from the basic authorization header sent by the client.
Packit 875988
Return @code{NULL} if no username could be found, a pointer to the username if found.
Packit 875988
If returned value is not @code{NULL}, the value must be @code{MHD_free()}'ed.
Packit 875988
Packit 875988
@var{password} reference a buffer to store the password. It can be @code{NULL}.
Packit 875988
If returned value is not @code{NULL}, the value must be @code{MHD_free()}'ed.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
@deftypefun {int} MHD_queue_basic_auth_fail_response (struct MHD_Connection *connection, const char *realm, struct MHD_Response *response)
Packit 875988
Queues a response to request basic authentication from the client.
Packit 875988
Return @code{MHD_YES} if successful, otherwise @code{MHD_NO}.
Packit 875988
Packit 875988
@var{realm} must reference to a zero-terminated string representing the realm.
Packit 875988
Packit 875988
@var{response} a response structure to specify what shall be presented to the
Packit 875988
client with a 401 HTTP status.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-dauth digest
Packit 875988
@section Using Digest Authentication
Packit 875988
Packit 875988
@deftypefun {char *} MHD_digest_auth_get_username (struct MHD_Connection *connection)
Packit 875988
Find and return a pointer to the username value from the request header.
Packit 875988
Return @code{NULL} if the value is not found or header does not exist.
Packit 875988
If returned value is not @code{NULL}, the value must be @code{MHD_free()}'ed.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
@deftypefun int MHD_digest_auth_check (struct MHD_Connection *connection, const char *realm, const char *username, const char *password, unsigned int nonce_timeout)
Packit 875988
Checks if the provided values in the WWW-Authenticate header are valid
Packit 875988
and sound according to RFC2716. If valid return @code{MHD_YES}, otherwise return @code{MHD_NO}.
Packit 875988
Packit 875988
@var{realm} must reference to a zero-terminated string representing the realm.
Packit 875988
Packit 875988
@var{username} must reference to a zero-terminated string representing the username,
Packit 875988
it is usually the returned value from MHD_digest_auth_get_username.
Packit 875988
Packit 875988
@var{password} must reference to a zero-terminated string representing the password,
Packit 875988
most probably it will be the result of a lookup of the username against a local database.
Packit 875988
Packit 875988
@var{nonce_timeout} is the amount of time in seconds for a nonce to be invalid.
Packit 875988
Most of the time it is sound to specify 300 seconds as its values.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
@deftypefun int MHD_queue_auth_fail_response (struct MHD_Connection *connection, const char *realm, const char *opaque, struct MHD_Response *response, int signal_stale)
Packit 875988
Queues a response to request authentication from the client,
Packit 875988
return @code{MHD_YES} if successful, otherwise @code{MHD_NO}.
Packit 875988
Packit 875988
@var{realm} must reference to a zero-terminated string representing the realm.
Packit 875988
Packit 875988
@var{opaque} must reference to a zero-terminated string representing a value
Packit 875988
that gets passed to the client and expected to be passed again to the server
Packit 875988
as-is. This value can be a hexadecimal or base64 string.
Packit 875988
Packit 875988
@var{response} a response structure to specify what shall be presented to the
Packit 875988
client with a 401 HTTP status.
Packit 875988
Packit 875988
@var{signal_stale} a value that signals "stale=true" in the response header to
Packit 875988
indicate the invalidity of the nonce and no need to ask for authentication
Packit 875988
parameters and only a new nonce gets generated. @code{MHD_YES} to generate a new
Packit 875988
nonce, @code{MHD_NO} to ask for authentication parameters.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Example: handling digest authentication requests and responses.
Packit 875988
Packit 875988
@example
Packit 875988
#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>"
Packit 875988
#define DENIED "<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>"
Packit 875988
#define OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4"
Packit 875988
Packit 875988
static int
Packit 875988
ahc_echo (void *cls,
Packit 875988
          struct MHD_Connection *connection,
Packit 875988
          const char *url,
Packit 875988
          const char *method,
Packit 875988
          const char *version,
Packit 875988
          const char *upload_data, size_t *upload_data_size, void **ptr)
Packit 875988
@{
Packit 875988
  struct MHD_Response *response;
Packit 875988
  char *username;
Packit 875988
  const char *password = "testpass";
Packit 875988
  const char *realm = "test@@example.com";
Packit 875988
  int ret;
Packit 875988
Packit 875988
  username = MHD_digest_auth_get_username(connection);
Packit 875988
  if (username == NULL)
Packit 875988
    @{
Packit 875988
      response = MHD_create_response_from_buffer(strlen (DENIED),
Packit 875988
					         DENIED,
Packit 875988
					         MHD_RESPMEM_PERSISTENT);
Packit 875988
      ret = MHD_queue_auth_fail_response(connection, realm,
Packit 875988
					 OPAQUE,
Packit 875988
					 response,
Packit 875988
					 MHD_NO);
Packit 875988
      MHD_destroy_response(response);
Packit 875988
      return ret;
Packit 875988
    @}
Packit 875988
  ret = MHD_digest_auth_check(connection, realm,
Packit 875988
			      username,
Packit 875988
			      password,
Packit 875988
			      300);
Packit 875988
  free(username);
Packit 875988
  if ( (ret == MHD_INVALID_NONCE) ||
Packit 875988
       (ret == MHD_NO) )
Packit 875988
    @{
Packit 875988
      response = MHD_create_response_from_buffer(strlen (DENIED),
Packit 875988
					         DENIED,
Packit 875988
					         MHD_RESPMEM_PERSISTENT);
Packit 875988
      if (NULL == response)
Packit 875988
	return MHD_NO;
Packit 875988
      ret = MHD_queue_auth_fail_response(connection, realm,
Packit 875988
					 OPAQUE,
Packit 875988
					 response,
Packit 875988
					 (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO);
Packit 875988
      MHD_destroy_response(response);
Packit 875988
      return ret;
Packit 875988
    @}
Packit 875988
  response = MHD_create_response_from_buffer (strlen(PAGE), PAGE,
Packit 875988
 					      MHD_RESPMEM_PERSISTENT);
Packit 875988
  ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
Packit 875988
  MHD_destroy_response(response);
Packit 875988
  return ret;
Packit 875988
@}
Packit 875988
@end example
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-post
Packit 875988
@chapter Adding a @code{POST} processor
Packit 875988
@cindex POST method
Packit 875988
Packit 875988
@menu
Packit 875988
* microhttpd-post api::         Programming interface for the
Packit 875988
                                @code{POST} processor.
Packit 875988
@end menu
Packit 875988
Packit 875988
Packit 875988
@noindent
Packit 875988
MHD provides the post processor API to make it easier for applications to
Packit 875988
parse the data of a client's @code{POST} request: the
Packit 875988
@code{MHD_AccessHandlerCallback} will be invoked multiple times to
Packit 875988
process data as it arrives; at each invocation a new chunk of data must
Packit 875988
be processed. The arguments @var{upload_data} and @var{upload_data_size}
Packit 875988
are used to reference the chunk of data.
Packit 875988
Packit 875988
When @code{MHD_AccessHandlerCallback} is invoked for a new connection:
Packit 875988
its @code{*@var{con_cls}} argument is set to @code{NULL}. When @code{POST}
Packit 875988
data comes in the upload buffer it is @strong{mandatory} to use the
Packit 875988
@var{con_cls} to store a reference to per-connection data.  The fact
Packit 875988
that the pointer was initially @code{NULL} can be used to detect that
Packit 875988
this is a new request.
Packit 875988
Packit 875988
One method to detect that a new connection was established is
Packit 875988
to set @code{*con_cls} to an unused integer:
Packit 875988
Packit 875988
@example
Packit 875988
int
Packit 875988
access_handler (void *cls,
Packit 875988
                struct MHD_Connection * connection,
Packit 875988
                const char *url,
Packit 875988
                const char *method, const char *version,
Packit 875988
                const char *upload_data, size_t *upload_data_size,
Packit 875988
                void **con_cls)
Packit 875988
@{
Packit 875988
  static int old_connection_marker;
Packit 875988
  int new_connection = (NULL == *con_cls);
Packit 875988
Packit 875988
  if (new_connection)
Packit 875988
    @{
Packit 875988
      /* new connection with POST */
Packit 875988
      *con_cls = &old_connection_marker;
Packit 875988
    @}
Packit 875988
Packit 875988
  ...
Packit 875988
@}
Packit 875988
@end example
Packit 875988
Packit 875988
@noindent
Packit 875988
In contrast to the previous example, for @code{POST} requests in particular,
Packit 875988
it is more common to use the value of @code{*con_cls} to keep track of
Packit 875988
actual state used during processing, such as the post processor (or a
Packit 875988
struct containing a post processor):
Packit 875988
Packit 875988
@example
Packit 875988
int
Packit 875988
access_handler (void *cls,
Packit 875988
                struct MHD_Connection * connection,
Packit 875988
                const char *url,
Packit 875988
                const char *method, const char *version,
Packit 875988
                const char *upload_data, size_t *upload_data_size,
Packit 875988
                void **con_cls)
Packit 875988
@{
Packit 875988
  struct MHD_PostProcessor * pp = *con_cls;
Packit 875988
Packit 875988
  if (pp == NULL)
Packit 875988
    @{
Packit 875988
      pp = MHD_create_post_processor(connection, ...);
Packit 875988
      *con_cls = pp;
Packit 875988
      return MHD_YES;
Packit 875988
    @}
Packit 875988
  if (*upload_data_size)
Packit 875988
    @{
Packit 875988
      MHD_post_process(pp, upload_data, *upload_data_size);
Packit 875988
      *upload_data_size = 0;
Packit 875988
      return MHD_YES;
Packit 875988
    @}
Packit 875988
  else
Packit 875988
    @{
Packit 875988
      MHD_destroy_post_processor(pp);
Packit 875988
      return MHD_queue_response(...);
Packit 875988
    @}
Packit 875988
@}
Packit 875988
@end example
Packit 875988
Packit 875988
Note that the callback from @code{MHD_OPTION_NOTIFY_COMPLETED}
Packit 875988
should be used to destroy the post processor.  This cannot be
Packit 875988
done inside of the access handler since the connection may not
Packit 875988
always terminate normally.
Packit 875988
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-post api
Packit 875988
@section Programming interface for the @code{POST} processor
Packit 875988
@cindex POST method
Packit 875988
Packit 875988
@deftypefun {struct MHD_PostProcessor *} MHD_create_post_processor (struct MHD_Connection *connection, size_t buffer_size, MHD_PostDataIterator iterator, void *iterator_cls)
Packit 875988
Create a PostProcessor.  A PostProcessor can be used to (incrementally)
Packit 875988
parse the data portion of a @code{POST} request.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item connection
Packit 875988
the connection on which the @code{POST} is happening (used to determine
Packit 875988
the @code{POST} format);
Packit 875988
Packit 875988
@item buffer_size
Packit 875988
maximum number of bytes to use for internal buffering (used only for the
Packit 875988
parsing, specifically the parsing of the keys).  A tiny value (256-1024)
Packit 875988
should be sufficient; do @strong{NOT} use a value smaller than 256;
Packit 875988
for good performance, use 32k or 64k (i.e. 65536).
Packit 875988
Packit 875988
@item iterator
Packit 875988
iterator to be called with the parsed data; must @strong{NOT} be
Packit 875988
@code{NULL};
Packit 875988
Packit 875988
@item iterator_cls
Packit 875988
custom value to be used as first argument to @var{iterator}.
Packit 875988
@end table
Packit 875988
Packit 875988
Return @code{NULL} on error (out of memory, unsupported encoding), otherwise
Packit 875988
a PP handle.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@deftypefun int MHD_post_process (struct MHD_PostProcessor *pp, const char *post_data, size_t post_data_len)
Packit 875988
Parse and process @code{POST} data.  Call this function when @code{POST}
Packit 875988
data is available (usually during an @code{MHD_AccessHandlerCallback})
Packit 875988
with the @var{upload_data} and @var{upload_data_size}.  Whenever
Packit 875988
possible, this will then cause calls to the
Packit 875988
@code{MHD_IncrementalKeyValueIterator}.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item pp
Packit 875988
the post processor;
Packit 875988
Packit 875988
@item post_data
Packit 875988
@var{post_data_len} bytes of @code{POST} data;
Packit 875988
Packit 875988
@item post_data_len
Packit 875988
length of @var{post_data}.
Packit 875988
@end table
Packit 875988
Packit 875988
Return @code{MHD_YES} on success, @code{MHD_NO} on error
Packit 875988
(out-of-memory, iterator aborted, parse error).
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@deftypefun int MHD_destroy_post_processor (struct MHD_PostProcessor *pp)
Packit 875988
Release PostProcessor resources.  After this function is being called,
Packit 875988
the PostProcessor is guaranteed to no longer call its iterator.  There
Packit 875988
is no special call to the iterator to indicate the end of the post processing
Packit 875988
stream.  After destroying the PostProcessor, the programmer should
Packit 875988
perform any necessary work to complete the processing of the iterator.
Packit 875988
Packit 875988
Return @code{MHD_YES} if processing completed nicely, @code{MHD_NO}
Packit 875988
if there were spurious characters or formatting problems with
Packit 875988
the post request.  It is common to ignore the return value
Packit 875988
of this function.
Packit 875988
Packit 875988
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-info
Packit 875988
@chapter Obtaining and modifying status information.
Packit 875988
Packit 875988
Packit 875988
@menu
Packit 875988
* microhttpd-info daemon::        State information about an MHD daemon
Packit 875988
* microhttpd-info conn::          State information about a connection
Packit 875988
* microhttpd-option conn::        Modify per-connection options
Packit 875988
@end menu
Packit 875988
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-info daemon
Packit 875988
@section Obtaining state information about an MHD daemon
Packit 875988
Packit 875988
@deftypefun {const union MHD_DaemonInfo *} MHD_get_daemon_info (struct MHD_Daemon *daemon, enum MHD_DaemonInfoType infoType, ...)
Packit 875988
Obtain information about the given daemon.  This function
Packit 875988
is currently not fully implemented.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item daemon
Packit 875988
the daemon about which information is desired;
Packit 875988
Packit 875988
@item infoType
Packit 875988
type of information that is desired
Packit 875988
Packit 875988
@item ...
Packit 875988
additional arguments about the desired information (depending on
Packit 875988
infoType)
Packit 875988
@end table
Packit 875988
Packit 875988
Returns a union with the respective member (depending on
Packit 875988
infoType) set to the desired information), or @code{NULL}
Packit 875988
in case the desired information is not available or
Packit 875988
applicable.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@deftp {Enumeration} MHD_DaemonInfoType
Packit 875988
Values of this enum are used to specify what
Packit 875988
information about a daemon is desired.
Packit 875988
@table @code
Packit 875988
@item MHD_DAEMON_INFO_KEY_SIZE
Packit 875988
Request information about the key size for a particular cipher
Packit 875988
algorithm.  The cipher algorithm should be passed as an extra argument
Packit 875988
(of type 'enum MHD_GNUTLS_CipherAlgorithm').  No longer supported,
Packit 875988
using this value will cause @code{MHD_get_daemon_info} to return NULL.
Packit 875988
Packit 875988
@item MHD_DAEMON_INFO_MAC_KEY_SIZE
Packit 875988
Request information about the key size for a particular cipher
Packit 875988
algorithm.  The cipher algorithm should be passed as an extra argument
Packit 875988
(of type 'enum MHD_GNUTLS_HashAlgorithm').  No longer supported,
Packit 875988
using this value will cause @code{MHD_get_daemon_info} to return NULL.
Packit 875988
Packit 875988
@item MHD_DAEMON_INFO_LISTEN_FD
Packit 875988
@cindex listen
Packit 875988
Request the file-descriptor number that MHD is using to listen to the
Packit 875988
server socket.  This can be useful if no port
Packit 875988
was specified and a client needs to learn what port
Packit 875988
is actually being used by MHD.
Packit 875988
No extra arguments should be passed.
Packit 875988
Packit 875988
@item MHD_DAEMON_INFO_EPOLL_FD
Packit 875988
@cindex epoll
Packit 875988
Request the file-descriptor number that MHD is using for epoll.  If
Packit 875988
the build is not supporting epoll, NULL is returned; if we are using a
Packit 875988
thread pool or this daemon was not started with
Packit 875988
@code{MHD_USE_EPOLL}, (a pointer to) -1 is returned.  If we are
Packit 875988
using @code{MHD_USE_INTERNAL_POLLING_THREAD} or are in 'external' select mode, the
Packit 875988
internal epoll FD is returned.  This function must be used in external
Packit 875988
select mode with epoll to obtain the FD to call epoll on.  No extra
Packit 875988
arguments should be passed.
Packit 875988
Packit 875988
@item MHD_DAEMON_INFO_CURRENT_CONNECTIONS
Packit 875988
@cindex connection, limiting number of connections
Packit 875988
Request the number of current connections handled by the daemon.  No
Packit 875988
extra arguments should be passed and a pointer to a @code{union
Packit 875988
MHD_DaemonInfo} value is returned, with the @code{num_connections}
Packit 875988
member of type @code{unsigned int} set to the number of active
Packit 875988
connections.
Packit 875988
Packit 875988
Note that in multi-threaded or internal-select mode, the real number of current
Packit 875988
connections may already be different when @code{MHD_get_daemon_info} returns.
Packit 875988
The number of current connections can be used (even in multi-threaded and
Packit 875988
internal-select mode) after @code{MHD_quiesce_daemon} to detect whether all
Packit 875988
connections have been handled.
Packit 875988
Packit 875988
@end table
Packit 875988
@end deftp
Packit 875988
Packit 875988
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-info conn
Packit 875988
@section Obtaining state information about a connection
Packit 875988
Packit 875988
Packit 875988
@deftypefun {const union MHD_ConnectionInfo *} MHD_get_connection_info (struct MHD_Connection *daemon, enum MHD_ConnectionInfoType infoType, ...)
Packit 875988
Obtain information about the given connection.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item connection
Packit 875988
the connection about which information is desired;
Packit 875988
Packit 875988
@item infoType
Packit 875988
type of information that is desired
Packit 875988
Packit 875988
@item ...
Packit 875988
additional arguments about the desired information (depending on
Packit 875988
infoType)
Packit 875988
@end table
Packit 875988
Packit 875988
Returns a union with the respective member (depending on
Packit 875988
infoType) set to the desired information), or @code{NULL}
Packit 875988
in case the desired information is not available or
Packit 875988
applicable.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
@deftp {Enumeration} MHD_ConnectionInfoType
Packit 875988
Values of this enum are used to specify what information about a
Packit 875988
connection is desired.
Packit 875988
Packit 875988
@table @code
Packit 875988
Packit 875988
@item MHD_CONNECTION_INFO_CIPHER_ALGO
Packit 875988
What cipher algorithm is being used (HTTPS connections only).
Packit 875988
@code{NULL} is returned for non-HTTPS connections.
Packit 875988
Packit 875988
Takes no extra arguments.
Packit 875988
Packit 875988
@item MHD_CONNECTION_INFO_PROTOCOL,
Packit 875988
Allows finding out the TLS/SSL protocol used
Packit 875988
(HTTPS connections only).
Packit 875988
@code{NULL} is returned for non-HTTPS connections.
Packit 875988
Packit 875988
Takes no extra arguments.
Packit 875988
Packit 875988
@item MHD_CONNECTION_INFO_CLIENT_ADDRESS
Packit 875988
Returns information about the address of the client.  Returns
Packit 875988
essentially a @code{struct sockaddr **} (since the API returns
Packit 875988
a @code{union MHD_ConnectionInfo *} and that union contains
Packit 875988
a @code{struct sockaddr *}).
Packit 875988
Packit 875988
Takes no extra arguments.
Packit 875988
Packit 875988
@item MHD_CONNECTION_INFO_GNUTLS_SESSION,
Packit 875988
Takes no extra arguments.  Allows access to the underlying GNUtls session,
Packit 875988
including access to the underlying GNUtls client certificate
Packit 875988
(HTTPS connections only).  Takes no extra arguments.
Packit 875988
@code{NULL} is returned for non-HTTPS connections.
Packit 875988
Packit 875988
Takes no extra arguments.
Packit 875988
Packit 875988
@item MHD_CONNECTION_INFO_GNUTLS_CLIENT_CERT,
Packit 875988
Dysfunctional (never implemented, deprecated).  Use
Packit 875988
MHD_CONNECTION_INFO_GNUTLS_SESSION to get the @code{gnutls_session_t}
Packit 875988
and then call @code{gnutls_certificate_get_peers()}.
Packit 875988
Packit 875988
@item MHD_CONNECTION_INFO_DAEMON
Packit 875988
Returns information about @code{struct MHD_Daemon} which manages
Packit 875988
this connection.
Packit 875988
Packit 875988
Takes no extra arguments.
Packit 875988
Packit 875988
@item MHD_CONNECTION_INFO_CONNECTION_FD
Packit 875988
Returns the file descriptor (usually a TCP socket) associated with
Packit 875988
this connection (in the ``connect-fd'' member of the returned struct).
Packit 875988
Note that manipulating the descriptor directly can have problematic
Packit 875988
consequences (as in, break HTTP).  Applications might use this access
Packit 875988
to manipulate TCP options, for example to set the ``TCP-NODELAY''
Packit 875988
option for COMET-like applications.  Note that MHD will set TCP-CORK
Packit 875988
after sending the HTTP header and clear it after finishing the footers
Packit 875988
automatically (if the platform supports it).  As the connection
Packit 875988
callbacks are invoked in between, those might be used to set different
Packit 875988
values for TCP-CORK and TCP-NODELAY in the meantime.
Packit 875988
Packit 875988
Takes no extra arguments.
Packit 875988
Packit 875988
@item MHD_CONNECTION_INFO_CONNECTION_SUSPENDED
Packit 875988
Returns pointer to an integer that is @code{MHD_YES} if the connection
Packit 875988
is currently suspended (and thus can be safely resumed) and
Packit 875988
@code{MHD_NO} otherwise.
Packit 875988
Packit 875988
Takes no extra arguments.
Packit 875988
Packit 875988
@item MHD_CONNECTION_INFO_SOCKET_CONTEXT
Packit 875988
Returns the client-specific pointer to a @code{void *} that was
Packit 875988
(possibly) set during a @code{MHD_NotifyConnectionCallback} when the
Packit 875988
socket was first accepted.  Note that this is NOT the same as the
Packit 875988
@code{con_cls} argument of the @code{MHD_AccessHandlerCallback}.  The
Packit 875988
@code{con_cls} is fresh for each HTTP request, while the
Packit 875988
@code{socket_context} is fresh for each socket.
Packit 875988
Packit 875988
Takes no extra arguments.
Packit 875988
Packit 875988
@item MHD_CONNECTION_INFO_CONNECTION_TIMEOUT
Packit 875988
Returns pointer to an @code{unsigned int} that is the current timeout
Packit 875988
used for the connection (in seconds, 0 for no timeout).  Note that
Packit 875988
while suspended connections will not timeout, the timeout value
Packit 875988
returned for suspended connections will be the timeout that the
Packit 875988
connection will use after it is resumed, and thus might not be zero.
Packit 875988
Packit 875988
Takes no extra arguments.
Packit 875988
Packit 875988
@item MHD_CONNECTION_INFO_REQUEST_HEADER_SIZE
Packit 875988
@cindex performance
Packit 875988
Returns pointer to an @code{size_t} that represents the size of the
Packit 875988
HTTP header received from the client. Only valid after the first callback
Packit 875988
to the access handler.
Packit 875988
Packit 875988
Takes no extra arguments.
Packit 875988
Packit 875988
@end table
Packit 875988
@end deftp
Packit 875988
Packit 875988
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-option conn
Packit 875988
@section Setting custom options for an individual connection
Packit 875988
@cindex timeout
Packit 875988
Packit 875988
Packit 875988
Packit 875988
@deftypefun {int} MHD_set_connection_option (struct MHD_Connection *daemon, enum MHD_CONNECTION_OPTION option, ...)
Packit 875988
Set a custom option for the given connection.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item connection
Packit 875988
the connection for which an option should be set or modified;
Packit 875988
Packit 875988
@item option
Packit 875988
option to set
Packit 875988
Packit 875988
@item ...
Packit 875988
additional arguments for the option (depending on option)
Packit 875988
@end table
Packit 875988
Packit 875988
Returns @code{MHD_YES} on success, @code{MHD_NO} for errors
Packit 875988
(i.e. option argument invalid or option unknown).
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@deftp {Enumeration} MHD_CONNECTION_OPTION
Packit 875988
Values of this enum are used to specify which option for a
Packit 875988
connection should be changed.
Packit 875988
Packit 875988
@table @code
Packit 875988
Packit 875988
@item MHD_CONNECTION_OPTION_TIMEOUT
Packit 875988
Set a custom timeout for the given connection.   Specified
Packit 875988
as the number of seconds, given as an @code{unsigned int}.  Use
Packit 875988
zero for no timeout.
Packit 875988
Packit 875988
@end table
Packit 875988
@end deftp
Packit 875988
Packit 875988
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-util
Packit 875988
@chapter Utility functions.
Packit 875988
Packit 875988
Packit 875988
@menu
Packit 875988
* microhttpd-util feature::       Test supported MHD features
Packit 875988
* microhttpd-util unescape::      Unescape strings
Packit 875988
@end menu
Packit 875988
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-util feature
Packit 875988
@section Testing for supported MHD features
Packit 875988
Packit 875988
Packit 875988
@deftp {Enumeration} MHD_FEATURE
Packit 875988
Values of this enum are used to specify what
Packit 875988
information about a daemon is desired.
Packit 875988
@table @code
Packit 875988
@item MHD_FEATURE_MESSAGES
Packit 875988
Get whether messages are supported. If supported then in debug
Packit 875988
mode messages can be printed to stderr or to external logger.
Packit 875988
Packit 875988
@item MHD_FEATURE_SSL
Packit 875988
Get whether HTTPS is supported.  If supported then flag
Packit 875988
MHD_USE_SSL and options MHD_OPTION_HTTPS_MEM_KEY,
Packit 875988
MHD_OPTION_HTTPS_MEM_CERT, MHD_OPTION_HTTPS_MEM_TRUST,
Packit 875988
MHD_OPTION_HTTPS_MEM_DHPARAMS, MHD_OPTION_HTTPS_CRED_TYPE,
Packit 875988
MHD_OPTION_HTTPS_PRIORITIES can be used.
Packit 875988
Packit 875988
@item MHD_FEATURE_HTTPS_CERT_CALLBACK
Packit 875988
Get whether option #MHD_OPTION_HTTPS_CERT_CALLBACK is
Packit 875988
supported.
Packit 875988
Packit 875988
@item MHD_FEATURE_IPv6
Packit 875988
Get whether IPv6 is supported. If supported then flag
Packit 875988
MHD_USE_IPv6 can be used.
Packit 875988
Packit 875988
@item MHD_FEATURE_IPv6_ONLY
Packit 875988
Get whether IPv6 without IPv4 is supported. If not supported
Packit 875988
then IPv4 is always enabled in IPv6 sockets and
Packit 875988
flag MHD_USE_DUAL_STACK if always used when MHD_USE_IPv6 is
Packit 875988
specified.
Packit 875988
Packit 875988
@item MHD_FEATURE_POLL
Packit 875988
Get whether @code{poll()} is supported. If supported then flag
Packit 875988
MHD_USE_POLL can be used.
Packit 875988
Packit 875988
@item MHD_FEATURE_EPOLL
Packit 875988
Get whether @code{epoll()} is supported. If supported then Flags
Packit 875988
MHD_USE_EPOLL and
Packit 875988
MHD_USE_EPOLL_INTERNAL_THREAD can be used.
Packit 875988
Packit 875988
@item MHD_FEATURE_SHUTDOWN_LISTEN_SOCKET
Packit 875988
Get whether shutdown on listen socket to signal other
Packit 875988
threads is supported. If not supported flag
Packit 875988
MHD_USE_ITC is automatically forced.
Packit 875988
Packit 875988
@item MHD_FEATURE_SOCKETPAIR
Packit 875988
Get whether a @code{socketpair()} is used internally instead of
Packit 875988
a @code{pipe()} to signal other threads.
Packit 875988
Packit 875988
@item MHD_FEATURE_TCP_FASTOPEN
Packit 875988
Get whether TCP Fast Open is supported. If supported then
Packit 875988
flag MHD_USE_TCP_FASTOPEN and option
Packit 875988
MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE can be used.
Packit 875988
Packit 875988
@item MHD_FEATURE_BASIC_AUTH
Packit 875988
Get whether HTTP Basic authorization is supported. If supported
Packit 875988
then functions @code{MHD_basic_auth_get_username_password()} and
Packit 875988
@code{MHD_queue_basic_auth_fail_response()} can be used.
Packit 875988
Packit 875988
@item MHD_FEATURE_DIGEST_AUTH
Packit 875988
Get whether HTTP Digest authorization is supported. If
Packit 875988
supported then options MHD_OPTION_DIGEST_AUTH_RANDOM,
Packit 875988
MHD_OPTION_NONCE_NC_SIZE and functions @code{MHD_digest_auth_check()},
Packit 875988
can be used.
Packit 875988
Packit 875988
@item MHD_FEATURE_POSTPROCESSOR
Packit 875988
Get whether postprocessor is supported. If supported then
Packit 875988
functions @code{MHD_create_post_processor()},
Packit 875988
@code{MHD_post_process()}, @code{MHD_destroy_post_processor()}
Packit 875988
can be used.
Packit 875988
Packit 875988
@item MHD_FEATURE_SENDFILE
Packit 875988
Get whether @code{sendfile()} is supported.
Packit 875988
Packit 875988
@end table
Packit 875988
@end deftp
Packit 875988
Packit 875988
Packit 875988
Packit 875988
@deftypefun {int} MHD_is_feature_supported (enum MHD_FEATURE feature)
Packit 875988
Get information about supported MHD features.  Indicate that MHD was
Packit 875988
compiled with or without support for particular feature. Some features
Packit 875988
require additional support by the kernel.  However, kernel support is not
Packit 875988
checked by this function.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item feature
Packit 875988
type of requested information
Packit 875988
@end table
Packit 875988
Packit 875988
Returns @code{MHD_YES} if the feature is supported,
Packit 875988
and @code{MHD_NO} if not.
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
@c ------------------------------------------------------------
Packit 875988
@node microhttpd-util unescape
Packit 875988
@section Unescape strings
Packit 875988
Packit 875988
@deftypefun {size_t} MHD_http_unescape (char *val)
Packit 875988
Process escape sequences ('%HH') Updates val in place; the result
Packit 875988
should be UTF-8 encoded and cannot be larger than the input.  The
Packit 875988
result must also still be 0-terminated.
Packit 875988
Packit 875988
@table @var
Packit 875988
@item val
Packit 875988
value to unescape (modified in the process), must be
Packit 875988
a 0-terminated UTF-8 string.
Packit 875988
@end table
Packit 875988
Packit 875988
Returns length of the resulting val (@code{strlen(val)} may be
Packit 875988
shorter afterwards due to elimination of escape sequences).
Packit 875988
Packit 875988
@end deftypefun
Packit 875988
Packit 875988
Packit 875988
Packit 875988
Packit 875988
@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packit 875988
Packit 875988
Packit 875988
@c **********************************************************
Packit 875988
@c *******************  Appendices  *************************
Packit 875988
@c **********************************************************
Packit 875988
Packit 875988
@node GNU-LGPL
Packit 875988
@unnumbered GNU-LGPL
Packit 875988
@cindex license
Packit 875988
@include lgpl.texi
Packit 875988
Packit 875988
@node GNU GPL with eCos Extension
Packit 875988
@unnumbered GNU GPL with eCos Extension
Packit 875988
@cindex license
Packit 875988
@include ecos.texi
Packit 875988
Packit 875988
@node GNU-FDL
Packit 875988
@unnumbered GNU-FDL
Packit 875988
@cindex license
Packit 875988
@include fdl-1.3.texi
Packit 875988
Packit 875988
@node Concept Index
Packit 875988
@unnumbered Concept Index
Packit 875988
Packit 875988
@printindex cp
Packit 875988
Packit 875988
@node Function and Data Index
Packit 875988
@unnumbered Function and Data Index
Packit 875988
Packit 875988
@printindex fn
Packit 875988
Packit 875988
@node Type Index
Packit 875988
@unnumbered Type Index
Packit 875988
Packit 875988
@printindex tp
Packit 875988
Packit 875988
@bye