Annotate

plugins/mod_iq.lua @ 2825:914d7afb8212

Mainfile: Broke up a really long line.
author Waqas Hussain <waqas20@gmail.com>
date Thu, 10 Dec 2009 01:56:16 +0500
parent 1522:569d58d21612
child 2686:d0d38fcaade0
child 2923:b7049746bd29
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
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1421
diff changeset
2 -- Copyright (C) 2008-2009 Matthew Wild
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1421
diff changeset
3 -- Copyright (C) 2008-2009 Waqas Hussain
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
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
56 module:hook("iq/host", function(data)
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
57 -- IQ to a local host recieved
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
58 local origin, stanza = data.origin, data.stanza;
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
59
1288
d2dc0954ebfd mod_iq: Limit sub-events to get and set IQs
Waqas Hussain <waqas20@gmail.com>
parents: 1268
diff changeset
60 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
61 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
62 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
63 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
64 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
65 end
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
66 end);