MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
evhttp.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2000-2004 Niels Provos <provos@citi.umich.edu>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 #ifndef _EVHTTP_H_
28 #define _EVHTTP_H_
29 
30 #include <event.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #ifdef WIN32
37 #define WIN32_LEAN_AND_MEAN
38 #include <winsock2.h>
39 #include <windows.h>
40 #undef WIN32_LEAN_AND_MEAN
41 #endif
42 
54 /* Response codes */
55 #define HTTP_OK 200
56 #define HTTP_NOCONTENT 204
57 #define HTTP_MOVEPERM 301
58 #define HTTP_MOVETEMP 302
59 #define HTTP_NOTMODIFIED 304
60 #define HTTP_BADREQUEST 400
61 #define HTTP_NOTFOUND 404
62 #define HTTP_SERVUNAVAIL 503
63 
64 struct evhttp;
65 struct evhttp_request;
66 struct evkeyvalq;
67 
73 struct evhttp *evhttp_new(struct event_base *base);
74 
87 int evhttp_bind_socket(struct evhttp *http, const char *address, u_short port);
88 
105 int evhttp_accept_socket(struct evhttp *http, int fd);
106 
115 void evhttp_free(struct evhttp* http);
116 
118 void evhttp_set_cb(struct evhttp *, const char *,
119  void (*)(struct evhttp_request *, void *), void *);
120 
122 int evhttp_del_cb(struct evhttp *, const char *);
123 
126 void evhttp_set_gencb(struct evhttp *,
127  void (*)(struct evhttp_request *, void *), void *);
128 
135 void evhttp_set_timeout(struct evhttp *, int timeout_in_secs);
136 
137 /* Request/Response functionality */
138 
146 void evhttp_send_error(struct evhttp_request *req, int error,
147  const char *reason);
148 
157 void evhttp_send_reply(struct evhttp_request *req, int code,
158  const char *reason, struct evbuffer *databuf);
159 
160 /* Low-level response interface, for streaming/chunked replies */
161 void evhttp_send_reply_start(struct evhttp_request *, int, const char *);
162 void evhttp_send_reply_chunk(struct evhttp_request *, struct evbuffer *);
163 void evhttp_send_reply_end(struct evhttp_request *);
164 
174 struct evhttp *evhttp_start(const char *address, u_short port);
175 
176 /*
177  * Interfaces for making requests
178  */
179 enum evhttp_cmd_type { EVHTTP_REQ_GET, EVHTTP_REQ_POST, EVHTTP_REQ_HEAD };
180 
181 enum evhttp_request_kind { EVHTTP_REQUEST, EVHTTP_RESPONSE };
182 
189 #if defined(TAILQ_ENTRY)
190  TAILQ_ENTRY(evhttp_request) next;
191 #else
192 struct {
193  struct evhttp_request *tqe_next;
194  struct evhttp_request **tqe_prev;
195 } next;
196 #endif
197 
198  /* the connection object that this request belongs to */
199  struct evhttp_connection *evcon;
200  int flags;
201 #define EVHTTP_REQ_OWN_CONNECTION 0x0001
202 #define EVHTTP_PROXY_REQUEST 0x0002
203 
204  struct evkeyvalq *input_headers;
205  struct evkeyvalq *output_headers;
206 
207  /* address of the remote host and the port connection came from */
208  char *remote_host;
209  u_short remote_port;
210 
211  enum evhttp_request_kind kind;
212  enum evhttp_cmd_type type;
213 
214  char *uri; /* uri after HTTP request was parsed */
215 
216  char major; /* HTTP Major number */
217  char minor; /* HTTP Minor number */
218 
219  int response_code; /* HTTP Response code */
220  char *response_code_line; /* Readable response */
221 
222  struct evbuffer *input_buffer; /* read data */
223  ev_int64_t ntoread;
224  int chunked;
225 
226  struct evbuffer *output_buffer; /* outgoing post or data */
227 
228  /* Callback */
229  void (*cb)(struct evhttp_request *, void *);
230  void *cb_arg;
231 
232  /*
233  * Chunked data callback - call for each completed chunk if
234  * specified. If not specified, all the data is delivered via
235  * the regular callback.
236  */
237  void (*chunk_cb)(struct evhttp_request *, void *);
238 };
239 
246  void (*cb)(struct evhttp_request *, void *), void *arg);
247 
250  void (*cb)(struct evhttp_request *, void *));
251 
253 void evhttp_request_free(struct evhttp_request *req);
254 
261  const char *address, unsigned short port);
262 
264 void evhttp_connection_free(struct evhttp_connection *evcon);
265 
268  const char *address);
269 
272  unsigned short port);
273 
276  int timeout_in_secs);
277 
280  int retry_max);
281 
284  void (*)(struct evhttp_connection *, void *), void *);
285 
291  struct event_base *base);
292 
295  char **address, u_short *port);
296 
298 int evhttp_make_request(struct evhttp_connection *evcon,
299  struct evhttp_request *req,
300  enum evhttp_cmd_type type, const char *uri);
301 
302 const char *evhttp_request_uri(struct evhttp_request *req);
303 
304 /* Interfaces for dealing with HTTP headers */
305 
306 const char *evhttp_find_header(const struct evkeyvalq *, const char *);
307 int evhttp_remove_header(struct evkeyvalq *, const char *);
308 int evhttp_add_header(struct evkeyvalq *, const char *, const char *);
309 void evhttp_clear_headers(struct evkeyvalq *);
310 
311 /* Miscellaneous utility functions */
312 
313 
322 char *evhttp_encode_uri(const char *uri);
323 
324 
333 char *evhttp_decode_uri(const char *uri);
334 
335 
351 void evhttp_parse_query(const char *uri, struct evkeyvalq *headers);
352 
353 
365 char *evhttp_htmlescape(const char *html);
366 
367 #ifdef __cplusplus
368 }
369 #endif
370 
371 #endif /* _EVHTTP_H_ */