]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix channel redirect out of MeetMe() and other issues with channel softhangup.
authorRussell Bryant <russell@russellbryant.com>
Mon, 24 Jan 2011 20:32:21 +0000 (20:32 +0000)
committerRussell Bryant <russell@russellbryant.com>
Mon, 24 Jan 2011 20:32:21 +0000 (20:32 +0000)
Mantis issue #18585 reports that a channel redirect out of MeetMe() stopped
working properly.  This issue includes a patch that resolves the issue by
removing a call to ast_check_hangup() from app_meetme.c.  I left that in my
patch, as it doesn't need to be there.  However, the rest of the patch fixes
this problem with or without the change to app_meetme.

The key difference between what happens before and after this patch is the
effect of the END_OF_Q control frame.  After END_OF_Q is hit in ast_read(),
ast_read() will return NULL.  With the ast_check_hangup() removed, app_meetme
sees this which causes it to exit as intended.  Checking ast_check_hangup()
caused app_meetme to exit earlier in the process, and the target of the
redirect saw the condition where ast_read() returned NULL.

Removing ast_check_hangup() works around the issue in app_meetme, but doesn't
solve the issue if another application did the same thing.  There are also
other edge cases where if an application finishes at the same time that a
redirect happens, the target of the redirect will think that the channel hung
up.  So, I made some changes in pbx.c to resolve it at a deeper level.  There
are already places that unset the SOFTHANGUP_ASYNCGOTO flag in an attempt to
abort the hangup process.  My patch extends this to remove the END_OF_Q frame
from the channel's read queue, making the "abort hangup" more complete.  This
same technique was used in every place where a softhangup flag was cleared.

(closes issue #18585)
Reported by: oej
Tested by: oej, wedhorn, russell

Review: https://reviewboard.asterisk.org/r/1082/

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

apps/app_meetme.c
include/asterisk/channel.h
main/channel.c
main/pbx.c
res/res_features.c

index 9f6d7d77f3f090d51bdde66d08613796d55d396d..af0c70638299475b79996041e397491b46d687bd 100644 (file)
@@ -2117,10 +2117,6 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c
                                break;
                        }
 
-                       /* Perform an extra hangup check just in case */
-                       if (ast_check_hangup(chan))
-                               break;
-
                        c = ast_waitfor_nandfds(&chan, 1, &fd, nfds, NULL, &outfd, &ms);
 
                        if (c) {
index 848682576680051e0a13dd8c81715b3218fc829f..66368a0762f5610c1a1dcd28bfcfd007455651b5 100644 (file)
@@ -645,6 +645,15 @@ enum {
         * instead of actually hanging up.
         */
        AST_SOFTHANGUP_UNBRIDGE =  (1 << 6),
+
+
+       /*!
+        * \brief All softhangup flags.
+        *
+        * This can be used as an argument to ast_channel_softhangup_clear
+        * to clear all softhangup flags from a channel.
+        */
+       AST_SOFTHANGUP_ALL =       (0xFFFFFFFF)
 };
 
 
@@ -834,6 +843,20 @@ int ast_softhangup(struct ast_channel *chan, int cause);
  * \param reason an AST_SOFTHANGUP_* reason code */
 int ast_softhangup_nolock(struct ast_channel *chan, int cause);
 
+/*!
+ * \brief Clear a set of softhangup flags from a channel
+ *
+ * Never clear a softhangup flag from a channel directly.  Instead,
+ * use this function.  This ensures that all aspects of the softhangup
+ * process are aborted.
+ *
+ * \param chan the channel to clear the flag on
+ * \param flag the flag or flags to clear
+ *
+ * \return Nothing.
+ */
+void ast_channel_clear_softhangup(struct ast_channel *chan, int flag);
+
 /*! \brief Check to see if a channel is needing hang up 
  * \param chan channel on which to check for hang up
  * This function determines if the channel is being requested to be hung up.
index d92b3c26f41b6d8f16d087f4f05f7ed2c9c3eca5..8ac513d4654b61b5b4a96140b7403b473c053634 100644 (file)
@@ -1571,6 +1571,31 @@ struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const
        return datastore;
 }
 
+void ast_channel_clear_softhangup(struct ast_channel *chan, int flag)
+{
+       ast_channel_lock(chan);
+
+       chan->_softhangup &= ~flag;
+
+       if (!chan->_softhangup) {
+               struct ast_frame *fr;
+
+               /* If we have completely cleared the softhangup flag,
+                * then we need to fully abort the hangup process.  This requires
+                * pulling the END_OF_Q frame out of the channel frame queue if it
+                * still happens to be there. */
+
+               fr = AST_LIST_LAST(&chan->readq);
+               if (fr && fr->frametype == AST_FRAME_CONTROL &&
+                               fr->subclass == AST_CONTROL_END_OF_Q) {
+                       AST_LIST_REMOVE(&chan->readq, fr, frame_list);
+                       ast_frfree(fr);
+               }
+       }
+
+       ast_channel_unlock(chan);
+}
+
 /*! \brief Softly hangup a channel, don't lock */
 int ast_softhangup_nolock(struct ast_channel *chan, int cause)
 {
@@ -4598,10 +4623,10 @@ static enum ast_bridge_result ast_generic_bridge(struct ast_channel *c0, struct
                                ast_jb_get_and_deliver(c0, c1);
                        if ((c0->_softhangup | c1->_softhangup) & AST_SOFTHANGUP_UNBRIDGE) {/* Bit operators are intentional. */
                                if (c0->_softhangup & AST_SOFTHANGUP_UNBRIDGE) {
-                                       c0->_softhangup &= ~AST_SOFTHANGUP_UNBRIDGE;
+                                       ast_channel_clear_softhangup(c0, AST_SOFTHANGUP_UNBRIDGE);
                                }
                                if (c1->_softhangup & AST_SOFTHANGUP_UNBRIDGE) {
-                                       c1->_softhangup &= ~AST_SOFTHANGUP_UNBRIDGE;
+                                       ast_channel_clear_softhangup(c1, AST_SOFTHANGUP_UNBRIDGE);
                                }
                                c0->_bridge = c1;
                                c1->_bridge = c0;
@@ -4844,10 +4869,10 @@ enum ast_bridge_result ast_channel_bridge(struct ast_channel *c0, struct ast_cha
 
                if ((c0->_softhangup | c1->_softhangup) & AST_SOFTHANGUP_UNBRIDGE) {/* Bit operators are intentional. */
                        if (c0->_softhangup & AST_SOFTHANGUP_UNBRIDGE) {
-                               c0->_softhangup &= ~AST_SOFTHANGUP_UNBRIDGE;
+                               ast_channel_clear_softhangup(c0, AST_SOFTHANGUP_UNBRIDGE);
                        }
                        if (c1->_softhangup & AST_SOFTHANGUP_UNBRIDGE) {
-                               c1->_softhangup &= ~AST_SOFTHANGUP_UNBRIDGE;
+                               ast_channel_clear_softhangup(c1, AST_SOFTHANGUP_UNBRIDGE);
                        }
                        c0->_bridge = c1;
                        c1->_bridge = c0;
index 491c8a9329cc9eeb1d16d8f9fdd542b9b44ff2c5..56135c845d64d39c8f17dc8db44b80f9e587189c 100644 (file)
@@ -2383,7 +2383,7 @@ static int collect_digits(struct ast_channel *c, int waittime, char *buf, int bu
                   keep reading digits until we can't possibly get a right answer anymore.  */
                digit = ast_waitfordigit(c, waittime * 1000);
                if (c->_softhangup & AST_SOFTHANGUP_ASYNCGOTO) {
-                       c->_softhangup &= ~AST_SOFTHANGUP_ASYNCGOTO;
+                       ast_channel_clear_softhangup(c, AST_SOFTHANGUP_ASYNCGOTO);
                } else {
                        if (!digit)     /* No entry */
                                break;
@@ -2474,7 +2474,7 @@ static int __ast_pbx_run(struct ast_channel *c)
                                if (option_verbose > 1)
                                        ast_verbose( VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
                                if (c->_softhangup & AST_SOFTHANGUP_ASYNCGOTO) {
-                                       c->_softhangup &= ~AST_SOFTHANGUP_ASYNCGOTO;
+                                       ast_channel_clear_softhangup(c, AST_SOFTHANGUP_ASYNCGOTO);
                                } else if (c->_softhangup & AST_SOFTHANGUP_TIMEOUT) {
                                        /* atimeout, nothing bad */
                                } else {
@@ -2485,12 +2485,12 @@ static int __ast_pbx_run(struct ast_channel *c)
                                }
                        }
                        if (c->_softhangup & AST_SOFTHANGUP_ASYNCGOTO) {
-                               c->_softhangup &= ~AST_SOFTHANGUP_ASYNCGOTO;
+                               ast_channel_clear_softhangup(c, AST_SOFTHANGUP_ASYNCGOTO);
                        } else if (c->_softhangup & AST_SOFTHANGUP_TIMEOUT && ast_exists_extension(c,c->context,"T",1,c->cid.cid_num)) {
                                set_ext_pri(c, "T", 0); /* 0 will become 1 with the c->priority++; at the end */
                                /* If the AbsoluteTimeout is not reset to 0, we'll get an infinite loop */
                                c->whentohangup = 0;
-                               c->_softhangup &= ~AST_SOFTHANGUP_TIMEOUT;
+                               ast_channel_clear_softhangup(c, AST_SOFTHANGUP_ASYNCGOTO);
                        } else if (c->_softhangup) {
                                if (option_debug)
                                        ast_log(LOG_DEBUG, "Extension %s, priority %d returned normally even though call was hung up\n",
@@ -2522,7 +2522,7 @@ static int __ast_pbx_run(struct ast_channel *c)
                        }
                } else if (c->_softhangup & AST_SOFTHANGUP_TIMEOUT) {
                        /* If we get this far with AST_SOFTHANGUP_TIMEOUT, then we know that the "T" extension is next. */
-                       c->_softhangup &= ~AST_SOFTHANGUP_TIMEOUT;
+                       ast_channel_clear_softhangup(c, AST_SOFTHANGUP_TIMEOUT);
                } else {        /* keypress received, get more digits for a full extension */
                        int waittime = 0;
                        if (digit)
index 54744be51a154414bbd4ee688c52d50ce4c5a8eb..fae659aba7a07ae94e722f303471e13b2d46b112 100644 (file)
@@ -419,6 +419,7 @@ static void check_goto_on_transfer(struct ast_channel *chan)
        xferchan->_state = AST_STATE_UP;
        ast_clear_flag(xferchan, AST_FLAGS_ALL);        
        xferchan->_softhangup = 0;
+       ast_channel_clear_softhangup(xferchan, AST_SOFTHANGUP_ALL);
        if ((f = ast_read(xferchan))) {
                ast_frfree(f);
                f = NULL;