[svn-commits] mmichelson: branch 13 r420794 - in /branches/13: ./ apps/ include/asterisk/ m...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Aug 11 13:32:44 CDT 2014


Author: mmichelson
Date: Mon Aug 11 13:32:37 2014
New Revision: 420794

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=420794
Log:
Improve call forwarding reporting, especially with regards to ARI.

This patch addresses a few issues:

1) The order of Dial events have been changed when performing a call forward.
   The order has now been altered to
    1) Dial begins dialing channel A.
    2) When A forwards the call to B, we issue the dial end event to channel
       A, indicating the dial is being canceled due to a forward to B.
    3) When the call to channel B occurs, we then issue a new dial begin to
       channel B.

2) Call forwards are now reported on the calling channel, not the peer channel.

3) AMI DialEnd events have been altered to display the extension the call is
   being forwarded to when relevant.

4) You can now get the values of channel variables for channels that are not
   currently in the Stasis application. This brings the retrieval of channel
   variables more in line with the rest of channel read operations since they
   may be performed on channels not in Stasis.

ASTERISK-24134 #close
Reported by Matt Jordan

ASTERISK-24138 #close
Reported by Matt Jordan

Patches:
	forward-shenanigans.diff uploaded by Matt Jordan (License #6283)

Review: https://reviewboard.asterisk.org/r/3899


Modified:
    branches/13/CHANGES
    branches/13/apps/app_dial.c
    branches/13/include/asterisk/stasis_app.h
    branches/13/main/manager_channels.c
    branches/13/main/stasis_channels.c
    branches/13/res/ari/resource_channels.c
    branches/13/res/res_pjsip_pubsub.c
    branches/13/res/stasis/app.c
    branches/13/res/stasis/control.c

Modified: branches/13/CHANGES
URL: http://svnview.digium.com/svn/asterisk/branches/13/CHANGES?view=diff&rev=420794&r1=420793&r2=420794
==============================================================================
--- branches/13/CHANGES (original)
+++ branches/13/CHANGES Mon Aug 11 13:32:37 2014
@@ -273,6 +273,10 @@
  
  * The AMI action PJSIPShowEndpoint now includes ContactStatusDetail sections
    that give information on Asterisk's attempts to qualify the endpoint.
+
+ * The DialEnd event will now contain a Forward header if the dial is ending
+   due to the call being forwarded. The contents of the Forward header is the
+   extension in the number to which the call is being forwarded.
 
 CEL
 ------------------

Modified: branches/13/apps/app_dial.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/apps/app_dial.c?view=diff&rev=420794&r1=420793&r2=420794
==============================================================================
--- branches/13/apps/app_dial.c (original)
+++ branches/13/apps/app_dial.c Mon Aug 11 13:32:37 2014
@@ -895,6 +895,7 @@
 				tech, stuff, cause);
 	}
 	if (!c) {
+		ast_channel_publish_dial(in, original, stuff, "BUSY");
 		ast_clear_flag64(o, DIAL_STILLGOING);
 		handle_cause(cause, num);
 		ast_hangup(original);
@@ -995,15 +996,17 @@
 		if (ast_call(c, stuff, 0)) {
 			ast_log(LOG_NOTICE, "Forwarding failed to dial '%s/%s'\n",
 				tech, stuff);
+			ast_channel_publish_dial(in, original, stuff, "CONGESTION");
 			ast_clear_flag64(o, DIAL_STILLGOING);
 			ast_hangup(original);
 			ast_hangup(c);
 			c = o->chan = NULL;
 			num->nochan++;
 		} else {
-			ast_channel_publish_dial(in, c, stuff, NULL);
 			ast_channel_publish_dial_forward(in, original, c, NULL, "CANCEL",
 				ast_channel_call_forward(original));
+
+			ast_channel_publish_dial(in, c, stuff, NULL);
 
 			/* Hangup the original channel now, in case we needed it */
 			ast_hangup(original);

Modified: branches/13/include/asterisk/stasis_app.h
URL: http://svnview.digium.com/svn/asterisk/branches/13/include/asterisk/stasis_app.h?view=diff&rev=420794&r1=420793&r2=420794
==============================================================================
--- branches/13/include/asterisk/stasis_app.h (original)
+++ branches/13/include/asterisk/stasis_app.h Mon Aug 11 13:32:37 2014
@@ -554,15 +554,6 @@
 int stasis_app_control_answer(struct stasis_app_control *control);
 
 /*!
- * \brief Get the value of a variable on the channel associated with this control.
- * \param control Control for \c res_stasis.
- * \param variable The name of the variable.
- *
- * \return The value of the variable.  The returned variable must be freed.
- */
-char *stasis_app_control_get_channel_var(struct stasis_app_control *control, const char *variable);
-
-/*!
  * \brief Set a variable on the channel associated with this control to value.
  * \param control Control for \c res_stasis.
  * \param variable The name of the variable

Modified: branches/13/main/manager_channels.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/main/manager_channels.c?view=diff&rev=420794&r1=420793&r2=420794
==============================================================================
--- branches/13/main/manager_channels.c (original)
+++ branches/13/main/manager_channels.c Mon Aug 11 13:32:37 2014
@@ -185,6 +185,10 @@
 						</enum>
 					</enumlist>
 				</parameter>
+				<parameter name="Forward" required="false">
+					<para>If the call was forwarded, where the call was
+					forwarded to.</para>
+				</parameter>
 			</syntax>
 			<see-also>
 				<ref type="application">Dial</ref>
@@ -986,6 +990,7 @@
 	struct ast_multi_channel_blob *obj = stasis_message_data(message);
 	const char *dialstatus;
 	const char *dialstring;
+	const char *forward;
 	struct ast_channel_snapshot *caller;
 	struct ast_channel_snapshot *peer;
 	RAII_VAR(struct ast_str *, caller_event_string, NULL, ast_free);
@@ -1007,6 +1012,7 @@
 
 	dialstatus = ast_json_string_get(ast_json_object_get(ast_multi_channel_blob_get_json(obj), "dialstatus"));
 	dialstring = ast_json_string_get(ast_json_object_get(ast_multi_channel_blob_get_json(obj), "dialstring"));
+	forward = ast_json_string_get(ast_json_object_get(ast_multi_channel_blob_get_json(obj), "forward"));
 	if (ast_strlen_zero(dialstatus)) {
 		manager_event(EVENT_FLAG_CALL, "DialBegin",
 				"%s"
@@ -1016,12 +1022,16 @@
 				ast_str_buffer(peer_event_string),
 				S_OR(dialstring, "unknown"));
 	} else {
+		int forwarded = !ast_strlen_zero(forward);
+
 		manager_event(EVENT_FLAG_CALL, "DialEnd",
 				"%s"
 				"%s"
+				"%s%s%s"
 				"DialStatus: %s\r\n",
 				caller_event_string ? ast_str_buffer(caller_event_string) : "",
 				ast_str_buffer(peer_event_string),
+				forwarded ? "Forward: " : "", S_OR(forward, ""), forwarded ? "\r\n" : "",
 				S_OR(dialstatus, "unknown"));
 	}
 

Modified: branches/13/main/stasis_channels.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/main/stasis_channels.c?view=diff&rev=420794&r1=420793&r2=420794
==============================================================================
--- branches/13/main/stasis_channels.c (original)
+++ branches/13/main/stasis_channels.c Mon Aug 11 13:32:37 2014
@@ -288,11 +288,6 @@
 	ast_json_unref(event->blob);
 }
 
-/*! \brief Dummy callback for receiving events */
-static void dummy_event_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
-{
-}
-
 void ast_channel_publish_dial_forward(struct ast_channel *caller, struct ast_channel *peer,
 	struct ast_channel *forwarded, const char *dialstring, const char *dialstatus,
 	const char *forward)
@@ -362,14 +357,7 @@
 		return;
 	}
 
-	if (forwarded) {
-		struct stasis_subscription *subscription = stasis_subscribe(ast_channel_topic(peer), dummy_event_cb, NULL);
-
-		stasis_publish(ast_channel_topic(peer), msg);
-		stasis_unsubscribe_and_join(subscription);
-	} else {
-		publish_message_for_channel_topics(msg, caller);
-	}
+	publish_message_for_channel_topics(msg, caller);
 }
 
 void ast_channel_publish_dial(struct ast_channel *caller, struct ast_channel *peer,

Modified: branches/13/res/ari/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/res/ari/resource_channels.c?view=diff&rev=420794&r1=420793&r2=420794
==============================================================================
--- branches/13/res/ari/resource_channels.c (original)
+++ branches/13/res/ari/resource_channels.c Mon Aug 11 13:32:37 2014
@@ -929,7 +929,8 @@
 {
 	RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
 	RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
-	RAII_VAR(char *, value, NULL, ast_free);
+	RAII_VAR(struct ast_str *, value, ast_str_create(32), ast_free);
+	RAII_VAR(struct ast_channel *, channel, NULL, ast_channel_cleanup);
 
 	ast_assert(response != NULL);
 
@@ -940,15 +941,41 @@
 		return;
 	}
 
-	control = find_control(response, args->channel_id);
-	if (control == NULL) {
-		/* response filled in by find_control */
-		return;
-	}
-
-	value = stasis_app_control_get_channel_var(control, args->variable);
-
-	if (!(json = ast_json_pack("{s: s}", "value", S_OR(value, "")))) {
+	if (ast_strlen_zero(args->channel_id)) {
+		ast_ari_response_error(
+			response, 400, "Bad Request",
+			"Channel ID is required");
+		return;
+	}
+
+	channel = ast_channel_get_by_name(args->channel_id);
+	if (!channel) {
+		ast_ari_response_error(
+			response, 404, "Channel Not Found",
+			"Provided channel was not found");
+		return;
+	}
+
+	/* You may be tempted to lock the channel you're about to read from. You
+	 * would be wrong. Some dialplan functions put the channel into
+	 * autoservice, which deadlocks if the channel is already locked.
+	 * ast_str_retrieve_variable() does its own locking, and the dialplan
+	 * functions need to as well. We should be fine without the lock.
+	 */
+
+	if (args->variable[strlen(args->variable) - 1] == ')') {
+		if (ast_func_read2(channel, args->variable, &value, 0)) {
+			ast_ari_response_alloc_failed(response);
+			return;
+		}
+	} else {
+		if (!ast_str_retrieve_variable(&value, 0, channel, NULL, args->variable)) {
+			ast_ari_response_alloc_failed(response);
+			return;
+		}
+	}
+
+	if (!(json = ast_json_pack("{s: s}", "value", S_OR(ast_str_buffer(value), "")))) {
 		ast_ari_response_alloc_failed(response);
 		return;
 	}

Modified: branches/13/res/res_pjsip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/res/res_pjsip_pubsub.c?view=diff&rev=420794&r1=420793&r2=420794
==============================================================================
--- branches/13/res/res_pjsip_pubsub.c (original)
+++ branches/13/res/res_pjsip_pubsub.c Mon Aug 11 13:32:37 2014
@@ -2032,10 +2032,13 @@
 	if (sub->tree->notification_batch_interval) {
 		return schedule_notification(sub->tree);
 	} else {
+		int res;
 		/* See the note in pubsub_on_rx_refresh() for why sub->tree is refbumped here */
 		ao2_ref(sub->tree, +1);
-		return send_notify(sub->tree, 0);
+		res = send_notify(sub->tree, 0);
 		ao2_ref(sub->tree, -1);
+		
+		return res;
 	}
 }
 

Modified: branches/13/res/stasis/app.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/res/stasis/app.c?view=diff&rev=420794&r1=420793&r2=420794
==============================================================================
--- branches/13/res/stasis/app.c (original)
+++ branches/13/res/stasis/app.c Mon Aug 11 13:32:37 2014
@@ -1073,9 +1073,7 @@
 
 	forwards = ao2_find(app->forwards, id, OBJ_SEARCH_KEY | OBJ_NOLOCK);
 	if (!forwards) {
-		ast_log(LOG_WARNING,
-			"App '%s' not subscribed to %s '%s'\n",
-			app->name, kind, id);
+		ast_debug(3, "App '%s' not subscribed to %s '%s'\n", app->name, kind, id);
 		return -1;
 	}
 	forwards->interested--;

Modified: branches/13/res/stasis/control.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/res/stasis/control.c?view=diff&rev=420794&r1=420793&r2=420794
==============================================================================
--- branches/13/res/stasis/control.c (original)
+++ branches/13/res/stasis/control.c Mon Aug 11 13:32:37 2014
@@ -565,34 +565,6 @@
 	return 0;
 }
 
-char *stasis_app_control_get_channel_var(struct stasis_app_control *control, const char *variable)
-{
-	RAII_VAR(struct ast_str *, tmp, ast_str_create(32), ast_free);
-
-	/* You may be tempted to lock the channel you're about to read from. You
-	 * would be wrong. Some dialplan functions put the channel into
-	 * autoservice, which deadlocks if the channel is already locked.
-	 * ast_str_retrieve_variable() does its own locking, and the dialplan
-	 * functions need to as well. We should be fine without the lock.
-	 */
-
-	if (!tmp) {
-		return NULL;
-	}
-
-	if (variable[strlen(variable) - 1] == ')') {
-		if (ast_func_read2(control->channel, variable, &tmp, 0)) {
-			return NULL;
-		}
-	} else {
-		if (!ast_str_retrieve_variable(&tmp, 0, control->channel, NULL, variable)) {
-			return NULL;
-		}
-	}
-
-	return ast_strdup(ast_str_buffer(tmp));
-}
-
 int stasis_app_control_set_channel_var(struct stasis_app_control *control, const char *variable, const char *value)
 {
 	return pbx_builtin_setvar_helper(control->channel, variable, value);




More information about the svn-commits mailing list