xmlhandlers: Rearranged a little code.
[prosody.git] / core / xmlhandlers.lua
index 85ce1040e1c441e59869e936237f4077b000b2a8..3d6ace12d0b5ce030bc0c258f4e68c74122db090 100644 (file)
@@ -116,7 +116,24 @@ function init_xmlhandlers(session, stream_callbacks)
                if name == "" then
                        curr_ns, name = "", curr_ns;
                end
-               if not stanza then
+               if stanza then
+                       if #chardata > 0 then
+                               -- We have some character data in the buffer
+                               stanza:text(t_concat(chardata));
+                               chardata = {};
+                       end
+                       -- Complete stanza
+                       if #stanza.last_add == 0 then
+                               if tagname ~= stream_error_tag then
+                                       cb_handlestanza(session, stanza);
+                               else
+                                       cb_error(session, "stream-error", stanza);
+                               end
+                               stanza = nil;
+                       else
+                               stanza:up();
+                       end
+               else
                        if tagname == stream_tag then
                                if cb_streamclosed then
                                        cb_streamclosed(session);
@@ -125,23 +142,6 @@ function init_xmlhandlers(session, stream_callbacks)
                                cb_error(session, "parse-error", "unexpected-element-close", name);
                        end
                        stanza, chardata = nil, {};
-                       return;
-               end
-               if #chardata > 0 then
-                       -- We have some character data in the buffer
-                       stanza:text(t_concat(chardata));
-                       chardata = {};
-               end
-               -- Complete stanza
-               if #stanza.last_add == 0 then
-                       if tagname ~= stream_error_tag then
-                               cb_handlestanza(session, stanza);
-                       else
-                               cb_error(session, "stream-error", stanza);
-                       end
-                       stanza = nil;
-               else
-                       stanza:up();
                end
        end
        return xml_handlers;