2003-05-14 05:33:06 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- A telephony toolkit for Linux.
|
|
|
|
*
|
2004-05-12 17:30:55 +00:00
|
|
|
* Transfer a caller
|
2003-05-14 05:33:06 +00:00
|
|
|
*
|
2005-01-21 07:06:25 +00:00
|
|
|
* Copyright (C) 1999 - 2005, Digium, Inc.
|
2003-05-14 05:33:06 +00:00
|
|
|
*
|
2004-10-02 00:58:31 +00:00
|
|
|
* Mark Spencer <markster@digium.com>
|
2003-05-14 05:33:06 +00:00
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License
|
|
|
|
*/
|
|
|
|
|
2005-06-06 22:39:32 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2005-04-21 06:02:45 +00:00
|
|
|
#include "asterisk/lock.h"
|
|
|
|
#include "asterisk/file.h"
|
|
|
|
#include "asterisk/logger.h"
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/module.h"
|
2003-05-14 05:33:06 +00:00
|
|
|
|
|
|
|
static char *tdesc = "Transfer";
|
|
|
|
|
|
|
|
static char *app = "Transfer";
|
|
|
|
|
|
|
|
static char *synopsis = "Transfer caller to remote extension";
|
|
|
|
|
|
|
|
static char *descrip =
|
2005-03-20 03:43:37 +00:00
|
|
|
" Transfer([Tech/]dest): Requests the remote caller be transfered\n"
|
|
|
|
"to a given extension. If TECH (SIP, IAX2, LOCAL etc) is used, only\n"
|
|
|
|
"an incoming call with the same channel technology will be transfered.\n"
|
|
|
|
"Note that for SIP, if you transfer before call is setup, a 302 redirect\n"
|
|
|
|
"SIP message will be returned to the caller.\n"
|
|
|
|
"Returns -1 on hangup, or 0 on completion regardless of whether the\n"
|
|
|
|
"transfer was successful. If the transfer was *not* supported or\n"
|
|
|
|
"successful and there exists a priority n + 101,\n"
|
2003-05-14 05:33:06 +00:00
|
|
|
"then that priority will be taken next.\n" ;
|
|
|
|
|
|
|
|
STANDARD_LOCAL_USER;
|
|
|
|
|
|
|
|
LOCAL_USER_DECL;
|
|
|
|
|
|
|
|
static int transfer_exec(struct ast_channel *chan, void *data)
|
|
|
|
{
|
|
|
|
int res=0;
|
2005-02-19 17:34:06 +00:00
|
|
|
int len;
|
2003-05-14 05:33:06 +00:00
|
|
|
struct localuser *u;
|
2005-02-19 17:34:06 +00:00
|
|
|
char *slash;
|
2005-05-08 16:35:54 +00:00
|
|
|
char *dest = data;
|
2003-05-14 05:33:06 +00:00
|
|
|
if (!data || !strlen(data)) {
|
2005-02-19 17:34:06 +00:00
|
|
|
ast_log(LOG_WARNING, "Transfer requires an argument ([Tech/]destination)\n");
|
2003-05-14 05:33:06 +00:00
|
|
|
res = 1;
|
|
|
|
}
|
2005-02-19 17:34:06 +00:00
|
|
|
if ((slash = strchr((char *)data, '/')) && (len = (slash - (char *)data))) {
|
2005-05-08 16:35:54 +00:00
|
|
|
dest = slash + 1;
|
2005-02-19 17:34:06 +00:00
|
|
|
/* Allow execution only if the Tech/destination agrees with the type of the channel */
|
|
|
|
if (strncasecmp(chan->type, (char *)data, len))
|
|
|
|
return 0;
|
|
|
|
}
|
2003-05-14 05:33:06 +00:00
|
|
|
LOCAL_USER_ADD(u);
|
|
|
|
if (!res) {
|
2005-05-08 16:35:54 +00:00
|
|
|
res = ast_transfer(chan, dest);
|
|
|
|
|
2003-05-14 05:33:06 +00:00
|
|
|
}
|
|
|
|
if (!res) {
|
|
|
|
/* Look for a "busy" place */
|
2004-10-02 00:58:31 +00:00
|
|
|
if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_num))
|
2003-05-14 05:33:06 +00:00
|
|
|
chan->priority += 100;
|
|
|
|
}
|
|
|
|
if (res > 0)
|
|
|
|
res = 0;
|
|
|
|
LOCAL_USER_REMOVE(u);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int unload_module(void)
|
|
|
|
{
|
|
|
|
STANDARD_HANGUP_LOCALUSERS;
|
|
|
|
return ast_unregister_application(app);
|
|
|
|
}
|
|
|
|
|
|
|
|
int load_module(void)
|
|
|
|
{
|
|
|
|
return ast_register_application(app, transfer_exec, synopsis, descrip);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *description(void)
|
|
|
|
{
|
|
|
|
return tdesc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usecount(void)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
STANDARD_USECOUNT(res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *key()
|
|
|
|
{
|
|
|
|
return ASTERISK_GPL_KEY;
|
|
|
|
}
|