From: Sean Bright Date: Fri, 11 Dec 2020 19:27:56 +0000 (-0500) Subject: app_chanspy: Spyee information missing in ChanSpyStop AMI Event X-Git-Tag: 19.0.0-rc1~257 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=357510cec336fb9c93c13f1baf723f1746cd68af;p=thirdparty%2Fasterisk.git 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 --- diff --git a/apps/app_chanspy.c b/apps/app_chanspy.c index c66d25030d..e02f25d920 100644 --- a/apps/app_chanspy.c +++ b/apps/app_chanspy.c @@ -845,13 +845,13 @@ static int channel_spy(struct ast_channel *chan, struct ast_autochan *spyee_auto 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 2655cf6723..73b76c88b9 100644 --- a/main/manager_channels.c +++ b/main/manager_channels.c @@ -808,12 +808,15 @@ static void channel_chanspy_stop_cb(void *data, struct stasis_subscription *sub, 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; } @@ -822,9 +825,18 @@ static void channel_chanspy_stop_cb(void *data, struct stasis_subscription *sub, 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 b234de1118..7e8761165d 100644 --- a/res/res_stasis_snoop.c +++ b/res/res_stasis_snoop.c @@ -66,12 +66,12 @@ struct stasis_app_snoop { 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 @@ static void snoop_destroy(void *obj) ast_free(snoop->app); + ast_channel_cleanup(snoop->spyee_chan); ast_channel_cleanup(snoop->chan); } @@ -134,7 +135,7 @@ static void publish_chanspy_message(struct stasis_app_snoop *snoop, int start) } 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 @@ struct ast_channel *stasis_app_control_snoop(struct ast_channel *chan, 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 @@ struct ast_channel *stasis_app_control_snoop(struct ast_channel *chan, 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 */