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 _EVHTTP_H_
00028 #define _EVHTTP_H_
00029
00030 #include <event.h>
00031
00032 #ifdef __cplusplus
00033 extern "C" {
00034 #endif
00035
00036 #ifdef WIN32
00037 #define WIN32_LEAN_AND_MEAN
00038 #include <winsock2.h>
00039 #include <windows.h>
00040 #undef WIN32_LEAN_AND_MEAN
00041 #endif
00042
00054
00055 #define HTTP_OK 200
00056 #define HTTP_NOCONTENT 204
00057 #define HTTP_MOVEPERM 301
00058 #define HTTP_MOVETEMP 302
00059 #define HTTP_NOTMODIFIED 304
00060 #define HTTP_BADREQUEST 400
00061 #define HTTP_NOTFOUND 404
00062 #define HTTP_SERVUNAVAIL 503
00063
00064 struct evhttp;
00065 struct evhttp_request;
00066 struct evkeyvalq;
00067
00073 struct evhttp *evhttp_new(struct event_base *base);
00074
00087 int evhttp_bind_socket(struct evhttp *http, const char *address, u_short port);
00088
00102 int evhttp_bind_socket_backlog(struct evhttp *http, const char *address, u_short port, int backlog);
00103
00113 int evhttp_bind_socket_with_fd(struct evhttp *http, const char *address, u_short port);
00114
00125 int evhttp_bind_socket_backlog_fd(struct evhttp *http, const char *address, u_short port, int backlog);
00126
00143 int evhttp_accept_socket(struct evhttp *http, int fd);
00144
00158 int evhttp_del_accept_socket(struct evhttp *http, int fd);
00159
00168 void evhttp_free(struct evhttp* http);
00169
00171 void evhttp_set_cb(struct evhttp *, const char *,
00172 void (*)(struct evhttp_request *, void *), void *);
00173
00175 int evhttp_del_cb(struct evhttp *, const char *);
00176
00179 void evhttp_set_gencb(struct evhttp *,
00180 void (*)(struct evhttp_request *, void *), void *);
00181
00188 void evhttp_set_timeout(struct evhttp *, int timeout_in_secs);
00189
00196 int evhttp_set_connection_limit(struct evhttp *http, int nlimit);
00197
00203 int evhttp_get_connection_limit(struct evhttp *http);
00204
00210 int evhttp_get_connection_count(struct evhttp *http);
00211
00212
00213
00221 void evhttp_send_error(struct evhttp_request *req, int error,
00222 const char *reason);
00223
00232 void evhttp_send_reply(struct evhttp_request *req, int code,
00233 const char *reason, struct evbuffer *databuf);
00234
00244 int evhttp_send_reply_sync_begin(struct evhttp_request *req, int code,
00245 const char *reason, struct evbuffer *databuf);
00246 void evhttp_send_reply_sync_end(int nwritten, struct evhttp_request *req);
00247
00248
00249 void evhttp_send_reply_start(struct evhttp_request *, int, const char *);
00250 void evhttp_send_reply_chunk(struct evhttp_request *, struct evbuffer *);
00251 void evhttp_send_reply_end(struct evhttp_request *);
00252
00262 struct evhttp *evhttp_start(const char *address, u_short port);
00263
00264
00265
00266
00267 enum evhttp_cmd_type { EVHTTP_REQ_GET, EVHTTP_REQ_POST, EVHTTP_REQ_HEAD };
00268
00269 enum evhttp_request_kind { EVHTTP_REQUEST, EVHTTP_RESPONSE };
00270
00276 struct evhttp_request {
00277 #if defined(TAILQ_ENTRY)
00278 TAILQ_ENTRY(evhttp_request) next;
00279 #else
00280 struct {
00281 struct evhttp_request *tqe_next;
00282 struct evhttp_request **tqe_prev;
00283 } next;
00284 #endif
00285
00286
00287 struct evhttp_connection *evcon;
00288 int flags;
00289 #define EVHTTP_REQ_OWN_CONNECTION 0x0001
00290 #define EVHTTP_PROXY_REQUEST 0x0002
00291
00292 struct evkeyvalq *input_headers;
00293 struct evkeyvalq *output_headers;
00294
00295
00296 char *remote_host;
00297 u_short remote_port;
00298
00299 enum evhttp_request_kind kind;
00300 enum evhttp_cmd_type type;
00301 char *ext_method;
00302
00303 char *uri;
00304
00305 char major;
00306 char minor;
00307
00308 int response_code;
00309 char *response_code_line;
00310
00311 struct evbuffer *input_buffer;
00312 ev_int64_t ntoread;
00313 int chunked:1,
00314 userdone:1;
00315
00316 int referenced;
00317
00318 struct evbuffer *output_buffer;
00319
00320
00321 void (*cb)(struct evhttp_request *, void *);
00322 void *cb_arg;
00323
00324
00325
00326
00327
00328
00329 void (*chunk_cb)(struct evhttp_request *, void *);
00330 };
00331
00337 struct evhttp_request *evhttp_request_new(
00338 void (*cb)(struct evhttp_request *, void *), void *arg);
00339
00341 void evhttp_request_set_chunked_cb(struct evhttp_request *,
00342 void (*cb)(struct evhttp_request *, void *));
00343
00345 void evhttp_request_free(struct evhttp_request *req);
00346
00348 struct evhttp_connection *evhttp_request_get_connection(struct evhttp_request *req);
00349
00355 struct evhttp_connection *evhttp_connection_new(
00356 const char *address, unsigned short port);
00357
00359 void evhttp_connection_free(struct evhttp_connection *evcon);
00360
00362 void evhttp_connection_set_local_address(struct evhttp_connection *evcon,
00363 const char *address);
00364
00366 void evhttp_connection_set_local_port(struct evhttp_connection *evcon,
00367 unsigned short port);
00368
00370 void evhttp_connection_set_timeout(struct evhttp_connection *evcon,
00371 int timeout_in_secs);
00372
00374 void evhttp_connection_set_retries(struct evhttp_connection *evcon,
00375 int retry_max);
00376
00378 void evhttp_connection_set_closecb(struct evhttp_connection *evcon,
00379 void (*)(struct evhttp_connection *, void *), void *);
00380
00385 void evhttp_connection_set_base(struct evhttp_connection *evcon,
00386 struct event_base *base);
00387
00389 void evhttp_connection_get_peer(struct evhttp_connection *evcon,
00390 char **address, u_short *port);
00391
00393 int evhttp_make_request(struct evhttp_connection *evcon,
00394 struct evhttp_request *req,
00395 enum evhttp_cmd_type type, const char *uri);
00396
00397 const char *evhttp_request_uri(struct evhttp_request *req);
00398
00399
00400
00401 const char *evhttp_find_header(const struct evkeyvalq *, const char *);
00402 int evhttp_remove_header(struct evkeyvalq *, const char *);
00403 int evhttp_add_header(struct evkeyvalq *, const char *, const char *);
00404 void evhttp_clear_headers(struct evkeyvalq *);
00405
00406
00407
00408
00417 char *evhttp_encode_uri(const char *uri);
00418
00419
00428 char *evhttp_decode_uri(const char *uri);
00429
00430
00446 void evhttp_parse_query(const char *uri, struct evkeyvalq *headers);
00447
00448
00460 char *evhttp_htmlescape(const char *html);
00461
00462 #ifdef __cplusplus
00463 }
00464 #endif
00465
00466 #endif