4 #include <evhtp-config.h>
5 #ifndef EVHTP_DISABLE_EVTHR
11 #ifndef EVHTP_DISABLE_REGEX
12 #include <onigposix.h>
15 #include <sys/queue.h>
16 #include <event2/event.h>
17 #include <event2/listener.h>
18 #include <event2/buffer.h>
19 #include <event2/bufferevent.h>
21 #ifndef EVHTP_DISABLE_SSL
22 #include <event2/bufferevent_ssl.h>
23 #include <openssl/ssl.h>
24 #include <openssl/err.h>
25 #include <openssl/rand.h>
32 #ifndef EVHTP_DISABLE_SSL
51 #ifdef EVHTP_DISABLE_EVTHR
52 typedef struct event_base evbase_t;
54 typedef void evthr_pool_t;
79 #define evhtp_header_s evhtp_kv_s
80 #define evhtp_headers_s evhtp_kvs_s
81 #define evhtp_query_s evhtp_kvs_s
83 #define evhtp_header_t evhtp_kv_t
84 #define evhtp_headers_t evhtp_kvs_t
85 #define evhtp_query_t evhtp_kvs_t
116 #ifndef EVHTP_DISABLE_REGEX
169 typedef evhtp_ssl_sess_t * (*evhtp_ssl_scache_get)(
evhtp_connection_t * connection,
unsigned char * sid,
int sid_len);
170 typedef void * (*evhtp_ssl_scache_init)(
evhtp_t *);
172 #define EVHTP_VERSION "1.2.8"
173 #define EVHTP_VERSION_MAJOR 1
174 #define EVHTP_VERSION_MINOR 2
175 #define EVHTP_VERSION_PATCH 8
177 #define evhtp_headers_iterator evhtp_kvs_iterator
179 #define EVHTP_RES_ERROR 0
180 #define EVHTP_RES_PAUSE 1
181 #define EVHTP_RES_FATAL 2
182 #define EVHTP_RES_USER 3
183 #define EVHTP_RES_DATA_TOO_LONG 4
184 #define EVHTP_RES_OK 200
186 #define EVHTP_RES_100 100
187 #define EVHTP_RES_CONTINUE 100
188 #define EVHTP_RES_SWITCH_PROTO 101
189 #define EVHTP_RES_PROCESSING 102
190 #define EVHTP_RES_URI_TOOLONG 122
192 #define EVHTP_RES_200 200
193 #define EVHTP_RES_CREATED 201
194 #define EVHTP_RES_ACCEPTED 202
195 #define EVHTP_RES_NAUTHINFO 203
196 #define EVHTP_RES_NOCONTENT 204
197 #define EVHTP_RES_RSTCONTENT 205
198 #define EVHTP_RES_PARTIAL 206
199 #define EVHTP_RES_MSTATUS 207
200 #define EVHTP_RES_IMUSED 226
202 #define EVHTP_RES_300 300
203 #define EVHTP_RES_MCHOICE 300
204 #define EVHTP_RES_MOVEDPERM 301
205 #define EVHTP_RES_FOUND 302
206 #define EVHTP_RES_SEEOTHER 303
207 #define EVHTP_RES_NOTMOD 304
208 #define EVHTP_RES_USEPROXY 305
209 #define EVHTP_RES_SWITCHPROXY 306
210 #define EVHTP_RES_TMPREDIR 307
212 #define EVHTP_RES_400 400
213 #define EVHTP_RES_BADREQ 400
214 #define EVHTP_RES_UNAUTH 401
215 #define EVHTP_RES_PAYREQ 402
216 #define EVHTP_RES_FORBIDDEN 403
217 #define EVHTP_RES_NOTFOUND 404
218 #define EVHTP_RES_METHNALLOWED 405
219 #define EVHTP_RES_NACCEPTABLE 406
220 #define EVHTP_RES_PROXYAUTHREQ 407
221 #define EVHTP_RES_TIMEOUT 408
222 #define EVHTP_RES_CONFLICT 409
223 #define EVHTP_RES_GONE 410
224 #define EVHTP_RES_LENREQ 411
225 #define EVHTP_RES_PRECONDFAIL 412
226 #define EVHTP_RES_ENTOOLARGE 413
227 #define EVHTP_RES_URITOOLARGE 414
228 #define EVHTP_RES_UNSUPPORTED 415
229 #define EVHTP_RES_RANGENOTSC 416
230 #define EVHTP_RES_EXPECTFAIL 417
231 #define EVHTP_RES_IAMATEAPOT 418
233 #define EVHTP_RES_500 500
234 #define EVHTP_RES_SERVERR 500
235 #define EVHTP_RES_NOTIMPL 501
236 #define EVHTP_RES_BADGATEWAY 502
237 #define EVHTP_RES_SERVUNAVAIL 503
238 #define EVHTP_RES_GWTIMEOUT 504
239 #define EVHTP_RES_VERNSUPPORT 505
240 #define EVHTP_RES_BWEXEED 509
271 #ifndef EVHTP_DISABLE_SSL
276 #ifndef EVHTP_DISABLE_EVTHR
280 #ifndef EVHTP_DISABLE_EVTHR
288 struct timeval recv_timeo;
289 struct timeval send_timeo;
320 #ifndef EVHTP_DISABLE_REGEX
328 TAILQ_HEAD(evhtp_callbacks_s, evhtp_callback_s);
418 #define evhtp_request_content_len(r) htparser_get_content_length(r->conn->parser)
430 struct timeval recv_timeo;
431 struct timeval send_timeo;
583 #ifndef EVHTP_DISABLE_REGEX
924 #define evhtp_header_find evhtp_kv_find
925 #define evhtp_headers_find_header evhtp_kvs_find_kv
926 #define evhtp_headers_for_each evhtp_kvs_for_each
927 #define evhtp_header_new evhtp_kv_new
928 #define evhtp_header_free evhtp_kv_free
929 #define evhtp_headers_new evhtp_kvs_new
930 #define evhtp_headers_free evhtp_kvs_free
931 #define evhtp_header_rm_and_free evhtp_kv_rm_and_free
932 #define evhtp_headers_add_header evhtp_kvs_add_kv
933 #define evhtp_headers_add_headers evhtp_kvs_add_kvs
934 #define evhtp_query_new evhtp_kvs_new
935 #define evhtp_query_free evhtp_kvs_free
1084 size_t read_burst,
size_t write_rate,
size_t write_burst,
const struct timeval * tick);
evhtp_callbacks_t * callbacks
evhtp_callback_t * evhtp_callback_new(const char *path, evhtp_callback_type type, evhtp_callback_cb cb, void *arg)
creates a new evhtp_callback_t structure.
unsigned int evhtp_request_status(evhtp_request_t *)
void evhtp_send_reply_chunk(evhtp_request_t *request, evbuf_t *buf)
send a chunk reply.
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...
void(* evhtp_ssl_scache_del)(evhtp_t *htp, unsigned char *sid, int sid_len)
evhtp_res(* evhtp_hook_header_cb)(evhtp_request_t *req, evhtp_header_t *hdr, void *arg)
evhtp_ssl_scache_init scache_init
void evhtp_set_post_accept_cb(evhtp_t *htp, evhtp_post_accept_cb, void *arg)
evhtp_hook_request_fini_cb on_request_fini
evhtp_ssl_sess_t *(* evhtp_ssl_scache_get)(evhtp_connection_t *connection, unsigned char *sid, int sid_len)
evhtp_hook_header_cb on_header
evhtp_ssl_scache_del scache_del
int evhtp_ssl_init(evhtp_t *htp, evhtp_ssl_cfg_t *ssl_cfg)
void * on_connection_fini_arg
int(* evhtp_ssl_scache_add)(evhtp_connection_t *connection, unsigned char *sid, int sid_len, evhtp_ssl_sess_t *sess)
evhtp_ssl_chk_issued_cb x509_chk_issued_cb
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
evhtp_kvs_t * evhtp_kvs_new(void)
void * on_headers_start_arg
int evhtp_use_callback_locks(evhtp_t *htp)
creates a lock around callbacks and hooks, allowing for threaded applications to add/remove/modify ho...
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 virtua...
void evhtp_free(evhtp_t *evhtp)
evbev_t * evhtp_connection_get_bev(evhtp_connection_t *conn)
returns the underlying connections bufferevent
evhtp_kv_t * evhtp_kv_new(const char *key, const char *val, char kalloc, char valloc)
Allocates a new key/value structure.
int evhtp_callbacks_add_callback(evhtp_callbacks_t *cbs, evhtp_callback_t *cb)
Adds a evhtp_callback_t to the evhtp_callbacks_t list.
unsigned char * query_raw
evhtp_thread_init_cb thread_init_cb
void evhtp_connection_pause(evhtp_connection_t *connection)
pauses a connection (disables reading)
void evhtp_connection_set_bev(evhtp_connection_t *conn, evbev_t *bev)
Sets the connections underlying bufferevent.
evhtp_ssl_verify_cb x509_verify_cb
evhtp_hook_write_cb on_write
evhtp_hook_path_cb on_path
evhtp_ssl_cfg_t * ssl_cfg
void evhtp_send_reply(evhtp_request_t *request, evhtp_res code)
int evhtp_use_threads(evhtp_t *htp, evhtp_thread_init_cb init_cb, int nthreads, void *arg)
evhtp_defaults_t defaults
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.
evhtp_hook_chunk_new_cb on_new_chunk
void(* evhtp_callback_cb)(evhtp_request_t *req, void *arg)
int(* evhtp_ssl_verify_cb)(int pre_verify, evhtp_x509_store_ctx_t *ctx)
evbev_t * evhtp_request_get_bev(evhtp_request_t *request)
returns the underlying requests bufferevent
void evhtp_send_reply_end(evhtp_request_t *request)
main structure containing all configuration information
evhtp_res(* evhtp_hook)()
int(* evhtp_ssl_chk_issued_cb)(evhtp_x509_store_ctx_t *ctx, evhtp_x509_t *x, evhtp_x509_t *issuer)
void evhtp_send_reply_body(evhtp_request_t *request, evbuf_t *buf)
void * on_request_fini_arg
#define evhtp_headers_iterator
void evhtp_unbind_socket(evhtp_t *htp)
stops the listening socket.
evhtp_request_t * request
evhtp_res(* evhtp_hook_chunks_fini_cb)(evhtp_request_t *r, void *arg)
void(* evhtp_hook_err_cb)(evhtp_request_t *req, evhtp_error_flags errtype, void *arg)
struct evhtp_callbacks_s evhtp_callbacks_t
htp_method evhtp_request_get_method(evhtp_request_t *r)
returns the htp_method enum version of the request method.
int evhtp_bind_sockaddr(evhtp_t *htp, struct sockaddr *, size_t sin_len, int backlog)
bind to an already allocated sockaddr.
SSL_SESSION evhtp_ssl_sess_t
evhtp_headers_t * headers_in
evhtp_ssl_scache_type scache_type
struct ev_token_bucket_cfg * ratelimit_cfg
evhtp_hook_read_cb on_read
evhtp_res(* evhtp_hook_headers_start_cb)(evhtp_request_t *r, void *arg)
#define evhtp_header_find
struct evhtp_kvs_s evhtp_kvs_t
uint8_t evhtp_error_flags
void evhtp_kv_free(evhtp_kv_t *kv)
X509_STORE_CTX evhtp_x509_store_ctx_t
evhtp_headers_t * headers_out
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
evhtp_res(* evhtp_hook_chunk_new_cb)(evhtp_request_t *r, uint64_t len, void *arg)
a generic key/value structure
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 ...
a structure containing all information for a http request.
const char * evhtp_kv_find(evhtp_kvs_t *kvs, const char *key)
void(* evhtp_thread_init_cb)(evhtp_t *htp, evthr_t *thr, void *arg)
evhtp_res(* evhtp_hook_headers_cb)(evhtp_request_t *req, evhtp_headers_t *hdr, void *arg)
void evhtp_set_pre_accept_cb(evhtp_t *htp, evhtp_pre_accept_cb, void *arg)
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 on...
evhtp_hook_type
types associated with where a developer can hook into during the request processing cycle...
evhtp_pre_accept_cb pre_accept
void evhtp_set_bev_flags(evhtp_t *htp, int flags)
set bufferevent flags, defaults to BEV_OPT_CLOSE_ON_FREE
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_hook_headers_cb on_headers
structure containing a single callback and configuration
evhtp_res(* evhtp_hook_read_cb)(evhtp_request_t *req, evbuf_t *buf, void *arg)
TAILQ_ENTRY(evhtp_alias_s) next
int(* evhtp_kvs_iterator)(evhtp_kv_t *kv, void *arg)
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...
int evhtp_unset_hook(evhtp_hooks_t **hooks, evhtp_hook_type type)
remove a specific hook from being called.
evhtp_post_accept_cb post_accept
void evhtp_callback_free(evhtp_callback_t *callback)
evhtp_ssl_ctx_t * ssl_ctx
void evhtp_kv_rm_and_free(evhtp_kvs_t *kvs, evhtp_kv_t *kv)
void evhtp_send_reply_start(evhtp_request_t *request, evhtp_res code)
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
void evhtp_request_set_bev(evhtp_request_t *request, evbev_t *bev)
sets the underlying bufferevent for a evhtp_request
a generic container representing an entire URI strucutre
evhtp_ssl_scache_get scache_get
struct evconnlistener evserv_t
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_res(* evhtp_hook_chunk_fini_cb)(evhtp_request_t *r, void *arg)
void evhtp_connection_resume(evhtp_connection_t *connection)
resumes a connection (enables reading) and activates resume event.
evhtp_hook_chunks_fini_cb on_chunks_fini
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 evhtp_request_pause(evhtp_request_t *request)
Wrapper around evhtp_connection_pause.
evhtp_res(* evhtp_hook_write_cb)(evhtp_connection_t *conn, void *arg)
pthread_mutex_t evhtp_mutex_t
void * on_chunks_fini_arg
evhtp_res(* evhtp_hook_request_fini_cb)(evhtp_request_t *req, void *arg)
evhtp_connection_t * conn
TAILQ_HEAD(evhtp_callbacks_s, evhtp_callback_s)
evhtp_res(* evhtp_hook_hostname_cb)(evhtp_request_t *r, const char *hostname, void *arg)
void evhtp_request_resume(evhtp_request_t *request)
Wrapper around evhtp_connection_resume.
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 ...
struct bufferevent evbev_t
evhtp_hook_connection_fini_cb on_connection_fini
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 .
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 ra...
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_res(* evhtp_pre_accept_cb)(evhtp_connection_t *conn, void *arg)
void evhtp_request_free(evhtp_request_t *request)
evhtp_t * evhtp_new(evbase_t *evbase, void *arg)
creates a new evhtp_t instance
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.
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 ...
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...
unsigned int matched_soff
unsigned int matched_eoff
evhtp_hook_err_cb on_error
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...
evhtp_res(* evhtp_hook_connection_fini_cb)(evhtp_connection_t *connection, void *arg)
int evhtp_make_request(evhtp_connection_t *c, evhtp_request_t *r, htp_method meth, const char *uri)
make a client request
void evhtp_set_max_keepalive_requests(evhtp_t *htp, uint64_t num)
sets a maximum number of requests that a single connection can make.
int evhtp_ssl_use_threads(void)
void evhtp_kvs_add_kvs(evhtp_kvs_t *dst, evhtp_kvs_t *src)
appends all key/val structures from src tailq onto dst tailq
uint64_t max_keepalive_requests
evhtp_res(* evhtp_post_accept_cb)(evhtp_connection_t *conn, void *arg)
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 0CRLFC...
evhtp_request_t * evhtp_request_new(evhtp_callback_cb cb, void *arg)
allocate a new request
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 HTT...
evhtp_connection_t * evhtp_request_get_connection(evhtp_request_t *request)
returns the underlying evhtp_connection_t structure from a request
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...
evhtp_hook_chunk_fini_cb on_chunk_fini
evhtp_kv_t * evhtp_kvs_find_kv(evhtp_kvs_t *kvs, const char *key)
void *(* evhtp_ssl_scache_init)(evhtp_t *)
void evhtp_kvs_free(evhtp_kvs_t *kvs)
evhtp_hook_hostname_cb on_hostname
int evhtp_kvs_for_each(evhtp_kvs_t *kvs, evhtp_kvs_iterator cb, void *arg)
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_ssl_scache_add scache_add
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 call...
structure which represents a URI path and or file
evhtp_connection_t * evhtp_connection_new(evbase_t *evbase, const char *addr, uint16_t port)
allocate a new connection
evhtp_hook_headers_start_cb on_headers_start
int evhtp_unset_all_hooks(evhtp_hooks_t **hooks)
removes all hooks.
#define evhtp_headers_add_header
structure which represents authority information in a URI
evhtp_res(* evhtp_hook_path_cb)(evhtp_request_t *req, evhtp_path_t *path, void *arg)
evhtp_authority_t * authority