]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
app_chanspy: Spyee information missing in ChanSpyStop AMI Event
authorSean Bright <sean.bright@gmail.com>
Fri, 11 Dec 2020 19:27:56 +0000 (14:27 -0500)
committerGeorge Joseph <gjoseph@digium.com>
Thu, 17 Dec 2020 20:03:38 +0000 (14:03 -0600)
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

apps/app_chanspy.c
main/manager_channels.c
res/res_stasis_snoop.c

index c66d25030dbe932d866692b76fb616b9de209631..e02f25d920fed91283effebfa232a56b3cdc97b0 100644 (file)
@@ -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;
 }
 
index 2655cf67231217cc6da6816041bbfdc620893018..73b76c88b9fae2bc430932f41a86a4a5ebfc8708 100644 (file)
@@ -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,
index b234de111815953f05e6543211b97cf7aca2f1a8..7e8761165dcb2d4a235782249a98c7c0fd89462a 100644 (file)
@@ -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 */