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