Software /
code /
prosody-modules
Comparison
mod_rawdebug/mod_rawdebug.lua @ 1444:56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 23 Jun 2014 20:22:19 +0200 |
child | 1445:ae1d7665cde9 |
comparison
equal
deleted
inserted
replaced
1443:faf1a5d89cd7 | 1444:56c394b9e60d |
---|---|
1 | |
2 local tostring = tostring; | |
3 local filters = require "util.filters"; | |
4 | |
5 local def_env = module:shared("/*/admin_telnet/env"); | |
6 local rawdebug_enabled = module:shared("sessions"); | |
7 local full_sessions = prosody.full_sessions; | |
8 local log = module._log; | |
9 | |
10 local rawdebug = {}; | |
11 def_env.rawdebug = rawdebug; | |
12 | |
13 local function new_logger(log, prefix) | |
14 local msg = prefix .. ": %s"; | |
15 return function (data) | |
16 log("debug", msg, tostring(data)) | |
17 return data; | |
18 end | |
19 end | |
20 | |
21 function rawdebug:enable(sessionid) | |
22 local session = full_sessions[sessionid]; | |
23 if not session then | |
24 return nil, "No such session"; | |
25 end | |
26 local f = { | |
27 ["stanzas/in"] = new_logger(session.log or log, "RECV"); | |
28 ["stanzas/out"] = new_logger(session.log or log, "SEND"); | |
29 }; | |
30 for type, callback in pairs(f) do | |
31 filters.add_filter(session, type, callback) | |
32 end | |
33 rawdebug_enabled[session] = f; | |
34 end | |
35 | |
36 function rawdebug:disable(sessionid) | |
37 local session = full_sessions[sessionid]; | |
38 if not session then | |
39 return nil, "No such session"; | |
40 end | |
41 local f = rawdebug_enabled[session]; | |
42 for type, callback in pairs(f) do | |
43 filters.remove_filter(session, type, callback) | |
44 end | |
45 end | |
46 | |
47 function module.unload() | |
48 def_env.rawdebug = nil; | |
49 for session, f in pairs(rawdebug_enabled) do | |
50 for type, callback in pairs(f) do | |
51 filters.remove_filter(session, type, callback) | |
52 end | |
53 end | |
54 end | |
55 |