Annotate

plugins/mod_iq.lua @ 3656:71fd1582f01b

mod_iq: Extra IQ get and set sub-events are now fired: "iq-{get,set}/{host,self,bare}/xmlns:tag" (when "iq/{host,self,bare}/xmlns:tag" is unhandled).
author Waqas Hussain <waqas20@gmail.com>
date Sun, 28 Nov 2010 02:24:26 +0500
parent 3647:140ce81778ca
child 3657:07f0c2ef16cb
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
2923
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 1522
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 1522
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
1522
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;
1234
0ff02499f05c mod_message, mod_iq: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents: 1233
diff changeset
12
0ff02499f05c mod_message, mod_iq: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents: 1233
diff changeset
13 local full_sessions = full_sessions;
0ff02499f05c mod_message, mod_iq: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents: 1233
diff changeset
14 local bare_sessions = bare_sessions;
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16 module:hook("iq/full", function(data)
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
17 -- IQ to full JID recieved
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
18 local origin, stanza = data.origin, data.stanza;
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
20 local session = full_sessions[stanza.attr.to];
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21 if session then
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22 -- TODO fire post processing event
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23 session.send(stanza);
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24 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
25 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
26 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
27 end
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28 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
29 return true;
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
30 end);
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
31
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
32 module:hook("iq/bare", function(data)
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
33 -- IQ to bare JID recieved
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34 local origin, stanza = data.origin, data.stanza;
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
36 -- 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
37 if stanza.attr.type == "get" or stanza.attr.type == "set" then
3656
71fd1582f01b mod_iq: Extra IQ get and set sub-events are now fired: "iq-{get,set}/{host,self,bare}/xmlns:tag" (when "iq/{host,self,bare}/xmlns:tag" is unhandled).
Waqas Hussain <waqas20@gmail.com>
parents: 3647
diff changeset
38 local ret = module:fire_event("iq/bare/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data);
71fd1582f01b mod_iq: Extra IQ get and set sub-events are now fired: "iq-{get,set}/{host,self,bare}/xmlns:tag" (when "iq/{host,self,bare}/xmlns:tag" is unhandled).
Waqas Hussain <waqas20@gmail.com>
parents: 3647
diff changeset
39 if ret ~= nil then return ret; end
71fd1582f01b mod_iq: Extra IQ get and set sub-events are now fired: "iq-{get,set}/{host,self,bare}/xmlns:tag" (when "iq/{host,self,bare}/xmlns:tag" is unhandled).
Waqas Hussain <waqas20@gmail.com>
parents: 3647
diff changeset
40 return module:fire_event("iq-"..stanza.attr.type.."/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
3647
140ce81778ca mod_iq: IQ error and result sub-events are now "iq-{error,result}/{host,self,bare}/id" (previously "iq/{host,self,bare}/id").
Waqas Hussain <waqas20@gmail.com>
parents: 3131
diff changeset
42 module:fire_event("iq-"..stanza.attr.type.."/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
43 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
44 end
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
45 end);
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
46
2686
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
47 module:hook("iq/self", function(data)
3656
71fd1582f01b mod_iq: Extra IQ get and set sub-events are now fired: "iq-{get,set}/{host,self,bare}/xmlns:tag" (when "iq/{host,self,bare}/xmlns:tag" is unhandled).
Waqas Hussain <waqas20@gmail.com>
parents: 3647
diff changeset
48 -- IQ to self JID recieved
2686
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
49 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
50
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
51 if stanza.attr.type == "get" or stanza.attr.type == "set" then
3656
71fd1582f01b mod_iq: Extra IQ get and set sub-events are now fired: "iq-{get,set}/{host,self,bare}/xmlns:tag" (when "iq/{host,self,bare}/xmlns:tag" is unhandled).
Waqas Hussain <waqas20@gmail.com>
parents: 3647
diff changeset
52 local ret = module:fire_event("iq/self/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data);
71fd1582f01b mod_iq: Extra IQ get and set sub-events are now fired: "iq-{get,set}/{host,self,bare}/xmlns:tag" (when "iq/{host,self,bare}/xmlns:tag" is unhandled).
Waqas Hussain <waqas20@gmail.com>
parents: 3647
diff changeset
53 if ret ~= nil then return ret; end
71fd1582f01b mod_iq: Extra IQ get and set sub-events are now fired: "iq-{get,set}/{host,self,bare}/xmlns:tag" (when "iq/{host,self,bare}/xmlns:tag" is unhandled).
Waqas Hussain <waqas20@gmail.com>
parents: 3647
diff changeset
54 return module:fire_event("iq-"..stanza.attr.type.."/self/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data);
2686
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
55 else
3647
140ce81778ca mod_iq: IQ error and result sub-events are now "iq-{error,result}/{host,self,bare}/id" (previously "iq/{host,self,bare}/id").
Waqas Hussain <waqas20@gmail.com>
parents: 3131
diff changeset
56 module:fire_event("iq-"..stanza.attr.type.."/self/"..stanza.attr.id, data);
2686
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
57 return true;
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
58 end
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
59 end);
d0d38fcaade0 mod_iq: Fire sub-events for iq/self events.
Waqas Hussain <waqas20@gmail.com>
parents: 1522
diff changeset
60
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
61 module:hook("iq/host", function(data)
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
62 -- IQ to a local host recieved
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
63 local origin, stanza = data.origin, data.stanza;
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
64
1288
d2dc0954ebfd mod_iq: Limit sub-events to get and set IQs
Waqas Hussain <waqas20@gmail.com>
parents: 1268
diff changeset
65 if stanza.attr.type == "get" or stanza.attr.type == "set" then
3656
71fd1582f01b mod_iq: Extra IQ get and set sub-events are now fired: "iq-{get,set}/{host,self,bare}/xmlns:tag" (when "iq/{host,self,bare}/xmlns:tag" is unhandled).
Waqas Hussain <waqas20@gmail.com>
parents: 3647
diff changeset
66 local ret = module:fire_event("iq/host/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data);
71fd1582f01b mod_iq: Extra IQ get and set sub-events are now fired: "iq-{get,set}/{host,self,bare}/xmlns:tag" (when "iq/{host,self,bare}/xmlns:tag" is unhandled).
Waqas Hussain <waqas20@gmail.com>
parents: 3647
diff changeset
67 if ret ~= nil then return ret; end
71fd1582f01b mod_iq: Extra IQ get and set sub-events are now fired: "iq-{get,set}/{host,self,bare}/xmlns:tag" (when "iq/{host,self,bare}/xmlns:tag" is unhandled).
Waqas Hussain <waqas20@gmail.com>
parents: 3647
diff changeset
68 return module:fire_event("iq-"..stanza.attr.type.."/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
69 else
3647
140ce81778ca mod_iq: IQ error and result sub-events are now "iq-{error,result}/{host,self,bare}/id" (previously "iq/{host,self,bare}/id").
Waqas Hussain <waqas20@gmail.com>
parents: 3131
diff changeset
70 module:fire_event("iq-"..stanza.attr.type.."/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
71 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
72 end
1233
4c8c3d7d9c27 mod_iq: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
73 end);