> Method 2 is my favorite. Note that this would not be a difficult
> feature to add, but it would be tedious since every type of channel
> would need to have every Dial exit area set the $RESULTCODE value.
> Perhaps I'll add that to the feature request list when I return from
> my trip...
John,
I went ahead and did a first step. This patch sets $RESULTCODE to the
hangup cause as contained in the DISCONNECT message, when dialing out on
a single pri channel and dial is called with the option 'R'. On 'normal
call clearing' (cause 16) Dial still hangs up. Nevertheless, the
following dialplan works for me:
[testing]
exten => 58005900,1,Answer
exten => 58005900,2,Dial(Zap/g8/12341234|20|R)
exten => 58005900,3,Goto(${RESULTCODE})
exten => 58005900,17,Busy
exten => 58005900,21,Congestion
exten => 58005900,31,Congestion
exten => 58005900,42,Congestion
If you did the same for SIP we might be able to throw together an
application to generalize messages based on a config file as you
suggested. Then we could perhaps do something like
[context1]
exten => 58005900,1,Dial(Zap/...|20|R)
exten => 58005900,2,ParseCause(Zap,${RESULTCODE},$GENERALCAUSE)
exten => 58005900,3,Goto(errorhandling,s,${GENERALCAUSE})
[context2]
exten => 58005900,1,Dial(SIP/...|20|R)
exten => 58005900,2,ParseCause(SIP,${RESULTCODE},$GENERALCAUSE)
exten => 58005900,3,Goto(errorhandling,s,${GENERALCAUSE})
[errorhandling]
exten => s,1,Busy
exten => s,2,Congestion
exten => s,3,Hangup
and we're almost there.
What do you think?
Thilo
Index: pbx.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx.c,v
retrieving revision 1.34
diff -u -r1.34 pbx.c
--- pbx.c 14 Jul 2003 17:17:05 -0000 1.34
+++ pbx.c 28 Jul 2003 16:07:54 -0000
@@ -846,6 +846,9 @@
*ret = workspace;
} else if (!strcmp(var, "UNIQUEID")) {
snprintf(workspace, workspacelen -1, "%s", c->uniqueid);
+ } else if (!strcmp(var, "RESULTCODE")) {
+ snprintf(workspace, workspacelen -1, "%i", c->res);
+ *ret = workspace;
} else {
AST_LIST_TRAVERSE(headp,variables,entries) {
#if 0
@@ -1621,7 +1624,7 @@
char exten[256];
int pos;
int waittime;
- int res=0;
+ int res=0;
/* A little initial setup here */
if (c->pbx)
Index: README.variables
===================================================================
RCS file: /usr/cvsroot/asterisk/README.variables,v
retrieving revision 1.5
diff -u -r1.5 README.variables
--- README.variables 30 May 2003 04:41:18 -0000 1.5
+++ README.variables 28 Jul 2003 16:07:54 -0000
@@ -40,6 +40,7 @@
${EPOCH} Current unix style epoch
${DATETIME} Current date time in the format: YYYY-MM-DD_HH:MM:SS
${UNIQUEID} Current call unique identifier
+${RESULTCODE} Resultcode set by last application
There are two reference modes - reference by value and reference by name.
To refer to a variable with its name (as an argument to a function that
Index: channels/chan_zap.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_zap.c,v
retrieving revision 1.69
diff -u -r1.69 chan_zap.c
--- channels/chan_zap.c 26 Jul 2003 19:24:09 -0000 1.69
+++ channels/chan_zap.c 28 Jul 2003 16:07:57 -0000
@@ -5816,11 +5816,13 @@
if (chan) {
ast_pthread_mutex_lock(&pri->pvt[chan]->lock);
if (pri->pvt[chan]->owner) {
- pri->pvt[chan]->alreadyhungup = 1;
+ pri->pvt[chan]->alreadyhungup = 1;
pri->pvt[chan]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Channel %d, span %d got hangup\n", chan, pri->span);
+ ast_verbose(VERBOSE_PREFIX_3 "Channel %d, span %d got hangup (cause %i: '%s')\n", chan, pri->span, e->hangup.cause, pri_cause2str(e->hangup.cause));
}
+ pri->pvt[chan]->owner->res = e->hangup.cause;
+
if (e->hangup.cause == PRI_CAUSE_REQUESTED_CHAN_UNAVAIL) {
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Forcing restart of channel %d since channel reported in use\n", chan);
Index: apps/app_dial.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_dial.c,v
retrieving revision 1.20
diff -u -r1.20 app_dial.c
--- apps/app_dial.c 25 Jul 2003 15:32:02 -0000 1.20
+++ apps/app_dial.c 28 Jul 2003 16:07:58 -0000
@@ -66,6 +66,7 @@
" 'c' -- clear-channel data call (PRI-PRI only).\n"
" 'H' -- allow caller to hang up by hitting *.\n"
" 'C' -- reset call detail record for this call.\n"
+" 'R' -- set ${RESULTCODE} to disconnect cause, if dialing pri channel .\n"
" 'P[(x)]' -- privacy mode, using 'x' as database if provided.\n"
" In addition to transferring the call, a call may be parked and then picked\n"
"up by another user.\n"
@@ -85,6 +86,7 @@
int musiconhold;
int dataquality;
int allowdisconnect;
+ int res;
struct localuser *next;
};
@@ -281,6 +283,11 @@
}
ast_frfree(f);
} else {
+ if (option_verbose > 2)
+ if(single && o->res) {
+ o->res = o->chan->res;
+ ast_verbose( VERBOSE_PREFIX_3 "Setting return code to %i\n", o->chan->res);
+ }
ast_hangup(o->chan);
o->chan = NULL;
o->stillgoing = 0;
@@ -472,6 +479,9 @@
if (strchr(transfer, 'd'))
tmp->dataquality = 1;
else tmp->dataquality = 0;
+ if (strchr(transfer, 'R'))
+ tmp->res = 1;
+ else tmp->res = 0;
if (strchr(transfer, 'H'))
allowdisconnect = tmp->allowdisconnect = 1;
else allowdisconnect = tmp->allowdisconnect = 0;
@@ -665,6 +675,7 @@
out:
hanguptree(outgoing, NULL);
LOCAL_USER_REMOVE(u);
+ chan->res = tmp->res;
return res;
}
Index: include/asterisk/channel.h
===================================================================
RCS file: /usr/cvsroot/asterisk/include/asterisk/channel.h,v
retrieving revision 1.15
diff -u -r1.15 channel.h
--- include/asterisk/channel.h 29 Jun 2003 20:32:26 -0000 1.15
+++ include/asterisk/channel.h 28 Jul 2003 16:07:58 -0000
@@ -105,6 +105,8 @@
char *appl;
/*! Data passed to current application */
char *data;
+ /*! Result code from the prior executed application */
+ int res;
/*! Has an exception been detected */
int exception;