Wed Jan 8 2020 09:49:40

Asterisk developer's documentation


app_transfer.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.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 Transfer a caller
22  *
23  * \author Mark Spencer <markster@digium.com>
24  *
25  * Requires transfer support from channel driver
26  *
27  * \ingroup applications
28  */
29 
30 /*** MODULEINFO
31  <support_level>core</support_level>
32  ***/
33 
34 #include "asterisk.h"
35 
36 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 405791 $")
37 
38 #include "asterisk/pbx.h"
39 #include "asterisk/module.h"
40 #include "asterisk/app.h"
41 #include "asterisk/channel.h"
42 
43 /*** DOCUMENTATION
44  <application name="Transfer" language="en_US">
45  <synopsis>
46  Transfer caller to remote extension.
47  </synopsis>
48  <syntax>
49  <parameter name="dest" required="true" argsep="">
50  <argument name="Tech/" />
51  <argument name="destination" required="true" />
52  </parameter>
53  </syntax>
54  <description>
55  <para>Requests the remote caller be transferred
56  to a given destination. If TECH (SIP, IAX2, LOCAL etc) is used, only
57  an incoming call with the same channel technology will be transferred.
58  Note that for SIP, if you transfer before call is setup, a 302 redirect
59  SIP message will be returned to the caller.</para>
60  <para>The result of the application will be reported in the <variable>TRANSFERSTATUS</variable>
61  channel variable:</para>
62  <variablelist>
63  <variable name="TRANSFERSTATUS">
64  <value name="SUCCESS">
65  Transfer succeeded.
66  </value>
67  <value name="FAILURE">
68  Transfer failed.
69  </value>
70  <value name="UNSUPPORTED">
71  Transfer unsupported by channel driver.
72  </value>
73  </variable>
74  </variablelist>
75  </description>
76  </application>
77  ***/
78 
79 static const char * const app = "Transfer";
80 
81 static int transfer_exec(struct ast_channel *chan, const char *data)
82 {
83  int res;
84  int len;
85  char *slash;
86  char *tech = NULL;
87  char *dest = NULL;
88  char *status;
89  char *parse;
91  AST_APP_ARG(dest);
92  );
93 
94  if (ast_strlen_zero((char *)data)) {
95  ast_log(LOG_WARNING, "Transfer requires an argument ([Tech/]destination)\n");
96  pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
97  return 0;
98  } else
99  parse = ast_strdupa(data);
100 
101  AST_STANDARD_APP_ARGS(args, parse);
102 
103  dest = args.dest;
104 
105  if ((slash = strchr(dest, '/')) && (len = (slash - dest))) {
106  tech = dest;
107  dest = slash + 1;
108  /* Allow execution only if the Tech/destination agrees with the type of the channel */
109  if (strncasecmp(chan->tech->type, tech, len)) {
110  pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
111  return 0;
112  }
113  }
114 
115  /* Check if the channel supports transfer before we try it */
116  if (!chan->tech->transfer) {
117  pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "UNSUPPORTED");
118  return 0;
119  }
120 
121  res = ast_transfer(chan, dest);
122 
123  if (res < 0) {
124  status = "FAILURE";
125  res = 0;
126  } else {
127  status = "SUCCESS";
128  res = 0;
129  }
130 
131  pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", status);
132 
133  return res;
134 }
135 
136 static int unload_module(void)
137 {
138  return ast_unregister_application(app);
139 }
140 
141 static int load_module(void)
142 {
144 }
145 
146 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Transfers a caller to another extension");
Main Channel structure associated with a channel.
Definition: channel.h:742
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
const char *const type
Definition: channel.h:508
Asterisk main include file. File version handling, generic pbx functions.
static const char *const app
Definition: app_transfer.c:79
#define LOG_WARNING
Definition: logger.h:144
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
General Asterisk PBX channel definitions.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static struct @350 args
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static int transfer_exec(struct ast_channel *chan, const char *data)
Definition: app_transfer.c:81
int(*const transfer)(struct ast_channel *chan, const char *newdest)
Blind transfer other side (see app_transfer.c and ast_transfer()
Definition: channel.h:588
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
static int load_module(void)
Definition: app_transfer.c:141
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...
Definition: pbx.c:10546
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
int ast_transfer(struct ast_channel *chan, char *dest)
Transfer a channel (if supported).
Definition: channel.c:5788
static int unload_module(void)
Definition: app_transfer.c:136
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
Asterisk module definitions.
union ast_frame::@172 data
struct ast_channel_tech * tech
Definition: channel.h:743
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
jack_status_t status
Definition: app_jack.c:143
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180