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"),
690 fd_set *write_fd_set,
691 fd_set *except_fd_set,
699#ifdef HAS_FD_SETSIZE_OVERRIDABLE
700 daemon->fdset_size_set_by_app ?
701 ((
unsigned int) daemon->fdset_size) :
710#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
724urh_to_fdset (
struct MHD_UpgradeResponseHandle *urh,
731 const MHD_socket conn_sckt = urh->connection->socket_fd;
735#ifndef HAS_FD_SETSIZE_OVERRIDABLE
737 fd_setsize = (int) FD_SETSIZE;
744 if ( (urh->in_buffer_used < urh->in_buffer_size) &&
750 if ( (0 != urh->out_buffer_used) &&
759 ((0 != urh->in_buffer_size) ||
760 (0 != urh->out_buffer_size) ||
761 (0 != urh->out_buffer_used))
770 if ( (urh->out_buffer_used < urh->out_buffer_size) &&
776 if ( (0 != urh->in_buffer_used) &&
785 ((0 != urh->out_buffer_size) ||
786 (0 != urh->in_buffer_size) ||
787 (0 != urh->in_buffer_used))
810urh_from_fdset (
struct MHD_UpgradeResponseHandle *urh,
816 const MHD_socket conn_sckt = urh->connection->socket_fd;
827#ifndef HAS_FD_SETSIZE_OVERRIDABLE
829 mhd_assert (((
int) FD_SETSIZE) <= fd_setsize);
830 fd_setsize = FD_SETSIZE;
883urh_update_pollfd (
struct MHD_UpgradeResponseHandle *urh,
889 if (urh->in_buffer_used < urh->in_buffer_size)
890 p[0].events |= POLLIN;
891 if (0 != urh->out_buffer_used)
892 p[0].events |= POLLOUT;
897 ((0 != urh->in_buffer_size) ||
898 (0 != urh->out_buffer_size) ||
899 (0 != urh->out_buffer_used)))
900 p[0].events |= MHD_POLL_EVENTS_ERR_DISC;
902 if (urh->out_buffer_used < urh->out_buffer_size)
903 p[1].events |= POLLIN;
904 if (0 != urh->in_buffer_used)
905 p[1].events |= POLLOUT;
910 ((0 != urh->out_buffer_size) ||
911 (0 != urh->in_buffer_size) ||
912 (0 != urh->in_buffer_used)))
913 p[1].events |= MHD_POLL_EVENTS_ERR_DISC;
924urh_to_pollfd (
struct MHD_UpgradeResponseHandle *urh,
927 p[0].fd = urh->connection->socket_fd;
928 p[1].fd = urh->mhd.socket;
929 urh_update_pollfd (urh,
940urh_from_pollfd (
struct MHD_UpgradeResponseHandle *urh,
949 if (0 != (p[0].revents & POLLIN))
951 if (0 != (p[0].revents & POLLOUT))
953 if (0 != (p[0].revents & POLLHUP))
955 if (0 != (p[0].revents & MHD_POLL_REVENTS_ERRROR))
957 if (0 != (p[1].revents & POLLIN))
959 if (0 != (p[1].revents & POLLOUT))
961 if (0 != (p[1].revents & POLLHUP))
963 if (0 != (p[1].revents & MHD_POLL_REVENTS_ERRROR))
989 fd_set *write_fd_set,
990 fd_set *except_fd_set,
1000#ifndef HAS_FD_SETSIZE_OVERRIDABLE
1002 fd_setsize = (int) FD_SETSIZE;
1057#ifdef MHD_POSIX_SOCKETS
1058 if (
NULL != except_fd_set)
1071#ifdef MHD_POSIX_SOCKETS
1072 if (
NULL != except_fd_set)
1080 if ( (
NULL == except_fd_set) ||
1092#ifdef MHD_WINSOCK_SOCKETS
1096 if (
NULL != except_fd_set)
1108#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
1111 struct MHD_UpgradeResponseHandle *urh;
1113 for (urh = daemon->urh_tail;
NULL != urh; urh = urh->prev)
1141#if _MHD_DEBUG_CONNECT
1145 _ (
"Maximum socket in select set: %d\n"),
1189 fd_set *read_fd_set,
1190 fd_set *write_fd_set,
1191 fd_set *except_fd_set,
1193 unsigned int fd_setsize)
1195 if ( (
NULL == daemon) ||
1196 (
NULL == read_fd_set) ||
1197 (
NULL == write_fd_set) ||
1203 if (
NULL == except_fd_set)
1206 _ (
"MHD_get_fdset2() called with except_fd_set "
1207 "set to NULL. Such behavior is unsupported.\n"));
1211#ifdef HAS_FD_SETSIZE_OVERRIDABLE
1212 if (0 == fd_setsize)
1214 else if (((
unsigned int)
INT_MAX) < fd_setsize)
1215 fd_setsize = (
unsigned int)
INT_MAX;
1217 else if (daemon->fdset_size > ((
int) fd_setsize))
1219 if (daemon->fdset_size_set_by_app)
1222 _ (
"%s() called with fd_setsize (%u) " \
1223 "less than value set by MHD_OPTION_APP_FD_SETSIZE (%d). " \
1224 "Some socket FDs may be not processed. " \
1225 "Use MHD_OPTION_APP_FD_SETSIZE with the correct value.\n"),
1226 "MHD_get_fdset2", fd_setsize, daemon->fdset_size);
1231 _ (
"%s() called with fd_setsize (%u) " \
1232 "less than FD_SETSIZE used by MHD (%d). " \
1233 "Some socket FDs may be not processed. " \
1234 "Consider using MHD_OPTION_APP_FD_SETSIZE option.\n"),
1235 "MHD_get_fdset2", fd_setsize, daemon->fdset_size);
1240 if (((
unsigned int) FD_SETSIZE) > fd_setsize)
1244 _ (
"%s() called with fd_setsize (%u) " \
1245 "less than fixed FD_SETSIZE value (%d) used on the " \
1247 "MHD_get_fdset2", fd_setsize, (
int) FD_SETSIZE);
1251 fd_setsize = (int) FD_SETSIZE;
1299 bool states_info_processed =
false;
1312 if (con->tls_read_ready)
1316 (read_ready || (force_close && con->
sk_nonblck)) )
1323 states_info_processed =
true;
1334 states_info_processed =
true;
1344 if (! states_info_processed)
1392 else if ( (con->tls_read_ready) &&
1401#ifdef UPGRADE_SUPPORT
1412 struct MHD_UpgradeResponseHandle *urh = connection->urh;
1420 gnutls_bye (connection->tls_session,
1429 connection->urh =
NULL;
1437#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
1447process_urh (
struct MHD_UpgradeResponseHandle *urh)
1460#ifdef MHD_USE_THREADS
1471 if (! urh->was_closed)
1474 _ (
"Initiated daemon shutdown while \"upgraded\" " \
1475 "connection was not closed.\n"));
1478 urh->was_closed =
true;
1480 was_closed = urh->was_closed;
1485 if (0 < urh->in_buffer_used)
1489 _ (
"Failed to forward to application %" PRIu64 \
1490 " bytes of data received from remote side: " \
1491 "application closed data forwarding.\n"),
1492 (uint64_t) urh->in_buffer_used);
1497 urh->in_buffer_used = 0;
1501 urh->in_buffer_size = 0;
1503 connection->tls_read_ready =
false;
1518 & urh->app.celi)) ||
1519 (connection->tls_read_ready)) &&
1520 (urh->in_buffer_used < urh->in_buffer_size))
1525 buf_size = urh->in_buffer_size - urh->in_buffer_used;
1529 res = gnutls_record_recv (connection->tls_session,
1530 &urh->in_buffer[urh->in_buffer_used],
1534 connection->tls_read_ready =
false;
1535 if (GNUTLS_E_INTERRUPTED != res)
1538 if ((GNUTLS_E_AGAIN != res) ||
1545 urh->in_buffer_size = 0;
1551 urh->in_buffer_used += (size_t) res;
1552 connection->tls_read_ready =
1553 (0 < gnutls_record_check_pending (connection->tls_session));
1568 && (urh->out_buffer_used < urh->out_buffer_size))
1573 buf_size = urh->out_buffer_size - urh->out_buffer_used;
1578 &urh->out_buffer[urh->out_buffer_used],
1598 urh->out_buffer_size = 0;
1604 urh->out_buffer_used += (size_t) res;
1605 if (buf_size > (
size_t) res)
1614 (urh->out_buffer_used > 0) )
1619 data_size = urh->out_buffer_used;
1623 res = gnutls_record_send (connection->tls_session,
1628 if (GNUTLS_E_INTERRUPTED != res)
1631 if (GNUTLS_E_AGAIN != res)
1637 _ (
"Failed to forward to remote client %" PRIu64 \
1638 " bytes of data received from application: %s\n"),
1639 (uint64_t) urh->out_buffer_used,
1640 gnutls_strerror ((
int) res));
1643 urh->out_buffer_used = 0;
1645 urh->out_buffer_size = 0;
1652 const size_t next_out_buffer_used = urh->out_buffer_used - (size_t) res;
1653 if (0 != next_out_buffer_used)
1655 memmove (urh->out_buffer,
1656 &urh->out_buffer[res],
1657 next_out_buffer_used);
1659 urh->out_buffer_used = next_out_buffer_used;
1661 if ( (0 == urh->out_buffer_used) &&
1669 urh->out_buffer_size = 0;
1678 (urh->in_buffer_used > 0) )
1683 data_size = urh->in_buffer_used;
1703 _ (
"Failed to forward to application %" PRIu64 \
1704 " bytes of data received from remote side: %s\n"),
1705 (uint64_t) urh->in_buffer_used,
1709 urh->in_buffer_used = 0;
1711 urh->in_buffer_size = 0;
1713 connection->tls_read_ready =
false;
1719 const size_t next_in_buffer_used = urh->in_buffer_used - (size_t) res;
1720 if (0 != next_in_buffer_used)
1722 memmove (urh->in_buffer,
1723 &urh->in_buffer[res],
1724 next_in_buffer_used);
1725 if (data_size > (
size_t) res)
1728 urh->in_buffer_used = next_in_buffer_used;
1730 if ( (0 == urh->in_buffer_used) &&
1736 urh->in_buffer_size = 0;
1738 connection->tls_read_ready =
false;
1744 if ( (connection->tls_read_ready) &&
1745 (urh->in_buffer_used < urh->in_buffer_size) &&
1750 ( (0 != urh->out_buffer_size) ||
1751 (0 != urh->out_buffer_used) ) )
1755 if (0 < urh->out_buffer_used)
1757 _ (
"Failed to forward to remote client %" PRIu64 \
1758 " bytes of data received from application: daemon shut down.\n"),
1759 (uint64_t) urh->out_buffer_used);
1762 urh->out_buffer_used = 0;
1766 urh->out_buffer_size = 0;
1770 if (! was_closed && urh->was_closed)
1777#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1778#ifdef UPGRADE_SUPPORT
1791 struct MHD_UpgradeResponseHandle *urh = con->urh;
1802 while ( (0 != urh->in_buffer_size) ||
1803 (0 != urh->out_buffer_size) ||
1804 (0 != urh->in_buffer_used) ||
1805 (0 != urh->out_buffer_used) )
1819 result = urh_to_fdset (urh,
1829 _ (
"Error preparing select.\n"));
1836 struct timeval *tvp;
1838 if (((con->tls_read_ready) &&
1839 (urh->in_buffer_used < urh->in_buffer_size)) ||
1864 _ (
"Error during select (%d): `%s'\n"),
1870 urh_from_fdset (urh,
1886 p[0].fd = urh->connection->socket_fd;
1887 p[1].fd = urh->mhd.socket;
1889 while ( (0 != urh->in_buffer_size) ||
1890 (0 != urh->out_buffer_size) ||
1891 (0 != urh->in_buffer_used) ||
1892 (0 != urh->out_buffer_used) )
1896 urh_update_pollfd (urh, p);
1898 if (((con->tls_read_ready) &&
1899 (urh->in_buffer_used < urh->in_buffer_size)) ||
1905 if (MHD_sys_poll_ (p,
1915 _ (
"Error during poll: `%s'\n"),
1920 urh_from_pollfd (urh,
1952 uint64_t mseconds_left;
1957 if (timeout < since_actv)
1964 if (5000 >= jump_back)
1972 else if (since_actv == timeout)
1981 mseconds_left = timeout - since_actv;
1983 return mseconds_left;
1994static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_
1995thread_main_handle_connection (
void *
data)
2006 unsigned int extra_slot;
2008#define EXTRA_SLOTS 1
2010#define EXTRA_SLOTS 0
2013 struct pollfd p[1 + EXTRA_SLOTS];
2019 const bool use_poll = 0;
2021 bool was_suspended =
false;
2027 bool use_zero_timeout;
2028#ifdef UPGRADE_SUPPORT
2029 struct MHD_UpgradeResponseHandle *
const urh = con->urh;
2031 static const void *
const urh =
NULL;
2038 was_suspended =
true;
2047 #ifdef HAVE_MESSAGES
2049 _ (
"Failed to add FD to fd_set.\n"));
2065 _ (
"Error during select (%d): `%s'\n"),
2075 p[0].events = POLLIN;
2076 p[0].fd = MHD_itc_r_fd_ (daemon->
itc);
2078 if (0 > MHD_sys_poll_ (p,
2086 _ (
"Error during poll: `%s'\n"),
2093 MHD_itc_clear_ (daemon->
itc);
2102 was_suspended =
false;
2108 || ( (con->tls_read_ready) &&
2115 bool err_state =
false;
2117 struct timeval *tvp;
2118 if (use_zero_timeout)
2126 const uint64_t mseconds_left = connection_get_wait (con);
2127#if (SIZEOF_UINT64_T - 2) >= SIZEOF_STRUCT_TIMEVAL_TV_SEC
2134 tv.tv_usec = ((uint16_t) (mseconds_left % 1000)) * ((int32_t) 1000);
2173 if (MHD_ITC_IS_VALID_ (daemon->
itc) )
2186 _ (
"Failed to add FD to fd_set.\n"));
2204 _ (
"Error during select (%d): `%s'\n"),
2213 if ( (MHD_ITC_IS_VALID_ (daemon->
itc)) &&
2214 (FD_ISSET (MHD_itc_r_fd_ (daemon->
itc),
2216 MHD_itc_clear_ (daemon->
itc);
2233 if (use_zero_timeout)
2237 const uint64_t mseconds_left = connection_get_wait (con);
2238#if SIZEOF_UINT64_T >= SIZEOF_INT
2243 timeout_val = (int) mseconds_left;
2255 p[0].events |= POLLIN | MHD_POLL_EVENTS_ERR_DISC;
2258 p[0].events |= POLLOUT | MHD_POLL_EVENTS_ERR_DISC;
2261 p[0].events |= MHD_POLL_EVENTS_ERR_DISC;
2269 if (MHD_ITC_IS_VALID_ (daemon->
itc))
2271 p[1].events |= POLLIN;
2272 p[1].fd = MHD_itc_r_fd_ (daemon->
itc);
2277 if (MHD_sys_poll_ (p,
2289 _ (
"Error during poll: `%s'\n"),
2297 if ( (MHD_ITC_IS_VALID_ (daemon->
itc)) &&
2298 (0 != (p[1].revents & (POLLERR | POLLHUP | POLLIN))) )
2299 MHD_itc_clear_ (daemon->
itc);
2303 (0 != (p[0].revents & POLLIN)),
2304 (0 != (p[0].revents & POLLOUT)),
2305 (0 != (p[0].revents & MHD_POLL_REVENTS_ERR_DISC)) ))
2309#ifdef UPGRADE_SUPPORT
2310 if (MHD_CONNECTION_UPGRADE == con->
state)
2322 thread_main_connection_upgrade (con);
2326 con->urh->clean_ready =
true;
2334 return (MHD_THRD_RTRN_TYPE_) 0;
2341 _ (
"Processing thread terminating. Closing connection.\n"));
2365 if ( (MHD_ITC_IS_VALID_ (daemon->
itc)) &&
2366 (! MHD_itc_activate_ (daemon->
itc,
"t")) )
2370 _ (
"Failed to signal thread termination via inter-thread " \
2371 "communication channel.\n"));
2374 return (MHD_THRD_RTRN_TYPE_) 0;
2391#if defined(HTTPS_SUPPORT)
2392#if defined(MHD_SEND_SPIPE_SUPPRESS_NEEDED) && \
2393 defined(MHD_SEND_SPIPE_SUPPRESS_POSSIBLE) && \
2394 ! defined(MHD_socket_nosignal_) && \
2395 (GNUTLS_VERSION_NUMBER + 0 < 0x030402) && defined(MSG_NOSIGNAL)
2401#define MHD_TLSLIB_NEED_PUSH_FUNC 1
2407#ifdef MHD_TLSLIB_NEED_PUSH_FUNC
2413MHD_tls_push_func_ (gnutls_transport_ptr_t trnsp,
2417#if (MHD_SCKT_SEND_MAX_SIZE_ < SSIZE_MAX) || (0 == SSIZE_MAX)
2437psk_gnutls_adapter (gnutls_session_t session,
2438 const char *username,
2439 gnutls_datum_t *key)
2443#if GNUTLS_VERSION_MAJOR >= 3
2445 size_t app_psk_size;
2448 connection = gnutls_session_get_ptr (session);
2449 if (
NULL == connection)
2453 MHD_PANIC (
_ (
"Internal server error. This should be impossible.\n"));
2457 daemon = connection->
daemon;
2458#if GNUTLS_VERSION_MAJOR >= 3
2459 if (
NULL == daemon->cred_callback)
2463 _ (
"PSK not supported by this server.\n"));
2467 if (0 != daemon->cred_callback (daemon->cred_callback_cls,
2477 _ (
"PSK authentication failed: PSK too long.\n"));
2482 if (
NULL == (key->data = gnutls_malloc (app_psk_size)))
2486 _ (
"PSK authentication failed: gnutls_malloc failed to " \
2487 "allocate memory.\n"));
2492 key->size = (
unsigned int) app_psk_size;
2499 (void) username; (void) key;
2502 _ (
"PSK not supported by this server.\n"));
2537 const struct sockaddr_storage *
addr,
2541 bool sk_spipe_supprs,
2548#if _MHD_DEBUG_CONNECT
2550 _ (
"Accepted connection on socket %d.\n"),
2562 _ (
"Server reached connection limit. " \
2563 "Closing inbound connection.\n"));
2566#if defined(ENFILE) && (ENFILE + 0 != 0)
2575 (
const struct sockaddr *)
addr,
2581 _ (
"Connection rejected by application. Closing connection.\n"));
2588#if defined(EACCESS) && (EACCESS + 0 != 0)
2599 _ (
"Error allocating memory: %s\n"),
2623 if (
NULL == (connection->
addr = malloc ((
size_t) addrlen)))
2628 _ (
"Error allocating memory: %s\n"),
2639 memcpy (connection->
addr,
2648 connection->
is_nonip = sk_is_nonip;
2650#ifdef MHD_USE_THREADS
2667#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030500)
2674 flags = GNUTLS_SERVER;
2675#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030402)
2676 flags |= GNUTLS_NO_SIGNAL;
2678#if GNUTLS_VERSION_MAJOR >= 3
2679 flags |= GNUTLS_NONBLOCK;
2681#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030603)
2683 flags |= GNUTLS_POST_HANDSHAKE_AUTH;
2685#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030605)
2687 flags |= GNUTLS_ENABLE_EARLY_DATA;
2691 if ((GNUTLS_E_SUCCESS != gnutls_init (&connection->tls_session, flags)) ||
2692 (GNUTLS_E_SUCCESS != gnutls_priority_set (connection->tls_session,
2693 daemon->priority_cache)))
2695 if (
NULL != connection->tls_session)
2696 gnutls_deinit (connection->tls_session);
2702 free (connection->
addr);
2706 _ (
"Failed to initialise TLS session.\n"));
2708#if defined(EPROTO) && (EPROTO + 0 != 0)
2713#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030200)
2714 if (!
daemon->disable_alpn)
2716 static const char prt1[] =
"http/1.1";
2717 static const char prt2[] =
"http/1.0";
2718 static const gnutls_datum_t prts[2] =
2722 if (GNUTLS_E_SUCCESS !=
2723 gnutls_alpn_set_protocols (connection->tls_session,
2725 sizeof(prts) /
sizeof(prts[0]),
2730 _ (
"Failed to set ALPN protocols.\n"));
2737 gnutls_session_set_ptr (connection->tls_session,
2739 switch (
daemon->cred_type)
2742 case GNUTLS_CRD_CERTIFICATE:
2743 gnutls_credentials_set (connection->tls_session,
2744 GNUTLS_CRD_CERTIFICATE,
2747 case GNUTLS_CRD_PSK:
2748 gnutls_credentials_set (connection->tls_session,
2751 gnutls_psk_set_server_credentials_function (
daemon->psk_cred,
2752 &psk_gnutls_adapter);
2754 case GNUTLS_CRD_ANON:
2755 case GNUTLS_CRD_SRP:
2760 _ (
"Failed to setup TLS credentials: " \
2761 "unknown credential type %d.\n"),
2764 gnutls_deinit (connection->tls_session);
2770 free (connection->
addr);
2772 MHD_PANIC (
_ (
"Unknown credential type.\n"));
2773#if defined(EINVAL) && (EINVAL + 0 != 0)
2778#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030109) && ! defined(_WIN64)
2779 gnutls_transport_set_int (connection->tls_session,
2780 (
int) (client_socket));
2782 gnutls_transport_set_ptr (connection->tls_session,
2783 (gnutls_transport_ptr_t) \
2784 (intptr_t) client_socket);
2786#ifdef MHD_TLSLIB_NEED_PUSH_FUNC
2787 gnutls_transport_set_push_function (connection->tls_session,
2788 MHD_tls_push_func_);
2790 if (
daemon->https_mem_trust)
2791 gnutls_certificate_server_set_request (connection->tls_session,
2792 GNUTLS_CERT_REQUEST);
2798 free (connection->
addr);
2800 MHD_PANIC (
_ (
"TLS connection on non-TLS daemon.\n"));
2813#ifdef MHD_USE_THREADS
2832 if (
NULL != connection->tls_session)
2835 gnutls_deinit (connection->tls_session);
2843 free (connection->
addr);
2869#ifdef MHD_USE_THREADS
2886 _ (
"Error allocating memory: %s\n"),
2889#if defined(ENOMEM) && (ENOMEM + 0 != 0)
2903 _ (
"Server reached connection limit. "
2904 "Closing inbound connection.\n"));
2906#if defined(ENFILE) && (ENFILE + 0 != 0)
2932#ifdef MHD_USE_THREADS
2938 daemon->thread_stack_size,
2939 &thread_main_handle_connection,
2947 _ (
"Failed to create a new thread because it would "
2948 "have exceeded the system limit on the number of "
2949 "threads or no system resources available.\n"));
2953 _ (
"Failed to create a thread: %s\n"),
2965#ifdef MHD_USE_THREADS
2966 connection->tid =
daemon->tid;
2973 struct epoll_event event;
2975 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET | EPOLLRDHUP;
2976 event.data.ptr = connection;
2977 if (0 != epoll_ctl (daemon->epoll_fd,
2985 _ (
"Call to epoll_ctl failed: %s\n"),
3002 daemon->eready_tail,
3036 if (
NULL != connection->tls_session)
3037 gnutls_deinit (connection->tls_session);
3043 free (connection->
addr);
3087 const struct sockaddr_storage *addr,
3091 bool sk_spipe_supprs,
3096#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3106 _ (
"New connection socket descriptor (%d) is not less " \
3107 "than FD_SETSIZE (%d).\n"),
3108 (
int) client_socket,
3112#if defined(ENFILE) && (ENFILE + 0 != 0)
3123 _ (
"Epoll mode supports only non-blocking sockets\n"));
3126#if defined(EINVAL) && (EINVAL + 0 != 0)
3139 if (
NULL == connection)
3142 if ((external_add) &&
3155 if ((MHD_ITC_IS_VALID_ (
daemon->
itc)) &&
3156 (! MHD_itc_activate_ (
daemon->
itc,
"n")))
3160 _ (
"Failed to signal new connection via inter-thread " \
3161 "communication channel.\n"));
3205 _ (
"Failed to start serving new connection.\n"));
3209 }
while (
NULL != local_tail);
3229#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3239#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3269 daemon->eready_tail,
3271 connection->epoll_state &=
3276 if (0 != epoll_ctl (daemon->epoll_fd,
3280 MHD_PANIC (
_ (
"Failed to remove FD from epoll set.\n"));
3281 connection->epoll_state &=
3287#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3326#ifdef MHD_USE_THREADS
3333 MHD_PANIC (
_ (
"Cannot suspend connections without " \
3334 "enabling MHD_ALLOW_SUSPEND_RESUME!\n"));
3335#ifdef UPGRADE_SUPPORT
3336 if (
NULL != connection->urh)
3340 _ (
"Error: connection scheduled for \"upgrade\" cannot " \
3341 "be suspended.\n"));
3368#if defined(MHD_USE_THREADS)
3373 MHD_PANIC (
_ (
"Cannot resume connections without enabling " \
3374 "MHD_ALLOW_SUSPEND_RESUME!\n"));
3375#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3380#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3383 if ( (MHD_ITC_IS_VALID_ (daemon->
itc)) &&
3384 (! MHD_itc_activate_ (daemon->
itc,
"r")) )
3388 _ (
"Failed to signal resume via inter-thread " \
3389 "communication channel.\n"));
3395#ifdef UPGRADE_SUPPORT
3404MHD_upgraded_connection_mark_app_closed_ (
struct MHD_Connection *connection)
3408#if defined(MHD_USE_THREADS)
3415 connection->urh->was_closed =
true;
3419 if ( (MHD_ITC_IS_VALID_ (daemon->
itc)) &&
3420 (! MHD_itc_activate_ (daemon->
itc,
"r")) )
3424 _ (
"Failed to signal resume via " \
3425 "inter-thread communication channel.\n"));
3450#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3457#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3473#ifdef UPGRADE_SUPPORT
3474 struct MHD_UpgradeResponseHandle *
const urh = pos->urh;
3476 static const void *
const urh =
NULL;
3480#ifdef UPGRADE_SUPPORT
3481 || ( (
NULL != urh) &&
3482 ( (! urh->was_closed) ||
3483 (! urh->clean_ready) ) )
3517 MHD_PANIC (
"Resumed connection was already in EREADY set.\n");
3521 daemon->eready_tail,
3530#ifdef UPGRADE_SUPPORT
3554#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3557 if ( (used_thr_p_c) &&
3560 if (! MHD_itc_activate_ (daemon->
itc,
3565 _ (
"Failed to signal resume of connection via " \
3566 "inter-thread communication channel.\n"));
3604 const struct sockaddr *addr,
3608 bool sk_spipe_supprs;
3609 struct sockaddr_storage addrstorage;
3621 _ (
"MHD_add_connection() has been called for daemon started"
3622 " without MHD_USE_ITC flag.\nDaemon will not process newly"
3623 " added connection until any activity occurs in already"
3624 " added sockets.\n"));
3629 if (AF_INET == addr->sa_family)
3631 if (
sizeof(
struct sockaddr_in) > (
size_t) addrlen)
3635 _ (
"MHD_add_connection() has been called with "
3636 "incorrect 'addrlen' value.\n"));
3640#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
3641 if ((0 != addr->sa_len) &&
3642 (
sizeof(
struct sockaddr_in) > (
size_t) addr->sa_len) )
3646 _ (
"MHD_add_connection() has been called with " \
3647 "non-zero value of 'sa_len' member of " \
3648 "'struct sockaddr' which does not match 'sa_family'.\n"));
3655 if (AF_INET6 == addr->sa_family)
3657 if (
sizeof(
struct sockaddr_in6) > (
size_t) addrlen)
3661 _ (
"MHD_add_connection() has been called with "
3662 "incorrect 'addrlen' value.\n"));
3666#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
3667 if ((0 != addr->sa_len) &&
3668 (
sizeof(
struct sockaddr_in6) > (
size_t) addr->sa_len) )
3672 _ (
"MHD_add_connection() has been called with " \
3673 "non-zero value of 'sa_len' member of " \
3674 "'struct sockaddr' which does not match 'sa_family'.\n"));
3680#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
3681 if ((0 != addr->sa_len) &&
3682 (addrlen > addr->sa_len))
3683 addrlen = (socklen_t) addr->sa_len;
3692 _ (
"Failed to set nonblocking mode on new client socket: %s\n"),
3700#ifndef MHD_WINSOCK_SOCKETS
3701 sk_spipe_supprs =
false;
3703 sk_spipe_supprs =
true;
3705#if defined(MHD_socket_nosignal_)
3706 if (! sk_spipe_supprs)
3707 sk_spipe_supprs = MHD_socket_nosignal_ (client_socket);
3708 if (! sk_spipe_supprs)
3712 _ (
"Failed to suppress SIGPIPE on new client socket: %s\n"),
3736 _ (
"Failed to set noninheritable mode on new client socket.\n"));
3742 memcpy (&addrstorage, addr, (
size_t) addrlen);
3743#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
3744 addrstorage.ss_len = addrlen;
3747#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3748 if (
NULL != daemon->worker_pool)
3754 for (i = 0; i < daemon->worker_pool_size; ++i)
3757 &daemon->worker_pool[(i + (
unsigned int) client_socket)
3758 % daemon->worker_pool_size];
3771#if defined(ENFILE) && (ENFILE + 0 != 0)
3806 struct sockaddr_storage addrstorage;
3811 bool sk_spipe_supprs;
3814#if defined(_DEBUG) && defined (USE_ACCEPT4)
3815 const bool use_accept4 = ! daemon->avoid_accept4;
3816#elif defined (USE_ACCEPT4)
3817 static const bool use_accept4 =
true;
3819 static const bool use_accept4 =
false;
3822#ifdef MHD_USE_THREADS
3832 addrlen = (socklen_t)
sizeof (addrstorage);
3833 memset (&addrstorage,
3836#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
3837 addrstorage.ss_len = addrlen;
3842 sk_spipe_supprs =
false;
3850 (
struct sockaddr *) &addrstorage,
3856#ifndef MHD_WINSOCK_SOCKETS
3859 sk_spipe_supprs =
true;
3864#if defined(_DEBUG) || ! defined(USE_ACCEPT4)
3865 if (! use_accept4 &&
3868 (
struct sockaddr *) &addrstorage,
3871#ifdef MHD_ACCEPT_INHERIT_NONBLOCK
3876#ifndef MHD_WINSOCK_SOCKETS
3877 sk_spipe_supprs =
false;
3879 sk_spipe_supprs =
true;
3898 _ (
"Error accepting connection: %s\n"),
3911 _ (
"Hit process or system resource limit at FIRST " \
3912 "connection. This is really bad as there is no sane " \
3913 "way to proceed. Will try busy waiting for system " \
3914 "resources to become magically available.\n"));
3919#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3923#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3928 _ (
"Hit process or system resource limit at %u " \
3929 "connections, temporarily suspending accept(). " \
3930 "Consider setting a lower MHD_OPTION_CONNECTION_LIMIT.\n"),
3944 _ (
"Accepted socket has zero-length address. "
3945 "Processing the new socket as a socket with " \
3946 "unknown type.\n"));
3951 if (((socklen_t)
sizeof (addrstorage)) < addrlen)
3957 _ (
"Accepted socket address is larger than expected by " \
3958 "system headers. Processing the new socket as a socket with " \
3959 "unknown type.\n"));
3969 _ (
"Failed to set nonblocking mode on incoming connection " \
3983 _ (
"Failed to set noninheritable mode on incoming connection " \
3990#if defined(MHD_socket_nosignal_)
3991 if (! sk_spipe_supprs && ! MHD_socket_nosignal_ (s))
3995 _ (
"Failed to suppress SIGPIPE on incoming connection " \
4012 sk_spipe_supprs =
true;
4015#if _MHD_DEBUG_CONNECT
4017 _ (
"Accepted connection on socket %d\n"),
4046#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
4058#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
4061 (! pos->thread_joined) &&
4063 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
4065#ifdef UPGRADE_SUPPORT
4066 cleanup_upgraded_connection (pos);
4070 if (
NULL != pos->tls_session)
4071 gnutls_deinit (pos->tls_session);
4094 if ( (-1 !=
daemon->epoll_fd) &&
4103 if (0 != epoll_ctl (
daemon->epoll_fd,
4107 MHD_PANIC (
_ (
"Failed to remove FD from epoll set.\n"));
4125#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
4131#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
4179#if SIZEOF_UINT64_T > SIZEOF_UNSIGNED_LONG_LONG
4227 uint64_t *timeout64)
4229 uint64_t earliest_deadline;
4233#ifdef MHD_USE_THREADS
4242 _ (
"Illegal call to MHD_get_timeout.\n"));
4259#
if defined(UPGRADE_SUPPORT) && defined(HTTPS_SUPPORT)
4270 earliest_tmot_conn =
NULL;
4271 earliest_deadline = 0;
4274 if ( (
NULL != pos) &&
4277 earliest_tmot_conn = pos;
4287 if ( (
NULL == earliest_tmot_conn) ||
4288 (earliest_deadline >
4291 earliest_tmot_conn = pos;
4297 if (
NULL != earliest_tmot_conn)
4299 *timeout64 = connection_get_wait (earliest_tmot_conn);
4306#if defined(HAVE_POLL) || defined(EPOLL_SUPPORT)
4354 return (int64_t) utimeout;
4400#if SIZEOF_INT >= SIZEOF_INT64_T
4423 int32_t max_timeout)
4426 mhd_assert (0 <= max_timeout || -1 == max_timeout);
4427 if (0 == max_timeout)
4433 if ((0 < max_timeout) && ((uint64_t) max_timeout < d_timeout))
4439 return (int64_t) d_timeout;
4456 int32_t max_timeout)
4460 res = get_timeout_millisec_ (
daemon, max_timeout);
4461#if SIZEOF_INT < SIZEOF_INT64_T
4484 const fd_set *read_fd_set,
4485 const fd_set *write_fd_set,
4486 const fd_set *except_fd_set,
4490#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4491 struct MHD_UpgradeResponseHandle *urh;
4492 struct MHD_UpgradeResponseHandle *urhn;
4504#ifndef HAS_FD_SETSIZE_OVERRIDABLE
4506 mhd_assert (((
int) FD_SETSIZE) <= fd_setsize);
4507 fd_setsize = FD_SETSIZE;
4513 if (MHD_ITC_IS_VALID_ (daemon->
itc))
4515 bool need_to_clear_itc =
true;
4518 need_to_clear_itc = FD_ISSET (MHD_itc_r_fd_ (daemon->
itc), \
4520 if (need_to_clear_itc)
4521 MHD_itc_clear_ (daemon->
itc);
4537 bool need_to_accept;
4539 need_to_accept = FD_ISSET (ds,
4568 r_ready = FD_ISSET (cs,
4570 w_ready = FD_ISSET (cs,
4572 has_err = (
NULL != except_fd_set) &&
4589#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4591 for (urh =
daemon->urh_tail;
NULL != urh; urh = urhn)
4595 urh_from_fdset (urh,
4603 if ( (0 == urh->in_buffer_size) &&
4604 (0 == urh->out_buffer_size) &&
4605 (0 == urh->in_buffer_used) &&
4606 (0 == urh->out_buffer_used) )
4609 urh->clean_ready =
true;
4620#undef MHD_run_from_select
4655 const fd_set *read_fd_set,
4656 const fd_set *write_fd_set,
4657 const fd_set *except_fd_set,
4658 unsigned int fd_setsize)
4663 if ((
NULL == read_fd_set) || (
NULL == write_fd_set))
4666 if (
NULL == except_fd_set)
4669 _ (
"MHD_run_from_select() called with except_fd_set "
4670 "set to NULL. Such behavior is deprecated.\n"));
4674#ifdef HAS_FD_SETSIZE_OVERRIDABLE
4675 if (0 == fd_setsize)
4677 else if (((
unsigned int)
INT_MAX) < fd_setsize)
4678 fd_setsize = (
unsigned int)
INT_MAX;
4680 else if (
daemon->fdset_size > ((
int) fd_setsize))
4682 if (
daemon->fdset_size_set_by_app)
4685 _ (
"%s() called with fd_setsize (%u) " \
4686 "less than value set by MHD_OPTION_APP_FD_SETSIZE (%d). " \
4687 "Some socket FDs may be not processed. " \
4688 "Use MHD_OPTION_APP_FD_SETSIZE with the correct value.\n"),
4689 "MHD_run_from_select2", fd_setsize,
daemon->fdset_size);
4694 _ (
"%s() called with fd_setsize (%u) " \
4695 "less than FD_SETSIZE used by MHD (%d). " \
4696 "Some socket FDs may be not processed. " \
4697 "Consider using MHD_OPTION_APP_FD_SETSIZE option.\n"),
4698 "MHD_run_from_select2", fd_setsize,
daemon->fdset_size);
4703 if (((
unsigned int) FD_SETSIZE) > fd_setsize)
4707 _ (
"%s() called with fd_setsize (%u) " \
4708 "less than fixed FD_SETSIZE value (%d) used on the " \
4710 "MHD_run_from_select2", fd_setsize, (
int) FD_SETSIZE);
4769 const fd_set *read_fd_set,
4770 const fd_set *write_fd_set,
4771 const fd_set *except_fd_set)
4777#ifdef HAS_FD_SETSIZE_OVERRIDABLE
4778 daemon->fdset_size_set_by_app ?
4779 ((
unsigned int)
daemon->fdset_size) :
4807 struct timeval timeout;
4813 timeout.tv_usec = 0;
4839 _ (
"Could not obtain daemon fdsets.\n"));
4849 if (MHD_ITC_IS_VALID_ (daemon->
itc))
4858 MHD_DLOG (daemon,
_ (
"Could not add control inter-thread " \
4859 "communication channel FD to fdset.\n"));
4884 _ (
"Could not add listen socket to fdset.\n"));
4896 timeout.tv_usec = 0;
4903 uint64_t select_tmo;
4908 if ( (0 < millisec) &&
4909 (mhd_tmo > (uint64_t) millisec) )
4910 select_tmo = (uint64_t) millisec;
4912 select_tmo = mhd_tmo;
4915 else if (0 < millisec)
4917 select_tmo = (uint64_t) millisec;
4928#if (SIZEOF_UINT64_T - 2) >= SIZEOF_STRUCT_TIMEVAL_TV_SEC
4935 timeout.tv_usec = ((uint16_t) (select_tmo % 1000)) * ((int32_t) 1000);
4952 _ (
"select failed: %s\n"),
4982 unsigned int num_connections;
4985#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4986 struct MHD_UpgradeResponseHandle *urh;
4987 struct MHD_UpgradeResponseHandle *urhn;
5002 num_connections = 0;
5005#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5006 for (urh = daemon->urh_head;
NULL != urh; urh = urh->next)
5007 num_connections += 2;
5012 unsigned int poll_server;
5019 sizeof (
struct pollfd));
5024 _ (
"Error allocating memory: %s\n"),
5037 p[poll_server].fd = ls;
5038 p[poll_server].events = POLLIN;
5039 p[poll_server].revents = 0;
5040 poll_listen = (int) poll_server;
5044 if (MHD_ITC_IS_VALID_ (daemon->
itc))
5046 p[poll_server].fd = MHD_itc_r_fd_ (daemon->
itc);
5047 p[poll_server].events = POLLIN;
5048 p[poll_server].revents = 0;
5049 poll_itc_idx = (int) poll_server;
5053 timeout = get_timeout_millisec_int (daemon, millisec);
5063 p[poll_server + i].events |= POLLIN | MHD_POLL_EVENTS_ERR_DISC;
5066 p[poll_server + i].events |= POLLOUT | MHD_POLL_EVENTS_ERR_DISC;
5069 p[poll_server + i].events |= MHD_POLL_EVENTS_ERR_DISC;
5077#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5078 for (urh = daemon->urh_tail;
NULL != urh; urh = urh->prev)
5080 urh_to_pollfd (urh, &(p[poll_server + i]));
5084 if (0 == poll_server + num_connections)
5089 if (MHD_sys_poll_ (p,
5090 poll_server + num_connections,
5101 _ (
"poll failed: %s\n"),
5111 if ( (-1 != poll_itc_idx) &&
5112 (0 != (p[poll_itc_idx].revents & POLLIN)) )
5113 MHD_itc_clear_ (daemon->
itc);
5127 if ( (-1 != poll_listen) &&
5128 (0 != (p[poll_listen].revents & POLLIN)) )
5136 while (
NULL != (pos = prev))
5140 if (i >= num_connections)
5145 0 != (p[poll_server + i].revents & POLLIN),
5146 0 != (p[poll_server + i].revents & POLLOUT),
5147 0 != (p[poll_server + i].revents
5148 & MHD_POLL_REVENTS_ERR_DISC));
5151#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5152 for (urh = daemon->urh_tail;
NULL != urh; urh = urhn)
5154 if (i >= num_connections)
5161 if ((p[poll_server + i].
fd != urh->connection->socket_fd) ||
5162 (p[poll_server + i + 1].fd != urh->mhd.socket))
5164 urh_from_pollfd (urh,
5165 &p[poll_server + i]);
5169 if ( (0 == urh->in_buffer_size) &&
5170 (0 == urh->out_buffer_size) &&
5171 (0 == urh->in_buffer_used) &&
5172 (0 == urh->out_buffer_used) )
5177 urh->clean_ready =
true;
5201MHD_poll_listen_socket (
struct MHD_Daemon *daemon,
5206 unsigned int poll_count;
5224 p[poll_count].fd = ls;
5225 p[poll_count].events = POLLIN;
5226 p[poll_count].revents = 0;
5227 poll_listen = (int) poll_count;
5230 if (MHD_ITC_IS_VALID_ (daemon->
itc))
5232 p[poll_count].fd = MHD_itc_r_fd_ (daemon->
itc);
5233 p[poll_count].events = POLLIN;
5234 p[poll_count].revents = 0;
5235 poll_itc_idx = (int) poll_count;
5246 if (0 == poll_count)
5248 if (MHD_sys_poll_ (p,
5258 _ (
"poll failed: %s\n"),
5263 if ( (0 <= poll_itc_idx) &&
5264 (0 != (p[poll_itc_idx].revents & POLLIN)) )
5265 MHD_itc_clear_ (daemon->
itc);
5275 if ( (0 <= poll_listen) &&
5276 (0 != (p[poll_listen].revents & POLLIN)) )
5298 return MHD_poll_all (daemon,
5299 may_block ? -1 : 0);
5300 return MHD_poll_listen_socket (daemon,
5318#define MAX_EVENTS 128
5321#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5331is_urh_ready (
struct MHD_UpgradeResponseHandle *
const urh)
5335 if ( (0 == urh->in_buffer_size) &&
5336 (0 == urh->out_buffer_size) &&
5337 (0 == urh->in_buffer_used) &&
5338 (0 == urh->out_buffer_used) )
5343 & urh->app.celi)) ||
5344 (connection->tls_read_ready) ) &&
5345 (urh->in_buffer_used < urh->in_buffer_size) )
5348 & urh->mhd.celi)) ||
5350 (urh->out_buffer_used < urh->out_buffer_size) )
5353 (urh->out_buffer_used > 0) )
5356 (urh->in_buffer_used > 0) )
5373 struct epoll_event events[MAX_EVENTS];
5375 struct MHD_UpgradeResponseHandle *pos;
5376 struct MHD_UpgradeResponseHandle *prev;
5378#ifdef MHD_USE_THREADS
5383 num_events = MAX_EVENTS;
5384 while (0 != num_events)
5388 num_events = epoll_wait (daemon->epoll_upgrade_fd,
5392 if (-1 == num_events)
5400 _ (
"Call to epoll_wait failed: %s\n"),
5405 for (i = 0; i < (
unsigned int) num_events; i++)
5407 struct UpgradeEpollHandle *
const ueh = events[i].data.ptr;
5408 struct MHD_UpgradeResponseHandle *
const urh = ueh->urh;
5409 bool new_err_state =
false;
5411 if (urh->clean_ready)
5415 if (0 != (events[i].events & EPOLLIN))
5419 if (0 != (events[i].events & EPOLLOUT))
5423 if (0 != (events[i].events & EPOLLHUP))
5429 (0 != (events[i].events & (EPOLLERR | EPOLLPRI))) )
5434 new_err_state =
true;
5436 if (! urh->in_eready_list)
5438 if (new_err_state ||
5442 daemon->eready_urh_tail,
5444 urh->in_eready_list =
true;
5449 prev = daemon->eready_urh_tail;
5450 while (
NULL != (pos = prev))
5454 if (! is_urh_ready (pos))
5457 daemon->eready_urh_tail,
5459 pos->in_eready_list =
false;
5462 if ( (0 == pos->in_buffer_size) &&
5463 (0 == pos->out_buffer_size) &&
5464 (0 == pos->in_buffer_used) &&
5465 (0 == pos->out_buffer_used) )
5468 pos->clean_ready =
true;
5487static const char *
const epoll_itc_marker =
"itc_marker";
5503#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5504 static const char *
const upgrade_marker =
"upgrade_ptr";
5508 struct epoll_event events[MAX_EVENTS];
5509 struct epoll_event event;
5514#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5515 bool run_upgraded =
false;
5517 bool need_to_accept;
5526 if (-1 == daemon->epoll_fd)
5533 (! daemon->listen_socket_in_epoll) &&
5536 event.events = EPOLLIN | EPOLLRDHUP;
5537 event.data.ptr = daemon;
5538 if (0 != epoll_ctl (daemon->epoll_fd,
5545 _ (
"Call to epoll_ctl failed: %s\n"),
5550 daemon->listen_socket_in_epoll =
true;
5553 (daemon->listen_socket_in_epoll) )
5555 if ( (0 != epoll_ctl (daemon->epoll_fd,
5561 MHD_PANIC (
"Failed to remove listen FD from epoll set.\n");
5562 daemon->listen_socket_in_epoll =
false;
5565#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5566 if ( ( (! daemon->upgrade_fd_in_epoll) &&
5567 (-1 != daemon->epoll_upgrade_fd) ) )
5569 event.events = EPOLLIN | EPOLLOUT | EPOLLRDHUP;
5571 if (0 != epoll_ctl (daemon->epoll_fd,
5573 daemon->epoll_upgrade_fd,
5578 _ (
"Call to epoll_ctl failed: %s\n"),
5583 daemon->upgrade_fd_in_epoll =
true;
5586 if ( (daemon->listen_socket_in_epoll) &&
5593 if (0 != epoll_ctl (daemon->epoll_fd,
5597 MHD_PANIC (
_ (
"Failed to remove listen FD from epoll set.\n"));
5598 daemon->listen_socket_in_epoll =
false;
5605 timeout_ms = get_timeout_millisec_int (daemon,
5613 need_to_accept =
false;
5618 num_events = MAX_EVENTS;
5619 while (MAX_EVENTS == num_events)
5622 num_events = epoll_wait (daemon->epoll_fd,
5626 if (-1 == num_events)
5633 _ (
"Call to epoll_wait failed: %s\n"),
5638 for (i = 0; i < (
unsigned int) num_events; i++)
5644#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5645 if (upgrade_marker == events[i].
data.ptr)
5649 run_upgraded =
true;
5653 if (epoll_itc_marker == events[i].
data.ptr)
5657 MHD_itc_clear_ (daemon->
itc);
5660 if (daemon == events[i].
data.ptr)
5664 if (0 == (events[i].events & (EPOLLERR | EPOLLHUP)))
5665 need_to_accept =
true;
5671 pos = events[i].data.ptr;
5673 if (0 != (events[i].events & (EPOLLPRI | EPOLLERR | EPOLLHUP)))
5679 daemon->eready_tail,
5686 if (0 != (events[i].events & EPOLLIN))
5694 daemon->eready_tail,
5699 if (0 != (events[i].events & EPOLLOUT))
5706 daemon->eready_tail,
5721 unsigned int series_length = 0;
5728 (series_length < 10) &&
5743 while (
NULL != (pos = prev))
5753 while (
NULL != (pos = prev))
5761#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5762 if (run_upgraded || (
NULL != daemon->eready_urh_head))
5763 run_epoll_for_upgrade (daemon);
5767 prev = daemon->eready_tail;
5768 while (
NULL != (pos = prev))
5786 daemon->eready_tail,
5894 res = MHD_poll_all (daemon, millisec);
5902 res = MHD_epoll (daemon, millisec);
5910#ifdef HAS_FD_SETSIZE_OVERRIDABLE
5912 if (daemon->fdset_size_set_by_app
5913 && (((
int) FD_SETSIZE) < daemon->fdset_size))
5916 _ (
"MHD_run()/MHD_run_wait() called for daemon started with " \
5917 "MHD_OPTION_APP_FD_SETSIZE option (%d). " \
5918 "The library was compiled with smaller FD_SETSIZE (%d). " \
5919 "Some socket FDs may be not processed. " \
5920 "Use MHD_run_from_select2() instead of MHD_run() or " \
5921 "do not use MHD_OPTION_APP_FD_SETSIZE option.\n"),
5922 daemon->fdset_size, (
int) FD_SETSIZE);
5947#ifdef MHD_USE_THREADS
5960#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5980#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5986#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5994static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_
5995MHD_polling_thread (
void *cls)
5998#ifdef HAVE_PTHREAD_SIGMASK
6004#ifdef HAVE_PTHREAD_SIGMASK
6005 if ((0 == sigemptyset (&s_mask)) &&
6006 (0 == sigaddset (&s_mask, SIGPIPE)))
6008 err = pthread_sigmask (SIG_BLOCK, &s_mask,
NULL);
6017 _ (
"Failed to block SIGPIPE on daemon thread: %s\n"),
6030 MHD_epoll (daemon, -1);
6044 return (MHD_THRD_RTRN_TYPE_) 0;
6079 MHD_DLOG (connection->
daemon,
6080 _ (
"The URL encoding is broken.\n"));
6155#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6169 _ (
"Using MHD_quiesce_daemon in this mode " \
6170 "requires MHD_USE_ITC.\n"));
6175#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6176 if (
NULL != daemon->worker_pool)
6177 for (i = 0; i < daemon->worker_pool_size; i++)
6182 (-1 != daemon->worker_pool[i].epoll_fd) &&
6183 (daemon->worker_pool[i].listen_socket_in_epoll) )
6185 if (0 != epoll_ctl (daemon->worker_pool[i].epoll_fd,
6189 MHD_PANIC (
_ (
"Failed to remove listen FD from epoll set.\n"));
6190 daemon->worker_pool[i].listen_socket_in_epoll =
false;
6194 if (MHD_ITC_IS_VALID_ (daemon->worker_pool[i].
itc))
6196 if (! MHD_itc_activate_ (daemon->worker_pool[i].
itc,
"q"))
6197 MHD_PANIC (
_ (
"Failed to signal quiesce via inter-thread " \
6198 "communication channel.\n"));
6205 (-1 != daemon->epoll_fd) &&
6206 (daemon->listen_socket_in_epoll) )
6208 if ( (0 != epoll_ctl (daemon->epoll_fd,
6214 MHD_PANIC (
"Failed to remove listen FD from epoll set.\n");
6215 daemon->listen_socket_in_epoll =
false;
6218 if ( (MHD_ITC_IS_VALID_ (daemon->
itc)) &&
6219 (! MHD_itc_activate_ (daemon->
itc,
"q")) )
6220 MHD_PANIC (
_ (
"failed to signal quiesce via inter-thread " \
6221 "communication channel.\n"));
6231struct MHD_InterimParams_
6244 bool fdset_size_set;
6260 bool pserver_addr_set;
6264 const struct sockaddr *pserver_addr;
6268 bool server_addr_len_set;
6272 socklen_t server_addr_len;
6299 struct MHD_InterimParams_ *params,
6314 struct MHD_InterimParams_ *params,
6320 va_start (ap, params);
6333enum MHD_TlsPrioritiesBaseType
6335 MHD_TLS_PRIO_BASE_LIBMHD = 0,
6336 MHD_TLS_PRIO_BASE_SYSTEM = 1,
6337#if GNUTLS_VERSION_NUMBER >= 0x030300
6338 MHD_TLS_PRIO_BASE_DEFAULT,
6340 MHD_TLS_PRIO_BASE_NORMAL
6346#if GNUTLS_VERSION_NUMBER >= 0x030300
6358daemon_tls_priorities_init_default (
struct MHD_Daemon *daemon)
6365 mhd_assert (MHD_TLS_PRIO_BASE_NORMAL + 1 == \
6366 sizeof(MHD_TlsBasePriotities) /
sizeof(MHD_TlsBasePriotities[0]));
6368 res = GNUTLS_E_SUCCESS;
6371 p <
sizeof(MHD_TlsBasePriotities) /
sizeof(MHD_TlsBasePriotities[0]);
6374 res = gnutls_priority_init (&daemon->priority_cache,
6375 MHD_TlsBasePriotities[p].str,
NULL);
6376 if (GNUTLS_E_SUCCESS == res)
6380 switch ((
enum MHD_TlsPrioritiesBaseType) p)
6382 case MHD_TLS_PRIO_BASE_LIBMHD:
6384 _ (
"GnuTLS priorities have been initialised with " \
6385 "@LIBMICROHTTPD application-specific system-wide " \
6386 "configuration.\n") );
6388 case MHD_TLS_PRIO_BASE_SYSTEM:
6390 _ (
"GnuTLS priorities have been initialised with " \
6391 "@SYSTEM system-wide configuration.\n") );
6393#if GNUTLS_VERSION_NUMBER >= 0x030300
6394 case MHD_TLS_PRIO_BASE_DEFAULT:
6396 _ (
"GnuTLS priorities have been initialised with " \
6397 "GnuTLS default configuration.\n") );
6400 case MHD_TLS_PRIO_BASE_NORMAL:
6402 _ (
"GnuTLS priorities have been initialised with " \
6403 "NORMAL configuration.\n") );
6415 _ (
"Failed to set GnuTLS priorities. Last error: %s\n"),
6416 gnutls_strerror (res));
6432daemon_tls_priorities_init_append_inner_ (
struct MHD_Daemon *daemon,
6436 const size_t buf_size)
6440 const char *err_pos;
6445 mhd_assert (MHD_TLS_PRIO_BASE_NORMAL + 1 == \
6446 sizeof(MHD_TlsBasePriotities) /
sizeof(MHD_TlsBasePriotities[0]));
6448 res = GNUTLS_E_SUCCESS;
6451 p <
sizeof(MHD_TlsBasePriotities) /
sizeof(MHD_TlsBasePriotities[0]);
6455#if GNUTLS_VERSION_NUMBER >= 0x030300
6456#if GNUTLS_VERSION_NUMBER >= 0x030603
6457 if (
NULL == MHD_TlsBasePriotities[p].
str)
6458 res = gnutls_priority_init2 (&daemon->priority_cache, prio, &err_pos,
6459 GNUTLS_PRIORITY_INIT_DEF_APPEND);
6463 if (
NULL == MHD_TlsBasePriotities[p].
str)
6474 memcpy (buf + buf_pos, MHD_TlsBasePriotities[p].
str,
6475 MHD_TlsBasePriotities[p].
len);
6476 buf_pos += MHD_TlsBasePriotities[p].
len;
6477 buf[buf_pos++] =
':';
6478 memcpy (buf + buf_pos, prio, prio_len + 1);
6480 buf_pos += prio_len + 1;
6483 res = gnutls_priority_init (&daemon->priority_cache, buf, &err_pos);
6485 if (GNUTLS_E_SUCCESS == res)
6489 switch ((
enum MHD_TlsPrioritiesBaseType) p)
6491 case MHD_TLS_PRIO_BASE_LIBMHD:
6493 _ (
"GnuTLS priorities have been initialised with " \
6494 "priorities specified by application appended to " \
6495 "@LIBMICROHTTPD application-specific system-wide " \
6496 "configuration.\n") );
6498 case MHD_TLS_PRIO_BASE_SYSTEM:
6500 _ (
"GnuTLS priorities have been initialised with " \
6501 "priorities specified by application appended to " \
6502 "@SYSTEM system-wide configuration.\n") );
6504#if GNUTLS_VERSION_NUMBER >= 0x030300
6505 case MHD_TLS_PRIO_BASE_DEFAULT:
6507 _ (
"GnuTLS priorities have been initialised with " \
6508 "priorities specified by application appended to " \
6509 "GnuTLS default configuration.\n") );
6512 case MHD_TLS_PRIO_BASE_NORMAL:
6514 _ (
"GnuTLS priorities have been initialised with " \
6515 "priorities specified by application appended to " \
6516 "NORMAL configuration.\n") );
6528 _ (
"Failed to set GnuTLS priorities. Last error: %s. " \
6529 "The problematic part starts at: %s\n"),
6530 gnutls_strerror (res), err_pos);
6536#define LOCAL_BUFF_SIZE 128
6547daemon_tls_priorities_init_append (
struct MHD_Daemon *daemon,
const char *prio)
6552 size_t buf_size_needed;
6555 return daemon_tls_priorities_init_default (daemon);
6560 prio_len = strlen (prio);
6562 buf_size_needed = longest_base_prio + 1 + prio_len + 1;
6564 if (LOCAL_BUFF_SIZE >= buf_size_needed)
6566 char local_buffer[LOCAL_BUFF_SIZE];
6567 ret = daemon_tls_priorities_init_append_inner_ (daemon, prio, prio_len,
6573 char *allocated_buffer;
6574 allocated_buffer = (
char *) malloc (buf_size_needed);
6575 if (
NULL == allocated_buffer)
6579 _ (
"Error allocating memory: %s\n"),
6584 ret = daemon_tls_priorities_init_append_inner_ (daemon, prio, prio_len,
6587 free (allocated_buffer);
6606 struct MHD_InterimParams_ *params,
6615#if GNUTLS_VERSION_MAJOR >= 3
6616 gnutls_certificate_retrieve_function2 * pgcrf;
6618#if GNUTLS_VERSION_NUMBER >= 0x030603
6619 gnutls_certificate_retrieve_function3 * pgcrf2;
6644 _ (
"Warning: specified " \
6645 "MHD_OPTION_CONNECTION_MEMORY_LIMIT " \
6646 "value is too small and rounded up to 64.\n"));
6670 _ (
"Warning: specified " \
6671 "MHD_OPTION_CONNECTION_MEMORY_INCREMENT value is " \
6672 "too large and rounded down to 1/4 of " \
6673 "MHD_OPTION_CONNECTION_MEMORY_LIMIT.\n"));
6687#if (SIZEOF_UINT64_T - 2) <= SIZEOF_UNSIGNED_INT
6692 _ (
"The specified connection timeout (%u) is too large. " \
6693 "Maximum allowed value (%" PRIu64 ") will be used " \
6720 params->server_addr_len = va_arg (ap,
6722 params->server_addr_len_set =
true;
6723 params->pserver_addr = va_arg (ap,
6724 const struct sockaddr *);
6725 params->pserver_addr_set =
true;
6728 params->server_addr_len_set =
false;
6729 params->pserver_addr = va_arg (ap,
6730 const struct sockaddr *);
6731 params->pserver_addr_set =
true;
6744#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6746 daemon->worker_pool_size = va_arg (ap,
6748 if (0 == daemon->worker_pool_size)
6752 else if (1 == daemon->worker_pool_size)
6756 _ (
"Warning: value \"1\", specified as the thread pool " \
6757 "size, is ignored. Thread pool is not used.\n"));
6759 daemon->worker_pool_size = 0;
6761#if SIZEOF_UNSIGNED_INT >= (SIZEOF_SIZE_T - 2)
6765 else if (daemon->worker_pool_size >=
6770 _ (
"Specified thread pool size (%u) too big.\n"),
6771 daemon->worker_pool_size);
6782 _ (
"MHD_OPTION_THREAD_POOL_SIZE option is specified but "
6783 "MHD_USE_INTERNAL_POLLING_THREAD flag is not specified.\n"));
6791 _ (
"Both MHD_OPTION_THREAD_POOL_SIZE option and "
6792 "MHD_USE_THREAD_PER_CONNECTION flag are specified.\n"));
6804 daemon->https_mem_key = pstr;
6808 _ (
"MHD HTTPS option %d passed to MHD but " \
6809 "MHD_USE_TLS not set.\n"),
6817 daemon->https_key_password = pstr;
6821 _ (
"MHD HTTPS option %d passed to MHD but " \
6822 "MHD_USE_TLS not set.\n"),
6830 daemon->https_mem_cert = pstr;
6834 _ (
"MHD HTTPS option %d passed to MHD but " \
6835 "MHD_USE_TLS not set.\n"),
6843 daemon->https_mem_trust = pstr;
6847 _ (
"MHD HTTPS option %d passed to MHD but " \
6848 "MHD_USE_TLS not set.\n"),
6853 daemon->cred_type = (gnutls_credentials_type_t) va_arg (ap,
6861 gnutls_datum_t dhpar;
6864 if (gnutls_dh_params_init (&daemon->https_mem_dhparams) < 0)
6868 _ (
"Error initializing DH parameters.\n"));
6873 pstr_len = strlen (pstr);
6878 _ (
"Diffie-Hellman parameters string too long.\n"));
6882 dhpar.size = (
unsigned int) pstr_len;
6883 if (gnutls_dh_params_import_pkcs3 (daemon->https_mem_dhparams,
6885 GNUTLS_X509_FMT_PEM) < 0)
6889 _ (
"Bad Diffie-Hellman parameters format.\n"));
6891 gnutls_dh_params_deinit (daemon->https_mem_dhparams);
6894 daemon->have_dhparams =
true;
6899 _ (
"MHD HTTPS option %d passed to MHD but " \
6900 "MHD_USE_TLS not set.\n"),
6910 if (
NULL != daemon->priority_cache)
6911 gnutls_priority_deinit (daemon->priority_cache);
6916 const char *err_pos;
6917 init_res = gnutls_priority_init (&daemon->priority_cache,
6920 if (GNUTLS_E_SUCCESS != init_res)
6924 _ (
"Setting priorities to '%s' failed: %s " \
6925 "The problematic part starts at: %s\n"),
6927 gnutls_strerror (init_res),
6930 daemon->priority_cache =
NULL;
6937 daemon->priority_cache =
NULL;
6938 if (! daemon_tls_priorities_init_append (daemon, pstr))
6945 _ (
"MHD HTTPS option %d passed to MHD but " \
6946 "MHD_USE_TLS not set.\n"),
6951#if GNUTLS_VERSION_MAJOR < 3
6954 _ (
"MHD_OPTION_HTTPS_CERT_CALLBACK requires building " \
6955 "MHD with GnuTLS >= 3.0.\n"));
6960 gnutls_certificate_retrieve_function2 *);
6962 daemon->cert_callback = pgcrf;
6966 _ (
"MHD HTTPS option %d passed to MHD but " \
6967 "MHD_USE_TLS not set.\n"),
6973#if GNUTLS_VERSION_NUMBER < 0x030603
6976 _ (
"MHD_OPTION_HTTPS_CERT_CALLBACK2 requires building " \
6977 "MHD with GnuTLS >= 3.6.3.\n"));
6981 pgcrf2 = va_arg (ap,
6982 gnutls_certificate_retrieve_function3 *);
6984 daemon->cert_callback2 = pgcrf2;
6988 _ (
"MHD HTTPS option %d passed to MHD but " \
6989 "MHD_USE_TLS not set.\n"),
6998 daemon->digest_auth_rand_size = va_arg (ap,
7000 daemon->digest_auth_random = va_arg (ap,
7004 daemon->digest_auth_random_copy = daemon;
7006 daemon->digest_auth_random_copy =
NULL;
7009 daemon->nonce_nc_size = va_arg (ap,
7012 case MHD_OPTION_DIGEST_AUTH_NONCE_BIND_TYPE:
7013 daemon->dauth_bind_type = va_arg (ap,
7025 daemon->dauth_def_nonce_timeout = val;
7035 daemon->dauth_def_max_nc = val;
7042 case MHD_OPTION_DIGEST_AUTH_NONCE_BIND_TYPE:
7047 _ (
"Digest Auth is disabled for this build " \
7048 "of GNU libmicrohttpd.\n"));
7053 params->listen_fd = va_arg (ap,
7055 params->listen_fd_set =
true;
7059 daemon->custom_error_log = va_arg (ap,
7061 daemon->custom_error_log_cls = va_arg (ap,
7063 if (1 != params->num_opts)
7065 _ (
"MHD_OPTION_EXTERNAL_LOGGER is not the first option "
7066 "specified for the daemon. Some messages may be "
7067 "printed by the standard MHD logger.\n"));
7076#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7078 daemon->thread_stack_size = va_arg (ap,
7084 daemon->fastopen_queue_size = va_arg (ap,
7090 _ (
"TCP fastopen is not supported on this platform.\n"));
7096 unsigned int) ? 1 : -1;
7114 _ (
"Flag MHD_USE_PEDANTIC_CHECKS is ignored because "
7115 "another behaviour is specified by "
7116 "MHD_OPTION_STRICT_CLIENT.\n"));
7127 _ (
"Flag MHD_USE_PEDANTIC_CHECKS is ignored because "
7128 "another behaviour is specified by "
7129 "MHD_OPTION_CLIENT_DISCIPLINE_LVL.\n"));
7154 (
size_t) oa[i].
value,
7168 case MHD_OPTION_DIGEST_AUTH_NONCE_BIND_TYPE:
7173 (
unsigned int) oa[i].
value,
7183 (gnutls_credentials_type_t) oa[i].
value,
7216 (uint32_t) oa[i].
value,
7249 (
void *) oa[i].
value,
7260 (
size_t) oa[i].
value,
7270 (socklen_t) oa[i].
value,
7290#if GNUTLS_VERSION_MAJOR >= 3
7291 daemon->cred_callback = va_arg (ap,
7293 daemon->cred_callback_cls = va_arg (ap,
7298 _ (
"MHD HTTPS option %d passed to MHD compiled " \
7299 "without GNUtls >= 3.\n"),
7316 daemon->disable_alpn = (va_arg (ap,
7319 (void) va_arg (ap,
int);
7324 _ (
"MHD HTTPS option %d passed to MHD " \
7325 "but MHD_USE_TLS not set.\n"),
7330 params->fdset_size_set =
true;
7331 params->fdset_size = va_arg (ap,
7334#ifndef HTTPS_SUPPORT
7348 _ (
"MHD HTTPS option %d passed to MHD "
7349 "compiled without HTTPS support.\n"),
7358 _ (
"Invalid option %d! (Did you terminate "
7359 "the list with MHD_OPTION_END?).\n"),
7375#ifndef HAVE_MESSAGES
7379#ifdef USE_EPOLL_CREATE1
7380 fd = epoll_create1 (EPOLL_CLOEXEC);
7382 fd = epoll_create (MAX_EVENTS);
7388 _ (
"Call to epoll_create1 failed: %s\n"),
7393#if ! defined(USE_EPOLL_CREATE1)
7398 _ (
"Failed to set noninheritable mode on epoll FD.\n"));
7415setup_epoll_to_listen (
struct MHD_Daemon *daemon)
7417 struct epoll_event event;
7424 MHD_ITC_IS_VALID_ (daemon->
itc) );
7425 daemon->epoll_fd = setup_epoll_fd (daemon);
7440 _ (
"The epoll FD is too large to be used with fd_set.\n"));
7445 if (-1 == daemon->epoll_fd)
7447#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
7450 daemon->epoll_upgrade_fd = setup_epoll_fd (daemon);
7458 event.events = EPOLLIN | EPOLLRDHUP;
7459 event.data.ptr = daemon;
7460 if (0 != epoll_ctl (daemon->epoll_fd,
7467 _ (
"Call to epoll_ctl failed: %s\n"),
7472 daemon->listen_socket_in_epoll =
true;
7475 if (MHD_ITC_IS_VALID_ (daemon->
itc))
7477 event.events = EPOLLIN | EPOLLRDHUP;
7479 if (0 != epoll_ctl (daemon->epoll_fd,
7481 MHD_itc_r_fd_ (daemon->
itc),
7486 _ (
"Call to epoll_ctl failed: %s\n"),
7512 const struct sockaddr **ppsockaddr,
7513 socklen_t *psockaddr_len,
7514 struct MHD_InterimParams_ *params)
7516 if (params->fdset_size_set)
7518 if (0 >= params->fdset_size)
7522 _ (
"MHD_OPTION_APP_FD_SETSIZE value (%d) is not positive.\n"),
7523 params->fdset_size);
7531 _ (
"MHD_OPTION_APP_FD_SETSIZE is ignored for daemon started " \
7532 "with MHD_USE_INTERNAL_POLLING_THREAD.\n"));
7540 _ (
"MHD_OPTION_APP_FD_SETSIZE is ignored for daemon started " \
7541 "with MHD_USE_POLL.\n"));
7547#ifndef HAS_FD_SETSIZE_OVERRIDABLE
7548 if (((
int) FD_SETSIZE) != params->fdset_size)
7552 _ (
"MHD_OPTION_APP_FD_SETSIZE value (%d) does not match " \
7553 "the platform FD_SETSIZE value (%d) and this platform " \
7554 "does not support overriding of FD_SETSIZE.\n"),
7555 params->fdset_size, (
int) FD_SETSIZE);
7560 d->fdset_size = params->fdset_size;
7561 d->fdset_size_set_by_app =
true;
7566 if (params->listen_fd_set)
7572#ifdef HAS_SIGNED_SOCKET
7573 else if (0 > params->listen_fd)
7577 _ (
"The value provided for MHD_OPTION_LISTEN_SOCKET " \
7587 _ (
"MHD_OPTION_LISTEN_SOCKET specified for daemon "
7588 "with MHD_USE_NO_LISTEN_SOCKET flag set.\n"));
7597#ifdef MHD_USE_GETSOCKNAME
7603 mhd_assert (! params->server_addr_len_set || params->pserver_addr_set);
7604 if (params->pserver_addr_set)
7606 if (
NULL == params->pserver_addr)
7609 if (params->server_addr_len_set && (0 != params->server_addr_len))
7617 _ (
"MHD_OPTION_LISTEN_SOCKET cannot be used together with " \
7618 "MHD_OPTION_SOCK_ADDR_LEN or MHD_OPTION_SOCK_ADDR.\n"));
7626 _ (
"MHD_OPTION_SOCK_ADDR_LEN or MHD_OPTION_SOCK_ADDR " \
7627 "specified for daemon with MHD_USE_NO_LISTEN_SOCKET " \
7639 *ppsockaddr = params->pserver_addr;
7640 if (params->server_addr_len_set)
7643 if (0 == params->server_addr_len)
7645 *psockaddr_len = params->server_addr_len;
7687 const struct sockaddr *pservaddr =
NULL;
7689#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7694 struct MHD_InterimParams_ *interim_params;
7711#ifndef EPOLL_SUPPORT
7715#ifndef HTTPS_SUPPORT
7725#ifdef UPGRADE_SUPPORT
7731#ifdef MHD_USE_THREADS
7760#if defined(EPOLL_SUPPORT) && defined(HAVE_POLL)
7765#elif defined(HAVE_POLL)
7768#elif defined(EPOLL_SUPPORT)
7780#ifdef HAVE_LISTEN_SHUTDOWN
7788 interim_params = (
struct MHD_InterimParams_ *) \
7789 MHD_calloc_ (1,
sizeof (
struct MHD_InterimParams_));
7790 if (
NULL == interim_params)
7792 int err_num = errno;
7798 daemon->epoll_fd = -1;
7799#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
7800 daemon->epoll_upgrade_fd = -1;
7805 daemon->priority_cache =
NULL;
7814 daemon->
port = port;
7825 MHD_itc_set_invalid_ (daemon->
itc);
7826#ifdef MHD_USE_THREADS
7835 daemon->custom_error_log = &MHD_default_logger_;
7836 daemon->custom_error_log_cls = stderr;
7838#ifndef MHD_WINSOCK_SOCKETS
7844#if defined(_DEBUG) && defined(HAVE_ACCEPT4)
7845 daemon->avoid_accept4 =
false;
7847#ifdef HAS_FD_SETSIZE_OVERRIDABLE
7848 daemon->fdset_size = (int) FD_SETSIZE;
7849 daemon->fdset_size_set_by_app =
false;
7853 daemon->digest_auth_rand_size = 0;
7854 daemon->digest_auth_random =
NULL;
7855 daemon->nonce_nc_size = 4;
7862 daemon->cred_type = GNUTLS_CRD_CERTIFICATE;
7866 interim_params->num_opts = 0;
7867 interim_params->fdset_size_set =
false;
7868 interim_params->fdset_size = 0;
7869 interim_params->listen_fd_set =
false;
7871 interim_params->pserver_addr_set =
false;
7872 interim_params->pserver_addr =
NULL;
7873 interim_params->server_addr_len_set =
false;
7874 interim_params->server_addr_len = 0;
7882 (
NULL != daemon->priority_cache) )
7883 gnutls_priority_deinit (daemon->priority_cache);
7885 free (interim_params);
7894 free (interim_params);
7898 free (interim_params);
7899 interim_params =
NULL;
7902 && (
NULL == daemon->priority_cache)
7903 && ! daemon_tls_priorities_init_default (daemon))
7907 _ (
"Failed to initialise GnuTLS priorities.\n"));
7919 _ (
"Warning: MHD_USE_THREAD_PER_CONNECTION must be used " \
7920 "only with MHD_USE_INTERNAL_POLLING_THREAD. " \
7921 "Flag MHD_USE_INTERNAL_POLLING_THREAD was added. " \
7922 "Consider setting MHD_USE_INTERNAL_POLLING_THREAD " \
7935 _ (
"Using debug build of libmicrohttpd.\n") );
7940#
if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7941 && (0 == daemon->worker_pool_size)
7945 if (! MHD_itc_init_ (daemon->
itc))
7949 _ (
"Failed to create inter-thread communication channel: %s\n"),
7950 MHD_itc_last_strerror_ ());
7953 if (
NULL != daemon->priority_cache)
7954 gnutls_priority_deinit (daemon->priority_cache);
7964 _ (
"file descriptor for inter-thread communication " \
7965 "channel exceeds maximum value.\n"));
7969 if (
NULL != daemon->priority_cache)
7970 gnutls_priority_deinit (daemon->priority_cache);
7978 if (
NULL != daemon->digest_auth_random_copy)
7980 mhd_assert (daemon == daemon->digest_auth_random_copy);
7981 daemon->digest_auth_random_copy = malloc (daemon->digest_auth_rand_size);
7982 if (
NULL == daemon->digest_auth_random_copy)
7986 gnutls_priority_deinit (daemon->priority_cache);
7991 memcpy (daemon->digest_auth_random_copy,
7992 daemon->digest_auth_random,
7993 daemon->digest_auth_rand_size);
7994 daemon->digest_auth_random = daemon->digest_auth_random_copy;
7996 if (daemon->nonce_nc_size > 0)
7998 if ( ( (
size_t) (daemon->nonce_nc_size * sizeof (
struct MHD_NonceNc)))
7999 /
sizeof(
struct MHD_NonceNc) != daemon->nonce_nc_size)
8003 _ (
"Specified value for NC_SIZE too large.\n"));
8007 gnutls_priority_deinit (daemon->priority_cache);
8009 free (daemon->digest_auth_random_copy);
8015 if (
NULL == daemon->nnc)
8019 _ (
"Failed to allocate memory for nonce-nc map: %s\n"),
8024 gnutls_priority_deinit (daemon->priority_cache);
8026 free (daemon->digest_auth_random_copy);
8032#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8037 _ (
"MHD failed to initialize nonce-nc mutex.\n"));
8041 gnutls_priority_deinit (daemon->priority_cache);
8043 free (daemon->digest_auth_random_copy);
8052#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8054 (daemon->worker_pool_size > 0) )
8058 _ (
"MHD thread polling only works with " \
8059 "MHD_USE_INTERNAL_POLLING_THREAD.\n"));
8069 struct sockaddr_in servaddr4;
8071 struct sockaddr_in6 servaddr6;
8074 const bool use_ipv6 =
false;
8078 if (
NULL != pservaddr)
8080#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
8081 const socklen_t sa_len = pservaddr->sa_len;
8084 if (use_ipv6 && (AF_INET6 != pservaddr->sa_family))
8088 _ (
"MHD_USE_IPv6 is enabled, but 'struct sockaddr *' " \
8089 "specified for MHD_OPTION_SOCK_ADDR_LEN or " \
8090 "MHD_OPTION_SOCK_ADDR is not IPv6 address.\n"));
8095 switch (pservaddr->sa_family)
8100 struct sockaddr_in sa4;
8103 && (((socklen_t)
sizeof(sa4)) > addrlen))
8107 _ (
"The size specified for MHD_OPTION_SOCK_ADDR_LEN " \
8108 "option is wrong.\n"));
8112#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
8115 if (((socklen_t)
sizeof(sa4)) > sa_len)
8119 _ (
"The value of 'struct sockaddr.sa_len' provided " \
8120 "via MHD_OPTION_SOCK_ADDR_LEN option is not zero " \
8121 "and does not match 'sa_family' value of the " \
8122 "same structure.\n"));
8126 if ((0 == addrlen) || (sa_len < addrlen))
8131 addrlen =
sizeof(sa4);
8132 memcpy (&sa4, pservaddr,
sizeof(sa4));
8133 sa4_port = (uint16_t) ntohs (sa4.sin_port);
8134#ifndef MHD_USE_GETSOCKNAME
8137 daemon->
port = sa4_port;
8145 struct sockaddr_in6 sa6;
8148 && (((socklen_t)
sizeof(sa6)) > addrlen))
8152 _ (
"The size specified for MHD_OPTION_SOCK_ADDR_LEN " \
8153 "option is wrong.\n"));
8157#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
8160 if (((socklen_t)
sizeof(sa6)) > sa_len)
8164 _ (
"The value of 'struct sockaddr.sa_len' provided " \
8165 "via MHD_OPTION_SOCK_ADDR_LEN option is not zero " \
8166 "and does not match 'sa_family' value of the " \
8167 "same structure.\n"));
8171 if ((0 == addrlen) || (sa_len < addrlen))
8176 addrlen =
sizeof(sa6);
8177 memcpy (&sa6, pservaddr,
sizeof(sa6));
8178 sa6_port = (uint16_t) ntohs (sa6.sin6_port);
8179#ifndef MHD_USE_GETSOCKNAME
8182 daemon->
port = sa6_port;
8192#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
8195 else if ((0 != sa_len) && (sa_len < addrlen))
8202 _ (
"The 'sa_family' of the 'struct sockaddr' provided " \
8203 "via MHD_OPTION_SOCK_ADDR option is not supported.\n"));
8208 if (AF_UNIX == pservaddr->sa_family)
8225 domain = pservaddr->sa_family;
8236 sizeof (
struct sockaddr_in));
8237 servaddr4.sin_family = AF_INET;
8238 servaddr4.sin_port = htons (port);
8239 if (0 != INADDR_ANY)
8240 servaddr4.sin_addr.s_addr = htonl (INADDR_ANY);
8241#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
8242 servaddr4.sin_len =
sizeof (
struct sockaddr_in);
8244 pservaddr = (
struct sockaddr *) &servaddr4;
8245 addrlen = (socklen_t)
sizeof(servaddr4);
8252#ifdef IN6ADDR_ANY_INIT
8253 static const struct in6_addr static_in6any = IN6ADDR_ANY_INIT;
8257 sizeof (
struct sockaddr_in6));
8258 servaddr6.sin6_family = AF_INET6;
8259 servaddr6.sin6_port = htons (port);
8260#ifdef IN6ADDR_ANY_INIT
8261 servaddr6.sin6_addr = static_in6any;
8263#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
8264 servaddr6.sin6_len =
sizeof (
struct sockaddr_in6);
8266 pservaddr = (
struct sockaddr *) &servaddr6;
8267 addrlen = (socklen_t)
sizeof (servaddr6);
8279 _ (
"Failed to create socket for listening: %s\n"),
8290 _ (
"Listen socket descriptor (%d) is not " \
8291 "less than daemon FD_SETSIZE value (%d).\n"),
8301#ifndef MHD_WINSOCK_SOCKETS
8309 (
const void *) &on, sizeof (on)))
8313 _ (
"setsockopt failed: %s\n"),
8322#ifndef MHD_WINSOCK_SOCKETS
8328 (
const void *) &on, sizeof (on)))
8332 _ (
"setsockopt failed: %s\n"),
8342#if defined(MHD_WINSOCK_SOCKETS) || defined(SO_REUSEPORT)
8345#ifndef MHD_WINSOCK_SOCKETS
8355 _ (
"setsockopt failed: %s\n"),
8365 _ (
"Cannot allow listening address reuse: " \
8366 "SO_REUSEPORT not defined.\n"));
8379#if (defined(MHD_WINSOCK_SOCKETS) && defined(SO_EXCLUSIVEADDRUSE)) || \
8380 (defined(__sun) && defined(SO_EXCLBIND))
8383#ifdef SO_EXCLUSIVEADDRUSE
8384 SO_EXCLUSIVEADDRUSE,
8393 _ (
"setsockopt failed: %s\n"),
8398#elif defined(MHD_WINSOCK_SOCKETS)
8401 _ (
"Cannot disallow listening address reuse: " \
8402 "SO_EXCLUSIVEADDRUSE not defined.\n"));
8420 IPPROTO_IPV6, IPV6_V6ONLY,
8421 (
const void *) &v6_only,
8426 _ (
"setsockopt failed: %s\n"),
8439 _ (
"Failed to bind to port %u: %s\n"),
8440 (
unsigned int) port,
8448 if (0 == daemon->fastopen_queue_size)
8449 daemon->fastopen_queue_size = MHD_TCP_FASTOPEN_QUEUE_SIZE_DEFAULT;
8453 (
const void *) &daemon->fastopen_queue_size,
8454 sizeof (daemon->fastopen_queue_size)))
8458 _ (
"setsockopt failed: %s\n"),
8469 _ (
"Failed to listen for connections: %s\n"),
8483 _ (
"Listen socket descriptor (%d) is not " \
8484 "less than daemon FD_SETSIZE value (%d).\n"),
8492#if defined(SOL_SOCKET) && (defined(SO_DOMAIN) || defined(SO_PROTOCOL_INFOW))
8496 socklen_t optval_size;
8498 opt_name = SO_DOMAIN;
8500 optval_size = (socklen_t)
sizeof (af);
8502 WSAPROTOCOL_INFOW prot_info;
8503 opt_name = SO_PROTOCOL_INFOW;
8504 poptval = &prot_info;
8505 optval_size = (socklen_t)
sizeof (prot_info);
8515 af = prot_info.iAddressFamily;
8545#ifdef MHD_USE_GETSOCKNAME
8550#ifdef MHD_USE_GETSOCKNAME
8551 if ( (0 == daemon->
port) &&
8555 struct sockaddr_storage bindaddr;
8559 sizeof (
struct sockaddr_storage));
8560 addrlen =
sizeof (
struct sockaddr_storage);
8561#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
8562 bindaddr.ss_len = (socklen_t) addrlen;
8564 if (0 != getsockname (daemon->
listen_fd,
8565 (
struct sockaddr *) &bindaddr,
8570 _ (
"Failed to get listen port number: %s\n"),
8571 MHD_socket_last_strerr_ ());
8575 else if (
sizeof (bindaddr) < addrlen)
8580 _ (
"Failed to get listen port number " \
8581 "(`struct sockaddr_storage` too small!?).\n"));
8585 else if (0 == addrlen)
8597 switch (bindaddr.ss_family)
8601 struct sockaddr_in *s4 = (
struct sockaddr_in *) &bindaddr;
8603 daemon->
port = ntohs (s4->sin_port);
8610 struct sockaddr_in6 *s6 = (
struct sockaddr_in6 *) &bindaddr;
8612 daemon->
port = ntohs (s6->sin6_port);
8627 _ (
"Listen socket has unknown address family!\n"));
8644 _ (
"Failed to set nonblocking mode on listening socket: %s\n"),
8648#
if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8649 || (daemon->worker_pool_size > 0)
8671#
if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8672 && (0 == daemon->worker_pool_size)
8680 _ (
"Combining MHD_USE_THREAD_PER_CONNECTION and " \
8681 "MHD_USE_EPOLL is not supported.\n"));
8685 if (
MHD_NO == setup_epoll_to_listen (daemon))
8690#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8695 _ (
"MHD failed to initialize IP connection limit mutex.\n"));
8704 (0 != MHD_TLS_init (daemon)) )
8708 _ (
"Failed to initialize TLS support.\n"));
8710#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8716#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8724#ifdef HAVE_LISTEN_SHUTDOWN
8725 mhd_assert ((1 < daemon->worker_pool_size) || \
8726 (MHD_ITC_IS_VALID_ (daemon->
itc)) || \
8729 mhd_assert ((1 < daemon->worker_pool_size) || \
8730 (MHD_ITC_IS_VALID_ (daemon->
itc)));
8732 if (0 == daemon->worker_pool_size)
8738 _ (
"Failed to initialise internal lists mutex.\n"));
8747 _ (
"Failed to initialise mutex.\n"));
8755 "MHD-listen" :
"MHD-single",
8756 daemon->thread_stack_size,
8757 &MHD_polling_thread,
8762 if (EAGAIN == errno)
8764 _ (
"Failed to create a new thread because it would have " \
8765 "exceeded the system limit on the number of threads or " \
8766 "no system resources available.\n"));
8770 _ (
"Failed to create listen thread: %s\n"),
8785 / daemon->worker_pool_size;
8787 % daemon->worker_pool_size;
8793 daemon->worker_pool = malloc (
sizeof (
struct MHD_Daemon)
8794 * daemon->worker_pool_size);
8795 if (
NULL == daemon->worker_pool)
8799 for (i = 0; i < daemon->worker_pool_size; ++i)
8802 struct MHD_Daemon *d = &daemon->worker_pool[i];
8804 memcpy (d, daemon,
sizeof (
struct MHD_Daemon));
8809 d->worker_pool_size = 0;
8810 d->worker_pool =
NULL;
8815 _ (
"Failed to initialise internal lists mutex.\n"));
8823 _ (
"Failed to initialise mutex.\n"));
8830 if (! MHD_itc_init_ (d->
itc))
8834 _ (
"Failed to create worker inter-thread " \
8835 "communication channel: %s\n"),
8836 MHD_itc_last_strerror_ () );
8847 _ (
"File descriptor for worker inter-thread " \
8848 "communication channel exceeds maximum value.\n"));
8857 MHD_itc_set_invalid_ (d->
itc);
8859#ifdef HAVE_LISTEN_SHUTDOWN
8870 if (i < leftover_conns)
8874 (
MHD_NO == setup_epoll_to_listen (d)) )
8876 if (MHD_ITC_IS_VALID_ (d->
itc))
8884#if defined(MHD_USE_THREADS)
8885 memset (&d->per_ip_connection_mutex, 0x7F,
8886 sizeof(d->per_ip_connection_mutex));
8890 d->nonce_nc_size = 0;
8891 d->digest_auth_random_copy =
NULL;
8892#if defined(MHD_USE_THREADS)
8893 memset (&d->nnc_lock, 0x7F,
sizeof(d->nnc_lock));
8900 daemon->thread_stack_size,
8901 &MHD_polling_thread,
8906 if (EAGAIN == errno)
8908 _ (
"Failed to create a new pool thread because it would " \
8909 "have exceeded the system limit on the number of " \
8910 "threads or no system resources available.\n"));
8914 _ (
"Failed to create pool thread: %s\n"),
8919 if (MHD_ITC_IS_VALID_ (d->
itc))
8934 _ (
"Failed to initialise internal lists mutex.\n"));
8943 _ (
"Failed to initialise mutex.\n"));
8954 daemon->https_key_password =
NULL;
8959#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8968 if (
NULL != daemon->worker_pool)
8969 free (daemon->worker_pool);
8977 daemon->worker_pool_size = i;
8986#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
8987 if (daemon->upgrade_fd_in_epoll)
8989 if (0 != epoll_ctl (daemon->epoll_fd,
8991 daemon->epoll_upgrade_fd,
8993 MHD_PANIC (
_ (
"Failed to remove FD from epoll set.\n"));
8994 daemon->upgrade_fd_in_epoll =
false;
8997 if (-1 != daemon->epoll_fd)
8998 close (daemon->epoll_fd);
8999#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
9000 if (-1 != daemon->epoll_upgrade_fd)
9001 close (daemon->epoll_upgrade_fd);
9005 free (daemon->digest_auth_random_copy);
9007#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9014 gnutls_priority_deinit (daemon->priority_cache);
9015 if (daemon->x509_cred)
9016 gnutls_certificate_free_credentials (daemon->x509_cred);
9017 if (daemon->psk_cred)
9018 gnutls_psk_free_server_credentials (daemon->psk_cred);
9021 if (MHD_ITC_IS_VALID_ (daemon->
itc))
9043#ifdef UPGRADE_SUPPORT
9046#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
9047 struct MHD_UpgradeResponseHandle *urh;
9048 struct MHD_UpgradeResponseHandle *urhn;
9052#ifdef MHD_USE_THREADS
9060#ifdef MHD_USE_THREADS
9070 new_connection_close_ (daemon, pos);
9075#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
9078 for (urh = daemon->urh_tail;
NULL != urh; urh = urhn)
9086 urh->clean_ready =
true;
9103#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9106#ifdef UPGRADE_SUPPORT
9112 while (
NULL != susp)
9114 if (
NULL == susp->urh)
9115 MHD_PANIC (
_ (
"MHD_stop_daemon() called while we have " \
9116 "suspended connections.\n"));
9118 else if (used_tls &&
9120 (! susp->urh->clean_ready) )
9121 shutdown (susp->urh->app.socket,
9127 if (! susp->urh->was_closed)
9129 _ (
"Initiated daemon shutdown while \"upgraded\" " \
9130 "connection was not closed.\n"));
9132 susp->urh->was_closed =
true;
9148 MHD_PANIC (
_ (
"MHD_stop_daemon() called while we have " \
9149 "suspended connections.\n"));
9150#if defined(UPGRADE_SUPPORT) && defined(HTTPS_SUPPORT)
9151#ifdef MHD_USE_THREADS
9152 if (upg_allowed && used_tls && used_thr_p_c)
9163 if (! pos->thread_joined)
9171 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
9172 pos->thread_joined =
true;
9183#ifdef MHD_WINSOCK_SOCKETS
9186 (! MHD_itc_activate_ (
daemon->
itc,
"e")) )
9187 MHD_PANIC (
_ (
"Failed to signal shutdown via inter-thread " \
9188 "communication channel.\n"));
9192#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9199 if (! pos->thread_joined)
9203 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
9205 pos->thread_joined =
true;
9217#ifdef UPGRADE_SUPPORT
9233#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9235 (! pos->thread_joined) )
9236 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
9254#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9261 MHD_PANIC (
_ (
"MHD_stop_daemon() was called twice."));
9279#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9286 for (i = 0; i <
daemon->worker_pool_size; ++i)
9289 if (MHD_ITC_IS_VALID_ (
daemon->worker_pool[i].
itc))
9291 if (! MHD_itc_activate_ (
daemon->worker_pool[i].
itc,
9293 MHD_PANIC (
_ (
"Failed to signal shutdown via inter-thread " \
9294 "communication channel.\n"));
9299#ifdef HAVE_LISTEN_SHUTDOWN
9302 (void) shutdown (
fd,
9306 for (i = 0; i <
daemon->worker_pool_size; ++i)
9310 free (
daemon->worker_pool);
9314#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
9322#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9331 MHD_PANIC (
_ (
"Failed to signal shutdown via inter-thread " \
9332 "communication channel.\n"));
9336#ifdef HAVE_LISTEN_SHUTDOWN
9340 (void) shutdown (
fd,
9350 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
9364#if defined(UPGRADE_SUPPORT) && defined(HTTPS_SUPPORT)
9373 (-1 !=
daemon->epoll_fd) )
9375#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
9377 (-1 !=
daemon->epoll_upgrade_fd) )
9382#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9397 if (
daemon->have_dhparams)
9399 gnutls_dh_params_deinit (
daemon->https_mem_dhparams);
9400 daemon->have_dhparams =
false;
9404 gnutls_priority_deinit (
daemon->priority_cache);
9406 gnutls_certificate_free_credentials (
daemon->x509_cred);
9408 gnutls_psk_free_server_credentials (
daemon->psk_cred);
9413 free (
daemon->digest_auth_random_copy);
9415#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9419#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9448 (
NULL != daemon->worker_pool) || \
9451 (
NULL == daemon->worker_pool)) || \
9465 daemon->daemon_info_dummy_epoll_fd.epoll_fd = daemon->epoll_fd;
9466 return &daemon->daemon_info_dummy_epoll_fd;
9473#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9474 else if (daemon->worker_pool)
9479 for (i = 0; i < daemon->worker_pool_size; i++)
9510#ifdef PACKAGE_VERSION
9511 return PACKAGE_VERSION;
9513 static char ver[12] =
"\0\0\0\0\0\0\0\0\0\0\0";
9516 int res = MHD_snprintf_ (ver,
9522 if ((0 >= res) || (
sizeof(ver) <= res))
9574#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_MAJOR >= 3
9580#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_NUMBER >= 0x030603
9592#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
9610#ifdef HAVE_LISTEN_SHUTDOWN
9616#ifdef _MHD_ITC_SOCKETPAIR
9640#ifdef HAVE_POSTPROCESSOR
9646#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_NUMBER >= 0x030111
9652#if defined(HAVE_PREAD64) || defined(_WIN32)
9654#elif defined(HAVE_PREAD)
9655 return (
sizeof(uint64_t) >
sizeof(off_t)) ?
MHD_NO :
MHD_YES;
9656#elif defined(HAVE_LSEEK64)
9659 return (
sizeof(uint64_t) >
sizeof(off_t)) ?
MHD_NO :
MHD_YES;
9662#if defined(MHD_USE_THREAD_NAME_)
9668#if defined(UPGRADE_SUPPORT)
9674#if defined(HAVE_PREAD64) || defined(HAVE_PREAD) || defined(_WIN32)
9680#ifdef MHD_USE_GETSOCKNAME
9686#if defined(MHD_SEND_SPIPE_SUPPRESS_POSSIBLE) || \
9687 ! defined(MHD_SEND_SPIPE_SUPPRESS_NEEDED)
9693#ifdef _MHD_HAVE_SENDFILE
9699#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9705#if defined(COOKIE_SUPPORT)
9717#if defined(DAUTH_SUPPORT) && defined(MHD_MD5_SUPPORT)
9723#if defined(DAUTH_SUPPORT) && defined(MHD_SHA256_SUPPORT)
9729#if defined(DAUTH_SUPPORT) && defined(MHD_SHA512_256_SUPPORT)
9753#if defined(MHD_MD5_TLSLIB) || defined(MHD_SHA256_TLSLIB)
9765#ifdef HAS_FD_SETSIZE_OVERRIDABLE
9778#ifdef MHD_HTTPS_REQUIRE_GCRYPT
9779#if defined(HTTPS_SUPPORT) && GCRYPT_VERSION_NUMBER < 0x010600
9780#if defined(MHD_USE_POSIX_THREADS)
9781GCRY_THREAD_OPTION_PTHREAD_IMPL;
9782#elif defined(MHD_W32_MUTEX_)
9785gcry_w32_mutex_init (
void **ppmtx)
9787 *ppmtx = malloc (
sizeof (MHD_mutex_));
9803gcry_w32_mutex_destroy (
void **ppmtx)
9812gcry_w32_mutex_lock (
void **ppmtx)
9819gcry_w32_mutex_unlock (
void **ppmtx)
9825static struct gcry_thread_cbs gcry_threads_w32 = {
9826 (GCRY_THREAD_OPTION_USER | (GCRY_THREAD_OPTION_VERSION << 8)),
9827 NULL, gcry_w32_mutex_init, gcry_w32_mutex_destroy,
9828 gcry_w32_mutex_lock, gcry_w32_mutex_unlock,
9842#if defined(MHD_WINSOCK_SOCKETS)
9848#if defined(MHD_WINSOCK_SOCKETS)
9849 if (0 != WSAStartup (MAKEWORD (2, 2), &wsd))
9850 MHD_PANIC (
_ (
"Failed to initialize winsock.\n"));
9851 if ((2 != LOBYTE (wsd.wVersion)) && (2 != HIBYTE (wsd.wVersion)))
9852 MHD_PANIC (
_ (
"Winsock version 2.2 is not available.\n"));
9855#ifdef MHD_HTTPS_REQUIRE_GCRYPT
9856#if GCRYPT_VERSION_NUMBER < 0x010600
9857#if GNUTLS_VERSION_NUMBER <= 0x020b00
9858#if defined(MHD_USE_POSIX_THREADS)
9859 if (0 != gcry_control (GCRYCTL_SET_THREAD_CBS,
9860 &gcry_threads_pthread))
9861 MHD_PANIC (
_ (
"Failed to initialise multithreading in libgcrypt.\n"));
9862#elif defined(MHD_W32_MUTEX_)
9863 if (0 != gcry_control (GCRYCTL_SET_THREAD_CBS,
9865 MHD_PANIC (
_ (
"Failed to initialise multithreading in libgcrypt.\n"));
9868 gcry_check_version (
NULL);
9870 if (
NULL == gcry_check_version (
"1.6.0"))
9871 MHD_PANIC (
_ (
"libgcrypt is too old. MHD was compiled for " \
9872 "libgcrypt 1.6.0 or newer.\n"));
9875 gnutls_global_init ();
9885 mhd_assert (
sizeof(tv.tv_sec) == SIZEOF_STRUCT_TIMEVAL_TV_SEC);
9888 mhd_assert (
sizeof(uint64_t) == SIZEOF_UINT64_T);
9896 gnutls_global_deinit ();
9898#if defined(MHD_WINSOCK_SOCKETS)
9905#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_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