Annotate

plugins/mod_iq.lua @ 1288:d2dc0954ebfd

mod_iq: Limit sub-events to get and set IQs
author Waqas Hussain <waqas20@gmail.com>
date Tue, 02 Jun 2009 20:18:02 +0500
parent 1268:dc1f95b37024
child 1403:a1762cfd4d83
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
1
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
2 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
3 local jid_split = require "util.jid".split;
1bf897de6c24 mod_iq: Immediately return an error for IQs to non-existing bare JIDs
Waqas Hussain <waqas20@gmail.com>
parents: 1266
diff changeset
4 local user_exists = require "core.usermanager".user_exists;
1234
0ff02499f05c mod_message, mod_iq: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents: 1233
diff changeset
5
0ff02499f05c mod_message, mod_iq: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents: 1233
diff changeset
6 local full_sessions = full_sessions;
0ff02499f05c mod_message, mod_iq: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents: 1233
diff changeset
7 local bare_sessions = bare_sessions;
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
8
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
9 module:hook("iq/full", function(data)
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
10 -- IQ to full JID recieved
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
11 local origin, stanza = data.origin, data.stanza;
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
12
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13 local session = full_sessions[stanza.attr.to];
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14 if session then
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15 -- TODO fire post processing event
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16 session.send(stanza);
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
17 else -- resource not online
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
18 if stanza.attr.type == "get" or stanza.attr.type == "set" then
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
19 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
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
20 end
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21 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
22 return true;
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23 end);
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
25 module:hook("iq/bare", function(data)
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26 -- IQ to bare JID recieved
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27 local origin, stanza = data.origin, data.stanza;
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28
1268
dc1f95b37024 mod_iq: Correctly handle the lack of 'to' on IQs
Waqas Hussain <waqas20@gmail.com>
parents: 1267
diff changeset
29 local to = stanza.attr.to;
dc1f95b37024 mod_iq: Correctly handle the lack of 'to' on IQs
Waqas Hussain <waqas20@gmail.com>
parents: 1267
diff changeset
30 if to and not bare_sessions[to] then -- quick check for account existance
dc1f95b37024 mod_iq: Correctly handle the lack of 'to' on IQs
Waqas Hussain <waqas20@gmail.com>
parents: 1267
diff changeset
31 local node, host = jid_split(to);
1267
1bf897de6c24 mod_iq: Immediately return an error for IQs to non-existing bare JIDs
Waqas Hussain <waqas20@gmail.com>
parents: 1266
diff changeset
32 if not user_exists(node, host) then -- full check for account existance
1bf897de6c24 mod_iq: Immediately return an error for IQs to non-existing bare JIDs
Waqas Hussain <waqas20@gmail.com>
parents: 1266
diff changeset
33 if stanza.attr.type == "get" or stanza.attr.type == "set" then
1bf897de6c24 mod_iq: Immediately return an error for IQs to non-existing bare JIDs
Waqas Hussain <waqas20@gmail.com>
parents: 1266
diff changeset
34 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
1bf897de6c24 mod_iq: Immediately return an error for IQs to non-existing bare JIDs
Waqas Hussain <waqas20@gmail.com>
parents: 1266
diff changeset
35 end
1bf897de6c24 mod_iq: Immediately return an error for IQs to non-existing bare JIDs
Waqas Hussain <waqas20@gmail.com>
parents: 1266
diff changeset
36 return true;
1bf897de6c24 mod_iq: Immediately return an error for IQs to non-existing bare JIDs
Waqas Hussain <waqas20@gmail.com>
parents: 1266
diff changeset
37 end
1bf897de6c24 mod_iq: Immediately return an error for IQs to non-existing bare JIDs
Waqas Hussain <waqas20@gmail.com>
parents: 1266
diff changeset
38 end
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
39 -- TODO fire post processing events
1288
d2dc0954ebfd mod_iq: Limit sub-events to get and set IQs
Waqas Hussain <waqas20@gmail.com>
parents: 1268
diff changeset
40 if stanza.attr.type == "get" or stanza.attr.type == "set" then
1266
605a73234230 mod_iq: Include event data in sub-events
Waqas Hussain <waqas20@gmail.com>
parents: 1265
diff changeset
41 return module:fire_event("iq/bare/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].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
42 else
04c1fae0eb03 mod_iq: Fire sub-events for IQs directed at bare JIDs and hosts
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
43 return true; -- TODO do something with results and errors
04c1fae0eb03 mod_iq: Fire sub-events for IQs directed at bare JIDs and hosts
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
44 end
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
45 end);
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
46
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47 module:hook("iq/host", function(data)
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
48 -- IQ to a local host recieved
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
49 local origin, stanza = data.origin, data.stanza;
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
50
1288
d2dc0954ebfd mod_iq: Limit sub-events to get and set IQs
Waqas Hussain <waqas20@gmail.com>
parents: 1268
diff changeset
51 if stanza.attr.type == "get" or stanza.attr.type == "set" then
1266
605a73234230 mod_iq: Include event data in sub-events
Waqas Hussain <waqas20@gmail.com>
parents: 1265
diff changeset
52 return module:fire_event("iq/host/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].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
53 else
04c1fae0eb03 mod_iq: Fire sub-events for IQs directed at bare JIDs and hosts
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
54 return true; -- TODO do something with results and errors
04c1fae0eb03 mod_iq: Fire sub-events for IQs directed at bare JIDs and hosts
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
55 end
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
56 end);