10.5. The Table API

Apache provides a general API for creating and maintaining lookup tables. Apache tables are ubiquitous, used for everything from storing the current request's outgoing HTTP headers to maintaining the list of environment variables passed to subprocesses.

Tables are similar to Perl hashes in that they are lists of key/value pairs. However, unlike a Perl hash, keys are case-insensitive, and a single key may correspond to a list of several values.[2] In addition, Apache table keys and values are always strings; arbitrary data types cannot be used.

[2] Despite the differences between Perl hashes and Apache tables, the Perl API allows programmers to access tables via tied Perl hashes. See Section 9.2.5.

10.5.1. The table and table_entry Data Types

Currently, a table is an Apache array containing array elements of the table_entry data type (defined in include/alloc.h):

typedef struct {
    char *key;   /* the key */
    char *val;   /* the value */
} table_entry;

When fetching or setting the value of a key, Apache searches for the key using a simple linear search. Since most tables are short, this usually doesn't impose a significant overhead. You will usually not want to access the table_entry directly, but use API function calls to manipulate the keys and values for you. If you do read directly from the table_entry, a note in the include file indicates that you should check the key for null. This is because the table_entry may be made part of a more sophisticated hash table ...

Get Writing Apache Modules with Perl and C now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.