Asterisk - The Open Source Telephony Project  18.5.0
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 <[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"
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 
75 static const char * const app = "AttendedTransfer";
76 
77 static 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");
96  if (ast_strlen_zero(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);
111  AST_STANDARD_APP_ARGS(args, parse);
112 
113  exten = args.exten;
114 
115  for (digit = feature_code; *digit; ++digit) {
116  f.subclass.integer = *digit;
117  ast_queue_frame(chan, &f);
118  }
119 
120  for (digit = exten; *digit; ++digit) {
121  f.subclass.integer = *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 
133 static int unload_module(void)
134 {
136 }
137 
138 static int load_module(void)
139 {
141 }
142 
143 AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Attended transfer to the given extension");
char digit
#define ast_channel_lock(chan)
Definition: channel.h:2945
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
#define LOG_WARNING
Definition: logger.h:274
static int attended_transfer_exec(struct ast_channel *chan, const char *data)
AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Attended transfer to the given extension")
const char * args
#define NULL
Definition: resample.c:96
#define AST_FRAME_DTMF
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
struct ast_frame_subclass subclass
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
General Asterisk PBX channel definitions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
Core PBX routines and definitions.
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel&#39;s frame queue.
Definition: channel.c:1139
static int load_module(void)
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_channel_unlock(chan)
Definition: channel.h:2946
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1872
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...
static int unload_module(void)
#define AST_FEATURE_MAX_LEN
Data structure associated with a single frame of data.
static const char *const app
enum ast_frame_type frametype
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Bridging API.
Asterisk module definitions.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626
#define AST_APP_ARG(name)
Define an application argument.