2 local st = require "util.stanza";
3 local jid_split = require "util.jid".split;
4 local user_exists = require "core.usermanager".user_exists;
6 local full_sessions = full_sessions;
7 local bare_sessions = bare_sessions;
9 module:hook("iq/full", function(data)
10 -- IQ to full JID recieved
11 local origin, stanza = data.origin, data.stanza;
13 local session = full_sessions[stanza.attr.to];
15 -- TODO fire post processing event
17 else -- resource not online
18 if stanza.attr.type == "get" or stanza.attr.type == "set" then
19 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
25 module:hook("iq/bare", function(data)
26 -- IQ to bare JID recieved
27 local origin, stanza = data.origin, data.stanza;
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"));
38 -- TODO fire post processing events
39 if #stanza.tags == 1 then
40 return module:fire_event("iq/bare/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data);
42 return true; -- TODO do something with results and errors
46 module:hook("iq/host", function(data)
47 -- IQ to a local host recieved
48 local origin, stanza = data.origin, data.stanza;
50 if #stanza.tags == 1 then
51 return module:fire_event("iq/host/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data);
53 return true; -- TODO do something with results and errors