1290001Sglebius/*
2290001Sglebius * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
3290001Sglebius * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4290001Sglebius *
5290001Sglebius * Redistribution and use in source and binary forms, with or without
6290001Sglebius * modification, are permitted provided that the following conditions
7290001Sglebius * are met:
8290001Sglebius * 1. Redistributions of source code must retain the above copyright
9290001Sglebius *    notice, this list of conditions and the following disclaimer.
10290001Sglebius * 2. Redistributions in binary form must reproduce the above copyright
11290001Sglebius *    notice, this list of conditions and the following disclaimer in the
12290001Sglebius *    documentation and/or other materials provided with the distribution.
13290001Sglebius * 3. The name of the author may not be used to endorse or promote products
14290001Sglebius *    derived from this software without specific prior written permission.
15290001Sglebius *
16290001Sglebius * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17290001Sglebius * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18290001Sglebius * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19290001Sglebius * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20290001Sglebius * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21290001Sglebius * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22290001Sglebius * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23290001Sglebius * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24290001Sglebius * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25290001Sglebius * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26290001Sglebius */
27290001Sglebius#ifndef EVENT2_HTTP_STRUCT_H_INCLUDED_
28290001Sglebius#define EVENT2_HTTP_STRUCT_H_INCLUDED_
29290001Sglebius
30290001Sglebius/** @file event2/http_struct.h
31290001Sglebius
32290001Sglebius  Data structures for http.  Using these structures may hurt forward
33290001Sglebius  compatibility with later versions of Libevent: be careful!
34290001Sglebius
35290001Sglebius */
36290001Sglebius
37290001Sglebius#ifdef __cplusplus
38290001Sglebiusextern "C" {
39290001Sglebius#endif
40290001Sglebius
41290001Sglebius#include <event2/event-config.h>
42290001Sglebius#ifdef EVENT__HAVE_SYS_TYPES_H
43290001Sglebius#include <sys/types.h>
44290001Sglebius#endif
45290001Sglebius#ifdef EVENT__HAVE_SYS_TIME_H
46290001Sglebius#include <sys/time.h>
47290001Sglebius#endif
48290001Sglebius
49290001Sglebius/* For int types. */
50290001Sglebius#include <event2/util.h>
51290001Sglebius
52290001Sglebius/**
53290001Sglebius * the request structure that a server receives.
54290001Sglebius * WARNING: expect this structure to change.  I will try to provide
55290001Sglebius * reasonable accessors.
56290001Sglebius */
57290001Sglebiusstruct evhttp_request {
58290001Sglebius#if defined(TAILQ_ENTRY)
59290001Sglebius	TAILQ_ENTRY(evhttp_request) next;
60290001Sglebius#else
61290001Sglebiusstruct {
62290001Sglebius	struct evhttp_request *tqe_next;
63290001Sglebius	struct evhttp_request **tqe_prev;
64290001Sglebius}       next;
65290001Sglebius#endif
66290001Sglebius
67290001Sglebius	/* the connection object that this request belongs to */
68290001Sglebius	struct evhttp_connection *evcon;
69290001Sglebius	int flags;
70290001Sglebius/** The request obj owns the evhttp connection and needs to free it */
71290001Sglebius#define EVHTTP_REQ_OWN_CONNECTION	0x0001
72290001Sglebius/** Request was made via a proxy */
73290001Sglebius#define EVHTTP_PROXY_REQUEST		0x0002
74290001Sglebius/** The request object is owned by the user; the user must free it */
75290001Sglebius#define EVHTTP_USER_OWNED		0x0004
76290001Sglebius/** The request will be used again upstack; freeing must be deferred */
77290001Sglebius#define EVHTTP_REQ_DEFER_FREE		0x0008
78290001Sglebius/** The request should be freed upstack */
79290001Sglebius#define EVHTTP_REQ_NEEDS_FREE		0x0010
80290001Sglebius
81290001Sglebius	struct evkeyvalq *input_headers;
82290001Sglebius	struct evkeyvalq *output_headers;
83290001Sglebius
84290001Sglebius	/* address of the remote host and the port connection came from */
85290001Sglebius	char *remote_host;
86290001Sglebius	ev_uint16_t remote_port;
87290001Sglebius
88290001Sglebius	/* cache of the hostname for evhttp_request_get_host */
89290001Sglebius	char *host_cache;
90290001Sglebius
91290001Sglebius	enum evhttp_request_kind kind;
92290001Sglebius	enum evhttp_cmd_type type;
93290001Sglebius
94290001Sglebius	size_t headers_size;
95290001Sglebius	size_t body_size;
96290001Sglebius
97290001Sglebius	char *uri;			/* uri after HTTP request was parsed */
98290001Sglebius	struct evhttp_uri *uri_elems;	/* uri elements */
99290001Sglebius
100290001Sglebius	char major;			/* HTTP Major number */
101290001Sglebius	char minor;			/* HTTP Minor number */
102290001Sglebius
103290001Sglebius	int response_code;		/* HTTP Response code */
104290001Sglebius	char *response_code_line;	/* Readable response */
105290001Sglebius
106290001Sglebius	struct evbuffer *input_buffer;	/* read data */
107290001Sglebius	ev_int64_t ntoread;
108290001Sglebius	unsigned chunked:1,		/* a chunked request */
109290001Sglebius	    userdone:1;			/* the user has sent all data */
110290001Sglebius
111290001Sglebius	struct evbuffer *output_buffer;	/* outgoing post or data */
112290001Sglebius
113290001Sglebius	/* Callback */
114290001Sglebius	void (*cb)(struct evhttp_request *, void *);
115290001Sglebius	void *cb_arg;
116290001Sglebius
117290001Sglebius	/*
118290001Sglebius	 * Chunked data callback - call for each completed chunk if
119290001Sglebius	 * specified.  If not specified, all the data is delivered via
120290001Sglebius	 * the regular callback.
121290001Sglebius	 */
122290001Sglebius	void (*chunk_cb)(struct evhttp_request *, void *);
123290001Sglebius
124290001Sglebius	/*
125290001Sglebius	 * Callback added for forked-daapd so they can collect ICY
126290001Sglebius	 * (shoutcast) metadata from the http header. If return
127290001Sglebius	 * int is negative the connection will be closed.
128290001Sglebius	 */
129290001Sglebius	int (*header_cb)(struct evhttp_request *, void *);
130290001Sglebius
131290001Sglebius	/*
132290001Sglebius	 * Error callback - called when error is occured.
133290001Sglebius	 * @see evhttp_request_error for error types.
134290001Sglebius	 *
135290001Sglebius	 * @see evhttp_request_set_error_cb()
136290001Sglebius	 */
137290001Sglebius	void (*error_cb)(enum evhttp_request_error, void *);
138290001Sglebius
139290001Sglebius	/*
140290001Sglebius	 * Send complete callback - called when the request is actually
141290001Sglebius	 * sent and completed.
142290001Sglebius	 */
143290001Sglebius	void (*on_complete_cb)(struct evhttp_request *, void *);
144290001Sglebius	void *on_complete_cb_arg;
145290001Sglebius};
146290001Sglebius
147290001Sglebius#ifdef __cplusplus
148290001Sglebius}
149290001Sglebius#endif
150290001Sglebius
151290001Sglebius#endif /* EVENT2_HTTP_STRUCT_H_INCLUDED_ */
152290001Sglebius
153