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;
1316 (read_ready || (force_close && con->
sk_nonblck)) )
1323 states_info_processed =
true;
1334 states_info_processed =
true;
1344 if (! states_info_processed)
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;
1518 & urh->app.celi)) ||
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],
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;
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;
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;
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;
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);
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_
2006 unsigned int extra_slot;
2008#define EXTRA_SLOTS 1
2010#define EXTRA_SLOTS 0
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;
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,
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
3555#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3558 if ( (used_thr_p_c) &&
3561 if (! MHD_itc_activate_ (daemon->
itc,
3566 _ (
"Failed to signal resume of connection via " \
3567 "inter-thread communication channel.\n"));
3605 const struct sockaddr *addr,
3609 bool sk_spipe_supprs;
3610 struct sockaddr_storage addrstorage;
3622 _ (
"MHD_add_connection() has been called for daemon started"
3623 " without MHD_USE_ITC flag.\nDaemon will not process newly"
3624 " added connection until any activity occurs in already"
3625 " added sockets.\n"));
3630 if (AF_INET == addr->sa_family)
3632 if (
sizeof(
struct sockaddr_in) > (
size_t) addrlen)
3636 _ (
"MHD_add_connection() has been called with "
3637 "incorrect 'addrlen' value.\n"));
3641#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
3642 if ((0 != addr->sa_len) &&
3643 (
sizeof(
struct sockaddr_in) > (
size_t) addr->sa_len) )
3647 _ (
"MHD_add_connection() has been called with " \
3648 "non-zero value of 'sa_len' member of " \
3649 "'struct sockaddr' which does not match 'sa_family'.\n"));
3656 if (AF_INET6 == addr->sa_family)
3658 if (
sizeof(
struct sockaddr_in6) > (
size_t) addrlen)
3662 _ (
"MHD_add_connection() has been called with "
3663 "incorrect 'addrlen' value.\n"));
3667#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
3668 if ((0 != addr->sa_len) &&
3669 (
sizeof(
struct sockaddr_in6) > (
size_t) addr->sa_len) )
3673 _ (
"MHD_add_connection() has been called with " \
3674 "non-zero value of 'sa_len' member of " \
3675 "'struct sockaddr' which does not match 'sa_family'.\n"));
3681#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
3682 if ((0 != addr->sa_len) &&
3683 (addrlen > addr->sa_len))
3684 addrlen = (socklen_t) addr->sa_len;
3693 _ (
"Failed to set nonblocking mode on new client socket: %s\n"),
3701#ifndef MHD_WINSOCK_SOCKETS
3702 sk_spipe_supprs =
false;
3704 sk_spipe_supprs =
true;
3706#if defined(MHD_socket_nosignal_)
3707 if (! sk_spipe_supprs)
3708 sk_spipe_supprs = MHD_socket_nosignal_ (client_socket);
3709 if (! sk_spipe_supprs)
3713 _ (
"Failed to suppress SIGPIPE on new client socket: %s\n"),
3737 _ (
"Failed to set noninheritable mode on new client socket.\n"));
3743 memcpy (&addrstorage, addr, (
size_t) addrlen);
3744#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
3745 addrstorage.ss_len = addrlen;
3748#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3758 &daemon->
worker_pool[(i + (
unsigned int) client_socket)
3772#if defined(ENFILE) && (ENFILE + 0 != 0)
3807 struct sockaddr_storage addrstorage;
3812 bool sk_spipe_supprs;
3815#if defined(_DEBUG) && defined (USE_ACCEPT4)
3816 const bool use_accept4 = ! daemon->avoid_accept4;
3817#elif defined (USE_ACCEPT4)
3818 static const bool use_accept4 =
true;
3820 static const bool use_accept4 =
false;
3823#ifdef MHD_USE_THREADS
3833 addrlen = (socklen_t)
sizeof (addrstorage);
3834 memset (&addrstorage,
3837#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
3838 addrstorage.ss_len = addrlen;
3843 sk_spipe_supprs =
false;
3851 (
struct sockaddr *) &addrstorage,
3857#ifndef MHD_WINSOCK_SOCKETS
3860 sk_spipe_supprs =
true;
3865#if defined(_DEBUG) || ! defined(USE_ACCEPT4)
3866 if (! use_accept4 &&
3869 (
struct sockaddr *) &addrstorage,
3872#ifdef MHD_ACCEPT_INHERIT_NONBLOCK
3877#ifndef MHD_WINSOCK_SOCKETS
3878 sk_spipe_supprs =
false;
3880 sk_spipe_supprs =
true;
3899 _ (
"Error accepting connection: %s\n"),
3912 _ (
"Hit process or system resource limit at FIRST " \
3913 "connection. This is really bad as there is no sane " \
3914 "way to proceed. Will try busy waiting for system " \
3915 "resources to become magically available.\n"));
3920#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3924#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3929 _ (
"Hit process or system resource limit at %u " \
3930 "connections, temporarily suspending accept(). " \
3931 "Consider setting a lower MHD_OPTION_CONNECTION_LIMIT.\n"),
3945 _ (
"Accepted socket has zero-length address. "
3946 "Processing the new socket as a socket with " \
3947 "unknown type.\n"));
3952 if (((socklen_t)
sizeof (addrstorage)) < addrlen)
3958 _ (
"Accepted socket address is larger than expected by " \
3959 "system headers. Processing the new socket as a socket with " \
3960 "unknown type.\n"));
3970 _ (
"Failed to set nonblocking mode on incoming connection " \
3984 _ (
"Failed to set noninheritable mode on incoming connection " \
3991#if defined(MHD_socket_nosignal_)
3992 if (! sk_spipe_supprs && ! MHD_socket_nosignal_ (s))
3996 _ (
"Failed to suppress SIGPIPE on incoming connection " \
4013 sk_spipe_supprs =
true;
4016#if _MHD_DEBUG_CONNECT
4018 _ (
"Accepted connection on socket %d\n"),
4047#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
4059#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
4064 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
4066#ifdef UPGRADE_SUPPORT
4067 cleanup_upgraded_connection (pos);
4071 if (
NULL != pos->tls_session)
4072 gnutls_deinit (pos->tls_session);
4095 if ( (-1 !=
daemon->epoll_fd) &&
4104 if (0 != epoll_ctl (
daemon->epoll_fd,
4108 MHD_PANIC (
_ (
"Failed to remove FD from epoll set.\n"));
4126#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
4132#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
4180#if SIZEOF_UINT64_T > SIZEOF_UNSIGNED_LONG_LONG
4228 uint64_t *timeout64)
4230 uint64_t earliest_deadline;
4234#ifdef MHD_USE_THREADS
4243 _ (
"Illegal call to MHD_get_timeout.\n"));
4260#
if defined(UPGRADE_SUPPORT) && defined(HTTPS_SUPPORT)
4271 earliest_tmot_conn =
NULL;
4272 earliest_deadline = 0;
4275 if ( (
NULL != pos) &&
4278 earliest_tmot_conn = pos;
4286 if ( (
NULL == earliest_tmot_conn) ||
4290 earliest_tmot_conn = pos;
4296 if (
NULL != earliest_tmot_conn)
4298 *timeout64 = connection_get_wait (earliest_tmot_conn);
4305#if defined(HAVE_POLL) || defined(EPOLL_SUPPORT)
4353 return (int64_t) utimeout;
4399#if SIZEOF_INT >= SIZEOF_INT64_T
4422 int32_t max_timeout)
4425 mhd_assert (0 <= max_timeout || -1 == max_timeout);
4426 if (0 == max_timeout)
4432 if ((0 < max_timeout) && ((uint64_t) max_timeout < d_timeout))
4438 return (int64_t) d_timeout;
4455 int32_t max_timeout)
4459 res = get_timeout_millisec_ (
daemon, max_timeout);
4460#if SIZEOF_INT < SIZEOF_INT64_T
4483 const fd_set *read_fd_set,
4484 const fd_set *write_fd_set,
4485 const fd_set *except_fd_set,
4489#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4490 struct MHD_UpgradeResponseHandle *urh;
4491 struct MHD_UpgradeResponseHandle *urhn;
4503#ifndef HAS_FD_SETSIZE_OVERRIDABLE
4505 mhd_assert (((
int) FD_SETSIZE) <= fd_setsize);
4506 fd_setsize = FD_SETSIZE;
4512 if (MHD_ITC_IS_VALID_ (daemon->
itc))
4514 bool need_to_clear_itc =
true;
4517 need_to_clear_itc = FD_ISSET (MHD_itc_r_fd_ (daemon->
itc), \
4519 if (need_to_clear_itc)
4520 MHD_itc_clear_ (daemon->
itc);
4536 bool need_to_accept;
4538 need_to_accept = FD_ISSET (ds,
4564 r_ready = FD_ISSET (cs,
4566 w_ready = FD_ISSET (cs,
4568 has_err = (
NULL != except_fd_set) &&
4585#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4587 for (urh =
daemon->urh_tail;
NULL != urh; urh = urhn)
4591 urh_from_fdset (urh,
4599 if ( (0 == urh->in_buffer_size) &&
4600 (0 == urh->out_buffer_size) &&
4601 (0 == urh->in_buffer_used) &&
4602 (0 == urh->out_buffer_used) )
4605 urh->clean_ready =
true;
4616#undef MHD_run_from_select
4651 const fd_set *read_fd_set,
4652 const fd_set *write_fd_set,
4653 const fd_set *except_fd_set,
4654 unsigned int fd_setsize)
4659 if ((
NULL == read_fd_set) || (
NULL == write_fd_set))
4662 if (
NULL == except_fd_set)
4665 _ (
"MHD_run_from_select() called with except_fd_set "
4666 "set to NULL. Such behavior is deprecated.\n"));
4670#ifdef HAS_FD_SETSIZE_OVERRIDABLE
4671 if (0 == fd_setsize)
4673 else if (((
unsigned int)
INT_MAX) < fd_setsize)
4674 fd_setsize = (
unsigned int)
INT_MAX;
4676 else if (
daemon->fdset_size > ((
int) fd_setsize))
4678 if (
daemon->fdset_size_set_by_app)
4681 _ (
"%s() called with fd_setsize (%u) " \
4682 "less than value set by MHD_OPTION_APP_FD_SETSIZE (%d). " \
4683 "Some socket FDs may be not processed. " \
4684 "Use MHD_OPTION_APP_FD_SETSIZE with the correct value.\n"),
4685 "MHD_run_from_select2", fd_setsize,
daemon->fdset_size);
4690 _ (
"%s() called with fd_setsize (%u) " \
4691 "less than FD_SETSIZE used by MHD (%d). " \
4692 "Some socket FDs may be not processed. " \
4693 "Consider using MHD_OPTION_APP_FD_SETSIZE option.\n"),
4694 "MHD_run_from_select2", fd_setsize,
daemon->fdset_size);
4699 if (((
unsigned int) FD_SETSIZE) > fd_setsize)
4703 _ (
"%s() called with fd_setsize (%u) " \
4704 "less than fixed FD_SETSIZE value (%d) used on the " \
4706 "MHD_run_from_select2", fd_setsize, (
int) FD_SETSIZE);
4765 const fd_set *read_fd_set,
4766 const fd_set *write_fd_set,
4767 const fd_set *except_fd_set)
4773#ifdef HAS_FD_SETSIZE_OVERRIDABLE
4774 daemon->fdset_size_set_by_app ?
4775 ((
unsigned int)
daemon->fdset_size) :
4803 struct timeval timeout;
4809 timeout.tv_usec = 0;
4835 _ (
"Could not obtain daemon fdsets.\n"));
4845 if (MHD_ITC_IS_VALID_ (daemon->
itc))
4854 MHD_DLOG (daemon,
_ (
"Could not add control inter-thread " \
4855 "communication channel FD to fdset.\n"));
4880 _ (
"Could not add listen socket to fdset.\n"));
4892 timeout.tv_usec = 0;
4899 uint64_t select_tmo;
4904 if ( (0 < millisec) &&
4905 (mhd_tmo > (uint64_t) millisec) )
4906 select_tmo = (uint64_t) millisec;
4908 select_tmo = mhd_tmo;
4911 else if (0 < millisec)
4913 select_tmo = (uint64_t) millisec;
4924#if (SIZEOF_UINT64_T - 2) >= SIZEOF_STRUCT_TIMEVAL_TV_SEC
4931 timeout.tv_usec = ((uint16_t) (select_tmo % 1000)) * ((int32_t) 1000);
4948 _ (
"select failed: %s\n"),
4978 unsigned int num_connections;
4981#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4982 struct MHD_UpgradeResponseHandle *urh;
4983 struct MHD_UpgradeResponseHandle *urhn;
4998 num_connections = 0;
5001#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5002 for (urh = daemon->urh_head;
NULL != urh; urh = urh->next)
5003 num_connections += 2;
5008 unsigned int poll_server;
5015 sizeof (
struct pollfd));
5020 _ (
"Error allocating memory: %s\n"),
5033 p[poll_server].fd = ls;
5034 p[poll_server].events = POLLIN;
5035 p[poll_server].revents = 0;
5036 poll_listen = (int) poll_server;
5040 if (MHD_ITC_IS_VALID_ (daemon->
itc))
5042 p[poll_server].fd = MHD_itc_r_fd_ (daemon->
itc);
5043 p[poll_server].events = POLLIN;
5044 p[poll_server].revents = 0;
5045 poll_itc_idx = (int) poll_server;
5049 timeout = get_timeout_millisec_int (daemon, millisec);
5059 p[poll_server + i].events |= POLLIN | MHD_POLL_EVENTS_ERR_DISC;
5062 p[poll_server + i].events |= POLLOUT | MHD_POLL_EVENTS_ERR_DISC;
5065 p[poll_server + i].events |= MHD_POLL_EVENTS_ERR_DISC;
5073#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5074 for (urh = daemon->urh_tail;
NULL != urh; urh = urh->prev)
5076 urh_to_pollfd (urh, &(p[poll_server + i]));
5080 if (0 == poll_server + num_connections)
5085 if (MHD_sys_poll_ (p,
5086 poll_server + num_connections,
5097 _ (
"poll failed: %s\n"),
5107 if ( (-1 != poll_itc_idx) &&
5108 (0 != (p[poll_itc_idx].revents & POLLIN)) )
5109 MHD_itc_clear_ (daemon->
itc);
5123 if ( (-1 != poll_listen) &&
5124 (0 != (p[poll_listen].revents & POLLIN)) )
5132 while (
NULL != (pos = prev))
5136 if (i >= num_connections)
5141 0 != (p[poll_server + i].revents & POLLIN),
5142 0 != (p[poll_server + i].revents & POLLOUT),
5143 0 != (p[poll_server + i].revents
5144 & MHD_POLL_REVENTS_ERR_DISC));
5147#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5148 for (urh = daemon->urh_tail;
NULL != urh; urh = urhn)
5150 if (i >= num_connections)
5157 if ((p[poll_server + i].
fd != urh->connection->socket_fd) ||
5158 (p[poll_server + i + 1].fd != urh->mhd.socket))
5160 urh_from_pollfd (urh,
5161 &p[poll_server + i]);
5165 if ( (0 == urh->in_buffer_size) &&
5166 (0 == urh->out_buffer_size) &&
5167 (0 == urh->in_buffer_used) &&
5168 (0 == urh->out_buffer_used) )
5173 urh->clean_ready =
true;
5197MHD_poll_listen_socket (
struct MHD_Daemon *daemon,
5202 unsigned int poll_count;
5220 p[poll_count].fd = ls;
5221 p[poll_count].events = POLLIN;
5222 p[poll_count].revents = 0;
5223 poll_listen = (int) poll_count;
5226 if (MHD_ITC_IS_VALID_ (daemon->
itc))
5228 p[poll_count].fd = MHD_itc_r_fd_ (daemon->
itc);
5229 p[poll_count].events = POLLIN;
5230 p[poll_count].revents = 0;
5231 poll_itc_idx = (int) poll_count;
5242 if (0 == poll_count)
5244 if (MHD_sys_poll_ (p,
5254 _ (
"poll failed: %s\n"),
5259 if ( (0 <= poll_itc_idx) &&
5260 (0 != (p[poll_itc_idx].revents & POLLIN)) )
5261 MHD_itc_clear_ (daemon->
itc);
5271 if ( (0 <= poll_listen) &&
5272 (0 != (p[poll_listen].revents & POLLIN)) )
5294 return MHD_poll_all (daemon,
5295 may_block ? -1 : 0);
5296 return MHD_poll_listen_socket (daemon,
5314#define MAX_EVENTS 128
5317#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5327is_urh_ready (
struct MHD_UpgradeResponseHandle *
const urh)
5331 if ( (0 == urh->in_buffer_size) &&
5332 (0 == urh->out_buffer_size) &&
5333 (0 == urh->in_buffer_used) &&
5334 (0 == urh->out_buffer_used) )
5339 & urh->app.celi)) ||
5341 (urh->in_buffer_used < urh->in_buffer_size) )
5344 & urh->mhd.celi)) ||
5346 (urh->out_buffer_used < urh->out_buffer_size) )
5349 (urh->out_buffer_used > 0) )
5352 (urh->in_buffer_used > 0) )
5369 struct epoll_event events[MAX_EVENTS];
5371 struct MHD_UpgradeResponseHandle *pos;
5372 struct MHD_UpgradeResponseHandle *prev;
5374#ifdef MHD_USE_THREADS
5379 num_events = MAX_EVENTS;
5380 while (0 != num_events)
5384 num_events = epoll_wait (daemon->epoll_upgrade_fd,
5388 if (-1 == num_events)
5396 _ (
"Call to epoll_wait failed: %s\n"),
5401 for (i = 0; i < (
unsigned int) num_events; i++)
5403 struct UpgradeEpollHandle *
const ueh = events[i].data.ptr;
5404 struct MHD_UpgradeResponseHandle *
const urh = ueh->urh;
5405 bool new_err_state =
false;
5407 if (urh->clean_ready)
5411 if (0 != (events[i].events & EPOLLIN))
5415 if (0 != (events[i].events & EPOLLOUT))
5419 if (0 != (events[i].events & EPOLLHUP))
5425 (0 != (events[i].events & (EPOLLERR | EPOLLPRI))) )
5430 new_err_state =
true;
5432 if (! urh->in_eready_list)
5434 if (new_err_state ||
5438 daemon->eready_urh_tail,
5440 urh->in_eready_list =
true;
5445 prev = daemon->eready_urh_tail;
5446 while (
NULL != (pos = prev))
5450 if (! is_urh_ready (pos))
5453 daemon->eready_urh_tail,
5455 pos->in_eready_list =
false;
5458 if ( (0 == pos->in_buffer_size) &&
5459 (0 == pos->out_buffer_size) &&
5460 (0 == pos->in_buffer_used) &&
5461 (0 == pos->out_buffer_used) )
5464 pos->clean_ready =
true;
5483static const char *
const epoll_itc_marker =
"itc_marker";
5499#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5500 static const char *
const upgrade_marker =
"upgrade_ptr";
5504 struct epoll_event events[MAX_EVENTS];
5505 struct epoll_event event;
5510#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5511 bool run_upgraded =
false;
5513 bool need_to_accept;
5522 if (-1 == daemon->epoll_fd)
5529 (! daemon->listen_socket_in_epoll) &&
5532 event.events = EPOLLIN | EPOLLRDHUP;
5533 event.data.ptr = daemon;
5534 if (0 != epoll_ctl (daemon->epoll_fd,
5541 _ (
"Call to epoll_ctl failed: %s\n"),
5546 daemon->listen_socket_in_epoll =
true;
5549 (daemon->listen_socket_in_epoll) )
5551 if ( (0 != epoll_ctl (daemon->epoll_fd,
5557 MHD_PANIC (
"Failed to remove listen FD from epoll set.\n");
5558 daemon->listen_socket_in_epoll =
false;
5561#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5562 if ( ( (! daemon->upgrade_fd_in_epoll) &&
5563 (-1 != daemon->epoll_upgrade_fd) ) )
5565 event.events = EPOLLIN | EPOLLOUT | EPOLLRDHUP;
5567 if (0 != epoll_ctl (daemon->epoll_fd,
5569 daemon->epoll_upgrade_fd,
5574 _ (
"Call to epoll_ctl failed: %s\n"),
5579 daemon->upgrade_fd_in_epoll =
true;
5582 if ( (daemon->listen_socket_in_epoll) &&
5589 if (0 != epoll_ctl (daemon->epoll_fd,
5593 MHD_PANIC (
_ (
"Failed to remove listen FD from epoll set.\n"));
5594 daemon->listen_socket_in_epoll =
false;
5601 timeout_ms = get_timeout_millisec_int (daemon, millisec);
5608 need_to_accept =
false;
5613 num_events = MAX_EVENTS;
5614 while (MAX_EVENTS == num_events)
5617 num_events = epoll_wait (daemon->epoll_fd,
5621 if (-1 == num_events)
5628 _ (
"Call to epoll_wait failed: %s\n"),
5633 for (i = 0; i < (
unsigned int) num_events; i++)
5639#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5640 if (upgrade_marker == events[i].
data.ptr)
5644 run_upgraded =
true;
5648 if (epoll_itc_marker == events[i].
data.ptr)
5652 MHD_itc_clear_ (daemon->
itc);
5655 if (daemon == events[i].
data.ptr)
5659 if (0 == (events[i].events & (EPOLLERR | EPOLLHUP)))
5660 need_to_accept =
true;
5666 pos = events[i].data.ptr;
5668 if (0 != (events[i].events & (EPOLLPRI | EPOLLERR | EPOLLHUP)))
5674 daemon->eready_tail,
5681 if (0 != (events[i].events & EPOLLIN))
5689 daemon->eready_tail,
5694 if (0 != (events[i].events & EPOLLOUT))
5701 daemon->eready_tail,
5716 unsigned int series_length = 0;
5723 (series_length < 10) &&
5738 while (
NULL != (pos = prev))
5748 while (
NULL != (pos = prev))
5756#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5757 if (run_upgraded || (
NULL != daemon->eready_urh_head))
5758 run_epoll_for_upgrade (daemon);
5762 prev = daemon->eready_tail;
5763 while (
NULL != (pos = prev))
5781 daemon->eready_tail,
5889 res = MHD_poll_all (daemon, millisec);
5897 res = MHD_epoll (daemon, millisec);
5905#ifdef HAS_FD_SETSIZE_OVERRIDABLE
5907 if (daemon->fdset_size_set_by_app
5908 && (((
int) FD_SETSIZE) < daemon->fdset_size))
5911 _ (
"MHD_run()/MHD_run_wait() called for daemon started with " \
5912 "MHD_OPTION_APP_FD_SETSIZE option (%d). " \
5913 "The library was compiled with smaller FD_SETSIZE (%d). " \
5914 "Some socket FDs may be not processed. " \
5915 "Use MHD_run_from_select2() instead of MHD_run() or " \
5916 "do not use MHD_OPTION_APP_FD_SETSIZE option.\n"),
5917 daemon->fdset_size, (
int) FD_SETSIZE);
5942#ifdef MHD_USE_THREADS
5955#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5975#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5981#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5989static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_
5993#ifdef HAVE_PTHREAD_SIGMASK
5999#ifdef HAVE_PTHREAD_SIGMASK
6000 if ((0 == sigemptyset (&s_mask)) &&
6001 (0 == sigaddset (&s_mask, SIGPIPE)))
6003 err = pthread_sigmask (SIG_BLOCK, &s_mask,
NULL);
6012 _ (
"Failed to block SIGPIPE on daemon thread: %s\n"),
6025 MHD_epoll (daemon, -1);
6039 return (MHD_THRD_RTRN_TYPE_) 0;
6074 MHD_DLOG (connection->
daemon,
6075 _ (
"The URL encoding is broken.\n"));
6150#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6164 _ (
"Using MHD_quiesce_daemon in this mode " \
6165 "requires MHD_USE_ITC.\n"));
6170#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6180 if (0 != epoll_ctl (daemon->
worker_pool[i].epoll_fd,
6184 MHD_PANIC (
_ (
"Failed to remove listen FD from epoll set.\n"));
6185 daemon->
worker_pool[i].listen_socket_in_epoll =
false;
6192 MHD_PANIC (
_ (
"Failed to signal quiesce via inter-thread " \
6193 "communication channel.\n"));
6200 (-1 != daemon->epoll_fd) &&
6201 (daemon->listen_socket_in_epoll) )
6203 if ( (0 != epoll_ctl (daemon->epoll_fd,
6209 MHD_PANIC (
"Failed to remove listen FD from epoll set.\n");
6210 daemon->listen_socket_in_epoll =
false;
6213 if ( (MHD_ITC_IS_VALID_ (daemon->
itc)) &&
6214 (! MHD_itc_activate_ (daemon->
itc,
"q")) )
6215 MHD_PANIC (
_ (
"failed to signal quiesce via inter-thread " \
6216 "communication channel.\n"));
6226struct MHD_InterimParams_
6239 bool fdset_size_set;
6255 bool pserver_addr_set;
6259 const struct sockaddr *pserver_addr;
6263 bool server_addr_len_set;
6267 socklen_t server_addr_len;
6294 struct MHD_InterimParams_ *params,
6309 struct MHD_InterimParams_ *params,
6315 va_start (ap, params);
6328enum MHD_TlsPrioritiesBaseType
6330 MHD_TLS_PRIO_BASE_LIBMHD = 0,
6331 MHD_TLS_PRIO_BASE_SYSTEM = 1,
6332#if GNUTLS_VERSION_NUMBER >= 0x030300
6333 MHD_TLS_PRIO_BASE_DEFAULT,
6335 MHD_TLS_PRIO_BASE_NORMAL
6341#if GNUTLS_VERSION_NUMBER >= 0x030300
6353daemon_tls_priorities_init_default (
struct MHD_Daemon *daemon)
6360 mhd_assert (MHD_TLS_PRIO_BASE_NORMAL + 1 == \
6361 sizeof(MHD_TlsBasePriotities) /
sizeof(MHD_TlsBasePriotities[0]));
6363 res = GNUTLS_E_SUCCESS;
6366 p <
sizeof(MHD_TlsBasePriotities) /
sizeof(MHD_TlsBasePriotities[0]);
6369 res = gnutls_priority_init (&daemon->priority_cache,
6370 MHD_TlsBasePriotities[p].str,
NULL);
6371 if (GNUTLS_E_SUCCESS == res)
6375 switch ((
enum MHD_TlsPrioritiesBaseType) p)
6377 case MHD_TLS_PRIO_BASE_LIBMHD:
6379 _ (
"GnuTLS priorities have been initialised with " \
6380 "@LIBMICROHTTPD application-specific system-wide " \
6381 "configuration.\n") );
6383 case MHD_TLS_PRIO_BASE_SYSTEM:
6385 _ (
"GnuTLS priorities have been initialised with " \
6386 "@SYSTEM system-wide configuration.\n") );
6388#if GNUTLS_VERSION_NUMBER >= 0x030300
6389 case MHD_TLS_PRIO_BASE_DEFAULT:
6391 _ (
"GnuTLS priorities have been initialised with " \
6392 "GnuTLS default configuration.\n") );
6395 case MHD_TLS_PRIO_BASE_NORMAL:
6397 _ (
"GnuTLS priorities have been initialised with " \
6398 "NORMAL configuration.\n") );
6410 _ (
"Failed to set GnuTLS priorities. Last error: %s\n"),
6411 gnutls_strerror (res));
6427daemon_tls_priorities_init_append_inner_ (
struct MHD_Daemon *daemon,
6431 const size_t buf_size)
6435 const char *err_pos;
6440 mhd_assert (MHD_TLS_PRIO_BASE_NORMAL + 1 == \
6441 sizeof(MHD_TlsBasePriotities) /
sizeof(MHD_TlsBasePriotities[0]));
6443 res = GNUTLS_E_SUCCESS;
6446 p <
sizeof(MHD_TlsBasePriotities) /
sizeof(MHD_TlsBasePriotities[0]);
6450#if GNUTLS_VERSION_NUMBER >= 0x030300
6451#if GNUTLS_VERSION_NUMBER >= 0x030603
6452 if (
NULL == MHD_TlsBasePriotities[p].
str)
6453 res = gnutls_priority_init2 (&daemon->priority_cache, prio, &err_pos,
6454 GNUTLS_PRIORITY_INIT_DEF_APPEND);
6458 if (
NULL == MHD_TlsBasePriotities[p].
str)
6469 memcpy (buf + buf_pos, MHD_TlsBasePriotities[p].
str,
6470 MHD_TlsBasePriotities[p].
len);
6471 buf_pos += MHD_TlsBasePriotities[p].
len;
6472 buf[buf_pos++] =
':';
6473 memcpy (buf + buf_pos, prio, prio_len + 1);
6475 buf_pos += prio_len + 1;
6478 res = gnutls_priority_init (&daemon->priority_cache, buf, &err_pos);
6480 if (GNUTLS_E_SUCCESS == res)
6484 switch ((
enum MHD_TlsPrioritiesBaseType) p)
6486 case MHD_TLS_PRIO_BASE_LIBMHD:
6488 _ (
"GnuTLS priorities have been initialised with " \
6489 "priorities specified by application appended to " \
6490 "@LIBMICROHTTPD application-specific system-wide " \
6491 "configuration.\n") );
6493 case MHD_TLS_PRIO_BASE_SYSTEM:
6495 _ (
"GnuTLS priorities have been initialised with " \
6496 "priorities specified by application appended to " \
6497 "@SYSTEM system-wide configuration.\n") );
6499#if GNUTLS_VERSION_NUMBER >= 0x030300
6500 case MHD_TLS_PRIO_BASE_DEFAULT:
6502 _ (
"GnuTLS priorities have been initialised with " \
6503 "priorities specified by application appended to " \
6504 "GnuTLS default configuration.\n") );
6507 case MHD_TLS_PRIO_BASE_NORMAL:
6509 _ (
"GnuTLS priorities have been initialised with " \
6510 "priorities specified by application appended to " \
6511 "NORMAL configuration.\n") );
6523 _ (
"Failed to set GnuTLS priorities. Last error: %s. " \
6524 "The problematic part starts at: %s\n"),
6525 gnutls_strerror (res), err_pos);
6531#define LOCAL_BUFF_SIZE 128
6542daemon_tls_priorities_init_append (
struct MHD_Daemon *daemon,
const char *prio)
6547 size_t buf_size_needed;
6550 return daemon_tls_priorities_init_default (daemon);
6555 prio_len = strlen (prio);
6557 buf_size_needed = longest_base_prio + 1 + prio_len + 1;
6559 if (LOCAL_BUFF_SIZE >= buf_size_needed)
6561 char local_buffer[LOCAL_BUFF_SIZE];
6562 ret = daemon_tls_priorities_init_append_inner_ (daemon, prio, prio_len,
6568 char *allocated_buffer;
6569 allocated_buffer = (
char *) malloc (buf_size_needed);
6570 if (
NULL == allocated_buffer)
6574 _ (
"Error allocating memory: %s\n"),
6579 ret = daemon_tls_priorities_init_append_inner_ (daemon, prio, prio_len,
6582 free (allocated_buffer);
6601 struct MHD_InterimParams_ *params,
6610#if GNUTLS_VERSION_MAJOR >= 3
6611 gnutls_certificate_retrieve_function2 * pgcrf;
6613#if GNUTLS_VERSION_NUMBER >= 0x030603
6614 gnutls_certificate_retrieve_function3 * pgcrf2;
6639 _ (
"Warning: specified " \
6640 "MHD_OPTION_CONNECTION_MEMORY_LIMIT " \
6641 "value is too small and rounded up to 64.\n"));
6665 _ (
"Warning: specified " \
6666 "MHD_OPTION_CONNECTION_MEMORY_INCREMENT value is " \
6667 "too large and rounded down to 1/4 of " \
6668 "MHD_OPTION_CONNECTION_MEMORY_LIMIT.\n"));
6682#if (SIZEOF_UINT64_T - 2) <= SIZEOF_UNSIGNED_INT
6687 _ (
"The specified connection timeout (%u) is too large. " \
6688 "Maximum allowed value (%" PRIu64 ") will be used " \
6715 params->server_addr_len = va_arg (ap,
6717 params->server_addr_len_set =
true;
6718 params->pserver_addr = va_arg (ap,
6719 const struct sockaddr *);
6720 params->pserver_addr_set =
true;
6723 params->server_addr_len_set =
false;
6724 params->pserver_addr = va_arg (ap,
6725 const struct sockaddr *);
6726 params->pserver_addr_set =
true;
6739#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6751 _ (
"Warning: value \"1\", specified as the thread pool " \
6752 "size, is ignored. Thread pool is not used.\n"));
6756#if SIZEOF_UNSIGNED_INT >= (SIZEOF_SIZE_T - 2)
6765 _ (
"Specified thread pool size (%u) too big.\n"),
6777 _ (
"MHD_OPTION_THREAD_POOL_SIZE option is specified but "
6778 "MHD_USE_INTERNAL_POLLING_THREAD flag is not specified.\n"));
6786 _ (
"Both MHD_OPTION_THREAD_POOL_SIZE option and "
6787 "MHD_USE_THREAD_PER_CONNECTION flag are specified.\n"));
6799 daemon->https_mem_key = pstr;
6803 _ (
"MHD HTTPS option %d passed to MHD but " \
6804 "MHD_USE_TLS not set.\n"),
6812 daemon->https_key_password = pstr;
6816 _ (
"MHD HTTPS option %d passed to MHD but " \
6817 "MHD_USE_TLS not set.\n"),
6825 daemon->https_mem_cert = pstr;
6829 _ (
"MHD HTTPS option %d passed to MHD but " \
6830 "MHD_USE_TLS not set.\n"),
6838 daemon->https_mem_trust = pstr;
6842 _ (
"MHD HTTPS option %d passed to MHD but " \
6843 "MHD_USE_TLS not set.\n"),
6848 daemon->cred_type = (gnutls_credentials_type_t) va_arg (ap,
6856 gnutls_datum_t dhpar;
6859 if (gnutls_dh_params_init (&daemon->https_mem_dhparams) < 0)
6863 _ (
"Error initializing DH parameters.\n"));
6868 pstr_len = strlen (pstr);
6873 _ (
"Diffie-Hellman parameters string too long.\n"));
6877 dhpar.size = (
unsigned int) pstr_len;
6878 if (gnutls_dh_params_import_pkcs3 (daemon->https_mem_dhparams,
6880 GNUTLS_X509_FMT_PEM) < 0)
6884 _ (
"Bad Diffie-Hellman parameters format.\n"));
6886 gnutls_dh_params_deinit (daemon->https_mem_dhparams);
6889 daemon->have_dhparams =
true;
6894 _ (
"MHD HTTPS option %d passed to MHD but " \
6895 "MHD_USE_TLS not set.\n"),
6905 if (
NULL != daemon->priority_cache)
6906 gnutls_priority_deinit (daemon->priority_cache);
6911 const char *err_pos;
6912 init_res = gnutls_priority_init (&daemon->priority_cache,
6915 if (GNUTLS_E_SUCCESS != init_res)
6919 _ (
"Setting priorities to '%s' failed: %s " \
6920 "The problematic part starts at: %s\n"),
6922 gnutls_strerror (init_res),
6925 daemon->priority_cache =
NULL;
6932 daemon->priority_cache =
NULL;
6933 if (! daemon_tls_priorities_init_append (daemon, pstr))
6940 _ (
"MHD HTTPS option %d passed to MHD but " \
6941 "MHD_USE_TLS not set.\n"),
6946#if GNUTLS_VERSION_MAJOR < 3
6949 _ (
"MHD_OPTION_HTTPS_CERT_CALLBACK requires building " \
6950 "MHD with GnuTLS >= 3.0.\n"));
6955 gnutls_certificate_retrieve_function2 *);
6957 daemon->cert_callback = pgcrf;
6961 _ (
"MHD HTTPS option %d passed to MHD but " \
6962 "MHD_USE_TLS not set.\n"),
6968#if GNUTLS_VERSION_NUMBER < 0x030603
6971 _ (
"MHD_OPTION_HTTPS_CERT_CALLBACK2 requires building " \
6972 "MHD with GnuTLS >= 3.6.3.\n"));
6976 pgcrf2 = va_arg (ap,
6977 gnutls_certificate_retrieve_function3 *);
6979 daemon->cert_callback2 = pgcrf2;
6983 _ (
"MHD HTTPS option %d passed to MHD but " \
6984 "MHD_USE_TLS not set.\n"),
6993 daemon->digest_auth_rand_size = va_arg (ap,
6995 daemon->digest_auth_random = va_arg (ap,
6999 daemon->digest_auth_random_copy = daemon;
7001 daemon->digest_auth_random_copy =
NULL;
7004 daemon->nonce_nc_size = va_arg (ap,
7008 daemon->dauth_bind_type = va_arg (ap,
7020 daemon->dauth_def_nonce_timeout = val;
7030 daemon->dauth_def_max_nc = val;
7035 params->listen_fd = va_arg (ap,
7037 params->listen_fd_set =
true;
7041 daemon->custom_error_log = va_arg (ap,
7043 daemon->custom_error_log_cls = va_arg (ap,
7045 if (1 != params->num_opts)
7047 _ (
"MHD_OPTION_EXTERNAL_LOGGER is not the first option "
7048 "specified for the daemon. Some messages may be "
7049 "printed by the standard MHD logger.\n"));
7058#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7060 daemon->thread_stack_size = va_arg (ap,
7066 daemon->fastopen_queue_size = va_arg (ap,
7072 _ (
"TCP fastopen is not supported on this platform.\n"));
7078 unsigned int) ? 1 : -1;
7096 _ (
"Flag MHD_USE_PEDANTIC_CHECKS is ignored because "
7097 "another behaviour is specified by "
7098 "MHD_OPTION_STRICT_CLIENT.\n"));
7109 _ (
"Flag MHD_USE_PEDANTIC_CHECKS is ignored because "
7110 "another behaviour is specified by "
7111 "MHD_OPTION_CLIENT_DISCIPLINE_LVL.\n"));
7130 (
size_t) oa[i].
value,
7149 (
unsigned int) oa[i].
value,
7159 (gnutls_credentials_type_t) oa[i].
value,
7191 (uint32_t) oa[i].
value,
7224 (
void *) oa[i].
value,
7235 (
size_t) oa[i].
value,
7245 (socklen_t) oa[i].
value,
7265#if GNUTLS_VERSION_MAJOR >= 3
7266 daemon->cred_callback = va_arg (ap,
7268 daemon->cred_callback_cls = va_arg (ap,
7273 _ (
"MHD HTTPS option %d passed to MHD compiled " \
7274 "without GNUtls >= 3.\n"),
7291 daemon->disable_alpn = (va_arg (ap,
7294 (void) va_arg (ap,
int);
7299 _ (
"MHD HTTPS option %d passed to MHD " \
7300 "but MHD_USE_TLS not set.\n"),
7305 params->fdset_size_set =
true;
7306 params->fdset_size = va_arg (ap,
7309#ifndef HTTPS_SUPPORT
7323 _ (
"MHD HTTPS option %d passed to MHD "
7324 "compiled without HTTPS support.\n"),
7333 _ (
"Invalid option %d! (Did you terminate "
7334 "the list with MHD_OPTION_END?).\n"),
7350#ifndef HAVE_MESSAGES
7354#ifdef USE_EPOLL_CREATE1
7355 fd = epoll_create1 (EPOLL_CLOEXEC);
7357 fd = epoll_create (MAX_EVENTS);
7363 _ (
"Call to epoll_create1 failed: %s\n"),
7368#if ! defined(USE_EPOLL_CREATE1)
7373 _ (
"Failed to set noninheritable mode on epoll FD.\n"));
7390setup_epoll_to_listen (
struct MHD_Daemon *daemon)
7392 struct epoll_event event;
7399 MHD_ITC_IS_VALID_ (daemon->
itc) );
7400 daemon->epoll_fd = setup_epoll_fd (daemon);
7415 _ (
"The epoll FD is too large to be used with fd_set.\n"));
7420 if (-1 == daemon->epoll_fd)
7422#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
7425 daemon->epoll_upgrade_fd = setup_epoll_fd (daemon);
7433 event.events = EPOLLIN | EPOLLRDHUP;
7434 event.data.ptr = daemon;
7435 if (0 != epoll_ctl (daemon->epoll_fd,
7442 _ (
"Call to epoll_ctl failed: %s\n"),
7447 daemon->listen_socket_in_epoll =
true;
7450 if (MHD_ITC_IS_VALID_ (daemon->
itc))
7452 event.events = EPOLLIN | EPOLLRDHUP;
7454 if (0 != epoll_ctl (daemon->epoll_fd,
7456 MHD_itc_r_fd_ (daemon->
itc),
7461 _ (
"Call to epoll_ctl failed: %s\n"),
7487 const struct sockaddr **ppsockaddr,
7488 socklen_t *psockaddr_len,
7489 struct MHD_InterimParams_ *params)
7491 if (params->fdset_size_set)
7493 if (0 >= params->fdset_size)
7497 _ (
"MHD_OPTION_APP_FD_SETSIZE value (%d) is not positive.\n"),
7498 params->fdset_size);
7506 _ (
"MHD_OPTION_APP_FD_SETSIZE is ignored for daemon started " \
7507 "with MHD_USE_INTERNAL_POLLING_THREAD.\n"));
7515 _ (
"MHD_OPTION_APP_FD_SETSIZE is ignored for daemon started " \
7516 "with MHD_USE_POLL.\n"));
7522#ifndef HAS_FD_SETSIZE_OVERRIDABLE
7523 if (((
int) FD_SETSIZE) != params->fdset_size)
7527 _ (
"MHD_OPTION_APP_FD_SETSIZE value (%d) does not match " \
7528 "the platform FD_SETSIZE value (%d) and this platform " \
7529 "does not support overriding of FD_SETSIZE.\n"),
7530 params->fdset_size, (
int) FD_SETSIZE);
7535 d->fdset_size = params->fdset_size;
7536 d->fdset_size_set_by_app =
true;
7541 if (params->listen_fd_set)
7547#ifdef HAS_SIGNED_SOCKET
7548 else if (0 > params->listen_fd)
7552 _ (
"The value provided for MHD_OPTION_LISTEN_SOCKET " \
7562 _ (
"MHD_OPTION_LISTEN_SOCKET specified for daemon "
7563 "with MHD_USE_NO_LISTEN_SOCKET flag set.\n"));
7572#ifdef MHD_USE_GETSOCKNAME
7578 mhd_assert (! params->server_addr_len_set || params->pserver_addr_set);
7579 if (params->pserver_addr_set)
7581 if (
NULL == params->pserver_addr)
7584 if (params->server_addr_len_set && (0 != params->server_addr_len))
7592 _ (
"MHD_OPTION_LISTEN_SOCKET cannot be used together with " \
7593 "MHD_OPTION_SOCK_ADDR_LEN or MHD_OPTION_SOCK_ADDR.\n"));
7601 _ (
"MHD_OPTION_SOCK_ADDR_LEN or MHD_OPTION_SOCK_ADDR " \
7602 "specified for daemon with MHD_USE_NO_LISTEN_SOCKET " \
7614 *ppsockaddr = params->pserver_addr;
7615 if (params->server_addr_len_set)
7618 if (0 == params->server_addr_len)
7620 *psockaddr_len = params->server_addr_len;
7663 const struct sockaddr *pservaddr =
NULL;
7665#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7670 struct MHD_InterimParams_ *interim_params;
7687#ifndef EPOLL_SUPPORT
7691#ifndef HTTPS_SUPPORT
7701#ifdef UPGRADE_SUPPORT
7707#ifdef MHD_USE_THREADS
7736#if defined(EPOLL_SUPPORT) && defined(HAVE_POLL)
7741#elif defined(HAVE_POLL)
7744#elif defined(EPOLL_SUPPORT)
7756#ifdef HAVE_LISTEN_SHUTDOWN
7764 interim_params = (
struct MHD_InterimParams_ *) \
7765 MHD_calloc_ (1,
sizeof (
struct MHD_InterimParams_));
7766 if (
NULL == interim_params)
7768 int err_num = errno;
7774 daemon->epoll_fd = -1;
7775#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
7776 daemon->epoll_upgrade_fd = -1;
7781 daemon->priority_cache =
NULL;
7790 daemon->
port = port;
7801 MHD_itc_set_invalid_ (daemon->
itc);
7802#ifdef MHD_USE_THREADS
7811 daemon->custom_error_log = &MHD_default_logger_;
7812 daemon->custom_error_log_cls = stderr;
7814#ifndef MHD_WINSOCK_SOCKETS
7820#if defined(_DEBUG) && defined(HAVE_ACCEPT4)
7821 daemon->avoid_accept4 =
false;
7823#ifdef HAS_FD_SETSIZE_OVERRIDABLE
7824 daemon->fdset_size = (int) FD_SETSIZE;
7825 daemon->fdset_size_set_by_app =
false;
7829 daemon->digest_auth_rand_size = 0;
7830 daemon->digest_auth_random =
NULL;
7831 daemon->nonce_nc_size = 4;
7838 daemon->cred_type = GNUTLS_CRD_CERTIFICATE;
7842 interim_params->num_opts = 0;
7843 interim_params->fdset_size_set =
false;
7844 interim_params->fdset_size = 0;
7845 interim_params->listen_fd_set =
false;
7847 interim_params->pserver_addr_set =
false;
7848 interim_params->pserver_addr =
NULL;
7849 interim_params->server_addr_len_set =
false;
7850 interim_params->server_addr_len = 0;
7858 (
NULL != daemon->priority_cache) )
7859 gnutls_priority_deinit (daemon->priority_cache);
7861 free (interim_params);
7870 free (interim_params);
7874 free (interim_params);
7875 interim_params =
NULL;
7878 && (
NULL == daemon->priority_cache)
7879 && ! daemon_tls_priorities_init_default (daemon))
7883 _ (
"Failed to initialise GnuTLS priorities.\n"));
7895 _ (
"Warning: MHD_USE_THREAD_PER_CONNECTION must be used " \
7896 "only with MHD_USE_INTERNAL_POLLING_THREAD. " \
7897 "Flag MHD_USE_INTERNAL_POLLING_THREAD was added. " \
7898 "Consider setting MHD_USE_INTERNAL_POLLING_THREAD " \
7911 _ (
"Using debug build of libmicrohttpd.\n") );
7916#
if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7921 if (! MHD_itc_init_ (daemon->
itc))
7925 _ (
"Failed to create inter-thread communication channel: %s\n"),
7926 MHD_itc_last_strerror_ ());
7929 if (
NULL != daemon->priority_cache)
7930 gnutls_priority_deinit (daemon->priority_cache);
7940 _ (
"file descriptor for inter-thread communication " \
7941 "channel exceeds maximum value.\n"));
7945 if (
NULL != daemon->priority_cache)
7946 gnutls_priority_deinit (daemon->priority_cache);
7954 if (
NULL != daemon->digest_auth_random_copy)
7956 mhd_assert (daemon == daemon->digest_auth_random_copy);
7957 daemon->digest_auth_random_copy = malloc (daemon->digest_auth_rand_size);
7958 if (
NULL == daemon->digest_auth_random_copy)
7962 gnutls_priority_deinit (daemon->priority_cache);
7967 memcpy (daemon->digest_auth_random_copy,
7968 daemon->digest_auth_random,
7969 daemon->digest_auth_rand_size);
7970 daemon->digest_auth_random = daemon->digest_auth_random_copy;
7972 if (daemon->nonce_nc_size > 0)
7974 if ( ( (
size_t) (daemon->nonce_nc_size * sizeof (
struct MHD_NonceNc)))
7975 /
sizeof(
struct MHD_NonceNc) != daemon->nonce_nc_size)
7979 _ (
"Specified value for NC_SIZE too large.\n"));
7983 gnutls_priority_deinit (daemon->priority_cache);
7985 free (daemon->digest_auth_random_copy);
7991 if (
NULL == daemon->nnc)
7995 _ (
"Failed to allocate memory for nonce-nc map: %s\n"),
8000 gnutls_priority_deinit (daemon->priority_cache);
8002 free (daemon->digest_auth_random_copy);
8008#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8013 _ (
"MHD failed to initialize nonce-nc mutex.\n"));
8017 gnutls_priority_deinit (daemon->priority_cache);
8019 free (daemon->digest_auth_random_copy);
8028#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8034 _ (
"MHD thread polling only works with " \
8035 "MHD_USE_INTERNAL_POLLING_THREAD.\n"));
8045 struct sockaddr_in servaddr4;
8047 struct sockaddr_in6 servaddr6;
8050 const bool use_ipv6 =
false;
8054 if (
NULL != pservaddr)
8056#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
8057 const socklen_t sa_len = pservaddr->sa_len;
8060 if (use_ipv6 && (AF_INET6 != pservaddr->sa_family))
8064 _ (
"MHD_USE_IPv6 is enabled, but 'struct sockaddr *' " \
8065 "specified for MHD_OPTION_SOCK_ADDR_LEN or " \
8066 "MHD_OPTION_SOCK_ADDR is not IPv6 address.\n"));
8071 switch (pservaddr->sa_family)
8076 struct sockaddr_in sa4;
8079 && (((socklen_t)
sizeof(sa4)) > addrlen))
8083 _ (
"The size specified for MHD_OPTION_SOCK_ADDR_LEN " \
8084 "option is wrong.\n"));
8088#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
8091 if (((socklen_t)
sizeof(sa4)) > sa_len)
8095 _ (
"The value of 'struct sockaddr.sa_len' provided " \
8096 "via MHD_OPTION_SOCK_ADDR_LEN option is not zero " \
8097 "and does not match 'sa_family' value of the " \
8098 "same structure.\n"));
8102 if ((0 == addrlen) || (sa_len < addrlen))
8107 addrlen =
sizeof(sa4);
8108 memcpy (&sa4, pservaddr,
sizeof(sa4));
8109 sa4_port = (uint16_t) ntohs (sa4.sin_port);
8110#ifndef MHD_USE_GETSOCKNAME
8113 daemon->
port = sa4_port;
8121 struct sockaddr_in6 sa6;
8124 && (((socklen_t)
sizeof(sa6)) > addrlen))
8128 _ (
"The size specified for MHD_OPTION_SOCK_ADDR_LEN " \
8129 "option is wrong.\n"));
8133#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
8136 if (((socklen_t)
sizeof(sa6)) > sa_len)
8140 _ (
"The value of 'struct sockaddr.sa_len' provided " \
8141 "via MHD_OPTION_SOCK_ADDR_LEN option is not zero " \
8142 "and does not match 'sa_family' value of the " \
8143 "same structure.\n"));
8147 if ((0 == addrlen) || (sa_len < addrlen))
8152 addrlen =
sizeof(sa6);
8153 memcpy (&sa6, pservaddr,
sizeof(sa6));
8154 sa6_port = (uint16_t) ntohs (sa6.sin6_port);
8155#ifndef MHD_USE_GETSOCKNAME
8158 daemon->
port = sa6_port;
8168#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
8171 else if ((0 != sa_len) && (sa_len < addrlen))
8178 _ (
"The 'sa_family' of the 'struct sockaddr' provided " \
8179 "via MHD_OPTION_SOCK_ADDR option is not supported.\n"));
8184 if (AF_UNIX == pservaddr->sa_family)
8201 domain = pservaddr->sa_family;
8212 sizeof (
struct sockaddr_in));
8213 servaddr4.sin_family = AF_INET;
8214 servaddr4.sin_port = htons (port);
8215 if (0 != INADDR_ANY)
8216 servaddr4.sin_addr.s_addr = htonl (INADDR_ANY);
8217#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
8218 servaddr4.sin_len =
sizeof (
struct sockaddr_in);
8220 pservaddr = (
struct sockaddr *) &servaddr4;
8221 addrlen = (socklen_t)
sizeof(servaddr4);
8228#ifdef IN6ADDR_ANY_INIT
8229 static const struct in6_addr static_in6any = IN6ADDR_ANY_INIT;
8233 sizeof (
struct sockaddr_in6));
8234 servaddr6.sin6_family = AF_INET6;
8235 servaddr6.sin6_port = htons (port);
8236#ifdef IN6ADDR_ANY_INIT
8237 servaddr6.sin6_addr = static_in6any;
8239#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
8240 servaddr6.sin6_len =
sizeof (
struct sockaddr_in6);
8242 pservaddr = (
struct sockaddr *) &servaddr6;
8243 addrlen = (socklen_t)
sizeof (servaddr6);
8255 _ (
"Failed to create socket for listening: %s\n"),
8265 _ (
"Listen socket descriptor (%d) is not " \
8266 "less than daemon FD_SETSIZE value (%d).\n"),
8278#ifndef MHD_WINSOCK_SOCKETS
8283 if (0 > setsockopt (listen_fd,
8286 (
const void *) &on,
sizeof (on)))
8290 _ (
"setsockopt failed: %s\n"),
8299#ifndef MHD_WINSOCK_SOCKETS
8302 if (0 > setsockopt (listen_fd,
8305 (
const void *) &on,
sizeof (on)))
8309 _ (
"setsockopt failed: %s\n"),
8319#if defined(MHD_WINSOCK_SOCKETS) || defined(SO_REUSEPORT)
8320 if (0 > setsockopt (listen_fd,
8322#ifndef MHD_WINSOCK_SOCKETS
8332 _ (
"setsockopt failed: %s\n"),
8342 _ (
"Cannot allow listening address reuse: " \
8343 "SO_REUSEPORT not defined.\n"));
8356#if (defined(MHD_WINSOCK_SOCKETS) && defined(SO_EXCLUSIVEADDRUSE)) || \
8357 (defined(__sun) && defined(SO_EXCLBIND))
8358 if (0 > setsockopt (listen_fd,
8360#ifdef SO_EXCLUSIVEADDRUSE
8361 SO_EXCLUSIVEADDRUSE,
8370 _ (
"setsockopt failed: %s\n"),
8375#elif defined(MHD_WINSOCK_SOCKETS)
8378 _ (
"Cannot disallow listening address reuse: " \
8379 "SO_EXCLUSIVEADDRUSE not defined.\n"));
8398 if (0 > setsockopt (listen_fd,
8399 IPPROTO_IPV6, IPV6_V6ONLY,
8400 (
const void *) &v6_only,
8405 _ (
"setsockopt failed: %s\n"),
8412 if (0 != bind (listen_fd, pservaddr, addrlen))
8416 _ (
"Failed to bind to port %u: %s\n"),
8417 (
unsigned int) port,
8427 if (0 == daemon->fastopen_queue_size)
8428 daemon->fastopen_queue_size = MHD_TCP_FASTOPEN_QUEUE_SIZE_DEFAULT;
8429 if (0 != setsockopt (listen_fd,
8432 (
const void *) &daemon->fastopen_queue_size,
8433 sizeof (daemon->fastopen_queue_size)))
8437 _ (
"setsockopt failed: %s\n"),
8443 if (0 != listen (listen_fd,
8448 _ (
"Failed to listen for connections: %s\n"),
8463 _ (
"Listen socket descriptor (%d) is not " \
8464 "less than daemon FD_SETSIZE value (%d).\n"),
8472#if defined(SOL_SOCKET) && (defined(SO_DOMAIN) || defined(SO_PROTOCOL_INFOW))
8476 socklen_t optval_size;
8478 opt_name = SO_DOMAIN;
8480 optval_size = (socklen_t)
sizeof (af);
8482 WSAPROTOCOL_INFOW prot_info;
8483 opt_name = SO_PROTOCOL_INFOW;
8484 poptval = &prot_info;
8485 optval_size = (socklen_t)
sizeof (prot_info);
8495 af = prot_info.iAddressFamily;
8526#ifdef MHD_USE_GETSOCKNAME
8531#ifdef MHD_USE_GETSOCKNAME
8532 if ( (0 == daemon->
port) &&
8536 struct sockaddr_storage bindaddr;
8540 sizeof (
struct sockaddr_storage));
8541 addrlen =
sizeof (
struct sockaddr_storage);
8542#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
8543 bindaddr.ss_len = (socklen_t) addrlen;
8545 if (0 != getsockname (listen_fd,
8546 (
struct sockaddr *) &bindaddr,
8551 _ (
"Failed to get listen port number: %s\n"),
8555#ifdef MHD_POSIX_SOCKETS
8556 else if (
sizeof (bindaddr) < addrlen)
8561 _ (
"Failed to get listen port number " \
8562 "(`struct sockaddr_storage` too small!?).\n"));
8566 else if (0 == addrlen)
8578 switch (bindaddr.ss_family)
8582 struct sockaddr_in *s4 = (
struct sockaddr_in *) &bindaddr;
8584 daemon->
port = ntohs (s4->sin_port);
8591 struct sockaddr_in6 *s6 = (
struct sockaddr_in6 *) &bindaddr;
8593 daemon->
port = ntohs (s6->sin6_port);
8608 _ (
"Listen socket has unknown address family!\n"));
8625 _ (
"Failed to set nonblocking mode on listening socket: %s\n"),
8629#
if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8654#
if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8663 _ (
"Combining MHD_USE_THREAD_PER_CONNECTION and " \
8664 "MHD_USE_EPOLL is not supported.\n"));
8668 if (
MHD_NO == setup_epoll_to_listen (daemon))
8673#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8678 _ (
"MHD failed to initialize IP connection limit mutex.\n"));
8689 (0 != MHD_TLS_init (daemon)) )
8693 _ (
"Failed to initialize TLS support.\n"));
8697#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8703#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8711#ifdef HAVE_LISTEN_SHUTDOWN
8713 (MHD_ITC_IS_VALID_ (daemon->
itc)) || \
8717 (MHD_ITC_IS_VALID_ (daemon->
itc)));
8725 _ (
"Failed to initialise internal lists mutex.\n"));
8736 _ (
"Failed to initialise mutex.\n"));
8746 "MHD-listen" :
"MHD-single",
8747 daemon->thread_stack_size,
8753 if (EAGAIN == errno)
8755 _ (
"Failed to create a new thread because it would have " \
8756 "exceeded the system limit on the number of threads or " \
8757 "no system resources available.\n"));
8761 _ (
"Failed to create listen thread: %s\n"),
8797 memcpy (d, daemon,
sizeof (
struct MHD_Daemon));
8808 _ (
"Failed to initialise internal lists mutex.\n"));
8816 _ (
"Failed to initialise mutex.\n"));
8823 if (! MHD_itc_init_ (d->
itc))
8827 _ (
"Failed to create worker inter-thread " \
8828 "communication channel: %s\n"),
8829 MHD_itc_last_strerror_ () );
8840 _ (
"File descriptor for worker inter-thread " \
8841 "communication channel exceeds maximum value.\n"));
8850 MHD_itc_set_invalid_ (d->
itc);
8852#ifdef HAVE_LISTEN_SHUTDOWN
8863 if (i < leftover_conns)
8867 (
MHD_NO == setup_epoll_to_listen (d)) )
8869 if (MHD_ITC_IS_VALID_ (d->
itc))
8877#if defined(MHD_USE_THREADS)
8883 d->nonce_nc_size = 0;
8884 d->digest_auth_random_copy =
NULL;
8885#if defined(MHD_USE_THREADS)
8886 memset (&d->nnc_lock, 0x7F,
sizeof(d->nnc_lock));
8893 daemon->thread_stack_size,
8899 if (EAGAIN == errno)
8901 _ (
"Failed to create a new pool thread because it would " \
8902 "have exceeded the system limit on the number of " \
8903 "threads or no system resources available.\n"));
8907 _ (
"Failed to create pool thread: %s\n"),
8913 if (MHD_ITC_IS_VALID_ (d->
itc))
8928 _ (
"Failed to initialise internal lists mutex.\n"));
8939 _ (
"Failed to initialise mutex.\n"));
8952 daemon->https_key_password =
NULL;
8957#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8987#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
8988 if (daemon->upgrade_fd_in_epoll)
8990 if (0 != epoll_ctl (daemon->epoll_fd,
8992 daemon->epoll_upgrade_fd,
8994 MHD_PANIC (
_ (
"Failed to remove FD from epoll set.\n"));
8995 daemon->upgrade_fd_in_epoll =
false;
8998 if (-1 != daemon->epoll_fd)
8999 close (daemon->epoll_fd);
9000#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
9001 if (-1 != daemon->epoll_upgrade_fd)
9002 close (daemon->epoll_upgrade_fd);
9006 free (daemon->digest_auth_random_copy);
9008#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9015 gnutls_priority_deinit (daemon->priority_cache);
9016 if (daemon->x509_cred)
9017 gnutls_certificate_free_credentials (daemon->x509_cred);
9018 if (daemon->psk_cred)
9019 gnutls_psk_free_server_credentials (daemon->psk_cred);
9022 if (MHD_ITC_IS_VALID_ (daemon->
itc))
9047#ifdef UPGRADE_SUPPORT
9050#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
9051 struct MHD_UpgradeResponseHandle *urh;
9052 struct MHD_UpgradeResponseHandle *urhn;
9056#ifdef MHD_USE_THREADS
9064#ifdef MHD_USE_THREADS
9074 new_connection_close_ (daemon, pos);
9079#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
9082 for (urh = daemon->urh_tail;
NULL != urh; urh = urhn)
9090 urh->clean_ready =
true;
9107#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9110#ifdef UPGRADE_SUPPORT
9116 while (
NULL != susp)
9118 if (
NULL == susp->urh)
9119 MHD_PANIC (
_ (
"MHD_stop_daemon() called while we have " \
9120 "suspended connections.\n"));
9122 else if (used_tls &&
9124 (! susp->urh->clean_ready) )
9125 shutdown (susp->urh->app.socket,
9131 if (! susp->urh->was_closed)
9133 _ (
"Initiated daemon shutdown while \"upgraded\" " \
9134 "connection was not closed.\n"));
9136 susp->urh->was_closed =
true;
9152 MHD_PANIC (
_ (
"MHD_stop_daemon() called while we have " \
9153 "suspended connections.\n"));
9154#if defined(UPGRADE_SUPPORT) && defined(HTTPS_SUPPORT)
9155#ifdef MHD_USE_THREADS
9156 if (upg_allowed && used_tls && used_thr_p_c)
9175 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
9187#ifdef MHD_WINSOCK_SOCKETS
9190 (! MHD_itc_activate_ (
daemon->
itc,
"e")) )
9191 MHD_PANIC (
_ (
"Failed to signal shutdown via inter-thread " \
9192 "communication channel.\n"));
9196#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9207 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
9221#ifdef UPGRADE_SUPPORT
9237#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9240 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
9258#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9265 MHD_PANIC (
_ (
"MHD_stop_daemon() was called twice."));
9283#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9297 MHD_PANIC (
_ (
"Failed to signal shutdown via inter-thread " \
9298 "communication channel.\n"));
9303#ifdef HAVE_LISTEN_SHUTDOWN
9306 (void) shutdown (
fd,
9318#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
9326#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9335 MHD_PANIC (
_ (
"Failed to signal shutdown via inter-thread " \
9336 "communication channel.\n"));
9340#ifdef HAVE_LISTEN_SHUTDOWN
9344 (void) shutdown (
fd,
9354 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
9368#if defined(UPGRADE_SUPPORT) && defined(HTTPS_SUPPORT)
9377 (-1 !=
daemon->epoll_fd) )
9379#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
9381 (-1 !=
daemon->epoll_upgrade_fd) )
9386#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9401 if (
daemon->have_dhparams)
9403 gnutls_dh_params_deinit (
daemon->https_mem_dhparams);
9404 daemon->have_dhparams =
false;
9408 gnutls_priority_deinit (
daemon->priority_cache);
9410 gnutls_certificate_free_credentials (
daemon->x509_cred);
9412 gnutls_psk_free_server_credentials (
daemon->psk_cred);
9417 free (
daemon->digest_auth_random_copy);
9419#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9423#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9469 daemon->daemon_info_dummy_epoll_fd.epoll_fd = daemon->epoll_fd;
9470 return &daemon->daemon_info_dummy_epoll_fd;
9477#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9514#ifdef PACKAGE_VERSION
9515 return PACKAGE_VERSION;
9517 static char ver[12] =
"\0\0\0\0\0\0\0\0\0\0\0";
9520 int res = MHD_snprintf_ (ver,
9526 if ((0 >= res) || (
sizeof(ver) <= res))
9578#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_MAJOR >= 3
9584#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_NUMBER >= 0x030603
9596#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
9614#ifdef HAVE_LISTEN_SHUTDOWN
9620#ifdef _MHD_ITC_SOCKETPAIR
9644#ifdef HAVE_POSTPROCESSOR
9650#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_NUMBER >= 0x030111
9656#if defined(HAVE_PREAD64) || defined(_WIN32)
9658#elif defined(HAVE_PREAD)
9659 return (
sizeof(uint64_t) >
sizeof(off_t)) ?
MHD_NO :
MHD_YES;
9660#elif defined(HAVE_LSEEK64)
9663 return (
sizeof(uint64_t) >
sizeof(off_t)) ?
MHD_NO :
MHD_YES;
9666#if defined(MHD_USE_THREAD_NAME_)
9672#if defined(UPGRADE_SUPPORT)
9678#if defined(HAVE_PREAD64) || defined(HAVE_PREAD) || defined(_WIN32)
9684#ifdef MHD_USE_GETSOCKNAME
9690#if defined(MHD_SEND_SPIPE_SUPPRESS_POSSIBLE) || \
9691 ! defined(MHD_SEND_SPIPE_SUPPRESS_NEEDED)
9697#ifdef _MHD_HAVE_SENDFILE
9703#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
9709#if defined(COOKIE_SUPPORT)
9721#if defined(DAUTH_SUPPORT) && defined(MHD_MD5_SUPPORT)
9727#if defined(DAUTH_SUPPORT) && defined(MHD_SHA256_SUPPORT)
9733#if defined(DAUTH_SUPPORT) && defined(MHD_SHA512_256_SUPPORT)
9757#if defined(MHD_MD5_TLSLIB) || defined(MHD_SHA256_TLSLIB)
9769#ifdef HAS_FD_SETSIZE_OVERRIDABLE
9782#ifdef MHD_HTTPS_REQUIRE_GCRYPT
9783#if defined(HTTPS_SUPPORT) && GCRYPT_VERSION_NUMBER < 0x010600
9784#if defined(MHD_USE_POSIX_THREADS)
9785GCRY_THREAD_OPTION_PTHREAD_IMPL;
9786#elif defined(MHD_W32_MUTEX_)
9789gcry_w32_mutex_init (
void **ppmtx)
9791 *ppmtx = malloc (
sizeof (MHD_mutex_));
9807gcry_w32_mutex_destroy (
void **ppmtx)
9816gcry_w32_mutex_lock (
void **ppmtx)
9823gcry_w32_mutex_unlock (
void **ppmtx)
9829static struct gcry_thread_cbs gcry_threads_w32 = {
9830 (GCRY_THREAD_OPTION_USER | (GCRY_THREAD_OPTION_VERSION << 8)),
9831 NULL, gcry_w32_mutex_init, gcry_w32_mutex_destroy,
9832 gcry_w32_mutex_lock, gcry_w32_mutex_unlock,
9846#if defined(MHD_WINSOCK_SOCKETS)
9852#if defined(MHD_WINSOCK_SOCKETS)
9853 if (0 != WSAStartup (MAKEWORD (2, 2), &wsd))
9854 MHD_PANIC (
_ (
"Failed to initialize winsock.\n"));
9855 if ((2 != LOBYTE (wsd.wVersion)) && (2 != HIBYTE (wsd.wVersion)))
9856 MHD_PANIC (
_ (
"Winsock version 2.2 is not available.\n"));
9859#ifdef MHD_HTTPS_REQUIRE_GCRYPT
9860#if GCRYPT_VERSION_NUMBER < 0x010600
9861#if GNUTLS_VERSION_NUMBER <= 0x020b00
9862#if defined(MHD_USE_POSIX_THREADS)
9863 if (0 != gcry_control (GCRYCTL_SET_THREAD_CBS,
9864 &gcry_threads_pthread))
9865 MHD_PANIC (
_ (
"Failed to initialise multithreading in libgcrypt.\n"));
9866#elif defined(MHD_W32_MUTEX_)
9867 if (0 != gcry_control (GCRYCTL_SET_THREAD_CBS,
9869 MHD_PANIC (
_ (
"Failed to initialise multithreading in libgcrypt.\n"));
9872 gcry_check_version (
NULL);
9874 if (
NULL == gcry_check_version (
"1.6.0"))
9875 MHD_PANIC (
_ (
"libgcrypt is too old. MHD was compiled for " \
9876 "libgcrypt 1.6.0 or newer.\n"));
9879 gnutls_global_init ();
9889 mhd_assert (
sizeof(tv.tv_sec) == SIZEOF_STRUCT_TIMEVAL_TV_SEC);
9892 mhd_assert (
sizeof(uint64_t) == SIZEOF_UINT64_T);
9900 gnutls_global_deinit ();
9902#if defined(MHD_WINSOCK_SOCKETS)
9909#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)
Methods for managing connections.
#define MHD_connection_finish_forward_(conn)
static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_ thread_main_handle_connection(void *data)
void MHD_connection_mark_closed_(struct MHD_Connection *connection)
void MHD_connection_close_(struct MHD_Connection *connection, enum MHD_RequestTerminationCode rtc)
void MHD_set_https_callbacks(struct MHD_Connection *connection)
Methods for managing connections.
void MHD_update_last_activity_(struct MHD_Connection *connection)
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)
static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_ MHD_polling_thread(void *cls)
_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)
#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 EDLL_insert(head, tail, element)
#define EDLL_remove(head, tail, element)
#define XDLL_remove(head, tail, element)
#define DLL_remove(head, tail, element)
void MHD_pool_destroy(struct MemoryPool *pool)
struct MemoryPool * MHD_pool_create(size_t max)
void * MHD_calloc_(size_t nelem, size_t elsize)
#define MHD_strerror_(errnum)
#define MHD_ITC_IS_INVALID_(itc)
#define MHD_itc_destroy_chk_(itc)
#define TIMEVAL_TV_SEC_MAX
#define MHD_mutex_unlock_chk_(pmutex)
#define MHD_mutex_destroy_chk_(pmutex)
#define MHD_mutex_lock_chk_(pmutex)
void MHD_monotonic_sec_counter_finish(void)
void MHD_monotonic_sec_counter_init(void)
int MHD_add_to_fd_set_(MHD_socket fd, fd_set *set, MHD_socket *max_fd, unsigned int fd_setsize)
int MHD_socket_noninheritable_(MHD_socket sock)
int MHD_socket_nonblocking_(MHD_socket sock)
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 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 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 MHD_STATICSTR_LEN_(macro)
#define MHD_create_named_thread_(t, n, s, r, a)
void * tfind(const void *vkey, void *const *vrootp, int(*compar)(const void *, const void *))
void * tdelete(const void *__restrict vkey, void **__restrict vrootp, int(*compar)(const void *, const void *))
void * tsearch(const void *vkey, void **vrootp, int(*compar)(const void *, const void *))
#define MHD_DAUTH_DEF_TIMEOUT_
#define MHD_DAUTH_DEF_MAX_NC_
void MHD_send_init_static_vars_(void)
Declarations of send() wrappers.
#define _MHD_S_STR_W_LEN(str)
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 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)
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 MHD_D_IS_USING_THREAD_PER_CONN_(d)
#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)
memory pool; mostly used for efficient (de)allocation for each connection and bounding memory use for...
Header for platform missing functions.
Header for platform-independent inter-thread communication.
limits values definitions
Header for platform-independent locks abstraction.
#define MHD_mutex_destroy_(ignore)
#define MHD_mutex_unlock_(ignore)
#define MHD_mutex_lock_(ignore)
#define MHD_mutex_init_(ignore)
uint64_t MHD_monotonic_msec_counter(void)
internal monotonic clock functions implementations
#define SOCK_NONBLOCK_OR_ZERO
#define SOCK_NOSIGPIPE_OR_ZERO
#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.
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)
@ 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_DIGEST_AUTH_MD5
@ MHD_FEATURE_HTTPS_COOKIE_PARSING
@ 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_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_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 * prevX
enum MHD_ConnectionEventLoopInfo event_loop_info
enum MHD_tristate is_nonip
struct MHD_Connection * next
struct sockaddr_storage addr
size_t read_buffer_offset
struct MHD_Connection * prev
struct MHD_Connection * nextX
enum MHD_CONNECTION_STATE state
struct MHD_Daemon * daemon
uint64_t connection_timeout_ms
enum MHD_tristate sk_corked
MHD_NotifyConnectionCallback notify_connection
MHD_AccessHandlerCallback default_handler
LogCallback uri_log_callback
bool data_already_pending
MHD_mutex_ per_ip_connection_mutex
union MHD_DaemonInfo daemon_info_dummy_port
void * per_ip_connection_count
struct MHD_Connection * new_connections_tail
unsigned int connection_limit
void * unescape_callback_cls
MHD_mutex_ cleanup_connection_mutex
enum MHD_DisableSanityCheck insanity_level
struct MHD_Connection * connections_head
union MHD_DaemonInfo daemon_info_dummy_listen_fd
unsigned int listen_backlog_size
union MHD_DaemonInfo daemon_info_dummy_flags
MHD_RequestCompletedCallback notify_completed
unsigned int worker_pool_size
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
UnescapeCallback unescape_callback
void * notify_completed_cls
struct MHD_Connection * cleanup_tail
struct MHD_Daemon * worker_pool
struct MHD_Connection * new_connections_head
struct MHD_Connection * manual_timeout_head
enum MHD_tristate listen_is_unix
void * default_handler_cls
struct MHD_Connection * suspended_connections_tail
MHD_AcceptPolicyCallback apc
struct MHD_Connection * cleanup_head
struct MHD_Daemon * master
struct MHD_Connection * normal_timeout_head
struct MHD_Connection * normal_timeout_tail
void * uri_log_callback_cls
struct MHD_Connection * suspended_connections_head
struct MHD_Connection * connections_tail
struct MHD_Response * response
unsigned int num_connections