32#include "microhttpd2.h"
41#include <gnutls/gnutls.h>
42#if GNUTLS_VERSION_MAJOR >= 3
43#include <gnutls/abstract.h>
61#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, msg); \
62 BUILTIN_NOT_REACHED; } while (0)
69#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); \
70 BUILTIN_NOT_REACHED; } while (0)
87 enum MHD_StatusCode sc,
98#define MHD_fd_close_chk_(fd) do { \
99 if ( (0 != close ((fd)) && (EBADF == errno)) ) \
100 MHD_PANIC (_ ("Failed to close FD.\n")); \
107#define EXTRA_CHECKS MHD_NO
109#define MHD_MAX(a,b) (((a)<(b)) ? (b) : (a))
110#define MHD_MIN(a,b) (((a)<(b)) ? (a) : (b))
120#define MHD_BUF_INC_SIZE 1024
134#if defined(__clang__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= \
136#define BUILTIN_NOT_REACHED __builtin_unreachable ()
137#elif defined(_MSC_FULL_VER)
138#define BUILTIN_NOT_REACHED __assume (0)
140#define BUILTIN_NOT_REACHED
143#ifndef MHD_STATICSTR_LEN_
147#define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1)
197 const void *read_from,
323#ifdef UPGRADE_SUPPORT
458#ifdef UPGRADE_SUPPORT
465 struct MHD_UpgradeResponseHandle *urh;
531 #if defined(_MHD_HAVE_SENDFILE)
533 enum MHD_resp_sender_
535 MHD_resp_sender_std = 0,
536 MHD_resp_sender_sendfile
700 struct MHD_TLS_ConnectionState *tls_cs;
723 MHD_thread_handle_ID_
pid;
797#ifdef UPGRADE_SUPPORT
807#define RESERVE_EBUF_SIZE 8
815struct UpgradeEpollHandle
821 struct MHD_UpgradeResponseHandle *urh;
853struct MHD_UpgradeResponseHandle
866 struct MHD_UpgradeResponseHandle *next;
871 struct MHD_UpgradeResponseHandle *prev;
877 struct MHD_UpgradeResponseHandle *nextE;
882 struct MHD_UpgradeResponseHandle *prevE;
909 size_t in_buffer_size;
916 size_t out_buffer_size;
925 size_t in_buffer_used;
934 size_t out_buffer_used;
939 struct UpgradeEpollHandle app;
945 struct UpgradeEpollHandle mhd;
951 char e_buf[RESERVE_EBUF_SIZE];
965 volatile bool was_closed;
1077#ifdef UPGRADE_SUPPORT
1083 struct MHD_UpgradeResponseHandle *urh_head;
1090 struct MHD_UpgradeResponseHandle *urh_tail;
1098 void *tls_backend_lib;
1111 const void *digest_auth_random_buf;
1203 const char *epoll_itc_marker;
1204#ifdef UPGRADE_SUPPORT
1208 struct MHD_UpgradeResponseHandle *eready_urh_head;
1213 struct MHD_UpgradeResponseHandle *eready_urh_tail;
1222 const char *digest_auth_random;
1232 MHD_mutex_ nnc_lock;
1237 size_t digest_auth_rand_size;
1242 unsigned int nonce_nc_size;
1276#define POOL_SIZE_DEFAULT (32 * 1024)
1290#define BUF_INC_SIZE_DEFAULT 1024
1309 size_t digest_auth_random_buf_size;
1314#define DIGEST_NC_LENGTH_DEFAULT 4
1320 size_t digest_nc_length;
1327#define LISTEN_BACKLOG_DEFAULT SOMAXCONN
1329#define LISTEN_BACKLOG_DEFAULT 511
1341#define FO_QUEUE_LENGTH_DEFAULT 50
1389 bool listen_socket_in_epoll;
1391#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
1396 int epoll_upgrade_fd;
1402 bool upgrade_fd_in_epoll;
1539typedef enum MHD_StatusCode
1619#ifdef UPGRADE_SUPPORT
1630 void *upgrade_handler_cls;
1732 unsigned int *num_headers);
1743#define DLL_insert(head,tail,element) do { \
1744 mhd_assert (NULL == (element)->next); \
1745 mhd_assert (NULL == (element)->prev); \
1746 (element)->next = (head); \
1747 (element)->prev = NULL; \
1748 if ((tail) == NULL) \
1751 (head)->prev = element; \
1752 (head) = (element); } while (0)
1763#define DLL_remove(head,tail,element) do { \
1764 mhd_assert ( (NULL != (element)->next) || ((element) == (tail))); \
1765 mhd_assert ( (NULL != (element)->prev) || ((element) == (head))); \
1766 if ((element)->prev == NULL) \
1767 (head) = (element)->next; \
1769 (element)->prev->next = (element)->next; \
1770 if ((element)->next == NULL) \
1771 (tail) = (element)->prev; \
1773 (element)->next->prev = (element)->prev; \
1774 (element)->next = NULL; \
1775 (element)->prev = NULL; } while (0)
1786#define XDLL_insert(head,tail,element) do { \
1787 mhd_assert (NULL == (element)->nextX); \
1788 mhd_assert (NULL == (element)->prevX); \
1789 (element)->nextX = (head); \
1790 (element)->prevX = NULL; \
1791 if (NULL == (tail)) \
1794 (head)->prevX = element; \
1795 (head) = (element); } while (0)
1806#define XDLL_remove(head,tail,element) do { \
1807 mhd_assert ( (NULL != (element)->nextX) || ((element) == (tail))); \
1808 mhd_assert ( (NULL != (element)->prevX) || ((element) == (head))); \
1809 if (NULL == (element)->prevX) \
1810 (head) = (element)->nextX; \
1812 (element)->prevX->nextX = (element)->nextX; \
1813 if (NULL == (element)->nextX) \
1814 (tail) = (element)->prevX; \
1816 (element)->nextX->prevX = (element)->prevX; \
1817 (element)->nextX = NULL; \
1818 (element)->prevX = NULL; } while (0)
1829#define EDLL_insert(head,tail,element) do { \
1830 (element)->nextE = (head); \
1831 (element)->prevE = NULL; \
1832 if ((tail) == NULL) \
1835 (head)->prevE = element; \
1836 (head) = (element); } while (0)
1847#define EDLL_remove(head,tail,element) do { \
1848 if ((element)->prevE == NULL) \
1849 (head) = (element)->nextE; \
1851 (element)->prevE->nextE = (element)->nextE; \
1852 if ((element)->nextE == NULL) \
1853 (tail) = (element)->prevE; \
1855 (element)->nextE->prevE = (element)->prevE; \
1856 (element)->nextE = NULL; \
1857 (element)->prevE = NULL; } while (0)
1863#define MHD_ERR_AGAIN_ (-3073)
1868#define MHD_ERR_CONNRESET_ (-3074)
1874#define MHD_ERR_NOTCONN_ (-3075)
1879#define MHD_ERR_NOMEM_ (-3076)
1884#define MHD_ERR_BADF_ (-3077)
1889#define MHD_ERR_INVAL_ (-3078)
void(* MHD_PanicCallback)(void *cls, const char *file, unsigned int line, const char *reason)
void(* MHD_NotifyConnectionCallback)(void *cls, struct MHD_Connection *connection, void **socket_context, enum MHD_ConnectionNotificationCode toe)
void(* MHD_ContentReaderFreeCallback)(void *cls)
MHD_PanicCallback mhd_panic
ssize_t(* TransmitCallback)(struct MHD_Connection *conn, const void *read_from, size_t max_bytes)
@ MHD_EPOLL_STATE_SUSPENDED
@ MHD_EPOLL_STATE_IN_EREADY_EDLL
@ MHD_EPOLL_STATE_READ_READY
@ MHD_EPOLL_STATE_IN_EPOLL_SET
@ MHD_EPOLL_STATE_UNREADY
@ MHD_EPOLL_STATE_WRITE_READY
bool(* MHD_ArgumentIterator_)(struct MHD_Request *request, const char *key, const char *value, enum MHD_ValueKind kind)
@ MHD_CONN_KEEPALIVE_UNKOWN
ssize_t(* ReceiveCallback)(struct MHD_Connection *conn, void *write_to, size_t max_bytes)
@ MHD_REQUEST_CHUNKED_BODY_UNREADY
@ MHD_REQUEST_CONTINUE_SENDING
@ MHD_REQUEST_NORMAL_BODY_READY
@ MHD_REQUEST_FOOTER_PART_RECEIVED
@ MHD_REQUEST_HEADER_PART_RECEIVED
@ MHD_REQUEST_FOOTERS_SENDING
@ MHD_REQUEST_HEADERS_SENDING
@ MHD_REQUEST_HEADERS_SENT
@ MHD_REQUEST_BODY_RECEIVED
@ MHD_REQUEST_CHUNKED_BODY_READY
@ MHD_REQUEST_HEADERS_RECEIVED
@ MHD_REQUEST_FOOTERS_RECEIVED
@ MHD_REQUEST_HEADERS_PROCESSED
@ MHD_REQUEST_FOOTERS_SENT
@ MHD_REQUEST_URL_RECEIVED
@ MHD_REQUEST_CONTINUE_SENT
@ MHD_REQUEST_NORMAL_BODY_UNREADY
bool MHD_parse_arguments_(struct MHD_Request *request, enum MHD_ValueKind kind, char *args, MHD_ArgumentIterator_ cb, unsigned int *num_headers)
enum MHD_StatusCode(* ActionCallback)(void *cls, struct MHD_Request *request)
additional automatic macros for MHD_config.h
ssize_t(* TransmitCallback)(struct MHD_Connection *conn, const void *read_from, size_t max_bytes)
ssize_t(* ReceiveCallback)(struct MHD_Connection *conn, void *write_to, size_t max_bytes)
memory pool; mostly used for efficient (de)allocation for each connection and bounding memory use for...
Header for platform missing functions.
Header for platform-independent inter-thread communication.
Types for platform-independent inter-thread communication.
Header for platform-independent locks abstraction.
internal monotonic clock functions implementations
Header for string manipulating helpers.
Header for platform-independent threads abstraction.
void(* MHD_UpgradeHandler)(void *cls, struct MHD_Connection *connection, void *con_cls, const char *extra_in, size_t extra_in_size, MHD_socket sock, struct MHD_UpgradeResponseHandle *urh)
enum MHD_Result(* MHD_AcceptPolicyCallback)(void *cls, const struct sockaddr *addr, socklen_t addrlen)
ssize_t(* MHD_ContentReaderCallback)(void *cls, uint64_t pos, char *buf, size_t max)
interface for TLS plugins of libmicrohttpd
struct MHD_Connection * prevX
struct MHD_Request request
struct MHD_Connection * next
time_t connection_timeout
struct sockaddr_storage addr
TransmitCallback send_cls
struct MHD_Connection * prev
MHD_thread_handle_ID_ pid
struct MHD_Connection * nextX
struct MHD_Daemon * daemon
bool data_already_pending
MHD_mutex_ per_ip_connection_mutex
void * per_ip_connection_count
MHD_EarlyUriLogCallback early_uri_logger_cb
unsigned int ip_connection_limit
enum MHD_AddressFamily listen_af
MHD_mutex_ cleanup_connection_mutex
MHD_AcceptPolicyCallback accept_policy_cb
struct MHD_Connection * connections_head
MHD_NotifyConnectionCallback notify_connection_cb
void * notify_connection_cb_cls
void * early_uri_logger_cb_cls
unsigned int worker_pool_size
enum MHD_FastOpenMethod fast_open_method
enum MHD_EventLoopSyscall event_loop_syscall
struct MHD_Connection * manual_timeout_tail
size_t connection_memory_increment_b
MHD_LoggingCallback logger
bool disallow_suspend_resume
struct sockaddr_storage listen_sa
struct MHD_Connection * cleanup_tail
enum MHD_ProtocolStrictLevel protocol_strict_level
struct MHD_Daemon * worker_pool
MHD_thread_handle_ID_ pid
time_t connection_default_timeout
struct MHD_Connection * manual_timeout_head
struct MHD_Connection * suspended_connections_tail
struct MHD_Connection * cleanup_head
struct MHD_Daemon * master
struct MHD_Connection * normal_timeout_head
size_t connection_memory_limit_b
struct MHD_Connection * normal_timeout_tail
enum MHD_ThreadingMode threading_mode
unsigned int global_connection_limit
MHD_UnescapeCallback unescape_cb
void * accept_policy_cb_cls
size_t thread_stack_limit_b
struct MHD_Connection * suspended_connections_head
struct MHD_Connection * connections_tail
unsigned int fo_queue_length
size_t write_buffer_append_offset
struct MHD_Response * response
uint64_t current_chunk_size
uint64_t current_chunk_offset
struct MHD_HTTP_Header * headers_received
struct MHD_HTTP_Header * headers_received_tail
size_t continue_message_write_offset
size_t write_buffer_send_offset
size_t read_buffer_offset
enum MHD_RequestEventLoopInfo event_loop_info
uint64_t response_write_position
struct MHD_Connection * connection
struct MHD_Daemon * daemon
enum MHD_REQUEST_STATE state
enum MHD_ConnKeepAlive keepalive
uint64_t remaining_upload_size
MHD_ContentReaderFreeCallback crfc
void * termination_cb_cls
struct MHD_HTTP_Header * first_header
enum MHD_HTTP_StatusCode status_code
MHD_ContentReaderCallback crc
MHD_RequestTerminationCallback termination_cb
unsigned int reference_count