diff --git a/apps/app_meetme.c b/apps/app_meetme.c index fcf0636702..8191df6eb4 100644 --- a/apps/app_meetme.c +++ b/apps/app_meetme.c @@ -2909,11 +2909,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) { diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h index 11fc9b67c1..eb5de85905 100644 --- a/include/asterisk/channel.h +++ b/include/asterisk/channel.h @@ -684,6 +684,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) }; @@ -1013,6 +1022,20 @@ int ast_softhangup(struct ast_channel *chan, int reason); */ int ast_softhangup_nolock(struct ast_channel *chan, int reason); +/*! + * \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. diff --git a/main/channel.c b/main/channel.c index d70c0ea7da..226ef3fdf9 100644 --- a/main/channel.c +++ b/main/channel.c @@ -1744,6 +1744,31 @@ void ast_poll_channel_del(struct ast_channel *chan0, struct ast_channel *chan1) return; } +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) { @@ -5187,10 +5212,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; @@ -5503,10 +5528,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; diff --git a/main/features.c b/main/features.c index e67c5fbd94..6e90b5ee76 100644 --- a/main/features.c +++ b/main/features.c @@ -553,7 +553,7 @@ static void check_goto_on_transfer(struct ast_channel *chan) ast_parseable_goto(xferchan, goto_on_transfer); 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; diff --git a/main/pbx.c b/main/pbx.c index 88935781f8..49ac156ca9 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -4253,7 +4253,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); 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; @@ -4324,14 +4324,14 @@ static enum ast_pbx_result __ast_pbx_run(struct ast_channel *c, 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 */ memset(&c->whentohangup, 0, sizeof(c->whentohangup)); - c->_softhangup &= ~AST_SOFTHANGUP_TIMEOUT; + ast_channel_clear_softhangup(c, AST_SOFTHANGUP_TIMEOUT); } else if (c->_softhangup & AST_SOFTHANGUP_TIMEOUT && ast_exists_extension(c, c->context, "e", 1, c->cid.cid_num)) { pbx_builtin_raise_exception(c, "ABSOLUTETIMEOUT"); /* If the AbsoluteTimeout is not reset to 0, we'll get an infinite loop */ memset(&c->whentohangup, 0, sizeof(c->whentohangup)); - c->_softhangup &= ~AST_SOFTHANGUP_TIMEOUT; + ast_channel_clear_softhangup(c, AST_SOFTHANGUP_TIMEOUT); } else if (c->_softhangup & AST_SOFTHANGUP_ASYNCGOTO) { - c->_softhangup &= ~AST_SOFTHANGUP_ASYNCGOTO; + ast_channel_clear_softhangup(c, AST_SOFTHANGUP_ASYNCGOTO); continue; } else if (ast_check_hangup(c)) { ast_debug(1, "Extension %s, priority %d returned normally even though call was hung up\n", @@ -4376,13 +4376,13 @@ static enum ast_pbx_result __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); continue; } else if (c->_softhangup & AST_SOFTHANGUP_TIMEOUT && ast_exists_extension(c, c->context, "T", 1, c->cid.cid_num)) { set_ext_pri(c, "T", 1); /* If the AbsoluteTimeout is not reset to 0, we'll get an infinite loop */ memset(&c->whentohangup, 0, sizeof(c->whentohangup)); - c->_softhangup &= ~AST_SOFTHANGUP_TIMEOUT; + ast_channel_clear_softhangup(c, AST_SOFTHANGUP_TIMEOUT); continue; } else { if (c->cdr) @@ -4420,7 +4420,7 @@ static enum ast_pbx_result __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)