Software /
code /
prosody
Annotate
plugins/mod_iq.lua @ 2686:d0d38fcaade0
mod_iq: Fire sub-events for iq/self events.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 21 Feb 2010 17:43:39 +0500 |
parent | 1522:569d58d21612 |
child | 2925:692b3c6c5bd2 |
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 | 16 |
17 module:hook("iq/full", function(data) | |
18 -- IQ to full JID recieved | |
19 local origin, stanza = data.origin, data.stanza; | |
20 | |
21 local session = full_sessions[stanza.attr.to]; | |
22 if session then | |
23 -- TODO fire post processing event | |
24 session.send(stanza); | |
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 | 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 | 31 end); |
32 | |
33 module:hook("iq/bare", function(data) | |
34 -- IQ to bare JID recieved | |
35 local origin, stanza = data.origin, data.stanza; | |
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 | 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 | 54 end); |
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 | 68 module:hook("iq/host", function(data) |
69 -- IQ to a local host recieved | |
70 local origin, stanza = data.origin, data.stanza; | |
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 | 78 end); |