Mercurial > prosody-modules
annotate mod_rawdebug/mod_rawdebug.lua @ 1476:08ca6dd36e39
mod_mam_archive: Fixing issues noted in code review for 153df603f73d3b69c434f2790cff0270de14bb75
author | syn@syn.im |
---|---|
date | Wed, 30 Jul 2014 21:27:56 +0200 |
parents | ae1d7665cde9 |
children | c5c583fae25d |
rev | line source |
---|---|
1445
ae1d7665cde9
mod_rawdebug: Make global (like mod_admin_telnet)
Kim Alvefur <zash@zash.se>
parents:
1444
diff
changeset
|
1 module:set_global(); |
1444
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local tostring = tostring; |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local filters = require "util.filters"; |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 |
1445
ae1d7665cde9
mod_rawdebug: Make global (like mod_admin_telnet)
Kim Alvefur <zash@zash.se>
parents:
1444
diff
changeset
|
6 local def_env = module:shared("admin_telnet/env"); |
1444
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 local rawdebug_enabled = module:shared("sessions"); |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 local full_sessions = prosody.full_sessions; |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 local log = module._log; |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 local rawdebug = {}; |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 def_env.rawdebug = rawdebug; |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 local function new_logger(log, prefix) |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 local msg = prefix .. ": %s"; |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 return function (data) |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 log("debug", msg, tostring(data)) |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 return data; |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 end |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 end |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 function rawdebug:enable(sessionid) |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 local session = full_sessions[sessionid]; |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 if not session then |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 return nil, "No such session"; |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 end |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 local f = { |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 ["stanzas/in"] = new_logger(session.log or log, "RECV"); |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 ["stanzas/out"] = new_logger(session.log or log, "SEND"); |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 }; |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 for type, callback in pairs(f) do |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 filters.add_filter(session, type, callback) |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 end |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 rawdebug_enabled[session] = f; |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 end |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 function rawdebug:disable(sessionid) |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 local session = full_sessions[sessionid]; |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 if not session then |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 return nil, "No such session"; |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 end |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 local f = rawdebug_enabled[session]; |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 for type, callback in pairs(f) do |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 filters.remove_filter(session, type, callback) |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 end |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 end |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 function module.unload() |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 def_env.rawdebug = nil; |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 for session, f in pairs(rawdebug_enabled) do |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 for type, callback in pairs(f) do |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 filters.remove_filter(session, type, callback) |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 end |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 end |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 end |
56c394b9e60d
mod_rawdebug: Adds a telnet command for enabling logging of entire stanzas that are sent and received
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 |