#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 = "a9c98e5d177805051735cb5b0b16b0a0" , .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 |
Definition in file func_global.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 249 of file func_global.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 249 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 58 of file func_global.c.
References ast_copy_string(), pbx_builtin_getvar_helper(), and var.
00059 { 00060 const char *var = pbx_builtin_getvar_helper(NULL, data); 00061 00062 *buf = '\0'; 00063 00064 if (var) 00065 ast_copy_string(buf, var, len); 00066 00067 return 0; 00068 }
static int global_write | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
const char * | value | |||
) | [static] |
Definition at line 70 of file func_global.c.
References pbx_builtin_setvar_helper().
00071 { 00072 pbx_builtin_setvar_helper(NULL, data, value); 00073 00074 return 0; 00075 }
static int load_module | ( | void | ) | [static] |
Definition at line 239 of file func_global.c.
References ast_custom_function_register, global_function, and shared_function.
00240 { 00241 int res = 0; 00242 00243 res |= ast_custom_function_register(&global_function); 00244 res |= ast_custom_function_register(&shared_function); 00245 00246 return res; 00247 }
static int shared_read | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 85 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(), chan, ast_datastore::data, ast_var_t::entries, LOG_ERROR, LOG_WARNING, prefix, shared_variable_info, and var.
00086 { 00087 struct ast_datastore *varstore; 00088 struct varshead *varshead; 00089 struct ast_var_t *var; 00090 AST_DECLARE_APP_ARGS(args, 00091 AST_APP_ARG(var); 00092 AST_APP_ARG(chan); 00093 ); 00094 00095 if (ast_strlen_zero(data)) { 00096 ast_log(LOG_WARNING, "SHARED() requires an argument: SHARED(<var>[,<chan>])\n"); 00097 return -1; 00098 } 00099 00100 AST_STANDARD_APP_ARGS(args, data); 00101 00102 if (!ast_strlen_zero(args.chan)) { 00103 char *prefix = alloca(strlen(args.chan) + 2); 00104 sprintf(prefix, "%s-", args.chan); 00105 if (!(chan = ast_get_channel_by_name_locked(args.chan)) && !(chan = ast_get_channel_by_name_prefix_locked(prefix, strlen(prefix)))) { 00106 ast_log(LOG_ERROR, "Channel '%s' not found! Variable '%s' will be blank.\n", args.chan, args.var); 00107 return -1; 00108 } 00109 } else 00110 ast_channel_lock(chan); 00111 00112 if (!(varstore = ast_channel_datastore_find(chan, &shared_variable_info, NULL))) { 00113 ast_channel_unlock(chan); 00114 return -1; 00115 } 00116 00117 varshead = varstore->data; 00118 *buf = '\0'; 00119 00120 /* Protected by the channel lock */ 00121 AST_LIST_TRAVERSE(varshead, var, entries) { 00122 if (!strcmp(args.var, ast_var_name(var))) { 00123 ast_copy_string(buf, ast_var_value(var), len); 00124 break; 00125 } 00126 } 00127 00128 ast_channel_unlock(chan); 00129 00130 return 0; 00131 }
static void shared_variable_free | ( | void * | data | ) | [static] |
Definition at line 47 of file func_global.c.
References ast_free, AST_LIST_REMOVE_HEAD, ast_var_delete(), ast_var_t::entries, and var.
00048 { 00049 struct varshead *varshead = data; 00050 struct ast_var_t *var; 00051 00052 while ((var = AST_LIST_REMOVE_HEAD(varshead, entries))) { 00053 ast_var_delete(var); 00054 } 00055 ast_free(varshead); 00056 }
static int shared_write | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
const char * | value | |||
) | [static] |
Definition at line 133 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(), chan, ast_datastore::data, ast_var_t::entries, EVENT_FLAG_DIALPLAN, LOG_ERROR, LOG_WARNING, manager_event, prefix, S_OR, shared_variable_info, and var.
00134 { 00135 struct ast_datastore *varstore; 00136 struct varshead *varshead; 00137 struct ast_var_t *var; 00138 AST_DECLARE_APP_ARGS(args, 00139 AST_APP_ARG(var); 00140 AST_APP_ARG(chan); 00141 ); 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 (!(chan = ast_get_channel_by_name_locked(args.chan)) && !(chan = ast_get_channel_by_name_prefix_locked(prefix, strlen(prefix)))) { 00154 ast_log(LOG_ERROR, "Channel '%s' not found! Variable '%s' not set to '%s'.\n", args.chan, args.var, value); 00155 return -1; 00156 } 00157 } else 00158 ast_channel_lock(chan); 00159 00160 if (!(varstore = ast_channel_datastore_find(chan, &shared_variable_info, NULL))) { 00161 if (!(varstore = ast_datastore_alloc(&shared_variable_info, NULL))) { 00162 ast_log(LOG_ERROR, "Unable to allocate new datastore. Shared variable not set.\n"); 00163 ast_channel_unlock(chan); 00164 return -1; 00165 } 00166 00167 if (!(varshead = ast_calloc(1, sizeof(*varshead)))) { 00168 ast_log(LOG_ERROR, "Unable to allocate variable structure. Shared variable not set.\n"); 00169 ast_datastore_free(varstore); 00170 ast_channel_unlock(chan); 00171 return -1; 00172 } 00173 00174 varstore->data = varshead; 00175 ast_channel_datastore_add(chan, varstore); 00176 } 00177 varshead = varstore->data; 00178 00179 /* Protected by the channel lock */ 00180 AST_LIST_TRAVERSE(varshead, var, entries) { 00181 /* If there's a previous value, remove it */ 00182 if (!strcmp(args.var, ast_var_name(var))) { 00183 AST_LIST_REMOVE(varshead, var, entries); 00184 ast_var_delete(var); 00185 break; 00186 } 00187 } 00188 00189 var = ast_var_assign(args.var, S_OR(value, "")); 00190 AST_LIST_INSERT_HEAD(varshead, var, entries); 00191 manager_event(EVENT_FLAG_DIALPLAN, "VarSet", 00192 "Channel: %s\r\n" 00193 "Variable: SHARED(%s)\r\n" 00194 "Value: %s\r\n" 00195 "Uniqueid: %s\r\n", 00196 chan ? chan->name : "none", args.var, value, 00197 chan ? chan->uniqueid : "none"); 00198 00199 ast_channel_unlock(chan); 00200 00201 return 0; 00202 }
static int unload_module | ( | void | ) | [static] |
Definition at line 229 of file func_global.c.
References ast_custom_function_unregister(), global_function, and shared_function.
00230 { 00231 int res = 0; 00232 00233 res |= ast_custom_function_unregister(&global_function); 00234 res |= ast_custom_function_unregister(&shared_function); 00235 00236 return res; 00237 }
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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 249 of file func_global.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 249 of file func_global.c.
struct ast_custom_function global_function [static] |
struct ast_custom_function shared_function [static] |
struct ast_datastore_info shared_variable_info [static] |
Initial value:
{ .type = "SHARED_VARIABLES", .destroy = shared_variable_free, }
Definition at line 42 of file func_global.c.
Referenced by shared_read(), and shared_write().