36 #include <gnutls/gnutls.h>
37 #if GNUTLS_VERSION_MAJOR >= 3
38 #include <gnutls/abstract.h>
58 #define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, msg); \
59 BUILTIN_NOT_REACHED; } while (0)
66 #define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); \
67 BUILTIN_NOT_REACHED; } while (0)
70 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
71 #include "mhd_threads.h"
82 #define _MHD_MACRO_NO 0
88 #define _MHD_MACRO_YES 1
94 #define MHD_fd_close_chk_(fd) do { \
95 if ( (0 != close ((fd)) && (EBADF == errno)) ) \
96 MHD_PANIC (_ ("Failed to close FD.\n")); \
104 #ifndef _MHD_DEBUG_CONNECT
109 #define _MHD_DEBUG_CONNECT _MHD_MACRO_NO
112 #ifndef _MHD_DEBUG_SEND_DATA
116 #define _MHD_DEBUG_SEND_DATA _MHD_MACRO_NO
119 #ifndef _MHD_DEBUG_CLOSE
124 #define _MHD_DEBUG_CLOSE _MHD_MACRO_NO
127 #define MHD_MAX(a,b) (((a)<(b)) ? (b) : (a))
128 #define MHD_MIN(a,b) (((a)<(b)) ? (a) : (b))
138 #define MHD_BUF_INC_SIZE 1024
152 #if defined(__clang__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= \
154 #define BUILTIN_NOT_REACHED __builtin_unreachable ()
155 #elif defined(_MSC_FULL_VER)
156 #define BUILTIN_NOT_REACHED __assume (0)
158 #define BUILTIN_NOT_REACHED
161 #ifndef MHD_STATICSTR_LEN_
165 #define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1)
257 #define MHD_TEST_ALLOW_SUSPEND_RESUME 8192
265 #define MAX_NONCE_LENGTH 129
383 #ifdef UPGRADE_SUPPORT
394 void *upgrade_handler_cls;
397 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
578 #ifdef UPGRADE_SUPPORT
583 MHD_CONNECTION_UPGRADE
609 #define DEBUG_STATES MHD_NO
644 const void *read_from,
740 struct MemoryPool *
pool;
819 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
824 MHD_thread_handle_ID_
pid;
876 #if defined(_MHD_HAVE_SENDFILE)
877 enum MHD_resp_sender_
879 MHD_resp_sender_std = 0,
880 MHD_resp_sender_sendfile
954 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1024 #ifdef UPGRADE_SUPPORT
1031 struct MHD_UpgradeResponseHandle *urh;
1034 #ifdef HTTPS_SUPPORT
1039 gnutls_session_t tls_session;
1080 #ifdef UPGRADE_SUPPORT
1090 #define RESERVE_EBUF_SIZE 8
1098 struct UpgradeEpollHandle
1104 struct MHD_UpgradeResponseHandle *urh;
1136 struct MHD_UpgradeResponseHandle
1145 #ifdef HTTPS_SUPPORT
1149 struct MHD_UpgradeResponseHandle *next;
1154 struct MHD_UpgradeResponseHandle *prev;
1156 #ifdef EPOLL_SUPPORT
1160 struct MHD_UpgradeResponseHandle *nextE;
1165 struct MHD_UpgradeResponseHandle *prevE;
1170 bool in_eready_list;
1192 size_t in_buffer_size;
1199 size_t out_buffer_size;
1208 size_t in_buffer_used;
1217 size_t out_buffer_used;
1222 struct UpgradeEpollHandle app;
1228 struct UpgradeEpollHandle mhd;
1234 char e_buf[RESERVE_EBUF_SIZE];
1248 volatile bool was_closed;
1271 volatile bool clean_ready;
1285 (*LogCallback)(
void *cls,
1372 #ifdef EPOLL_SUPPORT
1395 bool listen_socket_in_epoll;
1397 #ifdef UPGRADE_SUPPORT
1398 #ifdef HTTPS_SUPPORT
1403 int epoll_upgrade_fd;
1409 bool upgrade_fd_in_epoll;
1415 struct MHD_UpgradeResponseHandle *eready_urh_head;
1420 struct MHD_UpgradeResponseHandle *eready_urh_tail;
1527 #ifdef HAVE_MESSAGES
1537 void *custom_error_log_cls;
1553 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1583 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1587 size_t thread_stack_size;
1597 MHD_thread_handle_ID_
pid;
1613 MHD_mutex_ new_connections_mutex;
1638 struct MHD_itc_
itc;
1710 #ifdef HTTPS_SUPPORT
1711 #ifdef UPGRADE_SUPPORT
1717 struct MHD_UpgradeResponseHandle *urh_head;
1724 struct MHD_UpgradeResponseHandle *urh_tail;
1730 gnutls_priority_t priority_cache;
1736 gnutls_credentials_type_t cred_type;
1741 gnutls_certificate_credentials_t x509_cred;
1746 gnutls_dh_params_t dh_params;
1751 gnutls_psk_server_credentials_t psk_cred;
1753 #if GNUTLS_VERSION_MAJOR >= 3
1758 gnutls_certificate_retrieve_function2 *cert_callback;
1768 void *cred_callback_cls;
1771 #if GNUTLS_VERSION_NUMBER >= 0x030603
1776 gnutls_certificate_retrieve_function3 *cert_callback2;
1782 const char *https_mem_key;
1787 const char *https_mem_cert;
1792 const char *https_key_password;
1797 const char *https_mem_trust;
1802 gnutls_dh_params_t https_mem_dhparams;
1811 #ifdef DAUTH_SUPPORT
1816 const char *digest_auth_random;
1823 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1827 MHD_mutex_ nnc_lock;
1833 size_t digest_auth_rand_size;
1838 unsigned int nonce_nc_size;
1846 unsigned int fastopen_queue_size;
1864 #define DLL_insert(head,tail,element) do { \
1865 mhd_assert (NULL == (element)->next); \
1866 mhd_assert (NULL == (element)->prev); \
1867 (element)->next = (head); \
1868 (element)->prev = NULL; \
1869 if ((tail) == NULL) \
1872 (head)->prev = element; \
1873 (head) = (element); } while (0)
1885 #define DLL_remove(head,tail,element) do { \
1886 mhd_assert ( (NULL != (element)->next) || ((element) == (tail))); \
1887 mhd_assert ( (NULL != (element)->prev) || ((element) == (head))); \
1888 if ((element)->prev == NULL) \
1889 (head) = (element)->next; \
1891 (element)->prev->next = (element)->next; \
1892 if ((element)->next == NULL) \
1893 (tail) = (element)->prev; \
1895 (element)->next->prev = (element)->prev; \
1896 (element)->next = NULL; \
1897 (element)->prev = NULL; } while (0)
1908 #define XDLL_insert(head,tail,element) do { \
1909 mhd_assert (NULL == (element)->nextX); \
1910 mhd_assert (NULL == (element)->prevX); \
1911 (element)->nextX = (head); \
1912 (element)->prevX = NULL; \
1913 if (NULL == (tail)) \
1916 (head)->prevX = element; \
1917 (head) = (element); } while (0)
1929 #define XDLL_remove(head,tail,element) do { \
1930 mhd_assert ( (NULL != (element)->nextX) || ((element) == (tail))); \
1931 mhd_assert ( (NULL != (element)->prevX) || ((element) == (head))); \
1932 if (NULL == (element)->prevX) \
1933 (head) = (element)->nextX; \
1935 (element)->prevX->nextX = (element)->nextX; \
1936 if (NULL == (element)->nextX) \
1937 (tail) = (element)->prevX; \
1939 (element)->nextX->prevX = (element)->prevX; \
1940 (element)->nextX = NULL; \
1941 (element)->prevX = NULL; } while (0)
1952 #define EDLL_insert(head,tail,element) do { \
1953 (element)->nextE = (head); \
1954 (element)->prevE = NULL; \
1955 if ((tail) == NULL) \
1958 (head)->prevE = element; \
1959 (head) = (element); } while (0)
1971 #define EDLL_remove(head,tail,element) do { \
1972 if ((element)->prevE == NULL) \
1973 (head) = (element)->nextE; \
1975 (element)->prevE->nextE = (element)->nextE; \
1976 if ((element)->nextE == NULL) \
1977 (tail) = (element)->prevE; \
1979 (element)->nextE->prevE = (element)->prevE; \
1980 (element)->nextE = NULL; \
1981 (element)->prevE = NULL; } while (0)
2034 unsigned int *num_headers);
2071 #define MHD_check_response_header_s_token_ci(r,k,tkn) \
2072 MHD_check_response_header_token_ci ((r),(k),MHD_STATICSTR_LEN_ (k), \
2073 (tkn),MHD_STATICSTR_LEN_ (tkn))
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_CHUNKED_BODY_READY
@ MHD_CONNECTION_FOOTER_PART_RECEIVED
@ MHD_CONNECTION_CONTINUE_SENT
@ MHD_CONNECTION_FOOTERS_SENT
@ MHD_CONNECTION_CHUNKED_BODY_UNREADY
@ MHD_CONNECTION_BODY_SENT
@ MHD_CONNECTION_CONTINUE_SENDING
@ MHD_CONNECTION_URL_RECEIVED
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
void MHD_unescape_plus(char *arg)
void *(* LogCallback)(void *cls, const char *uri, struct MHD_Connection *con)
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_tristate sk_nodelay
size_t write_buffer_send_offset
struct MHD_Connection * prevX
enum MHD_ConnectionEventLoopInfo event_loop_info
size_t write_buffer_append_offset
uint64_t remaining_upload_size
struct MHD_Response * response
struct MHD_Connection * next
enum MHD_ConnKeepAlive keepalive
time_t connection_timeout
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
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
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
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
void * default_handler_cls
struct MHD_Connection * suspended_connections_tail
time_t connection_timeout
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]
MHD_ContentReaderFreeCallback crfc
struct MHD_HTTP_Header * first_header
MHD_ContentReaderCallback crc
enum MHD_ResponseFlags flags
unsigned int reference_count