comparison mod_measure_message_e2ee/mod_measure_message_e2ee.lua @ 3137:178ebea5097c

mod_measure_message_e2ee: Get statistics about message encryption status.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 22 Jun 2018 11:12:34 +0200
parents
children c414a7e884b3
comparison
equal deleted inserted replaced
3136:fdbf7c2aed7b 3137:178ebea5097c
1 module:set_global();
2
3 local count_message = module:measure("message", "rate");
4 local count_plain = module:measure("plain", "rate");
5 local count_openpgp = module:measure("openpgp", "rate");
6 local count_otr = module:measure("otr", "rate");
7 local count_ox = module:measure("ox", "rate");
8 local count_omemo = module:measure("omemo", "rate");
9 local count_encrypted = module:measure("encrypted", "rate");
10
11 local function message_handler(event)
12 local origin, stanza = event.origin, event.stanza;
13
14 -- This counts every message, even those with no body-like content.
15 count_message();
16
17 -- Annotates that a message is encrypted, using any of the following methods.
18 if stanza:get_child("encryption", "urn:xmpp:eme:0") then
19 count_encrypted();
20 end
21
22 if stanza:get_child("openpgp", "urn:xmpp:openpgp:0") then
23 count_ox();
24 return;
25 end
26
27 if stanza:get_child("encrypted", "eu.siacs.conversations.axolotl") then
28 count_omemo();
29 return;
30 end
31
32 if stanza:get_child("x", "jabber:x:encrypted") then
33 count_openpgp();
34 return;
35 end
36
37 local body = stanza:get_child("body");
38 if body ~= nil then
39 local otr_index = body:find("?OTR", 1, true);
40 if otr_index == 1 then
41 count_otr();
42 return;
43 end
44
45 count_plain();
46 end
47 end
48
49 function module.add_host(host_module)
50 module:log("debug", "Loaded on host %s", host_module);
51 host_module:hook("pre-message/host", message_handler, 2);
52 host_module:hook("pre-message/bare", message_handler, 2);
53 host_module:hook("pre-message/full", message_handler, 2);
54 end