45#define CONFIG_OPT_BUCKETS 5
47#define CONFIG_OPT_BUCKETS 53
74 unsigned int doc_unavailable:1;
106 ast_log(
LOG_ERROR,
"This may not be called without an initialized aco_info!\n");
109 return info->internal->pending;
174 if ((res = regcomp(
regex,
text, REG_EXTENDED | REG_ICASE | REG_NOSUB))) {
191 while ((
type = types[idx++])) {
192 if (!
type->internal) {
193 ast_log(
LOG_ERROR,
"Attempting to register option using uninitialized type\n");
206 opt->doc_unavailable = 1;
245 return option->
flags;
250 return option->
args[position];
270 for (x = 0; types[x]; x++) {
272 if (!strcasecmp(types[x]->
name, iter->
ref)) {
291 if (!strcasecmp(iter->
type,
"configObject") && !strcasecmp(iter->
name,
name)) {
302 unsigned int no_doc,
size_t argc, ...)
313 if (!(types && types[0])) {
330 opt->
args[
tmp] = va_arg(ap,
size_t);
345 ast_log(
LOG_ERROR,
"No handler provided, and no default handler exists for type %u\n", opt->
type);
375 const char *
name = arg;
377 switch (
match->match_type) {
393 if (!
type || !
type->internal || !
type->internal->opts) {
416 switch (
match->category_match) {
418 return regexec(
match->internal->regex, category, 0,
NULL, 0);
421 return !regexec(
match->internal->regex, category, 0,
NULL, 0);
424 return strcasecmp(
match->category, category);
427 return !strcasecmp(
match->category, category);
469 if (
match->matchfunc) {
473 }
else if (strcasecmp(
val,
match->matchvalue)) {
488 if (!
file->preload) {
493 if (!strcasecmp(cat,
file->preload[i])) {
517 if (!regexec(regex_skip, cat, 0,
NULL, 0)) {
528 ast_log(
LOG_ERROR,
"Could not find config type for category '%s' in '%s'\n", cat,
file->filename);
536 field =
info->internal->pending +
type->item_offset;
553 if (!(new_item =
type->item_find(*field, cat))) {
554 if (!(new_item =
type->item_alloc(cat))) {
566 if (
type->item_pre_process &&
type->item_pre_process(new_item)) {
576 if (
type->item_prelink &&
type->item_prelink(new_item)) {
581 if (
new && !
ao2_link(*field, new_item)) {
598 const char *cat =
NULL;
619 if (!
info->internal) {
624 if (!(
info->internal->pending =
info->snapshot_alloc())) {
633 if (
info->pre_apply_config &&
info->pre_apply_config()) {
660 if (!
info->internal) {
665 if (!(
info->files[0])) {
670 if (!(
info->internal->pending =
info->snapshot_alloc())) {
682 void **field =
info->internal->pending +
match->item_offset;
706 if (
file->alias && strcmp(
file->alias, filename)) {
707 filename =
file->alias;
730 if (file_count != 1) {
749 if (
info->pre_apply_config &&
info->pre_apply_config()) {
759 if (
info->post_apply_config) {
760 info->post_apply_config();
780 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);
786 ast_log(
LOG_ERROR,
"BUG! Somehow a config option for %s/%s was created with no handler!\n", cat,
var->name);
791 if (opt->doc_unavailable) {
792 ast_log(
LOG_ERROR,
"Config option '%s' of type '%s' is not completely documented and can not be set\n",
var->name,
type->name);
797 if (opt->handler(opt,
var, obj)) {
823 if (!
type->internal) {
827 if (
type->internal->regex) {
828 regfree(
type->internal->regex);
842 for (x = 0, t =
file->types[x]; t; t =
file->types[++x]) {
854 switch (
type->category_match) {
919 for (x = 0;
info->files[x]; x++) {
929 if (!
type->internal) {
967 size_t wordlen = strlen(
word);
973 if (!strncasecmp(
word, cur->
name, wordlen)) {
991 size_t wordlen = strlen(
word);
1002 if (!strcasecmp(cur->
type,
"configObject") && !strncasecmp(
word, cur->
name, wordlen)) {
1018 size_t wordlen = strlen(
word);
1029 if (!strcasecmp(cur->
type,
"configOption") && !strcasecmp(cur->
ref, option) && !strncasecmp(
word, cur->
name, wordlen)) {
1051 switch (category_match) {
1055 const char **matches = (
const char **) category;
1057 for (i = 0; matches[i]; i++) {
1082#define XMLDOC_STRICT 1
1092 struct ast_xml_node *
type, *syntax, *matchinfo, *
tmp;
1097 if ((results =
ast_xmldoc_query(
"/docs/configInfo[@name='%s']/configFile/configObject[@name='%s']/syntax", module,
name))) {
1101 if (!(results =
ast_xmldoc_query(
"/docs/configInfo[@name='%s']/configFile/configObject[@name='%s']", module,
name))) {
1102 ast_log(
LOG_WARNING,
"Cannot update type '%s' in module '%s' because it has no existing documentation!"
1103 " If this module was recently built, run 'xmldoc reload' to refresh documentation, then load the module again\n",
1129 if (derived_category) {
1134 switch (category_match) {
1149 ast_log(
LOG_WARNING,
"Could not add %s attribute for type '%s' in module '%s'\n", matchfield,
name, module);
1177 struct ast_xml_node *option;
1182 ast_log(
LOG_ERROR,
"XML Documentation for option '%s' in modules '%s' not found!\n",
name, module);
1186 if (!(results =
ast_xmldoc_query(
"/docs/configInfo[@name='%s']/configFile/configObject[@name='%s']/configOption[@name='%s']", module, object_name,
name))) {
1187 ast_log(
LOG_WARNING,
"Could not find option '%s' with type '%s' in module '%s'\n",
name, object_name, module);
1192 ast_log(
LOG_WARNING,
"Could not obtain results for option '%s' with type '%s' in module '%s'\n",
name, object_name, module);
1200 ast_log(
LOG_WARNING,
"Could not update option '%s' with values from config option registration\n",
name);
1218 ast_cli(
a->fd,
"No modules found.\n");
1223 ast_cli(
a->fd,
"The following modules have configuration information:\n");
1242 ast_cli(
a->fd,
"Module %s not found.\n",
a->argv[3]);
1254 ast_cli(
a->fd,
"Configuration option types for %s:\n",
tmp->name);
1256 if (!strcasecmp(
tmp->type,
"configObject")) {
1270 char option_type[64];
1276 ast_cli(
a->fd,
"Unknown module %s\n",
a->argv[3]);
1282 if (!strcasecmp(
tmp->type,
"configObject") && !strcasecmp(
tmp->name,
a->argv[4])) {
1301 ast_cli(
a->fd,
"Unknown configuration type %s\n",
a->argv[4]);
1308 if (!strcasecmp(
tmp->type,
"configOption") && !strcasecmp(
tmp->ref,
a->argv[4])) {
1309 ast_cli(
a->fd,
"%-25s -- %-120.120s\n",
tmp->name,
1322 char option_name[64];
1328 ast_cli(
a->fd,
"Unknown module %s\n",
a->argv[3]);
1333 if (!strcasecmp(
tmp->type,
"configOption") && !strcasecmp(
tmp->ref,
a->argv[4]) && !strcasecmp(
tmp->name,
a->argv[5])) {
1357 ast_cli(
a->fd,
"No option %s found for %s:%s\n",
a->argv[5],
a->argv[3],
a->argv[4]);
1365 e->
command =
"config show help";
1367 "Usage: config show help [<module> [<type> [<option>]]]\n"
1368 " Display detailed information about module configuration.\n"
1369 " * If nothing is specified, the modules that have\n"
1370 " configuration information are listed.\n"
1371 " * If <module> is specified, the configuration types\n"
1372 " for that module will be listed, along with brief\n"
1373 " information about that type.\n"
1374 " * If <module> and <type> are specified, detailed\n"
1375 " information about the type is displayed, as well\n"
1376 " as the available options.\n"
1377 " * If <module>, <type>, and <option> are specified,\n"
1378 " detailed information will be displayed about that\n"
1380 " NOTE: the help documentation is partially generated at run\n"
1381 " time when a module is loaded. If a module is not loaded,\n"
1382 " configuration help for that module may be incomplete.\n";
1448 int *field = (
int *)(obj + opt->
args[0]);
1457 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]);
1465 ast_log(
LOG_WARNING,
"Attempted to set %s=%s, but set it to %d instead due to default)\n",
var->name,
var->value, *field);
1478 unsigned int *field = (
unsigned int *)(obj + opt->
args[0]);
1487 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]);
1495 ast_log(
LOG_WARNING,
"Attempted to set %s=%s, but set it to %u instead due to default)\n",
var->name,
var->value, *field);
1509 int *field = (
int *)(obj + opt->
args[0]);
1520 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[2], (
int) opt->
args[3]);
1528 ast_log(
LOG_WARNING,
"Attempted to set %s=%s, but set it to %d instead due to default)\n",
var->name,
var->value, *field);
1541 double *field = (
double *)(obj + opt->
args[0]);
1588 unsigned int *field = (
unsigned int *)(obj + opt->
args[0]);
1599 unsigned int *flags_field = (
unsigned int *)(obj + opt->
args[0]);
1603 *flags_field |=
flag;
1605 *flags_field &=
~flag;
1633 char *field = (
char *)(obj + opt->
args[0]);
Prototypes for public functions only of internal interest,.
Access Control of various sorts.
struct ast_ha * ast_append_ha(const char *sense, const char *stuff, struct ast_ha *path, int *error)
Add a new rule to a list of HAs.
Asterisk main include file. File version handling, generic pbx functions.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
#define ast_strdup(str)
A wrapper for strdup()
#define ast_strdupa(s)
duplicate a string in memory from the stack
#define ast_calloc(num, len)
A wrapper for calloc()
#define ast_malloc(len)
A wrapper for malloc()
#define ao2_iterator_next(iter)
#define ao2_link(container, obj)
Add an object to a container.
@ AO2_ALLOC_OPT_LOCK_NOLOCK
@ AO2_ALLOC_OPT_LOCK_MUTEX
#define ao2_global_obj_replace_unref(holder, obj)
Replace an ao2 object in the global holder, throwing away any old object.
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
#define ao2_unlink(container, obj)
Remove an object from a container.
#define ao2_find(container, arg, flags)
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define ao2_alloc_options(data_size, destructor_fn, options)
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Standard Command Line Interface.
int ast_cli_unregister(struct ast_cli_entry *e)
Unregisters a command or an array of commands.
#define AST_CLI_DEFINE(fn, txt,...)
int ast_cli_completion_add(char *value)
Add a result to a request for completion options.
void ast_cli(int fd, const char *fmt,...)
#define ast_cli_register_multiple(e, len)
Register multiple commands.
struct ao2_container * aco_option_container_alloc(void)
Allocate a container to hold config options.
#define CONFIG_OPT_BUCKETS
static struct ao2_container * xmldocs
static char * aco_option_type_string[]
Value of the aco_option_type enum as strings.
static void internal_type_destroy(struct aco_type *type)
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 struct ast_cli_entry cli_aco[]
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.
static int find_option_cb(void *obj, void *arg, int flags)
int aco_set_defaults(struct aco_type *type, const char *category, void *obj)
Set all default options of obj.
void aco_info_destroy(struct aco_info *info)
Destroy an initialized aco_info struct.
static int chararray_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj)
Default handler for character arrays.
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 process_category(struct ast_config *cfg, struct aco_info *info, struct aco_file *file, const char *cat, int preload)
static int xmldoc_update_config_option(struct aco_type **types, const char *module, const char *name, const char *object_name, const char *default_value, unsigned int regex, enum aco_option_type type)
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_hash(const void *obj, const int flags)
static int internal_type_init(struct aco_type *type)
int aco_info_init(struct aco_info *info)
Initialize an aco_info structure.
static int config_opt_cmp(void *obj, void *arg, int flags)
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 int timelen_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj)
Default option handler for timelen signed integers.
static void aco_deinit(void)
static void config_option_destroy(void *obj)
static int uint_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj)
Default option handler for unsigned integers.
static int apply_config(struct aco_info *info)
static int double_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj)
Default option handler for doubles.
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 link_option_to_types(struct aco_info *info, struct aco_type **types, struct aco_option *opt)
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.
static struct ast_xml_doc_item * find_xmldoc_type(struct ast_xml_doc_item *config_info, const char *name)
static regex_t * build_regex(const char *text)
static void cli_show_modules(struct ast_cli_args *a)
static void internal_file_types_destroy(struct aco_file *file)
static struct ast_xml_doc_item * find_xmldoc_option(struct ast_xml_doc_item *config_info, struct aco_type **types, const char *name)
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.
static struct ast_str * derive_category_text(enum aco_category_op category_match, const char *category)
static char * complete_config_module(const char *word)
static int internal_aco_type_category_check(struct aco_type *match, const char *category)
static aco_option_handler ast_config_option_default_handler(enum aco_option_type type)
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.
static int acl_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj)
Default handler for ACLs.
static int noop_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj)
Default handler for doing nothing.
static void cli_show_module_types(struct ast_cli_args *a)
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.
static int xmldoc_update_config_type(const char *module, const char *name, const char *category, const char *matchfield, const char *matchvalue, enum aco_category_op category_match)
static enum aco_process_status internal_process_ast_config(struct aco_info *info, struct aco_file *file, struct ast_config *cfg)
static char * complete_config_option(const char *module, const char *option, const char *word)
static void cli_show_module_options(struct ast_cli_args *a)
static int is_preload(struct aco_file *file, const char *cat)
static struct aco_type * internal_aco_type_find(struct aco_file *file, struct ast_config *cfg, const char *category)
static struct aco_option * aco_option_find(struct aco_type *type, const char *name)
void * aco_pending_config(struct aco_info *info)
Get pending config changes.
static char * complete_config_type(const char *module, const char *word)
static void cli_show_module_type(struct ast_cli_args *a)
static char * cli_show_help(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
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.
static int int_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj)
Default option handler for signed integers.
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.
Configuration option-handling.
int(* aco_option_handler)(const struct aco_option *opt, struct ast_variable *var, void *obj)
A callback function for handling a particular option.
aco_matchtype
What kind of matching should be done on an option name.
aco_process_status
Return values for the aco_process functions.
@ ACO_PROCESS_UNCHANGED
The config had not been edited and no changes applied.
@ ACO_PROCESS_ERROR
Their was an error and no changes were applied.
@ ACO_PROCESS_OK
The config was processed and applied.
aco_option_type
The option types.
@ OPT_UINT_T
Type for default option handler for unsigned integers.
@ OPT_NOOP_T
Type for a default handler that should do nothing.
@ OPT_CODEC_T
Type for default option handler for format capabilities.
@ OPT_BOOL_T
Type for default option handler for bools (ast_true/ast_false)
@ OPT_BOOLFLAG_T
Type for default option handler for bools (ast_true/ast_false) that are stored in a flag.
@ OPT_CUSTOM_T
Type for a custom (user-defined) option handler.
@ OPT_CHAR_ARRAY_T
Type for default option handler for character array strings.
@ OPT_ACL_T
Type for default option handler for ACLs.
@ OPT_SOCKADDR_T
Type for default handler for ast_sockaddrs.
@ OPT_YESNO_T
Type for default option handler for bools (ast_true/ast_false)
@ OPT_INT_T
Type for default option handler for signed integers.
@ OPT_TIMELEN_T
Type for default option handler for time length signed integers.
@ OPT_DOUBLE_T
Type for default option handler for doubles.
@ OPT_STRINGFIELD_T
Type for default option handler for stringfields.
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
Configuration File Parser.
#define ast_config_load(filename, flags)
Load a config file.
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
#define CONFIG_STATUS_FILEMISSING
#define ast_variable_new(name, value, filename)
#define CONFIG_STATUS_FILEUNCHANGED
#define CONFIG_STATUS_FILEINVALID
int ast_parse_arg(const char *arg, enum ast_parse_flags flags, void *p_result,...)
The argument parsing routine.
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
@ CONFIG_FLAG_FILEUNCHANGED
Asterisk internal frame definitions.
#define ast_debug(level,...)
Log a DEBUG message.
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
const char * ast_string_field
#define ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data)
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
static force_inline int attribute_pure ast_strlen_zero(const char *s)
int attribute_pure ast_false(const char *val)
Make sure something is false. Determine if a string containing a boolean value is "false"....
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
static force_inline int attribute_pure ast_str_case_hash(const char *str)
Compute a hash value on a case-insensitive string.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
The representation of a single configuration file to be processed.
Bits of aco_info that shouldn't be assigned outside this file.
enum aco_matchtype match_type
aco_option_handler handler
enum aco_option_type type
struct ao2_container * opts
Type information about a category-level configurable object.
struct aco_type_internal * internal
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
descriptor for a cli entry.
Structure used to handle boolean flags.
internal representation of ACL entries In principle user applications would have no need for this,...
Socket address structure.
Support for dynamic strings.
Structure for variables, used for configurations and for channel variables.
Struct that contains the XML documentation for a particular item. Note that this is an ao2 ref counte...
const ast_string_field ref
struct ast_xml_doc_item * next
const ast_string_field type
const ast_string_field name
Handy terminal functions for vt* terms.
const char * ast_term_reset(void)
Returns the terminal reset code.
char * term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout)
Colorize a specified string by adding terminal color codes.
static void handler(const char *name, int response_code, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
struct association categories[]
static struct aco_type item
int error(const char *format,...)
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ast_clear_flag(p, flag)
struct ast_xml_node * ast_xml_new_child(struct ast_xml_node *parent, const char *child_name)
Add a child node inside a passed parent node.
struct ast_xml_node * ast_xml_xpath_get_first_result(struct ast_xml_xpath_results *results)
Return the first result node of an XPath query.
void ast_xml_xpath_results_free(struct ast_xml_xpath_results *results)
Free the XPath results.
int ast_xml_set_attribute(struct ast_xml_node *node, const char *name, const char *value)
Set an attribute to a node.
void ast_xml_set_text(struct ast_xml_node *node, const char *content)
Set an element content string.
Asterisk XML Documentation API.
struct ast_xml_xpath_results * ast_xmldoc_query(const char *fmt,...)
Execute an XPath query on the loaded XML documentation.
struct ao2_container * ast_xmldoc_build_documentation(const char *type)
Build the documentation for a particular source type.
char * ast_xmldoc_printable(const char *bwinput, int withcolors)
Colorize and put delimiters (instead of tags) to the xmldoc output.
int ast_xmldoc_regenerate_doc_item(struct ast_xml_doc_item *item)
Regenerate the documentation for a particular item.