annotate mod_measure_message_e2ee/mod_measure_message_e2ee.lua @ 3362:af085e8b9d48

mod_conversejs: Link to BOSH and WebSockets setup instructions instead of module pages
author Kim Alvefur <zash@zash.se>
date Thu, 25 Oct 2018 22:41:13 +0200
parents 178ebea5097c
children c414a7e884b3
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
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 local body = stanza:get_child("body");
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38 if body ~= nil then
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 local otr_index = body:find("?OTR", 1, true);
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 if otr_index == 1 then
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 count_otr();
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42 return;
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43 end
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 count_plain();
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 end
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48
178ebea5097c mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 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
50 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
51 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
52 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
53 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
54 end