[Asterisk-code-review] bridge: Fix returning to dialplan when executing Bridge() fr... (asterisk[14])

Joshua Colp asteriskteam at digium.com
Tue May 2 05:27:55 CDT 2017


Joshua Colp has uploaded a new change for review. ( https://gerrit.asterisk.org/5568 )

Change subject: bridge: Fix returning to dialplan when executing Bridge() from AMI.
......................................................................

bridge: Fix returning to dialplan when executing Bridge() from AMI.

When using the Bridge AMI action on the same channel multiple times
it was possible for the channel to return to the wrong location in
the dialplan if the other party hung up. This happened because the
priority of the channel was not preserved across each action
invocation and it would fail to move on to the next priority in
other cases.

This change makes it so that the priority of a channel is preserved
when taking control of it from another thread. Additionally the
Bridge AMI action was changed to ensure that the next priority was
explicitly executed instead of relying on internal behavior which
could result in the wrong thing being executed.

ASTERISK-24529

Change-Id: I52406669cf64208aef7252a65b63ade31fbf7a5a
---
M main/channel.c
M main/features.c
2 files changed, 7 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/68/5568/1

diff --git a/main/channel.c b/main/channel.c
index ea83ebf..f30a2f6 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -10682,6 +10682,7 @@
 		char *context;
 		char *name;
 		int amaflags;
+		int priority;
 		struct ast_format *readformat;
 		struct ast_format *writeformat;
 	} my_vars = { 0, };
@@ -10692,6 +10693,7 @@
 	my_vars.context = ast_strdupa(ast_channel_context(yankee));
 	my_vars.name = ast_strdupa(ast_channel_name(yankee));
 	my_vars.amaflags = ast_channel_amaflags(yankee);
+	my_vars.priority = ast_channel_priority(yankee);
 	my_vars.writeformat = ao2_bump(ast_channel_writeformat(yankee));
 	my_vars.readformat = ao2_bump(ast_channel_readformat(yankee));
 	ast_channel_unlock(yankee);
@@ -10711,6 +10713,7 @@
 	ast_channel_set_writeformat(yanked_chan, my_vars.writeformat);
 	ao2_cleanup(my_vars.readformat);
 	ao2_cleanup(my_vars.writeformat);
+	ast_channel_priority_set(yanked_chan, my_vars.priority);
 
 	ast_channel_unlock(yanked_chan);
 
diff --git a/main/features.c b/main/features.c
index 0af5a78..f7b9d7d 100644
--- a/main/features.c
+++ b/main/features.c
@@ -783,10 +783,7 @@
 	xfer_cfg_a = ast_get_chan_features_xfer_config(chana);
 	chana_exten = ast_strdupa(ast_channel_exten(chana));
 	chana_context = ast_strdupa(ast_channel_context(chana));
-	chana_priority = ast_channel_priority(chana);
-	if (!ast_test_flag(ast_channel_flags(chana), AST_FLAG_IN_AUTOLOOP)) {
-		chana_priority++;
-	}
+	chana_priority = ast_channel_priority(chana) + 1;
 	ast_channel_unlock(chana);
 
 	chanb = ast_channel_get_by_name_prefix(channelb, strlen(channelb));
@@ -799,10 +796,7 @@
 	xfer_cfg_b = ast_get_chan_features_xfer_config(chanb);
 	chanb_exten = ast_strdupa(ast_channel_exten(chanb));
 	chanb_context = ast_strdupa(ast_channel_context(chanb));
-	chanb_priority = ast_channel_priority(chanb);
-	if (!ast_test_flag(ast_channel_flags(chanb), AST_FLAG_IN_AUTOLOOP)) {
-		chanb_priority++;
-	}
+	chanb_priority = ast_channel_priority(chanb) + 1;
 	ast_channel_unlock(chanb);
 
 	bridge = ast_bridge_basic_new();
@@ -811,7 +805,7 @@
 		return 0;
 	}
 
-	ast_bridge_set_after_go_on(chana, chana_context, chana_exten, chana_priority, NULL);
+	ast_bridge_set_after_goto(chana, chana_context, chana_exten, chana_priority);
 	if (ast_bridge_add_channel(bridge, chana, NULL, playtone & PLAYTONE_CHANNEL1, xfer_cfg_a ? xfer_cfg_a->xfersound : NULL)) {
 		snprintf(buf, sizeof(buf), "Unable to add Channel1 to bridge: %s", ast_channel_name(chana));
 		astman_send_error(s, m, buf);
@@ -819,7 +813,7 @@
 		return 0;
 	}
 
-	ast_bridge_set_after_go_on(chanb, chanb_context, chanb_exten, chanb_priority, NULL);
+	ast_bridge_set_after_goto(chanb, chanb_context, chanb_exten, chanb_priority);
 	if (ast_bridge_add_channel(bridge, chanb, NULL, playtone & PLAYTONE_CHANNEL2, xfer_cfg_b ? xfer_cfg_b->xfersound : NULL)) {
 		snprintf(buf, sizeof(buf), "Unable to add Channel2 to bridge: %s", ast_channel_name(chanb));
 		astman_send_error(s, m, buf);

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I52406669cf64208aef7252a65b63ade31fbf7a5a
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 14
Gerrit-Owner: Joshua Colp <jcolp at digium.com>



More information about the asterisk-code-review mailing list