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
33 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
35 #include "asterisk/file.h"
36 #include "asterisk/logger.h"
37 #include "asterisk/channel.h"
38 #include "asterisk/pbx.h"
39 #include "asterisk/module.h"
40 #include "asterisk/lock.h"
41 #include "asterisk/app.h"
42 #include "asterisk/features.h"
44 static char *tdesc = "Channel Redirect";
45 static char *app = "ChannelRedirect";
46 static char *synopsis = "Redirects given channel to a dialplan target.";
47 static char *descrip =
48 "ChannelRedirect(channel|[[context|]extension|]priority):\n"
49 " Sends the specified channel to the specified extension priority\n";
53 static int asyncgoto_exec(struct ast_channel *chan, void *data)
57 char *info, *context, *exten, *priority;
59 struct ast_channel *chan2 = NULL;
61 AST_DECLARE_APP_ARGS(args,
66 if (ast_strlen_zero(data)) {
67 ast_log(LOG_WARNING, "%s requires an argument (channel|[[context|]exten|]priority)\n", app);
73 info = ast_strdupa(data);
74 AST_STANDARD_APP_ARGS(args, info);
76 if (ast_strlen_zero(args.channel) || ast_strlen_zero(args.label)) {
77 ast_log(LOG_WARNING, "%s requires an argument (channel|[[context|]exten|]priority)\n", app);
81 chan2 = ast_get_channel_by_name_locked(args.channel);
83 ast_log(LOG_WARNING, "No such channel: %s\n", args.channel);
87 /* Parsed right to left, so standard parsing won't work */
88 context = strsep(&args.label, "|");
89 exten = strsep(&args.label, "|");
91 priority = strsep(&args.label, "|");
102 if (!(prio = ast_findlabel_extension(chan2, S_OR(context, chan2->context), S_OR(exten, chan2->exten),
103 priority, chan2->cid.cid_num))) {
104 ast_log(LOG_WARNING, "'%s' is not a known priority or label\n", priority);
108 ast_log(LOG_DEBUG, "Attempting async goto (%s) to %s\n", args.channel, args.label);
110 if (ast_async_goto_if_exists(chan2, context ? context : chan2->context, exten ? exten : chan2->exten, prio))
111 ast_log(LOG_WARNING, "%s failed for %s\n", app, args.channel);
116 ast_mutex_unlock(&chan2->lock);
118 LOCAL_USER_REMOVE(u);
123 int unload_module(void)
127 res = ast_unregister_application(app);
129 STANDARD_HANGUP_LOCALUSERS;
134 int load_module(void)
136 return ast_register_application(app, asyncgoto_exec, synopsis, descrip);
139 char *description(void)
148 STANDARD_USECOUNT(res);
155 return ASTERISK_GPL_KEY;