mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-20 03:26:55 +00:00
change HANDLE_CAUSE into a function.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@47175 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
114
apps/app_dial.c
114
apps/app_dial.c
@@ -318,30 +318,47 @@ static void hanguptree(struct dial_localuser *outgoing, struct ast_channel *exce
|
|||||||
|
|
||||||
#define AST_MAX_WATCHERS 256
|
#define AST_MAX_WATCHERS 256
|
||||||
|
|
||||||
#define HANDLE_CAUSE(cause, chan) do { \
|
/*
|
||||||
switch(cause) { \
|
* argument to handle_cause() and other functions.
|
||||||
case AST_CAUSE_BUSY: \
|
*/
|
||||||
if (chan->cdr) \
|
struct cause_args {
|
||||||
ast_cdr_busy(chan->cdr); \
|
struct ast_channel *chan;
|
||||||
numbusy++; \
|
int busy;
|
||||||
break; \
|
int congestion;
|
||||||
case AST_CAUSE_CONGESTION: \
|
int nochan;
|
||||||
if (chan->cdr) \
|
};
|
||||||
ast_cdr_failed(chan->cdr); \
|
|
||||||
numcongestion++; \
|
static void handle_cause(int cause, struct cause_args *num)
|
||||||
break; \
|
{
|
||||||
case AST_CAUSE_UNREGISTERED: \
|
struct ast_cdr *cdr = num->chan->cdr;
|
||||||
if (chan->cdr) \
|
|
||||||
ast_cdr_failed(chan->cdr); \
|
switch(cause) {
|
||||||
numnochan++; \
|
case AST_CAUSE_BUSY:
|
||||||
break; \
|
if (cdr)
|
||||||
case AST_CAUSE_NORMAL_CLEARING: \
|
ast_cdr_busy(cdr);
|
||||||
break; \
|
num->busy++;
|
||||||
default: \
|
break;
|
||||||
numnochan++; \
|
|
||||||
break; \
|
case AST_CAUSE_CONGESTION:
|
||||||
} \
|
if (cdr)
|
||||||
} while (0)
|
ast_cdr_failed(cdr);
|
||||||
|
num->congestion++;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AST_CAUSE_UNREGISTERED:
|
||||||
|
if (cdr)
|
||||||
|
ast_cdr_failed(cdr);
|
||||||
|
num->nochan++;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AST_CAUSE_NORMAL_CLEARING:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
num->nochan++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* free the buffer if allocated, and set the pointer to the second arg */
|
/* free the buffer if allocated, and set the pointer to the second arg */
|
||||||
#define S_REPLACE(s, new_val) \
|
#define S_REPLACE(s, new_val) \
|
||||||
@@ -402,12 +419,11 @@ static void senddialendevent(const struct ast_channel *src, const char *dialstat
|
|||||||
src->name, dialstatus);
|
src->name, dialstatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_localuser *outgoing, int *to, struct ast_flags *peerflags, int *sentringing, char *status, size_t statussize, int busystart, int nochanstart, int congestionstart, int priority_jump, int *result)
|
static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_localuser *outgoing, int *to, struct ast_flags *peerflags, int *sentringing, char *status, size_t statussize,
|
||||||
|
const struct cause_args *num_in, int priority_jump, int *result)
|
||||||
{
|
{
|
||||||
int numbusy = busystart;
|
struct cause_args num = *num_in;
|
||||||
int numcongestion = congestionstart;
|
int prestart = num.busy + num.congestion + num.nochan;
|
||||||
int numnochan = nochanstart;
|
|
||||||
int prestart = busystart + congestionstart + nochanstart;
|
|
||||||
int orig = *to;
|
int orig = *to;
|
||||||
struct ast_channel *peer = NULL;
|
struct ast_channel *peer = NULL;
|
||||||
/* single is set if only one destination is enabled */
|
/* single is set if only one destination is enabled */
|
||||||
@@ -436,20 +452,20 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_l
|
|||||||
numlines++;
|
numlines++;
|
||||||
}
|
}
|
||||||
if (pos == 1) { /* only the input channel is available */
|
if (pos == 1) { /* only the input channel is available */
|
||||||
if (numlines == (numbusy + numcongestion + numnochan)) {
|
if (numlines == (num.busy + num.congestion + num.nochan)) {
|
||||||
if (option_verbose > 2)
|
if (option_verbose > 2)
|
||||||
ast_verbose( VERBOSE_PREFIX_2 "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, numbusy, numcongestion, numnochan);
|
ast_verbose( VERBOSE_PREFIX_2 "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
|
||||||
if (numbusy)
|
if (num.busy)
|
||||||
strcpy(status, "BUSY");
|
strcpy(status, "BUSY");
|
||||||
else if (numcongestion)
|
else if (num.congestion)
|
||||||
strcpy(status, "CONGESTION");
|
strcpy(status, "CONGESTION");
|
||||||
else if (numnochan)
|
else if (num.nochan)
|
||||||
strcpy(status, "CHANUNAVAIL");
|
strcpy(status, "CHANUNAVAIL");
|
||||||
if (ast_opt_priority_jumping || priority_jump)
|
if (ast_opt_priority_jumping || priority_jump)
|
||||||
ast_goto_if_exists(in, in->context, in->exten, in->priority + 101);
|
ast_goto_if_exists(in, in->context, in->exten, in->priority + 101);
|
||||||
} else {
|
} else {
|
||||||
if (option_verbose > 2)
|
if (option_verbose > 2)
|
||||||
ast_verbose(VERBOSE_PREFIX_3 "No one is available to answer at this time (%d:%d/%d/%d)\n", numlines, numbusy, numcongestion, numnochan);
|
ast_verbose(VERBOSE_PREFIX_3 "No one is available to answer at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
|
||||||
}
|
}
|
||||||
*to = 0;
|
*to = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -522,7 +538,7 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_l
|
|||||||
}
|
}
|
||||||
if (!c) {
|
if (!c) {
|
||||||
ast_clear_flag(o, DIAL_STILLGOING);
|
ast_clear_flag(o, DIAL_STILLGOING);
|
||||||
HANDLE_CAUSE(cause, in);
|
handle_cause(cause, &num);
|
||||||
} else {
|
} else {
|
||||||
ast_rtp_make_compatible(c, in, single);
|
ast_rtp_make_compatible(c, in, single);
|
||||||
if (c->cid.cid_num)
|
if (c->cid.cid_num)
|
||||||
@@ -552,7 +568,7 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_l
|
|||||||
ast_clear_flag(o, DIAL_STILLGOING);
|
ast_clear_flag(o, DIAL_STILLGOING);
|
||||||
ast_hangup(c);
|
ast_hangup(c);
|
||||||
c = o->chan = NULL;
|
c = o->chan = NULL;
|
||||||
numnochan++;
|
num.nochan++;
|
||||||
} else {
|
} else {
|
||||||
senddialevent(in, c);
|
senddialevent(in, c);
|
||||||
/* After calling, set callerid to extension */
|
/* After calling, set callerid to extension */
|
||||||
@@ -572,7 +588,7 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_l
|
|||||||
ast_hangup(c);
|
ast_hangup(c);
|
||||||
c = o->chan = NULL;
|
c = o->chan = NULL;
|
||||||
ast_clear_flag(o, DIAL_STILLGOING);
|
ast_clear_flag(o, DIAL_STILLGOING);
|
||||||
HANDLE_CAUSE(in->hangupcause, in);
|
handle_cause(in->hangupcause, &num);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (f->frametype == AST_FRAME_CONTROL) {
|
if (f->frametype == AST_FRAME_CONTROL) {
|
||||||
@@ -605,7 +621,7 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_l
|
|||||||
ast_hangup(c);
|
ast_hangup(c);
|
||||||
c = o->chan = NULL;
|
c = o->chan = NULL;
|
||||||
ast_clear_flag(o, DIAL_STILLGOING);
|
ast_clear_flag(o, DIAL_STILLGOING);
|
||||||
HANDLE_CAUSE(AST_CAUSE_BUSY, in);
|
handle_cause(AST_CAUSE_BUSY, &num);
|
||||||
break;
|
break;
|
||||||
case AST_CONTROL_CONGESTION:
|
case AST_CONTROL_CONGESTION:
|
||||||
if (option_verbose > 2)
|
if (option_verbose > 2)
|
||||||
@@ -614,7 +630,7 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_l
|
|||||||
ast_hangup(c);
|
ast_hangup(c);
|
||||||
c = o->chan = NULL;
|
c = o->chan = NULL;
|
||||||
ast_clear_flag(o, DIAL_STILLGOING);
|
ast_clear_flag(o, DIAL_STILLGOING);
|
||||||
HANDLE_CAUSE(AST_CAUSE_CONGESTION, in);
|
handle_cause(AST_CAUSE_CONGESTION, &num);
|
||||||
break;
|
break;
|
||||||
case AST_CONTROL_RINGING:
|
case AST_CONTROL_RINGING:
|
||||||
if (option_verbose > 2)
|
if (option_verbose > 2)
|
||||||
@@ -785,15 +801,13 @@ static int valid_priv_reply(struct ast_flags *opts, int res)
|
|||||||
|
|
||||||
static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags *peerflags)
|
static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags *peerflags)
|
||||||
{
|
{
|
||||||
int res = -1;
|
int res = -1; /* default: error */
|
||||||
struct ast_module_user *u;
|
struct ast_module_user *u;
|
||||||
char *rest, *cur;
|
char *rest, *cur; /* scan the list of destinations */
|
||||||
struct dial_localuser *outgoing = NULL;
|
struct dial_localuser *outgoing = NULL; /* list of destinations */
|
||||||
struct ast_channel *peer;
|
struct ast_channel *peer;
|
||||||
int to;
|
int to; /* timeout */
|
||||||
int numbusy = 0;
|
struct cause_args num = { chan, 0, 0, 0 };
|
||||||
int numcongestion = 0;
|
|
||||||
int numnochan = 0;
|
|
||||||
int cause;
|
int cause;
|
||||||
char numsubst[AST_MAX_EXTENSION];
|
char numsubst[AST_MAX_EXTENSION];
|
||||||
char cidname[AST_MAX_EXTENSION];
|
char cidname[AST_MAX_EXTENSION];
|
||||||
@@ -1092,7 +1106,7 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
|
|||||||
if (!tmp->chan) {
|
if (!tmp->chan) {
|
||||||
/* If we can't, just go on to the next call */
|
/* If we can't, just go on to the next call */
|
||||||
ast_log(LOG_WARNING, "Unable to create channel of type '%s' (cause %d - %s)\n", tech, cause, ast_cause2str(cause));
|
ast_log(LOG_WARNING, "Unable to create channel of type '%s' (cause %d - %s)\n", tech, cause, ast_cause2str(cause));
|
||||||
HANDLE_CAUSE(cause, chan);
|
handle_cause(cause, &num);
|
||||||
if (!rest) /* we are on the last destination */
|
if (!rest) /* we are on the last destination */
|
||||||
chan->hangupcause = cause;
|
chan->hangupcause = cause;
|
||||||
continue;
|
continue;
|
||||||
@@ -1137,7 +1151,7 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
|
|||||||
cause = AST_CAUSE_CONGESTION;
|
cause = AST_CAUSE_CONGESTION;
|
||||||
}
|
}
|
||||||
if (!tmp->chan) {
|
if (!tmp->chan) {
|
||||||
HANDLE_CAUSE(cause, chan);
|
handle_cause(cause, &num);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1242,7 +1256,7 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
|
|||||||
}
|
}
|
||||||
|
|
||||||
time(&start_time);
|
time(&start_time);
|
||||||
peer = wait_for_answer(chan, outgoing, &to, peerflags, &sentringing, status, sizeof(status), numbusy, numnochan, numcongestion, ast_test_flag(&opts, OPT_PRIORITY_JUMP), &result);
|
peer = wait_for_answer(chan, outgoing, &to, peerflags, &sentringing, status, sizeof(status), &num, ast_test_flag(&opts, OPT_PRIORITY_JUMP), &result);
|
||||||
|
|
||||||
if (!peer) {
|
if (!peer) {
|
||||||
if (result) {
|
if (result) {
|
||||||
|
Reference in New Issue
Block a user