]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Bridges: Fix feature interruption/unintended kick caused by external actions
authorJonathan Rose <jrose@digium.com>
Wed, 13 Aug 2014 15:21:07 +0000 (15:21 +0000)
committerJonathan Rose <jrose@digium.com>
Wed, 13 Aug 2014 15:21:07 +0000 (15:21 +0000)
If a manager or CLI user attached a mixmonitor to a call running a dynamic
bridge feature while in a bridge, the feature would be interrupted and the
channel would be forcibly kicked out of the bridge (usually ending the call
during a simple 1 to 1 call). This would also occur during any similar action
that could set the unbridge soft hangup flag, so the fix for this was to
remove unbridge from the soft hangup flags and make it a separate thing all
together.

ASTERISK-24027 #close
Reported by: mjordan
Review: https://reviewboard.asterisk.org/r/3900/

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

apps/app_chanspy.c
apps/app_mixmonitor.c
apps/app_stack.c
include/asterisk/channel.h
main/bridge_after.c
main/bridge_channel.c
main/channel.c
main/channel_internal_api.c
main/framehook.c
main/pbx.c

index 028c258c8e56a84c9b0cd40e119c9df00a16a7fd..1d8fd4c8ae3dccfda2190cb6e016b48f1bc1e4bf 100644 (file)
@@ -504,7 +504,7 @@ static int start_spying(struct ast_autochan *autochan, const char *spychan_name,
        if (!res) {
                ast_channel_lock(autochan->chan);
                if (ast_channel_is_bridged(autochan->chan)) {
-                       ast_softhangup_nolock(autochan->chan, AST_SOFTHANGUP_UNBRIDGE);
+                       ast_channel_set_unbridged_nolock(autochan->chan, 1);
                }
                ast_channel_unlock(autochan->chan);
        }
index c9e09301814b1a2ce8b5ca07e1276f7aceb8c626..86b424b58bbbad5ddc46faffcad46443ed37c322 100644 (file)
@@ -421,7 +421,7 @@ static int startmon(struct ast_channel *chan, struct ast_audiohook *audiohook)
        if (!res) {
                ast_channel_lock(chan);
                if (ast_channel_is_bridged(chan)) {
-                       ast_softhangup_nolock(chan, AST_SOFTHANGUP_UNBRIDGE);
+                       ast_channel_set_unbridged_nolock(chan, 1);
                }
                ast_channel_unlock(chan);
        }
index 2f89b35597b4ae347bb42fb03c65e6b2fed122c6..0f6f7a6bf37b0e69384d5db48bf09e9ab51ea0a4 100644 (file)
@@ -976,10 +976,9 @@ static int gosub_run(struct ast_channel *chan, const char *sub_args, int ignore_
 
        /* Save non-hangup softhangup flags. */
        saved_hangup_flags = ast_channel_softhangup_internal_flag(chan)
-               & (AST_SOFTHANGUP_ASYNCGOTO | AST_SOFTHANGUP_UNBRIDGE);
+               & AST_SOFTHANGUP_ASYNCGOTO;
        if (saved_hangup_flags) {
-               ast_channel_clear_softhangup(chan,
-                       AST_SOFTHANGUP_ASYNCGOTO | AST_SOFTHANGUP_UNBRIDGE);
+               ast_channel_clear_softhangup(chan, AST_SOFTHANGUP_ASYNCGOTO);
        }
 
        /* Save autoloop flag */
@@ -1028,10 +1027,6 @@ static int gosub_run(struct ast_channel *chan, const char *sub_args, int ignore_
                 */
                do {
                        /* Check for hangup. */
-                       if (ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_UNBRIDGE) {
-                               saved_hangup_flags |= AST_SOFTHANGUP_UNBRIDGE;
-                               ast_channel_clear_softhangup(chan, AST_SOFTHANGUP_UNBRIDGE);
-                       }
                        if (ast_check_hangup(chan)) {
                                if (ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_ASYNCGOTO) {
                                        ast_log(LOG_ERROR, "%s An async goto just messed up our execution location.\n",
index 41c225353e5d9bc61efa9297e3dbcf12e43c7999..e2d6b7323433c1a2e23105d21bcd79541f01a356 100644 (file)
@@ -1048,11 +1048,6 @@ enum {
         * needed.
         */
        AST_SOFTHANGUP_EXPLICIT =  (1 << 5),
-       /*!
-        * Used to request that the bridge core re-evaluate the current
-        * bridging technology in use by the bridge this channel is in.
-        */
-       AST_SOFTHANGUP_UNBRIDGE =  (1 << 6),
        /*!
         * Used to indicate that the channel is currently executing hangup
         * logic in the dialplan. The channel has been hungup when this is
@@ -1535,6 +1530,40 @@ int ast_check_hangup(struct ast_channel *chan);
 
 int ast_check_hangup_locked(struct ast_channel *chan);
 
+/*! \brief This function will check if the bridge needs to be re-evaluated due to
+ *         external changes.
+ *
+ *  \param chan Channel on which to check the unbridge_eval flag
+ *
+ *  \return Returns 0 if the flag is down or 1 if the flag is up.
+ */
+int ast_channel_unbridged(struct ast_channel *chan);
+
+/*! \brief ast_channel_unbridged variant. Use this if the channel
+ *         is already locked prior to calling.
+ *
+ *  \param chan Channel on which to check the unbridge flag
+ *
+ *  \return Returns 0 if the flag is down or 1 if the flag is up.
+ */
+int ast_channel_unbridged_nolock(struct ast_channel *chan);
+
+/*! \brief Sets the unbridged flag and queues a NULL frame on the channel to trigger
+ *         a check by bridge_channel_wait
+ *
+ *  \param chan Which channel is having its unbridged value set
+ *  \param value What the unbridge value is being set to
+ */
+void ast_channel_set_unbridged(struct ast_channel *chan, int value);
+
+/*! \brief Variant of ast_channel_set_unbridged. Use this if the channel
+ *         is already locked prior to calling.
+ *
+ *  \param chan Which channel is having its unbridged value set
+ *  \param value What the unbridge value is being set to
+ */
+void ast_channel_set_unbridged_nolock(struct ast_channel *chan, int value);
+
 /*!
  * \brief Lock the given channel, then request softhangup on the channel with the given causecode
  * \param chan channel on which to hang up
index fbe4e605a53873e27833a94cc862a9edaafaf206..a21cbf58ea60093e93ddb1d6c72e3edc25018500 100644 (file)
@@ -452,9 +452,9 @@ int ast_bridge_setup_after_goto(struct ast_channel *chan)
        int goto_failed = -1;
 
        /* We are going to be leaving the bridging system now;
-        * clear any pending UNBRIDGE flags
+        * clear any pending unbridge flags
         */
-       ast_channel_clear_softhangup(chan, AST_SOFTHANGUP_UNBRIDGE);
+       ast_channel_set_unbridged(chan, 0);
 
        /* Determine if we are going to setup a dialplan location and where. */
        if (ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_ASYNCGOTO) {
index d24409f2e3d750b3b14d9947cc4e9671a6c69ea2..badb6b2e1738c493c51add0b7451153e34eea52d 100644 (file)
@@ -2269,8 +2269,8 @@ static void bridge_channel_wait(struct ast_bridge_channel *bridge_channel)
                ms = bridge_channel_next_interval(bridge_channel);
                chan = ast_waitfor_nandfds(&bridge_channel->chan, 1,
                        &bridge_channel->alert_pipe[0], 1, NULL, &outfd, &ms);
-               if (ast_channel_softhangup_internal_flag(bridge_channel->chan) & AST_SOFTHANGUP_UNBRIDGE) {
-                       ast_channel_clear_softhangup(bridge_channel->chan, AST_SOFTHANGUP_UNBRIDGE);
+               if (ast_channel_unbridged(bridge_channel->chan)) {
+                       ast_channel_set_unbridged(bridge_channel->chan, 0);
                        ast_bridge_channel_lock_bridge(bridge_channel);
                        bridge_channel->bridge->reconfigured = 1;
                        bridge_reconfigured(bridge_channel->bridge, 0);
index bd968c553a1e11047218dd5607034bd2768eafbb..bd213cdb93e0cbf6bb29acd5b93491f6628f7e3d 100644 (file)
@@ -10182,11 +10182,11 @@ int ast_channel_is_bridged(const struct ast_channel *chan)
 int ast_channel_is_leaving_bridge(struct ast_channel *chan)
 {
        int hangup_flags = ast_channel_softhangup_internal_flag(chan);
-       int hangup_test = hangup_flags & (AST_SOFTHANGUP_ASYNCGOTO | AST_SOFTHANGUP_UNBRIDGE);
+       int hangup_test = hangup_flags & AST_SOFTHANGUP_ASYNCGOTO;
 
-       /* This function should only return true if either ASYNCGOTO
-        * or UNBRIDGE is set, or both flags are set. It should return
-        * false if any other flag is set.
+       /* This function should only return true if only the ASYNCGOTO
+        * is set. It should false if any other flag is set or if the
+        * ASYNCGOTO flag is not set.
         */
        return (hangup_test && (hangup_test == hangup_flags));
 }
@@ -10479,7 +10479,7 @@ void ast_channel_end_dtmf(struct ast_channel *chan, char digit, struct timeval s
        ast_channel_lock(chan);
        dead = ast_test_flag(ast_channel_flags(chan), AST_FLAG_ZOMBIE)
                || (ast_channel_softhangup_internal_flag(chan)
-                       & ~(AST_SOFTHANGUP_ASYNCGOTO | AST_SOFTHANGUP_UNBRIDGE));
+                       & ~AST_SOFTHANGUP_ASYNCGOTO);
        ast_channel_unlock(chan);
        if (dead) {
                /* Channel is a zombie or a real hangup. */
index c7924b0ee79802073c389f5ae182ae2a3eb630ae..9409556a9776d6e44916a0a8f186cd32670bab66 100644 (file)
@@ -173,6 +173,8 @@ struct ast_channel {
                                                         *   See \arg \ref AstFileDesc */
        int softhangup;                         /*!< Whether or not we have been hung up...  Do not set this value
                                                         *   directly, use ast_softhangup() */
+       int unbridged;              /*!< If non-zero, the bridge core needs to re-evaluate the current
+                                        bridging technology which is in use by this channel's bridge. */
        int fdno;                                       /*!< Which fd had an event detected on */
        int streamid;                                   /*!< For streaming playback, the schedule ID */
        int vstreamid;                                  /*!< For streaming video playback, the schedule ID */
@@ -377,7 +379,6 @@ int ast_channel_data_add_structure(struct ast_data *tree,
        ast_data_add_bool(data_softhangup, "timeout", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_TIMEOUT);
        ast_data_add_bool(data_softhangup, "appunload", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_APPUNLOAD);
        ast_data_add_bool(data_softhangup, "explicit", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_EXPLICIT);
-       ast_data_add_bool(data_softhangup, "unbridge", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_UNBRIDGE);
 
        /* channel flags */
        data_flags = ast_data_add_node(tree, "flags");
@@ -1115,6 +1116,33 @@ void ast_channel_softhangup_internal_flag_clear(struct ast_channel *chan, int va
        chan ->softhangup &= ~value;
 }
 
+int ast_channel_unbridged_nolock(struct ast_channel *chan)
+{
+       return chan->unbridged;
+}
+
+int ast_channel_unbridged(struct ast_channel *chan)
+{
+       int res;
+       ast_channel_lock(chan);
+       res = ast_channel_unbridged_nolock(chan);
+       ast_channel_unlock(chan);
+       return res;
+}
+
+void ast_channel_set_unbridged_nolock(struct ast_channel *chan, int value)
+{
+       chan->unbridged = value;
+       ast_queue_frame(chan, &ast_null_frame);
+}
+
+void ast_channel_set_unbridged(struct ast_channel *chan, int value)
+{
+       ast_channel_lock(chan);
+       ast_channel_set_unbridged_nolock(chan, value);
+       ast_channel_unlock(chan);
+}
+
 void ast_channel_callid_cleanup(struct ast_channel *chan)
 {
        if (chan->callid) {
index 0d42b49906b2a65722c8627834bb847e4e69c5c4..ec4e1695f9b69a360f2ca04731e4c6f5897822ad 100644 (file)
@@ -170,7 +170,7 @@ int ast_framehook_attach(struct ast_channel *chan, struct ast_framehook_interfac
        }
 
        if (ast_channel_is_bridged(chan)) {
-               ast_softhangup_nolock(chan, AST_SOFTHANGUP_UNBRIDGE);
+               ast_channel_set_unbridged_nolock(chan, 1);
        }
 
        return framehook->id;
@@ -199,7 +199,7 @@ int ast_framehook_detach(struct ast_channel *chan, int id)
        AST_LIST_TRAVERSE_SAFE_END;
 
        if (ast_channel_is_bridged(chan)) {
-               ast_softhangup_nolock(chan, AST_SOFTHANGUP_UNBRIDGE);
+               ast_channel_set_unbridged_nolock(chan, 1);
        }
 
        return res;
index 69a1f1a081094aaf5dd4125a876143dc8c1194ef..b1f8ad6ca0e382f08ccdbde114baddf1f32682b8 100644 (file)
@@ -6311,11 +6311,6 @@ static enum ast_pbx_result __ast_pbx_run(struct ast_channel *c,
                        S_COR(ast_channel_caller(c)->id.number.valid, ast_channel_caller(c)->id.number.str, NULL),
                        &found, 1))) {
 
-                       /* Defensively clear the UNBRIDGE flag in case it leaked
-                        * out of the bridging framework. UNBRIDE never implies
-                        * that a channel is hung up.
-                        */
-                       ast_channel_clear_softhangup(c, AST_SOFTHANGUP_UNBRIDGE);
                        if (!ast_check_hangup(c)) {
                                ast_channel_priority_set(c, ast_channel_priority(c) + 1);
                                continue;