mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-04 03:50:31 +00:00
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
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user