00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _EVENT2_HTTP_H_
00028 #define _EVENT2_HTTP_H_
00029
00030
00031 #include <event2/util.h>
00032
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif
00036
00037
00038 struct evbuffer;
00039 struct event_base;
00040
00052
00053 #define HTTP_OK 200
00054 #define HTTP_NOCONTENT 204
00055 #define HTTP_MOVEPERM 301
00056 #define HTTP_MOVETEMP 302
00057 #define HTTP_NOTMODIFIED 304
00058 #define HTTP_BADREQUEST 400
00059 #define HTTP_NOTFOUND 404
00060 #define HTTP_BADMETHOD 405
00061 #define HTTP_ENTITYTOOLARGE 413
00062 #define HTTP_EXPECTATIONFAILED 417
00063 #define HTTP_INTERNAL 500
00064 #define HTTP_NOTIMPLEMENTED 501
00065 #define HTTP_SERVUNAVAIL 503
00067 struct evhttp;
00068 struct evhttp_request;
00069 struct evkeyvalq;
00070 struct evhttp_bound_socket;
00071 struct evconnlistener;
00072
00080 struct evhttp *evhttp_new(struct event_base *base);
00081
00094 int evhttp_bind_socket(struct evhttp *http, const char *address, ev_uint16_t port);
00095
00107 struct evhttp_bound_socket *evhttp_bind_socket_with_handle(struct evhttp *http, const char *address, ev_uint16_t port);
00108
00125 int evhttp_accept_socket(struct evhttp *http, evutil_socket_t fd);
00126
00137 struct evhttp_bound_socket *evhttp_accept_socket_with_handle(struct evhttp *http, evutil_socket_t fd);
00138
00144 struct evhttp_bound_socket *evhttp_bind_listener(struct evhttp *http, struct evconnlistener *listener);
00145
00149 struct evconnlistener *evhttp_bound_socket_get_listener(struct evhttp_bound_socket *bound);
00150
00165 void evhttp_del_accept_socket(struct evhttp *http, struct evhttp_bound_socket *bound_socket);
00166
00174 evutil_socket_t evhttp_bound_socket_get_fd(struct evhttp_bound_socket *bound_socket);
00175
00184 void evhttp_free(struct evhttp* http);
00185
00187 void evhttp_set_max_headers_size(struct evhttp* http, ev_ssize_t max_headers_size);
00189 void evhttp_set_max_body_size(struct evhttp* http, ev_ssize_t max_body_size);
00190
00202 void evhttp_set_allowed_methods(struct evhttp* http, ev_uint16_t methods);
00203
00213 int evhttp_set_cb(struct evhttp *http, const char *path,
00214 void (*cb)(struct evhttp_request *, void *), void *cb_arg);
00215
00217 int evhttp_del_cb(struct evhttp *, const char *);
00218
00230 void evhttp_set_gencb(struct evhttp *http,
00231 void (*cb)(struct evhttp_request *, void *), void *arg);
00232
00255 int evhttp_add_virtual_host(struct evhttp* http, const char *pattern,
00256 struct evhttp* vhost);
00257
00266 int evhttp_remove_virtual_host(struct evhttp* http, struct evhttp* vhost);
00267
00276 int evhttp_add_server_alias(struct evhttp *http, const char *alias);
00277
00285 int evhttp_remove_server_alias(struct evhttp *http, const char *alias);
00286
00293 void evhttp_set_timeout(struct evhttp *http, int timeout_in_secs);
00294
00295
00296
00305 void evhttp_send_error(struct evhttp_request *req, int error,
00306 const char *reason);
00307
00321 void evhttp_send_reply(struct evhttp_request *req, int code,
00322 const char *reason, struct evbuffer *databuf);
00323
00324
00325
00340 void evhttp_send_reply_start(struct evhttp_request *req, int code,
00341 const char *reason);
00342
00354 void evhttp_send_reply_chunk(struct evhttp_request *req,
00355 struct evbuffer *databuf);
00361 void evhttp_send_reply_end(struct evhttp_request *req);
00362
00363
00364
00365
00366
00374 enum evhttp_cmd_type {
00375 EVHTTP_REQ_GET = 1 << 0,
00376 EVHTTP_REQ_POST = 1 << 1,
00377 EVHTTP_REQ_HEAD = 1 << 2,
00378 EVHTTP_REQ_PUT = 1 << 3,
00379 EVHTTP_REQ_DELETE = 1 << 4,
00380 EVHTTP_REQ_OPTIONS = 1 << 5,
00381 EVHTTP_REQ_TRACE = 1 << 6,
00382 EVHTTP_REQ_CONNECT = 1 << 7,
00383 EVHTTP_REQ_PATCH = 1 << 8
00384 };
00385
00387 enum evhttp_request_kind { EVHTTP_REQUEST, EVHTTP_RESPONSE };
00388
00394 struct evhttp_request *evhttp_request_new(
00395 void (*cb)(struct evhttp_request *, void *), void *arg);
00396
00404 void evhttp_request_set_chunked_cb(struct evhttp_request *,
00405 void (*cb)(struct evhttp_request *, void *));
00406
00408 void evhttp_request_free(struct evhttp_request *req);
00409
00410 struct evdns_base;
00411
00424 struct evhttp_connection *evhttp_connection_base_new(
00425 struct event_base *base, struct evdns_base *dnsbase,
00426 const char *address, unsigned short port);
00427
00433 void evhttp_request_own(struct evhttp_request *req);
00434
00436 int evhttp_request_is_owned(struct evhttp_request *req);
00437
00444 struct evhttp_connection *evhttp_request_get_connection(struct evhttp_request *req);
00445
00449 struct event_base *evhttp_connection_get_base(struct evhttp_connection *req);
00450
00451 void evhttp_connection_set_max_headers_size(struct evhttp_connection *evcon,
00452 ev_ssize_t new_max_headers_size);
00453
00454 void evhttp_connection_set_max_body_size(struct evhttp_connection* evcon,
00455 ev_ssize_t new_max_body_size);
00456
00458 void evhttp_connection_free(struct evhttp_connection *evcon);
00459
00461 void evhttp_connection_set_local_address(struct evhttp_connection *evcon,
00462 const char *address);
00463
00465 void evhttp_connection_set_local_port(struct evhttp_connection *evcon,
00466 ev_uint16_t port);
00467
00469 void evhttp_connection_set_timeout(struct evhttp_connection *evcon,
00470 int timeout_in_secs);
00471
00473 void evhttp_connection_set_retries(struct evhttp_connection *evcon,
00474 int retry_max);
00475
00477 void evhttp_connection_set_closecb(struct evhttp_connection *evcon,
00478 void (*)(struct evhttp_connection *, void *), void *);
00479
00481 void evhttp_connection_get_peer(struct evhttp_connection *evcon,
00482 char **address, ev_uint16_t *port);
00483
00497 int evhttp_make_request(struct evhttp_connection *evcon,
00498 struct evhttp_request *req,
00499 enum evhttp_cmd_type type, const char *uri);
00500
00514 void evhttp_cancel_request(struct evhttp_request *req);
00515
00519 struct evhttp_uri;
00520
00522 const char *evhttp_request_get_uri(const struct evhttp_request *req);
00524 const struct evhttp_uri *evhttp_request_get_evhttp_uri(const struct evhttp_request *req);
00526 enum evhttp_cmd_type evhttp_request_get_command(const struct evhttp_request *req);
00527
00528 int evhttp_request_get_response_code(const struct evhttp_request *req);
00529
00531 struct evkeyvalq *evhttp_request_get_input_headers(struct evhttp_request *req);
00533 struct evkeyvalq *evhttp_request_get_output_headers(struct evhttp_request *req);
00535 struct evbuffer *evhttp_request_get_input_buffer(struct evhttp_request *req);
00537 struct evbuffer *evhttp_request_get_output_buffer(struct evhttp_request *req);
00542 const char *evhttp_request_get_host(struct evhttp_request *req);
00543
00544
00545
00555 const char *evhttp_find_header(const struct evkeyvalq *headers,
00556 const char *key);
00557
00566 int evhttp_remove_header(struct evkeyvalq *headers, const char *key);
00567
00577 int evhttp_add_header(struct evkeyvalq *headers, const char *key, const char *value);
00578
00584 void evhttp_clear_headers(struct evkeyvalq *headers);
00585
00586
00587
00588
00600 char *evhttp_encode_uri(const char *str);
00601
00616 char *evhttp_uriencode(const char *str, ev_ssize_t size, int space_to_plus);
00617
00632 char *evhttp_decode_uri(const char *uri);
00633
00649 char *evhttp_uridecode(const char *uri, int decode_plus,
00650 size_t *size_out);
00651
00671 int evhttp_parse_query(const char *uri, struct evkeyvalq *headers);
00672
00690 int evhttp_parse_query_str(const char *uri, struct evkeyvalq *headers);
00691
00703 char *evhttp_htmlescape(const char *html);
00704
00708 struct evhttp_uri *evhttp_uri_new(void);
00709
00712 const char *evhttp_uri_get_scheme(const struct evhttp_uri *uri);
00717 const char *evhttp_uri_get_userinfo(const struct evhttp_uri *uri);
00730 const char *evhttp_uri_get_host(const struct evhttp_uri *uri);
00732 int evhttp_uri_get_port(const struct evhttp_uri *uri);
00734 const char *evhttp_uri_get_path(const struct evhttp_uri *uri);
00737 const char *evhttp_uri_get_query(const struct evhttp_uri *uri);
00740 const char *evhttp_uri_get_fragment(const struct evhttp_uri *uri);
00741
00744 int evhttp_uri_set_scheme(struct evhttp_uri *uri, const char *scheme);
00747 int evhttp_uri_set_userinfo(struct evhttp_uri *uri, const char *userinfo);
00750 int evhttp_uri_set_host(struct evhttp_uri *uri, const char *host);
00753 int evhttp_uri_set_port(struct evhttp_uri *uri, int port);
00756 int evhttp_uri_set_path(struct evhttp_uri *uri, const char *path);
00760 int evhttp_uri_set_query(struct evhttp_uri *uri, const char *query);
00764 int evhttp_uri_set_fragment(struct evhttp_uri *uri, const char *fragment);
00765
00798 struct evhttp_uri *evhttp_uri_parse(const char *source_uri);
00799
00807 void evhttp_uri_free(struct evhttp_uri *uri);
00808
00822 char *evhttp_uri_join(struct evhttp_uri *uri, char *buf, size_t limit);
00823
00824 #ifdef __cplusplus
00825 }
00826 #endif
00827
00828 #endif