GNU libmicrohttpd  0.9.72
connection_call_handlers.c File Reference

call the connection's handlers based on the event trigger More...

Include dependency graph for connection_call_handlers.c:

Go to the source code of this file.

Macros

#define MHD_SENFILE_CHUNK_   (0x20000)
 
#define MHD_SENFILE_CHUNK_THR_P_C_   (0x200000)
 
#define REQUEST_TOO_BIG   ""
 
#define REQUEST_LACKS_HOST   ""
 
#define REQUEST_MALFORMED   ""
 
#define INTERNAL_ERROR   ""
 
#define HTTP_100_CONTINUE   "HTTP/1.1 100 Continue\r\n\r\n"
 
#define CONNECTION_CLOSE_ERROR(c, sc, emsg)   connection_close_error (c, sc, NULL)
 
#define MHD_lookup_header_s_token_ci(r, h, tkn)    MHD_lookup_header_token_ci ((r),(h),(tkn),MHD_STATICSTR_LEN_ (tkn))
 
#define check_response_header_s_token_ci(r, k, tkn)    check_response_header_token_ci ((r),(k),(tkn),MHD_STATICSTR_LEN_ (tkn))
 

Functions

static void connection_close_error (struct MHD_Connection *connection, enum MHD_StatusCode sc, const char *emsg)
 
static bool try_grow_read_buffer (struct MHD_Request *request)
 
static void MHD_request_handle_read_ (struct MHD_Request *request)
 
static bool check_write_done (struct MHD_Request *request, enum MHD_REQUEST_STATE next_state)
 
static bool try_ready_normal_body (struct MHD_Request *request)
 
static bool try_ready_chunked_body (struct MHD_Request *request)
 
static void MHD_request_handle_write_ (struct MHD_Request *request)
 
static bool MHD_lookup_header_token_ci (const struct MHD_Request *request, const char *header, const char *token, size_t token_len)
 
static bool keepalive_possible (struct MHD_Request *request)
 
static void get_date_string (char *date, size_t date_len)
 
static bool check_response_header_token_ci (const struct MHD_Response *response, const char *key, const char *token, size_t token_len)
 
static bool build_header_response (struct MHD_Request *request)
 
static void transmit_error_response (struct MHD_Request *request, enum MHD_StatusCode ec, enum MHD_HTTP_StatusCode status_code, const char *message)
 
static enum MHD_Method method_string_to_enum (const char *method)
 
static bool request_add_header (struct MHD_Request *request, const char *key, const char *value, enum MHD_ValueKind kind)
 
static bool parse_initial_message_line (struct MHD_Request *request, char *line, size_t line_len)
 
static bool process_header_line (struct MHD_Request *request, char *line)
 
static bool process_broken_line (struct MHD_Request *request, char *line, enum MHD_ValueKind kind)
 
static char * get_next_header_line (struct MHD_Request *request, size_t *line_len)
 
static bool socket_flush_possible (struct MHD_Connection *connection)
 
static bool socket_start_extra_buffering (struct MHD_Connection *connection)
 
static bool socket_start_no_buffering (struct MHD_Connection *connection)
 
static bool socket_start_no_buffering_flush (struct MHD_Connection *connection)
 
static bool socket_start_normal_buffering (struct MHD_Connection *connection)
 
static bool need_100_continue (struct MHD_Request *request)
 
static int parse_cookie_header (struct MHD_Request *request)
 
static void parse_request_headers (struct MHD_Request *request)
 
static void call_request_handler (struct MHD_Request *request)
 
static void process_request_body (struct MHD_Request *request)
 
static void cleanup_connection (struct MHD_Connection *connection)
 
static void connection_update_event_loop_info (struct MHD_Connection *connection)
 
bool MHD_request_handle_idle_ (struct MHD_Request *request)
 
int MHD_connection_call_handlers_ (struct MHD_Connection *con, bool read_ready, bool write_ready, bool force_close)
 

Detailed Description

call the connection's handlers based on the event trigger

Author
Christian Grothoff

Definition in file connection_call_handlers.c.

Macro Definition Documentation

◆ check_response_header_s_token_ci

#define check_response_header_s_token_ci (   r,
  k,
  tkn 
)     check_response_header_token_ci ((r),(k),(tkn),MHD_STATICSTR_LEN_ (tkn))

Check whether response 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.

Parameters
rthe response to query
kheader name
tknthe static string of token to find
Returns
true if token is found in specified header, false otherwise

Definition at line 1227 of file connection_call_handlers.c.

◆ CONNECTION_CLOSE_ERROR

#define CONNECTION_CLOSE_ERROR (   c,
  sc,
  emsg 
)    connection_close_error (c, sc, NULL)

Macro to only include error message in call to connection_close_error() if we have HAVE_MESSAGES.

Definition at line 194 of file connection_call_handlers.c.

◆ HTTP_100_CONTINUE

#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 157 of file connection_call_handlers.c.

◆ INTERNAL_ERROR

#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 103 of file connection_call_handlers.c.

◆ MHD_lookup_header_s_token_ci

#define MHD_lookup_header_s_token_ci (   r,
  h,
  tkn 
)     MHD_lookup_header_token_ci ((r),(h),(tkn),MHD_STATICSTR_LEN_ (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.

Parameters
rthe request to get values from
hthe header name
tknthe static string of token to find
Returns
true if token is found in specified header, false otherwise

Definition at line 1058 of file connection_call_handlers.c.

◆ MHD_SENFILE_CHUNK_

#define MHD_SENFILE_CHUNK_   (0x20000)

sendfile() chuck size

Definition at line 43 of file connection_call_handlers.c.

◆ MHD_SENFILE_CHUNK_THR_P_C_

#define MHD_SENFILE_CHUNK_THR_P_C_   (0x200000)

sendfile() chuck size for thread-per-connection

Definition at line 48 of file connection_call_handlers.c.

◆ REQUEST_LACKS_HOST

#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 76 of file connection_call_handlers.c.

◆ REQUEST_MALFORMED

#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 90 of file connection_call_handlers.c.

◆ REQUEST_TOO_BIG

#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 62 of file connection_call_handlers.c.

Function Documentation

◆ build_header_response()

static bool build_header_response ( struct MHD_Request request)
static

Allocate the connection's write buffer and fill it with all of the headers (or footers, if we have already sent the body) from the HTTPd's response. If headers are missing in the response supplied by the application, additional headers may be added here.

Parameters
requestthe request for which to build the response header
Returns
true on success, false on failure (out of memory)

Definition at line 1241 of file connection_call_handlers.c.

References check_response_header_s_token_ci, MHD_Request::connection, MHD_Request::daemon, data, MHD_Response::first_header, get_date_string(), MHD_Request::have_chunked_upload, MHD_HTTP_Header::header, MHD_Response::icy, MHD_Request::keepalive, keepalive_possible(), MHD_HTTP_Header::kind, MHD_Request::method, mhd_assert, MHD_CONN_MUST_CLOSE, MHD_CONN_USE_KEEPALIVE, MHD_FOOTER_KIND, MHD_get_reason_phrase_for(), MHD_HEADER_KIND, MHD_HTTP_HEADER_CONNECTION, MHD_HTTP_HEADER_CONTENT_LENGTH, MHD_HTTP_HEADER_DATE, MHD_HTTP_HEADER_TRANSFER_ENCODING, MHD_HTTP_NO_CONTENT, MHD_HTTP_NOT_MODIFIED, MHD_HTTP_VERSION_1_0, MHD_HTTP_VERSION_1_1, MHD_lookup_header_s_token_ci, MHD_NO, mhd_panic, mhd_panic_cls, MHD_pool_allocate(), MHD_REQUEST_BODY_SENT, MHD_REQUEST_FOOTERS_RECEIVED, MHD_response_get_header(), MHD_SIZE_UNKNOWN, MHD_STATICSTR_LEN_, MHD_str_equal_caseless_(), MHD_UNSIGNED_LONG_LONG, MHD_UNSIGNED_LONG_LONG_PRINTF, MHD_YES, MHD_HTTP_Header::next, NULL, MHD_Connection::pool, MHD_Connection::read_closed, MHD_Connection::request, MHD_Request::response, MHD_Request::state, MHD_Response::status_code, MHD_Daemon::suppress_date, MHD_Response::total_size, MHD_Response::v10_only, MHD_HTTP_Header::value, MHD_Request::version_s, MHD_Request::write_buffer, MHD_Request::write_buffer_append_offset, MHD_Request::write_buffer_send_offset, and MHD_Request::write_buffer_size.

Referenced by method_string_to_enum(), and MHD_request_handle_idle_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ call_request_handler()

static void call_request_handler ( struct MHD_Request request)
static

Call the handler of the application for this request.

Parameters
requestrequest we're processing

Definition at line 2547 of file connection_call_handlers.c.

References _, MHD_Action::action, MHD_Request::connection, CONNECTION_CLOSE_ERROR, MHD_Request::daemon, MHD_Request::method, NULL, MHD_Daemon::rc, MHD_Daemon::rc_cls, MHD_Connection::request, MHD_Request::response, and MHD_Request::url.

Referenced by MHD_request_handle_idle_().

Here is the caller graph for this function:

◆ check_response_header_token_ci()

static bool check_response_header_token_ci ( const struct MHD_Response response,
const char *  key,
const char *  token,
size_t  token_len 
)
static

Check whether response 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.

Parameters
responsethe response to query
keyheader name
tokenthe token to find
token_lenthe length of token, not including optional terminating null-character.
Returns
true if token is found in specified header, false otherwise

Definition at line 1187 of file connection_call_handlers.c.

References MHD_Response::first_header, MHD_HTTP_Header::header, MHD_HTTP_Header::kind, MHD_HEADER_KIND, MHD_str_equal_caseless_(), MHD_str_has_token_caseless_(), MHD_HTTP_Header::next, NULL, and MHD_HTTP_Header::value.

Here is the call graph for this function:

◆ check_write_done()

static bool check_write_done ( struct MHD_Request request,
enum MHD_REQUEST_STATE  next_state 
)
static

Check if we are done sending the write-buffer. If so, transition into "next_state".

Parameters
connectionconnection to check write status for
next_statethe next state to transition to
Returns
false if we are not done, true if we are

Definition at line 551 of file connection_call_handlers.c.

References MHD_Request::connection, MHD_pool_reallocate(), NULL, MHD_Connection::pool, MHD_Request::state, MHD_Request::write_buffer, MHD_Request::write_buffer_append_offset, MHD_Request::write_buffer_send_offset, and MHD_Request::write_buffer_size.

Referenced by MHD_request_handle_write_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleanup_connection()

◆ connection_close_error()

static void connection_close_error ( struct MHD_Connection connection,
enum MHD_StatusCode  sc,
const char *  emsg 
)
static

A serious error occurred, close the connection (and notify the application).

Parameters
connectionconnection to close with error
scthe reason for closing the connection
emsgerror message (can be NULL)

Definition at line 169 of file connection_call_handlers.c.

References MHD_Connection::daemon, MHD_connection_close_(), MHD_REQUEST_TERMINATED_WITH_ERROR, and NULL.

Here is the call graph for this function:

◆ connection_update_event_loop_info()

static void connection_update_event_loop_info ( struct MHD_Connection connection)
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.

Parameters
connectionconnection to get poll set for

Definition at line 2942 of file connection_call_handlers.c.

References _, MHD_TLS_Plugin::cls, MHD_Request::connection, CONNECTION_CLOSE_ERROR, MHD_Connection::daemon, MHD_Request::event_loop_info, INTERNAL_ERROR, mhd_assert, MHD_EVENT_LOOP_INFO_BLOCK, MHD_EVENT_LOOP_INFO_CLEANUP, MHD_EVENT_LOOP_INFO_READ, MHD_EVENT_LOOP_INFO_WRITE, MHD_HTTP_INTERNAL_SERVER_ERROR, MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE, MHD_HTTP_URI_TOO_LONG, MHD_REQUEST_BODY_RECEIVED, MHD_REQUEST_BODY_SENT, MHD_REQUEST_CHUNKED_BODY_READY, MHD_REQUEST_CHUNKED_BODY_UNREADY, MHD_REQUEST_CLOSED, MHD_REQUEST_CONTINUE_SENDING, MHD_REQUEST_CONTINUE_SENT, MHD_REQUEST_FOOTER_PART_RECEIVED, MHD_REQUEST_FOOTERS_RECEIVED, MHD_REQUEST_FOOTERS_SENDING, MHD_REQUEST_FOOTERS_SENT, MHD_REQUEST_HEADER_PART_RECEIVED, MHD_REQUEST_HEADERS_PROCESSED, MHD_REQUEST_HEADERS_RECEIVED, MHD_REQUEST_HEADERS_SENDING, MHD_REQUEST_HEADERS_SENT, MHD_REQUEST_INIT, MHD_REQUEST_NORMAL_BODY_READY, MHD_REQUEST_NORMAL_BODY_UNREADY, MHD_REQUEST_URL_RECEIVED, NULL, MHD_Request::read_buffer_offset, MHD_Request::read_buffer_size, MHD_Connection::read_closed, MHD_Connection::request, REQUEST_TOO_BIG, MHD_Request::state, MHD_Connection::suspended, MHD_Daemon::threading_mode, transmit_error_response(), try_grow_read_buffer(), MHD_TLS_Plugin::update_event_loop_info, and MHD_Request::url.

Referenced by MHD_request_handle_idle_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_date_string()

static void get_date_string ( char *  date,
size_t  date_len 
)
static

Produce HTTP time stamp.

Parameters
datewhere to write the header, with at least 128 bytes available space.
date_lennumber of bytes in date

Definition at line 1123 of file connection_call_handlers.c.

References NULL.

Referenced by build_header_response().

Here is the caller graph for this function:

◆ get_next_header_line()

static char* get_next_header_line ( struct MHD_Request request,
size_t *  line_len 
)
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.

Parameters
requestrequest we're processing
[out]line_lenpointer to variable that receive length of line or NULL
Returns
NULL if no full line is available; note that the returned string will not be 0-termianted

Definition at line 2040 of file connection_call_handlers.c.

References MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE, MHD_HTTP_URI_TOO_LONG, NULL, MHD_Request::read_buffer, MHD_Request::read_buffer_offset, MHD_Connection::read_buffer_offset, MHD_Request::read_buffer_size, MHD_Connection::request, REQUEST_TOO_BIG, transmit_error_response(), try_grow_read_buffer(), and MHD_Request::url.

Referenced by MHD_request_handle_idle_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ keepalive_possible()

static bool keepalive_possible ( struct MHD_Request request)
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 (which is conservative for HTTP 1.0, but might be a bit optimistic for HTTP 1.1).

Parameters
requestthe request to check for keepalive
Returns
MHD_YES if (based on the request), a keepalive is legal

Definition at line 1079 of file connection_call_handlers.c.

References MHD_Request::keepalive, MHD_CONN_MUST_CLOSE, MHD_HTTP_HEADER_CONNECTION, MHD_HTTP_VERSION_1_0, MHD_HTTP_VERSION_1_1, MHD_lookup_header_s_token_ci, MHD_str_equal_caseless_(), NULL, MHD_Request::response, MHD_Response::v10_only, and MHD_Request::version_s.

Referenced by build_header_response().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ method_string_to_enum()

static enum MHD_Method method_string_to_enum ( const char *  method)
static

Convert method to the respective enum value.

Parameters
methodthe method string to look up enum value for
Returns
resulting enum, or generic value for "unknown"

Definition at line 1603 of file connection_call_handlers.c.

References _, build_header_response(), MHD_Request::connection, CONNECTION_CLOSE_ERROR, MHD_Request::daemon, MHD_Request::keepalive, MHD_CONN_MUST_CLOSE, MHD_HTTP_VERSION_1_0, MHD_REQUEST_FOOTERS_RECEIVED, MHD_REQUEST_HEADERS_SENDING, MHD_RESPMEM_PERSISTENT, MHD_response_from_buffer(), MHD_response_queue_for_destroy(), NULL, MHD_Connection::read_closed, MHD_Request::response, MHD_Request::state, MHD_Response::status_code, and MHD_Request::version_s.

Referenced by parse_initial_message_line().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_connection_call_handlers_()

int MHD_connection_call_handlers_ ( struct MHD_Connection con,
bool  read_ready,
bool  write_ready,
bool  force_close 
)

Call the handlers for a connection in the appropriate order based on the readiness as detected by the event loop.

Parameters
conconnection to handle
read_readyset if the socket is ready for reading
write_readyset if the socket is ready for writing
force_closeset if a hard error was detected on the socket; if this information is not available, simply pass MHD_NO
Returns
MHD_YES to continue normally, MHD_NO if a serious error was encountered and the connection is to be closed.

Definition at line 3623 of file connection_call_handlers.c.

References MHD_Connection::daemon, MHD_Daemon::data_already_pending, MHD_Request::event_loop_info, MHD_connection_close_(), MHD_EVENT_LOOP_INFO_BLOCK, MHD_EVENT_LOOP_INFO_READ, MHD_EVENT_LOOP_INFO_WRITE, MHD_REQUEST_CHUNKED_BODY_READY, MHD_request_handle_idle_(), MHD_request_handle_read_(), MHD_request_handle_write_(), MHD_REQUEST_HEADERS_SENDING, MHD_REQUEST_INIT, MHD_REQUEST_NORMAL_BODY_READY, MHD_REQUEST_TERMINATED_WITH_ERROR, MHD_Connection::request, MHD_Connection::sk_nonblck, MHD_Request::state, MHD_Daemon::threading_mode, and MHD_Connection::tls_read_ready.

Referenced by thread_main_handle_connection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_lookup_header_token_ci()

static bool MHD_lookup_header_token_ci ( const struct MHD_Request request,
const char *  header,
const char *  token,
size_t  token_len 
)
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.

Parameters
requestthe request to get values from
headerthe header name
tokenthe token to find
token_lenthe length of token, not including optional terminating null-character.
Returns
true if token is found in specified header, false otherwise

Definition at line 1019 of file connection_call_handlers.c.

References MHD_HTTP_Header::header, MHD_Request::headers_received, MHD_HTTP_Header::kind, MHD_HEADER_KIND, MHD_str_equal_caseless_(), MHD_str_has_token_caseless_(), MHD_HTTP_Header::next, NULL, and MHD_HTTP_Header::value.

Here is the call graph for this function:

◆ MHD_request_handle_idle_()

bool MHD_request_handle_idle_ ( struct MHD_Request request)

This function was created to handle per-request processing that has to happen even if the socket cannot be read or written to.

Remarks
To be called only from thread that process request's recv(), send() and response.
Parameters
requestthe request to handle
Returns
true if we should continue to process the request (not dead yet), false if it died

Definition at line 3104 of file connection_call_handlers.c.

References _, build_header_response(), call_request_handler(), cleanup_connection(), MHD_Request::client_context, MHD_TLS_Plugin::cls, MHD_Request::colon, MHD_Request::connection, CONNECTION_CLOSE_ERROR, MHD_Daemon::connection_memory_limit_b, MHD_Connection::connection_timeout, connection_update_event_loop_info(), MHD_Request::continue_message_write_offset, MHD_Response::crc, MHD_Request::daemon, MHD_Daemon::event_loop_syscall, get_next_header_line(), MHD_Request::have_chunked_upload, MHD_Request::header_size, HTTP_100_CONTINUE, MHD_TLS_Plugin::idle_ready, MHD_Request::in_idle, MHD_Request::keepalive, MHD_Request::last, MHD_Connection::last_activity, MHD_Request::method, mhd_assert, MHD_CONN_KEEPALIVE_UNKOWN, MHD_CONN_USE_KEEPALIVE, MHD_connection_close_(), MHD_FOOTER_KIND, MHD_HEADER_KIND, MHD_HTTP_BAD_REQUEST, MHD_HTTP_PROCESSING, MHD_monotonic_sec_counter(), MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_NO, MHD_pool_destroy(), MHD_pool_reset(), MHD_REQUEST_BODY_RECEIVED, MHD_REQUEST_BODY_SENT, MHD_REQUEST_CHUNKED_BODY_READY, MHD_REQUEST_CHUNKED_BODY_UNREADY, MHD_REQUEST_CLOSED, MHD_REQUEST_CONTINUE_SENDING, MHD_REQUEST_CONTINUE_SENT, MHD_REQUEST_FOOTER_PART_RECEIVED, MHD_REQUEST_FOOTERS_RECEIVED, MHD_REQUEST_FOOTERS_SENDING, MHD_REQUEST_FOOTERS_SENT, MHD_REQUEST_HEADER_PART_RECEIVED, MHD_REQUEST_HEADERS_PROCESSED, MHD_REQUEST_HEADERS_RECEIVED, MHD_REQUEST_HEADERS_SENDING, MHD_REQUEST_HEADERS_SENT, MHD_REQUEST_INIT, MHD_REQUEST_NORMAL_BODY_READY, MHD_REQUEST_NORMAL_BODY_UNREADY, MHD_REQUEST_TERMINATED_COMPLETED_OK, MHD_REQUEST_TERMINATED_TIMEOUT_REACHED, MHD_REQUEST_URL_RECEIVED, MHD_response_execute_upgrade_(), MHD_response_queue_for_destroy(), MHD_SIZE_UNKNOWN, MHD_STATICSTR_LEN_, MHD_Response::mutex, need_100_continue(), NULL, parse_initial_message_line(), parse_request_headers(), MHD_Connection::pool, process_broken_line(), process_header_line(), process_request_body(), MHD_Request::read_buffer, MHD_Request::read_buffer_offset, MHD_Request::read_buffer_size, MHD_Connection::read_closed, MHD_Request::remaining_upload_size, MHD_Connection::request, REQUEST_MALFORMED, MHD_Request::response, MHD_Request::response_write_position, socket_flush_possible(), socket_start_extra_buffering(), socket_start_no_buffering(), socket_start_no_buffering_flush(), socket_start_normal_buffering(), MHD_Request::state, MHD_Response::status_code, MHD_Connection::suspended, MHD_Response::termination_cb, MHD_Response::termination_cb_cls, MHD_Response::total_size, transmit_error_response(), try_ready_chunked_body(), try_ready_normal_body(), MHD_Request::version_s, MHD_Request::write_buffer_append_offset, and MHD_Request::write_buffer_send_offset.

Referenced by MHD_connection_call_handlers_(), response_action(), and thread_main_handle_connection().

Here is the caller graph for this function:

◆ MHD_request_handle_read_()

◆ MHD_request_handle_write_()

static void MHD_request_handle_write_ ( struct MHD_Request request)
static

This function was created to handle writes to sockets when it has been determined that the socket can be written to.

Parameters
requestthe request to handle

Definition at line 770 of file connection_call_handlers.c.

References _, check_write_done(), MHD_TLS_Plugin::cls, MHD_Request::connection, CONNECTION_CLOSE_ERROR, MHD_Request::continue_message_write_offset, MHD_Response::crc, MHD_Request::daemon, MHD_Response::data, MHD_Response::data_size, MHD_Response::data_start, MHD_TLS_Plugin::handshake, HTTP_100_CONTINUE, mhd_assert, MHD_connection_update_last_activity_(), MHD_ERR_AGAIN_, MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_PANIC, MHD_REQUEST_BODY_RECEIVED, MHD_REQUEST_BODY_SENT, MHD_REQUEST_CHUNKED_BODY_READY, MHD_REQUEST_CHUNKED_BODY_UNREADY, MHD_REQUEST_CLOSED, MHD_REQUEST_CONTINUE_SENDING, MHD_REQUEST_CONTINUE_SENT, MHD_REQUEST_FOOTER_PART_RECEIVED, MHD_REQUEST_FOOTERS_RECEIVED, MHD_REQUEST_FOOTERS_SENDING, MHD_REQUEST_FOOTERS_SENT, MHD_REQUEST_HEADER_PART_RECEIVED, MHD_REQUEST_HEADERS_PROCESSED, MHD_REQUEST_HEADERS_RECEIVED, MHD_REQUEST_HEADERS_SENDING, MHD_REQUEST_HEADERS_SENT, MHD_REQUEST_INIT, MHD_REQUEST_NORMAL_BODY_READY, MHD_REQUEST_NORMAL_BODY_UNREADY, MHD_REQUEST_URL_RECEIVED, MHD_STATICSTR_LEN_, MHD_Response::mutex, NULL, MHD_Connection::request, MHD_Request::response, MHD_Request::response_write_position, MHD_Connection::send_cls, SIZE_MAX, MHD_Request::state, MHD_Connection::suspended, MHD_Response::total_size, try_ready_normal_body(), MHD_Request::url, MHD_Request::write_buffer, MHD_Request::write_buffer_append_offset, and MHD_Request::write_buffer_send_offset.

Referenced by MHD_connection_call_handlers_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ need_100_continue()

static bool need_100_continue ( struct MHD_Request request)
static

Do we (still) need to send a 100 continue message for this request?

Parameters
requestthe request to test
Returns
false if we don't need 100 CONTINUE, true if we do

Definition at line 2328 of file connection_call_handlers.c.

References MHD_Request::continue_message_write_offset, HTTP_100_CONTINUE, MHD_HEADER_KIND, MHD_HTTP_HEADER_EXPECT, MHD_HTTP_VERSION_1_1, MHD_request_lookup_value(), MHD_STATICSTR_LEN_, MHD_str_equal_caseless_(), NULL, MHD_Connection::request, MHD_Request::response, and MHD_Request::version_s.

Referenced by MHD_request_handle_idle_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_cookie_header()

static int parse_cookie_header ( struct MHD_Request request)
static

Parse the cookie header (see RFC 2109).

Parameters
requestrequest to parse header of
Returns
true for success, false for failure (malformed, out of memory)

Definition at line 2354 of file connection_call_handlers.c.

References _, MHD_Request::connection, MHD_Request::daemon, MHD_COOKIE_KIND, MHD_HEADER_KIND, MHD_HTTP_HEADER_COOKIE, MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE, MHD_pool_allocate(), MHD_request_lookup_value(), MHD_YES, NULL, MHD_Connection::pool, MHD_Connection::request, request_add_header(), REQUEST_TOO_BIG, and transmit_error_response().

Referenced by parse_request_headers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_initial_message_line()

static bool parse_initial_message_line ( struct MHD_Request request,
char *  line,
size_t  line_len 
)
static

Parse the first line of the HTTP HEADER.

Parameters
connectionthe connection (updated)
linethe first line, not 0-terminated
line_lenlength of the first line
Returns
true if the line is ok, false if it is malformed

Definition at line 1763 of file connection_call_handlers.c.

References MHD_Request::client_context, MHD_Request::daemon, MHD_Daemon::early_uri_logger_cb, MHD_Daemon::early_uri_logger_cb_cls, MHD_Request::method, MHD_Request::method_s, method_string_to_enum(), MHD_GET_ARGUMENT_KIND, MHD_NO, MHD_parse_arguments_(), NULL, MHD_Daemon::protocol_strict_level, request_add_header(), MHD_Daemon::unescape_cb, MHD_Daemon::unescape_cb_cls, MHD_Request::url, and MHD_Request::version_s.

Referenced by MHD_request_handle_idle_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_request_headers()

◆ process_broken_line()

static bool process_broken_line ( struct MHD_Request request,
char *  line,
enum MHD_ValueKind  kind 
)
static

Process a header value that spans multiple lines. The previous line(s) are in connection->last.

Parameters
requestthe request we're processing
linethe current input line
kindif the line is complete, add a header of the given kind
Returns
true if the line was processed successfully

Definition at line 1947 of file connection_call_handlers.c.

References MHD_Request::colon, MHD_Request::connection, MHD_Request::last, MHD_Connection::last, mhd_assert, MHD_HTTP_BAD_REQUEST, MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE, MHD_NO, MHD_pool_reallocate(), MHD_YES, NULL, MHD_Connection::pool, process_header_line(), MHD_Connection::request, request_add_header(), REQUEST_MALFORMED, REQUEST_TOO_BIG, and transmit_error_response().

Referenced by MHD_request_handle_idle_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_header_line()

static bool process_header_line ( struct MHD_Request request,
char *  line 
)
static

We have received (possibly the beginning of) a line in the header (or footer). Validate (check for ":") and prepare to process.

Parameters
requestthe request we're processing
lineline from the header to process
Returns
true on success, false on error (malformed line)

Definition at line 1871 of file connection_call_handlers.c.

References _, MHD_Request::colon, MHD_Connection::colon, MHD_Request::connection, CONNECTION_CLOSE_ERROR, MHD_Request::daemon, MHD_Request::last, NULL, MHD_Daemon::protocol_strict_level, and MHD_Connection::request.

Referenced by MHD_request_handle_idle_(), and process_broken_line().

Here is the caller graph for this function:

◆ process_request_body()

static void process_request_body ( struct MHD_Request request)
static

Call the handler of the application for this request. Handles chunking of the upload as well as normal uploads.

Parameters
requestrequest we're processing
  1. no chunked encoding, give all to the client
  2. client may send large chunked data, but only a smaller part is available at one time.

Definition at line 2580 of file connection_call_handlers.c.

References _, MHD_Request::client_context, MHD_Request::connection, CONNECTION_CLOSE_ERROR, MHD_Request::current_chunk_offset, MHD_Request::current_chunk_size, MHD_Request::daemon, MHD_Connection::daemon, MHD_Request::have_chunked_upload, MHD_Request::method, MHD_NO, mhd_panic, mhd_panic_cls, MHD_SIZE_UNKNOWN, MHD_strx_to_uint64_n_(), NULL, MHD_Daemon::rc, MHD_Daemon::rc_cls, MHD_Request::read_buffer, MHD_Request::read_buffer_offset, MHD_Request::remaining_upload_size, MHD_Connection::request, MHD_Request::response, MHD_Connection::suspended, MHD_Daemon::threading_mode, and MHD_Request::url.

Referenced by MHD_request_handle_idle_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ request_add_header()

static bool request_add_header ( struct MHD_Request request,
const char *  key,
const char *  value,
enum MHD_ValueKind  kind 
)
static

Add an entry to the HTTP headers of a request. If this fails, transmit an error response (request too big).

Parameters
requestthe request for which a value should be set
kindkind of the value
keykey for the value
valuethe value itself
Returns
false on failure (out of memory), true for success

Definition at line 1728 of file connection_call_handlers.c.

References _, MHD_Request::daemon, MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE, MHD_NO, MHD_request_set_value(), REQUEST_TOO_BIG, and transmit_error_response().

Referenced by parse_cookie_header(), parse_initial_message_line(), and process_broken_line().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ socket_flush_possible()

static bool socket_flush_possible ( struct MHD_Connection connection)
static

Check whether is possible to force push socket buffer content as partial packet. MHD use different buffering logic depending on whether flushing of socket buffer is possible or not. If flushing IS possible than MHD activates extra buffering before sending data to prevent sending partial packets and flush pending data in socket buffer to push last partial packet to client after sending logical completed part of data (for example: after sending full response header or full response message). If flushing IS NOT possible than MHD activates no buffering (no delay sending) when it going to send formed fully completed logical part of data and activate normal buffering after sending. For idled keep-alive connection MHD always activate normal buffering.

Parameters
connectionconnection to check
Returns
true if force push is possible, false otherwise

Definition at line 2107 of file connection_call_handlers.c.

Referenced by MHD_request_handle_idle_().

Here is the caller graph for this function:

◆ socket_start_extra_buffering()

static bool socket_start_extra_buffering ( struct MHD_Connection connection)
static

Activate extra buffering mode on connection socket to prevent sending of partial packets.

Parameters
connectionconnection to be processed
Returns
true on success, false otherwise

Definition at line 2126 of file connection_call_handlers.c.

References mhd_assert, NULL, and MHD_Connection::socket_fd.

Referenced by MHD_request_handle_idle_().

Here is the caller graph for this function:

◆ socket_start_no_buffering()

static bool socket_start_no_buffering ( struct MHD_Connection connection)
static

Activate no buffering mode (no delay sending) on connection socket.

Parameters
connectionconnection to be processed
Returns
true on success, false otherwise

Definition at line 2185 of file connection_call_handlers.c.

References mhd_assert, NULL, and MHD_Connection::socket_fd.

Referenced by MHD_request_handle_idle_(), and socket_start_no_buffering_flush().

Here is the caller graph for this function:

◆ socket_start_no_buffering_flush()

static bool socket_start_no_buffering_flush ( struct MHD_Connection connection)
static

Activate no buffering mode (no delay sending) on connection socket and push to client data pending in socket buffer.

Parameters
connectionconnection to be processed
Returns
true on success, false otherwise

Definition at line 2238 of file connection_call_handlers.c.

References MHD_send_, NULL, MHD_Connection::socket_fd, and socket_start_no_buffering().

Referenced by MHD_request_handle_idle_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ socket_start_normal_buffering()

static bool socket_start_normal_buffering ( struct MHD_Connection connection)
static

Activate normal buffering mode on connection socket.

Parameters
connectionconnection to be processed
Returns
true on success, false otherwise

Definition at line 2268 of file connection_call_handlers.c.

References mhd_assert, NULL, and MHD_Connection::socket_fd.

Referenced by MHD_request_handle_idle_().

Here is the caller graph for this function:

◆ transmit_error_response()

static void transmit_error_response ( struct MHD_Request request,
enum MHD_StatusCode  ec,
enum MHD_HTTP_StatusCode  status_code,
const char *  message 
)
static

We encountered an error processing the request. Handle it properly by stopping to read data and sending the indicated response code and message.

Parameters
requestthe request
ecerror code for MHD
status_codethe response code to send (400, 413 or 414)
messagethe error message to send

Definition at line 1603 of file connection_call_handlers.c.

Referenced by connection_update_event_loop_info(), get_next_header_line(), MHD_request_handle_idle_(), parse_cookie_header(), process_broken_line(), and request_add_header().

Here is the caller graph for this function:

◆ try_grow_read_buffer()

static bool try_grow_read_buffer ( struct MHD_Request request)
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.

Parameters
requestthe request for which to grow the buffer
Returns
true on success, false on failure

Definition at line 209 of file connection_call_handlers.c.

References MHD_Request::connection, MHD_Daemon::connection_memory_increment_b, MHD_Daemon::connection_memory_limit_b, MHD_Request::daemon, MHD_pool_reallocate(), NULL, MHD_Connection::pool, MHD_Request::read_buffer, and MHD_Request::read_buffer_size.

Referenced by connection_update_event_loop_info(), get_next_header_line(), and MHD_request_handle_read_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_ready_chunked_body()

static bool try_ready_chunked_body ( struct MHD_Request request)
static

Prepare the response buffer of this request for sending. Assumes that the response mutex is already held. If the transmission is complete, this function may close the socket (and return false).

Parameters
connectionthe connection
Returns
false if readying the response failed

Definition at line 648 of file connection_call_handlers.c.

References _, MHD_Request::connection, CONNECTION_CLOSE_ERROR, MHD_Daemon::connection_memory_limit_b, MHD_Response::crc, MHD_Response::crc_cls, MHD_Request::daemon, MHD_Response::data, MHD_Response::data_size, MHD_Response::data_start, mhd_assert, MHD_CONTENT_READER_END_OF_STREAM, MHD_CONTENT_READER_END_WITH_ERROR, MHD_MIN, MHD_mutex_unlock_chk_, MHD_NO, MHD_pool_allocate(), MHD_REQUEST_CHUNKED_BODY_UNREADY, MHD_Response::mutex, NULL, MHD_Connection::pool, MHD_Connection::request, MHD_Request::response, MHD_Request::response_write_position, MHD_Request::state, MHD_Response::total_size, MHD_Request::write_buffer, MHD_Request::write_buffer_append_offset, MHD_Request::write_buffer_send_offset, and MHD_Request::write_buffer_size.

Referenced by MHD_request_handle_idle_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_ready_normal_body()

static bool try_ready_normal_body ( struct MHD_Request request)
static

Prepare the response buffer of this request for sending. Assumes that the response mutex is already held. If the transmission is complete, this function may close the socket (and return false).

Parameters
requestthe request handle
Returns
false if readying the response failed (the lock on the response will have been released already in this case).

Definition at line 581 of file connection_call_handlers.c.

References _, MHD_Request::connection, CONNECTION_CLOSE_ERROR, MHD_Response::crc, MHD_Response::crc_cls, MHD_Response::data, MHD_Response::data_buffer_size, MHD_Response::data_size, MHD_Response::data_start, MHD_connection_close_(), MHD_CONTENT_READER_END_OF_STREAM, MHD_CONTENT_READER_END_WITH_ERROR, MHD_MIN, MHD_mutex_unlock_chk_, MHD_REQUEST_NORMAL_BODY_UNREADY, MHD_REQUEST_TERMINATED_COMPLETED_OK, MHD_Response::mutex, NULL, MHD_Connection::request, MHD_Request::response, MHD_Connection::response, MHD_Request::response_write_position, MHD_Request::state, and MHD_Response::total_size.

Referenced by MHD_request_handle_idle_(), and MHD_request_handle_write_().

Here is the call graph for this function:
Here is the caller graph for this function: