[svn-commits] kmoore: branch 13 r421538 - in /branches/13: ./ include/asterisk/ main/ res/a...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Aug 20 08:04:33 CDT 2014


Author: kmoore
Date: Wed Aug 20 08:04:30 2014
New Revision: 421538

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=421538
Log:
Stasis: Add information to blind transfer event

When a blind transfer occurs that is forced to create a local channel
pair to satisfy the transfer request, information about the local
channel pair is not published. This adds a field to describe that
channel to the blind transfer message struct so that this information
is conveyed properly to consumers of the blind transfer message.

This also fixes a bug in which Stasis() was unable to properly identify
the channel that was replacing an existing Stasis-controlled channel
due to a blind transfer.

Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3921/
........

Merged revisions 421537 from http://svn.asterisk.org/svn/asterisk/branches/12

Modified:
    branches/13/   (props changed)
    branches/13/include/asterisk/stasis_bridges.h
    branches/13/main/bridge.c
    branches/13/main/stasis_bridges.c
    branches/13/res/ari/ari_model_validators.c
    branches/13/res/ari/ari_model_validators.h
    branches/13/res/stasis/app.c
    branches/13/rest-api/api-docs/events.json
    branches/13/tests/test_cel.c

Propchange: branches/13/
------------------------------------------------------------------------------
Binary property 'branch-12-merged' - no diff available.

Modified: branches/13/include/asterisk/stasis_bridges.h
URL: http://svnview.digium.com/svn/asterisk/branches/13/include/asterisk/stasis_bridges.h?view=diff&rev=421538&r1=421537&r2=421538
==============================================================================
--- branches/13/include/asterisk/stasis_bridges.h (original)
+++ branches/13/include/asterisk/stasis_bridges.h Wed Aug 20 08:04:30 2014
@@ -300,6 +300,8 @@
 	char exten[AST_MAX_EXTENSION];
 	/*! Transferee channel. NULL if there were multiple transferee channels */
 	struct ast_channel_snapshot *transferee;
+	/*! The channel replacing the transferer when multiple parties are being transferred */
+	struct ast_channel_snapshot *replace_channel;
 };
 
 /*!
@@ -312,11 +314,15 @@
  * \param to_transferee The bridge between the transferer and transferee plus the transferer channel
  * \param context The destination context for the blind transfer
  * \param exten The destination extension for the blind transfer
- * \param transferee_channel If a single channel is being transferred, this is it. If multiple parties are being transferred, this is NULL.
+ * \param transferee_channel If a single channel is being transferred, this is it. If
+ *                           multiple parties are being transferred, this is NULL.
+ * \param replace_channel If multiple parties are being transferred or the transfer
+ *                        cannot reach across the bridge due to bridge flags, this is
+ *                        the channel connecting their bridge to the destination.
  */
 void ast_bridge_publish_blind_transfer(int is_external, enum ast_transfer_result result,
 		struct ast_bridge_channel_pair *to_transferee, const char *context, const char *exten,
-		struct ast_channel *transferee_channel);
+		struct ast_channel *transferee_channel, struct ast_channel *replace_channel);
 
 enum ast_attended_transfer_dest_type {
 	/*! The transfer failed, so there is no appropriate final state */

Modified: branches/13/main/bridge.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/main/bridge.c?view=diff&rev=421538&r1=421537&r2=421538
==============================================================================
--- branches/13/main/bridge.c (original)
+++ branches/13/main/bridge.c Wed Aug 20 08:04:30 2014
@@ -3805,6 +3805,26 @@
 	return peer;
 }
 
+static void publish_blind_transfer_full(int is_external, enum ast_transfer_result result,
+		struct ast_channel *transferer, struct ast_bridge *bridge,
+		const char *context, const char *exten, struct ast_channel *transferee_channel,
+		struct ast_channel *replace_channel)
+{
+	struct ast_bridge_channel_pair pair;
+
+	pair.channel = transferer;
+	pair.bridge = bridge;
+
+	if (bridge) {
+		ast_bridge_lock(bridge);
+	}
+	ast_bridge_publish_blind_transfer(is_external, result, &pair, context, exten,
+		transferee_channel, replace_channel);
+	if (bridge) {
+		ast_bridge_unlock(bridge);
+	}
+}
+
 /*!
  * \internal
  * \brief Transfer an entire bridge to a specific destination.
@@ -3817,16 +3837,21 @@
  * bridges, this method is only used for multi-party bridges since this method would
  * be less efficient for two-party bridges.
  *
+ * \param is_external Whether the transfer is externally initiated
  * \param transferer The channel performing a transfer
  * \param bridge The bridge where the transfer is being performed
  * \param exten The destination extension for the blind transfer
+ * \param transferee The party being transferred if there is only one
  * \param context The destination context for the blind transfer
  * \param hook Framehook to attach to local channel
+ *
  * \return The success or failure of the operation
  */
-static enum ast_transfer_result blind_transfer_bridge(struct ast_channel *transferer,
-		struct ast_bridge *bridge, const char *exten, const char *context,
-		transfer_channel_cb new_channel_cb, struct transfer_channel_data *user_data_wrapper)
+static enum ast_transfer_result blind_transfer_bridge(int is_external,
+		struct ast_channel *transferer, struct ast_bridge *bridge,
+		const char *exten, const char *context, struct ast_channel *transferee,
+		transfer_channel_cb new_channel_cb,
+		struct transfer_channel_data *user_data_wrapper)
 {
 	struct ast_channel *local;
 	char chan_name[AST_MAX_EXTENSION + AST_MAX_CONTEXT + 2];
@@ -3858,6 +3883,8 @@
 		ast_hangup(local);
 		return AST_BRIDGE_TRANSFER_FAIL;
 	}
+	publish_blind_transfer_full(is_external, AST_BRIDGE_TRANSFER_SUCCESS, transferer, bridge,
+		context, exten, transferee, local);
 	return AST_BRIDGE_TRANSFER_SUCCESS;
 }
 
@@ -4214,16 +4241,8 @@
 		struct ast_channel *transferer, struct ast_bridge *bridge,
 		const char *context, const char *exten, struct ast_channel *transferee_channel)
 {
-	struct ast_bridge_channel_pair pair;
-	pair.channel = transferer;
-	pair.bridge = bridge;
-	if (bridge) {
-		ast_bridge_lock(bridge);
-	}
-	ast_bridge_publish_blind_transfer(is_external, result, &pair, context, exten, transferee_channel);
-	if (bridge) {
-		ast_bridge_unlock(bridge);
-	}
+	publish_blind_transfer_full(is_external, result, transferer, bridge, context,
+		exten, transferee_channel, NULL);
 }
 
 enum ast_transfer_result ast_bridge_transfer_blind(int is_external,
@@ -4301,8 +4320,12 @@
 	set_transfer_variables_all(transferer, channels, 0);
 
 	if (do_bridge_transfer) {
-		transfer_result = blind_transfer_bridge(transferer, bridge, exten, context,
-				new_channel_cb, user_data_wrapper);
+		/* if blind_transfer_bridge succeeds, it publishes its own message */
+		transfer_result = blind_transfer_bridge(is_external, transferer, bridge,
+			exten, context, transferee, new_channel_cb, user_data_wrapper);
+		if (transfer_result == AST_BRIDGE_TRANSFER_SUCCESS)  {
+			return transfer_result;
+		}
 		goto publish;
 	}
 

Modified: branches/13/main/stasis_bridges.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/main/stasis_bridges.c?view=diff&rev=421538&r1=421537&r2=421538
==============================================================================
--- branches/13/main/stasis_bridges.c (original)
+++ branches/13/main/stasis_bridges.c Wed Aug 20 08:04:30 2014
@@ -636,7 +636,10 @@
 	const struct stasis_message_sanitizer *sanitize)
 {
 	struct ast_blind_transfer_message *transfer_msg = stasis_message_data(msg);
-	struct ast_json *json_transferer, *json_transferee = NULL, *out;
+	struct ast_json *json_transferer;
+	struct ast_json *json_transferee = NULL;
+	struct ast_json *out;
+	struct ast_json *json_replace = NULL;
 	const struct timeval *tv = stasis_message_timestamp(msg);
 
 	json_transferer = ast_channel_snapshot_to_json(transfer_msg->to_transferee.channel_snapshot, sanitize);
@@ -647,6 +650,16 @@
 	if (transfer_msg->transferee) {
 		json_transferee = ast_channel_snapshot_to_json(transfer_msg->transferee, sanitize);
 		if (!json_transferee) {
+			ast_json_unref(json_transferer);
+			return NULL;
+		}
+	}
+
+	if (transfer_msg->replace_channel) {
+		json_replace = ast_channel_snapshot_to_json(transfer_msg->replace_channel, sanitize);
+		if (!json_replace) {
+			ast_json_unref(json_transferee);
+			ast_json_unref(json_transferer);
 			return NULL;
 		}
 	}
@@ -661,10 +674,18 @@
 		"is_external", ast_json_boolean(transfer_msg->is_external));
 
 	if (!out) {
+		ast_json_unref(json_transferee);
+		ast_json_unref(json_replace);
 		return NULL;
 	}
 
 	if (json_transferee && ast_json_object_set(out, "transferee", json_transferee)) {
+		ast_json_unref(out);
+		ast_json_unref(json_replace);
+		return NULL;
+	}
+
+	if (json_replace && ast_json_object_set(out, "replace_channel", json_replace)) {
 		ast_json_unref(out);
 		return NULL;
 	}
@@ -741,7 +762,7 @@
 
 void ast_bridge_publish_blind_transfer(int is_external, enum ast_transfer_result result,
 		struct ast_bridge_channel_pair *transferer, const char *context, const char *exten,
-		struct ast_channel *transferee_channel)
+		struct ast_channel *transferee_channel, struct ast_channel *replace_channel)
 {
 	struct ast_blind_transfer_message *msg;
 	struct stasis_message *stasis;
@@ -758,6 +779,9 @@
 
 	if (transferee_channel) {
 		msg->transferee = ast_channel_snapshot_get_latest(ast_channel_uniqueid(transferee_channel));
+	}
+	if (replace_channel) {
+		msg->replace_channel = ast_channel_snapshot_get_latest(ast_channel_uniqueid(replace_channel));
 	}
 	msg->is_external = is_external;
 	msg->result = result;

Modified: branches/13/res/ari/ari_model_validators.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/res/ari/ari_model_validators.c?view=diff&rev=421538&r1=421537&r2=421538
==============================================================================
--- branches/13/res/ari/ari_model_validators.c (original)
+++ branches/13/res/ari/ari_model_validators.c Wed Aug 20 08:04:30 2014
@@ -2062,6 +2062,15 @@
 				res = 0;
 			}
 		} else
+		if (strcmp("replace_channel", ast_json_object_iter_key(iter)) == 0) {
+			int prop_is_valid;
+			prop_is_valid = ast_ari_validate_channel(
+				ast_json_object_iter_value(iter));
+			if (!prop_is_valid) {
+				ast_log(LOG_ERROR, "ARI BridgeBlindTransfer field replace_channel failed validation\n");
+				res = 0;
+			}
+		} else
 		if (strcmp("result", ast_json_object_iter_key(iter)) == 0) {
 			int prop_is_valid;
 			has_result = 1;

Modified: branches/13/res/ari/ari_model_validators.h
URL: http://svnview.digium.com/svn/asterisk/branches/13/res/ari/ari_model_validators.h?view=diff&rev=421538&r1=421537&r2=421538
==============================================================================
--- branches/13/res/ari/ari_model_validators.h (original)
+++ branches/13/res/ari/ari_model_validators.h Wed Aug 20 08:04:30 2014
@@ -1304,6 +1304,7 @@
  * - context: string (required)
  * - exten: string (required)
  * - is_external: boolean (required)
+ * - replace_channel: Channel
  * - result: string (required)
  * - transferee: Channel
  * BridgeCreated

Modified: branches/13/res/stasis/app.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/res/stasis/app.c?view=diff&rev=421538&r1=421537&r2=421538
==============================================================================
--- branches/13/res/stasis/app.c (original)
+++ branches/13/res/stasis/app.c Wed Aug 20 08:04:30 2014
@@ -696,19 +696,6 @@
 	return subscribed;
 }
 
-static void bridge_blind_transfer_handler(void *data, struct stasis_subscription *sub,
-	struct stasis_message *message)
-{
-	struct stasis_app *app = data;
-	struct ast_blind_transfer_message *transfer_msg = stasis_message_data(message);
-	struct ast_bridge_snapshot *bridge = transfer_msg->to_transferee.bridge_snapshot;
-
-	if (bridge_app_subscribed(app, transfer_msg->to_transferee.channel_snapshot->uniqueid) ||
-		(bridge && bridge_app_subscribed_involved(app, bridge))) {
-		stasis_publish(app->topic, message);
-	}
-}
-
 static void set_replacement_channel(struct ast_channel_snapshot *to_be_replaced,
 		struct ast_channel_snapshot *replacing)
 {
@@ -724,6 +711,24 @@
 	}
 	ast_channel_cleanup(chan);
 	ao2_cleanup(control);
+}
+
+static void bridge_blind_transfer_handler(void *data, struct stasis_subscription *sub,
+	struct stasis_message *message)
+{
+	struct stasis_app *app = data;
+	struct ast_blind_transfer_message *transfer_msg = stasis_message_data(message);
+	struct ast_bridge_snapshot *bridge = transfer_msg->to_transferee.bridge_snapshot;
+
+	if (transfer_msg->replace_channel) {
+		set_replacement_channel(transfer_msg->to_transferee.channel_snapshot,
+				transfer_msg->replace_channel);
+	}
+
+	if (bridge_app_subscribed(app, transfer_msg->to_transferee.channel_snapshot->uniqueid) ||
+		(bridge && bridge_app_subscribed_involved(app, bridge))) {
+		stasis_publish(app->topic, message);
+	}
 }
 
 static void bridge_attended_transfer_handler(void *data, struct stasis_subscription *sub,

Modified: branches/13/rest-api/api-docs/events.json
URL: http://svnview.digium.com/svn/asterisk/branches/13/rest-api/api-docs/events.json?view=diff&rev=421538&r1=421537&r2=421538
==============================================================================
--- branches/13/rest-api/api-docs/events.json (original)
+++ branches/13/rest-api/api-docs/events.json Wed Aug 20 08:04:30 2014
@@ -285,6 +285,11 @@
 					"required": true,
 					"type": "Channel"
 				},
+				"replace_channel": {
+					"description": "The channel that is replacing transferer when the transferee(s) can not be transferred directly",
+					"required": false,
+					"type": "Channel"
+				},
 				"transferee": {
 					"description": "The channel that is being transferred",
 					"required": false,

Modified: branches/13/tests/test_cel.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/tests/test_cel.c?view=diff&rev=421538&r1=421537&r2=421538
==============================================================================
--- branches/13/tests/test_cel.c (original)
+++ branches/13/tests/test_cel.c Wed Aug 20 08:04:30 2014
@@ -1257,7 +1257,7 @@
 	pair.channel = chan_alice;
 	ast_bridge_lock(bridge);
 	ast_bridge_publish_blind_transfer(1, AST_BRIDGE_TRANSFER_SUCCESS,
-		&pair, "transfer_context", "transfer_extension", NULL);
+		&pair, "transfer_context", "transfer_extension", NULL, NULL);
 	ast_bridge_unlock(bridge);
 	BLINDTRANSFER_EVENT(chan_alice, bridge, "transfer_extension", "transfer_context");
 




More information about the svn-commits mailing list