aboutsummaryrefslogtreecommitdiff
path: root/src/include/microhttpd2.h
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-09-12 10:52:08 +0200
committerChristian Grothoff <christian@grothoff.org>2017-09-12 10:52:08 +0200
commit866fb1e020d8b5e1643d90ea2406ce0c56286449 (patch)
tree55217325890eca7548c98ce9038946da689a577a /src/include/microhttpd2.h
parent4adf1c6d1744e1ac4cb0c88817a3726c3038b919 (diff)
downloadlibmicrohttpd-866fb1e020d8b5e1643d90ea2406ce0c56286449.tar.gz
libmicrohttpd-866fb1e020d8b5e1643d90ea2406ce0c56286449.zip
further adaptations to API based on discussions with EG
Diffstat (limited to 'src/include/microhttpd2.h')
-rw-r--r--src/include/microhttpd2.h961
1 files changed, 478 insertions, 483 deletions
diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h
index 61da63b2..ea24a463 100644
--- a/src/include/microhttpd2.h
+++ b/src/include/microhttpd2.h
@@ -99,51 +99,292 @@ struct MHD_Request;
99 99
100 100
101/** 101/**
102 * Enumeration used to define options in 102 * Return values for reporting errors, also used
103 * `struct MHD_Option`. Opaque to the application. 103 * for logging.
104 */ 104 *
105enum MHD_OptionValue; 105 * A value of 0 indicates success (as a return value).
106 * Values between 1 and 10000 must not be used.
107 * Values from 10000-19999 are informational.
108 * Values from 20000-29999 indicate successful operations.
109 * Values from 30000-39999 indicate unsuccessful (normal) operations.
110 * Values from 40000-49999 indicate client errors.
111 * Values from 50000-59999 indicate server errors.
112 */
113enum MHD_StatusCode
114{
115
116 /**
117 * Successful operation (not used for logging).
118 */
119 MHD_SC_OK = 0,
120
121 /**
122 * Informational event, MHD started.
123 */
124 MHD_SC_DAEMON_STARTED = 10000,
125
126 /**
127 * This build of MHD does not support TLS, but the application
128 * requested TLS.
129 */
130 MHD_TLS_DISABLED = 50000,
131
132 /**
133 * The application requested an unsupported TLS backend to be used.
134 */
135 MHD_TLS_BACKEND_UNSUPPORTED = 50001,
136
137 /**
138 * The application requested a TLS cipher suite which is not
139 * supported by the selected backend.
140 */
141 MHD_TLS_CIPHERS_INVALID = 50002
142
143};
144
145
106 146
107 147
108/** 148/**
109 * Option configuring the service. This struct should be treated as 149 * Return values for the #MHD_RequestHeaderCallback implementations.
110 * completely opaque by the application. It is declared in the header
111 * to support applications allocating arrays of this struct (in
112 * particular on the stack).
113 */ 150 */
114struct MHD_Option 151enum MHD_HeaderResult
115{ 152{
116 /** 153 /**
117 * Which option is being given. #MHD_OPTION_VALUE_END 154 * Close the connection, we encountered a serious error.
118 * terminates the array.
119 */ 155 */
120 enum MHD_OptionValue option; 156 MHD_HR_CLOSE_CONNECTION = 0,
121 157
122 /** 158 /**
123 * Option value. Internal-use only! 159 * Continue to handle the connection normally, if requested
160 * by the client send a "100 CONTINUE" response. If the
161 * #MHD_RequestHeaderCallback is not defined for a given
162 * request, this behavior is what will always happen.
124 */ 163 */
125 intptr_t value1; 164 MHD_HR_CONTINUE_NORMALLY = 1,
126 165
127 /** 166 /**
128 * Option value. Internal-use only! 167 * Refuse handling the upload. This code ensures that MHD will
168 * not send a "100 CONTINUE" response (even if requested)
169 * and instead MHD will immediately proceed to the
170 * #MHD_RequestFetchResponseCallback to get the response. This
171 * is useful if an upload must be refused, i.e. because it is
172 * too big or not supported for the given encoding/uri/method.
129 */ 173 */
130 intptr_t value2; 174 MHD_HR_REFUSE_UPLOAD = 2
131 175
176};
177
178
179/**
180 * Signature of the callback used by MHD to notify the application
181 * that we have received the full header of a request. Can be used to
182 * suppress "100 CONTINUE" responses to requests containing an
183 * "Expect: 100-continue" header (by returning #MHD_HR_REFUSE_UPLOAD).
184 *
185 * @param cls client-defined closure
186 * @ingroup request
187 * @return how to proceed handling the request
188 */
189typedef enum MHD_HeaderResult
190(*MHD_RequestHeaderCallback) (void *cls);
191
192
193/**
194 * A client has uploaded data.
195 *
196 * @param cls argument given together with the function
197 * pointer when the handler was registered with MHD
198 * @param upload_data the data being uploaded (excluding headers)
199 * POST data will typically be made available incrementally via
200 * multiple callbacks
201 * @param[in,out] upload_data_size set initially to the size of the
202 * @a upload_data provided; the method must update this
203 * value to the number of bytes NOT processed;
204 * @return #MHD_YES if the upload was handled successfully,
205 * #MHD_NO if the socket must be closed due to a serios
206 * error while handling the request
207 */
208typedef enum MHD_Bool
209(*MHD_UploadCallback) (void *cls,
210 const char *upload_data,
211 size_t *upload_data_size);
212
213
214/**
215 * Signature of the callback used by MHD to notify the application
216 * that we now expect a response. The application can either
217 * call #MHD_response_queue() or suspend the request and return
218 * NULL to resume processing later, or return NULL without suspending
219 * to close the connection (hard error).
220 *
221 * @param cls client-defined closure
222 * @ingroup request
223 * @return response object to return, NULL if processing was
224 * suspended or on hard errors; the response object
225 * will be "consumed" at this point (i.e. the RC decremented)
226 */
227typedef struct MHD_Response *
228(*MHD_RequestFetchResponseCallback) (void *cls);
229
230
231/**
232 * Signature of the callback used by MHD to notify the
233 * application about completed requests.
234 *
235 * @param cls client-defined closure
236 * @param toe reason for request termination
237 * @see #MHD_option_request_completion()
238 * @ingroup request
239 */
240typedef void
241(*MHD_RequestTerminationCallback) (void *cls,
242 enum MHD_RequestTerminationCode toe);
243
244
245/**
246 * Functions called for an MHD request to process it.
247 * Not all functions must be implemented for each request.
248 */
249struct MHD_RequestHandlerCallbacks
250{
251 /**
252 * Closure argument passed to all callbacks in this struct.
253 */
254 void *cls;
255
256 /**
257 * Function called after we have received the full HTTP header.
258 */
259 MHD_RequestHeaderCallback header_cb;
260
261 /**
262 * Function called if we receive uploaded data.
263 */
264 MHD_UploadCallback upload_cb;
265
266 /**
267 * Function called when we expect the application to
268 * generate a response (mandatory to be set; if not
269 * set and #MHD_NO is not returned, MHD will generate
270 * 500 internal error and log an error).
271 */
272 MHD_RequestFetchResponseCallback fetch_response_cb;
273
132 /** 274 /**
133 * Option value. Internal-use only! 275 * Function called last to clean up. Gives the
276 * application a chance to check on the final status of
277 * the request (and to clean up @e cls).
134 */ 278 */
135 intptr_t value3; 279 MHD_RequestTerminationCallback termination_cb;
136 280
137}; 281};
138 282
139 283
140/** 284/**
141 * Returns terminating element of an option array. 285 * A client has requested the given url using the given method
286 * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT,
287 * #MHD_HTTP_METHOD_DELETE, #MHD_HTTP_METHOD_POST, etc). The callback
288 * must initialize @a rhp to provide further callbacks which will
289 * process the request further and ultimately to provide the response
290 * to give back to the client, or return #MHD_NO.
291 *
292 * @param cls argument given together with the function
293 * pointer when the handler was registered with MHD
294 * @param url the requested url (without arguments after "?")
295 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET,
296 * #MHD_HTTP_METHOD_PUT, etc.)
297 * @param[out] must be set to function pointers to be used to
298 * handle the request further; can be assumed to have
299 * been initialized to all-NULL values already.
300 * @return #MHD_YES if the request was handled successfully,
301 * #MHD_NO if the socket must be closed due to a serios
302 * error while handling the request
303 */
304typedef enum MHD_Bool
305(*MHD_RequestCallback) (void *cls,
306 struct MHD_Request *request,
307 const char *url,
308 const char *method,
309 struct MHD_RequestHandlerCallbacks *rhp);
310
311
312/**
313 * Create (but do not yet start) an MHD daemon.
314 * Usually, you will want to set various options before
315 * starting the daemon with #MHD_daemon_start().
142 * 316 *
143 * @return MHD option array terminator 317 * @param cb function to be called for incoming requests
318 * @param cb_cls closure for @a cb
144 */ 319 */
145_MHD_EXTERN struct MHD_Option 320struct MHD_Daemon *
146MHD_option_end (void); 321MHD_daemon_create (MHD_RequestCallback cb,
322 void *cb_cls);
323
324
325/**
326 * Start a webserver.
327 *
328 * @param daemon daemon to start; you can no longer set
329 * options on this daemon after this call!
330 * @return #MHD_SC_OK on success
331 * @ingroup event
332 */
333_MHD_EXTERN enum MHD_StatusCode
334MHD_daemon_start (struct MHD_Daemon *daemon);
335
336
337/**
338 * Stop accepting connections from the listening socket. Allows
339 * clients to continue processing, but stops accepting new
340 * connections. Note that the caller is responsible for closing the
341 * returned socket; however, if MHD is run using threads (anything but
342 * external select mode), it must not be closed until AFTER
343 * #MHD_stop_daemon has been called (as it is theoretically possible
344 * that an existing thread is still using it).
345 *
346 * Note that some thread modes require the caller to have passed
347 * #MHD_USE_ITC when using this API. If this daemon is
348 * in one of those modes and this option was not given to
349 * #MHD_start_daemon, this function will return #MHD_INVALID_SOCKET.
350 *
351 * @param daemon daemon to stop accepting new connections for
352 * @return old listen socket on success, #MHD_INVALID_SOCKET if
353 * the daemon was already not listening anymore, or
354 * was never started
355 * @ingroup specialized
356 */
357_MHD_EXTERN MHD_socket
358MHD_daemon_quiesce (struct MHD_Daemon *daemon);
359
360
361/**
362 * Shutdown and destroy an HTTP daemon.
363 *
364 * @param daemon daemon to stop
365 * @ingroup event
366 */
367_MHD_EXTERN void
368MHD_daemon_destroy (struct MHD_Daemon *daemon);
369
370
371/* ********************* daemon options ************** */
372
373
374/**
375 * Type of a callback function used for logging by MHD.
376 *
377 * @param cls closure
378 * @param sc status code of the event
379 * @param fm format string (`printf()`-style)
380 * @param ap arguments to @a fm
381 * @ingroup logging
382 */
383typedef void
384(*MHD_LoggingCallback)(void *cls,
385 enum MHD_StatusCode sc,
386 const char *fm,
387 va_list ap);
147 388
148 389
149/** 390/**
@@ -151,28 +392,31 @@ MHD_option_end (void);
151 * default (if this option is not given), we log error messages to 392 * default (if this option is not given), we log error messages to
152 * stderr. 393 * stderr.
153 * 394 *
154 * @return MHD option 395 * @param daemon which instance to setup logging for
396 * @param logger function to invoke
397 * @param logger_cls closure for @a logger
155 */ 398 */
156_MHD_EXTERN struct MHD_Option 399_MHD_EXTERN void
157MHD_option_log (MHD_LogCallback logger, 400MHD_option_set_logger (struct MHD_Daemon *daemon,
158 void *cls logger_cls); 401 MHD_LoggingCallback logger,
402 void *logger_cls);
159 403
160 404
161/** 405/**
162 * Convenience macro used to disable logging. 406 * Convenience macro used to disable logging.
163 * 407 *
164 * @return MHD option that disables logging 408 * @param daemon which instance to disable logging for
165 */ 409 */
166#define MHD_option_disable_logging() MHD_option_log (NULL, NULL) 410#define MHD_option_disable_logging(daemon) MHD_option_set_logger (daemon, NULL, NULL)
167 411
168 412
169/** 413/**
170 * Suppress use of "Date" header as this system has no RTC. 414 * Suppress use of "Date" header as this system has no RTC.
171 * 415 *
172 * @return MHD option 416 * @param daemon which instance to disable clock for.
173 */ 417 */
174_MHD_EXTERN struct MHD_Option 418_MHD_EXTERN void
175MHD_option_suppress_date_no_clock (void); 419MHD_option_suppress_date_no_clock (struct MHD_Daemon *daemon);
176 420
177 421
178/** 422/**
@@ -185,10 +429,10 @@ MHD_option_suppress_date_no_clock (void);
185 * automatically on platforms where select()/poll()/other ignore 429 * automatically on platforms where select()/poll()/other ignore
186 * shutdown() of a listen socket. 430 * shutdown() of a listen socket.
187 * 431 *
188 * @return MHD option 432 * @param daemon which instance to enable itc for
189 */ 433 */
190_MHD_EXTERN struct MHD_Option 434_MHD_EXTERN void
191MHD_option_enable_itc (void); 435MHD_option_enable_itc (struct MHD_Daemon *daemon);
192 436
193 437
194/** 438/**
@@ -197,20 +441,20 @@ MHD_option_enable_itc (void);
197 * other potentially unsafe optimizations. 441 * other potentially unsafe optimizations.
198 * Most effects only happen with #MHD_ELS_EPOLL. 442 * Most effects only happen with #MHD_ELS_EPOLL.
199 * 443 *
200 * @return MHD option 444 * @param daemon which instance to enable turbo for
201 */ 445 */
202_MHD_EXTERN struct MHD_Option 446_MHD_EXTERN void
203MHD_option_enable_turbo (void); 447MHD_option_enable_turbo (struct MHD_Daemon *daemon);
204 448
205 449
206/** 450/**
207 * Enable suspend/resume functions, which also implies setting up 451 * Enable suspend/resume functions, which also implies setting up
208 * #MHD_option_enable_itc() to signal resume. 452 * #MHD_option_enable_itc() to signal resume.
209 * 453 *
210 * @return MHD option 454 * @param daemon which instance to enable suspend/resume for
211 */ 455 */
212_MHD_EXTERN struct MHD_Option 456_MHD_EXTERN void
213MHD_option_allow_suspend_resume (void); 457MHD_option_allow_suspend_resume (struct MHD_Daemon *daemon);
214 458
215 459
216/** 460/**
@@ -218,10 +462,10 @@ MHD_option_allow_suspend_resume (void);
218 * "Upgrade" may require usage of additional internal resources, 462 * "Upgrade" may require usage of additional internal resources,
219 * which we do not want to use unless necessary. 463 * which we do not want to use unless necessary.
220 * 464 *
221 * @return MHD option 465 * @param daemon which instance to enable suspend/resume for
222 */ 466 */
223_MHD_EXTERN struct MHD_Option 467_MHD_EXTERN void
224MHD_option_allow_upgrade (void); 468MHD_option_allow_upgrade (struct MHD_Daemon *daemon);
225 469
226 470
227/** 471/**
@@ -241,9 +485,10 @@ enum MHD_FastOpenMethod
241 MHD_FOM_AUTO = 0, 485 MHD_FOM_AUTO = 0,
242 486
243 /** 487 /**
244 * If TCP_FASTOPEN is not available, cause #MHD_daemon_start() to 488 * If TCP_FASTOPEN is not available, return #MHD_NO.
245fail. 489 * Also causes #MHD_daemon_start() to fail if setting
246 */ 490 * the option fails later.
491 */
247 MHD_FOM_REQUIRE = 1 492 MHD_FOM_REQUIRE = 1
248}; 493};
249 494
@@ -256,50 +501,61 @@ fail.
256 * attack as the TCP stack has to now allocate resources for the SYN 501 * attack as the TCP stack has to now allocate resources for the SYN
257 * packet along with its DATA. 502 * packet along with its DATA.
258 * 503 *
504 * @param daemon which instance to configure TCP_FASTOPEN for
259 * @param fom under which conditions should we use TCP_FASTOPEN? 505 * @param fom under which conditions should we use TCP_FASTOPEN?
260 * @param queue_length queue length to use, default is 50 if this 506 * @param queue_length queue length to use, default is 50 if this
261 * option is never given. 507 * option is never given.
262 * @return MHD option 508 * @return #MHD_YES upon success, #MHD_NO if #MHD_FOM_REQUIRE was
509 * given, but TCP_FASTOPEN is not available on the platform
263 */ 510 */
264_MHD_EXTERN struct MHD_Option 511_MHD_EXTERN enum MHD_Bool
265MHD_option_tcp_fastopen (enum MHD_FastOpenMethod fom, 512MHD_option_tcp_fastopen (struct MHD_Daemon *daemon,
513 enum MHD_FastOpenMethod fom,
266 unsigned int queue_length); 514 unsigned int queue_length);
267 515
268 516
269/** 517/**
270 * Bind to the given TCP port. 518 * Bind to the given TCP port and address family.
271 * Ineffective in conjunction with #MHD_option_listen_socket(). 519 * Ineffective in conjunction with #MHD_option_listen_socket().
272 * Ineffective in conjunction with #MHD_option_bind_sa(). 520 * Ineffective in conjunction with #MHD_option_bind_sa().
273 * 521 *
274 * If neither this option nor the other two mentioned above 522 * If neither this option nor the other two mentioned above
275 * is specified, MHD will simply not listen on any socket! 523 * is specified, MHD will simply not listen on any socket!
276 * 524 *
525 * @param daemon which instance to configure the TCP port for
526 * @param af address family to use, i.e. #AF_INET or #AF_INET6,
527 * or #AF_UNSPEC for dual stack
277 * @param port port to use, 0 to bind to a random (free) port 528 * @param port port to use, 0 to bind to a random (free) port
278 * @return MHD option
279 */ 529 */
280_MHD_EXTERN struct MHD_Option 530_MHD_EXTERN void
281MHD_option_bind_port (uint16_t port); 531MHD_option_bind_port (struct MHD_Daemon *daemon,
532 int af,
533 uint16_t port);
282 534
283 535
284/** 536/**
285 * Bind to the given socket address. 537 * Bind to the given socket address.
286 * Ineffective in conjunction with #MHD_option_listen_socket(). 538 * Ineffective in conjunction with #MHD_option_listen_socket().
287 * 539 *
288 * @return MHD option 540 * @param daemon which instance to configure the binding address for
541 * @param sa address to bind to; can be IPv4 (AF_INET), IPv6 (AF_INET6)
542 * or even a UNIX domain socket (AF_UNIX)
289 */ 543 */
290_MHD_EXTERN struct MHD_Option 544_MHD_EXTERN void
291MHD_option_bind_socket_address (const struct sockaddr *sa); 545MHD_option_bind_socket_address (struct MHD_Daemon *daemon,
546 const struct sockaddr *sa);
292 547
293 548
294/** 549/**
295 * Use the given backlog for the listen() call. 550 * Use the given backlog for the listen() call.
296 * Ineffective in conjunction with #MHD_option_listen_socket(). 551 * Ineffective in conjunction with #MHD_option_listen_socket().
297 * 552 *
553 * @param daemon which instance to configure the backlog for
298 * @param listen_backlog backlog to use 554 * @param listen_backlog backlog to use
299 * @return MHD option
300 */ 555 */
301_MHD_EXTERN struct MHD_Option 556_MHD_EXTERN void
302MHD_option_listen_queue (int listen_backlog); 557MHD_option_listen_queue (struct MHD_Daemon *daemon,
558 int listen_backlog);
303 559
304 560
305/** 561/**
@@ -310,26 +566,29 @@ MHD_option_listen_queue (int listen_backlog);
310 * Windows). 566 * Windows).
311 * Ineffective in conjunction with #MHD_option_listen_socket(). 567 * Ineffective in conjunction with #MHD_option_listen_socket().
312 * 568 *
313 * @return MHD option 569 * @param daemon daemon to configure address reuse for
314 */ 570 */
315_MHD_EXTERN struct MHD_Option 571_MHD_EXTERN void
316MHD_option_listen_allow_address_reuse (void); 572MHD_option_listen_allow_address_reuse (struct MHD_Daemon *daemon);
317 573
318 574
319/** 575/**
320 * Accept connections from the given socket. Socket 576 * Accept connections from the given socket. Socket
321 * must be a TCP or UNIX domain (stream) socket. 577 * must be a TCP or UNIX domain (stream) socket.
322 * 578 *
323 * Disables other listen options, including 579 * Unless -1 is given, this disables other listen options, including
324 * #MHD_option_bind_sa(), #MHD_option_bind_port(), 580 * #MHD_option_bind_sa(), #MHD_option_bind_port(),
325 * #MHD_option_listen_queue() and 581 * #MHD_option_listen_queue() and
326 * #MHD_option_listen_allow_address_reuse(). 582 * #MHD_option_listen_allow_address_reuse().
327 * 583 *
328 * @param listen_socket listen socket to use 584 * @param daemon daemon to set listen socket for
329 * @return MHD option 585 * @param listen_socket listen socket to use,
586 * -1 will cause this call to be ignored (other
587 * binding options may still be effective)
330 */ 588 */
331_MHD_EXTERN struct MHD_Option 589_MHD_EXTERN void
332MHD_option_listen_socket (int listen_socket); 590MHD_option_listen_socket (struct MHD_Daemon *daemon,
591 int listen_socket);
333 592
334 593
335/** 594/**
@@ -363,11 +622,12 @@ enum MHD_EventLoopSyscall
363/** 622/**
364 * Force use of a particular event loop system call. 623 * Force use of a particular event loop system call.
365 * 624 *
625 * @param daemon daemon to set event loop style for
366 * @param els event loop syscall to use 626 * @param els event loop syscall to use
367 * @return MHD option
368 */ 627 */
369_MHD_EXTERN struct MHD_Option 628_MHD_EXTERN void
370MHD_option_event_loop (enum MHD_EventLoopSyscall els); 629MHD_option_event_loop (struct MHD_Daemon *daemon,
630 enum MHD_EventLoopSyscall els);
371 631
372 632
373/** 633/**
@@ -383,12 +643,12 @@ enum MHD_ProtocolStrictLevel
383 * It is not recommended to set this value on publicly available 643 * It is not recommended to set this value on publicly available
384 * servers as it may potentially lower level of protection. 644 * servers as it may potentially lower level of protection.
385 */ 645 */
386 MHD_SL_PERMISSIVE = -1, 646 MHD_PSL_PERMISSIVE = -1,
387 647
388 /** 648 /**
389 * Sane level of protocol enforcement for production use. 649 * Sane level of protocol enforcement for production use.
390 */ 650 */
391 MHD_SL_DEFAULT = 0, 651 MHD_PSL_DEFAULT = 0,
392 652
393 /** 653 /**
394 * Be strict about the protocol (as opposed to as tolerant as 654 * Be strict about the protocol (as opposed to as tolerant as
@@ -399,91 +659,98 @@ enum MHD_ProtocolStrictLevel
399 * recommended to set this if you are testing clients against 659 * recommended to set this if you are testing clients against
400 * MHD, and to use default in production. 660 * MHD, and to use default in production.
401 */ 661 */
402 MHD_SL_STRICT = 1 662 MHD_PSL_STRICT = 1
403}; 663};
404 664
405 665
406/** 666/**
407 * Set how strictly MHD will enforce the HTTP protocol. 667 * Set how strictly MHD will enforce the HTTP protocol.
408 * 668 *
669 * @param daemon daemon to configure strictness for
409 * @param sl how strict should we be 670 * @param sl how strict should we be
410 * @return MHD option
411 */ 671 */
412_MHD_EXTERN struct MHD_Option 672_MHD_EXTERN void
413MHD_option_protocol_strict_level (enum MHD_ProtocolStrictLevel sl); 673MHD_option_protocol_strict_level (struct MHD_Daemon *daemon,
674 enum MHD_ProtocolStrictLevel sl);
414 675
415 676
416/** 677/**
417 * Enable TLS. 678 * Enable and configure TLS.
418 * 679 *
680 * @param daemon which instance should be configured
419 * @param tls_backend which TLS backend should be used, 681 * @param tls_backend which TLS backend should be used,
420 * currently only "gnutls" is supported. You can 682 * currently only "gnutls" is supported. You can
421 * also specify "NULL" for best-available (which is the default). 683 * also specify "NULL" for best-available (which is the default).
684 * @param ciphers which ciphers should be used by TLS, default is
685 * "NORMAL"
686 * @return status code, #MHD_SC_OK upon success
687 * #MHD_TLS_BACKEND_UNSUPPORTED if the @a backend is unknown
688 * #MHD_TLS_DISABLED if this build of MHD does not support TLS
689 * #MHD_TLS_CIPHERS_INVALID if the given @a ciphers are not supported
690 * by this backend
422 */ 691 */
423_MHD_EXTERN struct MHD_Option 692_MHD_EXTERN enum MHD_StatusCode
424MHD_option_tls (const char *tls_backend); 693MHD_option_set_tls_backend (struct MHD_Daemon *daemon,
694 const char *tls_backend,
695 const char *ciphers);
425 696
426 697
427/** 698/**
428 * Provide TLS key and certificate data in-memory. 699 * Provide TLS key and certificate data in-memory.
429 * 700 *
701 * @param daemon which instance should be configured
430 * @param mem_key private key (key.pem) to be used by the 702 * @param mem_key private key (key.pem) to be used by the
431 * HTTPS daemon. Must be the actual data in-memory, not a filename. 703 * HTTPS daemon. Must be the actual data in-memory, not a filename.
432 * @param mem_cert certificate (cert.pem) to be used by the 704 * @param mem_cert certificate (cert.pem) to be used by the
433 * HTTPS daemon. Must be the actual data in-memory, not a filename. 705 * HTTPS daemon. Must be the actual data in-memory, not a filename.
434 * @return MHD option 706 * @param pass passphrase phrase to decrypt 'key.pem', NULL
707 * if @param mem_key is in cleartext already
708 * @return #MHD_SC_OK upon success; TODO: define failure modes
435 */ 709 */
436_MHD_EXTERN struct MHD_Option 710_MHD_EXTERN enum MHD_StatusCode
437MHD_option_tls_key_and_cert_from_memory (const char *mem_key, 711MHD_option_tls_key_and_cert_from_memory (struct MHD_Daemon *daemon,
438 const char *mem_cert); 712 const char *mem_key,
713 const char *mem_cert,
714 const char *pass);
439 715
440 716
441/**
442 * Provide passphrase to decrypt 'key.pem' (if required).
443 *
444 * @param pass passphrase phrase to decrypt 'key.pem'
445 */
446_MHD_EXTERN struct MHD_Option
447MHD_option_tls_key_passphrase (const char *pass);
448
449
450/**
451 * Configure TLS ciphers to use. Default is "NORMAL".
452 *
453 * @param ciphers which ciphers should be used by TLS
454 */
455_MHD_EXTERN struct MHD_Option
456MHD_option_tls_ciphers (const char *ciphers);
457
458 717
459/** 718/**
460 * Configure DH parameters (dh.pem) to use for the TLS key 719 * Configure DH parameters (dh.pem) to use for the TLS key
461 * exchange. 720 * exchange.
462 * 721 *
722 * @param daemon daemon to configure tls for
463 * @param dh parameters to use 723 * @param dh parameters to use
724 * @return #MHD_SC_OK upon success; TODO: define failure modes
464 */ 725 */
465_MHD_EXTERN struct MHD_Option 726_MHD_EXTERN enum MHD_StatusCode
466MHD_option_tls_mem_dhparams (const char *dh); 727 MHD_option_tls_mem_dhparams (struct MHD_Daemon *daemon,
728 const char *dh);
467 729
468 730
469/** 731/**
470 * Memory pointer for the certificate (ca.pem) to be used by the 732 * Memory pointer for the certificate (ca.pem) to be used by the
471 * HTTPS daemon for client authentification. 733 * HTTPS daemon for client authentification.
472 * 734 *
735 * @param daemon daemon to configure tls for
473 * @param mem_trust memory pointer to the certificate 736 * @param mem_trust memory pointer to the certificate
737 * @return #MHD_SC_OK upon success; TODO: define failure modes
474 */ 738 */
475_MHD_EXTERN struct MHD_Option 739_MHD_EXTERN enum MHD_StatusCode
476MHD_option_tls_mem_trust (const char *mem_trust); 740MHD_option_tls_mem_trust (struct MHD_Daemon *daemon,
477 741 const char *mem_trust);
742
478 743
479/** 744/**
480 * Configure daemon credentials type for GnuTLS. 745 * Configure daemon credentials type for GnuTLS.
481 * 746 *
482 * @param gnutls_credentials must be a value of 747 * @param gnutls_credentials must be a value of
483 * type `gnutls_credentials_type_t` 748 * type `gnutls_credentials_type_t`
749 * @return #MHD_SC_OK upon success; TODO: define failure modes
484 */ 750 */
485_MHD_EXTERN struct MHD_Option 751_MHD_EXTERN enum MHD_StatusCode
486MHD_option_gnutls_credentials (int gnutls_credentials); 752MHD_option_gnutls_credentials (struct MHD_Daemon *daemon,
753 int gnutls_credentials);
487 754
488 755
489/** 756/**
@@ -499,56 +766,62 @@ MHD_option_gnutls_credentials (int gnutls_credentials);
499 * the SNI data using `gnutls_server_name_get()`. Using this option 766 * the SNI data using `gnutls_server_name_get()`. Using this option
500 * requires GnuTLS 3.0 or higher. 767 * requires GnuTLS 3.0 or higher.
501 * 768 *
769 * @param daemon daemon to configure callback for
502 * @param cb must be of type `gnutls_certificate_retrieve_function2 *`. 770 * @param cb must be of type `gnutls_certificate_retrieve_function2 *`.
503 * @return MHD option
504 */
505_MHD_EXTERN struct MHD_Option
506MHD_option_gnutls_key_and_cert_from_callback (void *cb);
507
508
509/**
510 * Run using a specific address family (by default, MHD will support
511 * dual stack if supported by the operating system).
512 *
513 * @param af address family to use, i.e. #AF_INET or #AF_INET6,
514 * or #AF_UNSPEC for dual stack
515 * @return MHD option
516 */ 771 */
517_MHD_EXTERN struct MHD_Option 772_MHD_EXTERN void
518MHD_option_address_family (int af); 773MHD_option_gnutls_key_and_cert_from_callback (struct MHD_Daemon *daemon,
774 void *cb);
519 775
520 776
521/** 777/**
522 * Enable use of one thread per connection. 778 * Which threading model should be used by MHD?
523 *
524 * @return MHD option
525 */ 779 */
526_MHD_EXTERN struct MHD_Option 780enum MHD_ThreadingModel
527MHD_option_thread_per_connection (void); 781{
528
529 782
530/** 783 /**
531 * Enable use of MHD-internal worker thread. 784 * MHD should create its own thread for listening and furthermore
532 * 785 * create another thread per connection to handle requests. Use
533 * Run using an internal thread (or thread pool) for sockets sending 786 * this if handling requests is CPU-intensive or blocking, your
534 * and receiving and data processing. Without this flag MHD will not 787 * application is thread-safe and you have plenty of memory (per
535 * run automatically in background thread(s). If this option is set, 788 * request).
536 * #MHD_run() and #MHD_run_from_select() cannot be used. 789 */
537 * 790 MHD_TM_THREAD_PER_CONNECTION = -1,
538 * @return MHD option
539 */
540_MHD_EXTERN struct MHD_Option
541MHD_option_thread_iternal (void);
542 791
792 /**
793 * Use an external event loop. This is the default.
794 */
795 MHD_TM_EXTERNAL_EVENT_LOOP = 0,
543 796
797 /**
798 * Run with one or more worker threads. Any positive value
799 * means that MHD should start that number of worker threads
800 * (so > 1 is a thread pool) and distributed processing of
801 * requests among the workers.
802 *
803 * A good way to express the use of a thread pool
804 * in your code would be to write "4 * MHD_TM_WORKER_THREADS"
805 * to indicate four threads.
806 *
807 * If a positive value is set, * #MHD_daemon_run() and
808 * #MHD_daemon_run_from_select() cannot be used.
809 */
810 MHD_TM_WORKER_THREADS = 1
811
812};
813
814
544/** 815/**
545 * Enable use of a thread pool of the given size. 816 * Specify threading model to use.
546 * 817 *
547 * @param num_threads number of threads to run in the pool 818 * @param daemon daemon to configure
548 * @return MHD option 819 * @param tm model to use (positive values indicate the
820 * number of worker threads to be used)
549 */ 821 */
550_MHD_EXTERN struct MHD_Option 822_MHD_EXTERN void
551MHD_option_thread_pool_size (unsigned int num_threads); 823MHD_option_threading_model (struct MHD_Daemon *daemon,
824 enum MHD_ThreadingModel tm);
552 825
553 826
554/** 827/**
@@ -567,15 +840,17 @@ typedef enum MHD_Bool
567 840
568 841
569/** 842/**
570 * Return option setting a policy that accepts/rejects connections 843 * Set a policy callback that accepts/rejects connections
571 * based on the client's IP address. This function will be called 844 * based on the client's IP address. This function will be called
572 * before a connection object is created. 845 * before a connection object is created.
573 * 846 *
847 * @param daemon daemon to set policy for
574 * @param apc function to call to check the policy 848 * @param apc function to call to check the policy
575 * @param apc_cls closure for @a apc 849 * @param apc_cls closure for @a apc
576 */ 850 */
577_MHD_EXTERN struct MHD_Option 851_MHD_EXTERN void
578MHD_option_accept_policy (MHD_AcceptPolicyCallback apc, 852MHD_option_accept_policy (struct MHD_Daemon *daemon,
853 MHD_AcceptPolicyCallback apc,
579 void *apc_cls); 854 void *apc_cls);
580 855
581 856
@@ -608,11 +883,15 @@ typedef void
608 * Register a function that should be called whenever a connection is 883 * Register a function that should be called whenever a connection is
609 * started or closed. 884 * started or closed.
610 * 885 *
886 * @param daemon daemon to set callback for
611 * @param ncc function to call to check the policy 887 * @param ncc function to call to check the policy
612 * @param ncc_cls closure for @a apc 888 * @param ncc_cls closure for @a apc
889 * @param ccc function to call upon completion, NULL for none
890 * @param ccc_cls closure for @a ccc
613 */ 891 */
614_MHD_EXTERN struct MHD_Option 892_MHD_EXTERN void
615MHD_option_set_notify_connection (MHD_NotifyConnectionCallback ncc, 893MHD_option_set_notify_connection (struct MHD_Daemon *daemon,
894 MHD_NotifyConnectionCallback ncc,
616 void *ncc_cls); 895 void *ncc_cls);
617 896
618 897
@@ -623,61 +902,48 @@ MHD_option_set_notify_connection (MHD_NotifyConnectionCallback ncc,
623 * of the memory will be typically used for IO, and TCP buffers are 902 * of the memory will be typically used for IO, and TCP buffers are
624 * unlikely to support window sizes above 64k on most systems. 903 * unlikely to support window sizes above 64k on most systems.
625 * 904 *
905 * @param daemon daemon to configure
626 * @param memory_limit_b connection memory limit to use in bytes 906 * @param memory_limit_b connection memory limit to use in bytes
627 * @return MHD option 907 * @param memory_increment_b increment to use when growing the read buffer, must be smaller than @a memory_limit_b
628 */ 908 */
629_MHD_EXTERN struct MHD_Option 909_MHD_EXTERN void
630MHD_option_connection_memory_limit (size_t memory_limit_b); 910MHD_option_connection_memory_limit (struct MHD_Daemon *daemon,
631 911 size_t memory_limit_b,
632 912 size_t memory_increment_b);
633/**
634 * Increment to use for growing the read buffer (followed by a
635 * `size_t`). Must fit within #MHD_option_connection_memory_limit()).
636 *
637 * @param memory_limit_b connection memory limit to use in bytes
638 * @return MHD option
639 */
640_MHD_EXTERN struct MHD_Option
641MHD_option_connection_memory_increment (size_t memory_increment_b);
642 913
643 914
644/** 915/**
645 * Desired size of the stack for threads created by MHD. Use 0 for 916 * Desired size of the stack for threads created by MHD. Use 0 for
646 * system default. 917 * system default. Only useful if the selected threading model
918 * is not #MHD_TM_EXTERNAL_EVENT_LOOP.
647 * 919 *
920 * @param daemon daemon to configure
648 * @param stack_limit_b stack size to use in bytes 921 * @param stack_limit_b stack size to use in bytes
649 * @return MHD option
650 */ 922 */
651_MHD_EXTERN struct MHD_Option 923_MHD_EXTERN void
652MHD_option_thread_stack_size (size_t stack_limit_b); 924MHD_option_thread_stack_size (struct MHD_Daemon *daemon,
925 size_t stack_limit_b);
653 926
654 927
655/** 928/**
656 * Set maximum number of concurrent connections to accept. If not 929 * Set maximum number of concurrent connections to accept. If not
657 * given, MHD will not enforce any global limit (modulo running into 930 * given, MHD will not enforce any limits (modulo running into
658 * OS limits). 931 * OS limits). Values of 0 mean no limit.
659 * 932 *
660 * @param connection_limit maximum number of concurrent connections 933 * @param daemon daemon to configure
661 * @return MHD option 934 * @param global_connection_limit maximum number of (concurrent)
935 connections
936 * @param ip_connection_limit limit on the number of (concurrent)
937 * connections made to the server from the same IP address.
938 * Can be used to prevent one IP from taking over all of
939 * the allowed connections. If the same IP tries to
940 * establish more than the specified number of
941 * connections, they will be immediately rejected.
662 */ 942 */
663_MHD_EXTERN struct MHD_Option 943_MHD_EXTERN void
664MHD_option_connection_global_limit (unsigned int connection_limit); 944MHD_option_connection_limits (struct MHD_Daemon *daemon,
665 945 unsigned int global_connection_limit,
666 946 unsigned int ip_connection_limit);
667/**
668 * Limit on the number of (concurrent) connections made to the
669 * server from the same IP address. Can be used to prevent one
670 * IP from taking over all of the allowed connections. If the
671 * same IP tries to establish more than the specified number of
672 * connections, they will be immediately rejected. The default is
673 * zero, which means no limit on the number of connections
674 * from the same IP address.
675 *
676 * @param connection_limit maximum number of concurrent connections
677 * @return MHD option
678 */
679_MHD_EXTERN struct MHD_Option
680MHD_option_connection_ip_limit (unsigned int connection_limit);
681 947
682 948
683/** 949/**
@@ -685,11 +951,12 @@ MHD_option_connection_ip_limit (unsigned int connection_limit);
685 * connection automatically be timed out? 951 * connection automatically be timed out?
686 * Use zero for no timeout, which is also the (unsafe!) default. 952 * Use zero for no timeout, which is also the (unsafe!) default.
687 * 953 *
954 * @param daemon daemon to configure
688 * @param timeout_s number of seconds of timeout to use 955 * @param timeout_s number of seconds of timeout to use
689 * @return MHD option
690 */ 956 */
691_MHD_EXTERN struct MHD_Option 957_MHD_EXTERN void
692MHD_option_connection_default_timeout (unsigned int timeout_s); 958MHD_option_connection_default_timeout (struct MHD_Daemon *daemon,
959 unsigned int timeout_s);
693 960
694 961
695/** 962/**
@@ -717,12 +984,13 @@ MHD_UnescapeCallback (void *cls,
717 * option is not specified, the default method will be used which 984 * option is not specified, the default method will be used which
718 * decodes escape sequences of the form "%HH". 985 * decodes escape sequences of the form "%HH".
719 * 986 *
987 * @param daemon daemon to configure
720 * @param unescape_cb function to use, NULL for default 988 * @param unescape_cb function to use, NULL for default
721 * @param unescape_cb_cls closure for @a unescape_cb 989 * @param unescape_cb_cls closure for @a unescape_cb
722 * @return MHD option
723 */ 990 */
724_MHD_EXTERN struct MHD_Option 991_MHD_EXTERN void
725MHD_option_unescape_cb (MHD_UnescapeCallback unescape_cb, 992MHD_option_unescape_cb (struct MHD_Daemon *daemon,
993 MHD_UnescapeCallback unescape_cb,
726 void *unescape_cb_cls); 994 void *unescape_cb_cls);
727 995
728 996
@@ -731,12 +999,13 @@ MHD_option_unescape_cb (MHD_UnescapeCallback unescape_cb,
731 * the application must ensure that @a buf remains allocated and 999 * the application must ensure that @a buf remains allocated and
732 * unmodified while the deamon is running. 1000 * unmodified while the deamon is running.
733 * 1001 *
1002 * @param daemon daemon to configure
734 * @param buf_size number of bytes in @a buf 1003 * @param buf_size number of bytes in @a buf
735 * @param buf entropy buffer 1004 * @param buf entropy buffer
736 * @return MHD option
737 */ 1005 */
738_MHD_EXTERN struct MHD_Option 1006_MHD_EXTERN void
739MHD_option_digest_auth_random (size_t buf_size, 1007MHD_option_digest_auth_random (struct MHD_Daemon *daemon,
1008 size_t buf_size,
740 const void *buf); 1009 const void *buf);
741 1010
742 1011
@@ -744,256 +1013,17 @@ MHD_option_digest_auth_random (size_t buf_size,
744 * Size of the internal array holding the map of the nonce and 1013 * Size of the internal array holding the map of the nonce and
745 * the nonce counter. 1014 * the nonce counter.
746 * 1015 *
1016 * @param daemon daemon to configure
747 * @param nc_length desired array length 1017 * @param nc_length desired array length
748 * @return MHD option
749 */
750_MHD_EXTERN struct MHD_Option
751MHD_option_digest_auth_nc_size (size_t stack_limit_b);
752
753
754/**
755 * Return option setting a callback to call upon connection
756 * completion.
757 *
758 * @param ccc function to call
759 * @param ccc_cls closure for @a ccc
760 */
761_MHD_EXTERN struct MHD_Option
762MHD_option_connection_completion (MHD_ConnectionCompledCallback ccc,
763 void *ccc_cls);
764
765
766/**
767 * Return values for the #MHD_RequestHeaderCallback implementations.
768 */
769enum MHD_HeaderResult
770{
771 /**
772 * Close the connection, we encountered a serious error.
773 */
774 MHD_HR_CLOSE_CONNECTION = 0,
775
776 /**
777 * Continue to handle the connection normally, if requested
778 * by the client send a "100 CONTINUE" response. If the
779 * #MHD_RequestHeaderCallback is not defined for a given
780 * request, this behavior is what will always happen.
781 */
782 MHD_HR_CONTINUE_NORMALLY = 1,
783
784 /**
785 * Refuse handling the upload. This code ensures that MHD will
786 * not send a "100 CONTINUE" response (even if requested)
787 * and instead MHD will immediately proceed to the
788 * #MHD_RequestFetchResponseCallback to get the response. This
789 * is useful if an upload must be refused, i.e. because it is
790 * too big or not supported for the given encoding/uri/method.
791 */
792 MHD_HR_REFUSE_UPLOAD = 2
793
794};
795
796
797/**
798 * Signature of the callback used by MHD to notify the application
799 * that we have received the full header of a request. Can be used to
800 * suppress "100 CONTINUE" responses to requests containing an
801 * "Expect: 100-continue" header (by returning #MHD_HR_REFUSE_UPLOAD).
802 *
803 * @param cls client-defined closure
804 * @ingroup request
805 * @return how to proceed handling the request
806 */
807typedef enum MHD_HeaderResult
808(*MHD_RequestHeaderCallback) (void *cls);
809
810
811/**
812 * A client has uploaded data.
813 *
814 * @param cls argument given together with the function
815 * pointer when the handler was registered with MHD
816 * @param upload_data the data being uploaded (excluding headers)
817 * POST data will typically be made available incrementally via
818 * multiple callbacks
819 * @param[in,out] upload_data_size set initially to the size of the
820 * @a upload_data provided; the method must update this
821 * value to the number of bytes NOT processed;
822 * @return #MHD_YES if the upload was handled successfully,
823 * #MHD_NO if the socket must be closed due to a serios
824 * error while handling the request
825 */
826typedef enum MHD_Bool
827(*MHD_UploadCallback) (void *cls,
828 const char *upload_data,
829 size_t *upload_data_size);
830
831
832/**
833 * Signature of the callback used by MHD to notify the application
834 * that we now expect a response. The application can either
835 * call #MHD_response_queue() or suspend the request and return
836 * NULL to resume processing later, or return NULL without suspending
837 * to close the connection (hard error).
838 *
839 * @param cls client-defined closure
840 * @ingroup request
841 * @return response object to return, NULL if processing was
842 * suspended or on hard errors; the response object
843 * will be "consumed" at this point (i.e. the RC decremented)
844 */
845typedef struct MHD_Response *
846(*MHD_RequestFetchResponseCallback) (void *cls);
847
848
849/**
850 * Signature of the callback used by MHD to notify the
851 * application about completed requests.
852 *
853 * @param cls client-defined closure
854 * @param toe reason for request termination
855 * @see #MHD_option_request_completion()
856 * @ingroup request
857 */
858typedef void
859(*MHD_RequestCompletedCallback) (void *cls,
860 enum MHD_RequestTerminationCode toe);
861
862
863/**
864 * Functions called for an MHD request to process it.
865 * Not all functions must be implemented for each request.
866 */
867struct MHD_RequestHandlerCallbacks
868{
869 /**
870 * Closure argument passed to all callbacks in this struct.
871 */
872 void *cls;
873
874 /**
875 * Function called after we have received the full HTTP header.
876 */
877 MHD_RequestHeaderCallback header_cb;
878
879 /**
880 * Function called if we receive uploaded data.
881 */
882 MHD_UploadCallback upload_cb;
883
884 /**
885 * Function called when we expect the application to
886 * generate a response (mandatory to be set; if not
887 * set and #MHD_NO is not returned, MHD will generate
888 * 500 internal error and log an error).
889 */
890 MHD_RequestFetchResponseCallback fetch_response_cb;
891
892 /**
893 * Function called last to clean up. Gives the
894 * application a chance to check on the final status of
895 * the request (and to clean up @e cls).
896 */
897 MHD_RequestCompletedCallback completed_cb;
898
899};
900
901
902/**
903 * A client has requested the given url using the given method
904 * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT,
905 * #MHD_HTTP_METHOD_DELETE, #MHD_HTTP_METHOD_POST, etc). The callback
906 * must initialize @a rhp to provide further callbacks which will
907 * process the request further and ultimately to provide the response
908 * to give back to the client, or return #MHD_NO.
909 *
910 * @param cls argument given together with the function
911 * pointer when the handler was registered with MHD
912 * @param url the requested url (without arguments after "?")
913 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET,
914 * #MHD_HTTP_METHOD_PUT, etc.)
915 * @param[out] must be set to function pointers to be used to
916 * handle the request further; can be assumed to have
917 * been initialized to all-NULL values already.
918 * @return #MHD_YES if the request was handled successfully,
919 * #MHD_NO if the socket must be closed due to a serios
920 * error while handling the request
921 */
922typedef enum MHD_Bool
923(*MHD_RequestCallback) (void *cls,
924 struct MHD_Request *request,
925 const char *url,
926 const char *method,
927 struct MHD_RequestHandlerCallbacks *rhp);
928
929
930/* **************** Daemon handling functions ***************** */
931
932/**
933 * Start a webserver on the given port.
934 *
935 * @param options array of options, does NOT have to
936 * persist in memory past this call (note that individual
937 * arguments passed to the functions may need to
938 * be preserved)
939 * @param cb function to be called for incoming requests
940 * @param cb_cls closure for @a cb
941 * @return NULL on error, handle to daemon on success
942 * @ingroup event
943 */
944_MHD_EXTERN struct MHD_Daemon *
945MHD_daemon_start (const struct MHD_Option options[],
946 MHD_RequestCallback cb,
947 void *cb_cls);
948
949
950/**
951 * Stop accepting connections from the listening socket. Allows
952 * clients to continue processing, but stops accepting new
953 * connections. Note that the caller is responsible for closing the
954 * returned socket; however, if MHD is run using threads (anything but
955 * external select mode), it must not be closed until AFTER
956 * #MHD_stop_daemon has been called (as it is theoretically possible
957 * that an existing thread is still using it).
958 *
959 * Note that some thread modes require the caller to have passed
960 * #MHD_USE_ITC when using this API. If this daemon is
961 * in one of those modes and this option was not given to
962 * #MHD_start_daemon, this function will return #MHD_INVALID_SOCKET.
963 *
964 * @param daemon daemon to stop accepting new connections for
965 * @return old listen socket on success, #MHD_INVALID_SOCKET if
966 * the daemon was already not listening anymore
967 * @ingroup specialized
968 */
969_MHD_EXTERN MHD_socket
970MHD_daemon_quiesce (struct MHD_Daemon *daemon);
971
972
973/**
974 * Shutdown an HTTP daemon.
975 *
976 * @param daemon daemon to stop
977 * @ingroup event
978 */ 1018 */
979_MHD_EXTERN void 1019_MHD_EXTERN void
980MHD_daemon_stop (struct MHD_Daemon *daemon); 1020MHD_option_digest_auth_nc_size (struct MHD_Daemon *daemon,
1021 size_t stack_limit_b);
981 1022
982 1023
983/* ********************* connection options ************** */
984
985/**
986 * MHD connection options. Given to #MHD_set_connection_option() to
987 * set custom options for a particular connection.
988 */
989struct MHD_ConnectionOption;
990 1024
991 1025
992/** 1026/* ********************* connection options ************** */
993 * Generate array terminator for connection options.
994 */
995struct MHD_ConnectionOption
996MHD_connection_option_end (void);
997 1027
998 1028
999/** 1029/**
@@ -1002,24 +1032,12 @@ MHD_connection_option_end (void);
1002 * timeout was set to zero (or unset) before, setting of a new value 1032 * timeout was set to zero (or unset) before, setting of a new value
1003 * by MHD_connection_set_option() will reset timeout timer. 1033 * by MHD_connection_set_option() will reset timeout timer.
1004 * 1034 *
1035 * @param connection connection to configure timeout for
1005 * @param timeout_s new timeout in seconds 1036 * @param timeout_s new timeout in seconds
1006 */ 1037 */
1007struct MHD_ConnectionOption 1038struct MHD_ConnectionOption
1008MHD_connection_option_timeout (unsigned int timeout_s); 1039MHD_connection_option_timeout (struct MHD_Connection *connection,
1009 1040 unsigned int timeout_s);
1010
1011/**
1012 * Set a custom option for the given connection, overriding defaults.
1013 *
1014 * @param connection connection to modify
1015 * @param options array of options to set, does NOT have to
1016 * persist past this call
1017 * @ingroup specialized
1018 * @return #MHD_YES on success
1019 */
1020_MHD_EXTERN enum MHD_Bool
1021MHD_connection_set_options (struct MHD_Connection *connection,
1022 struct MHD_ConnectionOption options[]);
1023 1041
1024 1042
1025/* **************** Request handling functions ***************** */ 1043/* **************** Request handling functions ***************** */
@@ -1242,37 +1260,14 @@ MHD_request_resume (struct MHD_Request *request);
1242 1260
1243 1261
1244/** 1262/**
1245 * MHD response option.
1246 */
1247struct MHD_ResponseOption;
1248
1249
1250/**
1251 * End of options array.
1252 */
1253struct MHD_ResponseOption
1254MHD_response_option_end (void);
1255
1256
1257/**
1258 * Only respond in conservative HTTP 1.0-mode. In particular, 1263 * Only respond in conservative HTTP 1.0-mode. In particular,
1259 * do not (automatically) sent "Connection" headers and always 1264 * do not (automatically) sent "Connection" headers and always
1260 * close the connection after generating the response. 1265 * close the connection after generating the response.
1261 */
1262struct MHD_ResponseOption
1263MHD_response_option_v10_only (void);
1264
1265
1266/**
1267 * Set special @a options for a @a response.
1268 * 1266 *
1269 * @param response the response to modify 1267 * @param response the response to modify
1270 * @param options options to set for the response
1271 * @return #MHD_YES on success, #MHD_NO on error
1272 */ 1268 */
1273_MHD_EXTERN enum MHD_Bool 1269_MHD_EXTERN void
1274MHD_response_set_options (struct MHD_Response *response, 1270MHD_response_option_v10_only (struct MHD_Response *response);
1275 enum MHD_ResponseOption options[]);
1276 1271
1277 1272
1278/** 1273/**