[asterisk-commits] mmichelson: branch mmichelson/transfer_stasis r391427 - in /team/mmichelson/t...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jun 11 13:34:32 CDT 2013


Author: mmichelson
Date: Tue Jun 11 13:34:30 2013
New Revision: 391427

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=391427
Log:
Add publication of stasis messages for attended transfers.

There are a couple of spots that need cleaning up, but now all
eventualities of a native attended transfer result in an attended
transfer stasis message being published.


Modified:
    team/mmichelson/transfer_stasis/include/asterisk/stasis_bridging.h
    team/mmichelson/transfer_stasis/main/bridging.c
    team/mmichelson/transfer_stasis/main/stasis_bridging.c

Modified: team/mmichelson/transfer_stasis/include/asterisk/stasis_bridging.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/transfer_stasis/include/asterisk/stasis_bridging.h?view=diff&rev=391427&r1=391426&r2=391427
==============================================================================
--- team/mmichelson/transfer_stasis/include/asterisk/stasis_bridging.h (original)
+++ team/mmichelson/transfer_stasis/include/asterisk/stasis_bridging.h Tue Jun 11 13:34:30 2013
@@ -321,7 +321,7 @@
  * \param transferee The bridge between the transferer and transferees as well as the transferer channel from that bridge
  * \param target The bridge between the transferer and transfer targets as well as the transferer channel from that bridge
  */
-void ast_bridge_publish_attended_transfer_failure(int is_native, enum ast_transfer_result result,
+void ast_bridge_publish_attended_transfer_fail(int is_native, enum ast_transfer_result result,
 		struct ast_bridge_channel_pair *transferee, struct ast_bridge_channel_pair *target);
 
 /*!

Modified: team/mmichelson/transfer_stasis/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/transfer_stasis/main/bridging.c?view=diff&rev=391427&r1=391426&r2=391427
==============================================================================
--- team/mmichelson/transfer_stasis/main/bridging.c (original)
+++ team/mmichelson/transfer_stasis/main/bridging.c Tue Jun 11 13:34:30 2013
@@ -5602,6 +5602,84 @@
 	return AST_BRIDGE_TRANSFER_SUCCESS;
 }
 
+static void publish_attended_transfer_bridge_merge(struct ast_channel *to_transferee,
+		struct ast_bridge *to_transferee_bridge, struct ast_channel *to_transfer_target,
+		struct ast_bridge *to_target_bridge, struct ast_bridge *final_bridge)
+{
+	struct ast_bridge_channel_pair transferee = {
+		.channel = to_transferee,
+		.bridge = to_transferee_bridge,
+	};
+	struct ast_bridge_channel_pair target = {
+		.channel = to_transfer_target,
+		.bridge = to_target_bridge,
+	};
+
+	ast_bridge_publish_attended_transfer_bridge_merge(1, AST_BRIDGE_TRANSFER_SUCCESS,
+			&transferee, &target, final_bridge);
+}
+
+static void publish_attended_transfer_app(struct ast_channel *to_transferee,
+		struct ast_bridge *to_transferee_bridge, struct ast_channel *to_transfer_target,
+		struct ast_bridge *to_target_bridge, const char *app)
+{
+	struct ast_bridge_channel_pair transferee = {
+		.channel = to_transferee,
+		.bridge = to_transferee_bridge,
+	};
+	struct ast_bridge_channel_pair target = {
+		.channel = to_transfer_target,
+		.bridge = to_target_bridge,
+	};
+
+	ast_bridge_publish_attended_transfer_app(1, AST_BRIDGE_TRANSFER_SUCCESS,
+			&transferee, &target, app);
+}
+
+static void publish_attended_transfer_link(struct ast_channel *to_transferee,
+		struct ast_bridge *to_transferee_bridge, struct ast_channel *to_transfer_target,
+		struct ast_bridge *to_target_bridge, struct ast_channel *local_channel1,
+		struct ast_bridge *local_bridge1, struct ast_channel *local_channel2,
+		struct ast_bridge *local_bridge2)
+{
+	struct ast_bridge_channel_pair transferee = {
+		.channel = to_transferee,
+		.bridge = to_transferee_bridge,
+	};
+	struct ast_bridge_channel_pair target = {
+		.channel = to_transfer_target,
+		.bridge = to_target_bridge,
+	};
+	struct ast_bridge_channel_pair local1 = {
+		.channel = local_channel1,
+		.bridge = local_bridge1,
+	};
+	struct ast_bridge_channel_pair local2 = {
+		.channel = local_channel2,
+		.bridge = local_bridge2,
+	};
+	struct ast_bridge_channel_pair *locals[2] = { &local1, &local2 };
+
+	ast_bridge_publish_attended_transfer_link(1, AST_BRIDGE_TRANSFER_SUCCESS,
+			&transferee, &target, locals);
+}
+
+static void publish_attended_transfer_fail(enum ast_transfer_result result,
+		struct ast_channel *to_transferee, struct ast_bridge *to_transferee_bridge,
+		struct ast_channel *to_transfer_target, struct ast_bridge *to_target_bridge)
+{
+	struct ast_bridge_channel_pair transferee = {
+		.channel = to_transferee,
+		.bridge = to_transferee_bridge,
+	};
+	struct ast_bridge_channel_pair target = {
+		.channel = to_transfer_target,
+		.bridge = to_target_bridge,
+	};
+
+	ast_bridge_publish_attended_transfer_fail(1, result, &transferee, &target);
+}
+
 /*!
  * \brief Perform an attended transfer of a bridge
  *
@@ -5631,6 +5709,7 @@
 	struct ast_channel *local_chan;
 	int cause;
 	int res;
+	const char *app = NULL;
 
 	local_chan = ast_request("Local", ast_channel_nativeformats(chan1), chan1,
 			dest, &cause);
@@ -5642,6 +5721,7 @@
 	if (bridge2) {
 		res = ast_local_setup_bridge(local_chan, bridge2, chan2, NULL);
 	} else {
+		app = ast_strdupa(ast_channel_appl(chan2));
 		res = ast_local_setup_masquerade(local_chan, chan2);
 	}
 
@@ -5661,9 +5741,21 @@
 	}
 
 	if (bridge2) {
-		/* XXX Publish stasis link attended transfer */
+		/* XXX Need to lock local_chan here and check for failure */
+		struct ast_channel *local_chan2 = ast_local_get_peer(local_chan);
+
+		/* XXX This isn't accurate since the channels here aren't necessarily
+		 * labeled correctly for the publication. i.e. chan1 is not necessarily
+		 * bridged to the transferee.
+		 */
+		publish_attended_transfer_link(chan1, bridge1, chan2, bridge2,
+				local_chan, bridge1, local_chan2, bridge2);
 	} else {
-		/* XXX Publish stasis app attended transfer */
+		/* XXX This isn't accurate since the channels here aren't necessarily
+		 * labeled correctly for the publication. i.e. chan1 is not necessarily
+		 * bridged to the transferee.
+		 */
+		publish_attended_transfer_app(chan1, bridge1, chan2, bridge2, app);
 	}
 	return AST_BRIDGE_TRANSFER_SUCCESS;
 }
@@ -6025,19 +6117,24 @@
 			to_target_bridge_channel,
 	};
 	enum ast_transfer_result res;
+	struct ast_bridge *final_bridge = NULL;
 
 	switch (ast_bridges_allow_optimization(to_transferee_bridge, to_target_bridge)) {
 	case AST_BRIDGE_OPTIMIZE_SWAP_TO_CHAN_BRIDGE:
+		final_bridge = to_transferee_bridge;
 		res = bridge_swap_attended_transfer(to_transferee_bridge, to_target_bridge_channel, to_transferee);
 		goto end;
 	case AST_BRIDGE_OPTIMIZE_SWAP_TO_PEER_BRIDGE:
+		final_bridge = to_target_bridge;
 		res = bridge_swap_attended_transfer(to_target_bridge, to_transferee_bridge_channel, to_transfer_target);
 		goto end;
 	case AST_BRIDGE_OPTIMIZE_MERGE_TO_CHAN_BRIDGE:
+		final_bridge = to_transferee_bridge;
 		bridge_merge_do(to_transferee_bridge, to_target_bridge, kick_me, ARRAY_LEN(kick_me));
 		res = AST_BRIDGE_TRANSFER_SUCCESS;
 		goto end;
 	case AST_BRIDGE_OPTIMIZE_MERGE_TO_PEER_BRIDGE:
+		final_bridge = to_target_bridge;
 		bridge_merge_do(to_target_bridge, to_transferee_bridge, kick_me, ARRAY_LEN(kick_me));
 		res = AST_BRIDGE_TRANSFER_SUCCESS;
 		goto end;
@@ -6062,7 +6159,8 @@
 
 end:
 	if (res == AST_BRIDGE_TRANSFER_SUCCESS) {
-		/* XXX Publish stasis bridge merge attended transfer */
+		publish_attended_transfer_bridge_merge(to_transferee, to_transferee_bridge,
+				to_transfer_target, to_target_bridge, final_bridge);
 	}
 
 	return res;
@@ -6083,6 +6181,7 @@
 	int transfer_prohibited;
 	int do_bridge_transfer;
 	enum ast_transfer_result res;
+	const char *app = NULL;
 
 	to_transferee_bridge = acquire_bridge(to_transferee);
 	to_target_bridge = acquire_bridge(to_transfer_target);
@@ -6198,13 +6297,16 @@
 		goto end;
 	}
 
+	app = ast_strdupa(ast_channel_appl(chan_unbridged));
 	if (bridge_channel_queue_attended_transfer(transferee, chan_unbridged)) {
 		res = AST_BRIDGE_TRANSFER_FAIL;
 		goto end;
 	}
 
 	ast_bridge_remove(the_bridge, chan_bridged);
-	/* XXX Publish stasis app attended transfer message */
+
+	publish_attended_transfer_app(to_transferee, to_transferee_bridge, to_transfer_target,
+			to_target_bridge, app);
 	return AST_BRIDGE_TRANSFER_SUCCESS;
 
 end:
@@ -6212,7 +6314,8 @@
 	 * All failure paths have deferred publishing a stasis message until this point
 	 */
 	if (res != AST_BRIDGE_TRANSFER_SUCCESS) {
-		/* XXX Publish stasis failed attended transfer message */
+		publish_attended_transfer_fail(res, to_transferee, to_transferee_bridge,
+				to_transfer_target, to_target_bridge);
 	}
 	return res;
 }

Modified: team/mmichelson/transfer_stasis/main/stasis_bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/transfer_stasis/main/stasis_bridging.c?view=diff&rev=391427&r1=391426&r2=391427
==============================================================================
--- team/mmichelson/transfer_stasis/main/stasis_bridging.c (original)
+++ team/mmichelson/transfer_stasis/main/stasis_bridging.c Tue Jun 11 13:34:30 2013
@@ -440,7 +440,7 @@
 	return msg;
 }
 
-void ast_bridge_publish_attended_transfer_failure(int is_native, enum ast_transfer_result result,
+void ast_bridge_publish_attended_transfer_fail(int is_native, enum ast_transfer_result result,
 		struct ast_bridge_channel_pair *transferee, struct ast_bridge_channel_pair *target)
 {
 	RAII_VAR(struct ast_attended_transfer_message *, transfer_msg, NULL, ao2_cleanup);




More information about the asterisk-commits mailing list