Fri Jul 24 00:40:42 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: 152133 $")
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):  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    );
00068 
00069    if (ast_strlen_zero((char *)data)) {
00070       ast_log(LOG_WARNING, "Transfer requires an argument ([Tech/]destination)\n");
00071       pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
00072       return 0;
00073    } else
00074       parse = ast_strdupa(data);
00075 
00076    AST_STANDARD_APP_ARGS(args, parse);
00077 
00078    dest = args.dest;
00079 
00080    if ((slash = strchr(dest, '/')) && (len = (slash - dest))) {
00081       tech = dest;
00082       dest = slash + 1;
00083       /* Allow execution only if the Tech/destination agrees with the type of the channel */
00084       if (strncasecmp(chan->tech->type, tech, len)) {
00085          pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
00086          return 0;
00087       }
00088    }
00089 
00090    /* Check if the channel supports transfer before we try it */
00091    if (!chan->tech->transfer) {
00092       pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "UNSUPPORTED");
00093       return 0;
00094    }
00095 
00096    res = ast_transfer(chan, dest);
00097 
00098    if (res < 0) {
00099       status = "FAILURE";
00100       res = 0;
00101    } else {
00102       status = "SUCCESS";
00103       res = 0;
00104    }
00105 
00106    pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", status);
00107 
00108    return res;
00109 }
00110 
00111 static int unload_module(void)
00112 {
00113    return ast_unregister_application(app);
00114 }
00115 
00116 static int load_module(void)
00117 {
00118    return ast_register_application(app, transfer_exec, synopsis, descrip);
00119 }
00120 
00121 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Transfers a caller to another extension");

Generated on Fri Jul 24 00:40:42 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7