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;
13 local full_sessions = full_sessions;
14 local bare_sessions = bare_sessions;
16 if module:get_host_type() == "local" then
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"));
34 module:hook("iq/bare", function(data)
35 -- IQ to bare JID recieved
36 local origin, stanza = data.origin, data.stanza;
37 local type = stanza.attr.type;
39 -- TODO fire post processing events
40 if type == "get" or type == "set" then
41 local child = stanza.tags[1];
42 local ret = module:fire_event("iq/bare/"..child.attr.xmlns..":"..child.name, data);
43 if ret ~= nil then return ret; end
44 return module:fire_event("iq-"..type.."/bare/"..child.attr.xmlns..":"..child.name, data);
46 return module:fire_event("iq-"..type.."/bare/"..stanza.attr.id, data);
50 module:hook("iq/self", function(data)
51 -- IQ to self JID recieved
52 local origin, stanza = data.origin, data.stanza;
53 local type = stanza.attr.type;
55 if type == "get" or type == "set" then
56 local child = stanza.tags[1];
57 local ret = module:fire_event("iq/self/"..child.attr.xmlns..":"..child.name, data);
58 if ret ~= nil then return ret; end
59 return module:fire_event("iq-"..type.."/self/"..child.attr.xmlns..":"..child.name, data);
61 return module:fire_event("iq-"..type.."/self/"..stanza.attr.id, data);
65 module:hook("iq/host", function(data)
66 -- IQ to a local host recieved
67 local origin, stanza = data.origin, data.stanza;
68 local type = stanza.attr.type;
70 if type == "get" or type == "set" then
71 local child = stanza.tags[1];
72 local ret = module:fire_event("iq/host/"..child.attr.xmlns..":"..child.name, data);
73 if ret ~= nil then return ret; end
74 return module:fire_event("iq-"..type.."/host/"..child.attr.xmlns..":"..child.name, data);
76 return module:fire_event("iq-"..type.."/host/"..stanza.attr.id, data);