~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/third_party/apr/src/include/apr_tables.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Licensed to the Apache Software Foundation (ASF) under one or more
2
 
 * contributor license agreements.  See the NOTICE file distributed with
3
 
 * this work for additional information regarding copyright ownership.
4
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
5
 
 * (the "License"); you may not use this file except in compliance with
6
 
 * the License.  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 (either NULL or having no elements)
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 (either NULL or having no elements)
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
 
/** A helper macro for accessing a member of an APR array.
124
 
 *
125
 
 * @param ary the array
126
 
 * @param i the index into the array to return
127
 
 * @param type the type of the objects stored in the array
128
 
 *
129
 
 * @return the item at index i
130
 
 */
131
 
#define APR_ARRAY_IDX(ary,i,type) (((type *)(ary)->elts)[i])
132
 
 
133
 
/** A helper macro for pushing elements into an APR array.
134
 
 *
135
 
 * @param ary the array
136
 
 * @param type the type of the objects stored in the array
137
 
 *
138
 
 * @return the location where the new object should be placed
139
 
 */
140
 
#define APR_ARRAY_PUSH(ary,type) (*((type *)apr_array_push(ary)))
141
 
 
142
 
/**
143
 
 * Remove an element from an array (as a first-in, last-out stack)
144
 
 * @param arr The array to remove an element from.
145
 
 * @return Location of the element in the array.
146
 
 * @remark If there are no elements in the array, NULL is returned.
147
 
 */
148
 
APR_DECLARE(void *) apr_array_pop(apr_array_header_t *arr);
149
 
 
150
 
/**
151
 
 * Remove all elements from an array.
152
 
 * @param arr The array to remove all elements from.
153
 
 * @remark As the underlying storage is allocated from a pool, no
154
 
 * memory is freed by this operation, but is available for reuse.
155
 
 */
156
 
APR_DECLARE(void) apr_array_clear(apr_array_header_t *arr);
157
 
 
158
 
/**
159
 
 * Concatenate two arrays together
160
 
 * @param dst The destination array, and the one to go first in the combined 
161
 
 *            array
162
 
 * @param src The source array to add to the destination array
163
 
 */
164
 
APR_DECLARE(void) apr_array_cat(apr_array_header_t *dst,
165
 
                                const apr_array_header_t *src);
166
 
 
167
 
/**
168
 
 * Copy the entire array
169
 
 * @param p The pool to allocate the copy of the array out of
170
 
 * @param arr The array to copy
171
 
 * @return An exact copy of the array passed in
172
 
 * @remark The alternate apr_array_copy_hdr copies only the header, and arranges 
173
 
 *         for the elements to be copied if (and only if) the code subsequently
174
 
 *         does a push or arraycat.
175
 
 */
176
 
APR_DECLARE(apr_array_header_t *) apr_array_copy(apr_pool_t *p,
177
 
                                      const apr_array_header_t *arr);
178
 
/**
179
 
 * Copy the headers of the array, and arrange for the elements to be copied if
180
 
 * and only if the code subsequently does a push or arraycat.
181
 
 * @param p The pool to allocate the copy of the array out of
182
 
 * @param arr The array to copy
183
 
 * @return An exact copy of the array passed in
184
 
 * @remark The alternate apr_array_copy copies the *entire* array.
185
 
 */
186
 
APR_DECLARE(apr_array_header_t *) apr_array_copy_hdr(apr_pool_t *p,
187
 
                                      const apr_array_header_t *arr);
188
 
 
189
 
/**
190
 
 * Append one array to the end of another, creating a new array in the process.
191
 
 * @param p The pool to allocate the new array out of
192
 
 * @param first The array to put first in the new array.
193
 
 * @param second The array to put second in the new array.
194
 
 * @return A new array containing the data from the two arrays passed in.
195
 
*/
196
 
APR_DECLARE(apr_array_header_t *) apr_array_append(apr_pool_t *p,
197
 
                                      const apr_array_header_t *first,
198
 
                                      const apr_array_header_t *second);
199
 
 
200
 
/**
201
 
 * Generates a new string from the apr_pool_t containing the concatenated 
202
 
 * sequence of substrings referenced as elements within the array.  The string 
203
 
 * will be empty if all substrings are empty or null, or if there are no 
204
 
 * elements in the array.  If sep is non-NUL, it will be inserted between 
205
 
 * elements as a separator.
206
 
 * @param p The pool to allocate the string out of
207
 
 * @param arr The array to generate the string from
208
 
 * @param sep The separator to use
209
 
 * @return A string containing all of the data in the array.
210
 
 */
211
 
APR_DECLARE(char *) apr_array_pstrcat(apr_pool_t *p,
212
 
                                      const apr_array_header_t *arr,
213
 
                                      const char sep);
214
 
 
215
 
/**
216
 
 * Make a new table
217
 
 * @param p The pool to allocate the pool out of
218
 
 * @param nelts The number of elements in the initial table.
219
 
 * @return The new table.
220
 
 * @warning This table can only store text data
221
 
 */
222
 
APR_DECLARE(apr_table_t *) apr_table_make(apr_pool_t *p, int nelts);
223
 
 
224
 
/**
225
 
 * Create a new table and copy another table into it
226
 
 * @param p The pool to allocate the new table out of
227
 
 * @param t The table to copy
228
 
 * @return A copy of the table passed in
229
 
 * @warning The table keys and respective values are not copied
230
 
 */
231
 
APR_DECLARE(apr_table_t *) apr_table_copy(apr_pool_t *p,
232
 
                                          const apr_table_t *t);
233
 
 
234
 
/**
235
 
 * Create a new table whose contents are deep copied from the given
236
 
 * table. A deep copy operation copies all fields, and makes copies
237
 
 * of dynamically allocated memory pointed to by the fields.
238
 
 * @param p The pool to allocate the new table out of
239
 
 * @param t The table to clone
240
 
 * @return A deep copy of the table passed in
241
 
 */
242
 
APR_DECLARE(apr_table_t *) apr_table_clone(apr_pool_t *p,
243
 
                                           const apr_table_t *t);
244
 
 
245
 
/**
246
 
 * Delete all of the elements from a table
247
 
 * @param t The table to clear
248
 
 */
249
 
APR_DECLARE(void) apr_table_clear(apr_table_t *t);
250
 
 
251
 
/**
252
 
 * Get the value associated with a given key from the table.  After this call,
253
 
 * The data is still in the table
254
 
 * @param t The table to search for the key
255
 
 * @param key The key to search for
256
 
 * @return The value associated with the key, or NULL if the key does not exist. 
257
 
 */
258
 
APR_DECLARE(const char *) apr_table_get(const apr_table_t *t, const char *key);
259
 
 
260
 
/**
261
 
 * Add a key/value pair to a table, if another element already exists with the
262
 
 * same key, this will over-write the old data.
263
 
 * @param t The table to add the data to.
264
 
 * @param key The key to use
265
 
 * @param val The value to add
266
 
 * @remark When adding data, this function makes a copy of both the key and the
267
 
 *         value.
268
 
 */
269
 
APR_DECLARE(void) apr_table_set(apr_table_t *t, const char *key,
270
 
                                const char *val);
271
 
 
272
 
/**
273
 
 * Add a key/value pair to a table, if another element already exists with the
274
 
 * same key, this will over-write the old data.
275
 
 * @param t The table to add the data to.
276
 
 * @param key The key to use
277
 
 * @param val The value to add
278
 
 * @warning When adding data, this function does not make a copy of the key or 
279
 
 *          the value, so care should be taken to ensure that the values will 
280
 
 *          not change after they have been added..
281
 
 */
282
 
APR_DECLARE(void) apr_table_setn(apr_table_t *t, const char *key,
283
 
                                 const char *val);
284
 
 
285
 
/**
286
 
 * Remove data from the table
287
 
 * @param t The table to remove data from
288
 
 * @param key The key of the data being removed
289
 
 */
290
 
APR_DECLARE(void) apr_table_unset(apr_table_t *t, const char *key);
291
 
 
292
 
/**
293
 
 * Add data to a table by merging the value with data that has already been 
294
 
 * stored
295
 
 * @param t The table to search for the data
296
 
 * @param key The key to merge data for
297
 
 * @param val The data to add
298
 
 * @remark If the key is not found, then this function acts like apr_table_add
299
 
 */
300
 
APR_DECLARE(void) apr_table_merge(apr_table_t *t, const char *key,
301
 
                                  const char *val);
302
 
 
303
 
/**
304
 
 * Add data to a table by merging the value with data that has already been 
305
 
 * stored
306
 
 * @param t The table to search for the data
307
 
 * @param key The key to merge data for
308
 
 * @param val The data to add
309
 
 * @remark If the key is not found, then this function acts like apr_table_addn
310
 
 */
311
 
APR_DECLARE(void) apr_table_mergen(apr_table_t *t, const char *key,
312
 
                                   const char *val);
313
 
 
314
 
/**
315
 
 * Add data to a table, regardless of whether there is another element with the
316
 
 * same key.
317
 
 * @param t The table to add to
318
 
 * @param key The key to use
319
 
 * @param val The value to add.
320
 
 * @remark When adding data, this function makes a copy of both the key and the
321
 
 *         value.
322
 
 */
323
 
APR_DECLARE(void) apr_table_add(apr_table_t *t, const char *key,
324
 
                                const char *val);
325
 
 
326
 
/**
327
 
 * Add data to a table, regardless of whether there is another element with the
328
 
 * same key.
329
 
 * @param t The table to add to
330
 
 * @param key The key to use
331
 
 * @param val The value to add.
332
 
 * @remark When adding data, this function does not make a copy of the key or the
333
 
 *         value, so care should be taken to ensure that the values will not 
334
 
 *         change after they have been added..
335
 
 */
336
 
APR_DECLARE(void) apr_table_addn(apr_table_t *t, const char *key,
337
 
                                 const char *val);
338
 
 
339
 
/**
340
 
 * Merge two tables into one new table
341
 
 * @param p The pool to use for the new table
342
 
 * @param overlay The first table to put in the new table
343
 
 * @param base The table to add at the end of the new table
344
 
 * @return A new table containing all of the data from the two passed in
345
 
 */
346
 
APR_DECLARE(apr_table_t *) apr_table_overlay(apr_pool_t *p,
347
 
                                             const apr_table_t *overlay,
348
 
                                             const apr_table_t *base);
349
 
 
350
 
/**
351
 
 * Declaration prototype for the iterator callback function of apr_table_do()
352
 
 * and apr_table_vdo().
353
 
 * @param rec The data passed as the first argument to apr_table_[v]do()
354
 
 * @param key The key from this iteration of the table
355
 
 * @param value The value from this iteration of the table
356
 
 * @remark Iteration continues while this callback function returns non-zero.
357
 
 * To export the callback function for apr_table_[v]do() it must be declared 
358
 
 * in the _NONSTD convention.
359
 
 */
360
 
typedef int (apr_table_do_callback_fn_t)(void *rec, const char *key, 
361
 
                                                    const char *value);
362
 
 
363
 
/** 
364
 
 * Iterate over a table running the provided function once for every
365
 
 * element in the table.  The varargs array must be a list of zero or
366
 
 * more (char *) keys followed by a NULL pointer.  If zero keys are
367
 
 * given, the @param comp function will be invoked for every element
368
 
 * in the table.  Otherwise, the function is invoked only for those
369
 
 * elements matching the keys specified.
370
 
 *
371
 
 * If an invocation of the @param comp function returns zero,
372
 
 * iteration will continue using the next specified key, if any.
373
 
 *
374
 
 * @param comp The function to run
375
 
 * @param rec The data to pass as the first argument to the function
376
 
 * @param t The table to iterate over
377
 
 * @param ... A varargs array of zero or more (char *) keys followed by NULL
378
 
 * @return FALSE if one of the comp() iterations returned zero; TRUE if all
379
 
 *            iterations returned non-zero
380
 
 * @see apr_table_do_callback_fn_t
381
 
 */
382
 
APR_DECLARE_NONSTD(int) apr_table_do(apr_table_do_callback_fn_t *comp,
383
 
                                     void *rec, const apr_table_t *t, ...)
384
 
#if defined(__GNUC__) && __GNUC__ >= 4
385
 
    __attribute__((sentinel))
386
 
#endif
387
 
    ;
388
 
 
389
 
/** 
390
 
 * Iterate over a table running the provided function once for every
391
 
 * element in the table.  The @param vp varargs parameter must be a
392
 
 * list of zero or more (char *) keys followed by a NULL pointer.  If
393
 
 * zero keys are given, the @param comp function will be invoked for
394
 
 * every element in the table.  Otherwise, the function is invoked
395
 
 * only for those elements matching the keys specified.
396
 
 *
397
 
 * If an invocation of the @param comp function returns zero,
398
 
 * iteration will continue using the next specified key, if any.
399
 
 *
400
 
 * @param comp The function to run
401
 
 * @param rec The data to pass as the first argument to the function
402
 
 * @param t The table to iterate over
403
 
 * @param vp List of zero or more (char *) keys followed by NULL
404
 
 * @return FALSE if one of the comp() iterations returned zero; TRUE if all
405
 
 *            iterations returned non-zero
406
 
 * @see apr_table_do_callback_fn_t
407
 
 */
408
 
APR_DECLARE(int) apr_table_vdo(apr_table_do_callback_fn_t *comp,
409
 
                               void *rec, const apr_table_t *t, va_list vp);
410
 
 
411
 
/** flag for overlap to use apr_table_setn */
412
 
#define APR_OVERLAP_TABLES_SET   (0)
413
 
/** flag for overlap to use apr_table_mergen */
414
 
#define APR_OVERLAP_TABLES_MERGE (1)
415
 
/**
416
 
 * For each element in table b, either use setn or mergen to add the data
417
 
 * to table a.  Which method is used is determined by the flags passed in.
418
 
 * @param a The table to add the data to.
419
 
 * @param b The table to iterate over, adding its data to table a
420
 
 * @param flags How to add the table to table a.  One of:
421
 
 *          APR_OVERLAP_TABLES_SET        Use apr_table_setn
422
 
 *          APR_OVERLAP_TABLES_MERGE      Use apr_table_mergen
423
 
 * @remark  This function is highly optimized, and uses less memory and CPU cycles
424
 
 *          than a function that just loops through table b calling other functions.
425
 
 */
426
 
/**
427
 
 * Conceptually, apr_table_overlap does this:
428
 
 *
429
 
 * <pre>
430
 
 *  apr_array_header_t *barr = apr_table_elts(b);
431
 
 *  apr_table_entry_t *belt = (apr_table_entry_t *)barr->elts;
432
 
 *  int i;
433
 
 *
434
 
 *  for (i = 0; i < barr->nelts; ++i) {
435
 
 *      if (flags & APR_OVERLAP_TABLES_MERGE) {
436
 
 *          apr_table_mergen(a, belt[i].key, belt[i].val);
437
 
 *      }
438
 
 *      else {
439
 
 *          apr_table_setn(a, belt[i].key, belt[i].val);
440
 
 *      }
441
 
 *  }
442
 
 * </pre>
443
 
 *
444
 
 *  Except that it is more efficient (less space and cpu-time) especially
445
 
 *  when b has many elements.
446
 
 *
447
 
 *  Notice the assumptions on the keys and values in b -- they must be
448
 
 *  in an ancestor of a's pool.  In practice b and a are usually from
449
 
 *  the same pool.
450
 
 */
451
 
 
452
 
APR_DECLARE(void) apr_table_overlap(apr_table_t *a, const apr_table_t *b,
453
 
                                     unsigned flags);
454
 
 
455
 
/**
456
 
 * Eliminate redundant entries in a table by either overwriting
457
 
 * or merging duplicates
458
 
 *
459
 
 * @param t Table.
460
 
 * @param flags APR_OVERLAP_TABLES_MERGE to merge, or
461
 
 *              APR_OVERLAP_TABLES_SET to overwrite
462
 
 */
463
 
APR_DECLARE(void) apr_table_compress(apr_table_t *t, unsigned flags);
464
 
 
465
 
/** @} */
466
 
 
467
 
#ifdef __cplusplus
468
 
}
469
 
#endif
470
 
 
471
 
#endif  /* ! APR_TABLES_H */