38 #include <gnutls/gnutls.h> 39 #if GNUTLS_VERSION_MAJOR >= 3 40 #include <gnutls/abstract.h> 48 #ifdef HAVE_INTTYPES_H 59 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 60 #include "mhd_threads.h" 66 #if defined(BAUTH_SUPPORT) || defined(DAUTH_SUPPORT) 77 #define _MHD_DROP_CONST(ptr) ((void *) ((uintptr_t) ((const void *) (ptr)))) 83 #define _MHD_MACRO_NO 0 89 #define _MHD_MACRO_YES 1 95 #define MHD_fd_close_chk_(fd) do { \ 96 if ( (0 != close ((fd)) && (EBADF == errno)) ) { \ 97 MHD_PANIC (_ ("Failed to close FD.\n")); \ 106 #ifndef _MHD_DEBUG_CONNECT 111 #define _MHD_DEBUG_CONNECT _MHD_MACRO_NO 114 #ifndef _MHD_DEBUG_SEND_DATA 118 #define _MHD_DEBUG_SEND_DATA _MHD_MACRO_NO 121 #ifndef _MHD_DEBUG_CLOSE 126 #define _MHD_DEBUG_CLOSE _MHD_MACRO_NO 129 #define MHD_MAX(a,b) (((a)<(b)) ? (b) : (a)) 130 #define MHD_MIN(a,b) (((a)<(b)) ? (a) : (b)) 142 #define MHD_BUF_INC_SIZE 1500 144 #ifndef MHD_STATICSTR_LEN_ 148 #define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1) 249 #define MHD_TEST_ALLOW_SUSPEND_RESUME 8192 257 #define MAX_CLIENT_NONCE_LENGTH 129 266 #if defined(MHD_SHA256_SUPPORT) || defined(MHD_SHA512_256_SUPPORT) 267 #define MAX_DIGEST_NONCE_LENGTH ((32 + 6) * 2) 269 #define MAX_DIGEST_NONCE_LENGTH ((16 + 6) * 2) 415 #if defined(MHD_WINSOCK_SOCKETS) 420 typedef struct _MHD_W32_iovec
422 unsigned long iov_len;
425 #define MHD_IOV_ELMN_MAX_SIZE ULONG_MAX 427 #elif defined(HAVE_SENDMSG) || defined(HAVE_WRITEV) 433 #define MHD_IOV_ELMN_MAX_SIZE SIZE_MAX 441 #define MHD_IOV_ELMN_MAX_SIZE SIZE_MAX 509 #ifdef UPGRADE_SUPPORT 520 void *upgrade_handler_cls;
523 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 743 #ifdef UPGRADE_SUPPORT 775 #define DEBUG_STATES _MHD_MACRO_NO 810 const void *read_from,
881 #define MHD_IS_HTTP_VER_SUPPORTED(ver) (MHD_HTTP_VER_1_0 <= (ver) && \ 882 MHD_HTTP_VER_1_2__1_9 >= (ver)) 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)) 1201 #ifdef BAUTH_SUPPORT 1214 #ifdef DAUTH_SUPPORT 1220 const struct MHD_RqDAuth *dauth;
1258 #if defined(_MHD_HAVE_SENDFILE) 1259 enum MHD_resp_sender_
1261 MHD_resp_sender_std = 0,
1262 MHD_resp_sender_sendfile
1305 #if defined(_MHD_HAVE_SENDFILE) 1306 enum MHD_resp_sender_ resp_sender;
1321 #ifdef EPOLL_SUPPORT 1380 struct MemoryPool *
pool;
1417 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 1537 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 1555 #ifdef EPOLL_SUPPORT 1577 #ifdef UPGRADE_SUPPORT 1584 struct MHD_UpgradeResponseHandle *urh;
1587 #ifdef HTTPS_SUPPORT 1592 gnutls_session_t tls_session;
1630 #ifdef UPGRADE_SUPPORT 1640 #define RESERVE_EBUF_SIZE 8 1648 struct UpgradeEpollHandle
1654 struct MHD_UpgradeResponseHandle *urh;
1686 struct MHD_UpgradeResponseHandle
1695 #ifdef HTTPS_SUPPORT 1699 struct MHD_UpgradeResponseHandle *next;
1704 struct MHD_UpgradeResponseHandle *prev;
1706 #ifdef EPOLL_SUPPORT 1710 struct MHD_UpgradeResponseHandle *nextE;
1715 struct MHD_UpgradeResponseHandle *prevE;
1720 bool in_eready_list;
1742 size_t in_buffer_size;
1749 size_t out_buffer_size;
1758 size_t in_buffer_used;
1767 size_t out_buffer_used;
1772 struct UpgradeEpollHandle app;
1778 struct UpgradeEpollHandle mhd;
1784 char e_buf[RESERVE_EBUF_SIZE];
1798 volatile bool was_closed;
1821 volatile bool clean_ready;
1835 (*LogCallback)(
void *cls,
1927 #ifdef EPOLL_SUPPORT 1950 bool listen_socket_in_epoll;
1952 #ifdef UPGRADE_SUPPORT 1953 #ifdef HTTPS_SUPPORT 1958 int epoll_upgrade_fd;
1964 bool upgrade_fd_in_epoll;
1970 struct MHD_UpgradeResponseHandle *eready_urh_head;
1975 struct MHD_UpgradeResponseHandle *eready_urh_tail;
2082 #ifdef HAVE_MESSAGES 2092 void *custom_error_log_cls;
2113 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 2143 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 2147 size_t thread_stack_size;
2173 MHD_mutex_ new_connections_mutex;
2198 struct MHD_itc_
itc;
2267 #ifdef HAS_FD_SETSIZE_OVERRIDABLE 2280 bool fdset_size_set_by_app;
2288 #ifdef HTTPS_SUPPORT 2289 #ifdef UPGRADE_SUPPORT 2295 struct MHD_UpgradeResponseHandle *urh_head;
2302 struct MHD_UpgradeResponseHandle *urh_tail;
2308 gnutls_priority_t priority_cache;
2314 gnutls_credentials_type_t cred_type;
2319 gnutls_certificate_credentials_t x509_cred;
2324 gnutls_dh_params_t dh_params;
2329 gnutls_psk_server_credentials_t psk_cred;
2331 #if GNUTLS_VERSION_MAJOR >= 3 2336 gnutls_certificate_retrieve_function2 *cert_callback;
2346 void *cred_callback_cls;
2349 #if GNUTLS_VERSION_NUMBER >= 0x030603 2354 gnutls_certificate_retrieve_function3 *cert_callback2;
2360 const char *https_mem_key;
2365 const char *https_mem_cert;
2370 const char *https_key_password;
2375 const char *https_mem_trust;
2380 gnutls_dh_params_t https_mem_dhparams;
2394 #ifdef DAUTH_SUPPORT 2399 const char *digest_auth_random;
2404 size_t digest_auth_rand_size;
2409 void *digest_auth_random_copy;
2416 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 2420 MHD_mutex_ nnc_lock;
2426 unsigned int nonce_nc_size;
2431 unsigned int dauth_bind_type;
2436 unsigned int dauth_def_nonce_timeout;
2441 uint32_t dauth_def_max_nc;
2448 unsigned int fastopen_queue_size;
2462 #ifdef EPOLL_SUPPORT 2484 #if defined(_DEBUG) && defined(HAVE_ACCEPT4) 2498 #if defined(HAVE_POLL) && defined(EPOLL_SUPPORT) 2502 #define MHD_D_IS_USING_SELECT_(d) \ 2503 (0 == (d->options & (MHD_USE_POLL | MHD_USE_EPOLL))) 2507 #define MHD_D_IS_USING_POLL_(d) (0 != ((d)->options & MHD_USE_POLL)) 2511 #define MHD_D_IS_USING_EPOLL_(d) (0 != ((d)->options & MHD_USE_EPOLL)) 2512 #elif defined(HAVE_POLL) 2516 #define MHD_D_IS_USING_SELECT_(d) (0 == ((d)->options & MHD_USE_POLL)) 2520 #define MHD_D_IS_USING_POLL_(d) (0 != ((d)->options & MHD_USE_POLL)) 2524 #define MHD_D_IS_USING_EPOLL_(d) ((void) (d), 0) 2525 #elif defined(EPOLL_SUPPORT) 2529 #define MHD_D_IS_USING_SELECT_(d) (0 == ((d)->options & MHD_USE_EPOLL)) 2533 #define MHD_D_IS_USING_POLL_(d) ((void) (d), 0) 2537 #define MHD_D_IS_USING_EPOLL_(d) (0 != ((d)->options & MHD_USE_EPOLL)) 2542 #define MHD_D_IS_USING_SELECT_(d) ((void) (d), ! 0) 2546 #define MHD_D_IS_USING_POLL_(d) ((void) (d), 0) 2550 #define MHD_D_IS_USING_EPOLL_(d) ((void) (d), 0) 2553 #if defined(MHD_USE_THREADS) 2557 #define MHD_D_IS_USING_THREADS_(d) \ 2558 (0 != (d->options & (MHD_USE_INTERNAL_POLLING_THREAD))) 2562 #define MHD_D_IS_USING_THREAD_PER_CONN_(d) \ 2563 (0 != ((d)->options & MHD_USE_THREAD_PER_CONNECTION)) 2568 #define MHD_D_IS_THREAD_SAFE_(d) \ 2569 (0 == ((d)->options & MHD_USE_NO_THREAD_SAFETY)) 2574 #define MHD_D_IS_USING_THREADS_(d) ((void) d, 0) 2578 #define MHD_D_IS_USING_THREAD_PER_CONN_(d) ((void) d, 0) 2583 #define MHD_D_IS_THREAD_SAFE_(d) ((void) d, 0) 2586 #ifdef HAS_FD_SETSIZE_OVERRIDABLE 2590 #define MHD_D_GET_FD_SETSIZE_(d) ((d)->fdset_size) 2595 #define MHD_D_GET_FD_SETSIZE_(d) (FD_SETSIZE) 2601 #define MHD_D_DOES_SCKT_FIT_FDSET_(sckt,d) \ 2602 MHD_SCKT_FD_FITS_FDSET_SETSIZE_(sckt,NULL,MHD_D_GET_FD_SETSIZE_(d)) 2605 #ifdef DAUTH_SUPPORT 2610 struct MHD_RqDAuthParam
2629 struct MHD_RqDAuthParam nonce;
2630 struct MHD_RqDAuthParam opaque;
2631 struct MHD_RqDAuthParam response;
2632 struct MHD_RqDAuthParam username;
2633 struct MHD_RqDAuthParam username_ext;
2634 struct MHD_RqDAuthParam realm;
2635 struct MHD_RqDAuthParam uri;
2637 struct MHD_RqDAuthParam qop_raw;
2638 struct MHD_RqDAuthParam cnonce;
2639 struct MHD_RqDAuthParam nc;
2658 #define DLL_insert(head,tail,element) do { \ 2659 mhd_assert (NULL == (element)->next); \ 2660 mhd_assert (NULL == (element)->prev); \ 2661 (element)->next = (head); \ 2662 (element)->prev = NULL; \ 2663 if ((tail) == NULL) { \ 2666 (head)->prev = element; \ 2668 (head) = (element); } while (0) 2680 #define DLL_remove(head,tail,element) do { \ 2681 mhd_assert ( (NULL != (element)->next) || ((element) == (tail))); \ 2682 mhd_assert ( (NULL != (element)->prev) || ((element) == (head))); \ 2683 if ((element)->prev == NULL) { \ 2684 (head) = (element)->next; \ 2686 (element)->prev->next = (element)->next; \ 2688 if ((element)->next == NULL) { \ 2689 (tail) = (element)->prev; \ 2691 (element)->next->prev = (element)->prev; \ 2693 (element)->next = NULL; \ 2694 (element)->prev = NULL; } while (0) 2705 #define XDLL_insert(head,tail,element) do { \ 2706 mhd_assert (NULL == (element)->nextX); \ 2707 mhd_assert (NULL == (element)->prevX); \ 2708 (element)->nextX = (head); \ 2709 (element)->prevX = NULL; \ 2710 if (NULL == (tail)) { \ 2713 (head)->prevX = element; \ 2715 (head) = (element); } while (0) 2727 #define XDLL_remove(head,tail,element) do { \ 2728 mhd_assert ( (NULL != (element)->nextX) || ((element) == (tail))); \ 2729 mhd_assert ( (NULL != (element)->prevX) || ((element) == (head))); \ 2730 if (NULL == (element)->prevX) { \ 2731 (head) = (element)->nextX; \ 2733 (element)->prevX->nextX = (element)->nextX; \ 2735 if (NULL == (element)->nextX) { \ 2736 (tail) = (element)->prevX; \ 2738 (element)->nextX->prevX = (element)->prevX; \ 2740 (element)->nextX = NULL; \ 2741 (element)->prevX = NULL; } while (0) 2752 #define EDLL_insert(head,tail,element) do { \ 2753 (element)->nextE = (head); \ 2754 (element)->prevE = NULL; \ 2755 if ((tail) == NULL) { \ 2758 (head)->prevE = element; \ 2760 (head) = (element); } while (0) 2772 #define EDLL_remove(head,tail,element) do { \ 2773 if ((element)->prevE == NULL) { \ 2774 (head) = (element)->nextE; \ 2776 (element)->prevE->nextE = (element)->nextE; \ 2778 if ((element)->nextE == NULL) { \ 2779 (tail) = (element)->prevE; \ 2781 (element)->nextE->prevE = (element)->prevE; \ 2783 (element)->nextE = NULL; \ 2784 (element)->prevE = NULL; } while (0) 2874 #define MHD_check_response_header_s_token_ci(r,k,tkn) \ 2875 MHD_check_response_header_token_ci ((r),(k),MHD_STATICSTR_LEN_ (k), \ 2876 (tkn),MHD_STATICSTR_LEN_ (tkn)) 2914 #ifdef UPGRADE_SUPPORT 2923 MHD_upgraded_connection_mark_app_closed_ (
struct MHD_Connection *connection);
unsigned int per_ip_connection_limit
void * unescape_callback_cls
additional automatic macros for MHD_config.h
bool data_already_pending
int(* MHD_PskServerCredentialsCallback)(void *cls, const struct MHD_Connection *connection, const char *username, void **psk, size_t *psk_size)
union MHD_DaemonInfo daemon_info_dummy_listen_fd
struct MHD_Connection * cleanup_head
enum MHD_CONNECTION_STATE state
Declarations for HTTP authorisation general functions.
public interface to libmicrohttpd
enum MHD_ConnKeepAlive keepalive
ssize_t(* ReceiveCallback)(struct MHD_Connection *conn, void *write_to, size_t max_bytes)
enum MHD_ConnectionEventLoopInfo event_loop_info
struct MHD_Connection * prevX
MHD_ContentReaderFreeCallback crfc
enum MHD_ResponseAutoFlags flags_auto
void(* MHD_ContentReaderFreeCallback)(void *cls)
uint64_t current_chunk_size
size_t skipped_broken_lines
struct MHD_Connection * new_connections_tail
volatile bool was_quiesced
uint64_t rsp_write_position
struct MHD_Connection * manual_timeout_head
void *(* LogCallback)(void *cls, const char *uri, struct MHD_Connection *con)
struct MHD_HTTP_Req_Header * headers_received_tail
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)
struct MHD_HTTP_Res_Header * last_header
MHD_AccessHandlerCallback default_handler
uint64_t current_chunk_offset
union MHD_DaemonInfo daemon_info_dummy_flags
void * uri_log_callback_cls
struct MHD_Daemon * daemon
Types for platform-independent inter-thread communication.
void(* MHD_LogCallback)(void *cls, const char *fm, va_list ap)
int listening_address_reuse
MHD_mutex_ per_ip_connection_mutex
MHD_NotifyConnectionCallback notify_connection
enum MHD_HTTP_Method http_mthd
struct MHD_Connection * next
union MHD_DaemonInfo daemon_info_dummy_port
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)
size_t write_buffer_send_offset
struct sockaddr_storage * addr
struct MHD_Connection * connections_tail
enum MHD_Result(* MHD_AcceptPolicyCallback)(void *cls, const struct sockaddr *addr, socklen_t addrlen)
struct MHD_iovec_track_ resp_iov
struct MHD_Daemon * worker_pool
size_t continue_message_write_offset
bool MHD_parse_arguments_(struct MHD_Request *request, enum MHD_ValueKind kind, char *args, MHD_ArgumentIterator_ cb, unsigned int *num_headers)
struct MHD_HTTP_Req_Header * headers_received
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)
unsigned int connection_limit
size_t num_cr_sp_replaced
unsigned int worker_pool_size
enum MHD_tristate sk_corked
unsigned int skipped_empty_lines
struct MHD_Connection * connections_head
void internal_suspend_connection_(struct MHD_Connection *connection)
LogCallback uri_log_callback
ssize_t(* MHD_ContentReaderCallback)(void *cls, uint64_t pos, char *buf, size_t max)
union MHD_ConnectionInfo connection_info_dummy
unsigned int reference_count
uint64_t remaining_upload_size
void(* MHD_RequestCompletedCallback)(void *cls, struct MHD_Connection *connection, void **req_cls, enum MHD_RequestTerminationCode toe)
ssize_t(* TransmitCallback)(struct MHD_Connection *conn, const void *read_from, size_t max_bytes)
bool use_reply_body_headers
struct MHD_Daemon * master
struct MHD_Connection * manual_timeout_tail
char nonce[MAX_DIGEST_NONCE_LENGTH+1]
struct MHD_Connection * prev
struct MHD_Reply_Properties props
Header for string manipulating helpers types.
struct MHD_Connection * normal_timeout_head
struct MHD_Connection * nextX
UnescapeCallback unescape_callback
unsigned int listen_backlog_size
struct MHD_Connection * suspended_connections_tail
MHD_AcceptPolicyCallback apc
unsigned int responseCode
struct MHD_Connection * cleanup_tail
enum MHD_tristate is_nonip
enum MHD_ResponseFlags flags
#define MAX_DIGEST_NONCE_LENGTH
bool some_payload_processed
size_t write_buffer_append_offset
struct MHD_Connection * normal_timeout_tail
MHD_panic() function and helpers.
enum MHD_tristate listen_is_unix
MHD_RequestCompletedCallback notify_completed
enum MHD_EpollState _MHD_FIXED_FLAGS_ENUM
union MHD_HeadersProcessing hdrs
void * notify_completed_cls
bool(* MHD_ArgumentIterator_)(struct MHD_Request *request, const char *key, const char *value, enum MHD_ValueKind kind)
enum MHD_tristate sk_nodelay
uint64_t connection_timeout_ms
size_t(* UnescapeCallback)(void *cls, struct MHD_Connection *conn, char *uri)
void * notify_connection_cls
Header for platform-independent locks abstraction.
uint64_t connection_timeout_ms
MHD_ContentReaderCallback crc
_MHD_static_inline struct MHD_Daemon * MHD_get_master(struct MHD_Daemon *const daemon)
enum MHD_HTTP_Version http_ver
union MHD_DaemonInfo daemon_info_dummy_num_connections
MHD_ConnectionEventLoopInfo
struct MHD_Connection * suspended_connections_head
void * per_ip_connection_count
size_t read_buffer_offset
void * default_handler_cls
struct MHD_HTTP_Res_Header * first_header
MHD_mutex_ cleanup_connection_mutex
struct MHD_Connection * new_connections_head
void(* MHD_NotifyConnectionCallback)(void *cls, struct MHD_Connection *connection, void **socket_context, enum MHD_ConnectionNotificationCode toe)
union MHD_StartOrSize field_lines
struct MHD_Response * response
struct MHD_IoVec MHD_iovec_
MHD_FLAG
Flags for the struct MHD_Daemon.
void MHD_unescape_plus(char *arg)
enum MHD_tristate _MHD_FIXED_ENUM
enum MHD_DisableSanityCheck insanity_level