Hi again,
I'm finishing off my first module, but have some trouble with per server
config.
I have a simple virtualhost stanza with one added line that's causing a
segfault when I run httpd -t. The virtualhost looks like this (a
configtest runs fine with the last line commented out):
<VirtualHost 127.0.0.1:80>
ServerName sandbox
DocumentRoot /home/sandbox
AddOutputFilter my_insert php html
MYInsertFile /home/sandbox/test_config.html
</VirtualHost>
My module now has this code to handle configuration (hopefully, enough
relevant code here):
typedef struct
{
const char *search_str;
const char *insert_file;
unsigned int insert_after_on;
unsigned int globally_on;
} my_insert_srv_cfg;
static const command_rec my_ins_cmds[] =
{
AP_INIT_TAKE1("MYInsertFile",
ap_set_string_slot,
(void *) APR_OFFSETOF(my_insert_srv_cfg, insert_file),
RSRC_CONF,
"the path to the file to insert"),
AP_INIT_TAKE1("MYSearchString",
ap_set_string_slot,
(void *) APR_OFFSETOF(my_insert_srv_cfg, search_str),
RSRC_CONF,
"the search string"),
AP_INIT_FLAG("MYSetGlobalInsert",
ap_set_flag_slot,
(void *) APR_OFFSETOF(my_insert_srv_cfg, globally_on),
RSRC_CONF,
"insert globally or just first occurance (default Off)"),
AP_INIT_FLAG("MYSetInsertAfter",
ap_set_flag_slot,
(void *) APR_OFFSETOF(my_insert_srv_cfg, insert_after_on),
RSRC_CONF,
"insert after search string or before (default On)"),
{NULL}
};
static void *my_ins_create_srv_cfg(apr_pool_t *p, server_rec *s)
{
my_insert_srv_cfg *cfg = apr_pcalloc(p, sizeof *cfg);
cfg->search_str = NULL;
cfg->insert_file = NULL;
cfg->insert_after_on = 1;
cfg->globally_on = 0;
return cfg;
}
static int my_insert_filter(ap_filter_t *f, apr_bucket_brigade *bb)
{
...
my_insert_srv_cfg *cfg = ap_get_module_config(f->r->server->module_config,
&my_insert_module);
...
}
static void register_hooks(apr_pool_t *p)
{
ap_register_output_filter("MY_INSERT",
my_insert_filter,
NULL,
AP_FTYPE_CONTENT_SET);
}
module AP_MODULE_DECLARE_DATA my_insert_module =
{
STANDARD20_MODULE_STUFF,
NULL, /* create per-directory config structure */
NULL, /* merge per-directory config structures */
my_ins_create_srv_cfg, /* create per-server config structure */
NULL, /* merge per-server config structures */
my_ins_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};
The code compiles fine and works if I comment out the MYInsertFile line
in the virtualhost stanza.
Any one know if I've missed something or what I'm doing wrong?
Thanks,
--
Drew