aboutsummaryrefslogtreecommitdiffstats
path: root/apps/app_transfer.c
blob: f3628959c3828b0b06609f8724a250a5f8200277 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * Asterisk -- A telephony toolkit for Linux.
 *
 * Transfer a caller
 * 
 * Copyright (C) 1999 - 2005, Digium, Inc.
 *
 * Mark Spencer <markster@digium.com>
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License
 */

#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>

static char *tdesc = "Transfer";

static char *app = "Transfer";

static char *synopsis = "Transfer caller to remote extension";

static char *descrip = 
"  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"
"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;
	int len;
	struct localuser *u;
	char *slash;
	if (!data || !strlen(data)) {
		ast_log(LOG_WARNING, "Transfer requires an argument ([Tech/]destination)\n");
		res = 1;
	}
	if ((slash = strchr((char *)data, '/')) && (len = (slash - (char *)data))) {
		/* Allow execution only if the Tech/destination agrees with the type of the channel */
		if (strncasecmp(chan->type, (char *)data, len))
			return 0;
	}
	LOCAL_USER_ADD(u);
	if (!res) {
		res = ast_transfer(chan, data + strlen(chan->type) + 1);
	}
	if (!res) {
		/* Look for a "busy" place */
		if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_num))
			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;
}