Global variable dialplan functions. More...
#include "asterisk.h"#include <sys/stat.h>#include "asterisk/module.h"#include "asterisk/pbx.h"#include "asterisk/channel.h"#include "asterisk/app.h"#include "asterisk/manager.h"
Go to the source code of this file.
Functions | |
| static void | __reg_module (void) |
| static void | __unreg_module (void) |
| static int | global_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| static int | global_write (struct ast_channel *chan, const char *cmd, char *data, const char *value) |
| static int | load_module (void) |
| static int | shared_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| static void | shared_variable_free (void *data) |
| static int | shared_write (struct ast_channel *chan, const char *cmd, char *data, const char *value) |
| static int | unload_module (void) |
Variables | |
| static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Variable dialplan functions" , .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 = "0901e4e500243c855563a2d78b0c03e4" , .load = load_module, .unload = unload_module, } |
| static struct ast_module_info * | ast_module_info = &__mod_info |
| static struct ast_custom_function | global_function |
| static struct ast_custom_function | shared_function |
| static struct ast_datastore_info | shared_variable_info |
Global variable dialplan functions.
Definition in file func_global.c.
| static void __reg_module | ( | void | ) | [static] |
Definition at line 273 of file func_global.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 273 of file func_global.c.
| static int global_read | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Definition at line 103 of file func_global.c.
References ast_copy_string(), pbx_builtin_getvar_helper(), and var.
00104 { 00105 const char *var = pbx_builtin_getvar_helper(NULL, data); 00106 00107 *buf = '\0'; 00108 00109 if (var) 00110 ast_copy_string(buf, var, len); 00111 00112 return 0; 00113 }
| static int global_write | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| const char * | value | |||
| ) | [static] |
Definition at line 115 of file func_global.c.
References pbx_builtin_setvar_helper().
00116 { 00117 pbx_builtin_setvar_helper(NULL, data, value); 00118 00119 return 0; 00120 }
| static int load_module | ( | void | ) | [static] |
Definition at line 263 of file func_global.c.
References ast_custom_function_register.
00264 { 00265 int res = 0; 00266 00267 res |= ast_custom_function_register(&global_function); 00268 res |= ast_custom_function_register(&shared_function); 00269 00270 return res; 00271 }
| static int shared_read | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Definition at line 128 of file func_global.c.
References AST_APP_ARG, ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_get_channel_by_name_locked(), ast_get_channel_by_name_prefix_locked(), AST_LIST_TRAVERSE, ast_log(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_var_name(), ast_var_value(), ast_datastore::data, ast_var_t::entries, LOG_ERROR, LOG_WARNING, prefix, and var.
00129 { 00130 struct ast_datastore *varstore; 00131 struct varshead *varshead; 00132 struct ast_var_t *var; 00133 AST_DECLARE_APP_ARGS(args, 00134 AST_APP_ARG(var); 00135 AST_APP_ARG(chan); 00136 ); 00137 00138 if (ast_strlen_zero(data)) { 00139 ast_log(LOG_WARNING, "SHARED() requires an argument: SHARED(<var>[,<chan>])\n"); 00140 return -1; 00141 } 00142 00143 AST_STANDARD_APP_ARGS(args, data); 00144 00145 if (!ast_strlen_zero(args.chan)) { 00146 char *prefix = alloca(strlen(args.chan) + 2); 00147 sprintf(prefix, "%s-", args.chan); 00148 if (!(chan = ast_get_channel_by_name_locked(args.chan)) && !(chan = ast_get_channel_by_name_prefix_locked(prefix, strlen(prefix)))) { 00149 ast_log(LOG_ERROR, "Channel '%s' not found! Variable '%s' will be blank.\n", args.chan, args.var); 00150 return -1; 00151 } 00152 } else 00153 ast_channel_lock(chan); 00154 00155 if (!(varstore = ast_channel_datastore_find(chan, &shared_variable_info, NULL))) { 00156 ast_channel_unlock(chan); 00157 return -1; 00158 } 00159 00160 varshead = varstore->data; 00161 *buf = '\0'; 00162 00163 /* Protected by the channel lock */ 00164 AST_LIST_TRAVERSE(varshead, var, entries) { 00165 if (!strcmp(args.var, ast_var_name(var))) { 00166 ast_copy_string(buf, ast_var_value(var), len); 00167 break; 00168 } 00169 } 00170 00171 ast_channel_unlock(chan); 00172 00173 return 0; 00174 }
| static void shared_variable_free | ( | void * | data | ) | [static] |
Definition at line 92 of file func_global.c.
References ast_free, AST_LIST_REMOVE_HEAD, ast_var_delete(), ast_var_t::entries, and var.
00093 { 00094 struct varshead *varshead = data; 00095 struct ast_var_t *var; 00096 00097 while ((var = AST_LIST_REMOVE_HEAD(varshead, entries))) { 00098 ast_var_delete(var); 00099 } 00100 ast_free(varshead); 00101 }
| static int shared_write | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| const char * | value | |||
| ) | [static] |
Definition at line 176 of file func_global.c.
References AST_APP_ARG, ast_calloc, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, ast_datastore_alloc, ast_datastore_free(), AST_DECLARE_APP_ARGS, ast_get_channel_by_name_locked(), ast_get_channel_by_name_prefix_locked(), AST_LIST_INSERT_HEAD, AST_LIST_REMOVE, AST_LIST_TRAVERSE, ast_log(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_var_assign(), ast_var_delete(), ast_var_name(), ast_datastore::data, ast_var_t::entries, EVENT_FLAG_DIALPLAN, LOG_ERROR, LOG_WARNING, manager_event, ast_channel::name, prefix, S_OR, ast_channel::uniqueid, and var.
00177 { 00178 struct ast_datastore *varstore; 00179 struct varshead *varshead; 00180 struct ast_var_t *var; 00181 AST_DECLARE_APP_ARGS(args, 00182 AST_APP_ARG(var); 00183 AST_APP_ARG(chan); 00184 ); 00185 00186 if (ast_strlen_zero(data)) { 00187 ast_log(LOG_WARNING, "SHARED() requires an argument: SHARED(<var>[,<chan>])\n"); 00188 return -1; 00189 } 00190 00191 AST_STANDARD_APP_ARGS(args, data); 00192 00193 if (!ast_strlen_zero(args.chan)) { 00194 char *prefix = alloca(strlen(args.chan) + 2); 00195 sprintf(prefix, "%s-", args.chan); 00196 if (!(chan = ast_get_channel_by_name_locked(args.chan)) && !(chan = ast_get_channel_by_name_prefix_locked(prefix, strlen(prefix)))) { 00197 ast_log(LOG_ERROR, "Channel '%s' not found! Variable '%s' not set to '%s'.\n", args.chan, args.var, value); 00198 return -1; 00199 } 00200 } else 00201 ast_channel_lock(chan); 00202 00203 if (!(varstore = ast_channel_datastore_find(chan, &shared_variable_info, NULL))) { 00204 if (!(varstore = ast_datastore_alloc(&shared_variable_info, NULL))) { 00205 ast_log(LOG_ERROR, "Unable to allocate new datastore. Shared variable not set.\n"); 00206 ast_channel_unlock(chan); 00207 return -1; 00208 } 00209 00210 if (!(varshead = ast_calloc(1, sizeof(*varshead)))) { 00211 ast_log(LOG_ERROR, "Unable to allocate variable structure. Shared variable not set.\n"); 00212 ast_datastore_free(varstore); 00213 ast_channel_unlock(chan); 00214 return -1; 00215 } 00216 00217 varstore->data = varshead; 00218 ast_channel_datastore_add(chan, varstore); 00219 } 00220 varshead = varstore->data; 00221 00222 /* Protected by the channel lock */ 00223 AST_LIST_TRAVERSE(varshead, var, entries) { 00224 /* If there's a previous value, remove it */ 00225 if (!strcmp(args.var, ast_var_name(var))) { 00226 AST_LIST_REMOVE(varshead, var, entries); 00227 ast_var_delete(var); 00228 break; 00229 } 00230 } 00231 00232 var = ast_var_assign(args.var, S_OR(value, "")); 00233 AST_LIST_INSERT_HEAD(varshead, var, entries); 00234 manager_event(EVENT_FLAG_DIALPLAN, "VarSet", 00235 "Channel: %s\r\n" 00236 "Variable: SHARED(%s)\r\n" 00237 "Value: %s\r\n" 00238 "Uniqueid: %s\r\n", 00239 chan ? chan->name : "none", args.var, value, 00240 chan ? chan->uniqueid : "none"); 00241 00242 ast_channel_unlock(chan); 00243 00244 return 0; 00245 }
| static int unload_module | ( | void | ) | [static] |
Definition at line 253 of file func_global.c.
References ast_custom_function_unregister().
00254 { 00255 int res = 0; 00256 00257 res |= ast_custom_function_unregister(&global_function); 00258 res |= ast_custom_function_unregister(&shared_function); 00259 00260 return res; 00261 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Variable dialplan functions" , .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 = "0901e4e500243c855563a2d78b0c03e4" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 273 of file func_global.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 273 of file func_global.c.
struct ast_custom_function global_function [static] |
{
.name = "GLOBAL",
.read = global_read,
.write = global_write,
}
Definition at line 122 of file func_global.c.
struct ast_custom_function shared_function [static] |
{
.name = "SHARED",
.read = shared_read,
.write = shared_write,
}
Definition at line 247 of file func_global.c.
struct ast_datastore_info shared_variable_info [static] |
{
.type = "SHARED_VARIABLES",
.destroy = shared_variable_free,
}
Definition at line 87 of file func_global.c.
1.6.2