#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 = "88eaa8f5c1bd988bedd71113385e0886" , .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 |
Tilghman Lesher <func_config__200803@the-tilghman.com>
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_clear_flag, ast_config_destroy(), ast_config_load, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_free, ast_log(), ast_malloc, AST_RWLIST_INSERT_TAIL, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_variable_retrieve(), config_item::cfg, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, config_item::entry, config_item::filename, LOG_ERROR, and parse().
00070 { 00071 struct ast_config *cfg; 00072 struct ast_flags cfg_flags = { CONFIG_FLAG_FILEUNCHANGED }; 00073 const char *val; 00074 char *parse; 00075 struct config_item *cur; 00076 AST_DECLARE_APP_ARGS(args, 00077 AST_APP_ARG(filename); 00078 AST_APP_ARG(category); 00079 AST_APP_ARG(variable); 00080 AST_APP_ARG(index); 00081 ); 00082 00083 if (ast_strlen_zero(data)) { 00084 ast_log(LOG_ERROR, "AST_CONFIG() requires an argument\n"); 00085 return -1; 00086 } 00087 00088 parse = ast_strdupa(data); 00089 AST_STANDARD_APP_ARGS(args, parse); 00090 00091 if (ast_strlen_zero(args.filename)) { 00092 ast_log(LOG_ERROR, "AST_CONFIG() requires a filename\n"); 00093 return -1; 00094 } 00095 00096 if (ast_strlen_zero(args.category)) { 00097 ast_log(LOG_ERROR, "AST_CONFIG() requires a category\n"); 00098 return -1; 00099 } 00100 00101 if (ast_strlen_zero(args.variable)) { 00102 ast_log(LOG_ERROR, "AST_CONFIG() requires a variable\n"); 00103 return -1; 00104 } 00105 00106 if (!(cfg = ast_config_load(args.filename, cfg_flags)) || cfg == CONFIG_STATUS_FILEINVALID) { 00107 return -1; 00108 } 00109 00110 if (cfg == CONFIG_STATUS_FILEUNCHANGED) { 00111 /* Retrieve cfg from list */ 00112 AST_RWLIST_RDLOCK(&configs); 00113 AST_RWLIST_TRAVERSE(&configs, cur, entry) { 00114 if (!strcmp(cur->filename, args.filename)) { 00115 break; 00116 } 00117 } 00118 00119 if (!cur) { 00120 /* At worst, we might leak an entry while upgrading locks */ 00121 AST_RWLIST_UNLOCK(&configs); 00122 AST_RWLIST_WRLOCK(&configs); 00123 if (!(cur = ast_malloc(sizeof(*cur) + strlen(args.filename) + 1))) { 00124 AST_RWLIST_UNLOCK(&configs); 00125 return -1; 00126 } 00127 00128 strcpy(cur->filename, args.filename); 00129 00130 ast_clear_flag(&cfg_flags, CONFIG_FLAG_FILEUNCHANGED); 00131 if (!(cfg = ast_config_load(args.filename, cfg_flags)) || cfg == CONFIG_STATUS_FILEINVALID) { 00132 ast_free(cur); 00133 AST_RWLIST_UNLOCK(&configs); 00134 return -1; 00135 } 00136 00137 cur->cfg = cfg; 00138 AST_RWLIST_INSERT_TAIL(&configs, cur, entry); 00139 } 00140 00141 cfg = cur->cfg; 00142 } else { 00143 /* Replace cfg in list */ 00144 AST_RWLIST_WRLOCK(&configs); 00145 AST_RWLIST_TRAVERSE(&configs, cur, entry) { 00146 if (!strcmp(cur->filename, args.filename)) { 00147 break; 00148 } 00149 } 00150 00151 if (!cur) { 00152 if (!(cur = ast_malloc(sizeof(*cur) + strlen(args.filename) + 1))) { 00153 AST_RWLIST_UNLOCK(&configs); 00154 return -1; 00155 } 00156 00157 strcpy(cur->filename, args.filename); 00158 cur->cfg = cfg; 00159 00160 AST_RWLIST_INSERT_TAIL(&configs, cur, entry); 00161 } else { 00162 ast_config_destroy(cur->cfg); 00163 cur->cfg = cfg; 00164 } 00165 } 00166 00167 if (!(val = ast_variable_retrieve(cfg, args.category, args.variable))) { 00168 ast_log(LOG_ERROR, "'%s' not found in [%s] of '%s'\n", args.variable, 00169 args.category, args.filename); 00170 AST_RWLIST_UNLOCK(&configs); 00171 return -1; 00172 } 00173 00174 ast_copy_string(buf, val, len); 00175 00176 /* Unlock down here, so there's no chance the struct goes away while we're using it. */ 00177 AST_RWLIST_UNLOCK(&configs); 00178 00179 return 0; 00180 }
static int load_module | ( | void | ) | [static] |
Definition at line 202 of file func_config.c.
References ast_custom_function_register, and config_function.
00203 { 00204 return ast_custom_function_register(&config_function); 00205 }
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, AST_RWLIST_WRLOCK, config_item::cfg, config_function, and config_item::entry.
00188 { 00189 struct config_item *current; 00190 int res = ast_custom_function_unregister(&config_function); 00191 00192 AST_RWLIST_WRLOCK(&configs); 00193 while ((current = AST_RWLIST_REMOVE_HEAD(&configs, entry))) { 00194 ast_config_destroy(current->cfg); 00195 ast_free(current); 00196 } 00197 AST_RWLIST_UNLOCK(&configs); 00198 00199 return res; 00200 }
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 = "88eaa8f5c1bd988bedd71113385e0886" , .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] |
Initial value:
{ .name = "AST_CONFIG", .read = config_function_read, }
Definition at line 182 of file func_config.c.
Referenced by load_module(), and unload_module().