[asterisk-commits] rmudgett: branch 12 r418225 - in /branches/12: include/asterisk/ main/ res/ r...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 9 11:19:02 CDT 2014


Author: rmudgett
Date: Wed Jul  9 11:18:57 2014
New Revision: 418225

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=418225
Log:
ARI: Make mixing bridges propagate linkedids and accountcodes.

* Create a Stasis bridge sub-class to propagate linkedids and
accountcodes.

* Fixed the basic bridge sub-class to update peeraccount codes when the
number of channels in the bridge drops back down to two parties.

* Refactored ast_bridge_channel_update_accountcodes() to handle channels
joining/leaving the bridge.

* Fixed the basic bridge sub-class to not call the base bridge class pull
method twice.

AFS-105 #close
ASTERISK-23852 #close
Reported by: Richard Mudgett

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

Added:
    branches/12/res/stasis/stasis_bridge.c
      - copied unchanged from r418210, team/rmudgett/stasis_linkedids/res/stasis/stasis_bridge.c
    branches/12/res/stasis/stasis_bridge.h
      - copied unchanged from r418210, team/rmudgett/stasis_linkedids/res/stasis/stasis_bridge.h
Modified:
    branches/12/include/asterisk/bridge_channel.h
    branches/12/main/bridge_basic.c
    branches/12/main/bridge_channel.c
    branches/12/res/res_stasis.c

Modified: branches/12/include/asterisk/bridge_channel.h
URL: http://svnview.digium.com/svn/asterisk/branches/12/include/asterisk/bridge_channel.h?view=diff&rev=418225&r1=418224&r2=418225
==============================================================================
--- branches/12/include/asterisk/bridge_channel.h (original)
+++ branches/12/include/asterisk/bridge_channel.h Wed Jul  9 11:18:57 2014
@@ -326,14 +326,15 @@
  * \param bridge_channel The channel joining the bridge
  * \param swap The channel being swapped out of the bridge. May be NULL.
  *
- * \note The bridge must be locked prior to calling this function. This should be called
- * during a \ref bridge_channel_internal_push operation, typically by a sub-class of a bridge
+ * \note The bridge must be locked prior to calling this function.
+ * \note This should be called during a \ref bridge_channel_internal_push
+ * operation, typically by a sub-class of a bridge.
  */
 void ast_bridge_channel_update_linkedids(struct ast_bridge_channel *bridge_channel, struct ast_bridge_channel *swap);
 
 /*!
  * \internal
- * \brief Update the accountcodes for a channel entering a bridge
+ * \brief Update the accountcodes for channels joining/leaving a bridge
  * \since 12.0.0
  *
  * This function updates the accountcode and peeraccount on channels in two-party
@@ -341,13 +342,17 @@
  * however accountcode propagation will still occur if the channel joining has an
  * accountcode.
  *
- * \param bridge_channel The channel joining the bridge
- * \param swap The channel being swapped out of the bridge. May be NULL.
- *
- * \note The bridge must be locked prior to calling this function. This should be called
- * during a \ref bridge_channel_internal_push operation, typically by a sub-class of a bridge
- */
-void ast_bridge_channel_update_accountcodes(struct ast_bridge_channel *bridge_channel, struct ast_bridge_channel *swap);
+ * \param joining The channel joining the bridge.  May be NULL.
+ * \param leaving The channel leaving or being swapped out of the bridge. May be NULL.
+ *
+ * \note The joining and leaving parameters cannot both be NULL.
+ *
+ * \note The bridge must be locked prior to calling this function.
+ * \note This should be called during a \ref bridge_channel_internal_push
+ * or \ref bridge_channel_internal_pull operation, typically by a
+ * sub-class of a bridge.
+ */
+void ast_bridge_channel_update_accountcodes(struct ast_bridge_channel *joining, struct ast_bridge_channel *leaving);
 
 /*!
  * \brief Write a frame to the specified bridge_channel.

Modified: branches/12/main/bridge_basic.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/main/bridge_basic.c?view=diff&rev=418225&r1=418224&r2=418225
==============================================================================
--- branches/12/main/bridge_basic.c (original)
+++ branches/12/main/bridge_basic.c Wed Jul  9 11:18:57 2014
@@ -665,20 +665,22 @@
 		return -1;
 	}
 
+	return 0;
+}
+
+static int bridge_basic_push(struct ast_bridge *self, struct ast_bridge_channel *bridge_channel, struct ast_bridge_channel *swap)
+{
+	struct bridge_basic_personality *personality = self->personality;
+
+	ast_assert(personality != NULL);
+
+	if (personality->details[personality->current].v_table->push
+		&& personality->details[personality->current].v_table->push(self, bridge_channel, swap)) {
+		return -1;
+	}
+
+	ast_bridge_channel_update_linkedids(bridge_channel, swap);
 	ast_bridge_channel_update_accountcodes(bridge_channel, swap);
-	ast_bridge_channel_update_linkedids(bridge_channel, swap);
-	return 0;
-}
-
-static int bridge_basic_push(struct ast_bridge *self, struct ast_bridge_channel *bridge_channel, struct ast_bridge_channel *swap)
-{
-	struct bridge_basic_personality *personality = self->personality;
-
-	ast_assert(personality != NULL);
-
-	if (personality->details[personality->current].v_table->push(self, bridge_channel, swap)) {
-		return -1;
-	}
 
 	return ast_bridge_base_v_table.push(self, bridge_channel, swap);
 }
@@ -692,6 +694,8 @@
 	if (personality->details[personality->current].v_table->pull) {
 		personality->details[personality->current].v_table->pull(self, bridge_channel);
 	}
+
+	ast_bridge_channel_update_accountcodes(NULL, bridge_channel);
 
 	ast_bridge_base_v_table.pull(self, bridge_channel);
 }
@@ -3315,11 +3319,16 @@
 	ast_bridge_basic_v_table.pull = bridge_basic_pull;
 	ast_bridge_basic_v_table.destroy = bridge_basic_destroy;
 
-	personality_normal_v_table = ast_bridge_base_v_table;
+	/*
+	 * Personality vtables don't have the same rules as
+	 * normal bridge vtables.  These vtable functions are
+	 * used as alterations to the ast_bridge_basic_v_table
+	 * method functionality and are checked for NULL before
+	 * calling.
+	 */
 	personality_normal_v_table.name = "normal";
 	personality_normal_v_table.push = bridge_personality_normal_push;
 
-	personality_atxfer_v_table = ast_bridge_base_v_table;
 	personality_atxfer_v_table.name = "attended transfer";
 	personality_atxfer_v_table.push = bridge_personality_atxfer_push;
 	personality_atxfer_v_table.pull = bridge_personality_atxfer_pull;

Modified: branches/12/main/bridge_channel.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/main/bridge_channel.c?view=diff&rev=418225&r1=418224&r2=418225
==============================================================================
--- branches/12/main/bridge_channel.c (original)
+++ branches/12/main/bridge_channel.c Wed Jul  9 11:18:57 2014
@@ -357,7 +357,7 @@
 
 void ast_bridge_channel_update_linkedids(struct ast_bridge_channel *bridge_channel, struct ast_bridge_channel *swap)
 {
-	struct ast_bridge_channel *other = NULL;
+	struct ast_bridge_channel *other;
 	struct ast_bridge *bridge = bridge_channel->bridge;
 	struct ast_channel *oldest_linkedid_chan = bridge_channel->chan;
 
@@ -370,65 +370,212 @@
 	}
 
 	ast_channel_lock(bridge_channel->chan);
-	ast_channel_internal_copy_linkedid(bridge_channel->chan,
-		oldest_linkedid_chan);
+	ast_channel_internal_copy_linkedid(bridge_channel->chan, oldest_linkedid_chan);
 	ast_channel_unlock(bridge_channel->chan);
 	AST_LIST_TRAVERSE(&bridge->channels, other, entry) {
 		if (other == swap) {
 			continue;
 		}
 		ast_channel_lock(other->chan);
-		ast_channel_internal_copy_linkedid(other->chan,
-			oldest_linkedid_chan);
+		ast_channel_internal_copy_linkedid(other->chan, oldest_linkedid_chan);
 		ast_channel_unlock(other->chan);
 	}
 }
 
-void ast_bridge_channel_update_accountcodes(struct ast_bridge_channel *bridge_channel, struct ast_bridge_channel *swap)
-{
-	struct ast_bridge *bridge = bridge_channel->bridge;
-	struct ast_bridge_channel *other = NULL;
+/*!
+ * \internal
+ * \brief Set dest's empty peeraccount with the src's non-empty accountcode.
+ * \since 12.5.0
+ *
+ * \param dest Channel to update peeraccount.
+ * \param src Channel to get accountcode from.
+ *
+ * \note Both channels are already locked.
+ *
+ * \return Nothing
+ */
+static void channel_fill_empty_peeraccount(struct ast_channel *dest, struct ast_channel *src)
+{
+	if (ast_strlen_zero(ast_channel_peeraccount(dest))
+		&& !ast_strlen_zero(ast_channel_accountcode(src))) {
+		ast_debug(1, "Setting channel %s peeraccount with channel %s accountcode '%s'.\n",
+			ast_channel_name(dest),
+			ast_channel_name(src), ast_channel_accountcode(src));
+		ast_channel_peeraccount_set(dest, ast_channel_accountcode(src));
+	}
+}
+
+/*!
+ * \internal
+ * \brief Set dest's empty accountcode with the src's non-empty peeraccount.
+ * \since 12.5.0
+ *
+ * \param dest Channel to update accountcode.
+ * \param src Channel to get peeraccount from.
+ *
+ * \note Both channels are already locked.
+ *
+ * \return Nothing
+ */
+static void channel_fill_empty_accountcode(struct ast_channel *dest, struct ast_channel *src)
+{
+	if (ast_strlen_zero(ast_channel_accountcode(dest))
+		&& !ast_strlen_zero(ast_channel_peeraccount(src))) {
+		ast_debug(1, "Setting channel %s accountcode with channel %s peeraccount '%s'.\n",
+			ast_channel_name(dest),
+			ast_channel_name(src), ast_channel_peeraccount(src));
+		ast_channel_accountcode_set(dest, ast_channel_peeraccount(src));
+	}
+}
+
+/*!
+ * \internal
+ * \brief Set empty peeraccount and accountcode in a channel from the other channel.
+ * \since 12.5.0
+ *
+ * \param c0 First bridge channel to update.
+ * \param c1 Second bridge channel to update.
+ *
+ * \note Both channels are already locked.
+ *
+ * \return Nothing
+ */
+static void channel_set_empty_accountcodes(struct ast_channel *c0, struct ast_channel *c1)
+{
+	/* Set empty peeraccount from the other channel's accountcode. */
+	channel_fill_empty_peeraccount(c0, c1);
+	channel_fill_empty_peeraccount(c1, c0);
+
+	/* Set empty accountcode from the other channel's peeraccount. */
+	channel_fill_empty_accountcode(c0, c1);
+	channel_fill_empty_accountcode(c1, c0);
+}
+
+/*!
+ * \internal
+ * \brief Update dest's peeraccount with the src's different accountcode.
+ * \since 12.5.0
+ *
+ * \param dest Channel to update peeraccount.
+ * \param src Channel to get accountcode from.
+ *
+ * \note Both channels are already locked.
+ *
+ * \return Nothing
+ */
+static void channel_update_peeraccount(struct ast_channel *dest, struct ast_channel *src)
+{
+	if (strcmp(ast_channel_accountcode(src), ast_channel_peeraccount(dest))) {
+		ast_debug(1, "Changing channel %s peeraccount '%s' to match channel %s accountcode '%s'.\n",
+			ast_channel_name(dest), ast_channel_peeraccount(dest),
+			ast_channel_name(src), ast_channel_accountcode(src));
+		ast_channel_peeraccount_set(dest, ast_channel_accountcode(src));
+	}
+}
+
+/*!
+ * \internal
+ * \brief Update peeraccounts to match the other channel's accountcode.
+ * \since 12.5.0
+ *
+ * \param c0 First channel to update.
+ * \param c1 Second channel to update.
+ *
+ * \note Both channels are already locked.
+ *
+ * \return Nothing
+ */
+static void channel_update_peeraccounts(struct ast_channel *c0, struct ast_channel *c1)
+{
+	channel_update_peeraccount(c0, c1);
+	channel_update_peeraccount(c1, c0);
+}
+
+/*!
+ * \internal
+ * \brief Update channel accountcodes because a channel is joining a bridge.
+ * \since 12.5.0
+ *
+ * \param joining Channel joining the bridge.
+ * \param swap Channel being replaced by the joining channel.  May be NULL.
+ *
+ * \note The bridge must be locked prior to calling this function.
+ *
+ * \return Nothing
+ */
+static void bridge_channel_update_accountcodes_joining(struct ast_bridge_channel *joining, struct ast_bridge_channel *swap)
+{
+	struct ast_bridge *bridge = joining->bridge;
+	struct ast_bridge_channel *other;
+	unsigned int swap_in_bridge = 0;
+	unsigned int will_be_two_party;
+
+	/*
+	 * Only update the peeraccount to match if the joining channel
+	 * will make it a two party bridge.
+	 */
+	if (bridge->num_channels <= 2 && swap) {
+		AST_LIST_TRAVERSE(&bridge->channels, other, entry) {
+			if (other == swap) {
+				swap_in_bridge = 1;
+				break;
+			}
+		}
+	}
+	will_be_two_party = (1 == bridge->num_channels - swap_in_bridge);
 
 	AST_LIST_TRAVERSE(&bridge->channels, other, entry) {
 		if (other == swap) {
 			continue;
 		}
-		ast_channel_lock_both(bridge_channel->chan, other->chan);
-
-		if (!ast_strlen_zero(ast_channel_accountcode(bridge_channel->chan)) && ast_strlen_zero(ast_channel_peeraccount(other->chan))) {
-			ast_debug(1, "Setting peeraccount to %s for %s from data on channel %s\n",
-					ast_channel_accountcode(bridge_channel->chan), ast_channel_name(other->chan), ast_channel_name(bridge_channel->chan));
-			ast_channel_peeraccount_set(other->chan, ast_channel_accountcode(bridge_channel->chan));
-		}
-		if (!ast_strlen_zero(ast_channel_accountcode(other->chan)) && ast_strlen_zero(ast_channel_peeraccount(bridge_channel->chan))) {
-			ast_debug(1, "Setting peeraccount to %s for %s from data on channel %s\n",
-					ast_channel_accountcode(other->chan), ast_channel_name(bridge_channel->chan), ast_channel_name(other->chan));
-			ast_channel_peeraccount_set(bridge_channel->chan, ast_channel_accountcode(other->chan));
-		}
-		if (!ast_strlen_zero(ast_channel_peeraccount(bridge_channel->chan)) && ast_strlen_zero(ast_channel_accountcode(other->chan))) {
-			ast_debug(1, "Setting accountcode to %s for %s from data on channel %s\n",
-					ast_channel_peeraccount(bridge_channel->chan), ast_channel_name(other->chan), ast_channel_name(bridge_channel->chan));
-			ast_channel_accountcode_set(other->chan, ast_channel_peeraccount(bridge_channel->chan));
-		}
-		if (!ast_strlen_zero(ast_channel_peeraccount(other->chan)) && ast_strlen_zero(ast_channel_accountcode(bridge_channel->chan))) {
-			ast_debug(1, "Setting accountcode to %s for %s from data on channel %s\n",
-					ast_channel_peeraccount(other->chan), ast_channel_name(bridge_channel->chan), ast_channel_name(other->chan));
-			ast_channel_accountcode_set(bridge_channel->chan, ast_channel_peeraccount(other->chan));
-		}
-		if (bridge->num_channels == 2) {
-			if (strcmp(ast_channel_accountcode(bridge_channel->chan), ast_channel_peeraccount(other->chan))) {
-				ast_debug(1, "Changing peeraccount from %s to %s on %s to match channel %s\n",
-						ast_channel_peeraccount(other->chan), ast_channel_peeraccount(bridge_channel->chan), ast_channel_name(other->chan), ast_channel_name(bridge_channel->chan));
-				ast_channel_peeraccount_set(other->chan, ast_channel_accountcode(bridge_channel->chan));
-			}
-			if (strcmp(ast_channel_accountcode(other->chan), ast_channel_peeraccount(bridge_channel->chan))) {
-				ast_debug(1, "Changing peeraccount from %s to %s on %s to match channel %s\n",
-						ast_channel_peeraccount(bridge_channel->chan), ast_channel_peeraccount(other->chan), ast_channel_name(bridge_channel->chan), ast_channel_name(other->chan));
-				ast_channel_peeraccount_set(bridge_channel->chan, ast_channel_accountcode(other->chan));
-			}
-		}
-		ast_channel_unlock(bridge_channel->chan);
+		ast_assert(joining != other);
+		ast_channel_lock_both(joining->chan, other->chan);
+		channel_set_empty_accountcodes(joining->chan, other->chan);
+		if (will_be_two_party) {
+			channel_update_peeraccounts(joining->chan, other->chan);
+		}
+		ast_channel_unlock(joining->chan);
 		ast_channel_unlock(other->chan);
+	}
+}
+
+/*!
+ * \internal
+ * \brief Update channel peeraccount codes because a channel has left a bridge.
+ * \since 12.5.0
+ *
+ * \param leaving Channel leaving the bridge. (Has already been removed actually)
+ *
+ * \note The bridge must be locked prior to calling this function.
+ *
+ * \return Nothing
+ */
+static void bridge_channel_update_accountcodes_leaving(struct ast_bridge_channel *leaving)
+{
+	struct ast_bridge *bridge = leaving->bridge;
+	struct ast_bridge_channel *first;
+	struct ast_bridge_channel *second;
+
+	if (bridge->num_channels != 2 || bridge->dissolved) {
+		return;
+	}
+
+	first = AST_LIST_FIRST(&bridge->channels);
+	second = AST_LIST_LAST(&bridge->channels);
+	ast_assert(first && first != second);
+	ast_channel_lock_both(first->chan, second->chan);
+	channel_set_empty_accountcodes(first->chan, second->chan);
+	channel_update_peeraccounts(first->chan, second->chan);
+	ast_channel_unlock(second->chan);
+	ast_channel_unlock(first->chan);
+}
+
+void ast_bridge_channel_update_accountcodes(struct ast_bridge_channel *joining, struct ast_bridge_channel *leaving)
+{
+	if (joining) {
+		bridge_channel_update_accountcodes_joining(joining, leaving);
+	} else {
+		bridge_channel_update_accountcodes_leaving(leaving);
 	}
 }
 
@@ -1747,6 +1894,8 @@
 	}
 	--bridge->num_channels;
 	AST_LIST_REMOVE(&bridge->channels, bridge_channel, entry);
+
+	bridge_channel_dissolve_check(bridge_channel);
 	bridge->v_table->pull(bridge, bridge_channel);
 
 	ast_bridge_channel_clear_roles(bridge_channel);
@@ -1760,8 +1909,6 @@
 		ast_debug(2, "Channel %s will survive this bridge; clearing outgoing (dialed) flag\n", ast_channel_name(bridge_channel->chan));
 		ast_clear_flag(ast_channel_flags(bridge_channel->chan), AST_FLAG_OUTGOING);
 	}
-
-	bridge_channel_dissolve_check(bridge_channel);
 
 	bridge->reconfigured = 1;
 	ast_bridge_publish_leave(bridge, bridge_channel->chan);

Modified: branches/12/res/res_stasis.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_stasis.c?view=diff&rev=418225&r1=418224&r2=418225
==============================================================================
--- branches/12/res/res_stasis.c (original)
+++ branches/12/res/res_stasis.c Wed Jul  9 11:18:57 2014
@@ -66,6 +66,7 @@
 #include "asterisk/strings.h"
 #include "stasis/app.h"
 #include "stasis/control.h"
+#include "stasis/stasis_bridge.h"
 #include "asterisk/core_unreal.h"
 #include "asterisk/musiconhold.h"
 #include "asterisk/causes.h"
@@ -687,9 +688,7 @@
 		requested_type = ast_strip(requested_type);
 
 		if (!strcmp(requested_type, "mixing")) {
-			capabilities |= AST_BRIDGE_CAPABILITY_1TO1MIX |
-				AST_BRIDGE_CAPABILITY_MULTIMIX |
-				AST_BRIDGE_CAPABILITY_NATIVE;
+			capabilities |= STASIS_BRIDGE_MIXING_CAPABILITIES;
 			flags |= AST_BRIDGE_FLAG_SMART;
 		} else if (!strcmp(requested_type, "holding")) {
 			capabilities |= AST_BRIDGE_CAPABILITY_HOLDING;
@@ -699,11 +698,14 @@
 		}
 	}
 
-	if (!capabilities) {
+	if (!capabilities
+		/* Holding and mixing capabilities don't mix. */
+		|| ((capabilities & AST_BRIDGE_CAPABILITY_HOLDING)
+			&& (capabilities & (STASIS_BRIDGE_MIXING_CAPABILITIES)))) {
 		return NULL;
 	}
 
-	bridge = ast_bridge_base_new(capabilities, flags, "Stasis", name, id);
+	bridge = bridge_stasis_new(capabilities, flags, name, id);
 	if (bridge) {
 		if (!ao2_link(app_bridges, bridge)) {
 			ast_bridge_destroy(bridge, 0);
@@ -1493,6 +1495,8 @@
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
+	bridge_stasis_init();
+
 	stasis_app_register_event_sources();
 
 	return AST_MODULE_LOAD_SUCCESS;




More information about the asterisk-commits mailing list