O'Reilly logo

Writing Apache Modules with Perl and C by Lincoln Stein, Doug MacEachern

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required