8ccd820faa0c76daee0e585825e91d60228132ff
[prosody.git] / plugins / mod_iq.lua
1
2 local st = require "util.stanza";
3
4 local full_sessions = full_sessions;
5 local bare_sessions = bare_sessions;
6
7 module:hook("iq/full", function(data)
8         -- IQ to full JID recieved
9         local origin, stanza = data.origin, data.stanza;
10
11         local session = full_sessions[stanza.attr.to];
12         if session then
13                 -- TODO fire post processing event
14                 session.send(stanza);
15         else -- resource not online
16                 if stanza.attr.type == "get" or stanza.attr.type == "set" then
17                         origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
18                 end
19         end
20         return true;
21 end);
22
23 module:hook("iq/bare", function(data)
24         -- IQ to bare JID recieved
25         local origin, stanza = data.origin, data.stanza;
26
27         -- TODO if not user exists, return an error
28         -- TODO fire post processing events
29         if #stanza.tags == 1 then
30                 return module:fire_event("iq/bare/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name);
31         else
32                 return true; -- TODO do something with results and errors
33         end
34 end);
35
36 module:hook("iq/host", function(data)
37         -- IQ to a local host recieved
38         local origin, stanza = data.origin, data.stanza;
39
40         if #stanza.tags == 1 then
41                 return module:fire_event("iq/host/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name);
42         else
43                 return true; -- TODO do something with results and errors
44         end
45 end);