From: Russell Bryant Date: Sun, 23 Jan 2005 23:57:41 +0000 (+0000) Subject: fix penalty behavior, thanks florian!! (bug #3114) X-Git-Tag: 1.0.11.1~248 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9d599a84ddd5aff716872def1c316568fc2db89;p=thirdparty%2Fasterisk.git fix penalty behavior, thanks florian!! (bug #3114) git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/v1-0@4883 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/CHANGES b/CHANGES index 7ec5e1285b..1b2e0e1fdd 100755 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,11 @@ is available through the Asterisk-CVS mailing list hosted at http://lists.digium.com. +Asterisk 1.0.5 + -- chan_zap + -- fix a callerid bug introduced in 1.0.4 + -- app_queue + -- fix some penalty behavior Asterisk 1.0.4 -- general -- fix memory leak evident with extensive use of variables diff --git a/apps/app_queue.c b/apps/app_queue.c index f48bd963d1..4d56b820d2 100755 --- a/apps/app_queue.c +++ b/apps/app_queue.c @@ -545,7 +545,7 @@ static void hanguptree(struct localuser *outgoing, struct ast_channel *exception } } -static int ring_entry(struct queue_ent *qe, struct localuser *tmp) +static int ring_entry(struct queue_ent *qe, struct localuser *tmp, int *busies) { int res; if (qe->parent->wrapuptime && (time(NULL) - tmp->lastcall < qe->parent->wrapuptime)) { @@ -553,6 +553,7 @@ static int ring_entry(struct queue_ent *qe, struct localuser *tmp) if (qe->chan->cdr) ast_cdr_busy(qe->chan->cdr); tmp->stillgoing = 0; + (*busies)++; return 0; } /* Request the peer */ @@ -564,6 +565,7 @@ static int ring_entry(struct queue_ent *qe, struct localuser *tmp) if (qe->chan->cdr) ast_cdr_busy(qe->chan->cdr); tmp->stillgoing = 0; + (*busies)++; return 0; } tmp->chan->appl = "AppQueue"; @@ -594,6 +596,7 @@ static int ring_entry(struct queue_ent *qe, struct localuser *tmp) ast_hangup(tmp->chan); tmp->chan = NULL; tmp->stillgoing = 0; + (*busies)++; return 0; } else { if (qe->parent->eventwhencalled) { @@ -611,10 +614,10 @@ static int ring_entry(struct queue_ent *qe, struct localuser *tmp) if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "Called %s/%s\n", tmp->tech, tmp->numsubst); } - return 0; + return 1; } -static int ring_one(struct queue_ent *qe, struct localuser *outgoing) +static int ring_one(struct queue_ent *qe, struct localuser *outgoing, int *busies) { struct localuser *cur; struct localuser *best; @@ -636,9 +639,9 @@ static int ring_one(struct queue_ent *qe, struct localuser *outgoing) /* Ring everyone who shares this best metric (for ringall) */ cur = outgoing; while(cur) { - if (cur->stillgoing && !cur->chan && (cur->metric == bestmetric)) { + if (cur->stillgoing && !cur->chan && (cur->metric <= bestmetric)) { ast_log(LOG_DEBUG, "(Parallel) Trying '%s/%s' with metric %d\n", cur->tech, cur->numsubst, cur->metric); - ring_entry(qe, cur); + ring_entry(qe, cur, busies); } cur = cur->next; } @@ -647,7 +650,7 @@ static int ring_one(struct queue_ent *qe, struct localuser *outgoing) if (option_debug) ast_log(LOG_DEBUG, "Trying '%s/%s' with metric %d\n", best->tech, best->numsubst, best->metric); - ring_entry(qe, best); + ring_entry(qe, best, busies); } } } while (best && !best->chan); @@ -711,15 +714,36 @@ static int valid_exit(struct queue_ent *qe, char digit) #define AST_MAX_WATCHERS 256 -static struct localuser *wait_for_answer(struct queue_ent *qe, struct localuser *outgoing, int *to, int *allowredir_in, int *allowredir_out, int *allowdisconnect_in, int *allowdisconnect_out, char *digit) +#define BUILD_STATS do { \ + o = outgoing; \ + found = -1; \ + pos = 1; \ + numlines = 0; \ + watchers[0] = in; \ + while(o) { \ + /* Keep track of important channels */ \ + if (o->stillgoing) { \ + stillgoing = 1; \ + if (o->chan) { \ + watchers[pos++] = o->chan; \ + found = 1; \ + } \ + } \ + o = o->next; \ + numlines++; \ + } \ + } while(0) + +static struct localuser *wait_for_answer(struct queue_ent *qe, struct localuser *outgoing, int *to, int *allowredir_in, int *allowredir_out, int *allowdisconnect_in, int *allowdisconnect_out, char *digit, int prebusies) { char *queue = qe->parent->name; struct localuser *o; int found; int numlines; int sentringing = 0; - int numbusies = 0; + int numbusies = prebusies; int orig = *to; + int stillgoing = 0; struct ast_frame *f; struct localuser *peer = NULL; struct ast_channel *watchers[AST_MAX_WATCHERS]; @@ -728,25 +752,18 @@ static struct localuser *wait_for_answer(struct queue_ent *qe, struct localuser struct ast_channel *in = qe->chan; while(*to && !peer) { - o = outgoing; - found = -1; - pos = 1; - numlines = 0; - watchers[0] = in; - while(o) { - /* Keep track of important channels */ - if (o->stillgoing && o->chan) { - watchers[pos++] = o->chan; - found = 1; - } - o = o->next; - numlines++; + BUILD_STATS; + if ((found < 0) && stillgoing && !qe->parent->strategy) { + /* On "ringall" strategy we only move to the next penalty level + when *all* ringing phones are done in the current penalty level */ + ring_one(qe, outgoing, &numbusies); + BUILD_STATS; } if (found < 0) { if (numlines == numbusies) { ast_log(LOG_DEBUG, "Everyone is busy at this time\n"); } else { - ast_log(LOG_NOTICE, "No one is answering queue '%s'\n", queue); + ast_log(LOG_NOTICE, "No one is answering queue '%s' (%d/%d)\n", queue, numlines, numbusies); } *to = 0; return NULL; @@ -790,7 +807,7 @@ static struct localuser *wait_for_answer(struct queue_ent *qe, struct localuser ast_hangup(o->chan); o->chan = NULL; if (qe->parent->strategy) - ring_one(qe, outgoing); + ring_one(qe, outgoing, &numbusies); numbusies++; break; case AST_CONTROL_CONGESTION: @@ -802,7 +819,7 @@ static struct localuser *wait_for_answer(struct queue_ent *qe, struct localuser ast_hangup(o->chan); o->chan = NULL; if (qe->parent->strategy) - ring_one(qe, outgoing); + ring_one(qe, outgoing, &numbusies); numbusies++; break; case AST_CONTROL_RINGING: @@ -828,7 +845,7 @@ static struct localuser *wait_for_answer(struct queue_ent *qe, struct localuser ast_hangup(o->chan); o->chan = NULL; if (qe->parent->strategy) - ring_one(qe, outgoing); + ring_one(qe, outgoing, &numbusies); } } o = o->next; @@ -1024,6 +1041,7 @@ static int try_calling(struct queue_ent *qe, char *options, char *announceoverri struct member *member; int res = 0, bridge = 0; int zapx = 2; + int numbusies = 0; int x=0; char *announce = NULL; char digit = 0; @@ -1106,9 +1124,9 @@ static int try_calling(struct queue_ent *qe, char *options, char *announceoverri to = qe->parent->timeout * 1000; else to = -1; - ring_one(qe, outgoing); + ring_one(qe, outgoing, &numbusies); ast_mutex_unlock(&qe->parent->lock); - lpeer = wait_for_answer(qe, outgoing, &to, &allowredir_in, &allowredir_out, &allowdisconnect_in, &allowdisconnect_out, &digit); + lpeer = wait_for_answer(qe, outgoing, &to, &allowredir_in, &allowredir_out, &allowdisconnect_in, &allowdisconnect_out, &digit, numbusies); ast_mutex_lock(&qe->parent->lock); if (qe->parent->strategy == QUEUE_STRATEGY_RRMEMORY) { store_next(qe, outgoing);