Create Per-Directory Config Structure
void *module_create_dir_config(pool *pPool,char *szDir)
This structure is called once per
module, with szDir
set to NULL
,
when the main host’s configuration is initialized
and again for each <Directory>
,
<Location>
, or
<File>
section in the Config files
containing a directive from this module, with
szPath
set to the directory. Any per-directory
directives found outside <Directory>
,
<Location>
, or
<File>
sections end up in the
NULL
configuration. It is also called when
.htaccess files are parsed, with the name of the
directory in which they reside. Because this function is used for
.htaccess files, it may also be called after the
initializer is called. Also, the core caches per-directory
configurations arising from .htaccess files for
the duration of a request, so this function is called only once per
directory with an .htaccess file.
If a module does not support per-directory configuration, any
directives that appear in a <Directory>
section override the per-server configuration unless precautions are
taken. The usual way to avoid this is to set the req
_overrides
member appropriately in the command
table — see later in this section.
The purpose of this function is to allocate and initialize the memory required for any per-directory configuration. It returns a pointer to the allocated memory. See Example 21-2 (1.3) for an excerpt from mod_rewrite.c.
Example 21-2. mod_rewrite.c
static void *config_perdir_create(pool *p, char *path) { rewrite_perdir_conf *a; a = (rewrite_perdir_conf *)ap_pcalloc(p, sizeof(rewrite_perdir_conf)); a->state = ENGINE_DISABLED; a->options = OPTION_NONE; a->baseurl = NULL; a->rewriteconds = ap_make_array(p, 2, sizeof(rewritecond_entry)); a->rewriterules = ap_make_array(p, 2, sizeof(rewriterule_entry)); if (path == NULL) { a->directory = NULL; } else { /* make sure it has a trailing slash */ if (path[strlen(path)-1] == '/') { a->directory = ap_pstrdup(p, path); } else { a->directory = ap_pstrcat(p, path, "/", NULL); } } return (void *)a; }
This function allocates memory for a rewrite_
perdir_conf
structure (defined elsewhere in
mod_rewrite.c) and initializes it. Since this
function is called for every <Directory>
section, regardless of whether it contains any rewriting directives,
the initialization makes sure the engine is disabled unless
specifically enabled later.
The only changes for 2.0 in this are that pool
becomes apr_pool_t
and ap_pcalloc(
)
becomes apr_pcalloc()
.