app_channelredirect.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2006, Sergey Basmanov
00005  *
00006  * See http://www.asterisk.org for more information about
00007  * the Asterisk project. Please do not directly contact
00008  * any of the maintainers of this project for assistance;
00009  * the project provides a web site, mailing lists and IRC
00010  * channels for your use.
00011  *
00012  * This program is free software, distributed under the terms of
00013  * the GNU General Public License Version 2. See the LICENSE file
00014  * at the top of the source tree.
00015  */
00016 
00017 /*! \file
00018  *
00019  * \brief ChannelRedirect application
00020  *
00021  * \author Sergey Basmanov <sergey_basmanov@mail.ru>
00022  *
00023  * \ingroup applications
00024  */
00025 
00026 /*** MODULEINFO
00027    <support_level>core</support_level>
00028  ***/
00029 
00030 #include "asterisk.h"
00031 
00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 389378 $")
00033 
00034 #include "asterisk/file.h"
00035 #include "asterisk/channel.h"
00036 #include "asterisk/pbx.h"
00037 #include "asterisk/module.h"
00038 #include "asterisk/lock.h"
00039 #include "asterisk/app.h"
00040 #include "asterisk/features.h"
00041 
00042 /*** DOCUMENTATION
00043    <application name="ChannelRedirect" language="en_US">
00044       <synopsis>
00045          Redirects given channel to a dialplan target
00046       </synopsis>
00047       <syntax>
00048          <parameter name="channel" required="true" />
00049          <parameter name="context" required="false" />
00050          <parameter name="extension" required="false" />
00051          <parameter name="priority" required="true" />
00052       </syntax>
00053       <description>
00054          <para>Sends the specified channel to the specified extension priority</para>
00055 
00056          <para>This application sets the following channel variables upon completion</para>
00057          <variablelist>
00058             <variable name="CHANNELREDIRECT_STATUS">
00059                <value name="NOCHANNEL" />
00060                <value name="SUCCESS" />
00061                <para>Are set to the result of the redirection</para>
00062             </variable>
00063          </variablelist>
00064       </description>
00065    </application>
00066  ***/
00067 static const char app[] = "ChannelRedirect";
00068 
00069 static int asyncgoto_exec(struct ast_channel *chan, const char *data)
00070 {
00071    int res = -1;
00072    char *info;
00073    struct ast_channel *chan2 = NULL;
00074 
00075    AST_DECLARE_APP_ARGS(args,
00076       AST_APP_ARG(channel);
00077       AST_APP_ARG(label);
00078    );
00079 
00080    if (ast_strlen_zero(data)) {
00081       ast_log(LOG_WARNING, "%s requires an argument (channel,[[context,]exten,]priority)\n", app);
00082       return -1;
00083    }
00084 
00085    info = ast_strdupa(data);
00086    AST_STANDARD_APP_ARGS(args, info);
00087 
00088    if (ast_strlen_zero(args.channel) || ast_strlen_zero(args.label)) {
00089       ast_log(LOG_WARNING, "%s requires an argument (channel,[[context,]exten,]priority)\n", app);
00090       return -1;
00091    }
00092 
00093    if (!(chan2 = ast_channel_get_by_name(args.channel))) {
00094       ast_log(LOG_WARNING, "No such channel: %s\n", args.channel);
00095       pbx_builtin_setvar_helper(chan, "CHANNELREDIRECT_STATUS", "NOCHANNEL");
00096       return 0;
00097    }
00098 
00099    res = ast_async_parseable_goto(chan2, args.label);
00100 
00101    chan2 = ast_channel_unref(chan2);
00102 
00103    pbx_builtin_setvar_helper(chan, "CHANNELREDIRECT_STATUS", "SUCCESS");
00104 
00105    return res;
00106 }
00107 
00108 static int unload_module(void)
00109 {
00110    return ast_unregister_application(app);
00111 }
00112 
00113 static int load_module(void)
00114 {
00115    return ast_register_application_xml(app, asyncgoto_exec) ?
00116       AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
00117 }
00118 
00119 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Redirects a given channel to a dialplan target");

Generated on Thu Apr 16 06:27:08 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6