Comparison

plugins/mod_iq.lua @ 3787:95aaf9fc5a6c

mod_iq: Optimized a bit (fewer table accesses).
author Waqas Hussain <waqas20@gmail.com>
date Sun, 28 Nov 2010 02:37:18 +0500
parent 3786:28d9fff67fed
child 3658:13600f0d56b5
comparison
equal deleted inserted replaced
3786:28d9fff67fed 3787:95aaf9fc5a6c
30 end); 30 end);
31 31
32 module:hook("iq/bare", function(data) 32 module:hook("iq/bare", function(data)
33 -- IQ to bare JID recieved 33 -- IQ to bare JID recieved
34 local origin, stanza = data.origin, data.stanza; 34 local origin, stanza = data.origin, data.stanza;
35 local type = stanza.attr.type;
35 36
36 -- TODO fire post processing events 37 -- TODO fire post processing events
37 if stanza.attr.type == "get" or stanza.attr.type == "set" then 38 if type == "get" or type == "set" then
38 local ret = module:fire_event("iq/bare/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data); 39 local ret = module:fire_event("iq/bare/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data);
39 if ret ~= nil then return ret; end 40 if ret ~= nil then return ret; end
40 return module:fire_event("iq-"..stanza.attr.type.."/bare/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data); 41 return module:fire_event("iq-"..type.."/bare/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data);
41 else 42 else
42 module:fire_event("iq-"..stanza.attr.type.."/bare/"..stanza.attr.id, data); 43 module:fire_event("iq-"..type.."/bare/"..stanza.attr.id, data);
43 return true; 44 return true;
44 end 45 end
45 end); 46 end);
46 47
47 module:hook("iq/self", function(data) 48 module:hook("iq/self", function(data)
48 -- IQ to self JID recieved 49 -- IQ to self JID recieved
49 local origin, stanza = data.origin, data.stanza; 50 local origin, stanza = data.origin, data.stanza;
51 local type = stanza.attr.type;
50 52
51 if stanza.attr.type == "get" or stanza.attr.type == "set" then 53 if type == "get" or type == "set" then
52 local ret = module:fire_event("iq/self/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data); 54 local ret = module:fire_event("iq/self/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data);
53 if ret ~= nil then return ret; end 55 if ret ~= nil then return ret; end
54 return module:fire_event("iq-"..stanza.attr.type.."/self/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data); 56 return module:fire_event("iq-"..type.."/self/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data);
55 else 57 else
56 module:fire_event("iq-"..stanza.attr.type.."/self/"..stanza.attr.id, data); 58 module:fire_event("iq-"..type.."/self/"..stanza.attr.id, data);
57 return true; 59 return true;
58 end 60 end
59 end); 61 end);
60 62
61 module:hook("iq/host", function(data) 63 module:hook("iq/host", function(data)
62 -- IQ to a local host recieved 64 -- IQ to a local host recieved
63 local origin, stanza = data.origin, data.stanza; 65 local origin, stanza = data.origin, data.stanza;
66 local type = stanza.attr.type;
64 67
65 if stanza.attr.type == "get" or stanza.attr.type == "set" then 68 if type == "get" or type == "set" then
66 local ret = module:fire_event("iq/host/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data); 69 local ret = module:fire_event("iq/host/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data);
67 if ret ~= nil then return ret; end 70 if ret ~= nil then return ret; end
68 return module:fire_event("iq-"..stanza.attr.type.."/host/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data); 71 return module:fire_event("iq-"..type.."/host/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name, data);
69 else 72 else
70 module:fire_event("iq-"..stanza.attr.type.."/host/"..stanza.attr.id, data); 73 module:fire_event("iq-"..type.."/host/"..stanza.attr.id, data);
71 return true; 74 return true;
72 end 75 end
73 end); 76 end);