Asterisk - The Open Source Telephony Project GIT-master-f36a736
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 <synopsis>
43 Blind transfer channel(s) to the extension and context provided
44 </synopsis>
45 <syntax>
46 <parameter name="exten" required="true">
47 <para>Specify extension.</para>
48 </parameter>
49 <parameter name="context">
50 <para>Optionally specify a context.
51 By default, Asterisk will use the caller channel context.</para>
52 </parameter>
53 </syntax>
54 <description>
55 <para>Redirect all channels currently bridged to the caller channel to the
56 specified destination.</para>
57 <para>The result of the application will be reported in the <variable>BLINDTRANSFERSTATUS</variable>
58 channel variable:</para>
59 <variablelist>
60 <variable name="BLINDTRANSFERSTATUS">
61 <value name="SUCCESS">
62 Transfer succeeded.
63 </value>
64 <value name="FAILURE">
65 Transfer failed.
66 </value>
67 <value name="INVALID">
68 Transfer invalid.
69 </value>
70 <value name="NOTPERMITTED">
71 Transfer not permitted.
72 </value>
73 </variable>
74 </variablelist>
75 </description>
76 </application>
77 ***/
78
79static const char * const app = "BlindTransfer";
80
81static int blind_transfer_exec(struct ast_channel *chan, const char *data)
82{
83 char *exten = NULL;
84 char *context = NULL;
85 char *parse;
87 AST_APP_ARG(exten);
89 );
90
91 if (ast_strlen_zero((char *)data)) {
92 ast_log(LOG_WARNING, "%s requires an argument (exten)\n", app);
93 pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "FAILURE");
94 return 0;
95 }
96
97 parse = ast_strdupa(data);
99
100 exten = args.exten;
101 if (ast_strlen_zero(args.context)) {
102 context = (char *)ast_channel_context(chan);
103 } else {
104 context = args.context;
105 }
106
107 switch (ast_bridge_transfer_blind(1, chan, exten, context, NULL, NULL)) {
109 pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "NOTPERMITTED");
110 break;
112 pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "INVALID");
113 break;
115 pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "FAILURE");
116 break;
118 pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "SUCCESS");
119 break;
120 default:
121 pbx_builtin_setvar_helper(chan, "BLINDTRANSFERSTATUS", "FAILURE");
122 }
123
124 return 0;
125}
126
127static int unload_module(void)
128{
130}
131
132static int load_module(void)
133{
135}
136
137AST_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:4425
@ AST_BRIDGE_TRANSFER_NOT_PERMITTED
Definition: bridge.h:1102
@ AST_BRIDGE_TRANSFER_SUCCESS
Definition: bridge.h:1100
@ AST_BRIDGE_TRANSFER_INVALID
Definition: bridge.h:1104
@ AST_BRIDGE_TRANSFER_FAIL
Definition: bridge.h:1106
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