Debian Codegraph @

apps/app_attended_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 Attended 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 #include "asterisk/features_config.h"
40
41 /*** DOCUMENTATION
42 <application name="AttendedTransfer" language="en_US">
43 <since>
44 <version>13.28.0</version>
45 <version>16.5.0</version>
46 </since>
47 <synopsis>
48 Attended transfer to the extension provided and TRANSFER_CONTEXT
49 </synopsis>
50 <syntax>
51 <parameter name="exten" required="true">
52 <para>Specify extension.</para>
53 </parameter>
54 </syntax>
55 <description>
56 <para>Queue up attended transfer to the specified extension in the <literal>TRANSFER_CONTEXT</literal>.</para>
57 <para>Note that the attended transfer only work when two channels have answered and are bridged together.</para>
58 <para>Make sure to set Attended Transfer DTMF feature <literal>atxfer</literal>
59 and attended transfer is permitted.</para>
60 <para>The result of the application will be reported in the <variable>ATTENDEDTRANSFERSTATUS</variable>
61 channel variable:</para>
62 <variablelist>
63 <variable name="ATTENDEDTRANSFERSTATUS">
64 <value name="SUCCESS">
65 Transfer successfully queued.
66 </value>
67 <value name="FAILURE">
68 Transfer failed.
69 </value>
70 <value name="NOTPERMITTED">
71 Transfer not permitted.
72 </value>
73 </variable>
74 </variablelist>
75 </description>
76 </application>
77 ***/
78
79 static const char * const app = "AttendedTransfer";
80
81 static int attended_transfer_exec(struct ast_channel *chan, const char *data)
82 {
83 char *exten = NULL;
84 const char *context = NULL;
85 char *parse;
86 AST_DECLARE_APP_ARGS(args,
87 AST_APP_ARG(exten);
88 );
89 char feature_code[AST_FEATURE_MAX_LEN];
90 const char *digit;
91 struct ast_frame f = { .frametype = AST_FRAME_DTMF };
92
93 if (ast_strlen_zero((char *)data)) {
94 ast_log(LOG_WARNING, "%s requires an argument (exten)\n", app);
95 pbx_builtin_setvar_helper(chan, "ATTENDEDTRANSFERSTATUS", "FAILURE");
96 return 0;
97 }
98
99 context = pbx_builtin_getvar_helper(chan, "TRANSFER_CONTEXT");
100 if (ast_strlen_zero(context)) {
101 pbx_builtin_setvar_helper(chan, "ATTENDEDTRANSFERSTATUS", "NOTPERMITTED");
102 return 0;
103 }
104
105 ast_channel_lock(chan);
106 if (ast_get_builtin_feature(chan, "atxfer", feature_code, sizeof(feature_code)) ||
107 ast_strlen_zero(feature_code)) {
108 pbx_builtin_setvar_helper(chan, "ATTENDEDTRANSFERSTATUS", "NOTPERMITTED");
109 ast_channel_unlock(chan);
110 return 0;
111 }
112 ast_channel_unlock(chan);
113
114 parse = ast_strdupa(data);
115 AST_STANDARD_APP_ARGS(args, parse);
116
117 exten = args.exten;
118
119 for (digit = feature_code; *digit; ++digit) {
120 f.subclass.integer = *digit;
121 ast_queue_frame(chan, &f);
122 }
123
124 for (digit = exten; *digit; ++digit) {
125 f.subclass.integer = *digit;
126 ast_queue_frame(chan, &f);
127 }
128
129 f.subclass.integer = '#';
130 ast_queue_frame(chan, &f);
131
132 pbx_builtin_setvar_helper(chan, "ATTENDEDTRANSFERSTATUS", "SUCCESS");
133
134 return 0;
135 }
136
137 static int unload_module(void)
138 {
139 return ast_unregister_application(app);
140 }
141
142 static int load_module(void)
143 {
144 return ast_register_application_xml(app, attended_transfer_exec);
145 }
146
147 AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Attended transfer to the given extension");