Mercurial > prosody-modules
annotate mod_measure_message_e2ee/mod_measure_message_e2ee.lua @ 5771:72799c330986
mod_http_oauth2: Add logger to "session" for auth event
So many assumptions in so many other modules about auth-success/fail
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 04 Dec 2023 21:36:35 +0100 |
parents | 70e5bab388d8 |
children |
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 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
|
2 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
|
3 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
|
4 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
|
5 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
|
6 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
|
7 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
|
8 |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 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
|
10 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
|
11 |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 -- 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
|
13 count_message(); |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 -- 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
|
16 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
|
17 count_encrypted(); |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 end |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 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
|
21 count_ox(); |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 return; |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 end |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
24 |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
25 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
|
26 count_omemo(); |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 return; |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 end |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 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
|
31 count_openpgp(); |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 return; |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 end |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 |
3370
c414a7e884b3
mod_measure_message_e2ee: Count OTR messages too.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3137
diff
changeset
|
35 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
|
36 if body then |
c414a7e884b3
mod_measure_message_e2ee: Count OTR messages too.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3137
diff
changeset
|
37 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
|
38 count_otr(); |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
39 return; |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
40 end |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
41 |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 count_plain(); |
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 end |
178ebea5097c
mod_measure_message_e2ee: Get statistics about message encryption status.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
45 |
3782
70e5bab388d8
mod_measure_message_e2ee: Make this module non-global; users can aggregate data if they care about that
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3370
diff
changeset
|
46 module:hook("pre-message/host", message_handler, 2); |
70e5bab388d8
mod_measure_message_e2ee: Make this module non-global; users can aggregate data if they care about that
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3370
diff
changeset
|
47 module:hook("pre-message/bare", message_handler, 2); |
70e5bab388d8
mod_measure_message_e2ee: Make this module non-global; users can aggregate data if they care about that
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3370
diff
changeset
|
48 module:hook("pre-message/full", message_handler, 2); |