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
9 ** http://www.apache.org/licenses/LICENSE-2.0
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.
25 #include "apr_tables.h"
34 * @brief Main header file...
37 * Define the generic APREQ_ macros and common data structures.
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().
46 * @remark Both the declaration and implementations must use the same macro.
48 /** APREQ_DECLARE(rettype) apeq_func(args)
50 #define APREQ_DECLARE(d) APR_DECLARE(d)
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.
58 /** APEQ_DECLARE_NONSTD(rettype) apr_func(args, ...);
60 #define APREQ_DECLARE_NONSTD(d) APR_DECLARE_NONSTD(d)
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.
68 /** extern APREQ_DECLARE_DATA type apr_variable;\n
69 * APREQ_DECLARE_DATA type apr_variable = value;
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)
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)
87 * Read chucks of data in 64k blocks from the request
90 #define APREQ_DEFAULT_READ_BLOCK_SIZE (64 * 1024)
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
98 #define APREQ_DEFAULT_READ_LIMIT (64 * 1024 * 1024)
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
105 #define APREQ_DEFAULT_BRIGADE_LIMIT (256 * 1024)
108 * Number of elements in the initial apr_table
109 * @see apr_table_make
111 #define APREQ_DEFAULT_NELTS 8
116 * Check to see if specified bit f is off in bitfield name
118 #define APREQ_FLAGS_OFF(f, name) ((f) &= ~(name##_MASK << name##_BIT))
120 * Check to see if specified bit f is on in bitfield name
122 #define APREQ_FLAGS_ON(f, name) ((f) |= (name##_MASK << name##_BIT))
124 * Get specified bit f in bitfield name
126 #define APREQ_FLAGS_GET(f, name) (((f) >> name##_BIT) & name##_MASK)
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
133 #define APREQ_FLAGS_SET(f, name, value) \
134 ((f) = (((f) & ~(name##_MASK << name##_BIT)) \
135 | ((name##_MASK & (value)) << name##_BIT)))
139 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
140 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
142 #define APREQ_CHARSET_BIT 0
146 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
147 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
149 #define APREQ_CHARSET_MASK 255
153 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
154 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
156 #define APREQ_TAINTED_BIT 8
159 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
160 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
162 #define APREQ_TAINTED_MASK 1
165 * Cookier Version Bit
166 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
167 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
170 #define APREQ_COOKIE_VERSION_BIT 11
172 * Cookie Version Mask
173 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
174 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
176 #define APREQ_COOKIE_VERSION_MASK 3
179 * Cookie's Secure Bit
180 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
181 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
183 #define APREQ_COOKIE_SECURE_BIT 13
185 * Cookie's Secure Mask
186 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
187 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
189 #define APREQ_COOKIE_SECURE_MASK 1
192 * Cookie's HttpOnly Bit
193 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
194 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
196 #define APREQ_COOKIE_HTTPONLY_BIT 14
198 * Cookie's HttpOnly Mask
199 * @see APREQ_FLAGS_OFF @see APREQ_FLAGS_ON
200 * @see APREQ_FLAGS_GET @see APREQ_FLAGS_SET
202 #define APREQ_COOKIE_HTTPONLY_MASK 1
204 /** Character encodings. */
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
213 /** @enum apreq_join_t Join type */
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. */
221 /** @enum apreq_match_t Match type */
223 APREQ_MATCH_FULL, /**< Full match only. */
224 APREQ_MATCH_PARTIAL /**< Partial matches are ok. */
227 /** @enum apreq_expires_t Expiration date format */
229 APREQ_EXPIRES_HTTP, /**< Use date formatting consistent with RFC 2616 */
230 APREQ_EXPIRES_NSCOOKIE /**< Use format consistent with Netscape's Cookie Spec */
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 */
243 * Adds the specified apreq_value_t to the apr_table_t.
245 * @param v value to add
246 * @param t add v to this table
250 * @ see apr_table_t @see apr_value_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);
265 #define apreq_attr_to_type(T,A,P) ( (T*) ((char*)(P)-offsetof(T,A)) )
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.
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
278 APREQ_DECLARE(apr_status_t) apreq_initialize(apr_pool_t *pool);
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.
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
292 APREQ_DECLARE(apr_status_t) apreq_pre_initialize(apr_pool_t *pool);
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.
299 * @param pool the same pool that was used in apreq_pre_initialize().
301 APREQ_DECLARE(apr_status_t) apreq_post_initialize(apr_pool_t *pool);