Software /
code /
prosody
Annotate
plugins/mod_iq.lua @ 1417:b02b22f77326
util.events: Replaced ipairs with slightly faster numeric for loop - #optimization
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Fri, 26 Jun 2009 08:52:26 +0500 |
parent | 1403:a1762cfd4d83 |
child | 1421:7dafb3bae02b |
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 | 8 |
9 module:hook("iq/full", function(data) | |
10 -- IQ to full JID recieved | |
11 local origin, stanza = data.origin, data.stanza; | |
12 | |
13 local session = full_sessions[stanza.attr.to]; | |
14 if session then | |
15 -- TODO fire post processing event | |
16 session.send(stanza); | |
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 | 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 | 23 end); |
24 | |
25 module:hook("iq/bare", function(data) | |
26 -- IQ to bare JID recieved | |
27 local origin, stanza = data.origin, data.stanza; | |
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 | 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 |
1403
a1762cfd4d83
mod_iq: Fire sub-events for IQ results and errors
Waqas Hussain <waqas20@gmail.com>
parents:
1288
diff
changeset
|
43 module:fire_event("iq/bare/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data); |
a1762cfd4d83
mod_iq: Fire sub-events for IQ results and errors
Waqas Hussain <waqas20@gmail.com>
parents:
1288
diff
changeset
|
44 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
|
45 end |
1233 | 46 end); |
47 | |
48 module:hook("iq/host", function(data) | |
49 -- IQ to a local host recieved | |
50 local origin, stanza = data.origin, data.stanza; | |
51 | |
1288
d2dc0954ebfd
mod_iq: Limit sub-events to get and set IQs
Waqas Hussain <waqas20@gmail.com>
parents:
1268
diff
changeset
|
52 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
|
53 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
|
54 else |
1403
a1762cfd4d83
mod_iq: Fire sub-events for IQ results and errors
Waqas Hussain <waqas20@gmail.com>
parents:
1288
diff
changeset
|
55 module:fire_event("iq/host/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data); |
a1762cfd4d83
mod_iq: Fire sub-events for IQ results and errors
Waqas Hussain <waqas20@gmail.com>
parents:
1288
diff
changeset
|
56 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
|
57 end |
1233 | 58 end); |