aboutsummaryrefslogtreecommitdiff
path: root/src/lib/internal.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/internal.h')
-rw-r--r--src/lib/internal.h160
1 files changed, 154 insertions, 6 deletions
diff --git a/src/lib/internal.h b/src/lib/internal.h
index f5df8ce2..5a08a0b2 100644
--- a/src/lib/internal.h
+++ b/src/lib/internal.h
@@ -32,6 +32,8 @@
32#include "microhttpd2.h" 32#include "microhttpd2.h"
33#include "microhttpd_tls.h" 33#include "microhttpd_tls.h"
34#include "mhd_assert.h" 34#include "mhd_assert.h"
35#include "mhd_compat.h"
36#include "memorypool.h"
35 37
36#ifdef HTTPS_SUPPORT 38#ifdef HTTPS_SUPPORT
37#include <gnutls/gnutls.h> 39#include <gnutls/gnutls.h>
@@ -67,9 +69,23 @@
67#include "mhd_threads.h" 69#include "mhd_threads.h"
68#include "mhd_locks.h" 70#include "mhd_locks.h"
69#include "mhd_sockets.h" 71#include "mhd_sockets.h"
72#include "mhd_str.h"
70#include "mhd_itc_types.h" 73#include "mhd_itc_types.h"
71 74
72 75
76#ifdef HAVE_MESSAGES
77/**
78 * fprintf()-like helper function for logging debug
79 * messages.
80 */
81void
82MHD_DLOG (const struct MHD_Daemon *daemon,
83 enum MHD_StatusCode sc,
84 const char *format,
85 ...);
86#endif
87
88
73/** 89/**
74 * Close FD and abort execution if error is detected. 90 * Close FD and abort execution if error is detected.
75 * @param fd the FD to close 91 * @param fd the FD to close
@@ -345,13 +361,40 @@ struct MHD_HTTP_Header
345 361
346 362
347/** 363/**
364 * What is this request waiting for?
365 */
366enum MHD_RequestEventLoopInfo
367{
368 /**
369 * We are waiting to be able to read.
370 */
371 MHD_EVENT_LOOP_INFO_READ = 0,
372
373 /**
374 * We are waiting to be able to write.
375 */
376 MHD_EVENT_LOOP_INFO_WRITE = 1,
377
378 /**
379 * We are waiting for the application to provide data.
380 */
381 MHD_EVENT_LOOP_INFO_BLOCK = 2,
382
383 /**
384 * We are finished and are awaiting cleanup.
385 */
386 MHD_EVENT_LOOP_INFO_CLEANUP = 3
387};
388
389
390/**
348 * State kept for each HTTP request. 391 * State kept for each HTTP request.
349 */ 392 */
350struct MHD_Request 393struct MHD_Request
351{ 394{
352 395
353 /** 396 /**
354 * Reference to the MHD_Daemon struct. 397 * Reference to the `struct MHD_Daemon`.
355 */ 398 */
356 struct MHD_Daemon *daemon; 399 struct MHD_Daemon *daemon;
357 400
@@ -361,6 +404,12 @@ struct MHD_Request
361 struct MHD_Connection *connection; 404 struct MHD_Connection *connection;
362 405
363 /** 406 /**
407 * Response to return for this request, set once
408 * it is available.
409 */
410 struct MHD_Response *response;
411
412 /**
364 * Linked list of parsed headers. 413 * Linked list of parsed headers.
365 */ 414 */
366 struct MHD_HTTP_Header *headers_received; 415 struct MHD_HTTP_Header *headers_received;
@@ -389,9 +438,10 @@ struct MHD_Request
389 void *client_context; 438 void *client_context;
390 439
391 /** 440 /**
392 * Request method. Should be GET/POST/etc. Allocated in pool. 441 * Request method as string. Should be GET/POST/etc. Allocated in
442 * pool.
393 */ 443 */
394 char *method; 444 char *method_s;
395 445
396 /** 446 /**
397 * Requested URL (everything after "GET" only). Allocated 447 * Requested URL (everything after "GET" only). Allocated
@@ -557,6 +607,11 @@ struct MHD_Request
557 enum MHD_REQUEST_STATE state; 607 enum MHD_REQUEST_STATE state;
558 608
559 /** 609 /**
610 * HTTP method, as an enum.
611 */
612 enum MHD_Method method;
613
614 /**
560 * What is this request waiting for? 615 * What is this request waiting for?
561 */ 616 */
562 enum MHD_RequestEventLoopInfo event_loop_info; 617 enum MHD_RequestEventLoopInfo event_loop_info;
@@ -591,6 +646,54 @@ struct MHD_Request
591}; 646};
592 647
593 648
649#ifdef EPOLL_SUPPORT
650/**
651 * State of the socket with respect to epoll (bitmask).
652 */
653enum MHD_EpollState
654{
655
656 /**
657 * The socket is not involved with a defined state in epoll() right
658 * now.
659 */
660 MHD_EPOLL_STATE_UNREADY = 0,
661
662 /**
663 * epoll() told us that data was ready for reading, and we did
664 * not consume all of it yet.
665 */
666 MHD_EPOLL_STATE_READ_READY = 1,
667
668 /**
669 * epoll() told us that space was available for writing, and we did
670 * not consume all of it yet.
671 */
672 MHD_EPOLL_STATE_WRITE_READY = 2,
673
674 /**
675 * Is this connection currently in the 'eready' EDLL?
676 */
677 MHD_EPOLL_STATE_IN_EREADY_EDLL = 4,
678
679 /**
680 * Is this connection currently in the epoll() set?
681 */
682 MHD_EPOLL_STATE_IN_EPOLL_SET = 8,
683
684 /**
685 * Is this connection currently suspended?
686 */
687 MHD_EPOLL_STATE_SUSPENDED = 16,
688
689 /**
690 * Is this connection in some error state?
691 */
692 MHD_EPOLL_STATE_ERROR = 128
693};
694#endif
695
696
594/** 697/**
595 * State kept per HTTP connection. 698 * State kept per HTTP connection.
596 */ 699 */
@@ -990,7 +1093,11 @@ struct MHD_Daemon
990 */ 1093 */
991 bool allow_address_reuse; 1094 bool allow_address_reuse;
992 1095
993 1096 /**
1097 * Are we shutting down?
1098 */
1099 volatile bool shutdown;
1100
994}; 1101};
995 1102
996 1103
@@ -1000,10 +1107,11 @@ struct MHD_Daemon
1000 * 1107 *
1001 * @param cls action-specfic closure 1108 * @param cls action-specfic closure
1002 * @param request the request on which the action is to be performed 1109 * @param request the request on which the action is to be performed
1110 * @return #MHD_SC_OK on success, otherwise an error code
1003 */ 1111 */
1004typedef void 1112typedef enum MHD_StatusCode
1005(*ActionCallback) (void *cls, 1113(*ActionCallback) (void *cls,
1006 const struct MHD_Request *request); 1114 struct MHD_Request *request);
1007 1115
1008 1116
1009/** 1117/**
@@ -1153,4 +1261,44 @@ struct MHD_Response
1153 1261
1154 1262
1155 1263
1264/**
1265 * Callback invoked when iterating over @a key / @a value
1266 * argument pairs during parsing.
1267 *
1268 * @param connection context of the iteration
1269 * @param key 0-terminated key string, never NULL
1270 * @param value 0-terminated value string, may be NULL
1271 * @param kind origin of the key-value pair
1272 * @return #MHD_YES on success (continue to iterate)
1273 * #MHD_NO to signal failure (and abort iteration)
1274 */
1275typedef int
1276(*MHD_ArgumentIterator_)(struct MHD_Connection *connection,
1277 const char *key,
1278 const char *value,
1279 enum MHD_ValueKind kind);
1280
1281
1282/**
1283 * Parse and unescape the arguments given by the client
1284 * as part of the HTTP request URI.
1285 *
1286 * @param kind header kind to pass to @a cb
1287 * @param connection connection to add headers to
1288 * @param[in,out] args argument URI string (after "?" in URI),
1289 * clobbered in the process!
1290 * @param cb function to call on each key-value pair found
1291 * @param[out] num_headers set to the number of headers found
1292 * @return #MHD_NO on failure (@a cb returned #MHD_NO),
1293 * #MHD_YES for success (parsing succeeded, @a cb always
1294 * returned #MHD_YES)
1295 */
1296int
1297MHD_parse_arguments_ (struct MHD_Connection *connection,
1298 enum MHD_ValueKind kind,
1299 char *args,
1300 MHD_ArgumentIterator_ cb,
1301 unsigned int *num_headers);
1302
1303
1156#endif 1304#endif