GNU libmicrohttpd 1.0.5
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
28
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
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
1633};
1634
1635
1636#ifdef UPGRADE_SUPPORT
1646#define RESERVE_EBUF_SIZE 8
1647
1654struct UpgradeEpollHandle
1655{
1660 struct MHD_UpgradeResponseHandle *urh;
1661
1677 MHD_socket socket;
1678
1682 enum MHD_EpollState celi;
1683
1684};
1685
1686
1692struct MHD_UpgradeResponseHandle
1693{
1699 struct MHD_Connection *connection;
1700
1701#ifdef HTTPS_SUPPORT
1705 struct MHD_UpgradeResponseHandle *next;
1706
1710 struct MHD_UpgradeResponseHandle *prev;
1711
1712#ifdef EPOLL_SUPPORT
1716 struct MHD_UpgradeResponseHandle *nextE;
1717
1721 struct MHD_UpgradeResponseHandle *prevE;
1722
1726 bool in_eready_list;
1727#endif
1728
1734 char *in_buffer;
1735
1741 char *out_buffer;
1742
1748 size_t in_buffer_size;
1749
1755 size_t out_buffer_size;
1756
1764 size_t in_buffer_used;
1765
1773 size_t out_buffer_used;
1774
1778 struct UpgradeEpollHandle app;
1779
1784 struct UpgradeEpollHandle mhd;
1785
1790 char e_buf[RESERVE_EBUF_SIZE];
1791
1792#endif /* HTTPS_SUPPORT */
1793
1804 volatile bool was_closed;
1805
1827 volatile bool clean_ready;
1828};
1829#endif /* UPGRADE_SUPPORT */
1830
1831
1840typedef void *
1841(*LogCallback)(void *cls,
1842 const char *uri,
1843 struct MHD_Connection *con);
1844
1854typedef size_t
1855(*UnescapeCallback)(void *cls,
1856 struct MHD_Connection *conn,
1857 char *uri);
1858
1859
1868{
1869
1874
1879
1887
1892
1897
1902
1907
1912
1917
1922
1927
1932
1933#ifdef EPOLL_SUPPORT
1937 struct MHD_Connection *eready_head;
1938
1942 struct MHD_Connection *eready_tail;
1943
1950 int epoll_fd;
1951
1956 bool listen_socket_in_epoll;
1957
1958#ifdef UPGRADE_SUPPORT
1959#ifdef HTTPS_SUPPORT
1964 int epoll_upgrade_fd;
1965
1970 bool upgrade_fd_in_epoll;
1971#endif /* HTTPS_SUPPORT */
1972
1976 struct MHD_UpgradeResponseHandle *eready_urh_head;
1977
1981 struct MHD_UpgradeResponseHandle *eready_urh_tail;
1982#endif /* UPGRADE_SUPPORT */
1983#endif /* EPOLL_SUPPORT */
1984
2000
2007
2015
2022
2028
2032 void *apc_cls;
2033
2039
2044
2050
2055
2064
2069
2074
2079
2086 uint16_t port;
2087
2088#ifdef HAVE_MESSAGES
2093 MHD_LogCallback custom_error_log;
2094
2098 void *custom_error_log_cls;
2099#endif
2100
2105
2113
2118
2119#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2123 struct MHD_Daemon *worker_pool;
2124#endif
2125
2130
2137 unsigned int connections;
2138
2143
2148
2149#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2153 size_t thread_stack_size;
2154
2158 unsigned int worker_pool_size;
2159
2164
2168 MHD_mutex_ per_ip_connection_mutex;
2169
2174 MHD_mutex_ cleanup_connection_mutex;
2175
2179 MHD_mutex_ new_connections_mutex;
2180#endif
2181
2187
2198
2199
2204 struct MHD_itc_ itc;
2205
2209 volatile bool shutdown;
2210
2216 volatile bool was_quiesced;
2217
2226
2227 /*
2228 * Do we need to process resuming connections?
2229 */
2230 volatile bool resuming;
2231
2236 volatile bool have_new;
2237
2248
2252 unsigned int connection_limit;
2253
2260
2266
2272
2279
2280#ifdef HAS_FD_SETSIZE_OVERRIDABLE
2287 int fdset_size;
2288
2293 bool fdset_size_set_by_app;
2294#endif /* HAS_FD_SETSIZE_OVERRIDABLE */
2295
2300
2301#ifdef HTTPS_SUPPORT
2302#ifdef UPGRADE_SUPPORT
2308 struct MHD_UpgradeResponseHandle *urh_head;
2309
2315 struct MHD_UpgradeResponseHandle *urh_tail;
2316#endif /* UPGRADE_SUPPORT */
2317
2321 gnutls_priority_t priority_cache;
2322
2327 gnutls_credentials_type_t cred_type;
2328
2332 gnutls_certificate_credentials_t x509_cred;
2333
2337 gnutls_dh_params_t dh_params;
2338
2342 gnutls_psk_server_credentials_t psk_cred;
2343
2344#if GNUTLS_VERSION_MAJOR >= 3
2349 gnutls_certificate_retrieve_function2 *cert_callback;
2350
2355
2359 void *cred_callback_cls;
2360#endif
2361
2362#if GNUTLS_VERSION_NUMBER >= 0x030603
2367 gnutls_certificate_retrieve_function3 *cert_callback2;
2368#endif
2369
2373 const char *https_mem_key;
2374
2378 const char *https_mem_cert;
2379
2383 const char *https_key_password;
2384
2388 const char *https_mem_trust;
2389
2393 gnutls_dh_params_t https_mem_dhparams;
2394
2398 bool have_dhparams;
2399
2403 bool disable_alpn;
2404
2405 #endif /* HTTPS_SUPPORT */
2406
2407#ifdef DAUTH_SUPPORT
2408
2412 const char *digest_auth_random;
2413
2417 size_t digest_auth_rand_size;
2418
2422 void *digest_auth_random_copy;
2423
2427 struct MHD_NonceNc *nnc;
2428
2429#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2433 MHD_mutex_ nnc_lock;
2434#endif
2435
2439 unsigned int nonce_nc_size;
2440
2444 unsigned int dauth_bind_type;
2445
2449 unsigned int dauth_def_nonce_timeout;
2450
2454 uint32_t dauth_def_max_nc;
2455#endif
2456
2457#ifdef TCP_FASTOPEN
2461 unsigned int fastopen_queue_size;
2462#endif
2463
2468
2469 /* TODO: replace with a single member */
2474
2475#ifdef EPOLL_SUPPORT
2479 union MHD_DaemonInfo daemon_info_dummy_epoll_fd;
2480#endif /* EPOLL_SUPPORT */
2481
2486
2491
2496
2497#if defined(_DEBUG) && defined(HAVE_ACCEPT4)
2506 bool avoid_accept4;
2507#endif /* _DEBUG */
2508};
2509
2510
2511#if defined(HAVE_POLL) && defined(EPOLL_SUPPORT)
2515#define MHD_D_IS_USING_SELECT_(d) \
2516 (0 == (d->options & (MHD_USE_POLL | MHD_USE_EPOLL)))
2520#define MHD_D_IS_USING_POLL_(d) (0 != ((d)->options & MHD_USE_POLL))
2524#define MHD_D_IS_USING_EPOLL_(d) (0 != ((d)->options & MHD_USE_EPOLL))
2525#elif defined(HAVE_POLL)
2529#define MHD_D_IS_USING_SELECT_(d) (0 == ((d)->options & MHD_USE_POLL))
2533#define MHD_D_IS_USING_POLL_(d) (0 != ((d)->options & MHD_USE_POLL))
2537#define MHD_D_IS_USING_EPOLL_(d) ((void) (d), 0)
2538#elif defined(EPOLL_SUPPORT)
2542#define MHD_D_IS_USING_SELECT_(d) (0 == ((d)->options & MHD_USE_EPOLL))
2546#define MHD_D_IS_USING_POLL_(d) ((void) (d), 0)
2550#define MHD_D_IS_USING_EPOLL_(d) (0 != ((d)->options & MHD_USE_EPOLL))
2551#else /* select() only */
2555#define MHD_D_IS_USING_SELECT_(d) ((void) (d), ! 0)
2559#define MHD_D_IS_USING_POLL_(d) ((void) (d), 0)
2563#define MHD_D_IS_USING_EPOLL_(d) ((void) (d), 0)
2564#endif /* select() only */
2565
2566#if defined(MHD_USE_THREADS)
2570#define MHD_D_IS_USING_THREADS_(d) \
2571 (0 != (d->options & (MHD_USE_INTERNAL_POLLING_THREAD)))
2575#define MHD_D_IS_USING_THREAD_PER_CONN_(d) \
2576 (0 != ((d)->options & MHD_USE_THREAD_PER_CONNECTION))
2577
2581#define MHD_D_IS_THREAD_SAFE_(d) \
2582 (0 == ((d)->options & MHD_USE_NO_THREAD_SAFETY))
2583#else /* ! MHD_USE_THREADS */
2587#define MHD_D_IS_USING_THREADS_(d) ((void) d, 0)
2591#define MHD_D_IS_USING_THREAD_PER_CONN_(d) ((void) d, 0)
2592
2596#define MHD_D_IS_THREAD_SAFE_(d) ((void) d, 0)
2597#endif /* ! MHD_USE_THREADS */
2598
2599#ifdef HAS_FD_SETSIZE_OVERRIDABLE
2603#define MHD_D_GET_FD_SETSIZE_(d) ((d)->fdset_size)
2604#else /* ! HAS_FD_SETSIZE_OVERRIDABLE */
2608#define MHD_D_GET_FD_SETSIZE_(d) (FD_SETSIZE)
2609#endif /* ! HAS_FD_SETSIZE_OVERRIDABLE */
2610
2614#define MHD_D_DOES_SCKT_FIT_FDSET_(sckt,d) \
2615 MHD_SCKT_FD_FITS_FDSET_SETSIZE_(sckt,NULL,MHD_D_GET_FD_SETSIZE_(d))
2616
2617
2618#ifdef DAUTH_SUPPORT
2619
2623struct MHD_RqDAuthParam
2624{
2628 struct _MHD_str_w_len value;
2634 bool quoted;
2635};
2636
2640struct MHD_RqDAuth
2641{
2642 struct MHD_RqDAuthParam nonce;
2643 struct MHD_RqDAuthParam opaque;
2644 struct MHD_RqDAuthParam response;
2645 struct MHD_RqDAuthParam username;
2646 struct MHD_RqDAuthParam username_ext;
2647 struct MHD_RqDAuthParam realm;
2648 struct MHD_RqDAuthParam uri;
2649 /* The raw QOP value, used in the 'response' calculation */
2650 struct MHD_RqDAuthParam qop_raw;
2651 struct MHD_RqDAuthParam cnonce;
2652 struct MHD_RqDAuthParam nc;
2653
2654 /* Decoded values are below */
2655 bool userhash; /* True if 'userhash' parameter has value 'true'. */
2656 enum MHD_DigestAuthAlgo3 algo3;
2657 enum MHD_DigestAuthQOP qop;
2658};
2659
2660
2661#endif /* DAUTH_SUPPORT */
2662
2671#define DLL_insert(head,tail,element) do { \
2672 mhd_assert (NULL == (element)->next); \
2673 mhd_assert (NULL == (element)->prev); \
2674 (element)->next = (head); \
2675 (element)->prev = NULL; \
2676 if ((tail) == NULL) { \
2677 (tail) = element; \
2678 } else { \
2679 (head)->prev = element; \
2680 } \
2681 (head) = (element); } while (0)
2682
2683
2693#define DLL_remove(head,tail,element) do { \
2694 mhd_assert ( (NULL != (element)->next) || ((element) == (tail))); \
2695 mhd_assert ( (NULL != (element)->prev) || ((element) == (head))); \
2696 if ((element)->prev == NULL) { \
2697 (head) = (element)->next; \
2698 } else { \
2699 (element)->prev->next = (element)->next; \
2700 } \
2701 if ((element)->next == NULL) { \
2702 (tail) = (element)->prev; \
2703 } else { \
2704 (element)->next->prev = (element)->prev; \
2705 } \
2706 (element)->next = NULL; \
2707 (element)->prev = NULL; } while (0)
2708
2709
2718#define XDLL_insert(head,tail,element) do { \
2719 mhd_assert (NULL == (element)->nextX); \
2720 mhd_assert (NULL == (element)->prevX); \
2721 (element)->nextX = (head); \
2722 (element)->prevX = NULL; \
2723 if (NULL == (tail)) { \
2724 (tail) = element; \
2725 } else { \
2726 (head)->prevX = element; \
2727 } \
2728 (head) = (element); } while (0)
2729
2730
2740#define XDLL_remove(head,tail,element) do { \
2741 mhd_assert ( (NULL != (element)->nextX) || ((element) == (tail))); \
2742 mhd_assert ( (NULL != (element)->prevX) || ((element) == (head))); \
2743 if (NULL == (element)->prevX) { \
2744 (head) = (element)->nextX; \
2745 } else { \
2746 (element)->prevX->nextX = (element)->nextX; \
2747 } \
2748 if (NULL == (element)->nextX) { \
2749 (tail) = (element)->prevX; \
2750 } else { \
2751 (element)->nextX->prevX = (element)->prevX; \
2752 } \
2753 (element)->nextX = NULL; \
2754 (element)->prevX = NULL; } while (0)
2755
2756
2765#define EDLL_insert(head,tail,element) do { \
2766 (element)->nextE = (head); \
2767 (element)->prevE = NULL; \
2768 if ((tail) == NULL) { \
2769 (tail) = element; \
2770 } else { \
2771 (head)->prevE = element; \
2772 } \
2773 (head) = (element); } while (0)
2774
2775
2785#define EDLL_remove(head,tail,element) do { \
2786 if ((element)->prevE == NULL) { \
2787 (head) = (element)->nextE; \
2788 } else { \
2789 (element)->prevE->nextE = (element)->nextE; \
2790 } \
2791 if ((element)->nextE == NULL) { \
2792 (tail) = (element)->prevE; \
2793 } else { \
2794 (element)->nextE->prevE = (element)->prevE; \
2795 } \
2796 (element)->nextE = NULL; \
2797 (element)->prevE = NULL; } while (0)
2798
2799
2805void
2807
2808
2822typedef enum MHD_Result
2823(*MHD_ArgumentIterator_)(void *cls,
2824 const char *key,
2825 size_t key_size,
2826 const char *value,
2827 size_t value_size,
2828 enum MHD_ValueKind kind);
2829
2830
2845enum MHD_Result
2846MHD_parse_arguments_ (struct MHD_Connection *connection,
2847 enum MHD_ValueKind kind,
2848 char *args,
2850 void *cls);
2851
2852
2869bool
2870MHD_check_response_header_token_ci (const struct MHD_Response *response,
2871 const char *key,
2872 size_t key_len,
2873 const char *token,
2874 size_t token_len);
2875
2887#define MHD_check_response_header_s_token_ci(r,k,tkn) \
2888 MHD_check_response_header_token_ci ((r),(k),MHD_STATICSTR_LEN_ (k), \
2889 (tkn),MHD_STATICSTR_LEN_ (tkn))
2890
2891
2901void
2902internal_suspend_connection_ (struct MHD_Connection *connection);
2903
2904
2912_MHD_static_inline struct MHD_Daemon *
2913MHD_get_master (struct MHD_Daemon *const daemon)
2914{
2915 struct MHD_Daemon *ret;
2916
2917 if (NULL != daemon->master)
2918 ret = daemon->master;
2919 else
2920 ret = daemon;
2921 mhd_assert (NULL == ret->master);
2922
2923 return ret;
2924}
2925
2926
2927#ifdef UPGRADE_SUPPORT
2935void
2936MHD_upgraded_connection_mark_app_closed_ (struct MHD_Connection *connection);
2937
2938#endif /* UPGRADE_SUPPORT */
2939
2940
2941#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)
#define _MHD_FIXED_ENUM
Definition microhttpd.h:154
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:2823
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:1841
_MHD_static_inline struct MHD_Daemon * MHD_get_master(struct MHD_Daemon *const daemon)
Definition internal.h:2913
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
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
size_t(* UnescapeCallback)(void *cls, struct MHD_Connection *conn, char *uri)
Definition internal.h:1855
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.
struct _MHD_thread_handle_ID_ MHD_thread_handle_ID_
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)
#define _MHD_FIXED_FLAGS_ENUM
Definition microhttpd.h:157
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
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:1632
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:2142
MHD_NotifyConnectionCallback notify_connection
Definition internal.h:2049
MHD_AccessHandlerCallback default_handler
Definition internal.h:1873
LogCallback uri_log_callback
Definition internal.h:2063
bool data_already_pending
Definition internal.h:2247
union MHD_DaemonInfo daemon_info_dummy_port
Definition internal.h:2495
struct MHD_Connection * normal_timeout_tail
Definition internal.h:2006
bool at_limit
Definition internal.h:2225
struct MHD_Connection * new_connections_tail
Definition internal.h:1896
int client_discipline
Definition internal.h:2271
uint16_t port
Definition internal.h:2086
bool listen_nonblk
Definition internal.h:2117
unsigned int connection_limit
Definition internal.h:2252
void * unescape_callback_cls
Definition internal.h:2078
enum MHD_DisableSanityCheck insanity_level
Definition internal.h:2186
struct MHD_Connection * connections_tail
Definition internal.h:1906
struct MHD_Connection * suspended_connections_tail
Definition internal.h:1916
union MHD_DaemonInfo daemon_info_dummy_listen_fd
Definition internal.h:2473
struct MHD_Connection * manual_timeout_head
Definition internal.h:2014
unsigned int listen_backlog_size
Definition internal.h:2467
struct MHD_Connection * normal_timeout_head
Definition internal.h:1999
union MHD_DaemonInfo daemon_info_dummy_flags
Definition internal.h:2490
MHD_RequestCompletedCallback notify_completed
Definition internal.h:2038
struct MHD_Connection * cleanup_head
Definition internal.h:1921
unsigned int connections
Definition internal.h:2137
struct MHD_itc_ itc
Definition internal.h:2204
int listening_address_reuse
Definition internal.h:2197
uint64_t connection_timeout_ms
Definition internal.h:2259
void * apc_cls
Definition internal.h:2032
unsigned int per_ip_connection_limit
Definition internal.h:2265
struct MHD_Connection * manual_timeout_tail
Definition internal.h:2021
volatile bool shutdown
Definition internal.h:2209
union MHD_DaemonInfo daemon_info_dummy_num_connections
Definition internal.h:2485
enum MHD_FLAG options
Definition internal.h:1886
void * notify_connection_cls
Definition internal.h:2054
struct MHD_Connection * cleanup_tail
Definition internal.h:1926
bool sigpipe_blocked
Definition internal.h:2299
UnescapeCallback unescape_callback
Definition internal.h:2073
void * notify_completed_cls
Definition internal.h:2043
volatile bool was_quiesced
Definition internal.h:2216
struct MHD_Connection * suspended_connections_head
Definition internal.h:1911
struct MHD_Connection * new_connections_head
Definition internal.h:1891
int allow_bzero_in_url
Definition internal.h:2278
enum MHD_tristate listen_is_unix
Definition internal.h:1931
volatile bool resuming
Definition internal.h:2230
void * default_handler_cls
Definition internal.h:1878
struct MHD_Connection * connections_head
Definition internal.h:1901
MHD_AcceptPolicyCallback apc
Definition internal.h:2027
volatile bool have_new
Definition internal.h:2236
size_t pool_increment
Definition internal.h:2147
MHD_socket listen_fd
Definition internal.h:2112
void * per_ip_connection_count
Definition internal.h:2129
void * uri_log_callback_cls
Definition internal.h:2068
struct MHD_Daemon * master
Definition internal.h:2104
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