Software /
code /
prosody
Annotate
plugins/mod_iq.lua @ 1266:605a73234230
mod_iq: Include event data in sub-events
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 01 Jun 2009 10:27:47 +0500 |
parent | 1265:3f3c62e45eeb |
child | 1267:1bf897de6c24 |
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"; |
1234
0ff02499f05c
mod_message, mod_iq: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1233
diff
changeset
|
3 |
0ff02499f05c
mod_message, mod_iq: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1233
diff
changeset
|
4 local full_sessions = full_sessions; |
0ff02499f05c
mod_message, mod_iq: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1233
diff
changeset
|
5 local bare_sessions = bare_sessions; |
1233 | 6 |
7 module:hook("iq/full", function(data) | |
8 -- IQ to full JID recieved | |
9 local origin, stanza = data.origin, data.stanza; | |
10 | |
11 local session = full_sessions[stanza.attr.to]; | |
12 if session then | |
13 -- TODO fire post processing event | |
14 session.send(stanza); | |
15 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
|
16 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
|
17 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
|
18 end |
1233 | 19 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
|
20 return true; |
1233 | 21 end); |
22 | |
23 module:hook("iq/bare", function(data) | |
24 -- IQ to bare JID recieved | |
25 local origin, stanza = data.origin, data.stanza; | |
26 | |
27 -- TODO if not user exists, return an error | |
28 -- 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
|
29 if #stanza.tags == 1 then |
1266
605a73234230
mod_iq: Include event data in sub-events
Waqas Hussain <waqas20@gmail.com>
parents:
1265
diff
changeset
|
30 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
|
31 else |
04c1fae0eb03
mod_iq: Fire sub-events for IQs directed at bare JIDs and hosts
Waqas Hussain <waqas20@gmail.com>
parents:
1234
diff
changeset
|
32 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
|
33 end |
1233 | 34 end); |
35 | |
36 module:hook("iq/host", function(data) | |
37 -- IQ to a local host recieved | |
38 local origin, stanza = data.origin, data.stanza; | |
39 | |
1260
04c1fae0eb03
mod_iq: Fire sub-events for IQs directed at bare JIDs and hosts
Waqas Hussain <waqas20@gmail.com>
parents:
1234
diff
changeset
|
40 if #stanza.tags == 1 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/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
|
42 else |
04c1fae0eb03
mod_iq: Fire sub-events for IQs directed at bare JIDs and hosts
Waqas Hussain <waqas20@gmail.com>
parents:
1234
diff
changeset
|
43 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
|
44 end |
1233 | 45 end); |