Index: apps/app_queue.c =================================================================== --- apps/app_queue.c (revision 70163) +++ apps/app_queue.c (working copy) @@ -1288,19 +1288,19 @@ /* Say we're next, if we are */ if (qe->pos == 1) { res = play_file(qe->chan, qe->parent->sound_next); - if (res && valid_exit(qe, res)) + if (res) goto playout; else goto posout; } else { res = play_file(qe->chan, qe->parent->sound_thereare); - if (res && valid_exit(qe, res)) + if (res) goto playout; res = ast_say_number(qe->chan, qe->pos, AST_DIGIT_ANY, qe->chan->language, (char *) NULL); /* Needs gender */ - if (res && valid_exit(qe, res)) + if (res) goto playout; res = play_file(qe->chan, qe->parent->sound_calls); - if (res && valid_exit(qe, res)) + if (res) goto playout; } /* Round hold time to nearest minute */ @@ -1322,35 +1322,35 @@ if ((avgholdmins+avgholdsecs) > 0 && (qe->parent->announceholdtime) && (!(qe->parent->announceholdtime == ANNOUNCEHOLDTIME_ONCE) && qe->last_pos)) { res = play_file(qe->chan, qe->parent->sound_holdtime); - if (res && valid_exit(qe, res)) + if (res) goto playout; if (avgholdmins > 0) { if (avgholdmins < 2) { res = play_file(qe->chan, qe->parent->sound_lessthan); - if (res && valid_exit(qe, res)) + if (res) goto playout; res = ast_say_number(qe->chan, 2, AST_DIGIT_ANY, qe->chan->language, NULL); - if (res && valid_exit(qe, res)) + if (res) goto playout; } else { res = ast_say_number(qe->chan, avgholdmins, AST_DIGIT_ANY, qe->chan->language, NULL); - if (res && valid_exit(qe, res)) + if (res) goto playout; } res = play_file(qe->chan, qe->parent->sound_minutes); - if (res && valid_exit(qe, res)) + if (res) goto playout; } if (avgholdsecs>0) { res = ast_say_number(qe->chan, avgholdsecs, AST_DIGIT_ANY, qe->chan->language, NULL); - if (res && valid_exit(qe, res)) + if (res) goto playout; res = play_file(qe->chan, qe->parent->sound_seconds); - if (res && valid_exit(qe, res)) + if (res) goto playout; } @@ -1361,10 +1361,11 @@ ast_verbose(VERBOSE_PREFIX_3 "Told %s in %s their queue position (which was %d)\n", qe->chan->name, qe->parent->name, qe->pos); res = play_file(qe->chan, qe->parent->sound_thanks); - if (res && !valid_exit(qe, res)) - res = 0; playout: + if (res > 0 && !valid_exit(qe, res)) + res = 0; + /* Set our last_pos indicators */ qe->last_pos = now; qe->last_pos_said = qe->pos; @@ -1778,7 +1779,7 @@ if (!res) { /* Wait for a keypress */ res = ast_waitstream(chan, AST_DIGIT_ANY); - if (res < 0 || !valid_exit(qe, res)) + if (res > 0 && !valid_exit(qe, res)) res = 0; /* Stop playback */ @@ -1818,6 +1819,9 @@ if (!res) ast_moh_start(qe->chan, qe->moh, NULL); + if (res > 0 && !valid_exit(qe, res)) + res = 0; + /* update last_periodic_announce_time */ qe->last_periodic_announce_time = now; @@ -2212,8 +2216,12 @@ break; /* Wait a second before checking again */ - if ((res = ast_waitfordigit(qe->chan, RECHECK * 1000))) - break; + if ((res = ast_waitfordigit(qe->chan, RECHECK * 1000))) { + if (res > 0 && !valid_exit(qe, res)) + res = 0; + else + break; + } } return res; @@ -2703,7 +2711,11 @@ /* Don't need to hold the lock while we setup the outgoing calls */ int retrywait = qe->parent->retry * 1000; - return ast_waitfordigit(qe->chan, retrywait); + int res = ast_waitfordigit(qe->chan, retrywait); + if (res > 0 && !valid_exit(qe, res)) + res = 0; + + return res; } static struct member *interface_exists(struct call_queue *q, const char *interface) @@ -3388,29 +3400,13 @@ } else { ast_moh_start(chan, qe.moh, NULL); } - for (;;) { - /* This is the wait loop for callers 2 through maxlen */ - res = wait_our_turn(&qe, ringing, &reason); - /* If they hungup, return immediately */ - if (res < 0) { - /* Record this abandoned call */ - record_abandoned(&qe); - ast_queue_log(args.queuename, chan->uniqueid, "NONE", "ABANDON", "%d|%d|%ld", - qe.pos, qe.opos, (long) time(NULL) - qe.start); - if (option_verbose > 2) { - ast_verbose(VERBOSE_PREFIX_3 "User disconnected from queue %s while waiting their turn\n", args.queuename); - } - res = -1; - break; - } - if (!res) - break; - if (valid_exit(&qe, res)) { - ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%s|%d", qe.digits, qe.pos); - break; - } - } + /* This is the wait loop for callers 2 through maxlen */ + res = wait_our_turn(&qe, ringing, &reason); + if (res) + goto stop; + + /* always true... */ if (!res) { int makeannouncement = 0; @@ -3433,38 +3429,22 @@ if (makeannouncement) { /* Make a position announcement, if enabled */ - if (qe.parent->announcefrequency && !ringing && - (res = say_position(&qe))) { - ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%s|%d", qe.digits, qe.pos); - break; - } + if (qe.parent->announcefrequency && !ringing) + if ((res = say_position(&qe))) + goto stop; } makeannouncement = 1; /* Make a periodic announcement, if enabled */ - if (qe.parent->periodicannouncefrequency && !ringing && - (res = say_periodic_announcement(&qe))) { - ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%c|%d", res, qe.pos); - break; - } + if (qe.parent->periodicannouncefrequency && !ringing) + if ((res = say_periodic_announcement(&qe))) + goto stop; /* Try calling all queue members for 'timeout' seconds */ res = try_calling(&qe, args.options, args.announceoverride, args.url, &go_on, args.agi); - if (res) { - if (res < 0) { - if (!qe.handled) { - record_abandoned(&qe); - ast_queue_log(args.queuename, chan->uniqueid, "NONE", "ABANDON", - "%d|%d|%ld", qe.pos, qe.opos, - (long) time(NULL) - qe.start); - } - } else if (valid_exit(&qe, res)) { - ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHKEY", - "%s|%d", qe.digits, qe.pos); - } - break; - } + if (res) + goto stop; stat = get_member_status(qe.parent, qe.max_penalty); @@ -3495,19 +3475,9 @@ /* OK, we didn't get anybody; wait for 'retry' seconds; may get a digit to exit with */ res = wait_a_bit(&qe); - if (res < 0) { - record_abandoned(&qe); - ast_queue_log(args.queuename, chan->uniqueid, "NONE", "ABANDON", "%d|%d|%ld", qe.pos, qe.opos, (long)time(NULL) - qe.start); - if (option_verbose > 2) { - ast_verbose(VERBOSE_PREFIX_3 "User disconnected from queue %s when they almost made it\n", args.queuename); - } - res = -1; - break; - } - if (res && valid_exit(&qe, res)) { - ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%s|%d", qe.digits, qe.pos); - break; - } + if (res) + goto stop; + /* exit after 'timeout' cycle if 'n' option enabled */ if (go_on) { if (option_verbose > 2) @@ -3530,6 +3500,23 @@ } } } + +stop: + if (res) { + if (res < 0) { + if (!qe.handled) { + record_abandoned(&qe); + ast_queue_log(args.queuename, chan->uniqueid, "NONE", "ABANDON", + "%d|%d|%ld", qe.pos, qe.opos, + (long) time(NULL) - qe.start); + } + res = -1; + } else if (valid_exit(&qe, res)) { + ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHKEY", + "%s|%d", qe.digits, qe.pos); + } + } + /* Don't allow return code > 0 */ if (res >= 0 && res != AST_PBX_KEEPALIVE) { res = 0;