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 local to = stanza.attr.to;
30 if to and not bare_sessions[to] then -- quick check for account existance
31 local node, host = jid_split(to);
32 if not user_exists(node, host) then -- full check for account existance
33 if stanza.attr.type == "get" or stanza.attr.type == "set" then
34 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
39 -- TODO fire post processing events
40 if stanza.attr.type == "get" or stanza.attr.type == "set" then
41 return module:fire_event("iq/bare/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data);
43 return true; -- TODO do something with results and errors
47 module:hook("iq/host", function(data)
48 -- IQ to a local host recieved
49 local origin, stanza = data.origin, data.stanza;
51 if stanza.attr.type == "get" or stanza.attr.type == "set" then
52 return module:fire_event("iq/host/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data);
54 return true; -- TODO do something with results and errors