HomePort
|
Go to the source code of this file.
Data Structures | |
struct | hpd_httpd_request |
An http request. More... | |
Enumerations | |
enum | state { S_START, S_BEGIN, S_URL, S_HEADER_FIELD, S_HEADER_VALUE, S_HEADER_COMPLETE, S_BODY, S_COMPLETE, S_STOP, S_ERROR } |
The possible states of a request. More... | |
Functions | |
static hpd_error_t | header_parser_field_value_pair_complete (void *data, const char *field, size_t field_length, const char *value, size_t value_length) |
Callback for the header parser. More... | |
hpd_error_t | hpd_httpd_request_get_argument (hpd_httpd_request_t *req, const char *key, const char **val) |
Get a specific argument of a request. More... | |
hpd_error_t | hpd_httpd_request_get_arguments (hpd_httpd_request_t *req, hpd_map_t **arguments) |
Get a linked map of all URL arguements for a request. More... | |
hpd_error_t | hpd_httpd_request_get_cookie (hpd_httpd_request_t *req, const char *key, const char **val) |
Get a specific cookie for a request. More... | |
hpd_error_t | hpd_httpd_request_get_cookies (hpd_httpd_request_t *req, hpd_map_t **cookies) |
Get a all cookies for a request. More... | |
hpd_error_t | hpd_httpd_request_get_header (hpd_httpd_request_t *req, const char *key, const char **value) |
Get a specific header of a request. More... | |
hpd_error_t | hpd_httpd_request_get_headers (hpd_httpd_request_t *req, hpd_map_t **headers) |
Get a linked map of all headers for a request. More... | |
hpd_error_t | hpd_httpd_request_get_ip (hpd_httpd_request_t *req, const char **ip) |
Get the IP of a request. More... | |
hpd_error_t | hpd_httpd_request_get_method (hpd_httpd_request_t *req, hpd_httpd_method_t *method) |
Get the method of the http request. More... | |
hpd_error_t | hpd_httpd_request_get_url (hpd_httpd_request_t *req, const char **url) |
Get the URL of this request. More... | |
hpd_error_t | hpd_httpd_request_keep_open (hpd_httpd_request_t *req) |
Keep the connection for a request open. More... | |
hpd_error_t | http_request_create (hpd_httpd_request_t **req, hpd_httpd_t *httpd, hpd_httpd_settings_t *settings, hpd_tcpd_conn_t *conn, const hpd_module_t *context) |
Create a new ws_request. More... | |
hpd_error_t | http_request_destroy (hpd_httpd_request_t *req) |
Destroy a ws_request. More... | |
hpd_error_t | http_request_get_connection (hpd_httpd_request_t *req, hpd_tcpd_conn_t **conn) |
Get the connection of a request. More... | |
hpd_error_t | http_request_get_context (hpd_httpd_request_t *req, const hpd_module_t **context) |
hpd_error_t | http_request_parse (hpd_httpd_request_t *req, const char *buf, size_t len) |
Parse a new chunk of the message. More... | |
static int | parser_body (http_parser *parser, const char *buf, size_t len) |
Body callback for http_parser. More... | |
static int | parser_hdr_cmpl (http_parser *parser) |
Header complete callback for http_parser. More... | |
static int | parser_hdr_field (http_parser *parser, const char *buf, size_t len) |
Header field callback for http_parser. More... | |
static int | parser_hdr_value (http_parser *parser, const char *buf, size_t len) |
Header value callback for http_parser. More... | |
static int | parser_msg_begin (http_parser *parser) |
Message begin callback for http_parser. More... | |
static int | parser_msg_cmpl (http_parser *parser) |
Messages complete callback for http_parser. More... | |
static int | parser_url (http_parser *parser, const char *buf, size_t len) |
URL callback for http_parser. More... | |
static hpd_error_t | url_parser_key_value (void *data, const char *key, size_t key_len, const char *value, size_t value_len) |
Callback for URL parser. More... | |
static hpd_error_t | url_parser_path_complete (void *data, const char *parsedSegment, size_t segment_length) |
Callback for URL parser. More... | |
Variables | |
static http_parser_settings | parser_settings |
Global settings for http_parser. More... | |
struct hpd_httpd_request |
An http request.
nodata_cb and data_cb functions in hpd_tcpd_settings provides a request as their parameters. This allows the implenter of a webserver to receive requests.
ws_response_create() uses the request to create a response to the client.
ws_request_create() Creates new requests. Requests should be deallocated using ws_request_destroy() afterwards.
Initially requests are empty, they are filled with data using ws_request_parse() which appends a new string to the request. Note that the request do not save any data itself, beside from its state. All data in the string will be passed on as pointers to the callbacks defined in hpd_tcpd_settings.
ws_request_get_client() gets the client that sent the request.
A request will take states in the following order, the states of S_STOP and S_ERROR can be assumed as always possible target for a transition. The labels on the edges denote the callback from hpd_tcpd_settings, that will be called upon the transition.
Definition at line 121 of file httpd_request.c.
Data Fields | ||
---|---|---|
hpd_map_t * | arguments | URL Arguments. |
hpd_tcpd_conn_t * | conn | Connection to client. |
const hpd_module_t * | context | |
hpd_map_t * | cookies | Cookie Pairs. |
void * | data | User data. |
struct hp * | header_parser | Header Parser. |
hpd_map_t * | headers | Header Pairs. |
hpd_httpd_method_t | method | |
http_parser | parser | HTTP parser. |
hpd_httpd_settings_t * | settings | Settings. |
enum state | state | Current state. |
char * | url | URL. |
struct up * | url_parser | URL Parser. |
hpd_httpd_t * | webserver | HTTP Webserver. |
enum state |
The possible states of a request.
Definition at line 37 of file httpd_request.c.
|
static |
Callback for the header parser.
Is called for each header pairs with a field and a value. If the header pair is a cookie, the cookied will be parsed and stored in the list of cookies. Multiple headers will be combined into a a single with a comma-seperated list of values, according to the RFC 2616.
data | The HTTP Request |
field | The field, not null-terminated |
field_length | The length of the field |
value | The value, not null-terminated |
value_length | The length of the value |
Definition at line 216 of file httpd_request.c.
hpd_error_t hpd_httpd_request_get_argument | ( | hpd_httpd_request_t * | req, |
const char * | key, | ||
const char ** | val | ||
) |
Get a specific argument of a request.
req | http request |
key | Key value of argument to get |
Definition at line 841 of file httpd_request.c.
hpd_error_t hpd_httpd_request_get_arguments | ( | hpd_httpd_request_t * | req, |
hpd_map_t ** | arguments | ||
) |
Get a linked map of all URL arguements for a request.
req | http request |
Definition at line 824 of file httpd_request.c.
hpd_error_t hpd_httpd_request_get_cookie | ( | hpd_httpd_request_t * | req, |
const char * | key, | ||
const char ** | val | ||
) |
Get a specific cookie for a request.
req | http request |
key | Key of cookie to get |
Definition at line 874 of file httpd_request.c.
hpd_error_t hpd_httpd_request_get_cookies | ( | hpd_httpd_request_t * | req, |
hpd_map_t ** | cookies | ||
) |
Get a all cookies for a request.
req | http request |
Definition at line 856 of file httpd_request.c.
hpd_error_t hpd_httpd_request_get_header | ( | hpd_httpd_request_t * | req, |
const char * | key, | ||
const char ** | value | ||
) |
Get a specific header of a request.
req | http request |
key | Key for the header to get |
Definition at line 809 of file httpd_request.c.
hpd_error_t hpd_httpd_request_get_headers | ( | hpd_httpd_request_t * | req, |
hpd_map_t ** | headers | ||
) |
Get a linked map of all headers for a request.
req | http request |
Definition at line 791 of file httpd_request.c.
hpd_error_t hpd_httpd_request_get_ip | ( | hpd_httpd_request_t * | req, |
const char ** | ip | ||
) |
Get the IP of a request.
req | http request |
Definition at line 905 of file httpd_request.c.
hpd_error_t hpd_httpd_request_get_method | ( | hpd_httpd_request_t * | req, |
hpd_httpd_method_t * | method | ||
) |
Get the method of the http request.
req | http request |
Definition at line 759 of file httpd_request.c.
hpd_error_t hpd_httpd_request_get_url | ( | hpd_httpd_request_t * | req, |
const char ** | url | ||
) |
Get the URL of this request.
req | http request |
Definition at line 775 of file httpd_request.c.
hpd_error_t hpd_httpd_request_keep_open | ( | hpd_httpd_request_t * | req | ) |
Keep the connection for a request open.
Normally connections are closed when there has been no activity on it for the amount specified in the timeout field in the httpd settings struct. To keep the connection open forever, issue or call to this function with the http request. The connection will still be closed and destroyed when the client closes it.
req | http request to keep open |
Definition at line 924 of file httpd_request.c.
hpd_error_t http_request_create | ( | hpd_httpd_request_t ** | req, |
hpd_httpd_t * | httpd, | ||
hpd_httpd_settings_t * | settings, | ||
hpd_tcpd_conn_t * | conn, | ||
const hpd_module_t * | context | ||
) |
Create a new ws_request.
The created ws_request is ready to receive data through ws_reqeust_parse(), and it should be freed using ws_request_destroy() to avoid memory leaks.
webserver | The httpd creating the request |
settings | The settings for the webserver receiving the request. This will determine which callbacks to call on events. |
conn | The connection on which the request is being received |
Definition at line 601 of file httpd_request.c.
hpd_error_t http_request_destroy | ( | hpd_httpd_request_t * | req | ) |
Destroy a ws_request.
All ws_requests should be freed by a call to this function to avoid memory leaks.
req | The request to be destroyed. |
Definition at line 660 of file httpd_request.c.
hpd_error_t http_request_get_connection | ( | hpd_httpd_request_t * | req, |
hpd_tcpd_conn_t ** | conn | ||
) |
Get the connection of a request.
req | http request |
Definition at line 889 of file httpd_request.c.
hpd_error_t http_request_get_context | ( | hpd_httpd_request_t * | req, |
const hpd_module_t ** | context | ||
) |
hpd_error_t http_request_parse | ( | hpd_httpd_request_t * | req, |
const char * | buf, | ||
size_t | len | ||
) |
Parse a new chunk of the message.
This will sent the chunk to the http_parser, which will parse the new chunk and call the callbacks defined in parser_settings on events. The callbacks will change state of the ws_request and make calls on the functions defined in hpd_tcpd_settings.
req | The request, to which the chunk should be added. |
buf | The chunk, which is not assumed to be \0 terminated. |
len | Length of the chuck. |
Definition at line 697 of file httpd_request.c.
|
static |
Body callback for http_parser.
Called from http_parser each time it receives a chunk of the message body. Each chunk will be sent on to on_request_body() from hpd_tcpd_settings.
parser | The http_parser calling. |
buf | The buffer containing the chunk. Note that the buffer is not \0 terminated. |
len | The length of the chunk. |
Definition at line 528 of file httpd_request.c.
|
static |
Header complete callback for http_parser.
Called from http_parser when all headers are parsed. If any remains are left of the message, they are assumed to be the body. If there were no headers in the message, this will trigger a call to on_request_url_complete() from hpd_tcpd_settings. For both messages with or without headers, on_request_header_complete() will also be called.
parser | The http_parser calling. |
Definition at line 476 of file httpd_request.c.
|
static |
Header field callback for http_parser.
Called from http_parser with chunks of a header field. The first call to this callback will trigger a on_request_url_complete. Each chunk is sent on to the on_request_header_field() callback from hpd_tcpd_settings.
parser | The http_parser calling. |
buf | The buffer containing the chunk. Note that the buffer is not \0 terminated. |
len | The length of the chunk. |
Definition at line 380 of file httpd_request.c.
|
static |
Header value callback for http_parser.
Called from http_parser with chunks of a header value. The chunk will be sent on to the on_request_header_value() callback in hpd_tcpd_settings.
parser | The http_parser calling. |
buf | The buffer containing the chunk. Note that the buffer is not \0 terminated. |
len | The length of the chunk. |
Definition at line 433 of file httpd_request.c.
|
static |
Message begin callback for http_parser.
Called when the http request message begins, by the http_parser. This will call on_request_begin() and on_request_method() from hpd_tcpd_settings.
parser | The http_parser calling. |
Definition at line 284 of file httpd_request.c.
|
static |
Messages complete callback for http_parser.
Called from http_parser when the full message have been parsed. This will trigger a call to on_request_complete() in hpd_tcpd_settings.
parser | The http_parser calling. |
Definition at line 561 of file httpd_request.c.
|
static |
URL callback for http_parser.
Called from http_parser with chunks of the URL. Each chunk is sent to the on_request_url() callback in hpd_tcpd_settings and the the URL parser.
parser | The http_parser calling. |
buf | The buffer containing the chunk. Note that the buffer is not \0 terminated. |
len | The length of the chunk. |
Definition at line 321 of file httpd_request.c.
|
static |
Callback for URL parser.
Called when the URL parser has parsed an argument pair, with a key and a value.
data | The HTTP Request |
key | The key, not null-terminated |
key_len | The length of the key |
value | The value, not null-terminated |
value_len | The length of the value |
Definition at line 195 of file httpd_request.c.
|
static |
Callback for URL parser.
Called when the full path has been parsed and stores the full path in the url field of the request.
data | The HTTP Request |
parsendSegment | Full path, not null-terminated. |
segment_length | Length of path in characters |
Definition at line 171 of file httpd_request.c.
|
static |
Global settings for http_parser.
Definition at line 149 of file httpd_request.c.