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,
2473 if (
NULL == (key->data = gnutls_malloc (app_psk_size)))
2477 _ (
"PSK authentication failed: gnutls_malloc failed to " \
2478 "allocate memory.\n"));
2487 _ (
"PSK authentication failed: PSK too long.\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;
4285 if ( (
NULL == earliest_tmot_conn) ||
4289 earliest_tmot_conn = pos;
4295 if (
NULL != earliest_tmot_conn)
4297 *timeout64 = connection_get_wait (earliest_tmot_conn);
4304#if defined(HAVE_POLL) || defined(EPOLL_SUPPORT)
4352 return (int64_t) utimeout;
4398#if SIZEOF_INT >= SIZEOF_INT64_T
4421 int32_t max_timeout)
4424 mhd_assert (0 <= max_timeout || -1 == max_timeout);
4425 if (0 == max_timeout)
4431 if ((0 < max_timeout) && ((uint64_t) max_timeout < d_timeout))
4437 return (int64_t) d_timeout;
4454 int32_t max_timeout)
4458 res = get_timeout_millisec_ (
daemon, max_timeout);
4459#if SIZEOF_INT < SIZEOF_INT64_T
4482 const fd_set *read_fd_set,
4483 const fd_set *write_fd_set,
4484 const fd_set *except_fd_set,
4488#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4489 struct MHD_UpgradeResponseHandle *urh;
4490 struct MHD_UpgradeResponseHandle *urhn;
4502#ifndef HAS_FD_SETSIZE_OVERRIDABLE
4504 mhd_assert (((
int) FD_SETSIZE) <= fd_setsize);
4505 fd_setsize = FD_SETSIZE;
4511 if (MHD_ITC_IS_VALID_ (daemon->
itc))
4513 bool need_to_clear_itc =
true;
4516 need_to_clear_itc = FD_ISSET (MHD_itc_r_fd_ (daemon->
itc), \
4518 if (need_to_clear_itc)
4519 MHD_itc_clear_ (daemon->
itc);
4535 bool need_to_accept;
4537 need_to_accept = FD_ISSET (ds,
4566 r_ready = FD_ISSET (cs,
4568 w_ready = FD_ISSET (cs,
4570 has_err = (
NULL != except_fd_set) &&
4587#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4589 for (urh =
daemon->urh_tail;
NULL != urh; urh = urhn)
4593 urh_from_fdset (urh,
4601 if ( (0 == urh->in_buffer_size) &&
4602 (0 == urh->out_buffer_size) &&
4603 (0 == urh->in_buffer_used) &&
4604 (0 == urh->out_buffer_used) )
4607 urh->clean_ready =
true;
4618#undef MHD_run_from_select
4653 const fd_set *read_fd_set,
4654 const fd_set *write_fd_set,
4655 const fd_set *except_fd_set,
4656 unsigned int fd_setsize)
4661 if ((
NULL == read_fd_set) || (
NULL == write_fd_set))
4664 if (
NULL == except_fd_set)
4667 _ (
"MHD_run_from_select() called with except_fd_set "
4668 "set to NULL. Such behavior is deprecated.\n"));
4672#ifdef HAS_FD_SETSIZE_OVERRIDABLE
4673 if (0 == fd_setsize)
4675 else if (((
unsigned int)
INT_MAX) < fd_setsize)
4676 fd_setsize = (
unsigned int)
INT_MAX;
4678 else if (
daemon->fdset_size > ((
int) fd_setsize))
4680 if (
daemon->fdset_size_set_by_app)
4683 _ (
"%s() called with fd_setsize (%u) " \
4684 "less than value set by MHD_OPTION_APP_FD_SETSIZE (%d). " \
4685 "Some socket FDs may be not processed. " \
4686 "Use MHD_OPTION_APP_FD_SETSIZE with the correct value.\n"),
4687 "MHD_run_from_select2", fd_setsize,
daemon->fdset_size);
4692 _ (
"%s() called with fd_setsize (%u) " \
4693 "less than FD_SETSIZE used by MHD (%d). " \
4694 "Some socket FDs may be not processed. " \
4695 "Consider using MHD_OPTION_APP_FD_SETSIZE option.\n"),
4696 "MHD_run_from_select2", fd_setsize,
daemon->fdset_size);
4701 if (((
unsigned int) FD_SETSIZE) > fd_setsize)
4705 _ (
"%s() called with fd_setsize (%u) " \
4706 "less than fixed FD_SETSIZE value (%d) used on the " \
4708 "MHD_run_from_select2", fd_setsize, (
int) FD_SETSIZE);
4767 const fd_set *read_fd_set,
4768 const fd_set *write_fd_set,
4769 const fd_set *except_fd_set)
4775#ifdef HAS_FD_SETSIZE_OVERRIDABLE
4776 daemon->fdset_size_set_by_app ?
4777 ((
unsigned int)
daemon->fdset_size) :
4805 struct timeval timeout;
4811 timeout.tv_usec = 0;
4837 _ (
"Could not obtain daemon fdsets.\n"));
4847 if (MHD_ITC_IS_VALID_ (daemon->
itc))
4856 MHD_DLOG (daemon,
_ (
"Could not add control inter-thread " \
4857 "communication channel FD to fdset.\n"));
4882 _ (
"Could not add listen socket to fdset.\n"));
4894 timeout.tv_usec = 0;
4901 uint64_t select_tmo;
4906 if ( (0 < millisec) &&
4907 (mhd_tmo > (uint64_t) millisec) )
4908 select_tmo = (uint64_t) millisec;
4910 select_tmo = mhd_tmo;
4913 else if (0 < millisec)
4915 select_tmo = (uint64_t) millisec;
4926#if (SIZEOF_UINT64_T - 2) >= SIZEOF_STRUCT_TIMEVAL_TV_SEC
4933 timeout.tv_usec = ((uint16_t) (select_tmo % 1000)) * ((int32_t) 1000);
4950 _ (
"select failed: %s\n"),
4980 unsigned int num_connections;
4983#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4984 struct MHD_UpgradeResponseHandle *urh;
4985 struct MHD_UpgradeResponseHandle *urhn;
5000 num_connections = 0;
5003#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5004 for (urh = daemon->urh_head;
NULL != urh; urh = urh->next)
5005 num_connections += 2;
5010 unsigned int poll_server;
5017 sizeof (
struct pollfd));
5022 _ (
"Error allocating memory: %s\n"),
5035 p[poll_server].fd = ls;
5036 p[poll_server].events = POLLIN;
5037 p[poll_server].revents = 0;
5038 poll_listen = (int) poll_server;
5042 if (MHD_ITC_IS_VALID_ (daemon->
itc))
5044 p[poll_server].fd = MHD_itc_r_fd_ (daemon->
itc);
5045 p[poll_server].events = POLLIN;
5046 p[poll_server].revents = 0;
5047 poll_itc_idx = (int) poll_server;
5051 timeout = get_timeout_millisec_int (daemon, millisec);
5061 p[poll_server + i].events |= POLLIN | MHD_POLL_EVENTS_ERR_DISC;
5064 p[poll_server + i].events |= POLLOUT | MHD_POLL_EVENTS_ERR_DISC;
5067 p[poll_server + i].events |= MHD_POLL_EVENTS_ERR_DISC;
5075#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5076 for (urh = daemon->urh_tail;
NULL != urh; urh = urh->prev)
5078 urh_to_pollfd (urh, &(p[poll_server + i]));
5082 if (0 == poll_server + num_connections)
5087 if (MHD_sys_poll_ (p,
5088 poll_server + num_connections,
5099 _ (
"poll failed: %s\n"),
5109 if ( (-1 != poll_itc_idx) &&
5110 (0 != (p[poll_itc_idx].revents & POLLIN)) )
5111 MHD_itc_clear_ (daemon->
itc);
5125 if ( (-1 != poll_listen) &&
5126 (0 != (p[poll_listen].revents & POLLIN)) )
5134 while (
NULL != (pos = prev))
5138 if (i >= num_connections)
5143 0 != (p[poll_server + i].revents & POLLIN),
5144 0 != (p[poll_server + i].revents & POLLOUT),
5145 0 != (p[poll_server + i].revents
5146 & MHD_POLL_REVENTS_ERR_DISC));
5149#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5150 for (urh = daemon->urh_tail;
NULL != urh; urh = urhn)
5152 if (i >= num_connections)
5159 if ((p[poll_server + i].
fd != urh->connection->socket_fd) ||
5160 (p[poll_server + i + 1].fd != urh->mhd.socket))
5162 urh_from_pollfd (urh,
5163 &p[poll_server + i]);
5167 if ( (0 == urh->in_buffer_size) &&
5168 (0 == urh->out_buffer_size) &&
5169 (0 == urh->in_buffer_used) &&
5170 (0 == urh->out_buffer_used) )
5175 urh->clean_ready =
true;
5199MHD_poll_listen_socket (
struct MHD_Daemon *daemon,
5204 unsigned int poll_count;
5222 p[poll_count].fd = ls;
5223 p[poll_count].events = POLLIN;
5224 p[poll_count].revents = 0;
5225 poll_listen = (int) poll_count;
5228 if (MHD_ITC_IS_VALID_ (daemon->
itc))
5230 p[poll_count].fd = MHD_itc_r_fd_ (daemon->
itc);
5231 p[poll_count].events = POLLIN;
5232 p[poll_count].revents = 0;
5233 poll_itc_idx = (int) poll_count;
5244 if (0 == poll_count)
5246 if (MHD_sys_poll_ (p,
5256 _ (
"poll failed: %s\n"),
5261 if ( (0 <= poll_itc_idx) &&
5262 (0 != (p[poll_itc_idx].revents & POLLIN)) )
5263 MHD_itc_clear_ (daemon->
itc);
5273 if ( (0 <= poll_listen) &&
5274 (0 != (p[poll_listen].revents & POLLIN)) )
5296 return MHD_poll_all (daemon,
5297 may_block ? -1 : 0);
5298 return MHD_poll_listen_socket (daemon,
5316#define MAX_EVENTS 128
5319#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5329is_urh_ready (
struct MHD_UpgradeResponseHandle *
const urh)
5333 if ( (0 == urh->in_buffer_size) &&
5334 (0 == urh->out_buffer_size) &&
5335 (0 == urh->in_buffer_used) &&
5336 (0 == urh->out_buffer_used) )
5341 & urh->app.celi)) ||
5342 (connection->tls_read_ready) ) &&
5343 (urh->in_buffer_used < urh->in_buffer_size) )
5346 & urh->mhd.celi)) ||
5348 (urh->out_buffer_used < urh->out_buffer_size) )
5351 (urh->out_buffer_used > 0) )
5354 (urh->in_buffer_used > 0) )
5371 struct epoll_event events[MAX_EVENTS];
5373 struct MHD_UpgradeResponseHandle *pos;
5374 struct MHD_UpgradeResponseHandle *prev;
5376#ifdef MHD_USE_THREADS
5381 num_events = MAX_EVENTS;
5382 while (0 != num_events)
5386 num_events = epoll_wait (daemon->epoll_upgrade_fd,
5390 if (-1 == num_events)
5398 _ (
"Call to epoll_wait failed: %s\n"),
5403 for (i = 0; i < (
unsigned int) num_events; i++)
5405 struct UpgradeEpollHandle *
const ueh = events[i].data.ptr;
5406 struct MHD_UpgradeResponseHandle *
const urh = ueh->urh;
5407 bool new_err_state =
false;
5409 if (urh->clean_ready)
5413 if (0 != (events[i].events & EPOLLIN))
5417 if (0 != (events[i].events & EPOLLOUT))
5421 if (0 != (events[i].events & EPOLLHUP))
5427 (0 != (events[i].events & (EPOLLERR | EPOLLPRI))) )
5432 new_err_state =
true;
5434 if (! urh->in_eready_list)
5436 if (new_err_state ||
5440 daemon->eready_urh_tail,
5442 urh->in_eready_list =
true;
5447 prev = daemon->eready_urh_tail;
5448 while (
NULL != (pos = prev))
5452 if (! is_urh_ready (pos))
5455 daemon->eready_urh_tail,
5457 pos->in_eready_list =
false;
5460 if ( (0 == pos->in_buffer_size) &&
5461 (0 == pos->out_buffer_size) &&
5462 (0 == pos->in_buffer_used) &&
5463 (0 == pos->out_buffer_used) )
5466 pos->clean_ready =
true;
5485static const char *
const epoll_itc_marker =
"itc_marker";
5501#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5502 static const char *
const upgrade_marker =
"upgrade_ptr";
5506 struct epoll_event events[MAX_EVENTS];
5507 struct epoll_event event;
5512#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5513 bool run_upgraded =
false;
5515 bool need_to_accept;
5524 if (-1 == daemon->epoll_fd)
5531 (! daemon->listen_socket_in_epoll) &&
5534 event.events = EPOLLIN | EPOLLRDHUP;
5535 event.data.ptr = daemon;
5536 if (0 != epoll_ctl (daemon->epoll_fd,
5543 _ (
"Call to epoll_ctl failed: %s\n"),
5548 daemon->listen_socket_in_epoll =
true;
5551 (daemon->listen_socket_in_epoll) )
5553 if ( (0 != epoll_ctl (daemon->epoll_fd,
5559 MHD_PANIC (
"Failed to remove listen FD from epoll set.\n");
5560 daemon->listen_socket_in_epoll =
false;
5563#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5564 if ( ( (! daemon->upgrade_fd_in_epoll) &&
5565 (-1 != daemon->epoll_upgrade_fd) ) )
5567 event.events = EPOLLIN | EPOLLOUT | EPOLLRDHUP;
5569 if (0 != epoll_ctl (daemon->epoll_fd,
5571 daemon->epoll_upgrade_fd,
5576 _ (
"Call to epoll_ctl failed: %s\n"),
5581 daemon->upgrade_fd_in_epoll =
true;
5584 if ( (daemon->listen_socket_in_epoll) &&
5591 if (0 != epoll_ctl (daemon->epoll_fd,
5595 MHD_PANIC (
_ (
"Failed to remove listen FD from epoll set.\n"));
5596 daemon->listen_socket_in_epoll =
false;
5603 timeout_ms = get_timeout_millisec_int (daemon,
5611 need_to_accept =
false;
5616 num_events = MAX_EVENTS;
5617 while (MAX_EVENTS == num_events)
5620 num_events = epoll_wait (daemon->epoll_fd,
5624 if (-1 == num_events)
5631 _ (
"Call to epoll_wait failed: %s\n"),
5636 for (i = 0; i < (
unsigned int) num_events; i++)
5642#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5643 if (upgrade_marker == events[i].
data.ptr)
5647 run_upgraded =
true;
5651 if (epoll_itc_marker == events[i].
data.ptr)
5655 MHD_itc_clear_ (daemon->
itc);
5658 if (daemon == events[i].
data.ptr)
5662 if (0 == (events[i].events & (EPOLLERR | EPOLLHUP)))
5663 need_to_accept =
true;
5669 pos = events[i].data.ptr;
5671 if (0 != (events[i].events & (EPOLLPRI | EPOLLERR | EPOLLHUP)))
5677 daemon->eready_tail,
5684 if (0 != (events[i].events & EPOLLIN))
5692 daemon->eready_tail,
5697 if (0 != (events[i].events & EPOLLOUT))
5704 daemon->eready_tail,
5719 unsigned int series_length = 0;
5726 (series_length < 10) &&
5741 while (
NULL != (pos = prev))
5751 while (
NULL != (pos = prev))
5759#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5760 if (run_upgraded || (
NULL != daemon->eready_urh_head))
5761 run_epoll_for_upgrade (daemon);
5765 prev = daemon->eready_tail;
5766 while (
NULL != (pos = prev))
5784 daemon->eready_tail,
5892 res = MHD_poll_all (daemon, millisec);
5900 res = MHD_epoll (daemon, millisec);
5908#ifdef HAS_FD_SETSIZE_OVERRIDABLE
5910 if (daemon->fdset_size_set_by_app
5911 && (((
int) FD_SETSIZE) < daemon->fdset_size))
5914 _ (
"MHD_run()/MHD_run_wait() called for daemon started with " \
5915 "MHD_OPTION_APP_FD_SETSIZE option (%d). " \
5916 "The library was compiled with smaller FD_SETSIZE (%d). " \
5917 "Some socket FDs may be not processed. " \
5918 "Use MHD_run_from_select2() instead of MHD_run() or " \
5919 "do not use MHD_OPTION_APP_FD_SETSIZE option.\n"),
5920 daemon->fdset_size, (
int) FD_SETSIZE);
5945#ifdef MHD_USE_THREADS
5958#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5978#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5984#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5992static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_
5993MHD_polling_thread (
void *cls)
5996#ifdef HAVE_PTHREAD_SIGMASK
6002#ifdef HAVE_PTHREAD_SIGMASK
6003 if ((0 == sigemptyset (&s_mask)) &&
6004 (0 == sigaddset (&s_mask, SIGPIPE)))
6006 err = pthread_sigmask (SIG_BLOCK, &s_mask,
NULL);
6015 _ (
"Failed to block SIGPIPE on daemon thread: %s\n"),
6028 MHD_epoll (daemon, -1);
6042 return (MHD_THRD_RTRN_TYPE_) 0;
6077 MHD_DLOG (connection->
daemon,
6078 _ (
"The URL encoding is broken.\n"));
6153#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6167 _ (
"Using MHD_quiesce_daemon in this mode " \
6168 "requires MHD_USE_ITC.\n"));
6173#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6174 if (
NULL != daemon->worker_pool)
6175 for (i = 0; i < daemon->worker_pool_size; i++)
6180 (-1 != daemon->worker_pool[i].epoll_fd) &&
6181 (daemon->worker_pool[i].listen_socket_in_epoll) )
6183 if (0 != epoll_ctl (daemon->worker_pool[i].epoll_fd,
6187 MHD_PANIC (
_ (
"Failed to remove listen FD from epoll set.\n"));
6188 daemon->worker_pool[i].listen_socket_in_epoll =
false;
6192 if (MHD_ITC_IS_VALID_ (daemon->worker_pool[i].
itc))
6194 if (! MHD_itc_activate_ (daemon->worker_pool[i].
itc,
"q"))
6195 MHD_PANIC (
_ (
"Failed to signal quiesce via inter-thread " \
6196 "communication channel.\n"));
6203 (-1 != daemon->epoll_fd) &&
6204 (daemon->listen_socket_in_epoll) )
6206 if ( (0 != epoll_ctl (daemon->epoll_fd,
6212 MHD_PANIC (
"Failed to remove listen FD from epoll set.\n");
6213 daemon->listen_socket_in_epoll =
false;
6216 if ( (MHD_ITC_IS_VALID_ (daemon->
itc)) &&
6217 (! MHD_itc_activate_ (daemon->
itc,
"q")) )
6218 MHD_PANIC (
_ (
"failed to signal quiesce via inter-thread " \
6219 "communication channel.\n"));
6229struct MHD_InterimParams_
6242 bool fdset_size_set;
6258 bool pserver_addr_set;
6262 const struct sockaddr *pserver_addr;
6266 bool server_addr_len_set;
6270 socklen_t server_addr_len;
6297 struct MHD_InterimParams_ *params,
6312 struct MHD_InterimParams_ *params,
6318 va_start (ap, params);
6331enum MHD_TlsPrioritiesBaseType
6333 MHD_TLS_PRIO_BASE_LIBMHD = 0,
6334 MHD_TLS_PRIO_BASE_SYSTEM = 1,
6335#if GNUTLS_VERSION_NUMBER >= 0x030300
6336 MHD_TLS_PRIO_BASE_DEFAULT,
6338 MHD_TLS_PRIO_BASE_NORMAL
6344#if GNUTLS_VERSION_NUMBER >= 0x030300
6356daemon_tls_priorities_init_default (
struct MHD_Daemon *daemon)
6363 mhd_assert (MHD_TLS_PRIO_BASE_NORMAL + 1 == \
6364 sizeof(MHD_TlsBasePriotities) /
sizeof(MHD_TlsBasePriotities[0]));
6366 res = GNUTLS_E_SUCCESS;
6369 p <
sizeof(MHD_TlsBasePriotities) /
sizeof(MHD_TlsBasePriotities[0]);
6372 res = gnutls_priority_init (&daemon->priority_cache,
6373 MHD_TlsBasePriotities[p].str,
NULL);
6374 if (GNUTLS_E_SUCCESS == res)
6378 switch ((
enum MHD_TlsPrioritiesBaseType) p)
6380 case MHD_TLS_PRIO_BASE_LIBMHD:
6382 _ (
"GnuTLS priorities have been initialised with " \
6383 "@LIBMICROHTTPD application-specific system-wide " \
6384 "configuration.\n") );
6386 case MHD_TLS_PRIO_BASE_SYSTEM:
6388 _ (
"GnuTLS priorities have been initialised with " \
6389 "@SYSTEM system-wide configuration.\n") );
6391#if GNUTLS_VERSION_NUMBER >= 0x030300
6392 case MHD_TLS_PRIO_BASE_DEFAULT:
6394 _ (
"GnuTLS priorities have been initialised with " \
6395 "GnuTLS default configuration.\n") );
6398 case MHD_TLS_PRIO_BASE_NORMAL:
6400 _ (
"GnuTLS priorities have been initialised with " \
6401 "NORMAL configuration.\n") );
6413 _ (
"Failed to set GnuTLS priorities. Last error: %s\n"),
6414 gnutls_strerror (res));
6430daemon_tls_priorities_init_append_inner_ (
struct MHD_Daemon *daemon,
6434 const size_t buf_size)
6438 const char *err_pos;
6443 mhd_assert (MHD_TLS_PRIO_BASE_NORMAL + 1 == \
6444 sizeof(MHD_TlsBasePriotities) /
sizeof(MHD_TlsBasePriotities[0]));
6446 res = GNUTLS_E_SUCCESS;
6449 p <
sizeof(MHD_TlsBasePriotities) /
sizeof(MHD_TlsBasePriotities[0]);
6453#if GNUTLS_VERSION_NUMBER >= 0x030300
6454#if GNUTLS_VERSION_NUMBER >= 0x030603
6455 if (
NULL == MHD_TlsBasePriotities[p].
str)
6456 res = gnutls_priority_init2 (&daemon->priority_cache, prio, &err_pos,
6457 GNUTLS_PRIORITY_INIT_DEF_APPEND);
6461 if (
NULL == MHD_TlsBasePriotities[p].
str)
6472 memcpy (buf + buf_pos, MHD_TlsBasePriotities[p].
str,
6473 MHD_TlsBasePriotities[p].
len);
6474 buf_pos += MHD_TlsBasePriotities[p].
len;
6475 buf[buf_pos++] =
':';
6476 memcpy (buf + buf_pos, prio, prio_len + 1);
6478 buf_pos += prio_len + 1;
6481 res = gnutls_priority_init (&daemon->priority_cache, buf, &err_pos);
6483 if (GNUTLS_E_SUCCESS == res)
6487 switch ((
enum MHD_TlsPrioritiesBaseType) p)
6489 case MHD_TLS_PRIO_BASE_LIBMHD:
6491 _ (
"GnuTLS priorities have been initialised with " \
6492 "priorities specified by application appended to " \
6493 "@LIBMICROHTTPD application-specific system-wide " \
6494 "configuration.\n") );
6496 case MHD_TLS_PRIO_BASE_SYSTEM:
6498 _ (
"GnuTLS priorities have been initialised with " \
6499 "priorities specified by application appended to " \
6500 "@SYSTEM system-wide configuration.\n") );
6502#if GNUTLS_VERSION_NUMBER >= 0x030300
6503 case MHD_TLS_PRIO_BASE_DEFAULT:
6505 _ (
"GnuTLS priorities have been initialised with " \
6506 "priorities specified by application appended to " \
6507 "GnuTLS default configuration.\n") );
6510 case MHD_TLS_PRIO_BASE_NORMAL:
6512 _ (
"GnuTLS priorities have been initialised with " \
6513 "priorities specified by application appended to " \
6514 "NORMAL configuration.\n") );
6526 _ (
"Failed to set GnuTLS priorities. Last error: %s. " \
6527 "The problematic part starts at: %s\n"),
6528 gnutls_strerror (res), err_pos);
6534#define LOCAL_BUFF_SIZE 128
6545daemon_tls_priorities_init_append (
struct MHD_Daemon *daemon,
const char *prio)
6550 size_t buf_size_needed;
6553 return daemon_tls_priorities_init_default (daemon);
6558 prio_len = strlen (prio);
6560 buf_size_needed = longest_base_prio + 1 + prio_len + 1;
6562 if (LOCAL_BUFF_SIZE >= buf_size_needed)
6564 char local_buffer[LOCAL_BUFF_SIZE];
6565 ret = daemon_tls_priorities_init_append_inner_ (daemon, prio, prio_len,
6571 char *allocated_buffer;
6572 allocated_buffer = (
char *) malloc (buf_size_needed);
6573 if (
NULL == allocated_buffer)
6577 _ (
"Error allocating memory: %s\n"),
6582 ret = daemon_tls_priorities_init_append_inner_ (daemon, prio, prio_len,
6585 free (allocated_buffer);
6604 struct MHD_InterimParams_ *params,
6613#if GNUTLS_VERSION_MAJOR >= 3
6614 gnutls_certificate_retrieve_function2 * pgcrf;
6616#if GNUTLS_VERSION_NUMBER >= 0x030603
6617 gnutls_certificate_retrieve_function3 * pgcrf2;
6642 _ (
"Warning: specified " \
6643 "MHD_OPTION_CONNECTION_MEMORY_LIMIT " \
6644 "value is too small and rounded up to 64.\n"));
6668 _ (
"Warning: specified " \
6669 "MHD_OPTION_CONNECTION_MEMORY_INCREMENT value is " \
6670 "too large and rounded down to 1/4 of " \
6671 "MHD_OPTION_CONNECTION_MEMORY_LIMIT.\n"));
6685#if (SIZEOF_UINT64_T - 2) <= SIZEOF_UNSIGNED_INT
6690 _ (
"The specified connection timeout (%u) is too large. " \
6691 "Maximum allowed value (%" PRIu64 ") will be used " \
6718 params->server_addr_len = va_arg (ap,
6720 params->server_addr_len_set =
true;
6721 params->pserver_addr = va_arg (ap,
6722 const struct sockaddr *);
6723 params->pserver_addr_set =
true;
6726 params->server_addr_len_set =
false;
6727 params->pserver_addr = va_arg (ap,
6728 const struct sockaddr *);
6729 params->pserver_addr_set =
true;
6742#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6744 daemon->worker_pool_size = va_arg (ap,
6746 if (0 == daemon->worker_pool_size)
6750 else if (1 == daemon->worker_pool_size)
6754 _ (
"Warning: value \"1\", specified as the thread pool " \
6755 "size, is ignored. Thread pool is not used.\n"));
6757 daemon->worker_pool_size = 0;
6759#if SIZEOF_UNSIGNED_INT >= (SIZEOF_SIZE_T - 2)
6763 else if (daemon->worker_pool_size >=
6768 _ (
"Specified thread pool size (%u) too big.\n"),
6769 daemon->worker_pool_size);
6780 _ (
"MHD_OPTION_THREAD_POOL_SIZE option is specified but "
6781 "MHD_USE_INTERNAL_POLLING_THREAD flag is not specified.\n"));
6789 _ (
"Both MHD_OPTION_THREAD_POOL_SIZE option and "
6790 "MHD_USE_THREAD_PER_CONNECTION flag are specified.\n"));
6802 daemon->https_mem_key = pstr;
6806 _ (
"MHD HTTPS option %d passed to MHD but " \
6807 "MHD_USE_TLS not set.\n"),
6815 daemon->https_key_password = pstr;
6819 _ (
"MHD HTTPS option %d passed to MHD but " \
6820 "MHD_USE_TLS not set.\n"),
6828 daemon->https_mem_cert = pstr;
6832 _ (
"MHD HTTPS option %d passed to MHD but " \
6833 "MHD_USE_TLS not set.\n"),
6841 daemon->https_mem_trust = pstr;
6845 _ (
"MHD HTTPS option %d passed to MHD but " \
6846 "MHD_USE_TLS not set.\n"),
6851 daemon->cred_type = (gnutls_credentials_type_t) va_arg (ap,
6859 gnutls_datum_t dhpar;
6862 if (gnutls_dh_params_init (&daemon->https_mem_dhparams) < 0)
6866 _ (
"Error initializing DH parameters.\n"));
6871 pstr_len = strlen (pstr);
6876 _ (
"Diffie-Hellman parameters string too long.\n"));
6880 dhpar.size = (
unsigned int) pstr_len;
6881 if (gnutls_dh_params_import_pkcs3 (daemon->https_mem_dhparams,
6883 GNUTLS_X509_FMT_PEM) < 0)
6887 _ (
"Bad Diffie-Hellman parameters format.\n"));
6889 gnutls_dh_params_deinit (daemon->https_mem_dhparams);
6892 daemon->have_dhparams =
true;
6897 _ (
"MHD HTTPS option %d passed to MHD but " \
6898 "MHD_USE_TLS not set.\n"),
6908 if (
NULL != daemon->priority_cache)
6909 gnutls_priority_deinit (daemon->priority_cache);
6914 const char *err_pos;
6915 init_res = gnutls_priority_init (&daemon->priority_cache,
6918 if (GNUTLS_E_SUCCESS != init_res)
6922 _ (
"Setting priorities to '%s' failed: %s " \
6923 "The problematic part starts at: %s\n"),
6925 gnutls_strerror (init_res),
6928 daemon->priority_cache =
NULL;
6935 daemon->priority_cache =
NULL;
6936 if (! daemon_tls_priorities_init_append (daemon, pstr))
6943 _ (
"MHD HTTPS option %d passed to MHD but " \
6944 "MHD_USE_TLS not set.\n"),
6949#if GNUTLS_VERSION_MAJOR < 3
6952 _ (
"MHD_OPTION_HTTPS_CERT_CALLBACK requires building " \
6953 "MHD with GnuTLS >= 3.0.\n"));
6958 gnutls_certificate_retrieve_function2 *);
6960 daemon->cert_callback = pgcrf;
6964 _ (
"MHD HTTPS option %d passed to MHD but " \
6965 "MHD_USE_TLS not set.\n"),
6971#if GNUTLS_VERSION_NUMBER < 0x030603
6974 _ (
"MHD_OPTION_HTTPS_CERT_CALLBACK2 requires building " \
6975 "MHD with GnuTLS >= 3.6.3.\n"));
6979 pgcrf2 = va_arg (ap,
6980 gnutls_certificate_retrieve_function3 *);
6982 daemon->cert_callback2 = pgcrf2;
6986 _ (
"MHD HTTPS option %d passed to MHD but " \
6987 "MHD_USE_TLS not set.\n"),
6996 daemon->digest_auth_rand_size = va_arg (ap,
6998 daemon->digest_auth_random = va_arg (ap,
7002 daemon->digest_auth_random_copy = daemon;
7004 daemon->digest_auth_random_copy =
NULL;
7007 daemon->nonce_nc_size = va_arg (ap,
7011 daemon->dauth_bind_type = va_arg (ap,
7023 daemon->dauth_def_nonce_timeout = val;
7033 daemon->dauth_def_max_nc = val;
7045 _ (
"Digest Auth is disabled for this build " \
7046 "of GNU libmicrohttpd.\n"));
7051 params->listen_fd = va_arg (ap,
7053 params->listen_fd_set =
true;
7057 daemon->custom_error_log = va_arg (ap,
7059 daemon->custom_error_log_cls = va_arg (ap,
7061 if (1 != params->num_opts)
7063 _ (
"MHD_OPTION_EXTERNAL_LOGGER is not the first option "
7064 "specified for the daemon. Some messages may be "
7065 "printed by the standard MHD logger.\n"));
7074#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7076 daemon->thread_stack_size = va_arg (ap,
7082 daemon->fastopen_queue_size = va_arg (ap,
7088 _ (
"TCP fastopen is not supported on this platform.\n"));
7094 unsigned int) ? 1 : -1;
7112 _ (
"Flag MHD_USE_PEDANTIC_CHECKS is ignored because "
7113 "another behaviour is specified by "
7114 "MHD_OPTION_STRICT_CLIENT.\n"));
7125 _ (
"Flag MHD_USE_PEDANTIC_CHECKS is ignored because "
7126 "another behaviour is specified by "
7127 "MHD_OPTION_CLIENT_DISCIPLINE_LVL.\n"));
7152 (
size_t) oa[i].
value,
7171 (
unsigned int) oa[i].
value,
7181 (gnutls_credentials_type_t) oa[i].
value,
7214 (uint32_t) oa[i].
value,
7247 (
void *) oa[i].
value,
7258 (
size_t) oa[i].
value,
7268 (socklen_t) oa[i].
value,
7288#if GNUTLS_VERSION_MAJOR >= 3
7289 daemon->cred_callback = va_arg (ap,
7291 daemon->cred_callback_cls = va_arg (ap,
7296 _ (
"MHD HTTPS option %d passed to MHD compiled " \
7297 "without GNUtls >= 3.\n"),
7314 daemon->disable_alpn = (va_arg (ap,
7317 (void) va_arg (ap,
int);
7322 _ (
"MHD HTTPS option %d passed to MHD " \
7323 "but MHD_USE_TLS not set.\n"),
7328 params->fdset_size_set =
true;
7329 params->fdset_size = va_arg (ap,
7332#ifndef HTTPS_SUPPORT
7346 _ (
"MHD HTTPS option %d passed to MHD "
7347 "compiled without HTTPS support.\n"),
7356 _ (
"Invalid option %d! (Did you terminate "
7357 "the list with MHD_OPTION_END?).\n"),
7373#ifndef HAVE_MESSAGES
7377#ifdef USE_EPOLL_CREATE1
7378 fd = epoll_create1 (EPOLL_CLOEXEC);
7380 fd = epoll_create (MAX_EVENTS);
7386 _ (
"Call to epoll_create1 failed: %s\n"),
7391#if ! defined(USE_EPOLL_CREATE1)
7396 _ (
"Failed to set noninheritable mode on epoll FD.\n"));
7413setup_epoll_to_listen (
struct MHD_Daemon *daemon)
7415 struct epoll_event event;
7422 MHD_ITC_IS_VALID_ (daemon->
itc) );
7423 daemon->epoll_fd = setup_epoll_fd (daemon);
7438 _ (
"The epoll FD is too large to be used with fd_set.\n"));
7443 if (-1 == daemon->epoll_fd)
7445#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
7448 daemon->epoll_upgrade_fd = setup_epoll_fd (daemon);
7456 event.events = EPOLLIN | EPOLLRDHUP;
7457 event.data.ptr = daemon;
7458 if (0 != epoll_ctl (daemon->epoll_fd,
7465 _ (
"Call to epoll_ctl failed: %s\n"),
7470 daemon->listen_socket_in_epoll =
true;
7473 if (MHD_ITC_IS_VALID_ (daemon->
itc))
7475 event.events = EPOLLIN | EPOLLRDHUP;
7477 if (0 != epoll_ctl (daemon->epoll_fd,
7479 MHD_itc_r_fd_ (daemon->
itc),
7484 _ (
"Call to epoll_ctl failed: %s\n"),
7510 const struct sockaddr **ppsockaddr,
7511 socklen_t *psockaddr_len,
7512 struct MHD_InterimParams_ *params)
7514 if (params->fdset_size_set)
7516 if (0 >= params->fdset_size)
7520 _ (
"MHD_OPTION_APP_FD_SETSIZE value (%d) is not positive.\n"),
7521 params->fdset_size);
7529 _ (
"MHD_OPTION_APP_FD_SETSIZE is ignored for daemon started " \
7530 "with MHD_USE_INTERNAL_POLLING_THREAD.\n"));
7538 _ (
"MHD_OPTION_APP_FD_SETSIZE is ignored for daemon started " \
7539 "with MHD_USE_POLL.\n"));
7545#ifndef HAS_FD_SETSIZE_OVERRIDABLE
7546 if (((
int) FD_SETSIZE) != params->fdset_size)
7550 _ (
"MHD_OPTION_APP_FD_SETSIZE value (%d) does not match " \
7551 "the platform FD_SETSIZE value (%d) and this platform " \
7552 "does not support overriding of FD_SETSIZE.\n"),
7553 params->fdset_size, (
int) FD_SETSIZE);
7558 d->fdset_size = params->fdset_size;
7559 d->fdset_size_set_by_app =
true;
7564 if (params->listen_fd_set)
7570#ifdef HAS_SIGNED_SOCKET
7571 else if (0 > params->listen_fd)
7575 _ (
"The value provided for MHD_OPTION_LISTEN_SOCKET " \
7585 _ (
"MHD_OPTION_LISTEN_SOCKET specified for daemon "
7586 "with MHD_USE_NO_LISTEN_SOCKET flag set.\n"));
7595#ifdef MHD_USE_GETSOCKNAME
7601 mhd_assert (! params->server_addr_len_set || params->pserver_addr_set);
7602 if (params->pserver_addr_set)
7604 if (
NULL == params->pserver_addr)
7607 if (params->server_addr_len_set && (0 != params->server_addr_len))
7615 _ (
"MHD_OPTION_LISTEN_SOCKET cannot be used together with " \
7616 "MHD_OPTION_SOCK_ADDR_LEN or MHD_OPTION_SOCK_ADDR.\n"));
7624 _ (
"MHD_OPTION_SOCK_ADDR_LEN or MHD_OPTION_SOCK_ADDR " \
7625 "specified for daemon with MHD_USE_NO_LISTEN_SOCKET " \
7637 *ppsockaddr = params->pserver_addr;
7638 if (params->server_addr_len_set)
7641 if (0 == params->server_addr_len)
7643 *psockaddr_len = params->server_addr_len;
7685 const struct sockaddr *pservaddr =
NULL;
7687#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7692 struct MHD_InterimParams_ *interim_params;
7709#ifndef EPOLL_SUPPORT
7713#ifndef HTTPS_SUPPORT
7723#ifdef UPGRADE_SUPPORT
7729#ifdef MHD_USE_THREADS
7758#if defined(EPOLL_SUPPORT) && defined(HAVE_POLL)
7763#elif defined(HAVE_POLL)
7766#elif defined(EPOLL_SUPPORT)
7778#ifdef HAVE_LISTEN_SHUTDOWN
7786 interim_params = (
struct MHD_InterimParams_ *) \
7787 MHD_calloc_ (1,
sizeof (
struct MHD_InterimParams_));
7788 if (
NULL == interim_params)
7790 int err_num = errno;
7796 daemon->epoll_fd = -1;
7797#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
7798 daemon->epoll_upgrade_fd = -1;
7803 daemon->priority_cache =
NULL;
7812 daemon->
port = port;
7823 MHD_itc_set_invalid_ (daemon->
itc);
7824#ifdef MHD_USE_THREADS
7833 daemon->custom_error_log = &MHD_default_logger_;
7834 daemon->custom_error_log_cls = stderr;
7836#ifndef MHD_WINSOCK_SOCKETS
7842#if defined(_DEBUG) && defined(HAVE_ACCEPT4)
7843 daemon->avoid_accept4 =
false;
7845#ifdef HAS_FD_SETSIZE_OVERRIDABLE
7846 daemon->fdset_size = (int) FD_SETSIZE;
7847 daemon->fdset_size_set_by_app =
false;
7851 daemon->digest_auth_rand_size = 0;
7852 daemon->digest_auth_random =
NULL;
7853 daemon->nonce_nc_size = 4;
7860 daemon->cred_type = GNUTLS_CRD_CERTIFICATE;
7864 interim_params->num_opts = 0;
7865 interim_params->fdset_size_set =
false;
7866 interim_params->fdset_size = 0;
7867 interim_params->listen_fd_set =
false;
7869 interim_params->pserver_addr_set =
false;
7870 interim_params->pserver_addr =
NULL;
7871 interim_params->server_addr_len_set =
false;
7872 interim_params->server_addr_len = 0;
7880 (
NULL != daemon->priority_cache) )
7881 gnutls_priority_deinit (daemon->priority_cache);
7883 free (interim_params);
7892 free (interim_params);
7896 free (interim_params);
7897 interim_params =
NULL;
7900 && (
NULL == daemon->priority_cache)
7901 && ! daemon_tls_priorities_init_default (daemon))
7905 _ (
"Failed to initialise GnuTLS priorities.\n"));
7917 _ (
"Warning: MHD_USE_THREAD_PER_CONNECTION must be used " \
7918 "only with MHD_USE_INTERNAL_POLLING_THREAD. " \
7919 "Flag MHD_USE_INTERNAL_POLLING_THREAD was added. " \
7920 "Consider setting MHD_USE_INTERNAL_POLLING_THREAD " \
7933 _ (
"Using debug build of libmicrohttpd.\n") );
7938#
if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7939 && (0 == daemon->worker_pool_size)
7943 if (! MHD_itc_init_ (daemon->
itc))
7947 _ (
"Failed to create inter-thread communication channel: %s\n"),
7948 MHD_itc_last_strerror_ ());
7951 if (
NULL != daemon->priority_cache)
7952 gnutls_priority_deinit (daemon->priority_cache);
7962 _ (
"file descriptor for inter-thread communication " \
7963 "channel exceeds maximum value.\n"));
7967 if (
NULL != daemon->priority_cache)
7968 gnutls_priority_deinit (daemon->priority_cache);
7976 if (
NULL != daemon->digest_auth_random_copy)
7978 mhd_assert (daemon == daemon->digest_auth_random_copy);
7979 daemon->digest_auth_random_copy = malloc (daemon->digest_auth_rand_size);
7980 if (
NULL == daemon->digest_auth_random_copy)
7984 gnutls_priority_deinit (daemon->priority_cache);
7989 memcpy (daemon->digest_auth_random_copy,
7990 daemon->digest_auth_random,
7991 daemon->digest_auth_rand_size);
7992 daemon->digest_auth_random = daemon->digest_auth_random_copy;
7994 if (daemon->nonce_nc_size > 0)
7996 if ( ( (
size_t) (daemon->nonce_nc_size * sizeof (
struct MHD_NonceNc)))
7997 /
sizeof(
struct MHD_NonceNc) != daemon->nonce_nc_size)
8001 _ (
"Specified value for NC_SIZE too large.\n"));
8005 gnutls_priority_deinit (daemon->priority_cache);
8007 free (daemon->digest_auth_random_copy);
8013 if (
NULL == daemon->nnc)
8017 _ (
"Failed to allocate memory for nonce-nc map: %s\n"),
8022 gnutls_priority_deinit (daemon->priority_cache);
8024 free (daemon->digest_auth_random_copy);
8030#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8035 _ (
"MHD failed to initialize nonce-nc mutex.\n"));
8039 gnutls_priority_deinit (daemon->priority_cache);
8041 free (daemon->digest_auth_random_copy);
8050#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8052 (daemon->worker_pool_size > 0) )
8056 _ (
"MHD thread polling only works with " \
8057 "MHD_USE_INTERNAL_POLLING_THREAD.\n"));
8067 struct sockaddr_in servaddr4;
8069 struct sockaddr_in6 servaddr6;
8072 const bool use_ipv6 =
false;
8076 if (
NULL != pservaddr)
8078#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
8079 const socklen_t sa_len = pservaddr->sa_len;
8082 if (use_ipv6 && (AF_INET6 != pservaddr->sa_family))
8086 _ (
"MHD_USE_IPv6 is enabled, but 'struct sockaddr *' " \
8087 "specified for MHD_OPTION_SOCK_ADDR_LEN or " \
8088 "MHD_OPTION_SOCK_ADDR is not IPv6 address.\n"));
8093 switch (pservaddr->sa_family)
8098 struct sockaddr_in sa4;
8101 && (((socklen_t)
sizeof(sa4)) > addrlen))
8105 _ (
"The size specified for MHD_OPTION_SOCK_ADDR_LEN " \
8106 "option is wrong.\n"));
8110#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
8113 if (((socklen_t)
sizeof(sa4)) > sa_len)
8117 _ (
"The value of 'struct sockaddr.sa_len' provided " \
8118 "via MHD_OPTION_SOCK_ADDR_LEN option is not zero " \
8119 "and does not match 'sa_family' value of the " \
8120 "same structure.\n"));
8124 if ((0 == addrlen) || (sa_len < addrlen))
8129 addrlen =
sizeof(sa4);
8130 memcpy (&sa4, pservaddr,
sizeof(sa4));
8131 sa4_port = (uint16_t) ntohs (sa4.sin_port);
8132#ifndef MHD_USE_GETSOCKNAME
8135 daemon->
port = sa4_port;
8143 struct sockaddr_in6 sa6;
8146 && (((socklen_t)
sizeof(sa6)) > addrlen))
8150 _ (
"The size specified for MHD_OPTION_SOCK_ADDR_LEN " \
8151 "option is wrong.\n"));
8155#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
8158 if (((socklen_t)
sizeof(sa6)) > sa_len)
8162 _ (
"The value of 'struct sockaddr.sa_len' provided " \
8163 "via MHD_OPTION_SOCK_ADDR_LEN option is not zero " \
8164 "and does not match 'sa_family' value of the " \
8165 "same structure.\n"));
8169 if ((0 == addrlen) || (sa_len < addrlen))
8174 addrlen =
sizeof(sa6);
8175 memcpy (&sa6, pservaddr,
sizeof(sa6));
8176 sa6_port = (uint16_t) ntohs (sa6.sin6_port);
8177#ifndef MHD_USE_GETSOCKNAME
8180 daemon->
port = sa6_port;
8190#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
8193 else if ((0 != sa_len) && (sa_len < addrlen))
8200 _ (
"The 'sa_family' of the 'struct sockaddr' provided " \
8201 "via MHD_OPTION_SOCK_ADDR option is not supported.\n"));
8206 if (AF_UNIX == pservaddr->sa_family)
8223 domain = pservaddr->sa_family;
8234 sizeof (
struct sockaddr_in));
8235 servaddr4.sin_family = AF_INET;
8236 servaddr4.sin_port = htons (port);
8237 if (0 != INADDR_ANY)
8238 servaddr4.sin_addr.s_addr = htonl (INADDR_ANY);
8239#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
8240 servaddr4.sin_len =
sizeof (
struct sockaddr_in);
8242 pservaddr = (
struct sockaddr *) &servaddr4;
8243 addrlen = (socklen_t)
sizeof(servaddr4);
8250#ifdef IN6ADDR_ANY_INIT
8251 static const struct in6_addr static_in6any = IN6ADDR_ANY_INIT;
8255 sizeof (
struct sockaddr_in6));
8256 servaddr6.sin6_family = AF_INET6;
8257 servaddr6.sin6_port = htons (port);
8258#ifdef IN6ADDR_ANY_INIT
8259 servaddr6.sin6_addr = static_in6any;
8261#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
8262 servaddr6.sin6_len =
sizeof (
struct sockaddr_in6);
8264 pservaddr = (
struct sockaddr *) &servaddr6;
8265 addrlen = (socklen_t)
sizeof (servaddr6);
8277 _ (
"Failed to create socket for listening: %s\n"),
8288 _ (
"Listen socket descriptor (%d) is not " \
8289 "less than daemon FD_SETSIZE value (%d).\n"),
8299#ifndef MHD_WINSOCK_SOCKETS
8307 (
const void *) &on, sizeof (on)))
8311 _ (
"setsockopt failed: %s\n"),
8320#ifndef MHD_WINSOCK_SOCKETS
8326 (
const void *) &on, sizeof (on)))
8330 _ (
"setsockopt failed: %s\n"),
8340#if defined(MHD_WINSOCK_SOCKETS) || defined(SO_REUSEPORT)
8343#ifndef MHD_WINSOCK_SOCKETS
8353 _ (
"setsockopt failed: %s\n"),
8363 _ (
"Cannot allow listening address reuse: " \
8364 "SO_REUSEPORT not defined.\n"));
8377#if (defined(MHD_WINSOCK_SOCKETS) && defined(SO_EXCLUSIVEADDRUSE)) || \
8378 (defined(__sun) && defined(SO_EXCLBIND))
8381#ifdef SO_EXCLUSIVEADDRUSE
8382 SO_EXCLUSIVEADDRUSE,
8391 _ (
"setsockopt failed: %s\n"),
8396#elif defined(MHD_WINSOCK_SOCKETS)
8399 _ (
"Cannot disallow listening address reuse: " \
8400 "SO_EXCLUSIVEADDRUSE not defined.\n"));
8418 IPPROTO_IPV6, IPV6_V6ONLY,
8419 (
const void *) &v6_only,
8424 _ (
"setsockopt failed: %s\n"),
8437 _ (
"Failed to bind to port %u: %s\n"),
8438 (
unsigned int) port,
8446 if (0 == daemon->fastopen_queue_size)
8447 daemon->fastopen_queue_size = MHD_TCP_FASTOPEN_QUEUE_SIZE_DEFAULT;
8451 (
const void *) &daemon->fastopen_queue_size,
8452 sizeof (daemon->fastopen_queue_size)))
8456 _ (
"setsockopt failed: %s\n"),
8467 _ (
"Failed to listen for connections: %s\n"),
8481 _ (
"Listen socket descriptor (%d) is not " \
8482 "less than daemon FD_SETSIZE value (%d).\n"),
8490#if defined(SOL_SOCKET) && (defined(SO_DOMAIN) || defined(SO_PROTOCOL_INFOW))
8494 socklen_t optval_size;
8496 opt_name = SO_DOMAIN;
8498 optval_size = (socklen_t)
sizeof (af);
8500 WSAPROTOCOL_INFOW prot_info;
8501 opt_name = SO_PROTOCOL_INFOW;
8502 poptval = &prot_info;
8503 optval_size = (socklen_t)
sizeof (prot_info);
8513 af = prot_info.iAddressFamily;
8543#ifdef MHD_USE_GETSOCKNAME
8548#ifdef MHD_USE_GETSOCKNAME
8549 if ( (0 == daemon->
port) &&
8553 struct sockaddr_storage bindaddr;
8557 sizeof (
struct sockaddr_storage));
8558 addrlen =
sizeof (
struct sockaddr_storage);
8559#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
8560 bindaddr.ss_len = (socklen_t) addrlen;
8562 if (0 != getsockname (daemon->
listen_fd,
8563 (
struct sockaddr *) &bindaddr,
8568 _ (
"Failed to get listen port number: %s\n"),
8569 MHD_socket_last_strerr_ ());
8573 else if (
sizeof (bindaddr) < addrlen)
8578 _ (
"Failed to get listen port number " \
8579 "(`struct sockaddr_storage` too small!?).\n"));
8583 else if (0 == addrlen)
8595 switch (bindaddr.ss_family)
8599 struct sockaddr_in *s4 = (
struct sockaddr_in *) &bindaddr;
8601 daemon->
port = ntohs (s4->sin_port);
8608 struct sockaddr_in6 *s6 = (
struct sockaddr_in6 *) &bindaddr;
8610 daemon->
port = ntohs (s6->sin6_port);
8625 _ (
"Listen socket has unknown address family!\n"));
8642 _ (
"Failed to set nonblocking mode on listening socket: %s\n"),
8646#
if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8647 || (daemon->worker_pool_size > 0)
8669#
if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8670 && (0 == daemon->worker_pool_size)
8678 _ (
"Combining MHD_USE_THREAD_PER_CONNECTION and " \
8679 "MHD_USE_EPOLL is not supported.\n"));
8683 if (
MHD_NO == setup_epoll_to_listen (daemon))
8688#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8693 _ (
"MHD failed to initialize IP connection limit mutex.\n"));
8702 (0 != MHD_TLS_init (daemon)) )
8706 _ (
"Failed to initialize TLS support.\n"));
8708#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8714#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8722#ifdef HAVE_LISTEN_SHUTDOWN
8723 mhd_assert ((1 < daemon->worker_pool_size) || \
8724 (MHD_ITC_IS_VALID_ (daemon->
itc)) || \
8727 mhd_assert ((1 < daemon->worker_pool_size) || \
8728 (MHD_ITC_IS_VALID_ (daemon->
itc)));
8730 if (0 == daemon->worker_pool_size)
8736 _ (
"Failed to initialise internal lists mutex.\n"));
8745 _ (
"Failed to initialise mutex.\n"));
8753 "MHD-listen" :
"MHD-single",
8754 daemon->thread_stack_size,
8755 &MHD_polling_thread,
8760 if (EAGAIN == errno)
8762 _ (
"Failed to create a new thread because it would have " \
8763 "exceeded the system limit on the number of threads or " \
8764 "no system resources available.\n"));
8768 _ (
"Failed to create listen thread: %s\n"),
8783 / daemon->worker_pool_size;
8785 % daemon->worker_pool_size;
8791 daemon->worker_pool = malloc (
sizeof (
struct MHD_Daemon)
8792 * daemon->worker_pool_size);
8793 if (
NULL == daemon->worker_pool)
8797 for (i = 0; i < daemon->worker_pool_size; ++i)
8800 struct MHD_Daemon *d = &daemon->worker_pool[i];
8802 memcpy (d, daemon,
sizeof (
struct MHD_Daemon));
8807 d->worker_pool_size = 0;
8808 d->worker_pool =
NULL;
8813 _ (
"Failed to initialise internal lists mutex.\n"));
8821 _ (
"Failed to initialise mutex.\n"));
8828 if (! MHD_itc_init_ (d->
itc))
8832 _ (
"Failed to create worker inter-thread " \
8833 "communication channel: %s\n"),
8834 MHD_itc_last_strerror_ () );
8845 _ (
"File descriptor for worker inter-thread " \
8846 "communication channel exceeds maximum value.\n"));
8855 MHD_itc_set_invalid_ (d->
itc);
8857#ifdef HAVE_LISTEN_SHUTDOWN
8868 if (i < leftover_conns)
8872 (
MHD_NO == setup_epoll_to_listen (d)) )
8874 if (MHD_ITC_IS_VALID_ (d->
itc))
8882#if defined(MHD_USE_THREADS)
8883 memset (&d->per_ip_connection_mutex, 0x7F,
8884 sizeof(d->per_ip_connection_mutex));
8888 d->nonce_nc_size = 0;
8889 d->digest_auth_random_copy =
NULL;
8890#if defined(MHD_USE_THREADS)
8891 memset (&d->nnc_lock, 0x7F,
sizeof(d->nnc_lock));
8898 daemon->thread_stack_size,
8899 &MHD_polling_thread,
8904 if (EAGAIN == errno)
8906 _ (
"Failed to create a new pool thread because it would " \
8907 "have exceeded the system limit on the number of " \
8908 "threads or no system resources available.\n"));
8912 _ (
"Failed to create pool thread: %s\n"),
8918 if (MHD_ITC_IS_VALID_ (d->
itc))
8933 _ (
"Failed to initialise internal lists mutex.\n"));
8942 _ (
"Failed to initialise mutex.\n"));
8953 daemon->https_key_password =
NULL;
8958#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8967 if (
NULL != daemon->worker_pool)
8968 free (daemon->worker_pool);
8976 daemon->worker_pool_size = i;
8985#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
8986 if (daemon->upgrade_fd_in_epoll)
8988 if (0 != epoll_ctl (daemon->epoll_fd,
8990 daemon->epoll_upgrade_fd,
8992 MHD_PANIC (
_ (
"Failed to remove FD from epoll set.\n"));
8993 daemon->upgrade_fd_in_epoll =
false;
8996 if (-1 != daemon->epoll_fd)
8997 close (daemon->epoll_fd);
8998#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
8999 if (-1 != daemon->epoll_upgrade_fd)
9000 close (daemon->epoll_upgrade_fd);
9004 free (daemon->digest_auth_random_copy);
9006#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9013 gnutls_priority_deinit (daemon->priority_cache);
9014 if (daemon->x509_cred)
9015 gnutls_certificate_free_credentials (daemon->x509_cred);
9016 if (daemon->psk_cred)
9017 gnutls_psk_free_server_credentials (daemon->psk_cred);
9020 if (MHD_ITC_IS_VALID_ (daemon->
itc))
9042#ifdef UPGRADE_SUPPORT
9045#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
9046 struct MHD_UpgradeResponseHandle *urh;
9047 struct MHD_UpgradeResponseHandle *urhn;
9051#ifdef MHD_USE_THREADS
9059#ifdef MHD_USE_THREADS
9069 new_connection_close_ (daemon, pos);
9074#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
9077 for (urh = daemon->urh_tail;
NULL != urh; urh = urhn)
9085 urh->clean_ready =
true;
9102#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9105#ifdef UPGRADE_SUPPORT
9111 while (
NULL != susp)
9113 if (
NULL == susp->urh)
9114 MHD_PANIC (
_ (
"MHD_stop_daemon() called while we have " \
9115 "suspended connections.\n"));
9117 else if (used_tls &&
9119 (! susp->urh->clean_ready) )
9120 shutdown (susp->urh->app.socket,
9126 if (! susp->urh->was_closed)
9128 _ (
"Initiated daemon shutdown while \"upgraded\" " \
9129 "connection was not closed.\n"));
9131 susp->urh->was_closed =
true;
9147 MHD_PANIC (
_ (
"MHD_stop_daemon() called while we have " \
9148 "suspended connections.\n"));
9149#if defined(UPGRADE_SUPPORT) && defined(HTTPS_SUPPORT)
9150#ifdef MHD_USE_THREADS
9151 if (upg_allowed && used_tls && used_thr_p_c)
9162 if (! pos->thread_joined)
9170 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
9171 pos->thread_joined =
true;
9182#ifdef MHD_WINSOCK_SOCKETS
9185 (! MHD_itc_activate_ (
daemon->
itc,
"e")) )
9186 MHD_PANIC (
_ (
"Failed to signal shutdown via inter-thread " \
9187 "communication channel.\n"));
9191#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9198 if (! pos->thread_joined)
9202 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
9204 pos->thread_joined =
true;
9216#ifdef UPGRADE_SUPPORT
9232#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9234 (! pos->thread_joined) )
9235 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
9253#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9260 MHD_PANIC (
_ (
"MHD_stop_daemon() was called twice."));
9278#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9285 for (i = 0; i <
daemon->worker_pool_size; ++i)
9288 if (MHD_ITC_IS_VALID_ (
daemon->worker_pool[i].
itc))
9290 if (! MHD_itc_activate_ (
daemon->worker_pool[i].
itc,
9292 MHD_PANIC (
_ (
"Failed to signal shutdown via inter-thread " \
9293 "communication channel.\n"));
9298#ifdef HAVE_LISTEN_SHUTDOWN
9301 (void) shutdown (
fd,
9305 for (i = 0; i <
daemon->worker_pool_size; ++i)
9309 free (
daemon->worker_pool);
9313#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
9321#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9330 MHD_PANIC (
_ (
"Failed to signal shutdown via inter-thread " \
9331 "communication channel.\n"));
9335#ifdef HAVE_LISTEN_SHUTDOWN
9339 (void) shutdown (
fd,
9349 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
9363#if defined(UPGRADE_SUPPORT) && defined(HTTPS_SUPPORT)
9372 (-1 !=
daemon->epoll_fd) )
9374#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
9376 (-1 !=
daemon->epoll_upgrade_fd) )
9381#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9396 if (
daemon->have_dhparams)
9398 gnutls_dh_params_deinit (
daemon->https_mem_dhparams);
9399 daemon->have_dhparams =
false;
9403 gnutls_priority_deinit (
daemon->priority_cache);
9405 gnutls_certificate_free_credentials (
daemon->x509_cred);
9407 gnutls_psk_free_server_credentials (
daemon->psk_cred);
9412 free (
daemon->digest_auth_random_copy);
9414#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9418#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9447 (
NULL != daemon->worker_pool) || \
9450 (
NULL == daemon->worker_pool)) || \
9464 daemon->daemon_info_dummy_epoll_fd.epoll_fd = daemon->epoll_fd;
9465 return &daemon->daemon_info_dummy_epoll_fd;
9472#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9473 else if (daemon->worker_pool)
9478 for (i = 0; i < daemon->worker_pool_size; i++)
9509#ifdef PACKAGE_VERSION
9510 return PACKAGE_VERSION;
9512 static char ver[12] =
"\0\0\0\0\0\0\0\0\0\0\0";
9515 int res = MHD_snprintf_ (ver,
9521 if ((0 >= res) || (
sizeof(ver) <= res))
9573#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_MAJOR >= 3
9579#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_NUMBER >= 0x030603
9591#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
9609#ifdef HAVE_LISTEN_SHUTDOWN
9615#ifdef _MHD_ITC_SOCKETPAIR
9639#ifdef HAVE_POSTPROCESSOR
9645#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_NUMBER >= 0x030111
9651#if defined(HAVE_PREAD64) || defined(_WIN32)
9653#elif defined(HAVE_PREAD)
9654 return (
sizeof(uint64_t) >
sizeof(off_t)) ?
MHD_NO :
MHD_YES;
9655#elif defined(HAVE_LSEEK64)
9658 return (
sizeof(uint64_t) >
sizeof(off_t)) ?
MHD_NO :
MHD_YES;
9661#if defined(MHD_USE_THREAD_NAME_)
9667#if defined(UPGRADE_SUPPORT)
9673#if defined(HAVE_PREAD64) || defined(HAVE_PREAD) || defined(_WIN32)
9679#ifdef MHD_USE_GETSOCKNAME
9685#if defined(MHD_SEND_SPIPE_SUPPRESS_POSSIBLE) || \
9686 ! defined(MHD_SEND_SPIPE_SUPPRESS_NEEDED)
9692#ifdef _MHD_HAVE_SENDFILE
9698#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9704#if defined(COOKIE_SUPPORT)
9716#if defined(DAUTH_SUPPORT) && defined(MHD_MD5_SUPPORT)
9722#if defined(DAUTH_SUPPORT) && defined(MHD_SHA256_SUPPORT)
9728#if defined(DAUTH_SUPPORT) && defined(MHD_SHA512_256_SUPPORT)
9752#if defined(MHD_MD5_TLSLIB) || defined(MHD_SHA256_TLSLIB)
9764#ifdef HAS_FD_SETSIZE_OVERRIDABLE
9777#ifdef MHD_HTTPS_REQUIRE_GCRYPT
9778#if defined(HTTPS_SUPPORT) && GCRYPT_VERSION_NUMBER < 0x010600
9779#if defined(MHD_USE_POSIX_THREADS)
9780GCRY_THREAD_OPTION_PTHREAD_IMPL;
9781#elif defined(MHD_W32_MUTEX_)
9784gcry_w32_mutex_init (
void **ppmtx)
9786 *ppmtx = malloc (
sizeof (MHD_mutex_));
9802gcry_w32_mutex_destroy (
void **ppmtx)
9811gcry_w32_mutex_lock (
void **ppmtx)
9818gcry_w32_mutex_unlock (
void **ppmtx)
9824static struct gcry_thread_cbs gcry_threads_w32 = {
9825 (GCRY_THREAD_OPTION_USER | (GCRY_THREAD_OPTION_VERSION << 8)),
9826 NULL, gcry_w32_mutex_init, gcry_w32_mutex_destroy,
9827 gcry_w32_mutex_lock, gcry_w32_mutex_unlock,
9841#if defined(MHD_WINSOCK_SOCKETS)
9847#if defined(MHD_WINSOCK_SOCKETS)
9848 if (0 != WSAStartup (MAKEWORD (2, 2), &wsd))
9849 MHD_PANIC (
_ (
"Failed to initialize winsock.\n"));
9850 if ((2 != LOBYTE (wsd.wVersion)) && (2 != HIBYTE (wsd.wVersion)))
9851 MHD_PANIC (
_ (
"Winsock version 2.2 is not available.\n"));
9854#ifdef MHD_HTTPS_REQUIRE_GCRYPT
9855#if GCRYPT_VERSION_NUMBER < 0x010600
9856#if GNUTLS_VERSION_NUMBER <= 0x020b00
9857#if defined(MHD_USE_POSIX_THREADS)
9858 if (0 != gcry_control (GCRYCTL_SET_THREAD_CBS,
9859 &gcry_threads_pthread))
9860 MHD_PANIC (
_ (
"Failed to initialise multithreading in libgcrypt.\n"));
9861#elif defined(MHD_W32_MUTEX_)
9862 if (0 != gcry_control (GCRYCTL_SET_THREAD_CBS,
9864 MHD_PANIC (
_ (
"Failed to initialise multithreading in libgcrypt.\n"));
9867 gcry_check_version (
NULL);
9869 if (
NULL == gcry_check_version (
"1.6.0"))
9870 MHD_PANIC (
_ (
"libgcrypt is too old. MHD was compiled for " \
9871 "libgcrypt 1.6.0 or newer.\n"));
9874 gnutls_global_init ();
9884 mhd_assert (
sizeof(tv.tv_sec) == SIZEOF_STRUCT_TIMEVAL_TV_SEC);
9887 mhd_assert (
sizeof(uint64_t) == SIZEOF_UINT64_T);
9895 gnutls_global_deinit ();
9897#if defined(MHD_WINSOCK_SOCKETS)
9904#ifdef _AUTOINIT_FUNCS_ARE_SUPPORTED
#define _SET_INIT_AND_DEINIT_FUNCS(FI, FD)
void MHD_connection_set_initial_state_(struct MHD_Connection *c)
void MHD_connection_handle_write(struct MHD_Connection *connection)
void MHD_set_http_callbacks_(struct MHD_Connection *connection)
enum MHD_Result MHD_connection_handle_idle(struct MHD_Connection *connection)
void MHD_connection_handle_read(struct MHD_Connection *connection, bool socket_error)
void MHD_update_last_activity_(struct MHD_Connection *connection)
void MHD_connection_close_(struct MHD_Connection *connection, enum MHD_RequestTerminationCode termination_code)
void MHD_connection_mark_closed_(struct MHD_Connection *connection)
Methods for managing connections.
#define MHD_connection_finish_forward_(conn)
void MHD_set_https_callbacks(struct MHD_Connection *connection)
Methods for managing connections.
static void MHD_ip_limit_del(struct MHD_Daemon *daemon, const struct sockaddr_storage *addr, socklen_t addrlen)
static void close_all_connections(struct MHD_Daemon *daemon)
static enum MHD_Result MHD_ip_addr_to_key(const struct sockaddr_storage *addr, socklen_t addrlen, struct MHD_IPCount *key)
void internal_suspend_connection_(struct MHD_Connection *connection)
static enum MHD_Result MHD_ip_limit_add(struct MHD_Daemon *daemon, const struct sockaddr_storage *addr, socklen_t addrlen)
static enum MHD_Result call_handlers(struct MHD_Connection *con, bool read_ready, bool write_ready, bool force_close)
static void MHD_ip_count_unlock(struct MHD_Daemon *daemon)
static struct MHD_Connection * new_connection_prepare_(struct MHD_Daemon *daemon, MHD_socket client_socket, const struct sockaddr_storage *addr, socklen_t addrlen, bool external_add, bool non_blck, bool sk_spipe_supprs, enum MHD_tristate sk_is_nonip)
volatile int global_init_count
void MHD_check_global_init_(void)
static void close_connection(struct MHD_Connection *pos)
_MHD_EXTERN void MHD_resume_connection(struct MHD_Connection *connection)
static enum MHD_Result MHD_select(struct MHD_Daemon *daemon, int32_t millisec)
static enum MHD_Result parse_options(struct MHD_Daemon *daemon, struct MHD_InterimParams_ *params,...)
static int MHD_ip_addr_compare(const void *a1, const void *a2)
static void new_connections_list_process_(struct MHD_Daemon *daemon)
static void MHD_cleanup_connections(struct MHD_Daemon *daemon)
void(* VfprintfFunctionPointerType)(void *cls, const char *format, va_list va)
static enum MHD_Result MHD_accept_connection(struct MHD_Daemon *daemon)
static enum MHD_Result parse_options_va(struct MHD_Daemon *daemon, struct MHD_InterimParams_ *params, va_list ap)
#define MHD_MAX_CONNECTIONS_DEFAULT
static size_t unescape_wrapper(void *cls, struct MHD_Connection *connection, char *val)
static enum MHD_Result new_connection_process_(struct MHD_Daemon *daemon, struct MHD_Connection *connection)
static enum MHD_Result internal_add_connection(struct MHD_Daemon *daemon, MHD_socket client_socket, const struct sockaddr_storage *addr, socklen_t addrlen, bool external_add, bool non_blck, bool sk_spipe_supprs, enum MHD_tristate sk_is_nonip)
static void MHD_ip_count_lock(struct MHD_Daemon *daemon)
static enum MHD_Result resume_suspended_connections(struct MHD_Daemon *daemon)
#define MHD_POOL_SIZE_DEFAULT
static bool process_interim_params(struct MHD_Daemon *d, const struct sockaddr **ppsockaddr, socklen_t *psockaddr_len, struct MHD_InterimParams_ *params)
_MHD_EXTERN void MHD_suspend_connection(struct MHD_Connection *connection)
_MHD_EXTERN int MHD_get_timeout_i(struct MHD_Daemon *daemon)
_MHD_EXTERN int64_t MHD_get_timeout64s(struct MHD_Daemon *daemon)
#define MHD_run_from_select(d, r, w, e)
_MHD_EXTERN void MHD_stop_daemon(struct MHD_Daemon *daemon)
_MHD_EXTERN struct MHD_Daemon * MHD_start_daemon_va(unsigned int flags, uint16_t port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls, va_list ap)
_MHD_EXTERN enum MHD_Result MHD_run(struct MHD_Daemon *daemon)
static enum MHD_Result internal_run_from_select(struct MHD_Daemon *daemon, const fd_set *read_fd_set, const fd_set *write_fd_set, const fd_set *except_fd_set, int fd_setsize)
_MHD_EXTERN enum MHD_Result MHD_get_fdset2(struct MHD_Daemon *daemon, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, MHD_socket *max_fd, unsigned int fd_setsize)
static enum MHD_Result internal_get_fdset2(struct MHD_Daemon *daemon, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, MHD_socket *max_fd, int fd_setsize)
#define MHD_get_fdset(daemon, read_fd_set, write_fd_set, except_fd_set, max_fd)
_MHD_EXTERN enum MHD_Result MHD_get_timeout(struct MHD_Daemon *daemon, MHD_UNSIGNED_LONG_LONG *timeout)
_MHD_EXTERN enum MHD_Result MHD_get_timeout64(struct MHD_Daemon *daemon, uint64_t *timeout)
_MHD_EXTERN enum MHD_Result MHD_run_from_select2(struct MHD_Daemon *daemon, const fd_set *read_fd_set, const fd_set *write_fd_set, const fd_set *except_fd_set, unsigned int fd_setsize)
_MHD_EXTERN struct MHD_Daemon * MHD_start_daemon(unsigned int flags, uint16_t port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls,...)
_MHD_EXTERN enum MHD_Result MHD_run_wait(struct MHD_Daemon *daemon, int32_t millisec)
_MHD_EXTERN void MHD_set_panic_func(MHD_PanicCallback cb, void *cls)
void(* MHD_RequestCompletedCallback)(void *cls, struct MHD_Connection *connection, void **req_cls, enum MHD_RequestTerminationCode toe)
void(* MHD_NotifyConnectionCallback)(void *cls, struct MHD_Connection *connection, void **socket_context, enum MHD_ConnectionNotificationCode toe)
@ MHD_CONNECTION_NOTIFY_STARTED
@ MHD_CONNECTION_NOTIFY_CLOSED
@ MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN
@ MHD_REQUEST_TERMINATED_COMPLETED_OK
@ MHD_REQUEST_TERMINATED_WITH_ERROR
_MHD_EXTERN void MHD_destroy_response(struct MHD_Response *response)
_MHD_EXTERN enum MHD_Result MHD_add_connection(struct MHD_Daemon *daemon, MHD_socket client_socket, const struct sockaddr *addr, socklen_t addrlen)
_MHD_EXTERN enum MHD_Result MHD_is_feature_supported(enum MHD_FEATURE feature)
_MHD_EXTERN MHD_socket MHD_quiesce_daemon(struct MHD_Daemon *daemon)
_MHD_EXTERN const union MHD_DaemonInfo * MHD_get_daemon_info(struct MHD_Daemon *daemon, enum MHD_DaemonInfoType info_type,...)
_MHD_EXTERN uint32_t MHD_get_version_bin(void)
_MHD_EXTERN const char * MHD_get_version(void)
_MHD_EXTERN void MHD_free(void *ptr)
MHD internal shared structures.
@ MHD_CONNECTION_HEADERS_SENDING
@ MHD_CONNECTION_NORMAL_BODY_READY
@ MHD_CONNECTION_CHUNKED_BODY_READY
#define MHD_D_IS_USING_POLL_(d)
#define XDLL_insert(head, tail, element)
@ MHD_EPOLL_STATE_SUSPENDED
@ MHD_EPOLL_STATE_IN_EREADY_EDLL
@ MHD_EPOLL_STATE_READ_READY
@ MHD_EPOLL_STATE_IN_EPOLL_SET
@ MHD_EPOLL_STATE_WRITE_READY
#define DLL_insert(head, tail, element)
#define MHD_D_DOES_SCKT_FIT_FDSET_(sckt, d)
@ MHD_EVENT_LOOP_INFO_PROCESS_READ
@ MHD_EVENT_LOOP_INFO_PROCESS
@ MHD_EVENT_LOOP_INFO_READ
@ MHD_EVENT_LOOP_INFO_WRITE
@ MHD_EVENT_LOOP_INFO_CLEANUP
#define MHD_D_IS_USING_SELECT_(d)
#define EDLL_insert(head, tail, element)
void *(* LogCallback)(void *cls, const char *uri, struct MHD_Connection *con)
_MHD_static_inline struct MHD_Daemon * MHD_get_master(struct MHD_Daemon *const daemon)
#define _MHD_DROP_CONST(ptr)
#define MHD_D_GET_FD_SETSIZE_(d)
#define EDLL_remove(head, tail, element)
#define XDLL_remove(head, tail, element)
#define MHD_D_IS_USING_THREAD_PER_CONN_(d)
#define DLL_remove(head, tail, element)
#define MHD_D_IS_USING_THREADS_(d)
#define MHD_TEST_ALLOW_SUSPEND_RESUME
size_t(* UnescapeCallback)(void *cls, struct MHD_Connection *conn, char *uri)
#define MHD_D_IS_USING_EPOLL_(d)
#define MHD_D_IS_THREAD_SAFE_(d)
void MHD_init_mem_pools_(void)
void MHD_pool_destroy(struct MemoryPool *pool)
struct MemoryPool * MHD_pool_create(size_t max)
memory pool; mostly used for efficient (de)allocation for each connection and bounding memory use for...
#define mhd_assert(ignore)
void * MHD_calloc_(size_t nelem, size_t elsize)
Header for platform missing functions.
#define MHD_strerror_(errnum)
Header for platform-independent inter-thread communication.
#define MHD_ITC_IS_INVALID_(itc)
#define MHD_itc_destroy_chk_(itc)
limits values definitions
#define TIMEVAL_TV_SEC_MAX
Header for platform-independent locks abstraction.
#define MHD_mutex_unlock_chk_(ignore)
#define MHD_mutex_destroy_(ignore)
#define MHD_mutex_unlock_(ignore)
#define MHD_mutex_lock_(ignore)
#define MHD_mutex_init_(ignore)
#define MHD_mutex_lock_chk_(ignore)
#define MHD_mutex_destroy_chk_(ignore)
uint64_t MHD_monotonic_msec_counter(void)
void MHD_monotonic_sec_counter_finish(void)
void MHD_monotonic_sec_counter_init(void)
internal monotonic clock functions implementations
#define MHD_DAUTH_DEF_TIMEOUT_
#define MHD_DAUTH_DEF_MAX_NC_
void MHD_send_init_static_vars_(void)
Declarations of send() wrappers.
int MHD_socket_noninheritable_(MHD_socket sock)
int MHD_socket_nonblocking_(MHD_socket sock)
int MHD_add_to_fd_set_(MHD_socket fd, fd_set *set, MHD_socket *max_fd, int fd_setsize)
MHD_socket MHD_socket_create_listen_(int pf)
#define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err)
#define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd, pset, setsize)
#define MHD_SCKT_ERR_IS_(err, code)
#define SOCK_NONBLOCK_OR_ZERO
#define MHD_socket_close_(fd)
#define MHD_SCKT_ERR_IS_EAGAIN_(err)
#define MHD_SCKT_ERR_IS_LOW_RESOURCES_(err)
#define _MHD_SYS_DEFAULT_FD_SETSIZE
#define MHD_socket_strerr_(err)
#define MHD_socket_last_strerr_()
#define MHD_socket_get_error_()
#define SOCK_NOSIGPIPE_OR_ZERO
#define MHD_socket_close_chk_(fd)
#define MHD_SCKT_ERR_IS_EINTR_(err)
#define MHD_socket_fset_error_(err)
#define MHD_SCKT_SEND_MAX_SIZE_
#define MHD_recv_(s, b, l)
#define MHD_send_(s, b, l)
#define MHD_SCKT_LAST_ERR_IS_(code)
#define MHD_SYS_select_(n, r, w, e, t)
#define SOCK_CLOEXEC_OR_ZERO
size_t MHD_str_pct_decode_in_place_lenient_(char *str, bool *broken_encoding)
size_t MHD_str_pct_decode_in_place_strict_(char *str)
Header for string manipulating helpers.
#define _MHD_S_STR_W_LEN(str)
#define MHD_STATICSTR_LEN_(macro)
Header for platform-independent threads abstraction.
#define MHD_thread_handle_ID_set_current_thread_ID_(hndl_id_ptr)
#define MHD_thread_handle_ID_is_current_thread_(hndl_id)
#define MHD_thread_handle_ID_is_valid_handle_(hndl_id)
#define MHD_thread_handle_ID_join_thread_(hndl_id)
#define MHD_thread_handle_ID_set_invalid_(hndl_id_ptr)
#define MHD_thread_handle_ID_is_valid_ID_(hndl_id)
#define MHD_create_named_thread_(t, n, s, r, a)
@ MHD_FEATURE_POSTPROCESSOR
@ MHD_FEATURE_SHUTDOWN_LISTEN_SOCKET
@ MHD_FEATURE_DIGEST_AUTH_USERHASH
@ MHD_FEATURE_DIGEST_AUTH_AUTH_INT
@ MHD_FEATURE_DIGEST_AUTH_SHA256
@ MHD_FEATURE_AUTODETECT_BIND_PORT
@ MHD_FEATURE_DIGEST_AUTH_SHA512_256
@ MHD_FEATURE_EXTERN_HASH
@ MHD_FEATURE_HTTPS_CERT_CALLBACK
@ MHD_FEATURE_DIGEST_AUTH
@ MHD_FEATURE_THREAD_NAMES
@ MHD_FEATURE_DEBUG_BUILD
@ MHD_FEATURE_FLEXIBLE_FD_SETSIZE
@ MHD_FEATURE_HTTPS_KEY_PASSWORD
@ MHD_FEATURE_AUTOSUPPRESS_SIGPIPE
@ MHD_FEATURE_RESPONSES_SHARED_FD
@ MHD_FEATURE_DIGEST_AUTH_ALGO_SESSION
@ MHD_FEATURE_COOKIE_PARSING
@ MHD_FEATURE_DIGEST_AUTH_MD5
@ MHD_FEATURE_TCP_FASTOPEN
@ MHD_FEATURE_DIGEST_AUTH_RFC2069
@ MHD_FEATURE_HTTPS_CERT_CALLBACK2
@ MHD_OPTION_HTTPS_PRIORITIES_APPEND
@ MHD_OPTION_CONNECTION_MEMORY_INCREMENT
@ MHD_OPTION_HTTPS_CRED_TYPE
@ MHD_OPTION_URI_LOG_CALLBACK
@ MHD_OPTION_HTTPS_CERT_CALLBACK2
@ MHD_OPTION_DIGEST_AUTH_DEFAULT_NONCE_TIMEOUT
@ MHD_OPTION_CLIENT_DISCIPLINE_LVL
@ MHD_OPTION_SOCK_ADDR_LEN
@ MHD_OPTION_APP_FD_SETSIZE
@ MHD_OPTION_SIGPIPE_HANDLED_BY_APP
@ MHD_OPTION_UNESCAPE_CALLBACK
@ MHD_OPTION_EXTERNAL_LOGGER
@ MHD_OPTION_LISTEN_BACKLOG_SIZE
@ MHD_OPTION_HTTPS_PRIORITIES
@ MHD_OPTION_HTTPS_MEM_DHPARAMS
@ MHD_OPTION_NOTIFY_CONNECTION
@ MHD_OPTION_LISTENING_ADDRESS_REUSE
@ MHD_OPTION_THREAD_POOL_SIZE
@ MHD_OPTION_CONNECTION_LIMIT
@ MHD_OPTION_PER_IP_CONNECTION_LIMIT
@ MHD_OPTION_DIGEST_AUTH_DEFAULT_MAX_NC
@ MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE
@ MHD_OPTION_HTTPS_MEM_CERT
@ MHD_OPTION_SERVER_INSANITY
@ MHD_OPTION_LISTEN_SOCKET
@ MHD_OPTION_HTTPS_MEM_KEY
@ MHD_OPTION_DIGEST_AUTH_RANDOM
@ MHD_OPTION_HTTPS_KEY_PASSWORD
@ MHD_OPTION_NONCE_NC_SIZE
@ MHD_OPTION_ALLOW_BIN_ZERO_IN_URI_PATH
@ MHD_OPTION_CONNECTION_MEMORY_LIMIT
@ MHD_OPTION_THREAD_STACK_SIZE
@ MHD_OPTION_DIGEST_AUTH_RANDOM_COPY
@ MHD_OPTION_STRICT_FOR_CLIENT
@ MHD_OPTION_DIGEST_AUTH_NONCE_BIND_TYPE
@ MHD_OPTION_CONNECTION_TIMEOUT
@ MHD_OPTION_GNUTLS_PSK_CRED_HANDLER
@ MHD_OPTION_HTTPS_MEM_TRUST
@ MHD_OPTION_HTTPS_CERT_CALLBACK
@ MHD_OPTION_NOTIFY_COMPLETED
enum MHD_Result(* MHD_AcceptPolicyCallback)(void *cls, const struct sockaddr *addr, socklen_t addrlen)
#define MHD_UNSIGNED_LONG_LONG
enum MHD_Result(* MHD_AccessHandlerCallback)(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **req_cls)
#define MHD_POSIX_SOCKETS
#define MHD_INVALID_SOCKET
int(* MHD_PskServerCredentialsCallback)(void *cls, const struct MHD_Connection *connection, const char *username, void **psk, size_t *psk_size)
@ MHD_DAEMON_INFO_MAC_KEY_SIZE
@ MHD_DAEMON_INFO_BIND_PORT
@ MHD_DAEMON_INFO_EPOLL_FD
@ MHD_DAEMON_INFO_KEY_SIZE
@ MHD_DAEMON_INFO_CURRENT_CONNECTIONS
@ MHD_DAEMON_INFO_LISTEN_FD
MHD_FLAG
Flags for the struct MHD_Daemon.
@ MHD_ALLOW_SUSPEND_RESUME
@ MHD_USE_THREAD_PER_CONNECTION
@ MHD_USE_POST_HANDSHAKE_AUTH_SUPPORT
@ MHD_USE_SELECT_INTERNALLY
@ MHD_USE_INSECURE_TLS_EARLY_DATA
@ MHD_USE_NO_LISTEN_SOCKET
@ MHD_USE_PEDANTIC_CHECKS
@ MHD_USE_INTERNAL_POLLING_THREAD
@ MHD_USE_NO_THREAD_SAFETY
@ MHD_DAUTH_BIND_NONCE_URI
@ MHD_DAUTH_BIND_NONCE_URI_PARAMS
Methods for managing response objects.
enum MHD_tristate sk_nodelay
struct MHD_Connection * prev
enum MHD_ConnectionEventLoopInfo event_loop_info
enum MHD_tristate is_nonip
struct MHD_Connection * nextX
struct MHD_Connection * next
size_t read_buffer_offset
enum MHD_CONNECTION_STATE state
struct MHD_Connection * prevX
struct MHD_Daemon * daemon
uint64_t connection_timeout_ms
struct sockaddr_storage * addr
enum MHD_tristate sk_corked
MHD_NotifyConnectionCallback notify_connection
MHD_AccessHandlerCallback default_handler
LogCallback uri_log_callback
bool data_already_pending
union MHD_DaemonInfo daemon_info_dummy_port
struct MHD_Connection * normal_timeout_tail
struct MHD_Connection * new_connections_tail
unsigned int connection_limit
void * unescape_callback_cls
enum MHD_DisableSanityCheck insanity_level
struct MHD_Connection * connections_tail
struct MHD_Connection * suspended_connections_tail
union MHD_DaemonInfo daemon_info_dummy_listen_fd
struct MHD_Connection * manual_timeout_head
unsigned int listen_backlog_size
struct MHD_Connection * normal_timeout_head
union MHD_DaemonInfo daemon_info_dummy_flags
MHD_RequestCompletedCallback notify_completed
struct MHD_Connection * cleanup_head
int listening_address_reuse
uint64_t connection_timeout_ms
unsigned int per_ip_connection_limit
struct MHD_Connection * manual_timeout_tail
union MHD_DaemonInfo daemon_info_dummy_num_connections
void * notify_connection_cls
struct MHD_Connection * cleanup_tail
UnescapeCallback unescape_callback
void * notify_completed_cls
volatile bool was_quiesced
struct MHD_Connection * suspended_connections_head
struct MHD_Connection * new_connections_head
enum MHD_tristate listen_is_unix
void * default_handler_cls
struct MHD_Connection * connections_head
MHD_AcceptPolicyCallback apc
void * per_ip_connection_count
void * uri_log_callback_cls
struct MHD_Daemon * master
struct MHD_Response * response
void * tfind(const void *vkey, void *const *vrootp, int(*compar)(const void *, const void *))
void * tdelete(const void *vkey, void **vrootp, int(*compar)(const void *, const void *))
void * tsearch(const void *vkey, void **vrootp, int(*compar)(const void *, const void *))
unsigned int num_connections