GNU libmicrohttpd 0.9.77
|
Methods for managing connections. More...
#include "internal.h"
#include "mhd_limits.h"
#include "connection.h"
#include "memorypool.h"
#include "response.h"
#include "mhd_mono_clock.h"
#include "mhd_str.h"
#include "mhd_sockets.h"
#include "mhd_compat.h"
#include "mhd_itc.h"
#include "mhd_send.h"
#include "mhd_assert.h"
Go to the source code of this file.
Macros | |
#define | HTTP_100_CONTINUE "HTTP/1.1 100 Continue\r\n\r\n" |
#define | REQUEST_TOO_BIG "" |
#define | REQUEST_LACKS_HOST "" |
#define | REQUEST_MALFORMED "" |
#define | REQUEST_CHUNKED_MALFORMED "" |
#define | REQUEST_CHUNK_TOO_LARGE "" |
#define | REQUEST_CONTENTLENGTH_TOOLARGE "" |
#define | REQUEST_CONTENTLENGTH_MALFORMED "" |
#define | INTERNAL_ERROR "" |
#define | REQ_HTTP_VER_IS_TOO_OLD "" |
#define | REQ_HTTP_VER_IS_NOT_SUPPORTED "" |
#define | MHD_SENFILE_CHUNK_ (0x20000) |
#define | MHD_SENFILE_CHUNK_THR_P_C_ (0x200000) |
#define | MHD_lookup_header_s_token_ci(c, h, tkn) |
#define | CONNECTION_CLOSE_ERROR(c, emsg) connection_close_error (c, NULL) |
#define | CONNECTION_CLOSE_ERROR_CHECK(c, emsg) connection_close_error_check (c, NULL) |
#define | buffer_append_s(buf, ppos, buf_size, str) buffer_append(buf,ppos,buf_size,str, MHD_STATICSTR_LEN_(str)) |
#define | transmit_error_response_static(c, code, msg) transmit_error_response_len (c, code, msg, MHD_STATICSTR_LEN_ (msg)) |
Functions | |
static void * | connection_alloc_memory (struct MHD_Connection *connection, size_t size) |
static ssize_t | recv_param_adapter (struct MHD_Connection *connection, void *other, size_t i) |
_MHD_EXTERN int | MHD_get_connection_values (struct MHD_Connection *connection, enum MHD_ValueKind kind, MHD_KeyValueIterator iterator, void *iterator_cls) |
_MHD_EXTERN int | MHD_get_connection_values_n (struct MHD_Connection *connection, enum MHD_ValueKind kind, MHD_KeyValueIteratorN iterator, void *iterator_cls) |
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 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) |
_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 const char * | MHD_lookup_connection_value (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key) |
_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) |
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) |
static bool | need_100_continue (struct MHD_Connection *connection) |
void | MHD_connection_mark_closed_ (struct MHD_Connection *connection) |
void | MHD_connection_close_ (struct MHD_Connection *connection, enum MHD_RequestTerminationCode termination_code) |
static void | connection_close_error (struct MHD_Connection *connection, const char *emsg) |
static void | connection_close_error_check (struct MHD_Connection *connection, const char *emsg) |
static enum MHD_Result | try_ready_normal_body (struct MHD_Connection *connection) |
static enum MHD_Result | try_ready_chunked_body (struct MHD_Connection *connection, bool *p_finished) |
static enum MHD_ConnKeepAlive | keepalive_possible (struct MHD_Connection *connection) |
static bool | get_date_str (char *date) |
static bool | get_date_header (char *header) |
static bool | try_grow_read_buffer (struct MHD_Connection *connection, bool required) |
static void | connection_shrink_read_buffer (struct MHD_Connection *connection) |
static size_t | connection_maximize_write_buffer (struct MHD_Connection *connection) |
static void | connection_switch_from_recv_to_send (struct MHD_Connection *connection) |
static bool | is_reply_body_headers_needed (struct MHD_Connection *connection) |
static bool | is_reply_body_needed (struct MHD_Connection *connection) |
static void | setup_reply_properties (struct MHD_Connection *connection) |
static bool | buffer_append (char *buf, size_t *ppos, size_t buf_size, const char *append, size_t append_size) |
static bool | add_user_headers (char *buf, size_t *ppos, size_t buf_size, struct MHD_Response *response, enum MHD_ValueKind kind, bool filter_transf_enc, bool add_close, bool add_keep_alive) |
static enum MHD_Result | build_header_response (struct MHD_Connection *connection) |
static enum MHD_Result | build_connection_chunked_response_footer (struct MHD_Connection *connection) |
static void | transmit_error_response_len (struct MHD_Connection *connection, unsigned int status_code, const char *message, size_t message_len) |
static void | MHD_connection_update_event_loop_info (struct MHD_Connection *connection) |
static char * | get_next_header_line (struct MHD_Connection *connection, size_t *line_len) |
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) |
static enum MHD_Result | parse_cookie_header (struct MHD_Connection *connection) |
static enum MHD_Result | parse_http_version (struct MHD_Connection *connection, const char *http_string, size_t len) |
static enum MHD_Result | parse_http_std_method (struct MHD_Connection *connection, const char *method, size_t len) |
static enum MHD_Result | parse_initial_message_line (struct MHD_Connection *connection, char *line, size_t line_len) |
static void | call_connection_handler (struct MHD_Connection *connection) |
static void | process_request_body (struct MHD_Connection *connection) |
static enum MHD_Result | check_write_done (struct MHD_Connection *connection, enum MHD_CONNECTION_STATE next_state) |
static enum MHD_Result | process_header_line (struct MHD_Connection *connection, char *line) |
static enum MHD_Result | process_broken_line (struct MHD_Connection *connection, char *line, enum MHD_ValueKind kind) |
static void | parse_connection_headers (struct MHD_Connection *connection) |
void | MHD_update_last_activity_ (struct MHD_Connection *connection) |
void | MHD_connection_handle_read (struct MHD_Connection *connection, bool socket_error) |
void | MHD_connection_handle_write (struct MHD_Connection *connection) |
static bool | connection_check_timedout (struct MHD_Connection *c) |
static void | cleanup_connection (struct MHD_Connection *connection) |
static void | connection_reset (struct MHD_Connection *connection, bool reuse) |
enum MHD_Result | MHD_connection_handle_idle (struct MHD_Connection *connection) |
void | MHD_set_http_callbacks_ (struct MHD_Connection *connection) |
_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,...) |
_MHD_EXTERN enum MHD_Result | MHD_queue_response (struct MHD_Connection *connection, unsigned int status_code, struct MHD_Response *response) |
Methods for managing connections.
Definition in file connection.c.
#define buffer_append_s | ( | buf, | |
ppos, | |||
buf_size, | |||
str | |||
) | buffer_append(buf,ppos,buf_size,str, MHD_STATICSTR_LEN_(str)) |
Append static string to the buffer if enough space is available, update position.
[out] | buf | the buffer to append data to |
[in,out] | ppos | the pointer to position in the buffer |
buf_size | the size of the buffer | |
str | the static string to append |
Definition at line 1855 of file connection.c.
#define CONNECTION_CLOSE_ERROR | ( | c, | |
emsg | |||
) | connection_close_error (c, NULL) |
Macro to only include error message in call to connection_close_error() if we have HAVE_MESSAGES.
Definition at line 970 of file connection.c.
#define CONNECTION_CLOSE_ERROR_CHECK | ( | c, | |
emsg | |||
) | connection_close_error_check (c, NULL) |
Macro to only include error message in call to connection_close_error_check() if we have HAVE_MESSAGES.
Definition at line 1004 of file connection.c.
#define HTTP_100_CONTINUE "HTTP/1.1 100 Continue\r\n\r\n" |
Message to transmit when http 1.1 request is received
Definition at line 62 of file connection.c.
#define INTERNAL_ERROR "" |
Response text used when there is an internal server error.
Intentionally empty here to keep our memory footprint minimal.
Definition at line 160 of file connection.c.
#define MHD_lookup_header_s_token_ci | ( | c, | |
h, | |||
tkn | |||
) |
Check whether request header contains particular static tkn.
Token could be surrounded by spaces and tabs and delimited by comma. Case-insensitive match used for header names and tokens.
c | the connection to get values from |
h | the static string of header name |
tkn | the static string of token to find |
Definition at line 755 of file connection.c.
#define MHD_SENFILE_CHUNK_ (0x20000) |
sendfile() chuck size
Definition at line 187 of file connection.c.
#define MHD_SENFILE_CHUNK_THR_P_C_ (0x200000) |
sendfile() chuck size for thread-per-connection
Definition at line 192 of file connection.c.
#define REQ_HTTP_VER_IS_NOT_SUPPORTED "" |
Response text used when the request HTTP version is not supported.
Definition at line 180 of file connection.c.
#define REQ_HTTP_VER_IS_TOO_OLD "" |
Response text used when the request HTTP version is too old.
Definition at line 170 of file connection.c.
#define REQUEST_CHUNK_TOO_LARGE "" |
Response text used when the request HTTP chunk is too large.
Definition at line 124 of file connection.c.
#define REQUEST_CHUNKED_MALFORMED "" |
Response text used when the request HTTP chunked encoding is malformed.
Definition at line 114 of file connection.c.
#define REQUEST_CONTENTLENGTH_MALFORMED "" |
Response text used when the request HTTP chunked encoding is malformed.
Definition at line 147 of file connection.c.
#define REQUEST_CONTENTLENGTH_TOOLARGE "" |
Response text used when the request HTTP content is too large.
Definition at line 135 of file connection.c.
#define REQUEST_LACKS_HOST "" |
Response text used when the request (http header) does not contain a "Host:" header and still claims to be HTTP 1.1.
Intentionally empty here to keep our memory footprint minimal.
Definition at line 89 of file connection.c.
#define REQUEST_MALFORMED "" |
Response text used when the request (http header) is malformed.
Intentionally empty here to keep our memory footprint minimal.
Definition at line 103 of file connection.c.
#define REQUEST_TOO_BIG "" |
Response text used when the request (http header) is too big to be processed.
Intentionally empty here to keep our memory footprint minimal.
Definition at line 75 of file connection.c.
#define transmit_error_response_static | ( | c, | |
code, | |||
msg | |||
) | transmit_error_response_len (c, code, msg, MHD_STATICSTR_LEN_ (msg)) |
Transmit static string as error response
Definition at line 2395 of file connection.c.
|
static |
Add user-defined headers from response object to the text buffer.
buf | the buffer to add headers to |
ppos | the pointer to the position in the buf |
buf_size | the size of the buf |
response | the response |
kind | the kind of objects (headers or footers) |
filter_transf_enc | skip "Transfer-Encoding" header if any |
add_close | add "close" token to the "Connection:" header (if any), ignored if no "Connection:" header was added by user or if "close" token is already present in "Connection:" header |
add_keep_alive | add "Keep-Alive" token to the "Connection:" header (if any) |
< a short alias
< Iterates through User-specified headers
< the size of current element to be added to the buf
Definition at line 1879 of file connection.c.
References MHD_Response::first_header, MHD_Response::flags_auto, MHD_HTTP_Header::header, MHD_HTTP_Header::header_size, MHD_HTTP_Header::kind, mhd_assert, MHD_HEADER_KIND, MHD_HTTP_HEADER_CONNECTION, MHD_HTTP_HEADER_TRANSFER_ENCODING, MHD_RAF_HAS_CONNECTION_CLOSE, MHD_RAF_HAS_CONNECTION_HDR, MHD_RAF_HAS_TRANS_ENC_CHUNKED, MHD_STATICSTR_LEN_, MHD_str_equal_caseless_bin_n_(), MHD_str_equal_caseless_n_(), MHD_HTTP_Header::next, NULL, MHD_HTTP_Header::value, and MHD_HTTP_Header::value_size.
Referenced by build_header_response().
|
static |
Append data to the buffer if enough space is available, update position.
[out] | buf | the buffer to append data to |
[in,out] | ppos | the pointer to position in the buffer |
buf_size | the size of the buffer | |
append | the data to append | |
append_size | the size of the append |
Definition at line 1830 of file connection.c.
References mhd_assert, and NULL.
Referenced by build_header_response().
|
static |
Allocate the connection's write buffer (if necessary) and fill it with response footers. Works only for chunked responses as other responses do not need and do not support any kind of footers.
connection | the connection |
< the buffer to write footers to
< the size of the buf
< the used size of the buf
< a short alias
Definition at line 2203 of file connection.c.
References MHD_Reply_Properties::chunked, connection_maximize_write_buffer(), MHD_Response::first_header, MHD_HTTP_Header::header, MHD_HTTP_Header::header_size, MHD_HTTP_Header::kind, mhd_assert, MHD_CONNECTION_BODY_SENT, MHD_FOOTER_KIND, MHD_NO, MHD_YES, MHD_HTTP_Header::next, NULL, MHD_Connection::response, MHD_Connection::rp_props, MHD_Connection::state, MHD_HTTP_Header::value, MHD_HTTP_Header::value_size, MHD_Connection::write_buffer, MHD_Connection::write_buffer_append_offset, and MHD_Connection::write_buffer_size.
Referenced by MHD_connection_handle_idle().
|
static |
Allocate the connection's write buffer and fill it with all of the headers from the response. Required headers are added here.
connection | the connection |
< a short alias
< a short alias
< the output buffer
< append offset in the buf
< the size of the buf
< the size of current element to be added to the buf
< the response code
< Use "Connection: close" header
< Use "Connection: Keep-Alive" header
Definition at line 1980 of file connection.c.
References add_user_headers(), buffer_append(), buffer_append_s, MHD_Reply_Properties::chunked, connection_maximize_write_buffer(), MHD_Connection::daemon, MHD_Response::flags, MHD_Response::flags_auto, get_date_header(), MHD_Connection::http_ver, MHD_Connection::keepalive, mhd_assert, MHD_CONN_MUST_CLOSE, MHD_CONN_MUST_UPGRADE, MHD_CONN_USE_KEEPALIVE, MHD_get_reason_phrase_for(), MHD_get_reason_phrase_len_for(), MHD_HEADER_KIND, MHD_HTTP_HEADER_CONNECTION, MHD_HTTP_HEADER_CONTENT_LENGTH, MHD_HTTP_HEADER_TRANSFER_ENCODING, MHD_HTTP_VER_1_0, MHD_HTTP_VERSION_1_0, MHD_HTTP_VERSION_1_1, MHD_ICY_FLAG, MHD_NO, MHD_RAF_HAS_CONNECTION_HDR, MHD_RAF_HAS_DATE_HDR, MHD_RAF_HAS_TRANS_ENC_CHUNKED, MHD_RF_HTTP_1_0_SERVER, MHD_RF_SEND_KEEP_ALIVE_HEADER, MHD_SIZE_UNKNOWN, MHD_uint16_to_str(), MHD_uint64_to_str(), MHD_USE_SUPPRESS_DATE_NO_CLOCK, MHD_YES, NULL, MHD_Daemon::options, MHD_Connection::response, MHD_Connection::responseCode, MHD_Connection::rp_props, MHD_Reply_Properties::send_reply_body, MHD_Reply_Properties::set, setup_reply_properties(), MHD_Response::total_size, MHD_Reply_Properties::use_reply_body_headers, MHD_Connection::write_buffer, MHD_Connection::write_buffer_append_offset, and MHD_Connection::write_buffer_size.
Referenced by MHD_connection_handle_idle(), and transmit_error_response_len().
|
static |
Call the handler of the application for this connection. Handles chunking of the upload as well as normal uploads.
connection | connection we're processing |
Definition at line 3061 of file connection.c.
References _, MHD_Connection::client_aware, MHD_Connection::client_context, CONNECTION_CLOSE_ERROR, MHD_Connection::daemon, MHD_Daemon::default_handler, MHD_Daemon::default_handler_cls, MHD_Connection::method, MHD_NO, NULL, MHD_Connection::response, MHD_Connection::url, and MHD_Connection::version.
Referenced by MHD_connection_handle_idle().
|
static |
Check if we are done sending the write-buffer. If so, transition into "next_state".
connection | connection to check write status for |
next_state | the next state to transition to |
Definition at line 3386 of file connection.c.
References MHD_NO, MHD_YES, MHD_Connection::state, MHD_Connection::write_buffer_append_offset, and MHD_Connection::write_buffer_send_offset.
Referenced by MHD_connection_handle_write().
|
static |
Clean up the state of the given connection and move it into the clean up queue for final disposal.
connection | handle for the connection to clean up |
Definition at line 4216 of file connection.c.
References _, MHD_Daemon::cleanup_connection_mutex, MHD_Daemon::cleanup_head, MHD_Daemon::cleanup_tail, MHD_Connection::connection_timeout_ms, MHD_Daemon::connection_timeout_ms, MHD_Daemon::connections_head, MHD_Daemon::connections_tail, MHD_Connection::daemon, DLL_insert, DLL_remove, MHD_Connection::in_cleanup, MHD_Connection::in_idle, MHD_Daemon::itc, MHD_Daemon::manual_timeout_head, MHD_Daemon::manual_timeout_tail, mhd_assert, MHD_destroy_response(), MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_USE_INTERNAL_POLLING_THREAD, MHD_USE_THREAD_PER_CONNECTION, MHD_Daemon::normal_timeout_head, MHD_Daemon::normal_timeout_tail, NULL, MHD_Daemon::options, MHD_Connection::pid, MHD_Connection::response, MHD_Connection::resuming, MHD_Connection::suspended, MHD_Daemon::suspended_connections_head, MHD_Daemon::suspended_connections_tail, and XDLL_remove.
Referenced by MHD_connection_handle_idle().
|
static |
Add an entry to the HTTP headers of a connection. If this fails, transmit an error response (request too big).
connection | the connection for which a value should be set |
kind | kind of the value |
key | key for the value |
key_size | number of bytes in key |
value | the value itself |
value_size | number of bytes in value |
Definition at line 2661 of file connection.c.
References _, MHD_Connection::daemon, MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE, MHD_NO, MHD_set_connection_value_n(), MHD_YES, REQUEST_TOO_BIG, and transmit_error_response_static.
Referenced by parse_cookie_header(), parse_initial_message_line(), and process_broken_line().
|
static |
Allocate memory from connection's memory pool. If memory pool doesn't have enough free memory but read of write buffer have some unused memory, the size of the buffer will be reduced as needed.
connection | the connection to use |
size | the size of allocated memory area |
< The required amount of free memory
Definition at line 246 of file connection.c.
References mhd_assert, MHD_pool_allocate(), MHD_pool_reallocate(), MHD_pool_try_alloc(), NULL, MHD_Connection::pool, MHD_Connection::read_buffer, MHD_Connection::read_buffer_offset, MHD_Connection::read_buffer_size, MHD_Connection::write_buffer, MHD_Connection::write_buffer_append_offset, MHD_Connection::write_buffer_send_offset, and MHD_Connection::write_buffer_size.
Referenced by MHD_set_connection_value_n_nocheck_(), parse_cookie_header(), and try_ready_normal_body().
|
static |
Check whether connection has timed out.
c | the connection to check |
Definition at line 4164 of file connection.c.
References _, MHD_Connection::connection_timeout_ms, MHD_Connection::daemon, MHD_Connection::last_activity, MHD_monotonic_msec_counter(), PRIu64, MHD_Connection::suspended, and UINT64_MAX.
Referenced by MHD_connection_handle_idle().
|
static |
A serious error occurred, close the connection (and notify the application).
connection | connection to close with error |
emsg | error message (can be NULL) |
Definition at line 945 of file connection.c.
References MHD_Connection::daemon, MHD_Connection::discard_request, MHD_connection_close_(), MHD_REQUEST_TERMINATED_WITH_ERROR, NULL, and MHD_Connection::stop_with_error.
Referenced by connection_close_error_check().
|
static |
A serious error occurred, check whether error response is already queued and close the connection if response wasn't queued.
connection | connection to close with error |
emsg | error message (can be NULL) |
Definition at line 982 of file connection.c.
References connection_close_error(), MHD_Response::crc, MHD_CONNECTION_HEADERS_SENDING, NULL, MHD_Connection::response, MHD_Connection::responseCode, MHD_Connection::state, and MHD_Connection::stop_with_error.
|
static |
Allocate the maximum available amount of memory from MemoryPool for write buffer.
connection | the connection whose write buffer is being manipulated |
< a short alias
Definition at line 1577 of file connection.c.
References mhd_assert, MHD_pool_get_free(), MHD_pool_reallocate(), NULL, MHD_Connection::pool, MHD_Connection::write_buffer, MHD_Connection::write_buffer_append_offset, MHD_Connection::write_buffer_send_offset, and MHD_Connection::write_buffer_size.
Referenced by build_connection_chunked_response_footer(), and build_header_response().
|
static |
Reset connection after request-reply cycle.
connection | the connection to process |
reuse | the flag to choose whether to close connection or prepare connection for the next request processing |
< a short alias
Definition at line 4292 of file connection.c.
References MHD_Connection::client_aware, MHD_Connection::client_context, MHD_Connection::colon, MHD_Connection::continue_message_write_offset, MHD_Connection::current_chunk_offset, MHD_Connection::current_chunk_size, MHD_Connection::daemon, MHD_Connection::discard_request, MHD_Connection::have_chunked_upload, MHD_Connection::header_size, MHD_Connection::headers_received, MHD_Connection::headers_received_tail, MHD_Connection::http_mthd, MHD_Connection::http_ver, MHD_Connection::keepalive, MHD_Connection::last, MHD_Connection::method, mhd_assert, MHD_CONN_KEEPALIVE_UNKOWN, MHD_connection_close_(), MHD_CONNECTION_INIT, MHD_destroy_response(), MHD_HTTP_MTHD_NO_METHOD, MHD_HTTP_VER_UNKNOWN, MHD_pool_reset(), MHD_REQUEST_TERMINATED_COMPLETED_OK, MHD_REQUEST_TERMINATED_WITH_ERROR, MHD_Daemon::notify_completed, MHD_Daemon::notify_completed_cls, NULL, MHD_Connection::pool, MHD_Daemon::pool_size, MHD_Connection::read_buffer, MHD_Connection::read_buffer_offset, MHD_Connection::read_buffer_size, MHD_Connection::resp_iov, MHD_Connection::response, MHD_Connection::response_write_position, MHD_Connection::responseCode, MHD_Connection::rp_props, MHD_Connection::state, MHD_Connection::stop_with_error, MHD_Connection::url, MHD_Connection::version, MHD_Connection::write_buffer, MHD_Connection::write_buffer_append_offset, MHD_Connection::write_buffer_send_offset, and MHD_Connection::write_buffer_size.
Referenced by MHD_connection_handle_idle().
|
static |
Shrink connection read buffer to the zero size of free space in the buffer
connection | the connection whose read buffer is being manipulated |
< a short alias
Definition at line 1548 of file connection.c.
References mhd_assert, MHD_pool_reallocate(), NULL, MHD_Connection::pool, MHD_Connection::read_buffer, MHD_Connection::read_buffer_offset, and MHD_Connection::read_buffer_size.
Referenced by connection_switch_from_recv_to_send().
|
static |
Switch connection from recv mode to send mode.
Current request header or body will not be read anymore, response must be assigned to connection.
connection | the connection to prepare for sending. |
Definition at line 1669 of file connection.c.
References connection_shrink_read_buffer().
Referenced by MHD_connection_handle_idle().
|
static |
Produce HTTP DATE header. Result is always 37 bytes long (plus one terminating null).
[out] | header | where to write the header, with at least 38 bytes available space. |
Definition at line 1454 of file connection.c.
References get_date_str().
Referenced by build_header_response().
|
static |
Produce time stamp.
Result is NOT null-terminated. Result is always 29 bytes long.
[out] | date | where to write the time stamp, with at least 29 bytes available space. |
Definition at line 1369 of file connection.c.
References MHD_uint16_to_str(), MHD_uint8_to_str_pad(), and NULL.
Referenced by get_date_header().
|
static |
Parse a single line of the HTTP header. Advance read_buffer (!) appropriately. If the current line does not fit, consider growing the buffer. If the line is far too long, close the connection. If no line is found (incomplete, buffer too small, line too long), return NULL. Otherwise return a pointer to the line.
connection | connection we're processing | |
[out] | line_len | pointer to variable that receive length of line or NULL |
Definition at line 2586 of file connection.c.
References mhd_assert, MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE, MHD_HTTP_URI_TOO_LONG, NULL, MHD_Connection::read_buffer, MHD_Connection::read_buffer_offset, MHD_Connection::read_buffer_size, REQUEST_TOO_BIG, transmit_error_response_static, try_grow_read_buffer(), and MHD_Connection::url.
Referenced by MHD_connection_handle_idle().
|
static |
Check whether reply body-specific headers (namely Content-Length, Transfer-Encoding) are needed.
If reply body-specific headers are not needed then body itself is not allowed as well. When reply body-specific headers are needed, the body itself can be present or not, depending on other conditions.
connection | the connection to check |
< a short alias
< the response code
Definition at line 1691 of file connection.c.
References MHD_Connection::http_mthd, mhd_assert, MHD_HTTP_MTHD_CONNECT, MHD_HTTP_NO_CONTENT, MHD_ICY_FLAG, NULL, MHD_Connection::response, and MHD_Connection::responseCode.
Referenced by is_reply_body_needed(), and setup_reply_properties().
|
static |
Check whether reply body must be used.
If reply body is needed, it could be zero-sized.
connection | the connection to check |
< a short alias
< the response code
Definition at line 1731 of file connection.c.
References MHD_Connection::http_mthd, is_reply_body_headers_needed(), mhd_assert, MHD_HTTP_MTHD_HEAD, MHD_HTTP_NOT_MODIFIED, MHD_ICY_FLAG, and MHD_Connection::responseCode.
Referenced by setup_reply_properties().
|
static |
Are we allowed to keep the given connection alive? We can use the TCP stream for a second request if the connection is HTTP 1.1 and the "Connection" header either does not exist or is not set to "close", or if the connection is HTTP 1.0 and the "Connection" header is explicitly set to "keep-alive". If no HTTP version is specified (or if it is not 1.0 or 1.1), we definitively close the connection. If the "Connection" header is not exactly "close" or "keep-alive", we proceed to use the default for the respective HTTP version. If response has HTTP/1.0 flag or has "Connection: close" header then connection must be closed. If full request has not been read then connection must be closed as well.
connection | the connection to check for keepalive |
< a short alias
< a short alias
Definition at line 1301 of file connection.c.
References MHD_Connection::discard_request, MHD_Response::flags, MHD_Response::flags_auto, MHD_Connection::http_ver, MHD_Connection::keepalive, mhd_assert, MHD_CONN_MUST_CLOSE, MHD_CONN_MUST_UPGRADE, MHD_CONN_USE_KEEPALIVE, MHD_HTTP_HEADER_CONNECTION, MHD_HTTP_VER_1_0, MHD_IS_HTTP_VER_1_1_COMPAT, MHD_IS_HTTP_VER_SUPPORTED, MHD_lookup_header_s_token_ci, MHD_RAF_HAS_CONNECTION_CLOSE, MHD_RF_HTTP_1_0_COMPATIBLE_STRICT, MHD_RF_HTTP_1_0_SERVER, NULL, MHD_Connection::read_closed, MHD_Connection::response, and MHD_Connection::stop_with_error.
Referenced by setup_reply_properties().
void MHD_connection_close_ | ( | struct MHD_Connection * | connection, |
enum MHD_RequestTerminationCode | termination_code | ||
) |
Close the given connection and give the specified termination code to the user.
connection | connection to close |
termination_code | termination reason to give |
Definition at line 830 of file connection.c.
References MHD_Connection::client_aware, MHD_Connection::client_context, MHD_Connection::daemon, mhd_assert, MHD_connection_mark_closed_(), MHD_destroy_response(), MHD_pool_destroy(), MHD_USE_INTERNAL_POLLING_THREAD, MHD_Daemon::notify_completed, MHD_Daemon::notify_completed_cls, NULL, MHD_Daemon::options, MHD_Connection::pid, MHD_Connection::pool, MHD_Connection::response, and MHD_Connection::suspended.
Referenced by connection_close_error(), connection_reset(), MHD_connection_handle_idle(), MHD_connection_handle_read(), and try_ready_normal_body().
enum MHD_Result MHD_connection_handle_idle | ( | struct MHD_Connection * | connection | ) |
This function was created to handle per-connection processing that has to happen even if the socket cannot be read or written to.
connection | connection to handle |
Definition at line 4385 of file connection.c.
References _, build_connection_chunked_response_footer(), build_header_response(), call_connection_handler(), MHD_Reply_Properties::chunked, cleanup_connection(), connection_check_timedout(), CONNECTION_CLOSE_ERROR, CONNECTION_CLOSE_ERROR_CHECK, connection_reset(), connection_switch_from_recv_to_send(), MHD_Connection::continue_message_write_offset, MHD_Response::crc, MHD_Connection::daemon, MHD_Connection::discard_request, get_next_header_line(), MHD_Connection::have_chunked_upload, MHD_Connection::header_size, HTTP_100_CONTINUE, MHD_Connection::http_ver, MHD_Connection::in_idle, MHD_Connection::keepalive, MHD_Connection::method, mhd_assert, MHD_CONN_USE_KEEPALIVE, MHD_CONNECTION_BODY_RECEIVED, MHD_CONNECTION_BODY_SENT, MHD_CONNECTION_CHUNKED_BODY_READY, MHD_CONNECTION_CHUNKED_BODY_UNREADY, MHD_connection_close_(), MHD_CONNECTION_CLOSED, MHD_CONNECTION_CONTINUE_SENDING, MHD_CONNECTION_CONTINUE_SENT, MHD_CONNECTION_FOOTER_PART_RECEIVED, MHD_CONNECTION_FOOTERS_RECEIVED, MHD_CONNECTION_FOOTERS_SENDING, MHD_CONNECTION_FOOTERS_SENT, MHD_CONNECTION_FULL_REQ_RECEIVED, MHD_CONNECTION_HEADER_PART_RECEIVED, MHD_CONNECTION_HEADERS_PROCESSED, MHD_CONNECTION_HEADERS_RECEIVED, MHD_CONNECTION_HEADERS_SENDING, MHD_CONNECTION_HEADERS_SENT, MHD_CONNECTION_INIT, MHD_CONNECTION_NORMAL_BODY_READY, MHD_CONNECTION_NORMAL_BODY_UNREADY, MHD_CONNECTION_REQ_LINE_RECEIVING, MHD_CONNECTION_START_REPLY, MHD_connection_update_event_loop_info(), MHD_CONNECTION_URL_RECEIVED, MHD_destroy_response(), MHD_FOOTER_KIND, MHD_FUNC_, MHD_HEADER_KIND, MHD_HTTP_BAD_REQUEST, MHD_HTTP_PROCESSING, MHD_IS_HTTP_VER_SUPPORTED, MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_NO, MHD_REQUEST_TERMINATED_TIMEOUT_REACHED, MHD_response_execute_upgrade_(), MHD_SIZE_UNKNOWN, MHD_STATICSTR_LEN_, MHD_TLS_CONN_CONNECTED, MHD_TLS_CONN_NO_TLS, MHD_USE_EPOLL, MHD_USE_INTERNAL_POLLING_THREAD, MHD_YES, MHD_Response::mutex, need_100_continue(), NULL, MHD_Daemon::options, parse_connection_headers(), parse_initial_message_line(), MHD_Connection::pid, process_broken_line(), process_header_line(), process_request_body(), MHD_Connection::read_buffer, MHD_Connection::read_buffer_offset, MHD_Connection::read_closed, MHD_Connection::remaining_upload_size, REQUEST_MALFORMED, MHD_Connection::response, MHD_Connection::response_write_position, MHD_Connection::responseCode, MHD_Connection::rp_props, MHD_Reply_Properties::send_reply_body, MHD_Connection::state, MHD_Connection::suspended, MHD_Response::total_size, transmit_error_response_static, try_ready_chunked_body(), try_ready_normal_body(), MHD_Connection::write_buffer_append_offset, and MHD_Connection::write_buffer_send_offset.
Referenced by call_handlers(), and MHD_queue_response().
void MHD_connection_handle_read | ( | struct MHD_Connection * | connection, |
bool | socket_error | ||
) |
This function handles a particular connection when it has been determined that there is data to be read off a socket. All implementations (multithreaded, external polling, internal polling) call this function to handle reads.
connection | connection to handle |
socket_error | set to true if socket error was detected |
Definition at line 3668 of file connection.c.
References _, CONNECTION_CLOSE_ERROR, MHD_Connection::daemon, MHD_Connection::discard_request, mhd_assert, MHD_CONNECTION_BODY_RECEIVED, MHD_connection_close_(), MHD_CONNECTION_CLOSED, MHD_CONNECTION_CONTINUE_SENDING, MHD_CONNECTION_CONTINUE_SENT, MHD_CONNECTION_FOOTER_PART_RECEIVED, MHD_CONNECTION_FULL_REQ_RECEIVED, MHD_CONNECTION_HEADER_PART_RECEIVED, MHD_CONNECTION_HEADERS_PROCESSED, MHD_CONNECTION_HEADERS_RECEIVED, MHD_CONNECTION_INIT, MHD_CONNECTION_REQ_LINE_RECEIVING, MHD_CONNECTION_URL_RECEIVED, MHD_ERR_AGAIN_, MHD_ERR_CONNRESET_, MHD_FUNC_, MHD_pool_reallocate(), MHD_REQUEST_TERMINATED_CLIENT_ABORT, MHD_REQUEST_TERMINATED_COMPLETED_OK, MHD_REQUEST_TERMINATED_READ_ERROR, MHD_REQUEST_TERMINATED_WITH_ERROR, MHD_run_tls_handshake_(), MHD_TLS_CONN_CONNECTED, MHD_TLS_CONN_NO_TLS, MHD_update_last_activity_(), NULL, MHD_Connection::pool, MHD_Daemon::pool_increment, MHD_Connection::read_buffer, MHD_Connection::read_buffer_offset, MHD_Connection::read_buffer_size, MHD_Connection::read_closed, MHD_Connection::recv_cls, MHD_Connection::sk_nonblck, MHD_Connection::state, MHD_Connection::suspended, and try_grow_read_buffer().
Referenced by call_handlers().
void MHD_connection_handle_write | ( | struct MHD_Connection * | connection | ) |
This function was created to handle writes to sockets when it has been determined that the socket can be written to.
connection | connection to handle |
Definition at line 3826 of file connection.c.
References _, check_write_done(), MHD_Reply_Properties::chunked, CONNECTION_CLOSE_ERROR, MHD_Connection::continue_message_write_offset, MHD_Response::crc, MHD_Connection::daemon, MHD_Response::data, MHD_Response::data_iov, MHD_Response::data_size, MHD_Response::data_start, HTTP_100_CONTINUE, MHD_Connection::keepalive, mhd_assert, MHD_CONN_MUST_UPGRADE, MHD_CONNECTION_BODY_RECEIVED, MHD_CONNECTION_BODY_SENT, MHD_CONNECTION_CHUNKED_BODY_READY, MHD_CONNECTION_CHUNKED_BODY_UNREADY, MHD_CONNECTION_CLOSED, MHD_CONNECTION_CONTINUE_SENDING, MHD_CONNECTION_CONTINUE_SENT, MHD_CONNECTION_FOOTER_PART_RECEIVED, MHD_CONNECTION_FOOTERS_RECEIVED, MHD_CONNECTION_FOOTERS_SENDING, MHD_CONNECTION_FOOTERS_SENT, MHD_CONNECTION_FULL_REQ_RECEIVED, MHD_CONNECTION_HEADER_PART_RECEIVED, MHD_CONNECTION_HEADERS_PROCESSED, MHD_CONNECTION_HEADERS_RECEIVED, MHD_CONNECTION_HEADERS_SENDING, MHD_CONNECTION_HEADERS_SENT, MHD_CONNECTION_INIT, MHD_CONNECTION_NORMAL_BODY_READY, MHD_CONNECTION_NORMAL_BODY_UNREADY, MHD_CONNECTION_REQ_LINE_RECEIVING, MHD_CONNECTION_START_REPLY, MHD_CONNECTION_URL_RECEIVED, MHD_ERR_AGAIN_, MHD_FUNC_, MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_NO, MHD_PANIC, MHD_run_tls_handshake_(), MHD_send_data_(), MHD_send_hdr_and_body_(), MHD_send_iovec_(), MHD_SIZE_UNKNOWN, MHD_STATICSTR_LEN_, MHD_TLS_CONN_CONNECTED, MHD_TLS_CONN_NO_TLS, MHD_update_last_activity_(), MHD_Response::mutex, NULL, MHD_Connection::resp_iov, MHD_Connection::response, MHD_Connection::response_write_position, MHD_Connection::rp_props, MHD_Reply_Properties::send_reply_body, SIZE_MAX, MHD_Connection::state, MHD_Connection::suspended, MHD_Response::total_size, try_ready_normal_body(), MHD_Connection::url, MHD_Connection::write_buffer, MHD_Connection::write_buffer_append_offset, and MHD_Connection::write_buffer_send_offset.
Referenced by call_handlers().
void MHD_connection_mark_closed_ | ( | struct MHD_Connection * | connection | ) |
Mark connection as "closed".
connection | connection to close |
Definition at line 792 of file connection.c.
References MHD_Connection::daemon, MHD_Connection::event_loop_info, MHD_CONNECTION_CLOSED, MHD_EVENT_LOOP_INFO_CLEANUP, MHD_tls_connection_shutdown(), MHD_USE_TLS, MHD_USE_TURBO, MHD_Daemon::options, MHD_Daemon::shutdown, MHD_Connection::socket_fd, and MHD_Connection::state.
Referenced by MHD_connection_close_().
|
static |
Update the 'event_loop_info' field of this connection based on the state that the connection is now in. May also close the connection or perform other updates to the connection if needed to prepare for the next round of the event loop.
connection | connection to get poll set for |
Definition at line 2407 of file connection.c.
References _, CONNECTION_CLOSE_ERROR, MHD_Connection::daemon, MHD_Connection::discard_request, MHD_Connection::event_loop_info, INTERNAL_ERROR, mhd_assert, MHD_CONNECTION_BODY_RECEIVED, MHD_CONNECTION_BODY_SENT, MHD_CONNECTION_CHUNKED_BODY_READY, MHD_CONNECTION_CHUNKED_BODY_UNREADY, MHD_CONNECTION_CLOSED, MHD_CONNECTION_CONTINUE_SENDING, MHD_CONNECTION_CONTINUE_SENT, MHD_CONNECTION_FOOTER_PART_RECEIVED, MHD_CONNECTION_FOOTERS_RECEIVED, MHD_CONNECTION_FOOTERS_SENDING, MHD_CONNECTION_FOOTERS_SENT, MHD_CONNECTION_FULL_REQ_RECEIVED, MHD_CONNECTION_HEADER_PART_RECEIVED, MHD_CONNECTION_HEADERS_PROCESSED, MHD_CONNECTION_HEADERS_RECEIVED, MHD_CONNECTION_HEADERS_SENDING, MHD_CONNECTION_HEADERS_SENT, MHD_CONNECTION_INIT, MHD_CONNECTION_NORMAL_BODY_READY, MHD_CONNECTION_NORMAL_BODY_UNREADY, MHD_CONNECTION_REQ_LINE_RECEIVING, MHD_CONNECTION_START_REPLY, MHD_CONNECTION_URL_RECEIVED, MHD_EVENT_LOOP_INFO_BLOCK, MHD_EVENT_LOOP_INFO_CLEANUP, MHD_EVENT_LOOP_INFO_READ, MHD_EVENT_LOOP_INFO_WRITE, MHD_FUNC_, MHD_HTTP_INTERNAL_SERVER_ERROR, MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE, MHD_HTTP_URI_TOO_LONG, MHD_TLS_CONN_HANDSHAKING, MHD_TLS_CONN_INIT, MHD_TLS_CONN_NO_TLS, MHD_USE_INTERNAL_POLLING_THREAD, NULL, MHD_Daemon::options, MHD_Connection::read_buffer_offset, MHD_Connection::read_buffer_size, MHD_Connection::read_closed, REQUEST_TOO_BIG, MHD_Connection::state, MHD_Connection::suspended, transmit_error_response_static, try_grow_read_buffer(), and MHD_Connection::url.
Referenced by MHD_connection_handle_idle().
|
static |
Check whether request header contains particular token.
Token could be surrounded by spaces and tabs and delimited by comma. Case-insensitive match used for header names and tokens.
connection | the connection to get values from |
header | the header name |
header_len | the length of header, not including optional terminating null-character |
token | the token to find |
token_len | the length of token, not including optional terminating null-character. |
Definition at line 713 of file connection.c.
References MHD_HTTP_Header::header, MHD_HTTP_Header::header_size, MHD_Connection::headers_received, MHD_HTTP_Header::kind, MHD_HEADER_KIND, MHD_str_equal_caseless_bin_n_(), MHD_str_has_token_caseless_(), MHD_HTTP_Header::next, NULL, and MHD_HTTP_Header::value.
void MHD_set_http_callbacks_ | ( | struct MHD_Connection * | connection | ) |
Set callbacks for this connection to those for HTTP.
connection | connection to initialize |
Definition at line 4909 of file connection.c.
References MHD_Connection::recv_cls, and recv_param_adapter().
Referenced by new_connection_prepare_().
void MHD_update_last_activity_ | ( | struct MHD_Connection * | connection | ) |
Update the 'last_activity' field of the connection to the current time and move the connection to the head of the 'normal_timeout' list if the timeout for the connection uses the default value.
connection | the connection that saw some activity |
Definition at line 3626 of file connection.c.
References MHD_Daemon::cleanup_connection_mutex, MHD_Connection::connection_timeout_ms, MHD_Daemon::connection_timeout_ms, MHD_Connection::daemon, MHD_Connection::last_activity, MHD_monotonic_msec_counter(), MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_USE_THREAD_PER_CONNECTION, MHD_Daemon::normal_timeout_head, MHD_Daemon::normal_timeout_tail, MHD_Daemon::options, MHD_Connection::suspended, XDLL_insert, and XDLL_remove.
Referenced by MHD_connection_handle_read(), MHD_connection_handle_write(), and MHD_queue_response().
|
static |
Do we (still) need to send a 100 continue message for this connection?
connection | connection to test |
Definition at line 768 of file connection.c.
References MHD_Connection::http_ver, MHD_HEADER_KIND, MHD_HTTP_HEADER_EXPECT, MHD_IS_HTTP_VER_1_1_COMPAT, MHD_lookup_connection_value_n(), MHD_NO, MHD_STATICSTR_LEN_, MHD_str_equal_caseless_(), and NULL.
Referenced by MHD_connection_handle_idle().
|
static |
Parse the various headers; figure out the size of the upload and make sure the headers follow the protocol. Advance to the appropriate state.
connection | connection we're processing |
Definition at line 3527 of file connection.c.
References _, MHD_Connection::daemon, MHD_Connection::have_chunked_upload, MHD_Connection::http_ver, MHD_HEADER_KIND, MHD_HTTP_BAD_REQUEST, MHD_HTTP_CONTENT_TOO_LARGE, MHD_HTTP_HEADER_CONTENT_LENGTH, MHD_HTTP_HEADER_HOST, MHD_HTTP_HEADER_TRANSFER_ENCODING, MHD_IS_HTTP_VER_1_1_COMPAT, MHD_lookup_connection_value_n(), MHD_NO, MHD_SIZE_UNKNOWN, MHD_STATICSTR_LEN_, MHD_str_equal_caseless_(), MHD_str_to_uint64_n_(), NULL, parse_cookie_header(), MHD_Connection::remaining_upload_size, REQUEST_CONTENTLENGTH_MALFORMED, REQUEST_CONTENTLENGTH_TOOLARGE, REQUEST_LACKS_HOST, MHD_Daemon::strict_for_client, and transmit_error_response_static.
Referenced by MHD_connection_handle_idle().
|
static |
Parse the cookie header (see RFC 2109).
connection | connection to parse header of |
Definition at line 2696 of file connection.c.
References _, connection_add_header(), connection_alloc_memory(), MHD_Connection::daemon, MHD_COOKIE_KIND, MHD_HEADER_KIND, MHD_HTTP_HEADER_COOKIE, MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE, MHD_lookup_connection_value_n(), MHD_NO, MHD_STATICSTR_LEN_, MHD_YES, NULL, REQUEST_TOO_BIG, and transmit_error_response_static.
Referenced by parse_connection_headers().
|
static |
Detect standard HTTP request method
connection | the connection |
method | the pointer to HTTP request method string |
len | the length of method in bytes |
< short alias
Definition at line 2885 of file connection.c.
References MHD_Connection::http_mthd, mhd_assert, MHD_HTTP_METHOD_CONNECT, MHD_HTTP_METHOD_DELETE, MHD_HTTP_METHOD_GET, MHD_HTTP_METHOD_HEAD, MHD_HTTP_METHOD_OPTIONS, MHD_HTTP_METHOD_POST, MHD_HTTP_METHOD_PUT, MHD_HTTP_METHOD_TRACE, MHD_HTTP_MTHD_CONNECT, MHD_HTTP_MTHD_DELETE, MHD_HTTP_MTHD_GET, MHD_HTTP_MTHD_HEAD, MHD_HTTP_MTHD_OPTIONS, MHD_HTTP_MTHD_OTHER, MHD_HTTP_MTHD_POST, MHD_HTTP_MTHD_PUT, MHD_HTTP_MTHD_TRACE, MHD_NO, MHD_STATICSTR_LEN_, MHD_YES, and NULL.
Referenced by parse_initial_message_line().
|
static |
Detect HTTP version
connection | the connection |
http_string | the pointer to HTTP version string |
len | the length of http_string in bytes |
< short alias
Definition at line 2822 of file connection.c.
References MHD_Connection::http_ver, mhd_assert, MHD_HTTP_BAD_REQUEST, MHD_HTTP_HTTP_VERSION_NOT_SUPPORTED, MHD_HTTP_VER_1_0, MHD_HTTP_VER_1_1, MHD_HTTP_VER_1_2__1_9, MHD_HTTP_VER_FUTURE, MHD_HTTP_VER_INVALID, MHD_HTTP_VER_TOO_OLD, MHD_NO, MHD_YES, NULL, REQ_HTTP_VER_IS_NOT_SUPPORTED, REQ_HTTP_VER_IS_TOO_OLD, REQUEST_MALFORMED, and transmit_error_response_static.
Referenced by parse_initial_message_line().
|
static |
Parse the first line of the HTTP HEADER.
connection | the connection (updated) |
line | the first line, not 0-terminated |
line_len | length of the first line |
Definition at line 2936 of file connection.c.
References MHD_Connection::client_aware, MHD_Connection::client_context, connection_add_header(), MHD_Connection::daemon, MHD_Connection::method, MHD_GET_ARGUMENT_KIND, MHD_NO, MHD_parse_arguments_(), MHD_YES, NULL, parse_http_std_method(), parse_http_version(), MHD_Daemon::strict_for_client, MHD_Daemon::unescape_callback, MHD_Daemon::unescape_callback_cls, MHD_Daemon::uri_log_callback, MHD_Daemon::uri_log_callback_cls, MHD_Connection::url, and MHD_Connection::version.
Referenced by MHD_connection_handle_idle().
|
static |
Process a header value that spans multiple lines. The previous line(s) are in connection->last.
connection | connection we're processing |
line | the current input line |
kind | if the line is complete, add a header of the given kind |
Definition at line 3468 of file connection.c.
References MHD_Connection::colon, connection_add_header(), MHD_Connection::last, mhd_assert, MHD_HTTP_BAD_REQUEST, MHD_NO, MHD_YES, NULL, process_header_line(), REQUEST_MALFORMED, and transmit_error_response_static.
Referenced by MHD_connection_handle_idle().
|
static |
We have received (possibly the beginning of) a line in the header (or footer). Validate (check for ":") and prepare to process.
connection | connection we're processing |
line | line from the header to process |
Definition at line 3411 of file connection.c.
References MHD_Connection::colon, MHD_Connection::daemon, MHD_Connection::last, MHD_NO, MHD_YES, NULL, and MHD_Daemon::strict_for_client.
Referenced by MHD_connection_handle_idle(), and process_broken_line().
|
static |
Call the handler of the application for this connection. Handles chunking of the upload as well as normal uploads.
connection | connection we're processing |
The length of the string with the number of the chunk size
< first digit
Definition at line 3097 of file connection.c.
References _, MHD_Connection::client_aware, MHD_Connection::client_context, CONNECTION_CLOSE_ERROR, MHD_Connection::current_chunk_offset, MHD_Connection::current_chunk_size, MHD_Connection::daemon, MHD_Daemon::default_handler, MHD_Daemon::default_handler_cls, MHD_Connection::have_chunked_upload, MHD_Connection::method, mhd_assert, MHD_HTTP_BAD_REQUEST, MHD_HTTP_CONTENT_TOO_LARGE, MHD_MIN, MHD_NO, mhd_panic, mhd_panic_cls, MHD_SIZE_UNKNOWN, MHD_strx_to_uint64_n_(), MHD_USE_INTERNAL_POLLING_THREAD, NULL, MHD_Daemon::options, MHD_Connection::read_buffer, MHD_Connection::read_buffer_offset, MHD_Connection::remaining_upload_size, REQUEST_CHUNK_TOO_LARGE, REQUEST_CHUNKED_MALFORMED, MHD_Connection::response, MHD_Connection::suspended, transmit_error_response_static, MHD_Connection::url, and MHD_Connection::version.
Referenced by MHD_connection_handle_idle().
|
static |
Callback for receiving data from the socket.
connection | the MHD connection structure |
other | where to write received data to |
i | maximum size of other (in bytes) |
Definition at line 316 of file connection.c.
References MHD_CONNECTION_CLOSED, MHD_EPOLL_STATE_READ_READY, MHD_ERR_AGAIN_, MHD_ERR_BADF_, MHD_ERR_CONNRESET_, MHD_ERR_INVAL_, MHD_ERR_NOMEM_, MHD_ERR_NOTCONN_, MHD_ERR_OPNOTSUPP_, MHD_INVALID_SOCKET, MHD_recv_, MHD_SCKT_EBADF_, MHD_SCKT_EINVAL_, MHD_SCKT_ENOTCONN_, MHD_SCKT_EOPNOTSUPP_, MHD_SCKT_ERR_IS_, MHD_SCKT_ERR_IS_EAGAIN_, MHD_SCKT_ERR_IS_EINTR_, MHD_SCKT_ERR_IS_LOW_RESOURCES_, MHD_SCKT_ERR_IS_REMOTE_DISCNN_, MHD_SCKT_SEND_MAX_SIZE_, MHD_socket_get_error_, MHD_Connection::socket_fd, and MHD_Connection::state.
Referenced by MHD_set_http_callbacks_().
|
static |
Setup connection reply properties.
Reply properties include presence of reply body, transfer-encoding type and other.
connection | to connection to process |
reply_body_allowed |
< a short alias
< a short alias
Definition at line 1763 of file connection.c.
References MHD_Reply_Properties::chunked, MHD_Response::flags, MHD_Response::flags_auto, MHD_Connection::http_ver, is_reply_body_headers_needed(), is_reply_body_needed(), MHD_Connection::keepalive, keepalive_possible(), mhd_assert, MHD_CONN_MUST_CLOSE, MHD_IS_HTTP_VER_1_1_COMPAT, MHD_RAF_HAS_TRANS_ENC_CHUNKED, MHD_RF_HTTP_1_0_COMPATIBLE_STRICT, MHD_RF_HTTP_1_0_SERVER, MHD_SIZE_UNKNOWN, NULL, MHD_Connection::response, MHD_Connection::rp_props, MHD_Reply_Properties::send_reply_body, MHD_Reply_Properties::set, MHD_Response::total_size, and MHD_Reply_Properties::use_reply_body_headers.
Referenced by build_header_response().
|
static |
We encountered an error processing the request. Handle it properly by stopping to read data and sending the indicated response code and message.
connection | the connection |
status_code | the response code to send (400, 413 or 414) |
message | the error message to send |
message_len | the length of the message |
Definition at line 2272 of file connection.c.
References _, build_header_response(), MHD_Connection::colon, CONNECTION_CLOSE_ERROR, MHD_Connection::daemon, MHD_Connection::discard_request, MHD_Connection::headers_received, MHD_Connection::headers_received_tail, MHD_Connection::keepalive, MHD_Connection::last, MHD_Connection::method, mhd_assert, MHD_CONN_MUST_CLOSE, MHD_CONNECTION_CLOSED, MHD_CONNECTION_FULL_REQ_RECEIVED, MHD_CONNECTION_HEADERS_SENDING, MHD_create_response_from_buffer(), MHD_destroy_response(), MHD_NO, MHD_pool_reallocate(), MHD_pool_reset(), MHD_queue_response(), MHD_RESPMEM_PERSISTENT, NULL, MHD_Connection::pool, MHD_Connection::read_buffer, MHD_Connection::read_buffer_offset, MHD_Connection::read_buffer_size, MHD_Connection::response, MHD_Connection::state, MHD_Response::status_code, MHD_Connection::stop_with_error, MHD_Connection::url, MHD_Connection::version, MHD_Connection::write_buffer, MHD_Connection::write_buffer_append_offset, MHD_Connection::write_buffer_send_offset, and MHD_Connection::write_buffer_size.
|
static |
Try growing the read buffer. We initially claim half the available buffer space for the read buffer (the other half being left for management data structures; the write buffer can in the end take virtually everything as the read buffer can be reduced to the minimum necessary at that point.
connection | the connection |
required | set to 'true' if grow is required, i.e. connection will fail if no additional space is granted |
Definition at line 1487 of file connection.c.
References mhd_assert, MHD_BUF_INC_SIZE, MHD_pool_get_free(), MHD_pool_reallocate(), NULL, MHD_Connection::pool, MHD_Connection::read_buffer, and MHD_Connection::read_buffer_size.
Referenced by get_next_header_line(), MHD_connection_handle_read(), and MHD_connection_update_event_loop_info().
|
static |
Prepare the response buffer of this connection for sending. Assumes that the response mutex is already held. If the transmission is complete, this function may close the socket (and return MHD_NO).
connection | the connection | |
[out] | p_finished | the pointer to variable that will be set to "true" when application returned indication of the end of the stream |
Definition at line 1124 of file connection.c.
References _, CONNECTION_CLOSE_ERROR, MHD_Response::crc, MHD_Response::crc_cls, MHD_Response::data, MHD_Response::data_size, MHD_Response::data_start, mhd_assert, MHD_CONNECTION_CHUNKED_BODY_UNREADY, MHD_CONTENT_READER_END_OF_STREAM, MHD_CONTENT_READER_END_WITH_ERROR, MHD_mutex_unlock_chk_, MHD_NO, MHD_pool_get_free(), MHD_pool_reallocate(), MHD_SIZE_UNKNOWN, MHD_uint32_to_strx(), MHD_YES, MHD_Response::mutex, NULL, MHD_Connection::pool, MHD_Connection::response, MHD_Connection::response_write_position, MHD_Connection::state, MHD_Response::total_size, MHD_Connection::write_buffer, MHD_Connection::write_buffer_append_offset, MHD_Connection::write_buffer_send_offset, and MHD_Connection::write_buffer_size.
Referenced by MHD_connection_handle_idle().
|
static |
Prepare the response buffer of this connection for sending. Assumes that the response mutex is already held. If the transmission is complete, this function may close the socket (and return MHD_NO).
connection | the connection |
Definition at line 1022 of file connection.c.
References _, MHD_iovec_track_::cnt, connection_alloc_memory(), CONNECTION_CLOSE_ERROR, MHD_Response::crc, MHD_Response::crc_cls, MHD_Response::data, MHD_Response::data_buffer_size, MHD_Response::data_iov, MHD_Response::data_iovcnt, MHD_Response::data_size, MHD_Response::data_start, MHD_iovec_track_::iov, mhd_assert, MHD_connection_close_(), MHD_CONNECTION_NORMAL_BODY_UNREADY, MHD_CONTENT_READER_END_OF_STREAM, MHD_MIN, MHD_mutex_unlock_chk_, MHD_NO, MHD_REQUEST_TERMINATED_COMPLETED_OK, MHD_YES, MHD_Response::mutex, NULL, MHD_Connection::resp_iov, MHD_Connection::response, MHD_Connection::response_write_position, MHD_Connection::rp_props, MHD_Reply_Properties::send_reply_body, MHD_iovec_track_::sent, MHD_Connection::state, and MHD_Response::total_size.
Referenced by MHD_connection_handle_idle(), and MHD_connection_handle_write().