Comparison

mod_csi_battery_saver/mod_csi_battery_saver.lua @ 2735:b5fae17e4403

mod_csi_battery_saver: correctly handle encrypted message stanzas Thanks to michel
author tmolitor <thilo@eightysoft.de>
date Sat, 12 Aug 2017 20:45:11 +0200
parent 2606:538c54d2dab3
child 2737:f43c77c69a8a
comparison
equal deleted inserted replaced
2734:f5005d256877 2735:b5fae17e4403
18 -- Patched version of util.stanza:find() that supports giving stanza names 18 -- Patched version of util.stanza:find() that supports giving stanza names
19 -- without their namespace, allowing for every namespace. 19 -- without their namespace, allowing for every namespace.
20 local function find(self, path) 20 local function find(self, path)
21 local pos = 1; 21 local pos = 1;
22 local len = #path + 1; 22 local len = #path + 1;
23 23
24 repeat 24 repeat
25 local xmlns, name, text; 25 local xmlns, name, text;
26 local char = s_sub(path, pos, pos); 26 local char = s_sub(path, pos, pos);
27 if char == "@" then 27 if char == "@" then
28 return self.attr[s_sub(path, pos + 1)]; 28 return self.attr[s_sub(path, pos + 1)];
108 stanza_direction = carbon and stanza:child_with_name("sent") and "out" or "in"; 108 stanza_direction = carbon and stanza:child_with_name("sent") and "out" or "in";
109 --session.log("debug", "mod_csi_battery_saver(%s): stanza_direction = %s, carbon = %s, stanza = %s", id, stanza_direction, carbon and "true" or "false", tostring(stanza)); 109 --session.log("debug", "mod_csi_battery_saver(%s): stanza_direction = %s, carbon = %s, stanza = %s", id, stanza_direction, carbon and "true" or "false", tostring(stanza));
110 if carbon then stanza = carbon; end 110 if carbon then stanza = carbon; end
111 -- carbon copied outgoing messages aren't important (but incoming carbon copies are!) 111 -- carbon copied outgoing messages aren't important (but incoming carbon copies are!)
112 if carbon and stanza_direction == "out" then return false; end 112 if carbon and stanza_direction == "out" then return false; end
113 113
114 local st_type = stanza.attr.type; 114 local st_type = stanza.attr.type;
115 if st_type == "headline" then 115 if st_type == "headline" then
116 return false; 116 return false;
117 end 117 end
118
119 -- We can't check for nick in encrypted groupchat messages, so let's treat them as important
120 -- Some clients don't set a body or an empty body for encrypted messages
121
122 -- check omemo https://xmpp.org/extensions/inbox/omemo.html
123 if stanza:get_child("encrypted", "eu.siacs.conversations.axolotl") or stanza:get_child("encrypted", "urn:xmpp:omemo:0") then return true; end
124
125 -- check xep27 pgp https://xmpp.org/extensions/xep-0027.html
126 if stanza:get_child("x", "jabber:x:encrypted") then return true; end
127
128 -- check xep373 pgp (OX) https://xmpp.org/extensions/xep-0373.html
129 if stanza:get_child("openpgp", "urn:xmpp:openpgp:0") then return true; end
130
118 local body = stanza:get_child_text("body"); 131 local body = stanza:get_child_text("body");
119 if st_type == "groupchat" then 132 if st_type == "groupchat" then
120 if stanza:get_child_text("subject") then return true; end 133 if stanza:get_child_text("subject") then return true; end
121 if not body then return false; end 134 if not body then return false; end
122 if body:find(session.username, 1, true) then return true; end 135 if body:find(session.username, 1, true) then return true; end
142 session.pump = pump; 155 session.pump = pump;
143 session._pump_orig_send = session.send; 156 session._pump_orig_send = session.send;
144 function session.send(stanza) 157 function session.send(stanza)
145 session.log("debug", "mod_csi_battery_saver(%s): Got stanza: <%s>", id, tostring(stanza.name)); 158 session.log("debug", "mod_csi_battery_saver(%s): Got stanza: <%s>", id, tostring(stanza.name));
146 local important = is_important(stanza, session); 159 local important = is_important(stanza, session);
147 -- add delay stamp to unimported (buffered) stanzas that can/need be stamped 160 -- add delay stamp to unimportant (buffered) stanzas that can/need be stamped
148 if not important and is_stamp_needed(stanza, session) then stanza = add_stamp(stanza, session); end 161 if not important and is_stamp_needed(stanza, session) then stanza = add_stamp(stanza, session); end
149 pump:push(stanza); 162 pump:push(stanza);
150 if important then 163 if important then
151 session.log("debug", "mod_csi_battery_saver(%s): Encountered important stanza, flushing buffer: <%s>", id, tostring(stanza.name)); 164 session.log("debug", "mod_csi_battery_saver(%s): Encountered important stanza, flushing buffer: <%s>", id, tostring(stanza.name));
152 pump:flush(); 165 pump:flush();