From 1ef09e4285fafaffe133fcaab95d790865cd5ad9 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 23 Mar 2022 13:43:08 +0000 Subject: mod_admin_shell: Add watch:stanzas() command --- plugins/mod_admin_shell.lua | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'plugins') diff --git a/plugins/mod_admin_shell.lua b/plugins/mod_admin_shell.lua index 9af77676..ae7e3c7c 100644 --- a/plugins/mod_admin_shell.lua +++ b/plugins/mod_admin_shell.lua @@ -1609,6 +1609,40 @@ function def_env.watch:log() end end +local stanza_watchers = module:require("mod_debug_stanzas/watcher"); +function def_env.watch:stanzas(target_spec, filter_spec) + local function handler(event_type, stanza, session) + if stanza then + if event_type == "sent" then + self.session.print(("\n"):format(session.id)); + elseif event_type == "received" then + self.session.print(("\n"):format(session.id)); + else + self.session.print(("\n"):format(event_type, session.id)); + end + self.session.print(stanza); + elseif session then + self.session.print("\n"); + elseif event_type then + self.session.print("\n"); + end + end + + stanza_watchers.add({ + target_spec = { + jid = target_spec; + }; + filter_spec = filter_spec and { + with_jid = filter_spec; + }; + }, handler); + + while self.session.is_connected() do + async.sleep(3); + end + + stanza_watchers.remove(handler); +end def_env.debug = {}; @@ -1953,6 +1987,10 @@ function def_env.stats:show(name_filter) end +function module.unload() + stanza_watchers.cleanup(); +end + ------------- -- cgit v1.2.3