[asterisk-commits] twilson: branch twilson/config_work r367833 - in /team/twilson/config_work: a...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue May 29 02:10:10 CDT 2012
Author: twilson
Date: Tue May 29 02:10:06 2012
New Revision: 367833
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=367833
Log:
Add optional regex matching for option names
Modified:
team/twilson/config_work/apps/app_skel.c
team/twilson/config_work/include/asterisk/config_options.h
team/twilson/config_work/main/config_options.c
team/twilson/config_work/main/udptl.c
Modified: team/twilson/config_work/apps/app_skel.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/apps/app_skel.c?view=diff&rev=367833&r1=367832&r2=367833
==============================================================================
--- team/twilson/config_work/apps/app_skel.c (original)
+++ team/twilson/config_work/apps/app_skel.c Tue May 29 02:10:06 2012
@@ -658,20 +658,20 @@
}
/* Global options */
- aco_option_register(&cfg_info, "games", global_options, "3", OPT_UINT_T, 0, FLDSET(struct skel_global_config, num_games));
- aco_option_register_custom(&cfg_info, "cheat", global_options, "no", custom_bitfield_handler, 0);
+ aco_option_register(&cfg_info, "^games$", ACO_REGEX, global_options, "3", OPT_UINT_T, 0, FLDSET(struct skel_global_config, num_games));
+ aco_option_register_custom(&cfg_info, "cheat", ACO_EXACT, global_options, "no", custom_bitfield_handler, 0);
/* Sound options */
- aco_option_register(&cfg_info, "prompt", sound_options, "please-enter-your&number&queue-less-than", OPT_STRINGFIELD_T, 0, STRFLDSET(struct skel_global_config, prompt));
- aco_option_register(&cfg_info, "wrong_guess", sound_options, "vm-pls-try-again", OPT_STRINGFIELD_T, 0, STRFLDSET(struct skel_global_config, wrong));
- aco_option_register(&cfg_info, "right_guess", sound_options, "auth-thankyou", OPT_STRINGFIELD_T, 0, STRFLDSET(struct skel_global_config, right));
- aco_option_register(&cfg_info, "too_high", sound_options, "high", OPT_STRINGFIELD_T, 0, STRFLDSET(struct skel_global_config, high));
- aco_option_register(&cfg_info, "too_low", sound_options, "low", OPT_STRINGFIELD_T, 0, STRFLDSET(struct skel_global_config, low));
- aco_option_register(&cfg_info, "lose", sound_options, "vm-goodbye", OPT_STRINGFIELD_T, 0, STRFLDSET(struct skel_global_config, lose));
+ aco_option_register(&cfg_info, "prompt", ACO_EXACT, sound_options, "please-enter-your&number&queue-less-than", OPT_STRINGFIELD_T, 0, STRFLDSET(struct skel_global_config, prompt));
+ aco_option_register(&cfg_info, "wrong_guess", ACO_EXACT, sound_options, "vm-pls-try-again", OPT_STRINGFIELD_T, 0, STRFLDSET(struct skel_global_config, wrong));
+ aco_option_register(&cfg_info, "right_guess", ACO_EXACT, sound_options, "auth-thankyou", OPT_STRINGFIELD_T, 0, STRFLDSET(struct skel_global_config, right));
+ aco_option_register(&cfg_info, "too_high", ACO_EXACT, sound_options, "high", OPT_STRINGFIELD_T, 0, STRFLDSET(struct skel_global_config, high));
+ aco_option_register(&cfg_info, "too_low", ACO_EXACT, sound_options, "low", OPT_STRINGFIELD_T, 0, STRFLDSET(struct skel_global_config, low));
+ aco_option_register(&cfg_info, "lose", ACO_EXACT, sound_options, "vm-goodbye", OPT_STRINGFIELD_T, 0, STRFLDSET(struct skel_global_config, lose));
/* Level options */
- aco_option_register(&cfg_info, "max_number", level_options, NULL, OPT_UINT_T, 0, FLDSET(struct skel_level, max_num));
- aco_option_register(&cfg_info, "max_guesses", level_options, NULL, OPT_UINT_T, 1, FLDSET(struct skel_level, max_guesses));
+ aco_option_register(&cfg_info, "max_number", ACO_EXACT, level_options, NULL, OPT_UINT_T, 0, FLDSET(struct skel_level, max_num));
+ aco_option_register(&cfg_info, "max_guesses", ACO_EXACT, level_options, NULL, OPT_UINT_T, 1, FLDSET(struct skel_level, max_guesses));
if (aco_process_config(&cfg_info, 0)) {
goto error;
Modified: team/twilson/config_work/include/asterisk/config_options.h
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/include/asterisk/config_options.h?view=diff&rev=367833&r1=367832&r2=367833
==============================================================================
--- team/twilson/config_work/include/asterisk/config_options.h (original)
+++ team/twilson/config_work/include/asterisk/config_options.h Tue May 29 02:10:06 2012
@@ -46,6 +46,12 @@
enum aco_category_op {
ACO_BLACKLIST = 0,
ACO_WHITELIST,
+};
+
+/*! \brief What kind of matching should be done on an option name */
+enum aco_matchtype {
+ ACO_EXACT = 1,
+ ACO_REGEX,
};
/* Callback functions for option parsing via aco_process_config() */
@@ -287,7 +293,7 @@
* \retval 0 success
* \retval -1 failure
*/
-int __aco_option_register(struct aco_info *info, const char *name, struct aco_type **types,
+int __aco_option_register(struct aco_info *info, const char *name, enum aco_matchtype match_type, struct aco_type **types,
const char *default_val, enum aco_option_type type, aco_option_handler handler, unsigned int flags, size_t argc, ...);
/* \brief Register a config option
@@ -300,8 +306,8 @@
*
* \returns An option on success, NULL on failure
*/
-#define aco_option_register(info, name, types, default_val, opt_type, flags, ...) \
- __aco_option_register(info, name, types, default_val, opt_type, NULL, flags, VA_NARGS(__VA_ARGS__), __VA_ARGS__);
+#define aco_option_register(info, name, matchtype, types, default_val, opt_type, flags, ...) \
+ __aco_option_register(info, name, matchtype, types, default_val, opt_type, NULL, flags, VA_NARGS(__VA_ARGS__), __VA_ARGS__);
/* \brief Register a config option
* \param info A pointer to the aco_info struct
@@ -313,8 +319,8 @@
*
* \returns An option on success, NULL on failure
*/
-#define aco_option_register_custom(info, name, type, default_val, handler, flags) \
- __aco_option_register(info, name, type, default_val, OPT_CUSTOM_T, handler, flags, 0);
+#define aco_option_register_custom(info, name, matchtype, type, default_val, handler, flags) \
+ __aco_option_register(info, name, matchtype, type, default_val, OPT_CUSTOM_T, handler, flags, 0);
/*! \note Everything below this point is to handle converting varargs
* containing field names, to varargs containing a count of args, followed
Modified: team/twilson/config_work/main/config_options.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/main/config_options.c?view=diff&rev=367833&r1=367832&r2=367833
==============================================================================
--- team/twilson/config_work/main/config_options.c (original)
+++ team/twilson/config_work/main/config_options.c Tue May 29 02:10:06 2012
@@ -53,6 +53,8 @@
struct aco_option {
const char *name;
+ enum aco_matchtype match_type;
+ regex_t *name_regex;
const char *default_val;
struct aco_type **obj;
enum aco_option_type type;
@@ -73,7 +75,11 @@
static void config_option_destroy(void *obj)
{
- return;
+ struct aco_option *opt = obj;
+ if (opt->match_type == ACO_REGEX && opt->name_regex) {
+ regfree(opt->name_regex);
+ ast_free(opt->name_regex);
+ }
}
static int int_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
@@ -103,7 +109,7 @@
return NULL;
}
-static regex_t *build_category_regex(const char *text)
+static regex_t *build_regex(const char *text)
{
int res;
regex_t *regex;
@@ -124,7 +130,7 @@
return regex;
}
-int __aco_option_register(struct aco_info *info, const char *name, struct aco_type **types,
+int __aco_option_register(struct aco_info *info, const char *name, enum aco_matchtype matchtype, struct aco_type **types,
const char *default_val, enum aco_option_type kind, aco_option_handler handler, unsigned int flags, size_t argc, ...)
{
struct aco_option *opt;
@@ -145,6 +151,11 @@
return -1;
}
+ if (matchtype == ACO_REGEX && !(opt->name_regex = build_regex(name))) {
+ ao2_ref(opt, -1);
+ return -1;
+ }
+
va_start(ap, argc);
for (tmp = 0; tmp < argc; tmp++) {
opt->args[tmp] = va_arg(ap, size_t);
@@ -152,6 +163,7 @@
va_end(ap);
opt->name = name;
+ opt->match_type = matchtype;
opt->default_val = default_val;
opt->type = kind;
opt->handler = handler;
@@ -197,12 +209,26 @@
{
struct aco_option *match = obj;
const char *name = arg;
- return strcasecmp(name, match->name) ? 0 : CMP_MATCH | CMP_STOP;
+
+ switch (match->match_type) {
+ case ACO_EXACT:
+ return strcasecmp(name, match->name) ? 0 : CMP_MATCH | CMP_STOP;
+ case ACO_REGEX:
+ return regexec(match->name_regex, name, 0, NULL, 0) ? 0 : CMP_MATCH | CMP_STOP;
+ }
+ ast_log(LOG_ERROR, "Unknown match type. This should not be possible.\n");
+ return CMP_STOP;
}
static struct aco_option *aco_option_find(struct aco_type *type, const char *name)
{
- return ao2_callback(type->internal->opts, OBJ_KEY, find_option_cb, (void *) name);
+ struct aco_option *opt;
+ /* Try an exact match with OBJ_KEY for the common/fast case, then iterate through
+ * all options for the regex cases */
+ if (!(opt = ao2_callback(type->internal->opts, OBJ_KEY, find_option_cb, (void *) name))) {
+ opt = ao2_callback(type->internal->opts, 0, find_option_cb, (void *) name);
+ }
+ return opt;
}
struct ao2_container *aco_option_container_alloc(void)
@@ -489,7 +515,7 @@
return -1;
}
- if (!(type->internal->regex = build_category_regex(type->category))) {
+ if (!(type->internal->regex = build_regex(type->category))) {
internal_type_destroy(type);
}
Modified: team/twilson/config_work/main/udptl.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/main/udptl.c?view=diff&rev=367833&r1=367832&r2=367833
==============================================================================
--- team/twilson/config_work/main/udptl.c (original)
+++ team/twilson/config_work/main/udptl.c Tue May 29 02:10:06 2012
@@ -1460,30 +1460,30 @@
return;
}
- aco_option_register(&cfg_info, "udptlstart", general_options, __stringify(DEFAULT_UDPTLSTART),
+ aco_option_register(&cfg_info, "udptlstart", ACO_EXACT, general_options, __stringify(DEFAULT_UDPTLSTART),
OPT_UINT_T, PARSE_IN_RANGE | PARSE_DEFAULT,
FLDSET(struct udptl_global_options, start), DEFAULT_UDPTLSTART, 1024, 65535);
- aco_option_register(&cfg_info, "udptlend", general_options, __stringify(DEFAULT_UDPTLEND),
+ aco_option_register(&cfg_info, "udptlend", ACO_EXACT, general_options, __stringify(DEFAULT_UDPTLEND),
OPT_UINT_T, PARSE_IN_RANGE | PARSE_DEFAULT,
FLDSET(struct udptl_global_options, end), DEFAULT_UDPTLEND, 1024, 65535);
- aco_option_register(&cfg_info, "udptlfecentries", general_options, NULL,
+ aco_option_register(&cfg_info, "udptlfecentries", ACO_EXACT, general_options, NULL,
OPT_UINT_T, PARSE_IN_RANGE | PARSE_RANGE_DEFAULTS,
FLDSET(struct udptl_global_options, fecentries), 1, MAX_FEC_ENTRIES);
- aco_option_register(&cfg_info, "udptlfecspan", general_options, NULL,
+ aco_option_register(&cfg_info, "udptlfecspan", ACO_EXACT, general_options, NULL,
OPT_UINT_T, PARSE_IN_RANGE | PARSE_RANGE_DEFAULTS,
FLDSET(struct udptl_global_options, fecspan), 1, MAX_FEC_SPAN);
- aco_option_register(&cfg_info, "udptlchecksums", general_options, "yes",
+ aco_option_register(&cfg_info, "udptlchecksums", ACO_EXACT, general_options, "yes",
OPT_BOOL_T, 0, FLDSET(struct udptl_global_options, nochecksums));
- aco_option_register(&cfg_info, "use_even_ports", general_options, "no",
+ aco_option_register(&cfg_info, "use_even_ports", ACO_EXACT, general_options, "no",
OPT_BOOL_T, 1, FLDSET(struct udptl_global_options, use_even_ports));
- aco_option_register_custom(&cfg_info, "t38faxudpec", general_options, NULL, removed_options_handler, 0);
- aco_option_register_custom(&cfg_info, "t38faxmaxdatagram", general_options, NULL, removed_options_handler, 0);
+ aco_option_register_custom(&cfg_info, "t38faxudpec", ACO_EXACT, general_options, NULL, removed_options_handler, 0);
+ aco_option_register_custom(&cfg_info, "t38faxmaxdatagram", ACO_EXACT, general_options, NULL, removed_options_handler, 0);
ast_cli_register_multiple(cli_udptl, ARRAY_LEN(cli_udptl));
More information about the asterisk-commits
mailing list