Go to the documentation of this file.
5 #include <evhtp/config.h>
11 #ifndef EVHTP_DISABLE_EVTHR
12 #include <evhtp/thread.h>
15 #include <evhtp/parser.h>
17 #ifndef EVHTP_DISABLE_REGEX
18 #include <onigposix.h>
21 #include <sys/queue.h>
22 #include <event2/event.h>
23 #include <event2/listener.h>
24 #include <event2/buffer.h>
25 #include <event2/bufferevent.h>
27 #ifndef EVHTP_DISABLE_SSL
28 #include <event2/bufferevent_ssl.h>
29 #include <openssl/dh.h>
30 #include <openssl/ssl.h>
31 #include <openssl/err.h>
32 #include <openssl/rand.h>
40 struct evhtp_callbacks;
43 #ifndef EVHTP_DISABLE_SSL
49 #if OPENSSL_VERSION_NUMBER < 0x10100000L
67 #ifdef EVHTP_DISABLE_EVTHR
68 typedef struct event_base evbase_t;
70 typedef void evthr_pool_t;
76 typedef struct evhtp evhtp_t;
93 typedef struct evhtp_kv evhtp_header_t;
130 #ifndef EVHTP_DISABLE_REGEX
180 #ifndef EVHTP_DISABLE_SSL
183 typedef EVP_PKEY * (* evhtp_ssl_decrypt_cb)(
char * privfile);
189 typedef void * (* evhtp_ssl_scache_init)(evhtp_t *);
192 #define EVHTP_VERSION "1.2.18"
193 #define EVHTP_VERSION_MAJOR 1
194 #define EVHTP_VERSION_MINOR 2
195 #define EVHTP_VERSION_PATCH 18
197 #define evhtp_headers_iterator evhtp_kvs_iterator
199 #define EVHTP_RES_ERROR 0
200 #define EVHTP_RES_PAUSE 1
201 #define EVHTP_RES_FATAL 2
202 #define EVHTP_RES_USER 3
203 #define EVHTP_RES_DATA_TOO_LONG 4
204 #define EVHTP_RES_OK 200
206 #ifndef DOXYGEN_SHOULD_SKIP_THIS
207 #define EVHTP_RES_100 100
208 #define EVHTP_RES_CONTINUE 100
209 #define EVHTP_RES_SWITCH_PROTO 101
210 #define EVHTP_RES_PROCESSING 102
211 #define EVHTP_RES_URI_TOOLONG 122
213 #define EVHTP_RES_200 200
214 #define EVHTP_RES_CREATED 201
215 #define EVHTP_RES_ACCEPTED 202
216 #define EVHTP_RES_NAUTHINFO 203
217 #define EVHTP_RES_NOCONTENT 204
218 #define EVHTP_RES_RSTCONTENT 205
219 #define EVHTP_RES_PARTIAL 206
220 #define EVHTP_RES_MSTATUS 207
221 #define EVHTP_RES_IMUSED 226
223 #define EVHTP_RES_300 300
224 #define EVHTP_RES_MCHOICE 300
225 #define EVHTP_RES_MOVEDPERM 301
226 #define EVHTP_RES_FOUND 302
227 #define EVHTP_RES_SEEOTHER 303
228 #define EVHTP_RES_NOTMOD 304
229 #define EVHTP_RES_USEPROXY 305
230 #define EVHTP_RES_SWITCHPROXY 306
231 #define EVHTP_RES_TMPREDIR 307
233 #define EVHTP_RES_400 400
234 #define EVHTP_RES_BADREQ 400
235 #define EVHTP_RES_UNAUTH 401
236 #define EVHTP_RES_PAYREQ 402
237 #define EVHTP_RES_FORBIDDEN 403
238 #define EVHTP_RES_NOTFOUND 404
239 #define EVHTP_RES_METHNALLOWED 405
240 #define EVHTP_RES_NACCEPTABLE 406
241 #define EVHTP_RES_PROXYAUTHREQ 407
242 #define EVHTP_RES_TIMEOUT 408
243 #define EVHTP_RES_CONFLICT 409
244 #define EVHTP_RES_GONE 410
245 #define EVHTP_RES_LENREQ 411
246 #define EVHTP_RES_PRECONDFAIL 412
247 #define EVHTP_RES_ENTOOLARGE 413
248 #define EVHTP_RES_URITOOLARGE 414
249 #define EVHTP_RES_UNSUPPORTED 415
250 #define EVHTP_RES_RANGENOTSC 416
251 #define EVHTP_RES_EXPECTFAIL 417
252 #define EVHTP_RES_IAMATEAPOT 418
254 #define EVHTP_RES_500 500
255 #define EVHTP_RES_SERVERR 500
256 #define EVHTP_RES_NOTIMPL 501
257 #define EVHTP_RES_BADGATEWAY 502
258 #define EVHTP_RES_SERVUNAVAIL 503
259 #define EVHTP_RES_GWTIMEOUT 504
260 #define EVHTP_RES_VERNSUPPORT 505
261 #define EVHTP_RES_BWEXEED 509
293 #define EVHTP_FLAG_ENABLE_100_CONT (1 << 1)
294 #define EVHTP_FLAG_ENABLE_REUSEPORT (1 << 2)
295 #define EVHTP_FLAG_ENABLE_NODELAY (1 << 3)
296 #define EVHTP_FLAG_ENABLE_DEFER_ACCEPT (1 << 4)
297 #define EVHTP_FLAG_DEFAULTS EVHTP_FLAG_ENABLE_100_CONT
298 #define EVHTP_FLAG_ENABLE_ALL EVHTP_FLAG_ENABLE_100_CONT \
299 | EVHTP_FLAG_ENABLE_REUSEPORT \
300 | EVHTP_FLAG_ENABLE_NODELAY \
301 | EVHTP_FLAG_ENABLE_DEFER_ACCEPT
306 #ifndef EVHTP_DISABLE_SSL
311 #ifndef EVHTP_DISABLE_EVTHR
321 #define thread_init_cbarg thread_cbarg
413 #define EVHTP_REQ_FLAG_KEEPALIVE (1 << 1)
414 #define EVHTP_REQ_FLAG_FINISHED (1 << 2)
415 #define EVHTP_REQ_FLAG_CHUNKED (1 << 3)
416 #define EVHTP_REQ_FLAG_ERROR (1 << 4)
425 #define evhtp_request_content_len(r) htparser_get_content_length(r->conn->parser)
431 #ifndef EVHTP_DISABLE_EVTHR
434 #ifndef EVHTP_DISABLE_SSL
449 #define EVHTP_CONN_FLAG_ERROR (1 << 1)
450 #define EVHTP_CONN_FLAG_OWNER (1 << 2)
451 #define EVHTP_CONN_FLAG_VHOST_VIA_SNI (1 << 3)
452 #define EVHTP_CONN_FLAG_PAUSED (1 << 4)
453 #define EVHTP_CONN_FLAG_CONNECTED (1 << 5)
454 #define EVHTP_CONN_FLAG_WAITING (1 << 6)
455 #define EVHTP_CONN_FLAG_FREE_CONN (1 << 7)
456 #define EVHTP_CONN_FLAG_KEEPALIVE (1 << 8)
461 #ifdef EVHTP_FUTURE_USE
500 #ifndef EVHTP_DISABLE_SSL
531 void (*
free_)(
void *));
541 EVHTP_EXPORT evhtp_t *
evhtp_new(
struct event_base * evbase,
void * arg);
571 EVHTP_EXPORT
void evhtp_set_timeouts(evhtp_t * htp,
const struct timeval * r,
const struct timeval * w);
598 #ifndef EVHTP_DISABLE_SSL
600 EVHTP_EXPORT
int evhtp_ssl_init(evhtp_t * htp, evhtp_ssl_cfg_t * ssl_cfg);
611 DEPRECATED("evhtp_disable_100 will soon be deprecated, use htp->flags
instead");
666 EVHTP_EXPORT evhtp_callback_t *
evhtp_set_cb(evhtp_t * htp, const
char * path,
680 #ifndef EVHTP_DISABLE_REGEX
681 EVHTP_EXPORT evhtp_callback_t *
evhtp_set_regex_cb(evhtp_t * htp,
const char * pattern,
699 EVHTP_EXPORT evhtp_callback_t *
evhtp_set_glob_cb(evhtp_t * htp,
const char * pattern,
728 EVHTP_EXPORT evhtp_callback_t *
evhtp_get_cb(evhtp_t * htp,
const char * needle);
806 EVHTP_EXPORT
int evhtp_bind_socket(evhtp_t * htp,
const char * addr, uint16_t port,
int backlog);
844 size_t sin_len,
int backlog);
862 DEPRECATED(
"will take on the syntax of evhtp_use_threads_wexit");
871 int nthreads,
void * arg);
942 EVHTP_EXPORT evhtp_callback_t *
1019 EVHTP_EXPORT evhtp_kv_t *
evhtp_kv_new(
const char * key,
const char * val,
char kalloc,
char valloc);
1103 #define EVHTP_PARSE_QUERY_FLAG_STRICT 0
1104 #define EVHTP_PARSE_QUERY_FLAG_IGNORE_HEX (1 << 0)
1105 #define EVHTP_PARSE_QUERY_FLAG_ALLOW_EMPTY_VALS (1 << 1)
1106 #define EVHTP_PARSE_QUERY_FLAG_ALLOW_NULL_VALS (1 << 2)
1107 #define EVHTP_PARSE_QUERY_FLAG_TREAT_SEMICOLON_AS_SEP (1 << 3)
1108 #define EVHTP_PARSE_QUERY_FLAG_IGNORE_FRAGMENTS (1 << 4)
1109 #define EVHTP_PARSE_QUERY_FLAG_LENIENT \
1110 EVHTP_PARSE_QUERY_FLAG_IGNORE_HEX \
1111 | EVHTP_PARSE_QUERY_FLAG_ALLOW_EMPTY_VALS \
1112 | EVHTP_PARSE_QUERY_FLAG_ALLOW_NULL_VALS \
1113 | EVHTP_PARSE_QUERY_FLAG_TREAT_SEMICOLON_AS_SEP
1115 #define EVHTP_PARSE_QUERY_FLAG_DEFAULT EVHTP_PARSE_QUERY_FLAG_LENIENT
1164 EVHTP_EXPORT evhtp_header_t *
evhtp_header_new(
const char * key,
const char * val,
1165 char kalloc,
char valloc);
1178 const char * key,
char kalloc);
1191 const char * val,
char valloc);
1212 #define evhtp_headers_find_header evhtp_kvs_find_kv
1213 #define evhtp_headers_for_each evhtp_kvs_for_each
1214 #define evhtp_header_free evhtp_kv_free
1215 #define evhtp_headers_new evhtp_kvs_new
1216 #define evhtp_headers_free evhtp_kvs_free
1217 #define evhtp_header_rm_and_free evhtp_kv_rm_and_free
1218 #define evhtp_headers_add_headers evhtp_kvs_add_kvs
1219 #define evhtp_query_new evhtp_kvs_new
1220 #define evhtp_query_free evhtp_kvs_free
1334 const struct timeval * r,
1335 const struct timeval * w);
1415 struct event_base * evbase,
1416 struct evdns_base * dns_base,
1417 const char * addr, uint16_t port);
1422 EVHTP_EXPORT evhtp_connection_t *
1425 #ifndef EVHTP_DISABLE_SSL
1427 struct event_base * evbase,
1441 evhtp_request_t * r, htp_method meth,
const char * uri);
1445 #define evhtp_safe_free(_var, _freefn) do { \
struct evconnlistener * server
the libevent listener struct
EVHTP_EXPORT 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.
void * on_connection_error_arg
EVHTP_EXPORT int evhtp_callbacks_add_callback(evhtp_callbacks_t *cbs, evhtp_callback_t *cb)
Adds a evhtp_callback_t to the evhtp_callbacks_t list.
EVHTP_EXPORT int evhtp_use_threads(evhtp_t *, evhtp_thread_init_cb, int nthreads, void *) DEPRECATED("will take on the syntax of evhtp_use_threads_wexit")
Enable thread-pool support for an evhtp_t context.
evhtp_t * htp
the parent evhtp_t structure
EVHTP_EXPORT 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.
EVHTP_EXPORT 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.
evhtp_hook_type
types associated with where a developer can hook into during the request processing cycle.
EVHTP_EXPORT int evhtp_request_get_flags(evhtp_request_t *)
EVHTP_EXPORT 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'
struct evhtp_kvs evhtp_kvs_t
evhtp_res(* evhtp_hook_chunk_new_cb)(evhtp_request_t *r, uint64_t len, void *arg)
EVHTP_EXPORT 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
unsigned char * query_raw
the unparsed query arguments
void *(* evhtp_ssl_scache_init)(evhtp_t *)
EVP_PKEY *(* evhtp_ssl_decrypt_cb)(char *privfile)
evhtp_ssl_sess_t *(* evhtp_ssl_scache_get)(evhtp_connection_t *connection, evhtp_ssl_data_t *sid, int sid_len)
EVHTP_EXPORT 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.
EVHTP_EXPORT void evhtp_set_pre_accept_cb(evhtp_t *htp, evhtp_pre_accept_cb, void *arg)
call a user-defined function before the connection is accepted.
structure containing a single callback and configuration
char * password
the password in URI (scheme://...:PASS.
unsigned int matched_soff
offset of where the uri starts mainly used for regex matching
TAILQ_ENTRY(evhtp) next_vhost
evhtp_hook_write_cb on_write
EVHTP_EXPORT void evhtp_disable_100_continue(evhtp_t *htp) DEPRECATED("evhtp_disable_100 will soon be deprecated
when a client sends an Expect: 100-continue, if this is function is called, evhtp will not send a HTT...
EVHTP_EXPORT evhtp_hooks_t * evhtp_connection_get_hooks(evhtp_connection_t *c)
TAILQ_HEAD(, evhtp_alias) aliases
@ evhtp_hook_on_chunk_complete
X509_STORE_CTX evhtp_x509_store_ctx_t
EVHTP_EXPORT 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...
struct event_base * evbase
EVHTP_EXPORT evhtp_hooks_t * evhtp_callback_get_hooks(evhtp_callback_t *cb)
returns callback hooks
EVHTP_EXPORT void evhtp_disable_flag(evhtp_t *, int)
uint16_t flags
the base flags set for this context, see: EVHTP_FLAG_*
evhtp_hook_hostname_cb on_hostname
EVHTP_EXPORT 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
EVHTP_EXPORT evhtp_connection_t * evhtp_connection_ssl_new(struct event_base *evbase, const char *addr, uint16_t port, evhtp_ssl_ctx_t *ctx)
EVHTP_EXPORT void evhtp_request_disable_flag(evhtp_request_t *, int)
uint8_t evhtp_error_flags
EVHTP_EXPORT int evhtp_connection_unset_hook(evhtp_connection_t *conn, evhtp_hook_type type)
@ evhtp_ssl_scache_type_user
static void *(* realloc_)(void *d, size_t sz)
EVHTP_EXPORT evhtp_hooks_t * evhtp_request_get_hooks(evhtp_request_t *r)
returns request hooks
evhtp_ssl_decrypt_cb decrypt_cb
void * cbarg
argument which is passed to the cb function
evhtp_res(* evhtp_hook_headers_start_cb)(evhtp_request_t *r, void *arg)
int(* evhtp_kvs_iterator)(evhtp_kv_t *kv, void *arg)
EVHTP_EXPORT void evhtp_send_reply_start(evhtp_request_t *request, evhtp_res code)
EVHTP_EXPORT 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.
evhtp_res(* evhtp_hook_chunks_fini_cb)(evhtp_request_t *r, void *arg)
evhtp_hook_headers_start_cb on_headers_start
struct bufferevent evbev_t
void(* evhtp_thread_exit_cb)(evhtp_t *htp, evthr_t *thr, void *arg)
@ evhtp_callback_type_glob
evhtp_hook_chunks_fini_cb on_chunks_fini
EVHTP_EXPORT int evhtp_ssl_use_threads(void)
void * on_chunks_fini_arg
int(* evhtp_ssl_verify_cb)(int pre_verify, evhtp_x509_store_ctx_t *ctx)
EVHTP_EXPORT 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.
a generic container representing an entire URI strucutre
evhtp_hook_header_cb on_header
EVHTP_EXPORT int evhtp_connection_get_flags(evhtp_connection_t *)
@ evhtp_ssl_scache_type_disabled
evhtp_ssl_scache_get scache_get
#define evhtp_headers_iterator
EVHTP_EXPORT void evhtp_set_max_keepalive_requests(evhtp_t *htp, uint64_t num)
sets a maximum number of requests that a single connection can make.
evhtp_ssl_cfg_t * ssl_cfg
unsigned char * fragment
data after '#' in uri
struct evhtp_callbacks evhtp_callbacks_t
evhtp_res(* evhtp_hook_connection_fini_cb)(evhtp_connection_t *connection, void *arg)
evhtp_thread_exit_cb thread_exit_cb
evhtp_query_t * query
list of k/v for query arguments
const EVHTP_EXPORT char * evhtp_header_find(evhtp_headers_t *headers, const char *key)
finds the value of a key in a evhtp_headers_t structure
EVHTP_EXPORT 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
int(* evhtp_ssl_chk_issued_cb)(evhtp_x509_store_ctx_t *ctx, evhtp_x509_t *x, evhtp_x509_t *issuer)
EVHTP_EXPORT void evhtp_send_reply_chunk_start(evhtp_request_t *request, evhtp_res code)
start a chunked response.
evhtp_hook_event_cb on_event
unsigned char evhtp_ssl_data_t
structure which represents a URI path and or file
evhtp_type type
server or client
EVHTP_EXPORT 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.
EVHTP_EXPORT evhtp_connection_t * evhtp_connection_new_dns(struct event_base *evbase, struct evdns_base *dns_base, const char *addr, uint16_t port)
allocate a new connection
@ evhtp_hook_on_path
type which defines to hook once a path has been parsed
void(* evhtp_thread_init_cb)(evhtp_t *htp, evthr_t *thr, void *arg)
@ evhtp_callback_type_hash
EVHTP_EXPORT void evhtp_request_pause(evhtp_request_t *request)
Wrapper around evhtp_connection_pause.
char * file
the filename if present (c.html)
@ evhtp_hook_on_chunks_complete
EVHTP_EXPORT int evhtp_use_threads_wexit(evhtp_t *, evhtp_thread_init_cb, evhtp_thread_exit_cb, int nthreads, void *arg)
Temporary function which will be renamed evhtp_use_threads in the future.
evhtp_headers_t * headers_in
headers from client
evhtp_res(* evhtp_hook_conn_err_cb)(evhtp_connection_t *connection, evhtp_error_flags errtype, void *arg)
EVHTP_EXPORT 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.
evhtp_hook_chunk_fini_cb on_chunk_fini
EVHTP_EXPORT void evhtp_enable_flag(evhtp_t *, int)
evhtp_request_t * request
the request currently being processed
TAILQ_ENTRY(evhtp_kv) next
@ evhtp_hook_on_read
type which defines to hook whenever the parser recieves data in a body
evhtp_res(* evhtp_hook_header_cb)(evhtp_request_t *req, evhtp_header_t *hdr, void *arg)
evhtp_res(* evhtp_hook_write_cb)(evhtp_connection_t *conn, void *arg)
EVHTP_EXPORT int evhtp_request_set_hook(evhtp_request_t *r, evhtp_hook_type type, evhtp_hook cb, void *arg)
struct evconnlistener evserv_t
struct evbuffer * scratch_buf
always zero'd out after used
EVHTP_EXPORT void evhtp_kv_free(evhtp_kv_t *kv)
frees resources allocated for a single key/value
EVHTP_EXPORT int evhtp_ssl_init(evhtp_t *htp, evhtp_ssl_cfg_t *ssl_cfg)
a structure containing all information for a http request.
structure which represents authority information in a URI
char * username
the username in URI (scheme://USER:.
evhtp_hook_path_cb on_path
evhtp_ssl_scache_add scache_add
EVHTP_EXPORT 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.
EVHTP_EXPORT int evhtp_bind_sockaddr(evhtp_t *htp, struct sockaddr *, size_t sin_len, int backlog)
bind to an already allocated sockaddr.
EVHTP_EXPORT struct bufferevent * evhtp_connection_get_bev(evhtp_connection_t *conn)
returns the underlying connections bufferevent
evthr_pool_t * thr_pool
connection threadpool
evhtp_res(* evhtp_pre_accept_cb)(evhtp_connection_t *conn, void *arg)
EVHTP_EXPORT void evhtp_kvs_free(evhtp_kvs_t *kvs)
frees a the list of key/values, and all underlying entries
EVHTP_EXPORT void evhtp_request_free(evhtp_request_t *request)
EVHTP_EXPORT void evhtp_request_set_keepalive(evhtp_request_t *request, int val)
void(* evhtp_hook_err_cb)(evhtp_request_t *req, evhtp_error_flags errtype, void *arg)
const EVHTP_EXPORT char * evhtp_kv_find(evhtp_kvs_t *kvs, const char *key)
find the string value of 'key' from the key/value list 'kvs'
EVHTP_EXPORT void evhtp_send_reply_end(evhtp_request_t *request)
evhtp_res(* evhtp_hook_hostname_cb)(evhtp_request_t *r, const char *hostname, void *arg)
EVHTP_EXPORT int evhtp_use_callback_locks(evhtp_t *htp)
creates a lock around callbacks and hooks, allowing for threaded applications to add/remove/modify ho...
struct evbuffer * buffer_in
buffer containing data from client
EVHTP_EXPORT void evhtp_connection_disable_flag(evhtp_connection_t *, int)
char v_heaped
set to 1 if the val can be free()'d
struct timeval send_timeo
conn write timeouts (overrides global)
evhtp_res(* evhtp_post_accept_cb)(evhtp_connection_t *conn, void *arg)
char k_heaped
set to 1 if the key can be free()'d
char * path
the path (/a/b/)
EVHTP_EXPORT void evhtp_connection_enable_flag(evhtp_connection_t *, int)
@ evhtp_hook_on_request_fini
type which defines to hook before the request is free'd
EVHTP_EXPORT 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'
EVHTP_EXPORT void use htp flags instead
void(* evhtp_ssl_scache_del)(evhtp_t *htp, evhtp_ssl_data_t *sid, int sid_len)
evhtp_thread_init_cb thread_init_cb
EVHTP_EXPORT void evhtp_kvs_add_kvs(evhtp_kvs_t *dst, evhtp_kvs_t *src)
appends all key/val structures from src tailq onto dst tailq
struct timeval recv_timeo
conn read timeouts (overrides global)
char * hostname
hostname if present in URI
uint64_t max_keepalive_requests
evhtp_res(* evhtp_hook_path_cb)(evhtp_request_t *req, evhtp_path_t *path, void *arg)
pthread_mutex_t evhtp_mutex_t
struct timeval send_timeo
EVHTP_EXPORT 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.
EVHTP_EXPORT int evhtp_callback_set_hook(evhtp_callback_t *cb, evhtp_hook_type type, evhtp_hook hookcb, void *arg)
TAILQ_HEAD(evhtp_kvs, evhtp_kv)
struct evhtp_kvs evhtp_headers_t
evhtp_res(* evhtp_hook_read_cb)(evhtp_request_t *req, struct evbuffer *buf, void *arg)
EVHTP_EXPORT void evhtp_connection_resume(evhtp_connection_t *connection)
resumes a connection (enables reading) and activates resume event.
EVHTP_EXPORT int evhtp_get_flags(evhtp_t *)
EVHTP_EXPORT void evhtp_callback_free(evhtp_callback_t *callback)
safely frees callback structure memory and internals
EVHTP_EXPORT evhtp_connection_t * evhtp_connection_new(struct event_base *evbase, const char *addr, uint16_t port)
allocate a new connection
evhtp_ssl_chk_issued_cb x509_chk_issued_cb
EVHTP_EXPORT evhtp_t * evhtp_new(struct event_base *evbase, void *arg)
creates a new evhtp_t instance
EVHTP_EXPORT int evhtp_add_alias(evhtp_t *evhtp, const char *name)
Add an alias hostname for a virtual-host specific evhtp_t.
struct evhtp_kvs evhtp_query_t
evhtp_hook_chunk_new_cb on_new_chunk
EVHTP_EXPORT void evhtp_free(evhtp_t *evhtp)
Frees evhtp_t structure; will stop and free threads associated with the structure,...
EVHTP_EXPORT int evhtp_accept_socket(evhtp_t *htp, evutil_socket_t sock, int backlog)
create the listener plus setup various options with an already-bound socket.
evhtp_res(* evhtp_hook_chunk_fini_cb)(evhtp_request_t *r, void *arg)
evhtp_hook_read_cb on_read
EVHTP_EXPORT void evhtp_request_set_bev(evhtp_request_t *request, struct bufferevent *bev)
sets the underlying bufferevent for a evhtp_request
EVHTP_EXPORT void evhtp_request_enable_flag(evhtp_request_t *, int)
EVHTP_EXPORT evhtp_callback_t * evhtp_get_cb(evhtp_t *htp, const char *needle)
attempts to find the callback matching the exact string 'needle'.
EVHTP_EXPORT void evhtp_request_resume(evhtp_request_t *request)
Wrapper around evhtp_connection_resume.
@ evhtp_hook_on_conn_error
type which defines to hook whenever a connection error occurs
EVHTP_EXPORT 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
evhtp_uri_t * uri
request URI information
EVHTP_EXPORT int evhtp_unset_all_hooks(evhtp_hooks_t **hooks)
removes all hooks.
@ evhtp_callback_type_regex
evhtp_post_accept_cb post_accept
pthread_mutex_t * lock
parent lock for add/del cbs in threads
EVHTP_EXPORT unsigned int evhtp_request_status(evhtp_request_t *)
htp_scheme scheme
set if a scheme is found
EVHTP_EXPORT int evhtp_callback_unset_hook(evhtp_callback_t *callback, evhtp_hook_type type)
const EVHTP_EXPORT char * evhtp_request_get_status_code_str(evhtp_request_t *r)
wrapper around get_status_code that returns the string version of the last status code set for a requ...
EVHTP_EXPORT void evhtp_send_reply_chunk(evhtp_request_t *request, struct evbuffer *buf)
send a chunk reply.
@ evhtp_hook_on_headers_start
EVHTP_EXPORT int evhtp_add_aliases(evhtp_t *evhtp, const char *name,...)
set a variable number of aliases in one call @reference evhtp_add_alias
evhtp_res(* evhtp_hook_headers_cb)(evhtp_request_t *req, evhtp_headers_t *hdr, void *arg)
void * arg
user-defined evhtp_t specific arguments
EVHTP_EXPORT 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 ...
EVHTP_EXPORT void evhtp_set_post_accept_cb(evhtp_t *htp, evhtp_post_accept_cb, void *arg)
call a user-defined function right after a connection is accepted.
@ evhtp_hook_on_error
type which defines to hook whenever an error occurs
EVHTP_EXPORT void evhtp_send_reply_body(evhtp_request_t *request, struct evbuffer *buf)
EVHTP_EXPORT struct bufferevent * evhtp_request_get_bev(evhtp_request_t *request)
returns the underlying requests bufferevent
evhtp_hooks_t * hooks
request specific hooks
main structure containing all configuration information
static void *(* malloc_)(size_t sz)
htp_method method
HTTP method used.
EVHTP_EXPORT int evhtp_response_needs_body(const evhtp_res code, const htp_method method)
Determine if a response should have a body.
EVHTP_EXPORT void evhtp_connection_set_bev(evhtp_connection_t *conn, struct bufferevent *bev)
Sets the connections underlying bufferevent.
EVHTP_EXPORT 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}'.
void * on_headers_start_arg
evhtp_proto proto
HTTP protocol used.
EVHTP_EXPORT evhtp_kvs_t * evhtp_kvs_new(void)
creates an empty list of key/values
evhtp_headers_t * headers_out
headers to client
EVHTP_EXPORT evhtp_proto evhtp_request_get_proto(evhtp_request_t *r)
evhtp_authority_t * authority
void * on_connection_fini_arg
evhtp_connection_t * conn
the associated connection
EVHTP_EXPORT evhtp_request_t * evhtp_request_new(evhtp_callback_cb cb, void *arg)
allocate a new request
EVHTP_EXPORT int evhtp_request_unset_hook(evhtp_request_t *req, evhtp_hook_type type)
char * server_name
the name included in Host: responses
evhtp_ssl_scache_type scache_type
EVHTP_EXPORT 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.
@ evhtp_ssl_scache_type_internal
@ evhtp_hook_on_connection_fini
EVHTP_EXPORT htp_method evhtp_request_get_method(evhtp_request_t *r)
returns the htp_method enum version of the request method.
static void(* free_)(void *d)
EVHTP_EXPORT 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
struct evbuffer * buffer_out
buffer containing data to client
evhtp_res status
The HTTP response code or other error conditions.
uint16_t parser_flags
default query flags to alter 'strictness' (see EVHTP_PARSE_QUERY_FLAG_*)
@ evhtp_hook_on_header
type which defines to hook after one header has been parsed
evhtp_hook_conn_err_cb on_connection_error
struct timeval recv_timeo
evhtp_hook_headers_cb on_headers
EVHTP_EXPORT 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
EVHTP_EXPORT 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
TAILQ_ENTRY(evhtp_request) next
EVHTP_EXPORT evhtp_kv_t * evhtp_kv_new(const char *key, const char *val, char kalloc, char valloc)
Allocates a new key/value structure.
struct event_base * evbase
the initialized event_base
evhtp_ssl_ctx_t * ssl_ctx
if ssl enabled, this is the servers CTX
EVHTP_EXPORT int evhtp_connection_set_hook(evhtp_connection_t *c, evhtp_hook_type type, evhtp_hook cb, void *arg)
sets a callback hook for either a connection or a path/regex .
char * full
the full path+file (/a/b/c.html)
EVHTP_EXPORT 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
EVHTP_EXPORT void evhtp_kvs_add_kv(evhtp_kvs_t *kvs, evhtp_kv_t *kv)
appends a key/val structure to a evhtp_kvs_t tailq
@ evhtp_hook_on_headers
type which defines to hook after all headers have been parsed
evhtp_ssl_scache_del scache_del
a generic key/value structure
EVHTP_EXPORT void evhtp_unbind_socket(evhtp_t *htp)
stops the listening socket.
int bev_flags
bufferevent flags to use on bufferevent_*_socket_new()
@ evhtp_hook_on_new_chunk
EVHTP_EXPORT struct bufferevent * evhtp_connection_take_ownership(evhtp_connection_t *connection)
let a user take ownership of the underlying bufferevent and free all other underlying resources.
evhtp_callback_cb cb
the function to call when fully processed
TAILQ_ENTRY(evhtp_alias) next
evhtp_res(* evhtp_hook)()
int(* evhtp_ssl_scache_add)(evhtp_connection_t *connection, evhtp_ssl_data_t *sid, int sid_len, evhtp_ssl_sess_t *sess)
evhtp_ssl_verify_cb x509_verify_cb
evhtp_callbacks_t * callbacks
EVHTP_EXPORT void evhtp_connection_pause(evhtp_connection_t *connection)
pauses a connection (disables reading)
evhtp_hook_err_cb on_error
evhtp_ssl_scache_init scache_init
evhtp_defaults_t defaults
evhtp_hook_request_fini_cb on_request_fini
evhtp_pre_accept_cb pre_accept
void * on_request_fini_arg
EVHTP_EXPORT void evhtp_set_bev_flags(evhtp_t *htp, int flags)
bufferevent flags which will be used for bev sockets.
EVHTP_EXPORT evhtp_connection_t * evhtp_request_get_connection(evhtp_request_t *request)
returns the underlying evhtp_connection_t structure from a request
@ evhtp_ssl_scache_type_builtin
EVHTP_EXPORT 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
EVHTP_EXPORT int evhtp_make_request(evhtp_connection_t *c, evhtp_request_t *r, htp_method meth, const char *uri)
make a client request
evhtp_hook_connection_fini_cb on_connection_fini
EVHTP_EXPORT 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_bod...
evhtp_res(* evhtp_hook_request_fini_cb)(evhtp_request_t *req, void *arg)
EVHTP_EXPORT evhtp_res evhtp_request_get_status_code(evhtp_request_t *r)
Returns the last status code set for a request (request/response)
uint16_t port
port if present in URI
evhtp_t * parent
only when this is a vhost
unsigned int matched_eoff
offset of where the uri ends mainly used for regex matching
void(* evhtp_callback_cb)(evhtp_request_t *req, void *arg)
void(* evhtp_hook_event_cb)(evhtp_connection_t *conn, short events, void *arg)
EVHTP_EXPORT void evhtp_set_mem_functions(void *(*malloc_)(size_t), void *(*realloc_)(void *, size_t), void(*free_)(void *))
SSL_SESSION evhtp_ssl_sess_t