Debian Codegraph @

apps/app_blind_transfer.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2019, Alexei Gradinari
5 *
6 * Alexei Gradinari <[email protected]>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19 /*! \file
20 *
21 * \brief Blind transfer by caller channel
22 *
23 * \author Alexei Gradinari <[email protected]>
24 *
25 * \ingroup applications
26 */
27
28 /*** MODULEINFO
29 <support_level>extended</support_level>
30 ***/
31
32 #include "asterisk.h"
33
34 #include "asterisk/pbx.h"
35 #include "asterisk/module.h"
36 #include "asterisk/app.h"
37 #include "asterisk/channel.h"
38 #include "asterisk/bridge.h"
39
40 /*** DOCUMENTATION
41 <application name="BlindTransfer" language="en_US">
42 <since>
43 <version>13.28.0</version>
44 <version>16.5.0</version>
45 </since>
46 <synopsis>
47 Blind transfer channel(s) to the extension and context provided
48 </synopsis>
49 <syntax>
50 <parameter name="exten" required="true">
51 <para>Specify extension.</para>
52 </parameter>
53 <parameter name="context">
54 <para>Optionally specify a context.
55 By default, Asterisk will use the caller channel context.</para>
56 </parameter>
57 </syntax>
58 <description>
59 <para>Redirect all channels currently bridged to the caller channel to the
60 specified destination.</para>
61 <para>The result of the application will be reported in the <variable>BLINDTRANSFERSTATUS</variable>
62 channel variable:</para>
63 <variablelist>
64 <variable name="BLINDTRANSFERSTATUS">
65 <value name="SUCCESS">
66 Transfer succeeded.
67 </value>
68 <value name="FAILURE">
69 Transfer failed.
70 </value>
71 <value name="INVALID">
72 Transfer invalid.
73 </value>
74 <value name="NOTPERMITTED">
75 Transfer not permitted.
76 </value>
77 </variable>
78 </variablelist>
79 </description>
80 </application>
81 ***/
82
83 static const char * const app = "BlindTransfer";
84
85 static int blind_transfer_exec(struct ast_channel *chan, const char *data)
86 {
87 char *exten = NULL;
88 char *context = NULL;
89 char *parse;
90 AST_DECLARE_APP_ARGS(args,
91 AST_APP_ARG(exten);
92 AST_APP_ARG(context);
93 );
94
95 if (ast_strlen_zero((char *)data)) {
96 ast_log(LOG_WARNING, "%s requires an argument (exten)\n", app);
97 pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "FAILURE");
98 return 0;
99 }
100
101 parse = ast_strdupa(data);
102 AST_STANDARD_APP_ARGS(args, parse);
103
104 exten = args.exten;
105 if (ast_strlen_zero(args.context)) {
106 context = (char *)ast_channel_context(chan);
107 } else {
108 context = args.context;
109 }
110
111 switch (ast_bridge_transfer_blind(1, chan, exten, context, NULL, NULL)) {
112 case AST_BRIDGE_TRANSFER_NOT_PERMITTED:
113 pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "NOTPERMITTED");
114 break;
115 case AST_BRIDGE_TRANSFER_INVALID:
116 pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "INVALID");
117 break;
118 case AST_BRIDGE_TRANSFER_FAIL:
119 pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "FAILURE");
120 break;
121 case AST_BRIDGE_TRANSFER_SUCCESS:
122 pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "SUCCESS");
123 break;
124 default:
125 pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "FAILURE");
126 }
127
128 return 0;
129 }
130
131 static int unload_module(void)
132 {
133 return ast_unregister_application(app);
134 }
135
136 static int load_module(void)
137 {
138 return ast_register_application_xml(app, blind_transfer_exec);
139 }
140
141 AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Blind transfer channel to the given destination");