Consider the following sources (Note that I have cut out some code for
simplicity)
static int direc_handler(request_rec *r) {
struct info *direc;
// Commented out the following, but it holds the information
//direc = (struct info *)(((void **)(r->per_dir_config))[ 0]);
direc = (struct info *)ap_get_module_config(r->per_dir_config,
&all_hooks_module);
return DECLINED;
};
static void *all_hooks_create_dir_config(apr_pool_t *p, char *dirspec)
{
struct info *cfg;
cfg = (struct info *) apr_pcalloc(p, sizeof(struct info));
return (void *)cfg;
}
module AP_MODULE_DECLARE_DATA
all_hooks_module = {
STANDARD20_MODULE_STUFF,
all_hooks_create_dir_config,
all_hooks_merge_dir_config,
all_hooks_create_server_config,
all_hooks_merge_server_config,
all_hooks_cmds,
all_hooks_register_hooks
};
I am assuming the code I wrote above is correct. Here is what
happens. The module is loaded dynamically. Apache calls
create_dir_config. This returns a value. Then Apache calls my
handler, which in turn attempts to retrieve the directory
configuration information. Note that the create_dir config and
handler are working from the same URL, which is not the root url. The
problem is that when I attempt to retrieve the directory information I
get nothing.
So off I went to the sources and here is something I found. When a
dynamically loaded module is loaded the function ap_set_config_vectors
is called. This is not the problem. But if you do a back trace the
function is called from urlsection. Then going into that function and
one line above you will see the ap_set_config_vectors call, but notice
the module being used, core_module. This means I am setting the
directory information for the core module. If I then go back to my
function direc_handler and retrieve the directory information using
the base of core_module, which is zero, I do indeed get my correct cfg
information.
Now I thought ok, maybe I doing something wrong. So I checked how
mod_include.c is called up and it gets called from the function
create_default_per_dir_config. This function is implemented to use
the module index defined.
So my question is, is this a bug or am I doing something wrong? Note
that it only seems to happen when the module is loaded dynamically.
Christian Gross