1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/chromium/src/third_party/libevent/http-internal.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,195 @@ 1.4 +/* 1.5 + * Copyright 2001-2007 Niels Provos <provos@citi.umich.edu> 1.6 + * Copyright 2007-2012 Niels Provos and Nick Mathewson 1.7 + * 1.8 + * This header file contains definitions for dealing with HTTP requests 1.9 + * that are internal to libevent. As user of the library, you should not 1.10 + * need to know about these. 1.11 + */ 1.12 + 1.13 +#ifndef _HTTP_INTERNAL_H_ 1.14 +#define _HTTP_INTERNAL_H_ 1.15 + 1.16 +#include "event2/event_struct.h" 1.17 +#include "util-internal.h" 1.18 +#include "defer-internal.h" 1.19 + 1.20 +#define HTTP_CONNECT_TIMEOUT 45 1.21 +#define HTTP_WRITE_TIMEOUT 50 1.22 +#define HTTP_READ_TIMEOUT 50 1.23 + 1.24 +#define HTTP_PREFIX "http://" 1.25 +#define HTTP_DEFAULTPORT 80 1.26 + 1.27 +enum message_read_status { 1.28 + ALL_DATA_READ = 1, 1.29 + MORE_DATA_EXPECTED = 0, 1.30 + DATA_CORRUPTED = -1, 1.31 + REQUEST_CANCELED = -2, 1.32 + DATA_TOO_LONG = -3 1.33 +}; 1.34 + 1.35 +enum evhttp_connection_error { 1.36 + EVCON_HTTP_TIMEOUT, 1.37 + EVCON_HTTP_EOF, 1.38 + EVCON_HTTP_INVALID_HEADER, 1.39 + EVCON_HTTP_BUFFER_ERROR, 1.40 + EVCON_HTTP_REQUEST_CANCEL 1.41 +}; 1.42 + 1.43 +struct evbuffer; 1.44 +struct addrinfo; 1.45 +struct evhttp_request; 1.46 + 1.47 +/* Indicates an unknown request method. */ 1.48 +#define _EVHTTP_REQ_UNKNOWN (1<<15) 1.49 + 1.50 +enum evhttp_connection_state { 1.51 + EVCON_DISCONNECTED, /**< not currently connected not trying either*/ 1.52 + EVCON_CONNECTING, /**< tries to currently connect */ 1.53 + EVCON_IDLE, /**< connection is established */ 1.54 + EVCON_READING_FIRSTLINE,/**< reading Request-Line (incoming conn) or 1.55 + **< Status-Line (outgoing conn) */ 1.56 + EVCON_READING_HEADERS, /**< reading request/response headers */ 1.57 + EVCON_READING_BODY, /**< reading request/response body */ 1.58 + EVCON_READING_TRAILER, /**< reading request/response chunked trailer */ 1.59 + EVCON_WRITING /**< writing request/response headers/body */ 1.60 +}; 1.61 + 1.62 +struct event_base; 1.63 + 1.64 +/* A client or server connection. */ 1.65 +struct evhttp_connection { 1.66 + /* we use this tailq only if this connection was created for an http 1.67 + * server */ 1.68 + TAILQ_ENTRY(evhttp_connection) next; 1.69 + 1.70 + evutil_socket_t fd; 1.71 + struct bufferevent *bufev; 1.72 + 1.73 + struct event retry_ev; /* for retrying connects */ 1.74 + 1.75 + char *bind_address; /* address to use for binding the src */ 1.76 + u_short bind_port; /* local port for binding the src */ 1.77 + 1.78 + char *address; /* address to connect to */ 1.79 + u_short port; 1.80 + 1.81 + size_t max_headers_size; 1.82 + ev_uint64_t max_body_size; 1.83 + 1.84 + int flags; 1.85 +#define EVHTTP_CON_INCOMING 0x0001 /* only one request on it ever */ 1.86 +#define EVHTTP_CON_OUTGOING 0x0002 /* multiple requests possible */ 1.87 +#define EVHTTP_CON_CLOSEDETECT 0x0004 /* detecting if persistent close */ 1.88 + 1.89 + int timeout; /* timeout in seconds for events */ 1.90 + int retry_cnt; /* retry count */ 1.91 + int retry_max; /* maximum number of retries */ 1.92 + 1.93 + enum evhttp_connection_state state; 1.94 + 1.95 + /* for server connections, the http server they are connected with */ 1.96 + struct evhttp *http_server; 1.97 + 1.98 + TAILQ_HEAD(evcon_requestq, evhttp_request) requests; 1.99 + 1.100 + void (*cb)(struct evhttp_connection *, void *); 1.101 + void *cb_arg; 1.102 + 1.103 + void (*closecb)(struct evhttp_connection *, void *); 1.104 + void *closecb_arg; 1.105 + 1.106 + struct deferred_cb read_more_deferred_cb; 1.107 + 1.108 + struct event_base *base; 1.109 + struct evdns_base *dns_base; 1.110 +}; 1.111 + 1.112 +/* A callback for an http server */ 1.113 +struct evhttp_cb { 1.114 + TAILQ_ENTRY(evhttp_cb) next; 1.115 + 1.116 + char *what; 1.117 + 1.118 + void (*cb)(struct evhttp_request *req, void *); 1.119 + void *cbarg; 1.120 +}; 1.121 + 1.122 +/* both the http server as well as the rpc system need to queue connections */ 1.123 +TAILQ_HEAD(evconq, evhttp_connection); 1.124 + 1.125 +/* each bound socket is stored in one of these */ 1.126 +struct evhttp_bound_socket { 1.127 + TAILQ_ENTRY(evhttp_bound_socket) next; 1.128 + 1.129 + struct evconnlistener *listener; 1.130 +}; 1.131 + 1.132 +/* server alias list item. */ 1.133 +struct evhttp_server_alias { 1.134 + TAILQ_ENTRY(evhttp_server_alias) next; 1.135 + 1.136 + char *alias; /* the server alias. */ 1.137 +}; 1.138 + 1.139 +struct evhttp { 1.140 + /* Next vhost, if this is a vhost. */ 1.141 + TAILQ_ENTRY(evhttp) next_vhost; 1.142 + 1.143 + /* All listeners for this host */ 1.144 + TAILQ_HEAD(boundq, evhttp_bound_socket) sockets; 1.145 + 1.146 + TAILQ_HEAD(httpcbq, evhttp_cb) callbacks; 1.147 + 1.148 + /* All live connections on this host. */ 1.149 + struct evconq connections; 1.150 + 1.151 + TAILQ_HEAD(vhostsq, evhttp) virtualhosts; 1.152 + 1.153 + TAILQ_HEAD(aliasq, evhttp_server_alias) aliases; 1.154 + 1.155 + /* NULL if this server is not a vhost */ 1.156 + char *vhost_pattern; 1.157 + 1.158 + int timeout; 1.159 + 1.160 + size_t default_max_headers_size; 1.161 + ev_uint64_t default_max_body_size; 1.162 + 1.163 + /* Bitmask of all HTTP methods that we accept and pass to user 1.164 + * callbacks. */ 1.165 + ev_uint16_t allowed_methods; 1.166 + 1.167 + /* Fallback callback if all the other callbacks for this connection 1.168 + don't match. */ 1.169 + void (*gencb)(struct evhttp_request *req, void *); 1.170 + void *gencbarg; 1.171 + 1.172 + struct event_base *base; 1.173 +}; 1.174 + 1.175 +/* XXX most of these functions could be static. */ 1.176 + 1.177 +/* resets the connection; can be reused for more requests */ 1.178 +void evhttp_connection_reset(struct evhttp_connection *); 1.179 + 1.180 +/* connects if necessary */ 1.181 +int evhttp_connection_connect(struct evhttp_connection *); 1.182 + 1.183 +/* notifies the current request that it failed; resets connection */ 1.184 +void evhttp_connection_fail(struct evhttp_connection *, 1.185 + enum evhttp_connection_error error); 1.186 + 1.187 +enum message_read_status; 1.188 + 1.189 +enum message_read_status evhttp_parse_firstline(struct evhttp_request *, struct evbuffer*); 1.190 +enum message_read_status evhttp_parse_headers(struct evhttp_request *, struct evbuffer*); 1.191 + 1.192 +void evhttp_start_read(struct evhttp_connection *); 1.193 + 1.194 +/* response sending HTML the data in the buffer */ 1.195 +void evhttp_response_code(struct evhttp_request *, int, const char *); 1.196 +void evhttp_send_page(struct evhttp_request *, struct evbuffer *); 1.197 + 1.198 +#endif /* _HTTP_H */