aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/xmlhandlers.lua3
-rw-r--r--util/stanza.lua25
-rw-r--r--util/xmppstream.lua3
3 files changed, 16 insertions, 15 deletions
diff --git a/core/xmlhandlers.lua b/core/xmlhandlers.lua
index 182da894..c587548a 100644
--- a/core/xmlhandlers.lua
+++ b/core/xmlhandlers.lua
@@ -114,7 +114,8 @@ function init_xmlhandlers(session, stream_callbacks)
chardata = {};
end
-- Complete stanza
- if #stanza.last_add == 0 then
+ local last_add = stanza.last_add;
+ if not last_add or #last_add == 0 then
if tagname ~= stream_error_tag then
cb_handlestanza(session, stanza);
else
diff --git a/util/stanza.lua b/util/stanza.lua
index 28e26e0a..307a858a 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -46,7 +46,7 @@ stanza_mt = { __type = "stanza" };
stanza_mt.__index = stanza_mt;
function stanza(name, attr)
- local stanza = { name = name, attr = attr or {}, tags = {}, last_add = {}};
+ local stanza = { name = name, attr = attr or {}, tags = {} };
return setmetatable(stanza, stanza_mt);
end
@@ -60,26 +60,27 @@ end
function stanza_mt:tag(name, attrs)
local s = stanza(name, attrs);
- (self.last_add[#self.last_add] or self):add_direct_child(s);
- t_insert(self.last_add, s);
+ local last_add = self.last_add;
+ if not last_add then last_add = {}; self.last_add = last_add; end
+ (last_add[#last_add] or self):add_direct_child(s);
+ t_insert(last_add, s);
return self;
end
function stanza_mt:text(text)
- (self.last_add[#self.last_add] or self):add_direct_child(text);
+ local last_add = self.last_add;
+ (last_add and last_add[#last_add] or self):add_direct_child(text);
return self;
end
function stanza_mt:up()
- t_remove(self.last_add);
+ local last_add = self.last_add;
+ if last_add then t_remove(last_add); end
return self;
end
function stanza_mt:reset()
- local last_add = self.last_add;
- for i = 1,#last_add do
- last_add[i] = nil;
- end
+ self.last_add = nil;
return self;
end
@@ -91,7 +92,8 @@ function stanza_mt:add_direct_child(child)
end
function stanza_mt:add_child(child)
- (self.last_add[#self.last_add] or self):add_direct_child(child);
+ local last_add = self.last_add;
+ (last_add and last_add[#last_add] or self):add_direct_child(child);
return self;
end
@@ -311,9 +313,6 @@ function deserialize(stanza)
end
end
stanza.tags = tags;
- if not stanza.last_add then
- stanza.last_add = {};
- end
end
end
diff --git a/util/xmppstream.lua b/util/xmppstream.lua
index 0a6d554b..29095e41 100644
--- a/util/xmppstream.lua
+++ b/util/xmppstream.lua
@@ -117,7 +117,8 @@ function new_sax_handlers(session, stream_callbacks)
chardata = {};
end
-- Complete stanza
- if #stanza.last_add == 0 then
+ local last_add = stanza.last_add;
+ if not last_add or #last_add == 0 then
if tagname ~= stream_error_tag then
cb_handlestanza(session, stanza);
else