Annotate

plugins/mod_stanza_debug.lua @ 8348:c3de5b454ec4

mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
author Kim Alvefur <zash@zash.se>
date Mon, 23 Oct 2017 15:23:03 +0200
child 10111:0f335815244f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8348
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 module:set_global();
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local tostring = tostring;
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local filters = require "util.filters";
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 local function log_send(t, session)
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 if t and t ~= "" and t ~= " " then
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 session.log("debug", "SEND: %s", tostring(t));
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 end
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 return t;
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 end
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 local function log_recv(t, session)
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 if t and t ~= "" and t ~= " " then
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 session.log("debug", "RECV: %s", tostring(t));
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 end
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 return t;
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 end
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 local function init_raw_logging(session)
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 filters.add_filter(session, "stanzas/in", log_recv, -10000);
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 filters.add_filter(session, "stanzas/out", log_send, 10000);
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 end
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 filters.add_filter_hook(init_raw_logging);
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 function module.unload()
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 filters.remove_filter_hook(init_raw_logging);
c3de5b454ec4 mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 end