GNU libmicrohttpd 1.0.10
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 const char *url_for_callback;
1113
1118
1123
1131
1141
1147
1159
1168
1174
1191
1199
1206
1207#ifdef BAUTH_SUPPORT
1213 const struct MHD_RqBAuth *bauth;
1214
1218 bool bauth_tried;
1219#endif /* BAUTH_SUPPORT */
1220#ifdef DAUTH_SUPPORT
1226 const struct MHD_RqDAuth *dauth;
1227
1231 bool dauth_tried;
1232#endif /* DAUTH_SUPPORT */
1238
1243
1248};
1249
1250
1255{
1256#ifdef _DEBUG
1257 bool set;
1258#endif /* _DEBUG */
1261 bool chunked;
1262};
1263
1264#if defined(_MHD_HAVE_SENDFILE)
1265enum MHD_resp_sender_
1266{
1267 MHD_resp_sender_std = 0,
1268 MHD_resp_sender_sendfile
1269};
1270#endif /* _MHD_HAVE_SENDFILE */
1271
1278{
1283
1288 unsigned int responseCode;
1289
1295
1302
1310
1311#if defined(_MHD_HAVE_SENDFILE)
1312 enum MHD_resp_sender_ resp_sender;
1313#endif /* _MHD_HAVE_SENDFILE */
1314
1319};
1320
1325{
1326
1327#ifdef EPOLL_SUPPORT
1331 struct MHD_Connection *nextE;
1332
1336 struct MHD_Connection *prevE;
1337#endif
1338
1343
1348
1357
1362
1367
1372
1377
1386 struct MemoryPool *pool;
1387
1396
1403
1410
1416
1421 struct sockaddr_storage *addr;
1422
1423#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1429#endif
1430
1437
1443
1448
1453
1459
1465
1469 socklen_t addr_len;
1470
1476
1483
1490
1496
1501
1506
1511
1516
1524
1533
1542
1543#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1547 bool thread_joined;
1548#endif
1549
1555
1560
1561#ifdef EPOLL_SUPPORT
1565 enum MHD_EpollState epoll_state;
1566#endif
1567
1572
1577
1582
1583#ifdef UPGRADE_SUPPORT
1590 struct MHD_UpgradeResponseHandle *urh;
1591#endif /* UPGRADE_SUPPORT */
1592
1593#ifdef HTTPS_SUPPORT
1594
1598 gnutls_session_t tls_session;
1599
1603 enum MHD_TLS_CONN_STATE tls_state;
1604
1609 bool tls_read_ready;
1610#endif /* HTTPS_SUPPORT */
1611
1616
1623
1627 volatile bool resuming;
1628
1643
1657 struct MHD_itc_ resume_itc;
1658
1663};
1664
1665
1666#ifdef UPGRADE_SUPPORT
1676#define RESERVE_EBUF_SIZE 8
1677
1684struct UpgradeEpollHandle
1685{
1690 struct MHD_UpgradeResponseHandle *urh;
1691
1707 MHD_socket socket;
1708
1712 enum MHD_EpollState celi;
1713
1714};
1715
1716
1722struct MHD_UpgradeResponseHandle
1723{
1729 struct MHD_Connection *connection;
1730
1731#ifdef HTTPS_SUPPORT
1735 struct MHD_UpgradeResponseHandle *next;
1736
1740 struct MHD_UpgradeResponseHandle *prev;
1741
1742#ifdef EPOLL_SUPPORT
1746 struct MHD_UpgradeResponseHandle *nextE;
1747
1751 struct MHD_UpgradeResponseHandle *prevE;
1752
1756 bool in_eready_list;
1757#endif
1758
1764 char *in_buffer;
1765
1771 char *out_buffer;
1772
1778 size_t in_buffer_size;
1779
1785 size_t out_buffer_size;
1786
1794 size_t in_buffer_used;
1795
1803 size_t out_buffer_used;
1804
1808 struct UpgradeEpollHandle app;
1809
1814 struct UpgradeEpollHandle mhd;
1815
1820 char e_buf[RESERVE_EBUF_SIZE];
1821
1822#endif /* HTTPS_SUPPORT */
1823
1834 volatile bool was_closed;
1835
1857 volatile bool clean_ready;
1858};
1859#endif /* UPGRADE_SUPPORT */
1860
1861
1870typedef void *
1871(*LogCallback)(void *cls,
1872 const char *uri,
1873 struct MHD_Connection *con);
1874
1884typedef size_t
1885(*UnescapeCallback)(void *cls,
1886 struct MHD_Connection *conn,
1887 char *uri);
1888
1889
1898{
1899
1904
1909
1917
1922
1927
1932
1937
1942
1947
1952
1957
1962
1963#ifdef EPOLL_SUPPORT
1967 struct MHD_Connection *eready_head;
1968
1972 struct MHD_Connection *eready_tail;
1973
1980 int epoll_fd;
1981
1986 bool listen_socket_in_epoll;
1987
1988#ifdef UPGRADE_SUPPORT
1989#ifdef HTTPS_SUPPORT
1994 int epoll_upgrade_fd;
1995
2000 bool upgrade_fd_in_epoll;
2001#endif /* HTTPS_SUPPORT */
2002
2006 struct MHD_UpgradeResponseHandle *eready_urh_head;
2007
2011 struct MHD_UpgradeResponseHandle *eready_urh_tail;
2012#endif /* UPGRADE_SUPPORT */
2013#endif /* EPOLL_SUPPORT */
2014
2030
2037
2045
2052
2058
2062 void *apc_cls;
2063
2069
2074
2080
2085
2094
2099
2104
2109
2116 uint16_t port;
2117
2118#ifdef HAVE_MESSAGES
2123 MHD_LogCallback custom_error_log;
2124
2128 void *custom_error_log_cls;
2129#endif
2130
2135
2143
2148
2149#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2153 struct MHD_Daemon *worker_pool;
2154#endif
2155
2160
2167 unsigned int connections;
2168
2173
2178
2179#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2183 size_t thread_stack_size;
2184
2188 unsigned int worker_pool_size;
2189
2194
2198 MHD_mutex_ per_ip_connection_mutex;
2199
2204 MHD_mutex_ cleanup_connection_mutex;
2205
2209 MHD_mutex_ new_connections_mutex;
2210
2226 MHD_mutex_ epoll_listen_mutex;
2227#endif
2228
2234
2245
2246
2251 struct MHD_itc_ itc;
2252
2256 volatile bool shutdown;
2257
2263 volatile bool was_quiesced;
2264
2273
2274 /*
2275 * Do we need to process resuming connections?
2276 */
2277 volatile bool resuming;
2278
2283 volatile bool have_new;
2284
2295
2299 unsigned int connection_limit;
2300
2307
2313
2319
2326
2327#ifdef HAS_FD_SETSIZE_OVERRIDABLE
2334 int fdset_size;
2335
2340 bool fdset_size_set_by_app;
2341#endif /* HAS_FD_SETSIZE_OVERRIDABLE */
2342
2347
2348#ifdef HTTPS_SUPPORT
2349#ifdef UPGRADE_SUPPORT
2355 struct MHD_UpgradeResponseHandle *urh_head;
2356
2362 struct MHD_UpgradeResponseHandle *urh_tail;
2363#endif /* UPGRADE_SUPPORT */
2364
2368 gnutls_priority_t priority_cache;
2369
2374 gnutls_credentials_type_t cred_type;
2375
2379 gnutls_certificate_credentials_t x509_cred;
2380
2384 gnutls_dh_params_t dh_params;
2385
2389 gnutls_psk_server_credentials_t psk_cred;
2390
2391#if GNUTLS_VERSION_MAJOR >= 3
2396 gnutls_certificate_retrieve_function2 *cert_callback;
2397
2402
2406 void *cred_callback_cls;
2407#endif
2408
2409#if GNUTLS_VERSION_NUMBER >= 0x030603
2414 gnutls_certificate_retrieve_function3 *cert_callback2;
2415#endif
2416
2420 const char *https_mem_key;
2421
2425 const char *https_mem_cert;
2426
2430 const char *https_key_password;
2431
2435 const char *https_mem_trust;
2436
2440 gnutls_dh_params_t https_mem_dhparams;
2441
2445 bool have_dhparams;
2446
2450 bool disable_alpn;
2451
2452 #endif /* HTTPS_SUPPORT */
2453
2454#ifdef DAUTH_SUPPORT
2455
2459 const char *digest_auth_random;
2460
2464 size_t digest_auth_rand_size;
2465
2469 void *digest_auth_random_copy;
2470
2474 struct MHD_NonceNc *nnc;
2475
2476#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2480 MHD_mutex_ nnc_lock;
2481#endif
2482
2486 unsigned int nonce_nc_size;
2487
2491 unsigned int dauth_bind_type;
2492
2496 unsigned int dauth_def_nonce_timeout;
2497
2501 uint32_t dauth_def_max_nc;
2502#endif
2503
2504#ifdef TCP_FASTOPEN
2508 unsigned int fastopen_queue_size;
2509#endif
2510
2515
2516 /* TODO: replace with a single member */
2521
2522#ifdef EPOLL_SUPPORT
2526 union MHD_DaemonInfo daemon_info_dummy_epoll_fd;
2527#endif /* EPOLL_SUPPORT */
2528
2533
2538
2543
2544#if defined(_DEBUG) && defined(HAVE_ACCEPT4)
2553 bool avoid_accept4;
2554#endif /* _DEBUG */
2555};
2556
2557
2558#if defined(HAVE_POLL) && defined(EPOLL_SUPPORT)
2562#define MHD_D_IS_USING_SELECT_(d) \
2563 (0 == (d->options & (MHD_USE_POLL | MHD_USE_EPOLL)))
2567#define MHD_D_IS_USING_POLL_(d) (0 != ((d)->options & MHD_USE_POLL))
2571#define MHD_D_IS_USING_EPOLL_(d) (0 != ((d)->options & MHD_USE_EPOLL))
2572#elif defined(HAVE_POLL)
2576#define MHD_D_IS_USING_SELECT_(d) (0 == ((d)->options & MHD_USE_POLL))
2580#define MHD_D_IS_USING_POLL_(d) (0 != ((d)->options & MHD_USE_POLL))
2584#define MHD_D_IS_USING_EPOLL_(d) ((void) (d), 0)
2585#elif defined(EPOLL_SUPPORT)
2589#define MHD_D_IS_USING_SELECT_(d) (0 == ((d)->options & MHD_USE_EPOLL))
2593#define MHD_D_IS_USING_POLL_(d) ((void) (d), 0)
2597#define MHD_D_IS_USING_EPOLL_(d) (0 != ((d)->options & MHD_USE_EPOLL))
2598#else /* select() only */
2602#define MHD_D_IS_USING_SELECT_(d) ((void) (d), ! 0)
2606#define MHD_D_IS_USING_POLL_(d) ((void) (d), 0)
2610#define MHD_D_IS_USING_EPOLL_(d) ((void) (d), 0)
2611#endif /* select() only */
2612
2613#if defined(MHD_USE_THREADS)
2617#define MHD_D_IS_USING_THREADS_(d) \
2618 (0 != (d->options & (MHD_USE_INTERNAL_POLLING_THREAD)))
2622#define MHD_D_IS_USING_THREAD_PER_CONN_(d) \
2623 (0 != ((d)->options & MHD_USE_THREAD_PER_CONNECTION))
2624
2628#define MHD_D_IS_THREAD_SAFE_(d) \
2629 (0 == ((d)->options & MHD_USE_NO_THREAD_SAFETY))
2630#else /* ! MHD_USE_THREADS */
2634#define MHD_D_IS_USING_THREADS_(d) ((void) d, 0)
2638#define MHD_D_IS_USING_THREAD_PER_CONN_(d) ((void) d, 0)
2639
2643#define MHD_D_IS_THREAD_SAFE_(d) ((void) d, 0)
2644#endif /* ! MHD_USE_THREADS */
2645
2646#ifdef HAS_FD_SETSIZE_OVERRIDABLE
2650#define MHD_D_GET_FD_SETSIZE_(d) ((d)->fdset_size)
2651#else /* ! HAS_FD_SETSIZE_OVERRIDABLE */
2655#define MHD_D_GET_FD_SETSIZE_(d) (FD_SETSIZE)
2656#endif /* ! HAS_FD_SETSIZE_OVERRIDABLE */
2657
2661#define MHD_D_DOES_SCKT_FIT_FDSET_(sckt,d) \
2662 MHD_SCKT_FD_FITS_FDSET_SETSIZE_(sckt,NULL,MHD_D_GET_FD_SETSIZE_(d))
2663
2664
2665#ifdef DAUTH_SUPPORT
2666
2670struct MHD_RqDAuthParam
2671{
2675 struct _MHD_str_w_len value;
2681 bool quoted;
2682};
2683
2687struct MHD_RqDAuth
2688{
2689 struct MHD_RqDAuthParam nonce;
2690 struct MHD_RqDAuthParam opaque;
2691 struct MHD_RqDAuthParam response;
2692 struct MHD_RqDAuthParam username;
2693 struct MHD_RqDAuthParam username_ext;
2694 struct MHD_RqDAuthParam realm;
2695 struct MHD_RqDAuthParam uri;
2696 /* The raw QOP value, used in the 'response' calculation */
2697 struct MHD_RqDAuthParam qop_raw;
2698 struct MHD_RqDAuthParam cnonce;
2699 struct MHD_RqDAuthParam nc;
2700
2701 /* Decoded values are below */
2702 bool userhash; /* True if 'userhash' parameter has value 'true'. */
2703 enum MHD_DigestAuthAlgo3 algo3;
2704 enum MHD_DigestAuthQOP qop;
2705};
2706
2707
2708#endif /* DAUTH_SUPPORT */
2709
2718#define DLL_insert(head,tail,element) do { \
2719 mhd_assert (NULL == (element)->next); \
2720 mhd_assert (NULL == (element)->prev); \
2721 (element)->next = (head); \
2722 (element)->prev = NULL; \
2723 if ((tail) == NULL) { \
2724 (tail) = element; \
2725 } else { \
2726 (head)->prev = element; \
2727 } \
2728 (head) = (element); } while (0)
2729
2730
2740#define DLL_remove(head,tail,element) do { \
2741 mhd_assert ( (NULL != (element)->next) || ((element) == (tail))); \
2742 mhd_assert ( (NULL != (element)->prev) || ((element) == (head))); \
2743 if ((element)->prev == NULL) { \
2744 (head) = (element)->next; \
2745 } else { \
2746 (element)->prev->next = (element)->next; \
2747 } \
2748 if ((element)->next == NULL) { \
2749 (tail) = (element)->prev; \
2750 } else { \
2751 (element)->next->prev = (element)->prev; \
2752 } \
2753 (element)->next = NULL; \
2754 (element)->prev = NULL; } while (0)
2755
2756
2765#define XDLL_insert(head,tail,element) do { \
2766 mhd_assert (NULL == (element)->nextX); \
2767 mhd_assert (NULL == (element)->prevX); \
2768 (element)->nextX = (head); \
2769 (element)->prevX = NULL; \
2770 if (NULL == (tail)) { \
2771 (tail) = element; \
2772 } else { \
2773 (head)->prevX = element; \
2774 } \
2775 (head) = (element); } while (0)
2776
2777
2787#define XDLL_remove(head,tail,element) do { \
2788 mhd_assert ( (NULL != (element)->nextX) || ((element) == (tail))); \
2789 mhd_assert ( (NULL != (element)->prevX) || ((element) == (head))); \
2790 if (NULL == (element)->prevX) { \
2791 (head) = (element)->nextX; \
2792 } else { \
2793 (element)->prevX->nextX = (element)->nextX; \
2794 } \
2795 if (NULL == (element)->nextX) { \
2796 (tail) = (element)->prevX; \
2797 } else { \
2798 (element)->nextX->prevX = (element)->prevX; \
2799 } \
2800 (element)->nextX = NULL; \
2801 (element)->prevX = NULL; } while (0)
2802
2803
2812#define EDLL_insert(head,tail,element) do { \
2813 (element)->nextE = (head); \
2814 (element)->prevE = NULL; \
2815 if ((tail) == NULL) { \
2816 (tail) = element; \
2817 } else { \
2818 (head)->prevE = element; \
2819 } \
2820 (head) = (element); } while (0)
2821
2822
2832#define EDLL_remove(head,tail,element) do { \
2833 if ((element)->prevE == NULL) { \
2834 (head) = (element)->nextE; \
2835 } else { \
2836 (element)->prevE->nextE = (element)->nextE; \
2837 } \
2838 if ((element)->nextE == NULL) { \
2839 (tail) = (element)->prevE; \
2840 } else { \
2841 (element)->nextE->prevE = (element)->prevE; \
2842 } \
2843 (element)->nextE = NULL; \
2844 (element)->prevE = NULL; } while (0)
2845
2846
2852void
2854
2855
2869typedef enum MHD_Result
2870(*MHD_ArgumentIterator_)(void *cls,
2871 const char *key,
2872 size_t key_size,
2873 const char *value,
2874 size_t value_size,
2875 enum MHD_ValueKind kind);
2876
2877
2892enum MHD_Result
2893MHD_parse_arguments_ (struct MHD_Connection *connection,
2894 enum MHD_ValueKind kind,
2895 char *args,
2897 void *cls);
2898
2899
2916bool
2917MHD_check_response_header_token_ci (const struct MHD_Response *response,
2918 const char *key,
2919 size_t key_len,
2920 const char *token,
2921 size_t token_len);
2922
2934#define MHD_check_response_header_s_token_ci(r,k,tkn) \
2935 MHD_check_response_header_token_ci ((r),(k),MHD_STATICSTR_LEN_ (k), \
2936 (tkn),MHD_STATICSTR_LEN_ (tkn))
2937
2938
2948void
2949internal_suspend_connection_ (struct MHD_Connection *connection);
2950
2951
2959_MHD_static_inline struct MHD_Daemon *
2960MHD_get_master (struct MHD_Daemon *const daemon)
2961{
2962 struct MHD_Daemon *ret;
2963
2964 if (NULL != daemon->master)
2965 ret = daemon->master;
2966 else
2967 ret = daemon;
2968 mhd_assert (NULL == ret->master);
2969
2970 return ret;
2971}
2972
2973
2974#ifdef UPGRADE_SUPPORT
2982void
2983MHD_upgraded_connection_mark_app_closed_ (struct MHD_Connection *connection);
2984
2985#endif /* UPGRADE_SUPPORT */
2986
2987
2988#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:935
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:3401
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:2870
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:1871
_MHD_static_inline struct MHD_Daemon * MHD_get_master(struct MHD_Daemon *const daemon)
Definition internal.h:2960
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:1885
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:1489
enum MHD_tristate sk_nodelay
Definition internal.h:1515
size_t write_buffer_size
Definition internal.h:1447
size_t write_buffer_send_offset
Definition internal.h:1452
struct MHD_Connection * prev
Definition internal.h:1347
socklen_t addr_len
Definition internal.h:1469
enum MHD_ConnectionEventLoopInfo event_loop_info
Definition internal.h:1576
size_t write_buffer_append_offset
Definition internal.h:1458
enum MHD_tristate is_nonip
Definition internal.h:1495
char * write_buffer
Definition internal.h:1415
bool stop_with_error
Definition internal.h:1532
struct MHD_itc_ resume_itc
Definition internal.h:1657
bool discard_request
Definition internal.h:1541
ReceiveCallback recv_cls
Definition internal.h:1581
volatile bool resuming
Definition internal.h:1627
void * socket_context
Definition internal.h:1395
uint64_t last_activity
Definition internal.h:1475
enum MHD_ConnKeepAlive keepalive
Definition internal.h:1402
struct MHD_Request rq
Definition internal.h:1371
struct MHD_Connection * nextX
Definition internal.h:1356
union MHD_ConnectionInfo connection_info_dummy
Definition internal.h:1662
struct MHD_Connection * next
Definition internal.h:1342
size_t continue_message_write_offset
Definition internal.h:1464
size_t read_buffer_offset
Definition internal.h:1442
struct MHD_Reply rp
Definition internal.h:1376
struct MemoryPool * pool
Definition internal.h:1386
enum MHD_CONNECTION_STATE state
Definition internal.h:1571
char * read_buffer
Definition internal.h:1409
struct MHD_Connection * prevX
Definition internal.h:1361
struct MHD_Daemon * daemon
Definition internal.h:1366
bool in_access_handler
Definition internal.h:1622
bool sk_spipe_suppress
Definition internal.h:1505
uint64_t connection_timeout_ms
Definition internal.h:1482
struct sockaddr_storage * addr
Definition internal.h:1421
size_t read_buffer_size
Definition internal.h:1436
enum MHD_tristate sk_corked
Definition internal.h:1510
size_t pool_size
Definition internal.h:2172
MHD_NotifyConnectionCallback notify_connection
Definition internal.h:2079
MHD_AccessHandlerCallback default_handler
Definition internal.h:1903
LogCallback uri_log_callback
Definition internal.h:2093
bool data_already_pending
Definition internal.h:2294
union MHD_DaemonInfo daemon_info_dummy_port
Definition internal.h:2542
struct MHD_Connection * normal_timeout_tail
Definition internal.h:2036
bool at_limit
Definition internal.h:2272
struct MHD_Connection * new_connections_tail
Definition internal.h:1926
int client_discipline
Definition internal.h:2318
uint16_t port
Definition internal.h:2116
bool listen_nonblk
Definition internal.h:2147
unsigned int connection_limit
Definition internal.h:2299
void * unescape_callback_cls
Definition internal.h:2108
enum MHD_DisableSanityCheck insanity_level
Definition internal.h:2233
struct MHD_Connection * connections_tail
Definition internal.h:1936
struct MHD_Connection * suspended_connections_tail
Definition internal.h:1946
union MHD_DaemonInfo daemon_info_dummy_listen_fd
Definition internal.h:2520
struct MHD_Connection * manual_timeout_head
Definition internal.h:2044
unsigned int listen_backlog_size
Definition internal.h:2514
struct MHD_Connection * normal_timeout_head
Definition internal.h:2029
union MHD_DaemonInfo daemon_info_dummy_flags
Definition internal.h:2537
MHD_RequestCompletedCallback notify_completed
Definition internal.h:2068
struct MHD_Connection * cleanup_head
Definition internal.h:1951
unsigned int connections
Definition internal.h:2167
struct MHD_itc_ itc
Definition internal.h:2251
int listening_address_reuse
Definition internal.h:2244
uint64_t connection_timeout_ms
Definition internal.h:2306
void * apc_cls
Definition internal.h:2062
unsigned int per_ip_connection_limit
Definition internal.h:2312
struct MHD_Connection * manual_timeout_tail
Definition internal.h:2051
volatile bool shutdown
Definition internal.h:2256
union MHD_DaemonInfo daemon_info_dummy_num_connections
Definition internal.h:2532
enum MHD_FLAG options
Definition internal.h:1916
void * notify_connection_cls
Definition internal.h:2084
struct MHD_Connection * cleanup_tail
Definition internal.h:1956
bool sigpipe_blocked
Definition internal.h:2346
UnescapeCallback unescape_callback
Definition internal.h:2103
void * notify_completed_cls
Definition internal.h:2073
volatile bool was_quiesced
Definition internal.h:2263
struct MHD_Connection * suspended_connections_head
Definition internal.h:1941
struct MHD_Connection * new_connections_head
Definition internal.h:1921
int allow_bzero_in_url
Definition internal.h:2325
enum MHD_tristate listen_is_unix
Definition internal.h:1961
volatile bool resuming
Definition internal.h:2277
void * default_handler_cls
Definition internal.h:1908
struct MHD_Connection * connections_head
Definition internal.h:1931
MHD_AcceptPolicyCallback apc
Definition internal.h:2057
volatile bool have_new
Definition internal.h:2283
size_t pool_increment
Definition internal.h:2177
MHD_socket listen_fd
Definition internal.h:2142
void * per_ip_connection_count
Definition internal.h:2159
void * uri_log_callback_cls
Definition internal.h:2098
struct MHD_Daemon * master
Definition internal.h:2134
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:1301
bool responseIcy
Definition internal.h:1294
struct MHD_iovec_track_ resp_iov
Definition internal.h:1309
struct MHD_Response * response
Definition internal.h:1282
unsigned int responseCode
Definition internal.h:1288
struct MHD_Reply_Properties props
Definition internal.h:1318
unsigned int skipped_empty_lines
Definition internal.h:955
struct MHD_HTTP_Req_Header * headers_received
Definition internal.h:1117
union MHD_HeadersProcessing hdrs
Definition internal.h:1247
uint64_t current_chunk_size
Definition internal.h:1167
uint64_t current_chunk_offset
Definition internal.h:1173
bool some_payload_processed
Definition internal.h:1190
size_t skipped_broken_lines
Definition internal.h:1242
void * client_context
Definition internal.h:1198
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:1237
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:1130
union MHD_StartOrSize field_lines
Definition internal.h:1140
struct MHD_HTTP_Req_Header * headers_received_tail
Definition internal.h:1122
enum MHD_HTTP_Method http_mthd
Definition internal.h:1090
bool client_aware
Definition internal.h:1205
bool have_chunked_upload
Definition internal.h:1158
const char * url_for_callback
Definition internal.h:1112
uint64_t remaining_upload_size
Definition internal.h:1146
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