Convert app_confbridge to use the config options framework

Review: https://reviewboard.asterisk.org/r/2024/


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370303 65c4cc65-6c06-0410-ace0-fbb531ad65f3
certified/11.2
Terry Wilson 13 years ago
parent b78fd0ac89
commit 2f674bcdd1

File diff suppressed because it is too large Load Diff

@ -120,7 +120,6 @@ struct conf_menu_entry {
* sequences invoke.*/
struct conf_menu {
char name[128];
int delme;
AST_LIST_HEAD_NOLOCK(, conf_menu_entry) entries;
};
@ -135,7 +134,6 @@ struct user_profile {
unsigned int talking_threshold;
/*! The time in ms of silence before a user is considered to be silent by the dsp. */
unsigned int silence_threshold;
int delme;
};
enum conf_sounds {
@ -198,7 +196,6 @@ struct bridge_profile {
unsigned int internal_sample_rate; /*!< The internal sample rate of the bridge. 0 when set to auto adjust mode. */
unsigned int mix_interval; /*!< The internal mixing interval used by the bridge. When set to 0 the bridgewill use a default interval. */
struct bridge_profile_sounds *sounds;
int delme;
};
/*! \brief The structure that represents a conference bridge */

@ -281,6 +281,20 @@ enum aco_option_type {
OPT_BOOLFLAG_T,
/*! \brief Type for default option handler for character arrays
* \note aco_option_register varargs:
* CHARFLDSET macro with a field of type char[]
*
* Example:
* {code}
* struct test_item {
* char description[128];
* };
* aco_option_register(&cfg_info, "description", ACO_EXACT, my_types, "none", OPT_CHAR_ARRAY_T, CHARFLDSET(struct test_item, description));
* {endcode}
*/
OPT_CHAR_ARRAY_T,
/*! \brief Type for default option handler for codec preferences/capabilities
* \note aco_option_register flags:
* non-zero : This is an "allow" style option
@ -296,6 +310,7 @@ enum aco_option_type {
* };
* aco_option_register(&cfg_info, "allow", ACO_EXACT, my_types, "ulaw,alaw", OPT_CODEC_T, 1, FLDSET(struct test_item, pref, cap));
* aco_option_register(&cfg_info, "disallow", ACO_EXACT, my_types, "all", OPT_CODEC_T, 0, FLDSET(struct test_item, pref, cap));
* {endcode}
*/
OPT_CODEC_T,
@ -343,6 +358,13 @@ enum aco_option_type {
*/
OPT_INT_T,
/*! \brief Type for a default handler that should do nothing
*
* \note This might be useful for a "type" field that is valid, but doesn't
* actually need to do anything
*/
OPT_NOOP_T,
/*! \brief Type for default handler for ast_sockaddrs
*
* \note aco_option_register flags:
@ -373,7 +395,7 @@ enum aco_option_type {
* AST_STRING_FIELD(thing);
* );
* };
* aco_option_register(&cfg_info, "thing", ACO_EXACT, my_types, NULL, OPT_STR_T, 0, STRFLDSET(struct test_item, thing));
* aco_option_register(&cfg_info, "thing", ACO_EXACT, my_types, NULL, OPT_STRINGFIELD_T, 0, STRFLDSET(struct test_item, thing));
* {endcode}
*/
OPT_STRINGFIELD_T,
@ -447,6 +469,21 @@ enum aco_process_status aco_process_config(struct aco_info *info, int reload);
*/
enum aco_process_status aco_process_ast_config(struct aco_info *info, struct aco_file *file, struct ast_config *cfg);
/*! \brief Parse a single ast_variable and apply it to an object
* \note This function can be used to build up an object by repeatedly passing in
* the config variable name and values that would be found in a config file. This can
* be useful if the object is to be populated by a dialplan function, for example.
*
* \param type The aco_type associated with the object
* \param cat The category to use
* \param var A variable to apply to the object
* \param obj A pointer to the object to be configured
*
* \retval 0 Success
* \retval -1 Failure
*/
int aco_process_var(struct aco_type *type, const char *cat, struct ast_variable *var, void *obj);
/*! \brief Parse each option defined in a config category
* \param type The aco_type with the options for parsing
* \param cfg The ast_config being parsed
@ -659,6 +696,14 @@ int aco_option_register_deprecated(struct aco_info *info, const char *name, stru
*/
#define STRFLDSET(type, ...) FLDSET(type, __VA_ARGS__, __field_mgr_pool, __field_mgr)
/*! \def CHARFLDSET(type, field)
* \brief A helper macro to pass the appropriate arguments to aco_option_register for OPT_CHAR_ARRAY_T
* \note This will pass the offset of the field and its length as arguments
* \param type The type with the char array field (e.g. "struct my_struct")
* \param field The name of char array field
*/
#define CHARFLDSET(type, field) ARGIFY(offsetof(type, field), sizeof(((type *)0)->field))
/*! \def POPPED(...)
* \brief A list of arguments without the first argument
* \note Used internally to remove the leading "number of arguments" argument from ARGMAP for

@ -97,6 +97,8 @@ static int bool_handler_fn(const struct aco_option *opt, struct ast_variable *va
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);
static int noop_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
static int chararray_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
static aco_option_handler ast_config_option_default_handler(enum aco_option_type type)
{
@ -104,9 +106,11 @@ static aco_option_handler ast_config_option_default_handler(enum aco_option_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_CHAR_ARRAY_T: return chararray_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;
case OPT_NOOP_T: return noop_handler_fn;
case OPT_SOCKADDR_T: return sockaddr_handler_fn;
case OPT_STRINGFIELD_T: return stringfield_handler_fn;
case OPT_UINT_T: return uint_handler_fn;
@ -530,32 +534,40 @@ end:
ao2_cleanup(info->internal->pending);
return res;
}
int aco_process_var(struct aco_type *type, const char *cat, struct ast_variable *var, void *obj)
{
RAII_VAR(struct aco_option *, opt, aco_option_find(type, var->name), ao2_cleanup);
if (opt && opt->deprecated && !ast_strlen_zero(opt->aliased_to)) {
const char *alias = ast_strdupa(opt->aliased_to);
ast_log(LOG_WARNING, "At line %d of %s option '%s' is deprecated. Use '%s' instead\n", var->lineno, var->file, var->name, alias);
ao2_ref(opt, -1);
opt = aco_option_find(type, alias);
}
if (!opt) {
ast_log(LOG_ERROR, "Could not find option suitable for category '%s' named '%s' at line %d of %s\n", cat, var->name, var->lineno, var->file);
return -1;
}
if (!opt->handler) {
/* It should be impossible for an option to not have a handler */
ast_log(LOG_ERROR, "BUG! Somehow a config option for %s/%s was created with no handler!\n", cat, var->name);
return -1;
}
if (opt->handler(opt, var, obj)) {
ast_log(LOG_ERROR, "Error parsing %s=%s at line %d of %s\n", var->name, var->value, var->lineno, var->file);
return -1;
}
return 0;
}
int aco_process_category_options(struct aco_type *type, struct ast_config *cfg, const char *cat, void *obj)
{
struct ast_variable *var;
for (var = ast_variable_browse(cfg, cat); var; var = var->next) {
RAII_VAR(struct aco_option *, opt, aco_option_find(type, var->name), ao2_cleanup);
if (opt && opt->deprecated && !ast_strlen_zero(opt->aliased_to)) {
const char *alias = ast_strdupa(opt->aliased_to);
ast_log(LOG_WARNING, "At line %d of %s option '%s' is deprecated. Use '%s' instead\n", var->lineno, var->file, var->name, alias);
ao2_ref(opt, -1);
opt = aco_option_find(type, alias);
}
if (!opt) {
ast_log(LOG_ERROR, "Could not find option suitable for category '%s' named '%s' at line %d of %s\n", cat, var->name, var->lineno, var->file);
return -1;
}
if (!opt->handler) {
/* It should be impossible for an option to not have a handler */
ast_log(LOG_ERROR, "BUG! Somehow a config option for %s/%s was created with no handler!\n", cat, var->name);
return -1;
}
if (opt->handler(opt, var, obj)) {
ast_log(LOG_ERROR, "Error parsing %s=%s at line %d of %s\n", var->name, var->value, var->lineno, var->file);
if (aco_process_var(type, cat, var, obj)) {
return -1;
}
}
@ -813,3 +825,23 @@ static int sockaddr_handler_fn(const struct aco_option *opt, struct ast_variable
struct ast_sockaddr *field = (struct ast_sockaddr *)(obj + opt->args[0]);
return ast_parse_arg(var->value, PARSE_ADDR | opt->flags, field);
}
/*! \brief Default handler for doing noithing
*/
static int noop_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj)
{
return 0;
}
/*! \brief Default handler for character arrays
* \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 chararray_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj)
{
char *field = (char *)(obj + opt->args[0]);
size_t len = opt->args[1];
ast_copy_string(field, var->value, len);
return 0;
}

Loading…
Cancel
Save