~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/include/apr_tables.h

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
#ifndef APR_TABLES_H
 
18
#define APR_TABLES_H
 
19
 
 
20
/**
 
21
 * @file apr_tables.h
 
22
 * @brief APR Table library
 
23
 */
 
24
 
 
25
#include "apr.h"
 
26
#include "apr_pools.h"
 
27
 
 
28
#if APR_HAVE_STDARG_H
 
29
#include <stdarg.h>     /* for va_list */
 
30
#endif
 
31
 
 
32
#ifdef __cplusplus
 
33
extern "C" {
 
34
#endif /* __cplusplus */
 
35
 
 
36
/**
 
37
 * @defgroup apr_tables Table and Array Functions
 
38
 * @ingroup APR 
 
39
 * Tables are used to store entirely opaque structures 
 
40
 * for applications, while Arrays are usually used to
 
41
 * deal with string lists.
 
42
 * @{
 
43
 */
 
44
 
 
45
/** the table abstract data type */
 
46
typedef struct apr_table_t apr_table_t;
 
47
 
 
48
/** @see apr_array_header_t */
 
49
typedef struct apr_array_header_t apr_array_header_t;
 
50
 
 
51
/** An opaque array type */
 
52
struct apr_array_header_t {
 
53
    /** The pool the array is allocated out of */
 
54
    apr_pool_t *pool;
 
55
    /** The amount of memory allocated for each element of the array */
 
56
    int elt_size;
 
57
    /** The number of active elements in the array */
 
58
    int nelts;
 
59
    /** The number of elements allocated in the array */
 
60
    int nalloc;
 
61
    /** The elements in the array */
 
62
    char *elts;
 
63
};
 
64
 
 
65
/**
 
66
 * The (opaque) structure for string-content tables.
 
67
 */
 
68
typedef struct apr_table_entry_t apr_table_entry_t;
 
69
 
 
70
/** The type for each entry in a string-content table */
 
71
struct apr_table_entry_t {
 
72
    /** The key for the current table entry */
 
73
    char *key;          /* maybe NULL in future;
 
74
                         * check when iterating thru table_elts
 
75
                         */
 
76
    /** The value for the current table entry */
 
77
    char *val;
 
78
 
 
79
    /** A checksum for the key, for use by the apr_table internals */
 
80
    apr_uint32_t key_checksum;
 
81
};
 
82
 
 
83
/**
 
84
 * Get the elements from a table
 
85
 * @param t The table
 
86
 * @return An array containing the contents of the table
 
87
 */
 
88
APR_DECLARE(const apr_array_header_t *) apr_table_elts(const apr_table_t *t);
 
89
 
 
90
/**
 
91
 * Determine if the table is empty
 
92
 * @param t The table to check
 
93
 * @return True if empty, False otherwise
 
94
 */
 
95
APR_DECLARE(int) apr_is_empty_table(const apr_table_t *t);
 
96
 
 
97
/**
 
98
 * Determine if the array is empty
 
99
 * @param a The array to check
 
100
 * @return True if empty, False otherwise
 
101
 */
 
102
APR_DECLARE(int) apr_is_empty_array(const apr_array_header_t *a);
 
103
 
 
104
/**
 
105
 * Create an array
 
106
 * @param p The pool to allocate the memory out of
 
107
 * @param nelts the number of elements in the initial array
 
108
 * @param elt_size The size of each element in the array.
 
109
 * @return The new array
 
110
 */
 
111
APR_DECLARE(apr_array_header_t *) apr_array_make(apr_pool_t *p,
 
112
                                                 int nelts, int elt_size);
 
113
 
 
114
/**
 
115
 * Add a new element to an array (as a first-in, last-out stack)
 
116
 * @param arr The array to add an element to.
 
117
 * @return Location for the new element in the array.
 
118
 * @remark If there are no free spots in the array, then this function will
 
119
 *         allocate new space for the new element.
 
120
 */
 
121
APR_DECLARE(void *) apr_array_push(apr_array_header_t *arr);
 
122
 
 
123
/**
 
124
 * Remove an element from an array (as a first-in, last-out stack)
 
125
 * @param arr The array to remove an element from.
 
126
 * @return Location of the element in the array.
 
127
 * @remark If there are no elements in the array, NULL is returned.
 
128
 */
 
129
APR_DECLARE(void *) apr_array_pop(apr_array_header_t *arr);
 
130
 
 
131
/**
 
132
 * Concatenate two arrays together
 
133
 * @param dst The destination array, and the one to go first in the combined 
 
134
 *            array
 
135
 * @param src The source array to add to the destination array
 
136
 */
 
137
APR_DECLARE(void) apr_array_cat(apr_array_header_t *dst,
 
138
                                const apr_array_header_t *src);
 
139
 
 
140
/**
 
141
 * Copy the entire array
 
142
 * @param p The pool to allocate the copy of the array out of
 
143
 * @param arr The array to copy
 
144
 * @return An exact copy of the array passed in
 
145
 * @remark The alternate apr_array_copy_hdr copies only the header, and arranges 
 
146
 *         for the elements to be copied if (and only if) the code subsequently
 
147
 *         does a push or arraycat.
 
148
 */
 
149
APR_DECLARE(apr_array_header_t *) apr_array_copy(apr_pool_t *p,
 
150
                                      const apr_array_header_t *arr);
 
151
/**
 
152
 * Copy the headers of the array, and arrange for the elements to be copied if
 
153
 * and only if the code subsequently does a push or arraycat.
 
154
 * @param p The pool to allocate the copy of the array out of
 
155
 * @param arr The array to copy
 
156
 * @return An exact copy of the array passed in
 
157
 * @remark The alternate apr_array_copy copies the *entire* array.
 
158
 */
 
159
APR_DECLARE(apr_array_header_t *) apr_array_copy_hdr(apr_pool_t *p,
 
160
                                      const apr_array_header_t *arr);
 
161
 
 
162
/**
 
163
 * Append one array to the end of another, creating a new array in the process.
 
164
 * @param p The pool to allocate the new array out of
 
165
 * @param first The array to put first in the new array.
 
166
 * @param second The array to put second in the new array.
 
167
 * @return A new array containing the data from the two arrays passed in.
 
168
*/
 
169
APR_DECLARE(apr_array_header_t *) apr_array_append(apr_pool_t *p,
 
170
                                      const apr_array_header_t *first,
 
171
                                      const apr_array_header_t *second);
 
172
 
 
173
/**
 
174
 * Generates a new string from the apr_pool_t containing the concatenated 
 
175
 * sequence of substrings referenced as elements within the array.  The string 
 
176
 * will be empty if all substrings are empty or null, or if there are no 
 
177
 * elements in the array.  If sep is non-NUL, it will be inserted between 
 
178
 * elements as a separator.
 
179
 * @param p The pool to allocate the string out of
 
180
 * @param arr The array to generate the string from
 
181
 * @param sep The separator to use
 
182
 * @return A string containing all of the data in the array.
 
183
 */
 
184
APR_DECLARE(char *) apr_array_pstrcat(apr_pool_t *p,
 
185
                                      const apr_array_header_t *arr,
 
186
                                      const char sep);
 
187
 
 
188
/**
 
189
 * Make a new table
 
190
 * @param p The pool to allocate the pool out of
 
191
 * @param nelts The number of elements in the initial table.
 
192
 * @return The new table.
 
193
 * @warning This table can only store text data
 
194
 */
 
195
APR_DECLARE(apr_table_t *) apr_table_make(apr_pool_t *p, int nelts);
 
196
 
 
197
/**
 
198
 * Create a new table and copy another table into it
 
199
 * @param p The pool to allocate the new table out of
 
200
 * @param t The table to copy
 
201
 * @return A copy of the table passed in
 
202
 */
 
203
APR_DECLARE(apr_table_t *) apr_table_copy(apr_pool_t *p,
 
204
                                          const apr_table_t *t);
 
205
 
 
206
/**
 
207
 * Delete all of the elements from a table
 
208
 * @param t The table to clear
 
209
 */
 
210
APR_DECLARE(void) apr_table_clear(apr_table_t *t);
 
211
 
 
212
/**
 
213
 * Get the value associated with a given key from the table.  After this call,
 
214
 * The data is still in the table
 
215
 * @param t The table to search for the key
 
216
 * @param key The key to search for
 
217
 * @return The value associated with the key, or NULL if the key does not exist. 
 
218
 */
 
219
APR_DECLARE(const char *) apr_table_get(const apr_table_t *t, const char *key);
 
220
 
 
221
/**
 
222
 * Add a key/value pair to a table, if another element already exists with the
 
223
 * same key, this will over-write the old data.
 
224
 * @param t The table to add the data to.
 
225
 * @param key The key fo use
 
226
 * @param val The value to add
 
227
 * @remark When adding data, this function makes a copy of both the key and the
 
228
 *         value.
 
229
 */
 
230
APR_DECLARE(void) apr_table_set(apr_table_t *t, const char *key,
 
231
                                const char *val);
 
232
 
 
233
/**
 
234
 * Add a key/value pair to a table, if another element already exists with the
 
235
 * same key, this will over-write the old data.
 
236
 * @param t The table to add the data to.
 
237
 * @param key The key to use
 
238
 * @param val The value to add
 
239
 * @warning When adding data, this function does not make a copy of the key or 
 
240
 *          the value, so care should be taken to ensure that the values will 
 
241
 *          not change after they have been added..
 
242
 */
 
243
APR_DECLARE(void) apr_table_setn(apr_table_t *t, const char *key,
 
244
                                 const char *val);
 
245
 
 
246
/**
 
247
 * Remove data from the table
 
248
 * @param t The table to remove data from
 
249
 * @param key The key of the data being removed
 
250
 */
 
251
APR_DECLARE(void) apr_table_unset(apr_table_t *t, const char *key);
 
252
 
 
253
/**
 
254
 * Add data to a table by merging the value with data that has already been 
 
255
 * stored
 
256
 * @param t The table to search for the data
 
257
 * @param key The key to merge data for
 
258
 * @param val The data to add
 
259
 * @remark If the key is not found, then this function acts like apr_table_add
 
260
 */
 
261
APR_DECLARE(void) apr_table_merge(apr_table_t *t, const char *key,
 
262
                                  const char *val);
 
263
 
 
264
/**
 
265
 * Add data to a table by merging the value with data that has already been 
 
266
 * stored
 
267
 * @param t The table to search for the data
 
268
 * @param key The key to merge data for
 
269
 * @param val The data to add
 
270
 * @remark If the key is not found, then this function acts like apr_table_addn
 
271
 */
 
272
APR_DECLARE(void) apr_table_mergen(apr_table_t *t, const char *key,
 
273
                                   const char *val);
 
274
 
 
275
/**
 
276
 * Add data to a table, regardless of whether there is another element with the
 
277
 * same key.
 
278
 * @param t The table to add to
 
279
 * @param key The key to use
 
280
 * @param val The value to add.
 
281
 * @remark When adding data, this function makes a copy of both the key and the
 
282
 *         value.
 
283
 */
 
284
APR_DECLARE(void) apr_table_add(apr_table_t *t, const char *key,
 
285
                                const char *val);
 
286
 
 
287
/**
 
288
 * Add data to a table, regardless of whether there is another element with the
 
289
 * same key.
 
290
 * @param t The table to add to
 
291
 * @param key The key to use
 
292
 * @param val The value to add.
 
293
 * @remark When adding data, this function does not make a copy of the key or the
 
294
 *         value, so care should be taken to ensure that the values will not 
 
295
 *         change after they have been added..
 
296
 */
 
297
APR_DECLARE(void) apr_table_addn(apr_table_t *t, const char *key,
 
298
                                 const char *val);
 
299
 
 
300
/**
 
301
 * Merge two tables into one new table
 
302
 * @param p The pool to use for the new table
 
303
 * @param overlay The first table to put in the new table
 
304
 * @param base The table to add at the end of the new table
 
305
 * @return A new table containing all of the data from the two passed in
 
306
 */
 
307
APR_DECLARE(apr_table_t *) apr_table_overlay(apr_pool_t *p,
 
308
                                             const apr_table_t *overlay,
 
309
                                             const apr_table_t *base);
 
310
 
 
311
/**
 
312
 * Declaration prototype for the iterator callback function of apr_table_do()
 
313
 * and apr_table_vdo().
 
314
 * @param rec The data passed as the first argument to apr_table_[v]do()
 
315
 * @param key The key from this iteration of the table
 
316
 * @param value The value from this iteration of the table
 
317
 * @remark Iteration continues while this callback function returns non-zero.
 
318
 * To export the callback function for apr_table_[v]do() it must be declared 
 
319
 * in the _NONSTD convention.
 
320
 */
 
321
typedef int (apr_table_do_callback_fn_t)(void *rec, const char *key, 
 
322
                                                    const char *value);
 
323
 
 
324
/** 
 
325
 * Iterate over a table running the provided function once for every
 
326
 * element in the table.  If there is data passed in as a vararg, then the 
 
327
 * function is only run on those elements whose key matches something in 
 
328
 * the vararg.  If the vararg is NULL, then every element is run through the
 
329
 * function.  Iteration continues while the function returns non-zero.
 
330
 * @param comp The function to run
 
331
 * @param rec The data to pass as the first argument to the function
 
332
 * @param t The table to iterate over
 
333
 * @param ... The vararg.  If this is NULL, then all elements in the table are
 
334
 *            run through the function, otherwise only those whose key matches
 
335
 *            are run.
 
336
 * @return FALSE if one of the comp() iterations returned zero; TRUE if all
 
337
 *            iterations returned non-zero
 
338
 * @see apr_table_do_callback_fn_t
 
339
 */
 
340
APR_DECLARE_NONSTD(int) apr_table_do(apr_table_do_callback_fn_t *comp,
 
341
                                     void *rec, const apr_table_t *t, ...);
 
342
 
 
343
/** 
 
344
 * Iterate over a table running the provided function once for every
 
345
 * element in the table.  If there is data passed in as a vararg, then the 
 
346
 * function is only run on those element's whose key matches something in 
 
347
 * the vararg.  If the vararg is NULL, then every element is run through the
 
348
 * function.  Iteration continues while the function returns non-zero.
 
349
 * @param comp The function to run
 
350
 * @param rec The data to pass as the first argument to the function
 
351
 * @param t The table to iterate over
 
352
 * @param vp The vararg table.  If this is NULL, then all elements in the 
 
353
 *                table are run through the function, otherwise only those 
 
354
 *                whose key matches are run.
 
355
 * @return FALSE if one of the comp() iterations returned zero; TRUE if all
 
356
 *            iterations returned non-zero
 
357
 * @see apr_table_do_callback_fn_t
 
358
 */
 
359
APR_DECLARE(int) apr_table_vdo(apr_table_do_callback_fn_t *comp,
 
360
                               void *rec, const apr_table_t *t, va_list vp);
 
361
 
 
362
/** flag for overlap to use apr_table_setn */
 
363
#define APR_OVERLAP_TABLES_SET   (0)
 
364
/** flag for overlap to use apr_table_mergen */
 
365
#define APR_OVERLAP_TABLES_MERGE (1)
 
366
/**
 
367
 * For each element in table b, either use setn or mergen to add the data
 
368
 * to table a.  Which method is used is determined by the flags passed in.
 
369
 * @param a The table to add the data to.
 
370
 * @param b The table to iterate over, adding its data to table a
 
371
 * @param flags How to add the table to table a.  One of:
 
372
 *          APR_OVERLAP_TABLES_SET        Use apr_table_setn
 
373
 *          APR_OVERLAP_TABLES_MERGE      Use apr_table_mergen
 
374
 * @remark  This function is highly optimized, and uses less memory and CPU cycles
 
375
 *          than a function that just loops through table b calling other functions.
 
376
 */
 
377
/**
 
378
 *<PRE>
 
379
 * Conceptually, apr_table_overlap does this:
 
380
 *
 
381
 *  apr_array_header_t *barr = apr_table_elts(b);
 
382
 *  apr_table_entry_t *belt = (apr_table_entry_t *)barr->elts;
 
383
 *  int i;
 
384
 *
 
385
 *  for (i = 0; i < barr->nelts; ++i) {
 
386
 *      if (flags & APR_OVERLAP_TABLES_MERGE) {
 
387
 *          apr_table_mergen(a, belt[i].key, belt[i].val);
 
388
 *      }
 
389
 *      else {
 
390
 *          apr_table_setn(a, belt[i].key, belt[i].val);
 
391
 *      }
 
392
 *  }
 
393
 *
 
394
 *  Except that it is more efficient (less space and cpu-time) especially
 
395
 *  when b has many elements.
 
396
 *
 
397
 *  Notice the assumptions on the keys and values in b -- they must be
 
398
 *  in an ancestor of a's pool.  In practice b and a are usually from
 
399
 *  the same pool.
 
400
 * </PRE>
 
401
 */
 
402
 
 
403
APR_DECLARE(void) apr_table_overlap(apr_table_t *a, const apr_table_t *b,
 
404
                                     unsigned flags);
 
405
 
 
406
/**
 
407
 * Eliminate redundant entries in a table by either overwriting
 
408
 * or merging duplicates
 
409
 *
 
410
 * @param t Table.
 
411
 * @param flags APR_OVERLAP_TABLES_MERGE to merge, or
 
412
 *              APR_OVERLAP_TABLES_SET to overwrite
 
413
 */
 
414
APR_DECLARE(void) apr_table_compress(apr_table_t *t, unsigned flags);
 
415
 
 
416
/** @} */
 
417
 
 
418
#ifdef __cplusplus
 
419
}
 
420
#endif
 
421
 
 
422
#endif  /* ! APR_TABLES_H */