Asterisk - The Open Source Telephony Project  18.5.0
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 <[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 Blind 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 
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 
79 static const char * const app = "BlindTransfer";
80 
81 static 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);
88  AST_APP_ARG(context);
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 
127 static int unload_module(void)
128 {
130 }
131 
132 static int load_module(void)
133 {
135 }
136 
137 AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Blind transfer channel to the given destination");
AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Blind transfer channel to the given destination")
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
const char * args
#define NULL
Definition: resample.c:96
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
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:4477
General Asterisk PBX channel definitions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static const char *const app
Core PBX routines and definitions.
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 blind_transfer_exec(struct ast_channel *chan, const char *data)
const char * ast_channel_context(const struct ast_channel *chan)
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...
static int unload_module(void)
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626
static int load_module(void)
#define AST_APP_ARG(name)
Define an application argument.