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";
12 local full_sessions = full_sessions;
14 if module:get_host_type() == "local" then
15 module:hook("iq/full", function(data)
16 -- IQ to full JID recieved
17 local origin, stanza = data.origin, data.stanza;
19 local session = full_sessions[stanza.attr.to];
21 -- TODO fire post processing event
23 else -- resource not online
24 if stanza.attr.type == "get" or stanza.attr.type == "set" then
25 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
32 module:hook("iq/bare", function(data)
33 -- IQ to bare JID recieved
34 local stanza = data.stanza;
35 local type = stanza.attr.type;
37 -- TODO fire post processing events
38 if type == "get" or type == "set" then
39 local child = stanza.tags[1];
40 local ret = module:fire_event("iq/bare/"..child.attr.xmlns..":"..child.name, data);
41 if ret ~= nil then return ret; end
42 return module:fire_event("iq-"..type.."/bare/"..child.attr.xmlns..":"..child.name, data);
44 return module:fire_event("iq-"..type.."/bare/"..stanza.attr.id, data);
48 module:hook("iq/self", function(data)
49 -- IQ to self JID recieved
50 local stanza = data.stanza;
51 local type = stanza.attr.type;
53 if type == "get" or type == "set" then
54 local child = stanza.tags[1];
55 local ret = module:fire_event("iq/self/"..child.attr.xmlns..":"..child.name, data);
56 if ret ~= nil then return ret; end
57 return module:fire_event("iq-"..type.."/self/"..child.attr.xmlns..":"..child.name, data);
59 return module:fire_event("iq-"..type.."/self/"..stanza.attr.id, data);
63 module:hook("iq/host", function(data)
64 -- IQ to a local host recieved
65 local stanza = data.stanza;
66 local type = stanza.attr.type;
68 if type == "get" or type == "set" then
69 local child = stanza.tags[1];
70 local ret = module:fire_event("iq/host/"..child.attr.xmlns..":"..child.name, data);
71 if ret ~= nil then return ret; end
72 return module:fire_event("iq-"..type.."/host/"..child.attr.xmlns..":"..child.name, data);
74 return module:fire_event("iq-"..type.."/host/"..stanza.attr.id, data);