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 #ifdef WIN32
00038 #define WIN32_LEAN_AND_MEAN
00039 #include <winsock2.h>
00040 #include <windows.h>
00041 #undef WIN32_LEAN_AND_MEAN
00042 #endif
00043
00044
00045 struct evbuffer;
00046 struct event_base;
00047
00059
00060 #define HTTP_OK 200
00061 #define HTTP_NOCONTENT 204
00062 #define HTTP_MOVEPERM 301
00063 #define HTTP_MOVETEMP 302
00064 #define HTTP_NOTMODIFIED 304
00065 #define HTTP_BADREQUEST 400
00066 #define HTTP_NOTFOUND 404
00067 #define HTTP_SERVUNAVAIL 503
00069 struct evhttp;
00070 struct evhttp_request;
00071 struct evkeyvalq;
00072
00078 struct evhttp *evhttp_new(struct event_base *base);
00079
00092 int evhttp_bind_socket(struct evhttp *http, const char *address, ev_uint16_t port);
00093
00110 int evhttp_accept_socket(struct evhttp *http, evutil_socket_t fd);
00111
00120 void evhttp_free(struct evhttp* http);
00121
00131 int evhttp_set_cb(struct evhttp *http, const char *path,
00132 void (*cb)(struct evhttp_request *, void *), void *cb_arg);
00133
00135 int evhttp_del_cb(struct evhttp *, const char *);
00136
00148 void evhttp_set_gencb(struct evhttp *http,
00149 void (*cb)(struct evhttp_request *, void *), void *arg);
00150
00173 int evhttp_add_virtual_host(struct evhttp* http, const char *pattern,
00174 struct evhttp* vhost);
00175
00184 int evhttp_remove_virtual_host(struct evhttp* http, struct evhttp* vhost);
00185
00192 void evhttp_set_timeout(struct evhttp *http, int timeout_in_secs);
00193
00194
00195
00203 void evhttp_send_error(struct evhttp_request *req, int error,
00204 const char *reason);
00205
00219 void evhttp_send_reply(struct evhttp_request *req, int code,
00220 const char *reason, struct evbuffer *databuf);
00221
00222
00223
00238 void evhttp_send_reply_start(struct evhttp_request *req, int code,
00239 const char *reason);
00240
00252 void evhttp_send_reply_chunk(struct evhttp_request *req,
00253 struct evbuffer *databuf);
00259 void evhttp_send_reply_end(struct evhttp_request *req);
00260
00261
00262
00263
00264
00266 enum evhttp_cmd_type {
00267 EVHTTP_REQ_GET,
00268 EVHTTP_REQ_POST,
00269 EVHTTP_REQ_HEAD,
00270 EVHTTP_REQ_PUT,
00271 EVHTTP_REQ_DELETE
00272 };
00273
00275 enum evhttp_request_kind { EVHTTP_REQUEST, EVHTTP_RESPONSE };
00276
00282 struct evhttp_request *evhttp_request_new(
00283 void (*cb)(struct evhttp_request *, void *), void *arg);
00284
00292 void evhttp_request_set_chunked_cb(struct evhttp_request *,
00293 void (*cb)(struct evhttp_request *, void *));
00294
00296 void evhttp_request_free(struct evhttp_request *req);
00297
00303 struct evhttp_connection *evhttp_connection_base_new(
00304 struct event_base *base, const char *address, unsigned short port);
00305
00311 void evhttp_request_own(struct evhttp_request *req);
00312
00314 int evhttp_request_is_owned(struct evhttp_request *req);
00315
00317 void evhttp_connection_free(struct evhttp_connection *evcon);
00318
00320 void evhttp_connection_set_local_address(struct evhttp_connection *evcon,
00321 const char *address);
00322
00324 void evhttp_connection_set_local_port(struct evhttp_connection *evcon,
00325 ev_uint16_t port);
00326
00328 void evhttp_connection_set_timeout(struct evhttp_connection *evcon,
00329 int timeout_in_secs);
00330
00332 void evhttp_connection_set_retries(struct evhttp_connection *evcon,
00333 int retry_max);
00334
00336 void evhttp_connection_set_closecb(struct evhttp_connection *evcon,
00337 void (*)(struct evhttp_connection *, void *), void *);
00338
00340 void evhttp_connection_get_peer(struct evhttp_connection *evcon,
00341 char **address, ev_uint16_t *port);
00342
00355 int evhttp_make_request(struct evhttp_connection *evcon,
00356 struct evhttp_request *req,
00357 enum evhttp_cmd_type type, const char *uri);
00358
00372 void evhttp_cancel_request(struct evhttp_request *req);
00373
00374
00376 const char *evhttp_request_get_uri(struct evhttp_request *req);
00378 struct evkeyvalq *evhttp_request_get_input_headers(struct evhttp_request *req);
00380 struct evkeyvalq *evhttp_request_get_output_headers(struct evhttp_request *req);
00382 struct evbuffer *evhttp_request_get_input_buffer(struct evhttp_request *req);
00384 struct evbuffer *evhttp_request_get_output_buffer(struct evhttp_request *req);
00385
00386
00387
00397 const char *evhttp_find_header(const struct evkeyvalq *headers,
00398 const char *key);
00399
00408 int evhttp_remove_header(struct evkeyvalq *headers, const char *key);
00409
00419 int evhttp_add_header(struct evkeyvalq *headers, const char *key, const char *value);
00420
00426 void evhttp_clear_headers(struct evkeyvalq *headers);
00427
00428
00429
00430
00439 char *evhttp_encode_uri(const char *uri);
00440
00441
00450 char *evhttp_decode_uri(const char *uri);
00451
00452
00468 void evhttp_parse_query(const char *uri, struct evkeyvalq *headers);
00469
00470
00482 char *evhttp_htmlescape(const char *html);
00483
00484 #ifdef __cplusplus
00485 }
00486 #endif
00487
00488 #endif