2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
10 local st = require "util.stanza";
11 local jid_split = require "util.jid".split;
12 local user_exists = require "core.usermanager".user_exists;
14 local full_sessions = full_sessions;
15 local bare_sessions = bare_sessions;
17 module:hook("iq/full", function(data)
18 -- IQ to full JID recieved
19 local origin, stanza = data.origin, data.stanza;
21 local session = full_sessions[stanza.attr.to];
23 -- TODO fire post processing event
25 else -- resource not online
26 if stanza.attr.type == "get" or stanza.attr.type == "set" then
27 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
33 module:hook("iq/bare", function(data)
34 -- IQ to bare JID recieved
35 local origin, stanza = data.origin, data.stanza;
37 local to = stanza.attr.to;
38 if to and not bare_sessions[to] then -- quick check for account existance
39 local node, host = jid_split(to);
40 if not user_exists(node, host) then -- full check for account existance
41 if stanza.attr.type == "get" or stanza.attr.type == "set" then
42 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
47 -- TODO fire post processing events
48 if stanza.attr.type == "get" or stanza.attr.type == "set" then
49 return module:fire_event("iq/bare/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data);
51 module:fire_event("iq/bare/"..stanza.attr.id, data);
56 module:hook("iq/self", function(data)
57 -- IQ to bare JID recieved
58 local origin, stanza = data.origin, data.stanza;
60 if stanza.attr.type == "get" or stanza.attr.type == "set" then
61 return module:fire_event("iq/self/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data);
63 module:fire_event("iq/self/"..stanza.attr.id, data);
68 module:hook("iq/host", function(data)
69 -- IQ to a local host recieved
70 local origin, stanza = data.origin, data.stanza;
72 if stanza.attr.type == "get" or stanza.attr.type == "set" then
73 return module:fire_event("iq/host/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data);
75 module:fire_event("iq/host/"..stanza.attr.id, data);