Software /
code /
verse
Comparison
client.lua @ 37:0ccd523e110a
verse.client: Don't hook the stanza event every time a stanza comes in :)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 21 Dec 2009 14:25:44 +0000 |
parent | 30:9c96318913f7 |
child | 38:c40cc28ac7df |
comparison
equal
deleted
inserted
replaced
36:fc2cd2f36cdd | 37:0ccd523e110a |
---|---|
31 if stanza.attr.xmlns == xmlns_stream then | 31 if stanza.attr.xmlns == xmlns_stream then |
32 return stream:event("stream-"..stanza.name, stanza); | 32 return stream:event("stream-"..stanza.name, stanza); |
33 elseif stanza.attr.xmlns then | 33 elseif stanza.attr.xmlns then |
34 return stream:event("stream/"..stanza.attr.xmlns, stanza); | 34 return stream:event("stream/"..stanza.attr.xmlns, stanza); |
35 end | 35 end |
36 | |
37 stream:hook("stanza", function (stanza) | |
38 if stanza.attr.xmlns == nil or stanza.attr.xmlns == "jabber:client" then | |
39 if stanza.name == "iq" and (stanza.attr.type == "get" or stanza.attr.type == "set") then | |
40 local xmlns = stanza.tags[1] and stanza.tags[1].attr.xmlns; | |
41 if xmlns then | |
42 ret = stream:event("iq/"..xmlns, stanza); | |
43 if not ret then | |
44 ret = stream:event("iq", stanza); | |
45 end | |
46 end | |
47 else | |
48 ret = stream:event(stanza.name, stanza); | |
49 end | |
50 end | |
51 return ret; | |
52 end, -1); | |
53 | 36 |
54 return stream:event("stanza", stanza); | 37 return stream:event("stanza", stanza); |
55 end | 38 end |
56 | 39 |
57 local function reset_stream(stream) | 40 local function reset_stream(stream) |
87 self.tracked_iqs[id] = nil; | 70 self.tracked_iqs[id] = nil; |
88 return true; | 71 return true; |
89 end | 72 end |
90 end); | 73 end); |
91 | 74 |
75 self:hook("stanza", function (stanza) | |
76 if stanza.attr.xmlns == nil or stanza.attr.xmlns == "jabber:client" then | |
77 if stanza.name == "iq" and (stanza.attr.type == "get" or stanza.attr.type == "set") then | |
78 local xmlns = stanza.tags[1] and stanza.tags[1].attr.xmlns; | |
79 if xmlns then | |
80 ret = self:event("iq/"..xmlns, stanza); | |
81 if not ret then | |
82 ret = self:event("iq", stanza); | |
83 end | |
84 end | |
85 else | |
86 ret = self:event(stanza.name, stanza); | |
87 end | |
88 end | |
89 return ret; | |
90 end, -1); | |
91 | |
92 -- Initialise connection | 92 -- Initialise connection |
93 self:connect(self.connect_host or self.host, self.connect_port or 5222); | 93 self:connect(self.connect_host or self.host, self.connect_port or 5222); |
94 --reset_stream(self); | 94 --reset_stream(self); |
95 self:reopen(); | 95 self:reopen(); |
96 end | 96 end |