Comparison

plugins/mod_iq.lua @ 1267:1bf897de6c24

mod_iq: Immediately return an error for IQs to non-existing bare JIDs
author Waqas Hussain <waqas20@gmail.com>
date Mon, 01 Jun 2009 10:44:05 +0500
parent 1266:605a73234230
child 1268:dc1f95b37024
comparison
equal deleted inserted replaced
1266:605a73234230 1267:1bf897de6c24
1 1
2 local st = require "util.stanza"; 2 local st = require "util.stanza";
3 local jid_split = require "util.jid".split;
4 local user_exists = require "core.usermanager".user_exists;
3 5
4 local full_sessions = full_sessions; 6 local full_sessions = full_sessions;
5 local bare_sessions = bare_sessions; 7 local bare_sessions = bare_sessions;
6 8
7 module:hook("iq/full", function(data) 9 module:hook("iq/full", function(data)
22 24
23 module:hook("iq/bare", function(data) 25 module:hook("iq/bare", function(data)
24 -- IQ to bare JID recieved 26 -- IQ to bare JID recieved
25 local origin, stanza = data.origin, data.stanza; 27 local origin, stanza = data.origin, data.stanza;
26 28
27 -- TODO if not user exists, return an error 29 if not bare_sessions[stanza.attr.to] then -- quick check for account existance
30 local node, host = jid_split(stanza.attr.to);
31 if not user_exists(node, host) then -- full check for account existance
32 if stanza.attr.type == "get" or stanza.attr.type == "set" then
33 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
34 end
35 return true;
36 end
37 end
28 -- TODO fire post processing events 38 -- TODO fire post processing events
29 if #stanza.tags == 1 then 39 if #stanza.tags == 1 then
30 return module:fire_event("iq/bare/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data); 40 return module:fire_event("iq/bare/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data);
31 else 41 else
32 return true; -- TODO do something with results and errors 42 return true; -- TODO do something with results and errors