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