[asterisk-commits] mjordan: branch group/media_formats-reviewed-trunk r418112 - in /team/group/m...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 7 09:54:59 CDT 2014


Author: mjordan
Date: Mon Jul  7 09:54:51 2014
New Revision: 418112

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=418112
Log:
Re-enable automerge

Modified:
    team/group/media_formats-reviewed-trunk/   (props changed)
    team/group/media_formats-reviewed-trunk/channels/chan_pjsip.c
    team/group/media_formats-reviewed-trunk/include/asterisk/stasis_app.h
    team/group/media_formats-reviewed-trunk/main/cel.c
    team/group/media_formats-reviewed-trunk/res/ari/resource_channels.c
    team/group/media_formats-reviewed-trunk/res/res_pjsip_session.c
    team/group/media_formats-reviewed-trunk/res/res_stasis.c
    team/group/media_formats-reviewed-trunk/res/stasis/app.c
    team/group/media_formats-reviewed-trunk/tests/test_cel.c

Propchange: team/group/media_formats-reviewed-trunk/
------------------------------------------------------------------------------
    automerge = *

Propchange: team/group/media_formats-reviewed-trunk/
------------------------------------------------------------------------------
Binary property 'branch-12-merged' - no diff available.

Propchange: team/group/media_formats-reviewed-trunk/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Jul  7 09:54:51 2014
@@ -1,1 +1,1 @@
-/trunk:1-418068
+/trunk:1-418111

Modified: team/group/media_formats-reviewed-trunk/channels/chan_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/channels/chan_pjsip.c?view=diff&rev=418112&r1=418111&r2=418112
==============================================================================
--- team/group/media_formats-reviewed-trunk/channels/chan_pjsip.c (original)
+++ team/group/media_formats-reviewed-trunk/channels/chan_pjsip.c Mon Jul  7 09:54:51 2014
@@ -1530,6 +1530,7 @@
 	int res = ast_sip_session_create_invite(session, &tdata);
 
 	if (res) {
+		ast_set_hangupsource(session->channel, ast_channel_name(session->channel), 0);
 		ast_queue_hangup(session->channel);
 	} else {
 		update_initial_connected_line(session);
@@ -1965,6 +1966,7 @@
 
 	chan_pjsip_remove_hold(ast_channel_uniqueid(session->channel));
 
+	ast_set_hangupsource(session->channel, ast_channel_name(session->channel), 0);
 	if (!ast_channel_hangupcause(session->channel) && session->inv_session) {
 		int cause = hangup_sip2cause(session->inv_session->cause);
 
@@ -2092,6 +2094,8 @@
 static void chan_pjsip_incoming_response(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
 {
 	struct pjsip_status_line status = rdata->msg_info.msg->line.status;
+	struct ast_control_pvt_cause_code *cause_code;
+	int data_size = sizeof(*cause_code);
 
 	if (!session->channel) {
 		return;
@@ -2115,6 +2119,21 @@
 	default:
 		break;
 	}
+
+	/* Build and send the tech-specific cause information */
+	/* size of the string making up the cause code is "SIP " number + " " + reason length */
+	data_size += 4 + 4 + pj_strlen(&status.reason);
+	cause_code = ast_alloca(data_size);
+	memset(cause_code, 0, data_size);
+
+	ast_copy_string(cause_code->chan_name, ast_channel_name(session->channel), AST_CHANNEL_NAME);
+
+	snprintf(cause_code->code, data_size - sizeof(*cause_code) + 1, "SIP %d %.*s", status.code,
+		(int) pj_strlen(&status.reason), pj_strbuf(&status.reason));
+
+	cause_code->ast_cause = hangup_sip2cause(status.code);
+	ast_queue_control_data(session->channel, AST_CONTROL_PVT_CAUSE_CODE, cause_code, data_size);
+	ast_channel_hangupcause_hash_set(session->channel, cause_code, data_size);
 }
 
 static int chan_pjsip_incoming_ack(struct ast_sip_session *session, struct pjsip_rx_data *rdata)

Modified: team/group/media_formats-reviewed-trunk/include/asterisk/stasis_app.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/include/asterisk/stasis_app.h?view=diff&rev=418112&r1=418111&r2=418112
==============================================================================
--- team/group/media_formats-reviewed-trunk/include/asterisk/stasis_app.h (original)
+++ team/group/media_formats-reviewed-trunk/include/asterisk/stasis_app.h Mon Jul  7 09:54:51 2014
@@ -297,6 +297,21 @@
 	const char **event_source_uris, int event_sources_count,
 	struct ast_json **json);
 
+/*!
+ * \brief Directly subscribe an application to a channel
+ *
+ * \param app_name Name of the application to subscribe.
+ * \param chan The channel to subscribe to
+ *
+ * \return \ref stasis_app_subscribe_res return code.
+ *
+ * \note This method can be used when you already hold a channel and its
+ *       lock. This bypasses the channel lookup that would normally be
+ *       performed by \ref stasis_app_subscribe.
+ */
+enum stasis_app_subscribe_res stasis_app_subscribe_channel(const char *app_name,
+	struct ast_channel *chan);
+
 /*! @} */
 
 /*! @{ */

Modified: team/group/media_formats-reviewed-trunk/main/cel.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/main/cel.c?view=diff&rev=418112&r1=418111&r2=418112
==============================================================================
--- team/group/media_formats-reviewed-trunk/main/cel.c (original)
+++ team/group/media_formats-reviewed-trunk/main/cel.c Mon Jul  7 09:54:51 2014
@@ -1270,6 +1270,35 @@
 	}
 }
 
+static int is_valid_dialstatus(struct ast_multi_channel_blob *blob)
+{
+	const char *dialstatus = get_blob_variable(blob, "dialstatus");
+	int res = 0;
+
+	if (ast_strlen_zero(dialstatus)) {
+		res = 0;
+	} else if (!strcasecmp(dialstatus, "CHANUNAVAIL")) {
+		res = 1;
+	} else if (!strcasecmp(dialstatus, "CONGESTION")) {
+		res = 1;
+	} else if (!strcasecmp(dialstatus, "NOANSWER")) {
+		res = 1;
+	} else if (!strcasecmp(dialstatus, "BUSY")) {
+		res = 1;
+	} else if (!strcasecmp(dialstatus, "ANSWER")) {
+		res = 1;
+	} else if (!strcasecmp(dialstatus, "CANCEL")) {
+		res = 1;
+	} else if (!strcasecmp(dialstatus, "DONTCALL")) {
+		res = 1;
+	} else if (!strcasecmp(dialstatus, "TORTURE")) {
+		res = 1;
+	} else if (!strcasecmp(dialstatus, "INVALIDARGS")) {
+		res = 1;
+	}
+	return res;
+}
+
 static void cel_dial_cb(void *data, struct stasis_subscription *sub,
 	struct stasis_message *message)
 {
@@ -1298,11 +1327,9 @@
 		}
 	}
 
-	if (ast_strlen_zero(get_blob_variable(blob, "dialstatus"))) {
-		return;
-	}
-
-	save_dialstatus(blob);
+	if (is_valid_dialstatus(blob)) {
+		save_dialstatus(blob);
+	}
 }
 
 static void cel_generic_cb(

Modified: team/group/media_formats-reviewed-trunk/res/ari/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/res/ari/resource_channels.c?view=diff&rev=418112&r1=418111&r2=418112
==============================================================================
--- team/group/media_formats-reviewed-trunk/res/ari/resource_channels.c (original)
+++ team/group/media_formats-reviewed-trunk/res/ari/resource_channels.c Mon Jul  7 09:54:51 2014
@@ -43,6 +43,7 @@
 #include "asterisk/stasis_channels.h"
 #include "asterisk/causes.h"
 #include "asterisk/format_cache.h"
+#include "asterisk/core_local.h"
 #include "resource_channels.h"
 
 #include <limits.h>
@@ -775,6 +776,7 @@
 		ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT), ao2_cleanup);
 	char *stuff;
 	struct ast_channel *chan;
+	struct ast_channel *local_peer;
 	RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
 	struct ast_assigned_ids assignedids = {
 		.uniqueid = args_channel_id,
@@ -859,20 +861,24 @@
 		return;
 	}
 
+	/* See if this is a Local channel and if so, get the peer */
+	local_peer = ast_local_get_peer(chan);
+
+	if (!ast_strlen_zero(args_app)) {
+		stasis_app_subscribe_channel(args_app, chan);
+		if (local_peer) {
+			stasis_app_subscribe_channel(args_app, local_peer);
+		}
+	}
+
 	snapshot = ast_channel_snapshot_get_latest(ast_channel_uniqueid(chan));
 	ast_channel_unlock(chan);
 
-	if (!ast_strlen_zero(args_app)) {
-		/* channel: + channel ID + null terminator */
-		char uri[9 + strlen(ast_channel_uniqueid(chan))];
-		const char *uris[1] = { uri, };
-
-		sprintf(uri, "channel:%s", ast_channel_uniqueid(chan));
-		stasis_app_subscribe(args_app, uris, 1, NULL);
-	}
-
 	ast_ari_response_ok(response, ast_channel_snapshot_to_json(snapshot, NULL));
 	ast_channel_unref(chan);
+	if (local_peer) {
+		ast_channel_unref(local_peer);
+	}
 }
 
 void ast_ari_channels_originate_with_id(struct ast_variable *headers,

Modified: team/group/media_formats-reviewed-trunk/res/res_pjsip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/res/res_pjsip_session.c?view=diff&rev=418112&r1=418111&r2=418112
==============================================================================
--- team/group/media_formats-reviewed-trunk/res/res_pjsip_session.c (original)
+++ team/group/media_formats-reviewed-trunk/res/res_pjsip_session.c Mon Jul  7 09:54:51 2014
@@ -2134,6 +2134,7 @@
 	if ((status != PJ_SUCCESS) || (pjmedia_sdp_neg_get_active_local(inv->neg, &local) != PJ_SUCCESS) ||
 		(pjmedia_sdp_neg_get_active_remote(inv->neg, &remote) != PJ_SUCCESS)) {
 		ast_channel_hangupcause_set(session->channel, AST_CAUSE_BEARERCAPABILITY_NOTAVAIL);
+		ast_set_hangupsource(session->channel, ast_channel_name(session->channel), 0);
 		ast_queue_hangup(session->channel);
 		return;
 	}

Modified: team/group/media_formats-reviewed-trunk/res/res_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/res/res_stasis.c?view=diff&rev=418112&r1=418111&r2=418112
==============================================================================
--- team/group/media_formats-reviewed-trunk/res/res_stasis.c (original)
+++ team/group/media_formats-reviewed-trunk/res/res_stasis.c Mon Jul  7 09:54:51 2014
@@ -1225,6 +1225,29 @@
 	return STASIS_ASR_OK;
 }
 
+enum stasis_app_subscribe_res stasis_app_subscribe_channel(const char *app_name,
+	struct ast_channel *chan)
+{
+	RAII_VAR(struct stasis_app *, app, find_app_by_name(app_name), ao2_cleanup);
+	int res;
+
+	if (!app) {
+		return STASIS_ASR_APP_NOT_FOUND;
+	}
+
+	ast_debug(3, "%s: Subscribing to %s\n", app_name, ast_channel_uniqueid(chan));
+
+	res = app_subscribe_channel(app, chan);
+	if (res != 0) {
+		ast_log(LOG_ERROR, "Error subscribing app '%s' to channel '%s'\n",
+			app_name, ast_channel_uniqueid(chan));
+		return STASIS_ASR_INTERNAL_ERROR;
+	}
+
+	return STASIS_ASR_OK;
+}
+
+
 /*!
  * \internal
  * \brief Subscribe an app to an event source.

Modified: team/group/media_formats-reviewed-trunk/res/stasis/app.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/res/stasis/app.c?view=diff&rev=418112&r1=418111&r2=418112
==============================================================================
--- team/group/media_formats-reviewed-trunk/res/stasis/app.c (original)
+++ team/group/media_formats-reviewed-trunk/res/stasis/app.c Mon Jul  7 09:54:51 2014
@@ -35,6 +35,8 @@
 #include "asterisk/stasis_channels.h"
 #include "asterisk/stasis_endpoints.h"
 #include "asterisk/stasis_message_router.h"
+
+static int unsubscribe(struct stasis_app *app, const char *kind, const char *id, int terminate);
 
 struct stasis_app {
 	/*! Aggregation topic for this application. */
@@ -449,7 +451,7 @@
 static channel_snapshot_monitor channel_monitors[] = {
 	channel_state,
 	channel_dialplan,
-	channel_callerid
+	channel_callerid,
 };
 
 static void sub_channel_update_handler(void *data,
@@ -486,6 +488,10 @@
 			app_send(app, msg);
 		}
 	}
+
+	if (!new_snapshot && old_snapshot) {
+		unsubscribe(app, "channel", old_snapshot->uniqueid, 1);
+	}
 }
 
 static struct ast_json *simple_endpoint_event(
@@ -513,6 +519,7 @@
 	struct stasis_app *app = data;
 	struct stasis_cache_update *update;
 	struct ast_endpoint_snapshot *new_snapshot;
+	struct ast_endpoint_snapshot *old_snapshot;
 	const struct timeval *tv;
 
 	ast_assert(stasis_message_type(message) == stasis_cache_update_type());
@@ -522,17 +529,22 @@
 	ast_assert(update->type == ast_endpoint_snapshot_type());
 
 	new_snapshot = stasis_message_data(update->new_snapshot);
-	tv = update->new_snapshot ?
-		stasis_message_timestamp(update->new_snapshot) :
-		stasis_message_timestamp(message);
-
-	json = simple_endpoint_event("EndpointStateChange", new_snapshot, tv);
-
-	if (!json) {
-		return;
-	}
-
-	app_send(app, json);
+	old_snapshot = stasis_message_data(update->old_snapshot);
+
+	if (new_snapshot) {
+		tv = stasis_message_timestamp(update->new_snapshot);
+
+		json = simple_endpoint_event("EndpointStateChange", new_snapshot, tv);
+		if (!json) {
+			return;
+		}
+
+		app_send(app, json);
+	}
+
+	if (!new_snapshot && old_snapshot) {
+		unsubscribe(app, "endpoint", old_snapshot->id, 1);
+	}
 }
 
 static struct ast_json *simple_bridge_event(
@@ -580,11 +592,13 @@
 		json = simple_bridge_event("BridgeCreated", new_snapshot, tv);
 	}
 
-	if (!json) {
-		return;
-	}
-
-	app_send(app, json);
+	if (json) {
+		app_send(app, json);
+	}
+
+	if (!new_snapshot && old_snapshot) {
+		unsubscribe(app, "bridge", old_snapshot->uniqueid, 1);
+	}
 }
 
 
@@ -982,7 +996,7 @@
 	return app_subscribe_channel(app, obj);
 }
 
-static int unsubscribe(struct stasis_app *app, const char *kind, const char *id)
+static int unsubscribe(struct stasis_app *app, const char *kind, const char *id, int terminate)
 {
 	RAII_VAR(struct app_forwards *, forwards, NULL, ao2_cleanup);
 	SCOPED_AO2LOCK(lock, app->forwards);
@@ -997,7 +1011,7 @@
 	forwards->interested--;
 
 	ast_debug(3, "%s '%s': is %d interested in %s\n", kind, id, forwards->interested, app->name);
-	if (forwards->interested == 0) {
+	if (forwards->interested == 0 || terminate) {
 		/* No one is interested any more; unsubscribe */
 		ast_debug(3, "%s '%s' unsubscribed from %s\n", kind, id, app->name);
 		forwards_unsubscribe(forwards);
@@ -1024,7 +1038,7 @@
 		return -1;
 	}
 
-	return unsubscribe(app, "channel", channel_id);
+	return unsubscribe(app, "channel", channel_id, 0);
 }
 
 int app_is_subscribed_channel_id(struct stasis_app *app, const char *channel_id)
@@ -1093,7 +1107,7 @@
 		return -1;
 	}
 
-	return unsubscribe(app, "bridge", bridge_id);
+	return unsubscribe(app, "bridge", bridge_id, 0);
 }
 
 int app_is_subscribed_bridge_id(struct stasis_app *app, const char *bridge_id)
@@ -1153,7 +1167,7 @@
 		return -1;
 	}
 
-	return unsubscribe(app, "endpoint", endpoint_id);
+	return unsubscribe(app, "endpoint", endpoint_id, 0);
 }
 
 int app_is_subscribed_endpoint_id(struct stasis_app *app, const char *endpoint_id)

Modified: team/group/media_formats-reviewed-trunk/tests/test_cel.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/tests/test_cel.c?view=diff&rev=418112&r1=418111&r2=418112
==============================================================================
--- team/group/media_formats-reviewed-trunk/tests/test_cel.c (original)
+++ team/group/media_formats-reviewed-trunk/tests/test_cel.c Mon Jul  7 09:54:51 2014
@@ -773,6 +773,40 @@
 	return AST_TEST_PASS;
 }
 
+AST_TEST_DEFINE(test_cel_dial_unanswered_filter)
+{
+	RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
+	RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
+	struct ast_party_caller caller = ALICE_CALLERID;
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = __func__;
+		info->category = TEST_CATEGORY;
+		info->summary = "Test CEL for a dial that isn't answered";
+		info->description =
+			"Test CEL records for a channel that\n"
+			"performs a dial operation that isn't answered\n";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	CREATE_ALICE_CHANNEL(chan_caller, &caller);
+
+	EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
+
+	START_DIALED(chan_caller, chan_callee);
+
+	ast_channel_state_set(chan_caller, AST_STATE_RINGING);
+	ast_channel_publish_dial(chan_caller, chan_callee, NULL, "NOT A VALID DIAL STATUS");
+	ast_channel_publish_dial(chan_caller, chan_callee, NULL, "NOANSWER");
+
+	HANGUP_CHANNEL(chan_caller, AST_CAUSE_NO_ANSWER, "NOANSWER");
+	HANGUP_CHANNEL(chan_callee, AST_CAUSE_NO_ANSWER, "");
+
+	return AST_TEST_PASS;
+}
 
 AST_TEST_DEFINE(test_cel_dial_busy)
 {
@@ -2040,6 +2074,7 @@
 #endif
 
 	AST_TEST_UNREGISTER(test_cel_dial_unanswered);
+	AST_TEST_UNREGISTER(test_cel_dial_unanswered_filter);
 	AST_TEST_UNREGISTER(test_cel_dial_congestion);
 	AST_TEST_UNREGISTER(test_cel_dial_busy);
 	AST_TEST_UNREGISTER(test_cel_dial_unavailable);
@@ -2114,6 +2149,7 @@
 #endif
 
 	AST_TEST_REGISTER(test_cel_dial_unanswered);
+	AST_TEST_REGISTER(test_cel_dial_unanswered_filter);
 	AST_TEST_REGISTER(test_cel_dial_congestion);
 	AST_TEST_REGISTER(test_cel_dial_busy);
 	AST_TEST_REGISTER(test_cel_dial_unavailable);




More information about the asterisk-commits mailing list