Mercurial > prosody-hg
comparison plugins/mod_scansion_record.lua @ 9621:f85e12d9eede
Merge 0.11->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 12 Nov 2018 18:26:39 +0100 |
| parents | 7172077c0a53 |
| children | d229e4d31598 |
comparison
equal
deleted
inserted
replaced
| 9617:655b8d36a8a4 | 9621:f85e12d9eede |
|---|---|
| 4 | 4 |
| 5 local filters = require "util.filters"; | 5 local filters = require "util.filters"; |
| 6 local id = require "util.id"; | 6 local id = require "util.id"; |
| 7 local dt = require "util.datetime"; | 7 local dt = require "util.datetime"; |
| 8 local dm = require "util.datamanager"; | 8 local dm = require "util.datamanager"; |
| 9 local st = require "util.stanza"; | |
| 9 | 10 |
| 10 local record_id = id.medium():lower(); | 11 local record_id = id.medium():lower(); |
| 11 local record_date = os.date("%Y%b%d"):lower(); | 12 local record_date = os.date("%Y%b%d"):lower(); |
| 12 local header_file = dm.getpath(record_id, "scansion", record_date, "scs", true); | 13 local header_file = dm.getpath(record_id, "scansion", record_date, "scs", true); |
| 13 local record_file = dm.getpath(record_id, "scansion", record_date, "log", true); | 14 local record_file = dm.getpath(record_id, "scansion", record_date, "log", true); |
| 34 local function record_event(session, event) | 35 local function record_event(session, event) |
| 35 record(session.scansion_id.." "..event.."\n\n"); | 36 record(session.scansion_id.." "..event.."\n\n"); |
| 36 end | 37 end |
| 37 | 38 |
| 38 local function record_stanza(stanza, session, verb) | 39 local function record_stanza(stanza, session, verb) |
| 39 record(session.scansion_id.." "..verb..":\n\t"..tostring(stanza).."\n\n"); | 40 local flattened = tostring(stanza):gsub("><", ">\n\t<"); |
| 41 -- TODO Proper prettyprinting with indentation | |
| 42 record(session.scansion_id.." "..verb..":\n\t"..flattened.."\n\n"); | |
| 40 end | 43 end |
| 41 | 44 |
| 42 local function record_stanza_in(stanza, session) | 45 local function record_stanza_in(stanza, session) |
| 43 if stanza.attr.xmlns == nil then | 46 if stanza.attr.xmlns == nil then |
| 44 record_stanza(stanza, session, "sends") | 47 local copy = st.clone(stanza); |
| 48 copy.attr.from = nil; | |
| 49 record_stanza(copy, session, "sends") | |
| 45 end | 50 end |
| 46 return stanza; | 51 return stanza; |
| 47 end | 52 end |
| 48 | 53 |
| 49 local function record_stanza_out(stanza, session) | 54 local function record_stanza_out(stanza, session) |
| 50 if stanza.attr.xmlns == nil then | 55 if stanza.attr.xmlns == nil then |
| 51 if not (stanza.name == "iq" and stanza:get_child("bind", "urn:ietf:params:xml:ns:xmpp-bind")) then | 56 if not (stanza.name == "iq" and stanza:get_child("bind", "urn:ietf:params:xml:ns:xmpp-bind")) then |
| 52 record_stanza(stanza, session, "receives"); | 57 local copy = st.clone(stanza); |
| 58 if copy.attr.to == session.full_jid then | |
| 59 copy.attr.to = nil; | |
| 60 end | |
| 61 record_stanza(copy, session, "receives"); | |
| 53 end | 62 end |
| 54 end | 63 end |
| 55 return stanza; | 64 return stanza; |
| 56 end | 65 end |
| 57 | 66 |
