Comparison

mod_readonly/mod_readonly.lua @ 3270:7776c9dc5f37

mod_readonly: Simplify iq handling by hooking on iq-set/ instead of iq/.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 24 Aug 2018 21:35:47 +0200
parent 750:8133dd5f266a
comparison
equal deleted inserted replaced
3269:b0628bc93acf 3270:7776c9dc5f37
7 local namespaces = {}; 7 local namespaces = {};
8 for name, namespace in pairs(stores) do 8 for name, namespace in pairs(stores) do
9 namespaces[table.concat(namespace, ":")] = name; 9 namespaces[table.concat(namespace, ":")] = name;
10 end 10 end
11 11
12 function prevent_write(event) 12 local function prevent_write(event)
13 local stanza = event.stanza; 13 local stanza = event.stanza;
14 if stanza.attr.type ~= "set" then return; end
15 local xmlns_and_tag = stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name; 14 local xmlns_and_tag = stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name;
16 local store_name = namespaces[xmlns_and_tag]; 15 local store_name = namespaces[xmlns_and_tag];
17 if store_name then 16 if store_name then
18 module:log("warn", "Preventing modification of %s store by %s", store_name, stanza.attr.from); 17 module:log("warn", "Preventing modification of %s store by %s", store_name, stanza.attr.from);
19 event.origin.send(st.error_reply(stanza, "cancel", "not-allowed", store_name.." data is read-only")); 18 event.origin.send(st.error_reply(stanza, "cancel", "not-allowed", store_name.." data is read-only"));
20 return true; -- Block stanza 19 return true; -- Block stanza
21 end 20 end
22 end 21 end
23 22
24 for namespace in pairs(namespaces) do 23 for namespace in pairs(namespaces) do
25 module:hook("iq/bare/"..namespace, prevent_write, 200); 24 module:hook("iq-set/bare/"..namespace, prevent_write, 200);
26 end 25 end