Annotate

plugins/mod_iq.lua @ 3102:5cd408e36359

util.sasl.scram: Parsing client-final-message in a more strict way. (thanks Marc Santamaria)
author Tobias Markmann <tm@ayena.de>
date Sat, 22 May 2010 14:47:21 +0200
parent 2925:692b3c6c5bd2
child 3131:5c116a10ff0b
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;
1bf897de6c24 mod_iq: Immediately return an error for IQs to non-existing bare JIDs
Waqas Hussain <waqas20@gmail.com>
parents: 1266
diff changeset
12 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
13
0ff02499f05c mod_message, mod_iq: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents: 1233
diff changeset
14 local full_sessions = full_sessions;
0ff02499f05c mod_message, mod_iq: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents: 1233
diff changeset
15 local bare_sessions = bare_sessions;
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
17 module:hook("iq/full", function(data)
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
18 -- IQ to full JID recieved
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19 local origin, stanza = data.origin, data.stanza;
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
20
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21 local session = full_sessions[stanza.attr.to];
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22 if session then
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23 -- TODO fire post processing event
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24 session.send(stanza);
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
25 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
26 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
27 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
28 end
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
29 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
30 return true;
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
31 end);
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
32
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
33 module:hook("iq/bare", function(data)
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34 -- IQ to bare JID recieved
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35 local origin, stanza = data.origin, data.stanza;
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
36
1268
dc1f95b37024 mod_iq: Correctly handle the lack of 'to' on IQs
Waqas Hussain <waqas20@gmail.com>
parents: 1267
diff changeset
37 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
38 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
39 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
40 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
41 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
42 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
43 end
1bf897de6c24 mod_iq: Immediately return an error for IQs to non-existing bare JIDs
Waqas Hussain <waqas20@gmail.com>
parents: 1266
diff changeset
44 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
45 end
1bf897de6c24 mod_iq: Immediately return an error for IQs to non-existing bare JIDs
Waqas Hussain <waqas20@gmail.com>
parents: 1266
diff changeset
46 end
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47 -- 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
48 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
49 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
50 else
1421
7dafb3bae02b mod_iq: Change sub-event names for IQ errors and results to use stanza IDs
Waqas Hussain <waqas20@gmail.com>
parents: 1403
diff changeset
51 module:fire_event("iq/bare/"..stanza.attr.id, data);
1403
a1762cfd4d83 mod_iq: Fire sub-events for IQ results and errors
Waqas Hussain <waqas20@gmail.com>
parents: 1288
diff changeset
52 return true;
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 end
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
54 end);
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
55
2686
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
56 module:hook("iq/self", function(data)
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
57 -- IQ to bare JID recieved
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
58 local origin, stanza = data.origin, data.stanza;
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
59
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
60 if stanza.attr.type == "get" or stanza.attr.type == "set" then
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
61 return module:fire_event("iq/self/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data);
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
62 else
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
63 module:fire_event("iq/self/"..stanza.attr.id, data);
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
64 return true;
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
65 end
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
66 end);
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
67
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
68 module:hook("iq/host", function(data)
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
69 -- IQ to a local host recieved
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
70 local origin, stanza = data.origin, data.stanza;
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
71
1288
d2dc0954ebfd mod_iq: Limit sub-events to get and set IQs
Waqas Hussain <waqas20@gmail.com>
parents: 1268
diff changeset
72 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
73 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
74 else
1421
7dafb3bae02b mod_iq: Change sub-event names for IQ errors and results to use stanza IDs
Waqas Hussain <waqas20@gmail.com>
parents: 1403
diff changeset
75 module:fire_event("iq/host/"..stanza.attr.id, data);
1403
a1762cfd4d83 mod_iq: Fire sub-events for IQ results and errors
Waqas Hussain <waqas20@gmail.com>
parents: 1288
diff changeset
76 return true;
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);