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$")
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"
43 #include "asterisk/options.h"
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";
52 static int asyncgoto_exec(struct ast_channel
*chan
, void *data
)
55 struct ast_module_user
*u
;
56 char *info
, *context
, *exten
, *priority
;
58 struct ast_channel
*chan2
= NULL
;
60 AST_DECLARE_APP_ARGS(args
,
65 if (ast_strlen_zero(data
)) {
66 ast_log(LOG_WARNING
, "%s requires an argument (channel|[[context|]exten|]priority)\n", app
);
70 u
= ast_module_user_add(chan
);
72 info
= ast_strdupa(data
);
73 AST_STANDARD_APP_ARGS(args
, info
);
75 if (ast_strlen_zero(args
.channel
) || ast_strlen_zero(args
.label
)) {
76 ast_log(LOG_WARNING
, "%s requires an argument (channel|[[context|]exten|]priority)\n", app
);
80 chan2
= ast_get_channel_by_name_locked(args
.channel
);
82 ast_log(LOG_WARNING
, "No such channel: %s\n", args
.channel
);
86 /* Parsed right to left, so standard parsing won't work */
87 context
= strsep(&args
.label
, "|");
88 exten
= strsep(&args
.label
, "|");
90 priority
= strsep(&args
.label
, "|");
101 /* ast_findlabel_extension does not convert numeric priorities; it only does a lookup */
102 if (!(prio
= atoi(priority
)) && !(prio
= ast_findlabel_extension(chan2
, S_OR(context
, chan2
->context
),
103 S_OR(exten
, chan2
->exten
), priority
, chan2
->cid
.cid_num
))) {
104 ast_log(LOG_WARNING
, "'%s' is not a known priority or label\n", priority
);
108 if (option_debug
> 1)
109 ast_log(LOG_DEBUG
, "Attempting async goto (%s) to %s|%s|%d\n", args
.channel
, S_OR(context
, chan2
->context
), S_OR(exten
, chan2
->exten
), prio
);
111 if (ast_async_goto_if_exists(chan2
, S_OR(context
, chan2
->context
), S_OR(exten
, chan2
->exten
), prio
))
112 ast_log(LOG_WARNING
, "%s failed for %s\n", app
, args
.channel
);
117 ast_mutex_unlock(&chan2
->lock
);
119 ast_module_user_remove(u
);
124 static int unload_module(void)
128 res
= ast_unregister_application(app
);
130 ast_module_user_hangup_all();
135 static int load_module(void)
137 return ast_register_application(app
, asyncgoto_exec
, synopsis
, descrip
);
140 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "Channel Redirect");