ipc/chromium/src/third_party/libevent/http-internal.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial