2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2006, Sergey Basmanov
6 * See http://www.asterisk.org for more information about
7 * the Asterisk project. Please do not directly contact
8 * any of the maintainers of this project for assistance;
9 * the project provides a web site, mailing lists and IRC
10 * channels for your use.
12 * This program is free software, distributed under the terms of
13 * the GNU General Public License Version 2. See the LICENSE file
14 * at the top of the source tree.
19 * \brief ChannelRedirect application
21 * \author Sergey Basmanov <sergey_basmanov@mail.ru>
23 * \ingroup applications
28 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
30 #include "asterisk/file.h"
31 #include "asterisk/channel.h"
32 #include "asterisk/pbx.h"
33 #include "asterisk/module.h"
34 #include "asterisk/lock.h"
35 #include "asterisk/app.h"
36 #include "asterisk/features.h"
38 static char *app
= "ChannelRedirect";
39 static char *synopsis
= "Redirects given channel to a dialplan target.";
40 static char *descrip
=
41 "ChannelRedirect(channel,[[context,]extension,]priority)\n"
42 " Sends the specified channel to the specified extension priority\n"
43 "This application sets the following channel variables upon completion:\n"
44 " CHANNELREDIRECT_STATUS - Are set to the result of the redirection\n"
45 " either NOCHANNEL or SUCCESS\n";
47 static int asyncgoto_exec(struct ast_channel
*chan
, void *data
)
51 struct ast_channel
*chan2
= NULL
;
53 AST_DECLARE_APP_ARGS(args
,
58 if (ast_strlen_zero(data
)) {
59 ast_log(LOG_WARNING
, "%s requires an argument (channel,[[context,]exten,]priority)\n", app
);
63 info
= ast_strdupa(data
);
64 AST_STANDARD_APP_ARGS(args
, info
);
66 if (ast_strlen_zero(args
.channel
) || ast_strlen_zero(args
.label
)) {
67 ast_log(LOG_WARNING
, "%s requires an argument (channel,[[context,]exten,]priority)\n", app
);
71 chan2
= ast_get_channel_by_name_locked(args
.channel
);
73 ast_log(LOG_WARNING
, "No such channel: %s\n", args
.channel
);
74 pbx_builtin_setvar_helper(chan
, "CHANNELREDIRECT_STATUS", "NOCHANNEL");
78 res
= ast_async_parseable_goto(chan2
, args
.label
);
79 pbx_builtin_setvar_helper(chan
, "CHANNELREDIRECT_STATUS", "SUCCESS");
80 ast_channel_unlock(chan2
);
85 static int unload_module(void)
87 return ast_unregister_application(app
);
90 static int load_module(void)
92 return ast_register_application(app
, asyncgoto_exec
, synopsis
, descrip
) ?
93 AST_MODULE_LOAD_DECLINE
: AST_MODULE_LOAD_SUCCESS
;
96 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "Redirects a given channel to a dialplan target");