Skip to content

Commit bde816a

Browse files
InterLinked1Friendly Automation
authored and
Friendly Automation
committed
func_export: Add EXPORT function
Adds the EXPORT function, which allows write access to variables and functions on other channels. ASTERISK-29432 #close Change-Id: I7492645ae4307553d0f586d78e13a4f586231fdf
1 parent 492c938 commit bde816a

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

doc/CHANGES-staging/func_export.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Subject: New EXPORT function
2+
3+
A new function, EXPORT, allows writing variables
4+
and functions on other channels, the complement
5+
of the IMPORT function.

funcs/func_export.c

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Asterisk -- An open source telephony toolkit.
3+
*
4+
* Copyright (C) 2021-2022, Naveen Albert
5+
*
6+
* See http://www.asterisk.org for more information about
7+
* the Asterisk project. Please do not directly contact
8+
* any of the maintainers of this project for assistance;
9+
* the project provides a web site, mailing lists and IRC
10+
* channels for your use.
11+
*
12+
* This program is free software, distributed under the terms of
13+
* the GNU General Public License Version 2. See the LICENSE file
14+
* at the top of the source tree.
15+
*/
16+
17+
/*! \file
18+
*
19+
* \brief Set variables and functions on other channels
20+
*
21+
* \author Naveen Albert <asterisk@phreaknet.org>
22+
*
23+
* \ingroup functions
24+
*/
25+
26+
/*** MODULEINFO
27+
<support_level>extended</support_level>
28+
***/
29+
30+
#include "asterisk.h"
31+
32+
#include "asterisk/module.h"
33+
#include "asterisk/channel.h"
34+
#include "asterisk/pbx.h"
35+
#include "asterisk/utils.h"
36+
#include "asterisk/app.h"
37+
#include "asterisk/stringfields.h"
38+
39+
/*** DOCUMENTATION
40+
<function name="EXPORT" language="en_US">
41+
<synopsis>
42+
Set variables or dialplan functions on any arbitrary channel that exists.
43+
</synopsis>
44+
<syntax>
45+
<parameter name="channel" required="true">
46+
<para>The complete channel name: <literal>SIP/12-abcd1234</literal>.</para>
47+
</parameter>
48+
<parameter name="var" required="true">
49+
<para>Variable name</para>
50+
</parameter>
51+
</syntax>
52+
<description>
53+
<para>Allows setting variables or functions on any existing channel if it exists.</para>
54+
</description>
55+
<see-also>
56+
<ref type="function">IMPORT</ref>
57+
<ref type="function">MASTER_CHANNEL</ref>
58+
<ref type="function">SHARED</ref>
59+
</see-also>
60+
</function>
61+
***/
62+
63+
static int func_export_write(struct ast_channel *chan, const char *function, char *data, const char *value)
64+
{
65+
struct ast_channel *ochan;
66+
67+
AST_DECLARE_APP_ARGS(args,
68+
AST_APP_ARG(channel);
69+
AST_APP_ARG(var);
70+
);
71+
AST_STANDARD_APP_ARGS(args, data);
72+
73+
if (!args.channel) {
74+
ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
75+
return -1;
76+
}
77+
if (!args.var) {
78+
ast_log(LOG_WARNING, "No variable name was provided to %s function.\n", function);
79+
return -1;
80+
}
81+
ochan = ast_channel_get_by_name(args.channel);
82+
if (!ochan) {
83+
ast_log(LOG_WARNING, "Channel '%s' not found! '%s' not set.\n", args.channel, args.var);
84+
return -1;
85+
}
86+
87+
pbx_builtin_setvar_helper(ochan, data, value);
88+
ast_channel_unref(ochan);
89+
return 0;
90+
}
91+
92+
static struct ast_custom_function export_function = {
93+
.name = "EXPORT",
94+
.write = func_export_write,
95+
};
96+
97+
static int unload_module(void)
98+
{
99+
return ast_custom_function_unregister(&export_function);
100+
}
101+
102+
static int load_module(void)
103+
{
104+
return ast_custom_function_register(&export_function);
105+
}
106+
107+
AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Set variables and functions on other channels");

0 commit comments

Comments
 (0)