config_options.c File Reference

Configuration Option-handling. More...

#include "asterisk.h"
#include <regex.h>
#include "asterisk/_private.h"
#include "asterisk/config.h"
#include "asterisk/config_options.h"
#include "asterisk/stringfields.h"
#include "asterisk/acl.h"
#include "asterisk/frame.h"
#include "asterisk/xmldoc.h"
#include "asterisk/cli.h"
#include "asterisk/term.h"
#include "asterisk/format_cap.h"

Include dependency graph for config_options.c:

Go to the source code of this file.

Data Structures

struct  aco_info_internal
 Bits of aco_info that shouldn't be assigned outside this file. More...
struct  aco_option
struct  aco_type_internal

Defines

#define CONFIG_OPT_BUCKETS   53

Functions

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, unsigned int no_doc, size_t argc,...)
 register a config option
static int acl_handler_fn (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Default handler for ACLs.
void aco_info_destroy (struct aco_info *info)
 Destroy an initialized aco_info struct.
int aco_info_init (struct aco_info *info)
 Initialize an aco_info structure.
int aco_init (void)
struct ao2_containeraco_option_container_alloc (void)
 Allocate a container to hold config options.
static struct aco_optionaco_option_find (struct aco_type *type, const char *name)
intptr_t aco_option_get_argument (const struct aco_option *option, unsigned int position)
 Get the offset position for an argument within a config option.
unsigned int aco_option_get_flags (const struct aco_option *option)
 Read the flags of a config option - useful when using a custom callback for a config option.
int aco_option_register_deprecated (struct aco_info *info, const char *name, struct aco_type **types, const char *aliased_to)
 Register a deprecated (and aliased) config option.
void * aco_pending_config (struct aco_info *info)
 Get pending config changes.
enum aco_process_status aco_process_ast_config (struct aco_info *info, struct aco_file *file, struct ast_config *cfg)
 Process config info from an ast_config via options registered with an aco_info.
int aco_process_category_options (struct aco_type *type, struct ast_config *cfg, const char *cat, void *obj)
 Parse each option defined in a config category.
enum aco_process_status aco_process_config (struct aco_info *info, int reload)
 Process a config info via the options registered with an aco_info.
int aco_process_var (struct aco_type *type, const char *cat, struct ast_variable *var, void *obj)
 Parse a single ast_variable and apply it to an object.
int aco_set_defaults (struct aco_type *type, const char *category, void *obj)
 Set all default options of obj.
static int apply_config (struct aco_info *info)
static aco_option_handler ast_config_option_default_handler (enum aco_option_type type)
static int bool_handler_fn (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Default option handler for bools (ast_true/ast_false).
static int boolflag_handler_fn (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Default option handler for bools (ast_true/ast_false) that are stored as flags.
static regex_t * build_regex (const char *text)
static int chararray_handler_fn (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Default handler for character arrays.
static int codec_handler_fn (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Default option handler for codec preferences/capabilities.
static int config_opt_cmp (void *obj, void *arg, int flags)
static int config_opt_hash (const void *obj, const int flags)
static void config_option_destroy (void *obj)
static int double_handler_fn (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Default option handler for doubles.
static int find_option_cb (void *obj, void *arg, int flags)
static int int_handler_fn (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Default option handler for signed integers.
static struct aco_typeinternal_aco_type_find (struct aco_file *file, struct ast_config *cfg, const char *category)
static void internal_file_types_destroy (struct aco_file *file)
static enum aco_process_status internal_process_ast_config (struct aco_info *info, struct aco_file *file, struct ast_config *cfg)
static void internal_type_destroy (struct aco_type *type)
static int internal_type_init (struct aco_type *type)
static int is_preload (struct aco_file *file, const char *cat)
static int link_option_to_types (struct aco_info *info, struct aco_type **types, struct aco_option *opt)
static int noop_handler_fn (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Default handler for doing nothing.
static int process_category (struct ast_config *cfg, struct aco_info *info, struct aco_file *file, const char *cat, int preload)
static int sockaddr_handler_fn (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Default handler for ast_sockaddrs.
static int stringfield_handler_fn (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Default option handler for stringfields.
static int uint_handler_fn (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Default option handler for unsigned integers.

Variables

static char * aco_option_type_string []
 Value of the aco_option_type enum as strings.


Detailed Description

Configuration Option-handling.

Author:
Terry Wilson <twilson@digium.com>

Definition in file config_options.c.


Define Documentation

#define CONFIG_OPT_BUCKETS   53

Definition at line 48 of file config_options.c.

Referenced by aco_option_container_alloc().


Function Documentation

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,
unsigned int  no_doc,
size_t  argc,
  ... 
)

register a config option

Note:
this should probably only be called by one of the aco_option_register* macros
Parameters:
info The aco_info holding this module's config information
name The name of the option
match_type 
types An array of valid option types for matching categories to the correct struct type
default_val The default value of the option in the same format as defined in a config file
type The option type (only for default handlers)
handler The handler function for the option (only for non-default types)
flags a type specific flags, stored in the option and available to the handler
no_doc if non-zero, this option should not have documentation
argc The number for variadic arguments
... field offsets to store for default handlers
Return values:
0 success
-1 failure

Definition at line 287 of file config_options.c.

References ACO_REGEX, ao2_alloc, ao2_ref, aco_option::argc, aco_option::args, ast_config_option_default_handler(), ast_log, build_regex(), config_option_destroy(), aco_option::default_val, aco_option::flags, aco_option::handler, link_option_to_types(), LOG_ERROR, aco_option::match_type, aco_option::name, aco_option::name_regex, aco_option::no_doc, OPT_CUSTOM_T, tmp(), and aco_option::type.

Referenced by __ast_sorcery_object_field_register(), and ast_sorcery_object_fields_register().

00290 {
00291    struct aco_option *opt;
00292    va_list ap;
00293    int tmp;
00294 
00295    /* Custom option types require a handler */
00296    if (!handler && kind == OPT_CUSTOM_T) {
00297       return -1;
00298    }
00299 
00300    if (!(types && types[0])) {
00301       return -1;
00302    }
00303 
00304    if (!(opt = ao2_alloc(sizeof(*opt) + argc * sizeof(opt->args[0]), config_option_destroy))) {
00305       return -1;
00306    }
00307 
00308    if (matchtype == ACO_REGEX && !(opt->name_regex = build_regex(name))) {
00309       ao2_ref(opt, -1);
00310       return -1;
00311    }
00312 
00313    va_start(ap, argc);
00314    for (tmp = 0; tmp < argc; tmp++) {
00315       opt->args[tmp] = va_arg(ap, size_t);
00316    }
00317    va_end(ap);
00318 
00319    opt->name = name;
00320    opt->match_type = matchtype;
00321    opt->default_val = default_val;
00322    opt->type = kind;
00323    opt->handler = handler;
00324    opt->flags = flags;
00325    opt->argc = argc;
00326    opt->no_doc = no_doc;
00327 
00328    if (!opt->handler && !(opt->handler = ast_config_option_default_handler(opt->type))) {
00329       /* This should never happen */
00330       ast_log(LOG_ERROR, "No handler provided, and no default handler exists for type %u\n", opt->type);
00331       ao2_ref(opt, -1);
00332       return -1;
00333    };
00334 
00335    if (link_option_to_types(info, types, opt)) {
00336       ao2_ref(opt, -1);
00337       return -1;
00338    }
00339 
00340    return 0;
00341 }

static int acl_handler_fn ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
) [static]

Default handler for ACLs.

Note:
For a description of the opt->flags and opt->args values, see the documentation for enum aco_option_type in config_options.h

Definition at line 1369 of file config_options.c.

References aco_option::args, ast_append_ha(), error(), aco_option::flags, and ast_variable::value.

Referenced by ast_config_option_default_handler().

01369                                                                                              {
01370    struct ast_ha **ha = (struct ast_ha **)(obj + opt->args[0]);
01371    int error = 0;
01372    *ha = ast_append_ha(opt->flags ? "permit" : "deny", var->value, *ha, &error);
01373    return error;
01374 }

void aco_info_destroy ( struct aco_info info  ) 

Destroy an initialized aco_info struct.

Parameters:
info The address of the aco_info struct to destroy

Definition at line 821 of file config_options.c.

References ast_free, aco_info::files, aco_info::internal, internal_file_types_destroy(), and NULL.

Referenced by aco_info_init(), ast_ari_config_destroy(), ast_ari_config_init(), ast_features_config_shutdown(), cdr_engine_shutdown(), cel_engine_cleanup(), conf_destroy_config(), destroy_config(), load_module(), named_acl_cleanup(), sorcery_object_type_destructor(), stasis_cleanup(), udptl_shutdown(), and unload_module().

00822 {
00823    int x;
00824    /* It shouldn't be possible for internal->pending to be in use when this is called because
00825     * of the locks in loader.c around reloads and unloads and the fact that internal->pending
00826     * only exists while those locks are held */
00827    ast_free(info->internal);
00828    info->internal = NULL;
00829 
00830    for (x = 0; info->files[x]; x++) {
00831       internal_file_types_destroy(info->files[x]);
00832    }
00833 }

int aco_info_init ( struct aco_info info  ) 

Initialize an aco_info structure.

Note:
aco_info_destroy must be called if this succeeds
Parameters:
info The address of an aco_info struct to initialize
Return values:
0 Success
non-zero Failure

Definition at line 789 of file config_options.c.

References aco_info_destroy(), ACO_WHITELIST, ast_calloc, aco_type::category, aco_type::category_match, error(), aco_info::files, aco_type::hidden, aco_info::hidden, aco_info::internal, internal_type_init(), aco_type::matchfield, aco_type::matchvalue, aco_info::module, aco_type::name, type, and aco_file::types.

Referenced by __ast_sorcery_object_register(), ast_ari_config_init(), ast_cel_engine_init(), ast_named_acl_init(), AST_TEST_DEFINE(), ast_udptl_init(), conf_load_config(), load_config(), load_module(), process_config(), and stasis_init().

00790 {
00791    size_t x = 0, y = 0;
00792    struct aco_file *file;
00793    struct aco_type *type;
00794 
00795    if (!(info->internal = ast_calloc(1, sizeof(*info->internal)))) {
00796       return -1;
00797    }
00798 
00799    while ((file = info->files[x++])) {
00800       while ((type = file->types[y++])) {
00801          if (internal_type_init(type)) {
00802             goto error;
00803          }
00804 #ifdef AST_XML_DOCS
00805          if (!info->hidden &&
00806             !type->hidden &&
00807             xmldoc_update_config_type(info->module, type->name, type->category, type->matchfield, type->matchvalue, type->category_match == ACO_WHITELIST)) {
00808             goto error;
00809          }
00810 #endif /* AST_XML_DOCS */
00811       }
00812       y = 0;
00813    }
00814 
00815    return 0;
00816 error:
00817    aco_info_destroy(info);
00818    return -1;
00819 }

int aco_init ( void   ) 

Provided by config_options.c

Definition at line 1281 of file config_options.c.

References ARRAY_LEN, ast_cli_register_multiple(), ast_log, ast_register_cleanup(), and LOG_ERROR.

Referenced by main().

01282 {
01283 #ifdef AST_XML_DOCS
01284    ast_register_cleanup(aco_deinit);
01285    if (!(xmldocs = ast_xmldoc_build_documentation("configInfo"))) {
01286       ast_log(LOG_ERROR, "Couldn't build config documentation\n");
01287       return -1;
01288    }
01289    ast_cli_register_multiple(cli_aco, ARRAY_LEN(cli_aco));
01290 #endif /* AST_XML_DOCS */
01291    return 0;
01292 }

struct ao2_container* aco_option_container_alloc ( void   )  [read]

Allocate a container to hold config options.

Definition at line 389 of file config_options.c.

References ao2_container_alloc, CONFIG_OPT_BUCKETS, config_opt_cmp(), and config_opt_hash().

Referenced by internal_type_init().

static struct aco_option* aco_option_find ( struct aco_type type,
const char *  name 
) [static, read]

Definition at line 372 of file config_options.c.

References ao2_callback, ast_log, find_option_cb(), aco_type::internal, LOG_NOTICE, NULL, OBJ_KEY, and aco_type_internal::opts.

Referenced by aco_process_var().

00373 {
00374    struct aco_option *opt;
00375 
00376    if (!type || !type->internal || !type->internal->opts) {
00377       ast_log(LOG_NOTICE, "Attempting to use NULL or unitialized config type\n");
00378       return NULL;
00379    }
00380 
00381    /* Try an exact match with OBJ_KEY for the common/fast case, then iterate through
00382     * all options for the regex cases */
00383    if (!(opt = ao2_callback(type->internal->opts, OBJ_KEY, find_option_cb, (void *) name))) {
00384       opt = ao2_callback(type->internal->opts, 0, find_option_cb, (void *) name);
00385    }
00386    return opt;
00387 }

intptr_t aco_option_get_argument ( const struct aco_option option,
unsigned int  position 
)

Get the offset position for an argument within a config option.

Parameters:
option Pointer to the aco_option struct
arg Argument number
Return values:
position of the argument

Definition at line 235 of file config_options.c.

References aco_option::args.

Referenced by timeval_str2struct().

00236 {
00237    return option->args[position];
00238 }

unsigned int aco_option_get_flags ( const struct aco_option option  ) 

Read the flags of a config option - useful when using a custom callback for a config option.

Since:
12
Parameters:
option Pointer to the aco_option struct
Return values:
value of the flags on the config option

Definition at line 230 of file config_options.c.

References aco_option::flags.

Referenced by option_handler_parkedfeature().

00231 {
00232    return option->flags;
00233 }

int aco_option_register_deprecated ( struct aco_info info,
const char *  name,
struct aco_type **  types,
const char *  aliased_to 
)

Register a deprecated (and aliased) config option.

Parameters:
info A pointer to the aco_info struct
name The name of the deprecated option
types An array of valid option types for matching categories to the correct struct type
aliased_to The name of the option that this deprecated option matches to
Return values:
0 Success
-1 Failure

Definition at line 205 of file config_options.c.

References ACO_EXACT, aco_option::aliased_to, ao2_alloc, ao2_ref, ast_strlen_zero, config_option_destroy(), aco_option::deprecated, link_option_to_types(), aco_option::match_type, and aco_option::name.

Referenced by AST_TEST_DEFINE().

00206 {
00207    struct aco_option *opt;
00208 
00209    if (!info || ast_strlen_zero(name) || ast_strlen_zero(aliased_to)) {
00210       return -1;
00211    }
00212 
00213    if (!(opt = ao2_alloc(sizeof(*opt), config_option_destroy))) {
00214       return -1;
00215    }
00216 
00217    opt->name = name;
00218    opt->aliased_to = aliased_to;
00219    opt->deprecated = 1;
00220    opt->match_type = ACO_EXACT;
00221 
00222    if (link_option_to_types(info, types, opt)) {
00223       ao2_ref(opt, -1);
00224       return -1;
00225    }
00226 
00227    return 0;
00228 }

void* aco_pending_config ( struct aco_info info  ) 

Get pending config changes.

Note:
This will most likely be called from the pre_apply_config callback function
Parameters:
info An initialized aco_info
Return values:
NULL error
non-NULL A pointer to the user-defined config object with un-applied changes

Definition at line 99 of file config_options.c.

References ast_log, aco_info::internal, LOG_ERROR, NULL, and aco_info_internal::pending.

Referenced by cel_pre_apply_config(), configure_parking_extensions(), features_pre_apply_config(), menu_template_handler(), udptl_pre_apply_config(), unbound_config_preapply_callback(), verify_default_parking_lot(), and verify_default_profiles().

00100 {
00101    if (!(info && info->internal)) {
00102       ast_log(LOG_ERROR, "This may not be called without an initialized aco_info!\n");
00103       return NULL;
00104    }
00105    return info->internal->pending;
00106 }

enum aco_process_status aco_process_ast_config ( struct aco_info info,
struct aco_file file,
struct ast_config cfg 
)

Process config info from an ast_config via options registered with an aco_info.

Parameters:
info The aco_info to be used for handling the config
file The file attached to aco_info that the config represents
cfg A pointer to a loaded ast_config to parse
Return values:
ACO_PROCESS_OK Success
ACO_PROCESS_ERROR Failure

Definition at line 556 of file config_options.c.

References ACO_PROCESS_ERROR, ACO_PROCESS_OK, ao2_cleanup, apply_config(), ast_log, error(), aco_file::filename, aco_info::internal, internal_process_ast_config(), LOG_ERROR, aco_info_internal::pending, aco_info::pre_apply_config, and aco_info::snapshot_alloc.

00557 {
00558    if (!info->internal) {
00559       ast_log(LOG_ERROR, "Attempt to process %s with uninitialized aco_info\n", file->filename);
00560       goto error;
00561    }
00562 
00563    if (!(info->internal->pending = info->snapshot_alloc())) {
00564       ast_log(LOG_ERROR, "In %s: Could not allocate temporary objects\n", file->filename);
00565       goto error;
00566    }
00567 
00568    if (internal_process_ast_config(info, file, cfg)) {
00569       goto error;
00570    }
00571 
00572    if (info->pre_apply_config && info->pre_apply_config()) {
00573       goto error;
00574    }
00575 
00576    if (apply_config(info)) {
00577       goto error;
00578    };
00579 
00580    ao2_cleanup(info->internal->pending);
00581    return ACO_PROCESS_OK;
00582 
00583 error:
00584    ao2_cleanup(info->internal->pending);
00585    return ACO_PROCESS_ERROR;
00586 }

int aco_process_category_options ( struct aco_type type,
struct ast_config cfg,
const char *  cat,
void *  obj 
)

Parse each option defined in a config category.

Parameters:
type The aco_type with the options for parsing
cfg The ast_config being parsed
cat The config category being parsed
obj The user-defined config object that will store the parsed config items
Return values:
0 Success
-1 Failure

Definition at line 727 of file config_options.c.

References aco_process_var(), ast_variable_browse(), ast_variable::next, and var.

Referenced by process_category().

00728 {
00729    struct ast_variable *var;
00730 
00731    for (var = ast_variable_browse(cfg, cat); var; var = var->next) {
00732       if (aco_process_var(type, cat, var, obj)) {
00733          return -1;
00734       }
00735    }
00736 
00737    return 0;
00738 }

enum aco_process_status aco_process_config ( struct aco_info info,
int  reload 
)

Process a config info via the options registered with an aco_info.

Parameters:
info The config_options_info to be used for handling the config
reload Non-zero if this is for a reload.
Return values:
ACO_PROCESS_OK Success
ACO_PROCESS_ERROR Failure
ACO_PROCESS_UNCHANGED No change due to unedited config file

Definition at line 588 of file config_options.c.

References ACO_GLOBAL, ACO_PROCESS_ERROR, ACO_PROCESS_OK, ACO_PROCESS_UNCHANGED, aco_set_defaults(), aco_file::alias, ao2_cleanup, apply_config(), ast_clear_flag, ast_config_destroy(), ast_config_load, ast_debug, ast_log, aco_type::category, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, CONFIG_STATUS_FILEUNCHANGED, end, aco_file::filename, aco_info::files, aco_info::internal, internal_process_ast_config(), aco_type::item_offset, LOG_ERROR, match(), aco_info::module, aco_info_internal::pending, aco_info::post_apply_config, aco_info::pre_apply_config, aco_info::snapshot_alloc, aco_type::type, and aco_file::types.

Referenced by __ast_udptl_reload(), ast_cel_engine_init(), ast_cel_engine_reload(), ast_features_config_reload(), ast_named_acl_init(), ast_named_acl_reload(), AST_TEST_DEFINE(), conf_load_config(), conf_reload_config(), load_config(), load_module(), process_config(), reload(), reload_module(), and stasis_init().

00589 {
00590    struct ast_config *cfg;
00591    struct ast_flags cfg_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0, };
00592    int res = ACO_PROCESS_OK;
00593    int file_count = 0;
00594    struct aco_file *file;
00595 
00596    if (!info->internal) {
00597       ast_log(LOG_ERROR, "Attempting to process uninitialized aco_info\n");
00598       return ACO_PROCESS_ERROR;
00599    }
00600 
00601    if (!(info->files[0])) {
00602       ast_log(LOG_ERROR, "No filename given, cannot proceed!\n");
00603       return ACO_PROCESS_ERROR;
00604    }
00605 
00606    if (!(info->internal->pending = info->snapshot_alloc())) {
00607       ast_log(LOG_ERROR, "In %s: Could not allocate temporary objects\n", info->module);
00608       return ACO_PROCESS_ERROR;
00609    }
00610 
00611    while (res != ACO_PROCESS_ERROR && (file = info->files[file_count++])) {
00612       const char *filename = file->filename;
00613       struct aco_type *match;
00614       int i;
00615 
00616       /* set defaults for global objects */
00617       for (i = 0, match = file->types[i]; match; match = file->types[++i]) {
00618          void **field = info->internal->pending + match->item_offset;
00619 
00620          if (match->type != ACO_GLOBAL || !*field) {
00621             continue;
00622          }
00623 
00624          if (aco_set_defaults(match, match->category, *field)) {
00625             ast_log(LOG_ERROR, "In %s: Setting defaults for %s failed\n", file->filename, match->category);
00626             res = ACO_PROCESS_ERROR;
00627             break;
00628          }
00629       }
00630 
00631       if (res == ACO_PROCESS_ERROR) {
00632          break;
00633       }
00634 
00635 try_alias:
00636       cfg = ast_config_load(filename, cfg_flags);
00637       if (!cfg || cfg == CONFIG_STATUS_FILEMISSING) {
00638          if (file->alias && strcmp(file->alias, filename)) {
00639             filename = file->alias;
00640             goto try_alias;
00641          }
00642          ast_log(LOG_ERROR, "Unable to load config file '%s'\n", file->filename);
00643          res = ACO_PROCESS_ERROR;
00644          break;
00645       } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
00646          ast_debug(1, "%s was unchanged\n", file->filename);
00647          res = ACO_PROCESS_UNCHANGED;
00648          continue;
00649       } else if (cfg == CONFIG_STATUS_FILEINVALID) {
00650          ast_log(LOG_ERROR, "Contents of %s are invalid and cannot be parsed\n",
00651             file->filename);
00652          res = ACO_PROCESS_ERROR;
00653          break;
00654       }
00655 
00656       /* A file got loaded. */
00657       if (reload) {
00658          /* Must do any subsequent file loads unconditionally. */
00659          reload = 0;
00660          ast_clear_flag(&cfg_flags, CONFIG_FLAG_FILEUNCHANGED);
00661 
00662          if (file_count != 1) {
00663             /*
00664              * Must restart loading to load all config files since a file
00665              * after the first one changed.
00666              */
00667             file_count = 0;
00668          } else {
00669             res = internal_process_ast_config(info, file, cfg);
00670          }
00671       } else {
00672          res = internal_process_ast_config(info, file, cfg);
00673       }
00674       ast_config_destroy(cfg);
00675    }
00676 
00677    if (res != ACO_PROCESS_OK) {
00678       goto end;
00679    }
00680 
00681    if (info->pre_apply_config && info->pre_apply_config()) {
00682       res = ACO_PROCESS_ERROR;
00683       goto end;
00684    }
00685 
00686    if (apply_config(info)) {
00687       res = ACO_PROCESS_ERROR;
00688       goto end;
00689    }
00690 
00691    if (info->post_apply_config) {
00692       info->post_apply_config();
00693    }
00694 
00695 end:
00696    ao2_cleanup(info->internal->pending);
00697    return res;
00698 }

int aco_process_var ( struct aco_type type,
const char *  cat,
struct ast_variable var,
void *  obj 
)

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.
Parameters:
type The aco_type associated with the object
cat The category to use
var A variable to apply to the object
obj A pointer to the object to be configured
Return values:
0 Success
-1 Failure

Definition at line 699 of file config_options.c.

References aco_option_find(), ao2_cleanup, ao2_ref, ast_log, ast_strdupa, ast_strlen_zero, ast_variable::file, ast_variable::lineno, LOG_ERROR, LOG_WARNING, ast_variable::name, RAII_VAR, and ast_variable::value.

Referenced by aco_process_category_options(), ast_sorcery_objectset_apply(), and func_confbridge_helper().

00700 {
00701    RAII_VAR(struct aco_option *, opt, aco_option_find(type, var->name), ao2_cleanup);
00702    if (opt && opt->deprecated && !ast_strlen_zero(opt->aliased_to)) {
00703       const char *alias = ast_strdupa(opt->aliased_to);
00704       ast_log(LOG_WARNING, "At line %d of %s option '%s' is deprecated. Use '%s' instead\n", var->lineno, var->file, var->name, alias);
00705       ao2_ref(opt, -1);
00706       opt = aco_option_find(type, alias);
00707    }
00708 
00709    if (!opt) {
00710       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);
00711       return -1;
00712    }
00713 
00714    if (!opt->handler) {
00715       /* It should be impossible for an option to not have a handler */
00716       ast_log(LOG_ERROR, "BUG! Somehow a config option for %s/%s was created with no handler!\n", cat, var->name);
00717       return -1;
00718    }
00719    if (opt->handler(opt, var, obj)) {
00720       ast_log(LOG_ERROR, "Error parsing %s=%s at line %d of %s\n", var->name, var->value, var->lineno, var->file);
00721       return -1;
00722    }
00723 
00724    return 0;
00725 }

int aco_set_defaults ( struct aco_type type,
const char *  category,
void *  obj 
)

Set all default options of obj.

Parameters:
type The aco_type with the options
category The configuration category from which obj is being configured
obj The object being configured
Return values:
0 Success
-1 Failure

Definition at line 835 of file config_options.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_log, ast_strlen_zero, ast_variable_new(), ast_variables_destroy(), aco_option::default_val, aco_option::handler, aco_type::internal, LOG_ERROR, aco_option::name, NULL, aco_type_internal::opts, RAII_VAR, and var.

Referenced by __ast_udptl_reload(), aco_process_config(), ast_cel_engine_init(), ast_sorcery_alloc(), conf_alloc(), load_config(), process_category(), process_config(), stasis_init(), unbound_config_apply_default(), verify_default_parking_lot(), and verify_default_profiles().

00836 {
00837    struct aco_option *opt;
00838    struct ao2_iterator iter;
00839 
00840    iter = ao2_iterator_init(type->internal->opts, 0);
00841 
00842    while ((opt = ao2_iterator_next(&iter))) {
00843       RAII_VAR(struct ast_variable *, var, NULL, ast_variables_destroy);
00844 
00845       if (ast_strlen_zero(opt->default_val)) {
00846          ao2_ref(opt, -1);
00847          continue;
00848       }
00849       if (!(var = ast_variable_new(opt->name, opt->default_val, ""))) {
00850          ao2_ref(opt, -1);
00851          ao2_iterator_destroy(&iter);
00852          return -1;
00853       }
00854       if (opt->handler(opt, var, obj)) {
00855          ast_log(LOG_ERROR, "Unable to set default for %s, %s=%s\n", category, var->name, var->value);
00856          ao2_ref(opt, -1);
00857          ao2_iterator_destroy(&iter);
00858          return -1;
00859       }
00860       ao2_ref(opt, -1);
00861    }
00862    ao2_iterator_destroy(&iter);
00863 
00864    return 0;
00865 }

static int apply_config ( struct aco_info info  )  [static]

static aco_option_handler ast_config_option_default_handler ( enum aco_option_type  type  )  [static]

static int bool_handler_fn ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
) [static]

Default option handler for bools (ast_true/ast_false).

Note:
For a description of the opt->flags and opt->args values, see the documentation for enum aco_option_type in config_options.h

Definition at line 1406 of file config_options.c.

References aco_option::args, ast_false(), ast_true(), aco_option::flags, and ast_variable::value.

Referenced by ast_config_option_default_handler(), and sorcery_field_default_handler().

01407 {
01408    unsigned int *field = (unsigned int *)(obj + opt->args[0]);
01409    *field = opt->flags ? ast_true(var->value) : ast_false(var->value);
01410    return 0;
01411 }

static int boolflag_handler_fn ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
) [static]

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

Definition at line 1417 of file config_options.c.

References aco_option::args, ast_false(), ast_true(), aco_option::flags, and ast_variable::value.

Referenced by ast_config_option_default_handler().

01418 {
01419    unsigned int *flags_field = (unsigned int *)(obj + opt->args[0]);
01420    unsigned int val = opt->flags ? ast_true(var->value) : ast_false(var->value);
01421    unsigned int flag = opt->args[1];
01422    if (val) {
01423       *flags_field |= flag;
01424    } else {
01425       *flags_field &= ~flag;
01426    }
01427    return 0;
01428 }

static regex_t* build_regex ( const char *  text  )  [static]

Definition at line 155 of file config_options.c.

References ast_free, ast_log, ast_malloc, buf, len(), LOG_ERROR, NULL, and regex().

Referenced by __aco_option_register(), asterisk_start_devicestate_publishing(), asterisk_start_mwi_publishing(), internal_type_init(), process_category(), and regex_filter_handler().

00156 {
00157    int res;
00158    regex_t *regex;
00159 
00160    if (!(regex = ast_malloc(sizeof(*regex)))) {
00161       return NULL;
00162    }
00163 
00164    if ((res = regcomp(regex, text, REG_EXTENDED | REG_ICASE | REG_NOSUB))) {
00165       size_t len = regerror(res, regex, NULL, 0);
00166       char buf[len];
00167       regerror(res, regex, buf, len);
00168       ast_log(LOG_ERROR, "Could not compile regex '%s': %s\n", text, buf);
00169       ast_free(regex);
00170       return NULL;
00171    }
00172 
00173    return regex;
00174 }

static int chararray_handler_fn ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
) [static]

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

Definition at line 1451 of file config_options.c.

References aco_option::args, ast_copy_string(), ast_strlen_zero, aco_option::flags, len(), and ast_variable::value.

Referenced by ast_config_option_default_handler(), and sorcery_field_default_handler().

01452 {
01453    char *field = (char *)(obj + opt->args[0]);
01454    size_t len = opt->args[1];
01455 
01456    if (opt->flags && ast_strlen_zero(var->value)) {
01457       return -1;
01458    }
01459    ast_copy_string(field, var->value, len);
01460    return 0;
01461 }

static int codec_handler_fn ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
) [static]

Default option handler for codec preferences/capabilities.

Note:
For a description of the opt->flags and opt->args values, see the documentation for enum aco_option_type in config_options.h

Definition at line 1380 of file config_options.c.

References aco_option::args, ast_format_cap_update_by_allow_disallow(), aco_option::flags, and ast_variable::value.

Referenced by ast_config_option_default_handler(), and sorcery_field_default_handler().

01380                                                                                                {
01381    struct ast_format_cap **cap = (struct ast_format_cap **)(obj + opt->args[0]);
01382    return ast_format_cap_update_by_allow_disallow(*cap, var->value, opt->flags);
01383 }

static int config_opt_cmp ( void *  obj,
void *  arg,
int  flags 
) [static]

Definition at line 350 of file config_options.c.

References CMP_MATCH, CMP_STOP, aco_option::name, and OBJ_KEY.

Referenced by aco_option_container_alloc().

00351 {
00352    struct aco_option *opt1 = obj, *opt2 = arg;
00353    const char *name = (flags & OBJ_KEY) ? arg : opt2->name;
00354    return strcasecmp(opt1->name, name) ? 0 : CMP_MATCH | CMP_STOP;
00355 }

static int config_opt_hash ( const void *  obj,
const int  flags 
) [static]

Definition at line 343 of file config_options.c.

References ast_str_case_hash(), aco_option::name, and OBJ_KEY.

Referenced by aco_option_container_alloc().

00344 {
00345    const struct aco_option *opt = obj;
00346    const char *name = (flags & OBJ_KEY) ? obj : opt->name;
00347    return ast_str_case_hash(name);
00348 }

static void config_option_destroy ( void *  obj  )  [static]

Definition at line 108 of file config_options.c.

References ACO_REGEX, ast_free, aco_option::match_type, and aco_option::name_regex.

Referenced by __aco_option_register(), and aco_option_register_deprecated().

00109 {
00110    struct aco_option *opt = obj;
00111    if (opt->match_type == ACO_REGEX && opt->name_regex) {
00112       regfree(opt->name_regex);
00113       ast_free(opt->name_regex);
00114    }
00115 }

static int double_handler_fn ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
) [static]

Default option handler for doubles.

Note:
For a description of the opt->flags and opt->args values, see the documentation for enum aco_option_type in config_options.h

Definition at line 1360 of file config_options.c.

References aco_option::args, ast_parse_arg(), aco_option::flags, PARSE_DOUBLE, and ast_variable::value.

Referenced by ast_config_option_default_handler(), and sorcery_field_default_handler().

01360                                                                                                 {
01361    double *field = (double *)(obj + opt->args[0]);
01362    return ast_parse_arg(var->value, PARSE_DOUBLE | opt->flags, field);
01363 }

static int find_option_cb ( void *  obj,
void *  arg,
int  flags 
) [static]

Definition at line 357 of file config_options.c.

References ACO_EXACT, ACO_REGEX, ast_log, CMP_MATCH, CMP_STOP, LOG_ERROR, match(), aco_option::match_type, aco_option::name, aco_option::name_regex, and NULL.

Referenced by aco_option_find().

00358 {
00359    struct aco_option *match = obj;
00360    const char *name = arg;
00361 
00362    switch (match->match_type) {
00363    case ACO_EXACT:
00364       return strcasecmp(name, match->name) ? 0 : CMP_MATCH | CMP_STOP;
00365    case ACO_REGEX:
00366       return regexec(match->name_regex, name, 0, NULL, 0) ? 0 : CMP_MATCH | CMP_STOP;
00367    }
00368    ast_log(LOG_ERROR, "Unknown match type. This should not be possible.\n");
00369    return CMP_STOP;
00370 }

static int int_handler_fn ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
) [static]

Default option handler for signed integers.

Note:
For a description of the opt->flags and opt->args values, see the documentation for enum aco_option_type in config_options.h

Definition at line 1300 of file config_options.c.

References aco_option::args, ast_log, ast_parse_arg(), aco_option::flags, LOG_WARNING, ast_variable::name, PARSE_DEFAULT, PARSE_IN_RANGE, PARSE_INT32, PARSE_RANGE_DEFAULTS, and ast_variable::value.

Referenced by ast_config_option_default_handler(), and sorcery_field_default_handler().

01300                                                                                              {
01301    int *field = (int *)(obj + opt->args[0]);
01302    unsigned int flags = PARSE_INT32 | opt->flags;
01303    int res = 0;
01304    if (opt->flags & PARSE_IN_RANGE) {
01305       res = opt->flags & PARSE_DEFAULT ?
01306          ast_parse_arg(var->value, flags, field, (int) opt->args[1], (int) opt->args[2], opt->args[3]) :
01307          ast_parse_arg(var->value, flags, field, (int) opt->args[1], (int) opt->args[2]);
01308       if (res) {
01309          if (opt->flags & PARSE_RANGE_DEFAULTS) {
01310             ast_log(LOG_WARNING, "Failed to set %s=%s. Set to %d instead due to range limit (%d, %d)\n", var->name, var->value, *field, (int) opt->args[1], (int) opt->args[2]);
01311             res = 0;
01312          } else if (opt->flags & PARSE_DEFAULT) {
01313             ast_log(LOG_WARNING, "Failed to set %s=%s, Set to default value %d instead.\n", var->name, var->value, *field);
01314             res = 0;
01315          }
01316       }
01317    } else if ((opt->flags & PARSE_DEFAULT) && ast_parse_arg(var->value, flags, field, (int) opt->args[1])) {
01318       ast_log(LOG_WARNING, "Attempted to set %s=%s, but set it to %d instead due to default)\n", var->name, var->value, *field);
01319    } else {
01320       res = ast_parse_arg(var->value, flags, field);
01321    }
01322 
01323    return res;
01324 }

static struct aco_type* internal_aco_type_find ( struct aco_file file,
struct ast_config cfg,
const char *  category 
) [static, read]

Definition at line 394 of file config_options.c.

References ast_log, ast_strlen_zero, ast_variable_retrieve(), aco_type::category_match, aco_type::internal, LOG_ERROR, match(), aco_type::matchfield, aco_type::matchfunc, aco_type::matchvalue, NULL, aco_type_internal::regex, and aco_file::types.

Referenced by process_category().

00395 {
00396    size_t x;
00397    struct aco_type *match;
00398    const char *val;
00399 
00400    for (x = 0, match = file->types[x]; match; match = file->types[++x]) {
00401       /* First make sure we are an object that can service this category */
00402       if (!regexec(match->internal->regex, category, 0, NULL, 0) == !match->category_match) {
00403          continue;
00404       }
00405 
00406       /* Then, see if we need to match a particular field */
00407       if (!ast_strlen_zero(match->matchfield) && (!ast_strlen_zero(match->matchvalue) || match->matchfunc)) {
00408          if (!(val = ast_variable_retrieve(cfg, category, match->matchfield))) {
00409             ast_log(LOG_ERROR, "Required match field '%s' not found\n", match->matchfield);
00410             return NULL;
00411          }
00412          if (match->matchfunc) {
00413             if (!match->matchfunc(val)) {
00414                continue;
00415             }
00416          } else if (strcasecmp(val, match->matchvalue)) {
00417             continue;
00418          }
00419       }
00420       /* If we get this far, we're a match */
00421       break;
00422    }
00423 
00424    return match;
00425 }

static void internal_file_types_destroy ( struct aco_file file  )  [static]

Definition at line 759 of file config_options.c.

References internal_type_destroy(), NULL, and aco_file::types.

Referenced by aco_info_destroy().

00760 {
00761    size_t x;
00762    struct aco_type *t;
00763 
00764    for (x = 0, t = file->types[x]; t; t = file->types[++x]) {
00765       internal_type_destroy(t);
00766       t = NULL;
00767    }
00768 }

static enum aco_process_status internal_process_ast_config ( struct aco_info info,
struct aco_file file,
struct ast_config cfg 
) [static]

Definition at line 535 of file config_options.c.

References ACO_PROCESS_ERROR, ACO_PROCESS_OK, ast_category_browse(), ast_strlen_zero, NULL, aco_file::preload, and process_category().

Referenced by aco_process_ast_config(), and aco_process_config().

00536 {
00537    const char *cat = NULL;
00538 
00539    if (file->preload) {
00540       int i;
00541       for (i = 0; !ast_strlen_zero(file->preload[i]); i++) {
00542          if (process_category(cfg, info, file, file->preload[i], 1)) {
00543             return ACO_PROCESS_ERROR;
00544          }
00545       }
00546    }
00547 
00548    while ((cat = ast_category_browse(cfg, cat))) {
00549       if (process_category(cfg, info, file, cat, 0)) {
00550          return ACO_PROCESS_ERROR;
00551       }
00552    }
00553    return ACO_PROCESS_OK;
00554 }

static void internal_type_destroy ( struct aco_type type  )  [static]

Definition at line 740 of file config_options.c.

References ao2_cleanup, ast_free, aco_type::internal, NULL, aco_type_internal::opts, and aco_type_internal::regex.

Referenced by internal_file_types_destroy(), and internal_type_init().

00741 {
00742    /* If we've already had all our internal data cleared out,
00743     * then there's no need to proceed further
00744     */
00745    if (!type->internal) {
00746       return;
00747    }
00748 
00749    if (type->internal->regex) {
00750       regfree(type->internal->regex);
00751       ast_free(type->internal->regex);
00752    }
00753    ao2_cleanup(type->internal->opts);
00754    type->internal->opts = NULL;
00755    ast_free(type->internal);
00756    type->internal = NULL;
00757 }

static int internal_type_init ( struct aco_type type  )  [static]

Definition at line 770 of file config_options.c.

References aco_option_container_alloc(), ast_calloc, build_regex(), aco_type::category, aco_type::internal, internal_type_destroy(), aco_type_internal::opts, and aco_type_internal::regex.

Referenced by aco_info_init().

00771 {
00772    if (!(type->internal = ast_calloc(1, sizeof(*type->internal)))) {
00773       return -1;
00774    }
00775 
00776    if (!(type->internal->regex = build_regex(type->category))) {
00777       internal_type_destroy(type);
00778       return -1;
00779    }
00780 
00781    if (!(type->internal->opts = aco_option_container_alloc())) {
00782       internal_type_destroy(type);
00783       return -1;
00784    }
00785 
00786    return 0;
00787 }

static int is_preload ( struct aco_file file,
const char *  cat 
) [static]

Definition at line 427 of file config_options.c.

References ast_strlen_zero, and aco_file::preload.

Referenced by process_category().

00428 {
00429    int i;
00430 
00431    if (!file->preload) {
00432       return 0;
00433    }
00434 
00435    for (i = 0; !ast_strlen_zero(file->preload[i]); i++) {
00436       if (!strcasecmp(cat, file->preload[i])) {
00437          return 1;
00438       }
00439    }
00440    return 0;
00441 }

static int link_option_to_types ( struct aco_info info,
struct aco_type **  types,
struct aco_option opt 
) [static]

Definition at line 176 of file config_options.c.

References ACO_REGEX, ao2_link, ao2_ref, ao2_unlink, ast_log, aco_option::default_val, aco_info::hidden, aco_type::internal, LOG_ERROR, aco_option::match_type, aco_info::module, aco_type::name, aco_option::name, aco_option::no_doc, aco_type_internal::opts, aco_option::type, and type.

Referenced by __aco_option_register(), and aco_option_register_deprecated().

00177 {
00178    size_t idx = 0;
00179    struct aco_type *type;
00180 
00181    while ((type = types[idx++])) {
00182       if (!type->internal) {
00183          ast_log(LOG_ERROR, "Attempting to register option using uninitialized type\n");
00184          return -1;
00185       }
00186       if (!ao2_link(type->internal->opts, opt)
00187 #ifdef AST_XML_DOCS
00188             || (!info->hidden &&
00189                !opt->no_doc &&
00190                xmldoc_update_config_option(types, info->module, opt->name, type->name, opt->default_val, opt->match_type == ACO_REGEX, opt->type))
00191 #endif /* AST_XML_DOCS */
00192       ) {
00193          do {
00194             ao2_unlink(types[idx - 1]->internal->opts, opt);
00195          } while (--idx);
00196          return -1;
00197       }
00198    }
00199    /* The container(s) should hold the only ref to opt */
00200    ao2_ref(opt, -1);
00201 
00202    return 0;
00203 }

static int noop_handler_fn ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
) [static]

Default handler for doing nothing.

Definition at line 1442 of file config_options.c.

Referenced by ast_config_option_default_handler().

01443 {
01444    return 0;
01445 }

static int process_category ( struct ast_config cfg,
struct aco_info info,
struct aco_file file,
const char *  cat,
int  preload 
) [static]

Definition at line 443 of file config_options.c.

References ACO_GLOBAL, ACO_ITEM, aco_process_category_options(), aco_set_defaults(), ao2_cleanup, ao2_link, ast_free, ast_log, ast_strlen_zero, build_regex(), aco_file::filename, aco_info::internal, internal_aco_type_find(), is_preload(), aco_type::item_alloc, aco_type::item_find, aco_type::item_offset, aco_type::item_pre_process, aco_type::item_prelink, LOG_ERROR, NULL, aco_info_internal::pending, RAII_VAR, aco_file::skip_category, aco_type::type, and type.

Referenced by internal_process_ast_config().

00443                                                                                                                                 {
00444    RAII_VAR(void *, new_item, NULL, ao2_cleanup);
00445    struct aco_type *type;
00446    /* For global types, field is the global option struct. For non-global, it is the container for items.
00447     * We do not grab a reference to these objects, as the info already holds references to them. This
00448     * pointer is just a convenience. Do not actually store it somewhere. */
00449    void **field;
00450    regex_t *regex_skip;
00451 
00452    /* Skip preloaded categories if we aren't preloading */
00453    if (!preload && is_preload(file, cat)) {
00454       return 0;
00455    }
00456 
00457    /* Skip the category if we've been told to ignore it */
00458    if (!ast_strlen_zero(file->skip_category)) {
00459       regex_skip = build_regex(file->skip_category);
00460       if (!regexec(regex_skip, cat, 0, NULL, 0)) {
00461          regfree(regex_skip);
00462          ast_free(regex_skip);
00463          return 0;
00464       }
00465       regfree(regex_skip);
00466       ast_free(regex_skip);
00467    }
00468 
00469    /* Find aco_type by category, if not found it is an error */
00470    if (!(type = internal_aco_type_find(file, cfg, cat))) {
00471       ast_log(LOG_ERROR, "Could not find config type for category '%s' in '%s'\n", cat, file->filename);
00472       return -1;
00473    }
00474 
00475    field = info->internal->pending + type->item_offset;
00476    if (!*field) {
00477       ast_log(LOG_ERROR, "In %s: %s - No object to update!\n", file->filename, cat);
00478       return -1;
00479    }
00480 
00481    if (type->type == ACO_GLOBAL && *field) {
00482       if (aco_process_category_options(type, cfg, cat, *field)) {
00483          ast_log(LOG_ERROR, "In %s: Processing options for %s failed\n", file->filename, cat);
00484          return -1;
00485       }
00486    } else if (type->type == ACO_ITEM) {
00487       int new = 0;
00488       /* If we have multiple definitions of a category in a file, or can set the values from multiple
00489        * files, look up the entry if we've already added it so we can merge the values together.
00490        * Otherwise, alloc a new item. */
00491       if (*field) {
00492          if (!(new_item = type->item_find(*field, cat))) {
00493             if (!(new_item = type->item_alloc(cat))) {
00494                ast_log(LOG_ERROR, "In %s: Could not create item for %s\n", file->filename, cat);
00495                return -1;
00496             }
00497             if (aco_set_defaults(type, cat, new_item)) {
00498                ast_log(LOG_ERROR, "In %s: Setting defaults for %s failed\n", file->filename, cat);
00499                return -1;
00500             }
00501             new = 1;
00502          }
00503       }
00504 
00505       if (type->item_pre_process && type->item_pre_process(new_item)) {
00506          ast_log(LOG_ERROR, "In %s: Preprocess callback for %s failed\n", file->filename, cat);
00507          return -1;
00508       }
00509 
00510       if (aco_process_category_options(type, cfg, cat, new_item)) {
00511          ast_log(LOG_ERROR, "In %s: Processing options for %s failed\n", file->filename, cat);
00512          return -1;
00513       }
00514 
00515       if (type->item_prelink && type->item_prelink(new_item)) {
00516          ast_log(LOG_ERROR, "In %s: Pre-link callback for %s failed\n", file->filename, cat);
00517          return -1;
00518       }
00519 
00520       if (new && !ao2_link(*field, new_item)) {
00521          ast_log(LOG_ERROR, "In %s: Linking config for %s failed\n", file->filename, cat);
00522          return -1;
00523       }
00524    }
00525    return 0;
00526 }

static int sockaddr_handler_fn ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
) [static]

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

Definition at line 1434 of file config_options.c.

References aco_option::args, ast_parse_arg(), aco_option::flags, PARSE_ADDR, and ast_variable::value.

Referenced by ast_config_option_default_handler(), and sorcery_field_default_handler().

01435 {
01436    struct ast_sockaddr *field = (struct ast_sockaddr *)(obj + opt->args[0]);
01437    return ast_parse_arg(var->value, PARSE_ADDR | opt->flags, field);
01438 }

static int stringfield_handler_fn ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
) [static]

Default option handler for stringfields.

Note:
For a description of the opt->flags and opt->args values, see the documentation for enum aco_option_type in config_options.h

Definition at line 1389 of file config_options.c.

References aco_option::args, ast_string_field_ptr_set_by_fields, ast_strlen_zero, aco_option::flags, pool, and ast_variable::value.

Referenced by ast_config_option_default_handler(), and sorcery_field_default_handler().

01390 {
01391    ast_string_field *field = (const char **)(obj + opt->args[0]);
01392    struct ast_string_field_pool **pool = (struct ast_string_field_pool **)(obj + opt->args[1]);
01393    struct ast_string_field_mgr *mgr = (struct ast_string_field_mgr *)(obj + opt->args[2]);
01394 
01395    if (opt->flags && ast_strlen_zero(var->value)) {
01396       return -1;
01397    }
01398    ast_string_field_ptr_set_by_fields(*pool, *mgr, field, var->value);
01399    return 0;
01400 }

static int uint_handler_fn ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
) [static]

Default option handler for unsigned integers.

Note:
For a description of the opt->flags and opt->args values, see the documentation for enum aco_option_type in config_options.h

Definition at line 1330 of file config_options.c.

References aco_option::args, ast_log, ast_parse_arg(), aco_option::flags, LOG_WARNING, ast_variable::name, PARSE_DEFAULT, PARSE_IN_RANGE, PARSE_INT32, PARSE_RANGE_DEFAULTS, and ast_variable::value.

Referenced by ast_config_option_default_handler(), and sorcery_field_default_handler().

01330                                                                                               {
01331    unsigned int *field = (unsigned int *)(obj + opt->args[0]);
01332    unsigned int flags = PARSE_INT32 | opt->flags;
01333    int res = 0;
01334    if (opt->flags & PARSE_IN_RANGE) {
01335       res = opt->flags & PARSE_DEFAULT ?
01336          ast_parse_arg(var->value, flags, field, (unsigned int) opt->args[1], (unsigned int) opt->args[2], opt->args[3]) :
01337          ast_parse_arg(var->value, flags, field, (unsigned int) opt->args[1], (unsigned int) opt->args[2]);
01338       if (res) {
01339          if (opt->flags & PARSE_RANGE_DEFAULTS) {
01340             ast_log(LOG_WARNING, "Failed to set %s=%s. Set to %u instead due to range limit (%d, %d)\n", var->name, var->value, *field, (int) opt->args[1], (int) opt->args[2]);
01341             res = 0;
01342          } else if (opt->flags & PARSE_DEFAULT) {
01343             ast_log(LOG_WARNING, "Failed to set %s=%s, Set to default value %u instead.\n", var->name, var->value, *field);
01344             res = 0;
01345          }
01346       }
01347    } else if ((opt->flags & PARSE_DEFAULT) && ast_parse_arg(var->value, flags, field, (unsigned int) opt->args[1])) {
01348       ast_log(LOG_WARNING, "Attempted to set %s=%s, but set it to %u instead due to default)\n", var->name, var->value, *field);
01349    } else {
01350       res = ast_parse_arg(var->value, flags, field);
01351    }
01352 
01353    return res;
01354 }


Variable Documentation

char* aco_option_type_string[] [static]

Value of the aco_option_type enum as strings.

Definition at line 84 of file config_options.c.


Generated on Thu Apr 16 06:30:26 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6