app_transfer.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief Transfer a caller
00022  *
00023  * \author Mark Spencer <markster@digium.com>
00024  * 
00025  * Requires transfer support from channel driver
00026  *
00027  * \ingroup applications
00028  */
00029 
00030 /*** MODULEINFO
00031    <support_level>core</support_level>
00032  ***/
00033 
00034 #include "asterisk.h"
00035 
00036 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 405830 $")
00037 
00038 #include "asterisk/pbx.h"
00039 #include "asterisk/module.h"
00040 #include "asterisk/app.h"
00041 #include "asterisk/channel.h"
00042 
00043 /*** DOCUMENTATION
00044    <application name="Transfer" language="en_US">
00045       <synopsis>
00046          Transfer caller to remote extension.
00047       </synopsis>
00048       <syntax>
00049          <parameter name="dest" required="true" argsep="">
00050             <argument name="Tech/" />
00051             <argument name="destination" required="true" />
00052          </parameter>
00053       </syntax>
00054       <description>
00055          <para>Requests the remote caller be transferred
00056          to a given destination. If TECH (SIP, IAX2, LOCAL etc) is used, only
00057          an incoming call with the same channel technology will be transferred.
00058          Note that for SIP, if you transfer before call is setup, a 302 redirect
00059          SIP message will be returned to the caller.</para>
00060          <para>The result of the application will be reported in the <variable>TRANSFERSTATUS</variable>
00061          channel variable:</para>
00062          <variablelist>
00063             <variable name="TRANSFERSTATUS">
00064                <value name="SUCCESS">
00065                   Transfer succeeded.
00066                </value>
00067                <value name="FAILURE">
00068                   Transfer failed.
00069                </value>
00070                <value name="UNSUPPORTED">
00071                   Transfer unsupported by channel driver.
00072                </value>
00073             </variable>
00074          </variablelist>
00075       </description>
00076    </application>
00077  ***/
00078 
00079 static const char * const app = "Transfer";
00080 
00081 static int transfer_exec(struct ast_channel *chan, const char *data)
00082 {
00083    int res;
00084    int len;
00085    char *slash;
00086    char *tech = NULL;
00087    char *dest = NULL;
00088    char *status;
00089    char *parse;
00090    AST_DECLARE_APP_ARGS(args,
00091       AST_APP_ARG(dest);
00092    );
00093 
00094    if (ast_strlen_zero((char *)data)) {
00095       ast_log(LOG_WARNING, "Transfer requires an argument ([Tech/]destination)\n");
00096       pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
00097       return 0;
00098    } else
00099       parse = ast_strdupa(data);
00100 
00101    AST_STANDARD_APP_ARGS(args, parse);
00102 
00103    dest = args.dest;
00104 
00105    if ((slash = strchr(dest, '/')) && (len = (slash - dest))) {
00106       tech = dest;
00107       dest = slash + 1;
00108       /* Allow execution only if the Tech/destination agrees with the type of the channel */
00109       if (strncasecmp(ast_channel_tech(chan)->type, tech, len)) {
00110          pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
00111          return 0;
00112       }
00113    }
00114 
00115    /* Check if the channel supports transfer before we try it */
00116    if (!ast_channel_tech(chan)->transfer) {
00117       pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "UNSUPPORTED");
00118       return 0;
00119    }
00120 
00121    res = ast_transfer(chan, dest);
00122 
00123    if (res < 0) {
00124       status = "FAILURE";
00125       res = 0;
00126    } else {
00127       status = "SUCCESS";
00128       res = 0;
00129    }
00130 
00131    pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", status);
00132 
00133    return res;
00134 }
00135 
00136 static int unload_module(void)
00137 {
00138    return ast_unregister_application(app);
00139 }
00140 
00141 static int load_module(void)
00142 {
00143    return ast_register_application_xml(app, transfer_exec);
00144 }
00145 
00146 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Transfers a caller to another extension");

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