00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "asterisk.h"
00027
00028 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 172065 $")
00029
00030 #include "asterisk/file.h"
00031 #include "asterisk/channel.h"
00032 #include "asterisk/pbx.h"
00033 #include "asterisk/module.h"
00034 #include "asterisk/lock.h"
00035 #include "asterisk/app.h"
00036 #include "asterisk/features.h"
00037
00038 static char *app = "ChannelRedirect";
00039 static char *synopsis = "Redirects given channel to a dialplan target.";
00040 static char *descrip =
00041 "ChannelRedirect(channel,[[context,]extension,]priority)\n"
00042 " Sends the specified channel to the specified extension priority\n"
00043 "This application sets the following channel variables upon completion:\n"
00044 " CHANNELREDIRECT_STATUS - Are set to the result of the redirection\n"
00045 " either NOCHANNEL or SUCCESS\n";
00046
00047 static int asyncgoto_exec(struct ast_channel *chan, void *data)
00048 {
00049 int res = -1;
00050 char *info;
00051 struct ast_channel *chan2 = NULL;
00052
00053 AST_DECLARE_APP_ARGS(args,
00054 AST_APP_ARG(channel);
00055 AST_APP_ARG(label);
00056 );
00057
00058 if (ast_strlen_zero(data)) {
00059 ast_log(LOG_WARNING, "%s requires an argument (channel,[[context,]exten,]priority)\n", app);
00060 return -1;
00061 }
00062
00063 info = ast_strdupa(data);
00064 AST_STANDARD_APP_ARGS(args, info);
00065
00066 if (ast_strlen_zero(args.channel) || ast_strlen_zero(args.label)) {
00067 ast_log(LOG_WARNING, "%s requires an argument (channel,[[context,]exten,]priority)\n", app);
00068 return -1;
00069 }
00070
00071 chan2 = ast_get_channel_by_name_locked(args.channel);
00072 if (!chan2) {
00073 ast_log(LOG_WARNING, "No such channel: %s\n", args.channel);
00074 pbx_builtin_setvar_helper(chan, "CHANNELREDIRECT_STATUS", "NOCHANNEL");
00075 return 0;
00076 }
00077
00078 if (chan2->pbx) {
00079 ast_set_flag(chan2, AST_FLAG_BRIDGE_HANGUP_DONT);
00080 }
00081 res = ast_async_parseable_goto(chan2, args.label);
00082 pbx_builtin_setvar_helper(chan, "CHANNELREDIRECT_STATUS", "SUCCESS");
00083 ast_channel_unlock(chan2);
00084
00085 return res;
00086 }
00087
00088 static int unload_module(void)
00089 {
00090 return ast_unregister_application(app);
00091 }
00092
00093 static int load_module(void)
00094 {
00095 return ast_register_application(app, asyncgoto_exec, synopsis, descrip);
00096 }
00097
00098 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Redirects a given channel to a dialplan target");