Mon Jun 27 16:50:47 2011

Asterisk developer's documentation


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 #include "asterisk.h"
00031 
00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 196072 $")
00033 
00034 #include "asterisk/pbx.h"
00035 #include "asterisk/module.h"
00036 #include "asterisk/app.h"
00037 #include "asterisk/channel.h"
00038 
00039 /*** DOCUMENTATION
00040    <application name="Transfer" language="en_US">
00041       <synopsis>
00042          Transfer caller to remote extension.
00043       </synopsis>
00044       <syntax>
00045          <parameter name="dest" required="true" argsep="/">
00046             <argument name="Tech" />
00047             <argument name="destination" required="true" />
00048          </parameter>
00049       </syntax>
00050       <description>
00051          <para>Requests the remote caller be transferred
00052          to a given destination. If TECH (SIP, IAX2, LOCAL etc) is used, only
00053          an incoming call with the same channel technology will be transfered.
00054          Note that for SIP, if you transfer before call is setup, a 302 redirect
00055          SIP message will be returned to the caller.</para>
00056          <para>The result of the application will be reported in the <variable>TRANSFERSTATUS</variable>
00057          channel variable:</para>
00058          <variablelist>
00059             <variable name="TRANSFERSTATUS">
00060                <value name="SUCCESS">
00061                   Transfer succeeded.
00062                </value>
00063                <value name="FAILURE">
00064                   Transfer failed.
00065                </value>
00066                <value name="UNSUPPORTED">
00067                   Transfer unsupported by channel driver.
00068                </value>
00069             </variable>
00070          </variablelist>
00071       </description>
00072    </application>
00073  ***/
00074 
00075 static const char * const app = "Transfer";
00076 
00077 static int transfer_exec(struct ast_channel *chan, const char *data)
00078 {
00079    int res;
00080    int len;
00081    char *slash;
00082    char *tech = NULL;
00083    char *dest = NULL;
00084    char *status;
00085    char *parse;
00086    AST_DECLARE_APP_ARGS(args,
00087       AST_APP_ARG(dest);
00088    );
00089 
00090    if (ast_strlen_zero((char *)data)) {
00091       ast_log(LOG_WARNING, "Transfer requires an argument ([Tech/]destination)\n");
00092       pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
00093       return 0;
00094    } else
00095       parse = ast_strdupa(data);
00096 
00097    AST_STANDARD_APP_ARGS(args, parse);
00098 
00099    dest = args.dest;
00100 
00101    if ((slash = strchr(dest, '/')) && (len = (slash - dest))) {
00102       tech = dest;
00103       dest = slash + 1;
00104       /* Allow execution only if the Tech/destination agrees with the type of the channel */
00105       if (strncasecmp(chan->tech->type, tech, len)) {
00106          pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
00107          return 0;
00108       }
00109    }
00110 
00111    /* Check if the channel supports transfer before we try it */
00112    if (!chan->tech->transfer) {
00113       pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "UNSUPPORTED");
00114       return 0;
00115    }
00116 
00117    res = ast_transfer(chan, dest);
00118 
00119    if (res < 0) {
00120       status = "FAILURE";
00121       res = 0;
00122    } else {
00123       status = "SUCCESS";
00124       res = 0;
00125    }
00126 
00127    pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", status);
00128 
00129    return res;
00130 }
00131 
00132 static int unload_module(void)
00133 {
00134    return ast_unregister_application(app);
00135 }
00136 
00137 static int load_module(void)
00138 {
00139    return ast_register_application_xml(app, transfer_exec);
00140 }
00141 
00142 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Transfers a caller to another extension");

Generated on Mon Jun 27 16:50:47 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7