aboutsummaryrefslogtreecommitdiff
path: root/doc/libmicrohttpd.texi
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-09-08 19:15:04 +0000
committerChristian Grothoff <christian@grothoff.org>2012-09-08 19:15:04 +0000
commit5a046307a7475f15698afb6450d92ff4e6ffd0ad (patch)
treece8af1e94305b769f64ad24222127fd026e1bd06 /doc/libmicrohttpd.texi
parentad74bf4b442d214e4c3e8ade23d460fcf35c11f1 (diff)
downloadlibmicrohttpd-5a046307a7475f15698afb6450d92ff4e6ffd0ad.tar.gz
libmicrohttpd-5a046307a7475f15698afb6450d92ff4e6ffd0ad.zip
applyin Karl Berry's suggestions for GNU libextractor also to MHD
Diffstat (limited to 'doc/libmicrohttpd.texi')
-rw-r--r--doc/libmicrohttpd.texi2140
1 files changed, 2140 insertions, 0 deletions
diff --git a/doc/libmicrohttpd.texi b/doc/libmicrohttpd.texi
new file mode 100644
index 00000000..f9b99bea
--- /dev/null
+++ b/doc/libmicrohttpd.texi
@@ -0,0 +1,2140 @@
1\input texinfo
2@setfilename libmicrohttpd.info
3@include version.texi
4@settitle The GNU libmicrohttpd Reference Manual
5@c Unify all the indices into concept index.
6@syncodeindex fn cp
7@syncodeindex vr cp
8@syncodeindex ky cp
9@syncodeindex pg cp
10@syncodeindex tp cp
11@copying
12This manual is for GNU libmicrohttpd
13(version @value{VERSION}, @value{UPDATED}), a library for embedding
14an HTTP(S) server into C applications.
15
16Copyright @copyright{} 2007--2012 Christian Grothoff
17
18@quotation
19Permission is granted to copy, distribute and/or modify this document
20under the terms of the GNU Free Documentation License, Version 1.3
21or any later version published by the Free Software Foundation;
22with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
23Texts. A copy of the license is included in the section entitled "GNU
24Free Documentation License".
25@end quotation
26@end copying
27
28@dircategory Software libraries
29@direntry
30* libmicrohttpd: (libmicrohttpd). Embedded HTTP server library.
31@end direntry
32
33@c
34@c Titlepage
35@c
36@titlepage
37@title The GNU libmicrohttpd Reference Manual
38@subtitle Version @value{VERSION}
39@subtitle @value{UPDATED}
40@author Marco Maggi (@email{marco.maggi-ipsu@@poste.it})
41@author Christian Grothoff (@email{christian@@grothoff.org})
42@page
43@vskip 0pt plus 1filll
44@insertcopying
45@end titlepage
46
47@summarycontents
48@contents
49
50@c ------------------------------------------------------------
51@ifnottex
52@node Top
53@top The GNU libmicrohttpd Library
54@insertcopying
55@end ifnottex
56
57@menu
58* microhttpd-intro:: Introduction.
59* microhttpd-const:: Constants.
60* microhttpd-struct:: Structures type definition.
61* microhttpd-cb:: Callback functions definition.
62* microhttpd-init:: Starting and stopping the server.
63* microhttpd-inspect:: Implementing external @code{select}.
64* microhttpd-requests:: Handling requests.
65* microhttpd-responses:: Building responses to requests.
66* microhttpd-dauth:: Utilizing Authentication.
67* microhttpd-post:: Adding a @code{POST} processor.
68* microhttpd-info:: Obtaining and modifying status information.
69
70Appendices
71
72* GNU-LGPL:: The GNU Lesser General Public License says how you
73 can copy and share almost all of `libmicrohttpd'.
74* GNU GPL with eCos Extension:: The GNU General Public License with eCos extension says how you
75 can copy and share some parts of `libmicrohttpd'.
76* GNU-FDL:: The GNU Free Documentation License says how you
77 can copy and share the documentation of `libmicrohttpd'.
78
79Indices
80
81* Concept Index:: Index of concepts and programs.
82* Function and Data Index:: Index of functions, variables and data types.
83* Type Index:: Index of data types.
84@end menu
85
86@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
87
88@c ------------------------------------------------------------
89@node microhttpd-intro
90@chapter Introduction
91
92
93@noindent
94All symbols defined in the public API start with @code{MHD_}. MHD
95is a small HTTP daemon library. As such, it does not have any API
96for logging errors (you can only enable or disable logging to stderr).
97Also, it may not support all of the HTTP features directly, where
98applicable, portions of HTTP may have to be handled by clients of the
99library.
100
101The library is supposed to handle everything that it must handle
102(because the API would not allow clients to do this), such as basic
103connection management; however, detailed interpretations of headers ---
104such as range requests --- and HTTP methods are left to clients. The
105library does understand @code{HEAD} and will only send the headers of
106the response and not the body, even if the client supplied a body. The
107library also understands headers that control connection management
108(specifically, @code{Connection: close} and @code{Expect: 100 continue}
109are understood and handled automatically).
110
111MHD understands @code{POST} data and is able to decode certain
112formats (at the moment only @code{application/x-www-form-urlencoded}
113and @code{multipart/form-data}) using the post processor API. The
114data stream of a POST is also provided directly to the main
115application, so unsupported encodings could still be processed, just
116not conveniently by MHD.
117
118The header file defines various constants used by the HTTP protocol.
119This does not mean that MHD actually interprets all of these values.
120The provided constants are exported as a convenience for users of the
121library. MHD does not verify that transmitted HTTP headers are
122part of the standard specification; users of the library are free to
123define their own extensions of the HTTP standard and use those with
124MHD.
125
126All functions are guaranteed to be completely reentrant and
127thread-safe. MHD checks for allocation failures and tries to
128recover gracefully (for example, by closing the connection).
129Additionally, clients can specify resource limits on the overall
130number of connections, number of connections per IP address and memory
131used per connection to avoid resource exhaustion.
132
133@section Scope
134
135MHD is currently used in a wide range of implementations.
136Examples based on reports we've received from developers include:
137@itemize
138@item Embedded HTTP server on a cortex M3 (128 KB code space)
139@item Large-scale multimedia server (reportedly serving at the
140 simulator limit of 7.5 GB/s)
141@item Administrative console (via HTTP/HTTPS) for network appliances
142@c If you have other interesting examples, please let us know
143@end itemize
144
145
146@section Compiling GNU libmicrohttpd
147@cindex compilation
148@cindex embedded systems
149@cindex portability
150
151MHD uses the standard GNU system where the usual build process
152involves running
153@verbatim
154$ ./configure
155$ make
156$ make install
157@end verbatim
158
159MHD supports various options to be given to configure to tailor the
160binary to a specific situation. Note that some of these options will
161remove portions of the MHD code that are required for
162binary-compatibility. They should only be used on embedded systems
163with tight resource constraints and no concerns about library
164versioning. Standard distributions including MHD are expected to
165always ship with all features enabled, otherwise unexpected
166incompatibilities can arise!
167
168Here is a list of MHD-specific options that can be given to configure
169(canonical configure options such as ``--prefix'' are also supported, for a
170full list of options run ``./configure --help''):
171
172@table @code
173@item ``--disable-curl''
174disable running testcases using libcurl
175
176@item ``--disable-largefile''
177disable support for 64-bit files
178
179@item ``--disable-messages''
180disable logging of error messages (smaller binary size, not so much fun for debugging)
181
182@item ``--disable-https''
183disable 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)
184
185@item ``--disable-postprocessor''
186do not include the post processor API (results in binary incompatibility)
187
188@item ``--disable-dauth''
189do not include the authentication APIs (results in binary incompatibility)
190
191@item ``--enable-coverage''
192set flags for analysis of code-coverage with gcc/gcov (results in slow, large binaries)
193
194@item ``--with-gcrypt=PATH''
195specifies path to libgcrypt installation
196
197@item ``--with-gnutls=PATH''
198specifies path to libgnutls installation
199
200
201
202@end table
203
204@section Including the microhttpd.h header
205@cindex portability
206@cindex microhttpd.h
207
208Ideally, before including "microhttpd.h" you should add the necessary
209includes to define the @code{uint64_t}, @code{size_t}, @code{fd_set},
210@code{socklen_t} and @code{struct sockaddr} data types. Which
211specific headers are needed may depend on your platform and your build
212system might include some tests to provide you with the necessary
213conditional operations. For possible suggestions consult
214@code{platform.h} and @code{configure.ac} in the MHD distribution.
215
216Once you have ensured that you manually (!) included the right headers
217for your platform before "microhttpd.h", you should also add a line
218with @code{#define MHD_PLATFORM_H} which will prevent the
219"microhttpd.h" header from trying (and, depending on your platform,
220failing) to include the right headers.
221
222If you do not define MHD_PLATFORM_H, the "microhttpd.h" header will
223automatically include headers needed on GNU/Linux systems (possibly
224causing problems when porting to other platforms).
225
226@section SIGPIPE
227@cindex signals
228MHD does not install a signal handler for SIGPIPE. On platforms
229where this is possible (such as GNU/Linux), it disables SIGPIPE for
230its I/O operations (by passing MSG_NOSIGNAL). On other platforms,
231SIGPIPE signals may be generated from network operations by
232MHD and will cause the process to die unless the developer
233explicitly installs a signal handler for SIGPIPE.
234
235Hence portable code using MHD must install a SIGPIPE handler or
236explicitly block the SIGPIPE signal. MHD does not do so in order
237to avoid messing with other parts of the application that may
238need to handle SIGPIPE in a particular way. You can make your application handle SIGPIPE by calling the following function in @code{main}:
239
240@verbatim
241static void
242catcher (int sig)
243{
244}
245
246static void
247ignore_sigpipe ()
248{
249 struct sigaction oldsig;
250 struct sigaction sig;
251
252 sig.sa_handler = &catcher;
253 sigemptyset (&sig.sa_mask);
254#ifdef SA_INTERRUPT
255 sig.sa_flags = SA_INTERRUPT; /* SunOS */
256#else
257 sig.sa_flags = SA_RESTART;
258#endif
259 if (0 != sigaction (SIGPIPE, &sig, &oldsig))
260 fprintf (stderr,
261 "Failed to install SIGPIPE handler: %s\n", strerror (errno));
262}
263@end verbatim
264
265@section MHD_LONG_LONG
266@cindex long long
267@cindex IAR
268@cindex ARM
269@cindex cortex m3
270@cindex embedded systems
271
272Some platforms do not support @code{long long}. Hence MHD defines
273a macro @code{MHD_LONG_LONG} which will default to @code{long long}.
274If your platform does not support @code{long long}, you should
275change "platform.h" to define @code{MHD_LONG_LONG} to an appropriate
276alternative type and also define @code{MHD_LONG_LONG_PRINTF} to the
277corresponding format string for printing such a data type (without
278the percent sign).
279
280@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
281
282@c ------------------------------------------------------------
283@node microhttpd-const
284@chapter Constants
285
286
287@deftp {Enumeration} MHD_FLAG
288Options for the MHD daemon.
289
290Note that if neither @code{MHD_USE_THREAD_PER_CONNECTION} nor
291@code{MHD_USE_SELECT_INTERNALLY} is used, the client wants control over
292the process and will call the appropriate microhttpd callbacks.
293
294Starting the daemon may also fail if a particular option is not
295implemented or not supported on the target platform (i.e. no support for
296@acronym{SSL}, threads or IPv6). SSL support generally depends on
297options given during MHD compilation. Threaded operations
298(including @code{MHD_USE_SELECT_INTERNALLY}) are not supported on
299Symbian.
300
301@table @code
302@item MHD_NO_FLAG
303No options selected.
304
305@item MHD_USE_DEBUG
306@cindex debugging
307Run in debug mode. If this flag is used, the library should print error
308messages and warnings to stderr. Note that for this
309run-time option to have any effect, MHD needs to be
310compiled with messages enabled. This is done by default except you ran
311configure with the @code{--disable-messages} flag set.
312
313@item MHD_USE_SSL
314Run in https mode (this option may not work with all threading modes yet).
315
316@item MHD_USE_THREAD_PER_CONNECTION
317Run using one thread per connection.
318
319@item MHD_USE_SELECT_INTERNALLY
320Run using an internal thread doing @code{SELECT}.
321
322@item MHD_USE_IPv6
323@cindex IPv6
324Run using the IPv6 protocol (otherwise, MHD will just support IPv4).
325
326
327@item MHD_USE_PEDANTIC_CHECKS
328Be pedantic about the protocol (as opposed to as tolerant as possible).
329Specifically, at the moment, this flag causes MHD to reject HTTP
3301.1 connections without a @code{Host} header. This is required by the
331standard, but of course in violation of the ``be as liberal as possible
332in what you accept'' norm. It is recommended to turn this @strong{ON}
333if you are testing clients against MHD, and @strong{OFF} in
334production.
335
336@item MHD_USE_POLL
337@cindex FD_SETSIZE
338@cindex poll
339@cindex select
340Use poll instead of select. This allows sockets with descriptors
341@code{>= FD_SETSIZE}. This option only works in conjunction with
342@code{MHD_USE_THREAD_PER_CONNECTION} (at this point).
343
344@item MHD_SUPPRESS_DATE_NO_CLOCK
345@cindex date
346@cindex clock
347@cindex embedded systems
348Suppress (automatically) adding the 'Date:' header to HTTP responses.
349This option should ONLY be used on systems that do not have a clock
350and that DO provide other mechanisms for cache control. See also
351RFC 2616, section 14.18 (exception 3).
352
353
354@item MHD_USE_NO_LISTEN_SOCKET
355@cindex listen
356@cindex proxy
357@cindex embedded systems
358Run the HTTP server without any listen socket. This option only makes
359sense if @code{MHD_add_connection} is going to be used exclusively to
360connect HTTP clients to the HTTP server. This option is incompatible
361with using a thread pool; if it is used,
362@code{MHD_OPTION_THREAD_POOL_SIZE} is ignored.
363
364@end table
365@end deftp
366
367
368@deftp {Enumeration} MHD_OPTION
369MHD options. Passed in the varargs portion of
370@code{MHD_start_daemon()}.
371
372@table @code
373@item MHD_OPTION_END
374No more options / last option. This is used to terminate the VARARGs
375list.
376
377@item MHD_OPTION_CONNECTION_MEMORY_LIMIT
378@cindex memory, limiting memory utilization
379Maximum memory size per connection (followed by a @code{size_t}). The
380default is 32 kB (32*1024 bytes) as defined by the internal constant
381@code{MHD_POOL_SIZE_DEFAULT}.
382
383@item MHD_OPTION_CONNECTION_LIMIT
384@cindex connection, limiting number of connections
385Maximum number of concurrent connections to accept (followed by an
386@code{unsigned int}). The default is @code{FD_SETSIZE - 4} (the
387maximum number of file descriptors supported by @code{select} minus
388four for @code{stdin}, @code{stdout}, @code{stderr} and the server
389socket). In other words, the default is as large as possible.
390
391Note that if you set a low connection limit, you can easily get into
392trouble with browsers doing request pipelining. For example, if your
393connection limit is ``1'', a browser may open a first connection to
394access your ``index.html'' file, keep it open but use a second
395connection to retrieve CSS files, images and the like. In fact, modern
396browsers are typically by default configured for up to 15 parallel
397connections to a single server. If this happens, MHD will refuse to
398even accept the second connection until the first connection is
399closed --- which does not happen until timeout. As a result, the
400browser will fail to render the page and seem to hang. If you expect
401your server to operate close to the connection limit, you should
402first consider using a lower timeout value and also possibly add
403a ``Connection: close'' header to your response to ensure that
404request pipelining is not used and connections are closed immediately
405after the request has completed:
406@example
407MHD_add_response_header (response,
408 MHD_HTTP_HEADER_CONNECTION,
409 "close");
410@end example
411
412@item MHD_OPTION_CONNECTION_TIMEOUT
413@cindex timeout
414After how many seconds of inactivity should a connection automatically
415be timed out? (followed by an @code{unsigned int}; use zero for no
416timeout). The default is zero (no timeout).
417
418@item MHD_OPTION_NOTIFY_COMPLETED
419Register a function that should be called whenever a request has been
420completed (this can be used for application-specific clean up).
421Requests that have never been presented to the application (via
422@code{MHD_AccessHandlerCallback()}) will not result in
423notifications.
424
425This option should be followed by @strong{TWO} pointers. First a
426pointer to a function of type @code{MHD_RequestCompletedCallback()}
427and second a pointer to a closure to pass to the request completed
428callback. The second pointer maybe @code{NULL}.
429
430
431@item MHD_OPTION_PER_IP_CONNECTION_LIMIT
432Limit on the number of (concurrent) connections made to the
433server from the same IP address. Can be used to prevent one
434IP from taking over all of the allowed connections. If the
435same IP tries to establish more than the specified number of
436connections, they will be immediately rejected. The option
437should be followed by an @code{unsigned int}. The default is
438zero, which means no limit on the number of connections
439from the same IP address.
440
441@item MHD_OPTION_SOCK_ADDR
442@cindex bind, restricting bind
443Bind daemon to the supplied socket address. This option should be followed by a
444@code{struct sockaddr *}. If @code{MHD_USE_IPv6} is specified,
445the @code{struct sockaddr*} should point to a @code{struct sockaddr_in6},
446otherwise to a @code{struct sockaddr_in}. If this option is not specified,
447the daemon will listen to incoming connections from anywhere. If you use this
448option, the 'port' argument from @code{MHD_start_daemon} is ignored and the port
449from the given @code{struct sockaddr *} will be used instead.
450
451@item MHD_OPTION_URI_LOG_CALLBACK
452@cindex debugging
453@cindex logging
454@cindex query string
455Specify a function that should be called before parsing the URI from
456the client. The specified callback function can be used for processing
457the URI (including the options) before it is parsed. The URI after
458parsing will no longer contain the options, which maybe inconvenient for
459logging. This option should be followed by two arguments, the first
460one must be of the form
461@example
462 void * my_logger(void * cls, const char * uri)
463@end example
464where the return value will be passed as
465@code{*con_cls} in calls to the @code{MHD_AccessHandlerCallback}
466when this request is processed later; returning a
467value of @code{NULL} has no special significance; (however,
468note that if you return non-@code{NULL}, you can no longer
469rely on the first call to the access handler having
470@code{NULL == *con_cls} on entry)
471@code{cls} will be set to the second argument following
472MHD_OPTION_URI_LOG_CALLBACK. Finally, @code{uri} will
473be the 0-terminated URI of the request.
474
475@item MHD_OPTION_HTTPS_MEM_KEY
476@cindex SSL
477@cindex TLS
478Memory pointer to the private key to be used by the
479HTTPS daemon. This option should be followed by an
480"const char*" argument.
481This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_CERT'.
482
483@item MHD_OPTION_HTTPS_MEM_CERT
484@cindex SSL
485@cindex TLS
486Memory pointer to the certificate to be used by the
487HTTPS daemon. This option should be followed by an
488"const char*" argument.
489This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_KEY'.
490
491@item MHD_OPTION_HTTPS_MEM_TRUST
492@cindex SSL
493@cindex TLS
494Memory pointer to the CA certificate to be used by the
495HTTPS daemon to authenticate and trust clients certificates.
496This option should be followed by an "const char*" argument.
497The presence of this option activates the request of certificate
498to the client. The request to the client is marked optional, and
499it is the responsibility of the server to check the presence
500of the certificate if needed.
501Note that most browsers will only present a client certificate
502only if they have one matching the specified CA, not sending
503any certificate otherwise.
504
505@item MHD_OPTION_HTTPS_CRED_TYPE
506@cindex SSL
507@cindex TLS
508Daemon credentials type. Either certificate or anonymous,
509this option should be followed by one of the values listed in
510"enum gnutls_credentials_type_t".
511
512@item MHD_OPTION_HTTPS_PRIORITIES
513@cindex SSL
514@cindex TLS
515@cindex cipher
516SSL/TLS protocol version and ciphers.
517This option must be followed by an "const char *" argument
518specifying the SSL/TLS protocol versions and ciphers that
519are acceptable for the application. The string is passed
520unchanged to gnutls_priority_init. If this option is not
521specified, ``NORMAL'' is used.
522
523@item MHD_OPTION_DIGEST_AUTH_RANDOM
524@cindex digest auth
525@cindex random
526Digest Authentication nonce's seed.
527
528This option should be followed by two arguments. First an integer of
529type "size_t" which specifies the size of the buffer pointed to by the
530second argument in bytes. Note that the application must ensure that
531the buffer of the second argument remains allocated and unmodified
532while the daemon is running. For security, you SHOULD provide a fresh
533random nonce when using MHD with Digest Authentication.
534
535@item MHD_OPTION_NONCE_NC_SIZE
536@cindex digest auth
537@cindex replay attack
538
539Size of an array of nonce and nonce counter map. This option must be
540followed by an "unsigned int" argument that have the size (number of
541elements) of a map of a nonce and a nonce-counter. If this option
542is not specified, a default value of 4 will be used (which might be
543too small for servers handling many requests). If you do not use
544digest authentication at all, you can specify a value of zero to
545save some memory.
546
547You should calculate the value of NC_SIZE based on the number of
548connections per second multiplied by your expected session duration
549plus a factor of about two for hash table collisions. For example, if
550you expect 100 digest-authenticated connections per second and the
551average user to stay on your site for 5 minutes, then you likely need
552a value of about 60000. On the other hand, if you can only expect
553only 10 digest-authenticated connections per second, tolerate browsers
554getting a fresh nonce for each request and expect a HTTP request
555latency of 250 ms, then a value of about 5 should be fine.
556
557
558@item MHD_OPTION_LISTEN_SOCKET
559@cindex systemd
560Listen socket to use. Pass a listen socket for MHD to use
561(systemd-style). If this option is used, MHD will not open its own
562listen socket(s). The argument passed must be of type "int" and refer
563to an existing socket that has been bound to a port and is listening.
564
565@item MHD_OPTION_EXTERNAL_LOGGER
566@cindex logging
567Use the given function for logging error messages.
568This option must be followed by two arguments; the
569first must be a pointer to a function
570of type 'void fun(void * arg, const char * fmt, va_list ap)'
571and the second a pointer of type 'void*' which will
572be passed as the "arg" argument to "fun".
573
574Note that MHD will not generate any log messages without
575the MHD_USE_DEBUG flag set and if MHD was compiled
576with the "--disable-messages" flag.
577
578@item MHD_OPTION_THREAD_POOL_SIZE
579@cindex performance
580Number (unsigned int) of threads in thread pool. Enable
581thread pooling by setting this value to to something
582greater than 1. Currently, thread model must be
583MHD_USE_SELECT_INTERNALLY if thread pooling is enabled
584(MHD_start_daemon returns @code{NULL} for an unsupported thread
585model).
586
587@item MHD_OPTION_ARRAY
588@cindex options
589@cindex foreign-function interface
590This option can be used for initializing MHD using options from an
591array. A common use for this is writing an FFI for MHD. The actual
592options given are in an array of 'struct MHD_OptionItem', so this
593option requires a single argument of type 'struct MHD_OptionItem'.
594The array must be terminated with an entry @code{MHD_OPTION_END}.
595
596An example for code using MHD_OPTION_ARRAY is:
597@example
598struct MHD_OptionItem ops[] = @{
599 @{ MHD_OPTION_CONNECTION_LIMIT, 100, NULL @},
600 @{ MHD_OPTION_CONNECTION_TIMEOUT, 10, NULL @},
601 @{ MHD_OPTION_END, 0, NULL @}
602@};
603d = MHD_start_daemon(0, 8080, NULL, NULL, dh, NULL,
604 MHD_OPTION_ARRAY, ops,
605 MHD_OPTION_END);
606@end example
607For options that expect a single pointer argument, the
608second member of the @code{struct MHD_OptionItem} is ignored.
609For options that expect two pointer arguments, the first
610argument must be cast to @code{intptr_t}.
611
612@item MHD_OPTION_UNESCAPE_CALLBACK
613@cindex internationalization
614@cindex escaping
615
616Specify a function that should be called for unescaping escape
617sequences in URIs and URI arguments. Note that this function will NOT
618be used by the MHD_PostProcessor. If this option is not specified,
619the default method will be used which decodes escape sequences of the
620form "%HH". This option should be followed by two arguments, the
621first one must be of the form
622
623@example
624 size_t my_unescaper(void * cls, struct MHD_Connection *c, char *s)
625@end example
626
627where the return value must be @code{strlen(s)} and @code{s} should be
628updated. Note that the unescape function must not lengthen @code{s}
629(the result must be shorter than the input and still be 0-terminated).
630@code{cls} will be set to the second argument following
631MHD_OPTION_UNESCAPE_CALLBACK.
632
633
634@item MHD_OPTION_THREAD_STACK_SIZE
635@cindex stack
636@cindex thread
637@cindex pthread
638@cindex embedded systems
639Maximum stack size for threads created by MHD. This option must be
640followed by a @code{size_t}). Not specifying this option or using
641a value of zero means using the system default (which is likely to
642differ based on your platform).
643
644@end table
645@end deftp
646
647
648@deftp {C Struct} MHD_OptionItem
649Entry in an MHD_OPTION_ARRAY. See the @code{MHD_OPTION_ARRAY} option
650argument for its use.
651
652The @code{option} member is used to specify which option is specified
653in the array. The other members specify the respective argument.
654
655Note that for options taking only a single pointer, the
656@code{ptr_value} member should be set. For options taking two pointer
657arguments, the first pointer must be cast to @code{intptr_t} and both
658the @code{value} and the @code{ptr_value} members should be used to
659pass the two pointers.
660@end deftp
661
662
663@deftp {Enumeration} MHD_ValueKind
664The @code{MHD_ValueKind} specifies the source of the key-value pairs in
665the HTTP protocol.
666
667@table @code
668@item MHD_RESPONSE_HEADER_KIND
669Response header.
670
671@item MHD_HEADER_KIND
672HTTP header.
673
674@item MHD_COOKIE_KIND
675@cindex cookie
676Cookies. Note that the original HTTP header containing the cookie(s)
677will still be available and intact.
678
679@item MHD_POSTDATA_KIND
680@cindex POST method
681@code{POST} data. This is available only if a content encoding
682supported by MHD is used (currently only @acronym{URL} encoding), and
683only if the posted content fits within the available memory pool. Note
684that in that case, the upload data given to the
685@code{MHD_AccessHandlerCallback()} will be empty (since it has
686already been processed).
687
688@item MHD_GET_ARGUMENT_KIND
689@code{GET} (URI) arguments.
690
691@item MHD_FOOTER_KIND
692HTTP footer (only for http 1.1 chunked encodings).
693
694@end table
695@end deftp
696
697
698@deftp {Enumeration} MHD_RequestTerminationCode
699The @code{MHD_RequestTerminationCode} specifies reasons why a request
700has been terminated (or completed).
701
702@table @code
703@item MHD_REQUEST_TERMINATED_COMPLETED_OK
704We finished sending the response.
705
706@item MHD_REQUEST_TERMINATED_WITH_ERROR
707Error handling the connection (resources exhausted, other side closed
708connection, application error accepting request, etc.)
709
710@item MHD_REQUEST_TERMINATED_TIMEOUT_REACHED
711No activity on the connection for the number of seconds specified using
712@code{MHD_OPTION_CONNECTION_TIMEOUT}.
713
714@item MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN
715We had to close the session since MHD was being shut down.
716@end table
717@end deftp
718
719
720@deftp {Enumeration} MHD_ResponseMemoryMode
721The @code{MHD_ResponeMemoryMode} specifies how MHD should treat
722the memory buffer given for the response in
723@code{MHD_create_response_from_buffer}.
724
725@table @code
726@item MHD_RESPMEM_PERSISTENT
727Buffer is a persistent (static/global) buffer that won't change
728for at least the lifetime of the response, MHD should just use
729it, not free it, not copy it, just keep an alias to it.
730
731@item MHD_RESPMEM_MUST_FREE
732Buffer is heap-allocated with @code{malloc} (or equivalent) and
733should be freed by MHD after processing the response has
734concluded (response reference counter reaches zero).
735
736@item MHD_RESPMEM_MUST_COPY
737Buffer is in transient memory, but not on the heap (for example,
738on the stack or non-malloc allocated) and only valid during the
739call to @code{MHD_create_response_from_buffer}. MHD must make its
740own private copy of the data for processing.
741
742@end table
743@end deftp
744
745
746
747
748@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
749
750@c ------------------------------------------------------------
751@node microhttpd-struct
752@chapter Structures type definition
753
754
755@deftp {C Struct} MHD_Daemon
756Handle for the daemon (listening on a socket for HTTP traffic).
757@end deftp
758
759
760@deftp {C Struct} MHD_Connection
761Handle for a connection / HTTP request. With HTTP/1.1, multiple
762requests can be run over the same connection. However, MHD will only
763show one request per TCP connection to the client at any given time.
764@end deftp
765
766
767@deftp {C Struct} MHD_Response
768Handle for a response.
769@end deftp
770
771
772@deftp {C Struct} MHD_PostProcessor
773@cindex POST method
774Handle for @code{POST} processing.
775@end deftp
776
777
778@deftp {C Union} MHD_ConnectionInfo
779Information about a connection.
780@end deftp
781
782
783@deftp {C Union} MHD_DaemonInfo
784Information about an MHD daemon.
785@end deftp
786
787
788@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
789
790@c ------------------------------------------------------------
791@node microhttpd-cb
792@chapter Callback functions definition
793
794
795@deftypefn {Function Pointer} int {*MHD_AcceptPolicyCallback} (void *cls, const struct sockaddr * addr, socklen_t addrlen)
796Invoked in the context of a connection to allow or deny a client to
797connect. This callback return @code{MHD_YES} if connection is allowed,
798@code{MHD_NO} if not.
799
800@table @var
801@item cls
802custom value selected at callback registration time;
803@item addr
804address information from the client;
805@item addrlen
806length of the address information.
807@end table
808@end deftypefn
809
810
811@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)
812Invoked in the context of a connection to answer a request from the
813client. This callback must call MHD functions (example: the
814@code{MHD_Response} ones) to provide content to give back to the client
815and return an HTTP status code (i.e. @code{200} for OK, @code{404},
816etc.).
817
818@ref{microhttpd-post}, for details on how to code this callback.
819
820Must return @code{MHD_YES} if the connection was handled successfully,
821@code{MHD_NO} if the socket must be closed due to a serious error while
822handling the request
823
824@table @var
825@item cls
826custom value selected at callback registration time;
827
828@item url
829the URL requested by the client;
830
831@item method
832the HTTP method used by the client (@code{GET}, @code{PUT},
833@code{DELETE}, @code{POST}, etc.);
834
835@item version
836the HTTP version string (i.e. @code{HTTP/1.1});
837
838@item upload_data
839the data being uploaded (excluding headers):
840@cindex POST method
841@cindex PUT method
842
843@itemize
844@item
845for a @code{POST} that fits into memory and that is encoded with a
846supported encoding, the @code{POST} data will @strong{NOT} be given in
847@var{upload_data} and is instead available as part of
848@code{MHD_get_connection_values()};
849
850@item
851very large @code{POST} data @strong{will} be made available
852incrementally in @var{upload_data};
853@end itemize
854
855@item upload_data_size
856set initially to the size of the @var{upload_data} provided; this
857callback must update this value to the number of bytes @strong{NOT}
858processed; unless external select is used, the callback maybe
859required to process at least some data. If the callback fails to
860process data in multi-threaded or internal-select mode and if the
861read-buffer is already at the maximum size that MHD is willing to
862use for reading (about half of the maximum amount of memory allowed
863for the connection), then MHD will abort handling the connection
864and return an internal server error to the client. In order to
865avoid this, clients must be able to process upload data incrementally
866and reduce the value of @code{upload_data_size}.
867
868@item con_cls
869reference to a pointer, initially set to @code{NULL}, that this callback can
870set to some address and that will be preserved by MHD for future
871calls for this request;
872
873since the access handler may be called many times (i.e., for a
874@code{PUT}/@code{POST} operation with plenty of upload data) this allows
875the application to easily associate some request-specific state;
876
877if necessary, this state can be cleaned up in the global
878@code{MHD_RequestCompletedCallback} (which can be set with the
879@code{MHD_OPTION_NOTIFY_COMPLETED}).
880@end table
881@end deftypefn
882
883
884@deftypefn {Function Pointer} void {*MHD_RequestCompletedCallback} (void *cls, struct MHD_Connectionconnection, void **con_cls, enum MHD_RequestTerminationCode toe)
885Signature of the callback used by MHD to notify the application about
886completed requests.
887
888@table @var
889@item cls
890custom value selected at callback registration time;
891
892@item connection
893connection handle;
894
895@item con_cls
896value as set by the last call to the
897@code{MHD_AccessHandlerCallback};
898
899@item toe
900reason for request termination see @code{MHD_OPTION_NOTIFY_COMPLETED}.
901@end table
902@end deftypefn
903
904
905@deftypefn {Function Pointer} int {*MHD_KeyValueIterator} (void *cls, enum MHD_ValueKind kind, const char *key, const char *value)
906Iterator over key-value pairs. This iterator can be used to iterate
907over all of the cookies, headers, or @code{POST}-data fields of a
908request, and also to iterate over the headers that have been added to a
909response.
910
911Return @code{MHD_YES} to continue iterating, @code{MHD_NO} to abort the
912iteration.
913@end deftypefn
914
915
916@deftypefn {Function Pointer} int {*MHD_ContentReaderCallback} (void *cls, uint64_t pos, char *buf, size_t max)
917Callback used by MHD in order to obtain content. The callback has to
918copy at most @var{max} bytes of content into @var{buf}. The total
919number of bytes that has been placed into @var{buf} should be returned.
920
921Note that returning zero will cause MHD to try again, either
922``immediately'' if in multi-threaded mode (in which case the callback
923may want to do blocking operations to avoid busy waiting) or in the
924next round if @code{MHD_run} is used. Returning zero for a daemon
925that runs in internal @code{select}-mode is an error (since it
926would result in busy waiting) and cause the program to be aborted
927(@code{abort()}).
928
929While usually the callback simply returns the number of bytes written
930into @var{buf}, there are two special return value:
931
932@code{MHD_CONTENT_READER_END_OF_STREAM} (-1) should be returned
933for the regular end of transmission (with chunked encoding, MHD will then
934terminate the chunk and send any HTTP footers that might be
935present; without chunked encoding and given an unknown
936response size, MHD will simply close the connection; note
937that while returning @code{MHD_CONTENT_READER_END_OF_STREAM} is not technically
938legal if a response size was specified, MHD accepts this
939and treats it just as @code{MHD_CONTENT_READER_END_WITH_ERROR}.
940
941@code{MHD_CONTENT_READER_END_WITH_ERROR} (-2) is used to indicate a server
942error generating the response; this will cause MHD to simply
943close the connection immediately. If a response size was
944given or if chunked encoding is in use, this will indicate
945an error to the client. Note, however, that if the client
946does not know a response size and chunked encoding is not in
947use, then clients will not be able to tell the difference between
948@code{MHD_CONTENT_READER_END_WITH_ERROR} and
949@code{MHD_CONTENT_READER_END_OF_STREAM}.
950This is not a limitation of MHD but rather of the HTTP protocol.
951
952@table @var
953@item cls
954custom value selected at callback registration time;
955
956@item pos
957position in the datastream to access; note that if an
958@code{MHD_Response} object is re-used, it is possible for the same
959content reader to be queried multiple times for the same data; however,
960if an @code{MHD_Response} is not re-used, MHD guarantees that
961@var{pos} will be the sum of all non-negative return values obtained
962from the content reader so far.
963@end table
964
965Return @code{-1} on error (MHD will no longer try to read content and
966instead close the connection with the client).
967@end deftypefn
968
969
970@deftypefn {Function Pointer} void {*MHD_ContentReaderFreeCallback} (void *cls)
971This method is called by MHD if we are done with a content reader.
972It should be used to free resources associated with the content reader.
973@end deftypefn
974
975
976@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)
977Iterator over key-value pairs where the value maybe made available in
978increments and/or may not be zero-terminated. Used for processing
979@code{POST} data.
980
981@table @var
982@item cls
983custom value selected at callback registration time;
984
985@item kind
986type of the value;
987
988@item key
989zero-terminated key for the value;
990
991@item filename
992name of the uploaded file, @code{NULL} if not known;
993
994@item content_type
995mime-type of the data, @code{NULL} if not known;
996
997@item transfer_encoding
998encoding of the data, @code{NULL} if not known;
999
1000@item data
1001pointer to size bytes of data at the specified offset;
1002
1003@item off
1004offset of data in the overall value;
1005
1006@item size
1007number of bytes in data available.
1008@end table
1009
1010Return @code{MHD_YES} to continue iterating, @code{MHD_NO} to abort the
1011iteration.
1012@end deftypefn
1013
1014
1015@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1016
1017@c ------------------------------------------------------------
1018@node microhttpd-init
1019@chapter Starting and stopping the server
1020
1021@deftypefun {void} MHD_set_panic_func (MHD_PanicCallback cb, void *cls)
1022Set a handler for fatal errors.
1023
1024@table @var
1025@item cb
1026function to call if MHD encounters a fatal internal error. If no handler was set explicitly, MHD will call @code{abort}.
1027
1028@item cls
1029closure 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})
1030@end table
1031@end deftypefun
1032
1033@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, ...)
1034Start a webserver on the given port.
1035
1036@table @var
1037@item flags
1038OR-ed combination of @code{MHD_FLAG} values;
1039
1040@item port
1041port to bind to;
1042
1043@item apc
1044callback to call to check which clients will be allowed to connect; you
1045can pass @code{NULL} in which case connections from any @acronym{IP} will be
1046accepted;
1047
1048@item apc_cls
1049extra argument to @var{apc};
1050
1051@item dh
1052default handler for all URIs;
1053
1054@item dh_cls
1055extra argument to @var{dh}.
1056@end table
1057
1058Additional arguments are a list of options (type-value pairs,
1059terminated with @code{MHD_OPTION_END}). It is mandatory to use
1060@code{MHD_OPTION_END} as last argument, even when there are no
1061additional arguments.
1062
1063Return @code{NULL} on error, handle to daemon on success.
1064@end deftypefun
1065
1066
1067@deftypefun void MHD_stop_daemon (struct MHD_Daemon *daemon)
1068Shutdown an HTTP daemon.
1069@end deftypefun
1070
1071
1072@deftypefun int MHD_run (struct MHD_Daemon *daemon)
1073Run webserver operations (without blocking unless in client callbacks).
1074This method should be called by clients in combination with
1075@code{MHD_get_fdset()} if the client-controlled @code{select}-method is used.
1076
1077Return @code{MHD_YES} on success, @code{MHD_NO} if this daemon was not
1078started with the right options for this call.
1079@end deftypefun
1080
1081
1082@deftypefun void MHD_add_connection (struct MHD_Daemon *daemon, int client_socket, const struct sockaddr *addr, socklen_t addrlen)
1083Add another client connection to the set of connections
1084managed by MHD. This API is usually not needed (since
1085MHD will accept inbound connections on the server socket).
1086Use this API in special cases, for example if your HTTP
1087server is behind NAT and needs to connect out to the
1088HTTP client.
1089
1090The given client socket will be managed (and closed!) by MHD after
1091this call and must no longer be used directly by the application
1092afterwards.
1093
1094@table @var
1095@item daemon
1096daemon that manages the connection
1097@item client_socket
1098socket to manage (MHD will expect to receive an HTTP request from this socket next).
1099@item addr
1100IP address of the client
1101@item addrlen
1102number of bytes in addr
1103@end table
1104
1105This function will return @code{MHD_YES} on success,
1106@code{MHD_NO} if this daemon could
1107not handle the connection (i.e. malloc failed, etc).
1108The socket will be closed in any case.
1109@end deftypefun
1110
1111
1112@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1113
1114@c -----------------------------------------------------------
1115@node microhttpd-inspect
1116@chapter Implementing external @code{select}
1117
1118
1119@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)
1120Obtain the @code{select()} sets for this daemon. The daemon's socket
1121is added to @var{read_fd_set}. The list of currently existent
1122connections is scanned and their file descriptors added to the correct
1123set.
1124
1125After the call completed successfully: the variable referenced by
1126@var{max_fd} references the file descriptor with highest integer
1127identifier. The variable must be set to zero before invoking this
1128function.
1129
1130Return @code{MHD_YES} on success, @code{MHD_NO} if: the arguments are
1131invalid (example: @code{NULL} pointers); this daemon was not started with
1132the right options for this call.
1133@end deftypefun
1134
1135
1136@deftypefun int MHD_get_timeout (struct MHD_Daemon *daemon, unsigned long long *timeout)
1137@cindex timeout
1138Obtain timeout value for select for this daemon (only needed if
1139connection timeout is used). The returned value is how long
1140@code{select} should at most block, not the timeout value set for
1141connections. This function must not be called if the
1142@code{MHD_USE_THREAD_PER_CONNECTION} mode is in use (since then it
1143is not meaningful to ask for a timeout, after all, there is
1144concurrenct activity). The function must also not be called by
1145user-code if @code{MHD_USE_INTERNAL_SELECT} is in use. In the latter
1146case, the behavior is undefined.
1147
1148@table @var
1149@cindex timeout
1150set to the timeout (in milliseconds).
1151@end table
1152
1153Return @code{MHD_YES} on success, @code{MHD_NO} if timeouts are not used
1154(or no connections exist that would necessiate the use of a timeout
1155right now).
1156@end deftypefun
1157
1158
1159@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1160
1161@c -----------------------------------------------------------
1162@node microhttpd-requests
1163@chapter Handling requests
1164
1165
1166@deftypefun int MHD_get_connection_values (struct MHD_Connection *connection, enum MHD_ValueKind kind, MHD_KeyValueIterator iterator, void *iterator_cls)
1167Get all the headers matching @var{kind} from the request.
1168
1169The @var{iterator} callback is invoked once for each header, with
1170@var{iterator_cls} as first argument. After version 0.9.19, the
1171headers are iterated in the same order as they were received from
1172the network; previous versions iterated over the headers in reverse
1173order.
1174
1175@code{MHD_get_connection_values} returns the number of entries
1176iterated over; this can be less than the number of headers if, while
1177iterating, @var{iterator} returns @code{MHD_NO}.
1178
1179@var{iterator} can be @code{NULL}: in this case this function just counts
1180and returns the number of headers.
1181
1182In the case of @code{MHD_GET_ARGUMENT_KIND}, the @var{value} argument
1183will be @code{NULL} if the URL contained a key without an equals operator.
1184For example, for a HTTP request to the URL ``http://foo/bar?key'', the
1185@var{value} argument is @code{NULL}; in contrast, a HTTP request to the URL
1186``http://foo/bar?key='', the @var{value} argument is the empty string.
1187The normal case is that the URL contains ``http://foo/bar?key=value''
1188in which case @var{value} would be the string ``value'' and @var{key}
1189would contain the string ``key''.
1190@end deftypefun
1191
1192
1193@deftypefun int MHD_set_connection_value (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char * key, const char * value)
1194This function can be used to append an entry to
1195the list of HTTP headers of a connection (so that the
1196@code{MHD_get_connection_values function} will return
1197them -- and the MHD PostProcessor will also
1198see them). This maybe required in certain
1199situations (see Mantis #1399) where (broken)
1200HTTP implementations fail to supply values needed
1201by the post processor (or other parts of the
1202application).
1203
1204This function MUST only be called from within
1205the MHD_AccessHandlerCallback (otherwise, access
1206maybe improperly synchronized). Furthermore,
1207the client must guarantee that the key and
1208value arguments are 0-terminated strings that
1209are NOT freed until the connection is closed.
1210(The easiest way to do this is by passing only
1211arguments to permanently allocated strings.).
1212
1213@var{connection} is the connection for which
1214the entry for @var{key} of the given @var{kind}
1215should be set to the given @var{value}.
1216
1217The function returns @code{MHD_NO} if the operation
1218could not be performed due to insufficient memory
1219and @code{MHD_YES} on success.
1220@end deftypefun
1221
1222
1223@deftypefun {const char *} MHD_lookup_connection_value (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key)
1224Get a particular header value. If multiple values match the
1225@var{kind}, return one of them (the ``first'', whatever that means).
1226@var{key} must reference a zero-terminated ASCII-coded string
1227representing the header to look for: it is compared against the
1228headers using @code{strcasecmp()}, so case is ignored. A value of
1229@code{NULL} for @var{key} can be used to lookup 'trailing' values without a
1230key, for example if a URI is of the form
1231``http://example.com/?trailer'', a @var{key} of @code{NULL} can be used to
1232access ``tailer" The function returns @code{NULL} if no matching item
1233was found.
1234@end deftypefun
1235
1236
1237@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1238
1239@c ------------------------------------------------------------
1240@node microhttpd-responses
1241@chapter Building responses to requests
1242
1243
1244@noindent
1245Response objects handling by MHD is asynchronous with respect to the
1246application execution flow. Instances of the @code{MHD_Response}
1247structure are not associated to a daemon and neither to a client
1248connection: they are managed with reference counting.
1249
1250In the simplest case: we allocate a new @code{MHD_Response} structure
1251for each response, we use it once and finally we destroy it.
1252
1253MHD allows more efficient resources usages.
1254
1255Example: we allocate a new @code{MHD_Response} structure for each
1256response @strong{kind}, we use it every time we have to give that
1257response and we finally destroy it only when the daemon shuts down.
1258
1259@menu
1260* microhttpd-response enqueue:: Enqueuing a response.
1261* microhttpd-response create:: Creating a response object.
1262* microhttpd-response headers:: Adding headers to a response.
1263* microhttpd-response inspect:: Inspecting a response object.
1264@end menu
1265
1266@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1267
1268@c ------------------------------------------------------------
1269@node microhttpd-response enqueue
1270@section Enqueuing a response
1271
1272
1273@deftypefun int MHD_queue_response (struct MHD_Connection *connection, unsigned int status_code, struct MHD_Response *response)
1274Queue a response to be transmitted to the client as soon as possible
1275but only after MHD_AccessHandlerCallback returns. This function
1276checks that it is legal to queue a response at this time for the
1277given connection. It also increments the internal reference
1278counter for the response object (the counter will be decremented
1279automatically once the response has been transmitted).
1280
1281@table @var
1282@item connection
1283the connection identifying the client;
1284
1285@item status_code
1286HTTP status code (i.e. @code{200} for OK);
1287
1288@item response
1289response to transmit.
1290@end table
1291
1292Return @code{MHD_YES} on success or if message has been queued. Return
1293@code{MHD_NO}: if arguments are invalid (example: @code{NULL} pointer); on
1294error (i.e. reply already sent).
1295@end deftypefun
1296
1297
1298@deftypefun void MHD_destroy_response (struct MHD_Response *response)
1299Destroy a response object and associated resources (decrement the
1300reference counter). Note that MHD may keep some of the resources
1301around if the response is still in the queue for some clients, so the
1302memory may not necessarily be freed immediately.
1303@end deftypefun
1304
1305
1306An explanation of reference counting@footnote{Note to readers acquainted
1307to the Tcl API: reference counting on @code{MHD_Connection}
1308structures is handled in the same way as Tcl handles @code{Tcl_Obj}
1309structures through @code{Tcl_IncrRefCount()} and
1310@code{Tcl_DecrRefCount()}.}:
1311
1312@enumerate
1313@item
1314a @code{MHD_Response} object is allocated:
1315
1316@example
1317struct MHD_Response * response = MHD_create_response_from_buffer(...);
1318/* here: reference counter = 1 */
1319@end example
1320
1321@item
1322the @code{MHD_Response} object is enqueued in a @code{MHD_Connection}:
1323
1324@example
1325MHD_queue_response(connection, , response);
1326/* here: reference counter = 2 */
1327@end example
1328
1329@item
1330the creator of the response object discharges responsibility for it:
1331
1332@example
1333MHD_destroy_response(response);
1334/* here: reference counter = 1 */
1335@end example
1336
1337@item
1338the daemon handles the connection sending the response's data to the
1339client then decrements the reference counter by calling
1340@code{MHD_destroy_response()}: the counter's value drops to zero and
1341the @code{MHD_Response} object is released.
1342@end enumerate
1343
1344
1345@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1346
1347@c ------------------------------------------------------------
1348@node microhttpd-response create
1349@section Creating a response object
1350
1351
1352@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)
1353Create a response object. The response object can be extended with
1354header information and then it can be used any number of times.
1355
1356@table @var
1357@item size
1358size of the data portion of the response, @code{-1} for unknown;
1359
1360@item block_size
1361preferred block size for querying @var{crc} (advisory only, MHD may
1362still call @var{crc} using smaller chunks); this is essentially the
1363buffer size used for @acronym{IO}, clients should pick a value that is
1364appropriate for @acronym{IO} and memory performance requirements;
1365
1366@item crc
1367callback to use to obtain response data;
1368
1369@item crc_cls
1370extra argument to @var{crc};
1371
1372@item crfc
1373callback to call to free @var{crc_cls} resources.
1374@end table
1375
1376Return @code{NULL} on error (i.e. invalid arguments, out of memory).
1377@end deftypefun
1378
1379
1380
1381@deftypefun {struct MHD_Response *} MHD_create_response_from_fd (uint64_t size, int fd)
1382Create a response object. The response object can be extended with
1383header information and then it can be used any number of times.
1384
1385@table @var
1386@item size
1387size of the data portion of the response (should be smaller or equal to the
1388size of the file)
1389
1390@item fd
1391file descriptor referring to a file on disk with the data; will be
1392closed when response is destroyed; note that 'fd' must be an actual
1393file descriptor (not a pipe or socket) since MHD might use 'sendfile'
1394or 'seek' on it. The descriptor should be in blocking-IO mode.
1395@end table
1396
1397Return @code{NULL} on error (i.e. invalid arguments, out of memory).
1398@end deftypefun
1399
1400
1401@deftypefun {struct MHD_Response *} MHD_create_response_from_fd_at_offset (uint64_t size, int fd, off_t offset)
1402Create a response object. The response object can be extended with
1403header information and then it can be used any number of times.
1404Note that you need to be a bit careful about @code{off_t} when
1405writing this code. Depending on your platform, MHD is likely
1406to have been compiled with support for 64-bit files. When you
1407compile your own application, you must make sure that @code{off_t}
1408is also a 64-bit value. If not, your compiler may pass a 32-bit
1409value as @code{off_t}, which will result in 32-bits of garbage.
1410
1411If you use the autotools, use the @code{AC_SYS_LARGEFILE} autoconf
1412macro and make sure to include the generated @file{config.h} file
1413before @file{microhttpd.h} to avoid problems. If you do not have a
1414build system and only want to run on a GNU/Linux system, you could
1415also use
1416@verbatim
1417#define _FILE_OFFSET_BITS 64
1418#include <sys/types.h>
1419#include <sys/stat.h>
1420#include <fcntl.h>
1421#include <microhttpd.h>
1422@end verbatim
1423to ensure 64-bit @code{off_t}. Note that if your operating system
1424does not support 64-bit files, MHD will be compiled with a 32-bit
1425@code{off_t} (in which case the above would be wrong).
1426
1427@table @var
1428@item size
1429size of the data portion of the response (number of bytes to transmit from the
1430file starting at offset).
1431
1432@item fd
1433file descriptor referring to a file on disk with the data; will be
1434closed when response is destroyed; note that 'fd' must be an actual
1435file descriptor (not a pipe or socket) since MHD might use 'sendfile'
1436or 'seek' on it. The descriptor should be in blocking-IO mode.
1437
1438@item offset
1439offset to start reading from in the file
1440@end table
1441
1442Return @code{NULL} on error (i.e. invalid arguments, out of memory).
1443@end deftypefun
1444
1445
1446@deftypefun {struct MHD_Response *} MHD_create_response_from_buffer (size_t size, void *data, enum MHD_ResponseMemoryMode mode)
1447Create a response object. The response object can be extended with
1448header information and then it can be used any number of times.
1449
1450@table @var
1451@item size
1452size of the data portion of the response;
1453
1454@item buffer
1455the data itself;
1456
1457@item mode
1458memory management options for buffer; use
1459MHD_RESPMEM_PERSISTENT if the buffer is static/global memory,
1460use MHD_RESPMEM_MUST_FREE if the buffer is heap-allocated and
1461should be freed by MHD and MHD_RESPMEM_MUST_COPY if the
1462buffer is in transient memory (i.e. on the stack) and must
1463be copied by MHD;
1464@end table
1465
1466Return @code{NULL} on error (i.e. invalid arguments, out of memory).
1467@end deftypefun
1468
1469
1470@deftypefun {struct MHD_Response *} MHD_create_response_from_data (size_t size, void *data, int must_free, int must_copy)
1471Create a response object. The response object can be extended with
1472header information and then it can be used any number of times.
1473This function is deprecated, use @code{MHD_create_response_from_buffer} instead.
1474
1475@table @var
1476@item size
1477size of the data portion of the response;
1478
1479@item data
1480the data itself;
1481
1482@item must_free
1483if true: MHD should free data when done;
1484
1485@item must_copy
1486if true: MHD allocates a block of memory and use it to make a copy of
1487@var{data} embedded in the returned @code{MHD_Response} structure;
1488handling of the embedded memory is responsibility of MHD; @var{data}
1489can be released anytime after this call returns.
1490@end table
1491
1492Return @code{NULL} on error (i.e. invalid arguments, out of memory).
1493@end deftypefun
1494
1495
1496Example: create a response from a statically allocated string:
1497
1498@example
1499const char * data = "<html><body><p>Error!</p></body></html>";
1500
1501struct MHD_Connection * connection = ...;
1502struct MHD_Response * response;
1503
1504response = MHD_create_response_from_buffer (strlen(data), data,
1505 MHD_RESPMEM_PERSISTENT);
1506MHD_queue_response(connection, 404, response);
1507MHD_destroy_response(response);
1508@end example
1509
1510
1511
1512@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1513
1514@c ------------------------------------------------------------
1515@node microhttpd-response headers
1516@section Adding headers to a response
1517
1518
1519@deftypefun int MHD_add_response_header (struct MHD_Response *response, const char *header, const char *content)
1520Add a header line to the response. The strings referenced by
1521@var{header} and @var{content} must be zero-terminated and they are
1522duplicated into memory blocks embedded in @var{response}.
1523
1524Notice that the strings must not hold newlines, carriage returns or tab
1525chars.
1526
1527Return @code{MHD_NO} on error (i.e. invalid header or content format or
1528memory allocation error).
1529@end deftypefun
1530
1531
1532@deftypefun int MHD_add_response_footer (struct MHD_Response *response, const char *footer, const char *content)
1533Add a footer line to the response. The strings referenced by
1534@var{footer} and @var{content} must be zero-terminated and they are
1535duplicated into memory blocks embedded in @var{response}.
1536
1537Notice that the strings must not hold newlines, carriage returns or tab
1538chars. You can add response footers at any time before signalling the
1539end of the response to MHD (not just before calling 'MHD_queue_response').
1540Footers are useful for adding cryptographic checksums to the reply or to
1541signal errors encountered during data generation. This call was introduced
1542in MHD 0.9.3.
1543
1544Return @code{MHD_NO} on error (i.e. invalid header or content format or
1545memory allocation error).
1546@end deftypefun
1547
1548
1549
1550@deftypefun int MHD_del_response_header (struct MHD_Response *response, const char *header, const char *content)
1551Delete a header (or footer) line from the response. Return @code{MHD_NO} on error
1552(arguments are invalid or no such header known).
1553@end deftypefun
1554
1555
1556@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1557
1558@c ------------------------------------------------------------
1559@node microhttpd-response inspect
1560@section Inspecting a response object
1561
1562
1563@deftypefun int MHD_get_response_headers (struct MHD_Response *response, MHD_KeyValueIterator iterator, void *iterator_cls)
1564Get all of the headers added to a response.
1565
1566Invoke the @var{iterator} callback for each header in the response,
1567using @var{iterator_cls} as first argument. Return number of entries
1568iterated over. @var{iterator} can be @code{NULL}: in this case the function
1569just counts headers.
1570
1571@var{iterator} should not modify the its key and value arguments, unless
1572we know what we are doing.
1573@end deftypefun
1574
1575
1576@deftypefun {const char *} MHD_get_response_header (struct MHD_Response *response, const char *key)
1577Find and return a pointer to the value of a particular header from the
1578response. @var{key} must reference a zero-terminated string
1579representing the header to look for. The search is case sensitive.
1580Return @code{NULL} if header does not exist or @var{key} is @code{NULL}.
1581
1582We should not modify the value, unless we know what we are doing.
1583@end deftypefun
1584
1585
1586@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1587
1588@c ------------------------------------------------------------
1589@node microhttpd-dauth
1590@chapter Utilizing Authentication
1591
1592@noindent
1593MHD support three types of client authentication.
1594
1595Basic authentication uses a simple authentication method based
1596on BASE64 algorithm. Username and password are exchanged in clear
1597between the client and the server, so this method must only be used
1598for non-sensitive content or when the session is protected with https.
1599When using basic authentication MHD will have access to the clear
1600password, possibly allowing to create a chained authentication
1601toward an external authentication server.
1602
1603Digest authentication uses a one-way authentication method based
1604on MD5 hash algorithm. Only the hash will transit over the network,
1605hence protecting the user password. The nonce will prevent replay
1606attacks. This method is appropriate for general use, especially
1607when https is not used to encrypt the session.
1608
1609Client certificate authentication uses a X.509 certificate from
1610the client. This is the strongest authentication mechanism but it
1611requires the use of HTTPS. Client certificate authentication can
1612be used simultaneously with Basic or Digest Authentication in order
1613to provide a two levels authentication (like for instance separate
1614machine and user authentication). A code example for using
1615client certificates is presented in the MHD tutorial.
1616
1617@menu
1618* microhttpd-dauth basic:: Using Basic Authentication.
1619* microhttpd-dauth digest:: Using Digest Authentication.
1620@end menu
1621
1622@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1623
1624@c ------------------------------------------------------------
1625@node microhttpd-dauth basic
1626@section Using Basic Authentication
1627
1628@deftypefun {char *} MHD_basic_auth_get_username_password (struct MHD_Connection *connection, char** password)
1629Get the username and password from the basic authorization header sent by the client.
1630Return @code{NULL} if no username could be found, a pointer to the username if found.
1631If returned value is not @code{NULL}, the value must be @code{free()}'ed.
1632
1633@var{password} reference a buffer to store the password. It can be @code{NULL}.
1634If returned value is not @code{NULL}, the value must be @code{free()}'ed.
1635@end deftypefun
1636
1637@deftypefun {int} MHD_queue_basic_auth_fail_response (struct MHD_Connection *connection, const char *realm, struct MHD_Response *response)
1638Queues a response to request basic authentication from the client.
1639Return @code{MHD_YES} if successful, otherwise @code{MHD_NO}.
1640
1641@var{realm} must reference to a zero-terminated string representing the realm.
1642
1643@var{response} a response structure to specify what shall be presented to the
1644client with a 401 HTTP status.
1645@end deftypefun
1646
1647@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1648
1649@c ------------------------------------------------------------
1650@node microhttpd-dauth digest
1651@section Using Digest Authentication
1652
1653@deftypefun {char *} MHD_digest_auth_get_username (struct MHD_Connection *connection)
1654Find and return a pointer to the username value from the request header.
1655Return @code{NULL} if the value is not found or header does not exist.
1656If returned value is not @code{NULL}, the value must be @code{free()}'ed.
1657@end deftypefun
1658
1659@deftypefun int MHD_digest_auth_check (struct MHD_Connection *connection, const char *realm, const char *username, const char *password, unsigned int nonce_timeout)
1660Checks if the provided values in the WWW-Authenticate header are valid
1661and sound according to RFC2716. If valid return @code{MHD_YES}, otherwise return @code{MHD_NO}.
1662
1663@var{realm} must reference to a zero-terminated string representing the realm.
1664
1665@var{username} must reference to a zero-terminated string representing the username,
1666it is usually the returned value from MHD_digest_auth_get_username.
1667
1668@var{password} must reference to a zero-terminated string representing the password,
1669most probably it will be the result of a lookup of the username against a local database.
1670
1671@var{nonce_timeout} is the amount of time in seconds for a nonce to be invalid.
1672Most of the time it is sound to specify 300 seconds as its values.
1673@end deftypefun
1674
1675@deftypefun int MHD_queue_auth_fail_response (struct MHD_Connection *connection, const char *realm, const char *opaque, struct MHD_Response *response, int signal_stale)
1676Queues a response to request authentication from the client,
1677return @code{MHD_YES} if successful, otherwise @code{MHD_NO}.
1678
1679@var{realm} must reference to a zero-terminated string representing the realm.
1680
1681@var{opaque} must reference to a zero-terminated string representing a value
1682that gets passed to the client and expected to be passed again to the server
1683as-is. This value can be a hexadecimal or base64 string.
1684
1685@var{response} a response structure to specify what shall be presented to the
1686client with a 401 HTTP status.
1687
1688@var{signal_stale} a value that signals "stale=true" in the response header to
1689indicate the invalidity of the nonce and no need to ask for authentication
1690parameters and only a new nonce gets generated. @code{MHD_YES} to generate a new
1691nonce, @code{MHD_NO} to ask for authentication parameters.
1692@end deftypefun
1693
1694Example: handling digest authentication requests and responses.
1695
1696@example
1697#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>"
1698#define DENIED "<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>"
1699#define OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4"
1700
1701static int
1702ahc_echo (void *cls,
1703 struct MHD_Connection *connection,
1704 const char *url,
1705 const char *method,
1706 const char *version,
1707 const char *upload_data, size_t *upload_data_size, void **ptr)
1708@{
1709 struct MHD_Response *response;
1710 char *username;
1711 const char *password = "testpass";
1712 const char *realm = "test@@example.com";
1713 int ret;
1714
1715 username = MHD_digest_auth_get_username(connection);
1716 if (username == NULL)
1717 @{
1718 response = MHD_create_response_from_buffer(strlen (DENIED),
1719 DENIED,
1720 MHD_RESPMEM_PERSISTENT);
1721 ret = MHD_queue_auth_fail_response(connection, realm,
1722 OPAQUE,
1723 response,
1724 MHD_NO);
1725 MHD_destroy_response(response);
1726 return ret;
1727 @}
1728 ret = MHD_digest_auth_check(connection, realm,
1729 username,
1730 password,
1731 300);
1732 free(username);
1733 if ( (ret == MHD_INVALID_NONCE) ||
1734 (ret == MHD_NO) )
1735 @{
1736 response = MHD_create_response_from_buffer(strlen (DENIED),
1737 DENIED,
1738 MHD_RESPMEM_PERSISTENT);
1739 if (NULL == response)
1740 return MHD_NO;
1741 ret = MHD_queue_auth_fail_response(connection, realm,
1742 OPAQUE,
1743 response,
1744 (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO);
1745 MHD_destroy_response(response);
1746 return ret;
1747 @}
1748 response = MHD_create_response_from_buffer (strlen(PAGE), PAGE,
1749 MHD_RESPMEM_PERSISTENT);
1750 ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
1751 MHD_destroy_response(response);
1752 return ret;
1753@}
1754@end example
1755
1756@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1757
1758@c ------------------------------------------------------------
1759@node microhttpd-post
1760@chapter Adding a @code{POST} processor
1761@cindex POST method
1762
1763@menu
1764* microhttpd-post api:: Programming interface for the
1765 @code{POST} processor.
1766@end menu
1767
1768
1769@noindent
1770MHD provides the post processor API to make it easier for applications to
1771parse the data of a client's @code{POST} request: the
1772@code{MHD_AccessHandlerCallback} will be invoked multiple times to
1773process data as it arrives; at each invocation a new chunk of data must
1774be processed. The arguments @var{upload_data} and @var{upload_data_size}
1775are used to reference the chunk of data.
1776
1777When @code{MHD_AccessHandlerCallback} is invoked for a new connection:
1778its @code{*@var{con_cls}} argument is set to @code{NULL}. When @code{POST}
1779data comes in the upload buffer it is @strong{mandatory} to use the
1780@var{con_cls} to store a reference to per-connection data. The fact
1781that the pointer was initially @code{NULL} can be used to detect that
1782this is a new request.
1783
1784One method to detect that a new connection was established is
1785to set @code{*con_cls} to an unused integer:
1786
1787@example
1788int
1789access_handler (void *cls,
1790 struct MHD_Connection * connection,
1791 const char *url,
1792 const char *method, const char *version,
1793 const char *upload_data, size_t *upload_data_size,
1794 void **con_cls)
1795@{
1796 static int old_connection_marker;
1797 int new_connection = (NULL == *con_cls);
1798
1799 if (new_connection)
1800 @{
1801 /* new connection with POST */
1802 *con_cls = &old_connection_marker;
1803 @}
1804
1805 ...
1806@}
1807@end example
1808
1809@noindent
1810In contrast to the previous example, for @code{POST} requests in particular,
1811it is more common to use the value of @code{*con_cls} to keep track of
1812actual state used during processing, such as the post processor (or a
1813struct containing a post processor):
1814
1815@example
1816int
1817access_handler (void *cls,
1818 struct MHD_Connection * connection,
1819 const char *url,
1820 const char *method, const char *version,
1821 const char *upload_data, size_t *upload_data_size,
1822 void **con_cls)
1823@{
1824 struct MHD_PostProcessor * pp = *con_cls;
1825
1826 if (pp == NULL)
1827 @{
1828 pp = MHD_create_post_processor(connection, ...);
1829 *con_cls = pp;
1830 return MHD_YES;
1831 @}
1832 if (*upload_data_size)
1833 @{
1834 MHD_post_process(pp, upload_data, *upload_data_size);
1835 *upload_data_size = 0;
1836 return MHD_YES;
1837 @}
1838 else
1839 @{
1840 MHD_destroy_post_processor(pp);
1841 return MHD_queue_response(...);
1842 @}
1843@}
1844@end example
1845
1846Note that the callback from @code{MHD_OPTION_NOTIFY_COMPLETED}
1847should be used to destroy the post processor. This cannot be
1848done inside of the access handler since the connection may not
1849always terminate normally.
1850
1851
1852@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1853
1854@c ------------------------------------------------------------
1855@node microhttpd-post api
1856@section Programming interface for the @code{POST} processor
1857@cindex POST method
1858
1859@deftypefun {struct MHD_PostProcessor *} MHD_create_post_processor (struct MHD_Connection *connection, size_t buffer_size, MHD_PostDataIterator iterator, void *iterator_cls)
1860Create a PostProcessor. A PostProcessor can be used to (incrementally)
1861parse the data portion of a @code{POST} request.
1862
1863@table @var
1864@item connection
1865the connection on which the @code{POST} is happening (used to determine
1866the @code{POST} format);
1867
1868@item buffer_size
1869maximum number of bytes to use for internal buffering (used only for the
1870parsing, specifically the parsing of the keys). A tiny value (256-1024)
1871should be sufficient; do @strong{NOT} use a value smaller than 256;
1872
1873@item iterator
1874iterator to be called with the parsed data; must @strong{NOT} be
1875@code{NULL};
1876
1877@item iterator_cls
1878custom value to be used as first argument to @var{iterator}.
1879@end table
1880
1881Return @code{NULL} on error (out of memory, unsupported encoding), otherwise
1882a PP handle.
1883@end deftypefun
1884
1885
1886@deftypefun int MHD_post_process (struct MHD_PostProcessor *pp, const char *post_data, size_t post_data_len)
1887Parse and process @code{POST} data. Call this function when @code{POST}
1888data is available (usually during an @code{MHD_AccessHandlerCallback})
1889with the @var{upload_data} and @var{upload_data_size}. Whenever
1890possible, this will then cause calls to the
1891@code{MHD_IncrementalKeyValueIterator}.
1892
1893@table @var
1894@item pp
1895the post processor;
1896
1897@item post_data
1898@var{post_data_len} bytes of @code{POST} data;
1899
1900@item post_data_len
1901length of @var{post_data}.
1902@end table
1903
1904Return @code{MHD_YES} on success, @code{MHD_NO} on error
1905(out-of-memory, iterator aborted, parse error).
1906@end deftypefun
1907
1908
1909@deftypefun int MHD_destroy_post_processor (struct MHD_PostProcessor *pp)
1910Release PostProcessor resources. After this function is being called,
1911the PostProcessor is guaranteed to no longer call its iterator. There
1912is no special call to the iterator to indicate the end of the post processing
1913stream. After destroying the PostProcessor, the programmer should
1914perform any necessary work to complete the processing of the iterator.
1915
1916Return @code{MHD_YES} if processing completed nicely, @code{MHD_NO}
1917if there were spurious characters or formatting problems with
1918the post request. It is common to ignore the return value
1919of this function.
1920
1921
1922@end deftypefun
1923
1924
1925
1926@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1927
1928@c ------------------------------------------------------------
1929@node microhttpd-info
1930@chapter Obtaining and modifying status information.
1931
1932
1933@menu
1934* microhttpd-info daemon:: State information about an MHD daemon
1935* microhttpd-info conn:: State information about a connection
1936* microhttpd-option conn:: Modify per-connection options
1937@end menu
1938
1939
1940@c ------------------------------------------------------------
1941@node microhttpd-info daemon
1942@section Obtaining state information about an MHD daemon
1943
1944@deftypefun {const union MHD_DaemonInfo *} MHD_get_daemon_info (struct MHD_Daemon *daemon, enum MHD_DaemonInfoType infoType, ...)
1945Obtain information about the given daemon. This function
1946is currently not fully implemented.
1947
1948@table @var
1949@item daemon
1950the daemon about which information is desired;
1951
1952@item infoType
1953type of information that is desired
1954
1955@item ...
1956additional arguments about the desired information (depending on
1957infoType)
1958@end table
1959
1960Returns a union with the respective member (depending on
1961infoType) set to the desired information), or @code{NULL}
1962in case the desired information is not available or
1963applicable.
1964@end deftypefun
1965
1966
1967@deftp {Enumeration} MHD_DaemonInfoType
1968Values of this enum are used to specify what
1969information about a daemon is desired.
1970@table @code
1971@item MHD_DAEMON_INFO_KEY_SIZE
1972Request information about the key size for a particular cipher
1973algorithm. The cipher algorithm should be passed as an extra argument
1974(of type 'enum MHD_GNUTLS_CipherAlgorithm').
1975
1976@item MHD_DAEMON_INFO_MAC_KEY_SIZE
1977Request information about the key size for a particular cipher
1978algorithm. The cipher algorithm should be passed as an extra argument
1979(of type 'enum MHD_GNUTLS_HashAlgorithm').
1980
1981@item MHD_DAEMON_INFO_LISTEN_FD
1982@cindex listen
1983Request the file-descriptor number that MHD is using to listen to the
1984server socket. This can be useful if no port
1985was specified and a client needs to learn what port
1986is actually being used by MHD.
1987No extra arguments should be passed.
1988
1989@end table
1990@end deftp
1991
1992
1993
1994@c ------------------------------------------------------------
1995@node microhttpd-info conn
1996@section Obtaining state information about a connection
1997
1998
1999@deftypefun {const union MHD_ConnectionInfo *} MHD_get_connection_info (struct MHD_Connection *daemon, enum MHD_ConnectionInfoType infoType, ...)
2000Obtain information about the given connection.
2001
2002@table @var
2003@item connection
2004the connection about which information is desired;
2005
2006@item infoType
2007type of information that is desired
2008
2009@item ...
2010additional arguments about the desired information (depending on
2011infoType)
2012@end table
2013
2014Returns a union with the respective member (depending on
2015infoType) set to the desired information), or @code{NULL}
2016in case the desired information is not available or
2017applicable.
2018@end deftypefun
2019
2020@deftp {Enumeration} MHD_ConnectionInfoType
2021Values of this enum are used to specify what information about a
2022connection is desired.
2023
2024@table @code
2025
2026@item MHD_CONNECTION_INFO_CIPHER_ALGO
2027What cipher algorithm is being used (HTTPS connections only).
2028Takes no extra arguments.
2029@code{NULL} is returned for non-HTTPS connections.
2030
2031@item MHD_CONNECTION_INFO_PROTOCOL,
2032Takes no extra arguments. Allows finding out the TLS/SSL protocol used
2033(HTTPS connections only).
2034@code{NULL} is returned for non-HTTPS connections.
2035
2036@item MHD_CONNECTION_INFO_CLIENT_ADDRESS
2037Returns information about the address of the client. Returns
2038essentially a @code{struct sockaddr **} (since the API returns
2039a @code{union MHD_ConnectionInfo *} and that union contains
2040a @code{struct sockaddr *}).
2041
2042@item MHD_CONNECTION_INFO_GNUTLS_SESSION,
2043Takes no extra arguments. Allows access to the underlying GNUtls session,
2044including access to the underlying GNUtls client certificate
2045(HTTPS connections only). Takes no extra arguments.
2046@code{NULL} is returned for non-HTTPS connections.
2047
2048@item MHD_CONNECTION_INFO_GNUTLS_CLIENT_CERT,
2049Dysfunctional (never implemented, deprecated). Use
2050MHD_CONNECTION_INFO_GNUTLS_SESSION to get the @code{gnutls_session_t}
2051and then call @code{gnutls_certificate_get_peers()}.
2052
2053@item MHD_CONNECTION_INFO_DAEMON
2054Returns information about @code{struct MHD_Daemon} which manages
2055this connection.
2056
2057@end table
2058@end deftp
2059
2060
2061
2062@c ------------------------------------------------------------
2063@node microhttpd-option conn
2064@section Setting custom options for an individual connection
2065@cindex timeout
2066
2067
2068
2069@deftypefun {int} MHD_set_connection_option (struct MHD_Connection *daemon, enum MHD_CONNECTION_OPTION option, ...)
2070Set a custom option for the given connection.
2071
2072@table @var
2073@item connection
2074the connection for which an option should be set or modified;
2075
2076@item option
2077option to set
2078
2079@item ...
2080additional arguments for the option (depending on option)
2081@end table
2082
2083Returns @code{MHD_YES} on success, @code{MHD_NO} for errors
2084(i.e. option argument invalid or option unknown).
2085@end deftypefun
2086
2087
2088@deftp {Enumeration} MHD_CONNECTION_OPTION
2089Values of this enum are used to specify which option for a
2090connection should be changed.
2091
2092@table @code
2093
2094@item MHD_CONNECTION_OPTION_TIMEOUT
2095Set a custom timeout for the given connection. Specified
2096as the number of seconds, given as an @code{unsigned int}. Use
2097zero for no timeout.
2098
2099@end table
2100@end deftp
2101
2102
2103@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2104
2105
2106@c **********************************************************
2107@c ******************* Appendices *************************
2108@c **********************************************************
2109
2110@node GNU-LGPL
2111@unnumbered GNU-LGPL
2112@cindex license
2113@include lgpl.texi
2114
2115@node GNU GPL with eCos Extension
2116@unnumbered GNU GPL with eCos Extension
2117@cindex license
2118@include ecos.texi
2119
2120@node GNU-FDL
2121@unnumbered GNU-FDL
2122@cindex license
2123@include fdl-1.3.texi
2124
2125@node Concept Index
2126@unnumbered Concept Index
2127
2128@printindex cp
2129
2130@node Function and Data Index
2131@unnumbered Function and Data Index
2132
2133@printindex fn
2134
2135@node Type Index
2136@unnumbered Type Index
2137
2138@printindex tp
2139
2140@bye