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