30#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
40#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
50#ifdef MHD_USE_SYS_TSEARCH
58#ifdef MHD_HTTPS_REQUIRE_GCRYPT
63#if defined(_WIN32) && ! defined(__CYGWIN__)
64#ifndef WIN32_LEAN_AND_MEAN
65#define WIN32_LEAN_AND_MEAN 1
70#ifdef MHD_USE_POSIX_THREADS
79#ifdef MHD_POSIX_SOCKETS
80#define MHD_MAX_CONNECTIONS_DEFAULT (FD_SETSIZE - 3 - 1 - MHD_ITC_NUM_FDS_)
82#define MHD_MAX_CONNECTIONS_DEFAULT (FD_SETSIZE - 2)
88#define MHD_POOL_SIZE_DEFAULT (32 * 1024)
134#ifdef _AUTOINIT_FUNCS_ARE_SUPPORTED
139#define MHD_check_global_init_() (void) 0
146#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
147#ifdef MHD_MUTEX_STATIC_DEFN_INIT_
151MHD_MUTEX_STATIC_DEFN_INIT_ (global_init_mutex_);
163#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
164#ifdef MHD_MUTEX_STATIC_DEFN_INIT_
170#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
171#ifdef MHD_MUTEX_STATIC_DEFN_INIT_
185MHD_default_logger_ (
void *cls,
189 vfprintf ((FILE *) cls, fm, ap);
191 fflush ((FILE *) cls);
242 struct in6_addr ipv6;
262#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
279#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
302 offsetof (
struct MHD_IPCount,
318 struct MHD_IPCount *key)
325 if (
sizeof (
struct sockaddr_in) <= (
size_t) addrlen)
327 if (AF_INET == addr->ss_family)
329 key->family = AF_INET;
330 memcpy (&key->addr.ipv4,
331 &((
const struct sockaddr_in *) addr)->sin_addr,
332 sizeof(((
const struct sockaddr_in *)
NULL)->sin_addr));
338 if (
sizeof (
struct sockaddr_in6) <= (
size_t) addrlen)
341 if (AF_INET6 == addr->ss_family)
343 key->family = AF_INET6;
344 memcpy (&key->addr.ipv6,
345 &((
const struct sockaddr_in6 *) addr)->sin6_addr,
346 sizeof(((
const struct sockaddr_in6 *)
NULL)->sin6_addr));
370 const struct sockaddr_storage *addr,
373 struct MHD_IPCount *newkeyp;
374 struct MHD_IPCount *keyp;
375 struct MHD_IPCount **nodep;
383 newkeyp = (
struct MHD_IPCount *) malloc (
sizeof(
struct MHD_IPCount));
399 nodep = (
struct MHD_IPCount **)
tsearch (newkeyp,
408 _ (
"Failed to add IP connection count node.\n"));
438 const struct sockaddr_storage *addr,
441 struct MHD_IPCount search_key;
442 struct MHD_IPCount *found_key;
464 MHD_PANIC (
_ (
"Failed to find previously-added IP address.\n"));
466 found_key = (
struct MHD_IPCount *) *nodep;
468 if (0 == found_key->count)
470 MHD_PANIC (
_ (
"Previously-added IP address had counter of zero.\n"));
473 if (0 == --found_key->count)
494MHD_init_daemon_certificate (
struct MHD_Daemon *daemon)
500#if GNUTLS_VERSION_MAJOR >= 3
501 if (
NULL != daemon->cert_callback)
503 gnutls_certificate_set_retrieve_function2 (daemon->x509_cred,
504 daemon->cert_callback);
507#if GNUTLS_VERSION_NUMBER >= 0x030603
508 else if (
NULL != daemon->cert_callback2)
510 gnutls_certificate_set_retrieve_function3 (daemon->x509_cred,
511 daemon->cert_callback2);
515 if (
NULL != daemon->https_mem_trust)
518 paramlen = strlen (daemon->https_mem_trust);
523 _ (
"Too long trust certificate.\n"));
527 cert.data = (
unsigned char *)
_MHD_DROP_CONST (daemon->https_mem_trust);
528 cert.size = (
unsigned int) paramlen;
529 if (gnutls_certificate_set_x509_trust_mem (daemon->x509_cred,
531 GNUTLS_X509_FMT_PEM) < 0)
535 _ (
"Bad trust certificate format.\n"));
541 if (daemon->have_dhparams)
543 gnutls_certificate_set_dh_params (daemon->x509_cred,
544 daemon->https_mem_dhparams);
547 if ( (
NULL != daemon->https_mem_cert) &&
548 (
NULL != daemon->https_mem_key) )
553 param1len = strlen (daemon->https_mem_key);
554 param2len = strlen (daemon->https_mem_cert);
560 _ (
"Too long key or certificate.\n"));
565 key.size = (
unsigned int) param1len;
566 cert.data = (
unsigned char *)
_MHD_DROP_CONST (daemon->https_mem_cert);
567 cert.size = (
unsigned int) param2len;
569 if (
NULL != daemon->https_key_password)
571#if GNUTLS_VERSION_NUMBER >= 0x030111
572 ret = gnutls_certificate_set_x509_key_mem2 (daemon->x509_cred,
576 daemon->https_key_password,
581 _ (
"Failed to setup x509 certificate/key: pre 3.X.X version " \
582 "of GnuTLS does not support setting key password.\n"));
588 ret = gnutls_certificate_set_x509_key_mem (daemon->x509_cred,
591 GNUTLS_X509_FMT_PEM);
595 _ (
"GnuTLS failed to setup x509 certificate/key: %s\n"),
596 gnutls_strerror (ret));
600#if GNUTLS_VERSION_MAJOR >= 3
601 if (
NULL != daemon->cert_callback)
604#if GNUTLS_VERSION_NUMBER >= 0x030603
605 else if (
NULL != daemon->cert_callback2)
610 _ (
"You need to specify a certificate and key location.\n"));
625 switch (daemon->cred_type)
627 case GNUTLS_CRD_CERTIFICATE:
629 gnutls_certificate_allocate_credentials (&daemon->x509_cred))
630 return GNUTLS_E_MEMORY_ERROR;
631 return MHD_init_daemon_certificate (daemon);
634 gnutls_psk_allocate_server_credentials (&daemon->psk_cred))
635 return GNUTLS_E_MEMORY_ERROR;
637 case GNUTLS_CRD_ANON:
643 _ (
"Error: invalid credentials type %d specified.\n"),
665tls_cleanup_failed_start (
struct MHD_Daemon *daemon)
667 if (daemon->have_dhparams)
669 gnutls_dh_params_deinit (daemon->https_mem_dhparams);
670 daemon->have_dhparams =
false;
672 if (
NULL != daemon->priority_cache)
674 gnutls_priority_deinit (daemon->priority_cache);
675 daemon->priority_cache =
NULL;
677 if (
NULL != daemon->x509_cred)
679 gnutls_certificate_free_credentials (daemon->x509_cred);
680 daemon->x509_cred =
NULL;
682 if (
NULL != daemon->psk_cred)
684 gnutls_psk_free_server_credentials (daemon->psk_cred);
685 daemon->psk_cred =
NULL;
729 fd_set *write_fd_set,
730 fd_set *except_fd_set,
738#ifdef HAS_FD_SETSIZE_OVERRIDABLE
739 daemon->fdset_size_set_by_app ?
740 ((
unsigned int) daemon->fdset_size) :
749#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
763urh_to_fdset (
struct MHD_UpgradeResponseHandle *urh,
770 const MHD_socket conn_sckt = urh->connection->socket_fd;
774#ifndef HAS_FD_SETSIZE_OVERRIDABLE
776 fd_setsize = (int) FD_SETSIZE;
783 if ( (urh->in_buffer_used < urh->in_buffer_size) &&
789 if ( (0 != urh->out_buffer_used) &&
798 ((0 != urh->in_buffer_size) ||
799 (0 != urh->out_buffer_size) ||
800 (0 != urh->out_buffer_used))
809 if ( (urh->out_buffer_used < urh->out_buffer_size) &&
815 if ( (0 != urh->in_buffer_used) &&
824 ((0 != urh->out_buffer_size) ||
825 (0 != urh->in_buffer_size) ||
826 (0 != urh->in_buffer_used))
849urh_from_fdset (
struct MHD_UpgradeResponseHandle *urh,
855 const MHD_socket conn_sckt = urh->connection->socket_fd;
866#ifndef HAS_FD_SETSIZE_OVERRIDABLE
868 mhd_assert (((
int) FD_SETSIZE) <= fd_setsize);
869 fd_setsize = FD_SETSIZE;
922urh_update_pollfd (
struct MHD_UpgradeResponseHandle *urh,
928 if (urh->in_buffer_used < urh->in_buffer_size)
929 p[0].events |= POLLIN;
930 if (0 != urh->out_buffer_used)
931 p[0].events |= POLLOUT;
936 ((0 != urh->in_buffer_size) ||
937 (0 != urh->out_buffer_size) ||
938 (0 != urh->out_buffer_used)))
939 p[0].events |= MHD_POLL_EVENTS_ERR_DISC;
941 if (urh->out_buffer_used < urh->out_buffer_size)
942 p[1].events |= POLLIN;
943 if (0 != urh->in_buffer_used)
944 p[1].events |= POLLOUT;
949 ((0 != urh->out_buffer_size) ||
950 (0 != urh->in_buffer_size) ||
951 (0 != urh->in_buffer_used)))
952 p[1].events |= MHD_POLL_EVENTS_ERR_DISC;
963urh_to_pollfd (
struct MHD_UpgradeResponseHandle *urh,
966 p[0].fd = urh->connection->socket_fd;
967 p[1].fd = urh->mhd.socket;
968 urh_update_pollfd (urh,
979urh_from_pollfd (
struct MHD_UpgradeResponseHandle *urh,
988 if (0 != (p[0].revents & POLLIN))
990 if (0 != (p[0].revents & POLLOUT))
992 if (0 != (p[0].revents & POLLHUP))
994 if (0 != (p[0].revents & MHD_POLL_REVENTS_ERRROR))
996 if (0 != (p[1].revents & POLLIN))
998 if (0 != (p[1].revents & POLLOUT))
1000 if (0 != (p[1].revents & POLLHUP))
1002 if (0 != (p[1].revents & MHD_POLL_REVENTS_ERRROR))
1027 fd_set *read_fd_set,
1028 fd_set *write_fd_set,
1029 fd_set *except_fd_set,
1039#ifndef HAS_FD_SETSIZE_OVERRIDABLE
1041 fd_setsize = (int) FD_SETSIZE;
1096#ifdef MHD_POSIX_SOCKETS
1097 if (
NULL != except_fd_set)
1110#ifdef MHD_POSIX_SOCKETS
1111 if (
NULL != except_fd_set)
1119 if ( (
NULL == except_fd_set) ||
1131#ifdef MHD_WINSOCK_SOCKETS
1135 if (
NULL != except_fd_set)
1147#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
1150 struct MHD_UpgradeResponseHandle *urh;
1152 for (urh = daemon->urh_tail;
NULL != urh; urh = urh->prev)
1180#if _MHD_DEBUG_CONNECT
1184 _ (
"Maximum socket in select set: %d\n"),
1228 fd_set *read_fd_set,
1229 fd_set *write_fd_set,
1230 fd_set *except_fd_set,
1232 unsigned int fd_setsize)
1234 if ( (
NULL == daemon) ||
1235 (
NULL == read_fd_set) ||
1236 (
NULL == write_fd_set) ||
1242 if (
NULL == except_fd_set)
1245 _ (
"MHD_get_fdset2() called with except_fd_set "
1246 "set to NULL. Such behavior is unsupported.\n"));
1250#ifdef HAS_FD_SETSIZE_OVERRIDABLE
1251 if (0 == fd_setsize)
1253 else if (((
unsigned int)
INT_MAX) < fd_setsize)
1254 fd_setsize = (
unsigned int)
INT_MAX;
1256 else if (daemon->fdset_size > ((
int) fd_setsize))
1258 if (daemon->fdset_size_set_by_app)
1261 _ (
"%s() called with fd_setsize (%u) " \
1262 "less than value set by MHD_OPTION_APP_FD_SETSIZE (%d). " \
1263 "Some socket FDs may be not processed. " \
1264 "Use MHD_OPTION_APP_FD_SETSIZE with the correct value.\n"),
1265 "MHD_get_fdset2", fd_setsize, daemon->fdset_size);
1270 _ (
"%s() called with fd_setsize (%u) " \
1271 "less than FD_SETSIZE used by MHD (%d). " \
1272 "Some socket FDs may be not processed. " \
1273 "Consider using MHD_OPTION_APP_FD_SETSIZE option.\n"),
1274 "MHD_get_fdset2", fd_setsize, daemon->fdset_size);
1279 if (((
unsigned int) FD_SETSIZE) > fd_setsize)
1283 _ (
"%s() called with fd_setsize (%u) " \
1284 "less than fixed FD_SETSIZE value (%d) used on the " \
1286 "MHD_get_fdset2", fd_setsize, (
int) FD_SETSIZE);
1290 fd_setsize = (int) FD_SETSIZE;
1338 bool states_info_processed =
false;
1351 if (con->tls_read_ready)
1355 (read_ready || (force_close && con->
sk_nonblck)) )
1381 states_info_processed =
true;
1392 states_info_processed =
true;
1402 if (! states_info_processed)
1450 else if ( (con->tls_read_ready) &&
1459#ifdef UPGRADE_SUPPORT
1470 struct MHD_UpgradeResponseHandle *urh = connection->urh;
1478 gnutls_bye (connection->tls_session,
1487 connection->urh =
NULL;
1495#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
1505process_urh (
struct MHD_UpgradeResponseHandle *urh)
1518#ifdef MHD_USE_THREADS
1529 if (! urh->was_closed)
1532 _ (
"Initiated daemon shutdown while \"upgraded\" " \
1533 "connection was not closed.\n"));
1536 urh->was_closed =
true;
1538 was_closed = urh->was_closed;
1543 if (0 < urh->in_buffer_used)
1547 _ (
"Failed to forward to application %" PRIu64 \
1548 " bytes of data received from remote side: " \
1549 "application closed data forwarding.\n"),
1550 (uint64_t) urh->in_buffer_used);
1555 urh->in_buffer_used = 0;
1559 urh->in_buffer_size = 0;
1561 connection->tls_read_ready =
false;
1576 & urh->app.celi)) ||
1577 (connection->tls_read_ready)) &&
1578 (urh->in_buffer_used < urh->in_buffer_size))
1583 buf_size = urh->in_buffer_size - urh->in_buffer_used;
1587 res = gnutls_record_recv (connection->tls_session,
1588 &urh->in_buffer[urh->in_buffer_used],
1592 connection->tls_read_ready =
false;
1593 if (GNUTLS_E_INTERRUPTED != res)
1596 if ((GNUTLS_E_AGAIN != res) ||
1603 urh->in_buffer_size = 0;
1609 urh->in_buffer_used += (size_t) res;
1610 connection->tls_read_ready =
1611 (0 < gnutls_record_check_pending (connection->tls_session));
1626 && (urh->out_buffer_used < urh->out_buffer_size))
1631 buf_size = urh->out_buffer_size - urh->out_buffer_used;
1636 &urh->out_buffer[urh->out_buffer_used],
1656 urh->out_buffer_size = 0;
1662 urh->out_buffer_used += (size_t) res;
1663 if (buf_size > (
size_t) res)
1672 (urh->out_buffer_used > 0) )
1677 data_size = urh->out_buffer_used;
1681 res = gnutls_record_send (connection->tls_session,
1686 if (GNUTLS_E_INTERRUPTED != res)
1689 if (GNUTLS_E_AGAIN != res)
1695 _ (
"Failed to forward to remote client %" PRIu64 \
1696 " bytes of data received from application: %s\n"),
1697 (uint64_t) urh->out_buffer_used,
1698 gnutls_strerror ((
int) res));
1701 urh->out_buffer_used = 0;
1703 urh->out_buffer_size = 0;
1710 const size_t next_out_buffer_used = urh->out_buffer_used - (size_t) res;
1711 if (0 != next_out_buffer_used)
1713 memmove (urh->out_buffer,
1714 &urh->out_buffer[res],
1715 next_out_buffer_used);
1717 urh->out_buffer_used = next_out_buffer_used;
1719 if ( (0 == urh->out_buffer_used) &&
1727 urh->out_buffer_size = 0;
1736 (urh->in_buffer_used > 0) )
1741 data_size = urh->in_buffer_used;
1761 _ (
"Failed to forward to application %" PRIu64 \
1762 " bytes of data received from remote side: %s\n"),
1763 (uint64_t) urh->in_buffer_used,
1767 urh->in_buffer_used = 0;
1769 urh->in_buffer_size = 0;
1771 connection->tls_read_ready =
false;
1777 const size_t next_in_buffer_used = urh->in_buffer_used - (size_t) res;
1778 if (0 != next_in_buffer_used)
1780 memmove (urh->in_buffer,
1781 &urh->in_buffer[res],
1782 next_in_buffer_used);
1783 if (data_size > (
size_t) res)
1786 urh->in_buffer_used = next_in_buffer_used;
1788 if ( (0 == urh->in_buffer_used) &&
1794 urh->in_buffer_size = 0;
1796 connection->tls_read_ready =
false;
1802 if ( (connection->tls_read_ready) &&
1803 (urh->in_buffer_used < urh->in_buffer_size) &&
1808 ( (0 != urh->out_buffer_size) ||
1809 (0 != urh->out_buffer_used) ) )
1813 if (0 < urh->out_buffer_used)
1815 _ (
"Failed to forward to remote client %" PRIu64 \
1816 " bytes of data received from application: daemon shut down.\n"),
1817 (uint64_t) urh->out_buffer_used);
1820 urh->out_buffer_used = 0;
1824 urh->out_buffer_size = 0;
1828 if (! was_closed && urh->was_closed)
1835#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1836#ifdef UPGRADE_SUPPORT
1849 struct MHD_UpgradeResponseHandle *urh = con->urh;
1860 while ( (0 != urh->in_buffer_size) ||
1861 (0 != urh->out_buffer_size) ||
1862 (0 != urh->in_buffer_used) ||
1863 (0 != urh->out_buffer_used) )
1877 result = urh_to_fdset (urh,
1887 _ (
"Error preparing select.\n"));
1894 struct timeval *tvp;
1896 if (((con->tls_read_ready) &&
1897 (urh->in_buffer_used < urh->in_buffer_size)) ||
1922 _ (
"Error during select (%d): `%s'\n"),
1928 urh_from_fdset (urh,
1944 p[0].fd = urh->connection->socket_fd;
1945 p[1].fd = urh->mhd.socket;
1947 while ( (0 != urh->in_buffer_size) ||
1948 (0 != urh->out_buffer_size) ||
1949 (0 != urh->in_buffer_used) ||
1950 (0 != urh->out_buffer_used) )
1954 urh_update_pollfd (urh, p);
1956 if (((con->tls_read_ready) &&
1957 (urh->in_buffer_used < urh->in_buffer_size)) ||
1963 if (MHD_sys_poll_ (p,
1973 _ (
"Error during poll: `%s'\n"),
1978 urh_from_pollfd (urh,
2010 uint64_t mseconds_left;
2015 if (timeout < since_actv)
2022 if (5000 >= jump_back)
2030 else if (since_actv == timeout)
2039 mseconds_left = timeout - since_actv;
2041 return mseconds_left;
2052static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_
2053thread_main_handle_connection (
void *
data)
2064 unsigned int extra_slot;
2066#define EXTRA_SLOTS 1
2068#define EXTRA_SLOTS 0
2071 struct pollfd p[1 + EXTRA_SLOTS];
2077 const bool use_poll = 0;
2079 bool was_suspended =
false;
2085 bool use_zero_timeout;
2086#ifdef UPGRADE_SUPPORT
2087 struct MHD_UpgradeResponseHandle *
const urh = con->urh;
2089 static const void *
const urh =
NULL;
2096 was_suspended =
true;
2105 #ifdef HAVE_MESSAGES
2107 _ (
"Failed to add FD to fd_set.\n"));
2123 _ (
"Error during select (%d): `%s'\n"),
2133 p[0].events = POLLIN;
2134 p[0].fd = MHD_itc_r_fd_ (daemon->
itc);
2136 if (0 > MHD_sys_poll_ (p,
2144 _ (
"Error during poll: `%s'\n"),
2151 MHD_itc_clear_ (daemon->
itc);
2160 was_suspended =
false;
2166 || ( (con->tls_read_ready) &&
2173 bool err_state =
false;
2175 struct timeval *tvp;
2176 if (use_zero_timeout)
2184 const uint64_t mseconds_left = connection_get_wait (con);
2185#if (SIZEOF_UINT64_T - 2) >= SIZEOF_STRUCT_TIMEVAL_TV_SEC
2192 tv.tv_usec = ((uint16_t) (mseconds_left % 1000)) * ((int32_t) 1000);
2231 if (MHD_ITC_IS_VALID_ (daemon->
itc) )
2244 _ (
"Failed to add FD to fd_set.\n"));
2262 _ (
"Error during select (%d): `%s'\n"),
2271 if ( (MHD_ITC_IS_VALID_ (daemon->
itc)) &&
2272 (FD_ISSET (MHD_itc_r_fd_ (daemon->
itc),
2274 MHD_itc_clear_ (daemon->
itc);
2291 if (use_zero_timeout)
2295 const uint64_t mseconds_left = connection_get_wait (con);
2296#if SIZEOF_UINT64_T >= SIZEOF_INT
2301 timeout_val = (int) mseconds_left;
2313 p[0].events |= POLLIN | MHD_POLL_EVENTS_ERR_DISC;
2316 p[0].events |= POLLOUT | MHD_POLL_EVENTS_ERR_DISC;
2319 p[0].events |= MHD_POLL_EVENTS_ERR_DISC;
2327 if (MHD_ITC_IS_VALID_ (daemon->
itc))
2329 p[1].events |= POLLIN;
2330 p[1].fd = MHD_itc_r_fd_ (daemon->
itc);
2335 if (MHD_sys_poll_ (p,
2347 _ (
"Error during poll: `%s'\n"),
2355 if ( (MHD_ITC_IS_VALID_ (daemon->
itc)) &&
2356 (0 != (p[1].revents & (POLLERR | POLLHUP | POLLIN))) )
2357 MHD_itc_clear_ (daemon->
itc);
2361 (0 != (p[0].revents & POLLIN)),
2362 (0 != (p[0].revents & POLLOUT)),
2363 (0 != (p[0].revents & MHD_POLL_REVENTS_ERR_DISC)) ))
2367#ifdef UPGRADE_SUPPORT
2368 if (MHD_CONNECTION_UPGRADE == con->
state)
2380 thread_main_connection_upgrade (con);
2384 con->urh->clean_ready =
true;
2392 return (MHD_THRD_RTRN_TYPE_) 0;
2399 _ (
"Processing thread terminating. Closing connection.\n"));
2423 if ( (MHD_ITC_IS_VALID_ (daemon->
itc)) &&
2424 (! MHD_itc_activate_ (daemon->
itc,
"t")) )
2428 _ (
"Failed to signal thread termination via inter-thread " \
2429 "communication channel.\n"));
2432 return (MHD_THRD_RTRN_TYPE_) 0;
2449#if defined(HTTPS_SUPPORT)
2450#if defined(MHD_SEND_SPIPE_SUPPRESS_NEEDED) && \
2451 defined(MHD_SEND_SPIPE_SUPPRESS_POSSIBLE) && \
2452 ! defined(MHD_socket_nosignal_) && \
2453 (GNUTLS_VERSION_NUMBER + 0 < 0x030402) && defined(MSG_NOSIGNAL)
2459#define MHD_TLSLIB_NEED_PUSH_FUNC 1
2465#ifdef MHD_TLSLIB_NEED_PUSH_FUNC
2471MHD_tls_push_func_ (gnutls_transport_ptr_t trnsp,
2475#if (MHD_SCKT_SEND_MAX_SIZE_ < SSIZE_MAX) || (0 == SSIZE_MAX)
2494#define MHD_PSK_MIN_SIZE 16
2505psk_gnutls_adapter (gnutls_session_t session,
2506 const char *username,
2507 gnutls_datum_t *key)
2511#if GNUTLS_VERSION_MAJOR >= 3
2513 size_t app_psk_size;
2516 connection = gnutls_session_get_ptr (session);
2517 if (
NULL == connection)
2521 MHD_PANIC (
_ (
"Internal server error. This should be impossible.\n"));
2525 daemon = connection->
daemon;
2526#if GNUTLS_VERSION_MAJOR >= 3
2527 if (
NULL == daemon->cred_callback)
2531 _ (
"PSK not supported by this server.\n"));
2535 if (0 != daemon->cred_callback (daemon->cred_callback_cls,
2541 if (MHD_PSK_MIN_SIZE > app_psk_size)
2545 _ (
"PSK authentication failed: PSK too short.\n"));
2554 _ (
"PSK authentication failed: PSK too long.\n"));
2562 if (
NULL == (key->data = gnutls_malloc (app_psk_size)))
2566 _ (
"PSK authentication failed: gnutls_malloc failed to " \
2567 "allocate memory.\n"));
2572 key->size = (
unsigned int) app_psk_size;
2579 (void) username; (void) key;
2582 _ (
"PSK not supported by this server.\n"));
2617 const struct sockaddr_storage *
addr,
2621 bool sk_spipe_supprs,
2628#if _MHD_DEBUG_CONNECT
2630 _ (
"Accepted connection on socket %d.\n"),
2642 _ (
"Server reached connection limit. " \
2643 "Closing inbound connection.\n"));
2646#if defined(ENFILE) && (ENFILE + 0 != 0)
2655 (
const struct sockaddr *)
addr,
2661 _ (
"Connection rejected by application. Closing connection.\n"));
2668#if defined(EACCESS) && (EACCESS + 0 != 0)
2679 _ (
"Error allocating memory: %s\n"),
2703 if (
NULL == (connection->
addr = malloc ((
size_t) addrlen)))
2708 _ (
"Error allocating memory: %s\n"),
2719 memcpy (connection->
addr,
2728 connection->
is_nonip = sk_is_nonip;
2730#ifdef MHD_USE_THREADS
2747#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030500)
2754 flags = GNUTLS_SERVER;
2755#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030402)
2756 flags |= GNUTLS_NO_SIGNAL;
2758#if GNUTLS_VERSION_MAJOR >= 3
2759 flags |= GNUTLS_NONBLOCK;
2761#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030603)
2763 flags |= GNUTLS_POST_HANDSHAKE_AUTH;
2765#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030605)
2767 flags |= GNUTLS_ENABLE_EARLY_DATA;
2771 if ((GNUTLS_E_SUCCESS != gnutls_init (&connection->tls_session, flags)) ||
2772 (GNUTLS_E_SUCCESS != gnutls_priority_set (connection->tls_session,
2773 daemon->priority_cache)))
2775 if (
NULL != connection->tls_session)
2776 gnutls_deinit (connection->tls_session);
2782 free (connection->
addr);
2786 _ (
"Failed to initialise TLS session.\n"));
2788#if defined(EPROTO) && (EPROTO + 0 != 0)
2793#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030200)
2794 if (!
daemon->disable_alpn)
2796 static const char prt1[] =
"http/1.1";
2797 static const char prt2[] =
"http/1.0";
2798 static const gnutls_datum_t prts[2] =
2802 if (GNUTLS_E_SUCCESS !=
2803 gnutls_alpn_set_protocols (connection->tls_session,
2805 sizeof(prts) /
sizeof(prts[0]),
2810 _ (
"Failed to set ALPN protocols.\n"));
2817 gnutls_session_set_ptr (connection->tls_session,
2819 switch (
daemon->cred_type)
2822 case GNUTLS_CRD_CERTIFICATE:
2823 gnutls_credentials_set (connection->tls_session,
2824 GNUTLS_CRD_CERTIFICATE,
2827 case GNUTLS_CRD_PSK:
2828 gnutls_credentials_set (connection->tls_session,
2831 gnutls_psk_set_server_credentials_function (
daemon->psk_cred,
2832 &psk_gnutls_adapter);
2834 case GNUTLS_CRD_ANON:
2835 case GNUTLS_CRD_SRP:
2840 _ (
"Failed to setup TLS credentials: " \
2841 "unknown credential type %d.\n"),
2844 gnutls_deinit (connection->tls_session);
2850 free (connection->
addr);
2852 MHD_PANIC (
_ (
"Unknown credential type.\n"));
2853#if defined(EINVAL) && (EINVAL + 0 != 0)
2858#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030109) && ! defined(_WIN64)
2859 gnutls_transport_set_int (connection->tls_session,
2860 (
int) (client_socket));
2862 gnutls_transport_set_ptr (connection->tls_session,
2863 (gnutls_transport_ptr_t) \
2864 (intptr_t) client_socket);
2866#ifdef MHD_TLSLIB_NEED_PUSH_FUNC
2867 gnutls_transport_set_push_function (connection->tls_session,
2868 MHD_tls_push_func_);
2870 if (
daemon->https_mem_trust)
2871 gnutls_certificate_server_set_request (connection->tls_session,
2872 GNUTLS_CERT_REQUEST);
2878 free (connection->
addr);
2880 MHD_PANIC (
_ (
"TLS connection on non-TLS daemon.\n"));
2893#ifdef MHD_USE_THREADS
2912 if (
NULL != connection->tls_session)
2915 gnutls_deinit (connection->tls_session);
2923 free (connection->
addr);
2949#ifdef MHD_USE_THREADS
2966 _ (
"Error allocating memory: %s\n"),
2969#if defined(ENOMEM) && (ENOMEM + 0 != 0)
2983 _ (
"Server reached connection limit. "
2984 "Closing inbound connection.\n"));
2986#if defined(ENFILE) && (ENFILE + 0 != 0)
3012#ifdef MHD_USE_THREADS
3018 daemon->thread_stack_size,
3019 &thread_main_handle_connection,
3027 _ (
"Failed to create a new thread because it would "
3028 "have exceeded the system limit on the number of "
3029 "threads or no system resources available.\n"));
3033 _ (
"Failed to create a thread: %s\n"),
3045#ifdef MHD_USE_THREADS
3046 connection->tid =
daemon->tid;
3053 struct epoll_event event;
3055 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET | EPOLLRDHUP;
3056 event.data.ptr = connection;
3057 if (0 != epoll_ctl (daemon->epoll_fd,
3065 _ (
"Call to epoll_ctl failed: %s\n"),
3082 daemon->eready_tail,
3116 if (
NULL != connection->tls_session)
3117 gnutls_deinit (connection->tls_session);
3123 free (connection->
addr);
3167 const struct sockaddr_storage *addr,
3171 bool sk_spipe_supprs,
3176#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3186 _ (
"New connection socket descriptor (%d) is not less " \
3187 "than FD_SETSIZE (%d).\n"),
3188 (
int) client_socket,
3192#if defined(ENFILE) && (ENFILE + 0 != 0)
3203 _ (
"Epoll mode supports only non-blocking sockets\n"));
3206#if defined(EINVAL) && (EINVAL + 0 != 0)
3219 if (
NULL == connection)
3222 if ((external_add) &&
3235 if ((MHD_ITC_IS_VALID_ (
daemon->
itc)) &&
3236 (! MHD_itc_activate_ (
daemon->
itc,
"n")))
3240 _ (
"Failed to signal new connection via inter-thread " \
3241 "communication channel.\n"));
3285 _ (
"Failed to start serving new connection.\n"));
3289 }
while (
NULL != local_tail);
3309#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3319#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3349 daemon->eready_tail,
3351 connection->epoll_state &=
3356 if (0 != epoll_ctl (daemon->epoll_fd,
3360 MHD_PANIC (
_ (
"Failed to remove FD from epoll set.\n"));
3361 connection->epoll_state &=
3367#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3406#ifdef MHD_USE_THREADS
3413 MHD_PANIC (
_ (
"Cannot suspend connections without " \
3414 "enabling MHD_ALLOW_SUSPEND_RESUME!\n"));
3415#ifdef UPGRADE_SUPPORT
3416 if (
NULL != connection->urh)
3420 _ (
"Error: connection scheduled for \"upgrade\" cannot " \
3421 "be suspended.\n"));
3448#if defined(MHD_USE_THREADS)
3453 MHD_PANIC (
_ (
"Cannot resume connections without enabling " \
3454 "MHD_ALLOW_SUSPEND_RESUME!\n"));
3455#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3460#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3463 if ( (MHD_ITC_IS_VALID_ (daemon->
itc)) &&
3464 (! MHD_itc_activate_ (daemon->
itc,
"r")) )
3468 _ (
"Failed to signal resume via inter-thread " \
3469 "communication channel.\n"));
3475#ifdef UPGRADE_SUPPORT
3484MHD_upgraded_connection_mark_app_closed_ (
struct MHD_Connection *connection)
3488#if defined(MHD_USE_THREADS)
3495 connection->urh->was_closed =
true;
3499 if ( (MHD_ITC_IS_VALID_ (daemon->
itc)) &&
3500 (! MHD_itc_activate_ (daemon->
itc,
"r")) )
3504 _ (
"Failed to signal resume via " \
3505 "inter-thread communication channel.\n"));
3530#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3537#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3553#ifdef UPGRADE_SUPPORT
3554 struct MHD_UpgradeResponseHandle *
const urh = pos->urh;
3556 static const void *
const urh =
NULL;
3560#ifdef UPGRADE_SUPPORT
3561 || ( (
NULL != urh) &&
3562 ( (! urh->was_closed) ||
3563 (! urh->clean_ready) ) )
3597 MHD_PANIC (
"Resumed connection was already in EREADY set.\n");
3601 daemon->eready_tail,
3610#ifdef UPGRADE_SUPPORT
3634#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3637 if ( (used_thr_p_c) &&
3640 if (! MHD_itc_activate_ (daemon->
itc,
3645 _ (
"Failed to signal resume of connection via " \
3646 "inter-thread communication channel.\n"));
3684 const struct sockaddr *addr,
3688 bool sk_spipe_supprs;
3689 struct sockaddr_storage addrstorage;
3701 _ (
"MHD_add_connection() has been called for daemon started"
3702 " without MHD_USE_ITC flag.\nDaemon will not process newly"
3703 " added connection until any activity occurs in already"
3704 " added sockets.\n"));
3709 if (AF_INET == addr->sa_family)
3711 if (
sizeof(
struct sockaddr_in) > (
size_t) addrlen)
3715 _ (
"MHD_add_connection() has been called with "
3716 "incorrect 'addrlen' value.\n"));
3720#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
3721 if ((0 != addr->sa_len) &&
3722 (
sizeof(
struct sockaddr_in) > (
size_t) addr->sa_len) )
3726 _ (
"MHD_add_connection() has been called with " \
3727 "non-zero value of 'sa_len' member of " \
3728 "'struct sockaddr' which does not match 'sa_family'.\n"));
3735 if (AF_INET6 == addr->sa_family)
3737 if (
sizeof(
struct sockaddr_in6) > (
size_t) addrlen)
3741 _ (
"MHD_add_connection() has been called with "
3742 "incorrect 'addrlen' value.\n"));
3746#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
3747 if ((0 != addr->sa_len) &&
3748 (
sizeof(
struct sockaddr_in6) > (
size_t) addr->sa_len) )
3752 _ (
"MHD_add_connection() has been called with " \
3753 "non-zero value of 'sa_len' member of " \
3754 "'struct sockaddr' which does not match 'sa_family'.\n"));
3760#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
3761 if ((0 != addr->sa_len) &&
3762 (addrlen > addr->sa_len))
3763 addrlen = (socklen_t) addr->sa_len;
3772 _ (
"Failed to set nonblocking mode on new client socket: %s\n"),
3780#ifndef MHD_WINSOCK_SOCKETS
3781 sk_spipe_supprs =
false;
3783 sk_spipe_supprs =
true;
3785#if defined(MHD_socket_nosignal_)
3786 if (! sk_spipe_supprs)
3787 sk_spipe_supprs = MHD_socket_nosignal_ (client_socket);
3788 if (! sk_spipe_supprs)
3792 _ (
"Failed to suppress SIGPIPE on new client socket: %s\n"),
3816 _ (
"Failed to set noninheritable mode on new client socket.\n"));
3822 memcpy (&addrstorage, addr, (
size_t) addrlen);
3823#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
3824 addrstorage.ss_len = addrlen;
3827#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3828 if (
NULL != daemon->worker_pool)
3834 for (i = 0; i < daemon->worker_pool_size; ++i)
3837 &daemon->worker_pool[(i + (
unsigned int) client_socket)
3838 % daemon->worker_pool_size];
3851#if defined(ENFILE) && (ENFILE + 0 != 0)
3886 struct sockaddr_storage addrstorage;
3891 bool sk_spipe_supprs;
3894#if defined(_DEBUG) && defined (USE_ACCEPT4)
3895 const bool use_accept4 = ! daemon->avoid_accept4;
3896#elif defined (USE_ACCEPT4)
3897 static const bool use_accept4 =
true;
3899 static const bool use_accept4 =
false;
3902#ifdef MHD_USE_THREADS
3912 addrlen = (socklen_t)
sizeof (addrstorage);
3913 memset (&addrstorage,
3916#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
3917 addrstorage.ss_len = addrlen;
3922 sk_spipe_supprs =
false;
3930 (
struct sockaddr *) &addrstorage,
3936#ifndef MHD_WINSOCK_SOCKETS
3939 sk_spipe_supprs =
true;
3944#if defined(_DEBUG) || ! defined(USE_ACCEPT4)
3945 if (! use_accept4 &&
3948 (
struct sockaddr *) &addrstorage,
3951#ifdef MHD_ACCEPT_INHERIT_NONBLOCK
3956#ifndef MHD_WINSOCK_SOCKETS
3957 sk_spipe_supprs =
false;
3959 sk_spipe_supprs =
true;
3978 _ (
"Error accepting connection: %s\n"),
3991 _ (
"Hit process or system resource limit at FIRST " \
3992 "connection. This is really bad as there is no sane " \
3993 "way to proceed. Will try busy waiting for system " \
3994 "resources to become magically available.\n"));
3999#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
4003#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
4008 _ (
"Hit process or system resource limit at %u " \
4009 "connections, temporarily suspending accept(). " \
4010 "Consider setting a lower MHD_OPTION_CONNECTION_LIMIT.\n"),
4024 _ (
"Accepted socket has zero-length address. "
4025 "Processing the new socket as a socket with " \
4026 "unknown type.\n"));
4031 if (((socklen_t)
sizeof (addrstorage)) < addrlen)
4037 _ (
"Accepted socket address is larger than expected by " \
4038 "system headers. Processing the new socket as a socket with " \
4039 "unknown type.\n"));
4049 _ (
"Failed to set nonblocking mode on incoming connection " \
4063 _ (
"Failed to set noninheritable mode on incoming connection " \
4070#if defined(MHD_socket_nosignal_)
4071 if (! sk_spipe_supprs && ! MHD_socket_nosignal_ (s))
4075 _ (
"Failed to suppress SIGPIPE on incoming connection " \
4092 sk_spipe_supprs =
true;
4095#if _MHD_DEBUG_CONNECT
4097 _ (
"Accepted connection on socket %d\n"),
4126#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
4138#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
4141 (! pos->thread_joined) &&
4143 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
4145#ifdef UPGRADE_SUPPORT
4146 cleanup_upgraded_connection (pos);
4150 if (
NULL != pos->tls_session)
4151 gnutls_deinit (pos->tls_session);
4174 if ( (-1 !=
daemon->epoll_fd) &&
4183 if (0 != epoll_ctl (
daemon->epoll_fd,
4187 MHD_PANIC (
_ (
"Failed to remove FD from epoll set.\n"));
4205#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
4211#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
4259#if SIZEOF_UINT64_T > SIZEOF_UNSIGNED_LONG_LONG
4307 uint64_t *timeout64)
4309 uint64_t earliest_deadline;
4314#ifdef MHD_USE_THREADS
4323 _ (
"Illegal call to MHD_get_timeout.\n"));
4331#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
4335#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
4351#
if defined(UPGRADE_SUPPORT) && defined(HTTPS_SUPPORT)
4362 earliest_tmot_conn =
NULL;
4363 earliest_deadline = 0;
4366 if ( (
NULL != pos) &&
4369 earliest_tmot_conn = pos;
4379 if ( (
NULL == earliest_tmot_conn) ||
4380 (earliest_deadline >
4383 earliest_tmot_conn = pos;
4389 if (
NULL != earliest_tmot_conn)
4391 *timeout64 = connection_get_wait (earliest_tmot_conn);
4398#if defined(HAVE_POLL) || defined(EPOLL_SUPPORT)
4446 return (int64_t) utimeout;
4492#if SIZEOF_INT >= SIZEOF_INT64_T
4515 int32_t max_timeout)
4518 mhd_assert (0 <= max_timeout || -1 == max_timeout);
4519 if (0 == max_timeout)
4525 if ((0 < max_timeout) && ((uint64_t) max_timeout < d_timeout))
4531 return (int64_t) d_timeout;
4548 int32_t max_timeout)
4552 res = get_timeout_millisec_ (
daemon, max_timeout);
4553#if SIZEOF_INT < SIZEOF_INT64_T
4576 const fd_set *read_fd_set,
4577 const fd_set *write_fd_set,
4578 const fd_set *except_fd_set,
4582#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4583 struct MHD_UpgradeResponseHandle *urh;
4584 struct MHD_UpgradeResponseHandle *urhn;
4596#ifndef HAS_FD_SETSIZE_OVERRIDABLE
4598 mhd_assert (((
int) FD_SETSIZE) <= fd_setsize);
4599 fd_setsize = FD_SETSIZE;
4605 if (MHD_ITC_IS_VALID_ (daemon->
itc))
4607 bool need_to_clear_itc =
true;
4610 need_to_clear_itc = FD_ISSET (MHD_itc_r_fd_ (daemon->
itc), \
4612 if (need_to_clear_itc)
4613 MHD_itc_clear_ (daemon->
itc);
4629 bool need_to_accept;
4631 need_to_accept = FD_ISSET (ds,
4660 r_ready = FD_ISSET (cs,
4662 w_ready = FD_ISSET (cs,
4664 has_err = (
NULL != except_fd_set) &&
4681#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4683 for (urh =
daemon->urh_tail;
NULL != urh; urh = urhn)
4687 urh_from_fdset (urh,
4695 if ( (0 == urh->in_buffer_size) &&
4696 (0 == urh->out_buffer_size) &&
4697 (0 == urh->in_buffer_used) &&
4698 (0 == urh->out_buffer_used) )
4701 urh->clean_ready =
true;
4712#undef MHD_run_from_select
4747 const fd_set *read_fd_set,
4748 const fd_set *write_fd_set,
4749 const fd_set *except_fd_set,
4750 unsigned int fd_setsize)
4755 if ((
NULL == read_fd_set) || (
NULL == write_fd_set))
4758 if (
NULL == except_fd_set)
4761 _ (
"MHD_run_from_select() called with except_fd_set "
4762 "set to NULL. Such behavior is deprecated.\n"));
4766#ifdef HAS_FD_SETSIZE_OVERRIDABLE
4767 if (0 == fd_setsize)
4769 else if (((
unsigned int)
INT_MAX) < fd_setsize)
4770 fd_setsize = (
unsigned int)
INT_MAX;
4772 else if (
daemon->fdset_size > ((
int) fd_setsize))
4774 if (
daemon->fdset_size_set_by_app)
4777 _ (
"%s() called with fd_setsize (%u) " \
4778 "less than value set by MHD_OPTION_APP_FD_SETSIZE (%d). " \
4779 "Some socket FDs may be not processed. " \
4780 "Use MHD_OPTION_APP_FD_SETSIZE with the correct value.\n"),
4781 "MHD_run_from_select2", fd_setsize,
daemon->fdset_size);
4786 _ (
"%s() called with fd_setsize (%u) " \
4787 "less than FD_SETSIZE used by MHD (%d). " \
4788 "Some socket FDs may be not processed. " \
4789 "Consider using MHD_OPTION_APP_FD_SETSIZE option.\n"),
4790 "MHD_run_from_select2", fd_setsize,
daemon->fdset_size);
4795 if (((
unsigned int) FD_SETSIZE) > fd_setsize)
4799 _ (
"%s() called with fd_setsize (%u) " \
4800 "less than fixed FD_SETSIZE value (%d) used on the " \
4802 "MHD_run_from_select2", fd_setsize, (
int) FD_SETSIZE);
4861 const fd_set *read_fd_set,
4862 const fd_set *write_fd_set,
4863 const fd_set *except_fd_set)
4869#ifdef HAS_FD_SETSIZE_OVERRIDABLE
4870 daemon->fdset_size_set_by_app ?
4871 ((
unsigned int)
daemon->fdset_size) :
4899 struct timeval timeout;
4905 timeout.tv_usec = 0;
4931 _ (
"Could not obtain daemon fdsets.\n"));
4941 if (MHD_ITC_IS_VALID_ (daemon->
itc))
4950 MHD_DLOG (daemon,
_ (
"Could not add control inter-thread " \
4951 "communication channel FD to fdset.\n"));
4976 _ (
"Could not add listen socket to fdset.\n"));
4988 timeout.tv_usec = 0;
4995 uint64_t select_tmo;
5000 if ( (0 < millisec) &&
5001 (mhd_tmo > (uint64_t) millisec) )
5002 select_tmo = (uint64_t) millisec;
5004 select_tmo = mhd_tmo;
5007 else if (0 < millisec)
5009 select_tmo = (uint64_t) millisec;
5020#if (SIZEOF_UINT64_T - 2) >= SIZEOF_STRUCT_TIMEVAL_TV_SEC
5027 timeout.tv_usec = ((uint16_t) (select_tmo % 1000)) * ((int32_t) 1000);
5044 _ (
"select failed: %s\n"),
5074 unsigned int num_connections;
5077#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5078 struct MHD_UpgradeResponseHandle *urh;
5079 struct MHD_UpgradeResponseHandle *urhn;
5094 num_connections = 0;
5097#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5098 for (urh = daemon->urh_head;
NULL != urh; urh = urh->next)
5099 num_connections += 2;
5104 unsigned int poll_server;
5111 sizeof (
struct pollfd));
5116 _ (
"Error allocating memory: %s\n"),
5129 p[poll_server].fd = ls;
5130 p[poll_server].events = POLLIN;
5131 p[poll_server].revents = 0;
5132 poll_listen = (int) poll_server;
5136 if (MHD_ITC_IS_VALID_ (daemon->
itc))
5138 p[poll_server].fd = MHD_itc_r_fd_ (daemon->
itc);
5139 p[poll_server].events = POLLIN;
5140 p[poll_server].revents = 0;
5141 poll_itc_idx = (int) poll_server;
5145 timeout = get_timeout_millisec_int (daemon, millisec);
5155 p[poll_server + i].events |= POLLIN | MHD_POLL_EVENTS_ERR_DISC;
5158 p[poll_server + i].events |= POLLOUT | MHD_POLL_EVENTS_ERR_DISC;
5161 p[poll_server + i].events |= MHD_POLL_EVENTS_ERR_DISC;
5169#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5170 for (urh = daemon->urh_tail;
NULL != urh; urh = urh->prev)
5172 urh_to_pollfd (urh, &(p[poll_server + i]));
5176 if (0 == poll_server + num_connections)
5181 if (MHD_sys_poll_ (p,
5182 poll_server + num_connections,
5193 _ (
"poll failed: %s\n"),
5203 if ( (-1 != poll_itc_idx) &&
5204 (0 != (p[poll_itc_idx].revents & POLLIN)) )
5205 MHD_itc_clear_ (daemon->
itc);
5219 if ( (-1 != poll_listen) &&
5220 (0 != (p[poll_listen].revents & POLLIN)) )
5228 while (
NULL != (pos = prev))
5232 if (i >= num_connections)
5237 0 != (p[poll_server + i].revents & POLLIN),
5238 0 != (p[poll_server + i].revents & POLLOUT),
5239 0 != (p[poll_server + i].revents
5240 & MHD_POLL_REVENTS_ERR_DISC));
5243#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5244 for (urh = daemon->urh_tail;
NULL != urh; urh = urhn)
5246 if (i >= num_connections)
5253 if ((p[poll_server + i].
fd != urh->connection->socket_fd) ||
5254 (p[poll_server + i + 1].fd != urh->mhd.socket))
5256 urh_from_pollfd (urh,
5257 &p[poll_server + i]);
5261 if ( (0 == urh->in_buffer_size) &&
5262 (0 == urh->out_buffer_size) &&
5263 (0 == urh->in_buffer_used) &&
5264 (0 == urh->out_buffer_used) )
5269 urh->clean_ready =
true;
5293MHD_poll_listen_socket (
struct MHD_Daemon *daemon,
5298 unsigned int poll_count;
5316 p[poll_count].fd = ls;
5317 p[poll_count].events = POLLIN;
5318 p[poll_count].revents = 0;
5319 poll_listen = (int) poll_count;
5322 if (MHD_ITC_IS_VALID_ (daemon->
itc))
5324 p[poll_count].fd = MHD_itc_r_fd_ (daemon->
itc);
5325 p[poll_count].events = POLLIN;
5326 p[poll_count].revents = 0;
5327 poll_itc_idx = (int) poll_count;
5338 if (0 == poll_count)
5340 if (MHD_sys_poll_ (p,
5350 _ (
"poll failed: %s\n"),
5355 if ( (0 <= poll_itc_idx) &&
5356 (0 != (p[poll_itc_idx].revents & POLLIN)) )
5357 MHD_itc_clear_ (daemon->
itc);
5367 if ( (0 <= poll_listen) &&
5368 (0 != (p[poll_listen].revents & POLLIN)) )
5390 return MHD_poll_all (daemon,
5391 may_block ? -1 : 0);
5392 return MHD_poll_listen_socket (daemon,
5410#define MAX_EVENTS 128
5413#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5423is_urh_ready (
struct MHD_UpgradeResponseHandle *
const urh)
5427 if ( (0 == urh->in_buffer_size) &&
5428 (0 == urh->out_buffer_size) &&
5429 (0 == urh->in_buffer_used) &&
5430 (0 == urh->out_buffer_used) )
5435 & urh->app.celi)) ||
5436 (connection->tls_read_ready) ) &&
5437 (urh->in_buffer_used < urh->in_buffer_size) )
5440 & urh->mhd.celi)) ||
5442 (urh->out_buffer_used < urh->out_buffer_size) )
5445 (urh->out_buffer_used > 0) )
5448 (urh->in_buffer_used > 0) )
5465 struct epoll_event events[MAX_EVENTS];
5467 struct MHD_UpgradeResponseHandle *pos;
5468 struct MHD_UpgradeResponseHandle *prev;
5470#ifdef MHD_USE_THREADS
5475 num_events = MAX_EVENTS;
5476 while (0 != num_events)
5480 num_events = epoll_wait (daemon->epoll_upgrade_fd,
5484 if (-1 == num_events)
5492 _ (
"Call to epoll_wait failed: %s\n"),
5497 for (i = 0; i < (
unsigned int) num_events; i++)
5499 struct UpgradeEpollHandle *
const ueh = events[i].data.ptr;
5500 struct MHD_UpgradeResponseHandle *
const urh = ueh->urh;
5501 bool new_err_state =
false;
5503 if (urh->clean_ready)
5507 if (0 != (events[i].events & EPOLLIN))
5511 if (0 != (events[i].events & EPOLLOUT))
5515 if (0 != (events[i].events & EPOLLHUP))
5521 (0 != (events[i].events & (EPOLLERR | EPOLLPRI))) )
5526 new_err_state =
true;
5528 if (! urh->in_eready_list)
5530 if (new_err_state ||
5534 daemon->eready_urh_tail,
5536 urh->in_eready_list =
true;
5541 prev = daemon->eready_urh_tail;
5542 while (
NULL != (pos = prev))
5546 if (! is_urh_ready (pos))
5549 daemon->eready_urh_tail,
5551 pos->in_eready_list =
false;
5554 if ( (0 == pos->in_buffer_size) &&
5555 (0 == pos->out_buffer_size) &&
5556 (0 == pos->in_buffer_used) &&
5557 (0 == pos->out_buffer_used) )
5560 pos->clean_ready =
true;
5579static const char *
const epoll_itc_marker =
"itc_marker";
5595#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5596 static const char *
const upgrade_marker =
"upgrade_ptr";
5600 struct epoll_event events[MAX_EVENTS];
5601 struct epoll_event event;
5606#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5607 bool run_upgraded =
false;
5609 bool need_to_accept;
5618 if (-1 == daemon->epoll_fd)
5626#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5632 (! daemon->listen_socket_in_epoll) &&
5635 event.events = EPOLLIN | EPOLLRDHUP;
5636 event.data.ptr = daemon;
5637 if (0 != epoll_ctl (daemon->epoll_fd,
5642#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5647 _ (
"Call to epoll_ctl failed: %s\n"),
5652 daemon->listen_socket_in_epoll =
true;
5655 (daemon->listen_socket_in_epoll) )
5657 if (0 != epoll_ctl (daemon->epoll_fd,
5661 MHD_PANIC (
"Failed to remove listen FD from epoll set.\n");
5662 daemon->listen_socket_in_epoll =
false;
5664#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5668#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5669 if ( ( (! daemon->upgrade_fd_in_epoll) &&
5670 (-1 != daemon->epoll_upgrade_fd) ) )
5672 event.events = EPOLLIN | EPOLLOUT | EPOLLRDHUP;
5674 if (0 != epoll_ctl (daemon->epoll_fd,
5676 daemon->epoll_upgrade_fd,
5681 _ (
"Call to epoll_ctl failed: %s\n"),
5686 daemon->upgrade_fd_in_epoll =
true;
5689#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5692 if ( (daemon->listen_socket_in_epoll) &&
5699 if (0 != epoll_ctl (daemon->epoll_fd,
5703 MHD_PANIC (
_ (
"Failed to remove listen FD from epoll set.\n"));
5704 daemon->listen_socket_in_epoll =
false;
5706#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5714 timeout_ms = get_timeout_millisec_int (daemon,
5722 need_to_accept =
false;
5727 num_events = MAX_EVENTS;
5728 while (MAX_EVENTS == num_events)
5731 num_events = epoll_wait (daemon->epoll_fd,
5735 if (-1 == num_events)
5742 _ (
"Call to epoll_wait failed: %s\n"),
5747 for (i = 0; i < (
unsigned int) num_events; i++)
5753#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5754 if (upgrade_marker == events[i].
data.ptr)
5758 run_upgraded =
true;
5762 if (epoll_itc_marker == events[i].
data.ptr)
5766 MHD_itc_clear_ (daemon->
itc);
5769 if (daemon == events[i].
data.ptr)
5773 if (0 == (events[i].events & (EPOLLERR | EPOLLHUP)))
5774 need_to_accept =
true;
5780 pos = events[i].data.ptr;
5782 if (0 != (events[i].events & (EPOLLPRI | EPOLLERR | EPOLLHUP)))
5788 daemon->eready_tail,
5795 if (0 != (events[i].events & EPOLLIN))
5803 daemon->eready_tail,
5808 if (0 != (events[i].events & EPOLLOUT))
5815 daemon->eready_tail,
5830 unsigned int series_length = 0;
5837 (series_length < 10) &&
5852 while (
NULL != (pos = prev))
5862 while (
NULL != (pos = prev))
5870#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5871 if (run_upgraded || (
NULL != daemon->eready_urh_head))
5872 run_epoll_for_upgrade (daemon);
5876 prev = daemon->eready_tail;
5877 while (
NULL != (pos = prev))
5895 daemon->eready_tail,
6003 res = MHD_poll_all (daemon, millisec);
6011 res = MHD_epoll (daemon, millisec);
6019#ifdef HAS_FD_SETSIZE_OVERRIDABLE
6021 if (daemon->fdset_size_set_by_app
6022 && (((
int) FD_SETSIZE) < daemon->fdset_size))
6025 _ (
"MHD_run()/MHD_run_wait() called for daemon started with " \
6026 "MHD_OPTION_APP_FD_SETSIZE option (%d). " \
6027 "The library was compiled with smaller FD_SETSIZE (%d). " \
6028 "Some socket FDs may be not processed. " \
6029 "Use MHD_run_from_select2() instead of MHD_run() or " \
6030 "do not use MHD_OPTION_APP_FD_SETSIZE option.\n"),
6031 daemon->fdset_size, (
int) FD_SETSIZE);
6056#ifdef MHD_USE_THREADS
6069#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6089#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6095#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6103static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_
6104MHD_polling_thread (
void *cls)
6107#ifdef HAVE_PTHREAD_SIGMASK
6113#ifdef HAVE_PTHREAD_SIGMASK
6114 if ((0 == sigemptyset (&s_mask)) &&
6115 (0 == sigaddset (&s_mask, SIGPIPE)))
6117 err = pthread_sigmask (SIG_BLOCK, &s_mask,
NULL);
6126 _ (
"Failed to block SIGPIPE on daemon thread: %s\n"),
6139 MHD_epoll (daemon, -1);
6153 return (MHD_THRD_RTRN_TYPE_) 0;
6188 MHD_DLOG (connection->
daemon,
6189 _ (
"The URL encoding is broken.\n"));
6264#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6278 _ (
"Using MHD_quiesce_daemon in this mode " \
6279 "requires MHD_USE_ITC.\n"));
6284#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6285 if (
NULL != daemon->worker_pool)
6286 for (i = 0; i < daemon->worker_pool_size; i++)
6293#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6299 (-1 != daemon->worker_pool[i].epoll_fd) &&
6300 (daemon->worker_pool[i].listen_socket_in_epoll) )
6302 if (0 != epoll_ctl (daemon->worker_pool[i].epoll_fd,
6306 MHD_PANIC (
_ (
"Failed to remove listen FD from epoll set.\n"));
6307 daemon->worker_pool[i].listen_socket_in_epoll =
false;
6311 if (MHD_ITC_IS_VALID_ (daemon->worker_pool[i].
itc))
6313 if (! MHD_itc_activate_ (daemon->worker_pool[i].
itc,
"q"))
6314 MHD_PANIC (
_ (
"Failed to signal quiesce via inter-thread " \
6315 "communication channel.\n"));
6317#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6322#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6328 (-1 != daemon->epoll_fd) &&
6329 (daemon->listen_socket_in_epoll) )
6331 if (0 != epoll_ctl (daemon->epoll_fd,
6335 MHD_PANIC (
"Failed to remove listen FD from epoll set.\n");
6336 daemon->listen_socket_in_epoll =
false;
6339#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6342 if ( (MHD_ITC_IS_VALID_ (daemon->
itc)) &&
6343 (! MHD_itc_activate_ (daemon->
itc,
"q")) )
6344 MHD_PANIC (
_ (
"failed to signal quiesce via inter-thread " \
6345 "communication channel.\n"));
6355struct MHD_InterimParams_
6368 bool fdset_size_set;
6384 bool pserver_addr_set;
6388 const struct sockaddr *pserver_addr;
6392 bool server_addr_len_set;
6396 socklen_t server_addr_len;
6423 struct MHD_InterimParams_ *params,
6438 struct MHD_InterimParams_ *params,
6444 va_start (ap, params);
6457enum MHD_TlsPrioritiesBaseType
6459 MHD_TLS_PRIO_BASE_LIBMHD = 0,
6460 MHD_TLS_PRIO_BASE_SYSTEM = 1,
6461#if GNUTLS_VERSION_NUMBER >= 0x030300
6462 MHD_TLS_PRIO_BASE_DEFAULT,
6464 MHD_TLS_PRIO_BASE_NORMAL
6470#if GNUTLS_VERSION_NUMBER >= 0x030300
6482daemon_tls_priorities_init_default (
struct MHD_Daemon *daemon)
6489 mhd_assert (MHD_TLS_PRIO_BASE_NORMAL + 1 == \
6490 sizeof(MHD_TlsBasePriotities) /
sizeof(MHD_TlsBasePriotities[0]));
6492 res = GNUTLS_E_SUCCESS;
6495 p <
sizeof(MHD_TlsBasePriotities) /
sizeof(MHD_TlsBasePriotities[0]);
6498 res = gnutls_priority_init (&daemon->priority_cache,
6499 MHD_TlsBasePriotities[p].str,
NULL);
6500 if (GNUTLS_E_SUCCESS == res)
6504 switch ((
enum MHD_TlsPrioritiesBaseType) p)
6506 case MHD_TLS_PRIO_BASE_LIBMHD:
6508 _ (
"GnuTLS priorities have been initialised with " \
6509 "@LIBMICROHTTPD application-specific system-wide " \
6510 "configuration.\n") );
6512 case MHD_TLS_PRIO_BASE_SYSTEM:
6514 _ (
"GnuTLS priorities have been initialised with " \
6515 "@SYSTEM system-wide configuration.\n") );
6517#if GNUTLS_VERSION_NUMBER >= 0x030300
6518 case MHD_TLS_PRIO_BASE_DEFAULT:
6520 _ (
"GnuTLS priorities have been initialised with " \
6521 "GnuTLS default configuration.\n") );
6524 case MHD_TLS_PRIO_BASE_NORMAL:
6526 _ (
"GnuTLS priorities have been initialised with " \
6527 "NORMAL configuration.\n") );
6539 _ (
"Failed to set GnuTLS priorities. Last error: %s\n"),
6540 gnutls_strerror (res));
6556daemon_tls_priorities_init_append_inner_ (
struct MHD_Daemon *daemon,
6560 const size_t buf_size)
6564 const char *err_pos;
6569 mhd_assert (MHD_TLS_PRIO_BASE_NORMAL + 1 == \
6570 sizeof(MHD_TlsBasePriotities) /
sizeof(MHD_TlsBasePriotities[0]));
6572 res = GNUTLS_E_SUCCESS;
6575 p <
sizeof(MHD_TlsBasePriotities) /
sizeof(MHD_TlsBasePriotities[0]);
6579#if GNUTLS_VERSION_NUMBER >= 0x030300
6580#if GNUTLS_VERSION_NUMBER >= 0x030603
6581 if (
NULL == MHD_TlsBasePriotities[p].
str)
6582 res = gnutls_priority_init2 (&daemon->priority_cache, prio, &err_pos,
6583 GNUTLS_PRIORITY_INIT_DEF_APPEND);
6587 if (
NULL == MHD_TlsBasePriotities[p].
str)
6598 memcpy (buf + buf_pos, MHD_TlsBasePriotities[p].
str,
6599 MHD_TlsBasePriotities[p].
len);
6600 buf_pos += MHD_TlsBasePriotities[p].
len;
6601 buf[buf_pos++] =
':';
6602 memcpy (buf + buf_pos, prio, prio_len + 1);
6604 buf_pos += prio_len + 1;
6607 res = gnutls_priority_init (&daemon->priority_cache, buf, &err_pos);
6609 if (GNUTLS_E_SUCCESS == res)
6613 switch ((
enum MHD_TlsPrioritiesBaseType) p)
6615 case MHD_TLS_PRIO_BASE_LIBMHD:
6617 _ (
"GnuTLS priorities have been initialised with " \
6618 "priorities specified by application appended to " \
6619 "@LIBMICROHTTPD application-specific system-wide " \
6620 "configuration.\n") );
6622 case MHD_TLS_PRIO_BASE_SYSTEM:
6624 _ (
"GnuTLS priorities have been initialised with " \
6625 "priorities specified by application appended to " \
6626 "@SYSTEM system-wide configuration.\n") );
6628#if GNUTLS_VERSION_NUMBER >= 0x030300
6629 case MHD_TLS_PRIO_BASE_DEFAULT:
6631 _ (
"GnuTLS priorities have been initialised with " \
6632 "priorities specified by application appended to " \
6633 "GnuTLS default configuration.\n") );
6636 case MHD_TLS_PRIO_BASE_NORMAL:
6638 _ (
"GnuTLS priorities have been initialised with " \
6639 "priorities specified by application appended to " \
6640 "NORMAL configuration.\n") );
6652 _ (
"Failed to set GnuTLS priorities. Last error: %s. " \
6653 "The problematic part starts at: %s\n"),
6654 gnutls_strerror (res), err_pos);
6660#define LOCAL_BUFF_SIZE 128
6671daemon_tls_priorities_init_append (
struct MHD_Daemon *daemon,
const char *prio)
6676 size_t buf_size_needed;
6679 return daemon_tls_priorities_init_default (daemon);
6684 prio_len = strlen (prio);
6686 buf_size_needed = longest_base_prio + 1 + prio_len + 1;
6688 if (LOCAL_BUFF_SIZE >= buf_size_needed)
6690 char local_buffer[LOCAL_BUFF_SIZE];
6691 ret = daemon_tls_priorities_init_append_inner_ (daemon, prio, prio_len,
6697 char *allocated_buffer;
6698 allocated_buffer = (
char *) malloc (buf_size_needed);
6699 if (
NULL == allocated_buffer)
6703 _ (
"Error allocating memory: %s\n"),
6708 ret = daemon_tls_priorities_init_append_inner_ (daemon, prio, prio_len,
6711 free (allocated_buffer);
6730 struct MHD_InterimParams_ *params,
6739#if GNUTLS_VERSION_MAJOR >= 3
6740 gnutls_certificate_retrieve_function2 * pgcrf;
6742#if GNUTLS_VERSION_NUMBER >= 0x030603
6743 gnutls_certificate_retrieve_function3 * pgcrf2;
6768 _ (
"Warning: specified " \
6769 "MHD_OPTION_CONNECTION_MEMORY_LIMIT " \
6770 "value is too small and rounded up to 64.\n"));
6794 _ (
"Warning: specified " \
6795 "MHD_OPTION_CONNECTION_MEMORY_INCREMENT value is " \
6796 "too large and rounded down to 1/4 of " \
6797 "MHD_OPTION_CONNECTION_MEMORY_LIMIT.\n"));
6811#if (SIZEOF_UINT64_T - 2) <= SIZEOF_UNSIGNED_INT
6816 _ (
"The specified connection timeout (%u) is too large. " \
6817 "Maximum allowed value (%" PRIu64 ") will be used " \
6844 params->server_addr_len = va_arg (ap,
6846 params->server_addr_len_set =
true;
6847 params->pserver_addr = va_arg (ap,
6848 const struct sockaddr *);
6849 params->pserver_addr_set =
true;
6852 params->server_addr_len_set =
false;
6853 params->pserver_addr = va_arg (ap,
6854 const struct sockaddr *);
6855 params->pserver_addr_set =
true;
6868#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6870 daemon->worker_pool_size = va_arg (ap,
6872 if (0 == daemon->worker_pool_size)
6876 else if (1 == daemon->worker_pool_size)
6880 _ (
"Warning: value \"1\", specified as the thread pool " \
6881 "size, is ignored. Thread pool is not used.\n"));
6883 daemon->worker_pool_size = 0;
6885#if SIZEOF_UNSIGNED_INT >= (SIZEOF_SIZE_T - 2)
6889 else if (daemon->worker_pool_size >=
6894 _ (
"Specified thread pool size (%u) too big.\n"),
6895 daemon->worker_pool_size);
6906 _ (
"MHD_OPTION_THREAD_POOL_SIZE option is specified but "
6907 "MHD_USE_INTERNAL_POLLING_THREAD flag is not specified.\n"));
6915 _ (
"Both MHD_OPTION_THREAD_POOL_SIZE option and "
6916 "MHD_USE_THREAD_PER_CONNECTION flag are specified.\n"));
6928 daemon->https_mem_key = pstr;
6932 _ (
"MHD HTTPS option %d passed to MHD but " \
6933 "MHD_USE_TLS not set.\n"),
6941 daemon->https_key_password = pstr;
6945 _ (
"MHD HTTPS option %d passed to MHD but " \
6946 "MHD_USE_TLS not set.\n"),
6954 daemon->https_mem_cert = pstr;
6958 _ (
"MHD HTTPS option %d passed to MHD but " \
6959 "MHD_USE_TLS not set.\n"),
6967 daemon->https_mem_trust = pstr;
6971 _ (
"MHD HTTPS option %d passed to MHD but " \
6972 "MHD_USE_TLS not set.\n"),
6977 daemon->cred_type = (gnutls_credentials_type_t) va_arg (ap,
6985 gnutls_datum_t dhpar;
6988 if (gnutls_dh_params_init (&daemon->https_mem_dhparams) < 0)
6992 _ (
"Error initializing DH parameters.\n"));
6997 pstr_len = strlen (pstr);
7002 _ (
"Diffie-Hellman parameters string too long.\n"));
7006 dhpar.size = (
unsigned int) pstr_len;
7007 if (gnutls_dh_params_import_pkcs3 (daemon->https_mem_dhparams,
7009 GNUTLS_X509_FMT_PEM) < 0)
7013 _ (
"Bad Diffie-Hellman parameters format.\n"));
7015 gnutls_dh_params_deinit (daemon->https_mem_dhparams);
7018 daemon->have_dhparams =
true;
7023 _ (
"MHD HTTPS option %d passed to MHD but " \
7024 "MHD_USE_TLS not set.\n"),
7034 if (
NULL != daemon->priority_cache)
7035 gnutls_priority_deinit (daemon->priority_cache);
7040 const char *err_pos;
7041 init_res = gnutls_priority_init (&daemon->priority_cache,
7044 if (GNUTLS_E_SUCCESS != init_res)
7048 _ (
"Setting priorities to '%s' failed: %s " \
7049 "The problematic part starts at: %s\n"),
7051 gnutls_strerror (init_res),
7054 daemon->priority_cache =
NULL;
7061 daemon->priority_cache =
NULL;
7062 if (! daemon_tls_priorities_init_append (daemon, pstr))
7069 _ (
"MHD HTTPS option %d passed to MHD but " \
7070 "MHD_USE_TLS not set.\n"),
7075#if GNUTLS_VERSION_MAJOR < 3
7078 _ (
"MHD_OPTION_HTTPS_CERT_CALLBACK requires building " \
7079 "MHD with GnuTLS >= 3.0.\n"));
7084 gnutls_certificate_retrieve_function2 *);
7086 daemon->cert_callback = pgcrf;
7090 _ (
"MHD HTTPS option %d passed to MHD but " \
7091 "MHD_USE_TLS not set.\n"),
7097#if GNUTLS_VERSION_NUMBER < 0x030603
7100 _ (
"MHD_OPTION_HTTPS_CERT_CALLBACK2 requires building " \
7101 "MHD with GnuTLS >= 3.6.3.\n"));
7105 pgcrf2 = va_arg (ap,
7106 gnutls_certificate_retrieve_function3 *);
7108 daemon->cert_callback2 = pgcrf2;
7112 _ (
"MHD HTTPS option %d passed to MHD but " \
7113 "MHD_USE_TLS not set.\n"),
7122 daemon->digest_auth_rand_size = va_arg (ap,
7124 daemon->digest_auth_random = va_arg (ap,
7128 daemon->digest_auth_random_copy = daemon;
7130 daemon->digest_auth_random_copy =
NULL;
7133 daemon->nonce_nc_size = va_arg (ap,
7137 daemon->dauth_bind_type = va_arg (ap,
7149 daemon->dauth_def_nonce_timeout = val;
7159 daemon->dauth_def_max_nc = val;
7171 _ (
"Digest Auth is disabled for this build " \
7172 "of GNU libmicrohttpd.\n"));
7177 params->listen_fd = va_arg (ap,
7179 params->listen_fd_set =
true;
7183 daemon->custom_error_log = va_arg (ap,
7185 daemon->custom_error_log_cls = va_arg (ap,
7187 if (1 != params->num_opts)
7189 _ (
"MHD_OPTION_EXTERNAL_LOGGER is not the first option "
7190 "specified for the daemon. Some messages may be "
7191 "printed by the standard MHD logger.\n"));
7200#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7202 daemon->thread_stack_size = va_arg (ap,
7208 daemon->fastopen_queue_size = va_arg (ap,
7214 _ (
"TCP fastopen is not supported on this platform.\n"));
7220 unsigned int) ? 1 : -1;
7238 _ (
"Flag MHD_USE_PEDANTIC_CHECKS is ignored because "
7239 "another behaviour is specified by "
7240 "MHD_OPTION_STRICT_CLIENT.\n"));
7251 _ (
"Flag MHD_USE_PEDANTIC_CHECKS is ignored because "
7252 "another behaviour is specified by "
7253 "MHD_OPTION_CLIENT_DISCIPLINE_LVL.\n"));
7278 (
size_t) oa[i].
value,
7297 (
unsigned int) oa[i].
value,
7307 (gnutls_credentials_type_t) oa[i].
value,
7340 (uint32_t) oa[i].
value,
7373 (
void *) oa[i].
value,
7384 (
size_t) oa[i].
value,
7394 (socklen_t) oa[i].
value,
7414#if GNUTLS_VERSION_MAJOR >= 3
7415 daemon->cred_callback = va_arg (ap,
7417 daemon->cred_callback_cls = va_arg (ap,
7422 _ (
"MHD HTTPS option %d passed to MHD compiled " \
7423 "without GNUtls >= 3.\n"),
7440 daemon->disable_alpn = (va_arg (ap,
7443 (void) va_arg (ap,
int);
7448 _ (
"MHD HTTPS option %d passed to MHD " \
7449 "but MHD_USE_TLS not set.\n"),
7454 params->fdset_size_set =
true;
7455 params->fdset_size = va_arg (ap,
7458#ifndef HTTPS_SUPPORT
7472 _ (
"MHD HTTPS option %d passed to MHD "
7473 "compiled without HTTPS support.\n"),
7482 _ (
"Invalid option %d! (Did you terminate "
7483 "the list with MHD_OPTION_END?).\n"),
7499#ifndef HAVE_MESSAGES
7503#ifdef USE_EPOLL_CREATE1
7504 fd = epoll_create1 (EPOLL_CLOEXEC);
7506 fd = epoll_create (MAX_EVENTS);
7512 _ (
"Call to epoll_create1 failed: %s\n"),
7517#if ! defined(USE_EPOLL_CREATE1)
7522 _ (
"Failed to set noninheritable mode on epoll FD.\n"));
7539setup_epoll_to_listen (
struct MHD_Daemon *daemon)
7541 struct epoll_event event;
7548 MHD_ITC_IS_VALID_ (daemon->
itc) );
7549 daemon->epoll_fd = setup_epoll_fd (daemon);
7564 _ (
"The epoll FD is too large to be used with fd_set.\n"));
7569 if (-1 == daemon->epoll_fd)
7571#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
7574 daemon->epoll_upgrade_fd = setup_epoll_fd (daemon);
7582 event.events = EPOLLIN | EPOLLRDHUP;
7583 event.data.ptr = daemon;
7584 if (0 != epoll_ctl (daemon->epoll_fd,
7591 _ (
"Call to epoll_ctl failed: %s\n"),
7596 daemon->listen_socket_in_epoll =
true;
7599 if (MHD_ITC_IS_VALID_ (daemon->
itc))
7601 event.events = EPOLLIN | EPOLLRDHUP;
7603 if (0 != epoll_ctl (daemon->epoll_fd,
7605 MHD_itc_r_fd_ (daemon->
itc),
7610 _ (
"Call to epoll_ctl failed: %s\n"),
7636 const struct sockaddr **ppsockaddr,
7637 socklen_t *psockaddr_len,
7638 struct MHD_InterimParams_ *params)
7640 if (params->fdset_size_set)
7642 if (0 >= params->fdset_size)
7646 _ (
"MHD_OPTION_APP_FD_SETSIZE value (%d) is not positive.\n"),
7647 params->fdset_size);
7655 _ (
"MHD_OPTION_APP_FD_SETSIZE is ignored for daemon started " \
7656 "with MHD_USE_INTERNAL_POLLING_THREAD.\n"));
7664 _ (
"MHD_OPTION_APP_FD_SETSIZE is ignored for daemon started " \
7665 "with MHD_USE_POLL.\n"));
7671#ifndef HAS_FD_SETSIZE_OVERRIDABLE
7672 if (((
int) FD_SETSIZE) != params->fdset_size)
7676 _ (
"MHD_OPTION_APP_FD_SETSIZE value (%d) does not match " \
7677 "the platform FD_SETSIZE value (%d) and this platform " \
7678 "does not support overriding of FD_SETSIZE.\n"),
7679 params->fdset_size, (
int) FD_SETSIZE);
7684 d->fdset_size = params->fdset_size;
7685 d->fdset_size_set_by_app =
true;
7690 if (params->listen_fd_set)
7696#ifdef HAS_SIGNED_SOCKET
7697 else if (0 > params->listen_fd)
7701 _ (
"The value provided for MHD_OPTION_LISTEN_SOCKET " \
7711 _ (
"MHD_OPTION_LISTEN_SOCKET specified for daemon "
7712 "with MHD_USE_NO_LISTEN_SOCKET flag set.\n"));
7721#ifdef MHD_USE_GETSOCKNAME
7727 mhd_assert (! params->server_addr_len_set || params->pserver_addr_set);
7728 if (params->pserver_addr_set)
7730 if (
NULL == params->pserver_addr)
7733 if (params->server_addr_len_set && (0 != params->server_addr_len))
7741 _ (
"MHD_OPTION_LISTEN_SOCKET cannot be used together with " \
7742 "MHD_OPTION_SOCK_ADDR_LEN or MHD_OPTION_SOCK_ADDR.\n"));
7750 _ (
"MHD_OPTION_SOCK_ADDR_LEN or MHD_OPTION_SOCK_ADDR " \
7751 "specified for daemon with MHD_USE_NO_LISTEN_SOCKET " \
7763 *ppsockaddr = params->pserver_addr;
7764 if (params->server_addr_len_set)
7767 if (0 == params->server_addr_len)
7769 *psockaddr_len = params->server_addr_len;
7811 const struct sockaddr *pservaddr =
NULL;
7813#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7818 struct MHD_InterimParams_ *interim_params;
7835#ifndef EPOLL_SUPPORT
7839#ifndef HTTPS_SUPPORT
7849#ifdef UPGRADE_SUPPORT
7855#ifdef MHD_USE_THREADS
7884#if defined(EPOLL_SUPPORT) && defined(HAVE_POLL)
7889#elif defined(HAVE_POLL)
7892#elif defined(EPOLL_SUPPORT)
7904#ifdef HAVE_LISTEN_SHUTDOWN
7912 interim_params = (
struct MHD_InterimParams_ *) \
7913 MHD_calloc_ (1,
sizeof (
struct MHD_InterimParams_));
7914 if (
NULL == interim_params)
7916 int err_num = errno;
7922 daemon->epoll_fd = -1;
7923#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
7924 daemon->epoll_upgrade_fd = -1;
7929 daemon->priority_cache =
NULL;
7938 daemon->
port = port;
7949 MHD_itc_set_invalid_ (daemon->
itc);
7950#ifdef MHD_USE_THREADS
7959 daemon->custom_error_log = &MHD_default_logger_;
7960 daemon->custom_error_log_cls = stderr;
7962#ifndef MHD_WINSOCK_SOCKETS
7968#if defined(_DEBUG) && defined(HAVE_ACCEPT4)
7969 daemon->avoid_accept4 =
false;
7971#ifdef HAS_FD_SETSIZE_OVERRIDABLE
7972 daemon->fdset_size = (int) FD_SETSIZE;
7973 daemon->fdset_size_set_by_app =
false;
7977 daemon->digest_auth_rand_size = 0;
7978 daemon->digest_auth_random =
NULL;
7979 daemon->nonce_nc_size = 4;
7986 daemon->cred_type = GNUTLS_CRD_CERTIFICATE;
7990 interim_params->num_opts = 0;
7991 interim_params->fdset_size_set =
false;
7992 interim_params->fdset_size = 0;
7993 interim_params->listen_fd_set =
false;
7995 interim_params->pserver_addr_set =
false;
7996 interim_params->pserver_addr =
NULL;
7997 interim_params->server_addr_len_set =
false;
7998 interim_params->server_addr_len = 0;
8005 tls_cleanup_failed_start (daemon);
8007 free (interim_params);
8017 tls_cleanup_failed_start (daemon);
8019 free (interim_params);
8023 free (interim_params);
8024 interim_params =
NULL;
8027 && (
NULL == daemon->priority_cache)
8028 && ! daemon_tls_priorities_init_default (daemon))
8032 _ (
"Failed to initialise GnuTLS priorities.\n"));
8034 tls_cleanup_failed_start (daemon);
8045 _ (
"Warning: MHD_USE_THREAD_PER_CONNECTION must be used " \
8046 "only with MHD_USE_INTERNAL_POLLING_THREAD. " \
8047 "Flag MHD_USE_INTERNAL_POLLING_THREAD was added. " \
8048 "Consider setting MHD_USE_INTERNAL_POLLING_THREAD " \
8061 _ (
"Using debug build of libmicrohttpd.\n") );
8066#
if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8067 && (0 == daemon->worker_pool_size)
8071 if (! MHD_itc_init_ (daemon->
itc))
8075 _ (
"Failed to create inter-thread communication channel: %s\n"),
8076 MHD_itc_last_strerror_ ());
8079 if (
NULL != daemon->priority_cache)
8080 gnutls_priority_deinit (daemon->priority_cache);
8090 _ (
"file descriptor for inter-thread communication " \
8091 "channel exceeds maximum value.\n"));
8095 if (
NULL != daemon->priority_cache)
8096 gnutls_priority_deinit (daemon->priority_cache);
8104 if (
NULL != daemon->digest_auth_random_copy)
8106 mhd_assert (daemon == daemon->digest_auth_random_copy);
8107 daemon->digest_auth_random_copy = malloc (daemon->digest_auth_rand_size);
8108 if (
NULL == daemon->digest_auth_random_copy)
8112 gnutls_priority_deinit (daemon->priority_cache);
8117 memcpy (daemon->digest_auth_random_copy,
8118 daemon->digest_auth_random,
8119 daemon->digest_auth_rand_size);
8120 daemon->digest_auth_random = daemon->digest_auth_random_copy;
8122 if (daemon->nonce_nc_size > 0)
8124 if ( ( (
size_t) (daemon->nonce_nc_size * sizeof (
struct MHD_NonceNc)))
8125 /
sizeof(
struct MHD_NonceNc) != daemon->nonce_nc_size)
8129 _ (
"Specified value for NC_SIZE too large.\n"));
8133 gnutls_priority_deinit (daemon->priority_cache);
8135 free (daemon->digest_auth_random_copy);
8141 if (
NULL == daemon->nnc)
8145 _ (
"Failed to allocate memory for nonce-nc map: %s\n"),
8150 gnutls_priority_deinit (daemon->priority_cache);
8152 free (daemon->digest_auth_random_copy);
8158#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8163 _ (
"MHD failed to initialize nonce-nc mutex.\n"));
8167 gnutls_priority_deinit (daemon->priority_cache);
8169 free (daemon->digest_auth_random_copy);
8178#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8180 (daemon->worker_pool_size > 0) )
8184 _ (
"MHD thread polling only works with " \
8185 "MHD_USE_INTERNAL_POLLING_THREAD.\n"));
8195 struct sockaddr_in servaddr4;
8197 struct sockaddr_in6 servaddr6;
8200 const bool use_ipv6 =
false;
8204 if (
NULL != pservaddr)
8206#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
8207 const socklen_t sa_len = pservaddr->sa_len;
8210 if (use_ipv6 && (AF_INET6 != pservaddr->sa_family))
8214 _ (
"MHD_USE_IPv6 is enabled, but 'struct sockaddr *' " \
8215 "specified for MHD_OPTION_SOCK_ADDR_LEN or " \
8216 "MHD_OPTION_SOCK_ADDR is not IPv6 address.\n"));
8221 switch (pservaddr->sa_family)
8226 struct sockaddr_in sa4;
8229 && (((socklen_t)
sizeof(sa4)) > addrlen))
8233 _ (
"The size specified for MHD_OPTION_SOCK_ADDR_LEN " \
8234 "option is wrong.\n"));
8238#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
8241 if (((socklen_t)
sizeof(sa4)) > sa_len)
8245 _ (
"The value of 'struct sockaddr.sa_len' provided " \
8246 "via MHD_OPTION_SOCK_ADDR_LEN option is not zero " \
8247 "and does not match 'sa_family' value of the " \
8248 "same structure.\n"));
8252 if ((0 == addrlen) || (sa_len < addrlen))
8257 addrlen =
sizeof(sa4);
8258 memcpy (&sa4, pservaddr,
sizeof(sa4));
8259 sa4_port = (uint16_t) ntohs (sa4.sin_port);
8260#ifndef MHD_USE_GETSOCKNAME
8263 daemon->
port = sa4_port;
8271 struct sockaddr_in6 sa6;
8274 && (((socklen_t)
sizeof(sa6)) > addrlen))
8278 _ (
"The size specified for MHD_OPTION_SOCK_ADDR_LEN " \
8279 "option is wrong.\n"));
8283#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
8286 if (((socklen_t)
sizeof(sa6)) > sa_len)
8290 _ (
"The value of 'struct sockaddr.sa_len' provided " \
8291 "via MHD_OPTION_SOCK_ADDR_LEN option is not zero " \
8292 "and does not match 'sa_family' value of the " \
8293 "same structure.\n"));
8297 if ((0 == addrlen) || (sa_len < addrlen))
8302 addrlen =
sizeof(sa6);
8303 memcpy (&sa6, pservaddr,
sizeof(sa6));
8304 sa6_port = (uint16_t) ntohs (sa6.sin6_port);
8305#ifndef MHD_USE_GETSOCKNAME
8308 daemon->
port = sa6_port;
8318#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
8321 else if ((0 != sa_len) && (sa_len < addrlen))
8328 _ (
"The 'sa_family' of the 'struct sockaddr' provided " \
8329 "via MHD_OPTION_SOCK_ADDR option is not supported.\n"));
8334 if (AF_UNIX == pservaddr->sa_family)
8351 domain = pservaddr->sa_family;
8362 sizeof (
struct sockaddr_in));
8363 servaddr4.sin_family = AF_INET;
8364 servaddr4.sin_port = htons (port);
8365 if (0 != INADDR_ANY)
8366 servaddr4.sin_addr.s_addr = htonl (INADDR_ANY);
8367#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
8368 servaddr4.sin_len =
sizeof (
struct sockaddr_in);
8370 pservaddr = (
struct sockaddr *) &servaddr4;
8371 addrlen = (socklen_t)
sizeof(servaddr4);
8378#ifdef IN6ADDR_ANY_INIT
8379 static const struct in6_addr static_in6any = IN6ADDR_ANY_INIT;
8383 sizeof (
struct sockaddr_in6));
8384 servaddr6.sin6_family = AF_INET6;
8385 servaddr6.sin6_port = htons (port);
8386#ifdef IN6ADDR_ANY_INIT
8387 servaddr6.sin6_addr = static_in6any;
8389#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
8390 servaddr6.sin6_len =
sizeof (
struct sockaddr_in6);
8392 pservaddr = (
struct sockaddr *) &servaddr6;
8393 addrlen = (socklen_t)
sizeof (servaddr6);
8405 _ (
"Failed to create socket for listening: %s\n"),
8416 _ (
"Listen socket descriptor (%d) is not " \
8417 "less than daemon FD_SETSIZE value (%d).\n"),
8427#ifndef MHD_WINSOCK_SOCKETS
8435 (
const void *) &on, sizeof (on)))
8439 _ (
"setsockopt failed: %s\n"),
8448#ifndef MHD_WINSOCK_SOCKETS
8454 (
const void *) &on, sizeof (on)))
8458 _ (
"setsockopt failed: %s\n"),
8468#if defined(MHD_WINSOCK_SOCKETS) || defined(SO_REUSEPORT)
8471#ifndef MHD_WINSOCK_SOCKETS
8481 _ (
"setsockopt failed: %s\n"),
8491 _ (
"Cannot allow listening address reuse: " \
8492 "SO_REUSEPORT not defined.\n"));
8505#if (defined(MHD_WINSOCK_SOCKETS) && defined(SO_EXCLUSIVEADDRUSE)) || \
8506 (defined(__sun) && defined(SO_EXCLBIND))
8509#ifdef SO_EXCLUSIVEADDRUSE
8510 SO_EXCLUSIVEADDRUSE,
8519 _ (
"setsockopt failed: %s\n"),
8524#elif defined(MHD_WINSOCK_SOCKETS)
8527 _ (
"Cannot disallow listening address reuse: " \
8528 "SO_EXCLUSIVEADDRUSE not defined.\n"));
8546 IPPROTO_IPV6, IPV6_V6ONLY,
8547 (
const void *) &v6_only,
8552 _ (
"setsockopt failed: %s\n"),
8565 _ (
"Failed to bind to port %u: %s\n"),
8566 (
unsigned int) port,
8574 if (0 == daemon->fastopen_queue_size)
8575 daemon->fastopen_queue_size = MHD_TCP_FASTOPEN_QUEUE_SIZE_DEFAULT;
8579 (
const void *) &daemon->fastopen_queue_size,
8580 sizeof (daemon->fastopen_queue_size)))
8584 _ (
"setsockopt failed: %s\n"),
8595 _ (
"Failed to listen for connections: %s\n"),
8609 _ (
"Listen socket descriptor (%d) is not " \
8610 "less than daemon FD_SETSIZE value (%d).\n"),
8618#if defined(SOL_SOCKET) && (defined(SO_DOMAIN) || defined(SO_PROTOCOL_INFOW))
8622 socklen_t optval_size;
8624 opt_name = SO_DOMAIN;
8626 optval_size = (socklen_t)
sizeof (af);
8628 WSAPROTOCOL_INFOW prot_info;
8629 opt_name = SO_PROTOCOL_INFOW;
8630 poptval = &prot_info;
8631 optval_size = (socklen_t)
sizeof (prot_info);
8641 af = prot_info.iAddressFamily;
8671#ifdef MHD_USE_GETSOCKNAME
8676#ifdef MHD_USE_GETSOCKNAME
8677 if ( (0 == daemon->
port) &&
8681 struct sockaddr_storage bindaddr;
8685 sizeof (
struct sockaddr_storage));
8686 addrlen =
sizeof (
struct sockaddr_storage);
8687#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
8688 bindaddr.ss_len = (socklen_t) addrlen;
8690 if (0 != getsockname (daemon->
listen_fd,
8691 (
struct sockaddr *) &bindaddr,
8696 _ (
"Failed to get listen port number: %s\n"),
8697 MHD_socket_last_strerr_ ());
8701 else if (
sizeof (bindaddr) < addrlen)
8706 _ (
"Failed to get listen port number " \
8707 "(`struct sockaddr_storage` too small!?).\n"));
8711 else if (0 == addrlen)
8723 switch (bindaddr.ss_family)
8727 struct sockaddr_in *s4 = (
struct sockaddr_in *) &bindaddr;
8729 daemon->
port = ntohs (s4->sin_port);
8736 struct sockaddr_in6 *s6 = (
struct sockaddr_in6 *) &bindaddr;
8738 daemon->
port = ntohs (s6->sin6_port);
8753 _ (
"Listen socket has unknown address family!\n"));
8770 _ (
"Failed to set nonblocking mode on listening socket: %s\n"),
8774#
if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8775 || (daemon->worker_pool_size > 0)
8797#
if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8798 && (0 == daemon->worker_pool_size)
8806 _ (
"Combining MHD_USE_THREAD_PER_CONNECTION and " \
8807 "MHD_USE_EPOLL is not supported.\n"));
8811 if (
MHD_NO == setup_epoll_to_listen (daemon))
8816#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8821 _ (
"MHD failed to initialize IP connection limit mutex.\n"));
8830 (0 != MHD_TLS_init (daemon)) )
8834 _ (
"Failed to initialize TLS support.\n"));
8836#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8842#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8850#ifdef HAVE_LISTEN_SHUTDOWN
8851 mhd_assert ((1 < daemon->worker_pool_size) || \
8852 (MHD_ITC_IS_VALID_ (daemon->
itc)) || \
8855 mhd_assert ((1 < daemon->worker_pool_size) || \
8856 (MHD_ITC_IS_VALID_ (daemon->
itc)));
8858 if (0 == daemon->worker_pool_size)
8864 _ (
"Failed to initialise internal lists mutex.\n"));
8873 _ (
"Failed to initialise mutex.\n"));
8883 _ (
"Failed to initialise mutex.\n"));
8892 "MHD-listen" :
"MHD-single",
8893 daemon->thread_stack_size,
8894 &MHD_polling_thread,
8899 if (EAGAIN == errno)
8901 _ (
"Failed to create a new thread because it would have " \
8902 "exceeded the system limit on the number of threads or " \
8903 "no system resources available.\n"));
8907 _ (
"Failed to create listen thread: %s\n"),
8923 / daemon->worker_pool_size;
8925 % daemon->worker_pool_size;
8931 daemon->worker_pool = malloc (
sizeof (
struct MHD_Daemon)
8932 * daemon->worker_pool_size);
8933 if (
NULL == daemon->worker_pool)
8937 for (i = 0; i < daemon->worker_pool_size; ++i)
8940 struct MHD_Daemon *d = &daemon->worker_pool[i];
8942 memcpy (d, daemon,
sizeof (
struct MHD_Daemon));
8947 d->worker_pool_size = 0;
8948 d->worker_pool =
NULL;
8953 _ (
"Failed to initialise internal lists mutex.\n"));
8961 _ (
"Failed to initialise mutex.\n"));
8970 _ (
"Failed to initialise mutex.\n"));
8979 if (! MHD_itc_init_ (d->
itc))
8983 _ (
"Failed to create worker inter-thread " \
8984 "communication channel: %s\n"),
8985 MHD_itc_last_strerror_ () );
8997 _ (
"File descriptor for worker inter-thread " \
8998 "communication channel exceeds maximum value.\n"));
9008 MHD_itc_set_invalid_ (d->
itc);
9010#ifdef HAVE_LISTEN_SHUTDOWN
9021 if (i < leftover_conns)
9025 (
MHD_NO == setup_epoll_to_listen (d)) )
9027 if (MHD_ITC_IS_VALID_ (d->
itc))
9036#if defined(MHD_USE_THREADS)
9037 memset (&d->per_ip_connection_mutex, 0x7F,
9038 sizeof(d->per_ip_connection_mutex));
9042 d->nonce_nc_size = 0;
9043 d->digest_auth_random_copy =
NULL;
9044#if defined(MHD_USE_THREADS)
9045 memset (&d->nnc_lock, 0x7F,
sizeof(d->nnc_lock));
9052 daemon->thread_stack_size,
9053 &MHD_polling_thread,
9058 if (EAGAIN == errno)
9060 _ (
"Failed to create a new pool thread because it would " \
9061 "have exceeded the system limit on the number of " \
9062 "threads or no system resources available.\n"));
9066 _ (
"Failed to create pool thread: %s\n"),
9071 if (MHD_ITC_IS_VALID_ (d->
itc))
9087 _ (
"Failed to initialise internal lists mutex.\n"));
9096 _ (
"Failed to initialise mutex.\n"));
9106 _ (
"Failed to initialise mutex.\n"));
9118 daemon->https_key_password =
NULL;
9123#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9132 if (
NULL != daemon->worker_pool)
9133 free (daemon->worker_pool);
9141 daemon->worker_pool_size = i;
9150#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
9151 if (daemon->upgrade_fd_in_epoll)
9153 if (0 != epoll_ctl (daemon->epoll_fd,
9155 daemon->epoll_upgrade_fd,
9157 MHD_PANIC (
_ (
"Failed to remove FD from epoll set.\n"));
9158 daemon->upgrade_fd_in_epoll =
false;
9161 if (-1 != daemon->epoll_fd)
9162 close (daemon->epoll_fd);
9163#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
9164 if (-1 != daemon->epoll_upgrade_fd)
9165 close (daemon->epoll_upgrade_fd);
9169 free (daemon->digest_auth_random_copy);
9171#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9176 tls_cleanup_failed_start (daemon);
9178 if (MHD_ITC_IS_VALID_ (daemon->
itc))
9200#ifdef UPGRADE_SUPPORT
9203#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
9204 struct MHD_UpgradeResponseHandle *urh;
9205 struct MHD_UpgradeResponseHandle *urhn;
9209#ifdef MHD_USE_THREADS
9217#ifdef MHD_USE_THREADS
9234 new_connection_close_ (daemon, pos);
9239#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
9242 for (urh = daemon->urh_tail;
NULL != urh; urh = urhn)
9250 urh->clean_ready =
true;
9267#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9270#ifdef UPGRADE_SUPPORT
9276 while (
NULL != susp)
9278 if (
NULL == susp->urh)
9279 MHD_PANIC (
_ (
"MHD_stop_daemon() called while we have " \
9280 "suspended connections.\n"));
9282 else if (used_tls &&
9284 (! susp->urh->clean_ready) )
9285 shutdown (susp->urh->app.socket,
9291 if (! susp->urh->was_closed)
9293 _ (
"Initiated daemon shutdown while \"upgraded\" " \
9294 "connection was not closed.\n"));
9296 susp->urh->was_closed =
true;
9312 MHD_PANIC (
_ (
"MHD_stop_daemon() called while we have " \
9313 "suspended connections.\n"));
9314#if defined(UPGRADE_SUPPORT) && defined(HTTPS_SUPPORT)
9315#ifdef MHD_USE_THREADS
9316 if (upg_allowed && used_tls && used_thr_p_c)
9327 if (! pos->thread_joined)
9335 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
9336 pos->thread_joined =
true;
9347#ifdef MHD_WINSOCK_SOCKETS
9350 (! MHD_itc_activate_ (
daemon->
itc,
"e")) )
9351 MHD_PANIC (
_ (
"Failed to signal shutdown via inter-thread " \
9352 "communication channel.\n"));
9356#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9363 if (! pos->thread_joined)
9367 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
9369 pos->thread_joined =
true;
9381#ifdef UPGRADE_SUPPORT
9397#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9399 (! pos->thread_joined) )
9400 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
9418#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9425 MHD_PANIC (
_ (
"MHD_stop_daemon() was called twice."));
9443#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9450 for (i = 0; i <
daemon->worker_pool_size; ++i)
9453 if (MHD_ITC_IS_VALID_ (
daemon->worker_pool[i].
itc))
9455 if (! MHD_itc_activate_ (
daemon->worker_pool[i].
itc,
9457 MHD_PANIC (
_ (
"Failed to signal shutdown via inter-thread " \
9458 "communication channel.\n"));
9463#ifdef HAVE_LISTEN_SHUTDOWN
9466 (void) shutdown (
fd,
9470 for (i = 0; i <
daemon->worker_pool_size; ++i)
9474 free (
daemon->worker_pool);
9478#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
9486#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9495 MHD_PANIC (
_ (
"Failed to signal shutdown via inter-thread " \
9496 "communication channel.\n"));
9500#ifdef HAVE_LISTEN_SHUTDOWN
9504 (void) shutdown (
fd,
9514 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
9528#if defined(UPGRADE_SUPPORT) && defined(HTTPS_SUPPORT)
9537 (-1 !=
daemon->epoll_fd) )
9539#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
9541 (-1 !=
daemon->epoll_upgrade_fd) )
9546#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9562 if (
daemon->have_dhparams)
9564 gnutls_dh_params_deinit (
daemon->https_mem_dhparams);
9565 daemon->have_dhparams =
false;
9569 gnutls_priority_deinit (
daemon->priority_cache);
9571 gnutls_certificate_free_credentials (
daemon->x509_cred);
9573 gnutls_psk_free_server_credentials (
daemon->psk_cred);
9578 free (
daemon->digest_auth_random_copy);
9580#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9584#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9613 (
NULL != daemon->worker_pool) || \
9616 (
NULL == daemon->worker_pool)) || \
9630 daemon->daemon_info_dummy_epoll_fd.epoll_fd = daemon->epoll_fd;
9631 return &daemon->daemon_info_dummy_epoll_fd;
9638#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9639 else if (daemon->worker_pool)
9644 for (i = 0; i < daemon->worker_pool_size; i++)
9675#ifdef PACKAGE_VERSION
9676 return PACKAGE_VERSION;
9678 static char ver[12] =
"\0\0\0\0\0\0\0\0\0\0\0";
9681 int res = MHD_snprintf_ (ver,
9687 if ((0 >= res) || (
sizeof(ver) <= res))
9739#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_MAJOR >= 3
9745#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_NUMBER >= 0x030603
9757#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
9775#ifdef HAVE_LISTEN_SHUTDOWN
9781#ifdef _MHD_ITC_SOCKETPAIR
9805#ifdef HAVE_POSTPROCESSOR
9811#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_NUMBER >= 0x030111
9817#if defined(HAVE_PREAD64) || defined(_WIN32)
9819#elif defined(HAVE_PREAD)
9820 return (
sizeof(uint64_t) >
sizeof(off_t)) ?
MHD_NO :
MHD_YES;
9821#elif defined(HAVE_LSEEK64)
9824 return (
sizeof(uint64_t) >
sizeof(off_t)) ?
MHD_NO :
MHD_YES;
9827#if defined(MHD_USE_THREAD_NAME_)
9833#if defined(UPGRADE_SUPPORT)
9839#if defined(HAVE_PREAD64) || defined(HAVE_PREAD) || defined(_WIN32)
9845#ifdef MHD_USE_GETSOCKNAME
9851#if defined(MHD_SEND_SPIPE_SUPPRESS_POSSIBLE) || \
9852 ! defined(MHD_SEND_SPIPE_SUPPRESS_NEEDED)
9858#ifdef _MHD_HAVE_SENDFILE
9864#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9870#if defined(COOKIE_SUPPORT)
9882#if defined(DAUTH_SUPPORT) && defined(MHD_MD5_SUPPORT)
9888#if defined(DAUTH_SUPPORT) && defined(MHD_SHA256_SUPPORT)
9894#if defined(DAUTH_SUPPORT) && defined(MHD_SHA512_256_SUPPORT)
9918#if defined(MHD_MD5_TLSLIB) || defined(MHD_SHA256_TLSLIB)
9930#ifdef HAS_FD_SETSIZE_OVERRIDABLE
9943#ifdef MHD_HTTPS_REQUIRE_GCRYPT
9944#if defined(HTTPS_SUPPORT) && GCRYPT_VERSION_NUMBER < 0x010600
9945#if defined(MHD_USE_POSIX_THREADS)
9946GCRY_THREAD_OPTION_PTHREAD_IMPL;
9947#elif defined(MHD_W32_MUTEX_)
9950gcry_w32_mutex_init (
void **ppmtx)
9952 *ppmtx = malloc (
sizeof (MHD_mutex_));
9968gcry_w32_mutex_destroy (
void **ppmtx)
9977gcry_w32_mutex_lock (
void **ppmtx)
9984gcry_w32_mutex_unlock (
void **ppmtx)
9990static struct gcry_thread_cbs gcry_threads_w32 = {
9991 (GCRY_THREAD_OPTION_USER | (GCRY_THREAD_OPTION_VERSION << 8)),
9992 NULL, gcry_w32_mutex_init, gcry_w32_mutex_destroy,
9993 gcry_w32_mutex_lock, gcry_w32_mutex_unlock,
10007#if defined(MHD_WINSOCK_SOCKETS)
10013#if defined(MHD_WINSOCK_SOCKETS)
10014 if (0 != WSAStartup (MAKEWORD (2, 2), &wsd))
10015 MHD_PANIC (
_ (
"Failed to initialize winsock.\n"));
10016 if ((2 != LOBYTE (wsd.wVersion)) && (2 != HIBYTE (wsd.wVersion)))
10017 MHD_PANIC (
_ (
"Winsock version 2.2 is not available.\n"));
10019#ifdef HTTPS_SUPPORT
10020#ifdef MHD_HTTPS_REQUIRE_GCRYPT
10021#if GCRYPT_VERSION_NUMBER < 0x010600
10022#if GNUTLS_VERSION_NUMBER <= 0x020b00
10023#if defined(MHD_USE_POSIX_THREADS)
10024 if (0 != gcry_control (GCRYCTL_SET_THREAD_CBS,
10025 &gcry_threads_pthread))
10026 MHD_PANIC (
_ (
"Failed to initialise multithreading in libgcrypt.\n"));
10027#elif defined(MHD_W32_MUTEX_)
10028 if (0 != gcry_control (GCRYCTL_SET_THREAD_CBS,
10029 &gcry_threads_w32))
10030 MHD_PANIC (
_ (
"Failed to initialise multithreading in libgcrypt.\n"));
10033 gcry_check_version (
NULL);
10035 if (
NULL == gcry_check_version (
"1.6.0"))
10036 MHD_PANIC (
_ (
"libgcrypt is too old. MHD was compiled for " \
10037 "libgcrypt 1.6.0 or newer.\n"));
10040 gnutls_global_init ();
10050 mhd_assert (
sizeof(tv.tv_sec) == SIZEOF_STRUCT_TIMEVAL_TV_SEC);
10053 mhd_assert (
sizeof(uint64_t) == SIZEOF_UINT64_T);
10060#ifdef HTTPS_SUPPORT
10061 gnutls_global_deinit ();
10063#if defined(MHD_WINSOCK_SOCKETS)
10070#ifdef _AUTOINIT_FUNCS_ARE_SUPPORTED
#define _SET_INIT_AND_DEINIT_FUNCS(FI, FD)
void MHD_connection_set_initial_state_(struct MHD_Connection *c)
void MHD_connection_handle_write(struct MHD_Connection *connection)
void MHD_set_http_callbacks_(struct MHD_Connection *connection)
enum MHD_Result MHD_connection_handle_idle(struct MHD_Connection *connection)
void MHD_connection_handle_read(struct MHD_Connection *connection, bool socket_error)
void MHD_update_last_activity_(struct MHD_Connection *connection)
void MHD_connection_close_(struct MHD_Connection *connection, enum MHD_RequestTerminationCode termination_code)
void MHD_connection_mark_closed_(struct MHD_Connection *connection)
Methods for managing connections.
#define MHD_connection_finish_forward_(conn)
void MHD_set_https_callbacks(struct MHD_Connection *connection)
Methods for managing connections.
static void MHD_ip_limit_del(struct MHD_Daemon *daemon, const struct sockaddr_storage *addr, socklen_t addrlen)
static void close_all_connections(struct MHD_Daemon *daemon)
static enum MHD_Result MHD_ip_addr_to_key(const struct sockaddr_storage *addr, socklen_t addrlen, struct MHD_IPCount *key)
void internal_suspend_connection_(struct MHD_Connection *connection)
static enum MHD_Result MHD_ip_limit_add(struct MHD_Daemon *daemon, const struct sockaddr_storage *addr, socklen_t addrlen)
static enum MHD_Result call_handlers(struct MHD_Connection *con, bool read_ready, bool write_ready, bool force_close)
static void MHD_ip_count_unlock(struct MHD_Daemon *daemon)
static struct MHD_Connection * new_connection_prepare_(struct MHD_Daemon *daemon, MHD_socket client_socket, const struct sockaddr_storage *addr, socklen_t addrlen, bool external_add, bool non_blck, bool sk_spipe_supprs, enum MHD_tristate sk_is_nonip)
volatile int global_init_count
void MHD_check_global_init_(void)
static void close_connection(struct MHD_Connection *pos)
_MHD_EXTERN void MHD_resume_connection(struct MHD_Connection *connection)
static enum MHD_Result MHD_select(struct MHD_Daemon *daemon, int32_t millisec)
static enum MHD_Result parse_options(struct MHD_Daemon *daemon, struct MHD_InterimParams_ *params,...)
static int MHD_ip_addr_compare(const void *a1, const void *a2)
static void new_connections_list_process_(struct MHD_Daemon *daemon)
static void MHD_cleanup_connections(struct MHD_Daemon *daemon)
void(* VfprintfFunctionPointerType)(void *cls, const char *format, va_list va)
static enum MHD_Result MHD_accept_connection(struct MHD_Daemon *daemon)
static enum MHD_Result parse_options_va(struct MHD_Daemon *daemon, struct MHD_InterimParams_ *params, va_list ap)
#define MHD_MAX_CONNECTIONS_DEFAULT
static size_t unescape_wrapper(void *cls, struct MHD_Connection *connection, char *val)
static enum MHD_Result new_connection_process_(struct MHD_Daemon *daemon, struct MHD_Connection *connection)
static enum MHD_Result internal_add_connection(struct MHD_Daemon *daemon, MHD_socket client_socket, const struct sockaddr_storage *addr, socklen_t addrlen, bool external_add, bool non_blck, bool sk_spipe_supprs, enum MHD_tristate sk_is_nonip)
static void MHD_ip_count_lock(struct MHD_Daemon *daemon)
static enum MHD_Result resume_suspended_connections(struct MHD_Daemon *daemon)
#define MHD_POOL_SIZE_DEFAULT
static bool process_interim_params(struct MHD_Daemon *d, const struct sockaddr **ppsockaddr, socklen_t *psockaddr_len, struct MHD_InterimParams_ *params)
_MHD_EXTERN void MHD_suspend_connection(struct MHD_Connection *connection)
_MHD_EXTERN int MHD_get_timeout_i(struct MHD_Daemon *daemon)
_MHD_EXTERN int64_t MHD_get_timeout64s(struct MHD_Daemon *daemon)
#define MHD_run_from_select(d, r, w, e)
_MHD_EXTERN void MHD_stop_daemon(struct MHD_Daemon *daemon)
_MHD_EXTERN struct MHD_Daemon * MHD_start_daemon_va(unsigned int flags, uint16_t port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls, va_list ap)
_MHD_EXTERN enum MHD_Result MHD_run(struct MHD_Daemon *daemon)
static enum MHD_Result internal_run_from_select(struct MHD_Daemon *daemon, const fd_set *read_fd_set, const fd_set *write_fd_set, const fd_set *except_fd_set, int fd_setsize)
_MHD_EXTERN enum MHD_Result MHD_get_fdset2(struct MHD_Daemon *daemon, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, MHD_socket *max_fd, unsigned int fd_setsize)
static enum MHD_Result internal_get_fdset2(struct MHD_Daemon *daemon, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, MHD_socket *max_fd, int fd_setsize)
#define MHD_get_fdset(daemon, read_fd_set, write_fd_set, except_fd_set, max_fd)
_MHD_EXTERN enum MHD_Result MHD_get_timeout(struct MHD_Daemon *daemon, MHD_UNSIGNED_LONG_LONG *timeout)
_MHD_EXTERN enum MHD_Result MHD_get_timeout64(struct MHD_Daemon *daemon, uint64_t *timeout)
_MHD_EXTERN enum MHD_Result MHD_run_from_select2(struct MHD_Daemon *daemon, const fd_set *read_fd_set, const fd_set *write_fd_set, const fd_set *except_fd_set, unsigned int fd_setsize)
_MHD_EXTERN struct MHD_Daemon * MHD_start_daemon(unsigned int flags, uint16_t port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls,...)
_MHD_EXTERN enum MHD_Result MHD_run_wait(struct MHD_Daemon *daemon, int32_t millisec)
_MHD_EXTERN void MHD_set_panic_func(MHD_PanicCallback cb, void *cls)
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)
@ MHD_CONNECTION_NOTIFY_STARTED
@ MHD_CONNECTION_NOTIFY_CLOSED
@ MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN
@ MHD_REQUEST_TERMINATED_COMPLETED_OK
@ MHD_REQUEST_TERMINATED_WITH_ERROR
_MHD_EXTERN void MHD_destroy_response(struct MHD_Response *response)
_MHD_EXTERN enum MHD_Result MHD_add_connection(struct MHD_Daemon *daemon, MHD_socket client_socket, const struct sockaddr *addr, socklen_t addrlen)
_MHD_EXTERN enum MHD_Result MHD_is_feature_supported(enum MHD_FEATURE feature)
_MHD_EXTERN MHD_socket MHD_quiesce_daemon(struct MHD_Daemon *daemon)
_MHD_EXTERN const union MHD_DaemonInfo * MHD_get_daemon_info(struct MHD_Daemon *daemon, enum MHD_DaemonInfoType info_type,...)
_MHD_EXTERN uint32_t MHD_get_version_bin(void)
_MHD_EXTERN const char * MHD_get_version(void)
_MHD_EXTERN void MHD_free(void *ptr)
MHD internal shared structures.
@ MHD_CONNECTION_HEADERS_SENDING
@ MHD_CONNECTION_NORMAL_BODY_READY
@ MHD_CONNECTION_CHUNKED_BODY_READY
#define MHD_D_IS_USING_POLL_(d)
#define XDLL_insert(head, tail, element)
@ MHD_EPOLL_STATE_SUSPENDED
@ MHD_EPOLL_STATE_IN_EREADY_EDLL
@ MHD_EPOLL_STATE_READ_READY
@ MHD_EPOLL_STATE_IN_EPOLL_SET
@ MHD_EPOLL_STATE_WRITE_READY
#define DLL_insert(head, tail, element)
#define MHD_D_DOES_SCKT_FIT_FDSET_(sckt, d)
@ MHD_EVENT_LOOP_INFO_PROCESS_READ
@ MHD_EVENT_LOOP_INFO_PROCESS
@ MHD_EVENT_LOOP_INFO_READ
@ MHD_EVENT_LOOP_INFO_WRITE
@ MHD_EVENT_LOOP_INFO_CLEANUP
#define MHD_D_IS_USING_SELECT_(d)
#define EDLL_insert(head, tail, element)
void *(* LogCallback)(void *cls, const char *uri, struct MHD_Connection *con)
_MHD_static_inline struct MHD_Daemon * MHD_get_master(struct MHD_Daemon *const daemon)
#define _MHD_DROP_CONST(ptr)
#define MHD_D_GET_FD_SETSIZE_(d)
#define EDLL_remove(head, tail, element)
#define XDLL_remove(head, tail, element)
#define MHD_D_IS_USING_THREAD_PER_CONN_(d)
#define DLL_remove(head, tail, element)
#define MHD_D_IS_USING_THREADS_(d)
#define MHD_TEST_ALLOW_SUSPEND_RESUME
size_t(* UnescapeCallback)(void *cls, struct MHD_Connection *conn, char *uri)
#define MHD_D_IS_USING_EPOLL_(d)
#define MHD_D_IS_THREAD_SAFE_(d)
void MHD_init_mem_pools_(void)
void MHD_pool_destroy(struct MemoryPool *pool)
struct MemoryPool * MHD_pool_create(size_t max)
memory pool; mostly used for efficient (de)allocation for each connection and bounding memory use for...
#define mhd_assert(ignore)
void * MHD_calloc_(size_t nelem, size_t elsize)
Header for platform missing functions.
#define MHD_strerror_(errnum)
Header for platform-independent inter-thread communication.
#define MHD_ITC_IS_INVALID_(itc)
#define MHD_itc_destroy_chk_(itc)
limits values definitions
#define TIMEVAL_TV_SEC_MAX
Header for platform-independent locks abstraction.
#define MHD_mutex_unlock_chk_(ignore)
#define MHD_mutex_destroy_(ignore)
#define MHD_mutex_unlock_(ignore)
#define MHD_mutex_lock_(ignore)
#define MHD_mutex_init_(ignore)
#define MHD_mutex_lock_chk_(ignore)
#define MHD_mutex_destroy_chk_(ignore)
uint64_t MHD_monotonic_msec_counter(void)
void MHD_monotonic_sec_counter_finish(void)
void MHD_monotonic_sec_counter_init(void)
internal monotonic clock functions implementations
#define MHD_DAUTH_DEF_TIMEOUT_
#define MHD_DAUTH_DEF_MAX_NC_
void MHD_send_init_static_vars_(void)
Declarations of send() wrappers.
int MHD_socket_noninheritable_(MHD_socket sock)
int MHD_socket_nonblocking_(MHD_socket sock)
int MHD_add_to_fd_set_(MHD_socket fd, fd_set *set, MHD_socket *max_fd, int fd_setsize)
MHD_socket MHD_socket_create_listen_(int pf)
#define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err)
#define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd, pset, setsize)
#define MHD_SCKT_ERR_IS_(err, code)
#define SOCK_NONBLOCK_OR_ZERO
#define MHD_socket_close_(fd)
#define MHD_SCKT_ERR_IS_EAGAIN_(err)
#define MHD_SCKT_ERR_IS_LOW_RESOURCES_(err)
#define _MHD_SYS_DEFAULT_FD_SETSIZE
#define MHD_socket_strerr_(err)
#define MHD_socket_last_strerr_()
#define MHD_socket_get_error_()
#define SOCK_NOSIGPIPE_OR_ZERO
#define MHD_socket_close_chk_(fd)
#define MHD_SCKT_ERR_IS_EINTR_(err)
#define MHD_socket_fset_error_(err)
#define MHD_SCKT_SEND_MAX_SIZE_
#define MHD_recv_(s, b, l)
#define MHD_send_(s, b, l)
#define MHD_SCKT_LAST_ERR_IS_(code)
#define MHD_SYS_select_(n, r, w, e, t)
#define SOCK_CLOEXEC_OR_ZERO
size_t MHD_str_pct_decode_in_place_lenient_(char *str, bool *broken_encoding)
size_t MHD_str_pct_decode_in_place_strict_(char *str)
Header for string manipulating helpers.
#define _MHD_S_STR_W_LEN(str)
#define MHD_STATICSTR_LEN_(macro)
Header for platform-independent threads abstraction.
#define MHD_thread_handle_ID_set_current_thread_ID_(hndl_id_ptr)
#define MHD_thread_handle_ID_is_current_thread_(hndl_id)
#define MHD_thread_handle_ID_is_valid_handle_(hndl_id)
#define MHD_thread_handle_ID_join_thread_(hndl_id)
#define MHD_thread_handle_ID_set_invalid_(hndl_id_ptr)
#define MHD_thread_handle_ID_is_valid_ID_(hndl_id)
#define MHD_create_named_thread_(t, n, s, r, a)
@ MHD_FEATURE_POSTPROCESSOR
@ MHD_FEATURE_SHUTDOWN_LISTEN_SOCKET
@ MHD_FEATURE_DIGEST_AUTH_USERHASH
@ MHD_FEATURE_DIGEST_AUTH_AUTH_INT
@ MHD_FEATURE_DIGEST_AUTH_SHA256
@ MHD_FEATURE_AUTODETECT_BIND_PORT
@ MHD_FEATURE_DIGEST_AUTH_SHA512_256
@ MHD_FEATURE_EXTERN_HASH
@ MHD_FEATURE_HTTPS_CERT_CALLBACK
@ MHD_FEATURE_DIGEST_AUTH
@ MHD_FEATURE_THREAD_NAMES
@ MHD_FEATURE_DEBUG_BUILD
@ MHD_FEATURE_FLEXIBLE_FD_SETSIZE
@ MHD_FEATURE_HTTPS_KEY_PASSWORD
@ MHD_FEATURE_AUTOSUPPRESS_SIGPIPE
@ MHD_FEATURE_RESPONSES_SHARED_FD
@ MHD_FEATURE_DIGEST_AUTH_ALGO_SESSION
@ MHD_FEATURE_COOKIE_PARSING
@ MHD_FEATURE_DIGEST_AUTH_MD5
@ MHD_FEATURE_TCP_FASTOPEN
@ MHD_FEATURE_DIGEST_AUTH_RFC2069
@ MHD_FEATURE_HTTPS_CERT_CALLBACK2
@ MHD_OPTION_HTTPS_PRIORITIES_APPEND
@ MHD_OPTION_CONNECTION_MEMORY_INCREMENT
@ MHD_OPTION_HTTPS_CRED_TYPE
@ MHD_OPTION_URI_LOG_CALLBACK
@ MHD_OPTION_HTTPS_CERT_CALLBACK2
@ MHD_OPTION_DIGEST_AUTH_DEFAULT_NONCE_TIMEOUT
@ MHD_OPTION_CLIENT_DISCIPLINE_LVL
@ MHD_OPTION_SOCK_ADDR_LEN
@ MHD_OPTION_APP_FD_SETSIZE
@ MHD_OPTION_SIGPIPE_HANDLED_BY_APP
@ MHD_OPTION_UNESCAPE_CALLBACK
@ MHD_OPTION_EXTERNAL_LOGGER
@ MHD_OPTION_LISTEN_BACKLOG_SIZE
@ MHD_OPTION_HTTPS_PRIORITIES
@ MHD_OPTION_HTTPS_MEM_DHPARAMS
@ MHD_OPTION_NOTIFY_CONNECTION
@ MHD_OPTION_LISTENING_ADDRESS_REUSE
@ MHD_OPTION_THREAD_POOL_SIZE
@ MHD_OPTION_CONNECTION_LIMIT
@ MHD_OPTION_PER_IP_CONNECTION_LIMIT
@ MHD_OPTION_DIGEST_AUTH_DEFAULT_MAX_NC
@ MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE
@ MHD_OPTION_HTTPS_MEM_CERT
@ MHD_OPTION_SERVER_INSANITY
@ MHD_OPTION_LISTEN_SOCKET
@ MHD_OPTION_HTTPS_MEM_KEY
@ MHD_OPTION_DIGEST_AUTH_RANDOM
@ MHD_OPTION_HTTPS_KEY_PASSWORD
@ MHD_OPTION_NONCE_NC_SIZE
@ MHD_OPTION_ALLOW_BIN_ZERO_IN_URI_PATH
@ MHD_OPTION_CONNECTION_MEMORY_LIMIT
@ MHD_OPTION_THREAD_STACK_SIZE
@ MHD_OPTION_DIGEST_AUTH_RANDOM_COPY
@ MHD_OPTION_STRICT_FOR_CLIENT
@ MHD_OPTION_DIGEST_AUTH_NONCE_BIND_TYPE
@ MHD_OPTION_CONNECTION_TIMEOUT
@ MHD_OPTION_GNUTLS_PSK_CRED_HANDLER
@ MHD_OPTION_HTTPS_MEM_TRUST
@ MHD_OPTION_HTTPS_CERT_CALLBACK
@ MHD_OPTION_NOTIFY_COMPLETED
enum MHD_Result(* MHD_AcceptPolicyCallback)(void *cls, const struct sockaddr *addr, socklen_t addrlen)
#define MHD_UNSIGNED_LONG_LONG
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)
#define MHD_POSIX_SOCKETS
#define MHD_INVALID_SOCKET
int(* MHD_PskServerCredentialsCallback)(void *cls, const struct MHD_Connection *connection, const char *username, void **psk, size_t *psk_size)
@ MHD_DAEMON_INFO_MAC_KEY_SIZE
@ MHD_DAEMON_INFO_BIND_PORT
@ MHD_DAEMON_INFO_EPOLL_FD
@ MHD_DAEMON_INFO_KEY_SIZE
@ MHD_DAEMON_INFO_CURRENT_CONNECTIONS
@ MHD_DAEMON_INFO_LISTEN_FD
MHD_FLAG
Flags for the struct MHD_Daemon.
@ MHD_ALLOW_SUSPEND_RESUME
@ MHD_USE_THREAD_PER_CONNECTION
@ MHD_USE_POST_HANDSHAKE_AUTH_SUPPORT
@ MHD_USE_SELECT_INTERNALLY
@ MHD_USE_INSECURE_TLS_EARLY_DATA
@ MHD_USE_NO_LISTEN_SOCKET
@ MHD_USE_PEDANTIC_CHECKS
@ MHD_USE_INTERNAL_POLLING_THREAD
@ MHD_USE_NO_THREAD_SAFETY
@ MHD_DAUTH_BIND_NONCE_URI
@ MHD_DAUTH_BIND_NONCE_URI_PARAMS
Methods for managing response objects.
enum MHD_tristate sk_nodelay
struct MHD_Connection * prev
enum MHD_ConnectionEventLoopInfo event_loop_info
enum MHD_tristate is_nonip
struct MHD_Connection * nextX
struct MHD_Connection * next
size_t read_buffer_offset
enum MHD_CONNECTION_STATE state
struct MHD_Connection * prevX
struct MHD_Daemon * daemon
uint64_t connection_timeout_ms
struct sockaddr_storage * addr
enum MHD_tristate sk_corked
MHD_NotifyConnectionCallback notify_connection
MHD_AccessHandlerCallback default_handler
LogCallback uri_log_callback
bool data_already_pending
union MHD_DaemonInfo daemon_info_dummy_port
struct MHD_Connection * normal_timeout_tail
struct MHD_Connection * new_connections_tail
unsigned int connection_limit
void * unescape_callback_cls
enum MHD_DisableSanityCheck insanity_level
struct MHD_Connection * connections_tail
struct MHD_Connection * suspended_connections_tail
union MHD_DaemonInfo daemon_info_dummy_listen_fd
struct MHD_Connection * manual_timeout_head
unsigned int listen_backlog_size
struct MHD_Connection * normal_timeout_head
union MHD_DaemonInfo daemon_info_dummy_flags
MHD_RequestCompletedCallback notify_completed
struct MHD_Connection * cleanup_head
int listening_address_reuse
uint64_t connection_timeout_ms
unsigned int per_ip_connection_limit
struct MHD_Connection * manual_timeout_tail
union MHD_DaemonInfo daemon_info_dummy_num_connections
void * notify_connection_cls
struct MHD_Connection * cleanup_tail
UnescapeCallback unescape_callback
void * notify_completed_cls
volatile bool was_quiesced
struct MHD_Connection * suspended_connections_head
struct MHD_Connection * new_connections_head
enum MHD_tristate listen_is_unix
void * default_handler_cls
struct MHD_Connection * connections_head
MHD_AcceptPolicyCallback apc
void * per_ip_connection_count
void * uri_log_callback_cls
struct MHD_Daemon * master
struct MHD_Response * response
void * tfind(const void *vkey, void *const *vrootp, int(*compar)(const void *, const void *))
void * tdelete(const void *vkey, void **vrootp, int(*compar)(const void *, const void *))
void * tsearch(const void *vkey, void **vrootp, int(*compar)(const void *, const void *))
unsigned int num_connections