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 * Requires transfer support from channel driver
25 * \ingroup applications
34 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
36 #include "asterisk/lock.h"
37 #include "asterisk/file.h"
38 #include "asterisk/logger.h"
39 #include "asterisk/channel.h"
40 #include "asterisk/pbx.h"
41 #include "asterisk/module.h"
42 #include "asterisk/options.h"
43 #include "asterisk/app.h"
49 static const char *tdesc = "Transfer";
51 static const char *app = "Transfer";
53 static const char *synopsis = "Transfer caller to remote extension";
55 static const char *descrip =
56 " Transfer([Tech/]dest[|options]): Requests the remote caller be transferred\n"
57 "to a given destination. If TECH (SIP, IAX2, LOCAL etc) is used, only\n"
58 "an incoming call with the same channel technology will be transfered.\n"
59 "Note that for SIP, if you transfer before call is setup, a 302 redirect\n"
60 "SIP message will be returned to the caller.\n"
61 "\nThe result of the application will be reported in the TRANSFERSTATUS\n"
63 " SUCCESS Transfer succeeded\n"
64 " FAILURE Transfer failed\n"
65 " UNSUPPORTED Transfer unsupported by channel driver\n"
66 "The option string many contain the following character:\n"
67 "'j' -- jump to n+101 priority if the channel transfer attempt\n"
70 static int transfer_exec(struct ast_channel *chan, void *data)
80 int priority_jump = 0;
81 AST_DECLARE_APP_ARGS(args,
88 if (ast_strlen_zero((char *)data)) {
89 ast_log(LOG_WARNING, "Transfer requires an argument ([Tech/]destination[|options])\n");
91 pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
94 parse = ast_strdupa(data);
96 ast_log(LOG_ERROR, "Out of memory!\n");
102 AST_STANDARD_APP_ARGS(args, parse);
105 if (strchr(args.options, 'j'))
111 if ((slash = strchr(dest, '/')) && (len = (slash - dest))) {
114 /* Allow execution only if the Tech/destination agrees with the type of the channel */
115 if (strncasecmp(chan->type, tech, len)) {
116 pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
117 LOCAL_USER_REMOVE(u);
122 /* Check if the channel supports transfer before we try it */
123 if (!chan->tech->transfer) {
124 pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "UNSUPPORTED");
125 LOCAL_USER_REMOVE(u);
129 res = ast_transfer(chan, dest);
133 if (priority_jump || option_priority_jumping)
134 ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
141 pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", status);
143 LOCAL_USER_REMOVE(u);
148 int unload_module(void)
152 res = ast_unregister_application(app);
154 STANDARD_HANGUP_LOCALUSERS;
159 int load_module(void)
161 return ast_register_application(app, transfer_exec, synopsis, descrip);
164 char *description(void)
166 return (char *) tdesc;
173 STANDARD_USECOUNT(res);
180 return ASTERISK_GPL_KEY;