Libevhtp
1.2.13
|
implementation file for libevhtp. More...
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
#include <signal.h>
#include <strings.h>
#include <inttypes.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <sys/un.h>
#include <limits.h>
#include <event2/dns.h>
#include "internal.h"
#include "numtoa.h"
#include "evhtp/evhtp.h"
#include "log.h"
Go to the source code of this file.
Data Structures | |
struct | evhtp_callback_t |
structure containing a single callback and configuration More... | |
Macros | |
#define | SET_BIT(VAR, FLAG) VAR |= FLAG |
#define | UNSET_BIT(VAR, FLAG) VAR &= ~FLAG |
#define | HTP_FLAG_ON(PRE, FLAG) SET_BIT(PRE->flags, FLAG) |
#define | HTP_FLAG_OFF(PRE, FLAG) UNSET_BIT(PRE->flags, FLAG) |
#define | HOOK_AVAIL(var, hook_name) (var->hooks && var->hooks->hook_name) |
#define | HOOK_FUNC(var, hook_name) (var->hooks->hook_name) |
#define | HOOK_ARGS(var, hook_name) var->hooks->hook_name ## _arg |
#define | HOOK_REQUEST_RUN(request, hook_name, ...) |
#define | HOOK_REQUEST_RUN_NARGS(__request, hook_name) |
#define | htp__lock_(h) |
Helper macro to lock htp structure. More... | |
#define | htp__unlock_(h) |
Helper macro to unlock htp lock. More... | |
#define | rc_scratch conn->scratch_buf |
#define | rc_parser conn->parser |
#define | ch_fini_arg hooks->on_connection_fini_arg |
#define | ch_fini hooks->on_connection_fini |
#define | cr_status request->status |
#define | rh_err hooks->on_error |
#define | rh_err_arg hooks->on_error_arg |
#define | htp__is_http_11_(_major, _minor) (_major >= 1 && _minor >= 1) |
helper macro to determine if http version is HTTP/1.0 More... | |
#define | htp__is_http_10_(_major, _minor) (_major >= 1 && _minor <= 0) |
helper function to determine if http version is HTTP/1.1 More... | |
#define | HTP_FLAG_FNGEN(NAME, TYPE) |
#define | ssl_sk_new_ bufferevent_openssl_socket_new |
#define | ssl_sk_connect_ bufferevent_socket_connect |
Enumerations | |
enum | query_parser_state { s_query_start = 0, s_query_separator, s_query_key, s_query_val, s_query_key_hex_1, s_query_key_hex_2, s_query_val_hex_1, s_query_val_hex_2, s_query_done } |
enum | unscape_state { unscape_state_start = 0, unscape_state_hex1, unscape_state_hex2 } |
Functions | |
TAILQ_HEAD (evhtp_callbacks_s, evhtp_callback_s) | |
static void * | htp__malloc_ (size_t size) |
Wrapper for malloc so that a different malloc can be used if desired. More... | |
static void * | htp__realloc_ (void *ptr, size_t size) |
Wrapper for realloc so that a different realloc can be used if desired. More... | |
static void | htp__free_ (void *ptr) |
Wrapper for free so that a different free can be used if desired. More... | |
static void * | htp__calloc_ (size_t nmemb, size_t size) |
Wrapper for calloc so that a different calloc can be used if desired. More... | |
static char * | htp__strdup_ (const char *str) |
implementation of strdup function. More... | |
static char * | htp__strndup_ (const char *str, size_t len) |
implementation of strndup function. More... | |
void | evhtp_set_mem_functions (void *(*mallocfn_)(size_t len), void *(*reallocfn_)(void *p, size_t sz), void(*freefn_)(void *p)) |
static const char * | status_code_to_str (evhtp_res code) |
returns string status code from enum code More... | |
static evhtp_proto | htp__protocol_ (const char major, const char minor) |
returns the HTTP protocol version More... | |
static evhtp_res | htp__hook_path_ (evhtp_request_t *request, evhtp_path_t *path) |
runs the user-defined on_path hook for a request More... | |
static evhtp_res | htp__hook_header_ (evhtp_request_t *request, evhtp_header_t *header) |
runs the user-defined on_header hook for a request More... | |
static evhtp_res | htp__hook_headers_ (evhtp_request_t *request, evhtp_headers_t *headers) |
runs the user-defined on_Headers hook for a request after all headers have been parsed. More... | |
static evhtp_res | htp__hook_body_ (evhtp_request_t *request, struct evbuffer *buf) |
runs the user-defined on_body hook for requests containing a body. More... | |
static evhtp_res | htp__hook_request_fini_ (evhtp_request_t *request) |
runs the user-defined hook called just prior to a request been free()'d More... | |
static evhtp_res | htp__hook_chunk_new_ (evhtp_request_t *request, uint64_t len) |
Runs the user defined request hook. More... | |
static evhtp_res | htp__hook_chunk_fini_ (evhtp_request_t *request) |
Runs the user defined on_chunk_fini hook. More... | |
static evhtp_res | htp__hook_chunks_fini_ (evhtp_request_t *request) |
Runs the user defined on chunk_finis hook. More... | |
static evhtp_res | htp__hook_headers_start_ (evhtp_request_t *request) |
Runs the user defined on_headers_start hook. More... | |
static evhtp_res | htp__hook_connection_fini_ (evhtp_connection_t *connection) |
runs the user-definedhook called just prior to a connection being closed More... | |
static void | htp__hook_error_ (evhtp_request_t *request, evhtp_error_flags errtype) |
runs the user-defined hook when a connection error occurs More... | |
static evhtp_res | htp__hook_connection_error_ (evhtp_connection_t *connection, evhtp_error_flags errtype) |
runs the user-defined hook when a connection error occurs More... | |
static evhtp_res | htp__hook_hostname_ (evhtp_request_t *r, const char *hostname) |
Runs the user defined hostname processing hook. More... | |
static evhtp_res | htp__hook_connection_write_ (evhtp_connection_t *connection) |
Runs the user defined on_write hook. More... | |
static int | htp__glob_match_ (const char *pattern, size_t plen, const char *string, size_t str_len) |
glob/wildcard type pattern matching. More... | |
static evhtp_callback_t * | htp__callback_find_ (evhtp_callbacks_t *cbs, const char *path, unsigned int *start_offset, unsigned int *end_offset) |
Locates a given callback offsets performs a regex pattern match. More... | |
static int | htp__path_new_ (evhtp_path_t **out, const char *data, size_t len) |
parses the path and file from an input buffer More... | |
static void | htp__path_free_ (evhtp_path_t *path) |
Correctly frees the evhtp_path_t ptr that is passed in. More... | |
static int | htp__authority_new_ (evhtp_authority_t **out) |
create an authority structure More... | |
static void | htp__authority_free_ (evhtp_authority_t *authority) |
frees an authority structure More... | |
static void | htp__uri_free_ (evhtp_uri_t *uri) |
frees an overlay URI structure More... | |
static int | htp__uri_new_ (evhtp_uri_t **out) |
create an overlay URI structure More... | |
static void | htp__request_free_ (evhtp_request_t *request) |
frees all data in an evhtp_request_t along with calling finished hooks More... | |
static evhtp_request_t * | htp__request_new_ (evhtp_connection_t *c) |
Creates a new evhtp_request_t. More... | |
static int | htp__request_parse_start_ (htparser *p) |
Starts the parser for the connection associated with the parser struct. More... | |
static int | htp__request_parse_args_ (htparser *p, const char *data, size_t len) |
parses http request arguments More... | |
static int | htp__request_parse_headers_start_ (htparser *p) |
static int | htp__request_parse_header_key_ (htparser *p, const char *data, size_t len) |
static int | htp__request_parse_header_val_ (htparser *p, const char *data, size_t len) |
static evhtp_t * | htp__request_find_vhost_ (evhtp_t *evhtp, const char *name) |
static int | htp__request_set_callbacks_ (evhtp_request_t *request) |
static int | htp__request_parse_hostname_ (htparser *p, const char *data, size_t len) |
static int | htp__require_uri_ (evhtp_connection_t *c) |
static int | htp__request_parse_host_ (htparser *p, const char *data, size_t len) |
static int | htp__request_parse_port_ (htparser *p, const char *data, size_t len) |
static int | htp__request_parse_path_ (htparser *p, const char *data, size_t len) |
static int | htp__request_parse_headers_ (htparser *p) |
static int | htp__request_parse_body_ (htparser *p, const char *data, size_t len) |
static int | htp__request_parse_chunk_new_ (htparser *p) |
static int | htp__request_parse_chunk_fini_ (htparser *p) |
static int | htp__request_parse_chunks_fini_ (htparser *p) |
static int | htp__should_parse_query_body_ (evhtp_request_t *req) |
determines if the request body contains the query arguments. More... | |
static int | htp__request_parse_fini_ (htparser *p) |
static int | htp__create_headers_ (evhtp_header_t *header, void *arg) |
static struct evbuffer * | htp__create_reply_ (evhtp_request_t *request, evhtp_res code) |
static void | htp__connection_readcb_ (struct bufferevent *bev, void *arg) |
static void | htp__connection_writecb_ (struct bufferevent *bev, void *arg) |
static void | htp__connection_eventcb_ (struct bufferevent *bev, short events, void *arg) |
static void | htp__connection_resumecb_ (int fd, short events, void *arg) |
static int | htp__run_pre_accept_ (evhtp_t *htp, evhtp_connection_t *conn) |
static int | htp__connection_accept_ (struct event_base *evbase, evhtp_connection_t *connection) |
static void | htp__default_request_cb_ (evhtp_request_t *request, void *arg) |
static evhtp_connection_t * | htp__connection_new_ (evhtp_t *htp, evutil_socket_t sock, evhtp_type type) |
static int | htp__run_post_accept_ (evhtp_t *htp, evhtp_connection_t *connection) |
static void | htp__run_in_thread_ (evthr_t *thr, void *arg, void *shared) |
static void | htp__accept_cb_ (struct evconnlistener *serv, int fd, struct sockaddr *s, int sl, void *arg) |
static unsigned long | htp__ssl_get_thread_id_ (void) |
static void | htp__ssl_thread_lock_ (int mode, int type, const char *file, int line) |
static void | htp__ssl_delete_scache_ent_ (evhtp_ssl_ctx_t *ctx, evhtp_ssl_sess_t *sess) |
static int | htp__ssl_add_scache_ent_ (evhtp_ssl_t *ssl, evhtp_ssl_sess_t *sess) |
static evhtp_ssl_sess_t * | htp__ssl_get_scache_ent_ (evhtp_ssl_t *ssl, evhtp_ssl_data_t *sid, int sid_len, int *copy) |
static int | htp__ssl_servername_ (evhtp_ssl_t *ssl, int *unused, void *arg) |
htp_method | evhtp_request_get_method (evhtp_request_t *r) |
returns the htp_method enum version of the request method. More... | |
void | evhtp_connection_pause (evhtp_connection_t *c) |
pauses a connection (disables reading) More... | |
void | evhtp_connection_resume (evhtp_connection_t *c) |
resumes a connection (enables reading) and activates resume event. More... | |
void | evhtp_request_pause (evhtp_request_t *request) |
Wrapper around evhtp_connection_pause. More... | |
void | evhtp_request_resume (evhtp_request_t *request) |
Wrapper around evhtp_connection_resume. More... | |
evhtp_header_t * | evhtp_header_key_add (evhtp_headers_t *headers, const char *key, char key_alloc) |
creates a new evhtp_header_t, sets only the key, and adds to the evhtp_headers TAILQ More... | |
evhtp_header_t * | evhtp_header_val_add (evhtp_headers_t *headers, const char *val, char val_alloc) |
finds the last header in the headers tailq and adds the value More... | |
evhtp_kvs_t * | evhtp_kvs_new (void) |
creates an empty list of key/values More... | |
evhtp_kv_t * | evhtp_kv_new (const char *key, const char *val, char key_alloc, char val_alloc) |
Allocates a new key/value structure. More... | |
void | evhtp_kv_free (evhtp_kv_t *kv) |
frees resources allocated for a single key/value More... | |
void | evhtp_kv_rm_and_free (evhtp_kvs_t *kvs, evhtp_kv_t *kv) |
free's resources associated with 'kv' if ONLY found within the key/value list More... | |
void | evhtp_kvs_free (evhtp_kvs_t *kvs) |
frees a the list of key/values, and all underlying entries More... | |
int | evhtp_kvs_for_each (evhtp_kvs_t *kvs, evhtp_kvs_iterator cb, void *arg) |
callback iterator which executes 'cb' for every entry in 'kvs' More... | |
const char * | evhtp_kv_find (evhtp_kvs_t *kvs, const char *key) |
find the string value of 'key' from the key/value list 'kvs' More... | |
evhtp_kv_t * | evhtp_kvs_find_kv (evhtp_kvs_t *kvs, const char *key) |
find the evhtp_kv_t reference 'key' from the k/val list 'kvs' More... | |
void | evhtp_kvs_add_kv (evhtp_kvs_t *kvs, evhtp_kv_t *kv) |
appends a key/val structure to a evhtp_kvs_t tailq More... | |
void | evhtp_kvs_add_kvs (evhtp_kvs_t *dst, evhtp_kvs_t *src) |
appends all key/val structures from src tailq onto dst tailq More... | |
static int | evhtp_is_hex_query_char (unsigned char ch) |
int | evhtp_unescape_string (unsigned char **out, unsigned char *str, size_t str_len) |
Unescapes strings like '%7B1,%202,%203%7D' would become '{1, 2, 3}'. More... | |
evhtp_query_t * | evhtp_parse_query_wflags (const char *query, const size_t len, const int flags) |
Parses the query portion of the uri into a set of key/values. More... | |
evhtp_query_t * | evhtp_parse_query (const char *query, size_t len) |
Parses the query portion of the uri into a set of key/values in a strict manner. More... | |
void | evhtp_send_reply_start (evhtp_request_t *request, evhtp_res code) |
void | evhtp_send_reply_body (evhtp_request_t *request, struct evbuffer *buf) |
void | evhtp_send_reply_end (evhtp_request_t *request) |
void | evhtp_send_reply (evhtp_request_t *request, evhtp_res code) |
generates all the right information for a reply to be sent to the client More... | |
int | evhtp_response_needs_body (const evhtp_res code, const htp_method method) |
Determine if a response should have a body. More... | |
void | evhtp_send_reply_chunk_start (evhtp_request_t *request, evhtp_res code) |
start a chunked response. More... | |
void | evhtp_send_reply_chunk (evhtp_request_t *request, struct evbuffer *buf) |
send a chunk reply. More... | |
void | evhtp_send_reply_chunk_end (evhtp_request_t *request) |
call when all chunks have been sent and you wish to send the last bits. More... | |
void | evhtp_unbind_socket (evhtp_t *htp) |
stops the listening socket. More... | |
int | evhtp_accept_socket (evhtp_t *htp, evutil_socket_t sock, int backlog) |
create the listener plus setup various options with an already-bound socket. More... | |
int | evhtp_bind_sockaddr (evhtp_t *htp, struct sockaddr *sa, size_t sin_len, int backlog) |
bind to an already allocated sockaddr. More... | |
int | evhtp_bind_socket (evhtp_t *htp, const char *baddr, uint16_t port, int backlog) |
bind to a socket, optionally with specific protocol support formatting. More... | |
void | evhtp_callbacks_free (evhtp_callbacks_t *callbacks) |
evhtp_callback_t * | evhtp_callback_new (const char *path, evhtp_callback_type type, evhtp_callback_cb cb, void *arg) |
creates a new evhtp_callback_t structure. More... | |
void | evhtp_callback_free (evhtp_callback_t *callback) |
safely frees callback structure memory and internals More... | |
int | evhtp_callbacks_add_callback (evhtp_callbacks_t *cbs, evhtp_callback_t *cb) |
Adds a evhtp_callback_t to the evhtp_callbacks_t list. More... | |
static int | htp__set_hook_ (evhtp_hooks_t **hooks, evhtp_hook_type type, evhtp_hook cb, void *arg) |
static int | htp__unset_hook_ (evhtp_hooks_t **hooks, evhtp_hook_type type) |
int | evhtp_callback_unset_hook (evhtp_callback_t *callback, evhtp_hook_type type) |
int | evhtp_request_unset_hook (evhtp_request_t *req, evhtp_hook_type type) |
int | evhtp_connection_unset_hook (evhtp_connection_t *conn, evhtp_hook_type type) |
int | evhtp_callback_set_hook (evhtp_callback_t *callback, evhtp_hook_type type, evhtp_hook cb, void *arg) |
int | evhtp_request_set_hook (evhtp_request_t *req, evhtp_hook_type type, evhtp_hook cb, void *arg) |
int | evhtp_connection_set_hook (evhtp_connection_t *conn, evhtp_hook_type type, evhtp_hook cb, void *arg) |
sets a callback hook for either a connection or a path/regex . More... | |
int | evhtp_unset_all_hooks (evhtp_hooks_t **hooks) |
removes all hooks. More... | |
evhtp_hooks_t * | evhtp_connection_get_hooks (evhtp_connection_t *c) |
evhtp_hooks_t * | evhtp_request_get_hooks (evhtp_request_t *r) |
returns request hooks More... | |
evhtp_hooks_t * | evhtp_callback_get_hooks (evhtp_callback_t *cb) |
returns callback hooks More... | |
evhtp_callback_t * | evhtp_set_cb (evhtp_t *htp, const char *path, evhtp_callback_cb cb, void *arg) |
sets a callback to be executed on a specific path More... | |
evhtp_callback_t * | evhtp_get_cb (evhtp_t *htp, const char *path) |
attempts to find the callback matching the exact string 'needle'. More... | |
static void | htp__thread_init_ (evthr_t *thr, void *arg) |
static void | htp__thread_exit_ (evthr_t *thr, void *arg) |
static int | htp__use_threads_ (evhtp_t *htp, evhtp_thread_init_cb init_cb, evhtp_thread_exit_cb exit_cb, int nthreads, void *arg) |
int | evhtp_use_threads (evhtp_t *htp, evhtp_thread_init_cb init_cb, int nthreads, void *arg) |
Enable thread-pool support for an evhtp_t context. More... | |
int | evhtp_use_threads_wexit (evhtp_t *htp, evhtp_thread_init_cb init_cb, evhtp_thread_exit_cb exit_cb, int nthreads, void *arg) |
Temporary function which will be renamed evhtp_use_threads in the future. More... | |
int | evhtp_use_callback_locks (evhtp_t *htp) |
creates a lock around callbacks and hooks, allowing for threaded applications to add/remove/modify hooks & callbacks in a thread-safe manner. More... | |
evhtp_callback_t * | evhtp_set_regex_cb (evhtp_t *htp, const char *pattern, evhtp_callback_cb cb, void *arg) |
sets a callback to be executed based on a regex pattern More... | |
evhtp_callback_t * | evhtp_set_glob_cb (evhtp_t *htp, const char *pattern, evhtp_callback_cb cb, void *arg) |
sets a callback to to be executed on simple glob/wildcard patterns this is useful if the app does not care about what was matched, but just that it matched. More... | |
void | evhtp_set_gencb (evhtp_t *htp, evhtp_callback_cb cb, void *arg) |
sets a callback which is called if no other callbacks are matched More... | |
void | evhtp_set_pre_accept_cb (evhtp_t *htp, evhtp_pre_accept_cb cb, void *arg) |
call a user-defined function before the connection is accepted. More... | |
void | evhtp_set_post_accept_cb (evhtp_t *htp, evhtp_post_accept_cb cb, void *arg) |
call a user-defined function right after a connection is accepted. More... | |
int | evhtp_ssl_use_threads (void) |
int | evhtp_ssl_init (evhtp_t *htp, evhtp_ssl_cfg_t *cfg) |
struct bufferevent * | evhtp_connection_get_bev (evhtp_connection_t *connection) |
returns the underlying connections bufferevent More... | |
struct bufferevent * | evhtp_connection_take_ownership (evhtp_connection_t *connection) |
let a user take ownership of the underlying bufferevent and free all other underlying resources. More... | |
struct bufferevent * | evhtp_request_get_bev (evhtp_request_t *request) |
returns the underlying requests bufferevent More... | |
struct bufferevent * | evhtp_request_take_ownership (evhtp_request_t *request) |
void | evhtp_connection_set_bev (evhtp_connection_t *conn, struct bufferevent *bev) |
Sets the connections underlying bufferevent. More... | |
void | evhtp_request_set_bev (evhtp_request_t *request, struct bufferevent *bev) |
sets the underlying bufferevent for a evhtp_request More... | |
void | evhtp_request_set_keepalive (evhtp_request_t *request, int val) |
evhtp_connection_t * | evhtp_request_get_connection (evhtp_request_t *request) |
returns the underlying evhtp_connection_t structure from a request More... | |
evhtp_proto | evhtp_request_get_proto (evhtp_request_t *request) |
void | evhtp_connection_set_timeouts (evhtp_connection_t *c, const struct timeval *rtimeo, const struct timeval *wtimeo) |
sets a connection-specific read/write timeout which overrides the global read/write settings. More... | |
void | evhtp_connection_set_max_body_size (evhtp_connection_t *c, uint64_t len) |
set a max body size for a specific connection, this will default to the size set by evhtp_set_max_body_size More... | |
void | evhtp_request_set_max_body_size (evhtp_request_t *req, uint64_t len) |
just calls evhtp_connection_set_max_body_size for the request. More... | |
void | evhtp_connection_free (evhtp_connection_t *connection) |
free's all connection related resources, this will also call your request fini hook and request fini hook. More... | |
void | evhtp_request_free (evhtp_request_t *request) |
void | evhtp_set_timeouts (evhtp_t *htp, const struct timeval *r_timeo, const struct timeval *w_timeo) |
set a read/write timeout on all things evhtp_t. More... | |
void | evhtp_set_max_keepalive_requests (evhtp_t *htp, uint64_t num) |
sets a maximum number of requests that a single connection can make. More... | |
void | evhtp_set_bev_flags (evhtp_t *htp, int flags) |
bufferevent flags which will be used for bev sockets. More... | |
void | evhtp_set_max_body_size (evhtp_t *htp, uint64_t len) |
set a max body size to accept for an incoming request, this will default to unlimited. More... | |
void | evhtp_disable_100_continue (evhtp_t *htp) |
void | evhtp_set_parser_flags (evhtp_t *htp, int flags) |
during the request processing cycle, these flags will be used to for query argument parsing. More... | |
HTP_FLAG_FNGEN (, evhtp_t *) | |
HTP_FLAG_FNGEN (_connection, evhtp_connection_t *) | |
HTP_FLAG_FNGEN (_request, evhtp_request_t *) | |
int | evhtp_add_alias (evhtp_t *evhtp, const char *name) |
Add an alias hostname for a virtual-host specific evhtp_t. More... | |
int | evhtp_add_aliases (evhtp_t *htp, const char *name,...) |
set a variable number of aliases in one call evhtp_add_alias More... | |
int | evhtp_add_vhost (evhtp_t *evhtp, const char *name, evhtp_t *vhost) |
add an evhtp_t structure (with its own callbacks) to a base evhtp_t structure for virtual hosts. More... | |
static int | evhtp__new_ (evhtp_t **out, struct event_base *evbase, void *arg) |
Allocates new evhtp_t structure. More... | |
evhtp_t * | evhtp_new (struct event_base *evbase, void *arg) |
creates a new evhtp_t instance More... | |
void | evhtp_free (evhtp_t *evhtp) |
Frees evhtp_t structure; will stop and free threads associated with the structure, and free the ssl context as well (if applicable). More... | |
evhtp_connection_t * | evhtp_connection_new (struct event_base *evbase, const char *addr, uint16_t port) |
allocate a new connection More... | |
evhtp_connection_t * | evhtp_connection_new_dns (struct event_base *evbase, struct evdns_base *dns_base, const char *addr, uint16_t port) |
allocate a new connection More... | |
evhtp_connection_t * | evhtp_connection_ssl_new (struct event_base *evbase, const char *addr, uint16_t port, evhtp_ssl_ctx_t *ctx) |
evhtp_request_t * | evhtp_request_new (evhtp_callback_cb cb, void *arg) |
allocate a new request More... | |
int | evhtp_make_request (evhtp_connection_t *c, evhtp_request_t *r, htp_method meth, const char *uri) |
make a client request More... | |
unsigned int | evhtp_request_status (evhtp_request_t *r) |
Variables | |
static void *(* | malloc_ )(size_t sz) = malloc |
static void *(* | realloc_ )(void *d, size_t sz) = realloc |
static void(* | free_ )(void *d) = free |
static int | session_id_context = 1 |
static int | ssl_num_locks |
static evhtp_mutex_t * | ssl_locks |
static int | ssl_locks_initialized = 0 |
static htparse_hooks | request_psets |
callback definitions for request processing from libhtparse More... | |
implementation file for libevhtp.
Definition in file evhtp.c.
#define HOOK_ARGS | ( | var, | |
hook_name | |||
) | var->hooks->hook_name ## _arg |
#define HOOK_AVAIL | ( | var, | |
hook_name | |||
) | (var->hooks && var->hooks->hook_name) |
#define HOOK_REQUEST_RUN | ( | request, | |
hook_name, | |||
... | |||
) |
#define HOOK_REQUEST_RUN_NARGS | ( | __request, | |
hook_name | |||
) |
#define htp__is_http_10_ | ( | _major, | |
_minor | |||
) | (_major >= 1 && _minor <= 0) |
#define htp__is_http_11_ | ( | _major, | |
_minor | |||
) | (_major >= 1 && _minor >= 1) |
#define htp__lock_ | ( | h | ) |
#define htp__unlock_ | ( | h | ) |
#define HTP_FLAG_FNGEN | ( | NAME, | |
TYPE | |||
) |
#define HTP_FLAG_OFF | ( | PRE, | |
FLAG | |||
) | UNSET_BIT(PRE->flags, FLAG) |
enum query_parser_state |
enum unscape_state |
|
static |
Allocates new evhtp_t structure.
[OUT] | out - double ptr to evhtp_t structure. |
[IN] | evbase - event_base structure |
[IN] | arg - anonymous argument |
Definition at line 5284 of file evhtp.c.
int evhtp_accept_socket | ( | evhtp_t * | htp, |
evutil_socket_t | sock, | ||
int | backlog | ||
) |
create the listener plus setup various options with an already-bound socket.
htp | |
sock | |
backlog |
Definition at line 3951 of file evhtp.c.
int evhtp_add_alias | ( | evhtp_t * | evhtp, |
const char * | name | ||
) |
Add an alias hostname for a virtual-host specific evhtp_t.
This avoids having multiple evhtp_t virtual hosts with the same callback for the same vhost.
evhtp | |
name |
Definition at line 5186 of file evhtp.c.
int evhtp_add_aliases | ( | evhtp_t * | evhtp, |
const char * | name, | ||
... | |||
) |
int evhtp_add_vhost | ( | evhtp_t * | evhtp, |
const char * | name, | ||
evhtp_t * | vhost | ||
) |
add an evhtp_t structure (with its own callbacks) to a base evhtp_t structure for virtual hosts.
It should be noted that if you enable SSL on the base evhtp_t and your version of OpenSSL supports SNI, the SNI hostname will always take precedence over the Host header value.
evhtp | |
name | |
vhost |
Definition at line 5236 of file evhtp.c.
int evhtp_bind_sockaddr | ( | evhtp_t * | htp, |
struct sockaddr * | , | ||
size_t | sin_len, | ||
int | backlog | ||
) |
bind to an already allocated sockaddr.
htp | - ptr to evhtp_t structure |
sa | - ptr to sockaddr structure |
sin_len | - size of sockaddr structure |
backlog | - backlog flag |
Definition at line 4045 of file evhtp.c.
int evhtp_bind_socket | ( | evhtp_t * | htp, |
const char * | addr, | ||
uint16_t | port, | ||
int | backlog | ||
) |
bind to a socket, optionally with specific protocol support formatting.
The addr can be defined as one of the following: ipv6:<ipv6addr> for binding to an IPv6 address. unix:<named pipe>=""> for binding to a unix named socket ipv4:<ipv4addr> for binding to an ipv4 address Otherwise the addr is assumed to be ipv4.
htp | |
addr | |
port | |
backlog |
Definition at line 4122 of file evhtp.c.
void evhtp_callback_free | ( | evhtp_callback_t * | callback | ) |
safely frees callback structure memory and internals
callback | - callback to be freed |
Definition at line 4244 of file evhtp.c.
evhtp_hooks_t* evhtp_callback_get_hooks | ( | evhtp_callback_t * | cb | ) |
evhtp_callback_t* evhtp_callback_new | ( | const char * | path, |
evhtp_callback_type | type, | ||
evhtp_callback_cb | cb, | ||
void * | arg | ||
) |
creates a new evhtp_callback_t structure.
All callbacks are stored in this structure which define what the final function to be called after all parsing is done. A callback can be either a static string or a regular expression.
path | can either be a static path (/path/to/resource/) or a POSIX compatible regular expression (^/resource/(.*)) |
type | informs the function what type of of information is is contained within the path argument. This can either be callback_type_path, or callback_type_regex. |
cb | the callback function to be invoked |
arg | optional argument which is passed when the callback is executed. |
Definition at line 4199 of file evhtp.c.
int evhtp_callback_set_hook | ( | evhtp_callback_t * | callback, |
evhtp_hook_type | type, | ||
evhtp_hook | cb, | ||
void * | arg | ||
) |
int evhtp_callback_unset_hook | ( | evhtp_callback_t * | callback, |
evhtp_hook_type | type | ||
) |
int evhtp_callbacks_add_callback | ( | evhtp_callbacks_t * | cbs, |
evhtp_callback_t * | cb | ||
) |
void evhtp_callbacks_free | ( | evhtp_callbacks_t * | callbacks | ) |
void evhtp_connection_free | ( | evhtp_connection_t * | connection | ) |
struct bufferevent* evhtp_connection_get_bev | ( | evhtp_connection_t * | conn | ) |
evhtp_hooks_t* evhtp_connection_get_hooks | ( | evhtp_connection_t * | c | ) |
evhtp_connection_t* evhtp_connection_new | ( | struct event_base * | evbase, |
const char * | addr, | ||
uint16_t | port | ||
) |
evhtp_connection_t* evhtp_connection_new_dns | ( | struct event_base * | evbase, |
struct evdns_base * | dns_base, | ||
const char * | addr, | ||
uint16_t | port | ||
) |
void evhtp_connection_pause | ( | evhtp_connection_t * | connection | ) |
void evhtp_connection_resume | ( | evhtp_connection_t * | connection | ) |
void evhtp_connection_set_bev | ( | evhtp_connection_t * | conn, |
struct bufferevent * | bev | ||
) |
int evhtp_connection_set_hook | ( | evhtp_connection_t * | c, |
evhtp_hook_type | type, | ||
evhtp_hook | cb, | ||
void * | arg | ||
) |
sets a callback hook for either a connection or a path/regex .
A user may set a variety of hooks either per-connection, or per-callback. This allows the developer to hook into various parts of the request processing cycle.
a per-connection hook can be set at any time, but it is recommended to set these during either a pre-accept phase, or post-accept phase. This allows a developer to set hooks before any other hooks are called.
a per-callback hook works differently. In this mode a developer can setup a set of hooks prior to starting the event loop for specific callbacks. For example if you wanted to hook something ONLY for a callback set by evhtp_set_cb or evhtp_set_regex_cb this is the method of doing so.
per-callback example:
evhtp_callback_t * cb = evhtp_set_regex_cb(htp, "/anything/(.*)", default_cb, NULL);
evhtp_set_hook(&cb->hooks, evhtp_hook_on_headers, anything_headers_cb, NULL);
evhtp_set_hook(&cb->hooks, evhtp_hook_on_fini, anything_fini_cb, NULL);
With the above example, once libevhtp has determined that it has a user-defined callback for /anything/.*; anything_headers_cb will be executed after all headers have been parsed, and anything_fini_cb will be executed before the request is free()'d.
The same logic applies to per-connection hooks, but it should be noted that if a per-callback hook is set, the per-connection hook will be ignored.
hooks | double pointer to the evhtp_hooks_t structure |
type | the hook type |
cb | the callback to be executed. |
arg | optional argument which is passed when the callback is executed |
Definition at line 4399 of file evhtp.c.
void evhtp_connection_set_max_body_size | ( | evhtp_connection_t * | conn, |
uint64_t | len | ||
) |
|
inline |
evhtp_connection_t* evhtp_connection_ssl_new | ( | struct event_base * | evbase, |
const char * | addr, | ||
uint16_t | port, | ||
evhtp_ssl_ctx_t * | ctx | ||
) |
struct bufferevent* evhtp_connection_take_ownership | ( | evhtp_connection_t * | connection | ) |
let a user take ownership of the underlying bufferevent and free all other underlying resources.
Warning: this will free all evhtp_connection/request structures, remove all associated hooks and reset the bufferevent to defaults, i.e., disable EV_READ, and set all callbacks to NULL.
connection |
Definition at line 4972 of file evhtp.c.
int evhtp_connection_unset_hook | ( | evhtp_connection_t * | conn, |
evhtp_hook_type | type | ||
) |
evhtp_callback_t* evhtp_get_cb | ( | evhtp_t * | htp, |
const char * | needle | ||
) |
attempts to find the callback matching the exact string 'needle'.
This is useful in cases where we want to get the original handle, but is not in scope.
with pattern based callbacks, this does not attempt to find a callback that would match the string if the pattern matcher was executed.
Meaning: evhtp_set_glob_cb(htp, "/foo/bar*", ....);
Calling evhtp_get_cb(htp, "/foo/bar/baz");
Will return NULL since it's not the exact pattern set
Calling evhtp_get_cb(htp, "/foo/bar*");
Is the correct usage.
htp | |
needle |
evhtp_header_t* evhtp_header_key_add | ( | evhtp_headers_t * | headers, |
const char * | key, | ||
char | kalloc | ||
) |
creates a new evhtp_header_t, sets only the key, and adds to the evhtp_headers TAILQ
headers | the evhtp_headers_t TAILQ (evhtp_kv_t) |
key | a null terminated string |
kalloc | if 1 the string will be copied, otherwise assigned |
Definition at line 3081 of file evhtp.c.
evhtp_header_t* evhtp_header_val_add | ( | evhtp_headers_t * | headers, |
const char * | val, | ||
char | valloc | ||
) |
finds the last header in the headers tailq and adds the value
headers | the evhtp_headers_t TAILQ (evhtp_kv_t) |
val | a null terminated string |
valloc | if 1 the string will be copied, otherwise assigned |
Definition at line 3096 of file evhtp.c.
|
inlinestatic |
const char* evhtp_kv_find | ( | evhtp_kvs_t * | kvs, |
const char * | key | ||
) |
void evhtp_kv_free | ( | evhtp_kv_t * | kv | ) |
evhtp_kv_t* evhtp_kv_new | ( | const char * | key, |
const char * | val, | ||
char | kalloc, | ||
char | valloc | ||
) |
Allocates a new key/value structure.
key | null terminated string |
val | null terminated string |
kalloc | if set to 1, the key will be copied, if 0 no copy is done. |
valloc | if set to 1, the val will be copied, if 0 no copy is done. |
Definition at line 3147 of file evhtp.c.
void evhtp_kv_rm_and_free | ( | evhtp_kvs_t * | kvs, |
evhtp_kv_t * | kv | ||
) |
void evhtp_kvs_add_kv | ( | evhtp_kvs_t * | kvs, |
evhtp_kv_t * | kv | ||
) |
void evhtp_kvs_add_kvs | ( | evhtp_kvs_t * | dst, |
evhtp_kvs_t * | src | ||
) |
evhtp_kv_t* evhtp_kvs_find_kv | ( | evhtp_kvs_t * | kvs, |
const char * | key | ||
) |
int evhtp_kvs_for_each | ( | evhtp_kvs_t * | kvs, |
evhtp_kvs_iterator | cb, | ||
void * | arg | ||
) |
void evhtp_kvs_free | ( | evhtp_kvs_t * | kvs | ) |
evhtp_kvs_t* evhtp_kvs_new | ( | void | ) |
int evhtp_make_request | ( | evhtp_connection_t * | c, |
evhtp_request_t * | r, | ||
htp_method | meth, | ||
const char * | uri | ||
) |
evhtp_query_t* evhtp_parse_query | ( | const char * | query, |
size_t | len | ||
) |
Parses the query portion of the uri into a set of key/values in a strict manner.
Parses query arguments like "?herp=derp&foo=bar&blah=baz"
query | data containing the uri query arguments |
len | size of the data |
Definition at line 3748 of file evhtp.c.
evhtp_query_t* evhtp_parse_query_wflags | ( | const char * | query, |
size_t | len, | ||
int | flags | ||
) |
Parses the query portion of the uri into a set of key/values.
Parses query arguments like "?herp=&foo=bar;blah=baz&a=%3"
query | data containing the uri query arguments |
len | size of the data |
flags | parse query flags to alter 'strictness' (see EVHTP_PARSE_QUERY_FLAG_*) |
Definition at line 3482 of file evhtp.c.
void evhtp_request_free | ( | evhtp_request_t * | request | ) |
struct bufferevent* evhtp_request_get_bev | ( | evhtp_request_t * | request | ) |
evhtp_connection_t* evhtp_request_get_connection | ( | evhtp_request_t * | request | ) |
evhtp_hooks_t* evhtp_request_get_hooks | ( | evhtp_request_t * | r | ) |
htp_method evhtp_request_get_method | ( | evhtp_request_t * | r | ) |
evhtp_proto evhtp_request_get_proto | ( | evhtp_request_t * | request | ) |
evhtp_request_t* evhtp_request_new | ( | evhtp_callback_cb | cb, |
void * | arg | ||
) |
void evhtp_request_pause | ( | evhtp_request_t * | request | ) |
Wrapper around evhtp_connection_pause.
request |
Definition at line 3064 of file evhtp.c.
void evhtp_request_resume | ( | evhtp_request_t * | request | ) |
Wrapper around evhtp_connection_resume.
request |
Definition at line 3073 of file evhtp.c.
void evhtp_request_set_bev | ( | evhtp_request_t * | request, |
struct bufferevent * | bev | ||
) |
int evhtp_request_set_hook | ( | evhtp_request_t * | req, |
evhtp_hook_type | type, | ||
evhtp_hook | cb, | ||
void * | arg | ||
) |
void evhtp_request_set_keepalive | ( | evhtp_request_t * | request, |
int | val | ||
) |
void evhtp_request_set_max_body_size | ( | evhtp_request_t * | request, |
uint64_t | len | ||
) |
unsigned int evhtp_request_status | ( | evhtp_request_t * | r | ) |
struct bufferevent* evhtp_request_take_ownership | ( | evhtp_request_t * | request | ) |
int evhtp_request_unset_hook | ( | evhtp_request_t * | req, |
evhtp_hook_type | type | ||
) |
int evhtp_response_needs_body | ( | const evhtp_res | code, |
const htp_method | method | ||
) |
void evhtp_send_reply | ( | evhtp_request_t * | request, |
evhtp_res | code | ||
) |
void evhtp_send_reply_body | ( | evhtp_request_t * | request, |
struct evbuffer * | buf | ||
) |
void evhtp_send_reply_chunk | ( | evhtp_request_t * | request, |
struct evbuffer * | buf | ||
) |
void evhtp_send_reply_chunk_end | ( | evhtp_request_t * | request | ) |
void evhtp_send_reply_chunk_start | ( | evhtp_request_t * | request, |
evhtp_res | code | ||
) |
void evhtp_send_reply_end | ( | evhtp_request_t * | request | ) |
void evhtp_send_reply_start | ( | evhtp_request_t * | request, |
evhtp_res | code | ||
) |
void evhtp_set_bev_flags | ( | evhtp_t * | htp, |
int | flags | ||
) |
evhtp_callback_t* evhtp_set_cb | ( | evhtp_t * | htp, |
const char * | path, | ||
evhtp_callback_cb | cb, | ||
void * | arg | ||
) |
sets a callback to be executed on a specific path
htp | the initialized evhtp_t |
path | the path to match |
cb | the function to be executed |
arg | user-defined argument passed to the callback |
Definition at line 4484 of file evhtp.c.
void evhtp_set_gencb | ( | evhtp_t * | htp, |
evhtp_callback_cb | cb, | ||
void * | arg | ||
) |
evhtp_callback_t* evhtp_set_glob_cb | ( | evhtp_t * | htp, |
const char * | pattern, | ||
evhtp_callback_cb | cb, | ||
void * | arg | ||
) |
sets a callback to to be executed on simple glob/wildcard patterns this is useful if the app does not care about what was matched, but just that it matched.
This is technically faster than regex.
htp | |
pattern | wildcard pattern, the '*' can be set at either or both the front or end. |
cb | |
arg |
Definition at line 4678 of file evhtp.c.
void evhtp_set_max_body_size | ( | evhtp_t * | htp, |
uint64_t | len | ||
) |
void evhtp_set_max_keepalive_requests | ( | evhtp_t * | htp, |
uint64_t | num | ||
) |
void evhtp_set_mem_functions | ( | void *(*)(size_t len) | mallocfn_, |
void *(*)(void *p, size_t sz) | reallocfn_, | ||
void(*)(void *p) | freefn_ | ||
) |
void evhtp_set_parser_flags | ( | evhtp_t * | htp, |
int | flags | ||
) |
during the request processing cycle, these flags will be used to for query argument parsing.
i.e., what to parse and not to parse.
SEE: EVHTP_PARSE_QUERY_* stuff. For example, if you do not wish for the streaming parser attempting the act of fragment parsing: evhtp_set_parser_flags(htp, EVHTP_PARSE_QUERY_FLAG_IGNORE_FRAGMENTS);
htp | |
flags |
void evhtp_set_post_accept_cb | ( | evhtp_t * | htp, |
evhtp_post_accept_cb | , | ||
void * | arg | ||
) |
void evhtp_set_pre_accept_cb | ( | evhtp_t * | htp, |
evhtp_pre_accept_cb | , | ||
void * | arg | ||
) |
evhtp_callback_t* evhtp_set_regex_cb | ( | evhtp_t * | htp, |
const char * | pattern, | ||
evhtp_callback_cb | cb, | ||
void * | arg | ||
) |
sets a callback to be executed based on a regex pattern
htp | the initialized evhtp_t |
pattern | a POSIX compat regular expression |
cb | the function to be executed |
arg | user-defined argument passed to the callback |
Definition at line 4637 of file evhtp.c.
void evhtp_set_timeouts | ( | evhtp_t * | htp, |
const struct timeval * | r, | ||
const struct timeval * | w | ||
) |
int evhtp_ssl_init | ( | evhtp_t * | htp, |
evhtp_ssl_cfg_t * | cfg | ||
) |
int evhtp_ssl_use_threads | ( | void | ) |
void evhtp_unbind_socket | ( | evhtp_t * | htp | ) |
int evhtp_unescape_string | ( | unsigned char ** | out, |
unsigned char * | str, | ||
size_t | str_len | ||
) |
int evhtp_unset_all_hooks | ( | evhtp_hooks_t ** | hooks | ) |
int evhtp_use_callback_locks | ( | evhtp_t * | htp | ) |
int evhtp_use_threads | ( | evhtp_t * | , |
evhtp_thread_init_cb | , | ||
int | nthreads, | ||
void * | |||
) |
Enable thread-pool support for an evhtp_t context.
Connectios are distributed across 'nthreads'. An optional "on-start" callback can be set which allows you to manipulate the thread-specific inforation (such as the thread-specific event_base).
htp | |
init_cb | |
exit_cb | |
nthreads | |
arg |
Definition at line 4599 of file evhtp.c.
int evhtp_use_threads_wexit | ( | evhtp_t * | , |
evhtp_thread_init_cb | , | ||
evhtp_thread_exit_cb | , | ||
int | nthreads, | ||
void * | arg | ||
) |
Temporary function which will be renamed evhtp_use_threads in the future.
evhtp_use_threads() has been noted as deprecated for now
Definition at line 4606 of file evhtp.c.
|
static |
|
static |
|
static |
|
static |
|
static |
Wrapper for calloc so that a different calloc can be used if desired.
nmemb | number of members (as a size_t) |
size | size of member blocks (as a size_t) |
Definition at line 228 of file evhtp.c.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Wrapper for free so that a different free can be used if desired.
ptr | pointer to memory to be freed. |
Definition at line 211 of file evhtp.c.
|
static |
|
inlinestatic |
runs the user-defined on_body hook for requests containing a body.
the data is stored in the request->buffer_in so the user may either leave it, or drain upon being called.
request | the request strucutre |
buf | a evbuffer containing body data |
Definition at line 635 of file evhtp.c.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
runs the user-defined on_header hook for a request
once a full key: value header has been parsed, this will call the hook
request | the request strucutre |
header | the header structure |
Definition at line 600 of file evhtp.c.
|
inlinestatic |
runs the user-defined on_Headers hook for a request after all headers have been parsed.
request | the request structure |
headers | the headers tailq structure |
Definition at line 617 of file evhtp.c.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
static |
Wrapper for malloc so that a different malloc can be used if desired.
size | size_t of memory to be allocated |
Definition at line 179 of file evhtp.c.
|
static |
|
static |
parses the path and file from an input buffer
in order to properly create a structure that can match both a path and a file, this will parse a string into what it considers a path, and a file.
if for example the input was "/a/b/c", the parser will consider "/a/b/" as the path, and "c" as the file.
the | unallocated destination buffer. |
data | raw input data (assumes a /path/[file] structure) |
len | length of the input data |
Definition at line 990 of file evhtp.c.
|
inlinestatic |
|
static |
Wrapper for realloc so that a different realloc can be used if desired.
ptr | current memory ptr |
size | size_t of memory to be allocated |
|
inlinestatic |
|
static |
|
static |
|
static |
parses http request arguments
p | |
data | |
len |
Definition at line 1367 of file evhtp.c.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
inlinestatic |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
determines if the request body contains the query arguments.
if the query is NULL and the content length of the body has never been drained, and the content-type is x-www-form-urlencoded, the function returns 1
req |
Definition at line 1970 of file evhtp.c.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
HTP_FLAG_FNGEN | ( | evhtp_t * | ) |
HTP_FLAG_FNGEN | ( | _connection | , |
evhtp_connection_t * | |||
) |
HTP_FLAG_FNGEN | ( | _request | , |
evhtp_request_t * | |||
) |
|
static |
TAILQ_HEAD | ( | evhtp_callbacks_s | , |
evhtp_callback_s | |||
) |
|
static |
callback definitions for request processing from libhtparse
|
static |