Annotate

plugins/mod_iq.lua @ 4191:dfeae208e5b4

mod_auth_*: Get rid of undocumented and broken 'sasl_realm' config option.
author Waqas Hussain <waqas20@gmail.com>
date Wed, 23 Feb 2011 01:34:46 +0500
parent 3803:6e2d834e602c
child 4760:55501fc4394b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1522
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1421
diff changeset
1 -- Prosody IM
2923
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 1522
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 1522
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
1522
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1421
diff changeset
4 --
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1421
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1421
diff changeset
6 -- COPYING file in the source package for more information.
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1421
diff changeset
7 --
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1421
diff changeset
8
1265
3f3c62e45eeb mod_iq: Error reply for IQ to non-existing session. mod_iq now handles all 'iq/full' cases
Waqas Hussain <waqas20@gmail.com>
parents: 1260
diff changeset
9
3f3c62e45eeb mod_iq: Error reply for IQ to non-existing session. mod_iq now handles all 'iq/full' cases
Waqas Hussain <waqas20@gmail.com>
parents: 1260
diff changeset
10 local st = require "util.stanza";
1267
1bf897de6c24 mod_iq: Immediately return an error for IQs to non-existing bare JIDs
Waqas Hussain <waqas20@gmail.com>
parents: 1266
diff changeset
11 local jid_split = require "util.jid".split;
1234
0ff02499f05c mod_message, mod_iq: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents: 1233
diff changeset
12
0ff02499f05c mod_message, mod_iq: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents: 1233
diff changeset
13 local full_sessions = full_sessions;
0ff02499f05c mod_message, mod_iq: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents: 1233
diff changeset
14 local bare_sessions = bare_sessions;
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15
3803
6e2d834e602c mod_iq: Fix an extra character in previous commit...
Waqas Hussain <waqas20@gmail.com>
parents: 3802
diff changeset
16 if module:get_host_type() == "local" then
3802
530a74b60e45 mod_iq: Don't hook 'iq/full' on components.
Waqas Hussain <waqas20@gmail.com>
parents: 3797
diff changeset
17 module:hook("iq/full", function(data)
530a74b60e45 mod_iq: Don't hook 'iq/full' on components.
Waqas Hussain <waqas20@gmail.com>
parents: 3797
diff changeset
18 -- IQ to full JID recieved
530a74b60e45 mod_iq: Don't hook 'iq/full' on components.
Waqas Hussain <waqas20@gmail.com>
parents: 3797
diff changeset
19 local origin, stanza = data.origin, data.stanza;
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
20
3802
530a74b60e45 mod_iq: Don't hook 'iq/full' on components.
Waqas Hussain <waqas20@gmail.com>
parents: 3797
diff changeset
21 local session = full_sessions[stanza.attr.to];
530a74b60e45 mod_iq: Don't hook 'iq/full' on components.
Waqas Hussain <waqas20@gmail.com>
parents: 3797
diff changeset
22 if session then
530a74b60e45 mod_iq: Don't hook 'iq/full' on components.
Waqas Hussain <waqas20@gmail.com>
parents: 3797
diff changeset
23 -- TODO fire post processing event
530a74b60e45 mod_iq: Don't hook 'iq/full' on components.
Waqas Hussain <waqas20@gmail.com>
parents: 3797
diff changeset
24 session.send(stanza);
530a74b60e45 mod_iq: Don't hook 'iq/full' on components.
Waqas Hussain <waqas20@gmail.com>
parents: 3797
diff changeset
25 else -- resource not online
530a74b60e45 mod_iq: Don't hook 'iq/full' on components.
Waqas Hussain <waqas20@gmail.com>
parents: 3797
diff changeset
26 if stanza.attr.type == "get" or stanza.attr.type == "set" then
530a74b60e45 mod_iq: Don't hook 'iq/full' on components.
Waqas Hussain <waqas20@gmail.com>
parents: 3797
diff changeset
27 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
530a74b60e45 mod_iq: Don't hook 'iq/full' on components.
Waqas Hussain <waqas20@gmail.com>
parents: 3797
diff changeset
28 end
1265
3f3c62e45eeb mod_iq: Error reply for IQ to non-existing session. mod_iq now handles all 'iq/full' cases
Waqas Hussain <waqas20@gmail.com>
parents: 1260
diff changeset
29 end
3802
530a74b60e45 mod_iq: Don't hook 'iq/full' on components.
Waqas Hussain <waqas20@gmail.com>
parents: 3797
diff changeset
30 return true;
530a74b60e45 mod_iq: Don't hook 'iq/full' on components.
Waqas Hussain <waqas20@gmail.com>
parents: 3797
diff changeset
31 end);
530a74b60e45 mod_iq: Don't hook 'iq/full' on components.
Waqas Hussain <waqas20@gmail.com>
parents: 3797
diff changeset
32 end
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
33
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34 module:hook("iq/bare", function(data)
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35 -- IQ to bare JID recieved
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
36 local origin, stanza = data.origin, data.stanza;
3787
95aaf9fc5a6c mod_iq: Optimized a bit (fewer table accesses).
Waqas Hussain <waqas20@gmail.com>
parents: 3786
diff changeset
37 local type = stanza.attr.type;
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
38
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
39 -- TODO fire post processing events
3787
95aaf9fc5a6c mod_iq: Optimized a bit (fewer table accesses).
Waqas Hussain <waqas20@gmail.com>
parents: 3786
diff changeset
40 if type == "get" or type == "set" then
3788
588904a9fd8b mod_iq: Optimized a bit more (fewer table accesses).
Waqas Hussain <waqas20@gmail.com>
parents: 3787
diff changeset
41 local child = stanza.tags[1];
588904a9fd8b mod_iq: Optimized a bit more (fewer table accesses).
Waqas Hussain <waqas20@gmail.com>
parents: 3787
diff changeset
42 local ret = module:fire_event("iq/bare/"..child.attr.xmlns..":"..child.name, data);
3786
28d9fff67fed mod_iq: Extra IQ get and set sub-events are now fired: "iq-{get,set}/{host,self,bare}/xmlns:tag" (when "iq/{host,self,bare}/xmlns:tag" is unhandled).
Waqas Hussain <waqas20@gmail.com>
parents: 3781
diff changeset
43 if ret ~= nil then return ret; end
3788
588904a9fd8b mod_iq: Optimized a bit more (fewer table accesses).
Waqas Hussain <waqas20@gmail.com>
parents: 3787
diff changeset
44 return module:fire_event("iq-"..type.."/bare/"..child.attr.xmlns..":"..child.name, data);
1260
04c1fae0eb03 mod_iq: Fire sub-events for IQs directed at bare JIDs and hosts
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
45 else
3797
bd92e421728d mod_iq: Don't stop event dispatch for unhandled IQ errors and results (this lets negative priority handlers intercept the events).
Waqas Hussain <waqas20@gmail.com>
parents: 3788
diff changeset
46 return module:fire_event("iq-"..type.."/bare/"..stanza.attr.id, data);
1260
04c1fae0eb03 mod_iq: Fire sub-events for IQs directed at bare JIDs and hosts
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
47 end
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
48 end);
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
49
2686
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
50 module:hook("iq/self", function(data)
3786
28d9fff67fed mod_iq: Extra IQ get and set sub-events are now fired: "iq-{get,set}/{host,self,bare}/xmlns:tag" (when "iq/{host,self,bare}/xmlns:tag" is unhandled).
Waqas Hussain <waqas20@gmail.com>
parents: 3781
diff changeset
51 -- IQ to self JID recieved
2686
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
52 local origin, stanza = data.origin, data.stanza;
3787
95aaf9fc5a6c mod_iq: Optimized a bit (fewer table accesses).
Waqas Hussain <waqas20@gmail.com>
parents: 3786
diff changeset
53 local type = stanza.attr.type;
2686
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
54
3787
95aaf9fc5a6c mod_iq: Optimized a bit (fewer table accesses).
Waqas Hussain <waqas20@gmail.com>
parents: 3786
diff changeset
55 if type == "get" or type == "set" then
3788
588904a9fd8b mod_iq: Optimized a bit more (fewer table accesses).
Waqas Hussain <waqas20@gmail.com>
parents: 3787
diff changeset
56 local child = stanza.tags[1];
588904a9fd8b mod_iq: Optimized a bit more (fewer table accesses).
Waqas Hussain <waqas20@gmail.com>
parents: 3787
diff changeset
57 local ret = module:fire_event("iq/self/"..child.attr.xmlns..":"..child.name, data);
3786
28d9fff67fed mod_iq: Extra IQ get and set sub-events are now fired: "iq-{get,set}/{host,self,bare}/xmlns:tag" (when "iq/{host,self,bare}/xmlns:tag" is unhandled).
Waqas Hussain <waqas20@gmail.com>
parents: 3781
diff changeset
58 if ret ~= nil then return ret; end
3788
588904a9fd8b mod_iq: Optimized a bit more (fewer table accesses).
Waqas Hussain <waqas20@gmail.com>
parents: 3787
diff changeset
59 return module:fire_event("iq-"..type.."/self/"..child.attr.xmlns..":"..child.name, data);
2686
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
60 else
3797
bd92e421728d mod_iq: Don't stop event dispatch for unhandled IQ errors and results (this lets negative priority handlers intercept the events).
Waqas Hussain <waqas20@gmail.com>
parents: 3788
diff changeset
61 return module:fire_event("iq-"..type.."/self/"..stanza.attr.id, data);
2686
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
62 end
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
63 end);
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
64
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
65 module:hook("iq/host", function(data)
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
66 -- IQ to a local host recieved
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
67 local origin, stanza = data.origin, data.stanza;
3787
95aaf9fc5a6c mod_iq: Optimized a bit (fewer table accesses).
Waqas Hussain <waqas20@gmail.com>
parents: 3786
diff changeset
68 local type = stanza.attr.type;
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
69
3787
95aaf9fc5a6c mod_iq: Optimized a bit (fewer table accesses).
Waqas Hussain <waqas20@gmail.com>
parents: 3786
diff changeset
70 if type == "get" or type == "set" then
3788
588904a9fd8b mod_iq: Optimized a bit more (fewer table accesses).
Waqas Hussain <waqas20@gmail.com>
parents: 3787
diff changeset
71 local child = stanza.tags[1];
588904a9fd8b mod_iq: Optimized a bit more (fewer table accesses).
Waqas Hussain <waqas20@gmail.com>
parents: 3787
diff changeset
72 local ret = module:fire_event("iq/host/"..child.attr.xmlns..":"..child.name, data);
3786
28d9fff67fed mod_iq: Extra IQ get and set sub-events are now fired: "iq-{get,set}/{host,self,bare}/xmlns:tag" (when "iq/{host,self,bare}/xmlns:tag" is unhandled).
Waqas Hussain <waqas20@gmail.com>
parents: 3781
diff changeset
73 if ret ~= nil then return ret; end
3788
588904a9fd8b mod_iq: Optimized a bit more (fewer table accesses).
Waqas Hussain <waqas20@gmail.com>
parents: 3787
diff changeset
74 return module:fire_event("iq-"..type.."/host/"..child.attr.xmlns..":"..child.name, data);
1260
04c1fae0eb03 mod_iq: Fire sub-events for IQs directed at bare JIDs and hosts
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
75 else
3797
bd92e421728d mod_iq: Don't stop event dispatch for unhandled IQ errors and results (this lets negative priority handlers intercept the events).
Waqas Hussain <waqas20@gmail.com>
parents: 3788
diff changeset
76 return module:fire_event("iq-"..type.."/host/"..stanza.attr.id, data);
1260
04c1fae0eb03 mod_iq: Fire sub-events for IQs directed at bare JIDs and hosts
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
77 end
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
78 end);