diff options
author | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-09-01 23:41:06 +0000 |
---|---|---|
committer | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-09-01 23:41:06 +0000 |
commit | dc61593f9a28114e01e978d7ccb98c4e851384ae (patch) | |
tree | 70dc07a6e49b9e5101e6ae2a496c7b712e8e88e3 /funcs/func_channel.c | |
parent | f3042acc4fb96f3d6ae2d0681f48654efc0a9487 (diff) |
Add MASTER_CHANNEL() dialplan function, as well as a useful usage.
(closes issue #13140)
Reported by: cpina
Patches:
20090807__issue13140.diff.txt uploaded by tilghman (license 14)
Tested by: lmadsen
Change-type: feature
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@215301 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs/func_channel.c')
-rw-r--r-- | funcs/func_channel.c | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/funcs/func_channel.c b/funcs/func_channel.c index 9cc4001b6..e82c39a51 100644 --- a/funcs/func_channel.c +++ b/funcs/func_channel.c @@ -55,6 +55,15 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") will be space-delimited.</para> </description> </function> + <function name="MASTER_CHANNEL" language="en_US"> + <synopsis> + Gets or sets variables on the master channel + </synopsis> + <description> + <para>Allows access to the channel which created the current channel, if any. If the channel is already + a master channel, then accesses local channel variables.</para> + </description> + </function> <function name="CHANNEL" language="en_US"> <synopsis> Gets/sets various pieces of information about the channel. @@ -496,23 +505,55 @@ static struct ast_custom_function channels_function = { .read = func_channels_read, }; +static int func_mchan_read(struct ast_channel *chan, const char *function, + char *data, struct ast_str **buf, ssize_t len) +{ + struct ast_channel *mchan = ast_channel_get_by_name(chan->linkedid); + char *template = alloca(4 + strlen(data)); + sprintf(template, "${%s}", data); /* SAFE */ + ast_str_substitute_variables(buf, len, mchan ? mchan : chan, template); + if (mchan) { + ast_channel_unref(mchan); + } + return 0; +} + +static int func_mchan_write(struct ast_channel *chan, const char *function, + char *data, const char *value) +{ + struct ast_channel *mchan = ast_channel_get_by_name(chan->linkedid); + pbx_builtin_setvar_helper(mchan ? mchan : chan, data, value); + if (mchan) { + ast_channel_unref(mchan); + } + return 0; +} + +static struct ast_custom_function mchan_function = { + .name = "MASTER_CHANNEL", + .read2 = func_mchan_read, + .write = func_mchan_write, +}; + static int unload_module(void) { int res = 0; - + res |= ast_custom_function_unregister(&channel_function); res |= ast_custom_function_unregister(&channels_function); - + res |= ast_custom_function_unregister(&mchan_function); + return res; } static int load_module(void) { int res = 0; - + res |= ast_custom_function_register(&channel_function); res |= ast_custom_function_register(&channels_function); - + res |= ast_custom_function_register(&mchan_function); + return res; } |