1*c43e99fdSEd Maste /*
2*c43e99fdSEd Maste  * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
3*c43e99fdSEd Maste  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4*c43e99fdSEd Maste  *
5*c43e99fdSEd Maste  * Redistribution and use in source and binary forms, with or without
6*c43e99fdSEd Maste  * modification, are permitted provided that the following conditions
7*c43e99fdSEd Maste  * are met:
8*c43e99fdSEd Maste  * 1. Redistributions of source code must retain the above copyright
9*c43e99fdSEd Maste  *    notice, this list of conditions and the following disclaimer.
10*c43e99fdSEd Maste  * 2. Redistributions in binary form must reproduce the above copyright
11*c43e99fdSEd Maste  *    notice, this list of conditions and the following disclaimer in the
12*c43e99fdSEd Maste  *    documentation and/or other materials provided with the distribution.
13*c43e99fdSEd Maste  * 3. The name of the author may not be used to endorse or promote products
14*c43e99fdSEd Maste  *    derived from this software without specific prior written permission.
15*c43e99fdSEd Maste  *
16*c43e99fdSEd Maste  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17*c43e99fdSEd Maste  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18*c43e99fdSEd Maste  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19*c43e99fdSEd Maste  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20*c43e99fdSEd Maste  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21*c43e99fdSEd Maste  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22*c43e99fdSEd Maste  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23*c43e99fdSEd Maste  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24*c43e99fdSEd Maste  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25*c43e99fdSEd Maste  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*c43e99fdSEd Maste  */
27*c43e99fdSEd Maste #ifndef EVENT2_HTTP_STRUCT_H_INCLUDED_
28*c43e99fdSEd Maste #define EVENT2_HTTP_STRUCT_H_INCLUDED_
29*c43e99fdSEd Maste 
30*c43e99fdSEd Maste /** @file event2/http_struct.h
31*c43e99fdSEd Maste 
32*c43e99fdSEd Maste   Data structures for http.  Using these structures may hurt forward
33*c43e99fdSEd Maste   compatibility with later versions of Libevent: be careful!
34*c43e99fdSEd Maste 
35*c43e99fdSEd Maste  */
36*c43e99fdSEd Maste 
37*c43e99fdSEd Maste #ifdef __cplusplus
38*c43e99fdSEd Maste extern "C" {
39*c43e99fdSEd Maste #endif
40*c43e99fdSEd Maste 
41*c43e99fdSEd Maste #include <event2/event-config.h>
42*c43e99fdSEd Maste #ifdef EVENT__HAVE_SYS_TYPES_H
43*c43e99fdSEd Maste #include <sys/types.h>
44*c43e99fdSEd Maste #endif
45*c43e99fdSEd Maste #ifdef EVENT__HAVE_SYS_TIME_H
46*c43e99fdSEd Maste #include <sys/time.h>
47*c43e99fdSEd Maste #endif
48*c43e99fdSEd Maste 
49*c43e99fdSEd Maste /* For int types. */
50*c43e99fdSEd Maste #include <event2/util.h>
51*c43e99fdSEd Maste 
52*c43e99fdSEd Maste /**
53*c43e99fdSEd Maste  * the request structure that a server receives.
54*c43e99fdSEd Maste  * WARNING: expect this structure to change.  I will try to provide
55*c43e99fdSEd Maste  * reasonable accessors.
56*c43e99fdSEd Maste  */
57*c43e99fdSEd Maste struct evhttp_request {
58*c43e99fdSEd Maste #if defined(TAILQ_ENTRY)
59*c43e99fdSEd Maste 	TAILQ_ENTRY(evhttp_request) next;
60*c43e99fdSEd Maste #else
61*c43e99fdSEd Maste struct {
62*c43e99fdSEd Maste 	struct evhttp_request *tqe_next;
63*c43e99fdSEd Maste 	struct evhttp_request **tqe_prev;
64*c43e99fdSEd Maste }       next;
65*c43e99fdSEd Maste #endif
66*c43e99fdSEd Maste 
67*c43e99fdSEd Maste 	/* the connection object that this request belongs to */
68*c43e99fdSEd Maste 	struct evhttp_connection *evcon;
69*c43e99fdSEd Maste 	int flags;
70*c43e99fdSEd Maste /** The request obj owns the evhttp connection and needs to free it */
71*c43e99fdSEd Maste #define EVHTTP_REQ_OWN_CONNECTION	0x0001
72*c43e99fdSEd Maste /** Request was made via a proxy */
73*c43e99fdSEd Maste #define EVHTTP_PROXY_REQUEST		0x0002
74*c43e99fdSEd Maste /** The request object is owned by the user; the user must free it */
75*c43e99fdSEd Maste #define EVHTTP_USER_OWNED		0x0004
76*c43e99fdSEd Maste /** The request will be used again upstack; freeing must be deferred */
77*c43e99fdSEd Maste #define EVHTTP_REQ_DEFER_FREE		0x0008
78*c43e99fdSEd Maste /** The request should be freed upstack */
79*c43e99fdSEd Maste #define EVHTTP_REQ_NEEDS_FREE		0x0010
80*c43e99fdSEd Maste 
81*c43e99fdSEd Maste 	struct evkeyvalq *input_headers;
82*c43e99fdSEd Maste 	struct evkeyvalq *output_headers;
83*c43e99fdSEd Maste 
84*c43e99fdSEd Maste 	/* address of the remote host and the port connection came from */
85*c43e99fdSEd Maste 	char *remote_host;
86*c43e99fdSEd Maste 	ev_uint16_t remote_port;
87*c43e99fdSEd Maste 
88*c43e99fdSEd Maste 	/* cache of the hostname for evhttp_request_get_host */
89*c43e99fdSEd Maste 	char *host_cache;
90*c43e99fdSEd Maste 
91*c43e99fdSEd Maste 	enum evhttp_request_kind kind;
92*c43e99fdSEd Maste 	enum evhttp_cmd_type type;
93*c43e99fdSEd Maste 
94*c43e99fdSEd Maste 	size_t headers_size;
95*c43e99fdSEd Maste 	size_t body_size;
96*c43e99fdSEd Maste 
97*c43e99fdSEd Maste 	char *uri;			/* uri after HTTP request was parsed */
98*c43e99fdSEd Maste 	struct evhttp_uri *uri_elems;	/* uri elements */
99*c43e99fdSEd Maste 
100*c43e99fdSEd Maste 	char major;			/* HTTP Major number */
101*c43e99fdSEd Maste 	char minor;			/* HTTP Minor number */
102*c43e99fdSEd Maste 
103*c43e99fdSEd Maste 	int response_code;		/* HTTP Response code */
104*c43e99fdSEd Maste 	char *response_code_line;	/* Readable response */
105*c43e99fdSEd Maste 
106*c43e99fdSEd Maste 	struct evbuffer *input_buffer;	/* read data */
107*c43e99fdSEd Maste 	ev_int64_t ntoread;
108*c43e99fdSEd Maste 	unsigned chunked:1,		/* a chunked request */
109*c43e99fdSEd Maste 	    userdone:1;			/* the user has sent all data */
110*c43e99fdSEd Maste 
111*c43e99fdSEd Maste 	struct evbuffer *output_buffer;	/* outgoing post or data */
112*c43e99fdSEd Maste 
113*c43e99fdSEd Maste 	/* Callback */
114*c43e99fdSEd Maste 	void (*cb)(struct evhttp_request *, void *);
115*c43e99fdSEd Maste 	void *cb_arg;
116*c43e99fdSEd Maste 
117*c43e99fdSEd Maste 	/*
118*c43e99fdSEd Maste 	 * Chunked data callback - call for each completed chunk if
119*c43e99fdSEd Maste 	 * specified.  If not specified, all the data is delivered via
120*c43e99fdSEd Maste 	 * the regular callback.
121*c43e99fdSEd Maste 	 */
122*c43e99fdSEd Maste 	void (*chunk_cb)(struct evhttp_request *, void *);
123*c43e99fdSEd Maste 
124*c43e99fdSEd Maste 	/*
125*c43e99fdSEd Maste 	 * Callback added for forked-daapd so they can collect ICY
126*c43e99fdSEd Maste 	 * (shoutcast) metadata from the http header. If return
127*c43e99fdSEd Maste 	 * int is negative the connection will be closed.
128*c43e99fdSEd Maste 	 */
129*c43e99fdSEd Maste 	int (*header_cb)(struct evhttp_request *, void *);
130*c43e99fdSEd Maste 
131*c43e99fdSEd Maste 	/*
132*c43e99fdSEd Maste 	 * Error callback - called when error is occured.
133*c43e99fdSEd Maste 	 * @see evhttp_request_error for error types.
134*c43e99fdSEd Maste 	 *
135*c43e99fdSEd Maste 	 * @see evhttp_request_set_error_cb()
136*c43e99fdSEd Maste 	 */
137*c43e99fdSEd Maste 	void (*error_cb)(enum evhttp_request_error, void *);
138*c43e99fdSEd Maste 
139*c43e99fdSEd Maste 	/*
140*c43e99fdSEd Maste 	 * Send complete callback - called when the request is actually
141*c43e99fdSEd Maste 	 * sent and completed.
142*c43e99fdSEd Maste 	 */
143*c43e99fdSEd Maste 	void (*on_complete_cb)(struct evhttp_request *, void *);
144*c43e99fdSEd Maste 	void *on_complete_cb_arg;
145*c43e99fdSEd Maste };
146*c43e99fdSEd Maste 
147*c43e99fdSEd Maste #ifdef __cplusplus
148*c43e99fdSEd Maste }
149*c43e99fdSEd Maste #endif
150*c43e99fdSEd Maste 
151*c43e99fdSEd Maste #endif /* EVENT2_HTTP_STRUCT_H_INCLUDED_ */
152*c43e99fdSEd Maste 
153