Asterisk - The Open Source Telephony Project GIT-master-8924258
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
app_blind_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 Blind 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"
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
83static const char * const app = "BlindTransfer";
84
85static int blind_transfer_exec(struct ast_channel *chan, const char *data)
86{
87 char *exten = NULL;
88 char *context = NULL;
89 char *parse;
91 AST_APP_ARG(exten);
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);
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)) {
113 pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "NOTPERMITTED");
114 break;
116 pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "INVALID");
117 break;
119 pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "FAILURE");
120 break;
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
131static int unload_module(void)
132{
134}
135
136static int load_module(void)
137{
139}
140
141AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Blind transfer channel to the given destination");
static const char *const app
static int blind_transfer_exec(struct ast_channel *chan, const char *data)
AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Blind transfer channel to the given destination")
static int load_module(void)
static int unload_module(void)
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.
enum ast_transfer_result ast_bridge_transfer_blind(int is_external, struct ast_channel *transferer, const char *exten, const char *context, transfer_channel_cb new_channel_cb, void *user_data)
Blind transfer target to the extension and context provided.
Definition: bridge.c:4494
@ AST_BRIDGE_TRANSFER_NOT_PERMITTED
Definition: bridge.h:1106
@ AST_BRIDGE_TRANSFER_SUCCESS
Definition: bridge.h:1104
@ AST_BRIDGE_TRANSFER_INVALID
Definition: bridge.h:1108
@ AST_BRIDGE_TRANSFER_FAIL
Definition: bridge.h:1110
General Asterisk PBX channel definitions.
const char * ast_channel_context(const struct ast_channel *chan)
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
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:640
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 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.
const char * args