Creating tag for the release of asterisk-1.6.1-beta1
[asterisk-bristuff.git] / apps / app_channelredirect.c
blob610f254df2efac1cdad5ab30d886659d31fe30aa
1 /*
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.
17 /*! \file
19 * \brief ChannelRedirect application
21 * \author Sergey Basmanov <sergey_basmanov@mail.ru>
23 * \ingroup applications
26 #include "asterisk.h"
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)
49 int res = -1;
50 char *info;
51 struct ast_channel *chan2 = NULL;
53 AST_DECLARE_APP_ARGS(args,
54 AST_APP_ARG(channel);
55 AST_APP_ARG(label);
58 if (ast_strlen_zero(data)) {
59 ast_log(LOG_WARNING, "%s requires an argument (channel,[[context,]exten,]priority)\n", app);
60 return -1;
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);
68 return -1;
71 chan2 = ast_get_channel_by_name_locked(args.channel);
72 if (!chan2) {
73 ast_log(LOG_WARNING, "No such channel: %s\n", args.channel);
74 pbx_builtin_setvar_helper(chan, "CHANNELREDIRECT_STATUS", "NOCHANNEL");
75 return 0;
78 res = ast_async_parseable_goto(chan2, args.label);
79 pbx_builtin_setvar_helper(chan, "CHANNELREDIRECT_STATUS", "SUCCESS");
80 ast_channel_unlock(chan2);
82 return res;
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");