1999-12-04 21:35:07 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- A telephony toolkit for Linux.
|
|
|
|
*
|
2003-01-17 05:10:52 +00:00
|
|
|
* Trivial application to dial a channel and send an URL on answer
|
1999-12-04 21:35:07 +00:00
|
|
|
*
|
2004-09-22 05:19:06 +00:00
|
|
|
* Copyright (C) 1999-2004, Digium, Inc.
|
1999-12-04 21:35:07 +00:00
|
|
|
*
|
2004-09-22 05:19:06 +00:00
|
|
|
* Mark Spencer <markster@digium.com>
|
1999-12-04 21:35:07 +00:00
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License
|
|
|
|
*/
|
|
|
|
|
2002-05-17 14:33:10 +00:00
|
|
|
#include <asterisk/lock.h>
|
1999-12-04 21:35:07 +00:00
|
|
|
#include <asterisk/file.h>
|
|
|
|
#include <asterisk/logger.h>
|
|
|
|
#include <asterisk/channel.h>
|
|
|
|
#include <asterisk/pbx.h>
|
|
|
|
#include <asterisk/options.h>
|
|
|
|
#include <asterisk/module.h>
|
1999-12-18 07:01:48 +00:00
|
|
|
#include <asterisk/translate.h>
|
2000-03-26 01:59:06 +00:00
|
|
|
#include <asterisk/say.h>
|
2004-04-26 23:22:34 +00:00
|
|
|
#include <asterisk/config.h>
|
2004-07-17 20:58:01 +00:00
|
|
|
#include <asterisk/features.h>
|
2002-05-17 14:33:10 +00:00
|
|
|
#include <asterisk/musiconhold.h>
|
2003-01-17 05:10:52 +00:00
|
|
|
#include <asterisk/callerid.h>
|
2004-05-04 19:11:25 +00:00
|
|
|
#include <asterisk/utils.h>
|
2004-05-07 21:14:55 +00:00
|
|
|
#include <asterisk/app.h>
|
2004-10-26 22:25:43 +00:00
|
|
|
#include <asterisk/causes.h>
|
1999-12-04 21:35:07 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/time.h>
|
2000-03-26 01:59:06 +00:00
|
|
|
#include <sys/signal.h>
|
2001-05-07 03:15:48 +00:00
|
|
|
#include <netinet/in.h>
|
1999-12-04 21:35:07 +00:00
|
|
|
|
2001-12-20 15:21:47 +00:00
|
|
|
static char *tdesc = "Dialing Application";
|
1999-12-04 21:35:07 +00:00
|
|
|
|
|
|
|
static char *app = "Dial";
|
|
|
|
|
2003-11-06 04:08:40 +00:00
|
|
|
static char *synopsis = "Place a call and connect to the current channel";
|
2001-05-07 03:15:48 +00:00
|
|
|
|
|
|
|
static char *descrip =
|
2003-01-17 05:10:52 +00:00
|
|
|
" Dial(Technology/resource[&Technology2/resource2...][|timeout][|options][|URL]):\n"
|
2003-12-09 19:07:45 +00:00
|
|
|
"Requests one or more channels and places specified outgoing calls on them.\n"
|
|
|
|
"As soon as a channel answers, the Dial app will answer the originating\n"
|
2001-10-15 17:39:25 +00:00
|
|
|
"channel (if it needs to be answered) and will bridge a call with the channel\n"
|
2004-11-01 02:23:28 +00:00
|
|
|
"which first answered. All other calls placed by the Dial app will be hung up.\n"
|
2003-12-09 19:07:45 +00:00
|
|
|
"If a timeout is not specified, the Dial application will wait indefinitely\n"
|
|
|
|
"until either one of the called channels answers, the user hangs up, or all\n"
|
2004-02-22 05:31:42 +00:00
|
|
|
"channels return busy or error. In general, the dialer will return 0 if it\n"
|
2003-12-09 19:07:45 +00:00
|
|
|
"was unable to place the call, or the timeout expired. However, if all\n"
|
2001-10-15 17:39:25 +00:00
|
|
|
"channels were busy, and there exists an extension with priority n+101 (where\n"
|
2004-02-22 05:31:42 +00:00
|
|
|
"n is the priority of the dialer instance), then it will be the next\n"
|
2001-10-15 17:39:25 +00:00
|
|
|
"executed extension (this allows you to setup different behavior on busy from\n"
|
|
|
|
"no-answer).\n"
|
|
|
|
" This application returns -1 if the originating channel hangs up, or if the\n"
|
2003-12-09 19:07:45 +00:00
|
|
|
"call is bridged and either of the parties in the bridge terminate the call.\n"
|
2002-05-17 14:33:10 +00:00
|
|
|
"The option string may contain zero or more of the following characters:\n"
|
2004-05-18 18:27:55 +00:00
|
|
|
" 't' -- allow the called user transfer the calling user by hitting #.\n"
|
|
|
|
" 'T' -- allow the calling user to transfer the call by hitting #.\n"
|
2004-07-19 19:47:21 +00:00
|
|
|
" 'f' -- Forces callerid to be set as the extension of the line \n"
|
|
|
|
" making/redirecting the outgoing call. For example, some PSTNs\n"
|
|
|
|
" don't allow callerids from other extensions then the ones\n"
|
2004-06-14 19:43:41 +00:00
|
|
|
" that are assigned to you.\n"
|
2002-05-17 14:33:10 +00:00
|
|
|
" 'r' -- indicate ringing to the calling party, pass no audio until answered.\n"
|
|
|
|
" 'm' -- provide hold music to the calling party until answered.\n"
|
2004-09-10 02:31:30 +00:00
|
|
|
" 'M(x) -- Executes the macro (x) upon connect of the call\n"
|
2004-07-28 19:25:14 +00:00
|
|
|
" 'h' -- allow callee to hang up by hitting *.\n"
|
2002-09-02 15:20:28 +00:00
|
|
|
" 'H' -- allow caller to hang up by hitting *.\n"
|
2003-03-10 06:00:17 +00:00
|
|
|
" 'C' -- reset call detail record for this call.\n"
|
2003-01-17 05:10:52 +00:00
|
|
|
" 'P[(x)]' -- privacy mode, using 'x' as database if provided.\n"
|
2003-08-28 16:42:15 +00:00
|
|
|
" 'g' -- goes on in context if the destination channel hangs up\n"
|
2003-10-22 04:25:13 +00:00
|
|
|
" 'A(x)' -- play an announcement to the called party, using x as file\n"
|
2004-03-06 00:02:40 +00:00
|
|
|
" 'S(x)' -- hangup the call after x seconds AFTER called party picked up\n"
|
2004-05-07 20:39:14 +00:00
|
|
|
" 'D([digits])' -- Send DTMF digit string *after* called party has answered\n"
|
2004-07-19 19:47:21 +00:00
|
|
|
" but before the bridge. (w=500ms sec pause)\n"
|
|
|
|
" 'L(x[:y][:z])' -- Limit the call to 'x' ms warning when 'y' ms are left\n"
|
|
|
|
" repeated every 'z' ms) Only 'x' is required, 'y' and 'z' are optional.\n"
|
|
|
|
" The following special variables are optional:\n"
|
|
|
|
" * LIMIT_PLAYAUDIO_CALLER yes|no (default yes)\n"
|
|
|
|
" Play sounds to the caller.\n"
|
|
|
|
" * LIMIT_PLAYAUDIO_CALLEE yes|no\n"
|
|
|
|
" Play sounds to the callee.\n"
|
|
|
|
" * LIMIT_TIMEOUT_FILE File to play when time is up.\n"
|
|
|
|
" * LIMIT_CONNECT_FILE File to play when call begins.\n"
|
|
|
|
" * LIMIT_WARNING_FILE File to play as warning if 'y' is defined.\n"
|
|
|
|
" 'timeleft' is a special sound macro to auto-say the time \n"
|
|
|
|
" left and is the default.\n\n"
|
2001-10-15 17:39:25 +00:00
|
|
|
" In addition to transferring the call, a call may be parked and then picked\n"
|
2003-01-17 05:10:52 +00:00
|
|
|
"up by another user.\n"
|
2004-07-19 19:47:21 +00:00
|
|
|
" The optional URL will be sent to the called party if the channel supports it.\n"
|
2004-11-07 21:49:43 +00:00
|
|
|
" If the OUTBOUND_GROUP variable is set, all peer channels created by this\n"
|
|
|
|
" application will be put into that group (as in SetGroup).\n"
|
2004-07-19 19:47:21 +00:00
|
|
|
" This application sets the following channel variables upon completion:\n"
|
|
|
|
" DIALEDTIME Time from dial to answer\n"
|
|
|
|
" ANSWEREDTIME Time for actual call\n"
|
|
|
|
" DIALSTATUS The status of the call as a text string, one of\n"
|
|
|
|
" CHANUNAVAIL | CONGESTION | NOANSWER | BUSY | ANSWER | CANCEL\n"
|
|
|
|
"";
|
2001-05-07 03:15:48 +00:00
|
|
|
|
1999-12-04 21:35:07 +00:00
|
|
|
/* We define a customer "local user" structure because we
|
|
|
|
use it not only for keeping track of what is in use but
|
|
|
|
also for keeping track of who we're dialing. */
|
|
|
|
|
|
|
|
struct localuser {
|
|
|
|
struct ast_channel *chan;
|
|
|
|
int stillgoing;
|
2003-07-02 14:06:12 +00:00
|
|
|
int allowredirect_in;
|
|
|
|
int allowredirect_out;
|
2002-05-17 14:33:10 +00:00
|
|
|
int ringbackonly;
|
|
|
|
int musiconhold;
|
2004-07-28 19:25:14 +00:00
|
|
|
int allowdisconnect_in;
|
|
|
|
int allowdisconnect_out;
|
2004-06-14 19:43:41 +00:00
|
|
|
int forcecallerid;
|
1999-12-04 21:35:07 +00:00
|
|
|
struct localuser *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
LOCAL_USER_DECL;
|
|
|
|
|
|
|
|
static void hanguptree(struct localuser *outgoing, struct ast_channel *exception)
|
|
|
|
{
|
|
|
|
/* Hang up a tree of stuff */
|
|
|
|
struct localuser *oo;
|
|
|
|
while(outgoing) {
|
|
|
|
/* Hangup any existing lines we have open */
|
2003-04-06 06:37:08 +00:00
|
|
|
if (outgoing->chan && (outgoing->chan != exception))
|
1999-12-04 21:35:07 +00:00
|
|
|
ast_hangup(outgoing->chan);
|
|
|
|
oo = outgoing;
|
|
|
|
outgoing=outgoing->next;
|
|
|
|
free(oo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-22 17:42:14 +00:00
|
|
|
#define AST_MAX_WATCHERS 256
|
2001-05-07 03:15:48 +00:00
|
|
|
|
2004-10-26 22:25:43 +00:00
|
|
|
#define HANDLE_CAUSE(blah, bleh) do { \
|
|
|
|
switch(cause) { \
|
|
|
|
case AST_CAUSE_BUSY: \
|
|
|
|
if (bleh->cdr) \
|
|
|
|
ast_cdr_busy(bleh->cdr); \
|
|
|
|
numbusy++; \
|
|
|
|
case AST_CAUSE_CONGESTION: \
|
|
|
|
case AST_CAUSE_UNREGISTERED: \
|
|
|
|
if (bleh->cdr) \
|
|
|
|
ast_cdr_busy(bleh->cdr); \
|
|
|
|
numcongestion++; \
|
|
|
|
default: \
|
|
|
|
numnochan++; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
|
|
static struct ast_channel *wait_for_answer(struct ast_channel *in, struct localuser *outgoing, int *to, int *allowredir_in, int *allowredir_out, int *allowdisconnect_in, int *allowdisconnect_out, int *sentringing, char *status, size_t statussize, int busystart, int nochanstart, int congestionstart)
|
1999-12-04 21:35:07 +00:00
|
|
|
{
|
|
|
|
struct localuser *o;
|
|
|
|
int found;
|
|
|
|
int numlines;
|
2004-10-26 22:25:43 +00:00
|
|
|
int numbusy = busystart;
|
|
|
|
int numcongestion = congestionstart;
|
|
|
|
int numnochan = nochanstart;
|
|
|
|
int cause;
|
1999-12-04 21:35:07 +00:00
|
|
|
int orig = *to;
|
|
|
|
struct ast_frame *f;
|
|
|
|
struct ast_channel *peer = NULL;
|
2004-06-22 17:42:14 +00:00
|
|
|
struct ast_channel *watchers[AST_MAX_WATCHERS];
|
2001-05-07 03:15:48 +00:00
|
|
|
int pos;
|
|
|
|
int single;
|
|
|
|
struct ast_channel *winner;
|
|
|
|
|
2003-03-05 06:00:17 +00:00
|
|
|
single = (outgoing && !outgoing->next && !outgoing->musiconhold && !outgoing->ringbackonly);
|
2001-05-07 03:15:48 +00:00
|
|
|
|
|
|
|
if (single) {
|
2003-11-05 20:53:49 +00:00
|
|
|
/* Turn off hold music, etc */
|
2004-07-07 16:02:13 +00:00
|
|
|
ast_deactivate_generator(in);
|
2001-05-07 03:15:48 +00:00
|
|
|
/* If we are calling a single channel, make them compatible for in-band tone purpose */
|
|
|
|
ast_channel_make_compatible(outgoing->chan, in);
|
|
|
|
}
|
|
|
|
|
2002-05-17 14:33:10 +00:00
|
|
|
|
2001-05-07 03:15:48 +00:00
|
|
|
while(*to && !peer) {
|
1999-12-04 21:35:07 +00:00
|
|
|
o = outgoing;
|
|
|
|
found = -1;
|
2001-05-07 03:15:48 +00:00
|
|
|
pos = 1;
|
1999-12-04 21:35:07 +00:00
|
|
|
numlines = 0;
|
2001-05-07 03:15:48 +00:00
|
|
|
watchers[0] = in;
|
1999-12-04 21:35:07 +00:00
|
|
|
while(o) {
|
2001-05-07 03:15:48 +00:00
|
|
|
/* Keep track of important channels */
|
2003-07-22 15:16:55 +00:00
|
|
|
if (o->stillgoing && o->chan) {
|
2001-05-07 03:15:48 +00:00
|
|
|
watchers[pos++] = o->chan;
|
|
|
|
found = 1;
|
1999-12-04 21:35:07 +00:00
|
|
|
}
|
|
|
|
o = o->next;
|
2001-05-07 03:15:48 +00:00
|
|
|
numlines++;
|
1999-12-04 21:35:07 +00:00
|
|
|
}
|
2001-05-07 03:15:48 +00:00
|
|
|
if (found < 0) {
|
2004-06-23 03:16:58 +00:00
|
|
|
if (numlines == (numbusy + numcongestion + numnochan)) {
|
1999-12-04 21:35:07 +00:00
|
|
|
if (option_verbose > 2)
|
2004-06-23 03:16:58 +00:00
|
|
|
ast_verbose( VERBOSE_PREFIX_2 "Everyone is busy/congested at this time\n");
|
|
|
|
if (numbusy)
|
2004-07-14 07:22:30 +00:00
|
|
|
strncpy(status, "BUSY", statussize - 1);
|
2004-06-23 03:16:58 +00:00
|
|
|
else if (numcongestion)
|
2004-07-14 07:22:30 +00:00
|
|
|
strncpy(status, "CONGESTION", statussize - 1);
|
2004-06-23 03:16:58 +00:00
|
|
|
else if (numnochan)
|
2004-07-14 07:22:30 +00:00
|
|
|
strncpy(status, "CHANUNAVAIL", statussize - 1);
|
1999-12-04 21:35:07 +00:00
|
|
|
/* See if there is a special busy message */
|
2004-10-02 00:58:31 +00:00
|
|
|
if (ast_exists_extension(in, in->context, in->exten, in->priority + 101, in->cid.cid_num))
|
1999-12-04 21:35:07 +00:00
|
|
|
in->priority+=100;
|
|
|
|
} else {
|
|
|
|
if (option_verbose > 2)
|
|
|
|
ast_verbose( VERBOSE_PREFIX_2 "No one is available to answer at this time\n");
|
|
|
|
}
|
2001-05-07 03:15:48 +00:00
|
|
|
*to = 0;
|
1999-12-04 21:35:07 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2001-05-07 03:15:48 +00:00
|
|
|
winner = ast_waitfor_n(watchers, pos, to);
|
1999-12-04 21:35:07 +00:00
|
|
|
o = outgoing;
|
|
|
|
while(o) {
|
2003-07-30 16:10:51 +00:00
|
|
|
if (o->stillgoing && o->chan && (o->chan->_state == AST_STATE_UP)) {
|
2002-09-02 15:20:28 +00:00
|
|
|
if (!peer) {
|
|
|
|
if (option_verbose > 2)
|
|
|
|
ast_verbose( VERBOSE_PREFIX_3 "%s answered %s\n", o->chan->name, in->name);
|
|
|
|
peer = o->chan;
|
2003-07-02 14:06:12 +00:00
|
|
|
*allowredir_in = o->allowredirect_in;
|
|
|
|
*allowredir_out = o->allowredirect_out;
|
2004-07-28 19:25:14 +00:00
|
|
|
*allowdisconnect_in = o->allowdisconnect_in;
|
|
|
|
*allowdisconnect_out = o->allowdisconnect_out;
|
2002-09-02 15:20:28 +00:00
|
|
|
}
|
2003-07-25 15:32:02 +00:00
|
|
|
} else if (o->chan && (o->chan == winner)) {
|
2004-05-04 19:11:25 +00:00
|
|
|
if (!ast_strlen_zero(o->chan->call_forward)) {
|
2004-06-21 06:11:56 +00:00
|
|
|
char tmpchan[256]="";
|
|
|
|
char *stuff;
|
|
|
|
char *tech;
|
|
|
|
strncpy(tmpchan, o->chan->call_forward, sizeof(tmpchan) - 1);
|
|
|
|
if ((stuff = strchr(tmpchan, '/'))) {
|
|
|
|
*stuff = '\0';
|
|
|
|
stuff++;
|
|
|
|
tech = tmpchan;
|
|
|
|
} else {
|
|
|
|
snprintf(tmpchan, sizeof(tmpchan), "%s@%s", o->chan->call_forward, o->chan->context);
|
|
|
|
stuff = tmpchan;
|
|
|
|
tech = "Local";
|
|
|
|
}
|
2003-03-27 16:02:10 +00:00
|
|
|
/* Before processing channel, go ahead and check for forwarding */
|
|
|
|
if (option_verbose > 2)
|
2004-06-21 06:11:56 +00:00
|
|
|
ast_verbose(VERBOSE_PREFIX_3 "Now forwarding %s to '%s/%s' (thanks to %s)\n", in->name, tech, stuff, o->chan->name);
|
2003-03-27 16:02:10 +00:00
|
|
|
/* Setup parameters */
|
2004-10-26 22:25:43 +00:00
|
|
|
o->chan = ast_request(tech, in->nativeformats, stuff, &cause);
|
2003-04-06 06:37:08 +00:00
|
|
|
if (!o->chan) {
|
2004-06-21 06:11:56 +00:00
|
|
|
ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s'\n", tech, stuff);
|
2003-04-06 06:37:08 +00:00
|
|
|
o->stillgoing = 0;
|
2004-10-26 22:25:43 +00:00
|
|
|
HANDLE_CAUSE(cause, in);
|
2004-01-15 23:32:27 +00:00
|
|
|
} else {
|
2004-10-02 00:58:31 +00:00
|
|
|
if (o->chan->cid.cid_num)
|
|
|
|
free(o->chan->cid.cid_num);
|
|
|
|
o->chan->cid.cid_num = NULL;
|
|
|
|
if (o->chan->cid.cid_name)
|
|
|
|
free(o->chan->cid.cid_name);
|
|
|
|
o->chan->cid.cid_name = NULL;
|
2004-06-14 19:43:41 +00:00
|
|
|
|
|
|
|
if (o->forcecallerid) {
|
|
|
|
char *newcid = NULL;
|
|
|
|
|
|
|
|
if (strlen(in->macroexten))
|
|
|
|
newcid = in->macroexten;
|
2004-02-27 04:24:42 +00:00
|
|
|
else
|
2004-06-14 19:43:41 +00:00
|
|
|
newcid = in->exten;
|
2004-10-02 00:58:31 +00:00
|
|
|
o->chan->cid.cid_num = strdup(newcid);
|
2004-07-12 14:46:10 +00:00
|
|
|
strncpy(o->chan->accountcode, winner->accountcode, sizeof(o->chan->accountcode) - 1);
|
|
|
|
o->chan->cdrflags = winner->cdrflags;
|
2004-10-02 00:58:31 +00:00
|
|
|
if (!o->chan->cid.cid_num)
|
2004-06-14 19:43:41 +00:00
|
|
|
ast_log(LOG_WARNING, "Out of memory\n");
|
|
|
|
} else {
|
2004-10-02 00:58:31 +00:00
|
|
|
if (in->cid.cid_num) {
|
|
|
|
o->chan->cid.cid_num = strdup(in->cid.cid_num);
|
|
|
|
if (!o->chan->cid.cid_num)
|
|
|
|
ast_log(LOG_WARNING, "Out of memory\n");
|
|
|
|
}
|
|
|
|
if (in->cid.cid_name) {
|
|
|
|
o->chan->cid.cid_name = strdup(in->cid.cid_name);
|
|
|
|
if (!o->chan->cid.cid_name)
|
2004-08-27 03:16:16 +00:00
|
|
|
ast_log(LOG_WARNING, "Out of memory\n");
|
|
|
|
}
|
2004-07-12 14:46:10 +00:00
|
|
|
strncpy(o->chan->accountcode, in->accountcode, sizeof(o->chan->accountcode) - 1);
|
|
|
|
o->chan->cdrflags = in->cdrflags;
|
2004-01-15 23:32:27 +00:00
|
|
|
}
|
2004-06-14 19:43:41 +00:00
|
|
|
|
2004-10-02 00:58:31 +00:00
|
|
|
if (in->cid.cid_ani) {
|
|
|
|
if (o->chan->cid.cid_ani)
|
|
|
|
free(o->chan->cid.cid_ani);
|
|
|
|
o->chan->cid.cid_ani = malloc(strlen(in->cid.cid_ani) + 1);
|
|
|
|
if (o->chan->cid.cid_ani)
|
|
|
|
strncpy(o->chan->cid.cid_ani, in->cid.cid_ani, strlen(in->cid.cid_ani) + 1);
|
2004-02-27 04:24:42 +00:00
|
|
|
else
|
|
|
|
ast_log(LOG_WARNING, "Out of memory\n");
|
2004-01-15 23:32:27 +00:00
|
|
|
}
|
2004-10-02 00:58:31 +00:00
|
|
|
if (o->chan->cid.cid_rdnis)
|
|
|
|
free(o->chan->cid.cid_rdnis);
|
2004-05-04 19:11:25 +00:00
|
|
|
if (!ast_strlen_zero(in->macroexten))
|
2004-10-02 00:58:31 +00:00
|
|
|
o->chan->cid.cid_rdnis = strdup(in->macroexten);
|
2004-03-18 20:02:15 +00:00
|
|
|
else
|
2004-10-02 00:58:31 +00:00
|
|
|
o->chan->cid.cid_rdnis = strdup(in->exten);
|
2004-01-15 23:32:27 +00:00
|
|
|
if (ast_call(o->chan, tmpchan, 0)) {
|
|
|
|
ast_log(LOG_NOTICE, "Failed to dial on local channel for call forward to '%s'\n", tmpchan);
|
|
|
|
o->stillgoing = 0;
|
|
|
|
ast_hangup(o->chan);
|
|
|
|
o->chan = NULL;
|
2004-06-23 03:16:58 +00:00
|
|
|
numnochan++;
|
2004-01-15 23:32:27 +00:00
|
|
|
}
|
2003-04-06 06:37:08 +00:00
|
|
|
}
|
2004-07-12 14:46:10 +00:00
|
|
|
/* Hangup the original channel now, in case we needed it */
|
|
|
|
ast_hangup(winner);
|
2003-04-06 06:37:08 +00:00
|
|
|
continue;
|
2003-03-27 16:02:10 +00:00
|
|
|
}
|
2001-05-07 03:15:48 +00:00
|
|
|
f = ast_read(winner);
|
|
|
|
if (f) {
|
|
|
|
if (f->frametype == AST_FRAME_CONTROL) {
|
|
|
|
switch(f->subclass) {
|
|
|
|
case AST_CONTROL_ANSWER:
|
|
|
|
/* This is our guy if someone answered. */
|
|
|
|
if (!peer) {
|
1999-12-04 21:35:07 +00:00
|
|
|
if (option_verbose > 2)
|
2001-05-07 03:15:48 +00:00
|
|
|
ast_verbose( VERBOSE_PREFIX_3 "%s answered %s\n", o->chan->name, in->name);
|
|
|
|
peer = o->chan;
|
2003-07-02 14:06:12 +00:00
|
|
|
*allowredir_in = o->allowredirect_in;
|
|
|
|
*allowredir_out = o->allowredirect_out;
|
2004-07-28 19:25:14 +00:00
|
|
|
*allowdisconnect_in = o->allowdisconnect_in;
|
|
|
|
*allowdisconnect_out = o->allowdisconnect_out;
|
1999-12-04 21:35:07 +00:00
|
|
|
}
|
2001-05-07 03:15:48 +00:00
|
|
|
break;
|
|
|
|
case AST_CONTROL_BUSY:
|
|
|
|
if (option_verbose > 2)
|
|
|
|
ast_verbose( VERBOSE_PREFIX_3 "%s is busy\n", o->chan->name);
|
2003-10-01 16:05:40 +00:00
|
|
|
in->hangupcause = o->chan->hangupcause;
|
2003-07-22 23:08:45 +00:00
|
|
|
ast_hangup(o->chan);
|
2003-07-22 15:16:55 +00:00
|
|
|
o->chan = NULL;
|
2001-05-07 03:15:48 +00:00
|
|
|
o->stillgoing = 0;
|
2004-10-26 22:25:43 +00:00
|
|
|
HANDLE_CAUSE(AST_CAUSE_BUSY, in);
|
2001-05-07 03:15:48 +00:00
|
|
|
break;
|
2001-10-15 17:39:25 +00:00
|
|
|
case AST_CONTROL_CONGESTION:
|
|
|
|
if (option_verbose > 2)
|
|
|
|
ast_verbose( VERBOSE_PREFIX_3 "%s is circuit-busy\n", o->chan->name);
|
2003-10-01 16:05:40 +00:00
|
|
|
in->hangupcause = o->chan->hangupcause;
|
2003-07-22 23:08:45 +00:00
|
|
|
ast_hangup(o->chan);
|
2003-07-22 15:16:55 +00:00
|
|
|
o->chan = NULL;
|
2001-10-15 17:39:25 +00:00
|
|
|
o->stillgoing = 0;
|
2004-10-26 22:25:43 +00:00
|
|
|
HANDLE_CAUSE(AST_CAUSE_CONGESTION, in);
|
2001-10-15 17:39:25 +00:00
|
|
|
break;
|
2001-05-07 03:15:48 +00:00
|
|
|
case AST_CONTROL_RINGING:
|
|
|
|
if (option_verbose > 2)
|
|
|
|
ast_verbose( VERBOSE_PREFIX_3 "%s is ringing\n", o->chan->name);
|
2004-07-08 09:20:14 +00:00
|
|
|
if (!(*sentringing) && !outgoing->musiconhold) {
|
2001-05-07 03:15:48 +00:00
|
|
|
ast_indicate(in, AST_CONTROL_RINGING);
|
2004-07-08 09:20:14 +00:00
|
|
|
(*sentringing)++;
|
2001-05-07 03:15:48 +00:00
|
|
|
}
|
|
|
|
break;
|
2003-05-12 19:25:20 +00:00
|
|
|
case AST_CONTROL_PROGRESS:
|
|
|
|
if (option_verbose > 2)
|
|
|
|
ast_verbose ( VERBOSE_PREFIX_3 "%s is making progress passing it to %s\n", o->chan->name,in->name);
|
2004-10-07 18:28:49 +00:00
|
|
|
if (!outgoing->ringbackonly)
|
|
|
|
ast_indicate(in, AST_CONTROL_PROGRESS);
|
2003-05-12 19:25:20 +00:00
|
|
|
break;
|
2001-05-07 03:15:48 +00:00
|
|
|
case AST_CONTROL_OFFHOOK:
|
2004-11-03 22:37:55 +00:00
|
|
|
case AST_CONTROL_FLASH:
|
|
|
|
/* Ignore going off hook and flash */
|
2001-05-07 03:15:48 +00:00
|
|
|
break;
|
2003-04-06 06:11:25 +00:00
|
|
|
case -1:
|
2004-06-21 18:28:35 +00:00
|
|
|
if (!outgoing->ringbackonly && !outgoing->musiconhold) {
|
2004-03-19 00:08:43 +00:00
|
|
|
if (option_verbose > 2)
|
|
|
|
ast_verbose( VERBOSE_PREFIX_3 "%s stopped sounds\n", o->chan->name);
|
|
|
|
ast_indicate(in, -1);
|
2004-07-08 09:20:14 +00:00
|
|
|
(*sentringing) = 0;
|
2004-03-19 00:08:43 +00:00
|
|
|
}
|
2003-04-06 06:11:25 +00:00
|
|
|
break;
|
2001-05-07 03:15:48 +00:00
|
|
|
default:
|
|
|
|
ast_log(LOG_DEBUG, "Dunno what to do with control type %d\n", f->subclass);
|
1999-12-04 21:35:07 +00:00
|
|
|
}
|
2002-05-17 14:33:10 +00:00
|
|
|
} else if (single && (f->frametype == AST_FRAME_VOICE) &&
|
|
|
|
!(outgoing->ringbackonly || outgoing->musiconhold)) {
|
2001-05-07 03:15:48 +00:00
|
|
|
if (ast_write(in, f))
|
|
|
|
ast_log(LOG_WARNING, "Unable to forward frame\n");
|
2002-05-17 14:33:10 +00:00
|
|
|
} else if (single && (f->frametype == AST_FRAME_IMAGE) &&
|
|
|
|
!(outgoing->ringbackonly || outgoing->musiconhold)) {
|
2001-10-15 17:39:25 +00:00
|
|
|
if (ast_write(in, f))
|
|
|
|
ast_log(LOG_WARNING, "Unable to forward image\n");
|
1999-12-04 21:35:07 +00:00
|
|
|
}
|
2001-05-07 03:15:48 +00:00
|
|
|
ast_frfree(f);
|
|
|
|
} else {
|
2003-10-01 16:05:40 +00:00
|
|
|
in->hangupcause = o->chan->hangupcause;
|
2003-07-22 23:08:45 +00:00
|
|
|
ast_hangup(o->chan);
|
2003-07-22 15:16:55 +00:00
|
|
|
o->chan = NULL;
|
2001-05-07 03:15:48 +00:00
|
|
|
o->stillgoing = 0;
|
1999-12-04 21:35:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
o = o->next;
|
|
|
|
}
|
2001-05-07 03:15:48 +00:00
|
|
|
if (winner == in) {
|
1999-12-04 21:35:07 +00:00
|
|
|
f = ast_read(in);
|
|
|
|
#if 0
|
|
|
|
if (f && (f->frametype != AST_FRAME_VOICE))
|
|
|
|
printf("Frame type: %d, %d\n", f->frametype, f->subclass);
|
2001-10-15 17:39:25 +00:00
|
|
|
else if (!f || (f->frametype != AST_FRAME_VOICE))
|
|
|
|
printf("Hangup received on %s\n", in->name);
|
1999-12-04 21:35:07 +00:00
|
|
|
#endif
|
2001-10-15 17:39:25 +00:00
|
|
|
if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_HANGUP))) {
|
1999-12-04 21:35:07 +00:00
|
|
|
/* Got hung up */
|
|
|
|
*to=-1;
|
2004-07-14 07:22:30 +00:00
|
|
|
strncpy(status, "CANCEL", statussize - 1);
|
1999-12-04 21:35:07 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-07-28 19:25:14 +00:00
|
|
|
if (f && (f->frametype == AST_FRAME_DTMF) && *allowdisconnect_out &&
|
2002-09-02 15:20:28 +00:00
|
|
|
(f->subclass == '*')) {
|
|
|
|
if (option_verbose > 3)
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3 "User hit %c to disconnect call.\n", f->subclass);
|
|
|
|
*to=0;
|
2004-07-20 22:24:15 +00:00
|
|
|
strcpy(status, "CANCEL");
|
2002-09-02 15:20:28 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (single && ((f->frametype == AST_FRAME_VOICE) || (f->frametype == AST_FRAME_DTMF))) {
|
|
|
|
if (ast_write(outgoing->chan, f))
|
|
|
|
ast_log(LOG_WARNING, "Unable to forward voice\n");
|
2003-07-09 06:12:21 +00:00
|
|
|
ast_frfree(f);
|
2002-09-02 15:20:28 +00:00
|
|
|
}
|
1999-12-04 21:35:07 +00:00
|
|
|
}
|
2001-05-07 03:15:48 +00:00
|
|
|
if (!*to && (option_verbose > 2))
|
|
|
|
ast_verbose( VERBOSE_PREFIX_3 "Nobody picked up in %d ms\n", orig);
|
1999-12-04 21:35:07 +00:00
|
|
|
}
|
2002-05-17 14:33:10 +00:00
|
|
|
|
1999-12-04 21:35:07 +00:00
|
|
|
return peer;
|
2001-05-07 03:15:48 +00:00
|
|
|
|
1999-12-04 21:35:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dial_exec(struct ast_channel *chan, void *data)
|
|
|
|
{
|
|
|
|
int res=-1;
|
|
|
|
struct localuser *u;
|
2004-09-22 05:19:06 +00:00
|
|
|
char *info, *peers, *timeout, *tech, *number, *rest, *cur;
|
2003-01-17 05:10:52 +00:00
|
|
|
char privdb[256] = "", *s;
|
2003-10-22 04:25:13 +00:00
|
|
|
char announcemsg[256] = "", *ann;
|
2004-06-21 13:30:58 +00:00
|
|
|
struct localuser *outgoing=NULL, *tmp;
|
|
|
|
struct ast_channel *peer;
|
1999-12-04 21:35:07 +00:00
|
|
|
int to;
|
2003-07-02 14:06:12 +00:00
|
|
|
int allowredir_in=0;
|
|
|
|
int allowredir_out=0;
|
2004-07-28 19:25:14 +00:00
|
|
|
int allowdisconnect_in=0;
|
|
|
|
int allowdisconnect_out=0;
|
2004-09-10 02:31:30 +00:00
|
|
|
int hasmacro = 0;
|
2003-01-17 05:10:52 +00:00
|
|
|
int privacy=0;
|
2003-10-22 04:25:13 +00:00
|
|
|
int announce=0;
|
2003-03-10 06:00:17 +00:00
|
|
|
int resetcdr=0;
|
2004-10-26 22:25:43 +00:00
|
|
|
int numbusy = 0;
|
|
|
|
int numcongestion = 0;
|
|
|
|
int numnochan = 0;
|
|
|
|
int cause;
|
1999-12-18 07:01:48 +00:00
|
|
|
char numsubst[AST_MAX_EXTENSION];
|
1999-12-25 00:46:58 +00:00
|
|
|
char restofit[AST_MAX_EXTENSION];
|
2001-05-07 03:15:48 +00:00
|
|
|
char *transfer = NULL;
|
1999-12-18 07:01:48 +00:00
|
|
|
char *newnum;
|
2004-10-02 00:58:31 +00:00
|
|
|
char *l;
|
2003-01-17 05:10:52 +00:00
|
|
|
char *url=NULL; /* JDG */
|
|
|
|
struct ast_var_t *current;
|
|
|
|
struct varshead *headp, *newheadp;
|
|
|
|
struct ast_var_t *newvar;
|
2003-08-28 16:42:15 +00:00
|
|
|
int go_on=0;
|
2004-03-06 00:02:40 +00:00
|
|
|
unsigned int calldurationlimit=0;
|
|
|
|
char *cdl;
|
|
|
|
time_t now;
|
2004-04-26 23:22:34 +00:00
|
|
|
struct ast_bridge_config config;
|
|
|
|
long timelimit = 0;
|
|
|
|
long play_warning = 0;
|
|
|
|
long warning_freq=0;
|
|
|
|
char *warning_sound=NULL;
|
|
|
|
char *end_sound=NULL;
|
|
|
|
char *start_sound=NULL;
|
|
|
|
char *limitptr;
|
|
|
|
char limitdata[256];
|
2004-05-07 20:39:14 +00:00
|
|
|
char *sdtmfptr;
|
|
|
|
char sdtmfdata[256] = "";
|
2004-04-26 23:22:34 +00:00
|
|
|
char *stack,*var;
|
2004-09-10 02:31:30 +00:00
|
|
|
char *mac = NULL, macroname[256] = "";
|
2004-07-14 07:22:30 +00:00
|
|
|
char status[256]="";
|
2004-07-14 01:10:24 +00:00
|
|
|
char toast[80];
|
2004-04-26 23:22:34 +00:00
|
|
|
int play_to_caller=0,play_to_callee=0;
|
2004-06-21 18:28:35 +00:00
|
|
|
int playargs=0, sentringing=0, moh=0;
|
2004-11-01 02:23:28 +00:00
|
|
|
char *varname;
|
|
|
|
int vartype;
|
2004-11-07 21:49:43 +00:00
|
|
|
char *outbound_group = NULL;
|
2004-11-01 02:23:28 +00:00
|
|
|
|
2004-05-20 00:29:09 +00:00
|
|
|
int digit = 0;
|
2004-07-14 01:10:24 +00:00
|
|
|
time_t start_time, answer_time, end_time;
|
2004-04-26 23:22:34 +00:00
|
|
|
|
1999-12-04 21:35:07 +00:00
|
|
|
if (!data) {
|
2004-03-06 00:02:40 +00:00
|
|
|
ast_log(LOG_WARNING, "Dial requires an argument (technology1/number1&technology2/number2...|optional timeout|options)\n");
|
1999-12-04 21:35:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2004-09-22 05:19:06 +00:00
|
|
|
|
|
|
|
if (!(info = ast_strdupa(data))) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to dupe data :(\n");
|
|
|
|
return -1;
|
|
|
|
}
|
1999-12-04 21:35:07 +00:00
|
|
|
LOCAL_USER_ADD(u);
|
|
|
|
|
2001-03-30 18:47:35 +00:00
|
|
|
peers = info;
|
|
|
|
if (peers) {
|
2004-03-06 00:02:40 +00:00
|
|
|
|
2001-03-30 18:47:35 +00:00
|
|
|
timeout = strchr(info, '|');
|
|
|
|
if (timeout) {
|
|
|
|
*timeout = '\0';
|
|
|
|
timeout++;
|
2001-05-07 03:15:48 +00:00
|
|
|
transfer = strchr(timeout, '|');
|
|
|
|
if (transfer) {
|
|
|
|
*transfer = '\0';
|
|
|
|
transfer++;
|
2003-01-17 05:10:52 +00:00
|
|
|
/* JDG */
|
|
|
|
url = strchr(transfer, '|');
|
|
|
|
if (url) {
|
|
|
|
*url = '\0';
|
|
|
|
url++;
|
2004-11-01 02:23:28 +00:00
|
|
|
if (option_debug)
|
|
|
|
ast_log(LOG_DEBUG, "DIAL WITH URL=%s_\n", url);
|
2003-01-17 05:10:52 +00:00
|
|
|
} else
|
2004-11-01 02:23:28 +00:00
|
|
|
if (option_debug) {
|
|
|
|
ast_log(LOG_DEBUG, "SIMPLE DIAL (NO URL)\n");
|
|
|
|
}
|
2003-01-17 05:10:52 +00:00
|
|
|
/* /JDG */
|
2001-05-07 03:15:48 +00:00
|
|
|
}
|
2001-03-30 18:47:35 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
timeout = NULL;
|
2004-05-04 19:11:25 +00:00
|
|
|
if (!peers || ast_strlen_zero(peers)) {
|
1999-12-04 21:35:07 +00:00
|
|
|
ast_log(LOG_WARNING, "Dial argument takes format (technology1/number1&technology2/number2...|optional timeout)\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2001-03-30 18:47:35 +00:00
|
|
|
|
2003-01-17 05:10:52 +00:00
|
|
|
|
|
|
|
if (transfer) {
|
2004-04-26 23:22:34 +00:00
|
|
|
|
2004-03-06 00:02:40 +00:00
|
|
|
/* Extract call duration limit */
|
|
|
|
if ((cdl = strstr(transfer, "S("))) {
|
|
|
|
calldurationlimit=atoi(cdl+2);
|
|
|
|
if (option_verbose > 2)
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3 "Setting call duration limit to %i seconds.\n",calldurationlimit);
|
|
|
|
}
|
2004-04-26 23:22:34 +00:00
|
|
|
|
2004-05-07 20:39:14 +00:00
|
|
|
/* DTMF SCRIPT*/
|
|
|
|
if ((sdtmfptr = strstr(transfer, "D("))) {
|
2004-05-07 21:14:55 +00:00
|
|
|
strncpy(sdtmfdata, sdtmfptr + 2, sizeof(sdtmfdata) - 1);
|
|
|
|
/* Overwrite with X's what was the sdtmf info */
|
|
|
|
while (*sdtmfptr && (*sdtmfptr != ')'))
|
|
|
|
*(sdtmfptr++) = 'X';
|
|
|
|
if (*sdtmfptr)
|
|
|
|
*sdtmfptr = 'X';
|
|
|
|
/* Now find the end */
|
|
|
|
sdtmfptr = strchr(sdtmfdata, ')');
|
|
|
|
if (sdtmfptr)
|
|
|
|
*sdtmfptr = '\0';
|
|
|
|
else
|
|
|
|
ast_log(LOG_WARNING, "D( Data lacking trailing ')'\n");
|
2004-05-07 20:39:14 +00:00
|
|
|
}
|
|
|
|
|
2004-04-26 23:22:34 +00:00
|
|
|
/* XXX LIMIT SUPPORT */
|
|
|
|
if ((limitptr = strstr(transfer, "L("))) {
|
2004-05-07 21:14:55 +00:00
|
|
|
strncpy(limitdata, limitptr + 2, sizeof(limitdata) - 1);
|
|
|
|
/* Overwrite with X's what was the limit info */
|
|
|
|
while(*limitptr && (*limitptr != ')'))
|
|
|
|
*(limitptr++) = 'X';
|
|
|
|
if (*limitptr)
|
|
|
|
*limitptr = 'X';
|
|
|
|
/* Now find the end */
|
|
|
|
limitptr = strchr(limitdata, ')');
|
|
|
|
if (limitptr)
|
|
|
|
*limitptr = '\0';
|
|
|
|
else
|
|
|
|
ast_log(LOG_WARNING, "Limit Data lacking trailing ')'\n");
|
|
|
|
|
|
|
|
var = pbx_builtin_getvar_helper(chan,"LIMIT_PLAYAUDIO_CALLER");
|
|
|
|
play_to_caller = var ? ast_true(var) : 1;
|
2004-05-07 20:39:14 +00:00
|
|
|
|
2004-05-07 21:14:55 +00:00
|
|
|
var = pbx_builtin_getvar_helper(chan,"LIMIT_PLAYAUDIO_CALLEE");
|
|
|
|
play_to_callee = var ? ast_true(var) : 0;
|
2004-05-07 20:39:14 +00:00
|
|
|
|
2004-05-07 21:14:55 +00:00
|
|
|
if (!play_to_caller && !play_to_callee)
|
|
|
|
play_to_caller=1;
|
2004-05-07 20:39:14 +00:00
|
|
|
|
2004-05-07 21:14:55 +00:00
|
|
|
var = pbx_builtin_getvar_helper(chan,"LIMIT_WARNING_FILE");
|
|
|
|
warning_sound = var ? var : "timeleft";
|
|
|
|
|
|
|
|
var = pbx_builtin_getvar_helper(chan,"LIMIT_TIMEOUT_FILE");
|
|
|
|
end_sound = var ? var : NULL;
|
|
|
|
|
|
|
|
var = pbx_builtin_getvar_helper(chan,"LIMIT_CONNECT_FILE");
|
|
|
|
start_sound = var ? var : NULL;
|
|
|
|
|
|
|
|
var=stack=limitdata;
|
|
|
|
|
|
|
|
var = strsep(&stack, ":");
|
|
|
|
if (var) {
|
|
|
|
timelimit = atol(var);
|
|
|
|
playargs++;
|
|
|
|
var = strsep(&stack, ":");
|
|
|
|
if (var) {
|
|
|
|
play_warning = atol(var);
|
|
|
|
playargs++;
|
|
|
|
var = strsep(&stack, ":");
|
|
|
|
if(var) {
|
|
|
|
warning_freq = atol(var);
|
|
|
|
playargs++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-05-07 20:39:14 +00:00
|
|
|
|
2004-05-07 21:14:55 +00:00
|
|
|
if (!timelimit) {
|
|
|
|
timelimit=play_to_caller=play_to_callee=play_warning=warning_freq=0;
|
|
|
|
warning_sound=NULL;
|
|
|
|
}
|
|
|
|
/* undo effect of S(x) in case they are both used */
|
|
|
|
calldurationlimit=0;
|
|
|
|
/* more efficient do it like S(x) does since no advanced opts*/
|
|
|
|
if (!play_warning && !start_sound && !end_sound && timelimit) {
|
|
|
|
calldurationlimit=timelimit/1000;
|
|
|
|
timelimit=play_to_caller=play_to_callee=play_warning=warning_freq=0;
|
|
|
|
} else if (option_verbose > 2) {
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3"Limit Data:\n");
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3"timelimit=%ld\n",timelimit);
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3"play_warning=%ld\n",play_warning);
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3"play_to_caller=%s\n",play_to_caller ? "yes" : "no");
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3"play_to_callee=%s\n",play_to_callee ? "yes" : "no");
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3"warning_freq=%ld\n",warning_freq);
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3"start_sound=%s\n",start_sound ? start_sound : "UNDEF");
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3"warning_sound=%s\n",warning_sound ? warning_sound : "UNDEF");
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3"end_sound=%s\n",end_sound ? end_sound : "UNDEF");
|
|
|
|
}
|
2004-04-26 23:22:34 +00:00
|
|
|
}
|
2004-05-07 20:39:14 +00:00
|
|
|
|
2004-01-15 20:20:21 +00:00
|
|
|
/* XXX ANNOUNCE SUPPORT */
|
|
|
|
if ((ann = strstr(transfer, "A("))) {
|
|
|
|
announce = 1;
|
|
|
|
strncpy(announcemsg, ann + 2, sizeof(announcemsg) - 1);
|
|
|
|
/* Overwrite with X's what was the announce info */
|
|
|
|
while(*ann && (*ann != ')'))
|
|
|
|
*(ann++) = 'X';
|
|
|
|
if (*ann)
|
|
|
|
*ann = 'X';
|
|
|
|
/* Now find the end of the privdb */
|
|
|
|
ann = strchr(announcemsg, ')');
|
|
|
|
if (ann)
|
|
|
|
*ann = '\0';
|
|
|
|
else {
|
|
|
|
ast_log(LOG_WARNING, "Transfer with Announce spec lacking trailing ')'\n");
|
|
|
|
announce = 0;
|
|
|
|
}
|
|
|
|
}
|
2004-09-10 02:31:30 +00:00
|
|
|
|
|
|
|
/* Get the macroname from the dial option string */
|
|
|
|
if ((mac = strstr(transfer, "M("))) {
|
|
|
|
hasmacro = 1;
|
|
|
|
strncpy(macroname, mac + 2, sizeof(macroname) - 1);
|
|
|
|
while (*mac && (*mac != ')'))
|
|
|
|
*(mac++) = 'X';
|
|
|
|
if (*mac)
|
|
|
|
*mac = 'X';
|
|
|
|
else {
|
|
|
|
ast_log(LOG_WARNING, "Could not find macro to which we should jump.\n");
|
|
|
|
hasmacro = 0;
|
|
|
|
}
|
|
|
|
mac = strchr(macroname, ')');
|
|
|
|
if (mac)
|
|
|
|
*mac = '\0';
|
|
|
|
else {
|
|
|
|
ast_log(LOG_WARNING, "Macro flag set without trailing ')'\n");
|
|
|
|
hasmacro = 0;
|
|
|
|
}
|
|
|
|
}
|
2003-01-17 05:10:52 +00:00
|
|
|
/* Extract privacy info from transfer */
|
|
|
|
if ((s = strstr(transfer, "P("))) {
|
|
|
|
privacy = 1;
|
|
|
|
strncpy(privdb, s + 2, sizeof(privdb) - 1);
|
|
|
|
/* Overwrite with X's what was the privacy info */
|
|
|
|
while(*s && (*s != ')'))
|
|
|
|
*(s++) = 'X';
|
|
|
|
if (*s)
|
|
|
|
*s = 'X';
|
|
|
|
/* Now find the end of the privdb */
|
|
|
|
s = strchr(privdb, ')');
|
|
|
|
if (s)
|
|
|
|
*s = '\0';
|
|
|
|
else {
|
2004-01-15 20:20:21 +00:00
|
|
|
ast_log(LOG_WARNING, "Transfer with privacy lacking trailing ')'\n");
|
2003-01-17 05:10:52 +00:00
|
|
|
privacy = 0;
|
|
|
|
}
|
|
|
|
} else if (strchr(transfer, 'P')) {
|
|
|
|
/* No specified privdb */
|
|
|
|
privacy = 1;
|
2003-03-10 06:00:17 +00:00
|
|
|
} else if (strchr(transfer, 'C')) {
|
|
|
|
resetcdr = 1;
|
2003-01-17 05:10:52 +00:00
|
|
|
}
|
|
|
|
}
|
2003-03-10 06:00:17 +00:00
|
|
|
if (resetcdr && chan->cdr)
|
|
|
|
ast_cdr_reset(chan->cdr, 0);
|
2004-05-04 19:11:25 +00:00
|
|
|
if (ast_strlen_zero(privdb) && privacy) {
|
2003-01-17 05:10:52 +00:00
|
|
|
/* If privdb is not specified and we are using privacy, copy from extension */
|
|
|
|
strncpy(privdb, chan->exten, sizeof(privdb) - 1);
|
|
|
|
}
|
|
|
|
if (privacy) {
|
2004-10-02 00:58:31 +00:00
|
|
|
l = chan->cid.cid_num;
|
|
|
|
if (!l)
|
2003-01-17 05:10:52 +00:00
|
|
|
l = "";
|
|
|
|
ast_log(LOG_NOTICE, "Privacy DB is '%s', privacy is %d, clid is '%s'\n", privdb, privacy, l);
|
|
|
|
}
|
2004-11-07 21:49:43 +00:00
|
|
|
|
|
|
|
/* If a channel group has been specified, get it for use when we create peer channels */
|
|
|
|
outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP");
|
|
|
|
|
2001-03-30 18:47:35 +00:00
|
|
|
cur = peers;
|
1999-12-04 21:35:07 +00:00
|
|
|
do {
|
|
|
|
/* Remember where to start next time */
|
2001-03-30 18:47:35 +00:00
|
|
|
rest = strchr(cur, '&');
|
|
|
|
if (rest) {
|
|
|
|
*rest = 0;
|
|
|
|
rest++;
|
|
|
|
}
|
1999-12-18 07:01:48 +00:00
|
|
|
/* Get a technology/[device:]number pair */
|
2001-03-30 18:47:35 +00:00
|
|
|
tech = cur;
|
|
|
|
number = strchr(tech, '/');
|
1999-12-04 21:35:07 +00:00
|
|
|
if (!number) {
|
1999-12-18 07:01:48 +00:00
|
|
|
ast_log(LOG_WARNING, "Dial argument takes format (technology1/[device:]number1&technology2/[device:]number2...|optional timeout)\n");
|
1999-12-04 21:35:07 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2001-03-30 18:47:35 +00:00
|
|
|
*number = '\0';
|
|
|
|
number++;
|
1999-12-04 21:35:07 +00:00
|
|
|
tmp = malloc(sizeof(struct localuser));
|
|
|
|
if (!tmp) {
|
|
|
|
ast_log(LOG_WARNING, "Out of memory\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-17 14:33:10 +00:00
|
|
|
memset(tmp, 0, sizeof(struct localuser));
|
|
|
|
if (transfer) {
|
|
|
|
if (strchr(transfer, 't'))
|
2003-07-02 14:06:12 +00:00
|
|
|
tmp->allowredirect_in = 1;
|
|
|
|
else tmp->allowredirect_in = 0;
|
|
|
|
if (strchr(transfer, 'T'))
|
|
|
|
tmp->allowredirect_out = 1;
|
|
|
|
else tmp->allowredirect_out = 0;
|
2002-05-17 14:33:10 +00:00
|
|
|
if (strchr(transfer, 'r'))
|
|
|
|
tmp->ringbackonly = 1;
|
2003-01-17 05:10:52 +00:00
|
|
|
else tmp->ringbackonly = 0;
|
2002-05-17 14:33:10 +00:00
|
|
|
if (strchr(transfer, 'm'))
|
|
|
|
tmp->musiconhold = 1;
|
2003-01-17 05:10:52 +00:00
|
|
|
else tmp->musiconhold = 0;
|
2002-09-02 15:20:28 +00:00
|
|
|
if (strchr(transfer, 'H'))
|
2004-07-28 19:25:14 +00:00
|
|
|
allowdisconnect_out = tmp->allowdisconnect_out = 1;
|
|
|
|
else allowdisconnect_out = tmp->allowdisconnect_out = 0;
|
|
|
|
if(strchr(transfer, 'h'))
|
|
|
|
allowdisconnect_in = tmp->allowdisconnect_in = 1;
|
|
|
|
else allowdisconnect_in = tmp->allowdisconnect_in = 0;
|
2003-08-28 16:42:15 +00:00
|
|
|
if(strchr(transfer, 'g'))
|
|
|
|
go_on=1;
|
2004-06-14 19:43:41 +00:00
|
|
|
if (strchr(transfer, 'f'))
|
|
|
|
tmp->forcecallerid = 1;
|
|
|
|
else tmp->forcecallerid = 0;
|
2002-05-17 14:33:10 +00:00
|
|
|
}
|
2001-12-20 15:21:47 +00:00
|
|
|
strncpy(numsubst, number, sizeof(numsubst)-1);
|
1999-12-04 21:35:07 +00:00
|
|
|
/* If we're dialing by extension, look at the extension to know what to dial */
|
1999-12-18 07:01:48 +00:00
|
|
|
if ((newnum = strstr(numsubst, "BYEXTENSION"))) {
|
2001-12-20 15:21:47 +00:00
|
|
|
strncpy(restofit, newnum + strlen("BYEXTENSION"), sizeof(restofit)-1);
|
1999-12-25 00:46:58 +00:00
|
|
|
snprintf(newnum, sizeof(numsubst) - (newnum - numsubst), "%s%s", chan->exten,restofit);
|
1999-12-18 07:01:48 +00:00
|
|
|
if (option_debug)
|
|
|
|
ast_log(LOG_DEBUG, "Dialing by extension %s\n", numsubst);
|
1999-12-04 21:35:07 +00:00
|
|
|
}
|
|
|
|
/* Request the peer */
|
2004-10-26 22:25:43 +00:00
|
|
|
tmp->chan = ast_request(tech, chan->nativeformats, numsubst, &cause);
|
1999-12-04 21:35:07 +00:00
|
|
|
if (!tmp->chan) {
|
|
|
|
/* If we can't, just go on to the next call */
|
2001-12-20 15:21:47 +00:00
|
|
|
ast_log(LOG_NOTICE, "Unable to create channel of type '%s'\n", tech);
|
2004-10-26 22:25:43 +00:00
|
|
|
HANDLE_CAUSE(cause, chan);
|
2004-10-28 14:25:50 +00:00
|
|
|
cur = rest;
|
1999-12-04 21:35:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
2004-05-04 19:11:25 +00:00
|
|
|
if (!ast_strlen_zero(tmp->chan->call_forward)) {
|
2004-06-21 06:11:56 +00:00
|
|
|
char tmpchan[256]="";
|
|
|
|
char *stuff;
|
|
|
|
char *tech;
|
2004-06-21 13:30:58 +00:00
|
|
|
strncpy(tmpchan, tmp->chan->call_forward, sizeof(tmpchan) - 1);
|
2004-06-21 06:11:56 +00:00
|
|
|
if ((stuff = strchr(tmpchan, '/'))) {
|
|
|
|
*stuff = '\0';
|
|
|
|
stuff++;
|
|
|
|
tech = tmpchan;
|
|
|
|
} else {
|
|
|
|
snprintf(tmpchan, sizeof(tmpchan), "%s@%s", tmp->chan->call_forward, tmp->chan->context);
|
|
|
|
stuff = tmpchan;
|
|
|
|
tech = "Local";
|
|
|
|
}
|
|
|
|
/* Before processing channel, go ahead and check for forwarding */
|
2002-03-05 15:59:01 +00:00
|
|
|
if (option_verbose > 2)
|
2004-06-21 13:30:58 +00:00
|
|
|
ast_verbose(VERBOSE_PREFIX_3 "Forwarding %s to '%s/%s' (thanks to %s)\n", chan->name, tech, stuff, tmp->chan->name);
|
2004-06-21 06:11:56 +00:00
|
|
|
/* Setup parameters */
|
2004-06-21 13:30:58 +00:00
|
|
|
ast_hangup(tmp->chan);
|
2004-10-26 22:25:43 +00:00
|
|
|
tmp->chan = ast_request(tech, chan->nativeformats, stuff, &cause);
|
2003-04-06 06:37:08 +00:00
|
|
|
if (!tmp->chan) {
|
2004-06-21 06:11:56 +00:00
|
|
|
ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s'\n", tech, stuff);
|
2004-10-26 22:25:43 +00:00
|
|
|
HANDLE_CAUSE(cause, chan);
|
2004-10-28 14:25:50 +00:00
|
|
|
cur = rest;
|
2003-04-06 06:37:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
2002-03-05 15:59:01 +00:00
|
|
|
}
|
2004-11-01 02:23:28 +00:00
|
|
|
|
|
|
|
/* Contitionally copy channel variables to the newly created channel */
|
|
|
|
headp = &chan->varshead;
|
|
|
|
AST_LIST_TRAVERSE(headp, current, entries) {
|
|
|
|
varname = ast_var_full_name(current);
|
|
|
|
vartype = 0;
|
|
|
|
if (varname) {
|
|
|
|
if (varname[0] == '_') {
|
|
|
|
vartype = 1;
|
|
|
|
if (varname[1] == '_')
|
|
|
|
vartype = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (vartype == 1) {
|
|
|
|
newvar = ast_var_assign((char*)&(varname[1]),
|
|
|
|
ast_var_value(current));
|
|
|
|
newheadp = &tmp->chan->varshead;
|
|
|
|
AST_LIST_INSERT_HEAD(newheadp, newvar, entries);
|
|
|
|
if (option_debug)
|
|
|
|
ast_log(LOG_DEBUG, "Copying soft-transferable variable %s.\n",
|
|
|
|
ast_var_name(newvar));
|
|
|
|
} else if (vartype == 2) {
|
|
|
|
newvar = ast_var_assign(ast_var_full_name(current),
|
|
|
|
ast_var_value(current));
|
|
|
|
newheadp = &tmp->chan->varshead;
|
|
|
|
AST_LIST_INSERT_HEAD(newheadp, newvar, entries);
|
|
|
|
if (option_debug)
|
|
|
|
ast_log(LOG_DEBUG, "Copying hard-transferable variable %s.\n",
|
|
|
|
ast_var_name(newvar));
|
|
|
|
} else {
|
|
|
|
if (option_debug)
|
|
|
|
ast_log(LOG_DEBUG, "Not copying variable %s.\n",
|
|
|
|
ast_var_name(current));
|
2003-01-17 05:10:52 +00:00
|
|
|
}
|
|
|
|
}
|
2004-11-01 02:23:28 +00:00
|
|
|
|
1999-12-18 07:01:48 +00:00
|
|
|
tmp->chan->appl = "AppDial";
|
|
|
|
tmp->chan->data = "(Outgoing Line)";
|
2001-12-20 15:21:47 +00:00
|
|
|
tmp->chan->whentohangup = 0;
|
2004-10-02 00:58:31 +00:00
|
|
|
if (tmp->chan->cid.cid_num)
|
|
|
|
free(tmp->chan->cid.cid_num);
|
|
|
|
tmp->chan->cid.cid_num = NULL;
|
|
|
|
if (tmp->chan->cid.cid_name)
|
|
|
|
free(tmp->chan->cid.cid_name);
|
|
|
|
tmp->chan->cid.cid_name = NULL;
|
|
|
|
if (tmp->chan->cid.cid_ani)
|
|
|
|
free(tmp->chan->cid.cid_ani);
|
|
|
|
tmp->chan->cid.cid_ani = NULL;
|
|
|
|
|
|
|
|
if (chan->cid.cid_num)
|
|
|
|
tmp->chan->cid.cid_num = strdup(chan->cid.cid_num);
|
|
|
|
if (chan->cid.cid_name)
|
|
|
|
tmp->chan->cid.cid_name = strdup(chan->cid.cid_name);
|
|
|
|
if (chan->cid.cid_ani)
|
|
|
|
tmp->chan->cid.cid_ani = strdup(chan->cid.cid_ani);
|
|
|
|
|
2003-12-04 22:26:38 +00:00
|
|
|
/* Copy language from incoming to outgoing */
|
2004-07-14 07:22:30 +00:00
|
|
|
strncpy(tmp->chan->language, chan->language, sizeof(tmp->chan->language) - 1);
|
2004-07-22 03:51:54 +00:00
|
|
|
strncpy(tmp->chan->accountcode, chan->accountcode, sizeof(tmp->chan->accountcode) - 1);
|
|
|
|
tmp->chan->cdrflags = chan->cdrflags;
|
2004-05-04 19:11:25 +00:00
|
|
|
if (ast_strlen_zero(tmp->chan->musicclass))
|
2003-09-06 19:28:52 +00:00
|
|
|
strncpy(tmp->chan->musicclass, chan->musicclass, sizeof(tmp->chan->musicclass) - 1);
|
2004-10-31 23:34:22 +00:00
|
|
|
if (chan->cid.cid_rdnis)
|
|
|
|
tmp->chan->cid.cid_rdnis = strdup(chan->cid.cid_rdnis);
|
2003-10-01 15:59:26 +00:00
|
|
|
/* Pass callingpres setting */
|
2004-10-02 00:58:31 +00:00
|
|
|
tmp->chan->cid.cid_pres = chan->cid.cid_pres;
|
2004-10-02 01:05:11 +00:00
|
|
|
/* Pass type of number */
|
|
|
|
tmp->chan->cid.cid_ton = chan->cid.cid_ton;
|
|
|
|
/* Pass type of tns */
|
|
|
|
tmp->chan->cid.cid_tns = chan->cid.cid_tns;
|
2001-12-20 15:21:47 +00:00
|
|
|
/* Presense of ADSI CPE on outgoing channel follows ours */
|
|
|
|
tmp->chan->adsicpe = chan->adsicpe;
|
2003-12-18 23:42:10 +00:00
|
|
|
/* pass the digital flag */
|
|
|
|
ast_dup_flag(tmp->chan, chan, AST_FLAG_DIGITAL);
|
2004-11-07 21:49:43 +00:00
|
|
|
|
|
|
|
/* If we have an outbound group, set this peer channel to it */
|
|
|
|
if (outbound_group)
|
|
|
|
ast_app_group_set_channel(tmp->chan, outbound_group);
|
|
|
|
|
1999-12-04 21:35:07 +00:00
|
|
|
/* Place the call, but don't wait on the answer */
|
1999-12-18 07:01:48 +00:00
|
|
|
res = ast_call(tmp->chan, numsubst, 0);
|
2003-08-14 20:48:44 +00:00
|
|
|
|
|
|
|
/* Save the info in cdr's that we called them */
|
|
|
|
if (chan->cdr)
|
|
|
|
ast_cdr_setdestchan(chan->cdr, tmp->chan->name);
|
|
|
|
|
2004-06-20 06:24:25 +00:00
|
|
|
/* check the results of ast_call */
|
1999-12-04 21:35:07 +00:00
|
|
|
if (res) {
|
|
|
|
/* Again, keep going even if there's an error */
|
|
|
|
if (option_debug)
|
|
|
|
ast_log(LOG_DEBUG, "ast call on peer returned %d\n", res);
|
|
|
|
else if (option_verbose > 2)
|
1999-12-18 07:01:48 +00:00
|
|
|
ast_verbose(VERBOSE_PREFIX_3 "Couldn't call %s\n", numsubst);
|
1999-12-04 21:35:07 +00:00
|
|
|
ast_hangup(tmp->chan);
|
2004-10-26 22:25:43 +00:00
|
|
|
tmp->chan = NULL;
|
2004-11-01 14:48:07 +00:00
|
|
|
cur = rest;
|
1999-12-04 21:35:07 +00:00
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
if (option_verbose > 2)
|
1999-12-18 07:01:48 +00:00
|
|
|
ast_verbose(VERBOSE_PREFIX_3 "Called %s\n", numsubst);
|
1999-12-04 21:35:07 +00:00
|
|
|
/* Put them in the list of outgoing thingies... We're ready now.
|
|
|
|
XXX If we're forcibly removed, these outgoing calls won't get
|
|
|
|
hung up XXX */
|
|
|
|
tmp->stillgoing = -1;
|
|
|
|
tmp->next = outgoing;
|
|
|
|
outgoing = tmp;
|
2002-09-02 15:20:28 +00:00
|
|
|
/* If this line is up, don't try anybody else */
|
|
|
|
if (outgoing->chan->_state == AST_STATE_UP)
|
|
|
|
break;
|
2001-03-30 18:47:35 +00:00
|
|
|
cur = rest;
|
|
|
|
} while(cur);
|
|
|
|
|
2004-05-04 19:11:25 +00:00
|
|
|
if (timeout && !ast_strlen_zero(timeout)) {
|
2004-04-02 07:47:23 +00:00
|
|
|
to = atoi(timeout);
|
|
|
|
if (to > 0)
|
|
|
|
to *= 1000;
|
|
|
|
else
|
|
|
|
ast_log(LOG_WARNING, "Invalid timeout specified: '%s'\n", timeout);
|
|
|
|
} else
|
1999-12-04 21:35:07 +00:00
|
|
|
to = -1;
|
2004-06-21 18:28:35 +00:00
|
|
|
|
2004-06-22 13:53:45 +00:00
|
|
|
if (outgoing) {
|
2004-06-23 03:16:58 +00:00
|
|
|
/* Our status will at least be NOANSWER */
|
2004-07-14 07:22:30 +00:00
|
|
|
strncpy(status, "NOANSWER", sizeof(status) - 1);
|
2004-06-22 13:53:45 +00:00
|
|
|
if (outgoing->musiconhold) {
|
|
|
|
moh=1;
|
|
|
|
ast_moh_start(chan, NULL);
|
|
|
|
} else if (outgoing->ringbackonly) {
|
|
|
|
ast_indicate(chan, AST_CONTROL_RINGING);
|
|
|
|
sentringing++;
|
|
|
|
}
|
2004-06-23 03:16:58 +00:00
|
|
|
} else
|
2004-07-14 07:22:30 +00:00
|
|
|
strncpy(status, "CHANUNAVAIL", sizeof(status) - 1);
|
2004-06-21 18:28:35 +00:00
|
|
|
|
2004-07-14 01:10:24 +00:00
|
|
|
time(&start_time);
|
2004-10-26 22:25:43 +00:00
|
|
|
peer = wait_for_answer(chan, outgoing, &to, &allowredir_in, &allowredir_out, &allowdisconnect_in, &allowdisconnect_out, &sentringing, status, sizeof(status), numbusy, numnochan, numcongestion);
|
2004-06-21 18:28:35 +00:00
|
|
|
|
1999-12-04 21:35:07 +00:00
|
|
|
if (!peer) {
|
|
|
|
if (to)
|
|
|
|
/* Musta gotten hung up */
|
|
|
|
res = -1;
|
|
|
|
else
|
|
|
|
/* Nobody answered, next please? */
|
|
|
|
res=0;
|
|
|
|
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (peer) {
|
2004-07-14 01:10:24 +00:00
|
|
|
time(&answer_time);
|
2004-06-25 03:59:07 +00:00
|
|
|
#ifdef OSP_SUPPORT
|
|
|
|
/* Once call is answered, ditch the OSP Handle */
|
|
|
|
pbx_builtin_setvar_helper(chan, "OSPHANDLE", "");
|
|
|
|
#endif
|
2004-07-14 07:22:30 +00:00
|
|
|
strncpy(status, "ANSWER", sizeof(status) - 1);
|
1999-12-04 21:35:07 +00:00
|
|
|
/* Ah ha! Someone answered within the desired timeframe. Of course after this
|
|
|
|
we will always return with -1 so that it is hung up properly after the
|
|
|
|
conversation. */
|
|
|
|
hanguptree(outgoing, peer);
|
|
|
|
outgoing = NULL;
|
2001-12-20 15:21:47 +00:00
|
|
|
/* If appropriate, log that we have a destination channel */
|
|
|
|
if (chan->cdr)
|
|
|
|
ast_cdr_setdestchan(chan->cdr, peer->name);
|
2003-03-12 06:00:18 +00:00
|
|
|
if (peer->name)
|
|
|
|
pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", peer->name);
|
|
|
|
if (numsubst)
|
|
|
|
pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", numsubst);
|
2003-01-17 05:10:52 +00:00
|
|
|
/* JDG: sendurl */
|
2004-05-04 19:11:25 +00:00
|
|
|
if( url && !ast_strlen_zero(url) && ast_channel_supports_html(peer) ) {
|
2003-01-17 05:10:52 +00:00
|
|
|
ast_log(LOG_DEBUG, "app_dial: sendurl=%s.\n", url);
|
|
|
|
ast_channel_sendurl( peer, url );
|
|
|
|
} /* /JDG */
|
2004-05-07 20:39:14 +00:00
|
|
|
if (announce && announcemsg) {
|
2003-10-22 04:25:13 +00:00
|
|
|
// Start autoservice on the other chan
|
2004-05-07 20:39:14 +00:00
|
|
|
res = ast_autoservice_start(chan);
|
2003-10-22 04:25:13 +00:00
|
|
|
// Now Stream the File
|
2004-05-07 20:39:14 +00:00
|
|
|
if (!res)
|
|
|
|
res = ast_streamfile(peer,announcemsg,peer->language);
|
2004-05-20 00:29:09 +00:00
|
|
|
if (!res) {
|
|
|
|
digit = ast_waitstream(peer, AST_DIGIT_ANY);
|
|
|
|
}
|
2003-10-22 04:25:13 +00:00
|
|
|
// Ok, done. stop autoservice
|
2004-05-07 20:39:14 +00:00
|
|
|
res = ast_autoservice_stop(chan);
|
2004-05-20 00:29:09 +00:00
|
|
|
if (digit > 0 && !res)
|
|
|
|
res = ast_senddigit(chan, digit);
|
|
|
|
else
|
|
|
|
res = digit;
|
|
|
|
|
2004-05-07 21:14:55 +00:00
|
|
|
} else
|
|
|
|
res = 0;
|
2003-07-02 14:06:12 +00:00
|
|
|
|
2004-09-10 02:31:30 +00:00
|
|
|
if (hasmacro && macroname) {
|
|
|
|
void *app = NULL;
|
|
|
|
|
|
|
|
res = ast_autoservice_start(chan);
|
|
|
|
if (res) {
|
|
|
|
ast_log(LOG_ERROR, "Unable to start autoservice on calling channel\n");
|
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
app = pbx_findapp("Macro");
|
|
|
|
|
|
|
|
if (app && !res) {
|
|
|
|
res = pbx_exec(peer, app, macroname, 1);
|
|
|
|
ast_log(LOG_DEBUG, "Macro exited with status %d\n", res);
|
|
|
|
res = 0;
|
|
|
|
} else {
|
|
|
|
ast_log(LOG_ERROR, "Could not find application Macro\n");
|
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_autoservice_stop(chan) < 0) {
|
|
|
|
ast_log(LOG_ERROR, "Could not stop autoservice on calling channel\n");
|
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-07 21:14:55 +00:00
|
|
|
if (!res) {
|
|
|
|
if (calldurationlimit > 0) {
|
|
|
|
time(&now);
|
|
|
|
chan->whentohangup = now + calldurationlimit;
|
|
|
|
}
|
|
|
|
if (!ast_strlen_zero(sdtmfdata))
|
2004-06-06 02:30:10 +00:00
|
|
|
res = ast_dtmf_stream(peer,chan,sdtmfdata,250);
|
2004-05-07 20:39:14 +00:00
|
|
|
}
|
|
|
|
|
2004-05-07 21:14:55 +00:00
|
|
|
if (!res) {
|
|
|
|
memset(&config,0,sizeof(struct ast_bridge_config));
|
|
|
|
config.play_to_caller=play_to_caller;
|
|
|
|
config.play_to_callee=play_to_callee;
|
|
|
|
config.allowredirect_in = allowredir_in;
|
|
|
|
config.allowredirect_out = allowredir_out;
|
2004-07-28 19:25:14 +00:00
|
|
|
config.allowdisconnect_in = allowdisconnect_in;
|
|
|
|
config.allowdisconnect_out = allowdisconnect_out;
|
2004-05-07 21:14:55 +00:00
|
|
|
config.timelimit = timelimit;
|
|
|
|
config.play_warning = play_warning;
|
|
|
|
config.warning_freq = warning_freq;
|
|
|
|
config.warning_sound = warning_sound;
|
|
|
|
config.end_sound = end_sound;
|
|
|
|
config.start_sound = start_sound;
|
2004-06-21 18:28:35 +00:00
|
|
|
if (moh) {
|
|
|
|
moh = 0;
|
|
|
|
ast_moh_stop(chan);
|
|
|
|
} else if (sentringing) {
|
|
|
|
sentringing = 0;
|
|
|
|
ast_indicate(chan, -1);
|
|
|
|
}
|
2004-07-07 16:02:13 +00:00
|
|
|
/* Be sure no generators are left on it */
|
|
|
|
ast_deactivate_generator(chan);
|
|
|
|
/* Make sure channels are compatible */
|
|
|
|
res = ast_channel_make_compatible(chan, peer);
|
|
|
|
if (res < 0) {
|
|
|
|
ast_log(LOG_WARNING, "Had to drop call because I couldn't make %s compatible with %s\n", chan->name, peer->name);
|
|
|
|
ast_hangup(peer);
|
|
|
|
return -1;
|
|
|
|
}
|
2004-05-07 21:14:55 +00:00
|
|
|
res = ast_bridge_call(chan,peer,&config);
|
2004-07-14 01:10:24 +00:00
|
|
|
time(&end_time);
|
|
|
|
snprintf(toast, sizeof(toast), "%ld", (long)(end_time - start_time));
|
|
|
|
pbx_builtin_setvar_helper(chan, "DIALEDTIME", toast);
|
|
|
|
snprintf(toast, sizeof(toast), "%ld", (long)(end_time - answer_time));
|
|
|
|
pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", toast);
|
|
|
|
|
2004-05-07 21:14:55 +00:00
|
|
|
} else
|
|
|
|
res = -1;
|
2004-05-07 20:39:14 +00:00
|
|
|
|
2004-05-22 23:17:33 +00:00
|
|
|
if (res != AST_PBX_NO_HANGUP_PEER) {
|
|
|
|
if (!chan->_softhangup)
|
|
|
|
chan->hangupcause = peer->hangupcause;
|
2004-05-07 21:14:55 +00:00
|
|
|
ast_hangup(peer);
|
2004-05-22 23:17:33 +00:00
|
|
|
}
|
1999-12-04 21:35:07 +00:00
|
|
|
}
|
|
|
|
out:
|
2004-06-21 18:28:35 +00:00
|
|
|
if (moh) {
|
|
|
|
moh = 0;
|
|
|
|
ast_moh_stop(chan);
|
|
|
|
} else if (sentringing) {
|
|
|
|
sentringing = 0;
|
|
|
|
ast_indicate(chan, -1);
|
|
|
|
}
|
1999-12-04 21:35:07 +00:00
|
|
|
hanguptree(outgoing, NULL);
|
2004-06-23 03:16:58 +00:00
|
|
|
pbx_builtin_setvar_helper(chan, "DIALSTATUS", status);
|
2004-07-20 22:24:15 +00:00
|
|
|
ast_log(LOG_DEBUG, "Exiting with DIALSTATUS=%s.\n", status);
|
2004-06-23 03:16:58 +00:00
|
|
|
|
1999-12-04 21:35:07 +00:00
|
|
|
LOCAL_USER_REMOVE(u);
|
2003-08-28 16:42:15 +00:00
|
|
|
|
|
|
|
if((go_on>0) && (!chan->_softhangup))
|
|
|
|
res=0;
|
|
|
|
|
1999-12-04 21:35:07 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int unload_module(void)
|
|
|
|
{
|
|
|
|
STANDARD_HANGUP_LOCALUSERS;
|
|
|
|
return ast_unregister_application(app);
|
|
|
|
}
|
|
|
|
|
|
|
|
int load_module(void)
|
|
|
|
{
|
2000-03-26 01:59:06 +00:00
|
|
|
int res;
|
2001-12-20 15:21:47 +00:00
|
|
|
res = ast_register_application(app, dial_exec, synopsis, descrip);
|
2000-03-26 01:59:06 +00:00
|
|
|
return res;
|
1999-12-04 21:35:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *description(void)
|
|
|
|
{
|
|
|
|
return tdesc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usecount(void)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
STANDARD_USECOUNT(res);
|
|
|
|
return res;
|
|
|
|
}
|
2001-03-30 18:47:35 +00:00
|
|
|
|
|
|
|
char *key()
|
|
|
|
{
|
|
|
|
return ASTERISK_GPL_KEY;
|
|
|
|
}
|