[asterisk-commits] rest api/channels: Fix multiple issues with create and dial (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 13 08:08:41 CDT 2016


Anonymous Coward #1000019 has submitted this change and it was merged.

Change subject: rest_api/channels:  Fix multiple issues with create and dial
......................................................................


rest_api/channels:  Fix multiple issues with create and dial

* We weren't properly subscribing to the channel and it's originator
  on create.
* We weren't doing a publish_dial after calling ast_call on dial.
* We weren't calling depart_bridge when a channel left the dial bridge.

The first 2 issues were causing events to not be generated and the third
was actually causing channels to not get properly destroyed when hung up.

Together these 3 issues were causing the new
rest_apichannels/create_dial_bridge tests to fail.

As a result of the fixes, the cdr state machine had to be slightly
tweaked to allow bridge leave events without asserting and the tests
themselves had to be updated to account for the channels now cleaning
themselves up.

Change-Id: Ibf23abf5a62de76e82afb4461af5099c961b97d8
---
M main/cdr.c
M res/ari/resource_channels.c
M res/stasis/control.c
3 files changed, 27 insertions(+), 4 deletions(-)

Approvals:
  Mark Michelson: Looks good to me, but someone else must approve
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, approved



diff --git a/main/cdr.c b/main/cdr.c
index 586a106..e2f9b76 100644
--- a/main/cdr.c
+++ b/main/cdr.c
@@ -1409,9 +1409,7 @@
 
 static int base_process_bridge_leave(struct cdr_object *cdr, struct ast_bridge_snapshot *bridge, struct ast_channel_snapshot *channel)
 {
-	/* In general, most things shouldn't get a bridge leave */
-	ast_assert(0);
-	return 1;
+	return 0;
 }
 
 static int base_process_dial_end(struct cdr_object *cdr, struct ast_channel_snapshot *caller, struct ast_channel_snapshot *peer, const char *dial_status)
diff --git a/res/ari/resource_channels.c b/res/ari/resource_channels.c
index bce7c7d..35b7572 100644
--- a/res/ari/resource_channels.c
+++ b/res/ari/resource_channels.c
@@ -1776,6 +1776,9 @@
 	originator = ast_channel_get_by_name(args->originator);
 	if (originator) {
 		request_cap = ao2_bump(ast_channel_nativeformats(originator));
+		if (!ast_strlen_zero(args->app)) {
+			stasis_app_subscribe_channel(args->app, originator);
+		}
 	} else if (!ast_strlen_zero(args->formats)) {
 		char *format_name;
 		char *formats_copy = ast_strdupa(args->formats);
@@ -1816,13 +1819,20 @@
 
 	chan_data->chan = ast_request(dialtech, request_cap, &assignedids, originator, dialdevice, &cause);
 	ao2_cleanup(request_cap);
-	ast_channel_cleanup(originator);
+
 	if (!chan_data->chan) {
 		ast_ari_response_alloc_failed(response);
+		ast_channel_cleanup(originator);
 		chan_data_destroy(chan_data);
 		return;
 	}
 
+	if (!ast_strlen_zero(args->app)) {
+		stasis_app_subscribe_channel(args->app, chan_data->chan);
+	}
+
+	ast_channel_cleanup(originator);
+
 	if (save_dialstring(chan_data->chan, stuff)) {
 		ast_ari_response_alloc_failed(response);
 		chan_data_destroy(chan_data);
diff --git a/res/stasis/control.c b/res/stasis/control.c
index b255477..219a2c6 100644
--- a/res/stasis/control.c
+++ b/res/stasis/control.c
@@ -881,6 +881,9 @@
 	return ret_bridge;
 }
 
+static int bridge_channel_depart(struct stasis_app_control *control,
+	struct ast_channel *chan, void *data);
+
 /*!
  * \brief after bridge callback for the dial bridge
  *
@@ -890,6 +893,15 @@
 static void dial_bridge_after_cb(struct ast_channel *chan, void *data)
 {
 	struct stasis_app_control *control = data;
+	struct ast_bridge_channel *bridge_channel;
+
+	ast_channel_lock(chan);
+	bridge_channel = ast_channel_get_bridge_channel(chan);
+	ast_channel_unlock(chan);
+
+	ast_debug(3, "Channel: <%s>  Reason: %d\n", ast_channel_name(control->channel), ast_channel_hangupcause(chan));
+
+	stasis_app_send_command_async(control, bridge_channel_depart, bridge_channel, __ao2_cleanup);
 
 	control->bridge = NULL;
 }
@@ -898,6 +910,7 @@
 {
 	struct stasis_app_control *control = data;
 
+	ast_debug(3, "Channel: <%s>  Reason: %d\n", ast_channel_name(control->channel), reason);
 	dial_bridge_after_cb(control->channel, data);
 }
 
@@ -1443,6 +1456,8 @@
 		return -1;
 	}
 
+	ast_channel_publish_dial(NULL, chan, args->dialstring, NULL);
+
 	return 0;
 }
 

-- 
To view, visit https://gerrit.asterisk.org/3178
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ibf23abf5a62de76e82afb4461af5099c961b97d8
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-commits mailing list