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];
20 if not (session and session.send(stanza)) then
21 if stanza.attr.type == "get" or stanza.attr.type == "set" then
22 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
29 module:hook("iq/bare", function(data)
30 -- IQ to bare JID recieved
31 local stanza = data.stanza;
32 local type = stanza.attr.type;
34 -- TODO fire post processing events
35 if type == "get" or type == "set" then
36 local child = stanza.tags[1];
37 local xmlns = child.attr.xmlns or "jabber:client";
38 local ret = module:fire_event("iq/bare/"..xmlns..":"..child.name, data);
39 if ret ~= nil then return ret; end
40 return module:fire_event("iq-"..type.."/bare/"..xmlns..":"..child.name, data);
42 return module:fire_event("iq-"..type.."/bare/"..stanza.attr.id, data);
46 module:hook("iq/self", function(data)
47 -- IQ to self JID recieved
48 local stanza = data.stanza;
49 local type = stanza.attr.type;
51 if type == "get" or type == "set" then
52 local child = stanza.tags[1];
53 local xmlns = child.attr.xmlns or "jabber:client";
54 local ret = module:fire_event("iq/self/"..xmlns..":"..child.name, data);
55 if ret ~= nil then return ret; end
56 return module:fire_event("iq-"..type.."/self/"..xmlns..":"..child.name, data);
58 return module:fire_event("iq-"..type.."/self/"..stanza.attr.id, data);
62 module:hook("iq/host", function(data)
63 -- IQ to a local host recieved
64 local stanza = data.stanza;
65 local type = stanza.attr.type;
67 if type == "get" or type == "set" then
68 local child = stanza.tags[1];
69 local xmlns = child.attr.xmlns or "jabber:client";
70 local ret = module:fire_event("iq/host/"..xmlns..":"..child.name, data);
71 if ret ~= nil then return ret; end
72 return module:fire_event("iq-"..type.."/host/"..xmlns..":"..child.name, data);
74 return module:fire_event("iq-"..type.."/host/"..stanza.attr.id, data);