#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_LOAD_ORDER , .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 = "ac1f6a56484a8820659555499174e588" , .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 | global_function |
static struct ast_custom_function | shared_function |
static struct ast_datastore_info | shared_variable_info |
Definition in file func_global.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 301 of file func_global.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 301 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 107 of file func_global.c.
References ast_copy_string(), pbx_builtin_getvar_helper(), and var.
00108 { 00109 const char *var = pbx_builtin_getvar_helper(NULL, data); 00110 00111 *buf = '\0'; 00112 00113 if (var) 00114 ast_copy_string(buf, var, len); 00115 00116 return 0; 00117 }
static int global_write | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
const char * | value | |||
) | [static] |
Definition at line 119 of file func_global.c.
References pbx_builtin_setvar_helper().
00120 { 00121 pbx_builtin_setvar_helper(NULL, data, value); 00122 00123 return 0; 00124 }
static int load_module | ( | void | ) | [static] |
Definition at line 291 of file func_global.c.
References ast_custom_function_register, global_function, and shared_function.
00292 { 00293 int res = 0; 00294 00295 res |= ast_custom_function_register(&global_function); 00296 res |= ast_custom_function_register(&shared_function); 00297 00298 return res; 00299 }
static int shared_read | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 132 of file func_global.c.
References args, AST_APP_ARG, ast_channel_datastore_find(), ast_channel_get_by_name(), ast_channel_get_by_name_prefix(), ast_channel_lock, ast_channel_unlock, ast_channel_unref, ast_copy_string(), AST_DECLARE_APP_ARGS, AST_LIST_TRAVERSE, ast_log(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_var_name(), ast_var_value(), ast_datastore::data, LOG_ERROR, LOG_WARNING, prefix, shared_variable_info, var, and ast_channel::varshead.
00133 { 00134 struct ast_datastore *varstore; 00135 struct varshead *varshead; 00136 struct ast_var_t *var; 00137 AST_DECLARE_APP_ARGS(args, 00138 AST_APP_ARG(var); 00139 AST_APP_ARG(chan); 00140 ); 00141 struct ast_channel *c_ref = NULL; 00142 00143 if (ast_strlen_zero(data)) { 00144 ast_log(LOG_WARNING, "SHARED() requires an argument: SHARED(<var>[,<chan>])\n"); 00145 return -1; 00146 } 00147 00148 AST_STANDARD_APP_ARGS(args, data); 00149 00150 if (!ast_strlen_zero(args.chan)) { 00151 char *prefix = alloca(strlen(args.chan) + 2); 00152 sprintf(prefix, "%s-", args.chan); 00153 if (!(c_ref = ast_channel_get_by_name(args.chan)) && !(c_ref = ast_channel_get_by_name_prefix(prefix, strlen(prefix)))) { 00154 ast_log(LOG_ERROR, "Channel '%s' not found! Variable '%s' will be blank.\n", args.chan, args.var); 00155 return -1; 00156 } 00157 chan = c_ref; 00158 } 00159 00160 ast_channel_lock(chan); 00161 00162 if (!(varstore = ast_channel_datastore_find(chan, &shared_variable_info, NULL))) { 00163 ast_channel_unlock(chan); 00164 if (c_ref) { 00165 c_ref = ast_channel_unref(c_ref); 00166 } 00167 return -1; 00168 } 00169 00170 varshead = varstore->data; 00171 *buf = '\0'; 00172 00173 /* Protected by the channel lock */ 00174 AST_LIST_TRAVERSE(varshead, var, entries) { 00175 if (!strcmp(args.var, ast_var_name(var))) { 00176 ast_copy_string(buf, ast_var_value(var), len); 00177 break; 00178 } 00179 } 00180 00181 ast_channel_unlock(chan); 00182 00183 if (c_ref) { 00184 c_ref = ast_channel_unref(c_ref); 00185 } 00186 00187 return 0; 00188 }
static void shared_variable_free | ( | void * | data | ) | [static] |
Definition at line 96 of file func_global.c.
References ast_free, AST_LIST_REMOVE_HEAD, ast_var_delete(), ast_var_t::entries, and var.
00097 { 00098 struct varshead *varshead = data; 00099 struct ast_var_t *var; 00100 00101 while ((var = AST_LIST_REMOVE_HEAD(varshead, entries))) { 00102 ast_var_delete(var); 00103 } 00104 ast_free(varshead); 00105 }
static int shared_write | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
const char * | value | |||
) | [static] |
Definition at line 190 of file func_global.c.
References args, AST_APP_ARG, ast_calloc, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_channel_get_by_name(), ast_channel_get_by_name_prefix(), ast_channel_lock, ast_channel_unlock, ast_channel_unref, ast_datastore_alloc, ast_datastore_free(), AST_DECLARE_APP_ARGS, AST_LIST_INSERT_HEAD, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_var_assign(), ast_var_delete(), ast_var_name(), ast_datastore::data, EVENT_FLAG_DIALPLAN, LOG_ERROR, LOG_WARNING, manager_event, prefix, S_OR, shared_variable_info, var, and ast_channel::varshead.
00191 { 00192 struct ast_datastore *varstore; 00193 struct varshead *varshead; 00194 struct ast_var_t *var; 00195 AST_DECLARE_APP_ARGS(args, 00196 AST_APP_ARG(var); 00197 AST_APP_ARG(chan); 00198 ); 00199 struct ast_channel *c_ref = NULL; 00200 00201 if (ast_strlen_zero(data)) { 00202 ast_log(LOG_WARNING, "SHARED() requires an argument: SHARED(<var>[,<chan>])\n"); 00203 return -1; 00204 } 00205 00206 AST_STANDARD_APP_ARGS(args, data); 00207 00208 if (!ast_strlen_zero(args.chan)) { 00209 char *prefix = alloca(strlen(args.chan) + 2); 00210 sprintf(prefix, "%s-", args.chan); 00211 if (!(c_ref = ast_channel_get_by_name(args.chan)) && !(c_ref = ast_channel_get_by_name_prefix(prefix, strlen(prefix)))) { 00212 ast_log(LOG_ERROR, "Channel '%s' not found! Variable '%s' not set to '%s'.\n", args.chan, args.var, value); 00213 return -1; 00214 } 00215 chan = c_ref; 00216 } 00217 00218 ast_channel_lock(chan); 00219 00220 if (!(varstore = ast_channel_datastore_find(chan, &shared_variable_info, NULL))) { 00221 if (!(varstore = ast_datastore_alloc(&shared_variable_info, NULL))) { 00222 ast_log(LOG_ERROR, "Unable to allocate new datastore. Shared variable not set.\n"); 00223 ast_channel_unlock(chan); 00224 if (c_ref) { 00225 c_ref = ast_channel_unref(c_ref); 00226 } 00227 return -1; 00228 } 00229 00230 if (!(varshead = ast_calloc(1, sizeof(*varshead)))) { 00231 ast_log(LOG_ERROR, "Unable to allocate variable structure. Shared variable not set.\n"); 00232 ast_datastore_free(varstore); 00233 ast_channel_unlock(chan); 00234 if (c_ref) { 00235 c_ref = ast_channel_unref(c_ref); 00236 } 00237 return -1; 00238 } 00239 00240 varstore->data = varshead; 00241 ast_channel_datastore_add(chan, varstore); 00242 } 00243 varshead = varstore->data; 00244 00245 /* Protected by the channel lock */ 00246 AST_LIST_TRAVERSE_SAFE_BEGIN(varshead, var, entries) { 00247 /* If there's a previous value, remove it */ 00248 if (!strcmp(args.var, ast_var_name(var))) { 00249 AST_LIST_REMOVE_CURRENT(entries); 00250 ast_var_delete(var); 00251 break; 00252 } 00253 } 00254 AST_LIST_TRAVERSE_SAFE_END; 00255 00256 var = ast_var_assign(args.var, S_OR(value, "")); 00257 AST_LIST_INSERT_HEAD(varshead, var, entries); 00258 manager_event(EVENT_FLAG_DIALPLAN, "VarSet", 00259 "Channel: %s\r\n" 00260 "Variable: SHARED(%s)\r\n" 00261 "Value: %s\r\n" 00262 "Uniqueid: %s\r\n", 00263 chan ? chan->name : "none", args.var, value, 00264 chan ? chan->uniqueid : "none"); 00265 00266 ast_channel_unlock(chan); 00267 00268 if (c_ref) { 00269 c_ref = ast_channel_unref(c_ref); 00270 } 00271 00272 return 0; 00273 }
static int unload_module | ( | void | ) | [static] |
Definition at line 281 of file func_global.c.
References ast_custom_function_unregister(), global_function, and shared_function.
00282 { 00283 int res = 0; 00284 00285 res |= ast_custom_function_unregister(&global_function); 00286 res |= ast_custom_function_unregister(&shared_function); 00287 00288 return res; 00289 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static] |
Definition at line 301 of file func_global.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 301 of file func_global.c.
struct ast_custom_function global_function [static] |
Initial value:
{ .name = "GLOBAL", .read = global_read, .write = global_write, }
Definition at line 126 of file func_global.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function shared_function [static] |
Initial value:
{ .name = "SHARED", .read = shared_read, .write = shared_write, }
Definition at line 275 of file func_global.c.
Referenced by load_module(), and unload_module().
struct ast_datastore_info shared_variable_info [static] |
Initial value:
{ .type = "SHARED_VARIABLES", .destroy = shared_variable_free, }
Definition at line 91 of file func_global.c.
Referenced by shared_read(), and shared_write().