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 <windows.h>
00039 #include <winsock2.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
00097 void evhttp_free(struct evhttp* http);
00098
00100 void evhttp_set_cb(struct evhttp *, const char *,
00101 void (*)(struct evhttp_request *, void *), void *);
00102
00104 int evhttp_del_cb(struct evhttp *, const char *);
00105
00108 void evhttp_set_gencb(struct evhttp *,
00109 void (*)(struct evhttp_request *, void *), void *);
00110
00117 void evhttp_set_timeout(struct evhttp *, int timeout_in_secs);
00118
00119
00120
00128 void evhttp_send_error(struct evhttp_request *req, int error,
00129 const char *reason);
00130
00139 void evhttp_send_reply(struct evhttp_request *req, int code,
00140 const char *reason, struct evbuffer *databuf);
00141
00142
00143 void evhttp_send_reply_start(struct evhttp_request *, int, const char *);
00144 void evhttp_send_reply_chunk(struct evhttp_request *, struct evbuffer *);
00145 void evhttp_send_reply_end(struct evhttp_request *);
00146
00156 struct evhttp *evhttp_start(const char *address, u_short port);
00157
00158
00159
00160
00161 enum evhttp_cmd_type { EVHTTP_REQ_GET, EVHTTP_REQ_POST, EVHTTP_REQ_HEAD };
00162
00163 enum evhttp_request_kind { EVHTTP_REQUEST, EVHTTP_RESPONSE };
00164
00170 struct evhttp_request {
00171 #if defined(TAILQ_ENTRY)
00172 TAILQ_ENTRY(evhttp_request) next;
00173 #else
00174 struct {
00175 struct evhttp_request *tqe_next;
00176 struct evhttp_request **tqe_prev;
00177 } next;
00178 #endif
00179
00180
00181 struct evhttp_connection *evcon;
00182 int flags;
00183 #define EVHTTP_REQ_OWN_CONNECTION 0x0001
00184 #define EVHTTP_PROXY_REQUEST 0x0002
00185
00186 struct evkeyvalq *input_headers;
00187 struct evkeyvalq *output_headers;
00188
00189
00190 char *remote_host;
00191 u_short remote_port;
00192
00193 enum evhttp_request_kind kind;
00194 enum evhttp_cmd_type type;
00195
00196 char *uri;
00197
00198 char major;
00199 char minor;
00200
00201 int got_firstline;
00202 int response_code;
00203 char *response_code_line;
00204
00205 struct evbuffer *input_buffer;
00206 ev_int64_t ntoread;
00207 int chunked;
00208
00209 struct evbuffer *output_buffer;
00210
00211
00212 void (*cb)(struct evhttp_request *, void *);
00213 void *cb_arg;
00214
00215
00216
00217
00218
00219
00220 void (*chunk_cb)(struct evhttp_request *, void *);
00221 };
00222
00228 struct evhttp_request *evhttp_request_new(
00229 void (*cb)(struct evhttp_request *, void *), void *arg);
00230
00232 void evhttp_request_set_chunked_cb(struct evhttp_request *,
00233 void (*cb)(struct evhttp_request *, void *));
00234
00236 void evhttp_request_free(struct evhttp_request *req);
00237
00243 struct evhttp_connection *evhttp_connection_new(
00244 const char *address, unsigned short port);
00245
00247 void evhttp_connection_free(struct evhttp_connection *evcon);
00248
00250 void evhttp_connection_set_local_address(struct evhttp_connection *evcon,
00251 const char *address);
00252
00254 void evhttp_connection_set_timeout(struct evhttp_connection *evcon,
00255 int timeout_in_secs);
00256
00258 void evhttp_connection_set_retries(struct evhttp_connection *evcon,
00259 int retry_max);
00260
00262 void evhttp_connection_set_closecb(struct evhttp_connection *evcon,
00263 void (*)(struct evhttp_connection *, void *), void *);
00264
00269 void evhttp_connection_set_base(struct evhttp_connection *evcon,
00270 struct event_base *base);
00271
00273 void evhttp_connection_get_peer(struct evhttp_connection *evcon,
00274 char **address, u_short *port);
00275
00277 int evhttp_make_request(struct evhttp_connection *evcon,
00278 struct evhttp_request *req,
00279 enum evhttp_cmd_type type, const char *uri);
00280
00281 const char *evhttp_request_uri(struct evhttp_request *req);
00282
00283
00284
00285 const char *evhttp_find_header(const struct evkeyvalq *, const char *);
00286 int evhttp_remove_header(struct evkeyvalq *, const char *);
00287 int evhttp_add_header(struct evkeyvalq *, const char *, const char *);
00288 void evhttp_clear_headers(struct evkeyvalq *);
00289
00290
00291
00292
00301 char *evhttp_encode_uri(const char *uri);
00302
00303
00312 char *evhttp_decode_uri(const char *uri);
00313
00314
00320 void evhttp_parse_query(const char *uri, struct evkeyvalq *);
00321
00322
00334 char *evhttp_htmlescape(const char *html);
00335
00336 #ifdef __cplusplus
00337 }
00338 #endif
00339
00340 #endif