Software / code / prosody
Comparison
plugins/mod_admin_shell.lua @ 12464:f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Wed, 23 Mar 2022 13:43:08 +0000 |
| parent | 12399:d99772b739e0 |
| child | 12480:7e9ebdc75ce4 |
comparison
equal
deleted
inserted
replaced
| 12463:788048158982 | 12464:f4c59af273a3 |
|---|---|
| 1607 if not logger.remove_sink(sink) then | 1607 if not logger.remove_sink(sink) then |
| 1608 module:log("warn", "Unable to remove watch:log() sink"); | 1608 module:log("warn", "Unable to remove watch:log() sink"); |
| 1609 end | 1609 end |
| 1610 end | 1610 end |
| 1611 | 1611 |
| 1612 local stanza_watchers = module:require("mod_debug_stanzas/watcher"); | |
| 1613 function def_env.watch:stanzas(target_spec, filter_spec) | |
| 1614 local function handler(event_type, stanza, session) | |
| 1615 if stanza then | |
| 1616 if event_type == "sent" then | |
| 1617 self.session.print(("\n<!-- sent to %s -->"):format(session.id)); | |
| 1618 elseif event_type == "received" then | |
| 1619 self.session.print(("\n<!-- received from %s -->"):format(session.id)); | |
| 1620 else | |
| 1621 self.session.print(("\n<!-- %s (%s) -->"):format(event_type, session.id)); | |
| 1622 end | |
| 1623 self.session.print(stanza); | |
| 1624 elseif session then | |
| 1625 self.session.print("\n<!-- session "..session.id.." "..event_type.." -->"); | |
| 1626 elseif event_type then | |
| 1627 self.session.print("\n<!-- "..event_type.." -->"); | |
| 1628 end | |
| 1629 end | |
| 1630 | |
| 1631 stanza_watchers.add({ | |
| 1632 target_spec = { | |
| 1633 jid = target_spec; | |
| 1634 }; | |
| 1635 filter_spec = filter_spec and { | |
| 1636 with_jid = filter_spec; | |
| 1637 }; | |
| 1638 }, handler); | |
| 1639 | |
| 1640 while self.session.is_connected() do | |
| 1641 async.sleep(3); | |
| 1642 end | |
| 1643 | |
| 1644 stanza_watchers.remove(handler); | |
| 1645 end | |
| 1612 | 1646 |
| 1613 def_env.debug = {}; | 1647 def_env.debug = {}; |
| 1614 | 1648 |
| 1615 function def_env.debug:logevents(host) | 1649 function def_env.debug:logevents(host) |
| 1616 helpers.log_host_events(host); | 1650 helpers.log_host_events(host); |
| 1951 end | 1985 end |
| 1952 return displayed_stats; | 1986 return displayed_stats; |
| 1953 end | 1987 end |
| 1954 | 1988 |
| 1955 | 1989 |
| 1990 function module.unload() | |
| 1991 stanza_watchers.cleanup(); | |
| 1992 end | |
| 1993 | |
| 1956 | 1994 |
| 1957 ------------- | 1995 ------------- |
| 1958 | 1996 |
| 1959 function printbanner(session) | 1997 function printbanner(session) |
| 1960 local option = module:get_option_string("console_banner", "full"); | 1998 local option = module:get_option_string("console_banner", "full"); |