mod_csi_simple: Consider messages encrypted payload as important (fixes part of ...
[prosody.git] / plugins / mod_iq.lua
blob87c3a467c636c07193891b54d2f4cc74b1e94cb0
1 -- Prosody IM
2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
4 --
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
10 local st = require "util.stanza";
12 local full_sessions = prosody.full_sessions;
14 if module:get_host_type() == "local" then
15 module:hook("iq/full", function(data)
16 -- IQ to full JID received
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"));
23 end
24 end
25 return true;
26 end);
27 end
29 module:hook("iq/bare", function(data)
30 -- IQ to bare JID received
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);
41 else
42 return module:fire_event("iq-"..type.."/bare/"..stanza.attr.id, data);
43 end
44 end);
46 module:hook("iq/self", function(data)
47 -- IQ to self JID received
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);
57 else
58 return module:fire_event("iq-"..type.."/self/"..stanza.attr.id, data);
59 end
60 end);
62 module:hook("iq/host", function(data)
63 -- IQ to a local host received
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);
73 else
74 return module:fire_event("iq-"..type.."/host/"..stanza.attr.id, data);
75 end
76 end);