2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
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.
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.
21 * \brief Transfer a caller
23 * \author Mark Spencer <markster@digium.com>
25 * Requires transfer support from channel driver
27 * \ingroup applications
32 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
39 #include "asterisk/lock.h"
40 #include "asterisk/file.h"
41 #include "asterisk/logger.h"
42 #include "asterisk/channel.h"
43 #include "asterisk/pbx.h"
44 #include "asterisk/module.h"
45 #include "asterisk/options.h"
46 #include "asterisk/app.h"
49 static const char *app
= "Transfer";
51 static const char *synopsis
= "Transfer caller to remote extension";
53 static const char *descrip
=
54 " Transfer([Tech/]dest[|options]): Requests the remote caller be transferred\n"
55 "to a given destination. If TECH (SIP, IAX2, LOCAL etc) is used, only\n"
56 "an incoming call with the same channel technology will be transfered.\n"
57 "Note that for SIP, if you transfer before call is setup, a 302 redirect\n"
58 "SIP message will be returned to the caller.\n"
59 "\nThe result of the application will be reported in the TRANSFERSTATUS\n"
61 " SUCCESS Transfer succeeded\n"
62 " FAILURE Transfer failed\n"
63 " UNSUPPORTED Transfer unsupported by channel driver\n"
64 "The option string many contain the following character:\n"
65 "'j' -- jump to n+101 priority if the channel transfer attempt\n"
68 static int transfer_exec(struct ast_channel
*chan
, void *data
)
72 struct ast_module_user
*u
;
78 int priority_jump
= 0;
79 AST_DECLARE_APP_ARGS(args
,
84 u
= ast_module_user_add(chan
);
86 if (ast_strlen_zero((char *)data
)) {
87 ast_log(LOG_WARNING
, "Transfer requires an argument ([Tech/]destination[|options])\n");
88 ast_module_user_remove(u
);
89 pbx_builtin_setvar_helper(chan
, "TRANSFERSTATUS", "FAILURE");
92 parse
= ast_strdupa(data
);
94 AST_STANDARD_APP_ARGS(args
, parse
);
97 if (strchr(args
.options
, 'j'))
103 if ((slash
= strchr(dest
, '/')) && (len
= (slash
- dest
))) {
106 /* Allow execution only if the Tech/destination agrees with the type of the channel */
107 if (strncasecmp(chan
->tech
->type
, tech
, len
)) {
108 pbx_builtin_setvar_helper(chan
, "TRANSFERSTATUS", "FAILURE");
109 ast_module_user_remove(u
);
114 /* Check if the channel supports transfer before we try it */
115 if (!chan
->tech
->transfer
) {
116 pbx_builtin_setvar_helper(chan
, "TRANSFERSTATUS", "UNSUPPORTED");
117 ast_module_user_remove(u
);
121 res
= ast_transfer(chan
, dest
);
125 if (priority_jump
|| ast_opt_priority_jumping
)
126 ast_goto_if_exists(chan
, chan
->context
, chan
->exten
, chan
->priority
+ 101);
133 pbx_builtin_setvar_helper(chan
, "TRANSFERSTATUS", status
);
135 ast_module_user_remove(u
);
140 static int unload_module(void)
144 res
= ast_unregister_application(app
);
146 ast_module_user_hangup_all();
151 static int load_module(void)
153 return ast_register_application(app
, transfer_exec
, synopsis
, descrip
);
156 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "Transfer");