etc/services - sync with NetBSD-8
[minix.git] / external / bsd / libevent / dist / http-internal.h
blob838ca6f0c1a31c0fc5e6f9951bf5010d83b659f5
1 /* $NetBSD: http-internal.h,v 1.1.1.2 2013/04/11 16:43:24 christos Exp $ */
2 /*
3 * Copyright 2001-2007 Niels Provos <provos@citi.umich.edu>
4 * Copyright 2007-2012 Niels Provos and Nick Mathewson
6 * This header file contains definitions for dealing with HTTP requests
7 * that are internal to libevent. As user of the library, you should not
8 * need to know about these.
9 */
11 #ifndef _HTTP_INTERNAL_H_
12 #define _HTTP_INTERNAL_H_
14 #include "event2/event_struct.h"
15 #include "util-internal.h"
16 #include "defer-internal.h"
18 #define HTTP_CONNECT_TIMEOUT 45
19 #define HTTP_WRITE_TIMEOUT 50
20 #define HTTP_READ_TIMEOUT 50
22 #define HTTP_PREFIX "http://"
23 #define HTTP_DEFAULTPORT 80
25 enum message_read_status {
26 ALL_DATA_READ = 1,
27 MORE_DATA_EXPECTED = 0,
28 DATA_CORRUPTED = -1,
29 REQUEST_CANCELED = -2,
30 DATA_TOO_LONG = -3
33 enum evhttp_connection_error {
34 EVCON_HTTP_TIMEOUT,
35 EVCON_HTTP_EOF,
36 EVCON_HTTP_INVALID_HEADER,
37 EVCON_HTTP_BUFFER_ERROR,
38 EVCON_HTTP_REQUEST_CANCEL
41 struct evbuffer;
42 struct addrinfo;
43 struct evhttp_request;
45 /* Indicates an unknown request method. */
46 #define _EVHTTP_REQ_UNKNOWN (1<<15)
48 enum evhttp_connection_state {
49 EVCON_DISCONNECTED, /**< not currently connected not trying either*/
50 EVCON_CONNECTING, /**< tries to currently connect */
51 EVCON_IDLE, /**< connection is established */
52 EVCON_READING_FIRSTLINE,/**< reading Request-Line (incoming conn) or
53 **< Status-Line (outgoing conn) */
54 EVCON_READING_HEADERS, /**< reading request/response headers */
55 EVCON_READING_BODY, /**< reading request/response body */
56 EVCON_READING_TRAILER, /**< reading request/response chunked trailer */
57 EVCON_WRITING /**< writing request/response headers/body */
60 struct event_base;
62 /* A client or server connection. */
63 struct evhttp_connection {
64 /* we use this tailq only if this connection was created for an http
65 * server */
66 TAILQ_ENTRY(evhttp_connection) next;
68 evutil_socket_t fd;
69 struct bufferevent *bufev;
71 struct event retry_ev; /* for retrying connects */
73 char *bind_address; /* address to use for binding the src */
74 u_short bind_port; /* local port for binding the src */
76 char *address; /* address to connect to */
77 u_short port;
79 size_t max_headers_size;
80 ev_uint64_t max_body_size;
82 int flags;
83 #define EVHTTP_CON_INCOMING 0x0001 /* only one request on it ever */
84 #define EVHTTP_CON_OUTGOING 0x0002 /* multiple requests possible */
85 #define EVHTTP_CON_CLOSEDETECT 0x0004 /* detecting if persistent close */
87 int timeout; /* timeout in seconds for events */
88 int retry_cnt; /* retry count */
89 int retry_max; /* maximum number of retries */
91 enum evhttp_connection_state state;
93 /* for server connections, the http server they are connected with */
94 struct evhttp *http_server;
96 TAILQ_HEAD(evcon_requestq, evhttp_request) requests;
98 void (*cb)(struct evhttp_connection *, void *);
99 void *cb_arg;
101 void (*closecb)(struct evhttp_connection *, void *);
102 void *closecb_arg;
104 struct deferred_cb read_more_deferred_cb;
106 struct event_base *base;
107 struct evdns_base *dns_base;
110 /* A callback for an http server */
111 struct evhttp_cb {
112 TAILQ_ENTRY(evhttp_cb) next;
114 char *what;
116 void (*cb)(struct evhttp_request *req, void *);
117 void *cbarg;
120 /* both the http server as well as the rpc system need to queue connections */
121 TAILQ_HEAD(evconq, evhttp_connection);
123 /* each bound socket is stored in one of these */
124 struct evhttp_bound_socket {
125 TAILQ_ENTRY(evhttp_bound_socket) next;
127 struct evconnlistener *listener;
130 /* server alias list item. */
131 struct evhttp_server_alias {
132 TAILQ_ENTRY(evhttp_server_alias) next;
134 char *alias; /* the server alias. */
137 struct evhttp {
138 /* Next vhost, if this is a vhost. */
139 TAILQ_ENTRY(evhttp) next_vhost;
141 /* All listeners for this host */
142 TAILQ_HEAD(boundq, evhttp_bound_socket) sockets;
144 TAILQ_HEAD(httpcbq, evhttp_cb) callbacks;
146 /* All live connections on this host. */
147 struct evconq connections;
149 TAILQ_HEAD(vhostsq, evhttp) virtualhosts;
151 TAILQ_HEAD(aliasq, evhttp_server_alias) aliases;
153 /* NULL if this server is not a vhost */
154 char *vhost_pattern;
156 int timeout;
158 size_t default_max_headers_size;
159 ev_uint64_t default_max_body_size;
161 /* Bitmask of all HTTP methods that we accept and pass to user
162 * callbacks. */
163 ev_uint16_t allowed_methods;
165 /* Fallback callback if all the other callbacks for this connection
166 don't match. */
167 void (*gencb)(struct evhttp_request *req, void *);
168 void *gencbarg;
170 struct event_base *base;
173 /* XXX most of these functions could be static. */
175 /* resets the connection; can be reused for more requests */
176 void evhttp_connection_reset(struct evhttp_connection *);
178 /* connects if necessary */
179 int evhttp_connection_connect(struct evhttp_connection *);
181 /* notifies the current request that it failed; resets connection */
182 void evhttp_connection_fail(struct evhttp_connection *,
183 enum evhttp_connection_error error);
185 enum message_read_status;
187 enum message_read_status evhttp_parse_firstline(struct evhttp_request *, struct evbuffer*);
188 enum message_read_status evhttp_parse_headers(struct evhttp_request *, struct evbuffer*);
190 void evhttp_start_read(struct evhttp_connection *);
192 /* response sending HTML the data in the buffer */
193 void evhttp_response_code(struct evhttp_request *, int, const char *);
194 void evhttp_send_page(struct evhttp_request *, struct evbuffer *);
196 #endif /* _HTTP_H */