39 #ifdef MHD_LINUX_SOLARIS_SENDFILE 40 #include <sys/sendfile.h> 42 #if defined(HAVE_FREEBSD_SENDFILE) || defined(HAVE_DARWIN_SENDFILE) 43 #include <sys/types.h> 44 #include <sys/socket.h> 55 #define HTTP_100_CONTINUE "HTTP/1.1 100 Continue\r\n\r\n" 65 #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>" 67 #define REQUEST_TOO_BIG "" 78 #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>" 80 #define REQUEST_LACKS_HOST "" 91 #define REQUEST_MALFORMED "<html><head><title>Request malformed</title></head><body>Your HTTP request was syntactically incorrect.</body></html>" 93 #define REQUEST_MALFORMED "" 103 #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>" 105 #define INTERNAL_ERROR "" 112 #define DEBUG_CLOSE MHD_NO 117 #define DEBUG_SEND_DATA MHD_NO 123 #define MHD_SENFILE_CHUNK_ (0x20000) 128 #define MHD_SENFILE_CHUNK_THR_P_C_ (0x200000) 130 #ifdef HAVE_FREEBSD_SENDFILE 135 static int freebsd_sendfile_flags_;
140 static int freebsd_sendfile_flags_thd_p_c_;
146 MHD_conn_init_static_ (
void)
152 long sys_page_size = sysconf (_SC_PAGESIZE);
153 if (0 > sys_page_size)
155 freebsd_sendfile_flags_ = SF_NODISKIO;
156 freebsd_sendfile_flags_thd_p_c_ = SF_NODISKIO;
160 freebsd_sendfile_flags_ =
162 freebsd_sendfile_flags_thd_p_c_ =
214 else if (i > (
size_t)ret)
268 else if (i > (
size_t)ret)
275 #if defined(_MHD_HAVE_SENDFILE) 289 #ifndef HAVE_SENDFILE64 290 const uint64_t max_off_t = (uint64_t)
OFF_T_MAX;
292 const uint64_t max_off_t = (uint64_t)OFF64_T_MAX;
294 #ifdef MHD_LINUX_SOLARIS_SENDFILE 295 #ifndef HAVE_SENDFILE64 301 #ifdef HAVE_FREEBSD_SENDFILE 305 #ifdef HAVE_DARWIN_SENDFILE 310 size_t send_size = 0;
311 mhd_assert (MHD_resp_sender_sendfile == connection->resp_sender);
317 send_size = (left > chunk_size) ? chunk_size : (
size_t) left;
318 if (max_off_t < offsetu64)
320 connection->resp_sender = MHD_resp_sender_std;
323 #ifdef MHD_LINUX_SOLARIS_SENDFILE 324 #ifndef HAVE_SENDFILE64 325 offset = (off_t) offsetu64;
331 offset = (off64_t) offsetu64;
350 #ifdef HAVE_LINUX_SENDFILE 359 connection->resp_sender = MHD_resp_sender_std;
362 if ( (EAFNOSUPPORT == err) ||
364 (EOPNOTSUPP == err) )
366 connection->resp_sender = MHD_resp_sender_std;
369 if ( (ENOTCONN == err) ||
378 else if (send_size > (
size_t)ret)
381 #elif defined(HAVE_FREEBSD_SENDFILE) 383 flags = used_thr_p_c ?
384 freebsd_sendfile_flags_thd_p_c_ : freebsd_sendfile_flags_;
386 if (0 != sendfile (file_fd,
401 return (ssize_t)sent_bytes;
407 connection->resp_sender = MHD_resp_sender_std;
412 ret = (ssize_t)sent_bytes;
413 #elif defined(HAVE_DARWIN_SENDFILE) 414 len = (off_t)send_size;
415 if (0 != sendfile (file_fd,
434 if (ENOTCONN == err ||
437 if (ENOTSUP == err ||
441 connection->resp_sender = MHD_resp_sender_std;
479 #if defined(TCP_CORK) || defined(TCP_PUSH) 499 #if defined(TCP_CORK) || defined(TCP_NOPUSH) 501 #if defined(TCP_NODELAY) 505 #if defined(TCP_NOPUSH) && !defined(TCP_CORK) 507 res = (0 == setsockopt (connection->
socket_fd,
510 (
const void *) &on_val,
513 #if defined(TCP_NODELAY) 516 res &= (0 == setsockopt (connection->
socket_fd,
519 (
const void *) &off_val,
524 #if defined(TCP_NODELAY) 528 (void) setsockopt (connection->
socket_fd,
531 (
const void *) &off_val,
535 res = (0 == setsockopt (connection->
socket_fd,
538 (
const void *) &on_val,
556 #if defined(TCP_NODELAY) 559 #if defined(TCP_CORK) || defined(TCP_NOPUSH) 565 #if defined(TCP_CORK) 567 res &= (0 == setsockopt (connection->
socket_fd,
570 (
const void *) &off_val,
574 #if defined(TCP_NODELAY) 576 res &= (0 == setsockopt (connection->
socket_fd,
579 (
const void *) &on_val,
583 #if defined(TCP_NOPUSH) && !defined(TCP_CORK) 585 res &= (0 == setsockopt (connection->
socket_fd,
588 (
const void *) &off_val,
610 #if defined(TCP_NOPUSH) && !defined(TCP_CORK) 614 if (
NULL == connection)
617 #if defined(TCP_NOPUSH) && !defined(TCP_CORK) 639 #if defined(TCP_NODELAY) 642 #if defined(TCP_CORK) 644 socklen_t param_size =
sizeof (cork_val);
647 #if defined(TCP_CORK) 651 if ( (0 != getsockopt (connection->
socket_fd,
657 res &= (0 == setsockopt (connection->
socket_fd,
660 (
const void *) &off_val,
663 #elif defined(TCP_NOPUSH) 667 res &= (0 == setsockopt (connection->
socket_fd,
670 (
const void *) &off_val,
675 res &= (0 == setsockopt (connection->
socket_fd,
678 (
const void *) &off_val,
708 if (
NULL == connection)
715 if ( (
NULL != iterator) &&
716 (
MHD_YES != iterator (iterator_cls,
764 pos->
header = (
char *) key;
800 if (
NULL == connection)
861 #define MHD_lookup_header_s_token_ci(c,h,tkn) \ 862 MHD_lookup_header_token_ci((c),(h),(tkn),MHD_STATICSTR_LEN_(tkn)) 958 #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 973 struct MHD_UpgradeResponseHandle *urh = connection->urh;
984 (0 != epoll_ctl (daemon->epoll_upgrade_fd,
989 MHD_PANIC (
_(
"Failed to remove FD from epoll set\n"));
991 if (urh->in_eready_list)
994 daemon->eready_urh_tail,
996 urh->in_eready_list =
false;
1003 (0 != epoll_ctl (daemon->epoll_upgrade_fd,
1008 MHD_PANIC (
_(
"Failed to remove FD from epoll set\n"));
1013 shutdown (urh->mhd.socket, SHUT_RDWR);
1035 #ifdef HAVE_MESSAGES 1037 MHD_DLOG (connection->
daemon,
1051 #ifdef HAVE_MESSAGES 1052 #define CONNECTION_CLOSE_ERROR(c, emsg) connection_close_error (c, emsg) 1054 #define CONNECTION_CLOSE_ERROR(c, emsg) connection_close_error (c, NULL) 1087 #if defined(_MHD_HAVE_SENDFILE) 1088 if (MHD_resp_sender_sendfile == connection->resp_sender)
1112 _(
"Closing connection (application reported error generating data)\n"));
1152 2 * (0xFFFFFF +
sizeof(cbuf) + 2));
1161 _(
"Closing connection (out of memory)\n"));
1168 while (
NULL == buf);
1182 const size_t data_write_offset
1185 ret = response->
data_size - data_write_offset;
1189 &response->
data[data_write_offset],
1206 _(
"Closing connection (application error generating response)\n"));
1228 cblen = MHD_snprintf_(cbuf,
1231 (
unsigned int) ret);
1234 memcpy (&connection->
write_buffer[sizeof (cbuf) - cblen],
1237 memcpy (&connection->
write_buffer[sizeof (cbuf) + ret],
1314 static const char *
const days[] = {
1315 "Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat" 1317 static const char *
const mons[] = {
1318 "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
1319 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec" 1323 #if !defined(HAVE_C11_GMTIME_S) && !defined(HAVE_W32_GMTIME_S) && !defined(HAVE_GMTIME_R) 1329 #if defined(HAVE_C11_GMTIME_S) 1330 if (
NULL == gmtime_s (&t,
1333 #elif defined(HAVE_W32_GMTIME_S) 1334 if (0 != gmtime_s (&now,
1337 #elif defined(HAVE_GMTIME_R) 1338 if (
NULL == gmtime_r(&t,
1347 MHD_snprintf_ (date,
1349 "Date: %3s, %02u %3s %04u %02u:%02u:%02u GMT\r\n",
1350 days[now.tm_wday % 7],
1351 (
unsigned int) now.tm_mday,
1352 mons[now.tm_mon % 12],
1353 (
unsigned int) (1900 + now.tm_year),
1354 (
unsigned int) now.tm_hour,
1355 (
unsigned int) now.tm_min,
1356 (
unsigned int) now.tm_sec);
1410 char content_length_buf[128];
1411 size_t content_length_len;
1414 const char *reason_phrase;
1416 bool client_requested_close;
1417 bool response_has_close;
1418 bool response_has_keepalive;
1419 const char *have_encoding;
1420 const char *have_content_length;
1422 int must_add_chunked_encoding;
1423 int must_add_keep_alive;
1424 int must_add_content_length;
1427 if (0 == connection->
version[0])
1442 MHD_snprintf_ (code,
1453 off = strlen (code);
1464 size += strlen (date);
1477 must_add_chunked_encoding =
MHD_NO;
1478 must_add_keep_alive =
MHD_NO;
1479 must_add_content_length =
MHD_NO;
1480 response_has_close =
false;
1481 response_has_keepalive =
false;
1482 switch (connection->
state)
1497 #ifdef UPGRADE_SUPPORT 1498 else if (
NULL != connection->
response->upgrade_handler)
1507 #ifdef UPGRADE_SUPPORT
1510 (! response_has_close) &&
1511 (! client_requested_close) )
1524 if (
NULL == have_encoding)
1526 must_add_chunked_encoding =
MHD_YES;
1544 if (! response_has_close)
1550 if ( ( (client_requested_close) ||
1553 (! response_has_close) &&
1554 #ifdef UPGRADE_SUPPORT
1571 (
NULL == have_content_length) &&
1592 = MHD_snprintf_ (content_length_buf,
1593 sizeof (content_length_buf),
1596 must_add_content_length =
MHD_YES;
1600 if ( (! response_has_keepalive) &&
1601 (! response_has_close) &&
1602 (
MHD_NO == must_add_close) &&
1604 #ifdef UPGRADE_SUPPORT
1608 must_add_keep_alive =
MHD_YES;
1611 response_has_keepalive =
false;
1619 if ( (must_add_close) || (response_has_close) )
1621 else if ( (must_add_keep_alive) || (response_has_keepalive) )
1627 if (must_add_keep_alive)
1629 if (must_add_chunked_encoding)
1631 if (must_add_content_length)
1632 size += content_length_len;
1633 mhd_assert (! (must_add_close && must_add_keep_alive) );
1634 mhd_assert (! (must_add_chunked_encoding && must_add_content_length) );
1640 (! ( (
MHD_YES == must_add_close) &&
1641 (response_has_keepalive) &&
1645 "Keep-Alive")) ) ) )
1646 size += strlen (pos->
header) + strlen (pos->
value) + 4;
1654 #ifdef HAVE_MESSAGES 1655 MHD_DLOG (connection->
daemon,
1656 "Not enough memory for write!\n");
1670 "Connection: close\r\n",
1674 if (must_add_keep_alive)
1678 "Connection: Keep-Alive\r\n",
1682 if (must_add_chunked_encoding)
1686 "Transfer-Encoding: chunked\r\n",
1690 if (must_add_content_length)
1695 content_length_len);
1696 off += content_length_len;
1702 (! ( (
MHD_YES == must_add_close) &&
1703 (response_has_keepalive) &&
1707 "Keep-Alive")) ) ) )
1708 off += MHD_snprintf_ (&
data[off],
1718 off += strlen (date);
1749 unsigned int status_code,
1750 const char *message)
1762 #ifdef HAVE_MESSAGES 1763 MHD_DLOG (connection->
daemon,
1764 _(
"Error processing request (HTTP response code is %u (`%s')). Closing connection.\n"),
1787 _(
"Closing connection (failed to create response header)\n"));
1810 #ifdef HTTPS_SUPPORT 1813 switch (connection->tls_state)
1819 if (0 == gnutls_record_get_direction (connection->tls_session))
1832 MHD_DLOG (connection->
daemon,
1833 _(
"In function %s handling connection at state: %s\n"),
1835 MHD_state_to_string (connection->
state));
1837 switch (connection->
state)
1949 #ifdef UPGRADE_SUPPORT 1950 case MHD_CONNECTION_UPGRADE:
1986 while ( (pos < connection->read_buffer_offset - 1) &&
1987 (
'\r' != rbuf[pos]) &&
1988 (
'\n' != rbuf[pos]) )
1991 (
'\n' != rbuf[pos]) )
2012 if ( (
'\r' == rbuf[pos]) &&
2013 (
'\n' == rbuf[pos + 1]) )
2046 #ifdef HAVE_MESSAGES 2047 MHD_DLOG (connection->
daemon,
2048 _(
"Not enough memory in pool to allocate header record!\n"));
2088 #ifdef HAVE_MESSAGES 2089 MHD_DLOG (connection->
daemon,
2090 _(
"Not enough memory in pool to parse cookies!\n"));
2107 while ( ((*sce) !=
'\0') &&
2114 while ( (*ekill ==
' ') &&
2136 while ( (
'\0' != semicolon[0]) &&
2138 ( (
';' != semicolon[0]) &&
2139 (
',' != semicolon[0]) ) ) )
2141 if (
'"' == semicolon[0])
2142 quotes = (quotes + 1) & 1;
2145 if (
'\0' == semicolon[0])
2147 if (
NULL != semicolon)
2149 semicolon[0] =
'\0';
2153 if ( (
'"' == equals[0]) &&
2154 (
'"' == equals[strlen (equals) - 1]) )
2156 equals[strlen (equals) - 1] =
'\0';
2189 unsigned int unused_num_headers;
2191 if (
NULL == (uri = memchr (line,
2196 connection->
method = line;
2200 while ( (
' ' == uri[0]) &&
2201 ( (
size_t)(uri - line) < line_len) )
2203 if ((
size_t)(uri - line) == line_len)
2214 http_version = line + line_len - 1;
2216 while ( (
' ' == http_version[0]) &&
2217 (http_version > uri) )
2220 while ( (
' ' != http_version[0]) &&
2221 (http_version > uri) )
2223 if (http_version > uri)
2225 http_version[0] =
'\0';
2226 connection->
version = http_version + 1;
2229 http_version - uri);
2236 line_len - (uri - line));
2256 &unused_num_headers);
2262 connection->
url = curi;
2295 _(
"Application reported internal error, closing connection.\n"));
2323 size_t to_be_processed;
2324 size_t left_unprocessed;
2325 size_t processed_size;
2338 if ( (
'\r' == buffer_head[i]) ||
2339 (
'\n' == buffer_head[i]) )
2341 if ( (
'\r' == buffer_head[i]) ||
2342 (
'\n' == buffer_head[i]) )
2348 _(
"Received malformed HTTP request (bad chunked encoding). Closing connection.\n"));
2359 uint64_t cur_chunk_left;
2365 if (cur_chunk_left > available)
2366 to_be_processed = available;
2369 to_be_processed = (size_t)cur_chunk_left;
2370 if (available > to_be_processed)
2382 while (i < available)
2384 if ( (
'\r' == buffer_head[i]) ||
2385 (
'\n' == buffer_head[i]) ||
2386 (
';' == buffer_head[i]) )
2394 if (
';' == buffer_head[i])
2396 while (i < available)
2398 if ( (
'\r' == buffer_head[i]) ||
2399 (
'\n' == buffer_head[i]) )
2407 if ( (i + 1 >= available) &&
2410 (
'0' == buffer_head[0]) ) )
2413 malformed = (end_size >= 16);
2419 malformed = (end_size != num_dig);
2425 _(
"Received malformed HTTP request (bad chunked encoding). Closing connection.\n"));
2429 if ( (i < available) &&
2430 ( (
'\r' == buffer_head[i]) ||
2431 (
'\n' == buffer_head[i]) ) )
2463 to_be_processed = available;
2466 left_unprocessed = to_be_processed;
2480 _(
"Application reported internal error, closing connection.\n"));
2483 if (left_unprocessed > to_be_processed)
2487 #ifdef HAVE_MESSAGES
2488 ,
_(
"libmicrohttpd API violation")
2493 if (0 != left_unprocessed)
2496 #ifdef HAVE_MESSAGES 2502 MHD_DLOG (connection->
daemon,
2503 _(
"WARNING: incomplete upload processing and connection not suspended may result in hung connection.\n"));
2506 processed_size = to_be_processed - left_unprocessed;
2510 buffer_head += processed_size;
2511 available -= processed_size;
2515 while (
MHD_YES == instant_retry);
2541 connection->
state = next_state;
2568 colon = strchr (line,
':');
2573 _(
"Received malformed line (no colon). Closing connection.\n"));
2583 white = strchr (line,
' ');
2584 if ( (
NULL != white) &&
2587 white = strchr (line,
'\t');
2588 if ( (
NULL != white) &&
2595 while ( (
'\0' != colon[0]) &&
2596 ( (
' ' == colon[0]) ||
2597 (
'\t' == colon[0]) ) )
2604 connection->
last = line;
2605 connection->
colon = colon;
2630 last = connection->
last;
2631 if ( (
' ' == line[0]) ||
2636 last_len = strlen (last);
2639 while ( (
' ' == tmp[0]) ||
2642 tmp_len = strlen (tmp);
2655 last_len + tmp_len + 1);
2663 memcpy (&last[last_len], tmp, tmp_len + 1);
2664 connection->
last = last;
2723 #ifdef HAVE_MESSAGES 2724 MHD_DLOG (connection->
daemon,
2725 _(
"Received HTTP 1.1 request without `Host' header.\n"));
2759 if ( (clen == end) ||
2763 #ifdef HAVE_MESSAGES 2764 MHD_DLOG (connection->
daemon,
2765 "Failed to parse `Content-Length' header. Closing connection.\n");
2827 #ifdef HTTPS_SUPPORT 2846 bytes_read = connection->
recv_cls (connection,
2860 _(
"Socket disconnected while reading request.\n"));
2866 _(
"Connection socket is closed due to error when reading request.\n"));
2870 if (0 == bytes_read)
2880 MHD_DLOG (connection->
daemon,
2881 _(
"In function %s handling connection at state: %s\n"),
2883 MHD_state_to_string (connection->
state));
2885 switch (connection->
state)
2905 #ifdef UPGRADE_SUPPORT 2906 case MHD_CONNECTION_UPGRADE:
2936 #ifdef HTTPS_SUPPORT 2948 MHD_DLOG (connection->
daemon,
2949 _(
"In function %s handling connection at state: %s\n"),
2951 MHD_state_to_string (connection->
state));
2953 switch (connection->
state)
2964 ret = connection->
send_cls (connection,
2973 #ifdef HAVE_MESSAGES 2974 MHD_DLOG (connection->
daemon,
2975 _(
"Failed to send data in request for %s.\n"),
2984 _(
"Sent 100 continue response: `%.*s'\n"),
2998 ret = connection->
send_cls (connection,
3008 _(
"Connection was closed while sending response headers.\n"));
3025 uint64_t data_write_offset;
3034 #if defined(_MHD_HAVE_SENDFILE) 3035 if (MHD_resp_sender_sendfile == connection->resp_sender)
3037 ret = sendfile_adapter (connection);
3046 if (data_write_offset > (uint64_t)
SIZE_MAX)
3048 ret = connection->
send_cls (connection,
3050 [(
size_t)data_write_offset],
3052 (
size_t)data_write_offset);
3056 _(
"Sent %d-byte DATA response: `%.*s'\n"),
3069 #ifdef HAVE_MESSAGES 3070 MHD_DLOG (connection->
daemon,
3071 _(
"Failed to send data in request for `%s'.\n"),
3089 ret = connection->
send_cls (connection,
3099 _(
"Connection was closed while sending response body.\n"));
3117 ret = connection->
send_cls (connection,
3127 _(
"Connection was closed while sending response body.\n"));
3145 #ifdef UPGRADE_SUPPORT 3146 case MHD_CONNECTION_UPGRADE:
3153 _(
"Internal error\n"));
3217 if ( (MHD_ITC_IS_VALID_ (daemon->
itc)) &&
3218 (! MHD_itc_activate_ (daemon->
itc,
"c")) )
3220 #ifdef HAVE_MESSAGES 3222 _(
"Failed to signal end of connection via inter-thread communication channel"));
3250 #ifdef HTTPS_SUPPORT 3253 if ((MHD_TLS_CONN_INIT <= connection->tls_state) &&
3260 _(
"In function %s handling connection at state: %s\n"),
3262 MHD_state_to_string (connection->
state));
3264 switch (connection->
state)
3273 if ( (
NULL == line) ||
3495 _(
"Closing connection (failed to create response header)\n"));
3513 #ifdef UPGRADE_SUPPORT 3517 connection->
state = MHD_CONNECTION_UPGRADE;
3606 _(
"Closing connection (failed to create response header)\n"));
3699 #ifdef UPGRADE_SUPPORT 3700 case MHD_CONNECTION_UPGRADE:
3714 if ( (0 != timeout) &&
3725 #ifdef EPOLL_SUPPORT 3729 ret = MHD_connection_epoll_update_ (connection);
3737 #ifdef EPOLL_SUPPORT 3760 struct epoll_event event;
3762 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET;
3763 event.data.ptr = connection;
3764 if (0 != epoll_ctl (daemon->epoll_fd,
3769 #ifdef HAVE_MESSAGES 3772 _(
"Call to epoll_ctl failed: %s\n"),
3816 #ifdef HTTPS_SUPPORT 3818 if (
NULL == connection->tls_session)
3820 connection->cipher = gnutls_cipher_get (connection->tls_session);
3823 if (
NULL == connection->tls_session)
3825 connection->protocol = gnutls_protocol_get_version (connection->tls_session);
3828 if (
NULL == connection->tls_session)
3875 daemon = connection->
daemon;
3895 va_start (ap, option);
3932 unsigned int status_code,
3937 if ( (
NULL == connection) ||
3938 (
NULL == response) ||
3943 daemon = connection->
daemon;
3951 (!MHD_thread_ID_match_current_(connection->
pid.ID)) )
3953 #ifdef HAVE_MESSAGES 3955 _(
"Attempted to queue response on wrong thread!\n"));
3959 #ifdef UPGRADE_SUPPORT 3960 if ( (
NULL != response->upgrade_handler) &&
3963 #ifdef HAVE_MESSAGES 3965 _(
"Attempted 'upgrade' connection on daemon without MHD_ALLOW_UPGRADE option!\n"));
3970 (
NULL != response->upgrade_handler) )
3972 #ifdef HAVE_MESSAGES 3974 _(
"Application used invalid status code for 'upgrade' response!\n"));
3982 #if defined(_MHD_HAVE_SENDFILE) 3983 if ( (response->
fd == -1) ||
3985 connection->resp_sender = MHD_resp_sender_std;
3987 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)
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
#define MHD_send_(s, b, l)
void MHD_connection_handle_write(struct MHD_Connection *connection)
static int try_ready_normal_body(struct MHD_Connection *connection)
uint64_t current_chunk_offset
#define DLL_insert(head, tail, element)
_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)
enum MHD_CONNECTION_STATE state
static int try_ready_chunked_body(struct MHD_Connection *connection)
void * MHD_pool_reset(struct MemoryPool *pool, void *keep, size_t copy_bytes, size_t new_size)
#define MHD_lookup_header_s_token_ci(c, h, tkn)
uint64_t response_write_position
enum MHD_ConnKeepAlive keepalive
void MHD_pool_destroy(struct MemoryPool *pool)
#define HTTP_100_CONTINUE
#define MHD_SCKT_SEND_MAX_SIZE_
enum MHD_ConnectionEventLoopInfo event_loop_info
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.
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_socket_get_error_()
struct MHD_Connection * normal_timeout_tail
Header for platform missing functions.
#define MHD_HTTP_NOT_MODIFIED
void MHD_connection_mark_closed_(struct MHD_Connection *connection)
MHD_RequestTerminationCode
MHD_thread_handle_ID_ pid
struct MHD_HTTP_Header * first_header
static void transmit_error_response(struct MHD_Connection *connection, unsigned int status_code, const char *message)
MHD_AccessHandlerCallback default_handler
void * MHD_pool_allocate(struct MemoryPool *pool, size_t size, int from_end)
static void call_connection_handler(struct MHD_Connection *connection)
uint64_t remaining_upload_size
#define MHD_SCKT_ERR_IS_(err, code)
unsigned int responseCode
int MHD_parse_arguments_(struct MHD_Connection *connection, enum MHD_ValueKind kind, char *args, MHD_ArgumentIterator_ cb, unsigned int *num_headers)
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)
int MHD_response_execute_upgrade_(struct MHD_Response *response, struct MHD_Connection *connection)
struct MHD_Daemon * daemon
struct MHD_Connection * manual_timeout_head
#define MHD_SENFILE_CHUNK_THR_P_C_
struct MHD_Connection * cleanup_head
static bool MHD_lookup_header_token_ci(const struct MHD_Connection *connection, const char *header, const char *token, size_t token_len)
static void connection_close_error(struct MHD_Connection *connection, const char *emsg)
#define XDLL_remove(head, tail, element)
#define MHD_mutex_unlock_chk_(pmutex)
#define XDLL_insert(head, tail, element)
_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 MHD_HTTP_URI_TOO_LONG
struct MHD_Connection * cleanup_tail
Header for platform-independent inter-thread communication.
#define MHD_STATICSTR_LEN_(macro)
size_t write_buffer_send_offset
void * MHD_pool_reallocate(struct MemoryPool *pool, void *old, size_t old_size, size_t new_size)
struct MHD_Connection * manual_timeout_tail
size_t continue_message_write_offset
#define REQUEST_MALFORMED
#define MHD_INVALID_SOCKET
#define MHD_recv_(s, b, l)
#define MHD_SCKT_ERR_IS_EAGAIN_(err)
#define MHD_HTTP_NO_CONTENT
LogCallback uri_log_callback
static int socket_start_no_buffering(struct MHD_Connection *connection)
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,...)
void MHD_increment_response_rc(struct MHD_Response *response)
Methods for managing connections.
#define MHD_CONTENT_READER_END_OF_STREAM
struct MHD_Connection * normal_timeout_head
static void get_date_string(char *date, size_t date_len)
#define MHD_ERR_CONNRESET_
static int need_100_continue(struct MHD_Connection *connection)
limits values definitions
#define MHD_HTTP_VERSION_1_1
internal shared structures
#define MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE
UnescapeCallback unescape_callback
#define MHD_socket_last_strerr_()
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)
internal monotonic clock functions implementations
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 * connections_head
static int check_write_done(struct MHD_Connection *connection, enum MHD_CONNECTION_STATE next_state)
bool MHD_run_tls_handshake_(struct MHD_Connection *connection)
int MHD_connection_handle_idle(struct MHD_Connection *connection)
static int process_broken_line(struct MHD_Connection *connection, char *line, enum MHD_ValueKind kind)
#define MHD_check_response_header_s_token_ci(r, k, tkn)
enum MHD_ResponseFlags flags
#define MHD_connection_finish_forward_(conn)
#define MHD_HTTP_METHOD_HEAD
static void parse_connection_headers(struct MHD_Connection *connection)
time_t MHD_monotonic_sec_counter(void)
Header for string manipulating helpers.
size_t write_buffer_append_offset
MHD_RequestCompletedCallback notify_completed
bool MHD_str_has_token_caseless_(const char *str, const char *const token, size_t token_len)
static int socket_start_extra_buffering(struct MHD_Connection *connection)
void MHD_set_http_callbacks_(struct MHD_Connection *connection)
#define MHD_HTTP_METHOD_PUT
int MHD_str_equal_caseless_(const char *str1, const char *str2)
#define DLL_remove(head, tail, element)
void * notify_completed_cls
static void process_request_body(struct MHD_Connection *connection)
#define MHD_HTTP_VERSION_1_0
TransmitCallback send_cls
#define EDLL_remove(head, tail, element)
_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)
MHD_PanicCallback mhd_panic
struct MHD_Connection * suspended_connections_tail
static int socket_start_normal_buffering(struct MHD_Connection *connection)
#define MHD_UNSIGNED_LONG_LONG_PRINTF
#define MHD_HTTP_PROCESSING
static int socket_flush_possible(struct MHD_Connection *connection)
static int socket_start_no_buffering_flush(struct MHD_Connection *connection)
#define MHD_SCKT_ECONNRESET_
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)
size_t MHD_strx_to_uint64_n_(const char *str, size_t maxlen, uint64_t *out_val)
#define MHD_SCKT_ERR_IS_EINTR_(err)
MHD_mutex_ cleanup_connection_mutex
#define CONNECTION_CLOSE_ERROR(c, emsg)
uint64_t current_chunk_size
Header for platform-independent locks abstraction.
struct MHD_HTTP_Header * headers_received
#define MHD_HTTP_SWITCHING_PROTOCOLS
struct MHD_Connection * connections_tail
_MHD_EXTERN const char * MHD_get_reason_phrase_for(unsigned int code)
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_mutex_lock_chk_(pmutex)
#define MHD_HTTP_METHOD_POST
size_t MHD_str_to_uint64_(const char *str, uint64_t *out_val)
struct MHD_Connection * suspended_connections_head
memory pool; mostly used for efficient (de)allocation for each connection and bounding memory use for...