summaryrefslogtreecommitdiff
path: root/main/config_options.c
diff options
context:
space:
mode:
authorTerry Wilson <twilson@digium.com>2012-06-28 01:12:06 +0000
committerTerry Wilson <twilson@digium.com>2012-06-28 01:12:06 +0000
commit1609fca6bb0bb85ac3c423aa7507bb489f7616e9 (patch)
tree1313e845503f782464e8b5a14289d6d02ddc470c /main/config_options.c
parent7d9e0158c3bc528e4e59b225604fb4f39ebd653e (diff)
Add the ability to set flags via the config options api
Allows the setting of flags via the config options api. For example, code like this: #define OPT1 1 << 0 #define OPT2 1 << 1 #define OPT3 1 << 2 struct thing { unsigned int flags; }; and a config like this: [blah] opt1=yes opt2=no opt3=yes Review: https://reviewboard.asterisk.org/r/2004/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@369454 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/config_options.c')
-rw-r--r--main/config_options.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/main/config_options.c b/main/config_options.c
index eedce2879..efba8de3a 100644
--- a/main/config_options.c
+++ b/main/config_options.c
@@ -92,6 +92,7 @@ static int double_handler_fn(const struct aco_option *opt, struct ast_variable *
static int sockaddr_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
static int stringfield_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
static int bool_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
+static int boolflag_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
static int acl_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
static int codec_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
@@ -100,6 +101,7 @@ static aco_option_handler ast_config_option_default_handler(enum aco_option_type
switch(type) {
case OPT_ACL_T: return acl_handler_fn;
case OPT_BOOL_T: return bool_handler_fn;
+ case OPT_BOOLFLAG_T: return boolflag_handler_fn;
case OPT_CODEC_T: return codec_handler_fn;
case OPT_DOUBLE_T: return double_handler_fn;
case OPT_INT_T: return int_handler_fn;
@@ -741,6 +743,23 @@ static int bool_handler_fn(const struct aco_option *opt, struct ast_variable *va
return 0;
}
+/*! \brief Default option handler for bools (ast_true/ast_false) that are stored as flags
+ * \note For a description of the opt->flags and opt->args values, see the documentation for
+ * enum aco_option_type in config_options.h
+ */
+static int boolflag_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj)
+{
+ unsigned int *flags_field = (unsigned int *)(obj + opt->args[0]);
+ unsigned int val = opt->flags ? ast_true(var->value) : ast_false(var->value);
+ unsigned int flag = opt->args[1];
+ if (val) {
+ *flags_field |= flag;
+ } else {
+ *flags_field &= ~flag;
+ }
+ return 0;
+}
+
/*! \brief Default handler for ast_sockaddrs
* \note For a description of the opt->flags and opt->args values, see the documentation for
* enum aco_option_type in config_options.h