38#include <gnutls/gnutls.h>
39#if GNUTLS_VERSION_MAJOR >= 3
40#include <gnutls/abstract.h>
67#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, msg); \
68 BUILTIN_NOT_REACHED; } while (0)
75#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); \
76 BUILTIN_NOT_REACHED; } while (0)
79#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
80#include "mhd_threads.h"
91#define _MHD_MACRO_NO 0
97#define _MHD_MACRO_YES 1
103#define MHD_fd_close_chk_(fd) do { \
104 if ( (0 != close ((fd)) && (EBADF == errno)) ) { \
105 MHD_PANIC (_ ("Failed to close FD.\n")); \
114#ifndef _MHD_DEBUG_CONNECT
119#define _MHD_DEBUG_CONNECT _MHD_MACRO_NO
122#ifndef _MHD_DEBUG_SEND_DATA
126#define _MHD_DEBUG_SEND_DATA _MHD_MACRO_NO
129#ifndef _MHD_DEBUG_CLOSE
134#define _MHD_DEBUG_CLOSE _MHD_MACRO_NO
137#define MHD_MAX(a,b) (((a)<(b)) ? (b) : (a))
138#define MHD_MIN(a,b) (((a)<(b)) ? (a) : (b))
148#define MHD_BUF_INC_SIZE 1024
162#if defined(__clang__) || (__GNUC__ > 4) || \
163 (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
164#define BUILTIN_NOT_REACHED __builtin_unreachable ()
165#elif defined(_MSC_FULL_VER)
166#define BUILTIN_NOT_REACHED __assume (0)
168#define BUILTIN_NOT_REACHED
171#ifndef MHD_STATICSTR_LEN_
175#define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1)
269#define MHD_TEST_ALLOW_SUSPEND_RESUME 8192
277#define MAX_NONCE_LENGTH 129
376#if defined(MHD_WINSOCK_SOCKETS)
381typedef struct _MHD_W32_iovec
383 unsigned long iov_len;
386#define MHD_IOV_ELMN_MAX_SIZE ULONG_MAX
388#elif defined(HAVE_SENDMSG) || defined(HAVE_WRITEV)
394#define MHD_IOV_ELMN_MAX_SIZE SIZE_MAX
402#define MHD_IOV_ELMN_MAX_SIZE SIZE_MAX
470#ifdef UPGRADE_SUPPORT
481 void *upgrade_handler_cls;
484#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
698#ifdef UPGRADE_SUPPORT
703 MHD_CONNECTION_UPGRADE
729#define DEBUG_STATES _MHD_MACRO_NO
764 const void *read_from,
835#define MHD_IS_HTTP_VER_SUPPORTED(ver) (MHD_HTTP_VER_1_0 <= (ver) && \
836 MHD_HTTP_VER_1_2__1_9 >= (ver))
844#define MHD_IS_HTTP_VER_1_1_COMPAT(ver) (MHD_HTTP_VER_1_1 == (ver) || \
845 MHD_HTTP_VER_1_2__1_9 == (ver))
978 struct MemoryPool *
pool;
1067#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1072 MHD_thread_handle_ID_
pid;
1132#if defined(_MHD_HAVE_SENDFILE)
1133 enum MHD_resp_sender_
1135 MHD_resp_sender_std = 0,
1136 MHD_resp_sender_sendfile
1235#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1313#ifdef UPGRADE_SUPPORT
1320 struct MHD_UpgradeResponseHandle *urh;
1328 gnutls_session_t tls_session;
1369#ifdef UPGRADE_SUPPORT
1379#define RESERVE_EBUF_SIZE 8
1387struct UpgradeEpollHandle
1393 struct MHD_UpgradeResponseHandle *urh;
1425struct MHD_UpgradeResponseHandle
1438 struct MHD_UpgradeResponseHandle *next;
1443 struct MHD_UpgradeResponseHandle *prev;
1449 struct MHD_UpgradeResponseHandle *nextE;
1454 struct MHD_UpgradeResponseHandle *prevE;
1459 bool in_eready_list;
1481 size_t in_buffer_size;
1488 size_t out_buffer_size;
1497 size_t in_buffer_used;
1506 size_t out_buffer_used;
1511 struct UpgradeEpollHandle app;
1517 struct UpgradeEpollHandle mhd;
1523 char e_buf[RESERVE_EBUF_SIZE];
1537 volatile bool was_closed;
1560 volatile bool clean_ready;
1574(*LogCallback)(
void *cls,
1689 bool listen_socket_in_epoll;
1691#ifdef UPGRADE_SUPPORT
1697 int epoll_upgrade_fd;
1703 bool upgrade_fd_in_epoll;
1709 struct MHD_UpgradeResponseHandle *eready_urh_head;
1714 struct MHD_UpgradeResponseHandle *eready_urh_tail;
1831 void *custom_error_log_cls;
1852#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1882#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1886 size_t thread_stack_size;
1896 MHD_thread_handle_ID_
pid;
1912 MHD_mutex_ new_connections_mutex;
1937 struct MHD_itc_
itc;
2011#ifdef UPGRADE_SUPPORT
2017 struct MHD_UpgradeResponseHandle *urh_head;
2024 struct MHD_UpgradeResponseHandle *urh_tail;
2030 gnutls_priority_t priority_cache;
2036 gnutls_credentials_type_t cred_type;
2041 gnutls_certificate_credentials_t x509_cred;
2046 gnutls_dh_params_t dh_params;
2051 gnutls_psk_server_credentials_t psk_cred;
2053#if GNUTLS_VERSION_MAJOR >= 3
2058 gnutls_certificate_retrieve_function2 *cert_callback;
2068 void *cred_callback_cls;
2071#if GNUTLS_VERSION_NUMBER >= 0x030603
2076 gnutls_certificate_retrieve_function3 *cert_callback2;
2082 const char *https_mem_key;
2087 const char *https_mem_cert;
2092 const char *https_key_password;
2097 const char *https_mem_trust;
2102 gnutls_dh_params_t https_mem_dhparams;
2121 const char *digest_auth_random;
2128#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2132 MHD_mutex_ nnc_lock;
2138 size_t digest_auth_rand_size;
2143 unsigned int nonce_nc_size;
2151 unsigned int fastopen_queue_size;
2178#define DLL_insert(head,tail,element) do { \
2179 mhd_assert (NULL == (element)->next); \
2180 mhd_assert (NULL == (element)->prev); \
2181 (element)->next = (head); \
2182 (element)->prev = NULL; \
2183 if ((tail) == NULL) { \
2186 (head)->prev = element; \
2188 (head) = (element); } while (0)
2200#define DLL_remove(head,tail,element) do { \
2201 mhd_assert ( (NULL != (element)->next) || ((element) == (tail))); \
2202 mhd_assert ( (NULL != (element)->prev) || ((element) == (head))); \
2203 if ((element)->prev == NULL) { \
2204 (head) = (element)->next; \
2206 (element)->prev->next = (element)->next; \
2208 if ((element)->next == NULL) { \
2209 (tail) = (element)->prev; \
2211 (element)->next->prev = (element)->prev; \
2213 (element)->next = NULL; \
2214 (element)->prev = NULL; } while (0)
2225#define XDLL_insert(head,tail,element) do { \
2226 mhd_assert (NULL == (element)->nextX); \
2227 mhd_assert (NULL == (element)->prevX); \
2228 (element)->nextX = (head); \
2229 (element)->prevX = NULL; \
2230 if (NULL == (tail)) { \
2233 (head)->prevX = element; \
2235 (head) = (element); } while (0)
2247#define XDLL_remove(head,tail,element) do { \
2248 mhd_assert ( (NULL != (element)->nextX) || ((element) == (tail))); \
2249 mhd_assert ( (NULL != (element)->prevX) || ((element) == (head))); \
2250 if (NULL == (element)->prevX) { \
2251 (head) = (element)->nextX; \
2253 (element)->prevX->nextX = (element)->nextX; \
2255 if (NULL == (element)->nextX) { \
2256 (tail) = (element)->prevX; \
2258 (element)->nextX->prevX = (element)->prevX; \
2260 (element)->nextX = NULL; \
2261 (element)->prevX = NULL; } while (0)
2272#define EDLL_insert(head,tail,element) do { \
2273 (element)->nextE = (head); \
2274 (element)->prevE = NULL; \
2275 if ((tail) == NULL) { \
2278 (head)->prevE = element; \
2280 (head) = (element); } while (0)
2292#define EDLL_remove(head,tail,element) do { \
2293 if ((element)->prevE == NULL) { \
2294 (head) = (element)->nextE; \
2296 (element)->prevE->nextE = (element)->nextE; \
2298 if ((element)->nextE == NULL) { \
2299 (tail) = (element)->prevE; \
2301 (element)->nextE->prevE = (element)->prevE; \
2303 (element)->nextE = NULL; \
2304 (element)->prevE = NULL; } while (0)
2357 unsigned int *num_headers);
2394#define MHD_check_response_header_s_token_ci(r,k,tkn) \
2395 MHD_check_response_header_token_ci ((r),(k),MHD_STATICSTR_LEN_ (k), \
2396 (tkn),MHD_STATICSTR_LEN_ (tkn))
2421#ifdef UPGRADE_SUPPORT
2430MHD_upgraded_connection_mark_app_closed_ (
struct MHD_Connection *connection);
void(* MHD_PanicCallback)(void *cls, const char *file, unsigned int line, const char *reason)
void(* MHD_LogCallback)(void *cls, const char *fm, va_list ap)
void(* MHD_NotifyConnectionCallback)(void *cls, struct MHD_Connection *connection, void **socket_context, enum MHD_ConnectionNotificationCode toe)
void(* MHD_RequestCompletedCallback)(void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode 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)
bool MHD_parse_arguments_(struct MHD_Request *request, enum MHD_ValueKind kind, char *args, MHD_ArgumentIterator_ cb, unsigned int *num_headers)
additional automatic macros for MHD_config.h
@ MHD_CONNECTION_BODY_RECEIVED
@ MHD_CONNECTION_HEADER_PART_RECEIVED
@ MHD_CONNECTION_HEADERS_SENDING
@ MHD_CONNECTION_FOOTERS_SENDING
@ MHD_CONNECTION_FOOTERS_RECEIVED
@ MHD_CONNECTION_HEADERS_SENT
@ MHD_CONNECTION_HEADERS_PROCESSED
@ MHD_CONNECTION_NORMAL_BODY_UNREADY
@ MHD_CONNECTION_HEADERS_RECEIVED
@ MHD_CONNECTION_NORMAL_BODY_READY
@ MHD_CONNECTION_START_REPLY
@ MHD_CONNECTION_CHUNKED_BODY_READY
@ MHD_CONNECTION_FOOTER_PART_RECEIVED
@ MHD_CONNECTION_CONTINUE_SENT
@ MHD_CONNECTION_FOOTERS_SENT
@ MHD_CONNECTION_FULL_REQ_RECEIVED
@ MHD_CONNECTION_CHUNKED_BODY_UNREADY
@ MHD_CONNECTION_BODY_SENT
@ MHD_CONNECTION_CONTINUE_SENDING
@ MHD_CONNECTION_URL_RECEIVED
@ MHD_CONNECTION_REQ_LINE_RECEIVING
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)
void internal_suspend_connection_(struct MHD_Connection *connection)
@ MHD_TLS_CONN_TLS_CLOSING
@ MHD_TLS_CONN_WR_CLOSING
@ MHD_TLS_CONN_INVALID_STATE
@ MHD_TLS_CONN_TLS_CLOSED
@ MHD_TLS_CONN_TLS_FAILED
@ MHD_TLS_CONN_HANDSHAKING
MHD_ConnectionEventLoopInfo
@ MHD_EVENT_LOOP_INFO_READ
@ MHD_EVENT_LOOP_INFO_WRITE
@ MHD_EVENT_LOOP_INFO_CLEANUP
@ MHD_EVENT_LOOP_INFO_BLOCK
struct MHD_IoVec MHD_iovec_
void *(* LogCallback)(void *cls, const char *uri, struct MHD_Connection *con)
@ MHD_RAF_HAS_CONNECTION_CLOSE
@ MHD_RAF_HAS_TRANS_ENC_CHUNKED
@ MHD_RAF_HAS_CONNECTION_HDR
struct MHD_Daemon * MHD_get_master(struct MHD_Daemon *daemon)
ssize_t(* ReceiveCallback)(struct MHD_Connection *conn, void *write_to, size_t max_bytes)
void MHD_unescape_plus(char *arg)
enum MHD_EpollState _MHD_FIXED_FLAGS_ENUM
@ MHD_HTTP_MTHD_NO_METHOD
enum MHD_tristate _MHD_FIXED_ENUM
size_t(* UnescapeCallback)(void *cls, struct MHD_Connection *conn, char *uri)
Types for platform-independent inter-thread communication.
Header for platform-independent locks abstraction.
public interface to libmicrohttpd
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)
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 **con_cls)
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.
enum MHD_HTTP_Method http_mthd
enum MHD_tristate sk_nodelay
size_t write_buffer_send_offset
struct MHD_Connection * prevX
struct MHD_Reply_Properties rp_props
enum MHD_HTTP_Version http_ver
enum MHD_ConnectionEventLoopInfo event_loop_info
size_t write_buffer_append_offset
enum MHD_tristate is_nonip
uint64_t remaining_upload_size
struct MHD_Response * response
struct MHD_Connection * next
enum MHD_ConnKeepAlive keepalive
struct MHD_HTTP_Header * headers_received
size_t continue_message_write_offset
uint64_t response_write_position
struct MHD_HTTP_Header * headers_received_tail
uint64_t current_chunk_offset
size_t read_buffer_offset
struct MHD_Connection * prev
uint64_t current_chunk_size
struct MHD_iovec_track_ resp_iov
unsigned int responseCode
MHD_thread_handle_ID_ pid
struct MHD_Connection * nextX
enum MHD_CONNECTION_STATE state
struct MHD_Daemon * daemon
unsigned int connection_timeout_dummy
uint64_t connection_timeout_ms
enum MHD_tristate sk_corked
MHD_NotifyConnectionCallback notify_connection
MHD_AccessHandlerCallback default_handler
LogCallback uri_log_callback
bool data_already_pending
MHD_mutex_ per_ip_connection_mutex
void * per_ip_connection_count
struct MHD_Connection * new_connections_tail
unsigned int connection_limit
void * unescape_callback_cls
MHD_mutex_ cleanup_connection_mutex
enum MHD_DisableSanityCheck insanity_level
struct MHD_Connection * connections_head
unsigned int listen_backlog_size
MHD_RequestCompletedCallback notify_completed
unsigned int worker_pool_size
int listening_address_reuse
uint64_t connection_timeout_ms
unsigned int per_ip_connection_limit
struct MHD_Connection * manual_timeout_tail
void * notify_connection_cls
UnescapeCallback unescape_callback
void * notify_completed_cls
struct MHD_Connection * cleanup_tail
volatile bool was_quiesced
struct MHD_Daemon * worker_pool
struct MHD_Connection * new_connections_head
MHD_thread_handle_ID_ pid
struct MHD_Connection * manual_timeout_head
enum MHD_tristate listen_is_unix
void * default_handler_cls
struct MHD_Connection * suspended_connections_tail
MHD_AcceptPolicyCallback apc
struct MHD_Connection * cleanup_head
struct MHD_Daemon * master
struct MHD_Connection * normal_timeout_head
struct MHD_Connection * normal_timeout_tail
void * uri_log_callback_cls
struct MHD_Connection * suspended_connections_head
struct MHD_Connection * connections_tail
char nonce[MAX_NONCE_LENGTH]
bool use_reply_body_headers
MHD_ContentReaderFreeCallback crfc
struct MHD_HTTP_Header * first_header
MHD_ContentReaderCallback crc
struct MHD_HTTP_Header * last_header
enum MHD_ResponseAutoFlags flags_auto
enum MHD_ResponseFlags flags
unsigned int reference_count