GNU libmicrohttpd
0.9.59
|
Typedefs | |
typedef void(* | MHD_RequestCompletedCallback) (void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe) |
typedef void(* | MHD_NotifyConnectionCallback) (void *cls, struct MHD_Connection *connection, void **socket_context, enum MHD_ConnectionNotificationCode toe) |
typedef int(* | MHD_KeyValueIterator) (void *cls, enum MHD_ValueKind kind, const char *key, const char *value) |
Functions | |
_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_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 struct MHD_PostProcessor * | MHD_create_post_processor (struct MHD_Connection *connection, size_t buffer_size, MHD_PostDataIterator iter, void *iter_cls) |
_MHD_EXTERN int | MHD_post_process (struct MHD_PostProcessor *pp, const char *post_data, size_t post_data_len) |
_MHD_EXTERN int | MHD_destroy_post_processor (struct MHD_PostProcessor *pp) |
MHD API used to access information about requests.
typedef int(* MHD_KeyValueIterator) (void *cls, enum MHD_ValueKind kind, const char *key, const char *value) |
Iterator over key-value pairs. This iterator can be used to iterate over all of the cookies, headers, or POST-data fields of a request, and also to iterate over the headers that have been added to a response.
cls | closure |
kind | kind of the header we are looking at |
key | key for the value, can be an empty string |
value | corresponding value, can be NULL |
Definition at line 1996 of file microhttpd.h.
typedef void(* MHD_NotifyConnectionCallback) (void *cls, struct MHD_Connection *connection, void **socket_context, enum MHD_ConnectionNotificationCode toe) |
Signature of the callback used by MHD to notify the application about started/stopped connections
cls | client-defined closure |
connection | connection handle |
socket_context | socket-specific pointer where the client can associate some state specific to the TCP connection; note that this is different from the "con_cls" which is per HTTP request. The client can initialize during MHD_CONNECTION_NOTIFY_STARTED and cleanup during MHD_CONNECTION_NOTIFY_CLOSED and access in the meantime using MHD_CONNECTION_INFO_SOCKET_CONTEXT. |
toe | reason for connection notification |
Definition at line 1974 of file microhttpd.h.
typedef void(* MHD_RequestCompletedCallback) (void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe) |
Signature of the callback used by MHD to notify the application about completed requests.
cls | client-defined closure |
connection | connection handle |
con_cls | value as set by the last call to the MHD_AccessHandlerCallback |
toe | reason for request termination |
Definition at line 1948 of file microhttpd.h.
Values of this enum are used to specify what information about a connection is desired.
Enumerator | |
---|---|
MHD_CONNECTION_INFO_CIPHER_ALGO | What cipher algorithm is being used. Takes no extra arguments. |
MHD_CONNECTION_INFO_PROTOCOL | Takes no extra arguments. |
MHD_CONNECTION_INFO_CLIENT_ADDRESS | Obtain IP address of the client. Takes no extra arguments. Returns essentially a |
MHD_CONNECTION_INFO_GNUTLS_SESSION | Get the gnuTLS session handle. |
MHD_CONNECTION_INFO_GNUTLS_CLIENT_CERT | Get the gnuTLS client certificate handle. Dysfunctional (never implemented, deprecated). Use MHD_CONNECTION_INFO_GNUTLS_SESSION to get the |
MHD_CONNECTION_INFO_DAEMON | Get the |
MHD_CONNECTION_INFO_CONNECTION_FD | Request the file descriptor for the connection socket. No extra arguments should be passed. |
MHD_CONNECTION_INFO_SOCKET_CONTEXT | Returns the client-specific pointer to a |
MHD_CONNECTION_INFO_CONNECTION_SUSPENDED | Check whether the connection is suspended. |
MHD_CONNECTION_INFO_CONNECTION_TIMEOUT | Get connection timeout |
MHD_CONNECTION_INFO_REQUEST_HEADER_SIZE | Return length of the client's HTTP request header. |
Definition at line 1715 of file microhttpd.h.
The enum MHD_ConnectionNotificationCode
specifies types of connection notifications.
Enumerator | |
---|---|
MHD_CONNECTION_NOTIFY_STARTED | A new connection has been started. |
MHD_CONNECTION_NOTIFY_CLOSED | A connection is closed. |
Definition at line 1625 of file microhttpd.h.
The enum MHD_RequestTerminationCode
specifies reasons why a request has been terminated (or completed).
Enumerator | |
---|---|
MHD_REQUEST_TERMINATED_COMPLETED_OK | We finished sending the response. |
MHD_REQUEST_TERMINATED_WITH_ERROR | Error handling the connection (resources exhausted, other side closed connection, application error accepting request, etc.) |
MHD_REQUEST_TERMINATED_TIMEOUT_REACHED | No activity on the connection for the number of seconds specified using MHD_OPTION_CONNECTION_TIMEOUT. |
MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN | We had to close the session since MHD was being shut down. |
MHD_REQUEST_TERMINATED_READ_ERROR | We tried to read additional data, but the other side closed the connection. This error is similar to MHD_REQUEST_TERMINATED_WITH_ERROR, but specific to the case where the connection died because the other side did not send expected data. |
MHD_REQUEST_TERMINATED_CLIENT_ABORT | The client terminated the connection by closing the socket for writing (TCP half-closed); MHD aborted sending the response according to RFC 2616, section 8.1.4. |
Definition at line 1567 of file microhttpd.h.
struct MHD_PostProcessor * MHD_create_post_processor | ( | struct MHD_Connection * | connection, |
size_t | buffer_size, | ||
MHD_PostDataIterator | iter, | ||
void * | iter_cls | ||
) |
Create a struct MHD_PostProcessor
.
A struct MHD_PostProcessor
can be used to (incrementally) parse the data portion of a POST request. Note that some buggy browsers fail to set the encoding type. If you want to support those, you may have to call MHD_set_connection_value with the proper encoding type before creating a post processor (if no supported encoding type is set, this function will fail).
connection | the connection on which the POST is happening (used to determine the POST format) |
buffer_size | maximum number of bytes to use for internal buffering (used only for the parsing, specifically the parsing of the keys). A tiny value (256-1024) should be sufficient. Do NOT use a value smaller than 256. For good performance, use 32 or 64k (i.e. 65536). |
iter | iterator to be called with the parsed data, Must NOT be NULL. |
iter_cls | first argument to iter |
Definition at line 274 of file postprocessor.c.
References MHD_calloc_(), MHD_HEADER_KIND, MHD_HTTP_HEADER_CONTENT_TYPE, MHD_HTTP_POST_ENCODING_FORM_URLENCODED, MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, MHD_lookup_connection_value(), mhd_panic, mhd_panic_cls, MHD_STATICSTR_LEN_, MHD_str_equal_caseless_n_(), NULL, PP_Init, and RN_Inactive.
int MHD_destroy_post_processor | ( | struct MHD_PostProcessor * | pp | ) |
Release PostProcessor resources.
pp | the PostProcessor to destroy |
Release PostProcessor resources.
pp | post processor context to destroy |
Definition at line 1250 of file postprocessor.c.
References free_unmarked(), MHD_NO, MHD_YES, NE_none, NULL, post_process_urlencoded(), PP_Done, PP_ExpectNewLine, and PP_ProcessValue.
int MHD_get_connection_values | ( | struct MHD_Connection * | connection, |
enum MHD_ValueKind | kind, | ||
MHD_KeyValueIterator | iterator, | ||
void * | iterator_cls | ||
) |
Get all of the headers from the request.
connection | connection to get values from |
kind | types of values to iterate over, can be a bitmask |
iterator | callback to call on each header; maybe NULL (then just count headers) |
iterator_cls | extra argument to iterator |
Definition at line 700 of file connection.c.
References MHD_HTTP_Header::header, MHD_Connection::headers_received, MHD_HTTP_Header::kind, MHD_YES, MHD_HTTP_Header::next, NULL, and MHD_HTTP_Header::value.
const char * MHD_lookup_connection_value | ( | struct MHD_Connection * | connection, |
enum MHD_ValueKind | kind, | ||
const char * | key | ||
) |
Get a particular header value. If multiple values match the kind, return any one of them.
connection | connection to get values from |
kind | what kind of value are we looking for |
key | the header to look for, NULL to lookup 'trailing' value without a key |
Definition at line 794 of file connection.c.
References MHD_HTTP_Header::header, MHD_Connection::headers_received, MHD_HTTP_Header::kind, MHD_str_equal_caseless_(), MHD_HTTP_Header::next, NULL, and MHD_HTTP_Header::value.
Referenced by MHD_basic_auth_get_username_password(), MHD_create_post_processor(), MHD_digest_auth_check(), MHD_digest_auth_get_username(), need_100_continue(), parse_connection_headers(), and parse_cookie_header().
int MHD_post_process | ( | struct MHD_PostProcessor * | pp, |
const char * | post_data, | ||
size_t | post_data_len | ||
) |
Parse and process POST data. Call this function when POST data is available (usually during an MHD_AccessHandlerCallback) with the "upload_data" and "upload_data_size". Whenever possible, this will then cause calls to the MHD_PostDataIterator.
pp | the post processor |
post_data | post_data_len bytes of POST data |
post_data_len | length of post_data |
Definition at line 1214 of file postprocessor.c.
References MHD_HTTP_POST_ENCODING_FORM_URLENCODED, MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, MHD_NO, MHD_STATICSTR_LEN_, MHD_str_equal_caseless_n_(), MHD_YES, NULL, post_process_multipart(), and post_process_urlencoded().
int MHD_set_connection_value | ( | struct MHD_Connection * | connection, |
enum MHD_ValueKind | kind, | ||
const char * | key, | ||
const char * | value | ||
) |
This function can be used to add an entry to the HTTP headers of a connection (so that the MHD_get_connection_values function will return them – and the struct MHD_PostProcessor
will also see them). This maybe required in certain situations (see Mantis #1399) where (broken) HTTP implementations fail to supply values
needed by the post processor (or other parts of the application).
This function MUST only be called from within the MHD_AccessHandlerCallback (otherwise, access maybe improperly synchronized). Furthermore, the client must guarantee that the key and value arguments are 0-terminated strings that are NOT freed until the connection is closed. (The easiest way to do this is by passing only arguments to permanently allocated strings.).
connection | the connection for which a value should be set |
kind | kind of the value |
key | key for the value |
value | the value itself |
Definition at line 752 of file connection.c.
References MHD_HTTP_Header::header, MHD_Connection::headers_received, MHD_Connection::headers_received_tail, MHD_HTTP_Header::kind, MHD_NO, MHD_pool_allocate(), MHD_YES, MHD_HTTP_Header::next, NULL, MHD_Connection::pool, and MHD_HTTP_Header::value.
Referenced by connection_add_header().