35 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 36 #include "mhd_locks.h" 41 #ifdef MHD_LINUX_SOLARIS_SENDFILE 42 #include <sys/sendfile.h> 44 #if defined(HAVE_FREEBSD_SENDFILE) || defined(HAVE_DARWIN_SENDFILE) 45 #include <sys/types.h> 46 #include <sys/socket.h> 52 #ifdef HAVE_SYS_PARAM_H 54 #include <sys/param.h> 61 #define HTTP_100_CONTINUE "HTTP/1.1 100 Continue\r\n\r\n" 71 #define REQUEST_TOO_BIG "<html><head><title>Request too big</title></head><body>Your HTTP header was too big for the memory constraints of this webserver.</body></html>" 73 #define REQUEST_TOO_BIG "" 84 #define REQUEST_LACKS_HOST "<html><head><title>"Host:" header required</title></head><body>In HTTP 1.1, requests must include a "Host:" header, and your HTTP 1.1 request lacked such a header.</body></html>" 86 #define REQUEST_LACKS_HOST "" 97 #define REQUEST_MALFORMED "<html><head><title>Request malformed</title></head><body>Your HTTP request was syntactically incorrect.</body></html>" 99 #define REQUEST_MALFORMED "" 109 #define INTERNAL_ERROR "<html><head><title>Internal server error</title></head><body>Please ask the developer of this Web server to carefully read the GNU libmicrohttpd documentation about connection management and blocking.</body></html>" 111 #define INTERNAL_ERROR "" 118 #define DEBUG_CLOSE MHD_NO 123 #define DEBUG_SEND_DATA MHD_NO 129 #define MHD_SENFILE_CHUNK_ (0x20000) 134 #define MHD_SENFILE_CHUNK_THR_P_C_ (0x200000) 136 #ifdef HAVE_FREEBSD_SENDFILE 141 static int freebsd_sendfile_flags_;
146 static int freebsd_sendfile_flags_thd_p_c_;
152 MHD_conn_init_static_ (
void)
158 long sys_page_size = sysconf (_SC_PAGESIZE);
159 if (0 > sys_page_size)
161 freebsd_sendfile_flags_ = SF_NODISKIO;
162 freebsd_sendfile_flags_thd_p_c_ = SF_NODISKIO;
166 freebsd_sendfile_flags_ =
168 freebsd_sendfile_flags_thd_p_c_ =
220 else if (i > (
size_t)ret)
274 else if (i > (
size_t)ret)
281 #if defined(_MHD_HAVE_SENDFILE) 295 #ifndef HAVE_SENDFILE64 296 const uint64_t max_off_t = (uint64_t)
OFF_T_MAX;
298 const uint64_t max_off_t = (uint64_t)OFF64_T_MAX;
300 #ifdef MHD_LINUX_SOLARIS_SENDFILE 301 #ifndef HAVE_SENDFILE64 307 #ifdef HAVE_FREEBSD_SENDFILE 311 #ifdef HAVE_DARWIN_SENDFILE 316 size_t send_size = 0;
317 mhd_assert (MHD_resp_sender_sendfile == connection->resp_sender);
323 send_size = (left > chunk_size) ? chunk_size : (
size_t) left;
324 if (max_off_t < offsetu64)
326 connection->resp_sender = MHD_resp_sender_std;
329 #ifdef MHD_LINUX_SOLARIS_SENDFILE 330 #ifndef HAVE_SENDFILE64 331 offset = (off_t) offsetu64;
337 offset = (off64_t) offsetu64;
356 #ifdef HAVE_LINUX_SENDFILE 365 connection->resp_sender = MHD_resp_sender_std;
368 if ( (EAFNOSUPPORT == err) ||
370 (EOPNOTSUPP == err) )
372 connection->resp_sender = MHD_resp_sender_std;
375 if ( (ENOTCONN == err) ||
384 else if (send_size > (
size_t)ret)
387 #elif defined(HAVE_FREEBSD_SENDFILE) 389 flags = used_thr_p_c ?
390 freebsd_sendfile_flags_thd_p_c_ : freebsd_sendfile_flags_;
392 if (0 != sendfile (file_fd,
407 return (ssize_t)sent_bytes;
413 connection->resp_sender = MHD_resp_sender_std;
418 ret = (ssize_t)sent_bytes;
419 #elif defined(HAVE_DARWIN_SENDFILE) 420 len = (off_t)send_size;
421 if (0 != sendfile (file_fd,
440 if (ENOTCONN == err ||
443 if (ENOTSUP == err ||
447 connection->resp_sender = MHD_resp_sender_std;
481 _MHD_static_inline
bool 485 #if defined(TCP_CORK) || defined(TCP_PUSH) 500 _MHD_static_inline
bool 504 #if defined(TCP_NODELAY) 510 if (0 == setsockopt (connection->
socket_fd,
513 (
const void *) &off_val,
521 #if defined(MHD_TCP_CORK_NOPUSH) 527 if (0 == setsockopt (connection->
socket_fd,
530 (
const void *) &on_val,
538 #if defined(TCP_NODELAY) 552 _MHD_static_inline
bool 555 #if defined(MHD_TCP_CORK_NOPUSH) 560 if (0 == setsockopt (connection->
socket_fd,
563 (
const void *) &off_val,
571 #if defined(TCP_NODELAY) 576 if (0 == setsockopt (connection->
socket_fd,
579 (
const void *) &on_val,
597 _MHD_static_inline
bool 601 #if defined(TCP_NOPUSH) && !defined(TCP_CORK) 604 #if defined(TCP_CORK) || (defined(__FreeBSD__) && __FreeBSD__+0 >= 9) 608 if (0 == setsockopt (connection->
socket_fd,
611 (
const void *) &off_val,
619 #if defined(__FreeBSD__) && __FreeBSD__+0 >= 9 621 #elif defined(TCP_NOPUSH) && !defined(TCP_CORK) 639 _MHD_static_inline
bool 643 #if defined(MHD_TCP_CORK_NOPUSH) 648 if (0 == setsockopt (connection->
socket_fd,
651 (
const void *) &off_val,
659 #if defined(TCP_NODELAY) 664 if (0 == setsockopt (connection->
socket_fd,
667 (
const void *) &off_val,
698 if (
NULL == connection)
705 if ( (
NULL != iterator) &&
706 (
MHD_YES != iterator (iterator_cls,
754 pos->
header = (
char *) key;
790 if (
NULL == connection)
851 #define MHD_lookup_header_s_token_ci(c,h,tkn) \ 852 MHD_lookup_header_token_ci((c),(h),(tkn),MHD_STATICSTR_LEN_(tkn)) 948 #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 963 struct MHD_UpgradeResponseHandle *urh = connection->urh;
974 (0 != epoll_ctl (daemon->epoll_upgrade_fd,
979 MHD_PANIC (
_(
"Failed to remove FD from epoll set\n"));
981 if (urh->in_eready_list)
984 daemon->eready_urh_tail,
986 urh->in_eready_list =
false;
993 (0 != epoll_ctl (daemon->epoll_upgrade_fd,
998 MHD_PANIC (
_(
"Failed to remove FD from epoll set\n"));
1003 shutdown (urh->mhd.socket, SHUT_RDWR);
1025 #ifdef HAVE_MESSAGES 1027 MHD_DLOG (connection->
daemon,
1041 #ifdef HAVE_MESSAGES 1042 #define CONNECTION_CLOSE_ERROR(c, emsg) connection_close_error (c, emsg) 1044 #define CONNECTION_CLOSE_ERROR(c, emsg) connection_close_error (c, NULL) 1077 #if defined(_MHD_HAVE_SENDFILE) 1078 if (MHD_resp_sender_sendfile == connection->resp_sender)
1096 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 1104 _(
"Closing connection (application reported error generating data)\n"));
1112 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 1146 2 * (0xFFFFFF +
sizeof(cbuf) + 2));
1152 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 1157 _(
"Closing connection (out of memory)\n"));
1164 while (
NULL == buf);
1178 const size_t data_write_offset
1181 ret = response->
data_size - data_write_offset;
1185 &response->
data[data_write_offset],
1200 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 1204 _(
"Closing connection (application error generating response)\n"));
1222 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 1229 cblen = MHD_snprintf_(cbuf,
1232 (
unsigned int) ret);
1235 memcpy (&connection->
write_buffer[sizeof (cbuf) - cblen],
1238 memcpy (&connection->
write_buffer[sizeof (cbuf) + ret],
1317 static const char *
const days[] = {
1318 "Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat" 1320 static const char *
const mons[] = {
1321 "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
1322 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec" 1326 #if !defined(HAVE_C11_GMTIME_S) && !defined(HAVE_W32_GMTIME_S) && !defined(HAVE_GMTIME_R) 1332 #if defined(HAVE_C11_GMTIME_S) 1333 if (
NULL == gmtime_s (&t,
1336 #elif defined(HAVE_W32_GMTIME_S) 1337 if (0 != gmtime_s (&now,
1340 #elif defined(HAVE_GMTIME_R) 1341 if (
NULL == gmtime_r(&t,
1350 MHD_snprintf_ (date,
1352 "Date: %3s, %02u %3s %04u %02u:%02u:%02u GMT\r\n",
1353 days[now.tm_wday % 7],
1354 (
unsigned int) now.tm_mday,
1355 mons[now.tm_mon % 12],
1356 (
unsigned int) (1900 + now.tm_year),
1357 (
unsigned int) now.tm_hour,
1358 (
unsigned int) now.tm_min,
1359 (
unsigned int) now.tm_sec);
1415 char content_length_buf[128];
1416 size_t content_length_len;
1419 const char *reason_phrase;
1421 bool client_requested_close;
1422 bool response_has_close;
1423 bool response_has_keepalive;
1424 const char *have_encoding;
1426 int must_add_chunked_encoding;
1427 int must_add_keep_alive;
1428 int must_add_content_length;
1429 int may_add_content_length;
1432 if (0 == connection->
version[0])
1447 MHD_snprintf_ (code,
1459 off = strlen (code);
1470 datelen = strlen (date);
1485 must_add_chunked_encoding =
MHD_NO;
1486 must_add_keep_alive =
MHD_NO;
1487 must_add_content_length =
MHD_NO;
1488 response_has_close =
false;
1489 switch (connection->
state)
1504 #ifdef UPGRADE_SUPPORT 1505 else if (
NULL != response->upgrade_handler)
1514 if (
NULL == have_encoding)
1515 may_add_content_length =
MHD_YES;
1517 may_add_content_length =
MHD_NO;
1519 #ifdef UPGRADE_SUPPORT
1520 (
NULL == response->upgrade_handler) &&
1522 (! response_has_close) &&
1523 (! client_requested_close) )
1534 if (
NULL == have_encoding)
1536 must_add_chunked_encoding =
MHD_YES;
1557 if (! response_has_close)
1563 if ( ( (client_requested_close) ||
1566 (! response_has_close) &&
1567 #ifdef UPGRADE_SUPPORT
1568 (
NULL == response->upgrade_handler) &&
1575 if ( (! may_add_content_length) &&
1577 (! response_has_close) )
1590 (may_add_content_length) &&
1611 = MHD_snprintf_ (content_length_buf,
1612 sizeof (content_length_buf),
1615 must_add_content_length =
MHD_YES;
1619 if ( (! response_has_keepalive) &&
1620 (! response_has_close) &&
1621 (
MHD_NO == must_add_close) &&
1623 #ifdef UPGRADE_SUPPORT
1624 (
NULL == response->upgrade_handler) &&
1627 must_add_keep_alive =
MHD_YES;
1630 response_has_keepalive =
false;
1639 if ( (must_add_close) || (response_has_close) )
1641 else if ( (must_add_keep_alive) || (response_has_keepalive) )
1647 if (must_add_keep_alive)
1649 if (must_add_chunked_encoding)
1651 if (must_add_content_length)
1652 size += content_length_len;
1653 mhd_assert (! (must_add_close && must_add_keep_alive) );
1654 mhd_assert (! (must_add_chunked_encoding && must_add_content_length) );
1660 (! ( (
MHD_YES == must_add_close) &&
1661 (response_has_keepalive) &&
1665 "Keep-Alive")) ) ) )
1666 size += strlen (pos->
header) + strlen (pos->
value) + 4;
1674 #ifdef HAVE_MESSAGES 1675 MHD_DLOG (connection->
daemon,
1676 "Not enough memory for write!\n");
1690 "Connection: close\r\n",
1694 if (must_add_keep_alive)
1698 "Connection: Keep-Alive\r\n",
1702 if (must_add_chunked_encoding)
1706 "Transfer-Encoding: chunked\r\n",
1710 if (must_add_content_length)
1715 content_length_len);
1716 off += content_length_len;
1722 (! ( (
MHD_YES == must_add_close) &&
1723 (response_has_keepalive) &&
1727 "Keep-Alive")) ) ) )
1728 off += MHD_snprintf_ (&
data[off],
1770 unsigned int status_code,
1771 const char *message)
1784 #ifdef HAVE_MESSAGES 1785 MHD_DLOG (connection->
daemon,
1786 _(
"Error processing request (HTTP response code is %u (`%s')). Closing connection.\n"),
1798 if (
NULL == response)
1812 _(
"Closing connection (failed to queue response)\n"));
1822 _(
"Closing connection (failed to create response header)\n"));
1845 #ifdef HTTPS_SUPPORT 1848 switch (connection->tls_state)
1854 if (0 == gnutls_record_get_direction (connection->tls_session))
1867 MHD_DLOG (connection->
daemon,
1868 _(
"In function %s handling connection at state: %s\n"),
1870 MHD_state_to_string (connection->
state));
1872 switch (connection->
state)
1981 #ifdef UPGRADE_SUPPORT 1982 case MHD_CONNECTION_UPGRADE:
2018 while ( (pos < connection->read_buffer_offset - 1) &&
2019 (
'\r' != rbuf[pos]) &&
2020 (
'\n' != rbuf[pos]) )
2023 (
'\n' != rbuf[pos]) )
2044 if ( (
'\r' == rbuf[pos]) &&
2045 (
'\n' == rbuf[pos + 1]) )
2078 #ifdef HAVE_MESSAGES 2079 MHD_DLOG (connection->
daemon,
2080 _(
"Not enough memory in pool to allocate header record!\n"));
2120 #ifdef HAVE_MESSAGES 2121 MHD_DLOG (connection->
daemon,
2122 _(
"Not enough memory in pool to parse cookies!\n"));
2139 while ( ((*sce) !=
'\0') &&
2146 while ( (*ekill ==
' ') &&
2168 while ( (
'\0' != semicolon[0]) &&
2170 ( (
';' != semicolon[0]) &&
2171 (
',' != semicolon[0]) ) ) )
2173 if (
'"' == semicolon[0])
2174 quotes = (quotes + 1) & 1;
2177 if (
'\0' == semicolon[0])
2179 if (
NULL != semicolon)
2181 semicolon[0] =
'\0';
2185 if ( (
'"' == equals[0]) &&
2186 (
'"' == equals[strlen (equals) - 1]) )
2188 equals[strlen (equals) - 1] =
'\0';
2221 unsigned int unused_num_headers;
2224 if (
NULL == (uri = memchr (line,
2229 connection->
method = line;
2233 while ( (
' ' == uri[0]) &&
2234 ( (
size_t)(uri - line) < line_len) )
2236 if ((
size_t)(uri - line) == line_len)
2249 http_version = line + line_len - 1;
2251 while ( (
' ' == http_version[0]) &&
2252 (http_version > uri) )
2255 while ( (
' ' != http_version[0]) &&
2256 (http_version > uri) )
2258 if (http_version > uri)
2261 http_version[0] =
'\0';
2262 connection->
version = http_version + 1;
2263 uri_len = http_version - uri;
2268 uri_len = line_len - (uri - line);
2272 (
NULL != memchr (uri,
2304 &unused_num_headers);
2312 connection->
url = curi;
2346 _(
"Application reported internal error, closing connection.\n"));
2374 size_t to_be_processed;
2375 size_t left_unprocessed;
2376 size_t processed_size;
2389 if ( (
'\r' == buffer_head[i]) ||
2390 (
'\n' == buffer_head[i]) )
2392 if ( (
'\r' == buffer_head[i]) ||
2393 (
'\n' == buffer_head[i]) )
2399 _(
"Received malformed HTTP request (bad chunked encoding). Closing connection.\n"));
2410 uint64_t cur_chunk_left;
2416 if (cur_chunk_left > available)
2417 to_be_processed = available;
2420 to_be_processed = (size_t)cur_chunk_left;
2421 if (available > to_be_processed)
2433 while (i < available)
2435 if ( (
'\r' == buffer_head[i]) ||
2436 (
'\n' == buffer_head[i]) ||
2437 (
';' == buffer_head[i]) )
2445 if (
';' == buffer_head[i])
2447 while (i < available)
2449 if ( (
'\r' == buffer_head[i]) ||
2450 (
'\n' == buffer_head[i]) )
2458 if ( (i + 1 >= available) &&
2461 (
'0' == buffer_head[0]) ) )
2464 malformed = (end_size >= 16);
2470 malformed = (end_size != num_dig);
2476 _(
"Received malformed HTTP request (bad chunked encoding). Closing connection.\n"));
2480 if ( (i < available) &&
2481 ( (
'\r' == buffer_head[i]) ||
2482 (
'\n' == buffer_head[i]) ) )
2514 to_be_processed = available;
2517 left_unprocessed = to_be_processed;
2531 _(
"Application reported internal error, closing connection.\n"));
2534 if (left_unprocessed > to_be_processed)
2538 #ifdef HAVE_MESSAGES
2539 ,
_(
"libmicrohttpd API violation")
2544 if (0 != left_unprocessed)
2547 #ifdef HAVE_MESSAGES 2554 _(
"WARNING: incomplete upload processing and connection not suspended may result in hung connection.\n"));
2557 processed_size = to_be_processed - left_unprocessed;
2561 buffer_head += processed_size;
2562 available -= processed_size;
2566 while (
MHD_YES == instant_retry);
2592 connection->
state = next_state;
2619 colon = strchr (line,
':');
2624 _(
"Received malformed line (no colon). Closing connection.\n"));
2634 white = strchr (line,
' ');
2635 if ( (
NULL != white) &&
2638 white = strchr (line,
'\t');
2639 if ( (
NULL != white) &&
2646 while ( (
'\0' != colon[0]) &&
2647 ( (
' ' == colon[0]) ||
2648 (
'\t' == colon[0]) ) )
2655 connection->
last = line;
2656 connection->
colon = colon;
2681 last = connection->
last;
2682 if ( (
' ' == line[0]) ||
2687 last_len = strlen (last);
2690 while ( (
' ' == tmp[0]) ||
2693 tmp_len = strlen (tmp);
2706 last_len + tmp_len + 1);
2714 memcpy (&last[last_len], tmp, tmp_len + 1);
2715 connection->
last = last;
2776 #ifdef HAVE_MESSAGES 2777 MHD_DLOG (connection->
daemon,
2778 _(
"Received HTTP 1.1 request without `Host' header.\n"));
2785 if (
NULL == response)
2789 _(
"Closing connection (failed to create response)\n"));
2800 _(
"Closing connection (failed to queue response)\n"));
2825 if ( (clen == end) ||
2829 #ifdef HAVE_MESSAGES 2830 MHD_DLOG (connection->
daemon,
2831 "Failed to parse `Content-Length' header. Closing connection.\n");
2866 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 2876 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 2896 #ifdef HTTPS_SUPPORT 2915 bytes_read = connection->
recv_cls (connection,
2929 _(
"Socket disconnected while reading request.\n"));
2935 _(
"Connection socket is closed due to error when reading request.\n"));
2939 if (0 == bytes_read)
2949 MHD_DLOG (connection->
daemon,
2950 _(
"In function %s handling connection at state: %s\n"),
2952 MHD_state_to_string (connection->
state));
2954 switch (connection->
state)
2974 #ifdef UPGRADE_SUPPORT 2975 case MHD_CONNECTION_UPGRADE:
3005 #ifdef HTTPS_SUPPORT 3017 MHD_DLOG (connection->
daemon,
3018 _(
"In function %s handling connection at state: %s\n"),
3020 MHD_state_to_string (connection->
state));
3022 switch (connection->
state)
3033 ret = connection->
send_cls (connection,
3042 #ifdef HAVE_MESSAGES 3043 MHD_DLOG (connection->
daemon,
3044 _(
"Failed to send data in request for %s.\n"),
3053 _(
"Sent 100 continue response: `%.*s'\n"),
3067 ret = connection->
send_cls (connection,
3077 _(
"Connection was closed while sending response headers.\n"));
3094 uint64_t data_write_offset;
3096 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 3105 #if defined(_MHD_HAVE_SENDFILE) 3106 if (MHD_resp_sender_sendfile == connection->resp_sender)
3108 ret = sendfile_adapter (connection);
3117 if (data_write_offset > (uint64_t)
SIZE_MAX)
3119 ret = connection->
send_cls (connection,
3121 [(
size_t)data_write_offset],
3123 (
size_t)data_write_offset);
3127 _(
"Sent %d-byte DATA response: `%.*s'\n"),
3134 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 3142 #ifdef HAVE_MESSAGES 3143 MHD_DLOG (connection->
daemon,
3144 _(
"Failed to send data in request for `%s'.\n"),
3162 ret = connection->
send_cls (connection,
3172 _(
"Connection was closed while sending response body.\n"));
3190 ret = connection->
send_cls (connection,
3200 _(
"Connection was closed while sending response body.\n"));
3215 #ifdef UPGRADE_SUPPORT 3216 case MHD_CONNECTION_UPGRADE:
3223 _(
"Internal error\n"));
3251 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 3283 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 3291 if ( (MHD_ITC_IS_VALID_ (daemon->
itc)) &&
3292 (! MHD_itc_activate_ (daemon->
itc,
"c")) )
3294 #ifdef HAVE_MESSAGES 3296 _(
"Failed to signal end of connection via inter-thread communication channel"));
3324 #ifdef HTTPS_SUPPORT 3327 if ((MHD_TLS_CONN_INIT <= connection->tls_state) &&
3334 _(
"In function %s handling connection at state: %s\n"),
3336 MHD_state_to_string (connection->
state));
3338 switch (connection->
state)
3347 if ( (
NULL == line) ||
3569 _(
"Closing connection (failed to create response header)\n"));
3587 #ifdef UPGRADE_SUPPORT 3591 connection->
state = MHD_CONNECTION_UPGRADE;
3626 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 3632 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 3641 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 3658 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 3666 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 3675 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 3692 _(
"Closing connection (failed to create response header)\n"));
3784 #ifdef UPGRADE_SUPPORT 3785 case MHD_CONNECTION_UPGRADE:
3799 if ( (0 != timeout) &&
3810 #ifdef EPOLL_SUPPORT 3814 ret = MHD_connection_epoll_update_ (connection);
3822 #ifdef EPOLL_SUPPORT 3845 struct epoll_event event;
3847 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET;
3848 event.data.ptr = connection;
3849 if (0 != epoll_ctl (daemon->epoll_fd,
3854 #ifdef HAVE_MESSAGES 3857 _(
"Call to epoll_ctl failed: %s\n"),
3901 #ifdef HTTPS_SUPPORT 3903 if (
NULL == connection->tls_session)
3905 connection->cipher = gnutls_cipher_get (connection->tls_session);
3908 if (
NULL == connection->tls_session)
3910 connection->protocol = gnutls_protocol_get_version (connection->tls_session);
3913 if (
NULL == connection->tls_session)
3959 daemon = connection->
daemon;
3965 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 3980 va_start (ap, option);
3996 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 4019 unsigned int status_code,
4024 if ( (
NULL == connection) ||
4025 (
NULL == response) ||
4030 daemon = connection->
daemon;
4036 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 4039 (!MHD_thread_ID_match_current_(connection->
pid.ID)) )
4041 #ifdef HAVE_MESSAGES 4043 _(
"Attempted to queue response on wrong thread!\n"));
4048 #ifdef UPGRADE_SUPPORT 4049 if ( (
NULL != response->upgrade_handler) &&
4052 #ifdef HAVE_MESSAGES 4054 _(
"Attempted 'upgrade' connection on daemon without MHD_ALLOW_UPGRADE option!\n"));
4059 (
NULL != response->upgrade_handler) )
4061 #ifdef HAVE_MESSAGES 4063 _(
"Application used invalid status code for 'upgrade' response!\n"));
4071 #if defined(_MHD_HAVE_SENDFILE) 4072 if ( (response->
fd == -1) ||
4074 connection->resp_sender = MHD_resp_sender_std;
4076 connection->resp_sender = MHD_resp_sender_sendfile;
static int process_header_line(struct MHD_Connection *connection, char *line)
static ssize_t send_param_adapter(struct MHD_Connection *connection, const void *other, size_t i)
#define MHD_send_(s, b, l)
int(* MHD_KeyValueIterator)(void *cls, enum MHD_ValueKind kind, const char *key, const char *value)
static int parse_cookie_header(struct MHD_Connection *connection)
void * unescape_callback_cls
void MHD_connection_handle_write(struct MHD_Connection *connection)
Header for platform missing functions.
static int try_ready_normal_body(struct MHD_Connection *connection)
uint64_t current_chunk_offset
_MHD_EXTERN const char * MHD_lookup_connection_value(struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key)
#define MHD_HTTP_METHOD_CONNECT
static void MHD_connection_update_event_loop_info(struct MHD_Connection *connection)
struct sockaddr_storage addr
struct MHD_Connection * cleanup_head
enum MHD_CONNECTION_STATE state
static int try_ready_chunked_body(struct MHD_Connection *connection)
#define MHD_lookup_header_s_token_ci(c, h, tkn)
uint64_t response_write_position
enum MHD_ConnKeepAlive keepalive
size_t MHD_str_to_uint64_(const char *str, uint64_t *out_val)
#define HTTP_100_CONTINUE
enum MHD_ConnectionEventLoopInfo event_loop_info
#define MHD_mutex_unlock_chk_(pmutex)
time_t connection_timeout
static int connection_add_header(struct MHD_Connection *connection, const char *key, const char *value, enum MHD_ValueKind kind)
Methods for managing connections.
MHD_PanicCallback mhd_panic
#define MHD_socket_get_error_()
internal monotonic clock functions implementations
void MHD_connection_close_(struct MHD_Connection *connection, enum MHD_RequestTerminationCode termination_code)
struct MHD_Response * response
#define REQUEST_LACKS_HOST
#define MHD_SENFILE_CHUNK_
#define MHD_HTTP_NOT_MODIFIED
bool MHD_str_has_token_caseless_(const char *str, const char *const token, size_t token_len)
bool MHD_parse_arguments_(struct MHD_Request *request, enum MHD_ValueKind kind, char *args, MHD_ArgumentIterator_ cb, unsigned int *num_headers)
struct MHD_Connection * manual_timeout_head
void MHD_connection_mark_closed_(struct MHD_Connection *connection)
MHD_RequestTerminationCode
MHD_thread_handle_ID_ pid
int MHD_str_equal_caseless_(const char *str1, const char *str2)
_MHD_static_inline bool socket_start_no_buffering_flush(struct MHD_Connection *connection)
time_t MHD_monotonic_sec_counter(void)
static void transmit_error_response(struct MHD_Connection *connection, unsigned int status_code, const char *message)
MHD_AccessHandlerCallback default_handler
#define MHD_SCKT_ERR_IS_EAGAIN_(err)
static void call_connection_handler(struct MHD_Connection *connection)
uint64_t remaining_upload_size
unsigned int responseCode
#define MHD_ERR_CONNRESET_
Methods for managing response objects.
static void cleanup_connection(struct MHD_Connection *connection)
void MHD_update_last_activity_(struct MHD_Connection *connection)
#define MHD_UNSIGNED_LONG_LONG
void * uri_log_callback_cls
static ssize_t recv_param_adapter(struct MHD_Connection *connection, void *other, size_t i)
struct MHD_Daemon * daemon
int MHD_response_execute_upgrade_(struct MHD_Response *response, struct MHD_Connection *connection)
#define MHD_check_response_header_s_token_ci(r, k, tkn)
#define MHD_SENFILE_CHUNK_THR_P_C_
static bool MHD_lookup_header_token_ci(const struct MHD_Connection *connection, const char *header, const char *token, size_t token_len)
Header for platform-independent inter-thread communication.
static void connection_close_error(struct MHD_Connection *connection, const char *emsg)
void * MHD_pool_reset(struct MemoryPool *pool, void *keep, size_t copy_bytes, size_t new_size)
_MHD_EXTERN const union MHD_ConnectionInfo * MHD_get_connection_info(struct MHD_Connection *connection, enum MHD_ConnectionInfoType info_type,...)
static int keepalive_possible(struct MHD_Connection *connection)
#define DLL_insert(head, tail, element)
void MHD_increment_response_rc(struct MHD_Response *response)
#define MHD_HTTP_URI_TOO_LONG
struct MHD_HTTP_Header * first_header
#define MHD_socket_last_strerr_()
size_t write_buffer_send_offset
struct MHD_Connection * connections_tail
void * MHD_pool_allocate(struct MemoryPool *pool, size_t size, int from_end)
bool sk_tcp_cork_nopush_on
size_t continue_message_write_offset
#define REQUEST_MALFORMED
#define MHD_INVALID_SOCKET
size_t MHD_strx_to_uint64_n_(const char *str, size_t maxlen, uint64_t *out_val)
internal shared structures
enum MHD_HTTP_StatusCode status_code
#define MHD_SCKT_SEND_MAX_SIZE_
void * MHD_pool_reallocate(struct MemoryPool *pool, void *old, size_t old_size, size_t new_size)
struct MHD_Connection * connections_head
_MHD_static_inline bool socket_start_normal_buffering(struct MHD_Connection *connection)
#define MHD_HTTP_NO_CONTENT
LogCallback uri_log_callback
void MHD_connection_handle_read(struct MHD_Connection *connection)
_MHD_EXTERN void MHD_destroy_response(struct MHD_Response *response)
time_t connection_timeout
_MHD_EXTERN int MHD_set_connection_option(struct MHD_Connection *connection, enum MHD_CONNECTION_OPTION option,...)
#define MHD_SCKT_ERR_IS_(err, code)
Methods for managing connections.
#define MHD_CONTENT_READER_END_OF_STREAM
#define EDLL_remove(head, tail, element)
struct MHD_Connection * manual_timeout_tail
static void get_date_string(char *date, size_t date_len)
Header for string manipulating helpers.
#define DLL_remove(head, tail, element)
static int need_100_continue(struct MHD_Connection *connection)
#define MHD_STATICSTR_LEN_(macro)
#define MHD_HTTP_VERSION_1_1
struct MHD_Connection * normal_timeout_head
void MHD_pool_destroy(struct MemoryPool *pool)
#define MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE
UnescapeCallback unescape_callback
static int try_grow_read_buffer(struct MHD_Connection *connection)
_MHD_EXTERN int MHD_queue_response(struct MHD_Connection *connection, unsigned int status_code, struct MHD_Response *response)
void MHD_connection_finish_forward_(struct MHD_Connection *connection) MHD_NONNULL(1)
#define XDLL_remove(head, tail, element)
unsigned int connection_timeout_dummy
#define MHD_HTTP_BAD_REQUEST
_MHD_EXTERN struct MHD_Response * MHD_create_response_from_buffer(size_t size, void *buffer, enum MHD_ResponseMemoryMode mode)
struct MHD_Connection * suspended_connections_tail
static int check_write_done(struct MHD_Connection *connection, enum MHD_CONNECTION_STATE next_state)
bool MHD_run_tls_handshake_(struct MHD_Connection *connection)
struct MHD_Connection * cleanup_tail
int MHD_connection_handle_idle(struct MHD_Connection *connection)
static int process_broken_line(struct MHD_Connection *connection, char *line, enum MHD_ValueKind kind)
enum MHD_ResponseFlags flags
#define MHD_recv_(s, b, l)
#define MHD_HTTP_METHOD_HEAD
static void parse_connection_headers(struct MHD_Connection *connection)
size_t write_buffer_append_offset
struct MHD_Connection * normal_timeout_tail
MHD_RequestCompletedCallback notify_completed
#define MHD_mutex_lock_chk_(pmutex)
void MHD_set_http_callbacks_(struct MHD_Connection *connection)
#define MHD_HTTP_METHOD_PUT
void * notify_completed_cls
static void process_request_body(struct MHD_Connection *connection)
#define MHD_HTTP_VERSION_1_0
TransmitCallback send_cls
_MHD_EXTERN int MHD_get_connection_values(struct MHD_Connection *connection, enum MHD_ValueKind kind, MHD_KeyValueIterator iterator, void *iterator_cls)
#define MHD_HTTP_INTERNAL_SERVER_ERROR
#define MHD_CONTENT_READER_END_WITH_ERROR
MHD_ContentReaderCallback crc
static int parse_initial_message_line(struct MHD_Connection *connection, char *line, size_t line_len)
#define XDLL_insert(head, tail, element)
_MHD_static_inline bool socket_flush_possible(struct MHD_Connection *connection)
#define MHD_UNSIGNED_LONG_LONG_PRINTF
#define MHD_HTTP_PROCESSING
#define MHD_SCKT_ECONNRESET_
struct MHD_Connection * suspended_connections_head
_MHD_static_inline bool socket_start_no_buffering(struct MHD_Connection *connection)
size_t read_buffer_offset
static char * get_next_header_line(struct MHD_Connection *connection, size_t *line_len)
void * default_handler_cls
_MHD_EXTERN const char * MHD_get_response_header(struct MHD_Response *response, const char *key)
#define MHD_SCKT_ERR_IS_EINTR_(err)
MHD_mutex_ cleanup_connection_mutex
#define CONNECTION_CLOSE_ERROR(c, emsg)
uint64_t current_chunk_size
struct MHD_HTTP_Header * headers_received
#define MHD_HTTP_SWITCHING_PROTOCOLS
limits values definitions
_MHD_EXTERN const char * MHD_get_reason_phrase_for(unsigned int code)
_MHD_static_inline bool socket_start_extra_buffering(struct MHD_Connection *connection)
bool MHD_tls_connection_shutdown(struct MHD_Connection *connection)
_MHD_EXTERN int MHD_set_connection_value(struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key, const char *value)
struct MHD_HTTP_Header * headers_received_tail
static int build_header_response(struct MHD_Connection *connection)
#define MHD_HTTP_METHOD_POST