Attached is a patch that adds a new configuration command type.
It uses the traditional argv/argc. I grew tired of having to make
commands more complicated by using RAW_ARGS, when there is no need.
The patch includes changing 'IndexOptions' to use the new
AP_INIT_TAKE_ARGV, instead of RAW_ARGS. It also adds a minor MMN bump
for the new interface.
Comments/thoughts/flames/etc welcome...
-Paul
Index: server/config.c
===================================================================
--- server/config.c (revision 168162)
+++ server/config.c (working copy)
@@ -648,6 +648,8 @@
* invoking the function...
*/
+#define AP_MAX_ARGC 64
+
static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
void *mconfig, const char *args)
{
@@ -667,6 +669,20 @@
#endif
return cmd->AP_RAW_ARGS(parms, mconfig, args);
+ case TAKE_ARGV:
+ {
+ char *argv[AP_MAX_ARGC];
+ int argc = 0;
+
+ do {
+ w = ap_getword_conf(parms->pool, &args);
+ argv[argc] = w;
+ argc++;
+ } while (argc < AP_MAX_ARGC && *args != '\0');
+
+ return cmd->AP_TAKE_ARGV(parms, mconfig, argc, argv);
+ }
+
case NO_ARGS:
if (*args != 0)
return apr_pstrcat(parms->pool, cmd->name, " takes no arguments",
Index: modules/generators/mod_autoindex.c
===================================================================
--- modules/generators/mod_autoindex.c (revision 168162)
+++ modules/generators/mod_autoindex.c (working copy)
@@ -312,8 +312,9 @@
return NULL;
}
-static const char *add_opts(cmd_parms *cmd, void *d, const char *optstr)
+static const char *add_opts(cmd_parms *cmd, void *d, int argc, char *const
argv[])
{
+ int i;
char *w;
apr_int32_t opts;
apr_int32_t opts_add;
@@ -324,10 +325,11 @@
opts = d_cfg->opts;
opts_add = d_cfg->incremented_opts;
opts_remove = d_cfg->decremented_opts;
- while (optstr[0]) {
+
+ for (i = 0; i < argc; i++) {
int option = 0;
+ w = argv[i];
- w = ap_getword_conf(cmd->pool, &optstr);
if ((*w == '+') || (*w == '-')) {
action = *(w++);
}
@@ -554,8 +556,8 @@
AP_INIT_ITERATE2("AddAltByEncoding", add_alt, BY_ENCODING, DIR_CMD_PERMS,
"alternate descriptive text followed by one or more "
"content encodings"),
- AP_INIT_RAW_ARGS("IndexOptions", add_opts, NULL, DIR_CMD_PERMS,
- "one or more index options [+|-][]"),
+ AP_INIT_TAKE_ARGV("IndexOptions", add_opts, NULL, DIR_CMD_PERMS,
+ "one or more index options [+|-][]"),
AP_INIT_TAKE2("IndexOrderDefault", set_default_order, NULL, DIR_CMD_PERMS,
"{Ascending,Descending} {Name,Size,Description,Date}"),
AP_INIT_ITERATE("IndexIgnore", add_ignore, NULL, DIR_CMD_PERMS,
Index: include/http_config.h
===================================================================
--- include/http_config.h (revision 168162)
+++ include/http_config.h (working copy)
@@ -57,7 +57,8 @@
TAKE3, /**< three arguments only */
TAKE23, /**< two or three arguments */
TAKE123, /**< one, two or three arguments */
- TAKE13 /**< one or three arguments */
+ TAKE13, /**< one or three arguments */
+ TAKE_ARGV /**< an argc and argv are passed */
};
/**
* This structure is passed to a command which is being invoked,
@@ -78,6 +79,9 @@
/** function to call for a raw-args */
const char *(*raw_args) (cmd_parms *parms, void *mconfig,
const char *args);
+ /** function to call for a argv/argc */
+ const char *(*take_argv) (cmd_parms *parms, void *mconfig,
+ int argc, char *const argv[]);
/** function to call for a take1 */
const char *(*take1) (cmd_parms *parms, void *mconfig, const char *w);
/** function to call for a take2 */
@@ -94,6 +98,8 @@
# define AP_NO_ARGS func.no_args
/** This configuration directive will handle it's own parsing of arguments*/
# define AP_RAW_ARGS func.raw_args
+/** This configuration directive will handle it's own parsing of arguments*/
+# define AP_TAKE_ARGV func.take_argv
/** This configuration directive takes 1 argument*/
# define AP_TAKE1 func.take1
/** This configuration directive takes 2 arguments */
@@ -109,6 +115,9 @@
/** method of declaring a directive with raw argument parsing */
# define AP_INIT_RAW_ARGS(directive, func, mconfig, where, help) \
{ directive, { .raw_args=func }, mconfig, where, RAW_ARGS, help }
+/** method of declaring a directive with raw argument parsing */
+# define AP_INIT_TAKE_ARGV(directive, func, mconfig, where, help) \
+ { directive, { .take_argv=func }, mconfig, where, TAKE_ARGV, help }
/** method of declaring a directive which takes 1 argument */
# define AP_INIT_TAKE1(directive, func, mconfig, where, help) \
{ directive, { .take1=func }, mconfig, where, TAKE1, help }
@@ -146,6 +155,7 @@
# define AP_NO_ARGS func
# define AP_RAW_ARGS func
+# define AP_TAKE_ARGV func
# define AP_TAKE1 func
# define AP_TAKE2 func
# define AP_TAKE3 func
@@ -155,6 +165,8 @@
{ directive, func, mconfig, where, RAW_ARGS, help }
# define AP_INIT_RAW_ARGS(directive, func, mconfig, where, help) \
{ directive, func, mconfig, where, RAW_ARGS, help }
+# define AP_INIT_TAKE_ARGV(directive, func, mconfig, where, help) \
+ { directive, func, mconfig, where, TAKE_ARGV, help }
# define AP_INIT_TAKE1(directive, func, mconfig, where, help) \
{ directive, func, mconfig, where, TAKE1, help }
# define AP_INIT_ITERATE(directive, func, mconfig, where, help) \
Index: include/ap_mmn.h
===================================================================
--- include/ap_mmn.h (revision 168162)
+++ include/ap_mmn.h (working copy)
@@ -94,6 +94,7 @@
* with ap_ in the win32 os.h.
* 20050305.0 (2.1.4-dev) added pid and generation fields to worker_score
* 20050305.1 (2.1.5-dev) added ap_vhost_iterate_given_conn.
+ * 20050305.2 (2.1.5-dev) added AP_INIT_TAKE_ARGV.
*/
#define MODULE_MAGIC_COOKIE 0x41503230UL /* "AP20" */
@@ -101,7 +102,7 @@
#ifndef MODULE_MAGIC_NUMBER_MAJOR
#define MODULE_MAGIC_NUMBER_MAJOR 20050305
#endif
-#define MODULE_MAGIC_NUMBER_MINOR 1 /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 2 /* 0...n */
/**
* Determine if the server's current MODULE_MAGIC_NUMBER is at least a