Asterisk - The Open Source Telephony Project GIT-master-7e7a603
app_attended_transfer.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2019, Alexei Gradinari
5 *
6 * Alexei Gradinari <alex2grad@gmail.com>
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 <alex2grad@gmail.com>
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"
40
41/*** DOCUMENTATION
42 <application name="AttendedTransfer" language="en_US">
43 <synopsis>
44 Attended transfer to the extension provided and TRANSFER_CONTEXT
45 </synopsis>
46 <syntax>
47 <parameter name="exten" required="true">
48 <para>Specify extension.</para>
49 </parameter>
50 </syntax>
51 <description>
52 <para>Queue up attended transfer to the specified extension in the <literal>TRANSFER_CONTEXT</literal>.</para>
53 <para>Note that the attended transfer only work when two channels have answered and are bridged together.</para>
54 <para>Make sure to set Attended Transfer DTMF feature <literal>atxfer</literal>
55 and attended transfer is permitted.</para>
56 <para>The result of the application will be reported in the <variable>ATTENDEDTRANSFERSTATUS</variable>
57 channel variable:</para>
58 <variablelist>
59 <variable name="ATTENDEDTRANSFERSTATUS">
60 <value name="SUCCESS">
61 Transfer successfully queued.
62 </value>
63 <value name="FAILURE">
64 Transfer failed.
65 </value>
66 <value name="NOTPERMITTED">
67 Transfer not permitted.
68 </value>
69 </variable>
70 </variablelist>
71 </description>
72 </application>
73 ***/
74
75static const char * const app = "AttendedTransfer";
76
77static int attended_transfer_exec(struct ast_channel *chan, const char *data)
78{
79 char *exten = NULL;
80 const char *context = NULL;
81 char *parse;
83 AST_APP_ARG(exten);
84 );
85 char feature_code[AST_FEATURE_MAX_LEN];
86 const char *digit;
87 struct ast_frame f = { .frametype = AST_FRAME_DTMF };
88
89 if (ast_strlen_zero((char *)data)) {
90 ast_log(LOG_WARNING, "%s requires an argument (exten)\n", app);
91 pbx_builtin_setvar_helper(chan, "ATTENDEDTRANSFERSTATUS", "FAILURE");
92 return 0;
93 }
94
95 context = pbx_builtin_getvar_helper(chan, "TRANSFER_CONTEXT");
97 pbx_builtin_setvar_helper(chan, "ATTENDEDTRANSFERSTATUS", "NOTPERMITTED");
98 return 0;
99 }
100
101 ast_channel_lock(chan);
102 if (ast_get_builtin_feature(chan, "atxfer", feature_code, sizeof(feature_code)) ||
103 ast_strlen_zero(feature_code)) {
104 pbx_builtin_setvar_helper(chan, "ATTENDEDTRANSFERSTATUS", "NOTPERMITTED");
105 ast_channel_unlock(chan);
106 return 0;
107 }
108 ast_channel_unlock(chan);
109
110 parse = ast_strdupa(data);
112
113 exten = args.exten;
114
115 for (digit = feature_code; *digit; ++digit) {
117 ast_queue_frame(chan, &f);
118 }
119
120 for (digit = exten; *digit; ++digit) {
122 ast_queue_frame(chan, &f);
123 }
124
125 f.subclass.integer = '#';
126 ast_queue_frame(chan, &f);
127
128 pbx_builtin_setvar_helper(chan, "ATTENDEDTRANSFERSTATUS", "SUCCESS");
129
130 return 0;
131}
132
133static int unload_module(void)
134{
136}
137
138static int load_module(void)
139{
141}
142
143AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Attended transfer to the given extension");
char digit
static int attended_transfer_exec(struct ast_channel *chan, const char *data)
static const char *const app
static int load_module(void)
static int unload_module(void)
AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Attended transfer to the given extension")
Asterisk main include file. File version handling, generic pbx functions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
Bridging API.
General Asterisk PBX channel definitions.
#define ast_channel_lock(chan)
Definition: channel.h:2922
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel's frame queue.
Definition: channel.c:1139
#define ast_channel_unlock(chan)
Definition: channel.h:2923
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 AST_FEATURE_MAX_LEN
int ast_get_builtin_feature(struct ast_channel *chan, const char *feature, char *buf, size_t len)
Get the DTMF code for a builtin feature.
#define AST_FRAME_DTMF
#define LOG_WARNING
Asterisk module definitions.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626
Core PBX routines and definitions.
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
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 NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Main Channel structure associated with a channel.
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
union ast_frame::@226 data
enum ast_frame_type frametype
const char * args