#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_DEFAULT , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } |
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 191 of file func_config.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 191 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 47 of file func_config.c.
References 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_FILEUNCHANGED, config_item::entry, config_item::filename, LOG_ERROR, and parse().
00049 { 00050 struct ast_config *cfg; 00051 struct ast_flags cfg_flags = { CONFIG_FLAG_FILEUNCHANGED }; 00052 const char *val; 00053 char *parse; 00054 struct config_item *cur; 00055 AST_DECLARE_APP_ARGS(args, 00056 AST_APP_ARG(filename); 00057 AST_APP_ARG(category); 00058 AST_APP_ARG(variable); 00059 AST_APP_ARG(index); 00060 ); 00061 00062 if (ast_strlen_zero(data)) { 00063 ast_log(LOG_ERROR, "AST_CONFIG() requires an argument\n"); 00064 return -1; 00065 } 00066 00067 parse = ast_strdupa(data); 00068 AST_STANDARD_APP_ARGS(args, parse); 00069 00070 if (ast_strlen_zero(args.filename)) { 00071 ast_log(LOG_ERROR, "AST_CONFIG() requires a filename\n"); 00072 return -1; 00073 } 00074 00075 if (ast_strlen_zero(args.category)) { 00076 ast_log(LOG_ERROR, "AST_CONFIG() requires a category\n"); 00077 return -1; 00078 } 00079 00080 if (ast_strlen_zero(args.variable)) { 00081 ast_log(LOG_ERROR, "AST_CONFIG() requires a variable\n"); 00082 return -1; 00083 } 00084 00085 if (!(cfg = ast_config_load(args.filename, cfg_flags))) { 00086 return -1; 00087 } 00088 00089 if (cfg == CONFIG_STATUS_FILEUNCHANGED) { 00090 /* Retrieve cfg from list */ 00091 AST_RWLIST_RDLOCK(&configs); 00092 AST_RWLIST_TRAVERSE(&configs, cur, entry) { 00093 if (!strcmp(cur->filename, args.filename)) { 00094 break; 00095 } 00096 } 00097 00098 if (!cur) { 00099 /* At worst, we might leak an entry while upgrading locks */ 00100 AST_RWLIST_UNLOCK(&configs); 00101 AST_RWLIST_WRLOCK(&configs); 00102 if (!(cur = ast_malloc(sizeof(*cur) + strlen(args.filename) + 1))) { 00103 AST_RWLIST_UNLOCK(&configs); 00104 return -1; 00105 } 00106 00107 strcpy(cur->filename, args.filename); 00108 00109 ast_clear_flag(&cfg_flags, CONFIG_FLAG_FILEUNCHANGED); 00110 if (!(cfg = ast_config_load(args.filename, cfg_flags))) { 00111 ast_free(cur); 00112 AST_RWLIST_UNLOCK(&configs); 00113 return -1; 00114 } 00115 00116 cur->cfg = cfg; 00117 AST_RWLIST_INSERT_TAIL(&configs, cur, entry); 00118 } 00119 00120 cfg = cur->cfg; 00121 } else { 00122 /* Replace cfg in list */ 00123 AST_RWLIST_WRLOCK(&configs); 00124 AST_RWLIST_TRAVERSE(&configs, cur, entry) { 00125 if (!strcmp(cur->filename, args.filename)) { 00126 break; 00127 } 00128 } 00129 00130 if (!cur) { 00131 if (!(cur = ast_malloc(sizeof(*cur) + strlen(args.filename) + 1))) { 00132 AST_RWLIST_UNLOCK(&configs); 00133 return -1; 00134 } 00135 00136 strcpy(cur->filename, args.filename); 00137 cur->cfg = cfg; 00138 00139 AST_RWLIST_INSERT_TAIL(&configs, cur, entry); 00140 } else { 00141 ast_config_destroy(cur->cfg); 00142 cur->cfg = cfg; 00143 } 00144 } 00145 00146 if (!(val = ast_variable_retrieve(cfg, args.category, args.variable))) { 00147 ast_log(LOG_ERROR, "'%s' not found in [%s] of '%s'\n", args.variable, 00148 args.category, args.filename); 00149 AST_RWLIST_UNLOCK(&configs); 00150 return -1; 00151 } 00152 00153 ast_copy_string(buf, val, len); 00154 00155 /* Unlock down here, so there's no chance the struct goes away while we're using it. */ 00156 AST_RWLIST_UNLOCK(&configs); 00157 00158 return 0; 00159 }
static int load_module | ( | void | ) | [static] |
Definition at line 186 of file func_config.c.
References ast_custom_function_register, and config_function.
00187 { 00188 return ast_custom_function_register(&config_function); 00189 }
static int unload_module | ( | void | ) | [static] |
Definition at line 171 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.
00172 { 00173 struct config_item *current; 00174 int res = ast_custom_function_unregister(&config_function); 00175 00176 AST_RWLIST_WRLOCK(&configs); 00177 while ((current = AST_RWLIST_REMOVE_HEAD(&configs, entry))) { 00178 ast_config_destroy(current->cfg); 00179 ast_free(current); 00180 } 00181 AST_RWLIST_UNLOCK(&configs); 00182 00183 return res; 00184 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 191 of file func_config.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 191 of file func_config.c.
struct ast_custom_function config_function [static] |