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