diff options
Diffstat (limited to 'src/include/microhttpd2.h')
-rw-r--r-- | src/include/microhttpd2.h | 511 |
1 files changed, 239 insertions, 272 deletions
diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h index ea24a463..63d3d47e 100644 --- a/src/include/microhttpd2.h +++ b/src/include/microhttpd2.h | |||
@@ -30,8 +30,11 @@ | |||
30 | * - simplify application callbacks by splitting header/upload/post | 30 | * - simplify application callbacks by splitting header/upload/post |
31 | * functionality currently provided by calling the same | 31 | * functionality currently provided by calling the same |
32 | * MHD_AccessHandlerCallback 3+ times into separate callbacks. | 32 | * MHD_AccessHandlerCallback 3+ times into separate callbacks. |
33 | * - keep the API very simple for simple requests, but allow | ||
34 | * more complex logic to be incrementally introduced | ||
35 | * (via new struct MHD_Action construction) | ||
33 | * - avoid repeated scans for URL matches via the new | 36 | * - avoid repeated scans for URL matches via the new |
34 | * struct MHD_RequestHandlerCallbacks construction | 37 | * struct MHD_Action construction |
35 | * - provide default logarithmic implementation of URL scan | 38 | * - provide default logarithmic implementation of URL scan |
36 | * => reduce strcmp(url) from >= 3n operations to "log n" | 39 | * => reduce strcmp(url) from >= 3n operations to "log n" |
37 | * per request. | 40 | * per request. |
@@ -55,11 +58,12 @@ | |||
55 | * (so we can have one binary implementing old and new | 58 | * (so we can have one binary implementing old and new |
56 | * library API at the same time via compatibility layer). | 59 | * library API at the same time via compatibility layer). |
57 | * - make it impossible to queue a response at the wrong time | 60 | * - make it impossible to queue a response at the wrong time |
61 | * - make it impossible to suspend a connection/request at the | ||
62 | * wrong time (improves thread-safety) | ||
58 | * - make it clear which response status codes are "properly" | 63 | * - make it clear which response status codes are "properly" |
59 | * supported (include the descriptive string) by using an enum; | 64 | * supported (include the descriptive string) by using an enum; |
60 | * - simplify API for common-case of one-shot responses by | 65 | * - simplify API for common-case of one-shot responses by |
61 | * eliminating need for destroy response in those cases; | 66 | * eliminating need for destroy response in most cases; |
62 | * - improve thread-safety | ||
63 | */ | 67 | */ |
64 | 68 | ||
65 | 69 | ||
@@ -143,142 +147,11 @@ enum MHD_StatusCode | |||
143 | }; | 147 | }; |
144 | 148 | ||
145 | 149 | ||
146 | |||
147 | |||
148 | /** | ||
149 | * Return values for the #MHD_RequestHeaderCallback implementations. | ||
150 | */ | ||
151 | enum MHD_HeaderResult | ||
152 | { | ||
153 | /** | ||
154 | * Close the connection, we encountered a serious error. | ||
155 | */ | ||
156 | MHD_HR_CLOSE_CONNECTION = 0, | ||
157 | |||
158 | /** | ||
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. | ||
163 | */ | ||
164 | MHD_HR_CONTINUE_NORMALLY = 1, | ||
165 | |||
166 | /** | ||
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. | ||
173 | */ | ||
174 | MHD_HR_REFUSE_UPLOAD = 2 | ||
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 | */ | ||
189 | typedef 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 | */ | ||
208 | typedef enum MHD_Bool | ||
209 | (*MHD_UploadCallback) (void *cls, | ||
210 | const char *upload_data, | ||
211 | size_t *upload_data_size); | ||
212 | |||
213 | |||
214 | /** | 150 | /** |
215 | * Signature of the callback used by MHD to notify the application | 151 | * Actions are returned by the application to drive the request |
216 | * that we now expect a response. The application can either | 152 | * handling of MHD. |
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 | */ | ||
227 | typedef 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 | */ | ||
240 | typedef 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 | */ | 153 | */ |
249 | struct MHD_RequestHandlerCallbacks | 154 | struct MHD_Action; |
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 | |||
274 | /** | ||
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). | ||
278 | */ | ||
279 | MHD_RequestTerminationCallback termination_cb; | ||
280 | |||
281 | }; | ||
282 | 155 | ||
283 | 156 | ||
284 | /** | 157 | /** |
@@ -294,19 +167,15 @@ struct MHD_RequestHandlerCallbacks | |||
294 | * @param url the requested url (without arguments after "?") | 167 | * @param url the requested url (without arguments after "?") |
295 | * @param method the HTTP method used (#MHD_HTTP_METHOD_GET, | 168 | * @param method the HTTP method used (#MHD_HTTP_METHOD_GET, |
296 | * #MHD_HTTP_METHOD_PUT, etc.) | 169 | * #MHD_HTTP_METHOD_PUT, etc.) |
297 | * @param[out] must be set to function pointers to be used to | 170 | * @return action how to proceed, NULL |
298 | * handle the request further; can be assumed to have | 171 | * if the socket must be closed due to a serios |
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 | 172 | * error while handling the request |
303 | */ | 173 | */ |
304 | typedef enum MHD_Bool | 174 | typedef struct MHD_Action * |
305 | (*MHD_RequestCallback) (void *cls, | 175 | (*MHD_RequestCallback) (void *cls, |
306 | struct MHD_Request *request, | 176 | struct MHD_Request *request, |
307 | const char *url, | 177 | const char *url, |
308 | const char *method, | 178 | const char *method); |
309 | struct MHD_RequestHandlerCallbacks *rhp); | ||
310 | 179 | ||
311 | 180 | ||
312 | /** | 181 | /** |
@@ -397,7 +266,7 @@ typedef void | |||
397 | * @param logger_cls closure for @a logger | 266 | * @param logger_cls closure for @a logger |
398 | */ | 267 | */ |
399 | _MHD_EXTERN void | 268 | _MHD_EXTERN void |
400 | MHD_option_set_logger (struct MHD_Daemon *daemon, | 269 | MHD_daemon_set_logger (struct MHD_Daemon *daemon, |
401 | MHD_LoggingCallback logger, | 270 | MHD_LoggingCallback logger, |
402 | void *logger_cls); | 271 | void *logger_cls); |
403 | 272 | ||
@@ -407,7 +276,7 @@ MHD_option_set_logger (struct MHD_Daemon *daemon, | |||
407 | * | 276 | * |
408 | * @param daemon which instance to disable logging for | 277 | * @param daemon which instance to disable logging for |
409 | */ | 278 | */ |
410 | #define MHD_option_disable_logging(daemon) MHD_option_set_logger (daemon, NULL, NULL) | 279 | #define MHD_daemon_disable_logging(daemon) MHD_daemon_set_logger (daemon, NULL, NULL) |
411 | 280 | ||
412 | 281 | ||
413 | /** | 282 | /** |
@@ -416,23 +285,23 @@ MHD_option_set_logger (struct MHD_Daemon *daemon, | |||
416 | * @param daemon which instance to disable clock for. | 285 | * @param daemon which instance to disable clock for. |
417 | */ | 286 | */ |
418 | _MHD_EXTERN void | 287 | _MHD_EXTERN void |
419 | MHD_option_suppress_date_no_clock (struct MHD_Daemon *daemon); | 288 | MHD_daemon_suppress_date_no_clock (struct MHD_Daemon *daemon); |
420 | 289 | ||
421 | 290 | ||
422 | /** | 291 | /** |
423 | * Use inter-thread communication channel. #MHD_option_enable_itc() | 292 | * Use inter-thread communication channel. #MHD_daemon_enable_itc() |
424 | * can be used with #MHD_option_thread_internal() and is ignored with | 293 | * can be used with #MHD_daemon_thread_internal() and is ignored with |
425 | * any "external" mode. It's required for use of | 294 | * any "external" mode. It's required for use of |
426 | * #MHD_daemon_quiesce() or #MHD_connection_add(). This option is | 295 | * #MHD_daemon_quiesce() or #MHD_connection_add(). This option is |
427 | * enforced by #MHD_option_allow_suspend_resume() and if there is no | 296 | * enforced by #MHD_daemon_allow_suspend_resume() and if there is no |
428 | * listen socket. #MHD_option_enable_itc() is always used | 297 | * listen socket. #MHD_daemon_enable_itc() is always used |
429 | * automatically on platforms where select()/poll()/other ignore | 298 | * automatically on platforms where select()/poll()/other ignore |
430 | * shutdown() of a listen socket. | 299 | * shutdown() of a listen socket. |
431 | * | 300 | * |
432 | * @param daemon which instance to enable itc for | 301 | * @param daemon which instance to enable itc for |
433 | */ | 302 | */ |
434 | _MHD_EXTERN void | 303 | _MHD_EXTERN void |
435 | MHD_option_enable_itc (struct MHD_Daemon *daemon); | 304 | MHD_daemon_enable_itc (struct MHD_Daemon *daemon); |
436 | 305 | ||
437 | 306 | ||
438 | /** | 307 | /** |
@@ -444,17 +313,17 @@ MHD_option_enable_itc (struct MHD_Daemon *daemon); | |||
444 | * @param daemon which instance to enable turbo for | 313 | * @param daemon which instance to enable turbo for |
445 | */ | 314 | */ |
446 | _MHD_EXTERN void | 315 | _MHD_EXTERN void |
447 | MHD_option_enable_turbo (struct MHD_Daemon *daemon); | 316 | MHD_daemon_enable_turbo (struct MHD_Daemon *daemon); |
448 | 317 | ||
449 | 318 | ||
450 | /** | 319 | /** |
451 | * Enable suspend/resume functions, which also implies setting up | 320 | * Enable suspend/resume functions, which also implies setting up |
452 | * #MHD_option_enable_itc() to signal resume. | 321 | * #MHD_daemon_enable_itc() to signal resume. |
453 | * | 322 | * |
454 | * @param daemon which instance to enable suspend/resume for | 323 | * @param daemon which instance to enable suspend/resume for |
455 | */ | 324 | */ |
456 | _MHD_EXTERN void | 325 | _MHD_EXTERN void |
457 | MHD_option_allow_suspend_resume (struct MHD_Daemon *daemon); | 326 | MHD_daemon_allow_suspend_resume (struct MHD_Daemon *daemon); |
458 | 327 | ||
459 | 328 | ||
460 | /** | 329 | /** |
@@ -465,7 +334,7 @@ MHD_option_allow_suspend_resume (struct MHD_Daemon *daemon); | |||
465 | * @param daemon which instance to enable suspend/resume for | 334 | * @param daemon which instance to enable suspend/resume for |
466 | */ | 335 | */ |
467 | _MHD_EXTERN void | 336 | _MHD_EXTERN void |
468 | MHD_option_allow_upgrade (struct MHD_Daemon *daemon); | 337 | MHD_daemon_allow_upgrade (struct MHD_Daemon *daemon); |
469 | 338 | ||
470 | 339 | ||
471 | /** | 340 | /** |
@@ -509,15 +378,15 @@ enum MHD_FastOpenMethod | |||
509 | * given, but TCP_FASTOPEN is not available on the platform | 378 | * given, but TCP_FASTOPEN is not available on the platform |
510 | */ | 379 | */ |
511 | _MHD_EXTERN enum MHD_Bool | 380 | _MHD_EXTERN enum MHD_Bool |
512 | MHD_option_tcp_fastopen (struct MHD_Daemon *daemon, | 381 | MHD_daemon_tcp_fastopen (struct MHD_Daemon *daemon, |
513 | enum MHD_FastOpenMethod fom, | 382 | enum MHD_FastOpenMethod fom, |
514 | unsigned int queue_length); | 383 | unsigned int queue_length); |
515 | 384 | ||
516 | 385 | ||
517 | /** | 386 | /** |
518 | * Bind to the given TCP port and address family. | 387 | * Bind to the given TCP port and address family. |
519 | * Ineffective in conjunction with #MHD_option_listen_socket(). | 388 | * Ineffective in conjunction with #MHD_daemon_listen_socket(). |
520 | * Ineffective in conjunction with #MHD_option_bind_sa(). | 389 | * Ineffective in conjunction with #MHD_daemon_bind_sa(). |
521 | * | 390 | * |
522 | * If neither this option nor the other two mentioned above | 391 | * If neither this option nor the other two mentioned above |
523 | * is specified, MHD will simply not listen on any socket! | 392 | * is specified, MHD will simply not listen on any socket! |
@@ -528,33 +397,33 @@ MHD_option_tcp_fastopen (struct MHD_Daemon *daemon, | |||
528 | * @param port port to use, 0 to bind to a random (free) port | 397 | * @param port port to use, 0 to bind to a random (free) port |
529 | */ | 398 | */ |
530 | _MHD_EXTERN void | 399 | _MHD_EXTERN void |
531 | MHD_option_bind_port (struct MHD_Daemon *daemon, | 400 | MHD_daemon_bind_port (struct MHD_Daemon *daemon, |
532 | int af, | 401 | int af, |
533 | uint16_t port); | 402 | uint16_t port); |
534 | 403 | ||
535 | 404 | ||
536 | /** | 405 | /** |
537 | * Bind to the given socket address. | 406 | * Bind to the given socket address. |
538 | * Ineffective in conjunction with #MHD_option_listen_socket(). | 407 | * Ineffective in conjunction with #MHD_daemon_listen_socket(). |
539 | * | 408 | * |
540 | * @param daemon which instance to configure the binding address for | 409 | * @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) | 410 | * @param sa address to bind to; can be IPv4 (AF_INET), IPv6 (AF_INET6) |
542 | * or even a UNIX domain socket (AF_UNIX) | 411 | * or even a UNIX domain socket (AF_UNIX) |
543 | */ | 412 | */ |
544 | _MHD_EXTERN void | 413 | _MHD_EXTERN void |
545 | MHD_option_bind_socket_address (struct MHD_Daemon *daemon, | 414 | MHD_daemon_bind_socket_address (struct MHD_Daemon *daemon, |
546 | const struct sockaddr *sa); | 415 | const struct sockaddr *sa); |
547 | 416 | ||
548 | 417 | ||
549 | /** | 418 | /** |
550 | * Use the given backlog for the listen() call. | 419 | * Use the given backlog for the listen() call. |
551 | * Ineffective in conjunction with #MHD_option_listen_socket(). | 420 | * Ineffective in conjunction with #MHD_daemon_listen_socket(). |
552 | * | 421 | * |
553 | * @param daemon which instance to configure the backlog for | 422 | * @param daemon which instance to configure the backlog for |
554 | * @param listen_backlog backlog to use | 423 | * @param listen_backlog backlog to use |
555 | */ | 424 | */ |
556 | _MHD_EXTERN void | 425 | _MHD_EXTERN void |
557 | MHD_option_listen_queue (struct MHD_Daemon *daemon, | 426 | MHD_daemon_listen_queue (struct MHD_Daemon *daemon, |
558 | int listen_backlog); | 427 | int listen_backlog); |
559 | 428 | ||
560 | 429 | ||
@@ -564,12 +433,12 @@ MHD_option_listen_queue (struct MHD_Daemon *daemon, | |||
564 | * present and set to false, disallow reusing address:port socket | 433 | * present and set to false, disallow reusing address:port socket |
565 | * (does nothing on most plaform, but uses SO_EXCLUSIVEADDRUSE on | 434 | * (does nothing on most plaform, but uses SO_EXCLUSIVEADDRUSE on |
566 | * Windows). | 435 | * Windows). |
567 | * Ineffective in conjunction with #MHD_option_listen_socket(). | 436 | * Ineffective in conjunction with #MHD_daemon_listen_socket(). |
568 | * | 437 | * |
569 | * @param daemon daemon to configure address reuse for | 438 | * @param daemon daemon to configure address reuse for |
570 | */ | 439 | */ |
571 | _MHD_EXTERN void | 440 | _MHD_EXTERN void |
572 | MHD_option_listen_allow_address_reuse (struct MHD_Daemon *daemon); | 441 | MHD_daemon_listen_allow_address_reuse (struct MHD_Daemon *daemon); |
573 | 442 | ||
574 | 443 | ||
575 | /** | 444 | /** |
@@ -577,9 +446,9 @@ MHD_option_listen_allow_address_reuse (struct MHD_Daemon *daemon); | |||
577 | * must be a TCP or UNIX domain (stream) socket. | 446 | * must be a TCP or UNIX domain (stream) socket. |
578 | * | 447 | * |
579 | * Unless -1 is given, this disables other listen options, including | 448 | * Unless -1 is given, this disables other listen options, including |
580 | * #MHD_option_bind_sa(), #MHD_option_bind_port(), | 449 | * #MHD_daemon_bind_sa(), #MHD_daemon_bind_port(), |
581 | * #MHD_option_listen_queue() and | 450 | * #MHD_daemon_listen_queue() and |
582 | * #MHD_option_listen_allow_address_reuse(). | 451 | * #MHD_daemon_listen_allow_address_reuse(). |
583 | * | 452 | * |
584 | * @param daemon daemon to set listen socket for | 453 | * @param daemon daemon to set listen socket for |
585 | * @param listen_socket listen socket to use, | 454 | * @param listen_socket listen socket to use, |
@@ -587,7 +456,7 @@ MHD_option_listen_allow_address_reuse (struct MHD_Daemon *daemon); | |||
587 | * binding options may still be effective) | 456 | * binding options may still be effective) |
588 | */ | 457 | */ |
589 | _MHD_EXTERN void | 458 | _MHD_EXTERN void |
590 | MHD_option_listen_socket (struct MHD_Daemon *daemon, | 459 | MHD_daemon_listen_socket (struct MHD_Daemon *daemon, |
591 | int listen_socket); | 460 | int listen_socket); |
592 | 461 | ||
593 | 462 | ||
@@ -626,7 +495,7 @@ enum MHD_EventLoopSyscall | |||
626 | * @param els event loop syscall to use | 495 | * @param els event loop syscall to use |
627 | */ | 496 | */ |
628 | _MHD_EXTERN void | 497 | _MHD_EXTERN void |
629 | MHD_option_event_loop (struct MHD_Daemon *daemon, | 498 | MHD_daemon_event_loop (struct MHD_Daemon *daemon, |
630 | enum MHD_EventLoopSyscall els); | 499 | enum MHD_EventLoopSyscall els); |
631 | 500 | ||
632 | 501 | ||
@@ -670,7 +539,7 @@ enum MHD_ProtocolStrictLevel | |||
670 | * @param sl how strict should we be | 539 | * @param sl how strict should we be |
671 | */ | 540 | */ |
672 | _MHD_EXTERN void | 541 | _MHD_EXTERN void |
673 | MHD_option_protocol_strict_level (struct MHD_Daemon *daemon, | 542 | MHD_daemon_protocol_strict_level (struct MHD_Daemon *daemon, |
674 | enum MHD_ProtocolStrictLevel sl); | 543 | enum MHD_ProtocolStrictLevel sl); |
675 | 544 | ||
676 | 545 | ||
@@ -690,7 +559,7 @@ MHD_option_protocol_strict_level (struct MHD_Daemon *daemon, | |||
690 | * by this backend | 559 | * by this backend |
691 | */ | 560 | */ |
692 | _MHD_EXTERN enum MHD_StatusCode | 561 | _MHD_EXTERN enum MHD_StatusCode |
693 | MHD_option_set_tls_backend (struct MHD_Daemon *daemon, | 562 | MHD_daemon_set_tls_backend (struct MHD_Daemon *daemon, |
694 | const char *tls_backend, | 563 | const char *tls_backend, |
695 | const char *ciphers); | 564 | const char *ciphers); |
696 | 565 | ||
@@ -708,13 +577,12 @@ MHD_option_set_tls_backend (struct MHD_Daemon *daemon, | |||
708 | * @return #MHD_SC_OK upon success; TODO: define failure modes | 577 | * @return #MHD_SC_OK upon success; TODO: define failure modes |
709 | */ | 578 | */ |
710 | _MHD_EXTERN enum MHD_StatusCode | 579 | _MHD_EXTERN enum MHD_StatusCode |
711 | MHD_option_tls_key_and_cert_from_memory (struct MHD_Daemon *daemon, | 580 | MHD_daemon_tls_key_and_cert_from_memory (struct MHD_Daemon *daemon, |
712 | const char *mem_key, | 581 | const char *mem_key, |
713 | const char *mem_cert, | 582 | const char *mem_cert, |
714 | const char *pass); | 583 | const char *pass); |
715 | 584 | ||
716 | 585 | ||
717 | |||
718 | /** | 586 | /** |
719 | * Configure DH parameters (dh.pem) to use for the TLS key | 587 | * Configure DH parameters (dh.pem) to use for the TLS key |
720 | * exchange. | 588 | * exchange. |
@@ -724,7 +592,7 @@ MHD_option_tls_key_and_cert_from_memory (struct MHD_Daemon *daemon, | |||
724 | * @return #MHD_SC_OK upon success; TODO: define failure modes | 592 | * @return #MHD_SC_OK upon success; TODO: define failure modes |
725 | */ | 593 | */ |
726 | _MHD_EXTERN enum MHD_StatusCode | 594 | _MHD_EXTERN enum MHD_StatusCode |
727 | MHD_option_tls_mem_dhparams (struct MHD_Daemon *daemon, | 595 | MHD_daemon_tls_mem_dhparams (struct MHD_Daemon *daemon, |
728 | const char *dh); | 596 | const char *dh); |
729 | 597 | ||
730 | 598 | ||
@@ -737,7 +605,7 @@ _MHD_EXTERN enum MHD_StatusCode | |||
737 | * @return #MHD_SC_OK upon success; TODO: define failure modes | 605 | * @return #MHD_SC_OK upon success; TODO: define failure modes |
738 | */ | 606 | */ |
739 | _MHD_EXTERN enum MHD_StatusCode | 607 | _MHD_EXTERN enum MHD_StatusCode |
740 | MHD_option_tls_mem_trust (struct MHD_Daemon *daemon, | 608 | MHD_daemon_tls_mem_trust (struct MHD_Daemon *daemon, |
741 | const char *mem_trust); | 609 | const char *mem_trust); |
742 | 610 | ||
743 | 611 | ||
@@ -749,7 +617,7 @@ MHD_option_tls_mem_trust (struct MHD_Daemon *daemon, | |||
749 | * @return #MHD_SC_OK upon success; TODO: define failure modes | 617 | * @return #MHD_SC_OK upon success; TODO: define failure modes |
750 | */ | 618 | */ |
751 | _MHD_EXTERN enum MHD_StatusCode | 619 | _MHD_EXTERN enum MHD_StatusCode |
752 | MHD_option_gnutls_credentials (struct MHD_Daemon *daemon, | 620 | MHD_daemon_gnutls_credentials (struct MHD_Daemon *daemon, |
753 | int gnutls_credentials); | 621 | int gnutls_credentials); |
754 | 622 | ||
755 | 623 | ||
@@ -758,7 +626,7 @@ MHD_option_gnutls_credentials (struct MHD_Daemon *daemon, | |||
758 | * | 626 | * |
759 | * Use a callback to determine which X.509 certificate should be used | 627 | * Use a callback to determine which X.509 certificate should be used |
760 | * for a given HTTPS connection. This option provides an alternative | 628 | * for a given HTTPS connection. This option provides an alternative |
761 | * to #MHD_option_tls_key_and_cert_from_memory(). You must use this | 629 | * to #MHD_daemon_tls_key_and_cert_from_memory(). You must use this |
762 | * version if multiple domains are to be hosted at the same IP address | 630 | * version if multiple domains are to be hosted at the same IP address |
763 | * using TLS's Server Name Indication (SNI) extension. In this case, | 631 | * using TLS's Server Name Indication (SNI) extension. In this case, |
764 | * the callback is expected to select the correct certificate based on | 632 | * the callback is expected to select the correct certificate based on |
@@ -770,7 +638,7 @@ MHD_option_gnutls_credentials (struct MHD_Daemon *daemon, | |||
770 | * @param cb must be of type `gnutls_certificate_retrieve_function2 *`. | 638 | * @param cb must be of type `gnutls_certificate_retrieve_function2 *`. |
771 | */ | 639 | */ |
772 | _MHD_EXTERN void | 640 | _MHD_EXTERN void |
773 | MHD_option_gnutls_key_and_cert_from_callback (struct MHD_Daemon *daemon, | 641 | MHD_daemon_gnutls_key_and_cert_from_callback (struct MHD_Daemon *daemon, |
774 | void *cb); | 642 | void *cb); |
775 | 643 | ||
776 | 644 | ||
@@ -820,7 +688,7 @@ enum MHD_ThreadingModel | |||
820 | * number of worker threads to be used) | 688 | * number of worker threads to be used) |
821 | */ | 689 | */ |
822 | _MHD_EXTERN void | 690 | _MHD_EXTERN void |
823 | MHD_option_threading_model (struct MHD_Daemon *daemon, | 691 | MHD_daemon_threading_model (struct MHD_Daemon *daemon, |
824 | enum MHD_ThreadingModel tm); | 692 | enum MHD_ThreadingModel tm); |
825 | 693 | ||
826 | 694 | ||
@@ -830,7 +698,7 @@ MHD_option_threading_model (struct MHD_Daemon *daemon, | |||
830 | * @param cls closure | 698 | * @param cls closure |
831 | * @param addr address information from the client | 699 | * @param addr address information from the client |
832 | * @param addrlen length of @a addr | 700 | * @param addrlen length of @a addr |
833 | * @see #MHD_option_accept_policy() | 701 | * @see #MHD_daemon_accept_policy() |
834 | * @return #MHD_YES if connection is allowed, #MHD_NO if not | 702 | * @return #MHD_YES if connection is allowed, #MHD_NO if not |
835 | */ | 703 | */ |
836 | typedef enum MHD_Bool | 704 | typedef enum MHD_Bool |
@@ -849,11 +717,23 @@ typedef enum MHD_Bool | |||
849 | * @param apc_cls closure for @a apc | 717 | * @param apc_cls closure for @a apc |
850 | */ | 718 | */ |
851 | _MHD_EXTERN void | 719 | _MHD_EXTERN void |
852 | MHD_option_accept_policy (struct MHD_Daemon *daemon, | 720 | MHD_daemon_accept_policy (struct MHD_Daemon *daemon, |
853 | MHD_AcceptPolicyCallback apc, | 721 | MHD_AcceptPolicyCallback apc, |
854 | void *apc_cls); | 722 | void *apc_cls); |
855 | 723 | ||
856 | 724 | ||
725 | typedef void * | ||
726 | (MHD_EarlyUriLogCallback)(void *cls, | ||
727 | const char *uri, | ||
728 | struct MHD_Request *request); | ||
729 | |||
730 | |||
731 | _MHD_EXTERN void | ||
732 | MHD_daemon_set_early_uri_logger (struct MHD_Daemon *daemon, | ||
733 | MHD_EarlyUriLogCallback cb, | ||
734 | void *cb_cls); | ||
735 | |||
736 | |||
857 | /** | 737 | /** |
858 | * Signature of the callback used by MHD to notify the | 738 | * Signature of the callback used by MHD to notify the |
859 | * application about started/stopped connections | 739 | * application about started/stopped connections |
@@ -890,7 +770,7 @@ typedef void | |||
890 | * @param ccc_cls closure for @a ccc | 770 | * @param ccc_cls closure for @a ccc |
891 | */ | 771 | */ |
892 | _MHD_EXTERN void | 772 | _MHD_EXTERN void |
893 | MHD_option_set_notify_connection (struct MHD_Daemon *daemon, | 773 | MHD_daemon_set_notify_connection (struct MHD_Daemon *daemon, |
894 | MHD_NotifyConnectionCallback ncc, | 774 | MHD_NotifyConnectionCallback ncc, |
895 | void *ncc_cls); | 775 | void *ncc_cls); |
896 | 776 | ||
@@ -907,7 +787,7 @@ MHD_option_set_notify_connection (struct MHD_Daemon *daemon, | |||
907 | * @param memory_increment_b increment to use when growing the read buffer, must be smaller than @a memory_limit_b | 787 | * @param memory_increment_b increment to use when growing the read buffer, must be smaller than @a memory_limit_b |
908 | */ | 788 | */ |
909 | _MHD_EXTERN void | 789 | _MHD_EXTERN void |
910 | MHD_option_connection_memory_limit (struct MHD_Daemon *daemon, | 790 | MHD_daemon_connection_memory_limit (struct MHD_Daemon *daemon, |
911 | size_t memory_limit_b, | 791 | size_t memory_limit_b, |
912 | size_t memory_increment_b); | 792 | size_t memory_increment_b); |
913 | 793 | ||
@@ -921,7 +801,7 @@ MHD_option_connection_memory_limit (struct MHD_Daemon *daemon, | |||
921 | * @param stack_limit_b stack size to use in bytes | 801 | * @param stack_limit_b stack size to use in bytes |
922 | */ | 802 | */ |
923 | _MHD_EXTERN void | 803 | _MHD_EXTERN void |
924 | MHD_option_thread_stack_size (struct MHD_Daemon *daemon, | 804 | MHD_daemon_thread_stack_size (struct MHD_Daemon *daemon, |
925 | size_t stack_limit_b); | 805 | size_t stack_limit_b); |
926 | 806 | ||
927 | 807 | ||
@@ -941,7 +821,7 @@ MHD_option_thread_stack_size (struct MHD_Daemon *daemon, | |||
941 | * connections, they will be immediately rejected. | 821 | * connections, they will be immediately rejected. |
942 | */ | 822 | */ |
943 | _MHD_EXTERN void | 823 | _MHD_EXTERN void |
944 | MHD_option_connection_limits (struct MHD_Daemon *daemon, | 824 | MHD_daemon_connection_limits (struct MHD_Daemon *daemon, |
945 | unsigned int global_connection_limit, | 825 | unsigned int global_connection_limit, |
946 | unsigned int ip_connection_limit); | 826 | unsigned int ip_connection_limit); |
947 | 827 | ||
@@ -955,7 +835,7 @@ MHD_option_connection_limits (struct MHD_Daemon *daemon, | |||
955 | * @param timeout_s number of seconds of timeout to use | 835 | * @param timeout_s number of seconds of timeout to use |
956 | */ | 836 | */ |
957 | _MHD_EXTERN void | 837 | _MHD_EXTERN void |
958 | MHD_option_connection_default_timeout (struct MHD_Daemon *daemon, | 838 | MHD_daemon_connection_default_timeout (struct MHD_Daemon *daemon, |
959 | unsigned int timeout_s); | 839 | unsigned int timeout_s); |
960 | 840 | ||
961 | 841 | ||
@@ -989,7 +869,7 @@ MHD_UnescapeCallback (void *cls, | |||
989 | * @param unescape_cb_cls closure for @a unescape_cb | 869 | * @param unescape_cb_cls closure for @a unescape_cb |
990 | */ | 870 | */ |
991 | _MHD_EXTERN void | 871 | _MHD_EXTERN void |
992 | MHD_option_unescape_cb (struct MHD_Daemon *daemon, | 872 | MHD_daemon_unescape_cb (struct MHD_Daemon *daemon, |
993 | MHD_UnescapeCallback unescape_cb, | 873 | MHD_UnescapeCallback unescape_cb, |
994 | void *unescape_cb_cls); | 874 | void *unescape_cb_cls); |
995 | 875 | ||
@@ -1004,7 +884,7 @@ MHD_option_unescape_cb (struct MHD_Daemon *daemon, | |||
1004 | * @param buf entropy buffer | 884 | * @param buf entropy buffer |
1005 | */ | 885 | */ |
1006 | _MHD_EXTERN void | 886 | _MHD_EXTERN void |
1007 | MHD_option_digest_auth_random (struct MHD_Daemon *daemon, | 887 | MHD_daemon_digest_auth_random (struct MHD_Daemon *daemon, |
1008 | size_t buf_size, | 888 | size_t buf_size, |
1009 | const void *buf); | 889 | const void *buf); |
1010 | 890 | ||
@@ -1017,12 +897,10 @@ MHD_option_digest_auth_random (struct MHD_Daemon *daemon, | |||
1017 | * @param nc_length desired array length | 897 | * @param nc_length desired array length |
1018 | */ | 898 | */ |
1019 | _MHD_EXTERN void | 899 | _MHD_EXTERN void |
1020 | MHD_option_digest_auth_nc_size (struct MHD_Daemon *daemon, | 900 | MHD_daemon_digest_auth_nc_size (struct MHD_Daemon *daemon, |
1021 | size_t stack_limit_b); | 901 | size_t stack_limit_b); |
1022 | 902 | ||
1023 | 903 | ||
1024 | |||
1025 | |||
1026 | /* ********************* connection options ************** */ | 904 | /* ********************* connection options ************** */ |
1027 | 905 | ||
1028 | 906 | ||
@@ -1036,8 +914,8 @@ MHD_option_digest_auth_nc_size (struct MHD_Daemon *daemon, | |||
1036 | * @param timeout_s new timeout in seconds | 914 | * @param timeout_s new timeout in seconds |
1037 | */ | 915 | */ |
1038 | struct MHD_ConnectionOption | 916 | struct MHD_ConnectionOption |
1039 | MHD_connection_option_timeout (struct MHD_Connection *connection, | 917 | MHD_connection_timeout (struct MHD_Connection *connection, |
1040 | unsigned int timeout_s); | 918 | unsigned int timeout_s); |
1041 | 919 | ||
1042 | 920 | ||
1043 | /* **************** Request handling functions ***************** */ | 921 | /* **************** Request handling functions ***************** */ |
@@ -1207,6 +1085,7 @@ enum MHD_HTTP_StatusCode { | |||
1207 | /** @} */ /* end of group httpcode */ | 1085 | /** @} */ /* end of group httpcode */ |
1208 | 1086 | ||
1209 | 1087 | ||
1088 | |||
1210 | /** | 1089 | /** |
1211 | * Suspend handling of network data for a given request. This can | 1090 | * Suspend handling of network data for a given request. This can |
1212 | * be used to dequeue a request from MHD's event loop for a while. | 1091 | * be used to dequeue a request from MHD's event loop for a while. |
@@ -1227,15 +1106,15 @@ enum MHD_HTTP_StatusCode { | |||
1227 | * #MHD_RequestfetchResponseCallback. Suspending a request | 1106 | * #MHD_RequestfetchResponseCallback. Suspending a request |
1228 | * at any other time will cause an assertion failure. | 1107 | * at any other time will cause an assertion failure. |
1229 | * | 1108 | * |
1230 | * Finally, it is an API violation to call #MHD_stop_daemon while | 1109 | * Finally, it is an API violation to call #MHD_daemon_stop() while |
1231 | * having suspended requests (this will at least create memory and | 1110 | * having suspended requests (this will at least create memory and |
1232 | * socket leaks or lead to undefined behavior). You must explicitly | 1111 | * socket leaks or lead to undefined behavior). You must explicitly |
1233 | * resume all requests before stopping the daemon. | 1112 | * resume all requests before stopping the daemon. |
1234 | * | 1113 | * |
1235 | * @param request the request to suspend | 1114 | * @return action to cause a request to be suspended. |
1236 | */ | 1115 | */ |
1237 | _MHD_EXTERN void | 1116 | _MHD_EXTERN struct MHD_Action * |
1238 | MHD_request_suspend (struct MHD_Request *request); | 1117 | MHD_action_suspend (void); |
1239 | 1118 | ||
1240 | 1119 | ||
1241 | /** | 1120 | /** |
@@ -1260,18 +1139,68 @@ MHD_request_resume (struct MHD_Request *request); | |||
1260 | 1139 | ||
1261 | 1140 | ||
1262 | /** | 1141 | /** |
1263 | * Only respond in conservative HTTP 1.0-mode. In particular, | 1142 | * Converts a @a response to an action. If @a consume |
1264 | * do not (automatically) sent "Connection" headers and always | 1143 | * is set, the reference to the @a response is consumed |
1265 | * close the connection after generating the response. | 1144 | * by the conversion. If @a consume is #MHD_NO, then |
1145 | * the response can be converted to actions in the future. | ||
1146 | * However, the @a response is frozen by this step and | ||
1147 | * must no longer be modified (i.e. by setting headers). | ||
1148 | * | ||
1149 | * @param response response to convert, not NULL | ||
1150 | * @param consume should the response object be consumed? | ||
1151 | * @return corresponding action, never returns NULL | ||
1266 | * | 1152 | * |
1267 | * @param response the response to modify | 1153 | * Implementation note: internally, this is largely just |
1154 | * a cast (and possibly an RC increment operation), | ||
1155 | * as a response *is* an action. As no memory is | ||
1156 | * allocated, this operation cannot fail. | ||
1157 | */ | ||
1158 | struct MHD_Action * | ||
1159 | MHD_action_from_response (struct MHD_Response *response, | ||
1160 | enum MHD_bool consume); | ||
1161 | |||
1162 | |||
1163 | /** | ||
1164 | * Only respond in conservative HTTP 1.0-mode. In | ||
1165 | * particular, do not (automatically) sent "Connection" headers and | ||
1166 | * always close the connection after generating the response. | ||
1167 | * | ||
1168 | * @param request the request for which we force HTTP 1.0 to be used | ||
1268 | */ | 1169 | */ |
1269 | _MHD_EXTERN void | 1170 | _MHD_EXTERN void |
1270 | MHD_response_option_v10_only (struct MHD_Response *response); | 1171 | MHD_response_option_v10_only (struct MHD_Response *response); |
1271 | 1172 | ||
1272 | 1173 | ||
1273 | /** | 1174 | /** |
1274 | * Create a response object. The response object can be extended with | 1175 | * Signature of the callback used by MHD to notify the |
1176 | * application about completed requests. | ||
1177 | * | ||
1178 | * @param cls client-defined closure | ||
1179 | * @param toe reason for request termination | ||
1180 | * @see #MHD_option_request_completion() | ||
1181 | * @ingroup request | ||
1182 | */ | ||
1183 | typedef void | ||
1184 | (*MHD_RequestTerminationCallback) (void *cls, | ||
1185 | enum MHD_RequestTerminationCode toe); | ||
1186 | |||
1187 | |||
1188 | /** | ||
1189 | * Set a function to be called once MHD is finished with the | ||
1190 | * request. | ||
1191 | * | ||
1192 | * @param response which response to set the callback for | ||
1193 | * @param termination_cb function to call | ||
1194 | * @param termination_cb_cls closure for @e termination_cb | ||
1195 | */ | ||
1196 | void | ||
1197 | MHD_response_option_termination_callback (struct MHD_Response *response, | ||
1198 | MHD_RequestTerminationCallback termination_cb, | ||
1199 | void *termination_cb_cls); | ||
1200 | |||
1201 | |||
1202 | /** | ||
1203 | * Create a response action. The response object can be extended with | ||
1275 | * header information and then be used any number of times. | 1204 | * header information and then be used any number of times. |
1276 | * | 1205 | * |
1277 | * @param sc status code to return | 1206 | * @param sc status code to return |
@@ -1377,12 +1306,12 @@ MHD_response_from_fd (enum MHD_HTTP_StatusCode sc, | |||
1377 | 1306 | ||
1378 | 1307 | ||
1379 | /** | 1308 | /** |
1380 | * Enumeration for actions MHD should perform on the underlying socket | 1309 | * Enumeration for operations MHD should perform on the underlying socket |
1381 | * of the upgrade. This API is not finalized, and in particular | 1310 | * of the upgrade. This API is not finalized, and in particular |
1382 | * the final set of actions is yet to be decided. This is just an | 1311 | * the final set of actions is yet to be decided. This is just an |
1383 | * idea for what we might want. | 1312 | * idea for what we might want. |
1384 | */ | 1313 | */ |
1385 | enum MHD_UpgradeAction | 1314 | enum MHD_UpgradeOperation |
1386 | { | 1315 | { |
1387 | 1316 | ||
1388 | /** | 1317 | /** |
@@ -1390,7 +1319,7 @@ enum MHD_UpgradeAction | |||
1390 | * | 1319 | * |
1391 | * Takes no extra arguments. | 1320 | * Takes no extra arguments. |
1392 | */ | 1321 | */ |
1393 | MHD_UPGRADE_ACTION_CLOSE = 0 | 1322 | MHD_UPGRADE_OPERATION_CLOSE = 0 |
1394 | 1323 | ||
1395 | }; | 1324 | }; |
1396 | 1325 | ||
@@ -1411,14 +1340,14 @@ struct MHD_UpgradeResponseHandle; | |||
1411 | * | 1340 | * |
1412 | * @param urh the handle identifying the connection to perform | 1341 | * @param urh the handle identifying the connection to perform |
1413 | * the upgrade @a action on. | 1342 | * the upgrade @a action on. |
1414 | * @param action which action should be performed | 1343 | * @param operation which operation should be performed |
1415 | * @param ... arguments to the action (depends on the action) | 1344 | * @param ... arguments to the action (depends on the action) |
1416 | * @return #MHD_NO on error, #MHD_YES on success | 1345 | * @return #MHD_NO on error, #MHD_YES on success |
1417 | */ | 1346 | */ |
1418 | _MHD_EXTERN enum MHD_Bool | 1347 | _MHD_EXTERN enum MHD_Bool |
1419 | MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh, | 1348 | MHD_upgrade_operation (struct MHD_UpgradeResponseHandle *urh, |
1420 | enum MHD_UpgradeAction action, | 1349 | enum MHD_UpgradeOperation operation, |
1421 | ...); | 1350 | ...); |
1422 | 1351 | ||
1423 | 1352 | ||
1424 | /** | 1353 | /** |
@@ -1514,8 +1443,10 @@ MHD_response_for_upgrade (MHD_UpgradeHandler upgrade_handler, | |||
1514 | 1443 | ||
1515 | 1444 | ||
1516 | /** | 1445 | /** |
1517 | * Decrease reference counter of a response object. If the counter | 1446 | * Explicitly decrease reference counter of a response object. If the |
1518 | * hits zero, destroys a response object and associated resources. | 1447 | * counter hits zero, destroys a response object and associated |
1448 | * resources. Usually, this is implicitly done by converting a | ||
1449 | * response to an action and returning the action to MHD. | ||
1519 | * | 1450 | * |
1520 | * @param response response to decrement RC of | 1451 | * @param response response to decrement RC of |
1521 | * @ingroup response | 1452 | * @ingroup response |
@@ -1525,17 +1456,6 @@ MHD_response_decref (struct MHD_Response *response); | |||
1525 | 1456 | ||
1526 | 1457 | ||
1527 | /** | 1458 | /** |
1528 | * Increases reference counter of a response object. Used so that | ||
1529 | * the same response object can be queued repeatedly. | ||
1530 | * | ||
1531 | * @param response response to increment RC for | ||
1532 | * @ingroup response | ||
1533 | */ | ||
1534 | _MHD_EXTERN void | ||
1535 | MHD_response_incref (struct MHD_Response *response); | ||
1536 | |||
1537 | |||
1538 | /** | ||
1539 | * Add a header line to the response. | 1459 | * Add a header line to the response. |
1540 | * | 1460 | * |
1541 | * @param response response to add a header to | 1461 | * @param response response to add a header to |
@@ -1610,20 +1530,100 @@ MHD_response_get_header (struct MHD_Response *response, | |||
1610 | const char *key); | 1530 | const char *key); |
1611 | 1531 | ||
1612 | 1532 | ||
1613 | /* ********************** PostProcessor functions ********************** */ | 1533 | /* ************Upload and PostProcessor functions ********************** */ |
1614 | 1534 | ||
1615 | /** | 1535 | /** |
1616 | * Create a `struct MHD_PostProcessor`. | 1536 | * Action telling MHD to continue processing the upload. |
1617 | * | 1537 | * |
1618 | * A `struct MHD_PostProcessor` can be used to (incrementally) parse | 1538 | * @return action operation, never NULL |
1619 | * the data portion of a POST request. Note that some buggy browsers | 1539 | */ |
1620 | * fail to set the encoding type. If you want to support those, you | 1540 | _MHD_EXTERN struct MHD_Action * |
1621 | * may have to call #MHD_set_connection_value with the proper encoding | 1541 | MHD_action_continue (void); |
1622 | * type before creating a post processor (if no supported encoding | 1542 | |
1623 | * type is set, this function will fail). | 1543 | |
1544 | /** | ||
1545 | * Function to process data uploaded by a client. | ||
1546 | * | ||
1547 | * @param cls argument given together with the function | ||
1548 | * pointer when the handler was registered with MHD | ||
1549 | * @param upload_data the data being uploaded (excluding headers) | ||
1550 | * POST data will typically be made available incrementally via | ||
1551 | * multiple callbacks | ||
1552 | * @param[in,out] upload_data_size set initially to the size of the | ||
1553 | * @a upload_data provided; the method must update this | ||
1554 | * value to the number of bytes NOT processed; | ||
1555 | * @return action specifying how to proceed, often | ||
1556 | * #MHD_action_continue() if all is well, | ||
1557 | * #MHD_action_suspend() to stop reading the upload until | ||
1558 | * the request is resumed, | ||
1559 | * NULL to close the socket, or a response | ||
1560 | * to discard the rest of the upload and return the data given | ||
1561 | */ | ||
1562 | typedef struct MHD_Action * | ||
1563 | (*MHD_UploadCallback) (void *cls, | ||
1564 | const char *upload_data, | ||
1565 | size_t *upload_data_size); | ||
1566 | |||
1567 | |||
1568 | /** | ||
1569 | * Create an action that handles an upload. | ||
1570 | * | ||
1571 | * @param uc function to call with uploaded data | ||
1572 | * @param uc_cls closure for @a uc | ||
1573 | * @return NULL on error (out of memory) | ||
1574 | * @ingroup action | ||
1575 | */ | ||
1576 | _MHD_EXTERN struct MHD_Action * | ||
1577 | MHD_action_process_upload (MHD_UploadCallback uc, | ||
1578 | void *uc_cls); | ||
1579 | |||
1580 | |||
1581 | /** | ||
1582 | * Iterator over key-value pairs where the value maybe made available | ||
1583 | * in increments and/or may not be zero-terminated. Used for | ||
1584 | * MHD parsing POST data. To access "raw" data from POST or PUT | ||
1585 | * requests, use #MHD_action_process_upload() instead. | ||
1586 | * | ||
1587 | * @param cls user-specified closure | ||
1588 | * @param kind type of the value, always #MHD_POSTDATA_KIND when called from MHD | ||
1589 | * @param key 0-terminated key for the value | ||
1590 | * @param filename name of the uploaded file, NULL if not known | ||
1591 | * @param content_type mime-type of the data, NULL if not known | ||
1592 | * @param transfer_encoding encoding of the data, NULL if not known | ||
1593 | * @param data pointer to @a size bytes of data at the | ||
1594 | * specified offset | ||
1595 | * @param off offset of data in the overall value | ||
1596 | * @param size number of bytes in @a data available | ||
1597 | * @return action specifying how to proceed, often | ||
1598 | * #MHD_action_continue() if all is well, | ||
1599 | * #MHD_action_suspend() to stop reading the upload until | ||
1600 | * the request is resumed, | ||
1601 | * NULL to close the socket, or a response | ||
1602 | * to discard the rest of the upload and return the data given | ||
1603 | */ | ||
1604 | typedef struct MHD_Action * | ||
1605 | (*MHD_PostDataIterator) (void *cls, | ||
1606 | enum MHD_ValueKind kind, | ||
1607 | const char *key, | ||
1608 | const char *filename, | ||
1609 | const char *content_type, | ||
1610 | const char *transfer_encoding, | ||
1611 | const char *data, | ||
1612 | uint64_t off, | ||
1613 | size_t size); | ||
1614 | |||
1615 | |||
1616 | /** | ||
1617 | * Create an action that parses a POST request. | ||
1618 | * | ||
1619 | * This action can be used to (incrementally) parse the data portion | ||
1620 | * of a POST request. Note that some buggy browsers fail to set the | ||
1621 | * encoding type. If you want to support those, you may have to call | ||
1622 | * #MHD_set_connection_value with the proper encoding type before | ||
1623 | * returning this action (if no supported encoding type is detected, | ||
1624 | * returning this action will cause a bad request to be returned to | ||
1625 | * the client). | ||
1624 | * | 1626 | * |
1625 | * @param connection the connection on which the POST is | ||
1626 | * happening (used to determine the POST format) | ||
1627 | * @param buffer_size maximum number of bytes to use for | 1627 | * @param buffer_size maximum number of bytes to use for |
1628 | * internal buffering (used only for the parsing, | 1628 | * internal buffering (used only for the parsing, |
1629 | * specifically the parsing of the keys). A | 1629 | * specifically the parsing of the keys). A |
@@ -1637,44 +1637,11 @@ MHD_response_get_header (struct MHD_Response *response, | |||
1637 | * otherwise a PP handle | 1637 | * otherwise a PP handle |
1638 | * @ingroup request | 1638 | * @ingroup request |
1639 | */ | 1639 | */ |
1640 | _MHD_EXTERN struct MHD_PostProcessor * | 1640 | _MHD_EXTERN struct MHD_Action * |
1641 | MHD_post_processor_create (struct MHD_Connection *connection, | 1641 | MHD_action_parse_post (size_t buffer_size, |
1642 | size_t buffer_size, | 1642 | MHD_PostDataIterator iter, |
1643 | MHD_PostDataIterator iter, | 1643 | void *iter_cls); |
1644 | void *iter_cls); | ||
1645 | |||
1646 | |||
1647 | /** | ||
1648 | * Parse and process POST data. Call this function when POST data is | ||
1649 | * available (usually during an #MHD_AccessHandlerCallback) with the | ||
1650 | * "upload_data" and "upload_data_size". Whenever possible, this will | ||
1651 | * then cause calls to the #MHD_PostDataIterator. | ||
1652 | * | ||
1653 | * @param pp the post processor | ||
1654 | * @param post_data @a post_data_len bytes of POST data | ||
1655 | * @param post_data_len length of @a post_data | ||
1656 | * @return #MHD_YES on success, #MHD_NO on error | ||
1657 | * (out-of-memory, iterator aborted, parse error) | ||
1658 | * @ingroup request | ||
1659 | */ | ||
1660 | _MHD_EXTERN enum MHD_Bool | ||
1661 | MHD_post_processor_run (struct MHD_PostProcessor *pp, | ||
1662 | const char *post_data, | ||
1663 | size_t post_data_len); | ||
1664 | |||
1665 | 1644 | ||
1666 | /** | ||
1667 | * Release PostProcessor resources. | ||
1668 | * | ||
1669 | * @param pp the PostProcessor to destroy | ||
1670 | * @return #MHD_YES if processing completed nicely, | ||
1671 | * #MHD_NO if there were spurious characters / formatting | ||
1672 | * problems; it is common to ignore the return | ||
1673 | * value of this function | ||
1674 | * @ingroup request | ||
1675 | */ | ||
1676 | _MHD_EXTERN enum MHD_Bool | ||
1677 | MHD_post_processor_destroy (struct MHD_PostProcessor *pp); | ||
1678 | 1645 | ||
1679 | 1646 | ||
1680 | /* ********************** generic query functions ********************** */ | 1647 | /* ********************** generic query functions ********************** */ |