Show Contents Previous Page Next Page Chapter 11 - C API Reference Guide, Part II / Customizing the Configuration Process static command_rec traffic_cmds[] =
{
{"<TrafficCopSpeedLimits", spdlimit_container_cmd, NULL,
RSRC_CONF, RAW_ARGS, "a district speed limit container"},
{"</TrafficCopSpeedLimits>", spdlimit_container_cmd_end, NULL,
RSRC_CONF, NO_ARGS, "end of speed limit container"},
{ NULL },
};
The command handler for the start-section directive uses a three-argument prototype similar to this one: const char *spdlimit_container_cmd(cmd_parms *parms,
void *mconfig, const char *args)
Everything to the right of the directive name will be passed in char *endp = strrchr(args, '>');
if (!endp) {
return "Syntax error: no terminal \">\" sign";
}
*endp = '\0';
The routine should then call ap_getword_conf() (or one of the other ap_getword_ variants) in order to parse out the arguments and take the appropriate actions: const char *pos = args;
char *nextword;
while (*pos && (nextword = ap_getword_conf(parms->pool, &pos))) {
/* do something */
}
Now the directive handler will process the contents of the container. It does this by reading directly from char line[MAX_STRING_LEN];
while (!ap_cfg_getline(line, sizeof(line), parms->config_file)) {
if (!strcasecmp(line, "</TrafficCopSpeedLimits>")) {
break;
}
/* otherwise parse the line and do something with it */
}
( Because this loop swallows the container terminator, Apache will normally never even see it. The reason for including the end-section directive in the module's command table is to catch configuration errors in which the end-section directive appears without being preceded by a matching start-section directive. The handler for this directive returns an error string: static const char *spdlimit_container_cmd_end(cmd_parms *parms,
void *mconfig)
{
return "</TrafficCopSpeedLimits> without matching
<TrafficCopSpeedLimits> section";
}
You can also write a completely generic end-section directive handler by taking advantage of the information stored in static const char *end_section(cmd_parms *parms, void *mconfig) {
return ap_pstrcat(parms->pool, parms->cmd->name,
" without matching <", parms->cmd->name + 2, " section", NULL);
}
We now turn to utility functions for manipulating strings, URIs, dates, and files. Footnotes 2 Actually, the Copyright © 1999 by O'Reilly & Associates, Inc. |
HIVE: All information for read only. Please respect copyright! |