Libevhtp  0.3.7
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
evhtp.h
Go to the documentation of this file.
1 #ifndef __EVHTP__H__
2 #define __EVHTP__H__
3 
4 #include <evhtp-config.h>
5 #ifndef EVHTP_DISABLE_EVTHR
6 #include <evthr.h>
7 #endif
8 
9 #include <htparse.h>
10 
11 #ifndef EVHTP_DISABLE_REGEX
12 #include <onigposix.h>
13 #endif
14 
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>
20 
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>
26 #endif
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #ifndef EVHTP_DISABLE_SSL
33 typedef SSL_SESSION evhtp_ssl_sess_t;
34 typedef SSL evhtp_ssl_t;
35 typedef SSL_CTX evhtp_ssl_ctx_t;
36 typedef X509 evhtp_x509_t;
37 typedef X509_STORE_CTX evhtp_x509_store_ctx_t;
38 #else
39 typedef void evhtp_ssl_sess_t;
40 typedef void evhtp_ssl_t;
41 typedef void evhtp_ssl_ctx_t;
42 typedef void evhtp_x509_t;
43 typedef void evhtp_x509_store_ctx_t;
44 #endif
45 
46 typedef struct evbuffer evbuf_t;
47 typedef struct event event_t;
48 typedef struct evconnlistener evserv_t;
49 typedef struct bufferevent evbev_t;
50 
51 #ifdef EVHTP_DISABLE_EVTHR
52 typedef struct event_base evbase_t;
53 typedef void evthr_t;
54 typedef void evthr_pool_t;
55 typedef void evhtp_mutex_t;
56 #else
57 typedef pthread_mutex_t evhtp_mutex_t;
58 #endif
59 
60 typedef struct evhtp_s evhtp_t;
62 typedef struct evhtp_callbacks_s evhtp_callbacks_t;
65 typedef struct evhtp_kv_s evhtp_kv_t;
66 typedef struct evhtp_kvs_s evhtp_kvs_t;
67 typedef struct evhtp_uri_s evhtp_uri_t;
68 typedef struct evhtp_path_s evhtp_path_t;
75 typedef uint16_t evhtp_res;
76 typedef uint8_t evhtp_error_flags;
77 
78 
79 #define evhtp_header_s evhtp_kv_s
80 #define evhtp_headers_s evhtp_kvs_s
81 #define evhtp_query_s evhtp_kvs_s
82 
83 #define evhtp_header_t evhtp_kv_t
84 #define evhtp_headers_t evhtp_kvs_t
85 #define evhtp_query_t evhtp_kvs_t
86 
92 };
93 
112 };
113 
116 #ifndef EVHTP_DISABLE_REGEX
118 #endif
120 };
121 
126 };
127 
131 };
132 
137 typedef enum evhtp_type evhtp_type;
138 
139 typedef void (*evhtp_thread_init_cb)(evhtp_t * htp, evthr_t * thr, void * arg);
140 typedef void (*evhtp_callback_cb)(evhtp_request_t * req, void * arg);
141 typedef void (*evhtp_hook_err_cb)(evhtp_request_t * req, evhtp_error_flags errtype, void * arg);
142 
143 /* Generic hook for passing ISO tests */
144 typedef evhtp_res (*evhtp_hook)();
145 
146 typedef evhtp_res (*evhtp_pre_accept_cb)(evhtp_connection_t * conn, void * arg);
147 typedef evhtp_res (*evhtp_post_accept_cb)(evhtp_connection_t * conn, void * arg);
148 typedef evhtp_res (*evhtp_hook_header_cb)(evhtp_request_t * req, evhtp_header_t * hdr, void * arg);
149 typedef evhtp_res (*evhtp_hook_headers_cb)(evhtp_request_t * req, evhtp_headers_t * hdr, void * arg);
150 typedef evhtp_res (*evhtp_hook_path_cb)(evhtp_request_t * req, evhtp_path_t * path, void * arg);
151 typedef evhtp_res (*evhtp_hook_read_cb)(evhtp_request_t * req, evbuf_t * buf, void * arg);
153 typedef evhtp_res (*evhtp_hook_connection_fini_cb)(evhtp_connection_t * connection, void * arg);
154 typedef evhtp_res (*evhtp_hook_chunk_new_cb)(evhtp_request_t * r, uint64_t len, void * arg);
158 typedef evhtp_res (*evhtp_hook_hostname_cb)(evhtp_request_t * r, const char * hostname, void * arg);
159 typedef evhtp_res (*evhtp_hook_write_cb)(evhtp_connection_t * conn, void * arg);
160 
161 typedef int (*evhtp_kvs_iterator)(evhtp_kv_t * kv, void * arg);
162 typedef int (*evhtp_headers_iterator)(evhtp_header_t * header, void * arg);
163 
164 typedef int (*evhtp_ssl_verify_cb)(int pre_verify, evhtp_x509_store_ctx_t * ctx);
165 typedef int (*evhtp_ssl_chk_issued_cb)(evhtp_x509_store_ctx_t * ctx, evhtp_x509_t * x, evhtp_x509_t * issuer);
166 
167 typedef int (*evhtp_ssl_scache_add)(evhtp_connection_t * connection, unsigned char * sid, int sid_len, evhtp_ssl_sess_t * sess);
168 typedef void (*evhtp_ssl_scache_del)(evhtp_t * htp, unsigned char * sid, int sid_len);
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 *);
171 
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
176 
177 #define evhtp_headers_iterator evhtp_kvs_iterator
178 
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
185 
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
191 
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
201 
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
211 
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
232 
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
241 
246  void * cbarg;
249 };
250 
252  char * alias;
253 
255 };
256 
260 struct evhtp_s {
262  evbase_t * evbase;
264  char * server_name;
265  void * arg;
266  int bev_flags;
267  uint64_t max_body_size;
271 #ifndef EVHTP_DISABLE_SSL
272  evhtp_ssl_ctx_t * ssl_ctx;
274 #endif
275 
276 #ifndef EVHTP_DISABLE_EVTHR
277  evthr_pool_t * thr_pool;
278 #endif
279 
280 #ifndef EVHTP_DISABLE_EVTHR
281  pthread_mutex_t * lock;
284 #endif
287 
288  struct timeval recv_timeo;
289  struct timeval send_timeo;
290 
291  TAILQ_HEAD(, evhtp_alias_s) aliases;
292  TAILQ_HEAD(, evhtp_s) vhosts;
293  TAILQ_ENTRY(evhtp_s) next_vhost;
294 };
295 
311  evhtp_callback_type type;
313  unsigned int hash;
314  void * cbarg;
317  union {
318  char * path;
319  char * glob;
320 #ifndef EVHTP_DISABLE_REGEX
321  regex_t * regex;
322 #endif
323  } val;
324 
325  TAILQ_ENTRY(evhtp_callback_s) next;
326 };
327 
328 TAILQ_HEAD(evhtp_callbacks_s, evhtp_callback_s);
329 
333 struct evhtp_kv_s {
334  char * key;
335  char * val;
336 
337  size_t klen;
338  size_t vlen;
339 
340  char k_heaped;
341  char v_heaped;
343  TAILQ_ENTRY(evhtp_kv_s) next;
344 };
345 
346 TAILQ_HEAD(evhtp_kvs_s, evhtp_kv_s);
347 
348 
349 
353 struct evhtp_uri_s {
356  unsigned char * fragment;
357  unsigned char * query_raw;
359  htp_scheme scheme;
360 };
361 
362 
367  char * username;
368  char * password;
369  char * hostname;
370  uint16_t port;
371 };
372 
373 
377 struct evhtp_path_s {
378  char * full;
379  char * path;
380  char * file;
381  char * match_start;
382  char * match_end;
383  unsigned int matched_soff;
386  unsigned int matched_eoff;
389 };
390 
391 
404  evhtp_proto proto;
405  htp_method method;
406  evhtp_res status;
407  int keepalive;
408  int finished;
409  int chunked;
412  void * cbarg;
413  int error;
414 
416 };
417 
418 #define evhtp_request_content_len(r) htparser_get_content_length(r->conn->parser)
419 
422  evbase_t * evbase;
424  evthr_t * thread;
425  evhtp_ssl_t * ssl;
427  htparser * parser;
429  struct sockaddr * saddr;
430  struct timeval recv_timeo;
431  struct timeval send_timeo;
432  evutil_socket_t sock;
433  uint8_t error;
434  uint8_t owner;
435  uint8_t vhost_via_sni;
437  uint64_t max_body_size;
438  uint64_t body_bytes_read;
439  uint64_t num_requests;
440  evhtp_type type;
441  char paused;
443  struct ev_token_bucket_cfg * ratelimit_cfg;
445  TAILQ_HEAD(, evhtp_request_s) pending;
446 };
447 
462 
466  void * on_path_arg;
467  void * on_read_arg;
470  void * on_error_arg;
475  void * on_write_arg;
476 };
477 
479  char * pemfile;
480  char * privfile;
481  char * cafile;
482  char * capath;
483  char * ciphers;
484  char * named_curve;
485  char * dhparams;
486  long ssl_opts;
493  evhtp_ssl_scache_type scache_type;
500  void * args;
501 };
502 
511 evhtp_t * evhtp_new(evbase_t * evbase, void * arg);
512 void evhtp_free(evhtp_t * evhtp);
513 
514 
524 void evhtp_set_timeouts(evhtp_t * htp, const struct timeval * r, const struct timeval * w);
525 void evhtp_set_bev_flags(evhtp_t * htp, int flags);
526 int evhtp_ssl_use_threads(void);
527 int evhtp_ssl_init(evhtp_t * htp, evhtp_ssl_cfg_t * ssl_cfg);
528 
529 
537 
547 
555 void evhtp_set_gencb(evhtp_t * htp, evhtp_callback_cb cb, void * arg);
556 void evhtp_set_pre_accept_cb(evhtp_t * htp, evhtp_pre_accept_cb, void * arg);
557 void evhtp_set_post_accept_cb(evhtp_t * htp, evhtp_post_accept_cb, void * arg);
558 
559 
570 evhtp_callback_t * evhtp_set_cb(evhtp_t * htp, const char * path, evhtp_callback_cb cb, void * arg);
571 
572 
583 #ifndef EVHTP_DISABLE_REGEX
584 evhtp_callback_t * evhtp_set_regex_cb(evhtp_t * htp, const char * pattern, evhtp_callback_cb cb, void * arg);
585 #endif
586 
587 
588 
601 evhtp_callback_t * evhtp_set_glob_cb(evhtp_t * htp, const char * pattern, evhtp_callback_cb cb, void * arg);
602 
642 int evhtp_set_hook(evhtp_hooks_t ** hooks, evhtp_hook_type type, evhtp_hook cb, void * arg);
643 
644 
653 int evhtp_unset_hook(evhtp_hooks_t ** hooks, evhtp_hook_type type);
654 
655 
664 
665 
681 int evhtp_bind_socket(evhtp_t * htp, const char * addr, uint16_t port, int backlog);
682 
683 
689 void evhtp_unbind_socket(evhtp_t * htp);
690 
701 int evhtp_bind_sockaddr(evhtp_t * htp, struct sockaddr *, size_t sin_len, int backlog);
702 
703 int evhtp_use_threads(evhtp_t * htp, evhtp_thread_init_cb init_cb, int nthreads, void * arg);
704 void evhtp_send_reply(evhtp_request_t * request, evhtp_res code);
705 void evhtp_send_reply_start(evhtp_request_t * request, evhtp_res code);
706 void evhtp_send_reply_body(evhtp_request_t * request, evbuf_t * buf);
707 void evhtp_send_reply_end(evhtp_request_t * request);
708 
715 int evhtp_response_needs_body(const evhtp_res code, const htp_method method);
716 
717 
725 void evhtp_send_reply_chunk_start(evhtp_request_t * request, evhtp_res code);
726 
727 
734 void evhtp_send_reply_chunk(evhtp_request_t * request, evbuf_t * buf);
735 
736 
744 
764 evhtp_callback_t * evhtp_callback_new(const char * path, evhtp_callback_type type, evhtp_callback_cb cb, void * arg);
765 void evhtp_callback_free(evhtp_callback_t * callback);
766 
767 
777 
778 
791 int evhtp_add_vhost(evhtp_t * evhtp, const char * name, evhtp_t * vhost);
792 
793 
804 int evhtp_add_alias(evhtp_t * evhtp, const char * name);
805 
816 evhtp_kv_t * evhtp_kv_new(const char * key, const char * val, char kalloc, char valloc);
817 evhtp_kvs_t * evhtp_kvs_new(void);
818 
819 void evhtp_kv_free(evhtp_kv_t * kv);
820 void evhtp_kvs_free(evhtp_kvs_t * kvs);
822 
823 const char * evhtp_kv_find(evhtp_kvs_t * kvs, const char * key);
824 evhtp_kv_t * evhtp_kvs_find_kv(evhtp_kvs_t * kvs, const char * key);
825 
826 
833 void evhtp_kvs_add_kv(evhtp_kvs_t * kvs, evhtp_kv_t * kv);
834 
841 void evhtp_kvs_add_kvs(evhtp_kvs_t * dst, evhtp_kvs_t * src);
842 
843 int evhtp_kvs_for_each(evhtp_kvs_t * kvs, evhtp_kvs_iterator cb, void * arg);
844 
855 evhtp_query_t * evhtp_parse_query(const char * query, size_t len);
856 
857 
867 int evhtp_unescape_string(unsigned char ** out, unsigned char * str, size_t str_len);
868 
879 evhtp_header_t * evhtp_header_new(const char * key, const char * val, char kalloc, char valloc);
880 
891 evhtp_header_t * evhtp_header_key_add(evhtp_headers_t * headers, const char * key, char kalloc);
892 
893 
903 evhtp_header_t * evhtp_header_val_add(evhtp_headers_t * headers, const char * val, char valloc);
904 
905 
913 
922 const char * evhtp_header_find(evhtp_headers_t * headers, const char * key);
923 
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
936 
937 
946 
947 void evhtp_connection_pause(evhtp_connection_t * connection);
949 void evhtp_request_pause(evhtp_request_t * request);
950 void evhtp_request_resume(evhtp_request_t * request);
951 
952 
961 
969 
976 void evhtp_request_set_bev(evhtp_request_t * request, evbev_t * bev);
977 
978 
987 
988 
997 void evhtp_connection_set_timeouts(evhtp_connection_t * conn, const struct timeval * r, const struct timeval * w);
998 
1007 
1008 
1022 
1023 
1030 void evhtp_connection_free(evhtp_connection_t * connection);
1031 
1032 void evhtp_request_free(evhtp_request_t * request);
1033 
1041 void evhtp_set_max_body_size(evhtp_t * htp, uint64_t len);
1042 
1043 
1051 void evhtp_connection_set_max_body_size(evhtp_connection_t * conn, uint64_t len);
1052 
1059 void evhtp_request_set_max_body_size(evhtp_request_t * request, uint64_t len);
1060 
1067 void evhtp_set_max_keepalive_requests(evhtp_t * htp, uint64_t num);
1068 
1069 
1083 int evhtp_connection_set_ratelimit(evhtp_connection_t * c, size_t read_rate,
1084  size_t read_burst, size_t write_rate, size_t write_burst, const struct timeval * tick);
1085 
1086 /*****************************************************************
1087 * client request functions *
1088 *****************************************************************/
1089 
1093 evhtp_connection_t * evhtp_connection_new(evbase_t * evbase, const char * addr, uint16_t port);
1094 
1099 
1103 int evhtp_make_request(evhtp_connection_t * c, evhtp_request_t * r, htp_method meth, const char * uri);
1104 
1105 unsigned int evhtp_request_status(evhtp_request_t *);
1106 
1107 #ifdef __cplusplus
1108 }
1109 #endif
1110 
1111 #endif /* __EVHTP__H__ */
char * key
Definition: evhtp.h:334
evhtp_callbacks_t * callbacks
Definition: evhtp.h:285
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.
Definition: evhtp.c:2832
unsigned int evhtp_request_status(evhtp_request_t *)
Definition: evhtp.c:3774
void evhtp_send_reply_chunk(evhtp_request_t *request, evbuf_t *buf)
send a chunk reply.
Definition: evhtp.c:2676
uint16_t evhtp_res
Definition: evhtp.h:75
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...
Definition: evhtp.c:2599
void * on_new_chunk_arg
Definition: evhtp.h:471
void(* evhtp_ssl_scache_del)(evhtp_t *htp, unsigned char *sid, int sid_len)
Definition: evhtp.h:168
evhtp_res(* evhtp_hook_header_cb)(evhtp_request_t *req, evhtp_header_t *hdr, void *arg)
Definition: evhtp.h:148
evhtp_ssl_scache_init scache_init
Definition: evhtp.h:496
void evhtp_set_post_accept_cb(evhtp_t *htp, evhtp_post_accept_cb, void *arg)
Definition: evhtp.c:3190
evhtp_proto proto
Definition: evhtp.h:404
evhtp_hook_request_fini_cb on_request_fini
Definition: evhtp.h:454
int finished
Definition: evhtp.h:408
evhtp_ssl_sess_t *(* evhtp_ssl_scache_get)(evhtp_connection_t *connection, unsigned char *sid, int sid_len)
Definition: evhtp.h:169
long store_flags
Definition: evhtp.h:492
evhtp_hook_header_cb on_header
Definition: evhtp.h:450
evhtp_ssl_scache_del scache_del
Definition: evhtp.h:499
int evhtp_ssl_init(evhtp_t *htp, evhtp_ssl_cfg_t *ssl_cfg)
Definition: evhtp.c:3223
void * on_connection_fini_arg
Definition: evhtp.h:469
int(* evhtp_ssl_scache_add)(evhtp_connection_t *connection, unsigned char *sid, int sid_len, evhtp_ssl_sess_t *sess)
Definition: evhtp.h:167
evhtp_ssl_chk_issued_cb x509_chk_issued_cb
Definition: evhtp.h:491
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
Definition: evhtp.c:3040
evbase_t * evbase
Definition: evhtp.h:422
evhtp_kvs_t * evhtp_kvs_new(void)
Definition: evhtp.c:2060
void * on_headers_start_arg
Definition: evhtp.h:463
struct evbuffer evbuf_t
Definition: evhtp.h:46
int evhtp_use_callback_locks(evhtp_t *htp)
creates a lock around callbacks and hooks, allowing for threaded applications to add/remove/modify ho...
Definition: evhtp.c:3100
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...
Definition: evhtp.c:3536
void evhtp_free(evhtp_t *evhtp)
Definition: evhtp.c:3632
evbev_t * evhtp_connection_get_bev(evhtp_connection_t *conn)
returns the underlying connections bufferevent
Definition: evhtp.c:3373
evhtp_kv_t * evhtp_kv_new(const char *key, const char *val, char kalloc, char valloc)
Allocates a new key/value structure.
Definition: evhtp.c:2068
char * alias
Definition: evhtp.h:252
int evhtp_callbacks_add_callback(evhtp_callbacks_t *cbs, evhtp_callback_t *cb)
Adds a evhtp_callback_t to the evhtp_callbacks_t list.
Definition: evhtp.c:2901
unsigned char * query_raw
Definition: evhtp.h:357
evhtp_ssl_t * ssl
Definition: evhtp.h:425
void * on_header_arg
Definition: evhtp.h:464
char * privfile
Definition: evhtp.h:480
evhtp_thread_init_cb thread_init_cb
Definition: evhtp.h:282
void evhtp_connection_pause(evhtp_connection_t *connection)
pauses a connection (disables reading)
Definition: evhtp.c:1969
void evhtp_connection_set_bev(evhtp_connection_t *conn, evbev_t *bev)
Sets the connections underlying bufferevent.
Definition: evhtp.c:3410
evhtp_ssl_verify_cb x509_verify_cb
Definition: evhtp.h:490
void * on_read_arg
Definition: evhtp.h:467
char * glob
Definition: evhtp.h:319
evbase_t * evbase
Definition: evhtp.h:262
void * cbarg
Definition: evhtp.h:246
evhtp_hook_write_cb on_write
Definition: evhtp.h:461
char * path
Definition: evhtp.h:318
evhtp_hook_path_cb on_path
Definition: evhtp.h:452
evhtp_ssl_cfg_t * ssl_cfg
Definition: evhtp.h:273
unsigned char * fragment
Definition: evhtp.h:356
void evhtp_send_reply(evhtp_request_t *request, evhtp_res code)
Definition: evhtp.c:2582
int evhtp_use_threads(evhtp_t *htp, evhtp_thread_init_cb init_cb, int nthreads, void *arg)
Definition: evhtp.c:3080
evhtp_defaults_t defaults
Definition: evhtp.h:286
evbuf_t * buffer_out
Definition: evhtp.h:401
regex_t * regex
Definition: evhtp.h:321
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.
Definition: evhtp.c:3445
void * thread_init_cbarg
Definition: evhtp.h:283
evhtp_hook_chunk_new_cb on_new_chunk
Definition: evhtp.h:457
void(* evhtp_callback_cb)(evhtp_request_t *req, void *arg)
Definition: evhtp.h:140
int(* evhtp_ssl_verify_cb)(int pre_verify, evhtp_x509_store_ctx_t *ctx)
Definition: evhtp.h:164
char k_heaped
Definition: evhtp.h:340
uint8_t error
Definition: evhtp.h:433
uint64_t max_body_size
Definition: evhtp.h:267
evbev_t * evhtp_request_get_bev(evhtp_request_t *request)
returns the underlying requests bufferevent
Definition: evhtp.c:3400
void evhtp_send_reply_end(evhtp_request_t *request)
Definition: evhtp.c:2574
main structure containing all configuration information
Definition: evhtp.h:260
evhtp_res(* evhtp_hook)()
Definition: evhtp.h:144
SSL evhtp_ssl_t
Definition: evhtp.h:34
evhtp_callback_cb cb
Definition: evhtp.h:411
char * hostname
Definition: evhtp.h:369
int(* evhtp_ssl_chk_issued_cb)(evhtp_x509_store_ctx_t *ctx, evhtp_x509_t *x, evhtp_x509_t *issuer)
Definition: evhtp.h:165
void evhtp_send_reply_body(evhtp_request_t *request, evbuf_t *buf)
Definition: evhtp.c:2565
void * on_request_fini_arg
Definition: evhtp.h:468
#define evhtp_headers_iterator
Definition: evhtp.h:177
void evhtp_unbind_socket(evhtp_t *htp)
stops the listening socket.
Definition: evhtp.c:2706
uint64_t num_requests
Definition: evhtp.h:439
void * args
Definition: evhtp.h:500
#define evhtp_headers_t
Definition: evhtp.h:84
evhtp_request_t * request
Definition: evhtp.h:436
void * on_error_arg
Definition: evhtp.h:470
evhtp_res(* evhtp_hook_chunks_fini_cb)(evhtp_request_t *r, void *arg)
Definition: evhtp.h:156
void(* evhtp_hook_err_cb)(evhtp_request_t *req, evhtp_error_flags errtype, void *arg)
Definition: evhtp.h:141
void * on_headers_arg
Definition: evhtp.h:465
struct evhtp_callbacks_s evhtp_callbacks_t
Definition: evhtp.h:62
uint64_t body_bytes_read
Definition: evhtp.h:438
htp_method evhtp_request_get_method(evhtp_request_t *r)
returns the htp_method enum version of the request method.
Definition: evhtp.c:1959
char * path
Definition: evhtp.h:379
int evhtp_bind_sockaddr(evhtp_t *htp, struct sockaddr *, size_t sin_len, int backlog)
bind to an already allocated sockaddr.
Definition: evhtp.c:2712
SSL_SESSION evhtp_ssl_sess_t
Definition: evhtp.h:33
evhtp_headers_t * headers_in
Definition: evhtp.h:402
evhtp_callback_cb cb
Definition: evhtp.h:312
evhtp_ssl_scache_type scache_type
Definition: evhtp.h:493
SSL_CTX evhtp_ssl_ctx_t
Definition: evhtp.h:35
char free_connection
Definition: evhtp.h:442
struct ev_token_bucket_cfg * ratelimit_cfg
Definition: evhtp.h:443
evhtp_hook_read_cb on_read
Definition: evhtp.h:453
char * password
Definition: evhtp.h:368
evhtp_res(* evhtp_hook_headers_start_cb)(evhtp_request_t *r, void *arg)
Definition: evhtp.h:157
evutil_socket_t sock
Definition: evhtp.h:432
#define evhtp_header_find
Definition: evhtp.h:924
struct evhtp_kvs_s evhtp_kvs_t
Definition: evhtp.h:66
long scache_timeout
Definition: evhtp.h:494
evhtp_ssl_scache_type
Definition: evhtp.h:87
uint8_t evhtp_error_flags
Definition: evhtp.h:76
void evhtp_kv_free(evhtp_kv_t *kv)
Definition: evhtp.c:2114
X509_STORE_CTX evhtp_x509_store_ctx_t
Definition: evhtp.h:37
evhtp_t * parent
Definition: evhtp.h:261
evhtp_headers_t * headers_out
Definition: evhtp.h:403
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
Definition: evhtp.c:3116
void * pre_accept_cbarg
Definition: evhtp.h:247
uint16_t port
Definition: evhtp.h:370
evhtp_res(* evhtp_hook_chunk_new_cb)(evhtp_request_t *r, uint64_t len, void *arg)
Definition: evhtp.h:154
long ssl_ctx_timeout
Definition: evhtp.h:487
a generic key/value structure
Definition: evhtp.h:333
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 ...
Definition: evhtp.c:3450
a structure containing all information for a http request.
Definition: evhtp.h:395
evhtp_callback_cb cb
Definition: evhtp.h:243
htp_scheme scheme
Definition: evhtp.h:359
const char * evhtp_kv_find(evhtp_kvs_t *kvs, const char *key)
Definition: evhtp.c:2181
void(* evhtp_thread_init_cb)(evhtp_t *htp, evthr_t *thr, void *arg)
Definition: evhtp.h:139
int verify_depth
Definition: evhtp.h:489
evhtp_res(* evhtp_hook_headers_cb)(evhtp_request_t *req, evhtp_headers_t *hdr, void *arg)
Definition: evhtp.h:149
uint64_t max_body_size
Definition: evhtp.h:437
struct sockaddr * saddr
Definition: evhtp.h:429
void evhtp_set_pre_accept_cb(evhtp_t *htp, evhtp_pre_accept_cb, void *arg)
Definition: evhtp.c:3184
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...
Definition: evhtp.c:2754
evhtp_hook_type
types associated with where a developer can hook into during the request processing cycle...
Definition: evhtp.h:98
htparser * parser
Definition: evhtp.h:427
void * on_path_arg
Definition: evhtp.h:466
evhtp_pre_accept_cb pre_accept
Definition: evhtp.h:244
void evhtp_set_bev_flags(evhtp_t *htp, int flags)
set bufferevent flags, defaults to BEV_OPT_CLOSE_ON_FREE
Definition: evhtp.c:3521
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
Definition: evhtp.c:2029
evhtp_hook_headers_cb on_headers
Definition: evhtp.h:451
structure containing a single callback and configuration
Definition: evhtp.h:310
evhtp_res(* evhtp_hook_read_cb)(evhtp_request_t *req, evbuf_t *buf, void *arg)
Definition: evhtp.h:151
TAILQ_ENTRY(evhtp_alias_s) next
evhtp_proto
Definition: evhtp.h:122
void * cbarg
Definition: evhtp.h:314
char * cafile
Definition: evhtp.h:481
int(* evhtp_kvs_iterator)(evhtp_kv_t *kv, void *arg)
Definition: evhtp.h:161
long scache_size
Definition: evhtp.h:495
evhtp_type type
Definition: evhtp.h:440
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...
Definition: evhtp.c:3436
size_t vlen
Definition: evhtp.h:338
int evhtp_unset_hook(evhtp_hooks_t **hooks, evhtp_hook_type type)
remove a specific hook from being called.
Definition: evhtp.c:2976
evhtp_post_accept_cb post_accept
Definition: evhtp.h:245
evthr_t * thread
Definition: evhtp.h:424
evhtp_query_t * query
Definition: evhtp.h:358
void evhtp_callback_free(evhtp_callback_t *callback)
Definition: evhtp.c:2871
evhtp_ssl_ctx_t * ssl_ctx
Definition: evhtp.h:272
uint8_t owner
Definition: evhtp.h:434
evhtp_path_t * path
Definition: evhtp.h:355
void evhtp_kv_rm_and_free(evhtp_kvs_t *kvs, evhtp_kv_t *kv)
Definition: evhtp.c:2131
char * full
Definition: evhtp.h:378
evhtp_callback_type
Definition: evhtp.h:114
void evhtp_send_reply_start(evhtp_request_t *request, evhtp_res code)
Definition: evhtp.c:2549
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
Definition: evhtp.c:3178
evhtp_type
Definition: evhtp.h:128
void evhtp_request_set_bev(evhtp_request_t *request, evbev_t *bev)
sets the underlying bufferevent for a evhtp_request
Definition: evhtp.c:3415
char * dhparams
Definition: evhtp.h:485
a generic container representing an entire URI strucutre
Definition: evhtp.h:353
evhtp_ssl_scache_get scache_get
Definition: evhtp.h:498
struct evconnlistener evserv_t
Definition: evhtp.h:48
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.
Definition: evhtp.c:3526
evhtp_res(* evhtp_hook_chunk_fini_cb)(evhtp_request_t *r, void *arg)
Definition: evhtp.h:155
uint8_t vhost_via_sni
Definition: evhtp.h:435
event_t * resume_ev
Definition: evhtp.h:428
void evhtp_connection_resume(evhtp_connection_t *connection)
resumes a connection (enables reading) and activates resume event.
Definition: evhtp.c:1982
void * on_hostname_arg
Definition: evhtp.h:474
evhtp_hook_chunks_fini_cb on_chunks_fini
Definition: evhtp.h:459
void * post_accept_cbarg
Definition: evhtp.h:248
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}'.
Definition: evhtp.c:2281
void evhtp_request_pause(evhtp_request_t *request)
Wrapper around evhtp_connection_pause.
Definition: evhtp.c:1998
pthread_mutex_t * lock
Definition: evhtp.h:281
evhtp_res(* evhtp_hook_write_cb)(evhtp_connection_t *conn, void *arg)
Definition: evhtp.h:159
pthread_mutex_t evhtp_mutex_t
Definition: evhtp.h:57
void * on_chunks_fini_arg
Definition: evhtp.h:473
evhtp_res(* evhtp_hook_request_fini_cb)(evhtp_request_t *req, void *arg)
Definition: evhtp.h:152
evhtp_connection_t * conn
Definition: evhtp.h:397
TAILQ_HEAD(evhtp_callbacks_s, evhtp_callback_s)
evhtp_res(* evhtp_hook_hostname_cb)(evhtp_request_t *r, const char *hostname, void *arg)
Definition: evhtp.h:158
void evhtp_request_resume(evhtp_request_t *request)
Wrapper around evhtp_connection_resume.
Definition: evhtp.c:2011
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 ...
Definition: evhtp.c:2607
int bev_flags
Definition: evhtp.h:266
void * arg
Definition: evhtp.h:265
struct bufferevent evbev_t
Definition: evhtp.h:49
#define evhtp_header_new
Definition: evhtp.h:927
#define evhtp_query_t
Definition: evhtp.h:85
evhtp_hook_connection_fini_cb on_connection_fini
Definition: evhtp.h:455
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 .
Definition: evhtp.c:2908
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...
char * capath
Definition: evhtp.h:482
void evhtp_kvs_add_kv(evhtp_kvs_t *kvs, evhtp_kv_t *kv)
appends a key/val structure to a evhtp_kvs_t tailq
Definition: evhtp.c:2215
evhtp_res(* evhtp_pre_accept_cb)(evhtp_connection_t *conn, void *arg)
Definition: evhtp.h:146
char * username
Definition: evhtp.h:367
unsigned int hash
Definition: evhtp.h:313
void evhtp_request_free(evhtp_request_t *request)
Definition: evhtp.c:3494
evhtp_t * evhtp_new(evbase_t *evbase, void *arg)
creates a new evhtp_t instance
Definition: evhtp.c:3606
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.
Definition: evhtp.c:2356
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 ...
Definition: evhtp.c:2016
evhtp_hooks_t * hooks
Definition: evhtp.h:426
#define evhtp_header_t
Definition: evhtp.h:83
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...
Definition: evhtp.c:3425
unsigned int matched_soff
Definition: evhtp.h:383
unsigned int matched_eoff
Definition: evhtp.h:386
char * file
Definition: evhtp.h:380
evhtp_hook_err_cb on_error
Definition: evhtp.h:456
evhtp_callback_type type
Definition: evhtp.h:311
struct event event_t
Definition: evhtp.h:47
char * named_curve
Definition: evhtp.h:484
char * match_end
Definition: evhtp.h:382
evhtp_uri_t * uri
Definition: evhtp.h:399
char * server_name
Definition: evhtp.h:264
X509 evhtp_x509_t
Definition: evhtp.h:36
evthr_pool_t * thr_pool
Definition: evhtp.h:277
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...
Definition: evhtp.c:3148
char * val
Definition: evhtp.h:335
evhtp_res(* evhtp_hook_connection_fini_cb)(evhtp_connection_t *connection, void *arg)
Definition: evhtp.h:153
evserv_t * server
Definition: evhtp.h:263
int evhtp_make_request(evhtp_connection_t *c, evhtp_request_t *r, htp_method meth, const char *uri)
make a client request
Definition: evhtp.c:3745
void evhtp_set_max_keepalive_requests(evhtp_t *htp, uint64_t num)
sets a maximum number of requests that a single connection can make.
Definition: evhtp.c:3510
evhtp_t * htp
Definition: evhtp.h:421
int evhtp_ssl_use_threads(void)
Definition: evhtp.c:3198
void evhtp_kvs_add_kvs(evhtp_kvs_t *dst, evhtp_kvs_t *src)
appends all key/val structures from src tailq onto dst tailq
Definition: evhtp.c:2224
uint64_t max_keepalive_requests
Definition: evhtp.h:268
evhtp_res(* evhtp_post_accept_cb)(evhtp_connection_t *conn, void *arg)
Definition: evhtp.h:147
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...
Definition: evhtp.c:2696
evhtp_request_t * evhtp_request_new(evhtp_callback_cb cb, void *arg)
allocate a new request
Definition: evhtp.c:3730
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...
Definition: evhtp.c:3531
evhtp_connection_t * evhtp_request_get_connection(evhtp_request_t *request)
returns the underlying evhtp_connection_t structure from a request
Definition: evhtp.c:3420
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...
Definition: evhtp.c:3378
evhtp_hook_chunk_fini_cb on_chunk_fini
Definition: evhtp.h:458
evbev_t * bev
Definition: evhtp.h:423
evhtp_hooks_t * hooks
Definition: evhtp.h:315
size_t klen
Definition: evhtp.h:337
evhtp_kv_t * evhtp_kvs_find_kv(evhtp_kvs_t *kvs, const char *key)
Definition: evhtp.c:2198
void *(* evhtp_ssl_scache_init)(evhtp_t *)
Definition: evhtp.h:170
htp_method method
Definition: evhtp.h:405
void evhtp_kvs_free(evhtp_kvs_t *kvs)
Definition: evhtp.c:2142
char * pemfile
Definition: evhtp.h:479
evhtp_hook_hostname_cb on_hostname
Definition: evhtp.h:460
evbuf_t * buffer_in
Definition: evhtp.h:400
int evhtp_kvs_for_each(evhtp_kvs_t *kvs, evhtp_kvs_iterator cb, void *arg)
Definition: evhtp.c:2162
evhtp_hooks_t * hooks
Definition: evhtp.h:398
void * cbarg
Definition: evhtp.h:412
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...
Definition: evhtp.c:3571
evhtp_ssl_scache_add scache_add
Definition: evhtp.h:497
char * ciphers
Definition: evhtp.h:483
void * on_write_arg
Definition: evhtp.h:475
int keepalive
Definition: evhtp.h:407
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...
Definition: evhtp.c:3499
evhtp_t * htp
Definition: evhtp.h:396
structure which represents a URI path and or file
Definition: evhtp.h:377
char * match_start
Definition: evhtp.h:381
evhtp_connection_t * evhtp_connection_new(evbase_t *evbase, const char *addr, uint16_t port)
allocate a new connection
Definition: evhtp.c:3699
evhtp_hook_headers_start_cb on_headers_start
Definition: evhtp.h:449
int evhtp_unset_all_hooks(evhtp_hooks_t **hooks)
removes all hooks.
Definition: evhtp.c:2981
#define evhtp_headers_add_header
Definition: evhtp.h:932
int disable_100_cont
Definition: evhtp.h:269
char v_heaped
Definition: evhtp.h:341
int verify_peer
Definition: evhtp.h:488
structure which represents authority information in a URI
Definition: evhtp.h:366
evhtp_res status
Definition: evhtp.h:406
evhtp_res(* evhtp_hook_path_cb)(evhtp_request_t *req, evhtp_path_t *path, void *arg)
Definition: evhtp.h:150
void * on_chunk_fini_arg
Definition: evhtp.h:472
evhtp_authority_t * authority
Definition: evhtp.h:354
long ssl_opts
Definition: evhtp.h:486