A function to retrieve variables from an Asterisk configuration file. More...
#include "asterisk.h"#include "asterisk/module.h"#include "asterisk/channel.h"#include "asterisk/pbx.h"#include "asterisk/app.h"
Go to the source code of this file.
Data Structures | |
| struct | config_item |
| struct | configs |
Functions | |
| static void | __reg_module (void) |
| static void | __unreg_module (void) |
| static int | config_function_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| static int | load_module (void) |
| static int | unload_module (void) |
Variables | |
| static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Asterisk configuration file variable access" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } |
| static struct ast_module_info * | ast_module_info = &__mod_info |
| static struct ast_custom_function | config_function |
| static struct configs | configs |
A function to retrieve variables from an Asterisk configuration file.
Definition in file func_config.c.
| static void __reg_module | ( | void | ) | [static] |
Definition at line 207 of file func_config.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 207 of file func_config.c.
| static int config_function_read | ( | struct ast_channel * | chan, |
| const char * | cmd, | ||
| char * | data, | ||
| char * | buf, | ||
| size_t | len | ||
| ) | [static] |
Definition at line 68 of file func_config.c.
References args, AST_APP_ARG, ast_calloc, ast_clear_flag, ast_config_destroy(), ast_config_load, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_free, ast_log(), AST_RWLIST_INSERT_TAIL, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_variable_retrieve(), CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, LOG_ERROR, and parse().
{
struct ast_config *cfg;
struct ast_flags cfg_flags = { CONFIG_FLAG_FILEUNCHANGED };
const char *val;
char *parse;
struct config_item *cur;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(filename);
AST_APP_ARG(category);
AST_APP_ARG(variable);
AST_APP_ARG(index);
);
if (ast_strlen_zero(data)) {
ast_log(LOG_ERROR, "AST_CONFIG() requires an argument\n");
return -1;
}
parse = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, parse);
if (ast_strlen_zero(args.filename)) {
ast_log(LOG_ERROR, "AST_CONFIG() requires a filename\n");
return -1;
}
if (ast_strlen_zero(args.category)) {
ast_log(LOG_ERROR, "AST_CONFIG() requires a category\n");
return -1;
}
if (ast_strlen_zero(args.variable)) {
ast_log(LOG_ERROR, "AST_CONFIG() requires a variable\n");
return -1;
}
if (!(cfg = ast_config_load(args.filename, cfg_flags)) || cfg == CONFIG_STATUS_FILEINVALID) {
return -1;
}
if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
/* Retrieve cfg from list */
AST_RWLIST_RDLOCK(&configs);
AST_RWLIST_TRAVERSE(&configs, cur, entry) {
if (!strcmp(cur->filename, args.filename)) {
break;
}
}
if (!cur) {
/* At worst, we might leak an entry while upgrading locks */
AST_RWLIST_UNLOCK(&configs);
AST_RWLIST_WRLOCK(&configs);
if (!(cur = ast_calloc(1, sizeof(*cur) + strlen(args.filename) + 1))) {
AST_RWLIST_UNLOCK(&configs);
return -1;
}
strcpy(cur->filename, args.filename);
ast_clear_flag(&cfg_flags, CONFIG_FLAG_FILEUNCHANGED);
if (!(cfg = ast_config_load(args.filename, cfg_flags)) || cfg == CONFIG_STATUS_FILEINVALID) {
ast_free(cur);
AST_RWLIST_UNLOCK(&configs);
return -1;
}
cur->cfg = cfg;
AST_RWLIST_INSERT_TAIL(&configs, cur, entry);
}
cfg = cur->cfg;
} else {
/* Replace cfg in list */
AST_RWLIST_WRLOCK(&configs);
AST_RWLIST_TRAVERSE(&configs, cur, entry) {
if (!strcmp(cur->filename, args.filename)) {
break;
}
}
if (!cur) {
if (!(cur = ast_calloc(1, sizeof(*cur) + strlen(args.filename) + 1))) {
AST_RWLIST_UNLOCK(&configs);
return -1;
}
strcpy(cur->filename, args.filename);
cur->cfg = cfg;
AST_RWLIST_INSERT_TAIL(&configs, cur, entry);
} else {
ast_config_destroy(cur->cfg);
cur->cfg = cfg;
}
}
if (!(val = ast_variable_retrieve(cfg, args.category, args.variable))) {
ast_log(LOG_ERROR, "'%s' not found in [%s] of '%s'\n", args.variable,
args.category, args.filename);
AST_RWLIST_UNLOCK(&configs);
return -1;
}
ast_copy_string(buf, val, len);
/* Unlock down here, so there's no chance the struct goes away while we're using it. */
AST_RWLIST_UNLOCK(&configs);
return 0;
}
| static int load_module | ( | void | ) | [static] |
Definition at line 202 of file func_config.c.
References ast_custom_function_register.
{
return ast_custom_function_register(&config_function);
}
| static int unload_module | ( | void | ) | [static] |
Definition at line 187 of file func_config.c.
References ast_config_destroy(), ast_custom_function_unregister(), ast_free, AST_RWLIST_REMOVE_HEAD, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.
{
struct config_item *current;
int res = ast_custom_function_unregister(&config_function);
AST_RWLIST_WRLOCK(&configs);
while ((current = AST_RWLIST_REMOVE_HEAD(&configs, entry))) {
ast_config_destroy(current->cfg);
ast_free(current);
}
AST_RWLIST_UNLOCK(&configs);
return res;
}
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Asterisk configuration file variable access" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static] |
Definition at line 207 of file func_config.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 207 of file func_config.c.
struct ast_custom_function config_function [static] |
{
.name = "AST_CONFIG",
.read = config_function_read,
}
Definition at line 182 of file func_config.c.