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_INCLUDED_
00028 #define EVENT2_HTTP_H_INCLUDED_
00029
00030
00031 #include <event2/util.h>
00032 #include <event2/visibility.h>
00033
00034 #ifdef __cplusplus
00035 extern "C" {
00036 #endif
00037
00038
00039 struct evbuffer;
00040 struct event_base;
00041 struct bufferevent;
00042 struct evhttp_connection;
00043
00055
00056 #define HTTP_OK 200
00057 #define HTTP_NOCONTENT 204
00058 #define HTTP_MOVEPERM 301
00059 #define HTTP_MOVETEMP 302
00060 #define HTTP_NOTMODIFIED 304
00061 #define HTTP_BADREQUEST 400
00062 #define HTTP_NOTFOUND 404
00063 #define HTTP_BADMETHOD 405
00064 #define HTTP_ENTITYTOOLARGE 413
00065 #define HTTP_EXPECTATIONFAILED 417
00066 #define HTTP_INTERNAL 500
00067 #define HTTP_NOTIMPLEMENTED 501
00068 #define HTTP_SERVUNAVAIL 503
00070 struct evhttp;
00071 struct evhttp_request;
00072 struct evkeyvalq;
00073 struct evhttp_bound_socket;
00074 struct evconnlistener;
00075 struct evdns_base;
00076
00084 EVENT2_EXPORT_SYMBOL
00085 struct evhttp *evhttp_new(struct event_base *base);
00086
00099 EVENT2_EXPORT_SYMBOL
00100 int evhttp_bind_socket(struct evhttp *http, const char *address, ev_uint16_t port);
00101
00113 EVENT2_EXPORT_SYMBOL
00114 struct evhttp_bound_socket *evhttp_bind_socket_with_handle(struct evhttp *http, const char *address, ev_uint16_t port);
00115
00132 EVENT2_EXPORT_SYMBOL
00133 int evhttp_accept_socket(struct evhttp *http, evutil_socket_t fd);
00134
00145 EVENT2_EXPORT_SYMBOL
00146 struct evhttp_bound_socket *evhttp_accept_socket_with_handle(struct evhttp *http, evutil_socket_t fd);
00147
00153 EVENT2_EXPORT_SYMBOL
00154 struct evhttp_bound_socket *evhttp_bind_listener(struct evhttp *http, struct evconnlistener *listener);
00155
00159 EVENT2_EXPORT_SYMBOL
00160 struct evconnlistener *evhttp_bound_socket_get_listener(struct evhttp_bound_socket *bound);
00161
00162 typedef void evhttp_bound_socket_foreach_fn(struct evhttp_bound_socket *, void *);
00173 EVENT2_EXPORT_SYMBOL
00174 void evhttp_foreach_bound_socket(struct evhttp *http, evhttp_bound_socket_foreach_fn *function, void *argument);
00175
00193 EVENT2_EXPORT_SYMBOL
00194 void evhttp_del_accept_socket(struct evhttp *http, struct evhttp_bound_socket *bound_socket);
00195
00203 EVENT2_EXPORT_SYMBOL
00204 evutil_socket_t evhttp_bound_socket_get_fd(struct evhttp_bound_socket *bound_socket);
00205
00214 EVENT2_EXPORT_SYMBOL
00215 void evhttp_free(struct evhttp* http);
00216
00218 EVENT2_EXPORT_SYMBOL
00219 void evhttp_set_max_headers_size(struct evhttp* http, ev_ssize_t max_headers_size);
00221 EVENT2_EXPORT_SYMBOL
00222 void evhttp_set_max_body_size(struct evhttp* http, ev_ssize_t max_body_size);
00223
00232 EVENT2_EXPORT_SYMBOL
00233 void evhttp_set_default_content_type(struct evhttp *http,
00234 const char *content_type);
00235
00247 EVENT2_EXPORT_SYMBOL
00248 void evhttp_set_allowed_methods(struct evhttp* http, ev_uint16_t methods);
00249
00259 EVENT2_EXPORT_SYMBOL
00260 int evhttp_set_cb(struct evhttp *http, const char *path,
00261 void (*cb)(struct evhttp_request *, void *), void *cb_arg);
00262
00264 EVENT2_EXPORT_SYMBOL
00265 int evhttp_del_cb(struct evhttp *, const char *);
00266
00278 EVENT2_EXPORT_SYMBOL
00279 void evhttp_set_gencb(struct evhttp *http,
00280 void (*cb)(struct evhttp_request *, void *), void *arg);
00281
00296 EVENT2_EXPORT_SYMBOL
00297 void evhttp_set_bevcb(struct evhttp *http,
00298 struct bufferevent *(*cb)(struct event_base *, void *), void *arg);
00299
00322 EVENT2_EXPORT_SYMBOL
00323 int evhttp_add_virtual_host(struct evhttp* http, const char *pattern,
00324 struct evhttp* vhost);
00325
00334 EVENT2_EXPORT_SYMBOL
00335 int evhttp_remove_virtual_host(struct evhttp* http, struct evhttp* vhost);
00336
00345 EVENT2_EXPORT_SYMBOL
00346 int evhttp_add_server_alias(struct evhttp *http, const char *alias);
00347
00355 EVENT2_EXPORT_SYMBOL
00356 int evhttp_remove_server_alias(struct evhttp *http, const char *alias);
00357
00364 EVENT2_EXPORT_SYMBOL
00365 void evhttp_set_timeout(struct evhttp *http, int timeout_in_secs);
00366
00373 EVENT2_EXPORT_SYMBOL
00374 void evhttp_set_timeout_tv(struct evhttp *http, const struct timeval* tv);
00375
00376
00377
00378 #define EVHTTP_SERVER_LINGERING_CLOSE 0x0001
00379
00386 EVENT2_EXPORT_SYMBOL
00387 int evhttp_set_flags(struct evhttp *http, int flags);
00388
00389
00390
00399 EVENT2_EXPORT_SYMBOL
00400 void evhttp_send_error(struct evhttp_request *req, int error,
00401 const char *reason);
00402
00416 EVENT2_EXPORT_SYMBOL
00417 void evhttp_send_reply(struct evhttp_request *req, int code,
00418 const char *reason, struct evbuffer *databuf);
00419
00420
00421
00436 EVENT2_EXPORT_SYMBOL
00437 void evhttp_send_reply_start(struct evhttp_request *req, int code,
00438 const char *reason);
00439
00451 EVENT2_EXPORT_SYMBOL
00452 void evhttp_send_reply_chunk(struct evhttp_request *req,
00453 struct evbuffer *databuf);
00454
00468 EVENT2_EXPORT_SYMBOL
00469 void evhttp_send_reply_chunk_with_cb(struct evhttp_request *, struct evbuffer *,
00470 void (*cb)(struct evhttp_connection *, void *), void *arg);
00471
00477 EVENT2_EXPORT_SYMBOL
00478 void evhttp_send_reply_end(struct evhttp_request *req);
00479
00480
00481
00482
00483
00491 enum evhttp_cmd_type {
00492 EVHTTP_REQ_GET = 1 << 0,
00493 EVHTTP_REQ_POST = 1 << 1,
00494 EVHTTP_REQ_HEAD = 1 << 2,
00495 EVHTTP_REQ_PUT = 1 << 3,
00496 EVHTTP_REQ_DELETE = 1 << 4,
00497 EVHTTP_REQ_OPTIONS = 1 << 5,
00498 EVHTTP_REQ_TRACE = 1 << 6,
00499 EVHTTP_REQ_CONNECT = 1 << 7,
00500 EVHTTP_REQ_PATCH = 1 << 8
00501 };
00502
00504 enum evhttp_request_kind { EVHTTP_REQUEST, EVHTTP_RESPONSE };
00505
00521 EVENT2_EXPORT_SYMBOL
00522 struct evhttp_connection *evhttp_connection_base_bufferevent_new(
00523 struct event_base *base, struct evdns_base *dnsbase, struct bufferevent* bev, const char *address, ev_uint16_t port);
00524
00528 EVENT2_EXPORT_SYMBOL
00529 struct bufferevent* evhttp_connection_get_bufferevent(struct evhttp_connection *evcon);
00530
00534 EVENT2_EXPORT_SYMBOL
00535 struct evhttp *evhttp_connection_get_server(struct evhttp_connection *evcon);
00536
00542 EVENT2_EXPORT_SYMBOL
00543 struct evhttp_request *evhttp_request_new(
00544 void (*cb)(struct evhttp_request *, void *), void *arg);
00545
00553 EVENT2_EXPORT_SYMBOL
00554 void evhttp_request_set_chunked_cb(struct evhttp_request *,
00555 void (*cb)(struct evhttp_request *, void *));
00556
00563 EVENT2_EXPORT_SYMBOL
00564 void evhttp_request_set_header_cb(struct evhttp_request *,
00565 int (*cb)(struct evhttp_request *, void *));
00566
00572 enum evhttp_request_error {
00576 EVREQ_HTTP_TIMEOUT,
00580 EVREQ_HTTP_EOF,
00584 EVREQ_HTTP_INVALID_HEADER,
00588 EVREQ_HTTP_BUFFER_ERROR,
00592 EVREQ_HTTP_REQUEST_CANCEL,
00596 EVREQ_HTTP_DATA_TOO_LONG
00597 };
00605 EVENT2_EXPORT_SYMBOL
00606 void evhttp_request_set_error_cb(struct evhttp_request *,
00607 void (*)(enum evhttp_request_error, void *));
00608
00621 EVENT2_EXPORT_SYMBOL
00622 void evhttp_request_set_on_complete_cb(struct evhttp_request *req,
00623 void (*cb)(struct evhttp_request *, void *), void *cb_arg);
00624
00626 EVENT2_EXPORT_SYMBOL
00627 void evhttp_request_free(struct evhttp_request *req);
00628
00641 EVENT2_EXPORT_SYMBOL
00642 struct evhttp_connection *evhttp_connection_base_new(
00643 struct event_base *base, struct evdns_base *dnsbase,
00644 const char *address, ev_uint16_t port);
00645
00649 EVENT2_EXPORT_SYMBOL
00650 void evhttp_connection_set_family(struct evhttp_connection *evcon,
00651 int family);
00652
00653
00654 #define EVHTTP_CON_REUSE_CONNECTED_ADDR 0x0008
00655
00656
00657
00658 #define EVHTTP_CON_READ_ON_WRITE_ERROR 0x0010
00659
00660 #define EVHTTP_CON_LINGERING_CLOSE 0x0020
00661
00662 #define EVHTTP_CON_PUBLIC_FLAGS_END 0x100000
00663
00670 EVENT2_EXPORT_SYMBOL
00671 int evhttp_connection_set_flags(struct evhttp_connection *evcon,
00672 int flags);
00673
00679 EVENT2_EXPORT_SYMBOL
00680 void evhttp_request_own(struct evhttp_request *req);
00681
00683 EVENT2_EXPORT_SYMBOL
00684 int evhttp_request_is_owned(struct evhttp_request *req);
00685
00692 EVENT2_EXPORT_SYMBOL
00693 struct evhttp_connection *evhttp_request_get_connection(struct evhttp_request *req);
00694
00698 EVENT2_EXPORT_SYMBOL
00699 struct event_base *evhttp_connection_get_base(struct evhttp_connection *req);
00700
00701 EVENT2_EXPORT_SYMBOL
00702 void evhttp_connection_set_max_headers_size(struct evhttp_connection *evcon,
00703 ev_ssize_t new_max_headers_size);
00704
00705 EVENT2_EXPORT_SYMBOL
00706 void evhttp_connection_set_max_body_size(struct evhttp_connection* evcon,
00707 ev_ssize_t new_max_body_size);
00708
00710 EVENT2_EXPORT_SYMBOL
00711 void evhttp_connection_free(struct evhttp_connection *evcon);
00712
00718 EVENT2_EXPORT_SYMBOL
00719 void evhttp_connection_free_on_completion(struct evhttp_connection *evcon);
00720
00722 EVENT2_EXPORT_SYMBOL
00723 void evhttp_connection_set_local_address(struct evhttp_connection *evcon,
00724 const char *address);
00725
00727 EVENT2_EXPORT_SYMBOL
00728 void evhttp_connection_set_local_port(struct evhttp_connection *evcon,
00729 ev_uint16_t port);
00730
00732 EVENT2_EXPORT_SYMBOL
00733 void evhttp_connection_set_timeout(struct evhttp_connection *evcon,
00734 int timeout_in_secs);
00735
00738 EVENT2_EXPORT_SYMBOL
00739 void evhttp_connection_set_timeout_tv(struct evhttp_connection *evcon,
00740 const struct timeval *tv);
00741
00746 EVENT2_EXPORT_SYMBOL
00747 void evhttp_connection_set_initial_retry_tv(struct evhttp_connection *evcon,
00748 const struct timeval *tv);
00749
00751 EVENT2_EXPORT_SYMBOL
00752 void evhttp_connection_set_retries(struct evhttp_connection *evcon,
00753 int retry_max);
00754
00756 EVENT2_EXPORT_SYMBOL
00757 void evhttp_connection_set_closecb(struct evhttp_connection *evcon,
00758 void (*)(struct evhttp_connection *, void *), void *);
00759
00761 EVENT2_EXPORT_SYMBOL
00762 void evhttp_connection_get_peer(struct evhttp_connection *evcon,
00763 char **address, ev_uint16_t *port);
00764
00771 EVENT2_EXPORT_SYMBOL
00772 const struct sockaddr*
00773 evhttp_connection_get_addr(struct evhttp_connection *evcon);
00774
00788 EVENT2_EXPORT_SYMBOL
00789 int evhttp_make_request(struct evhttp_connection *evcon,
00790 struct evhttp_request *req,
00791 enum evhttp_cmd_type type, const char *uri);
00792
00806 EVENT2_EXPORT_SYMBOL
00807 void evhttp_cancel_request(struct evhttp_request *req);
00808
00812 struct evhttp_uri;
00813
00815 EVENT2_EXPORT_SYMBOL
00816 const char *evhttp_request_get_uri(const struct evhttp_request *req);
00818 EVENT2_EXPORT_SYMBOL
00819 const struct evhttp_uri *evhttp_request_get_evhttp_uri(const struct evhttp_request *req);
00821 EVENT2_EXPORT_SYMBOL
00822 enum evhttp_cmd_type evhttp_request_get_command(const struct evhttp_request *req);
00823
00824 EVENT2_EXPORT_SYMBOL
00825 int evhttp_request_get_response_code(const struct evhttp_request *req);
00826 EVENT2_EXPORT_SYMBOL
00827 const char * evhttp_request_get_response_code_line(const struct evhttp_request *req);
00828
00830 EVENT2_EXPORT_SYMBOL
00831 struct evkeyvalq *evhttp_request_get_input_headers(struct evhttp_request *req);
00833 EVENT2_EXPORT_SYMBOL
00834 struct evkeyvalq *evhttp_request_get_output_headers(struct evhttp_request *req);
00836 EVENT2_EXPORT_SYMBOL
00837 struct evbuffer *evhttp_request_get_input_buffer(struct evhttp_request *req);
00839 EVENT2_EXPORT_SYMBOL
00840 struct evbuffer *evhttp_request_get_output_buffer(struct evhttp_request *req);
00845 EVENT2_EXPORT_SYMBOL
00846 const char *evhttp_request_get_host(struct evhttp_request *req);
00847
00848
00849
00859 EVENT2_EXPORT_SYMBOL
00860 const char *evhttp_find_header(const struct evkeyvalq *headers,
00861 const char *key);
00862
00871 EVENT2_EXPORT_SYMBOL
00872 int evhttp_remove_header(struct evkeyvalq *headers, const char *key);
00873
00883 EVENT2_EXPORT_SYMBOL
00884 int evhttp_add_header(struct evkeyvalq *headers, const char *key, const char *value);
00885
00891 EVENT2_EXPORT_SYMBOL
00892 void evhttp_clear_headers(struct evkeyvalq *headers);
00893
00894
00895
00896
00908 EVENT2_EXPORT_SYMBOL
00909 char *evhttp_encode_uri(const char *str);
00910
00925 EVENT2_EXPORT_SYMBOL
00926 char *evhttp_uriencode(const char *str, ev_ssize_t size, int space_to_plus);
00927
00942 EVENT2_EXPORT_SYMBOL
00943 char *evhttp_decode_uri(const char *uri);
00944
00960 EVENT2_EXPORT_SYMBOL
00961 char *evhttp_uridecode(const char *uri, int decode_plus,
00962 size_t *size_out);
00963
00983 EVENT2_EXPORT_SYMBOL
00984 int evhttp_parse_query(const char *uri, struct evkeyvalq *headers);
00985
01003 EVENT2_EXPORT_SYMBOL
01004 int evhttp_parse_query_str(const char *uri, struct evkeyvalq *headers);
01005
01017 EVENT2_EXPORT_SYMBOL
01018 char *evhttp_htmlescape(const char *html);
01019
01023 EVENT2_EXPORT_SYMBOL
01024 struct evhttp_uri *evhttp_uri_new(void);
01025
01030 EVENT2_EXPORT_SYMBOL
01031 void evhttp_uri_set_flags(struct evhttp_uri *uri, unsigned flags);
01032
01035 EVENT2_EXPORT_SYMBOL
01036 const char *evhttp_uri_get_scheme(const struct evhttp_uri *uri);
01041 EVENT2_EXPORT_SYMBOL
01042 const char *evhttp_uri_get_userinfo(const struct evhttp_uri *uri);
01055 EVENT2_EXPORT_SYMBOL
01056 const char *evhttp_uri_get_host(const struct evhttp_uri *uri);
01058 EVENT2_EXPORT_SYMBOL
01059 int evhttp_uri_get_port(const struct evhttp_uri *uri);
01061 EVENT2_EXPORT_SYMBOL
01062 const char *evhttp_uri_get_path(const struct evhttp_uri *uri);
01065 EVENT2_EXPORT_SYMBOL
01066 const char *evhttp_uri_get_query(const struct evhttp_uri *uri);
01069 EVENT2_EXPORT_SYMBOL
01070 const char *evhttp_uri_get_fragment(const struct evhttp_uri *uri);
01071
01074 EVENT2_EXPORT_SYMBOL
01075 int evhttp_uri_set_scheme(struct evhttp_uri *uri, const char *scheme);
01078 EVENT2_EXPORT_SYMBOL
01079 int evhttp_uri_set_userinfo(struct evhttp_uri *uri, const char *userinfo);
01082 EVENT2_EXPORT_SYMBOL
01083 int evhttp_uri_set_host(struct evhttp_uri *uri, const char *host);
01086 EVENT2_EXPORT_SYMBOL
01087 int evhttp_uri_set_port(struct evhttp_uri *uri, int port);
01090 EVENT2_EXPORT_SYMBOL
01091 int evhttp_uri_set_path(struct evhttp_uri *uri, const char *path);
01095 EVENT2_EXPORT_SYMBOL
01096 int evhttp_uri_set_query(struct evhttp_uri *uri, const char *query);
01100 EVENT2_EXPORT_SYMBOL
01101 int evhttp_uri_set_fragment(struct evhttp_uri *uri, const char *fragment);
01102
01137 EVENT2_EXPORT_SYMBOL
01138 struct evhttp_uri *evhttp_uri_parse_with_flags(const char *source_uri,
01139 unsigned flags);
01140
01153 #define EVHTTP_URI_NONCONFORMANT 0x01
01154
01156 EVENT2_EXPORT_SYMBOL
01157 struct evhttp_uri *evhttp_uri_parse(const char *source_uri);
01158
01166 EVENT2_EXPORT_SYMBOL
01167 void evhttp_uri_free(struct evhttp_uri *uri);
01168
01182 EVENT2_EXPORT_SYMBOL
01183 char *evhttp_uri_join(struct evhttp_uri *uri, char *buf, size_t limit);
01184
01185 #ifdef __cplusplus
01186 }
01187 #endif
01188
01189 #endif