40 #include "asterisk/stasis_channels.h"
139 static void shared_variable_free(
void *data);
142 .
type =
"SHARED_VARIABLES",
143 .destroy = shared_variable_free,
146 static void shared_variable_free(
void *data)
157 static int global_read(
struct ast_channel *chan,
const char *cmd,
char *data,
char *buf,
size_t len)
169 static int global_write(
struct ast_channel *chan,
const char *cmd,
char *data,
const char *value)
179 .write = global_write,
182 static int global_delete_write(
struct ast_channel *chan,
const char *cmd,
char *data,
const char *value)
190 .
name =
"GLOBAL_DELETE",
191 .write = global_delete_write,
194 static int global_exists_read(
struct ast_channel *chan,
const char *cmd,
char *data,
195 char *buf,
size_t len)
199 strcpy(buf, var ?
"1" :
"0");
205 .
name =
"GLOBAL_EXISTS",
206 .read = global_exists_read,
209 static int shared_read(
struct ast_channel *chan,
const char *cmd,
char *data,
char *buf,
size_t len)
212 struct varshead *varshead;
220 if (ast_strlen_zero(data)) {
221 ast_log(LOG_WARNING,
"SHARED() requires an argument: SHARED(<var>[,<chan>])\n");
227 if (!ast_strlen_zero(args.chan)) {
228 char *prefix =
ast_alloca(strlen(args.chan) + 2);
229 sprintf(prefix,
"%s-", args.chan);
231 ast_log(LOG_ERROR,
"Channel '%s' not found! Variable '%s' will be blank.\n", args.chan, args.var);
236 ast_log(LOG_WARNING,
"No channel was provided to %s function.\n", cmd);
240 ast_channel_lock(chan);
243 ast_channel_unlock(chan);
250 varshead = varstore->
data;
255 if (!strcmp(args.var, ast_var_name(var))) {
261 ast_channel_unlock(chan);
270 static int shared_write(
struct ast_channel *chan,
const char *cmd,
char *data,
const char *value)
273 struct varshead *varshead;
281 RAII_VAR(
char *, shared_buffer, NULL, ast_free);
283 if (ast_strlen_zero(data)) {
284 ast_log(LOG_WARNING,
"SHARED() requires an argument: SHARED(<var>[,<chan>])\n");
290 if (!ast_strlen_zero(args.chan)) {
291 char *prefix =
ast_alloca(strlen(args.chan) + 2);
292 sprintf(prefix,
"%s-", args.chan);
294 ast_log(LOG_ERROR,
"Channel '%s' not found! Variable '%s' not set to '%s'.\n", args.chan, args.var, value);
299 ast_log(LOG_WARNING,
"No channel was provided to %s function.\n", cmd);
303 len = 9 + strlen(args.var);
305 if (!shared_buffer) {
312 ast_channel_lock(chan);
315 if (!(varstore = ast_datastore_alloc(&shared_variable_info, NULL))) {
316 ast_log(LOG_ERROR,
"Unable to allocate new datastore. Shared variable not set.\n");
317 ast_channel_unlock(chan);
324 if (!(varshead =
ast_calloc(1,
sizeof(*varshead)))) {
325 ast_log(LOG_ERROR,
"Unable to allocate variable structure. Shared variable not set.\n");
327 ast_channel_unlock(chan);
337 varshead = varstore->
data;
342 if (!strcmp(args.var, ast_var_name(var))) {
350 if ((var = ast_var_assign(args.var,
S_OR(value,
"")))) {
353 sprintf(shared_buffer,
"SHARED(%s)", args.var);
357 ast_channel_unlock(chan);
369 .write = shared_write,
372 static int unload_module(
void)
384 static int load_module(
void)
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
#define ast_channel_unref(c)
Decrease channel reference count.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
Structure for a data store type.
Structure for a data store object.
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
struct ast_channel * ast_channel_get_by_name_prefix(const char *name, size_t name_len)
Find a channel by a name prefix.
General Asterisk PBX channel definitions.
Data structure associated with a custom dialplan function.
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
#define ast_malloc(len)
A wrapper for malloc()
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Core PBX routines and definitions.
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
void ast_channel_publish_varset(struct ast_channel *chan, const char *variable, const char *value)
Publish a ast_channel_publish_varset for a channel.
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
#define ast_calloc(num, len)
A wrapper for calloc()
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
#define ASTERISK_GPL_KEY
The text the key() function should return.
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Asterisk module definitions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define ast_custom_function_register(acf)
Register a custom function.
#define AST_APP_ARG(name)
Define an application argument.