You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Hroi Sigurdsson <hr...@asdf.dk> on 2001/05/16 18:32:48 UTC
config handler question (null mconfig pointer?)
Hello in the wigwam.
I'm having a difficult time implementing configuraton command handlers
:-(.
Apache always calls my command handlers with a null mconfig pointer
which makes it impossible to store any configuration (and segfaults when
I try to access anything in the typecasted structure, naturally). Stock
Apache 1.3.19.
I've prepared a very simple module which demonstrates the problem:
#include "httpd.h"
#include "http_config.h"
typedef struct {
int enabled;
int color;
char *name;
} sheep_server_config;
static void *sheep_server_conf(pool *p, server_rec *r) {
sheep_server_config *cfg = (sheep_server_config *)
ap_pcalloc(p, sizeof(sheep_server_config));
cfg->enabled = 0;
cfg->color = 0xffffff;
cfg->name = "Dolly";
return (void *) cfg;
}
static const char *sheep_toggle(cmd_parms *parms, void *mconfig, const
int toggled) {
sheep_server_config *cfg = (sheep_server_config *)mconfig;
if(mconfig == NULL) {
return "mconfig == NULL. No sheep for you :-(.";
} else {
cfg->enabled = toggled;
}
return NULL;
}
static const command_rec sheep_cmds[] =
{
{"Sheep", sheep_toggle, NULL, OR_ALL, FLAG, "toggle sheep"},
{NULL}
};
module MODULE_VAR_EXPORT sheep_module =
{
STANDARD_MODULE_STUFF,
NULL, /* initializer */
NULL, /* create per-dir config */
NULL, /* merge per-dir config */
sheep_server_conf, /* server config */
NULL, /* merge server config */
sheep_cmds, /* command table */
NULL, /* handlers */
NULL, /* filename translation */
NULL, /* check_user_id */
NULL, /* check auth */
NULL, /* check access */
NULL, /* type_checker */
NULL, /* fixups */
NULL, /* logger */
NULL, /* header parser */
NULL, /* child_init */
NULL,
NULL /* post read-request */
};
sheep_toggle() in my tests always gets called with a null mconfig
pointer.
I have added the following in my httpd.conf
LoadModule sheep_module libexec/mod_sheep.so
<VirtualHost sheep.dummy:8910>
ServerName sheep.dummy
ServerAlias www.sheep.dummy
DocumentRoot /sheep
Sheep On
</VirtualHost>
I compile/install the module using apxs -ci mod_sheep.c.
Running httpd -X gives me:
Syntax error on line 965 of /path/to/httpd.conf:
mconfig == NULL. No sheep for you :-(.
What am I doing wrong??
--
Hroi Sigurdsson hroi@netgroup.dk
Netgroup A/S http://www.netgroup.dk
Re: config handler question (null mconfig pointer?)
Posted by Hroi Sigurdsson <hr...@asdf.dk>.
On Wed, May 16, 2001 at 06:32:48PM +0200, Hroi Sigurdsson wrote:
> Apache always calls my command handlers with a null mconfig pointer
I seemed to have missed the fact that one should use get_module_config()
instead of relying on the mconfig pointer for server config handlers.
Changing the line
sheep_server_config *cfg = (sheep_server_config *)mconfig;
to
sheep_server_config *cfg = (sheep_server_config *)
ap_get_module_config(s->module_config,&sheep_module);
fixed it.
--
Hroi Sigurdsson hroi@netgroup.dk
Netgroup A/S http://www.netgroup.dk