1 /*
2 ** Licensed to the Apache Software Foundation (ASF) under one or more
3 ** contributor license agreements. See the NOTICE file distributed with
4 ** this work for additional information regarding copyright ownership.
5 ** The ASF licenses this file to You under the Apache License, Version 2.0
6 ** (the "License"); you may not use this file except in compliance with
7 ** the License. You may obtain a copy of the License at
8 **
9 ** http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17
18 #ifndef APREQ_H
19 #define APREQ_H
20
21 #ifdef APREQ_DEBUG
22 #include <assert.h>
23 #endif
24
25 #include "apr_tables.h"
26 #include <stddef.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 /**
33 * @file apreq.h
34 * @brief Main header file...
35 * @ingroup libapreq2
36 *
37 * Define the generic APREQ_ macros and common data structures.
38 */
39
40 #ifndef WIN32
41 /**
42 * The public APREQ functions are declared with APREQ_DECLARE(), so they may
43 * use the most appropriate calling convention. Public APR functions with
44 * variable arguments must use APR_DECLARE_NONSTD().
45 *
46 * @remark Both the declaration and implementations must use the same macro.
47 */
48 /** APREQ_DECLARE(rettype) apeq_func(args)
49 */
50 #define APREQ_DECLARE(d) APR_DECLARE(d)
51 /**
52 * The public APEQ functions using variable arguments are declared with
53 * APEQ_DECLARE_NONSTD(), as they must follow the C language calling convention.
54 * @see APEQ_DECLARE @see APEQ_DECLARE_DATA
55 * @remark Both the declaration and implementations must use the same macro.
56 * @example
57 */
58 /** APEQ_DECLARE_NONSTD(rettype) apr_func(args, ...);
59 */
60 #define APREQ_DECLARE_NONSTD(d) APR_DECLARE_NONSTD(d)
61 /**
62 * The public APREQ variables are declared with APREQ_DECLARE_DATA.
63 * This assures the appropriate indirection is invoked at compile time.
64 * @see APREQ_DECLARE @see APREQ_DECLARE_NONSTD
65 * @remark Note that the declaration and implementations use different forms,
66 * but both must include the macro.
67 */
68 /** extern APREQ_DECLARE_DATA type apr_variable;\n
69 * APREQ_DECLARE_DATA type apr_variable = value;
70 */
71 #define APREQ_DECLARE_DATA
72 #elif defined (APREQ_DECLARE_STATIC)
73 #define APREQ_DECLARE(type) type __stdcall
74 #define APREQ_DECLARE_NONSTD(type) type
75 #define APREQ_DECLARE_DATA
76 #elif defined (APREQ_DECLARE_EXPORT)
77 #define APREQ_DECLARE(type) __declspec(dllexport) type __stdcall
78 #define APREQ_DECLARE_NONSTD(type) __declspec(dllexport) type
79 #define APREQ_DECLARE_DATA __declspec(dllexport)
80 #else
81 #define APREQ_DECLARE(type) __declspec(dllimport) type __stdcall
82 #define APREQ_DECLARE_NONSTD(type) __declspec(dllimport) type
83 #define APREQ_DECLARE_DATA __declspec(dllimport)
84 #endif
85
86 /**
87 * Read chucks of data in 64k blocks from the request
88 */
89
90 #define APREQ_DEFAULT_READ_BLOCK_SIZE (64 * 1024)
91
92 /**
93 * Maximum number of bytes mod_apreq2 will send off to libapreq2 for parsing.
94 * mod_apreq2 will log this event and subsequently remove itself
95 * from the filter chain.
96 * @see ap_set_read_limit
97 */
98 #define APREQ_DEFAULT_READ_LIMIT (64 * 1024 * 1024)
99 /**
100 * Maximum number of bytes mod_apreq2 will let accumulate within the
101 * heap-buckets in a brigade. Excess data will be spooled to an
102 * appended file bucket
103 * @see ap_set_brigade_read_limit
104 */
105 #define APREQ_DEFAULT_BRIGADE_LIMIT (256 * 1024)
106
107 /**
108 * Number of elements in the initial apr_table
109 * @see apr_table_make
110 */
111 #define APREQ_DEFAULT_NELTS 8
112
113
114
115 /**
116 * Check to see if specified bit f is off in bitfield name
117 */
118 #define APREQ_FLAGS_OFF(f, name) ((f) &= ~(name##_MASK << name##_BIT))
119 /**
120 * Check to see if specified bit f is on in bitfield name
121 */
122 #define APREQ_FLAGS_ON(f, name) ((f) |= (name##_MASK << name##_BIT))
123 /**
124 * Get specified bit f in bitfield name
125 */
126 #define APREQ_FLAGS_GET(f, name) (((f) >> name##_BIT) & name##_MASK)
127 /**
128 * Set specified bit f in bitfield name to value
129 * Note the below BIT/Mask defines are used sans the
130 * _BIT, _MASK because of the this define's \#\#_MASK, \#\#_BIT usage.
131 * Each come in a pair
132 */
133 #define APREQ_FLAGS_SET(f, name, value) \
134 ((f) = (((f) & ~(name##_MASK << name##_BIT)) \
135 | ((name##_MASK & (value)) << name##_BIT)))
136
137 /**
138 * Charset Bit
139 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
140 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
141 */
142 #define APREQ_CHARSET_BIT 0
143
144 /**
145 * Charset Mask
146 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
147 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
148 */
149 #define APREQ_CHARSET_MASK 255
150
151 /**
152 * Tainted Bit
153 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
154 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
155 */
156 #define APREQ_TAINTED_BIT 8
157 /**
158 * Tainted Mask
159 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
160 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
161 */
162 #define APREQ_TAINTED_MASK 1
163
164 /**
165 * Cookier Version Bit
166 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
167 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
168 */
169
170 #define APREQ_COOKIE_VERSION_BIT 11
171 /**
172 * Cookie Version Mask
173 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
174 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
175 */
176 #define APREQ_COOKIE_VERSION_MASK 3
177
178 /**
179 * Cookie's Secure Bit
180 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
181 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
182 */
183 #define APREQ_COOKIE_SECURE_BIT 13
184 /**
185 * Cookie's Secure Mask
186 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
187 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
188 */
189 #define APREQ_COOKIE_SECURE_MASK 1
190
191 /**
192 * Cookie's HttpOnly Bit
193 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
194 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
195 */
196 #define APREQ_COOKIE_HTTPONLY_BIT 14
197 /**
198 * Cookie's HttpOnly Mask
199 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
200 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
201 */
202 #define APREQ_COOKIE_HTTPONLY_MASK 1
203
204 /** Character encodings. */
205 typedef enum {
206 APREQ_CHARSET_ASCII =0,
207 APREQ_CHARSET_LATIN1 =1, /* ISO-8859-1 */
208 APREQ_CHARSET_CP1252 =2, /* Windows-1252 */
209 APREQ_CHARSET_UTF8 =8
210 } apreq_charset_t;
211
212
213 /** @enum apreq_join_t Join type */
214 typedef enum {
215 APREQ_JOIN_AS_IS, /**< Join the strings without modification */
216 APREQ_JOIN_ENCODE, /**< Url-encode the strings before joining them */
217 APREQ_JOIN_DECODE, /**< Url-decode the strings before joining them */
218 APREQ_JOIN_QUOTE /**< Quote the strings, backslashing existing quote marks. */
219 } apreq_join_t;
220
221 /** @enum apreq_match_t Match type */
222 typedef enum {
223 APREQ_MATCH_FULL, /**< Full match only. */
224 APREQ_MATCH_PARTIAL /**< Partial matches are ok. */
225 } apreq_match_t;
226
227 /** @enum apreq_expires_t Expiration date format */
228 typedef enum {
229 APREQ_EXPIRES_HTTP, /**< Use date formatting consistent with RFC 2616 */
230 APREQ_EXPIRES_NSCOOKIE /**< Use format consistent with Netscape's Cookie Spec */
231 } apreq_expires_t;
232
233
234 /** @brief libapreq's pre-extensible string type */
235 typedef struct apreq_value_t {
236 char *name; /**< value name */
237 apr_size_t nlen; /**< length of name */
238 apr_size_t dlen; /**< length of data */
239 char data[1]; /**< value data */
240 } apreq_value_t;
241
242 /**
243 * Adds the specified apreq_value_t to the apr_table_t.
244 *
245 * @param v value to add
246 * @param t add v to this table
247 *
248 * @return void
249 *
250 * @ see apr_table_t @see apr_value_t
251 */
252
253 static APR_INLINE
apreq_value_table_add(const apreq_value_t * v,apr_table_t * t)254 void apreq_value_table_add(const apreq_value_t *v, apr_table_t *t) {
255 apr_table_addn(t, v->name, v->data);
256 }
257
258 /**
259 * @param T type
260 * @param A attribute
261 * @param P
262 *
263 * XXX
264 */
265 #define apreq_attr_to_type(T,A,P) ( (T*) ((char*)(P)-offsetof(T,A)) )
266
267 /**
268 * Initialize libapreq2. Applications (except apache modules using
269 * mod_apreq) should call this exactly once before they use any
270 * libapreq2 modules. If you want to modify the list of default parsers
271 * with apreq_register_parser(), please use apreq_pre_initialize()
272 * and apreq_post_initialize() instead.
273 *
274 * @param pool a base pool persisting while libapreq2 is used
275 * @remarks after you detroy the pool, you have to call this function again
276 * with a new pool if you still plan to use libapreq2
277 */
278 APREQ_DECLARE(apr_status_t) apreq_initialize(apr_pool_t *pool);
279
280
281 /**
282 * Pre-initialize libapreq2. Applications (except apache modules using
283 * mod_apreq2) should call this exactly once before they register custom
284 * parsers with libapreq2. mod_apreq2 does this automatically during the
285 * post-config phase, so modules that need call apreq_register_parser should
286 * create a post-config hook using APR_HOOK_MIDDLE.
287 *
288 * @param pool a base pool persisting while libapreq2 is used
289 * @remarks after you detroyed the pool, you have to call this function again
290 * with a new pool if you still plan to use libapreq2
291 */
292 APREQ_DECLARE(apr_status_t) apreq_pre_initialize(apr_pool_t *pool);
293
294 /**
295 * Post-initialize libapreq2. Applications (except apache modules using
296 * mod_apreq2) should this exactly once before they use any
297 * libapreq2 modules for parsing.
298 *
299 * @param pool the same pool that was used in apreq_pre_initialize().
300 */
301 APREQ_DECLARE(apr_status_t) apreq_post_initialize(apr_pool_t *pool);
302
303
304 #ifdef __cplusplus
305 }
306 #endif
307
308 #endif /* APREQ_H */
309