34 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
35 #include "mhd_locks.h"
40 #ifdef MHD_LINUX_SOLARIS_SENDFILE
41 #include <sys/sendfile.h>
43 #if defined(HAVE_FREEBSD_SENDFILE) || defined(HAVE_DARWIN_SENDFILE)
44 #include <sys/types.h>
45 #include <sys/socket.h>
51 #ifdef HAVE_SYS_PARAM_H
53 #include <sys/param.h>
60 #define HTTP_100_CONTINUE "HTTP/1.1 100 Continue\r\n\r\n"
70 #define REQUEST_TOO_BIG \
71 "<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 \
85 "<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>"
87 #define REQUEST_LACKS_HOST ""
98 #define REQUEST_MALFORMED \
99 "<html><head><title>Request malformed</title></head><body>Your HTTP request was syntactically incorrect.</body></html>"
101 #define REQUEST_MALFORMED ""
111 #define INTERNAL_ERROR \
112 "<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>"
114 #define INTERNAL_ERROR ""
121 #define MHD_SENFILE_CHUNK_ (0x20000)
126 #define MHD_SENFILE_CHUNK_THR_P_C_ (0x200000)
174 else if (i > (
size_t) ret)
202 if (
NULL == connection)
209 if ( (
NULL != iterator) &&
210 (
MHD_NO == iterator (iterator_cls,
241 if (
NULL == connection)
245 if (
NULL == iterator)
256 if (
MHD_NO == iterator (iterator_cls,
300 pos->
header = (
char *) key;
355 ( ((key ? strlen (key) : 0) != key_size) ||
433 (
NULL == key) ? 0 : strlen (key),
464 const char **value_ptr,
465 size_t *value_size_ptr)
469 if (
NULL == connection)
498 if (
NULL != value_ptr)
499 *value_ptr = pos->
value;
501 if (
NULL != value_size_ptr)
566 #define MHD_lookup_header_s_token_ci(c,h,tkn) \
567 MHD_lookup_header_token_ci ((c),(h),MHD_STATICSTR_LEN_ (h), \
568 (tkn),MHD_STATICSTR_LEN_ (tkn))
649 #ifdef MHD_USE_THREADS
651 MHD_thread_ID_match_current_ (connection->
pid) );
670 #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
685 struct MHD_UpgradeResponseHandle *urh = connection->urh;
687 #ifdef MHD_USE_THREADS
690 MHD_thread_ID_match_current_ (daemon->
pid) );
702 (0 != epoll_ctl (daemon->epoll_upgrade_fd,
707 MHD_PANIC (
_ (
"Failed to remove FD from epoll set.\n"));
709 if (urh->in_eready_list)
712 daemon->eready_urh_tail,
714 urh->in_eready_list =
false;
721 (0 != epoll_ctl (daemon->epoll_upgrade_fd,
726 MHD_PANIC (
_ (
"Failed to remove FD from epoll set.\n"));
731 shutdown (urh->mhd.socket, SHUT_RDWR);
757 MHD_DLOG (connection->
daemon,
772 #define CONNECTION_CLOSE_ERROR(c, emsg) connection_close_error (c, emsg)
774 #define CONNECTION_CLOSE_ERROR(c, emsg) connection_close_error (c, NULL)
807 #if defined(_MHD_HAVE_SENDFILE)
808 if (MHD_resp_sender_sendfile == connection->resp_sender)
826 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
835 "Closing connection (application reported error generating data).\n"));
843 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
879 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
884 _ (
"Closing connection (out of memory).\n"));
887 if ( (2 * (0xFFFFFF +
sizeof(cbuf) + 2)) < size)
888 size = 2 * (0xFFFFFF +
sizeof(cbuf) + 2);
905 const size_t data_write_offset
908 ret = response->
data_size - data_write_offset;
912 &response->
data[data_write_offset],
927 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
932 "Closing connection (application error generating response).\n"));
950 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
957 cblen = MHD_snprintf_ (cbuf,
963 memcpy (&connection->
write_buffer[sizeof (cbuf) - cblen],
1046 static const char *
const days[] = {
1047 "Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat"
1049 static const char *
const mons[] = {
1050 "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
1051 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
1055 #if ! defined(HAVE_C11_GMTIME_S) && ! defined(HAVE_W32_GMTIME_S) && \
1056 ! defined(HAVE_GMTIME_R)
1062 #if defined(HAVE_C11_GMTIME_S)
1063 if (
NULL == gmtime_s (&t,
1066 #elif defined(HAVE_W32_GMTIME_S)
1067 if (0 != gmtime_s (&now,
1070 #elif defined(HAVE_GMTIME_R)
1071 if (
NULL == gmtime_r (&t,
1080 MHD_snprintf_ (date,
1082 "Date: %3s, %02u %3s %04u %02u:%02u:%02u GMT\r\n",
1083 days[now.tm_wday % 7],
1084 (
unsigned int) now.tm_mday,
1085 mons[now.tm_mon % 12],
1086 (
unsigned int) (1900 + now.tm_year),
1087 (
unsigned int) now.tm_hour,
1088 (
unsigned int) now.tm_min,
1089 (
unsigned int) now.tm_sec);
1114 if (0 == avail_size)
1117 new_size = avail_size / 2;
1122 grow_size = avail_size / 8;
1131 if (small_inc < avail_size)
1132 grow_size = small_inc;
1134 grow_size = avail_size;
1181 char content_length_buf[128];
1182 size_t content_length_len;
1185 const char *reason_phrase;
1187 bool client_requested_close;
1188 bool response_has_close;
1189 bool response_has_keepalive;
1190 const char *have_encoding;
1191 bool must_add_close;
1192 bool must_add_chunked_encoding;
1193 bool must_add_keep_alive;
1194 bool must_add_content_length;
1195 bool may_add_content_length;
1198 if (0 == connection->
version[0])
1213 off = MHD_snprintf_ (code,
1237 datelen = strlen (date);
1251 must_add_close =
false;
1252 must_add_chunked_encoding =
false;
1253 must_add_keep_alive =
false;
1254 must_add_content_length =
false;
1255 response_has_close =
false;
1256 switch (connection->
state)
1271 #ifdef UPGRADE_SUPPORT
1272 else if (
NULL != response->upgrade_handler)
1281 if (
NULL == have_encoding)
1282 may_add_content_length =
true;
1284 may_add_content_length =
false;
1286 #ifdef UPGRADE_SUPPORT
1287 (
NULL == response->upgrade_handler) &&
1289 (! response_has_close) &&
1290 (! client_requested_close) )
1301 if (
NULL == have_encoding)
1303 must_add_chunked_encoding =
true;
1312 must_add_close =
true;
1325 must_add_close =
true;
1330 if ( ( (client_requested_close) ||
1333 (! response_has_close) &&
1334 #ifdef UPGRADE_SUPPORT
1335 (
NULL == response->upgrade_handler) &&
1338 must_add_close =
true;
1342 if ( (! may_add_content_length) &&
1344 (! response_has_close) )
1345 must_add_close =
true;
1358 (may_add_content_length) &&
1379 = MHD_snprintf_ (content_length_buf,
1380 sizeof (content_length_buf),
1384 must_add_content_length =
true;
1388 if ( (! response_has_keepalive) &&
1389 (! response_has_close) &&
1390 (! must_add_close) &&
1392 #ifdef UPGRADE_SUPPORT
1393 (
NULL == response->upgrade_handler) &&
1396 must_add_keep_alive =
true;
1399 response_has_keepalive =
false;
1408 if ( (must_add_close) || (response_has_close) )
1410 else if ( (must_add_keep_alive) || (response_has_keepalive) )
1416 if (must_add_keep_alive)
1418 if (must_add_chunked_encoding)
1420 if (must_add_content_length)
1421 size += content_length_len;
1422 mhd_assert (! (must_add_close && must_add_keep_alive) );
1423 mhd_assert (! (must_add_chunked_encoding && must_add_content_length) );
1429 (! ( (must_add_close) &&
1430 (response_has_keepalive) &&
1438 "Keep-Alive")) ) ) )
1447 #ifdef HAVE_MESSAGES
1448 MHD_DLOG (connection->
daemon,
1449 "Not enough memory for write!\n");
1463 "Connection: close\r\n",
1467 if (must_add_keep_alive)
1471 "Connection: Keep-Alive\r\n",
1475 if (must_add_chunked_encoding)
1479 "Transfer-Encoding: chunked\r\n",
1483 if (must_add_content_length)
1488 content_length_len);
1489 off += content_length_len;
1495 (! ( (must_add_close) &&
1496 (response_has_keepalive) &&
1504 "Keep-Alive")) ) ) )
1505 off += MHD_snprintf_ (&
data[off],
1547 unsigned int status_code,
1548 const char *message)
1571 #ifdef HAVE_MESSAGES
1572 MHD_DLOG (connection->
daemon,
1574 "Error processing request (HTTP response code is %u (`%s')). Closing connection.\n"),
1586 if (
NULL == response)
1601 "Closing connection (failed to queue response).\n"));
1612 "Closing connection (failed to create response header).\n"));
1635 #ifdef HTTPS_SUPPORT
1638 switch (connection->tls_state)
1644 if (0 == gnutls_record_get_direction (connection->tls_session))
1657 MHD_DLOG (connection->
daemon,
1658 _ (
"In function %s handling connection at state: %s\n"),
1660 MHD_state_to_string (connection->
state));
1662 switch (connection->
state)
1696 const bool internal_poll = (0 != (connection->
daemon->
options
1772 #ifdef UPGRADE_SUPPORT
1773 case MHD_CONNECTION_UPGRADE:
1809 while ( (pos < connection->read_buffer_offset - 1) &&
1810 (
'\r' != rbuf[pos]) &&
1811 (
'\n' != rbuf[pos]) )
1814 (
'\n' != rbuf[pos]) )
1834 if ( (
'\r' == rbuf[pos]) &&
1835 (
'\n' == rbuf[pos + 1]) )
1874 #ifdef HAVE_MESSAGES
1875 MHD_DLOG (connection->
daemon,
1876 _ (
"Not enough memory in pool to allocate header record!\n"));
1921 #ifdef HAVE_MESSAGES
1922 MHD_DLOG (connection->
daemon,
1923 _ (
"Not enough memory in pool to parse cookies!\n"));
1933 cpy[hdr_len] =
'\0';
1941 while ( ((*sce) !=
'\0') &&
1948 while ( (*ekill ==
' ') &&
1972 while ( (
'\0' != semicolon[0]) &&
1974 ( (
';' != semicolon[0]) &&
1975 (
',' != semicolon[0]) ) ) )
1977 if (
'"' == semicolon[0])
1978 quotes = (quotes + 1) & 1;
1982 if (
'\0' == semicolon[0])
1984 if (
NULL != semicolon)
1986 semicolon[0] =
'\0';
1990 if ( (
'"' == equals[0]) &&
2029 unsigned int unused_num_headers;
2031 if (
NULL == (uri = memchr (line,
2036 connection->
method = line;
2040 while ( (
' ' == uri[0]) &&
2041 ( (
size_t) (uri - line) < line_len) )
2043 if ((
size_t) (uri - line) == line_len)
2056 http_version = line + line_len - 1;
2058 while ( (
' ' == http_version[0]) &&
2059 (http_version > uri) )
2062 while ( (
' ' != http_version[0]) &&
2063 (http_version > uri) )
2065 if (http_version > uri)
2068 http_version[0] =
'\0';
2069 connection->
version = http_version + 1;
2070 uri_len = http_version - uri;
2075 uri_len = line_len - (uri - line);
2079 (
NULL != memchr (uri,
2111 &unused_num_headers);
2119 connection->
url = curi;
2154 "Application reported internal error, closing connection.\n"));
2196 size_t to_be_processed;
2197 size_t left_unprocessed;
2198 size_t processed_size;
2212 if ( (
'\r' == buffer_head[i]) ||
2213 (
'\n' == buffer_head[i]) )
2215 if ( (
'\r' == buffer_head[i]) ||
2216 (
'\n' == buffer_head[i]) )
2223 "Received malformed HTTP request (bad chunked encoding). Closing connection.\n"));
2234 uint64_t cur_chunk_left;
2240 if (cur_chunk_left > available)
2241 to_be_processed = available;
2244 to_be_processed = (size_t) cur_chunk_left;
2245 if (available > to_be_processed)
2257 while (i < available)
2259 if ( (
'\r' == buffer_head[i]) ||
2260 (
'\n' == buffer_head[i]) ||
2261 (
';' == buffer_head[i]) )
2269 if (
';' == buffer_head[i])
2271 while (i < available)
2273 if ( (
'\r' == buffer_head[i]) ||
2274 (
'\n' == buffer_head[i]) )
2282 if ( (i + 1 >= available) &&
2285 (
'0' == buffer_head[0]) ) )
2288 malformed = (end_size >= 16);
2294 current_chunk_size);
2295 malformed = (end_size != num_dig);
2302 "Received malformed HTTP request (bad chunked encoding). Closing connection.\n"));
2306 if ( (i < available) &&
2307 ( (
'\r' == buffer_head[i]) ||
2308 (
'\n' == buffer_head[i]) ) )
2340 to_be_processed = available;
2343 left_unprocessed = to_be_processed;
2358 "Application reported internal error, closing connection.\n"));
2361 if (left_unprocessed > to_be_processed)
2365 #ifdef HAVE_MESSAGES
2366 ,
_ (
"libmicrohttpd API violation.\n")
2371 if (0 != left_unprocessed)
2374 #ifdef HAVE_MESSAGES
2382 "WARNING: incomplete upload processing and connection not suspended may result in hung connection.\n"));
2385 processed_size = to_be_processed - left_unprocessed;
2389 buffer_head += processed_size;
2390 available -= processed_size;
2394 while (
MHD_NO != instant_retry);
2395 if ( (available > 0) &&
2423 connection->
state = next_state;
2450 colon = strchr (line,
':');
2456 "Received malformed line (no colon). Closing connection.\n"));
2466 white = strchr (line,
' ');
2467 if ( (
NULL != white) &&
2470 white = strchr (line,
'\t');
2471 if ( (
NULL != white) &&
2478 while ( (
'\0' != colon[0]) &&
2479 ( (
' ' == colon[0]) ||
2480 (
'\t' == colon[0]) ) )
2487 connection->
last = line;
2488 connection->
colon = colon;
2513 last = connection->
last;
2514 if ( (
' ' == line[0]) ||
2519 last_len = strlen (last);
2522 while ( (
' ' == tmp[0]) ||
2525 tmp_len = strlen (tmp);
2538 last_len + tmp_len + 1);
2546 memcpy (&last[last_len],
2549 connection->
last = last;
2559 strlen (connection->
colon),
2617 #ifdef HAVE_MESSAGES
2618 MHD_DLOG (connection->
daemon,
2619 _ (
"Received HTTP 1.1 request without `Host' header.\n"));
2626 if (
NULL == response)
2631 "Closing connection (failed to create response).\n"));
2643 "Closing connection (failed to queue response).\n"));
2674 if ( (clen == end) ||
2678 #ifdef HAVE_MESSAGES
2679 MHD_DLOG (connection->
daemon,
2680 "Failed to parse `Content-Length' header. Closing connection.\n");
2715 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2725 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2745 #ifdef HTTPS_SUPPORT
2766 bytes_read = connection->
recv_cls (connection,
2781 "Socket disconnected while reading request.\n"));
2788 "Connection socket is closed due to error when reading request.\n"));
2792 if (0 == bytes_read)
2802 MHD_DLOG (connection->
daemon,
2803 _ (
"In function %s handling connection at state: %s\n"),
2805 MHD_state_to_string (connection->
state));
2807 switch (connection->
state)
2827 #ifdef UPGRADE_SUPPORT
2828 case MHD_CONNECTION_UPGRADE:
2858 #ifdef HTTPS_SUPPORT
2870 MHD_DLOG (connection->
daemon,
2871 _ (
"In function %s handling connection at state: %s\n"),
2873 MHD_state_to_string (connection->
state));
2875 switch (connection->
state)
2896 #ifdef HAVE_MESSAGES
2897 MHD_DLOG (connection->
daemon,
2898 _ (
"Failed to send data in request for %s.\n"),
2905 #if _MHD_DEBUG_SEND_DATA
2907 _ (
"Sent 100 continue response: `%.*s'\n"),
2975 "Connection was closed while sending response headers.\n"));
2979 if (((
size_t) ret) > wb_ready)
3004 uint64_t data_write_offset;
3006 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3015 #if defined(_MHD_HAVE_SENDFILE)
3016 if (MHD_resp_sender_sendfile == connection->resp_sender)
3018 ret = MHD_send_sendfile_ (connection);
3027 if (data_write_offset > (uint64_t)
SIZE_MAX)
3028 MHD_PANIC (
_ (
"Data offset exceeds limit.\n"));
3031 [(
size_t) data_write_offset],
3033 - (
size_t) data_write_offset,
3035 #if _MHD_DEBUG_SEND_DATA
3038 _ (
"Sent %d-byte DATA response: `%.*s'\n"),
3045 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3053 #ifdef HAVE_MESSAGES
3054 MHD_DLOG (connection->
daemon,
3055 _ (
"Failed to send data in request for `%s'.\n"),
3085 "Connection was closed while sending response body.\n"));
3115 "Connection was closed while sending response body.\n"));
3130 #ifdef UPGRADE_SUPPORT
3131 case MHD_CONNECTION_UPGRADE:
3138 _ (
"Internal error.\n"));
3157 #ifdef MHD_USE_THREADS
3159 MHD_thread_ID_match_current_ (connection->
pid) );
3170 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3202 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3210 if ( (MHD_ITC_IS_VALID_ (daemon->
itc)) &&
3211 (! MHD_itc_activate_ (daemon->
itc,
"c")) )
3213 #ifdef HAVE_MESSAGES
3216 "Failed to signal end of connection via inter-thread communication channel.\n"));
3240 #ifdef MHD_USE_THREADS
3242 MHD_thread_ID_match_current_ (connection->
pid) );
3248 #ifdef HTTPS_SUPPORT
3251 if ((MHD_TLS_CONN_INIT <= connection->tls_state) &&
3258 _ (
"In function %s handling connection at state: %s\n"),
3260 MHD_state_to_string (connection->
state));
3262 switch (connection->
state)
3271 if ( (
NULL == line) ||
3485 "Closing connection (failed to create response header).\n"));
3495 #ifdef UPGRADE_SUPPORT
3498 connection->
state = MHD_CONNECTION_UPGRADE;
3529 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3535 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3544 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3560 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3568 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3577 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3594 "Closing connection (failed to create response header).\n"));
3680 #ifdef UPGRADE_SUPPORT
3681 case MHD_CONNECTION_UPGRADE:
3695 if ( (0 != timeout) &&
3707 #ifdef EPOLL_SUPPORT
3711 ret = MHD_connection_epoll_update_ (connection);
3719 #ifdef EPOLL_SUPPORT
3742 struct epoll_event event;
3744 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET;
3745 event.data.ptr = connection;
3746 if (0 != epoll_ctl (daemon->epoll_fd,
3751 #ifdef HAVE_MESSAGES
3754 _ (
"Call to epoll_ctl failed: %s\n"),
3799 #ifdef HTTPS_SUPPORT
3801 if (
NULL == connection->tls_session)
3803 connection->cipher = gnutls_cipher_get (connection->tls_session);
3806 if (
NULL == connection->tls_session)
3808 connection->protocol = gnutls_protocol_get_version (
3809 connection->tls_session);
3812 if (
NULL == connection->tls_session)
3831 connection_timeout_dummy;
3860 daemon = connection->
daemon;
3866 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3881 va_start (ap, option);
3897 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3920 unsigned int status_code,
3925 if ( (
NULL == connection) ||
3926 (
NULL == response) ||
3931 daemon = connection->
daemon;
3937 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3940 (! MHD_thread_ID_match_current_ (connection->
pid)) )
3942 #ifdef HAVE_MESSAGES
3944 _ (
"Attempted to queue response on wrong thread!\n"));
3949 #ifdef UPGRADE_SUPPORT
3950 if ( (
NULL != response->upgrade_handler) &&
3953 #ifdef HAVE_MESSAGES
3956 "Attempted 'upgrade' connection on daemon without MHD_ALLOW_UPGRADE option!\n"));
3961 (
NULL != response->upgrade_handler) )
3963 #ifdef HAVE_MESSAGES
3966 "Application used invalid status code for 'upgrade' response!\n"));
3974 #if defined(_MHD_HAVE_SENDFILE)
3975 if ( (response->
fd == -1) ||
3978 #
if ! defined(MHD_WINSOCK_SOCKETS) && defined(HAVE_SEND_SIGPIPE_SUPPRESS)
3982 connection->resp_sender = MHD_resp_sender_std;
3984 connection->resp_sender = MHD_resp_sender_sendfile;
static ssize_t recv_param_adapter(struct MHD_Connection *connection, void *other, size_t i)
static enum MHD_Result build_header_response(struct MHD_Connection *connection)
static void connection_close_error(struct MHD_Connection *connection, const char *emsg)
static enum MHD_Result process_header_line(struct MHD_Connection *connection, char *line)
#define MHD_lookup_header_s_token_ci(c, h, tkn)
void MHD_connection_handle_read(struct MHD_Connection *connection)
void MHD_connection_handle_write(struct MHD_Connection *connection)
static void MHD_connection_update_event_loop_info(struct MHD_Connection *connection)
static enum MHD_Result try_ready_normal_body(struct MHD_Connection *connection)
static void call_connection_handler(struct MHD_Connection *connection)
static void process_request_body(struct MHD_Connection *connection)
#define HTTP_100_CONTINUE
static enum MHD_Result keepalive_possible(struct MHD_Connection *connection)
static enum MHD_Result parse_cookie_header(struct MHD_Connection *connection)
#define REQUEST_MALFORMED
void MHD_set_http_callbacks_(struct MHD_Connection *connection)
#define REQUEST_LACKS_HOST
static bool try_grow_read_buffer(struct MHD_Connection *connection, bool required)
static bool need_100_continue(struct MHD_Connection *connection)
static void transmit_error_response(struct MHD_Connection *connection, unsigned int status_code, const char *message)
enum MHD_Result MHD_connection_handle_idle(struct MHD_Connection *connection)
static void cleanup_connection(struct MHD_Connection *connection)
static enum MHD_Result try_ready_chunked_body(struct MHD_Connection *connection)
static enum MHD_Result process_broken_line(struct MHD_Connection *connection, char *line, enum MHD_ValueKind kind)
static char * get_next_header_line(struct MHD_Connection *connection, size_t *line_len)
static void parse_connection_headers(struct MHD_Connection *connection)
void MHD_update_last_activity_(struct MHD_Connection *connection)
static enum MHD_Result parse_initial_message_line(struct MHD_Connection *connection, char *line, size_t line_len)
static void get_date_string(char *date, size_t date_len)
void MHD_connection_close_(struct MHD_Connection *connection, enum MHD_RequestTerminationCode termination_code)
static enum MHD_Result connection_add_header(struct MHD_Connection *connection, const char *key, size_t key_size, const char *value, size_t value_size, enum MHD_ValueKind kind)
void MHD_connection_mark_closed_(struct MHD_Connection *connection)
#define CONNECTION_CLOSE_ERROR(c, emsg)
static enum MHD_Result check_write_done(struct MHD_Connection *connection, enum MHD_CONNECTION_STATE next_state)
static bool MHD_lookup_header_token_ci(const struct MHD_Connection *connection, const char *header, size_t header_len, const char *token, size_t token_len)
Methods for managing connections.
void MHD_connection_finish_forward_(struct MHD_Connection *connection) MHD_NONNULL(1)
bool MHD_tls_connection_shutdown(struct MHD_Connection *connection)
bool MHD_run_tls_handshake_(struct MHD_Connection *connection)
Methods for managing connections.
#define MHD_HTTP_INTERNAL_SERVER_ERROR
#define MHD_HTTP_URI_TOO_LONG
#define MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE
#define MHD_HTTP_PROCESSING
#define MHD_HTTP_SWITCHING_PROTOCOLS
#define MHD_HTTP_NOT_MODIFIED
#define MHD_HTTP_NO_CONTENT
#define MHD_HTTP_BAD_REQUEST
#define MHD_HTTP_METHOD_HEAD
#define MHD_HTTP_METHOD_CONNECT
enum MHD_Result(* MHD_KeyValueIterator)(void *cls, enum MHD_ValueKind kind, const char *key, const char *value)
_MHD_EXTERN int MHD_get_connection_values_n(struct MHD_Connection *connection, enum MHD_ValueKind kind, MHD_KeyValueIteratorN iterator, void *iterator_cls)
_MHD_EXTERN enum MHD_Result MHD_set_connection_value_n(struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key, size_t key_size, const char *value, size_t value_size)
enum MHD_Result(* MHD_KeyValueIteratorN)(void *cls, enum MHD_ValueKind kind, const char *key, size_t key_size, const char *value, size_t value_size)
static enum MHD_Result MHD_set_connection_value_n_nocheck_(struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key, size_t key_size, const char *value, size_t value_size)
_MHD_EXTERN const char * MHD_lookup_connection_value(struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key)
_MHD_EXTERN int MHD_get_connection_values(struct MHD_Connection *connection, enum MHD_ValueKind kind, MHD_KeyValueIterator iterator, void *iterator_cls)
_MHD_EXTERN enum MHD_Result MHD_set_connection_value(struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key, const char *value)
_MHD_EXTERN enum MHD_Result MHD_lookup_connection_value_n(struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key, size_t key_size, const char **value_ptr, size_t *value_size_ptr)
MHD_RequestTerminationCode
@ MHD_CONNECTION_INFO_CONNECTION_TIMEOUT
@ MHD_CONNECTION_INFO_SOCKET_CONTEXT
@ MHD_CONNECTION_INFO_GNUTLS_SESSION
@ MHD_CONNECTION_INFO_REQUEST_HEADER_SIZE
@ MHD_CONNECTION_INFO_CIPHER_ALGO
@ MHD_CONNECTION_INFO_CONNECTION_SUSPENDED
@ MHD_CONNECTION_INFO_CLIENT_ADDRESS
@ MHD_CONNECTION_INFO_DAEMON
@ MHD_CONNECTION_INFO_CONNECTION_FD
@ MHD_CONNECTION_INFO_PROTOCOL
@ MHD_REQUEST_TERMINATED_TIMEOUT_REACHED
@ MHD_REQUEST_TERMINATED_COMPLETED_OK
@ MHD_REQUEST_TERMINATED_WITH_ERROR
@ MHD_REQUEST_TERMINATED_READ_ERROR
@ MHD_REQUEST_TERMINATED_CLIENT_ABORT
_MHD_EXTERN struct MHD_Response * MHD_create_response_from_buffer(size_t size, void *buffer, enum MHD_ResponseMemoryMode mode)
_MHD_EXTERN enum MHD_Result MHD_queue_response(struct MHD_Connection *connection, unsigned int status_code, struct MHD_Response *response)
_MHD_EXTERN void MHD_destroy_response(struct MHD_Response *response)
_MHD_EXTERN const char * MHD_get_response_header(struct MHD_Response *response, const char *key)
_MHD_EXTERN const union MHD_ConnectionInfo * MHD_get_connection_info(struct MHD_Connection *connection, enum MHD_ConnectionInfoType info_type,...)
_MHD_EXTERN enum MHD_Result MHD_set_connection_option(struct MHD_Connection *connection, enum MHD_CONNECTION_OPTION option,...)
#define MHD_HTTP_VERSION_1_0
#define MHD_HTTP_VERSION_1_1
bool MHD_parse_arguments_(struct MHD_Request *request, enum MHD_ValueKind kind, char *args, MHD_ArgumentIterator_ cb, unsigned int *num_headers)
#define MHD_ERR_CONNRESET_
#define XDLL_insert(head, tail, element)
MHD_PanicCallback mhd_panic
@ MHD_EPOLL_STATE_SUSPENDED
@ MHD_EPOLL_STATE_READ_READY
@ MHD_EPOLL_STATE_IN_EPOLL_SET
@ MHD_EPOLL_STATE_WRITE_READY
#define DLL_insert(head, tail, element)
@ MHD_CONN_KEEPALIVE_UNKOWN
#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)
void * MHD_pool_reallocate(struct MemoryPool *pool, void *old, size_t old_size, size_t new_size)
size_t MHD_pool_get_free(struct MemoryPool *pool)
void * MHD_pool_reset(struct MemoryPool *pool, void *keep, size_t copy_bytes, size_t new_size)
void * MHD_pool_allocate(struct MemoryPool *pool, size_t size, int from_end)
#define MHD_mutex_unlock_chk_(pmutex)
#define MHD_mutex_lock_chk_(pmutex)
time_t MHD_monotonic_sec_counter(void)
#define MHD_SCKT_ERR_IS_(err, code)
#define MHD_SCKT_ERR_IS_EAGAIN_(err)
#define MHD_socket_last_strerr_()
#define MHD_socket_get_error_()
#define MHD_SCKT_ERR_IS_EINTR_(err)
#define MHD_SCKT_SEND_MAX_SIZE_
#define MHD_recv_(s, b, l)
#define MHD_SCKT_ECONNRESET_
int MHD_str_equal_caseless_(const char *str1, const char *str2)
size_t MHD_strx_to_uint64_n_(const char *str, size_t maxlen, uint64_t *out_val)
size_t MHD_str_to_uint64_(const char *str, uint64_t *out_val)
bool MHD_str_has_token_caseless_(const char *str, const char *const token, size_t token_len)
#define MHD_STATICSTR_LEN_(macro)
ssize_t MHD_send_hdr_and_body_(struct MHD_Connection *connection, const char *header, size_t header_size, bool never_push_hdr, const char *body, size_t body_size, bool complete_response)
ssize_t MHD_send_data_(struct MHD_Connection *connection, const char *buffer, size_t buffer_size, bool push_data)
Declarations of send() wrappers.
internal shared structures
@ MHD_CONNECTION_BODY_RECEIVED
@ MHD_CONNECTION_HEADER_PART_RECEIVED
@ MHD_CONNECTION_HEADERS_SENDING
@ MHD_CONNECTION_FOOTERS_SENDING
@ MHD_CONNECTION_FOOTERS_RECEIVED
@ MHD_CONNECTION_HEADERS_SENT
@ MHD_CONNECTION_HEADERS_PROCESSED
@ MHD_CONNECTION_NORMAL_BODY_UNREADY
@ MHD_CONNECTION_HEADERS_RECEIVED
@ MHD_CONNECTION_NORMAL_BODY_READY
@ MHD_CONNECTION_CHUNKED_BODY_READY
@ MHD_CONNECTION_FOOTER_PART_RECEIVED
@ MHD_CONNECTION_CONTINUE_SENT
@ MHD_CONNECTION_FOOTERS_SENT
@ MHD_CONNECTION_CHUNKED_BODY_UNREADY
@ MHD_CONNECTION_BODY_SENT
@ MHD_CONNECTION_CONTINUE_SENDING
@ MHD_CONNECTION_URL_RECEIVED
#define MHD_check_response_header_s_token_ci(r, k, tkn)
@ MHD_TLS_CONN_HANDSHAKING
@ MHD_EVENT_LOOP_INFO_READ
@ MHD_EVENT_LOOP_INFO_WRITE
@ MHD_EVENT_LOOP_INFO_CLEANUP
@ MHD_EVENT_LOOP_INFO_BLOCK
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
internal monotonic clock functions implementations
bool MHD_str_equal_caseless_bin_n_(const char *const str1, const char *const str2, size_t len)
Header for string manipulating helpers.
void MHD_increment_response_rc(struct MHD_Response *response)
#define MHD_CONTENT_READER_END_OF_STREAM
#define MHD_UNSIGNED_LONG_LONG
#define MHD_UNSIGNED_LONG_LONG_PRINTF
#define MHD_INVALID_SOCKET
#define MHD_CONTENT_READER_END_WITH_ERROR
_MHD_EXTERN const char * MHD_get_reason_phrase_for(unsigned int code)
@ MHD_USE_THREAD_PER_CONNECTION
@ MHD_USE_SUPPRESS_DATE_NO_CLOCK
@ MHD_USE_INTERNAL_POLLING_THREAD
@ MHD_RF_HTTP_VERSION_1_0_RESPONSE
@ MHD_RF_HTTP_VERSION_1_0_ONLY
@ MHD_CONNECTION_OPTION_TIMEOUT
Methods for managing response objects.
enum MHD_Result MHD_response_execute_upgrade_(struct MHD_Response *response, struct MHD_Connection *connection)
size_t write_buffer_send_offset
enum MHD_ConnectionEventLoopInfo event_loop_info
size_t write_buffer_append_offset
uint64_t remaining_upload_size
struct MHD_Response * response
enum MHD_ConnKeepAlive keepalive
time_t connection_timeout
struct MHD_HTTP_Header * headers_received
size_t continue_message_write_offset
uint64_t response_write_position
struct sockaddr_storage addr
struct MHD_HTTP_Header * headers_received_tail
uint64_t current_chunk_offset
size_t read_buffer_offset
uint64_t current_chunk_size
unsigned int responseCode
MHD_thread_handle_ID_ pid
enum MHD_CONNECTION_STATE state
struct MHD_Daemon * daemon
unsigned int connection_timeout_dummy
MHD_AccessHandlerCallback default_handler
LogCallback uri_log_callback
void * unescape_callback_cls
MHD_mutex_ cleanup_connection_mutex
struct MHD_Connection * connections_head
MHD_RequestCompletedCallback notify_completed
struct MHD_Connection * manual_timeout_tail
UnescapeCallback unescape_callback
void * notify_completed_cls
struct MHD_Connection * cleanup_tail
MHD_thread_handle_ID_ pid
struct MHD_Connection * manual_timeout_head
void * default_handler_cls
struct MHD_Connection * suspended_connections_tail
time_t connection_timeout
struct MHD_Connection * cleanup_head
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_HTTP_Header * first_header
enum MHD_HTTP_StatusCode status_code
MHD_ContentReaderCallback crc
enum MHD_ResponseFlags flags