annotate mod_measure_message_e2ee/mod_measure_message_e2ee.lua @ 3562:b33b2fbdc713

mod_net_proxy: Ensure port numbers are coerced into numbers LuaSocket likes to use strings for port numbers for some reason, so this might help with some type related problems.
author Kim Alvefur <zash@zash.se>
date Fri, 12 Apr 2019 21:44:29 +0200
parents c414a7e884b3
children 70e5bab388d8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3137
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 module:set_global();
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 local count_message = module:measure("message", "rate");
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 local count_plain = module:measure("plain", "rate");
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 local count_openpgp = module:measure("openpgp", "rate");
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 local count_otr = module:measure("otr", "rate");
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 local count_ox = module:measure("ox", "rate");
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 local count_omemo = module:measure("omemo", "rate");
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 local count_encrypted = module:measure("encrypted", "rate");
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 local function message_handler(event)
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 local origin, stanza = event.origin, event.stanza;
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 -- This counts every message, even those with no body-like content.
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 count_message();
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 -- Annotates that a message is encrypted, using any of the following methods.
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 if stanza:get_child("encryption", "urn:xmpp:eme:0") then
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 count_encrypted();
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 end
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 if stanza:get_child("openpgp", "urn:xmpp:openpgp:0") then
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 count_ox();
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 return;
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 end
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 if stanza:get_child("encrypted", "eu.siacs.conversations.axolotl") then
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 count_omemo();
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 return;
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 end
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32 if stanza:get_child("x", "jabber:x:encrypted") then
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 count_openpgp();
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 return;
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 end
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36
3370
c414a7e884b3 mod_measure_message_e2ee: Count OTR messages too.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3137
diff changeset
37 local body = stanza:get_child_text("body");
c414a7e884b3 mod_measure_message_e2ee: Count OTR messages too.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3137
diff changeset
38 if body then
c414a7e884b3 mod_measure_message_e2ee: Count OTR messages too.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3137
diff changeset
39 if body:sub(1,4) == "?OTR" then
3137
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 count_otr();
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 return;
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42 end
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 count_plain();
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 end
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46 end
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48 function module.add_host(host_module)
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 module:log("debug", "Loaded on host %s", host_module);
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50 host_module:hook("pre-message/host", message_handler, 2);
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51 host_module:hook("pre-message/bare", message_handler, 2);
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52 host_module:hook("pre-message/full", message_handler, 2);
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 end