[asterisk-commits] twilson: branch twilson/config_work r361904 - in /team/twilson/config_work: a...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 10 18:52:53 CDT 2012


Author: twilson
Date: Tue Apr 10 18:52:49 2012
New Revision: 361904

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=361904
Log:
Make custom options work and provide example

Modified:
    team/twilson/config_work/apps/app_skel.c
    team/twilson/config_work/configs/app_skel.conf.sample
    team/twilson/config_work/include/asterisk/config_options.h
    team/twilson/config_work/main/config_options.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=361904&r1=361903&r2=361904
==============================================================================
--- team/twilson/config_work/apps/app_skel.c (original)
+++ team/twilson/config_work/apps/app_skel.c Tue Apr 10 18:52:49 2012
@@ -119,6 +119,8 @@
 	struct ast_codec_pref prefs;
 	struct ast_format_cap *caps;
 	struct ast_ha *permit;
+	unsigned int bit1:1;
+	unsigned int bit2:1;
 };
 
 struct skel_pvt {
@@ -187,6 +189,25 @@
 	struct skel_pvt_config *one = obj, *two = arg;
 	const char *match = (flags & OBJ_KEY) ? arg : two->name;
 	return strcasecmp(one->name, match) ? 0 : (CMP_MATCH | CMP_STOP);
+}
+
+/*! \brief A custom bitfield handler
+ * \note It is not possible to take the address of a bitfield, therefor all
+ * bitfields in the config struct will have to use a custom handler
+ */
+static int custom_bitfield_handler(const struct ast_config_option *opt, struct ast_variable *var, void *obj)
+{
+	struct skel_pvt_config *cfg = obj;
+
+	if (!strcasecmp(var->name, "bit1")) {
+		cfg->bit1 = ast_true(var->value);
+	} else if (!strcasecmp(var->name, "bit2")) {
+		cfg->bit2 = ast_true(var->value);
+	} else {
+		return -1;
+	}
+
+	return 0;
 }
 
 static void apply_config(struct skel_global_config *new_global, struct ao2_container *new_pvt_container, struct ao2_container *new_cfg_container)
@@ -509,8 +530,8 @@
 		return NULL;
 	}
 
-#define SKEL_FORMAT "%-20.20s %-25.25s %-20.20s %-5.5s\n"
-	ast_cli(a->fd, SKEL_FORMAT, "Name", "Description", "Codecs", "ACL");
+#define SKEL_FORMAT "%-15.15s %-25.25s %-20.20s %-5.5s %-5.5s %-5.5s\n"
+	ast_cli(a->fd, SKEL_FORMAT, "Name", "Description", "Codecs", "ACL", "Bit1", "Bit2");
 	iter = ao2_iterator_init(pvts, 0);
 	while ((pvt = ao2_iterator_next(&iter))) {
 		struct skel_pvt_config *cfg;
@@ -520,7 +541,7 @@
 			continue;
 		}
 		ast_getformatname_multiple(codec_buf, sizeof(codec_buf) - 1, cfg->caps);
-		ast_cli(a->fd, SKEL_FORMAT, pvt->name, cfg->description, codec_buf, AST_CLI_YESNO(cfg->permit != NULL));
+		ast_cli(a->fd, SKEL_FORMAT, pvt->name, cfg->description, codec_buf, AST_CLI_YESNO(cfg->permit != NULL), AST_CLI_YESNO(cfg->bit1), AST_CLI_YESNO(cfg->bit2));
 		ao2_ref(pvt, -1);
 		ao2_ref(cfg, -1);
 	}
@@ -570,6 +591,8 @@
 	ast_config_option_register(config_opts, "description", CONTEXT_DENY, "general", NULL, OPT_STRINGFIELD_T, struct skel_pvt_config, 0, description);
 	ast_config_option_register(config_opts, "allow", CONTEXT_DENY, "general", "ulaw,alaw", OPT_CODEC_T, struct skel_pvt_config, 1, prefs, caps);
 	ast_config_option_register(config_opts, "permit", CONTEXT_DENY, "general", NULL, OPT_ACL_T, struct skel_pvt_config, 1, permit);
+	ast_config_option_register_custom(config_opts, "bit1", CONTEXT_DENY, "general", "yes", custom_bitfield_handler, 0);
+	ast_config_option_register_custom(config_opts, "bit2", CONTEXT_DENY, "general", "no", custom_bitfield_handler, 0);
 
 	if (process_config(0)) {
 		return AST_MODULE_LOAD_DECLINE;

Modified: team/twilson/config_work/configs/app_skel.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/configs/app_skel.conf.sample?view=diff&rev=361904&r1=361903&r2=361904
==============================================================================
--- team/twilson/config_work/configs/app_skel.conf.sample (original)
+++ team/twilson/config_work/configs/app_skel.conf.sample Tue Apr 10 18:52:49 2012
@@ -9,7 +9,13 @@
 description=first private
 allow=!all,ulaw,alaw
 permit=127.0.0.1/32
+bit1=yes
+bit2=no
 
 [pvt2]
 description=second private
 allow=!all,ulaw
+bit1=no
+bit2=yes
+
+[pvt3]

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=361904&r1=361903&r2=361904
==============================================================================
--- team/twilson/config_work/include/asterisk/config_options.h (original)
+++ team/twilson/config_work/include/asterisk/config_options.h Tue Apr 10 18:52:49 2012
@@ -42,6 +42,8 @@
 	OPT_BOOL_T,
 	OPT_ACL_T,
 	OPT_CODEC_T,
+
+	OPT_CUSTOM_T,
 };
 
 enum ast_config_option_context_op {
@@ -78,8 +80,8 @@
 	} \
 }
 
-#define ast_config_option_register_custom(container, name, op, context, default_val, opt_type, handler, flags) { \
-	struct ast_config_option *__opt = ast_config_option_build(name, op, context, default_val, opt_type, handler, flags); \
+#define ast_config_option_register_custom(container, name, op, context, default_val, handler, flags) { \
+	struct ast_config_option *__opt = __ast_config_option_build(name, op, context, default_val, OPT_CUSTOM_T, handler, flags, 0); \
 	if (__opt) { \
 		ao2_link(container, __opt); \
 		ao2_ref(__opt, -1); \

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=361904&r1=361903&r2=361904
==============================================================================
--- team/twilson/config_work/main/config_options.c (original)
+++ team/twilson/config_work/main/config_options.c Tue Apr 10 18:52:49 2012
@@ -72,6 +72,8 @@
 	case OPT_SOCKADDR_T: return ast_config_option_sockaddr_fn;
 	case OPT_STRINGFIELD_T: return ast_config_option_stringfield_fn;
 	case OPT_UINT_T: return ast_config_option_uint_fn;
+
+	case OPT_CUSTOM_T: return NULL;
 	}
 
 	return NULL;
@@ -87,6 +89,11 @@
 	va_list ap;
 	regex_t *regex;
 	int tmp;
+
+	/* Custom option types require a handler */
+	if (!handler && type == OPT_CUSTOM_T) {
+		return NULL;
+	}
 
 	if (!(regex = ast_calloc(1, sizeof(*regex)))) {
 		return NULL;




More information about the asterisk-commits mailing list