Asterisk - The Open Source Telephony Project GIT-master-8924258
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
func_export.c
Go to the documentation of this file.
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"
38
39/*** DOCUMENTATION
40 <function name="EXPORT" language="en_US">
41 <since>
42 <version>16.30.0</version>
43 <version>18.16.0</version>
44 <version>19.8.0</version>
45 <version>20.1.0</version>
46 </since>
47 <synopsis>
48 Set variables or dialplan functions on any arbitrary channel that exists.
49 </synopsis>
50 <syntax>
51 <parameter name="channel" required="true">
52 <para>The complete channel name: <literal>SIP/12-abcd1234</literal>.</para>
53 </parameter>
54 <parameter name="var" required="true">
55 <para>Variable name</para>
56 </parameter>
57 </syntax>
58 <description>
59 <para>Allows setting variables or functions on any existing channel if it exists.</para>
60 </description>
61 <see-also>
62 <ref type="function">IMPORT</ref>
63 <ref type="function">MASTER_CHANNEL</ref>
64 <ref type="function">SHARED</ref>
65 </see-also>
66 </function>
67 ***/
68
69static int func_export_write(struct ast_channel *chan, const char *function, char *data, const char *value)
70{
71 struct ast_channel *ochan;
72
74 AST_APP_ARG(channel);
76 );
78
79 if (!args.channel) {
80 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
81 return -1;
82 }
83 if (!args.var) {
84 ast_log(LOG_WARNING, "No variable name was provided to %s function.\n", function);
85 return -1;
86 }
87 ochan = ast_channel_get_by_name(args.channel);
88 if (!ochan) {
89 ast_log(LOG_WARNING, "Channel '%s' not found! '%s' not set.\n", args.channel, args.var);
90 return -1;
91 }
92
94 ast_channel_unref(ochan);
95 return 0;
96}
97
99 .name = "EXPORT",
100 .write = func_export_write,
101};
102
103static int unload_module(void)
104{
106}
107
108static int load_module(void)
109{
111}
112
113AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Set variables and functions on other channels");
#define var
Definition: ast_expr2f.c:605
Asterisk main include file. File version handling, generic pbx functions.
#define ast_log
Definition: astobj2.c:42
General Asterisk PBX channel definitions.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:3006
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1481
AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Set variables and functions on other channels")
static struct ast_custom_function export_function
Definition: func_export.c:98
static int func_export_write(struct ast_channel *chan, const char *function, char *data, const char *value)
Definition: func_export.c:69
static int load_module(void)
Definition: func_export.c:108
static int unload_module(void)
Definition: func_export.c:103
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define LOG_WARNING
Asterisk module definitions.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Core PBX routines and definitions.
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.
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1559
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
Main Channel structure associated with a channel.
const char * data
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
const char * name
Definition: pbx.h:119
int value
Definition: syslog.c:37
const char * args
Utility functions.