GNU libmicrohttpd 1.0.2
Loading...
Searching...
No Matches
internal.h
Go to the documentation of this file.
1/*
2 This file is part of libmicrohttpd
3 Copyright (C) 2007-2018 Daniel Pittman and Christian Grothoff
4 Copyright (C) 2014-2023 Evgeny Grin (Karlson2k)
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20
29#ifndef INTERNAL_H
30#define INTERNAL_H
31
32#include "mhd_options.h"
33#include "platform.h"
34#include "microhttpd.h"
35#include "mhd_assert.h"
36
37#ifdef HTTPS_SUPPORT
38#include <gnutls/gnutls.h>
39#if GNUTLS_VERSION_MAJOR >= 3
40#include <gnutls/abstract.h>
41#endif
42#endif /* HTTPS_SUPPORT */
43
44#ifdef HAVE_STDBOOL_H
45#include <stdbool.h>
46#endif
47
48#ifdef HAVE_INTTYPES_H
49#include <inttypes.h>
50#endif /* HAVE_INTTYPES_H */
51
52#ifndef PRIu64
53#define PRIu64 "llu"
54#endif /* ! PRIu64 */
55
56/* Must be included before other internal headers! */
57#include "mhd_panic.h"
58
59#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
60#include "mhd_threads.h"
61#endif
62#include "mhd_locks.h"
63#include "mhd_sockets.h"
64#include "mhd_itc_types.h"
65#include "mhd_str_types.h"
66#if defined(BAUTH_SUPPORT) || defined(DAUTH_SUPPORT)
67#include "gen_auth.h"
68#endif /* BAUTH_SUPPORT || DAUTH_SUPPORT*/
69
70
77#define _MHD_DROP_CONST(ptr) ((void *) ((uintptr_t) ((const void *) (ptr))))
78
83#define _MHD_MACRO_NO 0
84
89#define _MHD_MACRO_YES 1
90
95#define MHD_fd_close_chk_(fd) do { \
96 if ( (0 != close ((fd)) && (EBADF == errno)) ) { \
97 MHD_PANIC (_ ("Failed to close FD.\n")); \
98 } \
99} while (0)
100
101/*
102#define EXTRA_CHECKS _MHD_MACRO_NO
103 * Not used. Behaviour is controlled by _DEBUG/NDEBUG macros.
104 */
105
106#ifndef _MHD_DEBUG_CONNECT
111#define _MHD_DEBUG_CONNECT _MHD_MACRO_NO
112#endif /* ! _MHD_DEBUG_CONNECT */
113
114#ifndef _MHD_DEBUG_SEND_DATA
118#define _MHD_DEBUG_SEND_DATA _MHD_MACRO_NO
119#endif /* ! _MHD_DEBUG_SEND_DATA */
120
121#ifndef _MHD_DEBUG_CLOSE
126#define _MHD_DEBUG_CLOSE _MHD_MACRO_NO
127#endif /* ! _MHD_DEBUG_CLOSE */
128
129#define MHD_MAX(a,b) (((a)<(b)) ? (b) : (a))
130#define MHD_MIN(a,b) (((a)<(b)) ? (a) : (b))
131
132
142#define MHD_BUF_INC_SIZE 1500
143
144#ifndef MHD_STATICSTR_LEN_
148#define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1)
149#endif /* ! MHD_STATICSTR_LEN_ */
150
151
156{
158 _MHD_OFF = false,
159 _MHD_NO = false,
160 _MHD_ON = true,
161 _MHD_YES = true
163
164
209
210
243
244
249#define MHD_TEST_ALLOW_SUSPEND_RESUME 8192
250
257#define MAX_CLIENT_NONCE_LENGTH 129
258
266#if defined(MHD_SHA256_SUPPORT) || defined(MHD_SHA512_256_SUPPORT)
267#define MAX_DIGEST_NONCE_LENGTH ((32 + 6) * 2)
268#else /* !MHD_SHA256_SUPPORT && !MHD_SHA512_256_SUPPORT */
269#define MAX_DIGEST_NONCE_LENGTH ((16 + 6) * 2)
270#endif /* !MHD_SHA256_SUPPORT && !MHD_SHA512_256_SUPPORT */
271
277{
278
285 uint32_t nc;
286
293 uint64_t nmask;
294
299
300};
301
302#ifdef HAVE_MESSAGES
307void
308MHD_DLOG (const struct MHD_Daemon *daemon,
309 const char *format,
310 ...);
311
312#endif
313
314
319{
324
329
333 char *header;
334
339
343 char *value;
344
349
354
355};
356
357
362{
367
372
376 const char *header;
377
382
386 const char *value;
387
392
397
398};
399
400
413
414
415#if defined(MHD_WINSOCK_SOCKETS)
420typedef struct _MHD_W32_iovec
421{
422 unsigned long iov_len;
423 char *iov_base;
424} MHD_iovec_;
425#define MHD_IOV_ELMN_MAX_SIZE ULONG_MAX
426typedef unsigned long MHD_iov_size_;
427#elif defined(HAVE_SENDMSG) || defined(HAVE_WRITEV)
432typedef struct iovec MHD_iovec_;
433#define MHD_IOV_ELMN_MAX_SIZE SIZE_MAX
434typedef size_t MHD_iov_size_;
435#else
440typedef struct MHD_IoVec MHD_iovec_;
441#define MHD_IOV_ELMN_MAX_SIZE SIZE_MAX
442typedef size_t MHD_iov_size_;
443#endif
444
445
447{
454
459 size_t cnt;
460
466 size_t sent;
467};
468
473{
474
479
484
489 const char *data;
490
495 void *crc_cls;
496
502
508
509#ifdef UPGRADE_SUPPORT
515 MHD_UpgradeHandler upgrade_handler;
516
520 void *upgrade_handler_cls;
521#endif /* UPGRADE_SUPPORT */
522
523#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
528 MHD_mutex_ mutex;
529#endif
530
535 uint64_t total_size;
536
541 uint64_t data_start;
542
546 uint64_t fd_off;
547
552 size_t data_size;
553
558
563 unsigned int reference_count;
564
568 int fd;
569
574
579
584
589
593 unsigned int data_iovcnt;
594};
595
596
613{
619
625
632
637
642
647
652
657
664
669
676
682
689
695
700
706
711
716
721
726
731
737
742
743#ifdef UPGRADE_SUPPORT
744 ,
749 MHD_CONNECTION_UPGRADE = MHD_CONNECTION_CLOSED + 1
750#endif /* UPGRADE_SUPPORT */
751
753
754
771
775#define DEBUG_STATES _MHD_MACRO_NO
776
777
778#ifdef HAVE_MESSAGES
779#if DEBUG_STATES
780const char *
781MHD_state_to_string (enum MHD_CONNECTION_STATE state);
782
783#endif
784#endif
785
794typedef ssize_t
795(*ReceiveCallback) (struct MHD_Connection *conn,
796 void *write_to,
797 size_t max_bytes);
798
799
808typedef ssize_t
809(*TransmitCallback) (struct MHD_Connection *conn,
810 const void *read_from,
811 size_t max_bytes);
812
813
839
877
881#define MHD_IS_HTTP_VER_SUPPORTED(ver) (MHD_HTTP_VER_1_0 <= (ver) && \
882 MHD_HTTP_VER_1_2__1_9 >= (ver))
883
890#define MHD_IS_HTTP_VER_1_1_COMPAT(ver) (MHD_HTTP_VER_1_1 == (ver) || \
891 MHD_HTTP_VER_1_2__1_9 == (ver))
892
941
942
981
986{
990 size_t proc_pos;
991
999 size_t ws_start;
1000
1006
1012 size_t name_len;
1013
1019
1026};
1027
1043
1044
1049{
1055 const char *start;
1061 size_t size;
1062};
1063
1070{
1075 const char *version;
1076
1081
1085 const char *method;
1086
1091
1096 const char *url;
1097
1101 size_t url_len;
1102
1107
1112
1117
1125
1135
1141
1153
1162
1168
1185
1193
1200
1201#ifdef BAUTH_SUPPORT
1207 const struct MHD_RqBAuth *bauth;
1208
1212 bool bauth_tried;
1213#endif /* BAUTH_SUPPORT */
1214#ifdef DAUTH_SUPPORT
1220 const struct MHD_RqDAuth *dauth;
1221
1225 bool dauth_tried;
1226#endif /* DAUTH_SUPPORT */
1232
1237
1242};
1243
1244
1249{
1250#ifdef _DEBUG
1251 bool set;
1252#endif /* _DEBUG */
1255 bool chunked;
1256};
1257
1258#if defined(_MHD_HAVE_SENDFILE)
1259enum MHD_resp_sender_
1260{
1261 MHD_resp_sender_std = 0,
1262 MHD_resp_sender_sendfile
1263};
1264#endif /* _MHD_HAVE_SENDFILE */
1265
1272{
1277
1282 unsigned int responseCode;
1283
1289
1296
1304
1305#if defined(_MHD_HAVE_SENDFILE)
1306 enum MHD_resp_sender_ resp_sender;
1307#endif /* _MHD_HAVE_SENDFILE */
1308
1313};
1314
1319{
1320
1321#ifdef EPOLL_SUPPORT
1325 struct MHD_Connection *nextE;
1326
1330 struct MHD_Connection *prevE;
1331#endif
1332
1337
1342
1351
1356
1361
1366
1371
1380 struct MemoryPool *pool;
1381
1390
1397
1404
1410
1415 struct sockaddr_storage *addr;
1416
1417#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1423#endif
1424
1431
1437
1442
1447
1453
1459
1463 socklen_t addr_len;
1464
1470
1477
1484
1490
1495
1500
1505
1510
1518
1527
1536
1537#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1541 bool thread_joined;
1542#endif
1543
1549
1554
1555#ifdef EPOLL_SUPPORT
1559 enum MHD_EpollState epoll_state;
1560#endif
1561
1566
1571
1576
1577#ifdef UPGRADE_SUPPORT
1584 struct MHD_UpgradeResponseHandle *urh;
1585#endif /* UPGRADE_SUPPORT */
1586
1587#ifdef HTTPS_SUPPORT
1588
1592 gnutls_session_t tls_session;
1593
1597 enum MHD_TLS_CONN_STATE tls_state;
1598
1603 bool tls_read_ready;
1604#endif /* HTTPS_SUPPORT */
1605
1610
1617
1621 volatile bool resuming;
1622
1627};
1628
1629
1630#ifdef UPGRADE_SUPPORT
1640#define RESERVE_EBUF_SIZE 8
1641
1648struct UpgradeEpollHandle
1649{
1654 struct MHD_UpgradeResponseHandle *urh;
1655
1671 MHD_socket socket;
1672
1676 enum MHD_EpollState celi;
1677
1678};
1679
1680
1686struct MHD_UpgradeResponseHandle
1687{
1693 struct MHD_Connection *connection;
1694
1695#ifdef HTTPS_SUPPORT
1699 struct MHD_UpgradeResponseHandle *next;
1700
1704 struct MHD_UpgradeResponseHandle *prev;
1705
1706#ifdef EPOLL_SUPPORT
1710 struct MHD_UpgradeResponseHandle *nextE;
1711
1715 struct MHD_UpgradeResponseHandle *prevE;
1716
1720 bool in_eready_list;
1721#endif
1722
1728 char *in_buffer;
1729
1735 char *out_buffer;
1736
1742 size_t in_buffer_size;
1743
1749 size_t out_buffer_size;
1750
1758 size_t in_buffer_used;
1759
1767 size_t out_buffer_used;
1768
1772 struct UpgradeEpollHandle app;
1773
1778 struct UpgradeEpollHandle mhd;
1779
1784 char e_buf[RESERVE_EBUF_SIZE];
1785
1786#endif /* HTTPS_SUPPORT */
1787
1798 volatile bool was_closed;
1799
1821 volatile bool clean_ready;
1822};
1823#endif /* UPGRADE_SUPPORT */
1824
1825
1834typedef void *
1835(*LogCallback)(void *cls,
1836 const char *uri,
1837 struct MHD_Connection *con);
1838
1848typedef size_t
1849(*UnescapeCallback)(void *cls,
1850 struct MHD_Connection *conn,
1851 char *uri);
1852
1853
1862{
1863
1868
1873
1881
1886
1891
1896
1901
1906
1911
1916
1921
1926
1927#ifdef EPOLL_SUPPORT
1931 struct MHD_Connection *eready_head;
1932
1936 struct MHD_Connection *eready_tail;
1937
1944 int epoll_fd;
1945
1950 bool listen_socket_in_epoll;
1951
1952#ifdef UPGRADE_SUPPORT
1953#ifdef HTTPS_SUPPORT
1958 int epoll_upgrade_fd;
1959
1964 bool upgrade_fd_in_epoll;
1965#endif /* HTTPS_SUPPORT */
1966
1970 struct MHD_UpgradeResponseHandle *eready_urh_head;
1971
1975 struct MHD_UpgradeResponseHandle *eready_urh_tail;
1976#endif /* UPGRADE_SUPPORT */
1977#endif /* EPOLL_SUPPORT */
1978
1994
2001
2009
2016
2022
2026 void *apc_cls;
2027
2033
2038
2044
2049
2058
2063
2068
2073
2080 uint16_t port;
2081
2082#ifdef HAVE_MESSAGES
2087 MHD_LogCallback custom_error_log;
2088
2092 void *custom_error_log_cls;
2093#endif
2094
2099
2107
2112
2113#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2117 struct MHD_Daemon *worker_pool;
2118#endif
2119
2124
2131 unsigned int connections;
2132
2137
2142
2143#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2147 size_t thread_stack_size;
2148
2152 unsigned int worker_pool_size;
2153
2158
2162 MHD_mutex_ per_ip_connection_mutex;
2163
2168 MHD_mutex_ cleanup_connection_mutex;
2169
2173 MHD_mutex_ new_connections_mutex;
2174#endif
2175
2181
2192
2193
2198 struct MHD_itc_ itc;
2199
2203 volatile bool shutdown;
2204
2210 volatile bool was_quiesced;
2211
2220
2221 /*
2222 * Do we need to process resuming connections?
2223 */
2224 volatile bool resuming;
2225
2230 volatile bool have_new;
2231
2242
2246 unsigned int connection_limit;
2247
2254
2260
2266
2267#ifdef HAS_FD_SETSIZE_OVERRIDABLE
2274 int fdset_size;
2275
2280 bool fdset_size_set_by_app;
2281#endif /* HAS_FD_SETSIZE_OVERRIDABLE */
2282
2287
2288#ifdef HTTPS_SUPPORT
2289#ifdef UPGRADE_SUPPORT
2295 struct MHD_UpgradeResponseHandle *urh_head;
2296
2302 struct MHD_UpgradeResponseHandle *urh_tail;
2303#endif /* UPGRADE_SUPPORT */
2304
2308 gnutls_priority_t priority_cache;
2309
2314 gnutls_credentials_type_t cred_type;
2315
2319 gnutls_certificate_credentials_t x509_cred;
2320
2324 gnutls_dh_params_t dh_params;
2325
2329 gnutls_psk_server_credentials_t psk_cred;
2330
2331#if GNUTLS_VERSION_MAJOR >= 3
2336 gnutls_certificate_retrieve_function2 *cert_callback;
2337
2342
2346 void *cred_callback_cls;
2347#endif
2348
2349#if GNUTLS_VERSION_NUMBER >= 0x030603
2354 gnutls_certificate_retrieve_function3 *cert_callback2;
2355#endif
2356
2360 const char *https_mem_key;
2361
2365 const char *https_mem_cert;
2366
2370 const char *https_key_password;
2371
2375 const char *https_mem_trust;
2376
2380 gnutls_dh_params_t https_mem_dhparams;
2381
2385 bool have_dhparams;
2386
2390 bool disable_alpn;
2391
2392 #endif /* HTTPS_SUPPORT */
2393
2394#ifdef DAUTH_SUPPORT
2395
2399 const char *digest_auth_random;
2400
2404 size_t digest_auth_rand_size;
2405
2409 void *digest_auth_random_copy;
2410
2414 struct MHD_NonceNc *nnc;
2415
2416#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2420 MHD_mutex_ nnc_lock;
2421#endif
2422
2426 unsigned int nonce_nc_size;
2427
2431 unsigned int dauth_bind_type;
2432
2436 unsigned int dauth_def_nonce_timeout;
2437
2441 uint32_t dauth_def_max_nc;
2442#endif
2443
2444#ifdef TCP_FASTOPEN
2448 unsigned int fastopen_queue_size;
2449#endif
2450
2455
2456 /* TODO: replace with a single member */
2461
2462#ifdef EPOLL_SUPPORT
2466 union MHD_DaemonInfo daemon_info_dummy_epoll_fd;
2467#endif /* EPOLL_SUPPORT */
2468
2473
2478
2483
2484#if defined(_DEBUG) && defined(HAVE_ACCEPT4)
2493 bool avoid_accept4;
2494#endif /* _DEBUG */
2495};
2496
2497
2498#if defined(HAVE_POLL) && defined(EPOLL_SUPPORT)
2502#define MHD_D_IS_USING_SELECT_(d) \
2503 (0 == (d->options & (MHD_USE_POLL | MHD_USE_EPOLL)))
2507#define MHD_D_IS_USING_POLL_(d) (0 != ((d)->options & MHD_USE_POLL))
2511#define MHD_D_IS_USING_EPOLL_(d) (0 != ((d)->options & MHD_USE_EPOLL))
2512#elif defined(HAVE_POLL)
2516#define MHD_D_IS_USING_SELECT_(d) (0 == ((d)->options & MHD_USE_POLL))
2520#define MHD_D_IS_USING_POLL_(d) (0 != ((d)->options & MHD_USE_POLL))
2524#define MHD_D_IS_USING_EPOLL_(d) ((void) (d), 0)
2525#elif defined(EPOLL_SUPPORT)
2529#define MHD_D_IS_USING_SELECT_(d) (0 == ((d)->options & MHD_USE_EPOLL))
2533#define MHD_D_IS_USING_POLL_(d) ((void) (d), 0)
2537#define MHD_D_IS_USING_EPOLL_(d) (0 != ((d)->options & MHD_USE_EPOLL))
2538#else /* select() only */
2542#define MHD_D_IS_USING_SELECT_(d) ((void) (d), ! 0)
2546#define MHD_D_IS_USING_POLL_(d) ((void) (d), 0)
2550#define MHD_D_IS_USING_EPOLL_(d) ((void) (d), 0)
2551#endif /* select() only */
2552
2553#if defined(MHD_USE_THREADS)
2557#define MHD_D_IS_USING_THREADS_(d) \
2558 (0 != (d->options & (MHD_USE_INTERNAL_POLLING_THREAD)))
2562#define MHD_D_IS_USING_THREAD_PER_CONN_(d) \
2563 (0 != ((d)->options & MHD_USE_THREAD_PER_CONNECTION))
2564
2568#define MHD_D_IS_THREAD_SAFE_(d) \
2569 (0 == ((d)->options & MHD_USE_NO_THREAD_SAFETY))
2570#else /* ! MHD_USE_THREADS */
2574#define MHD_D_IS_USING_THREADS_(d) ((void) d, 0)
2578#define MHD_D_IS_USING_THREAD_PER_CONN_(d) ((void) d, 0)
2579
2583#define MHD_D_IS_THREAD_SAFE_(d) ((void) d, 0)
2584#endif /* ! MHD_USE_THREADS */
2585
2586#ifdef HAS_FD_SETSIZE_OVERRIDABLE
2590#define MHD_D_GET_FD_SETSIZE_(d) ((d)->fdset_size)
2591#else /* ! HAS_FD_SETSIZE_OVERRIDABLE */
2595#define MHD_D_GET_FD_SETSIZE_(d) (FD_SETSIZE)
2596#endif /* ! HAS_FD_SETSIZE_OVERRIDABLE */
2597
2601#define MHD_D_DOES_SCKT_FIT_FDSET_(sckt,d) \
2602 MHD_SCKT_FD_FITS_FDSET_SETSIZE_(sckt,NULL,MHD_D_GET_FD_SETSIZE_(d))
2603
2604
2605#ifdef DAUTH_SUPPORT
2606
2610struct MHD_RqDAuthParam
2611{
2615 struct _MHD_str_w_len value;
2621 bool quoted;
2622};
2623
2627struct MHD_RqDAuth
2628{
2629 struct MHD_RqDAuthParam nonce;
2630 struct MHD_RqDAuthParam opaque;
2631 struct MHD_RqDAuthParam response;
2632 struct MHD_RqDAuthParam username;
2633 struct MHD_RqDAuthParam username_ext;
2634 struct MHD_RqDAuthParam realm;
2635 struct MHD_RqDAuthParam uri;
2636 /* The raw QOP value, used in the 'response' calculation */
2637 struct MHD_RqDAuthParam qop_raw;
2638 struct MHD_RqDAuthParam cnonce;
2639 struct MHD_RqDAuthParam nc;
2640
2641 /* Decoded values are below */
2642 bool userhash; /* True if 'userhash' parameter has value 'true'. */
2643 enum MHD_DigestAuthAlgo3 algo3;
2644 enum MHD_DigestAuthQOP qop;
2645};
2646
2647
2648#endif /* DAUTH_SUPPORT */
2649
2658#define DLL_insert(head,tail,element) do { \
2659 mhd_assert (NULL == (element)->next); \
2660 mhd_assert (NULL == (element)->prev); \
2661 (element)->next = (head); \
2662 (element)->prev = NULL; \
2663 if ((tail) == NULL) { \
2664 (tail) = element; \
2665 } else { \
2666 (head)->prev = element; \
2667 } \
2668 (head) = (element); } while (0)
2669
2670
2680#define DLL_remove(head,tail,element) do { \
2681 mhd_assert ( (NULL != (element)->next) || ((element) == (tail))); \
2682 mhd_assert ( (NULL != (element)->prev) || ((element) == (head))); \
2683 if ((element)->prev == NULL) { \
2684 (head) = (element)->next; \
2685 } else { \
2686 (element)->prev->next = (element)->next; \
2687 } \
2688 if ((element)->next == NULL) { \
2689 (tail) = (element)->prev; \
2690 } else { \
2691 (element)->next->prev = (element)->prev; \
2692 } \
2693 (element)->next = NULL; \
2694 (element)->prev = NULL; } while (0)
2695
2696
2705#define XDLL_insert(head,tail,element) do { \
2706 mhd_assert (NULL == (element)->nextX); \
2707 mhd_assert (NULL == (element)->prevX); \
2708 (element)->nextX = (head); \
2709 (element)->prevX = NULL; \
2710 if (NULL == (tail)) { \
2711 (tail) = element; \
2712 } else { \
2713 (head)->prevX = element; \
2714 } \
2715 (head) = (element); } while (0)
2716
2717
2727#define XDLL_remove(head,tail,element) do { \
2728 mhd_assert ( (NULL != (element)->nextX) || ((element) == (tail))); \
2729 mhd_assert ( (NULL != (element)->prevX) || ((element) == (head))); \
2730 if (NULL == (element)->prevX) { \
2731 (head) = (element)->nextX; \
2732 } else { \
2733 (element)->prevX->nextX = (element)->nextX; \
2734 } \
2735 if (NULL == (element)->nextX) { \
2736 (tail) = (element)->prevX; \
2737 } else { \
2738 (element)->nextX->prevX = (element)->prevX; \
2739 } \
2740 (element)->nextX = NULL; \
2741 (element)->prevX = NULL; } while (0)
2742
2743
2752#define EDLL_insert(head,tail,element) do { \
2753 (element)->nextE = (head); \
2754 (element)->prevE = NULL; \
2755 if ((tail) == NULL) { \
2756 (tail) = element; \
2757 } else { \
2758 (head)->prevE = element; \
2759 } \
2760 (head) = (element); } while (0)
2761
2762
2772#define EDLL_remove(head,tail,element) do { \
2773 if ((element)->prevE == NULL) { \
2774 (head) = (element)->nextE; \
2775 } else { \
2776 (element)->prevE->nextE = (element)->nextE; \
2777 } \
2778 if ((element)->nextE == NULL) { \
2779 (tail) = (element)->prevE; \
2780 } else { \
2781 (element)->nextE->prevE = (element)->prevE; \
2782 } \
2783 (element)->nextE = NULL; \
2784 (element)->prevE = NULL; } while (0)
2785
2786
2792void
2794
2795
2809typedef enum MHD_Result
2810(*MHD_ArgumentIterator_)(void *cls,
2811 const char *key,
2812 size_t key_size,
2813 const char *value,
2814 size_t value_size,
2815 enum MHD_ValueKind kind);
2816
2817
2832enum MHD_Result
2833MHD_parse_arguments_ (struct MHD_Connection *connection,
2834 enum MHD_ValueKind kind,
2835 char *args,
2837 void *cls);
2838
2839
2856bool
2857MHD_check_response_header_token_ci (const struct MHD_Response *response,
2858 const char *key,
2859 size_t key_len,
2860 const char *token,
2861 size_t token_len);
2862
2874#define MHD_check_response_header_s_token_ci(r,k,tkn) \
2875 MHD_check_response_header_token_ci ((r),(k),MHD_STATICSTR_LEN_ (k), \
2876 (tkn),MHD_STATICSTR_LEN_ (tkn))
2877
2878
2888void
2889internal_suspend_connection_ (struct MHD_Connection *connection);
2890
2891
2899_MHD_static_inline struct MHD_Daemon *
2900MHD_get_master (struct MHD_Daemon *const daemon)
2901{
2902 struct MHD_Daemon *ret;
2903
2904 if (NULL != daemon->master)
2905 ret = daemon->master;
2906 else
2907 ret = daemon;
2908 mhd_assert (NULL == ret->master);
2909
2910 return ret;
2911}
2912
2913
2914#ifdef UPGRADE_SUPPORT
2922void
2923MHD_upgraded_connection_mark_app_closed_ (struct MHD_Connection *connection);
2924
2925#endif /* UPGRADE_SUPPORT */
2926
2927
2928#endif
Declarations for HTTP authorisation general functions.
void(* MHD_LogCallback)(void *cls, const char *fm, va_list ap)
void(* MHD_RequestCompletedCallback)(void *cls, struct MHD_Connection *connection, void **req_cls, enum MHD_RequestTerminationCode toe)
void(* MHD_NotifyConnectionCallback)(void *cls, struct MHD_Connection *connection, void **socket_context, enum MHD_ConnectionNotificationCode toe)
void(* MHD_ContentReaderFreeCallback)(void *cls)
MHD_CONNECTION_STATE
Definition internal.h:613
@ MHD_CONNECTION_BODY_RECEIVED
Definition internal.h:663
@ MHD_CONNECTION_CHUNKED_BODY_SENT
Definition internal.h:725
@ MHD_CONNECTION_REQ_HEADERS_RECEIVING
Definition internal.h:636
@ MHD_CONNECTION_BODY_RECEIVING
Definition internal.h:656
@ MHD_CONNECTION_HEADERS_SENDING
Definition internal.h:694
@ MHD_CONNECTION_FOOTERS_SENDING
Definition internal.h:730
@ MHD_CONNECTION_FOOTERS_RECEIVED
Definition internal.h:675
@ MHD_CONNECTION_FULL_REPLY_SENT
Definition internal.h:736
@ MHD_CONNECTION_HEADERS_SENT
Definition internal.h:699
@ MHD_CONNECTION_HEADERS_PROCESSED
Definition internal.h:646
@ MHD_CONNECTION_INIT
Definition internal.h:618
@ MHD_CONNECTION_CLOSED
Definition internal.h:741
@ MHD_CONNECTION_REQ_LINE_RECEIVED
Definition internal.h:631
@ MHD_CONNECTION_NORMAL_BODY_UNREADY
Definition internal.h:705
@ MHD_CONNECTION_HEADERS_RECEIVED
Definition internal.h:641
@ MHD_CONNECTION_NORMAL_BODY_READY
Definition internal.h:710
@ MHD_CONNECTION_START_REPLY
Definition internal.h:688
@ MHD_CONNECTION_FOOTERS_RECEIVING
Definition internal.h:668
@ MHD_CONNECTION_CHUNKED_BODY_READY
Definition internal.h:720
@ MHD_CONNECTION_FULL_REQ_RECEIVED
Definition internal.h:681
@ MHD_CONNECTION_CHUNKED_BODY_UNREADY
Definition internal.h:715
@ MHD_CONNECTION_CONTINUE_SENDING
Definition internal.h:651
@ MHD_CONNECTION_REQ_LINE_RECEIVING
Definition internal.h:624
bool MHD_check_response_header_token_ci(const struct MHD_Response *response, const char *key, size_t key_len, const char *token, size_t token_len)
Definition response.c:930
ssize_t(* TransmitCallback)(struct MHD_Connection *conn, const void *read_from, size_t max_bytes)
Definition internal.h:809
MHD_EpollState
Definition internal.h:169
@ MHD_EPOLL_STATE_SUSPENDED
Definition internal.h:202
@ MHD_EPOLL_STATE_IN_EREADY_EDLL
Definition internal.h:192
@ MHD_EPOLL_STATE_READ_READY
Definition internal.h:181
@ MHD_EPOLL_STATE_IN_EPOLL_SET
Definition internal.h:197
@ MHD_EPOLL_STATE_UNREADY
Definition internal.h:175
@ MHD_EPOLL_STATE_WRITE_READY
Definition internal.h:187
@ MHD_EPOLL_STATE_ERROR
Definition internal.h:207
void internal_suspend_connection_(struct MHD_Connection *connection)
Definition daemon.c:3224
MHD_TLS_CONN_STATE
Definition internal.h:759
@ MHD_TLS_CONN_TLS_CLOSING
Definition internal.h:766
@ MHD_TLS_CONN_WR_CLOSING
Definition internal.h:764
@ MHD_TLS_CONN_INVALID_STATE
Definition internal.h:769
@ MHD_TLS_CONN_WR_CLOSED
Definition internal.h:765
@ MHD_TLS_CONN_NO_TLS
Definition internal.h:760
@ MHD_TLS_CONN_INIT
Definition internal.h:761
@ MHD_TLS_CONN_TLS_CLOSED
Definition internal.h:767
@ MHD_TLS_CONN_TLS_FAILED
Definition internal.h:768
@ MHD_TLS_CONN_CONNECTED
Definition internal.h:763
@ MHD_TLS_CONN_HANDSHAKING
Definition internal.h:762
MHD_ConnectionEventLoopInfo
Definition internal.h:215
@ MHD_EVENT_LOOP_INFO_PROCESS_READ
Definition internal.h:235
@ MHD_EVENT_LOOP_INFO_PROCESS
Definition internal.h:229
@ MHD_EVENT_LOOP_INFO_READ
Definition internal.h:219
@ MHD_EVENT_LOOP_INFO_WRITE
Definition internal.h:224
@ MHD_EVENT_LOOP_INFO_CLEANUP
Definition internal.h:241
struct MHD_IoVec MHD_iovec_
Definition internal.h:440
enum MHD_Result(* MHD_ArgumentIterator_)(void *cls, const char *key, size_t key_size, const char *value, size_t value_size, enum MHD_ValueKind kind)
Definition internal.h:2810
size_t MHD_iov_size_
Definition internal.h:442
#define MAX_DIGEST_NONCE_LENGTH
Definition internal.h:269
void *(* LogCallback)(void *cls, const char *uri, struct MHD_Connection *con)
Definition internal.h:1835
_MHD_static_inline struct MHD_Daemon * MHD_get_master(struct MHD_Daemon *const daemon)
Definition internal.h:2900
MHD_ResponseAutoFlags
Definition internal.h:405
@ MHD_RAF_HAS_DATE_HDR
Definition internal.h:411
@ MHD_RAF_HAS_CONTENT_LENGTH
Definition internal.h:410
@ MHD_RAF_NO_FLAGS
Definition internal.h:406
@ MHD_RAF_HAS_CONNECTION_CLOSE
Definition internal.h:408
@ MHD_RAF_HAS_TRANS_ENC_CHUNKED
Definition internal.h:409
@ MHD_RAF_HAS_CONNECTION_HDR
Definition internal.h:407
MHD_HTTP_Version
Definition internal.h:841
@ MHD_HTTP_VER_1_0
Definition internal.h:860
@ MHD_HTTP_VER_1_1
Definition internal.h:865
@ MHD_HTTP_VER_TOO_OLD
Definition internal.h:855
@ MHD_HTTP_VER_INVALID
Definition internal.h:845
@ MHD_HTTP_VER_UNKNOWN
Definition internal.h:850
@ MHD_HTTP_VER_1_2__1_9
Definition internal.h:870
@ MHD_HTTP_VER_FUTURE
Definition internal.h:875
MHD_ConnKeepAlive
Definition internal.h:818
@ MHD_CONN_USE_KEEPALIVE
Definition internal.h:832
@ MHD_CONN_MUST_UPGRADE
Definition internal.h:837
@ MHD_CONN_MUST_CLOSE
Definition internal.h:822
@ MHD_CONN_KEEPALIVE_UNKOWN
Definition internal.h:827
ssize_t(* ReceiveCallback)(struct MHD_Connection *conn, void *write_to, size_t max_bytes)
Definition internal.h:795
void MHD_unescape_plus(char *arg)
Definition internal.c:129
enum MHD_Result MHD_parse_arguments_(struct MHD_Connection *connection, enum MHD_ValueKind kind, char *args, MHD_ArgumentIterator_ cb, void *cls)
Definition internal.c:169
enum MHD_EpollState _MHD_FIXED_FLAGS_ENUM
MHD_HTTP_Method
Definition internal.h:899
@ MHD_HTTP_MTHD_GET
Definition internal.h:907
@ MHD_HTTP_MTHD_CONNECT
Definition internal.h:927
@ MHD_HTTP_MTHD_DELETE
Definition internal.h:923
@ MHD_HTTP_MTHD_OPTIONS
Definition internal.h:931
@ MHD_HTTP_MTHD_TRACE
Definition internal.h:935
@ MHD_HTTP_MTHD_HEAD
Definition internal.h:911
@ MHD_HTTP_MTHD_POST
Definition internal.h:915
@ MHD_HTTP_MTHD_OTHER
Definition internal.h:939
@ MHD_HTTP_MTHD_NO_METHOD
Definition internal.h:903
@ MHD_HTTP_MTHD_PUT
Definition internal.h:919
enum MHD_tristate _MHD_FIXED_ENUM
size_t(* UnescapeCallback)(void *cls, struct MHD_Connection *conn, char *uri)
Definition internal.h:1849
MHD_tristate
Definition internal.h:156
@ _MHD_ON
Definition internal.h:160
@ _MHD_UNKNOWN
Definition internal.h:157
@ _MHD_YES
Definition internal.h:161
@ _MHD_OFF
Definition internal.h:158
@ _MHD_NO
Definition internal.h:159
macros for mhd_assert()
#define mhd_assert(ignore)
Definition mhd_assert.h:45
Types for platform-independent inter-thread communication.
Header for platform-independent locks abstraction.
#define NULL
additional automatic macros for MHD_config.h
MHD_panic() function and helpers.
Header for string manipulating helpers types.
Header for platform-independent threads abstraction.
public interface to libmicrohttpd
int MHD_socket
Definition microhttpd.h:206
MHD_DisableSanityCheck
MHD_Result
Definition microhttpd.h:163
enum MHD_Result(* MHD_AcceptPolicyCallback)(void *cls, const struct sockaddr *addr, socklen_t addrlen)
enum MHD_Result(* MHD_AccessHandlerCallback)(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **req_cls)
MHD_DigestAuthAlgo3
MHD_DigestAuthQOP
ssize_t(* MHD_ContentReaderCallback)(void *cls, uint64_t pos, char *buf, size_t max)
MHD_ValueKind
void(* MHD_UpgradeHandler)(void *cls, struct MHD_Connection *connection, void *req_cls, const char *extra_in, size_t extra_in_size, MHD_socket sock, struct MHD_UpgradeResponseHandle *urh)
int(* MHD_PskServerCredentialsCallback)(void *cls, const struct MHD_Connection *connection, const char *username, void **psk, size_t *psk_size)
MHD_FLAG
Flags for the struct MHD_Daemon.
MHD_ResponseFlags
platform-specific includes for libmicrohttpd
MHD_socket socket_fd
Definition internal.h:1483
enum MHD_tristate sk_nodelay
Definition internal.h:1509
size_t write_buffer_size
Definition internal.h:1441
size_t write_buffer_send_offset
Definition internal.h:1446
struct MHD_Connection * prev
Definition internal.h:1341
socklen_t addr_len
Definition internal.h:1463
enum MHD_ConnectionEventLoopInfo event_loop_info
Definition internal.h:1570
size_t write_buffer_append_offset
Definition internal.h:1452
enum MHD_tristate is_nonip
Definition internal.h:1489
char * write_buffer
Definition internal.h:1409
bool stop_with_error
Definition internal.h:1526
bool discard_request
Definition internal.h:1535
ReceiveCallback recv_cls
Definition internal.h:1575
volatile bool resuming
Definition internal.h:1621
void * socket_context
Definition internal.h:1389
uint64_t last_activity
Definition internal.h:1469
enum MHD_ConnKeepAlive keepalive
Definition internal.h:1396
struct MHD_Request rq
Definition internal.h:1365
struct MHD_Connection * nextX
Definition internal.h:1350
union MHD_ConnectionInfo connection_info_dummy
Definition internal.h:1626
struct MHD_Connection * next
Definition internal.h:1336
size_t continue_message_write_offset
Definition internal.h:1458
size_t read_buffer_offset
Definition internal.h:1436
struct MHD_Reply rp
Definition internal.h:1370
struct MemoryPool * pool
Definition internal.h:1380
enum MHD_CONNECTION_STATE state
Definition internal.h:1565
char * read_buffer
Definition internal.h:1403
struct MHD_Connection * prevX
Definition internal.h:1355
struct MHD_Daemon * daemon
Definition internal.h:1360
bool in_access_handler
Definition internal.h:1616
bool sk_spipe_suppress
Definition internal.h:1499
uint64_t connection_timeout_ms
Definition internal.h:1476
struct sockaddr_storage * addr
Definition internal.h:1415
size_t read_buffer_size
Definition internal.h:1430
enum MHD_tristate sk_corked
Definition internal.h:1504
size_t pool_size
Definition internal.h:2136
MHD_NotifyConnectionCallback notify_connection
Definition internal.h:2043
MHD_AccessHandlerCallback default_handler
Definition internal.h:1867
LogCallback uri_log_callback
Definition internal.h:2057
bool data_already_pending
Definition internal.h:2241
union MHD_DaemonInfo daemon_info_dummy_port
Definition internal.h:2482
struct MHD_Connection * normal_timeout_tail
Definition internal.h:2000
bool at_limit
Definition internal.h:2219
struct MHD_Connection * new_connections_tail
Definition internal.h:1890
int client_discipline
Definition internal.h:2265
uint16_t port
Definition internal.h:2080
bool listen_nonblk
Definition internal.h:2111
unsigned int connection_limit
Definition internal.h:2246
void * unescape_callback_cls
Definition internal.h:2072
enum MHD_DisableSanityCheck insanity_level
Definition internal.h:2180
struct MHD_Connection * connections_tail
Definition internal.h:1900
struct MHD_Connection * suspended_connections_tail
Definition internal.h:1910
union MHD_DaemonInfo daemon_info_dummy_listen_fd
Definition internal.h:2460
struct MHD_Connection * manual_timeout_head
Definition internal.h:2008
unsigned int listen_backlog_size
Definition internal.h:2454
struct MHD_Connection * normal_timeout_head
Definition internal.h:1993
union MHD_DaemonInfo daemon_info_dummy_flags
Definition internal.h:2477
MHD_RequestCompletedCallback notify_completed
Definition internal.h:2032
struct MHD_Connection * cleanup_head
Definition internal.h:1915
unsigned int connections
Definition internal.h:2131
struct MHD_itc_ itc
Definition internal.h:2198
int listening_address_reuse
Definition internal.h:2191
uint64_t connection_timeout_ms
Definition internal.h:2253
void * apc_cls
Definition internal.h:2026
unsigned int per_ip_connection_limit
Definition internal.h:2259
struct MHD_Connection * manual_timeout_tail
Definition internal.h:2015
volatile bool shutdown
Definition internal.h:2203
union MHD_DaemonInfo daemon_info_dummy_num_connections
Definition internal.h:2472
enum MHD_FLAG options
Definition internal.h:1880
void * notify_connection_cls
Definition internal.h:2048
struct MHD_Connection * cleanup_tail
Definition internal.h:1920
bool sigpipe_blocked
Definition internal.h:2286
UnescapeCallback unescape_callback
Definition internal.h:2067
void * notify_completed_cls
Definition internal.h:2037
volatile bool was_quiesced
Definition internal.h:2210
struct MHD_Connection * suspended_connections_head
Definition internal.h:1905
struct MHD_Connection * new_connections_head
Definition internal.h:1885
enum MHD_tristate listen_is_unix
Definition internal.h:1925
volatile bool resuming
Definition internal.h:2224
void * default_handler_cls
Definition internal.h:1872
struct MHD_Connection * connections_head
Definition internal.h:1895
MHD_AcceptPolicyCallback apc
Definition internal.h:2021
volatile bool have_new
Definition internal.h:2230
size_t pool_increment
Definition internal.h:2141
MHD_socket listen_fd
Definition internal.h:2106
void * per_ip_connection_count
Definition internal.h:2123
void * uri_log_callback_cls
Definition internal.h:2062
struct MHD_Daemon * master
Definition internal.h:2098
enum MHD_ValueKind kind
Definition internal.h:396
struct MHD_HTTP_Req_Header * prev
Definition internal.h:371
const char * value
Definition internal.h:386
struct MHD_HTTP_Req_Header * next
Definition internal.h:366
const char * header
Definition internal.h:376
struct MHD_HTTP_Res_Header * prev
Definition internal.h:328
struct MHD_HTTP_Res_Header * next
Definition internal.h:323
enum MHD_ValueKind kind
Definition internal.h:353
uint32_t nc
Definition internal.h:285
uint64_t nmask
Definition internal.h:293
char nonce[MAX_DIGEST_NONCE_LENGTH+1]
Definition internal.h:298
uint64_t rsp_write_position
Definition internal.h:1295
bool responseIcy
Definition internal.h:1288
struct MHD_iovec_track_ resp_iov
Definition internal.h:1303
struct MHD_Response * response
Definition internal.h:1276
unsigned int responseCode
Definition internal.h:1282
struct MHD_Reply_Properties props
Definition internal.h:1312
unsigned int skipped_empty_lines
Definition internal.h:955
struct MHD_HTTP_Req_Header * headers_received
Definition internal.h:1111
union MHD_HeadersProcessing hdrs
Definition internal.h:1241
uint64_t current_chunk_size
Definition internal.h:1161
uint64_t current_chunk_offset
Definition internal.h:1167
bool some_payload_processed
Definition internal.h:1184
size_t skipped_broken_lines
Definition internal.h:1236
void * client_context
Definition internal.h:1192
const char * url
Definition internal.h:1096
size_t url_len
Definition internal.h:1101
const char * version
Definition internal.h:1075
size_t num_cr_sp_replaced
Definition internal.h:1231
enum MHD_HTTP_Version http_ver
Definition internal.h:1080
size_t req_target_len
Definition internal.h:1106
const char * method
Definition internal.h:1085
size_t header_size
Definition internal.h:1124
union MHD_StartOrSize field_lines
Definition internal.h:1134
struct MHD_HTTP_Req_Header * headers_received_tail
Definition internal.h:1116
enum MHD_HTTP_Method http_mthd
Definition internal.h:1090
bool client_aware
Definition internal.h:1199
bool have_chunked_upload
Definition internal.h:1152
uint64_t remaining_upload_size
Definition internal.h:1140
MHD_ContentReaderFreeCallback crfc
Definition internal.h:507
struct MHD_HTTP_Res_Header * last_header
Definition internal.h:483
size_t data_buffer_size
Definition internal.h:557
MHD_iovec_ * data_iov
Definition internal.h:588
const char * data
Definition internal.h:489
uint64_t data_start
Definition internal.h:541
MHD_ContentReaderCallback crc
Definition internal.h:501
enum MHD_ResponseAutoFlags flags_auto
Definition internal.h:578
unsigned int data_iovcnt
Definition internal.h:593
size_t data_size
Definition internal.h:552
enum MHD_ResponseFlags flags
Definition internal.h:573
void * crc_cls
Definition internal.h:495
unsigned int reference_count
Definition internal.h:563
struct MHD_HTTP_Res_Header * first_header
Definition internal.h:478
uint64_t total_size
Definition internal.h:535
uint64_t fd_off
Definition internal.h:546
MHD_iovec_ * iov
Definition internal.h:453
struct MHD_RequestLineProcessing rq_line
Definition internal.h:1036
struct MHD_HeaderProcessing hdr
Definition internal.h:1041
const char * start
Definition internal.h:1055