[Asterisk-code-review] app_chanspy: Spyee information missing in ChanSpyStop AMI Event (asterisk[16])

Friendly Automation asteriskteam at digium.com
Thu Dec 17 12:07:55 CST 2020


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/14889 )

Change subject: app_chanspy: Spyee information missing in ChanSpyStop AMI Event
......................................................................

app_chanspy: Spyee information missing in ChanSpyStop AMI Event

The documentation in the wiki says there should be spyee-channel
information elements in the ChanSpyStop AMI event.

    https://wiki.asterisk.org/wiki/x/Xc5uAg

However, this is not the case in Asterisk <= 16.10.0 Version. We're
using these Spyee* arguments since Asterisk 11.x, so these arguments
vanished in Asterisk 12 or higher.

For maximum compatibility, we still send the ChanSpyStop event even if
we are not able to find any 'Spyee' information.

ASTERISK-28883 #close

Change-Id: I81ce397a3fd614c094d043ffe5b1b1d76188835f
---
M apps/app_chanspy.c
M main/manager_channels.c
M res/res_stasis_snoop.c
3 files changed, 25 insertions(+), 11 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, approved
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, but someone else must approve
  Friendly Automation: Approved for Submit



diff --git a/apps/app_chanspy.c b/apps/app_chanspy.c
index c66d250..e02f25d 100644
--- a/apps/app_chanspy.c
+++ b/apps/app_chanspy.c
@@ -845,13 +845,13 @@
 	ast_audiohook_unlock(&csth.spy_audiohook);
 	ast_audiohook_destroy(&csth.spy_audiohook);
 
+	ast_verb(2, "Done Spying on channel %s\n", name);
+	publish_chanspy_message(chan, spyee_autochan->chan, 0);
+
 	if (spyee_bridge_autochan) {
 		ast_autochan_destroy(spyee_bridge_autochan);
 	}
 
-	ast_verb(2, "Done Spying on channel %s\n", name);
-	publish_chanspy_message(chan, NULL, 0);
-
 	return running;
 }
 
diff --git a/main/manager_channels.c b/main/manager_channels.c
index c964033..25f94da 100644
--- a/main/manager_channels.c
+++ b/main/manager_channels.c
@@ -825,12 +825,15 @@
 		struct stasis_message *message)
 {
 	RAII_VAR(struct ast_str *, spyer_channel_string, NULL, ast_free);
+	RAII_VAR(struct ast_str *, spyee_channel_string, NULL, ast_free);
 	struct ast_channel_snapshot *spyer;
+	struct ast_channel_snapshot *spyee;
+	const char *spyee_info = "";
 	struct ast_multi_channel_blob *payload = stasis_message_data(message);
 
 	spyer = ast_multi_channel_blob_get_channel(payload, "spyer_channel");
 	if (!spyer) {
-		ast_log(AST_LOG_WARNING, "Received ChanSpy Start event with no spyer channel!\n");
+		ast_log(AST_LOG_WARNING, "Received ChanSpy Stop event with no spyer channel!\n");
 		return;
 	}
 
@@ -839,9 +842,18 @@
 		return;
 	}
 
+	spyee = ast_multi_channel_blob_get_channel(payload, "spyee_channel");
+	if (spyee) {
+		spyee_channel_string = ast_manager_build_channel_state_string_prefix(spyee, "Spyee");
+		if (spyee_channel_string) {
+			spyee_info = ast_str_buffer(spyee_channel_string);
+		}
+	}
+
 	manager_event(EVENT_FLAG_CALL, "ChanSpyStop",
-		      "%s",
-		      ast_str_buffer(spyer_channel_string));
+		      "%s%s",
+		      ast_str_buffer(spyer_channel_string),
+		      spyee_info);
 }
 
 static void channel_chanspy_start_cb(void *data, struct stasis_subscription *sub,
diff --git a/res/res_stasis_snoop.c b/res/res_stasis_snoop.c
index b234de1..7e87611 100644
--- a/res/res_stasis_snoop.c
+++ b/res/res_stasis_snoop.c
@@ -66,12 +66,12 @@
 	struct ast_str *app;
 	/*! \brief Snoop channel */
 	struct ast_channel *chan;
+	/*! \brief The channel that the Snoop channel is snooping on */
+	struct ast_channel *spyee_chan;
 	/*! \brief Whether the spy capability is active or not */
 	unsigned int spy_active:1;
 	/*! \brief Whether the whisper capability is active or not */
 	unsigned int whisper_active:1;
-	/*! \brief Uniqueid of the channel this snoop is snooping on */
-	char uniqueid[AST_MAX_UNIQUEID];
 	/*! \brief A frame of silence to use when the audiohook returns null */
 	struct ast_frame silence;
 };
@@ -100,6 +100,7 @@
 
 	ast_free(snoop->app);
 
+	ast_channel_cleanup(snoop->spyee_chan);
 	ast_channel_cleanup(snoop->chan);
 }
 
@@ -134,7 +135,7 @@
 	}
 	ast_multi_channel_blob_add_channel(payload, "spyer_channel", snoop_snapshot);
 
-	spyee_snapshot = ast_channel_snapshot_get_latest(snoop->uniqueid);
+	spyee_snapshot = ast_channel_snapshot_get_latest(ast_channel_uniqueid(snoop->spyee_chan));
 	if (spyee_snapshot) {
 		ast_multi_channel_blob_add_channel(payload, "spyee_channel", spyee_snapshot);
 	}
@@ -354,8 +355,6 @@
 		return NULL;
 	}
 
-	ast_copy_string(snoop->uniqueid, ast_channel_uniqueid(chan), sizeof(snoop->uniqueid));
-
 	/* To keep the channel valid on the Snoop structure until it is destroyed we bump the ref up here */
 	ast_channel_ref(snoop->chan);
 
@@ -425,6 +424,9 @@
 		return NULL;
 	}
 
+	/* Keep a reference to the channel we are spying on */
+	snoop->spyee_chan = ast_channel_ref(chan);
+
 	publish_chanspy_message(snoop, 1);
 
 	/* The caller of this has a reference as well */

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/14889
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I81ce397a3fd614c094d043ffe5b1b1d76188835f
Gerrit-Change-Number: 14889
Gerrit-PatchSet: 6
Gerrit-Owner: Hendrik Wedhorn <hwedhorn at addix.net>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-CC: Sean Bright <sean.bright at gmail.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20201217/22ef8241/attachment.html>


More information about the asterisk-code-review mailing list