Software /
code /
prosody
Annotate
plugins/mod_iq.lua @ 1267:1bf897de6c24
mod_iq: Immediately return an error for IQs to non-existing bare JIDs
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 01 Jun 2009 10:44:05 +0500 |
parent | 1266:605a73234230 |
child | 1268:dc1f95b37024 |
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 | |
1267
1bf897de6c24
mod_iq: Immediately return an error for IQs to non-existing bare JIDs
Waqas Hussain <waqas20@gmail.com>
parents:
1266
diff
changeset
|
29 if not bare_sessions[stanza.attr.to] then -- quick 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
|
30 local node, host = jid_split(stanza.attr.to); |
1bf897de6c24
mod_iq: Immediately return an error for IQs to non-existing bare JIDs
Waqas Hussain <waqas20@gmail.com>
parents:
1266
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 end |
1bf897de6c24
mod_iq: Immediately return an error for IQs to non-existing bare JIDs
Waqas Hussain <waqas20@gmail.com>
parents:
1266
diff
changeset
|
35 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
|
36 end |
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 |
1233 | 38 -- TODO fire post processing events |
1260
04c1fae0eb03
mod_iq: Fire sub-events for IQs directed at bare JIDs and hosts
Waqas Hussain <waqas20@gmail.com>
parents:
1234
diff
changeset
|
39 if #stanza.tags == 1 then |
1266
605a73234230
mod_iq: Include event data in sub-events
Waqas Hussain <waqas20@gmail.com>
parents:
1265
diff
changeset
|
40 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
|
41 else |
04c1fae0eb03
mod_iq: Fire sub-events for IQs directed at bare JIDs and hosts
Waqas Hussain <waqas20@gmail.com>
parents:
1234
diff
changeset
|
42 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
|
43 end |
1233 | 44 end); |
45 | |
46 module:hook("iq/host", function(data) | |
47 -- IQ to a local host recieved | |
48 local origin, stanza = data.origin, data.stanza; | |
49 | |
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 if #stanza.tags == 1 then |
1266
605a73234230
mod_iq: Include event data in sub-events
Waqas Hussain <waqas20@gmail.com>
parents:
1265
diff
changeset
|
51 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
|
52 else |
04c1fae0eb03
mod_iq: Fire sub-events for IQs directed at bare JIDs and hosts
Waqas Hussain <waqas20@gmail.com>
parents:
1234
diff
changeset
|
53 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
|
54 end |
1233 | 55 end); |