Show Contents Previous Page Next Page Chapter 11 - C API Reference Guide, Part II / Implementing Configuration Directives in C It is often the case that a configuration directive will end up simply setting the value of a structure field without doing any additional work. There are a few directive handlers built into the Apache API to handle such common cases. Since it isn't possible for a built-in function to know anything about the
structure of a module-specific data type, these functions work by writing directly
into the module's configuration data using pointer arithmetic. You calculate
the correct offset into the structure using the XtOffsetOf() macro1
and place this offset into the command table's For example, in Example 11-3 the HelloTo
directive simply sets a string pointer in the static command_rec hello_cmds[] = { { "HelloTo", ap_set_string_slot, (void *)XtOffsetOf(hello_dir_config, to), OR_ALL, TAKE1, "Who we say hello to, default is 'world'" }, {NULL} }; The generic directive handlers and the XtOffsetOf() macro are declared in ap_config.h. The following generic directive handlers are available: const char *ap_set_string_slot (cmd_parms *parms, char *ptr, char *arg)
const char *ap_set_string_slot_lower (cmd_parms *parms, char *ptr,
char *arg)
const char *ap_set_flag_slot (cmd_parms *parms, char *ptr, int flag)
{ "SayHello", ap_set_flag_slot, (void *)XtOffsetOf(hello_dir_config, helloOn), OR_ALL, FLAG, "Should we say Hello, On or Off", },
const char *ap_set_file_slot (cmd_parms *parms, char *ptr, char *file)
{ "HelloToFile", ap_set_file_slot, (void *)XtOffsetOf(hello_dir_config, to_file), OR_ALL, TAKE1, "File containing hello message, absolute or server root relative." },
Accessing Other Modules' Configuration Information Show Contents Go to Top Previous Page Next PageAlthough it violates the principles of code encapsulation, there's no reason that one module can't access another module's configuration information. The module simply calls ap_get_module_config() with the address of the other module's If you happen to have a C module that needs to tap into the PerlSetVar configuration, you can do so by following this example: #include "modules/perl/mod_perl.h" perl_dir_config *c = (perl_dir_config *) ap_get_module_config(r->per_dir_config, &perl_module); table *perl_vars = c->vars;
char *value = ap_table_get(perl_vars, "GuestbookFile"); Before interacting with another module, it is wise to determine if the module has been configured with the server. There are a few functions that can be used to find out if a module is accessible: module *ap_find_linked_module (const char *name)
if(ap_find_linked_module("mod_proxy.c")) { /* mod_proxy is loaded */ } int ap_exists_config_define (char *name)
if(ap_exists_config_define("SSL")) { /* mod_ssl started the server with -DSSL */ } else { ... } Footnotes 1 The name XtOffsetOf() betrays this macro's origins. It was cut and pasted from the X Windows source code! Show Contents Go to Top Previous Page Next PageCopyright © 1999 by O'Reilly & Associates, Inc. |