Libevhtp  0.3.7
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Data Structures | Macros | Typedefs | Enumerations | Functions
evhtp.h File Reference
#include <evhtp-config.h>
#include <evthr.h>
#include <htparse.h>
#include <onigposix.h>
#include <sys/queue.h>
#include <event2/event.h>
#include <event2/listener.h>
#include <event2/buffer.h>
#include <event2/bufferevent.h>
#include <event2/bufferevent_ssl.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/rand.h>

Go to the source code of this file.

Data Structures

struct  evhtp_defaults_s
 
struct  evhtp_alias_s
 
struct  evhtp_s
 main structure containing all configuration information More...
 
struct  evhtp_callback_s
 structure containing a single callback and configuration More...
 
struct  evhtp_kv_s
 a generic key/value structure More...
 
struct  evhtp_uri_s
 a generic container representing an entire URI strucutre More...
 
struct  evhtp_authority_s
 structure which represents authority information in a URI More...
 
struct  evhtp_path_s
 structure which represents a URI path and or file More...
 
struct  evhtp_request_s
 a structure containing all information for a http request. More...
 
struct  evhtp_connection_s
 
struct  evhtp_hooks_s
 
struct  evhtp_ssl_cfg_s
 

Macros

#define evhtp_header_s   evhtp_kv_s
 
#define evhtp_headers_s   evhtp_kvs_s
 
#define evhtp_query_s   evhtp_kvs_s
 
#define evhtp_header_t   evhtp_kv_t
 
#define evhtp_headers_t   evhtp_kvs_t
 
#define evhtp_query_t   evhtp_kvs_t
 
#define EVHTP_VERSION   "1.2.8"
 
#define EVHTP_VERSION_MAJOR   1
 
#define EVHTP_VERSION_MINOR   2
 
#define EVHTP_VERSION_PATCH   8
 
#define evhtp_headers_iterator   evhtp_kvs_iterator
 
#define EVHTP_RES_ERROR   0
 
#define EVHTP_RES_PAUSE   1
 
#define EVHTP_RES_FATAL   2
 
#define EVHTP_RES_USER   3
 
#define EVHTP_RES_DATA_TOO_LONG   4
 
#define EVHTP_RES_OK   200
 
#define EVHTP_RES_100   100
 
#define EVHTP_RES_CONTINUE   100
 
#define EVHTP_RES_SWITCH_PROTO   101
 
#define EVHTP_RES_PROCESSING   102
 
#define EVHTP_RES_URI_TOOLONG   122
 
#define EVHTP_RES_200   200
 
#define EVHTP_RES_CREATED   201
 
#define EVHTP_RES_ACCEPTED   202
 
#define EVHTP_RES_NAUTHINFO   203
 
#define EVHTP_RES_NOCONTENT   204
 
#define EVHTP_RES_RSTCONTENT   205
 
#define EVHTP_RES_PARTIAL   206
 
#define EVHTP_RES_MSTATUS   207
 
#define EVHTP_RES_IMUSED   226
 
#define EVHTP_RES_300   300
 
#define EVHTP_RES_MCHOICE   300
 
#define EVHTP_RES_MOVEDPERM   301
 
#define EVHTP_RES_FOUND   302
 
#define EVHTP_RES_SEEOTHER   303
 
#define EVHTP_RES_NOTMOD   304
 
#define EVHTP_RES_USEPROXY   305
 
#define EVHTP_RES_SWITCHPROXY   306
 
#define EVHTP_RES_TMPREDIR   307
 
#define EVHTP_RES_400   400
 
#define EVHTP_RES_BADREQ   400
 
#define EVHTP_RES_UNAUTH   401
 
#define EVHTP_RES_PAYREQ   402
 
#define EVHTP_RES_FORBIDDEN   403
 
#define EVHTP_RES_NOTFOUND   404
 
#define EVHTP_RES_METHNALLOWED   405
 
#define EVHTP_RES_NACCEPTABLE   406
 
#define EVHTP_RES_PROXYAUTHREQ   407
 
#define EVHTP_RES_TIMEOUT   408
 
#define EVHTP_RES_CONFLICT   409
 
#define EVHTP_RES_GONE   410
 
#define EVHTP_RES_LENREQ   411
 
#define EVHTP_RES_PRECONDFAIL   412
 
#define EVHTP_RES_ENTOOLARGE   413
 
#define EVHTP_RES_URITOOLARGE   414
 
#define EVHTP_RES_UNSUPPORTED   415
 
#define EVHTP_RES_RANGENOTSC   416
 
#define EVHTP_RES_EXPECTFAIL   417
 
#define EVHTP_RES_IAMATEAPOT   418
 
#define EVHTP_RES_500   500
 
#define EVHTP_RES_SERVERR   500
 
#define EVHTP_RES_NOTIMPL   501
 
#define EVHTP_RES_BADGATEWAY   502
 
#define EVHTP_RES_SERVUNAVAIL   503
 
#define EVHTP_RES_GWTIMEOUT   504
 
#define EVHTP_RES_VERNSUPPORT   505
 
#define EVHTP_RES_BWEXEED   509
 
#define evhtp_request_content_len(r)   htparser_get_content_length(r->conn->parser)
 
#define evhtp_header_find   evhtp_kv_find
 
#define evhtp_headers_find_header   evhtp_kvs_find_kv
 
#define evhtp_headers_for_each   evhtp_kvs_for_each
 
#define evhtp_header_new   evhtp_kv_new
 
#define evhtp_header_free   evhtp_kv_free
 
#define evhtp_headers_new   evhtp_kvs_new
 
#define evhtp_headers_free   evhtp_kvs_free
 
#define evhtp_header_rm_and_free   evhtp_kv_rm_and_free
 
#define evhtp_headers_add_header   evhtp_kvs_add_kv
 
#define evhtp_headers_add_headers   evhtp_kvs_add_kvs
 
#define evhtp_query_new   evhtp_kvs_new
 
#define evhtp_query_free   evhtp_kvs_free
 

Typedefs

typedef SSL_SESSION evhtp_ssl_sess_t
 
typedef SSL evhtp_ssl_t
 
typedef SSL_CTX evhtp_ssl_ctx_t
 
typedef X509 evhtp_x509_t
 
typedef X509_STORE_CTX evhtp_x509_store_ctx_t
 
typedef struct evbuffer evbuf_t
 
typedef struct event event_t
 
typedef struct evconnlistener evserv_t
 
typedef struct bufferevent evbev_t
 
typedef pthread_mutex_t evhtp_mutex_t
 
typedef struct evhtp_s evhtp_t
 
typedef struct evhtp_defaults_s evhtp_defaults_t
 
typedef struct evhtp_callbacks_s evhtp_callbacks_t
 
typedef struct evhtp_callback_s evhtp_callback_t
 
typedef struct evhtp_defaults_s evhtp_defaults_5
 
typedef struct evhtp_kv_s evhtp_kv_t
 
typedef struct evhtp_kvs_s evhtp_kvs_t
 
typedef struct evhtp_uri_s evhtp_uri_t
 
typedef struct evhtp_path_s evhtp_path_t
 
typedef struct evhtp_authority_s evhtp_authority_t
 
typedef struct evhtp_request_s evhtp_request_t
 
typedef struct evhtp_hooks_s evhtp_hooks_t
 
typedef struct evhtp_connection_s evhtp_connection_t
 
typedef struct evhtp_ssl_cfg_s evhtp_ssl_cfg_t
 
typedef struct evhtp_alias_s evhtp_alias_t
 
typedef uint16_t evhtp_res
 
typedef uint8_t evhtp_error_flags
 
typedef enum evhtp_hook_type evhtp_hook_type
 
typedef enum evhtp_callback_type evhtp_callback_type
 
typedef enum evhtp_proto evhtp_proto
 
typedef enum evhtp_ssl_scache_type evhtp_ssl_scache_type
 
typedef enum evhtp_type evhtp_type
 
typedef void(* evhtp_thread_init_cb )(evhtp_t *htp, evthr_t *thr, void *arg)
 
typedef void(* evhtp_callback_cb )(evhtp_request_t *req, void *arg)
 
typedef void(* evhtp_hook_err_cb )(evhtp_request_t *req, evhtp_error_flags errtype, void *arg)
 
typedef evhtp_res(* evhtp_hook )()
 
typedef evhtp_res(* evhtp_pre_accept_cb )(evhtp_connection_t *conn, void *arg)
 
typedef evhtp_res(* evhtp_post_accept_cb )(evhtp_connection_t *conn, void *arg)
 
typedef evhtp_res(* evhtp_hook_header_cb )(evhtp_request_t *req, evhtp_header_t *hdr, void *arg)
 
typedef evhtp_res(* evhtp_hook_headers_cb )(evhtp_request_t *req, evhtp_headers_t *hdr, void *arg)
 
typedef evhtp_res(* evhtp_hook_path_cb )(evhtp_request_t *req, evhtp_path_t *path, void *arg)
 
typedef evhtp_res(* evhtp_hook_read_cb )(evhtp_request_t *req, evbuf_t *buf, void *arg)
 
typedef evhtp_res(* evhtp_hook_request_fini_cb )(evhtp_request_t *req, void *arg)
 
typedef evhtp_res(* evhtp_hook_connection_fini_cb )(evhtp_connection_t *connection, void *arg)
 
typedef evhtp_res(* evhtp_hook_chunk_new_cb )(evhtp_request_t *r, uint64_t len, void *arg)
 
typedef evhtp_res(* evhtp_hook_chunk_fini_cb )(evhtp_request_t *r, void *arg)
 
typedef evhtp_res(* evhtp_hook_chunks_fini_cb )(evhtp_request_t *r, void *arg)
 
typedef evhtp_res(* evhtp_hook_headers_start_cb )(evhtp_request_t *r, void *arg)
 
typedef evhtp_res(* evhtp_hook_hostname_cb )(evhtp_request_t *r, const char *hostname, void *arg)
 
typedef evhtp_res(* evhtp_hook_write_cb )(evhtp_connection_t *conn, void *arg)
 
typedef int(* evhtp_kvs_iterator )(evhtp_kv_t *kv, void *arg)
 
typedef int(* evhtp_headers_iterator )(evhtp_header_t *header, void *arg)
 
typedef int(* evhtp_ssl_verify_cb )(int pre_verify, evhtp_x509_store_ctx_t *ctx)
 
typedef int(* evhtp_ssl_chk_issued_cb )(evhtp_x509_store_ctx_t *ctx, evhtp_x509_t *x, evhtp_x509_t *issuer)
 
typedef int(* evhtp_ssl_scache_add )(evhtp_connection_t *connection, unsigned char *sid, int sid_len, evhtp_ssl_sess_t *sess)
 
typedef void(* evhtp_ssl_scache_del )(evhtp_t *htp, unsigned char *sid, int sid_len)
 
typedef evhtp_ssl_sess_t *(* evhtp_ssl_scache_get )(evhtp_connection_t *connection, unsigned char *sid, int sid_len)
 
typedef void *(* evhtp_ssl_scache_init )(evhtp_t *)
 

Enumerations

enum  evhtp_ssl_scache_type { evhtp_ssl_scache_type_disabled = 0, evhtp_ssl_scache_type_internal, evhtp_ssl_scache_type_user, evhtp_ssl_scache_type_builtin }
 
enum  evhtp_hook_type {
  evhtp_hook_on_header, evhtp_hook_on_headers, evhtp_hook_on_path, evhtp_hook_on_read,
  evhtp_hook_on_request_fini, evhtp_hook_on_connection_fini, evhtp_hook_on_new_chunk, evhtp_hook_on_chunk_complete,
  evhtp_hook_on_chunks_complete, evhtp_hook_on_headers_start, evhtp_hook_on_error, evhtp_hook_on_hostname,
  evhtp_hook_on_write
}
 types associated with where a developer can hook into during the request processing cycle. More...
 
enum  evhtp_callback_type { evhtp_callback_type_hash, evhtp_callback_type_regex, evhtp_callback_type_glob }
 
enum  evhtp_proto { EVHTP_PROTO_INVALID, EVHTP_PROTO_10, EVHTP_PROTO_11 }
 
enum  evhtp_type { evhtp_type_client, evhtp_type_server }
 

Functions

 TAILQ_HEAD (evhtp_callbacks_s, evhtp_callback_s)
 
 TAILQ_HEAD (evhtp_kvs_s, evhtp_kv_s)
 
evhtp_tevhtp_new (evbase_t *evbase, void *arg)
 creates a new evhtp_t instance More...
 
void evhtp_free (evhtp_t *evhtp)
 
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. More...
 
void evhtp_set_bev_flags (evhtp_t *htp, int flags)
 set bufferevent flags, defaults to BEV_OPT_CLOSE_ON_FREE More...
 
int evhtp_ssl_use_threads (void)
 
int evhtp_ssl_init (evhtp_t *htp, evhtp_ssl_cfg_t *ssl_cfg)
 
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...
 
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...
 
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, void *arg)
 
void evhtp_set_post_accept_cb (evhtp_t *htp, evhtp_post_accept_cb, void *arg)
 
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...
 
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...
 
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...
 
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. More...
 
void evhtp_unbind_socket (evhtp_t *htp)
 stops the listening socket. More...
 
int evhtp_bind_sockaddr (evhtp_t *htp, struct sockaddr *, size_t sin_len, int backlog)
 bind to an already allocated sockaddr. More...
 
int evhtp_use_threads (evhtp_t *htp, evhtp_thread_init_cb init_cb, int nthreads, void *arg)
 
void evhtp_send_reply (evhtp_request_t *request, evhtp_res code)
 
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)
 
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...
 
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)
 
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_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. 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...
 
evhtp_kv_tevhtp_kv_new (const char *key, const char *val, char kalloc, char valloc)
 Allocates a new key/value structure. More...
 
evhtp_kvs_tevhtp_kvs_new (void)
 
void evhtp_kv_free (evhtp_kv_t *kv)
 
void evhtp_kvs_free (evhtp_kvs_t *kvs)
 
void evhtp_kv_rm_and_free (evhtp_kvs_t *kvs, evhtp_kv_t *kv)
 
const char * evhtp_kv_find (evhtp_kvs_t *kvs, const char *key)
 
evhtp_kv_tevhtp_kvs_find_kv (evhtp_kvs_t *kvs, const char *key)
 
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...
 
int evhtp_kvs_for_each (evhtp_kvs_t *kvs, evhtp_kvs_iterator cb, void *arg)
 
evhtp_query_tevhtp_parse_query (const char *query, size_t len)
 Parses the query portion of the uri into a set of key/values. More...
 
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_header_tevhtp_header_new (const char *key, const char *val, char kalloc, char valloc)
 creates a new evhtp_header_t key/val structure 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...
 
void evhtp_headers_add_header (evhtp_headers_t *headers, evhtp_header_t *header)
 adds an evhtp_header_t to the end of the evhtp_headers_t tailq More...
 
const char * evhtp_header_find (evhtp_headers_t *headers, const char *key)
 finds the value of a key in a evhtp_headers_t structure More...
 
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 *connection)
 pauses a connection (disables reading) More...
 
void evhtp_connection_resume (evhtp_connection_t *connection)
 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_connection_tevhtp_request_get_connection (evhtp_request_t *request)
 returns the underlying evhtp_connection_t structure from a request More...
 
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...
 
evbev_tevhtp_connection_get_bev (evhtp_connection_t *conn)
 returns the underlying connections bufferevent More...
 
void evhtp_connection_set_timeouts (evhtp_connection_t *conn, const struct timeval *r, const struct timeval *w)
 sets a connection-specific read/write timeout which overrides the global read/write settings. More...
 
evbev_tevhtp_request_get_bev (evhtp_request_t *request)
 returns the underlying requests 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...
 
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_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_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 More...
 
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. 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...
 
int evhtp_connection_set_ratelimit (evhtp_connection_t *c, size_t read_rate, size_t read_burst, size_t write_rate, size_t write_burst, const struct timeval *tick)
 set a bufferevent ratelimit on a evhtp_connection_t structure. The logic is the same as libevent's rate-limiting code. More...
 
evhtp_connection_tevhtp_connection_new (evbase_t *evbase, const char *addr, uint16_t port)
 allocate a new connection More...
 
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 *)
 

Macro Definition Documentation

#define evhtp_header_find   evhtp_kv_find

Definition at line 924 of file evhtp.h.

#define evhtp_header_free   evhtp_kv_free

Definition at line 928 of file evhtp.h.

#define evhtp_header_new   evhtp_kv_new

Definition at line 927 of file evhtp.h.

#define evhtp_header_rm_and_free   evhtp_kv_rm_and_free

Definition at line 931 of file evhtp.h.

#define evhtp_header_s   evhtp_kv_s

Definition at line 79 of file evhtp.h.

#define evhtp_header_t   evhtp_kv_t

Definition at line 83 of file evhtp.h.

#define evhtp_headers_add_header   evhtp_kvs_add_kv

Definition at line 932 of file evhtp.h.

#define evhtp_headers_add_headers   evhtp_kvs_add_kvs

Definition at line 933 of file evhtp.h.

#define evhtp_headers_find_header   evhtp_kvs_find_kv

Definition at line 925 of file evhtp.h.

#define evhtp_headers_for_each   evhtp_kvs_for_each

Definition at line 926 of file evhtp.h.

#define evhtp_headers_free   evhtp_kvs_free

Definition at line 930 of file evhtp.h.

#define evhtp_headers_iterator   evhtp_kvs_iterator

Definition at line 177 of file evhtp.h.

#define evhtp_headers_new   evhtp_kvs_new

Definition at line 929 of file evhtp.h.

#define evhtp_headers_s   evhtp_kvs_s

Definition at line 80 of file evhtp.h.

#define evhtp_headers_t   evhtp_kvs_t

Definition at line 84 of file evhtp.h.

#define evhtp_query_free   evhtp_kvs_free

Definition at line 935 of file evhtp.h.

#define evhtp_query_new   evhtp_kvs_new

Definition at line 934 of file evhtp.h.

#define evhtp_query_s   evhtp_kvs_s

Definition at line 81 of file evhtp.h.

#define evhtp_query_t   evhtp_kvs_t

Definition at line 85 of file evhtp.h.

#define evhtp_request_content_len (   r)    htparser_get_content_length(r->conn->parser)

Definition at line 418 of file evhtp.h.

#define EVHTP_RES_100   100

Definition at line 186 of file evhtp.h.

#define EVHTP_RES_200   200

Definition at line 192 of file evhtp.h.

#define EVHTP_RES_300   300

Definition at line 202 of file evhtp.h.

#define EVHTP_RES_400   400

Definition at line 212 of file evhtp.h.

#define EVHTP_RES_500   500

Definition at line 233 of file evhtp.h.

#define EVHTP_RES_ACCEPTED   202

Definition at line 194 of file evhtp.h.

#define EVHTP_RES_BADGATEWAY   502

Definition at line 236 of file evhtp.h.

#define EVHTP_RES_BADREQ   400

Definition at line 213 of file evhtp.h.

#define EVHTP_RES_BWEXEED   509

Definition at line 240 of file evhtp.h.

#define EVHTP_RES_CONFLICT   409

Definition at line 222 of file evhtp.h.

#define EVHTP_RES_CONTINUE   100

Definition at line 187 of file evhtp.h.

#define EVHTP_RES_CREATED   201

Definition at line 193 of file evhtp.h.

#define EVHTP_RES_DATA_TOO_LONG   4

Definition at line 183 of file evhtp.h.

#define EVHTP_RES_ENTOOLARGE   413

Definition at line 226 of file evhtp.h.

#define EVHTP_RES_ERROR   0

Definition at line 179 of file evhtp.h.

#define EVHTP_RES_EXPECTFAIL   417

Definition at line 230 of file evhtp.h.

#define EVHTP_RES_FATAL   2

Definition at line 181 of file evhtp.h.

#define EVHTP_RES_FORBIDDEN   403

Definition at line 216 of file evhtp.h.

#define EVHTP_RES_FOUND   302

Definition at line 205 of file evhtp.h.

#define EVHTP_RES_GONE   410

Definition at line 223 of file evhtp.h.

#define EVHTP_RES_GWTIMEOUT   504

Definition at line 238 of file evhtp.h.

#define EVHTP_RES_IAMATEAPOT   418

Definition at line 231 of file evhtp.h.

#define EVHTP_RES_IMUSED   226

Definition at line 200 of file evhtp.h.

#define EVHTP_RES_LENREQ   411

Definition at line 224 of file evhtp.h.

#define EVHTP_RES_MCHOICE   300

Definition at line 203 of file evhtp.h.

#define EVHTP_RES_METHNALLOWED   405

Definition at line 218 of file evhtp.h.

#define EVHTP_RES_MOVEDPERM   301

Definition at line 204 of file evhtp.h.

#define EVHTP_RES_MSTATUS   207

Definition at line 199 of file evhtp.h.

#define EVHTP_RES_NACCEPTABLE   406

Definition at line 219 of file evhtp.h.

#define EVHTP_RES_NAUTHINFO   203

Definition at line 195 of file evhtp.h.

#define EVHTP_RES_NOCONTENT   204

Definition at line 196 of file evhtp.h.

#define EVHTP_RES_NOTFOUND   404

Definition at line 217 of file evhtp.h.

#define EVHTP_RES_NOTIMPL   501

Definition at line 235 of file evhtp.h.

#define EVHTP_RES_NOTMOD   304

Definition at line 207 of file evhtp.h.

#define EVHTP_RES_OK   200

Definition at line 184 of file evhtp.h.

#define EVHTP_RES_PARTIAL   206

Definition at line 198 of file evhtp.h.

#define EVHTP_RES_PAUSE   1

Definition at line 180 of file evhtp.h.

#define EVHTP_RES_PAYREQ   402

Definition at line 215 of file evhtp.h.

#define EVHTP_RES_PRECONDFAIL   412

Definition at line 225 of file evhtp.h.

#define EVHTP_RES_PROCESSING   102

Definition at line 189 of file evhtp.h.

#define EVHTP_RES_PROXYAUTHREQ   407

Definition at line 220 of file evhtp.h.

#define EVHTP_RES_RANGENOTSC   416

Definition at line 229 of file evhtp.h.

#define EVHTP_RES_RSTCONTENT   205

Definition at line 197 of file evhtp.h.

#define EVHTP_RES_SEEOTHER   303

Definition at line 206 of file evhtp.h.

#define EVHTP_RES_SERVERR   500

Definition at line 234 of file evhtp.h.

#define EVHTP_RES_SERVUNAVAIL   503

Definition at line 237 of file evhtp.h.

#define EVHTP_RES_SWITCH_PROTO   101

Definition at line 188 of file evhtp.h.

#define EVHTP_RES_SWITCHPROXY   306

Definition at line 209 of file evhtp.h.

#define EVHTP_RES_TIMEOUT   408

Definition at line 221 of file evhtp.h.

#define EVHTP_RES_TMPREDIR   307

Definition at line 210 of file evhtp.h.

#define EVHTP_RES_UNAUTH   401

Definition at line 214 of file evhtp.h.

#define EVHTP_RES_UNSUPPORTED   415

Definition at line 228 of file evhtp.h.

#define EVHTP_RES_URI_TOOLONG   122

Definition at line 190 of file evhtp.h.

#define EVHTP_RES_URITOOLARGE   414

Definition at line 227 of file evhtp.h.

#define EVHTP_RES_USEPROXY   305

Definition at line 208 of file evhtp.h.

#define EVHTP_RES_USER   3

Definition at line 182 of file evhtp.h.

#define EVHTP_RES_VERNSUPPORT   505

Definition at line 239 of file evhtp.h.

#define EVHTP_VERSION   "1.2.8"

Definition at line 172 of file evhtp.h.

#define EVHTP_VERSION_MAJOR   1

Definition at line 173 of file evhtp.h.

#define EVHTP_VERSION_MINOR   2

Definition at line 174 of file evhtp.h.

#define EVHTP_VERSION_PATCH   8

Definition at line 175 of file evhtp.h.

Typedef Documentation

typedef struct bufferevent evbev_t

Definition at line 49 of file evhtp.h.

typedef struct evbuffer evbuf_t

Definition at line 46 of file evhtp.h.

typedef struct event event_t

Definition at line 47 of file evhtp.h.

typedef struct evhtp_alias_s evhtp_alias_t

Definition at line 74 of file evhtp.h.

Definition at line 69 of file evhtp.h.

typedef void(* evhtp_callback_cb)(evhtp_request_t *req, void *arg)

Definition at line 140 of file evhtp.h.

Definition at line 63 of file evhtp.h.

Definition at line 134 of file evhtp.h.

typedef struct evhtp_callbacks_s evhtp_callbacks_t

Definition at line 62 of file evhtp.h.

Definition at line 72 of file evhtp.h.

Definition at line 64 of file evhtp.h.

Definition at line 61 of file evhtp.h.

typedef uint8_t evhtp_error_flags

Definition at line 76 of file evhtp.h.

typedef int(* evhtp_headers_iterator)(evhtp_header_t *header, void *arg)

Definition at line 162 of file evhtp.h.

typedef evhtp_res(* evhtp_hook)()

Definition at line 144 of file evhtp.h.

typedef evhtp_res(* evhtp_hook_chunk_fini_cb)(evhtp_request_t *r, void *arg)

Definition at line 155 of file evhtp.h.

typedef evhtp_res(* evhtp_hook_chunk_new_cb)(evhtp_request_t *r, uint64_t len, void *arg)

Definition at line 154 of file evhtp.h.

typedef evhtp_res(* evhtp_hook_chunks_fini_cb)(evhtp_request_t *r, void *arg)

Definition at line 156 of file evhtp.h.

typedef evhtp_res(* evhtp_hook_connection_fini_cb)(evhtp_connection_t *connection, void *arg)

Definition at line 153 of file evhtp.h.

typedef void(* evhtp_hook_err_cb)(evhtp_request_t *req, evhtp_error_flags errtype, void *arg)

Definition at line 141 of file evhtp.h.

typedef evhtp_res(* evhtp_hook_header_cb)(evhtp_request_t *req, evhtp_header_t *hdr, void *arg)

Definition at line 148 of file evhtp.h.

typedef evhtp_res(* evhtp_hook_headers_cb)(evhtp_request_t *req, evhtp_headers_t *hdr, void *arg)

Definition at line 149 of file evhtp.h.

typedef evhtp_res(* evhtp_hook_headers_start_cb)(evhtp_request_t *r, void *arg)

Definition at line 157 of file evhtp.h.

typedef evhtp_res(* evhtp_hook_hostname_cb)(evhtp_request_t *r, const char *hostname, void *arg)

Definition at line 158 of file evhtp.h.

typedef evhtp_res(* evhtp_hook_path_cb)(evhtp_request_t *req, evhtp_path_t *path, void *arg)

Definition at line 150 of file evhtp.h.

typedef evhtp_res(* evhtp_hook_read_cb)(evhtp_request_t *req, evbuf_t *buf, void *arg)

Definition at line 151 of file evhtp.h.

typedef evhtp_res(* evhtp_hook_request_fini_cb)(evhtp_request_t *req, void *arg)

Definition at line 152 of file evhtp.h.

Definition at line 133 of file evhtp.h.

typedef evhtp_res(* evhtp_hook_write_cb)(evhtp_connection_t *conn, void *arg)

Definition at line 159 of file evhtp.h.

typedef struct evhtp_hooks_s evhtp_hooks_t

Definition at line 71 of file evhtp.h.

typedef struct evhtp_kv_s evhtp_kv_t

Definition at line 65 of file evhtp.h.

typedef int(* evhtp_kvs_iterator)(evhtp_kv_t *kv, void *arg)

Definition at line 161 of file evhtp.h.

typedef struct evhtp_kvs_s evhtp_kvs_t

Definition at line 66 of file evhtp.h.

typedef pthread_mutex_t evhtp_mutex_t

Definition at line 57 of file evhtp.h.

typedef struct evhtp_path_s evhtp_path_t

Definition at line 68 of file evhtp.h.

typedef evhtp_res(* evhtp_post_accept_cb)(evhtp_connection_t *conn, void *arg)

Definition at line 147 of file evhtp.h.

typedef evhtp_res(* evhtp_pre_accept_cb)(evhtp_connection_t *conn, void *arg)

Definition at line 146 of file evhtp.h.

typedef enum evhtp_proto evhtp_proto

Definition at line 135 of file evhtp.h.

Definition at line 70 of file evhtp.h.

typedef uint16_t evhtp_res

Definition at line 75 of file evhtp.h.

Definition at line 73 of file evhtp.h.

typedef int(* evhtp_ssl_chk_issued_cb)(evhtp_x509_store_ctx_t *ctx, evhtp_x509_t *x, evhtp_x509_t *issuer)

Definition at line 165 of file evhtp.h.

typedef SSL_CTX evhtp_ssl_ctx_t

Definition at line 35 of file evhtp.h.

typedef int(* evhtp_ssl_scache_add)(evhtp_connection_t *connection, unsigned char *sid, int sid_len, evhtp_ssl_sess_t *sess)

Definition at line 167 of file evhtp.h.

typedef void(* evhtp_ssl_scache_del)(evhtp_t *htp, unsigned char *sid, int sid_len)

Definition at line 168 of file evhtp.h.

typedef evhtp_ssl_sess_t*(* evhtp_ssl_scache_get)(evhtp_connection_t *connection, unsigned char *sid, int sid_len)

Definition at line 169 of file evhtp.h.

typedef void*(* evhtp_ssl_scache_init)(evhtp_t *)

Definition at line 170 of file evhtp.h.

Definition at line 136 of file evhtp.h.

typedef SSL_SESSION evhtp_ssl_sess_t

Definition at line 33 of file evhtp.h.

typedef SSL evhtp_ssl_t

Definition at line 34 of file evhtp.h.

typedef int(* evhtp_ssl_verify_cb)(int pre_verify, evhtp_x509_store_ctx_t *ctx)

Definition at line 164 of file evhtp.h.

typedef struct evhtp_s evhtp_t

Definition at line 60 of file evhtp.h.

typedef void(* evhtp_thread_init_cb)(evhtp_t *htp, evthr_t *thr, void *arg)

Definition at line 139 of file evhtp.h.

typedef enum evhtp_type evhtp_type

Definition at line 137 of file evhtp.h.

typedef struct evhtp_uri_s evhtp_uri_t

Definition at line 67 of file evhtp.h.

typedef X509_STORE_CTX evhtp_x509_store_ctx_t

Definition at line 37 of file evhtp.h.

typedef X509 evhtp_x509_t

Definition at line 36 of file evhtp.h.

typedef struct evconnlistener evserv_t

Definition at line 48 of file evhtp.h.

Enumeration Type Documentation

Enumerator
evhtp_callback_type_hash 
evhtp_callback_type_regex 
evhtp_callback_type_glob 

Definition at line 114 of file evhtp.h.

types associated with where a developer can hook into during the request processing cycle.

Enumerator
evhtp_hook_on_header 

type which defines to hook after one header has been parsed

evhtp_hook_on_headers 

type which defines to hook after all headers have been parsed

evhtp_hook_on_path 

type which defines to hook once a path has been parsed

evhtp_hook_on_read 

type which defines to hook whenever the parser recieves data in a body

evhtp_hook_on_request_fini 

type which defines to hook before the request is free'd

evhtp_hook_on_connection_fini 
evhtp_hook_on_new_chunk 
evhtp_hook_on_chunk_complete 
evhtp_hook_on_chunks_complete 
evhtp_hook_on_headers_start 
evhtp_hook_on_error 

type which defines to hook whenever an error occurs

evhtp_hook_on_hostname 
evhtp_hook_on_write 

Definition at line 98 of file evhtp.h.

Enumerator
EVHTP_PROTO_INVALID 
EVHTP_PROTO_10 
EVHTP_PROTO_11 

Definition at line 122 of file evhtp.h.

Enumerator
evhtp_ssl_scache_type_disabled 
evhtp_ssl_scache_type_internal 
evhtp_ssl_scache_type_user 
evhtp_ssl_scache_type_builtin 

Definition at line 87 of file evhtp.h.

enum evhtp_type
Enumerator
evhtp_type_client 
evhtp_type_server 

Definition at line 128 of file evhtp.h.

Function Documentation

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 3536 of file evhtp.c.

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.

Parameters
evhtp
name
vhost
Returns

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 3571 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
htp
@paramsin_len
backlog
Returns

Definition at line 2712 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 2754 of file evhtp.c.

void evhtp_callback_free ( evhtp_callback_t callback)

Definition at line 2871 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 2832 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 2901 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 3450 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 3373 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 3699 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 1969 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 1982 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 3410 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 3436 of file evhtp.c.

int evhtp_connection_set_ratelimit ( evhtp_connection_t c,
size_t  read_rate,
size_t  read_burst,
size_t  write_rate,
size_t  write_burst,
const struct timeval *  tick 
)

set a bufferevent ratelimit on a evhtp_connection_t structure. The logic is the same as libevent's rate-limiting code.

Parameters
c
read_rate
read_burst
write_rate
write_burst
tick
Returns
void evhtp_connection_set_timeouts ( evhtp_connection_t conn,
const struct timeval *  r,
const struct timeval *  w 
)

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 3425 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 3378 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 3531 of file evhtp.c.

void evhtp_free ( evhtp_t evhtp)

Definition at line 3632 of file evhtp.c.

const char* evhtp_header_find ( evhtp_headers_t headers,
const char *  key 
)

finds the value of a key in a evhtp_headers_t structure

Parameters
headersthe evhtp_headers_t tailq
keythe key to find
Returns
the value of the header key if found, NULL if not found.
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 2016 of file evhtp.c.

evhtp_header_t* evhtp_header_new ( const char *  key,
const char *  val,
char  kalloc,
char  valloc 
)

creates a new evhtp_header_t key/val structure

Parameters
keya null terminated string
vala null terminated string
kallocif 1, key will be copied, otherwise no copy performed
vallocif 1, val will be copied, otehrwise no copy performed
Returns
evhtp_header_t * or NULL on error
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 2029 of file evhtp.c.

void evhtp_headers_add_header ( evhtp_headers_t headers,
evhtp_header_t header 
)

adds an evhtp_header_t to the end of the evhtp_headers_t tailq

Parameters
headers
header
const char* evhtp_kv_find ( evhtp_kvs_t kvs,
const char *  key 
)

Definition at line 2181 of file evhtp.c.

void evhtp_kv_free ( evhtp_kv_t kv)

Definition at line 2114 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 2068 of file evhtp.c.

void evhtp_kv_rm_and_free ( evhtp_kvs_t kvs,
evhtp_kv_t kv 
)

Definition at line 2131 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 2215 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 2224 of file evhtp.c.

evhtp_kv_t* evhtp_kvs_find_kv ( evhtp_kvs_t kvs,
const char *  key 
)

Definition at line 2198 of file evhtp.c.

int evhtp_kvs_for_each ( evhtp_kvs_t kvs,
evhtp_kvs_iterator  cb,
void *  arg 
)

Definition at line 2162 of file evhtp.c.

void evhtp_kvs_free ( evhtp_kvs_t kvs)

Definition at line 2142 of file evhtp.c.

evhtp_kvs_t* evhtp_kvs_new ( void  )

Definition at line 2060 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 3745 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 3606 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.

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 2356 of file evhtp.c.

void evhtp_request_free ( evhtp_request_t request)

Definition at line 3494 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 3400 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 3420 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 1959 of file evhtp.c.

evhtp_request_t* evhtp_request_new ( evhtp_callback_cb  cb,
void *  arg 
)

allocate a new request

Definition at line 3730 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 1998 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 2011 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 3415 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 3445 of file evhtp.c.

unsigned int evhtp_request_status ( evhtp_request_t )

Definition at line 3774 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 2599 of file evhtp.c.

void evhtp_send_reply ( evhtp_request_t request,
evhtp_res  code 
)

Definition at line 2582 of file evhtp.c.

void evhtp_send_reply_body ( evhtp_request_t request,
evbuf_t buf 
)

Definition at line 2565 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 2676 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 2696 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 2607 of file evhtp.c.

void evhtp_send_reply_end ( evhtp_request_t request)

Definition at line 2574 of file evhtp.c.

void evhtp_send_reply_start ( evhtp_request_t request,
evhtp_res  code 
)

Definition at line 2549 of file evhtp.c.

void evhtp_set_bev_flags ( evhtp_t htp,
int  flags 
)

set bufferevent flags, defaults to BEV_OPT_CLOSE_ON_FREE

Parameters
htp
flags

Definition at line 3521 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 3040 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 3178 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 3148 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 2908 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 3526 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 3510 of file evhtp.c.

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

Definition at line 3190 of file evhtp.c.

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

Definition at line 3184 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 3116 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 3499 of file evhtp.c.

int evhtp_ssl_init ( evhtp_t htp,
evhtp_ssl_cfg_t ssl_cfg 
)

Definition at line 3223 of file evhtp.c.

int evhtp_ssl_use_threads ( void  )

Definition at line 3198 of file evhtp.c.

void evhtp_unbind_socket ( evhtp_t htp)

stops the listening socket.

Parameters
htp

Definition at line 2706 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 2281 of file evhtp.c.

int evhtp_unset_all_hooks ( evhtp_hooks_t **  hooks)

removes all hooks.

Parameters
hooks
Returns

Definition at line 2981 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 2976 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 3100 of file evhtp.c.

int evhtp_use_threads ( evhtp_t htp,
evhtp_thread_init_cb  init_cb,
int  nthreads,
void *  arg 
)

Definition at line 3080 of file evhtp.c.

TAILQ_HEAD ( evhtp_callbacks_s  ,
evhtp_callback_s   
)
TAILQ_HEAD ( evhtp_kvs_s  ,
evhtp_kv_s   
)