diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-09-08 19:15:04 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-09-08 19:15:04 +0000 |
commit | 5a046307a7475f15698afb6450d92ff4e6ffd0ad (patch) | |
tree | ce8af1e94305b769f64ad24222127fd026e1bd06 /doc/libmicrohttpd.texi | |
parent | ad74bf4b442d214e4c3e8ade23d460fcf35c11f1 (diff) | |
download | libmicrohttpd-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.texi | 2140 |
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 | ||
12 | This manual is for GNU libmicrohttpd | ||
13 | (version @value{VERSION}, @value{UPDATED}), a library for embedding | ||
14 | an HTTP(S) server into C applications. | ||
15 | |||
16 | Copyright @copyright{} 2007--2012 Christian Grothoff | ||
17 | |||
18 | @quotation | ||
19 | Permission is granted to copy, distribute and/or modify this document | ||
20 | under the terms of the GNU Free Documentation License, Version 1.3 | ||
21 | or any later version published by the Free Software Foundation; | ||
22 | with no Invariant Sections, no Front-Cover Texts, and no Back-Cover | ||
23 | Texts. A copy of the license is included in the section entitled "GNU | ||
24 | Free 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 | |||
70 | Appendices | ||
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 | |||
79 | Indices | ||
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 | ||
94 | All symbols defined in the public API start with @code{MHD_}. MHD | ||
95 | is a small HTTP daemon library. As such, it does not have any API | ||
96 | for logging errors (you can only enable or disable logging to stderr). | ||
97 | Also, it may not support all of the HTTP features directly, where | ||
98 | applicable, portions of HTTP may have to be handled by clients of the | ||
99 | library. | ||
100 | |||
101 | The library is supposed to handle everything that it must handle | ||
102 | (because the API would not allow clients to do this), such as basic | ||
103 | connection management; however, detailed interpretations of headers --- | ||
104 | such as range requests --- and HTTP methods are left to clients. The | ||
105 | library does understand @code{HEAD} and will only send the headers of | ||
106 | the response and not the body, even if the client supplied a body. The | ||
107 | library also understands headers that control connection management | ||
108 | (specifically, @code{Connection: close} and @code{Expect: 100 continue} | ||
109 | are understood and handled automatically). | ||
110 | |||
111 | MHD understands @code{POST} data and is able to decode certain | ||
112 | formats (at the moment only @code{application/x-www-form-urlencoded} | ||
113 | and @code{multipart/form-data}) using the post processor API. The | ||
114 | data stream of a POST is also provided directly to the main | ||
115 | application, so unsupported encodings could still be processed, just | ||
116 | not conveniently by MHD. | ||
117 | |||
118 | The header file defines various constants used by the HTTP protocol. | ||
119 | This does not mean that MHD actually interprets all of these values. | ||
120 | The provided constants are exported as a convenience for users of the | ||
121 | library. MHD does not verify that transmitted HTTP headers are | ||
122 | part of the standard specification; users of the library are free to | ||
123 | define their own extensions of the HTTP standard and use those with | ||
124 | MHD. | ||
125 | |||
126 | All functions are guaranteed to be completely reentrant and | ||
127 | thread-safe. MHD checks for allocation failures and tries to | ||
128 | recover gracefully (for example, by closing the connection). | ||
129 | Additionally, clients can specify resource limits on the overall | ||
130 | number of connections, number of connections per IP address and memory | ||
131 | used per connection to avoid resource exhaustion. | ||
132 | |||
133 | @section Scope | ||
134 | |||
135 | MHD is currently used in a wide range of implementations. | ||
136 | Examples 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 | |||
151 | MHD uses the standard GNU system where the usual build process | ||
152 | involves running | ||
153 | @verbatim | ||
154 | $ ./configure | ||
155 | $ make | ||
156 | $ make install | ||
157 | @end verbatim | ||
158 | |||
159 | MHD supports various options to be given to configure to tailor the | ||
160 | binary to a specific situation. Note that some of these options will | ||
161 | remove portions of the MHD code that are required for | ||
162 | binary-compatibility. They should only be used on embedded systems | ||
163 | with tight resource constraints and no concerns about library | ||
164 | versioning. Standard distributions including MHD are expected to | ||
165 | always ship with all features enabled, otherwise unexpected | ||
166 | incompatibilities can arise! | ||
167 | |||
168 | Here 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 | ||
170 | full list of options run ``./configure --help''): | ||
171 | |||
172 | @table @code | ||
173 | @item ``--disable-curl'' | ||
174 | disable running testcases using libcurl | ||
175 | |||
176 | @item ``--disable-largefile'' | ||
177 | disable support for 64-bit files | ||
178 | |||
179 | @item ``--disable-messages'' | ||
180 | disable logging of error messages (smaller binary size, not so much fun for debugging) | ||
181 | |||
182 | @item ``--disable-https'' | ||
183 | 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) | ||
184 | |||
185 | @item ``--disable-postprocessor'' | ||
186 | do not include the post processor API (results in binary incompatibility) | ||
187 | |||
188 | @item ``--disable-dauth'' | ||
189 | do not include the authentication APIs (results in binary incompatibility) | ||
190 | |||
191 | @item ``--enable-coverage'' | ||
192 | set flags for analysis of code-coverage with gcc/gcov (results in slow, large binaries) | ||
193 | |||
194 | @item ``--with-gcrypt=PATH'' | ||
195 | specifies path to libgcrypt installation | ||
196 | |||
197 | @item ``--with-gnutls=PATH'' | ||
198 | specifies 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 | |||
208 | Ideally, before including "microhttpd.h" you should add the necessary | ||
209 | includes to define the @code{uint64_t}, @code{size_t}, @code{fd_set}, | ||
210 | @code{socklen_t} and @code{struct sockaddr} data types. Which | ||
211 | specific headers are needed may depend on your platform and your build | ||
212 | system might include some tests to provide you with the necessary | ||
213 | conditional operations. For possible suggestions consult | ||
214 | @code{platform.h} and @code{configure.ac} in the MHD distribution. | ||
215 | |||
216 | Once you have ensured that you manually (!) included the right headers | ||
217 | for your platform before "microhttpd.h", you should also add a line | ||
218 | with @code{#define MHD_PLATFORM_H} which will prevent the | ||
219 | "microhttpd.h" header from trying (and, depending on your platform, | ||
220 | failing) to include the right headers. | ||
221 | |||
222 | If you do not define MHD_PLATFORM_H, the "microhttpd.h" header will | ||
223 | automatically include headers needed on GNU/Linux systems (possibly | ||
224 | causing problems when porting to other platforms). | ||
225 | |||
226 | @section SIGPIPE | ||
227 | @cindex signals | ||
228 | MHD does not install a signal handler for SIGPIPE. On platforms | ||
229 | where this is possible (such as GNU/Linux), it disables SIGPIPE for | ||
230 | its I/O operations (by passing MSG_NOSIGNAL). On other platforms, | ||
231 | SIGPIPE signals may be generated from network operations by | ||
232 | MHD and will cause the process to die unless the developer | ||
233 | explicitly installs a signal handler for SIGPIPE. | ||
234 | |||
235 | Hence portable code using MHD must install a SIGPIPE handler or | ||
236 | explicitly block the SIGPIPE signal. MHD does not do so in order | ||
237 | to avoid messing with other parts of the application that may | ||
238 | need 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 | ||
241 | static void | ||
242 | catcher (int sig) | ||
243 | { | ||
244 | } | ||
245 | |||
246 | static void | ||
247 | ignore_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 | |||
272 | Some platforms do not support @code{long long}. Hence MHD defines | ||
273 | a macro @code{MHD_LONG_LONG} which will default to @code{long long}. | ||
274 | If your platform does not support @code{long long}, you should | ||
275 | change "platform.h" to define @code{MHD_LONG_LONG} to an appropriate | ||
276 | alternative type and also define @code{MHD_LONG_LONG_PRINTF} to the | ||
277 | corresponding format string for printing such a data type (without | ||
278 | the percent sign). | ||
279 | |||
280 | @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
281 | |||
282 | @c ------------------------------------------------------------ | ||
283 | @node microhttpd-const | ||
284 | @chapter Constants | ||
285 | |||
286 | |||
287 | @deftp {Enumeration} MHD_FLAG | ||
288 | Options for the MHD daemon. | ||
289 | |||
290 | Note that if neither @code{MHD_USE_THREAD_PER_CONNECTION} nor | ||
291 | @code{MHD_USE_SELECT_INTERNALLY} is used, the client wants control over | ||
292 | the process and will call the appropriate microhttpd callbacks. | ||
293 | |||
294 | Starting the daemon may also fail if a particular option is not | ||
295 | implemented or not supported on the target platform (i.e. no support for | ||
296 | @acronym{SSL}, threads or IPv6). SSL support generally depends on | ||
297 | options given during MHD compilation. Threaded operations | ||
298 | (including @code{MHD_USE_SELECT_INTERNALLY}) are not supported on | ||
299 | Symbian. | ||
300 | |||
301 | @table @code | ||
302 | @item MHD_NO_FLAG | ||
303 | No options selected. | ||
304 | |||
305 | @item MHD_USE_DEBUG | ||
306 | @cindex debugging | ||
307 | Run in debug mode. If this flag is used, the library should print error | ||
308 | messages and warnings to stderr. Note that for this | ||
309 | run-time option to have any effect, MHD needs to be | ||
310 | compiled with messages enabled. This is done by default except you ran | ||
311 | configure with the @code{--disable-messages} flag set. | ||
312 | |||
313 | @item MHD_USE_SSL | ||
314 | Run in https mode (this option may not work with all threading modes yet). | ||
315 | |||
316 | @item MHD_USE_THREAD_PER_CONNECTION | ||
317 | Run using one thread per connection. | ||
318 | |||
319 | @item MHD_USE_SELECT_INTERNALLY | ||
320 | Run using an internal thread doing @code{SELECT}. | ||
321 | |||
322 | @item MHD_USE_IPv6 | ||
323 | @cindex IPv6 | ||
324 | Run using the IPv6 protocol (otherwise, MHD will just support IPv4). | ||
325 | |||
326 | |||
327 | @item MHD_USE_PEDANTIC_CHECKS | ||
328 | Be pedantic about the protocol (as opposed to as tolerant as possible). | ||
329 | Specifically, at the moment, this flag causes MHD to reject HTTP | ||
330 | 1.1 connections without a @code{Host} header. This is required by the | ||
331 | standard, but of course in violation of the ``be as liberal as possible | ||
332 | in what you accept'' norm. It is recommended to turn this @strong{ON} | ||
333 | if you are testing clients against MHD, and @strong{OFF} in | ||
334 | production. | ||
335 | |||
336 | @item MHD_USE_POLL | ||
337 | @cindex FD_SETSIZE | ||
338 | @cindex poll | ||
339 | @cindex select | ||
340 | Use 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 | ||
348 | Suppress (automatically) adding the 'Date:' header to HTTP responses. | ||
349 | This option should ONLY be used on systems that do not have a clock | ||
350 | and that DO provide other mechanisms for cache control. See also | ||
351 | RFC 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 | ||
358 | Run the HTTP server without any listen socket. This option only makes | ||
359 | sense if @code{MHD_add_connection} is going to be used exclusively to | ||
360 | connect HTTP clients to the HTTP server. This option is incompatible | ||
361 | with 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 | ||
369 | MHD options. Passed in the varargs portion of | ||
370 | @code{MHD_start_daemon()}. | ||
371 | |||
372 | @table @code | ||
373 | @item MHD_OPTION_END | ||
374 | No more options / last option. This is used to terminate the VARARGs | ||
375 | list. | ||
376 | |||
377 | @item MHD_OPTION_CONNECTION_MEMORY_LIMIT | ||
378 | @cindex memory, limiting memory utilization | ||
379 | Maximum memory size per connection (followed by a @code{size_t}). The | ||
380 | default 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 | ||
385 | Maximum number of concurrent connections to accept (followed by an | ||
386 | @code{unsigned int}). The default is @code{FD_SETSIZE - 4} (the | ||
387 | maximum number of file descriptors supported by @code{select} minus | ||
388 | four for @code{stdin}, @code{stdout}, @code{stderr} and the server | ||
389 | socket). In other words, the default is as large as possible. | ||
390 | |||
391 | Note that if you set a low connection limit, you can easily get into | ||
392 | trouble with browsers doing request pipelining. For example, if your | ||
393 | connection limit is ``1'', a browser may open a first connection to | ||
394 | access your ``index.html'' file, keep it open but use a second | ||
395 | connection to retrieve CSS files, images and the like. In fact, modern | ||
396 | browsers are typically by default configured for up to 15 parallel | ||
397 | connections to a single server. If this happens, MHD will refuse to | ||
398 | even accept the second connection until the first connection is | ||
399 | closed --- which does not happen until timeout. As a result, the | ||
400 | browser will fail to render the page and seem to hang. If you expect | ||
401 | your server to operate close to the connection limit, you should | ||
402 | first consider using a lower timeout value and also possibly add | ||
403 | a ``Connection: close'' header to your response to ensure that | ||
404 | request pipelining is not used and connections are closed immediately | ||
405 | after the request has completed: | ||
406 | @example | ||
407 | MHD_add_response_header (response, | ||
408 | MHD_HTTP_HEADER_CONNECTION, | ||
409 | "close"); | ||
410 | @end example | ||
411 | |||
412 | @item MHD_OPTION_CONNECTION_TIMEOUT | ||
413 | @cindex timeout | ||
414 | After how many seconds of inactivity should a connection automatically | ||
415 | be timed out? (followed by an @code{unsigned int}; use zero for no | ||
416 | timeout). The default is zero (no timeout). | ||
417 | |||
418 | @item MHD_OPTION_NOTIFY_COMPLETED | ||
419 | Register a function that should be called whenever a request has been | ||
420 | completed (this can be used for application-specific clean up). | ||
421 | Requests that have never been presented to the application (via | ||
422 | @code{MHD_AccessHandlerCallback()}) will not result in | ||
423 | notifications. | ||
424 | |||
425 | This option should be followed by @strong{TWO} pointers. First a | ||
426 | pointer to a function of type @code{MHD_RequestCompletedCallback()} | ||
427 | and second a pointer to a closure to pass to the request completed | ||
428 | callback. The second pointer maybe @code{NULL}. | ||
429 | |||
430 | |||
431 | @item MHD_OPTION_PER_IP_CONNECTION_LIMIT | ||
432 | Limit on the number of (concurrent) connections made to the | ||
433 | server from the same IP address. Can be used to prevent one | ||
434 | IP from taking over all of the allowed connections. If the | ||
435 | same IP tries to establish more than the specified number of | ||
436 | connections, they will be immediately rejected. The option | ||
437 | should be followed by an @code{unsigned int}. The default is | ||
438 | zero, which means no limit on the number of connections | ||
439 | from the same IP address. | ||
440 | |||
441 | @item MHD_OPTION_SOCK_ADDR | ||
442 | @cindex bind, restricting bind | ||
443 | Bind daemon to the supplied socket address. This option should be followed by a | ||
444 | @code{struct sockaddr *}. If @code{MHD_USE_IPv6} is specified, | ||
445 | the @code{struct sockaddr*} should point to a @code{struct sockaddr_in6}, | ||
446 | otherwise to a @code{struct sockaddr_in}. If this option is not specified, | ||
447 | the daemon will listen to incoming connections from anywhere. If you use this | ||
448 | option, the 'port' argument from @code{MHD_start_daemon} is ignored and the port | ||
449 | from 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 | ||
455 | Specify a function that should be called before parsing the URI from | ||
456 | the client. The specified callback function can be used for processing | ||
457 | the URI (including the options) before it is parsed. The URI after | ||
458 | parsing will no longer contain the options, which maybe inconvenient for | ||
459 | logging. This option should be followed by two arguments, the first | ||
460 | one must be of the form | ||
461 | @example | ||
462 | void * my_logger(void * cls, const char * uri) | ||
463 | @end example | ||
464 | where the return value will be passed as | ||
465 | @code{*con_cls} in calls to the @code{MHD_AccessHandlerCallback} | ||
466 | when this request is processed later; returning a | ||
467 | value of @code{NULL} has no special significance; (however, | ||
468 | note that if you return non-@code{NULL}, you can no longer | ||
469 | rely 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 | ||
472 | MHD_OPTION_URI_LOG_CALLBACK. Finally, @code{uri} will | ||
473 | be the 0-terminated URI of the request. | ||
474 | |||
475 | @item MHD_OPTION_HTTPS_MEM_KEY | ||
476 | @cindex SSL | ||
477 | @cindex TLS | ||
478 | Memory pointer to the private key to be used by the | ||
479 | HTTPS daemon. This option should be followed by an | ||
480 | "const char*" argument. | ||
481 | This 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 | ||
486 | Memory pointer to the certificate to be used by the | ||
487 | HTTPS daemon. This option should be followed by an | ||
488 | "const char*" argument. | ||
489 | This 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 | ||
494 | Memory pointer to the CA certificate to be used by the | ||
495 | HTTPS daemon to authenticate and trust clients certificates. | ||
496 | This option should be followed by an "const char*" argument. | ||
497 | The presence of this option activates the request of certificate | ||
498 | to the client. The request to the client is marked optional, and | ||
499 | it is the responsibility of the server to check the presence | ||
500 | of the certificate if needed. | ||
501 | Note that most browsers will only present a client certificate | ||
502 | only if they have one matching the specified CA, not sending | ||
503 | any certificate otherwise. | ||
504 | |||
505 | @item MHD_OPTION_HTTPS_CRED_TYPE | ||
506 | @cindex SSL | ||
507 | @cindex TLS | ||
508 | Daemon credentials type. Either certificate or anonymous, | ||
509 | this 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 | ||
516 | SSL/TLS protocol version and ciphers. | ||
517 | This option must be followed by an "const char *" argument | ||
518 | specifying the SSL/TLS protocol versions and ciphers that | ||
519 | are acceptable for the application. The string is passed | ||
520 | unchanged to gnutls_priority_init. If this option is not | ||
521 | specified, ``NORMAL'' is used. | ||
522 | |||
523 | @item MHD_OPTION_DIGEST_AUTH_RANDOM | ||
524 | @cindex digest auth | ||
525 | @cindex random | ||
526 | Digest Authentication nonce's seed. | ||
527 | |||
528 | This option should be followed by two arguments. First an integer of | ||
529 | type "size_t" which specifies the size of the buffer pointed to by the | ||
530 | second argument in bytes. Note that the application must ensure that | ||
531 | the buffer of the second argument remains allocated and unmodified | ||
532 | while the daemon is running. For security, you SHOULD provide a fresh | ||
533 | random nonce when using MHD with Digest Authentication. | ||
534 | |||
535 | @item MHD_OPTION_NONCE_NC_SIZE | ||
536 | @cindex digest auth | ||
537 | @cindex replay attack | ||
538 | |||
539 | Size of an array of nonce and nonce counter map. This option must be | ||
540 | followed by an "unsigned int" argument that have the size (number of | ||
541 | elements) of a map of a nonce and a nonce-counter. If this option | ||
542 | is not specified, a default value of 4 will be used (which might be | ||
543 | too small for servers handling many requests). If you do not use | ||
544 | digest authentication at all, you can specify a value of zero to | ||
545 | save some memory. | ||
546 | |||
547 | You should calculate the value of NC_SIZE based on the number of | ||
548 | connections per second multiplied by your expected session duration | ||
549 | plus a factor of about two for hash table collisions. For example, if | ||
550 | you expect 100 digest-authenticated connections per second and the | ||
551 | average user to stay on your site for 5 minutes, then you likely need | ||
552 | a value of about 60000. On the other hand, if you can only expect | ||
553 | only 10 digest-authenticated connections per second, tolerate browsers | ||
554 | getting a fresh nonce for each request and expect a HTTP request | ||
555 | latency of 250 ms, then a value of about 5 should be fine. | ||
556 | |||
557 | |||
558 | @item MHD_OPTION_LISTEN_SOCKET | ||
559 | @cindex systemd | ||
560 | Listen 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 | ||
562 | listen socket(s). The argument passed must be of type "int" and refer | ||
563 | to an existing socket that has been bound to a port and is listening. | ||
564 | |||
565 | @item MHD_OPTION_EXTERNAL_LOGGER | ||
566 | @cindex logging | ||
567 | Use the given function for logging error messages. | ||
568 | This option must be followed by two arguments; the | ||
569 | first must be a pointer to a function | ||
570 | of type 'void fun(void * arg, const char * fmt, va_list ap)' | ||
571 | and the second a pointer of type 'void*' which will | ||
572 | be passed as the "arg" argument to "fun". | ||
573 | |||
574 | Note that MHD will not generate any log messages without | ||
575 | the MHD_USE_DEBUG flag set and if MHD was compiled | ||
576 | with the "--disable-messages" flag. | ||
577 | |||
578 | @item MHD_OPTION_THREAD_POOL_SIZE | ||
579 | @cindex performance | ||
580 | Number (unsigned int) of threads in thread pool. Enable | ||
581 | thread pooling by setting this value to to something | ||
582 | greater than 1. Currently, thread model must be | ||
583 | MHD_USE_SELECT_INTERNALLY if thread pooling is enabled | ||
584 | (MHD_start_daemon returns @code{NULL} for an unsupported thread | ||
585 | model). | ||
586 | |||
587 | @item MHD_OPTION_ARRAY | ||
588 | @cindex options | ||
589 | @cindex foreign-function interface | ||
590 | This option can be used for initializing MHD using options from an | ||
591 | array. A common use for this is writing an FFI for MHD. The actual | ||
592 | options given are in an array of 'struct MHD_OptionItem', so this | ||
593 | option requires a single argument of type 'struct MHD_OptionItem'. | ||
594 | The array must be terminated with an entry @code{MHD_OPTION_END}. | ||
595 | |||
596 | An example for code using MHD_OPTION_ARRAY is: | ||
597 | @example | ||
598 | struct MHD_OptionItem ops[] = @{ | ||
599 | @{ MHD_OPTION_CONNECTION_LIMIT, 100, NULL @}, | ||
600 | @{ MHD_OPTION_CONNECTION_TIMEOUT, 10, NULL @}, | ||
601 | @{ MHD_OPTION_END, 0, NULL @} | ||
602 | @}; | ||
603 | d = MHD_start_daemon(0, 8080, NULL, NULL, dh, NULL, | ||
604 | MHD_OPTION_ARRAY, ops, | ||
605 | MHD_OPTION_END); | ||
606 | @end example | ||
607 | For options that expect a single pointer argument, the | ||
608 | second member of the @code{struct MHD_OptionItem} is ignored. | ||
609 | For options that expect two pointer arguments, the first | ||
610 | argument must be cast to @code{intptr_t}. | ||
611 | |||
612 | @item MHD_OPTION_UNESCAPE_CALLBACK | ||
613 | @cindex internationalization | ||
614 | @cindex escaping | ||
615 | |||
616 | Specify a function that should be called for unescaping escape | ||
617 | sequences in URIs and URI arguments. Note that this function will NOT | ||
618 | be used by the MHD_PostProcessor. If this option is not specified, | ||
619 | the default method will be used which decodes escape sequences of the | ||
620 | form "%HH". This option should be followed by two arguments, the | ||
621 | first 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 | |||
627 | where the return value must be @code{strlen(s)} and @code{s} should be | ||
628 | updated. 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 | ||
631 | MHD_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 | ||
639 | Maximum stack size for threads created by MHD. This option must be | ||
640 | followed by a @code{size_t}). Not specifying this option or using | ||
641 | a value of zero means using the system default (which is likely to | ||
642 | differ based on your platform). | ||
643 | |||
644 | @end table | ||
645 | @end deftp | ||
646 | |||
647 | |||
648 | @deftp {C Struct} MHD_OptionItem | ||
649 | Entry in an MHD_OPTION_ARRAY. See the @code{MHD_OPTION_ARRAY} option | ||
650 | argument for its use. | ||
651 | |||
652 | The @code{option} member is used to specify which option is specified | ||
653 | in the array. The other members specify the respective argument. | ||
654 | |||
655 | Note that for options taking only a single pointer, the | ||
656 | @code{ptr_value} member should be set. For options taking two pointer | ||
657 | arguments, the first pointer must be cast to @code{intptr_t} and both | ||
658 | the @code{value} and the @code{ptr_value} members should be used to | ||
659 | pass the two pointers. | ||
660 | @end deftp | ||
661 | |||
662 | |||
663 | @deftp {Enumeration} MHD_ValueKind | ||
664 | The @code{MHD_ValueKind} specifies the source of the key-value pairs in | ||
665 | the HTTP protocol. | ||
666 | |||
667 | @table @code | ||
668 | @item MHD_RESPONSE_HEADER_KIND | ||
669 | Response header. | ||
670 | |||
671 | @item MHD_HEADER_KIND | ||
672 | HTTP header. | ||
673 | |||
674 | @item MHD_COOKIE_KIND | ||
675 | @cindex cookie | ||
676 | Cookies. Note that the original HTTP header containing the cookie(s) | ||
677 | will 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 | ||
682 | supported by MHD is used (currently only @acronym{URL} encoding), and | ||
683 | only if the posted content fits within the available memory pool. Note | ||
684 | that in that case, the upload data given to the | ||
685 | @code{MHD_AccessHandlerCallback()} will be empty (since it has | ||
686 | already been processed). | ||
687 | |||
688 | @item MHD_GET_ARGUMENT_KIND | ||
689 | @code{GET} (URI) arguments. | ||
690 | |||
691 | @item MHD_FOOTER_KIND | ||
692 | HTTP footer (only for http 1.1 chunked encodings). | ||
693 | |||
694 | @end table | ||
695 | @end deftp | ||
696 | |||
697 | |||
698 | @deftp {Enumeration} MHD_RequestTerminationCode | ||
699 | The @code{MHD_RequestTerminationCode} specifies reasons why a request | ||
700 | has been terminated (or completed). | ||
701 | |||
702 | @table @code | ||
703 | @item MHD_REQUEST_TERMINATED_COMPLETED_OK | ||
704 | We finished sending the response. | ||
705 | |||
706 | @item MHD_REQUEST_TERMINATED_WITH_ERROR | ||
707 | Error handling the connection (resources exhausted, other side closed | ||
708 | connection, application error accepting request, etc.) | ||
709 | |||
710 | @item MHD_REQUEST_TERMINATED_TIMEOUT_REACHED | ||
711 | No 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 | ||
715 | We had to close the session since MHD was being shut down. | ||
716 | @end table | ||
717 | @end deftp | ||
718 | |||
719 | |||
720 | @deftp {Enumeration} MHD_ResponseMemoryMode | ||
721 | The @code{MHD_ResponeMemoryMode} specifies how MHD should treat | ||
722 | the memory buffer given for the response in | ||
723 | @code{MHD_create_response_from_buffer}. | ||
724 | |||
725 | @table @code | ||
726 | @item MHD_RESPMEM_PERSISTENT | ||
727 | Buffer is a persistent (static/global) buffer that won't change | ||
728 | for at least the lifetime of the response, MHD should just use | ||
729 | it, not free it, not copy it, just keep an alias to it. | ||
730 | |||
731 | @item MHD_RESPMEM_MUST_FREE | ||
732 | Buffer is heap-allocated with @code{malloc} (or equivalent) and | ||
733 | should be freed by MHD after processing the response has | ||
734 | concluded (response reference counter reaches zero). | ||
735 | |||
736 | @item MHD_RESPMEM_MUST_COPY | ||
737 | Buffer is in transient memory, but not on the heap (for example, | ||
738 | on the stack or non-malloc allocated) and only valid during the | ||
739 | call to @code{MHD_create_response_from_buffer}. MHD must make its | ||
740 | own 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 | ||
756 | Handle for the daemon (listening on a socket for HTTP traffic). | ||
757 | @end deftp | ||
758 | |||
759 | |||
760 | @deftp {C Struct} MHD_Connection | ||
761 | Handle for a connection / HTTP request. With HTTP/1.1, multiple | ||
762 | requests can be run over the same connection. However, MHD will only | ||
763 | show one request per TCP connection to the client at any given time. | ||
764 | @end deftp | ||
765 | |||
766 | |||
767 | @deftp {C Struct} MHD_Response | ||
768 | Handle for a response. | ||
769 | @end deftp | ||
770 | |||
771 | |||
772 | @deftp {C Struct} MHD_PostProcessor | ||
773 | @cindex POST method | ||
774 | Handle for @code{POST} processing. | ||
775 | @end deftp | ||
776 | |||
777 | |||
778 | @deftp {C Union} MHD_ConnectionInfo | ||
779 | Information about a connection. | ||
780 | @end deftp | ||
781 | |||
782 | |||
783 | @deftp {C Union} MHD_DaemonInfo | ||
784 | Information 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) | ||
796 | Invoked in the context of a connection to allow or deny a client to | ||
797 | connect. This callback return @code{MHD_YES} if connection is allowed, | ||
798 | @code{MHD_NO} if not. | ||
799 | |||
800 | @table @var | ||
801 | @item cls | ||
802 | custom value selected at callback registration time; | ||
803 | @item addr | ||
804 | address information from the client; | ||
805 | @item addrlen | ||
806 | length 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) | ||
812 | Invoked in the context of a connection to answer a request from the | ||
813 | client. This callback must call MHD functions (example: the | ||
814 | @code{MHD_Response} ones) to provide content to give back to the client | ||
815 | and return an HTTP status code (i.e. @code{200} for OK, @code{404}, | ||
816 | etc.). | ||
817 | |||
818 | @ref{microhttpd-post}, for details on how to code this callback. | ||
819 | |||
820 | Must 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 | ||
822 | handling the request | ||
823 | |||
824 | @table @var | ||
825 | @item cls | ||
826 | custom value selected at callback registration time; | ||
827 | |||
828 | @item url | ||
829 | the URL requested by the client; | ||
830 | |||
831 | @item method | ||
832 | the HTTP method used by the client (@code{GET}, @code{PUT}, | ||
833 | @code{DELETE}, @code{POST}, etc.); | ||
834 | |||
835 | @item version | ||
836 | the HTTP version string (i.e. @code{HTTP/1.1}); | ||
837 | |||
838 | @item upload_data | ||
839 | the data being uploaded (excluding headers): | ||
840 | @cindex POST method | ||
841 | @cindex PUT method | ||
842 | |||
843 | @itemize | ||
844 | @item | ||
845 | for a @code{POST} that fits into memory and that is encoded with a | ||
846 | supported 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 | ||
851 | very large @code{POST} data @strong{will} be made available | ||
852 | incrementally in @var{upload_data}; | ||
853 | @end itemize | ||
854 | |||
855 | @item upload_data_size | ||
856 | set initially to the size of the @var{upload_data} provided; this | ||
857 | callback must update this value to the number of bytes @strong{NOT} | ||
858 | processed; unless external select is used, the callback maybe | ||
859 | required to process at least some data. If the callback fails to | ||
860 | process data in multi-threaded or internal-select mode and if the | ||
861 | read-buffer is already at the maximum size that MHD is willing to | ||
862 | use for reading (about half of the maximum amount of memory allowed | ||
863 | for the connection), then MHD will abort handling the connection | ||
864 | and return an internal server error to the client. In order to | ||
865 | avoid this, clients must be able to process upload data incrementally | ||
866 | and reduce the value of @code{upload_data_size}. | ||
867 | |||
868 | @item con_cls | ||
869 | reference to a pointer, initially set to @code{NULL}, that this callback can | ||
870 | set to some address and that will be preserved by MHD for future | ||
871 | calls for this request; | ||
872 | |||
873 | since 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 | ||
875 | the application to easily associate some request-specific state; | ||
876 | |||
877 | if 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) | ||
885 | Signature of the callback used by MHD to notify the application about | ||
886 | completed requests. | ||
887 | |||
888 | @table @var | ||
889 | @item cls | ||
890 | custom value selected at callback registration time; | ||
891 | |||
892 | @item connection | ||
893 | connection handle; | ||
894 | |||
895 | @item con_cls | ||
896 | value as set by the last call to the | ||
897 | @code{MHD_AccessHandlerCallback}; | ||
898 | |||
899 | @item toe | ||
900 | reason 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) | ||
906 | Iterator over key-value pairs. This iterator can be used to iterate | ||
907 | over all of the cookies, headers, or @code{POST}-data fields of a | ||
908 | request, and also to iterate over the headers that have been added to a | ||
909 | response. | ||
910 | |||
911 | Return @code{MHD_YES} to continue iterating, @code{MHD_NO} to abort the | ||
912 | iteration. | ||
913 | @end deftypefn | ||
914 | |||
915 | |||
916 | @deftypefn {Function Pointer} int {*MHD_ContentReaderCallback} (void *cls, uint64_t pos, char *buf, size_t max) | ||
917 | Callback used by MHD in order to obtain content. The callback has to | ||
918 | copy at most @var{max} bytes of content into @var{buf}. The total | ||
919 | number of bytes that has been placed into @var{buf} should be returned. | ||
920 | |||
921 | Note that returning zero will cause MHD to try again, either | ||
922 | ``immediately'' if in multi-threaded mode (in which case the callback | ||
923 | may want to do blocking operations to avoid busy waiting) or in the | ||
924 | next round if @code{MHD_run} is used. Returning zero for a daemon | ||
925 | that runs in internal @code{select}-mode is an error (since it | ||
926 | would result in busy waiting) and cause the program to be aborted | ||
927 | (@code{abort()}). | ||
928 | |||
929 | While usually the callback simply returns the number of bytes written | ||
930 | into @var{buf}, there are two special return value: | ||
931 | |||
932 | @code{MHD_CONTENT_READER_END_OF_STREAM} (-1) should be returned | ||
933 | for the regular end of transmission (with chunked encoding, MHD will then | ||
934 | terminate the chunk and send any HTTP footers that might be | ||
935 | present; without chunked encoding and given an unknown | ||
936 | response size, MHD will simply close the connection; note | ||
937 | that while returning @code{MHD_CONTENT_READER_END_OF_STREAM} is not technically | ||
938 | legal if a response size was specified, MHD accepts this | ||
939 | and 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 | ||
942 | error generating the response; this will cause MHD to simply | ||
943 | close the connection immediately. If a response size was | ||
944 | given or if chunked encoding is in use, this will indicate | ||
945 | an error to the client. Note, however, that if the client | ||
946 | does not know a response size and chunked encoding is not in | ||
947 | use, 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}. | ||
950 | This is not a limitation of MHD but rather of the HTTP protocol. | ||
951 | |||
952 | @table @var | ||
953 | @item cls | ||
954 | custom value selected at callback registration time; | ||
955 | |||
956 | @item pos | ||
957 | position in the datastream to access; note that if an | ||
958 | @code{MHD_Response} object is re-used, it is possible for the same | ||
959 | content reader to be queried multiple times for the same data; however, | ||
960 | if 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 | ||
962 | from the content reader so far. | ||
963 | @end table | ||
964 | |||
965 | Return @code{-1} on error (MHD will no longer try to read content and | ||
966 | instead close the connection with the client). | ||
967 | @end deftypefn | ||
968 | |||
969 | |||
970 | @deftypefn {Function Pointer} void {*MHD_ContentReaderFreeCallback} (void *cls) | ||
971 | This method is called by MHD if we are done with a content reader. | ||
972 | It 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) | ||
977 | Iterator over key-value pairs where the value maybe made available in | ||
978 | increments and/or may not be zero-terminated. Used for processing | ||
979 | @code{POST} data. | ||
980 | |||
981 | @table @var | ||
982 | @item cls | ||
983 | custom value selected at callback registration time; | ||
984 | |||
985 | @item kind | ||
986 | type of the value; | ||
987 | |||
988 | @item key | ||
989 | zero-terminated key for the value; | ||
990 | |||
991 | @item filename | ||
992 | name of the uploaded file, @code{NULL} if not known; | ||
993 | |||
994 | @item content_type | ||
995 | mime-type of the data, @code{NULL} if not known; | ||
996 | |||
997 | @item transfer_encoding | ||
998 | encoding of the data, @code{NULL} if not known; | ||
999 | |||
1000 | @item data | ||
1001 | pointer to size bytes of data at the specified offset; | ||
1002 | |||
1003 | @item off | ||
1004 | offset of data in the overall value; | ||
1005 | |||
1006 | @item size | ||
1007 | number of bytes in data available. | ||
1008 | @end table | ||
1009 | |||
1010 | Return @code{MHD_YES} to continue iterating, @code{MHD_NO} to abort the | ||
1011 | iteration. | ||
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) | ||
1022 | Set a handler for fatal errors. | ||
1023 | |||
1024 | @table @var | ||
1025 | @item cb | ||
1026 | function to call if MHD encounters a fatal internal error. If no handler was set explicitly, MHD will call @code{abort}. | ||
1027 | |||
1028 | @item cls | ||
1029 | 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}) | ||
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, ...) | ||
1034 | Start a webserver on the given port. | ||
1035 | |||
1036 | @table @var | ||
1037 | @item flags | ||
1038 | OR-ed combination of @code{MHD_FLAG} values; | ||
1039 | |||
1040 | @item port | ||
1041 | port to bind to; | ||
1042 | |||
1043 | @item apc | ||
1044 | callback to call to check which clients will be allowed to connect; you | ||
1045 | can pass @code{NULL} in which case connections from any @acronym{IP} will be | ||
1046 | accepted; | ||
1047 | |||
1048 | @item apc_cls | ||
1049 | extra argument to @var{apc}; | ||
1050 | |||
1051 | @item dh | ||
1052 | default handler for all URIs; | ||
1053 | |||
1054 | @item dh_cls | ||
1055 | extra argument to @var{dh}. | ||
1056 | @end table | ||
1057 | |||
1058 | Additional arguments are a list of options (type-value pairs, | ||
1059 | terminated with @code{MHD_OPTION_END}). It is mandatory to use | ||
1060 | @code{MHD_OPTION_END} as last argument, even when there are no | ||
1061 | additional arguments. | ||
1062 | |||
1063 | Return @code{NULL} on error, handle to daemon on success. | ||
1064 | @end deftypefun | ||
1065 | |||
1066 | |||
1067 | @deftypefun void MHD_stop_daemon (struct MHD_Daemon *daemon) | ||
1068 | Shutdown an HTTP daemon. | ||
1069 | @end deftypefun | ||
1070 | |||
1071 | |||
1072 | @deftypefun int MHD_run (struct MHD_Daemon *daemon) | ||
1073 | Run webserver operations (without blocking unless in client callbacks). | ||
1074 | This method should be called by clients in combination with | ||
1075 | @code{MHD_get_fdset()} if the client-controlled @code{select}-method is used. | ||
1076 | |||
1077 | Return @code{MHD_YES} on success, @code{MHD_NO} if this daemon was not | ||
1078 | started 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) | ||
1083 | Add another client connection to the set of connections | ||
1084 | managed by MHD. This API is usually not needed (since | ||
1085 | MHD will accept inbound connections on the server socket). | ||
1086 | Use this API in special cases, for example if your HTTP | ||
1087 | server is behind NAT and needs to connect out to the | ||
1088 | HTTP client. | ||
1089 | |||
1090 | The given client socket will be managed (and closed!) by MHD after | ||
1091 | this call and must no longer be used directly by the application | ||
1092 | afterwards. | ||
1093 | |||
1094 | @table @var | ||
1095 | @item daemon | ||
1096 | daemon that manages the connection | ||
1097 | @item client_socket | ||
1098 | socket to manage (MHD will expect to receive an HTTP request from this socket next). | ||
1099 | @item addr | ||
1100 | IP address of the client | ||
1101 | @item addrlen | ||
1102 | number of bytes in addr | ||
1103 | @end table | ||
1104 | |||
1105 | This function will return @code{MHD_YES} on success, | ||
1106 | @code{MHD_NO} if this daemon could | ||
1107 | not handle the connection (i.e. malloc failed, etc). | ||
1108 | The 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) | ||
1120 | Obtain the @code{select()} sets for this daemon. The daemon's socket | ||
1121 | is added to @var{read_fd_set}. The list of currently existent | ||
1122 | connections is scanned and their file descriptors added to the correct | ||
1123 | set. | ||
1124 | |||
1125 | After the call completed successfully: the variable referenced by | ||
1126 | @var{max_fd} references the file descriptor with highest integer | ||
1127 | identifier. The variable must be set to zero before invoking this | ||
1128 | function. | ||
1129 | |||
1130 | Return @code{MHD_YES} on success, @code{MHD_NO} if: the arguments are | ||
1131 | invalid (example: @code{NULL} pointers); this daemon was not started with | ||
1132 | the 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 | ||
1138 | Obtain timeout value for select for this daemon (only needed if | ||
1139 | connection timeout is used). The returned value is how long | ||
1140 | @code{select} should at most block, not the timeout value set for | ||
1141 | connections. This function must not be called if the | ||
1142 | @code{MHD_USE_THREAD_PER_CONNECTION} mode is in use (since then it | ||
1143 | is not meaningful to ask for a timeout, after all, there is | ||
1144 | concurrenct activity). The function must also not be called by | ||
1145 | user-code if @code{MHD_USE_INTERNAL_SELECT} is in use. In the latter | ||
1146 | case, the behavior is undefined. | ||
1147 | |||
1148 | @table @var | ||
1149 | @cindex timeout | ||
1150 | set to the timeout (in milliseconds). | ||
1151 | @end table | ||
1152 | |||
1153 | Return @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 | ||
1155 | right 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) | ||
1167 | Get all the headers matching @var{kind} from the request. | ||
1168 | |||
1169 | The @var{iterator} callback is invoked once for each header, with | ||
1170 | @var{iterator_cls} as first argument. After version 0.9.19, the | ||
1171 | headers are iterated in the same order as they were received from | ||
1172 | the network; previous versions iterated over the headers in reverse | ||
1173 | order. | ||
1174 | |||
1175 | @code{MHD_get_connection_values} returns the number of entries | ||
1176 | iterated over; this can be less than the number of headers if, while | ||
1177 | iterating, @var{iterator} returns @code{MHD_NO}. | ||
1178 | |||
1179 | @var{iterator} can be @code{NULL}: in this case this function just counts | ||
1180 | and returns the number of headers. | ||
1181 | |||
1182 | In the case of @code{MHD_GET_ARGUMENT_KIND}, the @var{value} argument | ||
1183 | will be @code{NULL} if the URL contained a key without an equals operator. | ||
1184 | For 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. | ||
1187 | The normal case is that the URL contains ``http://foo/bar?key=value'' | ||
1188 | in which case @var{value} would be the string ``value'' and @var{key} | ||
1189 | would 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) | ||
1194 | This function can be used to append an entry to | ||
1195 | the list of HTTP headers of a connection (so that the | ||
1196 | @code{MHD_get_connection_values function} will return | ||
1197 | them -- and the MHD PostProcessor will also | ||
1198 | see them). This maybe required in certain | ||
1199 | situations (see Mantis #1399) where (broken) | ||
1200 | HTTP implementations fail to supply values needed | ||
1201 | by the post processor (or other parts of the | ||
1202 | application). | ||
1203 | |||
1204 | This function MUST only be called from within | ||
1205 | the MHD_AccessHandlerCallback (otherwise, access | ||
1206 | maybe improperly synchronized). Furthermore, | ||
1207 | the client must guarantee that the key and | ||
1208 | value arguments are 0-terminated strings that | ||
1209 | are NOT freed until the connection is closed. | ||
1210 | (The easiest way to do this is by passing only | ||
1211 | arguments to permanently allocated strings.). | ||
1212 | |||
1213 | @var{connection} is the connection for which | ||
1214 | the entry for @var{key} of the given @var{kind} | ||
1215 | should be set to the given @var{value}. | ||
1216 | |||
1217 | The function returns @code{MHD_NO} if the operation | ||
1218 | could not be performed due to insufficient memory | ||
1219 | and @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) | ||
1224 | Get 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 | ||
1227 | representing the header to look for: it is compared against the | ||
1228 | headers 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 | ||
1230 | key, for example if a URI is of the form | ||
1231 | ``http://example.com/?trailer'', a @var{key} of @code{NULL} can be used to | ||
1232 | access ``tailer" The function returns @code{NULL} if no matching item | ||
1233 | was 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 | ||
1245 | Response objects handling by MHD is asynchronous with respect to the | ||
1246 | application execution flow. Instances of the @code{MHD_Response} | ||
1247 | structure are not associated to a daemon and neither to a client | ||
1248 | connection: they are managed with reference counting. | ||
1249 | |||
1250 | In the simplest case: we allocate a new @code{MHD_Response} structure | ||
1251 | for each response, we use it once and finally we destroy it. | ||
1252 | |||
1253 | MHD allows more efficient resources usages. | ||
1254 | |||
1255 | Example: we allocate a new @code{MHD_Response} structure for each | ||
1256 | response @strong{kind}, we use it every time we have to give that | ||
1257 | response 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) | ||
1274 | Queue a response to be transmitted to the client as soon as possible | ||
1275 | but only after MHD_AccessHandlerCallback returns. This function | ||
1276 | checks that it is legal to queue a response at this time for the | ||
1277 | given connection. It also increments the internal reference | ||
1278 | counter for the response object (the counter will be decremented | ||
1279 | automatically once the response has been transmitted). | ||
1280 | |||
1281 | @table @var | ||
1282 | @item connection | ||
1283 | the connection identifying the client; | ||
1284 | |||
1285 | @item status_code | ||
1286 | HTTP status code (i.e. @code{200} for OK); | ||
1287 | |||
1288 | @item response | ||
1289 | response to transmit. | ||
1290 | @end table | ||
1291 | |||
1292 | Return @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 | ||
1294 | error (i.e. reply already sent). | ||
1295 | @end deftypefun | ||
1296 | |||
1297 | |||
1298 | @deftypefun void MHD_destroy_response (struct MHD_Response *response) | ||
1299 | Destroy a response object and associated resources (decrement the | ||
1300 | reference counter). Note that MHD may keep some of the resources | ||
1301 | around if the response is still in the queue for some clients, so the | ||
1302 | memory may not necessarily be freed immediately. | ||
1303 | @end deftypefun | ||
1304 | |||
1305 | |||
1306 | An explanation of reference counting@footnote{Note to readers acquainted | ||
1307 | to the Tcl API: reference counting on @code{MHD_Connection} | ||
1308 | structures is handled in the same way as Tcl handles @code{Tcl_Obj} | ||
1309 | structures through @code{Tcl_IncrRefCount()} and | ||
1310 | @code{Tcl_DecrRefCount()}.}: | ||
1311 | |||
1312 | @enumerate | ||
1313 | @item | ||
1314 | a @code{MHD_Response} object is allocated: | ||
1315 | |||
1316 | @example | ||
1317 | struct MHD_Response * response = MHD_create_response_from_buffer(...); | ||
1318 | /* here: reference counter = 1 */ | ||
1319 | @end example | ||
1320 | |||
1321 | @item | ||
1322 | the @code{MHD_Response} object is enqueued in a @code{MHD_Connection}: | ||
1323 | |||
1324 | @example | ||
1325 | MHD_queue_response(connection, , response); | ||
1326 | /* here: reference counter = 2 */ | ||
1327 | @end example | ||
1328 | |||
1329 | @item | ||
1330 | the creator of the response object discharges responsibility for it: | ||
1331 | |||
1332 | @example | ||
1333 | MHD_destroy_response(response); | ||
1334 | /* here: reference counter = 1 */ | ||
1335 | @end example | ||
1336 | |||
1337 | @item | ||
1338 | the daemon handles the connection sending the response's data to the | ||
1339 | client then decrements the reference counter by calling | ||
1340 | @code{MHD_destroy_response()}: the counter's value drops to zero and | ||
1341 | the @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) | ||
1353 | Create a response object. The response object can be extended with | ||
1354 | header information and then it can be used any number of times. | ||
1355 | |||
1356 | @table @var | ||
1357 | @item size | ||
1358 | size of the data portion of the response, @code{-1} for unknown; | ||
1359 | |||
1360 | @item block_size | ||
1361 | preferred block size for querying @var{crc} (advisory only, MHD may | ||
1362 | still call @var{crc} using smaller chunks); this is essentially the | ||
1363 | buffer size used for @acronym{IO}, clients should pick a value that is | ||
1364 | appropriate for @acronym{IO} and memory performance requirements; | ||
1365 | |||
1366 | @item crc | ||
1367 | callback to use to obtain response data; | ||
1368 | |||
1369 | @item crc_cls | ||
1370 | extra argument to @var{crc}; | ||
1371 | |||
1372 | @item crfc | ||
1373 | callback to call to free @var{crc_cls} resources. | ||
1374 | @end table | ||
1375 | |||
1376 | Return @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) | ||
1382 | Create a response object. The response object can be extended with | ||
1383 | header information and then it can be used any number of times. | ||
1384 | |||
1385 | @table @var | ||
1386 | @item size | ||
1387 | size of the data portion of the response (should be smaller or equal to the | ||
1388 | size of the file) | ||
1389 | |||
1390 | @item fd | ||
1391 | file descriptor referring to a file on disk with the data; will be | ||
1392 | closed when response is destroyed; note that 'fd' must be an actual | ||
1393 | file descriptor (not a pipe or socket) since MHD might use 'sendfile' | ||
1394 | or 'seek' on it. The descriptor should be in blocking-IO mode. | ||
1395 | @end table | ||
1396 | |||
1397 | Return @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) | ||
1402 | Create a response object. The response object can be extended with | ||
1403 | header information and then it can be used any number of times. | ||
1404 | Note that you need to be a bit careful about @code{off_t} when | ||
1405 | writing this code. Depending on your platform, MHD is likely | ||
1406 | to have been compiled with support for 64-bit files. When you | ||
1407 | compile your own application, you must make sure that @code{off_t} | ||
1408 | is also a 64-bit value. If not, your compiler may pass a 32-bit | ||
1409 | value as @code{off_t}, which will result in 32-bits of garbage. | ||
1410 | |||
1411 | If you use the autotools, use the @code{AC_SYS_LARGEFILE} autoconf | ||
1412 | macro and make sure to include the generated @file{config.h} file | ||
1413 | before @file{microhttpd.h} to avoid problems. If you do not have a | ||
1414 | build system and only want to run on a GNU/Linux system, you could | ||
1415 | also 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 | ||
1423 | to ensure 64-bit @code{off_t}. Note that if your operating system | ||
1424 | does 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 | ||
1429 | size of the data portion of the response (number of bytes to transmit from the | ||
1430 | file starting at offset). | ||
1431 | |||
1432 | @item fd | ||
1433 | file descriptor referring to a file on disk with the data; will be | ||
1434 | closed when response is destroyed; note that 'fd' must be an actual | ||
1435 | file descriptor (not a pipe or socket) since MHD might use 'sendfile' | ||
1436 | or 'seek' on it. The descriptor should be in blocking-IO mode. | ||
1437 | |||
1438 | @item offset | ||
1439 | offset to start reading from in the file | ||
1440 | @end table | ||
1441 | |||
1442 | Return @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) | ||
1447 | Create a response object. The response object can be extended with | ||
1448 | header information and then it can be used any number of times. | ||
1449 | |||
1450 | @table @var | ||
1451 | @item size | ||
1452 | size of the data portion of the response; | ||
1453 | |||
1454 | @item buffer | ||
1455 | the data itself; | ||
1456 | |||
1457 | @item mode | ||
1458 | memory management options for buffer; use | ||
1459 | MHD_RESPMEM_PERSISTENT if the buffer is static/global memory, | ||
1460 | use MHD_RESPMEM_MUST_FREE if the buffer is heap-allocated and | ||
1461 | should be freed by MHD and MHD_RESPMEM_MUST_COPY if the | ||
1462 | buffer is in transient memory (i.e. on the stack) and must | ||
1463 | be copied by MHD; | ||
1464 | @end table | ||
1465 | |||
1466 | Return @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) | ||
1471 | Create a response object. The response object can be extended with | ||
1472 | header information and then it can be used any number of times. | ||
1473 | This function is deprecated, use @code{MHD_create_response_from_buffer} instead. | ||
1474 | |||
1475 | @table @var | ||
1476 | @item size | ||
1477 | size of the data portion of the response; | ||
1478 | |||
1479 | @item data | ||
1480 | the data itself; | ||
1481 | |||
1482 | @item must_free | ||
1483 | if true: MHD should free data when done; | ||
1484 | |||
1485 | @item must_copy | ||
1486 | if 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; | ||
1488 | handling of the embedded memory is responsibility of MHD; @var{data} | ||
1489 | can be released anytime after this call returns. | ||
1490 | @end table | ||
1491 | |||
1492 | Return @code{NULL} on error (i.e. invalid arguments, out of memory). | ||
1493 | @end deftypefun | ||
1494 | |||
1495 | |||
1496 | Example: create a response from a statically allocated string: | ||
1497 | |||
1498 | @example | ||
1499 | const char * data = "<html><body><p>Error!</p></body></html>"; | ||
1500 | |||
1501 | struct MHD_Connection * connection = ...; | ||
1502 | struct MHD_Response * response; | ||
1503 | |||
1504 | response = MHD_create_response_from_buffer (strlen(data), data, | ||
1505 | MHD_RESPMEM_PERSISTENT); | ||
1506 | MHD_queue_response(connection, 404, response); | ||
1507 | MHD_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) | ||
1520 | Add a header line to the response. The strings referenced by | ||
1521 | @var{header} and @var{content} must be zero-terminated and they are | ||
1522 | duplicated into memory blocks embedded in @var{response}. | ||
1523 | |||
1524 | Notice that the strings must not hold newlines, carriage returns or tab | ||
1525 | chars. | ||
1526 | |||
1527 | Return @code{MHD_NO} on error (i.e. invalid header or content format or | ||
1528 | memory allocation error). | ||
1529 | @end deftypefun | ||
1530 | |||
1531 | |||
1532 | @deftypefun int MHD_add_response_footer (struct MHD_Response *response, const char *footer, const char *content) | ||
1533 | Add a footer line to the response. The strings referenced by | ||
1534 | @var{footer} and @var{content} must be zero-terminated and they are | ||
1535 | duplicated into memory blocks embedded in @var{response}. | ||
1536 | |||
1537 | Notice that the strings must not hold newlines, carriage returns or tab | ||
1538 | chars. You can add response footers at any time before signalling the | ||
1539 | end of the response to MHD (not just before calling 'MHD_queue_response'). | ||
1540 | Footers are useful for adding cryptographic checksums to the reply or to | ||
1541 | signal errors encountered during data generation. This call was introduced | ||
1542 | in MHD 0.9.3. | ||
1543 | |||
1544 | Return @code{MHD_NO} on error (i.e. invalid header or content format or | ||
1545 | memory 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) | ||
1551 | Delete 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) | ||
1564 | Get all of the headers added to a response. | ||
1565 | |||
1566 | Invoke the @var{iterator} callback for each header in the response, | ||
1567 | using @var{iterator_cls} as first argument. Return number of entries | ||
1568 | iterated over. @var{iterator} can be @code{NULL}: in this case the function | ||
1569 | just counts headers. | ||
1570 | |||
1571 | @var{iterator} should not modify the its key and value arguments, unless | ||
1572 | we 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) | ||
1577 | Find and return a pointer to the value of a particular header from the | ||
1578 | response. @var{key} must reference a zero-terminated string | ||
1579 | representing the header to look for. The search is case sensitive. | ||
1580 | Return @code{NULL} if header does not exist or @var{key} is @code{NULL}. | ||
1581 | |||
1582 | We 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 | ||
1593 | MHD support three types of client authentication. | ||
1594 | |||
1595 | Basic authentication uses a simple authentication method based | ||
1596 | on BASE64 algorithm. Username and password are exchanged in clear | ||
1597 | between the client and the server, so this method must only be used | ||
1598 | for non-sensitive content or when the session is protected with https. | ||
1599 | When using basic authentication MHD will have access to the clear | ||
1600 | password, possibly allowing to create a chained authentication | ||
1601 | toward an external authentication server. | ||
1602 | |||
1603 | Digest authentication uses a one-way authentication method based | ||
1604 | on MD5 hash algorithm. Only the hash will transit over the network, | ||
1605 | hence protecting the user password. The nonce will prevent replay | ||
1606 | attacks. This method is appropriate for general use, especially | ||
1607 | when https is not used to encrypt the session. | ||
1608 | |||
1609 | Client certificate authentication uses a X.509 certificate from | ||
1610 | the client. This is the strongest authentication mechanism but it | ||
1611 | requires the use of HTTPS. Client certificate authentication can | ||
1612 | be used simultaneously with Basic or Digest Authentication in order | ||
1613 | to provide a two levels authentication (like for instance separate | ||
1614 | machine and user authentication). A code example for using | ||
1615 | client 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) | ||
1629 | Get the username and password from the basic authorization header sent by the client. | ||
1630 | Return @code{NULL} if no username could be found, a pointer to the username if found. | ||
1631 | If 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}. | ||
1634 | If 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) | ||
1638 | Queues a response to request basic authentication from the client. | ||
1639 | Return @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 | ||
1644 | client 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) | ||
1654 | Find and return a pointer to the username value from the request header. | ||
1655 | Return @code{NULL} if the value is not found or header does not exist. | ||
1656 | If 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) | ||
1660 | Checks if the provided values in the WWW-Authenticate header are valid | ||
1661 | and 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, | ||
1666 | it 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, | ||
1669 | most 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. | ||
1672 | Most 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) | ||
1676 | Queues a response to request authentication from the client, | ||
1677 | return @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 | ||
1682 | that gets passed to the client and expected to be passed again to the server | ||
1683 | as-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 | ||
1686 | client with a 401 HTTP status. | ||
1687 | |||
1688 | @var{signal_stale} a value that signals "stale=true" in the response header to | ||
1689 | indicate the invalidity of the nonce and no need to ask for authentication | ||
1690 | parameters and only a new nonce gets generated. @code{MHD_YES} to generate a new | ||
1691 | nonce, @code{MHD_NO} to ask for authentication parameters. | ||
1692 | @end deftypefun | ||
1693 | |||
1694 | Example: 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 | |||
1701 | static int | ||
1702 | ahc_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 | ||
1770 | MHD provides the post processor API to make it easier for applications to | ||
1771 | parse the data of a client's @code{POST} request: the | ||
1772 | @code{MHD_AccessHandlerCallback} will be invoked multiple times to | ||
1773 | process data as it arrives; at each invocation a new chunk of data must | ||
1774 | be processed. The arguments @var{upload_data} and @var{upload_data_size} | ||
1775 | are used to reference the chunk of data. | ||
1776 | |||
1777 | When @code{MHD_AccessHandlerCallback} is invoked for a new connection: | ||
1778 | its @code{*@var{con_cls}} argument is set to @code{NULL}. When @code{POST} | ||
1779 | data 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 | ||
1781 | that the pointer was initially @code{NULL} can be used to detect that | ||
1782 | this is a new request. | ||
1783 | |||
1784 | One method to detect that a new connection was established is | ||
1785 | to set @code{*con_cls} to an unused integer: | ||
1786 | |||
1787 | @example | ||
1788 | int | ||
1789 | access_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 | ||
1810 | In contrast to the previous example, for @code{POST} requests in particular, | ||
1811 | it is more common to use the value of @code{*con_cls} to keep track of | ||
1812 | actual state used during processing, such as the post processor (or a | ||
1813 | struct containing a post processor): | ||
1814 | |||
1815 | @example | ||
1816 | int | ||
1817 | access_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 | |||
1846 | Note that the callback from @code{MHD_OPTION_NOTIFY_COMPLETED} | ||
1847 | should be used to destroy the post processor. This cannot be | ||
1848 | done inside of the access handler since the connection may not | ||
1849 | always 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) | ||
1860 | Create a PostProcessor. A PostProcessor can be used to (incrementally) | ||
1861 | parse the data portion of a @code{POST} request. | ||
1862 | |||
1863 | @table @var | ||
1864 | @item connection | ||
1865 | the connection on which the @code{POST} is happening (used to determine | ||
1866 | the @code{POST} format); | ||
1867 | |||
1868 | @item buffer_size | ||
1869 | maximum number of bytes to use for internal buffering (used only for the | ||
1870 | parsing, specifically the parsing of the keys). A tiny value (256-1024) | ||
1871 | should be sufficient; do @strong{NOT} use a value smaller than 256; | ||
1872 | |||
1873 | @item iterator | ||
1874 | iterator to be called with the parsed data; must @strong{NOT} be | ||
1875 | @code{NULL}; | ||
1876 | |||
1877 | @item iterator_cls | ||
1878 | custom value to be used as first argument to @var{iterator}. | ||
1879 | @end table | ||
1880 | |||
1881 | Return @code{NULL} on error (out of memory, unsupported encoding), otherwise | ||
1882 | a 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) | ||
1887 | Parse and process @code{POST} data. Call this function when @code{POST} | ||
1888 | data is available (usually during an @code{MHD_AccessHandlerCallback}) | ||
1889 | with the @var{upload_data} and @var{upload_data_size}. Whenever | ||
1890 | possible, this will then cause calls to the | ||
1891 | @code{MHD_IncrementalKeyValueIterator}. | ||
1892 | |||
1893 | @table @var | ||
1894 | @item pp | ||
1895 | the post processor; | ||
1896 | |||
1897 | @item post_data | ||
1898 | @var{post_data_len} bytes of @code{POST} data; | ||
1899 | |||
1900 | @item post_data_len | ||
1901 | length of @var{post_data}. | ||
1902 | @end table | ||
1903 | |||
1904 | Return @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) | ||
1910 | Release PostProcessor resources. After this function is being called, | ||
1911 | the PostProcessor is guaranteed to no longer call its iterator. There | ||
1912 | is no special call to the iterator to indicate the end of the post processing | ||
1913 | stream. After destroying the PostProcessor, the programmer should | ||
1914 | perform any necessary work to complete the processing of the iterator. | ||
1915 | |||
1916 | Return @code{MHD_YES} if processing completed nicely, @code{MHD_NO} | ||
1917 | if there were spurious characters or formatting problems with | ||
1918 | the post request. It is common to ignore the return value | ||
1919 | of 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, ...) | ||
1945 | Obtain information about the given daemon. This function | ||
1946 | is currently not fully implemented. | ||
1947 | |||
1948 | @table @var | ||
1949 | @item daemon | ||
1950 | the daemon about which information is desired; | ||
1951 | |||
1952 | @item infoType | ||
1953 | type of information that is desired | ||
1954 | |||
1955 | @item ... | ||
1956 | additional arguments about the desired information (depending on | ||
1957 | infoType) | ||
1958 | @end table | ||
1959 | |||
1960 | Returns a union with the respective member (depending on | ||
1961 | infoType) set to the desired information), or @code{NULL} | ||
1962 | in case the desired information is not available or | ||
1963 | applicable. | ||
1964 | @end deftypefun | ||
1965 | |||
1966 | |||
1967 | @deftp {Enumeration} MHD_DaemonInfoType | ||
1968 | Values of this enum are used to specify what | ||
1969 | information about a daemon is desired. | ||
1970 | @table @code | ||
1971 | @item MHD_DAEMON_INFO_KEY_SIZE | ||
1972 | Request information about the key size for a particular cipher | ||
1973 | algorithm. 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 | ||
1977 | Request information about the key size for a particular cipher | ||
1978 | algorithm. 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 | ||
1983 | Request the file-descriptor number that MHD is using to listen to the | ||
1984 | server socket. This can be useful if no port | ||
1985 | was specified and a client needs to learn what port | ||
1986 | is actually being used by MHD. | ||
1987 | No 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, ...) | ||
2000 | Obtain information about the given connection. | ||
2001 | |||
2002 | @table @var | ||
2003 | @item connection | ||
2004 | the connection about which information is desired; | ||
2005 | |||
2006 | @item infoType | ||
2007 | type of information that is desired | ||
2008 | |||
2009 | @item ... | ||
2010 | additional arguments about the desired information (depending on | ||
2011 | infoType) | ||
2012 | @end table | ||
2013 | |||
2014 | Returns a union with the respective member (depending on | ||
2015 | infoType) set to the desired information), or @code{NULL} | ||
2016 | in case the desired information is not available or | ||
2017 | applicable. | ||
2018 | @end deftypefun | ||
2019 | |||
2020 | @deftp {Enumeration} MHD_ConnectionInfoType | ||
2021 | Values of this enum are used to specify what information about a | ||
2022 | connection is desired. | ||
2023 | |||
2024 | @table @code | ||
2025 | |||
2026 | @item MHD_CONNECTION_INFO_CIPHER_ALGO | ||
2027 | What cipher algorithm is being used (HTTPS connections only). | ||
2028 | Takes no extra arguments. | ||
2029 | @code{NULL} is returned for non-HTTPS connections. | ||
2030 | |||
2031 | @item MHD_CONNECTION_INFO_PROTOCOL, | ||
2032 | Takes 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 | ||
2037 | Returns information about the address of the client. Returns | ||
2038 | essentially a @code{struct sockaddr **} (since the API returns | ||
2039 | a @code{union MHD_ConnectionInfo *} and that union contains | ||
2040 | a @code{struct sockaddr *}). | ||
2041 | |||
2042 | @item MHD_CONNECTION_INFO_GNUTLS_SESSION, | ||
2043 | Takes no extra arguments. Allows access to the underlying GNUtls session, | ||
2044 | including 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, | ||
2049 | Dysfunctional (never implemented, deprecated). Use | ||
2050 | MHD_CONNECTION_INFO_GNUTLS_SESSION to get the @code{gnutls_session_t} | ||
2051 | and then call @code{gnutls_certificate_get_peers()}. | ||
2052 | |||
2053 | @item MHD_CONNECTION_INFO_DAEMON | ||
2054 | Returns information about @code{struct MHD_Daemon} which manages | ||
2055 | this 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, ...) | ||
2070 | Set a custom option for the given connection. | ||
2071 | |||
2072 | @table @var | ||
2073 | @item connection | ||
2074 | the connection for which an option should be set or modified; | ||
2075 | |||
2076 | @item option | ||
2077 | option to set | ||
2078 | |||
2079 | @item ... | ||
2080 | additional arguments for the option (depending on option) | ||
2081 | @end table | ||
2082 | |||
2083 | Returns @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 | ||
2089 | Values of this enum are used to specify which option for a | ||
2090 | connection should be changed. | ||
2091 | |||
2092 | @table @code | ||
2093 | |||
2094 | @item MHD_CONNECTION_OPTION_TIMEOUT | ||
2095 | Set a custom timeout for the given connection. Specified | ||
2096 | as the number of seconds, given as an @code{unsigned int}. Use | ||
2097 | zero 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 | ||