Libevhtp  1.2.13
evhtp/evhtp.h
Go to the documentation of this file.
1 
5 #include <evhtp/config.h>
6 
7 #ifndef __EVHTP__H__
8 #define __EVHTP__H__
9 
11 #ifndef EVHTP_DISABLE_EVTHR
12 #include <evhtp/thread.h>
13 #endif
14 
15 #include <evhtp/parser.h>
16 
17 #ifndef EVHTP_DISABLE_REGEX
18 #include <onigposix.h>
19 #endif
20 
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>
26 
27 #ifndef EVHTP_DISABLE_SSL
28 #include <event2/bufferevent_ssl.h>
29 #include <openssl/ssl.h>
30 #include <openssl/err.h>
31 #include <openssl/rand.h>
32 #endif
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 struct evhtp_callback_s;
39 struct evhtp_callbacks_s;
40 
41 #ifndef EVHTP_DISABLE_SSL
42 typedef SSL_SESSION evhtp_ssl_sess_t;
43 typedef SSL evhtp_ssl_t;
44 typedef SSL_CTX evhtp_ssl_ctx_t;
45 typedef X509 evhtp_x509_t;
46 typedef X509_STORE_CTX evhtp_x509_store_ctx_t;
47 #if OPENSSL_VERSION_NUMBER < 0x10100000L
48 typedef unsigned char evhtp_ssl_data_t;
49 #else
50 typedef const unsigned char evhtp_ssl_data_t;
51 #endif
52 #else
53 typedef void evhtp_ssl_sess_t;
54 typedef void evhtp_ssl_t;
55 typedef void evhtp_ssl_ctx_t;
56 typedef void evhtp_x509_t;
57 typedef void evhtp_x509_store_ctx_t;
58 #endif
59 
60 typedef struct evbuffer evbuf_t;
61 typedef struct event event_t;
62 typedef struct evconnlistener evserv_t;
63 typedef struct bufferevent evbev_t;
64 
65 #ifdef EVHTP_DISABLE_EVTHR
66 typedef struct event_base evbase_t;
67 typedef void evthr_t;
68 typedef void evthr_pool_t;
69 typedef void evhtp_mutex_t;
70 #else
71 typedef pthread_mutex_t evhtp_mutex_t;
72 #endif
73 
74 typedef struct evhtp_s evhtp_t;
75 typedef struct evhtp_defaults_s evhtp_defaults_t;
76 typedef struct evhtp_callbacks_s evhtp_callbacks_t;
77 typedef struct evhtp_callback_s evhtp_callback_t;
78 typedef struct evhtp_defaults_s evhtp_defaults_5;
79 typedef struct evhtp_kv_s evhtp_kv_t;
80 typedef struct evhtp_kvs_s evhtp_kvs_t;
81 typedef struct evhtp_uri_s evhtp_uri_t;
82 typedef struct evhtp_path_s evhtp_path_t;
83 typedef struct evhtp_authority_s evhtp_authority_t;
84 typedef struct evhtp_request_s evhtp_request_t;
85 typedef struct evhtp_hooks_s evhtp_hooks_t;
86 typedef struct evhtp_connection_s evhtp_connection_t;
87 typedef struct evhtp_ssl_cfg_s evhtp_ssl_cfg_t;
88 typedef struct evhtp_alias_s evhtp_alias_t;
89 typedef uint16_t evhtp_res;
90 typedef uint8_t evhtp_error_flags;
91 
92 
93 #define evhtp_header_s evhtp_kv_s
94 #define evhtp_headers_s evhtp_kvs_s
95 #define evhtp_query_s evhtp_kvs_s
96 
97 #define evhtp_header_t evhtp_kv_t
98 #define evhtp_headers_t evhtp_kvs_t
99 #define evhtp_query_t evhtp_kvs_t
100 
106 };
107 
128 };
129 
133 #ifndef EVHTP_DISABLE_REGEX
135 #endif
136 };
137 
142 };
143 
147 };
148 
153 typedef enum evhtp_type evhtp_type;
154 
155 typedef void (* evhtp_thread_init_cb)(evhtp_t * htp, evthr_t * thr, void * arg);
156 typedef void (* evhtp_thread_exit_cb)(evhtp_t * htp, evthr_t * thr, void * arg);
157 typedef void (* evhtp_callback_cb)(evhtp_request_t * req, void * arg);
158 typedef void (* evhtp_hook_err_cb)(evhtp_request_t * req, evhtp_error_flags errtype, void * arg);
159 typedef void (* evhtp_hook_event_cb)(evhtp_connection_t * conn, short events, void * arg);
160 
161 /* Generic hook for passing ISO tests */
162 typedef evhtp_res (* evhtp_hook)();
163 
164 typedef evhtp_res (* evhtp_hook_conn_err_cb)(evhtp_connection_t * connection, evhtp_error_flags errtype, void * arg);
165 typedef evhtp_res (* evhtp_pre_accept_cb)(evhtp_connection_t * conn, void * arg);
166 typedef evhtp_res (* evhtp_post_accept_cb)(evhtp_connection_t * conn, void * arg);
167 typedef evhtp_res (* evhtp_hook_header_cb)(evhtp_request_t * req, evhtp_header_t * hdr, void * arg);
168 typedef evhtp_res (* evhtp_hook_headers_cb)(evhtp_request_t * req, evhtp_headers_t * hdr, void * arg);
169 typedef evhtp_res (* evhtp_hook_path_cb)(evhtp_request_t * req, evhtp_path_t * path, void * arg);
170 typedef evhtp_res (* evhtp_hook_read_cb)(evhtp_request_t * req, struct evbuffer * buf, void * arg);
171 typedef evhtp_res (* evhtp_hook_request_fini_cb)(evhtp_request_t * req, void * arg);
172 typedef evhtp_res (* evhtp_hook_connection_fini_cb)(evhtp_connection_t * connection, void * arg);
173 typedef evhtp_res (* evhtp_hook_chunk_new_cb)(evhtp_request_t * r, uint64_t len, void * arg);
174 typedef evhtp_res (* evhtp_hook_chunk_fini_cb)(evhtp_request_t * r, void * arg);
175 typedef evhtp_res (* evhtp_hook_chunks_fini_cb)(evhtp_request_t * r, void * arg);
176 typedef evhtp_res (* evhtp_hook_headers_start_cb)(evhtp_request_t * r, void * arg);
177 typedef evhtp_res (* evhtp_hook_hostname_cb)(evhtp_request_t * r, const char * hostname, void * arg);
178 typedef evhtp_res (* evhtp_hook_write_cb)(evhtp_connection_t * conn, void * arg);
179 
180 typedef int (* evhtp_kvs_iterator)(evhtp_kv_t * kv, void * arg);
181 typedef int (* evhtp_headers_iterator)(evhtp_header_t * header, void * arg);
182 
183 #ifndef EVHTP_DISABLE_SSL
184 typedef int (* evhtp_ssl_verify_cb)(int pre_verify, evhtp_x509_store_ctx_t * ctx);
185 typedef int (* evhtp_ssl_chk_issued_cb)(evhtp_x509_store_ctx_t * ctx, evhtp_x509_t * x, evhtp_x509_t * issuer);
186 typedef EVP_PKEY * (* evhtp_ssl_decrypt_cb)(char * privfile);
187 
188 typedef int (* evhtp_ssl_scache_add)(evhtp_connection_t * connection, evhtp_ssl_data_t * sid, int sid_len, evhtp_ssl_sess_t * sess);
189 typedef void (* evhtp_ssl_scache_del)(evhtp_t * htp, evhtp_ssl_data_t * sid, int sid_len);
190 typedef evhtp_ssl_sess_t * (* evhtp_ssl_scache_get)(evhtp_connection_t * connection, evhtp_ssl_data_t * sid, int sid_len);
191 
192 typedef void * (* evhtp_ssl_scache_init)(evhtp_t *);
193 #endif
194 
195 #define EVHTP_VERSION "1.2.15"
196 #define EVHTP_VERSION_MAJOR 1
197 #define EVHTP_VERSION_MINOR 2
198 #define EVHTP_VERSION_PATCH 15
199 
200 #define evhtp_headers_iterator evhtp_kvs_iterator
201 
202 #define EVHTP_RES_ERROR 0
203 #define EVHTP_RES_PAUSE 1
204 #define EVHTP_RES_FATAL 2
205 #define EVHTP_RES_USER 3
206 #define EVHTP_RES_DATA_TOO_LONG 4
207 #define EVHTP_RES_OK 200
208 
209 #ifndef DOXYGEN_SHOULD_SKIP_THIS
210 #define EVHTP_RES_100 100
211 #define EVHTP_RES_CONTINUE 100
212 #define EVHTP_RES_SWITCH_PROTO 101
213 #define EVHTP_RES_PROCESSING 102
214 #define EVHTP_RES_URI_TOOLONG 122
215 
216 #define EVHTP_RES_200 200
217 #define EVHTP_RES_CREATED 201
218 #define EVHTP_RES_ACCEPTED 202
219 #define EVHTP_RES_NAUTHINFO 203
220 #define EVHTP_RES_NOCONTENT 204
221 #define EVHTP_RES_RSTCONTENT 205
222 #define EVHTP_RES_PARTIAL 206
223 #define EVHTP_RES_MSTATUS 207
224 #define EVHTP_RES_IMUSED 226
225 
226 #define EVHTP_RES_300 300
227 #define EVHTP_RES_MCHOICE 300
228 #define EVHTP_RES_MOVEDPERM 301
229 #define EVHTP_RES_FOUND 302
230 #define EVHTP_RES_SEEOTHER 303
231 #define EVHTP_RES_NOTMOD 304
232 #define EVHTP_RES_USEPROXY 305
233 #define EVHTP_RES_SWITCHPROXY 306
234 #define EVHTP_RES_TMPREDIR 307
235 
236 #define EVHTP_RES_400 400
237 #define EVHTP_RES_BADREQ 400
238 #define EVHTP_RES_UNAUTH 401
239 #define EVHTP_RES_PAYREQ 402
240 #define EVHTP_RES_FORBIDDEN 403
241 #define EVHTP_RES_NOTFOUND 404
242 #define EVHTP_RES_METHNALLOWED 405
243 #define EVHTP_RES_NACCEPTABLE 406
244 #define EVHTP_RES_PROXYAUTHREQ 407
245 #define EVHTP_RES_TIMEOUT 408
246 #define EVHTP_RES_CONFLICT 409
247 #define EVHTP_RES_GONE 410
248 #define EVHTP_RES_LENREQ 411
249 #define EVHTP_RES_PRECONDFAIL 412
250 #define EVHTP_RES_ENTOOLARGE 413
251 #define EVHTP_RES_URITOOLARGE 414
252 #define EVHTP_RES_UNSUPPORTED 415
253 #define EVHTP_RES_RANGENOTSC 416
254 #define EVHTP_RES_EXPECTFAIL 417
255 #define EVHTP_RES_IAMATEAPOT 418
256 
257 #define EVHTP_RES_500 500
258 #define EVHTP_RES_SERVERR 500
259 #define EVHTP_RES_NOTIMPL 501
260 #define EVHTP_RES_BADGATEWAY 502
261 #define EVHTP_RES_SERVUNAVAIL 503
262 #define EVHTP_RES_GWTIMEOUT 504
263 #define EVHTP_RES_VERNSUPPORT 505
264 #define EVHTP_RES_BWEXEED 509
265 #endif
266 
271  void * cbarg;
274 };
275 
277  char * alias;
278 
279  TAILQ_ENTRY(evhtp_alias_s) next;
280 };
281 
286 struct evhtp_s {
287  evhtp_t * parent;
288  struct event_base * evbase;
289  struct evconnlistener * server;
290  char * server_name;
291  void * arg;
292  int bev_flags;
293  uint64_t max_body_size;
295 
296  #define EVHTP_FLAG_ENABLE_100_CONT (1 << 1)
297  #define EVHTP_FLAG_ENABLE_REUSEPORT (1 << 2)
298  #define EVHTP_FLAG_ENABLE_NODELAY (1 << 3)
299  #define EVHTP_FLAG_ENABLE_DEFER_ACCEPT (1 << 4)
300  #define EVHTP_FLAG_DEFAULTS EVHTP_FLAG_ENABLE_100_CONT
301  uint16_t flags;
302  uint16_t parser_flags;
304 #ifndef EVHTP_DISABLE_SSL
305  evhtp_ssl_ctx_t * ssl_ctx;
306  evhtp_ssl_cfg_t * ssl_cfg;
307 #endif
308 
309 #ifndef EVHTP_DISABLE_EVTHR
310  evthr_pool_t * thr_pool;
311  pthread_mutex_t * lock;
315 
316  /* keep backwards compat because I'm dumb and didn't
317  * make these structs private
318  */
319  #define thread_init_cbarg thread_cbarg
320  void * thread_cbarg;
321 #endif
323  evhtp_defaults_t defaults;
324 
325  struct timeval recv_timeo;
326  struct timeval send_timeo;
327 
328  TAILQ_HEAD(, evhtp_alias_s) aliases;
329  TAILQ_HEAD(, evhtp_s) vhosts;
330  TAILQ_ENTRY(evhtp_s) next_vhost;
331 };
332 
333 
337 struct evhtp_kv_s {
338  char * key;
339  char * val;
340 
341  size_t klen;
342  size_t vlen;
343 
344  char k_heaped;
345  char v_heaped;
347  TAILQ_ENTRY(evhtp_kv_s) next;
348 };
349 
350 TAILQ_HEAD(evhtp_kvs_s, evhtp_kv_s);
351 
352 
353 
357 struct evhtp_uri_s {
358  evhtp_authority_t * authority;
359  evhtp_path_t * path;
360  unsigned char * fragment;
361  unsigned char * query_raw;
363  htp_scheme scheme;
364 };
365 
366 
371  char * username;
372  char * password;
373  char * hostname;
374  uint16_t port;
375 };
376 
377 
381 struct evhtp_path_s {
382  char * full;
383  char * path;
384  char * file;
385  char * match_start;
386  char * match_end;
387  unsigned int matched_soff;
390  unsigned int matched_eoff;
393 };
394 
395 
400  evhtp_t * htp;
401  evhtp_connection_t * conn;
402  evhtp_hooks_t * hooks;
403  evhtp_uri_t * uri;
404  struct evbuffer * buffer_in;
405  struct evbuffer * buffer_out;
408  evhtp_proto proto;
409  htp_method method;
410  evhtp_res status;
411  #define EVHTP_REQ_FLAG_KEEPALIVE (1 << 1)
412  #define EVHTP_REQ_FLAG_FINISHED (1 << 2)
413  #define EVHTP_REQ_FLAG_CHUNKED (1 << 3)
414  #define EVHTP_REQ_FLAG_ERROR (1 << 4)
415  uint16_t flags;
416 
418  void * cbarg;
420  TAILQ_ENTRY(evhtp_request_s) next;
421 };
422 
423 #define evhtp_request_content_len(r) htparser_get_content_length(r->conn->parser)
424 
426  evhtp_t * htp;
427  struct event_base * evbase;
428  struct bufferevent * bev;
429 #ifndef EVHTP_DISABLE_EVTHR
430  evthr_t * thread;
431 #endif
432 #ifndef EVHTP_DISABLE_SSL
433  evhtp_ssl_t * ssl;
434 #endif
435  evhtp_hooks_t * hooks;
437  struct event * resume_ev;
438  struct sockaddr * saddr;
439  struct timeval recv_timeo;
440  struct timeval send_timeo;
441  evutil_socket_t sock;
442  evhtp_request_t * request;
443  uint64_t max_body_size;
444  uint64_t body_bytes_read;
445  uint64_t num_requests;
446  evhtp_type type;
447  #define EVHTP_CONN_FLAG_ERROR (1 << 1)
448  #define EVHTP_CONN_FLAG_OWNER (1 << 2)
449  #define EVHTP_CONN_FLAG_VHOST_VIA_SNI (1 << 3)
450  #define EVHTP_CONN_FLAG_PAUSED (1 << 4)
451  #define EVHTP_CONN_FLAG_CONNECTED (1 << 5)
452  #define EVHTP_CONN_FLAG_WAITING (1 << 6)
453  #define EVHTP_CONN_FLAG_FREE_CONN (1 << 7)
454  #define EVHTP_CONN_FLAG_KEEPALIVE (1 << 8)
455  uint16_t flags;
456 
457  struct evbuffer * scratch_buf;
459 #ifdef EVHTP_FUTURE_USE
460  TAILQ_HEAD(, evhtp_request_s) pending;
461 #endif
462 };
463 
480 
484  void * on_path_arg;
485  void * on_read_arg;
489  void * on_error_arg;
494  void * on_write_arg;
495  void * on_event_arg;
496 };
497 
498 #ifndef EVHTP_DISABLE_SSL
500  char * pemfile;
501  char * privfile;
502  char * cafile;
503  char * capath;
504  char * ciphers;
505  char * named_curve;
506  char * dhparams;
507  long ssl_opts;
515  evhtp_ssl_scache_type scache_type;
522  void * args;
523 };
524 #endif
525 
526 
527 EVHTP_EXPORT void evhtp_set_mem_functions(void *(*malloc_)(size_t),
528  void *(*realloc_)(void *, size_t),
529  void (* free_)(void *));
530 
544 EVHTP_EXPORT evhtp_t * evhtp_new(struct event_base * evbase, void * arg);
545 
546 EVHTP_EXPORT void evhtp_enable_flag(evhtp_t *, int);
547 EVHTP_EXPORT void evhtp_connection_enable_flag(evhtp_connection_t *, int);
548 EVHTP_EXPORT void evhtp_request_enable_flag(evhtp_request_t *, int);
549 EVHTP_EXPORT int evhtp_get_flags(evhtp_t *);
550 EVHTP_EXPORT int evhtp_connection_get_flags(evhtp_connection_t *);
551 EVHTP_EXPORT int evhtp_request_get_flags(evhtp_request_t *);
552 EVHTP_EXPORT void evhtp_disable_flag(evhtp_t *, int);
553 EVHTP_EXPORT void evhtp_connection_disable_flag(evhtp_connection_t *, int);
554 EVHTP_EXPORT void evhtp_request_disable_flag(evhtp_request_t *, int);
555 
563 EVHTP_EXPORT void evhtp_free(evhtp_t * evhtp);
564 
576 EVHTP_EXPORT void evhtp_set_timeouts(evhtp_t * htp, const struct timeval * r, const struct timeval * w);
577 
578 
579 
593 EVHTP_EXPORT void evhtp_set_parser_flags(evhtp_t * htp, int flags);
594 
601 EVHTP_EXPORT void evhtp_set_bev_flags(evhtp_t * htp, int flags);
602 
603 #ifndef EVHTP_DISABLE_SSL
604 EVHTP_EXPORT int evhtp_ssl_use_threads(void);
605 EVHTP_EXPORT int evhtp_ssl_init(evhtp_t * htp, evhtp_ssl_cfg_t * ssl_cfg);
606 #endif
607 
608 
615 EVHTP_EXPORT void evhtp_disable_100_continue(evhtp_t * htp)
616 DEPRECATED("evhtp_disable_100 will soon be deprecated, use htp->flags instead");
617 
626 EVHTP_EXPORT int evhtp_use_callback_locks(evhtp_t * htp);
627 
635 EVHTP_EXPORT void evhtp_set_gencb(evhtp_t * htp, evhtp_callback_cb cb, void * arg);
636 
637 
647 EVHTP_EXPORT void evhtp_set_pre_accept_cb(evhtp_t * htp, evhtp_pre_accept_cb, void * arg);
648 
649 
659 EVHTP_EXPORT void evhtp_set_post_accept_cb(evhtp_t * htp, evhtp_post_accept_cb, void * arg);
660 
671 EVHTP_EXPORT evhtp_callback_t * evhtp_set_cb(evhtp_t * htp, const char * path,
672  evhtp_callback_cb cb, void * arg);
673 
674 
685 #ifndef EVHTP_DISABLE_REGEX
686 EVHTP_EXPORT evhtp_callback_t * evhtp_set_regex_cb(evhtp_t * htp, const char * pattern,
687  evhtp_callback_cb cb, void * arg);
688 #endif
689 
690 
691 
704 EVHTP_EXPORT evhtp_callback_t * evhtp_set_glob_cb(evhtp_t * htp, const char * pattern,
705  evhtp_callback_cb cb, void * arg);
706 
707 
733 EVHTP_EXPORT evhtp_callback_t * evhtp_get_cb(evhtp_t * htp, const char * needle);
734 
774 EVHTP_EXPORT int evhtp_connection_set_hook(evhtp_connection_t * c, evhtp_hook_type type, evhtp_hook cb, void * arg);
775 EVHTP_EXPORT int evhtp_request_set_hook(evhtp_request_t * r, evhtp_hook_type type, evhtp_hook cb, void * arg);
776 EVHTP_EXPORT int evhtp_callback_set_hook(evhtp_callback_t * cb, evhtp_hook_type type, evhtp_hook hookcb, void * arg);
777 
785 EVHTP_EXPORT int evhtp_unset_all_hooks(evhtp_hooks_t ** hooks);
786 
802 EVHTP_EXPORT int evhtp_bind_socket(evhtp_t * htp, const char * addr, uint16_t port, int backlog);
803 
804 
810 EVHTP_EXPORT void evhtp_unbind_socket(evhtp_t * htp);
811 
812 
826 EVHTP_EXPORT int evhtp_accept_socket(evhtp_t * htp, evutil_socket_t sock, int backlog);
827 
839 EVHTP_EXPORT int evhtp_bind_sockaddr(evhtp_t * htp, struct sockaddr *,
840  size_t sin_len, int backlog);
841 
842 
857 EVHTP_EXPORT int evhtp_use_threads(evhtp_t *, evhtp_thread_init_cb, int nthreads, void *)
858 DEPRECATED("will take on the syntax of evhtp_use_threads_wexit");
859 
864 EVHTP_EXPORT int evhtp_use_threads_wexit(evhtp_t *,
867  int nthreads, void * arg);
868 
875 EVHTP_EXPORT void evhtp_send_reply(evhtp_request_t * request, evhtp_res code);
876 
877 
878 /* The following three functions allow for the user to do what evhtp_send_reply does at its core
879  * but for the weak of heart.
880  */
881 EVHTP_EXPORT void evhtp_send_reply_start(evhtp_request_t * request, evhtp_res code);
882 EVHTP_EXPORT void evhtp_send_reply_body(evhtp_request_t * request, struct evbuffer * buf);
883 EVHTP_EXPORT void evhtp_send_reply_end(evhtp_request_t * request);
884 
891 EVHTP_EXPORT int evhtp_response_needs_body(const evhtp_res code, const htp_method method);
892 
900 EVHTP_EXPORT void evhtp_send_reply_chunk_start(evhtp_request_t * request, evhtp_res code);
901 
902 
909 EVHTP_EXPORT void evhtp_send_reply_chunk(evhtp_request_t * request, struct evbuffer * buf);
910 
917 EVHTP_EXPORT void evhtp_send_reply_chunk_end(evhtp_request_t * request);
918 
938 EVHTP_EXPORT evhtp_callback_t *
939 evhtp_callback_new(const char * path, evhtp_callback_type type, evhtp_callback_cb cb, void * arg);
940 
950 EVHTP_EXPORT void evhtp_callback_free(evhtp_callback_t * callback);
951 
952 
961 EVHTP_EXPORT int evhtp_callbacks_add_callback(evhtp_callbacks_t * cbs, evhtp_callback_t * cb);
962 
963 
976 EVHTP_EXPORT int evhtp_add_vhost(evhtp_t * evhtp, const char * name, evhtp_t * vhost);
977 
978 
989 EVHTP_EXPORT int evhtp_add_alias(evhtp_t * evhtp, const char * name);
990 
991 
1003 EVHTP_EXPORT int evhtp_add_aliases(evhtp_t * evhtp, const char * name, ...);
1004 
1015 EVHTP_EXPORT evhtp_kv_t * evhtp_kv_new(const char * key, const char * val, char kalloc, char valloc);
1016 
1017 
1023 EVHTP_EXPORT evhtp_kvs_t * evhtp_kvs_new(void);
1024 
1025 
1031 EVHTP_EXPORT void evhtp_kv_free(evhtp_kv_t * kv);
1032 
1033 
1039 EVHTP_EXPORT void evhtp_kvs_free(evhtp_kvs_t * kvs);
1040 
1047 EVHTP_EXPORT void evhtp_kv_rm_and_free(evhtp_kvs_t * kvs, evhtp_kv_t * kv);
1048 
1057 EVHTP_EXPORT const char * evhtp_kv_find(evhtp_kvs_t * kvs, const char * key);
1058 
1059 
1068 EVHTP_EXPORT evhtp_kv_t * evhtp_kvs_find_kv(evhtp_kvs_t * kvs, const char * key);
1069 
1070 
1077 EVHTP_EXPORT void evhtp_kvs_add_kv(evhtp_kvs_t * kvs, evhtp_kv_t * kv);
1078 
1085 EVHTP_EXPORT void evhtp_kvs_add_kvs(evhtp_kvs_t * dst, evhtp_kvs_t * src);
1086 
1087 
1097 EVHTP_EXPORT int evhtp_kvs_for_each(evhtp_kvs_t * kvs, evhtp_kvs_iterator cb, void * arg);
1098 
1099 #define EVHTP_PARSE_QUERY_FLAG_STRICT 0
1100 #define EVHTP_PARSE_QUERY_FLAG_IGNORE_HEX (1 << 0)
1101 #define EVHTP_PARSE_QUERY_FLAG_ALLOW_EMPTY_VALS (1 << 1)
1102 #define EVHTP_PARSE_QUERY_FLAG_ALLOW_NULL_VALS (1 << 2)
1103 #define EVHTP_PARSE_QUERY_FLAG_TREAT_SEMICOLON_AS_SEP (1 << 3)
1104 #define EVHTP_PARSE_QUERY_FLAG_IGNORE_FRAGMENTS (1 << 4)
1105 #define EVHTP_PARSE_QUERY_FLAG_LENIENT \
1106  EVHTP_PARSE_QUERY_FLAG_IGNORE_HEX \
1107  | EVHTP_PARSE_QUERY_FLAG_ALLOW_EMPTY_VALS \
1108  | EVHTP_PARSE_QUERY_FLAG_ALLOW_NULL_VALS \
1109  | EVHTP_PARSE_QUERY_FLAG_TREAT_SEMICOLON_AS_SEP
1110 
1111 #define EVHTP_PARSE_QUERY_FLAG_DEFAULT EVHTP_PARSE_QUERY_FLAG_LENIENT
1112 
1124 EVHTP_EXPORT evhtp_query_t * evhtp_parse_query_wflags(const char * query, size_t len, int flags);
1125 
1137 EVHTP_EXPORT evhtp_query_t * evhtp_parse_query(const char * query, size_t len);
1138 
1148 EVHTP_EXPORT int evhtp_unescape_string(unsigned char ** out, unsigned char * str, size_t str_len);
1149 
1160 EVHTP_EXPORT evhtp_header_t * evhtp_header_new(const char * key, const char * val,
1161  char kalloc, char valloc);
1162 
1173 EVHTP_EXPORT evhtp_header_t * evhtp_header_key_add(evhtp_headers_t * headers,
1174  const char * key, char kalloc);
1175 
1176 
1186 EVHTP_EXPORT evhtp_header_t * evhtp_header_val_add(evhtp_headers_t * headers,
1187  const char * val, char valloc);
1188 
1189 
1196 EVHTP_EXPORT void evhtp_headers_add_header(evhtp_headers_t * headers, evhtp_header_t * header);
1197 
1206 EVHTP_EXPORT const char * evhtp_header_find(evhtp_headers_t * headers, const char * key);
1207 
1208 #define evhtp_header_find evhtp_kv_find
1209 #define evhtp_headers_find_header evhtp_kvs_find_kv
1210 #define evhtp_headers_for_each evhtp_kvs_for_each
1211 #define evhtp_header_new evhtp_kv_new
1212 #define evhtp_header_free evhtp_kv_free
1213 #define evhtp_headers_new evhtp_kvs_new
1214 #define evhtp_headers_free evhtp_kvs_free
1215 #define evhtp_header_rm_and_free evhtp_kv_rm_and_free
1216 #define evhtp_headers_add_header evhtp_kvs_add_kv
1217 #define evhtp_headers_add_headers evhtp_kvs_add_kvs
1218 #define evhtp_query_new evhtp_kvs_new
1219 #define evhtp_query_free evhtp_kvs_free
1220 
1221 
1229 EVHTP_EXPORT htp_method evhtp_request_get_method(evhtp_request_t * r);
1230 EVHTP_EXPORT evhtp_proto evhtp_request_get_proto(evhtp_request_t * r);
1231 
1232 /* the following functions all do the same thing, pause and the processing */
1233 
1239 EVHTP_EXPORT void evhtp_connection_pause(evhtp_connection_t * connection);
1240 
1246 EVHTP_EXPORT void evhtp_connection_resume(evhtp_connection_t * connection);
1247 
1255 EVHTP_EXPORT void evhtp_request_pause(evhtp_request_t * request);
1256 
1264 EVHTP_EXPORT void evhtp_request_resume(evhtp_request_t * request);
1265 
1266 
1274 EVHTP_EXPORT evhtp_connection_t * evhtp_request_get_connection(evhtp_request_t * request);
1275 
1282 EVHTP_EXPORT void evhtp_connection_set_bev(evhtp_connection_t * conn, struct bufferevent * bev);
1283 
1290 EVHTP_EXPORT void evhtp_request_set_bev(evhtp_request_t * request, struct bufferevent * bev);
1291 
1292 
1300 EVHTP_EXPORT struct bufferevent * evhtp_connection_get_bev(evhtp_connection_t * conn);
1301 
1310 EVHTP_EXPORT void
1311 evhtp_connection_set_timeouts(evhtp_connection_t * conn,
1312  const struct timeval * r,
1313  const struct timeval * w);
1314 
1322 EVHTP_EXPORT struct bufferevent * evhtp_request_get_bev(evhtp_request_t * request);
1323 
1324 
1337 EVHTP_EXPORT struct bufferevent * evhtp_connection_take_ownership(evhtp_connection_t * connection);
1338 
1339 
1346 EVHTP_EXPORT void evhtp_connection_free(evhtp_connection_t * connection);
1347 EVHTP_EXPORT void evhtp_request_free(evhtp_request_t * request);
1348 
1356 EVHTP_EXPORT void evhtp_set_max_body_size(evhtp_t * htp, uint64_t len);
1357 
1365 EVHTP_EXPORT void evhtp_connection_set_max_body_size(evhtp_connection_t * conn, uint64_t len);
1366 
1373 EVHTP_EXPORT void evhtp_request_set_max_body_size(evhtp_request_t * request, uint64_t len);
1374 EVHTP_EXPORT void evhtp_request_set_keepalive(evhtp_request_t * request, int val);
1375 
1382 EVHTP_EXPORT void evhtp_set_max_keepalive_requests(evhtp_t * htp, uint64_t num);
1383 
1384 
1385 /*****************************************************************
1386 * client request functions *
1387 *****************************************************************/
1388 
1392 EVHTP_EXPORT evhtp_connection_t * evhtp_connection_new_dns(
1393  struct event_base * evbase,
1394  struct evdns_base * dns_base,
1395  const char * addr, uint16_t port);
1396 
1400 EVHTP_EXPORT evhtp_connection_t *
1401 evhtp_connection_new(struct event_base * evbase, const char * addr, uint16_t port);
1402 
1403 #ifndef EVHTP_DISABLE_SSL
1404 EVHTP_EXPORT evhtp_connection_t * evhtp_connection_ssl_new(
1405  struct event_base * evbase,
1406  const char * addr, uint16_t port, evhtp_ssl_ctx_t * ctx);
1407 #endif
1408 
1409 
1413 EVHTP_EXPORT evhtp_request_t * evhtp_request_new(evhtp_callback_cb cb, void * arg);
1414 
1418 EVHTP_EXPORT int evhtp_make_request(evhtp_connection_t * c,
1419  evhtp_request_t * r, htp_method meth, const char * uri);
1420 
1421 EVHTP_EXPORT unsigned int evhtp_request_status(evhtp_request_t *);
1422 
1423 #ifdef __cplusplus
1424 }
1425 #endif
1426 
1427 #endif /* __EVHTP__H__ */
EVHTP_EXPORT void evhtp_connection_set_bev(evhtp_connection_t *conn, struct bufferevent *bev)
Sets the connections underlying bufferevent.
Definition: evhtp.c:4976
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 ...
Definition: evhtp.c:3081
void(* evhtp_thread_init_cb)(evhtp_t *htp, evthr_t *thr, void *arg)
Definition: evhtp/evhtp.h:155
void * post_accept_cbarg
Definition: evhtp/evhtp.h:273
evhtp_res(* evhtp_hook_write_cb)(evhtp_connection_t *conn, void *arg)
Definition: evhtp/evhtp.h:178
EVHTP_EXPORT evhtp_proto evhtp_request_get_proto(evhtp_request_t *r)
Definition: evhtp.c:5003
evhtp_hook_chunk_new_cb on_new_chunk
Definition: evhtp/evhtp.h:474
uint16_t parser_flags
default query flags to alter &#39;strictness&#39; (see EVHTP_PARSE_QUERY_FLAG_*)
Definition: evhtp/evhtp.h:302
evhtp_query_t * query
list of k/v for query arguments
Definition: evhtp/evhtp.h:362
EVHTP_EXPORT unsigned int evhtp_request_status(evhtp_request_t *)
Definition: evhtp.c:5564
EVHTP_EXPORT void evhtp_kv_free(evhtp_kv_t *kv)
frees resources allocated for a single key/value
Definition: evhtp.c:3206
evhtp_type
Definition: evhtp/evhtp.h:144
void * cbarg
argument which is passed to the cb function
Definition: evhtp/evhtp.h:418
size_t klen
Definition: evhtp/evhtp.h:341
type which defines to hook whenever an error occurs
Definition: evhtp/evhtp.h:123
evhtp_uri_t * uri
request URI information
Definition: evhtp/evhtp.h:403
void * pre_accept_cbarg
Definition: evhtp/evhtp.h:272
evhtp_res(* evhtp_hook_hostname_cb)(evhtp_request_t *r, const char *hostname, void *arg)
Definition: evhtp/evhtp.h:177
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.
Definition: evhtp.c:5112
uint64_t max_body_size
Definition: evhtp/evhtp.h:293
unsigned char evhtp_ssl_data_t
Definition: evhtp/evhtp.h:48
htparser * parser
Definition: evhtp/evhtp.h:436
evhtp_hook_hostname_cb on_hostname
Definition: evhtp/evhtp.h:477
EVHTP_EXPORT void evhtp_connection_enable_flag(evhtp_connection_t *, int)
#define evhtp_header_t
Definition: evhtp/evhtp.h:97
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
Definition: evhtp.c:4625
evhtp_ssl_decrypt_cb decrypt_cb
Definition: evhtp/evhtp.h:513
evhtp_type type
server or client
Definition: evhtp/evhtp.h:446
struct evhtp_callbacks_s evhtp_callbacks_t
Definition: evhtp/evhtp.h:76
evhtp_path_t * path
Definition: evhtp/evhtp.h:359
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 .
Definition: evhtp.c:4387
struct evconnlistener evserv_t
Definition: evhtp/evhtp.h:62
unsigned char * query_raw
the unparsed query arguments
Definition: evhtp/evhtp.h:361
void * on_headers_start_arg
Definition: evhtp/evhtp.h:481
EVHTP_EXPORT int evhtp_request_set_hook(evhtp_request_t *r, evhtp_hook_type type, evhtp_hook cb, void *arg)
Definition: evhtp.c:4381
evhtp_connection_t * conn
the associated connection
Definition: evhtp/evhtp.h:401
EVHTP_EXPORT evhtp_request_t * evhtp_request_new(evhtp_callback_cb cb, void *arg)
allocate a new request
Definition: evhtp.c:5514
SSL evhtp_ssl_t
Definition: evhtp/evhtp.h:43
EVHTP_EXPORT void evhtp_disable_flag(evhtp_t *, int)
char * hostname
hostname if present in URI
Definition: evhtp/evhtp.h:373
EVHTP_EXPORT htp_method evhtp_request_get_method(evhtp_request_t *r)
returns the htp_method enum version of the request method.
Definition: evhtp.c:3030
EVHTP_EXPORT int evhtp_bind_sockaddr(evhtp_t *htp, struct sockaddr *, size_t sin_len, int backlog)
bind to an already allocated sockaddr.
Definition: evhtp.c:4033
evhtp_ssl_scache_add scache_add
Definition: evhtp/evhtp.h:519
htp_method method
HTTP method used.
Definition: evhtp/evhtp.h:409
EVHTP_EXPORT evhtp_kv_t * evhtp_kvs_find_kv(evhtp_kvs_t *kvs, const char *key)
find the evhtp_kv_t reference &#39;key&#39; from the k/val list &#39;kvs&#39;
Definition: evhtp.c:3308
evhtp_hook_read_cb on_read
Definition: evhtp/evhtp.h:469
EVHTP_EXPORT int evhtp_request_get_flags(evhtp_request_t *)
EVHTP_EXPORT void use htp flags instead
Definition: evhtp/evhtp.h:616
EVHTP_EXPORT void evhtp_request_free(evhtp_request_t *request)
Definition: evhtp.c:5080
EVHTP_EXPORT void evhtp_request_set_keepalive(evhtp_request_t *request, int val)
Definition: evhtp.c:4988
evhtp_post_accept_cb post_accept
Definition: evhtp/evhtp.h:270
evhtp_ssl_scache_del scache_del
Definition: evhtp/evhtp.h:521
type which defines to hook once a path has been parsed
Definition: evhtp/evhtp.h:115
void(* evhtp_ssl_scache_del)(evhtp_t *htp, evhtp_ssl_data_t *sid, int sid_len)
Definition: evhtp/evhtp.h:189
EVHTP_EXPORT void evhtp_send_reply_end(evhtp_request_t *request)
Definition: evhtp.c:3784
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.
Definition: evhtp.c:4187
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...
Definition: evhtp.c:4606
void * on_connection_fini_arg
Definition: evhtp/evhtp.h:487
int(* evhtp_ssl_scache_add)(evhtp_connection_t *connection, evhtp_ssl_data_t *sid, int sid_len, evhtp_ssl_sess_t *sess)
Definition: evhtp/evhtp.h:188
char * key
Definition: evhtp/evhtp.h:338
X509 evhtp_x509_t
Definition: evhtp/evhtp.h:45
EVHTP_EXPORT int evhtp_callback_set_hook(evhtp_callback_t *cb, evhtp_hook_type type, evhtp_hook hookcb, void *arg)
Definition: evhtp.c:4375
char * file
the filename if present (c.html)
Definition: evhtp/evhtp.h:384
main structure containing all configuration information
Definition: evhtp/evhtp.h:286
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
Definition: evhtp.c:3328
EVHTP_EXPORT void evhtp_connection_resume(evhtp_connection_t *connection)
resumes a connection (enables reading) and activates resume event.
Definition: evhtp.c:3052
char k_heaped
set to 1 if the key can be free()&#39;d
Definition: evhtp/evhtp.h:344
struct event_base * evbase
the initialized event_base
Definition: evhtp/evhtp.h:288
evhtp_res(* evhtp_hook_conn_err_cb)(evhtp_connection_t *connection, evhtp_error_flags errtype, void *arg)
Definition: evhtp/evhtp.h:164
evhtp_hook_chunk_fini_cb on_chunk_fini
Definition: evhtp/evhtp.h:475
SSL_CTX evhtp_ssl_ctx_t
Definition: evhtp/evhtp.h:44
evhtp_res status
The HTTP response code or other error conditions.
Definition: evhtp/evhtp.h:410
void *(* evhtp_ssl_scache_init)(evhtp_t *)
Definition: evhtp/evhtp.h:192
struct evbuffer * buffer_in
buffer containing data from client
Definition: evhtp/evhtp.h:404
#define evhtp_query_t
Definition: evhtp/evhtp.h:99
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.
Definition: evhtp.c:4587
EVHTP_EXPORT void evhtp_request_set_bev(evhtp_request_t *request, struct bufferevent *bev)
sets the underlying bufferevent for a evhtp_request
Definition: evhtp.c:4982
htp_scheme scheme
set if a scheme is found
Definition: evhtp/evhtp.h:363
EVHTP_EXPORT void evhtp_connection_pause(evhtp_connection_t *connection)
pauses a connection (disables reading)
Definition: evhtp.c:3040
evhtp_callback_type
Definition: evhtp/evhtp.h:130
pthread_mutex_t evhtp_mutex_t
Definition: evhtp/evhtp.h:71
evhtp_ssl_scache_type scache_type
Definition: evhtp/evhtp.h:515
struct evbuffer * scratch_buf
always zero&#39;d out after used
Definition: evhtp/evhtp.h:457
pthread_mutex_t * lock
parent lock for add/del cbs in threads
Definition: evhtp/evhtp.h:311
EVHTP_EXPORT evhtp_callback_t * evhtp_get_cb(evhtp_t *htp, const char *needle)
attempts to find the callback matching the exact string &#39;needle&#39;.
Definition: evhtp.c:4511
EVHTP_EXPORT void evhtp_request_resume(evhtp_request_t *request)
Wrapper around evhtp_connection_resume.
Definition: evhtp.c:3073
struct bufferevent * bev
Definition: evhtp/evhtp.h:428
evhtp_hook_type
types associated with where a developer can hook into during the request processing cycle...
Definition: evhtp/evhtp.h:112
char * named_curve
Definition: evhtp/evhtp.h:505
evhtp_res(* evhtp_hook_path_cb)(evhtp_request_t *req, evhtp_path_t *path, void *arg)
Definition: evhtp/evhtp.h:169
EVHTP_EXPORT 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:5529
evhtp_hook_header_cb on_header
Definition: evhtp/evhtp.h:466
EVHTP_EXPORT int evhtp_unset_all_hooks(evhtp_hooks_t **hooks)
removes all hooks.
Definition: evhtp.c:4393
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
Definition: evhtp.c:4705
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.
Definition: evhtp.c:3482
static void(* free_)(void *d)
Definition: evhtp.c:166
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...
Definition: evhtp.c:5023
evhtp_res(* evhtp_hook_request_fini_cb)(evhtp_request_t *req, void *arg)
Definition: evhtp/evhtp.h:171
EVHTP_EXPORT void evhtp_callback_free(evhtp_callback_t *callback)
safely frees callback structure memory and internals
Definition: evhtp.c:4232
evhtp_hook_path_cb on_path
Definition: evhtp/evhtp.h:468
void * thread_cbarg
Definition: evhtp/evhtp.h:320
EVHTP_EXPORT evhtp_connection_t * evhtp_connection_new(struct event_base *evbase, const char *addr, uint16_t port)
allocate a new connection
Definition: evhtp.c:5358
char * username
the username in URI (scheme://USER:.
Definition: evhtp/evhtp.h:371
void * on_event_arg
Definition: evhtp/evhtp.h:495
X509_STORE_CTX evhtp_x509_store_ctx_t
Definition: evhtp/evhtp.h:46
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.
Definition: evhtp.c:4719
EVHTP_EXPORT int evhtp_connection_get_flags(evhtp_connection_t *)
EVHTP_EXPORT void evhtp_connection_free(evhtp_connection_t *connection)
free&#39;s all connection related resources, this will also call your request fini hook and request fini ...
Definition: evhtp.c:5040
type which defines to hook before the request is free&#39;d
Definition: evhtp/evhtp.h:117
evhtp_headers_t * headers_in
headers from client
Definition: evhtp/evhtp.h:406
uint16_t evhtp_res
Definition: evhtp/evhtp.h:89
EVHTP_EXPORT int evhtp_response_needs_body(const evhtp_res code, const htp_method method)
Determine if a response should have a body.
Definition: evhtp.c:3819
evhtp_hook_err_cb on_error
Definition: evhtp/evhtp.h:473
EVHTP_EXPORT int evhtp_unescape_string(unsigned char **out, unsigned char *str, size_t str_len)
Unescapes strings like &#39;%7B1,%202,%203%7D&#39; would become &#39;{1, 2, 3}&#39;.
Definition: evhtp.c:3403
EVHTP_EXPORT int evhtp_get_flags(evhtp_t *)
uint64_t max_body_size
Definition: evhtp/evhtp.h:443
evhtp_res(* evhtp_hook_chunk_fini_cb)(evhtp_request_t *r, void *arg)
Definition: evhtp/evhtp.h:174
EVHTP_EXPORT evhtp_kvs_t * evhtp_kvs_new(void)
creates an empty list of key/values
Definition: evhtp.c:3134
void(* evhtp_hook_err_cb)(evhtp_request_t *req, evhtp_error_flags errtype, void *arg)
Definition: evhtp/evhtp.h:158
evhtp_t * parent
only when this is a vhost
Definition: evhtp/evhtp.h:287
evhtp_res(* evhtp_hook_header_cb)(evhtp_request_t *req, evhtp_header_t *hdr, void *arg)
Definition: evhtp/evhtp.h:167
void(* evhtp_thread_exit_cb)(evhtp_t *htp, evthr_t *thr, void *arg)
Definition: evhtp/evhtp.h:156
uint8_t evhtp_error_flags
Definition: evhtp/evhtp.h:90
evhtp_thread_exit_cb thread_exit_cb
Definition: evhtp/evhtp.h:314
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.
Definition: evhtp.c:4712
evhtp_hooks_t * hooks
request specific hooks
Definition: evhtp/evhtp.h:402
evhtp_callbacks_t * callbacks
Definition: evhtp/evhtp.h:322
evhtp_res(* evhtp_hook)()
Definition: evhtp/evhtp.h:162
a generic key/value structure
Definition: evhtp/evhtp.h:337
unsigned int matched_eoff
offset of where the uri ends mainly used for regex matching
Definition: evhtp/evhtp.h:390
struct event_base * evbase
Definition: evhtp/evhtp.h:427
EVHTP_EXPORT void evhtp_send_reply_chunk(evhtp_request_t *request, struct evbuffer *buf)
send a chunk reply.
Definition: evhtp.c:3900
evhtp_res(* evhtp_hook_headers_cb)(evhtp_request_t *req, evhtp_headers_t *hdr, void *arg)
Definition: evhtp/evhtp.h:168
a structure containing all information for a http request.
Definition: evhtp/evhtp.h:399
evthr_pool_t * thr_pool
connection threadpool
Definition: evhtp/evhtp.h:310
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...
void * on_path_arg
Definition: evhtp/evhtp.h:484
EVHTP_EXPORT struct bufferevent * evhtp_request_get_bev(evhtp_request_t *request)
returns the underlying requests bufferevent
Definition: evhtp.c:4966
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...
Definition: evhtp.c:4666
TAILQ_HEAD(evhtp_kvs_s, evhtp_kv_s)
evhtp_callback_cb cb
Definition: evhtp/evhtp.h:268
#define evhtp_headers_t
Definition: evhtp/evhtp.h:98
struct event * resume_ev
Definition: evhtp/evhtp.h:437
evhtp_hook_connection_fini_cb on_connection_fini
Definition: evhtp/evhtp.h:471
EVHTP_EXPORT void evhtp_request_enable_flag(evhtp_request_t *, int)
void * on_chunks_fini_arg
Definition: evhtp/evhtp.h:492
evhtp_hook_conn_err_cb on_connection_error
Definition: evhtp/evhtp.h:472
void * on_new_chunk_arg
Definition: evhtp/evhtp.h:490
int(* evhtp_ssl_chk_issued_cb)(evhtp_x509_store_ctx_t *ctx, evhtp_x509_t *x, evhtp_x509_t *issuer)
Definition: evhtp/evhtp.h:185
structure containing a single callback and configuration
Definition: evhtp.c:51
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
Definition: evhtp.c:3096
EVHTP_EXPORT evhtp_connection_t * evhtp_connection_ssl_new(struct event_base *evbase, const char *addr, uint16_t port, evhtp_ssl_ctx_t *ctx)
Definition: evhtp.c:5441
evhtp_callback_cb cb
the function to call when fully processed
Definition: evhtp/evhtp.h:417
int(* evhtp_ssl_verify_cb)(int pre_verify, evhtp_x509_store_ctx_t *ctx)
Definition: evhtp/evhtp.h:184
struct evconnlistener * server
the libevent listener struct
Definition: evhtp/evhtp.h:289
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.
Definition: evhtp.c:5086
evhtp_res(* evhtp_hook_connection_fini_cb)(evhtp_connection_t *connection, void *arg)
Definition: evhtp/evhtp.h:172
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...
Definition: evhtp.c:5009
evhtp_ssl_t * ssl
Definition: evhtp/evhtp.h:433
evhtp_hook_chunks_fini_cb on_chunks_fini
Definition: evhtp/evhtp.h:476
type which defines to hook after all headers have been parsed
Definition: evhtp/evhtp.h:114
char * server_name
the name included in Host: responses
Definition: evhtp/evhtp.h:290
evhtp_hook_write_cb on_write
Definition: evhtp/evhtp.h:478
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
Definition: evhtp.c:4472
EVHTP_EXPORT evhtp_t * evhtp_new(struct event_base *evbase, void *arg)
creates a new evhtp_t instance
Definition: evhtp.c:5293
evhtp_request_t * request
the request currently being processed
Definition: evhtp/evhtp.h:442
struct evhtp_kvs_s evhtp_kvs_t
Definition: evhtp/evhtp.h:80
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
Definition: evhtp.c:3790
EVHTP_EXPORT 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:3147
EVHTP_EXPORT void evhtp_set_bev_flags(evhtp_t *htp, int flags)
bufferevent flags which will be used for bev sockets.
Definition: evhtp.c:5106
EVHTP_EXPORT evhtp_connection_t * evhtp_request_get_connection(evhtp_request_t *request)
returns the underlying evhtp_connection_t structure from a request
Definition: evhtp.c:4997
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
Definition: evhtp.c:5364
EVHTP_EXPORT void evhtp_request_disable_flag(evhtp_request_t *, int)
evhtp_hooks_t * hooks
Definition: evhtp/evhtp.h:435
evhtp_hook_headers_start_cb on_headers_start
Definition: evhtp/evhtp.h:465
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.
Definition: evhtp.c:4594
a generic container representing an entire URI strucutre
Definition: evhtp/evhtp.h:357
void * on_hostname_arg
Definition: evhtp/evhtp.h:493
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.
Definition: evhtp.c:5100
char * path
the path (/a/b/)
Definition: evhtp/evhtp.h:383
EVHTP_EXPORT void evhtp_unbind_socket(evhtp_t *htp)
stops the listening socket.
Definition: evhtp.c:3940
char * match_start
Definition: evhtp/evhtp.h:385
char v_heaped
set to 1 if the val can be free()&#39;d
Definition: evhtp/evhtp.h:345
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...
Definition: evhtp.c:4939
EVHTP_EXPORT void evhtp_set_mem_functions(void *(*malloc_)(size_t), void *(*realloc_)(void *, size_t), void(*free_)(void *))
evhtp_res(* evhtp_pre_accept_cb)(evhtp_connection_t *conn, void *arg)
Definition: evhtp/evhtp.h:165
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.
Definition: evhtp.c:5034
evhtp_pre_accept_cb pre_accept
Definition: evhtp/evhtp.h:269
evhtp_proto
Definition: evhtp/evhtp.h:138
EVHTP_EXPORT int evhtp_ssl_init(evhtp_t *htp, evhtp_ssl_cfg_t *ssl_cfg)
Definition: evhtp.c:4760
int(* evhtp_kvs_iterator)(evhtp_kv_t *kv, void *arg)
Definition: evhtp/evhtp.h:180
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.
Definition: evhtp.c:3928
char * match_end
Definition: evhtp/evhtp.h:386
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...
Definition: evhtp.c:5203
evhtp_authority_t * authority
Definition: evhtp/evhtp.h:358
char * full
the full path+file (/a/b/c.html)
Definition: evhtp/evhtp.h:382
void * on_read_arg
Definition: evhtp/evhtp.h:485
EVHTP_EXPORT int evhtp_kvs_for_each(evhtp_kvs_t *kvs, evhtp_kvs_iterator cb, void *arg)
callback iterator which executes &#39;cb&#39; for every entry in &#39;kvs&#39;
Definition: evhtp.c:3266
EVHTP_EXPORT void evhtp_kv_rm_and_free(evhtp_kvs_t *kvs, evhtp_kv_t *kv)
free&#39;s resources associated with &#39;kv&#39; if ONLY found within the key/value list
Definition: evhtp.c:3227
EVHTP_EXPORT const char * evhtp_kv_find(evhtp_kvs_t *kvs, const char *key)
find the string value of &#39;key&#39; from the key/value list &#39;kvs&#39;
Definition: evhtp.c:3288
EVHTP_EXPORT void evhtp_kvs_free(evhtp_kvs_t *kvs)
frees a the list of key/values, and all underlying entries
Definition: evhtp.c:3240
type which defines to hook whenever the parser recieves data in a body
Definition: evhtp/evhtp.h:116
EVHTP_EXPORT void evhtp_request_pause(evhtp_request_t *request)
Wrapper around evhtp_connection_pause.
Definition: evhtp.c:3064
type which defines to hook whenever a connection error occurs
Definition: evhtp/evhtp.h:127
void * on_chunk_fini_arg
Definition: evhtp/evhtp.h:491
evhtp_res(* evhtp_hook_headers_start_cb)(evhtp_request_t *r, void *arg)
Definition: evhtp/evhtp.h:176
#define evhtp_header_find
Definition: evhtp/evhtp.h:1208
void * arg
user-defined evhtp_t specific arguments
Definition: evhtp/evhtp.h:291
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...
Definition: evhtp.c:5124
EVHTP_EXPORT void evhtp_connection_disable_flag(evhtp_connection_t *, int)
SSL_SESSION evhtp_ssl_sess_t
Definition: evhtp/evhtp.h:39
evhtp_res(* evhtp_post_accept_cb)(evhtp_connection_t *conn, void *arg)
Definition: evhtp/evhtp.h:166
evhtp_proto proto
HTTP protocol used.
Definition: evhtp/evhtp.h:408
evhtp_ssl_cfg_t * ssl_cfg
Definition: evhtp/evhtp.h:306
struct evbuffer * buffer_out
buffer containing data to client
Definition: evhtp/evhtp.h:405
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.
Definition: evhtp.c:4265
void * on_error_arg
Definition: evhtp/evhtp.h:489
char * password
the password in URI (scheme://...:PASS.
Definition: evhtp/evhtp.h:372
struct evbuffer evbuf_t
Definition: evhtp/evhtp.h:60
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.
Definition: evhtp.c:3748
EVHTP_EXPORT struct bufferevent * evhtp_connection_get_bev(evhtp_connection_t *conn)
returns the underlying connections bufferevent
Definition: evhtp.c:4934
#define evhtp_headers_add_header
Definition: evhtp/evhtp.h:1216
void(* evhtp_hook_event_cb)(evhtp_connection_t *conn, short events, void *arg)
Definition: evhtp/evhtp.h:159
uint16_t flags
the base flags set for this context, see: EVHTP_FLAG_*
Definition: evhtp/evhtp.h:301
evutil_socket_t sock
Definition: evhtp/evhtp.h:441
evhtp_hook_request_fini_cb on_request_fini
Definition: evhtp/evhtp.h:470
EVHTP_EXPORT void evhtp_send_reply_start(evhtp_request_t *request, evhtp_res code)
Definition: evhtp.c:3755
evhtp_ssl_ctx_t * ssl_ctx
if ssl enabled, this is the servers CTX
Definition: evhtp/evhtp.h:305
char * val
Definition: evhtp/evhtp.h:339
evhtp_res(* evhtp_hook_read_cb)(evhtp_request_t *req, struct evbuffer *buf, void *arg)
Definition: evhtp/evhtp.h:170
struct bufferevent evbev_t
Definition: evhtp/evhtp.h:63
#define evhtp_header_new
Definition: evhtp/evhtp.h:1211
evhtp_t * htp
the parent evhtp_t structure
Definition: evhtp/evhtp.h:400
evhtp_hook_headers_cb on_headers
Definition: evhtp/evhtp.h:467
static void *(* malloc_)(size_t sz)
Definition: evhtp.c:164
evhtp_ssl_scache_init scache_init
Definition: evhtp/evhtp.h:518
uint64_t body_bytes_read
Definition: evhtp/evhtp.h:444
evhtp_ssl_chk_issued_cb x509_chk_issued_cb
Definition: evhtp/evhtp.h:512
void(* evhtp_callback_cb)(evhtp_request_t *req, void *arg)
Definition: evhtp/evhtp.h:157
void * on_connection_error_arg
Definition: evhtp/evhtp.h:488
uint16_t port
port if present in URI
Definition: evhtp/evhtp.h:374
EVP_PKEY *(* evhtp_ssl_decrypt_cb)(char *privfile)
Definition: evhtp/evhtp.h:186
int bev_flags
bufferevent flags to use on bufferevent_*_socket_new()
Definition: evhtp/evhtp.h:292
evhtp_res(* evhtp_hook_chunk_new_cb)(evhtp_request_t *r, uint64_t len, void *arg)
Definition: evhtp/evhtp.h:173
struct sockaddr * saddr
Definition: evhtp/evhtp.h:438
EVHTP_EXPORT int evhtp_ssl_use_threads(void)
Definition: evhtp.c:4728
unsigned int matched_soff
offset of where the uri starts mainly used for regex matching
Definition: evhtp/evhtp.h:387
EVHTP_EXPORT int evhtp_add_alias(evhtp_t *evhtp, const char *name)
Add an alias hostname for a virtual-host specific evhtp_t.
Definition: evhtp.c:5153
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.
Definition: evhtp.c:3951
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
Definition: evhtp.c:3339
evhtp_res(* evhtp_hook_chunks_fini_cb)(evhtp_request_t *r, void *arg)
Definition: evhtp/evhtp.h:175
evhtp_ssl_verify_cb x509_verify_cb
Definition: evhtp/evhtp.h:511
evhtp_defaults_t defaults
Definition: evhtp/evhtp.h:323
size_t vlen
Definition: evhtp/evhtp.h:342
#define evhtp_headers_iterator
Definition: evhtp/evhtp.h:200
evhtp_ssl_sess_t *(* evhtp_ssl_scache_get)(evhtp_connection_t *connection, evhtp_ssl_data_t *sid, int sid_len)
Definition: evhtp/evhtp.h:190
evhtp_hook_event_cb on_event
Definition: evhtp/evhtp.h:479
uint16_t flags
Definition: evhtp/evhtp.h:415
evhtp_thread_init_cb thread_init_cb
Definition: evhtp/evhtp.h:313
evhtp_ssl_scache_get scache_get
Definition: evhtp/evhtp.h:520
static void *(* realloc_)(void *d, size_t sz)
Definition: evhtp.c:165
unsigned char * fragment
data after &#39;#&#39; in uri
Definition: evhtp/evhtp.h:360
type which defines to hook after one header has been parsed
Definition: evhtp/evhtp.h:113
void * on_write_arg
Definition: evhtp/evhtp.h:494
EVHTP_EXPORT int evhtp_add_aliases(evhtp_t *evhtp, const char *name,...)
set a variable number of aliases in one call evhtp_add_alias
Definition: evhtp.c:5178
structure which represents a URI path and or file
Definition: evhtp/evhtp.h:381
EVHTP_EXPORT void evhtp_send_reply_chunk_start(evhtp_request_t *request, evhtp_res code)
start a chunked response.
Definition: evhtp.c:3828
void * on_header_arg
Definition: evhtp/evhtp.h:482
uint64_t max_keepalive_requests
Definition: evhtp/evhtp.h:294
EVHTP_EXPORT void evhtp_free(evhtp_t *evhtp)
Frees evhtp_t structure; will stop and free threads associated with the structure, and free the ssl context as well (if applicable).
Definition: evhtp.c:5306
struct event event_t
Definition: evhtp/evhtp.h:61
EVHTP_EXPORT void evhtp_send_reply_body(evhtp_request_t *request, struct evbuffer *buf)
Definition: evhtp.c:3774
structure which represents authority information in a URI
Definition: evhtp/evhtp.h:370
EVHTP_EXPORT void evhtp_enable_flag(evhtp_t *, int)
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.
Definition: evhtp.c:4110
evhtp_ssl_scache_type
Definition: evhtp/evhtp.h:101
evhtp_headers_t * headers_out
headers to client
Definition: evhtp/evhtp.h:407
void * on_request_fini_arg
Definition: evhtp/evhtp.h:486
void * on_headers_arg
Definition: evhtp/evhtp.h:483
uint64_t num_requests
Definition: evhtp/evhtp.h:445