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
00105 int evhttp_accept_socket(struct evhttp *http, int fd);
00106
00115 void evhttp_free(struct evhttp* http);
00116
00118 void evhttp_set_cb(struct evhttp *, const char *,
00119 void (*)(struct evhttp_request *, void *), void *);
00120
00122 int evhttp_del_cb(struct evhttp *, const char *);
00123
00126 void evhttp_set_gencb(struct evhttp *,
00127 void (*)(struct evhttp_request *, void *), void *);
00128
00135 void evhttp_set_timeout(struct evhttp *, int timeout_in_secs);
00136
00137
00138
00146 void evhttp_send_error(struct evhttp_request *req, int error,
00147 const char *reason);
00148
00157 void evhttp_send_reply(struct evhttp_request *req, int code,
00158 const char *reason, struct evbuffer *databuf);
00159
00160
00161 void evhttp_send_reply_start(struct evhttp_request *, int, const char *);
00162 void evhttp_send_reply_chunk(struct evhttp_request *, struct evbuffer *);
00163 void evhttp_send_reply_end(struct evhttp_request *);
00164
00174 struct evhttp *evhttp_start(const char *address, u_short port);
00175
00176
00177
00178
00179 enum evhttp_cmd_type { EVHTTP_REQ_GET, EVHTTP_REQ_POST, EVHTTP_REQ_HEAD };
00180
00181 enum evhttp_request_kind { EVHTTP_REQUEST, EVHTTP_RESPONSE };
00182
00188 struct evhttp_request {
00189 #if defined(TAILQ_ENTRY)
00190 TAILQ_ENTRY(evhttp_request) next;
00191 #else
00192 struct {
00193 struct evhttp_request *tqe_next;
00194 struct evhttp_request **tqe_prev;
00195 } next;
00196 #endif
00197
00198
00199 struct evhttp_connection *evcon;
00200 int flags;
00201 #define EVHTTP_REQ_OWN_CONNECTION 0x0001
00202 #define EVHTTP_PROXY_REQUEST 0x0002
00203
00204 struct evkeyvalq *input_headers;
00205 struct evkeyvalq *output_headers;
00206
00207
00208 char *remote_host;
00209 u_short remote_port;
00210
00211 enum evhttp_request_kind kind;
00212 enum evhttp_cmd_type type;
00213
00214 char *uri;
00215
00216 char major;
00217 char minor;
00218
00219 int response_code;
00220 char *response_code_line;
00221
00222 struct evbuffer *input_buffer;
00223 ev_int64_t ntoread;
00224 int chunked;
00225
00226 struct evbuffer *output_buffer;
00227
00228
00229 void (*cb)(struct evhttp_request *, void *);
00230 void *cb_arg;
00231
00232
00233
00234
00235
00236
00237 void (*chunk_cb)(struct evhttp_request *, void *);
00238 };
00239
00245 struct evhttp_request *evhttp_request_new(
00246 void (*cb)(struct evhttp_request *, void *), void *arg);
00247
00249 void evhttp_request_set_chunked_cb(struct evhttp_request *,
00250 void (*cb)(struct evhttp_request *, void *));
00251
00253 void evhttp_request_free(struct evhttp_request *req);
00254
00260 struct evhttp_connection *evhttp_connection_new(
00261 const char *address, unsigned short port);
00262
00264 void evhttp_connection_free(struct evhttp_connection *evcon);
00265
00267 void evhttp_connection_set_local_address(struct evhttp_connection *evcon,
00268 const char *address);
00269
00271 void evhttp_connection_set_local_port(struct evhttp_connection *evcon,
00272 unsigned short port);
00273
00275 void evhttp_connection_set_timeout(struct evhttp_connection *evcon,
00276 int timeout_in_secs);
00277
00279 void evhttp_connection_set_retries(struct evhttp_connection *evcon,
00280 int retry_max);
00281
00283 void evhttp_connection_set_closecb(struct evhttp_connection *evcon,
00284 void (*)(struct evhttp_connection *, void *), void *);
00285
00290 void evhttp_connection_set_base(struct evhttp_connection *evcon,
00291 struct event_base *base);
00292
00294 void evhttp_connection_get_peer(struct evhttp_connection *evcon,
00295 char **address, u_short *port);
00296
00298 int evhttp_make_request(struct evhttp_connection *evcon,
00299 struct evhttp_request *req,
00300 enum evhttp_cmd_type type, const char *uri);
00301
00302 const char *evhttp_request_uri(struct evhttp_request *req);
00303
00304
00305
00306 const char *evhttp_find_header(const struct evkeyvalq *, const char *);
00307 int evhttp_remove_header(struct evkeyvalq *, const char *);
00308 int evhttp_add_header(struct evkeyvalq *, const char *, const char *);
00309 void evhttp_clear_headers(struct evkeyvalq *);
00310
00311
00312
00313
00322 char *evhttp_encode_uri(const char *uri);
00323
00324
00333 char *evhttp_decode_uri(const char *uri);
00334
00335
00341 void evhttp_parse_query(const char *uri, struct evkeyvalq *);
00342
00343
00355 char *evhttp_htmlescape(const char *html);
00356
00357 #ifdef __cplusplus
00358 }
00359 #endif
00360
00361 #endif