Changes to update Tomato RAF.
[tomato.git] / release / src / router / dnscrypt / src / libevent / http-internal.h
blob5f66673e13aa7f6a4c60f407383c1ad041182a49
1 /*
2 * Copyright 2001-2007 Niels Provos <provos@citi.umich.edu>
3 * Copyright 2007-2012 Niels Provos and Nick Mathewson
5 * This header file contains definitions for dealing with HTTP requests
6 * that are internal to libevent. As user of the library, you should not
7 * need to know about these.
8 */
10 #ifndef _HTTP_INTERNAL_H_
11 #define _HTTP_INTERNAL_H_
13 #include "event2/event_struct.h"
14 #include "util-internal.h"
15 #include "defer-internal.h"
17 #define HTTP_CONNECT_TIMEOUT 45
18 #define HTTP_WRITE_TIMEOUT 50
19 #define HTTP_READ_TIMEOUT 50
21 #define HTTP_PREFIX "http://"
22 #define HTTP_DEFAULTPORT 80
24 enum message_read_status {
25 ALL_DATA_READ = 1,
26 MORE_DATA_EXPECTED = 0,
27 DATA_CORRUPTED = -1,
28 REQUEST_CANCELED = -2,
29 DATA_TOO_LONG = -3
32 enum evhttp_connection_error {
33 EVCON_HTTP_TIMEOUT,
34 EVCON_HTTP_EOF,
35 EVCON_HTTP_INVALID_HEADER,
36 EVCON_HTTP_BUFFER_ERROR,
37 EVCON_HTTP_REQUEST_CANCEL
40 struct evbuffer;
41 struct addrinfo;
42 struct evhttp_request;
44 /* Indicates an unknown request method. */
45 #define _EVHTTP_REQ_UNKNOWN (1<<15)
47 enum evhttp_connection_state {
48 EVCON_DISCONNECTED, /**< not currently connected not trying either*/
49 EVCON_CONNECTING, /**< tries to currently connect */
50 EVCON_IDLE, /**< connection is established */
51 EVCON_READING_FIRSTLINE,/**< reading Request-Line (incoming conn) or
52 **< Status-Line (outgoing conn) */
53 EVCON_READING_HEADERS, /**< reading request/response headers */
54 EVCON_READING_BODY, /**< reading request/response body */
55 EVCON_READING_TRAILER, /**< reading request/response chunked trailer */
56 EVCON_WRITING /**< writing request/response headers/body */
59 struct event_base;
61 /* A client or server connection. */
62 struct evhttp_connection {
63 /* we use this tailq only if this connection was created for an http
64 * server */
65 TAILQ_ENTRY(evhttp_connection) next;
67 evutil_socket_t fd;
68 struct bufferevent *bufev;
70 struct event retry_ev; /* for retrying connects */
72 char *bind_address; /* address to use for binding the src */
73 u_short bind_port; /* local port for binding the src */
75 char *address; /* address to connect to */
76 u_short port;
78 size_t max_headers_size;
79 ev_uint64_t max_body_size;
81 int flags;
82 #define EVHTTP_CON_INCOMING 0x0001 /* only one request on it ever */
83 #define EVHTTP_CON_OUTGOING 0x0002 /* multiple requests possible */
84 #define EVHTTP_CON_CLOSEDETECT 0x0004 /* detecting if persistent close */
86 int timeout; /* timeout in seconds for events */
87 int retry_cnt; /* retry count */
88 int retry_max; /* maximum number of retries */
90 enum evhttp_connection_state state;
92 /* for server connections, the http server they are connected with */
93 struct evhttp *http_server;
95 TAILQ_HEAD(evcon_requestq, evhttp_request) requests;
97 void (*cb)(struct evhttp_connection *, void *);
98 void *cb_arg;
100 void (*closecb)(struct evhttp_connection *, void *);
101 void *closecb_arg;
103 struct deferred_cb read_more_deferred_cb;
105 struct event_base *base;
106 struct evdns_base *dns_base;
109 /* A callback for an http server */
110 struct evhttp_cb {
111 TAILQ_ENTRY(evhttp_cb) next;
113 char *what;
115 void (*cb)(struct evhttp_request *req, void *);
116 void *cbarg;
119 /* both the http server as well as the rpc system need to queue connections */
120 TAILQ_HEAD(evconq, evhttp_connection);
122 /* each bound socket is stored in one of these */
123 struct evhttp_bound_socket {
124 TAILQ_ENTRY(evhttp_bound_socket) next;
126 struct evconnlistener *listener;
129 /* server alias list item. */
130 struct evhttp_server_alias {
131 TAILQ_ENTRY(evhttp_server_alias) next;
133 char *alias; /* the server alias. */
136 struct evhttp {
137 /* Next vhost, if this is a vhost. */
138 TAILQ_ENTRY(evhttp) next_vhost;
140 /* All listeners for this host */
141 TAILQ_HEAD(boundq, evhttp_bound_socket) sockets;
143 TAILQ_HEAD(httpcbq, evhttp_cb) callbacks;
145 /* All live connections on this host. */
146 struct evconq connections;
148 TAILQ_HEAD(vhostsq, evhttp) virtualhosts;
150 TAILQ_HEAD(aliasq, evhttp_server_alias) aliases;
152 /* NULL if this server is not a vhost */
153 char *vhost_pattern;
155 int timeout;
157 size_t default_max_headers_size;
158 ev_uint64_t default_max_body_size;
160 /* Bitmask of all HTTP methods that we accept and pass to user
161 * callbacks. */
162 ev_uint16_t allowed_methods;
164 /* Fallback callback if all the other callbacks for this connection
165 don't match. */
166 void (*gencb)(struct evhttp_request *req, void *);
167 void *gencbarg;
169 struct event_base *base;
172 /* XXX most of these functions could be static. */
174 /* resets the connection; can be reused for more requests */
175 void evhttp_connection_reset(struct evhttp_connection *);
177 /* connects if necessary */
178 int evhttp_connection_connect(struct evhttp_connection *);
180 /* notifies the current request that it failed; resets connection */
181 void evhttp_connection_fail(struct evhttp_connection *,
182 enum evhttp_connection_error error);
184 enum message_read_status;
186 enum message_read_status evhttp_parse_firstline(struct evhttp_request *, struct evbuffer*);
187 enum message_read_status evhttp_parse_headers(struct evhttp_request *, struct evbuffer*);
189 void evhttp_start_read(struct evhttp_connection *);
191 /* response sending HTML the data in the buffer */
192 void evhttp_response_code(struct evhttp_request *, int, const char *);
193 void evhttp_send_page(struct evhttp_request *, struct evbuffer *);
195 #endif /* _HTTP_H */