[Asterisk-code-review] func_channel: Added new OTHER_CHANNEL function (asterisk[16])
N A
asteriskteam at digium.com
Mon May 17 09:26:47 CDT 2021
N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/15908 )
Change subject: func_channel: Added new OTHER_CHANNEL function
......................................................................
func_channel: Added new OTHER_CHANNEL function
A new function allows read and write access to
any existing channel. This is broader than the
access permitted by MASTER_CHANNEL and different
from SHARED which accesses a separate variable
space.
ASTERISK-29432
Change-Id: I7492645ae4307553d0f586d78e13a4f586231fdf
---
A doc/CHANGES-staging/func_channel_ochan.txt
M funcs/func_channel.c
2 files changed, 86 insertions(+), 0 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/08/15908/1
diff --git a/doc/CHANGES-staging/func_channel_ochan.txt b/doc/CHANGES-staging/func_channel_ochan.txt
new file mode 100644
index 0000000..00598f2
--- /dev/null
+++ b/doc/CHANGES-staging/func_channel_ochan.txt
@@ -0,0 +1,5 @@
+Subject: New OTHER_CHANNEL function
+
+A new function, OTHER_CHANNEL, allows
+read and write access to any channel.
+
diff --git a/funcs/func_channel.c b/funcs/func_channel.c
index d143fdc..a8b8695 100644
--- a/funcs/func_channel.c
+++ b/funcs/func_channel.c
@@ -20,6 +20,7 @@
*
* \author Kevin P. Fleming <kpfleming at digium.com>
* \author Ben Winslow
+ * \author Naveen Albert <asterisk at phreaknet.org>
*
* \ingroup functions
*/
@@ -74,6 +75,14 @@
the channel's linkedid.</para>
</description>
</function>
+ <function name="OTHER_CHANNEL" language="en_US">
+ <synopsis>
+ Gets or sets variables on another channel
+ </synopsis>
+ <description>
+ <para>Allows access to any existing channel if it exists.</para>
+ </description>
+ </function>
<function name="CHANNEL" language="en_US">
<synopsis>
Gets/sets various pieces of information about the channel.
@@ -755,6 +764,76 @@
.write = func_mchan_write,
};
+static int func_ochan_read(struct ast_channel *chan, const char *function,
+ char *data, struct ast_str **buf, ssize_t len)
+{
+ struct ast_channel *ochan;
+ char *template = ast_alloca(4 + strlen(data));
+
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(var);
+ AST_APP_ARG(channel);
+ );
+ AST_STANDARD_APP_ARGS(args, data);
+
+ if (!args.channel) {
+ ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
+ return -1;
+ }
+ if (!(ochan = ast_channel_get_by_name(args.channel))) {
+ ast_log(LOG_ERROR, "Channel '%s' not found! Variable '%s' will be blank.\n", args.channel, args.var);
+ return -1;
+ }
+ if (!args.var) {
+ ast_log(LOG_WARNING, "No variable name was provided to %s function.\n", function);
+ return -1;
+ }
+
+ sprintf(template, "${%s}", data); /* SAFE */
+ ast_str_substitute_variables(buf, len, ochan, template);
+ if (ochan) {
+ ast_channel_unref(ochan);
+ }
+ return 0;
+}
+
+static int func_ochan_write(struct ast_channel *chan, const char *function,
+ char *data, const char *value)
+{
+ struct ast_channel *ochan;
+
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(var);
+ AST_APP_ARG(channel);
+ );
+ AST_STANDARD_APP_ARGS(args, data);
+
+ if (!args.channel) {
+ ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
+ return -1;
+ }
+ if (!(ochan = ast_channel_get_by_name(args.channel))) {
+ ast_log(LOG_ERROR, "Channel '%s' not found! Variable '%s' will be blank.\n", args.channel, args.var);
+ return -1;
+ }
+ if (!args.var) {
+ ast_log(LOG_WARNING, "No variable name was provided to %s function.\n", function);
+ return -1;
+ }
+
+ pbx_builtin_setvar_helper(ochan, data, value);
+ if (ochan) {
+ ast_channel_unref(ochan);
+ }
+ return 0;
+}
+
+static struct ast_custom_function ochan_function = {
+ .name = "OTHER_CHANNEL",
+ .read2 = func_ochan_read,
+ .write = func_ochan_write,
+};
+
static int unload_module(void)
{
int res = 0;
@@ -762,6 +841,7 @@
res |= ast_custom_function_unregister(&channel_function);
res |= ast_custom_function_unregister(&channels_function);
res |= ast_custom_function_unregister(&mchan_function);
+ res |= ast_custom_function_unregister(&ochan_function);
return res;
}
@@ -773,6 +853,7 @@
res |= ast_custom_function_register(&channel_function);
res |= ast_custom_function_register(&channels_function);
res |= ast_custom_function_register(&mchan_function);
+ res |= ast_custom_function_register(&ochan_function);
return res;
}
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15908
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I7492645ae4307553d0f586d78e13a4f586231fdf
Gerrit-Change-Number: 15908
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210517/85662f47/attachment.html>
More information about the asterisk-code-review
mailing list