[Asterisk-code-review] core/dial: New channel variable FORWARDERNAME (asterisk[master])

Joshua Colp asteriskteam at digium.com
Mon Jun 6 07:34:23 CDT 2016


Joshua Colp has submitted this change and it was merged.

Change subject: core/dial: New channel variable FORWARDERNAME
......................................................................


core/dial: New channel variable FORWARDERNAME

Added a new channel variable FORWARDERNAME which indicates which
channel was responsible for a forwarding requests received on dial attempt.

Fixed a bug in the app_queue: FORWARD_CONTEXT is not used.

ASTERISK-26059 #close

Change-Id: I34e93e8c1b5e17776a77b319703c48c8ca48e7b2
---
M CHANGES
M apps/app_dial.c
M apps/app_queue.c
M main/bridge_channel.c
M main/channel.c
M main/dial.c
6 files changed, 32 insertions(+), 5 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, approved; Verified



diff --git a/CHANGES b/CHANGES
index 6ffefbf..608a4a4 100644
--- a/CHANGES
+++ b/CHANGES
@@ -331,6 +331,11 @@
 --- Functionality changes from Asterisk 13.9.0 to Asterisk 13.10.0 -----------
 ------------------------------------------------------------------------------
 
+Core
+------------------
+ * A channel variable FORWARDERNAME is now set which indicates which channel
+   was responsible for a forwarding requests received on dial attempt.
+
 func_odbc
 ------------------
  * Added new global option "single_db_connection".
diff --git a/apps/app_dial.c b/apps/app_dial.c
index 5e034d3..1f019d6 100644
--- a/apps/app_dial.c
+++ b/apps/app_dial.c
@@ -834,6 +834,7 @@
 	struct ast_party_id *forced_clid, struct ast_party_id *stored_clid)
 {
 	char tmpchan[256];
+	char forwarder[AST_CHANNEL_NAME];
 	struct ast_channel *original = o->chan;
 	struct ast_channel *c = o->chan; /* the winner */
 	struct ast_channel *in = num->chan; /* the input channel */
@@ -842,6 +843,7 @@
 	int cause;
 	struct ast_party_caller caller;
 
+	ast_copy_string(forwarder, ast_channel_name(c), sizeof(forwarder));
 	ast_copy_string(tmpchan, ast_channel_call_forward(c), sizeof(tmpchan));
 	if ((stuff = strchr(tmpchan, '/'))) {
 		*stuff++ = '\0';
@@ -895,6 +897,7 @@
 			ast_channel_lock_both(in, o->chan);
 			ast_channel_inherit_variables(in, o->chan);
 			ast_channel_datastore_inherit(in, o->chan);
+			pbx_builtin_setvar_helper(o->chan, "FORWARDERNAME", forwarder);
 			ast_max_forwards_decrement(o->chan);
 			ast_channel_unlock(in);
 			ast_channel_unlock(o->chan);
diff --git a/apps/app_queue.c b/apps/app_queue.c
index 165924e..45297f5 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -4854,16 +4854,22 @@
 					continue;
 				} else if (!ast_strlen_zero(ast_channel_call_forward(o->chan))) {
 					struct ast_channel *original = o->chan;
+					char forwarder[AST_CHANNEL_NAME];
 					char tmpchan[256];
 					char *stuff;
 					char *tech;
 
 					ast_copy_string(tmpchan, ast_channel_call_forward(o->chan), sizeof(tmpchan));
+					ast_copy_string(forwarder, ast_channel_name(o->chan), sizeof(forwarder));
 					if ((stuff = strchr(tmpchan, '/'))) {
 						*stuff++ = '\0';
 						tech = tmpchan;
 					} else {
-						snprintf(tmpchan, sizeof(tmpchan), "%s@%s", ast_channel_call_forward(o->chan), ast_channel_context(o->chan));
+						const char *forward_context;
+						ast_channel_lock(o->chan);
+						forward_context = pbx_builtin_getvar_helper(o->chan, "FORWARD_CONTEXT");
+						snprintf(tmpchan, sizeof(tmpchan), "%s@%s", ast_channel_call_forward(o->chan), forward_context ? forward_context : ast_channel_context(o->chan));
+						ast_channel_unlock(o->chan);
 						stuff = tmpchan;
 						tech = "Local";
 					}
@@ -4895,6 +4901,7 @@
 						ast_channel_lock_both(o->chan, in);
 						ast_channel_inherit_variables(in, o->chan);
 						ast_channel_datastore_inherit(in, o->chan);
+						pbx_builtin_setvar_helper(o->chan, "FORWARDERNAME", forwarder);
 						ast_max_forwards_decrement(o->chan);
 
 						if (o->pending_connected_update) {
diff --git a/main/bridge_channel.c b/main/bridge_channel.c
index 6766dff..3ba61aa 100644
--- a/main/bridge_channel.c
+++ b/main/bridge_channel.c
@@ -2162,9 +2162,10 @@
 
 	ast_bridge_publish_enter(bridge, bridge_channel->chan, swap ? swap->chan : NULL);
 
-	/* Clear any BLINDTRANSFER and ATTENDEDTRANSFER since the transfer has completed. */
+	/* Clear any BLINDTRANSFER,ATTENDEDTRANSFER and FORWARDERNAME since the transfer has completed. */
 	pbx_builtin_setvar_helper(bridge_channel->chan, "BLINDTRANSFER", NULL);
 	pbx_builtin_setvar_helper(bridge_channel->chan, "ATTENDEDTRANSFER", NULL);
+	pbx_builtin_setvar_helper(bridge_channel->chan, "FORWARDERNAME", NULL);
 
 	/* Wake up the bridge channel thread to reevaluate any interval timers. */
 	ast_queue_frame(bridge_channel->chan, &ast_null_frame);
diff --git a/main/channel.c b/main/channel.c
index 852de1a..f654e4d 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -5663,6 +5663,7 @@
 struct ast_channel *ast_call_forward(struct ast_channel *caller, struct ast_channel *orig, int *timeout, struct ast_format_cap *cap, struct outgoing_helper *oh, int *outstate)
 {
 	char tmpchan[256];
+	char forwarder[AST_CHANNEL_NAME];
 	struct ast_channel *new_chan = NULL;
 	char *data, *type;
 	int cause = 0;
@@ -5670,6 +5671,7 @@
 
 	/* gather data and request the new forward channel */
 	ast_copy_string(tmpchan, ast_channel_call_forward(orig), sizeof(tmpchan));
+	ast_copy_string(forwarder, ast_channel_name(orig), sizeof(forwarder));
 	if ((data = strchr(tmpchan, '/'))) {
 		*data++ = '\0';
 		type = tmpchan;
@@ -5713,6 +5715,7 @@
 	ast_set_flag(ast_channel_flags(new_chan), AST_FLAG_ORIGINATED);
 
 	ast_channel_lock_both(orig, new_chan);
+	pbx_builtin_setvar_helper(new_chan, "FORWARDERNAME", forwarder);
 	ast_party_connected_line_copy(ast_channel_connected(new_chan), ast_channel_connected(orig));
 	ast_party_redirecting_copy(ast_channel_redirecting(new_chan), ast_channel_redirecting(orig));
 	ast_channel_req_accountcodes(new_chan, orig, AST_CHANNEL_REQUESTOR_REPLACEMENT);
diff --git a/main/dial.c b/main/dial.c
index bac191e..7677c5a 100644
--- a/main/dial.c
+++ b/main/dial.c
@@ -454,14 +454,22 @@
 }
 
 /*! \brief Helper function that does the beginning dialing per-appended channel */
-static int begin_dial_channel(struct ast_dial_channel *channel, struct ast_channel *chan, int async, const char *predial_string)
+static int begin_dial_channel(struct ast_dial_channel *channel, struct ast_channel *chan, int async, const char *predial_string, struct ast_channel *forwarder_chan)
 {
 	char numsubst[AST_MAX_EXTENSION];
 	int res = 1;
+	char forwarder[AST_CHANNEL_NAME];
 
 	/* If no owner channel exists yet execute pre-run */
 	if (!channel->owner && begin_dial_prerun(channel, chan, NULL, predial_string)) {
 		return 0;
+	}
+
+	if (forwarder_chan) {
+		ast_copy_string(forwarder, ast_channel_name(forwarder_chan), sizeof(forwarder));
+		ast_channel_lock(channel->owner);
+		pbx_builtin_setvar_helper(channel->owner, "FORWARDERNAME", forwarder);
+		ast_channel_unlock(channel->owner);
 	}
 
 	/* Copy device string over */
@@ -494,7 +502,7 @@
 	/* Iterate through channel list, requesting and calling each one */
 	AST_LIST_LOCK(&dial->channels);
 	AST_LIST_TRAVERSE(&dial->channels, channel, list) {
-		success += begin_dial_channel(channel, chan, async, predial_string);
+		success += begin_dial_channel(channel, chan, async, predial_string, NULL);
 	}
 	AST_LIST_UNLOCK(&dial->channels);
 
@@ -550,7 +558,7 @@
 	channel->owner = NULL;
 
 	/* Finally give it a go... send it out into the world */
-	begin_dial_channel(channel, chan, chan ? 0 : 1, predial_string);
+	begin_dial_channel(channel, chan, chan ? 0 : 1, predial_string, original);
 
 	ast_channel_publish_dial_forward(chan, original, channel->owner, NULL, "CANCEL",
 		ast_channel_call_forward(original));

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I34e93e8c1b5e17776a77b319703c48c8ca48e7b2
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Alexei Gradinari <alex2grad at gmail.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>



More information about the asterisk-code-review mailing list