Thu Jul 9 13:40:20 2009

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

Generated on Thu Jul 9 13:40:20 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7