Libevhtp  0.3.7
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Macros | Enumerations | Functions | Variables
evhtp.c File Reference
#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 "evhtp-internal.h"
#include "evhtp_numtoa.h"
#include "evhtp.h"

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 
#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 HOOK_CONN_RUN(conn, hook_name,...)
 
#define _evhtp_lock(h)
 
#define _evhtp_unlock(h)
 
#define _evhtp_is_http_11(_major, _minor)   (_major >= 1 && _minor >= 1)
 helper macro to determine if http version is HTTP/1.0 More...
 
#define _evhtp_is_http_10(_major, _minor)   (_major >= 1 && _minor <= 0)
 helper function to determine if http version is HTTP/1.1 More...
 

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

static int _evhtp_request_parser_start (htparser *p)
 
static int _evhtp_request_parser_host (htparser *p, const char *data, size_t len)
 
static int _evhtp_request_parser_port (htparser *p, const char *data, size_t len)
 
static int _evhtp_request_parser_path (htparser *p, const char *data, size_t len)
 
static int _evhtp_request_parser_args (htparser *p, const char *data, size_t len)
 
static int _evhtp_request_parser_header_key (htparser *p, const char *data, size_t len)
 
static int _evhtp_request_parser_header_val (htparser *p, const char *data, size_t len)
 
static int _evhtp_request_parser_hostname (htparser *p, const char *data, size_t len)
 
static int _evhtp_request_parser_headers (htparser *p)
 
static int _evhtp_request_parser_body (htparser *p, const char *data, size_t len)
 
static int _evhtp_request_parser_fini (htparser *p)
 
static int _evhtp_request_parser_chunk_new (htparser *p)
 
static int _evhtp_request_parser_chunk_fini (htparser *p)
 
static int _evhtp_request_parser_chunks_fini (htparser *p)
 
static int _evhtp_request_parser_headers_start (htparser *p)
 
static void _evhtp_connection_readcb (evbev_t *bev, void *arg)
 
static evhtp_connection_t_evhtp_connection_new (evhtp_t *htp, evutil_socket_t sock, evhtp_type type)
 
static evhtp_uri_t_evhtp_uri_new (void)
 create an overlay URI structure More...
 
static void _evhtp_uri_free (evhtp_uri_t *uri)
 frees an overlay URI structure More...
 
static evhtp_authority_t_evhtp_authority_new (void)
 create an authority structure More...
 
static void _evhtp_authority_free (evhtp_authority_t *authority)
 frees an authority structure More...
 
static evhtp_path_t_evhtp_path_new (const char *data, size_t len)
 parses the path and file from an input buffer More...
 
static void _evhtp_path_free (evhtp_path_t *path)
 
static void _evhtp_request_free (evhtp_request_t *request)
 frees all data in an evhtp_request_t along with calling finished hooks More...
 
static const char * status_code_to_str (evhtp_res code)
 
static unsigned int _evhtp_quick_hash (const char *str)
 a weak hash function More...
 
static evhtp_proto _evhtp_protocol (const char major, const char minor)
 returns the HTTP protocol version More...
 
static evhtp_res _evhtp_path_hook (evhtp_request_t *request, evhtp_path_t *path)
 runs the user-defined on_path hook for a request More...
 
static evhtp_res _evhtp_header_hook (evhtp_request_t *request, evhtp_header_t *header)
 runs the user-defined on_header hook for a request More...
 
static evhtp_res _evhtp_headers_hook (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 _evhtp_body_hook (evhtp_request_t *request, evbuf_t *buf)
 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. More...
 
static evhtp_res _evhtp_request_fini_hook (evhtp_request_t *request)
 runs the user-defined hook called just prior to a request been free()'d More...
 
static evhtp_res _evhtp_chunk_new_hook (evhtp_request_t *request, uint64_t len)
 
static evhtp_res _evhtp_chunk_fini_hook (evhtp_request_t *request)
 
static evhtp_res _evhtp_chunks_fini_hook (evhtp_request_t *request)
 
static evhtp_res _evhtp_headers_start_hook (evhtp_request_t *request)
 
static evhtp_res _evhtp_connection_fini_hook (evhtp_connection_t *connection)
 runs the user-definedhook called just prior to a connection being closed More...
 
static void _evhtp_error_hook (evhtp_request_t *request, evhtp_error_flags errtype)
 runs the user-defined hook when a connection error occurs More...
 
static evhtp_res _evhtp_connection_error_hook (evhtp_connection_t *connection, evhtp_error_flags errtype)
 runs the user-defined hook when a connection error occurs More...
 
static evhtp_res _evhtp_hostname_hook (evhtp_request_t *r, const char *hostname)
 
static evhtp_res _evhtp_connection_write_hook (evhtp_connection_t *connection)
 
static int _evhtp_glob_match2 (const char *pattern, size_t plen, const char *string, size_t str_len)
 
static int _evhtp_glob_match (const char *pattern, size_t pat_len, const char *string, size_t str_len)
 glob/wildcard type pattern matching. More...
 
static evhtp_callback_t_evhtp_callback_find (evhtp_callbacks_t *cbs, const char *path, unsigned int *start_offset, unsigned int *end_offset)
 
static evhtp_request_t_evhtp_request_new (evhtp_connection_t *c)
 Creates a new evhtp_request_t. More...
 
static evhtp_t_evhtp_request_find_vhost (evhtp_t *evhtp, const char *name)
 
static int _evhtp_request_set_callbacks (evhtp_request_t *request)
 
static int _evhtp_require_uri (evhtp_connection_t *c)
 
static int _evhtp_should_parse_query_body (evhtp_request_t *req)
 determines if the request body contains the query arguments. if the query is NULL and the contenet length of the body has never been drained, and the content-type is x-www-form-urlencoded, the function returns 1 More...
 
static int _evhtp_create_headers (evhtp_header_t *header, void *arg)
 
static evbuf_t_evhtp_create_reply (evhtp_request_t *request, evhtp_res code)
 
static void _evhtp_connection_resumecb (int fd, short events, void *arg)
 
static void _evhtp_connection_writecb (evbev_t *bev, void *arg)
 
static void _evhtp_connection_eventcb (evbev_t *bev, short events, void *arg)
 
static int _evhtp_run_pre_accept (evhtp_t *htp, evhtp_connection_t *conn)
 
static int _evhtp_connection_accept (evbase_t *evbase, evhtp_connection_t *connection)
 
static void _evhtp_default_request_cb (evhtp_request_t *request, void *arg)
 
static int _evhtp_run_post_accept (evhtp_t *htp, evhtp_connection_t *connection)
 
static void _evhtp_run_in_thread (evthr_t *thr, void *arg, void *shared)
 
static void _evhtp_accept_cb (evserv_t *serv, int fd, struct sockaddr *s, int sl, void *arg)
 
static unsigned long _evhtp_ssl_get_thread_id (void)
 
static void _evhtp_ssl_thread_lock (int mode, int type, const char *file, int line)
 
static void _evhtp_ssl_delete_scache_ent (evhtp_ssl_ctx_t *ctx, evhtp_ssl_sess_t *sess)
 
static int _evhtp_ssl_add_scache_ent (evhtp_ssl_t *ssl, evhtp_ssl_sess_t *sess)
 
static evhtp_ssl_sess_t_evhtp_ssl_get_scache_ent (evhtp_ssl_t *ssl, unsigned char *sid, int sid_len, int *copy)
 
static int _evhtp_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_tevhtp_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 More...
 
evhtp_header_tevhtp_header_val_add (evhtp_headers_t *headers, const char *val, char valloc)
 finds the last header in the headers tailq and adds the value More...
 
evhtp_kvs_tevhtp_kvs_new (void)
 creates an empty list of key/values More...
 
evhtp_kv_tevhtp_kv_new (const char *key, const char *val, char kalloc, char valloc)
 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_tevhtp_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_tevhtp_parse_query_wflags (const char *query, size_t len, int flags)
 Parses the query portion of the uri into a set of key/values. More...
 
evhtp_query_tevhtp_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, evbuf_t *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. Follows the rules in RFC 2616 section 4.3. More...
 
void evhtp_send_reply_chunk_start (evhtp_request_t *request, evhtp_res code)
 start a chunked response. If data already exists on the output buffer, this will be converted to the first chunk. More...
 
void evhtp_send_reply_chunk (evhtp_request_t *request, evbuf_t *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. This will add the last 0CRLFCRCL and call send_reply_end(). More...
 
void evhtp_unbind_socket (evhtp_t *htp)
 stops the listening 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. 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. More...
 
void evhtp_callbacks_free (evhtp_callbacks_t *callbacks)
 
evhtp_callback_tevhtp_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)
 frees information associated with a ainflwx callback. 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...
 
int evhtp_set_hook (evhtp_hooks_t **hooks, 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_hook (evhtp_hooks_t **hooks, evhtp_hook_type type)
 remove a specific hook from being called. More...
 
int evhtp_unset_all_hooks (evhtp_hooks_t **hooks)
 removes all hooks. More...
 
evhtp_callback_tevhtp_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...
 
static void _evhtp_thread_init (evthr_t *thr, 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. 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). 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_tevhtp_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_tevhtp_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. 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)
 
void evhtp_set_post_accept_cb (evhtp_t *htp, evhtp_post_accept_cb cb, void *arg)
 
int evhtp_ssl_use_threads (void)
 
int evhtp_ssl_init (evhtp_t *htp, evhtp_ssl_cfg_t *cfg)
 
evbev_tevhtp_connection_get_bev (evhtp_connection_t *connection)
 returns the underlying connections bufferevent More...
 
evbev_tevhtp_connection_take_ownership (evhtp_connection_t *connection)
 let a user take ownership of the underlying bufferevent and free all other underlying resources. More...
 
evbev_tevhtp_request_get_bev (evhtp_request_t *request)
 returns the underlying requests bufferevent More...
 
evbev_tevhtp_request_take_ownership (evhtp_request_t *request)
 
void evhtp_connection_set_bev (evhtp_connection_t *conn, evbev_t *bev)
 Sets the connections underlying bufferevent. More...
 
void evhtp_request_set_bev (evhtp_request_t *request, evbev_t *bev)
 sets the underlying bufferevent for a evhtp_request More...
 
evhtp_connection_tevhtp_request_get_connection (evhtp_request_t *request)
 returns the underlying evhtp_connection_t structure from a request More...
 
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. When the timeout expires your error hook will be called with the libevent supplied event flags. 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)
 set bufferevent flags, defaults to BEV_OPT_CLOSE_ON_FREE 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)
 when a client sends an Expect: 100-continue, if this is function is called, evhtp will not send a HTTP/x.x continue response. More...
 
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. More...
 
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. More...
 
int evhtp_add_vhost (evhtp_t *evhtp, const char *name, evhtp_t *vhost)
 add a virtual host. More...
 
evhtp_tevhtp_new (evbase_t *evbase, void *arg)
 creates a new evhtp_t instance More...
 
void evhtp_free (evhtp_t *evhtp)
 
int evhtp_connection_set_rate_limit (evhtp_connection_t *conn, size_t read_rate, size_t read_burst, size_t write_rate, size_t write_burst, const struct timeval *tick)
 
evhtp_connection_tevhtp_connection_new (evbase_t *evbase, const char *addr, uint16_t port)
 allocate a new connection More...
 
evhtp_connection_tevhtp_connection_new_dns (evbase_t *evbase, struct evdns_base *dns_base, const char *addr, uint16_t port)
 allocate a new connection More...
 
evhtp_connection_tevhtp_connection_ssl_new (evbase_t *evbase, const char *addr, uint16_t port, evhtp_ssl_ctx_t *ctx)
 
evhtp_request_tevhtp_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 htparse_hooks request_psets
 callback definitions for request processing from libhtparse More...
 
static int session_id_context = 1
 
static int ssl_num_locks
 
static evhtp_mutex_tssl_locks
 
static int ssl_locks_initialized = 0
 

Macro Definition Documentation

#define _evhtp_is_http_10 (   _major,
  _minor 
)    (_major >= 1 && _minor <= 0)

helper function to determine if http version is HTTP/1.1

Parameters
majorthe major version number
minorthe minor version number
Returns
1 if HTTP/1.1, else 0

Definition at line 346 of file evhtp.c.

#define _evhtp_is_http_11 (   _major,
  _minor 
)    (_major >= 1 && _minor >= 1)

helper macro to determine if http version is HTTP/1.0

Parameters
majorthe major version number
minorthe minor version number
Returns
1 if HTTP/1.0, else 0

Definition at line 335 of file evhtp.c.

#define _evhtp_lock (   h)
Value:
do { \
if (h->lock) { \
pthread_mutex_lock(h->lock); \
} \
} while (0)

Definition at line 106 of file evhtp.c.

#define _evhtp_unlock (   h)
Value:
do { \
if (h->lock) { \
pthread_mutex_unlock(h->lock); \
} \
} while (0)

Definition at line 112 of file evhtp.c.

#define _GNU_SOURCE

Definition at line 1 of file evhtp.c.

#define HOOK_ARGS (   var,
  hook_name 
)    var->hooks->hook_name ## _arg

Definition at line 64 of file evhtp.c.

#define HOOK_AVAIL (   var,
  hook_name 
)    (var->hooks && var->hooks->hook_name)

Definition at line 62 of file evhtp.c.

#define HOOK_CONN_RUN (   conn,
  hook_name,
  ... 
)
Value:
do { \
if (conn->request) { \
evhtp_request_t * request = conn->request; \
if (HOOK_AVAIL(request, hook_name)) { \
return HOOK_FUNC(conn, hook_name) (conn, __VA_ARGS__, \
HOOK_ARGS(conn, hook_name)); \
} \
} \
\
if (HOOK_AVAIL(conn, hook_name)) { \
return HOOK_FUNC(conn, hook_name) (conn, __VA_ARGS__, \
HOOK_ARGS(conn, hook_name)); \
} \
} while (0);
#define HOOK_ARGS(var, hook_name)
Definition: evhtp.c:64
struct evhtp_request_s evhtp_request_t
Definition: evhtp.h:79
#define HOOK_AVAIL(var, hook_name)
Definition: evhtp.c:62
#define HOOK_FUNC(var, hook_name)
Definition: evhtp.c:63

Definition at line 90 of file evhtp.c.

#define HOOK_FUNC (   var,
  hook_name 
)    (var->hooks->hook_name)

Definition at line 63 of file evhtp.c.

#define HOOK_REQUEST_RUN (   request,
  hook_name,
  ... 
)
Value:
do { \
if (HOOK_AVAIL(request, hook_name)) { \
return HOOK_FUNC(request, hook_name) (request, __VA_ARGS__, \
HOOK_ARGS(request, hook_name)); \
} \
\
if (HOOK_AVAIL(evhtp_request_get_connection(request), hook_name)) { \
return HOOK_FUNC(request->conn, hook_name) (request, __VA_ARGS__, \
HOOK_ARGS(request->conn, hook_name)); \
} \
} while (0)
evhtp_connection_t * evhtp_request_get_connection(evhtp_request_t *request)
returns the underlying evhtp_connection_t structure from a request
Definition: evhtp.c:3894
#define HOOK_ARGS(var, hook_name)
Definition: evhtp.c:64
#define HOOK_AVAIL(var, hook_name)
Definition: evhtp.c:62
#define HOOK_FUNC(var, hook_name)
Definition: evhtp.c:63

Definition at line 66 of file evhtp.c.

#define HOOK_REQUEST_RUN_NARGS (   request,
  hook_name 
)
Value:
do { \
if (HOOK_AVAIL(request, hook_name)) { \
return HOOK_FUNC(request, hook_name) (request, \
HOOK_ARGS(request, hook_name)); \
} \
\
if (HOOK_AVAIL(request->conn, hook_name)) { \
return HOOK_FUNC(request->conn, hook_name) (request, \
HOOK_ARGS(request->conn, hook_name)); \
} \
} while (0);
#define HOOK_ARGS(var, hook_name)
Definition: evhtp.c:64
#define HOOK_AVAIL(var, hook_name)
Definition: evhtp.c:62
#define HOOK_FUNC(var, hook_name)
Definition: evhtp.c:63

Definition at line 78 of file evhtp.c.

Enumeration Type Documentation

Enumerator
s_query_start 
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 

Definition at line 2614 of file evhtp.c.

Enumerator
unscape_state_start 
unscape_state_hex1 
unscape_state_hex2 

Definition at line 2653 of file evhtp.c.

Function Documentation

static void _evhtp_accept_cb ( evserv_t serv,
int  fd,
struct sockaddr *  s,
int  sl,
void *  arg 
)
static

Definition at line 2161 of file evhtp.c.

static void _evhtp_authority_free ( evhtp_authority_t authority)
static

frees an authority structure

Parameters
authorityevhtp_authority_t

Definition at line 851 of file evhtp.c.

static evhtp_authority_t * _evhtp_authority_new ( void  )
static

create an authority structure

Returns
evhtp_authority_t

Definition at line 869 of file evhtp.c.

static evhtp_res _evhtp_body_hook ( evhtp_request_t request,
evbuf_t buf 
)
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.

Parameters
requestthe request strucutre
bufa evbuffer containing body data
Returns
EVHTP_RES_OK on success, otherwise something else.

Definition at line 431 of file evhtp.c.

static evhtp_callback_t* _evhtp_callback_find ( evhtp_callbacks_t cbs,
const char *  path,
unsigned int *  start_offset,
unsigned int *  end_offset 
)
static

Definition at line 680 of file evhtp.c.

static evhtp_res _evhtp_chunk_fini_hook ( evhtp_request_t request)
inlinestatic

Definition at line 460 of file evhtp.c.

static evhtp_res _evhtp_chunk_new_hook ( evhtp_request_t request,
uint64_t  len 
)
inlinestatic

Definition at line 453 of file evhtp.c.

static evhtp_res _evhtp_chunks_fini_hook ( evhtp_request_t request)
inlinestatic

Definition at line 467 of file evhtp.c.

static int _evhtp_connection_accept ( evbase_t *  evbase,
evhtp_connection_t connection 
)
static

Definition at line 1994 of file evhtp.c.

static evhtp_res _evhtp_connection_error_hook ( evhtp_connection_t connection,
evhtp_error_flags  errtype 
)
inlinestatic

runs the user-defined hook when a connection error occurs

Parameters
connectionthe connection structure
errtypethe error that ocurred

Definition at line 519 of file evhtp.c.

static void _evhtp_connection_eventcb ( evbev_t bev,
short  events,
void *  arg 
)
static

Definition at line 1915 of file evhtp.c.

static evhtp_res _evhtp_connection_fini_hook ( evhtp_connection_t connection)
inlinestatic

runs the user-definedhook called just prior to a connection being closed

Parameters
connectionthe connection structure
Returns
EVHTP_RES_OK on success, but pretty much ignored in any case.

Definition at line 489 of file evhtp.c.

static evhtp_connection_t * _evhtp_connection_new ( evhtp_t htp,
evutil_socket_t  sock,
evhtp_type  type 
)
static

Definition at line 2063 of file evhtp.c.

static void _evhtp_connection_readcb ( evbev_t bev,
void *  arg 
)
static

Definition at line 1783 of file evhtp.c.

static void _evhtp_connection_resumecb ( int  fd,
short  events,
void *  arg 
)
static

Definition at line 1751 of file evhtp.c.

static evhtp_res _evhtp_connection_write_hook ( evhtp_connection_t connection)
inlinestatic

Definition at line 536 of file evhtp.c.

static void _evhtp_connection_writecb ( evbev_t bev,
void *  arg 
)
static

Definition at line 1840 of file evhtp.c.

static int _evhtp_create_headers ( evhtp_header_t header,
void *  arg 
)
static

Definition at line 1626 of file evhtp.c.

static evbuf_t* _evhtp_create_reply ( evhtp_request_t request,
evhtp_res  code 
)
static

Definition at line 1639 of file evhtp.c.

static void _evhtp_default_request_cb ( evhtp_request_t request,
void *  arg 
)
static

Definition at line 2058 of file evhtp.c.

static void _evhtp_error_hook ( evhtp_request_t request,
evhtp_error_flags  errtype 
)
inlinestatic

runs the user-defined hook when a connection error occurs

Parameters
requestthe request structure
errtypethe error that ocurred

Definition at line 505 of file evhtp.c.

static int _evhtp_glob_match ( const char *  pattern,
size_t  pat_len,
const char *  string,
size_t  str_len 
)
inlinestatic

glob/wildcard type pattern matching.

Note: This code was derived from redis's (v2.6) stringmatchlen() function.

Parameters
pattern
string
Returns

Definition at line 612 of file evhtp.c.

static int _evhtp_glob_match2 ( const char *  pattern,
size_t  plen,
const char *  string,
size_t  str_len 
)
static

Definition at line 546 of file evhtp.c.

static evhtp_res _evhtp_header_hook ( evhtp_request_t request,
evhtp_header_t header 
)
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

Parameters
requestthe request strucutre
headerthe header structure
Returns
EVHTP_RES_OK on success, otherwise something else.

Definition at line 398 of file evhtp.c.

static evhtp_res _evhtp_headers_hook ( evhtp_request_t request,
evhtp_headers_t headers 
)
inlinestatic

runs the user-defined on_Headers hook for a request after all headers have been parsed.

Parameters
requestthe request structure
headersthe headers tailq structure
Returns
EVHTP_RES_OK on success, otherwise something else.

Definition at line 414 of file evhtp.c.

static evhtp_res _evhtp_headers_start_hook ( evhtp_request_t request)
inlinestatic

Definition at line 474 of file evhtp.c.

static evhtp_res _evhtp_hostname_hook ( evhtp_request_t r,
const char *  hostname 
)
inlinestatic

Definition at line 529 of file evhtp.c.

static void _evhtp_path_free ( evhtp_path_t path)
static

Definition at line 1005 of file evhtp.c.

static evhtp_res _evhtp_path_hook ( evhtp_request_t request,
evhtp_path_t path 
)
inlinestatic

runs the user-defined on_path hook for a request

Parameters
requestthe request structure
paththe path structure
Returns
EVHTP_RES_OK on success, otherwise something else.

Definition at line 381 of file evhtp.c.

static evhtp_path_t * _evhtp_path_new ( const char *  data,
size_t  len 
)
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.

Parameters
dataraw input data (assumes a /path/[file] structure)
lenlength of the input data
Returns
evhtp_request_t * on success, NULL on error.

Definition at line 916 of file evhtp.c.

static evhtp_proto _evhtp_protocol ( const char  major,
const char  minor 
)
inlinestatic

returns the HTTP protocol version

Parameters
majorthe major version number
minorthe minor version number
Returns
EVHTP_PROTO_10 if HTTP/1.0, EVHTP_PROTO_11 if HTTP/1.1, otherwise EVHTP_PROTO_INVALID

Definition at line 360 of file evhtp.c.

static unsigned int _evhtp_quick_hash ( const char *  str)
inlinestatic

a weak hash function

Parameters
stra null terminated string
Returns
an unsigned integer hash of str

Definition at line 315 of file evhtp.c.

static evhtp_t* _evhtp_request_find_vhost ( evhtp_t evhtp,
const char *  name 
)
inlinestatic

Definition at line 1176 of file evhtp.c.

static evhtp_res _evhtp_request_fini_hook ( evhtp_request_t request)
inlinestatic

runs the user-defined hook called just prior to a request been free()'d

Parameters
requesttherequest structure
Returns
EVHTP_RES_OK on success, otherwise treated as an error

Definition at line 446 of file evhtp.c.

static void _evhtp_request_free ( evhtp_request_t request)
static

frees all data in an evhtp_request_t along with calling finished hooks

Parameters
requestthe request structure

Definition at line 794 of file evhtp.c.

static evhtp_request_t* _evhtp_request_new ( evhtp_connection_t c)
static

Creates a new evhtp_request_t.

Parameters
c
Returns
evhtp_request_t structure on success, otherwise NULL

Definition at line 743 of file evhtp.c.

static int _evhtp_request_parser_args ( htparser *  p,
const char *  data,
size_t  len 
)
static

Definition at line 1048 of file evhtp.c.

static int _evhtp_request_parser_body ( htparser *  p,
const char *  data,
size_t  len 
)
static

Definition at line 1470 of file evhtp.c.

static int _evhtp_request_parser_chunk_fini ( htparser *  p)
static

Definition at line 1513 of file evhtp.c.

static int _evhtp_request_parser_chunk_new ( htparser *  p)
static

Definition at line 1501 of file evhtp.c.

static int _evhtp_request_parser_chunks_fini ( htparser *  p)
static

Definition at line 1524 of file evhtp.c.

static int _evhtp_request_parser_fini ( htparser *  p)
static

Definition at line 1579 of file evhtp.c.

static int _evhtp_request_parser_header_key ( htparser *  p,
const char *  data,
size_t  len 
)
static

Definition at line 1129 of file evhtp.c.

static int _evhtp_request_parser_header_val ( htparser *  p,
const char *  data,
size_t  len 
)
static

Definition at line 1150 of file evhtp.c.

static int _evhtp_request_parser_headers ( htparser *  p)
static

Definition at line 1440 of file evhtp.c.

static int _evhtp_request_parser_headers_start ( htparser *  p)
static

Definition at line 1118 of file evhtp.c.

static int _evhtp_request_parser_host ( htparser *  p,
const char *  data,
size_t  len 
)
static

Definition at line 1362 of file evhtp.c.

static int _evhtp_request_parser_hostname ( htparser *  p,
const char *  data,
size_t  len 
)
static

Definition at line 1297 of file evhtp.c.

static int _evhtp_request_parser_path ( htparser *  p,
const char *  data,
size_t  len 
)
static

Definition at line 1408 of file evhtp.c.

static int _evhtp_request_parser_port ( htparser *  p,
const char *  data,
size_t  len 
)
static

Definition at line 1383 of file evhtp.c.

static int _evhtp_request_parser_start ( htparser *  p)
static

Definition at line 1021 of file evhtp.c.

static int _evhtp_request_set_callbacks ( evhtp_request_t request)
inlinestatic

Definition at line 1204 of file evhtp.c.

static int _evhtp_require_uri ( evhtp_connection_t c)
static

Definition at line 1349 of file evhtp.c.

static void _evhtp_run_in_thread ( evthr_t *  thr,
void *  arg,
void *  shared 
)
static

Definition at line 2138 of file evhtp.c.

static int _evhtp_run_post_accept ( evhtp_t htp,
evhtp_connection_t connection 
)
static

Definition at line 2118 of file evhtp.c.

static int _evhtp_run_pre_accept ( evhtp_t htp,
evhtp_connection_t conn 
)
static

Definition at line 1975 of file evhtp.c.

static int _evhtp_should_parse_query_body ( evhtp_request_t req)
static

determines if the request body contains the query arguments. if the query is NULL and the contenet length of the body has never been drained, and the content-type is x-www-form-urlencoded, the function returns 1

Parameters
req
Returns
1 if evhtp can use the body as the query arguments, 0 otherwise.

Definition at line 1545 of file evhtp.c.

static int _evhtp_ssl_add_scache_ent ( evhtp_ssl_t ssl,
evhtp_ssl_sess_t sess 
)
static

Definition at line 2243 of file evhtp.c.

static void _evhtp_ssl_delete_scache_ent ( evhtp_ssl_ctx_t ctx,
evhtp_ssl_sess_t sess 
)
static

Definition at line 2225 of file evhtp.c.

static evhtp_ssl_sess_t* _evhtp_ssl_get_scache_ent ( evhtp_ssl_t ssl,
unsigned char *  sid,
int  sid_len,
int *  copy 
)
static

Definition at line 2265 of file evhtp.c.

static unsigned long _evhtp_ssl_get_thread_id ( void  )
static

Definition at line 2202 of file evhtp.c.

static int _evhtp_ssl_servername ( evhtp_ssl_t ssl,
int *  unused,
void *  arg 
)
static

Definition at line 2284 of file evhtp.c.

static void _evhtp_ssl_thread_lock ( int  mode,
int  type,
const char *  file,
int  line 
)
static

Definition at line 2213 of file evhtp.c.

static void _evhtp_thread_init ( evthr_t *  thr,
void *  arg 
)
static

Definition at line 3535 of file evhtp.c.

static void _evhtp_uri_free ( evhtp_uri_t uri)
static

frees an overlay URI structure

Parameters
urievhtp_uri_t

Definition at line 885 of file evhtp.c.

static evhtp_uri_t * _evhtp_uri_new ( void  )
static

create an overlay URI structure

Returns
evhtp_uri_t

Definition at line 827 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.

Parameters
evhtp
name
Returns

Definition at line 4011 of file evhtp.c.

int evhtp_add_vhost ( evhtp_t evhtp,
const char *  name,
evhtp_t vhost 
)

add a virtual host.

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.

NOTE: If SSL is being used and the vhost was found via SNI, the Host: header will NOT be used to find a matching vhost.

Also, any hooks which are set prior to finding a vhost that are hooks which are after the host hook, they are overwritten by the callbacks and hooks set for the vhost specific evhtp_t structure.

Parameters
evhtp
name
vhost
Returns

Definition at line 4046 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.

Parameters
htps
sin_len
backlog
Returns

Definition at line 3154 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.

Parameters
htp
addr
port
backlog
Returns

Definition at line 3196 of file evhtp.c.

void evhtp_callback_free ( evhtp_callback_t callback)

frees information associated with a ainflwx callback.

Parameters
callback

Definition at line 3314 of file evhtp.c.

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.

Parameters
pathcan either be a static path (/path/to/resource/) or a POSIX compatible regular expression (^/resource/(.*))
typeinforms 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.
cbthe callback function to be invoked
argoptional argument which is passed when the callback is executed.
Returns
0 on success, -1 on error.

Definition at line 3273 of file evhtp.c.

int evhtp_callbacks_add_callback ( evhtp_callbacks_t cbs,
evhtp_callback_t cb 
)

Adds a evhtp_callback_t to the evhtp_callbacks_t list.

Parameters
cbsan allocated evhtp_callbacks_t structure
cban initialized evhtp_callback_t structure
Returns
0 on success, -1 on error

Definition at line 3344 of file evhtp.c.

void evhtp_callbacks_free ( evhtp_callbacks_t callbacks)

Definition at line 3255 of file evhtp.c.

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.

Parameters
connection

Definition at line 3926 of file evhtp.c.

evbev_t* evhtp_connection_get_bev ( evhtp_connection_t conn)

returns the underlying connections bufferevent

Parameters
conn
Returns
bufferevent on success, otherwise NULL

Definition at line 3847 of file evhtp.c.

evhtp_connection_t* evhtp_connection_new ( evbase_t *  evbase,
const char *  addr,
uint16_t  port 
)

allocate a new connection

Definition at line 4178 of file evhtp.c.

evhtp_connection_t* evhtp_connection_new_dns ( evbase_t *  evbase,
struct evdns_base *  dns_base,
const char *  addr,
uint16_t  port 
)

allocate a new connection

Definition at line 4183 of file evhtp.c.

void evhtp_connection_pause ( evhtp_connection_t c)

pauses a connection (disables reading)

Parameters
ca evhtp_connection_t * structure

Definition at line 2338 of file evhtp.c.

void evhtp_connection_resume ( evhtp_connection_t c)

resumes a connection (enables reading) and activates resume event.

Parameters
c

Definition at line 2352 of file evhtp.c.

void evhtp_connection_set_bev ( evhtp_connection_t conn,
evbev_t bev 
)

Sets the connections underlying bufferevent.

Parameters
conn
bev

Definition at line 3884 of file evhtp.c.

void evhtp_connection_set_max_body_size ( evhtp_connection_t conn,
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

Parameters
conn
len

Definition at line 3912 of file evhtp.c.

int evhtp_connection_set_rate_limit ( evhtp_connection_t conn,
size_t  read_rate,
size_t  read_burst,
size_t  write_rate,
size_t  write_burst,
const struct timeval *  tick 
)

Definition at line 4151 of file evhtp.c.

void evhtp_connection_set_timeouts ( evhtp_connection_t conn,
const struct timeval *  r,
const struct timeval *  w 
)
inline

sets a connection-specific read/write timeout which overrides the global read/write settings.

Parameters
conn
rtimeval for read
wtimeval for write

Definition at line 3899 of file evhtp.c.

evhtp_connection_t* evhtp_connection_ssl_new ( evbase_t *  evbase,
const char *  addr,
uint16_t  port,
evhtp_ssl_ctx_t ctx 
)

Definition at line 4250 of file evhtp.c.

evbev_t* 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.

Parameters
connection
Returns
underlying connections bufferevent.

Definition at line 3852 of file evhtp.c.

void evhtp_disable_100_continue ( evhtp_t htp)

when a client sends an Expect: 100-continue, if this is function is called, evhtp will not send a HTTP/x.x continue response.

Parameters
htp

Definition at line 4001 of file evhtp.c.

void evhtp_free ( evhtp_t evhtp)

Definition at line 4105 of file evhtp.c.

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

Parameters
headersthe evhtp_headers_t TAILQ (evhtp_kv_t)
keya null terminated string
kallocif 1 the string will be copied, otherwise assigned
Returns
an evhtp_header_t pointer or NULL on error

Definition at line 2386 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

Parameters
headersthe evhtp_headers_t TAILQ (evhtp_kv_t)
vala null terminated string
vallocif 1 the string will be copied, otherwise assigned
Returns
an evhtp_header_t pointer or NULL on error

Definition at line 2399 of file evhtp.c.

static int evhtp_is_hex_query_char ( unsigned char  ch)
inlinestatic

Definition at line 2627 of file evhtp.c.

const char* evhtp_kv_find ( evhtp_kvs_t kvs,
const char *  key 
)

find the string value of 'key' from the key/value list 'kvs'

Parameters
kvs
key
Returns
NULL if not found

Definition at line 2559 of file evhtp.c.

void evhtp_kv_free ( evhtp_kv_t kv)

frees resources allocated for a single key/value

Parameters
kv

Definition at line 2492 of file evhtp.c.

evhtp_kv_t* evhtp_kv_new ( const char *  key,
const char *  val,
char  kalloc,
char  valloc 
)

Allocates a new key/value structure.

Parameters
keynull terminated string
valnull terminated string
kallocif set to 1, the key will be copied, if 0 no copy is done.
vallocif set to 1, the val will be copied, if 0 no copy is done.
Returns
evhtp_kv_t * on success, NULL on error.

Definition at line 2439 of file evhtp.c.

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

Parameters
kvs
kv

Definition at line 2509 of file evhtp.c.

void evhtp_kvs_add_kv ( evhtp_kvs_t kvs,
evhtp_kv_t kv 
)

appends a key/val structure to a evhtp_kvs_t tailq

Parameters
kvsan evhtp_kvs_t structure
kvan evhtp_kv_t structure

Definition at line 2593 of file evhtp.c.

void evhtp_kvs_add_kvs ( evhtp_kvs_t dst,
evhtp_kvs_t src 
)

appends all key/val structures from src tailq onto dst tailq

Parameters
dstan evhtp_kvs_t structure
srcan evhtp_kvs_t structure

Definition at line 2602 of file evhtp.c.

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'

Parameters
kvs
key
Returns

Definition at line 2576 of file evhtp.c.

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'

Parameters
kvs
cb
arg
Returns

Definition at line 2540 of file evhtp.c.

void evhtp_kvs_free ( evhtp_kvs_t kvs)

frees a the list of key/values, and all underlying entries

Parameters
kvs

Definition at line 2520 of file evhtp.c.

evhtp_kvs_t* evhtp_kvs_new ( void  )

creates an empty list of key/values

Returns

Definition at line 2430 of file evhtp.c.

int evhtp_make_request ( evhtp_connection_t c,
evhtp_request_t r,
htp_method  meth,
const char *  uri 
)

make a client request

Definition at line 4301 of file evhtp.c.

evhtp_t* evhtp_new ( evbase_t *  evbase,
void *  arg 
)

creates a new evhtp_t instance

Parameters
evbasethe initialized event base
arguser-defined argument which is evhtp_t specific
Returns
a new evhtp_t structure or NULL on error

Definition at line 4081 of file evhtp.c.

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"

Parameters
querydata containing the uri query arguments
lensize of the data
Returns
evhtp_query_t * on success, NULL on error

Definition at line 2983 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"

Parameters
querydata containing the uri query arguments
lensize of the data
flagsparse query flags to alter 'strictness' (see EVHTP_PARSE_QUERY_FLAG_*)
Returns
evhtp_query_t * on success, NULL on error

Definition at line 2735 of file evhtp.c.

void evhtp_request_free ( evhtp_request_t request)

Definition at line 3964 of file evhtp.c.

evbev_t* evhtp_request_get_bev ( evhtp_request_t request)

returns the underlying requests bufferevent

Parameters
request
Returns
bufferevent on success, otherwise NULL

Definition at line 3874 of file evhtp.c.

evhtp_connection_t* evhtp_request_get_connection ( evhtp_request_t request)

returns the underlying evhtp_connection_t structure from a request

Parameters
request
Returns
evhtp_connection_t on success, otherwise NULL

Definition at line 3894 of file evhtp.c.

htp_method evhtp_request_get_method ( evhtp_request_t r)

returns the htp_method enum version of the request method.

Parameters
r
Returns
htp_method enum

Definition at line 2328 of file evhtp.c.

evhtp_request_t* evhtp_request_new ( evhtp_callback_cb  cb,
void *  arg 
)

allocate a new request

Definition at line 4286 of file evhtp.c.

void evhtp_request_pause ( evhtp_request_t request)

Wrapper around evhtp_connection_pause.

See also
evhtp_connection_pause
Parameters
request

Definition at line 2368 of file evhtp.c.

void evhtp_request_resume ( evhtp_request_t request)

Wrapper around evhtp_connection_resume.

See also
evhtp_connection_resume
Parameters
request

Definition at line 2381 of file evhtp.c.

void evhtp_request_set_bev ( evhtp_request_t request,
evbev_t bev 
)

sets the underlying bufferevent for a evhtp_request

Parameters
request
bev

Definition at line 3889 of file evhtp.c.

void evhtp_request_set_max_body_size ( evhtp_request_t request,
uint64_t  len 
)

just calls evhtp_connection_set_max_body_size for the request.

Parameters
request
len

Definition at line 3921 of file evhtp.c.

unsigned int evhtp_request_status ( evhtp_request_t r)

Definition at line 4330 of file evhtp.c.

evbev_t* evhtp_request_take_ownership ( evhtp_request_t request)

Definition at line 3879 of file evhtp.c.

int evhtp_response_needs_body ( const evhtp_res  code,
const htp_method  method 
)

Determine if a response should have a body. Follows the rules in RFC 2616 section 4.3.

Returns
1 if the response MUST have a body; 0 if the response MUST NOT have a body.

Definition at line 3037 of file evhtp.c.

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

Parameters
request
codeHTTP return status code

Definition at line 3019 of file evhtp.c.

void evhtp_send_reply_body ( evhtp_request_t request,
evbuf_t buf 
)

Definition at line 3005 of file evhtp.c.

void evhtp_send_reply_chunk ( evhtp_request_t request,
evbuf_t buf 
)

send a chunk reply.

Parameters
request
buf

Definition at line 3114 of file evhtp.c.

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. This will add the last 0CRLFCRCL and call send_reply_end().

Parameters
request

Definition at line 3138 of file evhtp.c.

void evhtp_send_reply_chunk_start ( evhtp_request_t request,
evhtp_res  code 
)

start a chunked response. If data already exists on the output buffer, this will be converted to the first chunk.

Parameters
request
code

Definition at line 3045 of file evhtp.c.

void evhtp_send_reply_end ( evhtp_request_t request)

Definition at line 3014 of file evhtp.c.

void evhtp_send_reply_start ( evhtp_request_t request,
evhtp_res  code 
)

Definition at line 2988 of file evhtp.c.

void evhtp_set_bev_flags ( evhtp_t htp,
int  flags 
)

set bufferevent flags, defaults to BEV_OPT_CLOSE_ON_FREE

bufferevent flags which will be used for bev sockets.

Parameters
htp
flags

Definition at line 3991 of file evhtp.c.

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

Parameters
htpthe initialized evhtp_t
paththe path to match
cbthe function to be executed
arguser-defined argument passed to the callback
Returns
evhtp_callback_t * on success, NULL on error.

Definition at line 3500 of file evhtp.c.

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

Parameters
htpthe initialized evhtp_t
cbthe function to be executed
arguser-defined argument passed to the callback

Definition at line 3651 of file evhtp.c.

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.

Parameters
htp
patternwildcard pattern, the '*' can be set at either or both the front or end.
cb
arg
Returns

Definition at line 3617 of file evhtp.c.

int evhtp_set_hook ( evhtp_hooks_t **  hooks,
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.

Parameters
hooksdouble pointer to the evhtp_hooks_t structure
typethe hook type
cbthe callback to be executed.
argoptional argument which is passed when the callback is executed
Returns
0 on success, -1 on error (if hooks is NULL, it is allocated)

Definition at line 3351 of file evhtp.c.

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.

Parameters
htp
len

Definition at line 3996 of file evhtp.c.

void evhtp_set_max_keepalive_requests ( evhtp_t htp,
uint64_t  num 
)

sets a maximum number of requests that a single connection can make.

Parameters
htp
num

Definition at line 3980 of file evhtp.c.

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);

Parameters
htp
flags

Definition at line 4006 of file evhtp.c.

void evhtp_set_post_accept_cb ( evhtp_t htp,
evhtp_post_accept_cb  cb,
void *  arg 
)

Definition at line 3663 of file evhtp.c.

void evhtp_set_pre_accept_cb ( evhtp_t htp,
evhtp_pre_accept_cb  cb,
void *  arg 
)

Definition at line 3657 of file evhtp.c.

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

Parameters
htpthe initialized evhtp_t
patterna POSIX compat regular expression
cbthe function to be executed
arguser-defined argument passed to the callback
Returns
evhtp_callback_t * on success, NULL on error

Definition at line 3581 of file evhtp.c.

void evhtp_set_timeouts ( evhtp_t htp,
const struct timeval *  r,
const struct timeval *  w 
)

set a read/write timeout on all things evhtp_t. When the timeout expires your error hook will be called with the libevent supplied event flags.

Parameters
htpthe base evhtp_t struct
rread-timeout in timeval
wwrite-timeout in timeval.

Definition at line 3969 of file evhtp.c.

int evhtp_ssl_init ( evhtp_t htp,
evhtp_ssl_cfg_t cfg 
)

Definition at line 3696 of file evhtp.c.

int evhtp_ssl_use_threads ( void  )

Definition at line 3671 of file evhtp.c.

void evhtp_unbind_socket ( evhtp_t htp)

stops the listening socket.

Parameters
htp

Definition at line 3148 of file evhtp.c.

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}'.

Parameters
outdouble pointer where output is stored. This is allocated by the user.
strthe string to unescape
str_lenthe length of the string to unescape
Returns
0 on success, -1 on error

Definition at line 2660 of file evhtp.c.

int evhtp_unset_all_hooks ( evhtp_hooks_t **  hooks)

removes all hooks.

Parameters
hooks
Returns

Definition at line 3433 of file evhtp.c.

int evhtp_unset_hook ( evhtp_hooks_t **  hooks,
evhtp_hook_type  type 
)

remove a specific hook from being called.

Parameters
hooks
type
Returns

Definition at line 3428 of file evhtp.c.

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.

Parameters
htp
Returns
0 on success, -1 on error

Definition at line 3565 of file evhtp.c.

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. 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).

Parameters
htp
init_cb
nthreads
arg
Returns

Definition at line 3544 of file evhtp.c.

static const char* status_code_to_str ( evhtp_res  code)
static

Definition at line 130 of file evhtp.c.

Variable Documentation

htparse_hooks request_psets
static
Initial value:
= {
.on_msg_begin = _evhtp_request_parser_start,
.method = NULL,
.scheme = NULL,
.uri = NULL,
.on_hdrs_complete = _evhtp_request_parser_headers,
.on_chunk_complete = _evhtp_request_parser_chunk_fini,
.on_chunks_complete = _evhtp_request_parser_chunks_fini,
.on_msg_complete = _evhtp_request_parser_fini
}
static int _evhtp_request_parser_hostname(htparser *p, const char *data, size_t len)
Definition: evhtp.c:1297
static int _evhtp_request_parser_host(htparser *p, const char *data, size_t len)
Definition: evhtp.c:1362
static int _evhtp_request_parser_chunk_new(htparser *p)
Definition: evhtp.c:1501
static int _evhtp_request_parser_path(htparser *p, const char *data, size_t len)
Definition: evhtp.c:1408
static int _evhtp_request_parser_port(htparser *p, const char *data, size_t len)
Definition: evhtp.c:1383
static int _evhtp_request_parser_chunk_fini(htparser *p)
Definition: evhtp.c:1513
static int _evhtp_request_parser_headers(htparser *p)
Definition: evhtp.c:1440
static int _evhtp_request_parser_header_key(htparser *p, const char *data, size_t len)
Definition: evhtp.c:1129
static int _evhtp_request_parser_start(htparser *p)
Definition: evhtp.c:1021
static int _evhtp_request_parser_args(htparser *p, const char *data, size_t len)
Definition: evhtp.c:1048
static int _evhtp_request_parser_headers_start(htparser *p)
Definition: evhtp.c:1118
static int _evhtp_request_parser_chunks_fini(htparser *p)
Definition: evhtp.c:1524
static int _evhtp_request_parser_fini(htparser *p)
Definition: evhtp.c:1579
static int _evhtp_request_parser_body(htparser *p, const char *data, size_t len)
Definition: evhtp.c:1470
static int _evhtp_request_parser_header_val(htparser *p, const char *data, size_t len)
Definition: evhtp.c:1150

callback definitions for request processing from libhtparse

Definition at line 234 of file evhtp.c.

int session_id_context = 1
static

Definition at line 256 of file evhtp.c.

evhtp_mutex_t* ssl_locks
static

Definition at line 259 of file evhtp.c.

int ssl_locks_initialized = 0
static

Definition at line 260 of file evhtp.c.

int ssl_num_locks
static

Definition at line 258 of file evhtp.c.