Convert code that checks the _softhangup member of ast_channel directory to use
authorRussell Bryant <russell@russellbryant.com>
Wed, 1 Aug 2007 15:39:54 +0000 (15:39 +0000)
committerRussell Bryant <russell@russellbryant.com>
Wed, 1 Aug 2007 15:39:54 +0000 (15:39 +0000)
the ast_check_hangup() funciton.  This function takes scheduled hangups into
account.
(closes issue #10230, patch by Juggie)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@77858 65c4cc65-6c06-0410-ace0-fbb531ad65f3

12 files changed:
apps/app_dial.c
apps/app_macro.c
apps/app_meetme.c
apps/app_osplookup.c
apps/app_queue.c
apps/app_zapras.c
channels/chan_local.c
channels/chan_vpb.cc
main/autoservice.c
main/pbx.c
pbx/pbx_dundi.c
res/res_features.c

index 8fd479f..c792811 100644 (file)
@@ -1789,7 +1789,7 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
                        ast_set2_flag(peer, autoloopflag, AST_FLAG_IN_AUTOLOOP);  /* set it back the way it was */
                }
                if (res != AST_PBX_NO_HANGUP_PEER) {
-                       if (!chan->_softhangup)
+                       if (!ast_check_hangup(chan))
                                chan->hangupcause = peer->hangupcause;
                        ast_hangup(peer);
                }
@@ -1808,7 +1808,7 @@ out:
        senddialendevent(chan, pa.status);
        ast_debug(1, "Exiting with DIALSTATUS=%s.\n", pa.status);
        
-       if ((ast_test_flag64(peerflags, OPT_GO_ON)) && (!chan->_softhangup) && (res != AST_PBX_KEEPALIVE)) {
+       if ((ast_test_flag64(peerflags, OPT_GO_ON)) && !ast_check_hangup(chan) && (res != AST_PBX_KEEPALIVE)) {
                if (calldurationlimit)
                        chan->whentohangup = 0;
                res = 0;
index 9949f43..32e9d2d 100644 (file)
@@ -385,7 +385,7 @@ static int _macro_exec(struct ast_channel *chan, void *data, int exclusive)
                }
 
                /* don't stop executing extensions when we're in "h" */
-               if (chan->_softhangup && !inhangup) {
+               if (ast_check_hangup(chan) && !inhangup) {
                        ast_debug(1, "Extension %s, macroexten %s, priority %d returned normally even though call was hung up\n", chan->exten, chan->macroexten, chan->priority);
                        goto out;
                }
@@ -434,7 +434,7 @@ static int _macro_exec(struct ast_channel *chan, void *data, int exclusive)
                /* If we're leaving the macro normally, restore original information */
                chan->priority = oldpriority;
                ast_copy_string(chan->context, oldcontext, sizeof(chan->context));
-               if (!(chan->_softhangup & AST_SOFTHANGUP_ASYNCGOTO)) {
+               if (!(ast_check_hangup(chan) & AST_SOFTHANGUP_ASYNCGOTO)) {
                        /* Copy the extension, so long as we're not in softhangup, where we could be given an asyncgoto */
                        const char *offsets;
                        ast_copy_string(chan->exten, oldexten, sizeof(chan->exten));
index e033044..fcf45e8 100644 (file)
@@ -718,7 +718,7 @@ static void conf_play(struct ast_channel *chan, struct ast_conference *conf, enu
        int len;
        int res = -1;
 
-       if (!chan->_softhangup)
+       if (!ast_check_hangup(chan))
                res = ast_autoservice_start(chan);
 
        AST_LIST_LOCK(&confs);
index dd75b57..3e7f9b2 100644 (file)
@@ -1734,7 +1734,7 @@ static int ospfinished_exec(
        ast_debug(1, "OSPFinish: connect '%ld'\n", connect);
        ast_debug(1, "OSPFinish: end '%ld'\n", end);
 
-       release = chan->_softhangup ? 0 : 1;
+       release = ast_check_hangup(chan) ? 0 : 1;
 
        if (osp_finish(outhandle, recorded, cause, start, connect, end, release) <= 0) {
                ast_debug(1, "OSPFinish: Unable to report usage for outbound call\n");
index 166237f..291c883 100644 (file)
@@ -2651,7 +2651,7 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
                                }
                        }
                        res2 |= ast_autoservice_stop(qe->chan);
-                       if (peer->_softhangup) {
+                       if (ast_check_hangup(peer)) {
                                /* Agent must have hung up */
                                ast_log(LOG_WARNING, "Agent on %s hungup on the customer.\n", peer->name);
                                ast_queue_log(queuename, qe->chan->uniqueid, member->membername, "AGENTDUMP", "%s", "");
@@ -2943,7 +2943,7 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
                                qe->chan->exten, qe->chan->context, (long) (callstart - qe->start),
                                (long) (time(NULL) - callstart));
                        send_agent_complete(qe, queuename, peer, member, callstart, vars, sizeof(vars), TRANSFER);
-               } else if (qe->chan->_softhangup) {
+               } else if (ast_check_hangup(qe->chan)) {
                        ast_queue_log(queuename, qe->chan->uniqueid, member->membername, "COMPLETECALLER", "%ld|%ld|%d",
                                (long) (callstart - qe->start), (long) (time(NULL) - callstart), qe->opos);
                        send_agent_complete(qe, queuename, peer, member, callstart, vars, sizeof(vars), CALLER);
index 448c45b..3433ba0 100644 (file)
@@ -161,7 +161,7 @@ static void run_ras(struct ast_channel *chan, char *args)
                        res = wait4(pid, &status, WNOHANG, NULL);
                        if (!res) {
                                /* Check for hangup */
-                               if (chan->_softhangup && !signalled) {
+                               if (ast_check_hangup(chan) && !signalled) {
                                        ast_debug(1, "Channel '%s' hungup.  Signalling RAS at %d to die...\n", chan->name, pid);
                                        kill(pid, SIGTERM);
                                        signalled=1;
index 3d814d1..30ad220 100644 (file)
@@ -246,9 +246,9 @@ static void check_bridge(struct local_pvt *p, int isoutbound)
                   we can't get everything.  Remember, we'll get another
                   chance in just a little bit */
                if (!ast_mutex_trylock(&(p->chan->_bridge)->lock)) {
-                       if (!p->chan->_bridge->_softhangup) {
+                       if (!ast_check_hangup(p->chan->_bridge)) {
                                if (!ast_mutex_trylock(&p->owner->lock)) {
-                                       if (!p->owner->_softhangup) {
+                                       if (!ast_check_hangup(p->owner)) {
                                                ast_channel_masquerade(p->owner, p->chan->_bridge);
                                                ast_set_flag(p, LOCAL_ALREADY_MASQED);
                                        }
@@ -265,9 +265,9 @@ static void check_bridge(struct local_pvt *p, int isoutbound)
        } else if (!isoutbound && p->owner && p->owner->_bridge && p->chan && AST_LIST_EMPTY(&p->chan->readq)) {
                /* Masquerade bridged channel into chan */
                if (!ast_mutex_trylock(&(p->owner->_bridge)->lock)) {
-                       if (!p->owner->_bridge->_softhangup) {
+                       if (!ast_check_hangup(p->owner->_bridge)) {
                                if (!ast_mutex_trylock(&p->chan->lock)) {
-                                       if (!p->chan->_softhangup) {
+                                       if (!ast_check_hangup(p->chan)) {
                                                ast_channel_masquerade(p->chan, p->owner->_bridge);
                                                ast_set_flag(p, LOCAL_ALREADY_MASQED);
                                        }
index 02c3faf..bcc3f68 100644 (file)
@@ -546,11 +546,11 @@ static enum ast_bridge_result ast_vpb_bridge(struct ast_channel *c0, struct ast_
                                *rc = who;
                                ast_debug(1, "%s: vpb_bridge: Got a [%s]\n",p0->dev, f ? "digit" : "hangup");
 /*
-                               if ((c0->tech_pvt == pvt0) && (!c0->_softhangup)) {
+                               if ((c0->tech_pvt == pvt0) && (!ast_check_hangup(c0))) {
                                        if (pr0->set_rtp_peer(c0, NULL, NULL, 0)) 
                                                ast_log(LOG_WARNING, "Channel '%s' failed to revert\n", c0->name);
                                }
-                               if ((c1->tech_pvt == pvt1) && (!c1->_softhangup)) {
+                               if ((c1->tech_pvt == pvt1) && (!ast_check_hangup(c1))) {
                                        if (pr1->set_rtp_peer(c1, NULL, NULL, 0)) 
                                                ast_log(LOG_WARNING, "Channel '%s' failed to revert back\n", c1->name);
                                }
index 029555a..9f175bc 100644 (file)
@@ -71,7 +71,7 @@ static void *autoservice_run(void *ign)
 
                AST_RWLIST_RDLOCK(&aslist);
                AST_RWLIST_TRAVERSE(&aslist, as, list) {
-                       if (!as->chan->_softhangup) {
+                       if (!ast_check_hangup(as->chan)) {
                                if (x < MAX_AUTOMONS)
                                        mons[x++] = as->chan;
                                else
@@ -137,7 +137,7 @@ int ast_autoservice_stop(struct ast_channel *chan)
                if (as->chan == chan) {
                        AST_RWLIST_REMOVE_CURRENT(&aslist, list);
                        ast_free(as);
-                       if (!chan->_softhangup)
+                       if (!ast_check_hangup(chan))
                                res = 0;
                        break;
                }
index 34b3eee..419523d 100644 (file)
@@ -2418,7 +2418,7 @@ static int __ast_pbx_run(struct ast_channel *c)
                                /* If the AbsoluteTimeout is not reset to 0, we'll get an infinite loop */
                                c->whentohangup = 0;
                                c->_softhangup &= ~AST_SOFTHANGUP_TIMEOUT;
-                       } else if (c->_softhangup) {
+                       } else if (ast_check_hangup(c)) {
                                ast_debug(1, "Extension %s, priority %d returned normally even though call was hung up\n",
                                        c->exten, c->priority);
                                error = 1;
index b37c4ed..41866f0 100644 (file)
@@ -3484,7 +3484,7 @@ static int dundi_lookup_internal(struct dundi_result *result, int maxret, struct
        struct timeval start;
        
        /* Don't do anthing for a hungup channel */
-       if (chan && chan->_softhangup)
+       if (chan && ast_check_hangup(chan))
                return 0;
 
        ttlms = DUNDI_FLUFF_TIME + ttl * DUNDI_TTL_TIME;
@@ -3525,7 +3525,7 @@ static int dundi_lookup_internal(struct dundi_result *result, int maxret, struct
                                ast_log(LOG_DEBUG, "Waiting for similar request for '%s@%s' for '%s'\n",
                                        dr.number,dr.dcontext,dundi_eid_to_str(eid_str, sizeof(eid_str), &pending->root_eid));
                        start = ast_tvnow();
-                       while(check_request(pending) && (ast_tvdiff_ms(ast_tvnow(), start) < ttlms) && (!chan || !chan->_softhangup)) {
+                       while(check_request(pending) && (ast_tvdiff_ms(ast_tvnow(), start) < ttlms) && (!chan || !ast_check_hangup(chan))) {
                                /* XXX Would be nice to have a way to poll/select here XXX */
                                /* XXX this is a busy wait loop!!! */
                                usleep(1);
@@ -3558,11 +3558,11 @@ static int dundi_lookup_internal(struct dundi_result *result, int maxret, struct
        discover_transactions(&dr);
        /* Wait for transaction to come back */
        start = ast_tvnow();
-       while (!AST_LIST_EMPTY(&dr.trans) && (ast_tvdiff_ms(ast_tvnow(), start) < ttlms) && (!chan || !chan->_softhangup)) {
+       while (!AST_LIST_EMPTY(&dr.trans) && (ast_tvdiff_ms(ast_tvnow(), start) < ttlms) && (!chan || !ast_check_hangup(chan))) {
                ms = 100;
                ast_waitfor_n_fd(dr.pfds, 1, &ms, NULL);
        }
-       if (chan && chan->_softhangup && option_debug)
+       if (chan && ast_check_hangup(chan) && option_debug)
                ast_log(LOG_DEBUG, "Hrm, '%s' hungup before their query for %s@%s finished\n", chan->name, dr.number, dr.dcontext);
        cancel_request(&dr);
        unregister_request(&dr);
index 610fffa..c90a5c5 100644 (file)
@@ -854,7 +854,7 @@ static int builtin_atxfer(struct ast_channel *chan, struct ast_channel *peer, st
                ast_set_flag(&(bconfig.features_caller), AST_FEATURE_DISCONNECT);
                ast_set_flag(&(bconfig.features_callee), AST_FEATURE_DISCONNECT);
                res = ast_bridge_call(transferer, newchan, &bconfig);
-               if (newchan->_softhangup || !transferer->_softhangup) {
+               if (ast_check_hangup(newchan) || !ast_check_hangup(transferer)) {
                        ast_hangup(newchan);
                        if (ast_stream_and_wait(transferer, xfersound, ""))
                                ast_log(LOG_WARNING, "Failed to play transfer sound!\n");
@@ -1450,7 +1450,7 @@ static struct ast_channel *ast_feature_request_and_dial(struct ast_channel *call
                        x = 0;
                        started = ast_tvnow();
                        to = timeout;
-                       while (!((transferee && transferee->_softhangup) && (!igncallerstate && ast_check_hangup(caller))) && timeout && (chan->_state != AST_STATE_UP)) {
+                       while (!((transferee && ast_check_hangup(transferee)) && (!igncallerstate && ast_check_hangup(caller))) && timeout && (chan->_state != AST_STATE_UP)) {
                                struct ast_frame *f = NULL;
 
                                monitor_chans[0] = caller;
@@ -1504,7 +1504,7 @@ static struct ast_channel *ast_feature_request_and_dial(struct ast_channel *call
                                        f = ast_read(caller);
                                        if (f == NULL) { /*doh! where'd he go?*/
                                                if (!igncallerstate) {
-                                                       if (caller->_softhangup && !chan->_softhangup) {
+                                                       if (ast_check_hangup(caller) && !ast_check_hangup(chan)) {
                                                                /* make this a blind transfer */
                                                                ready = 1;
                                                                break;