util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
[prosody.git] / util / xmppstream.lua
index 0a6d554b734333aee3f42bbae8df4401d7702b43..cbdadd9bcbe3dac89a48665956ba69e29f1c34cb 100644 (file)
@@ -14,7 +14,7 @@ local tostring = tostring;
 local t_insert = table.insert;
 local t_concat = table.concat;
 
-local default_log = require "util.logger".init("xmlhandlers");
+local default_log = require "util.logger".init("xmppstream");
 
 local error = error;
 
@@ -31,6 +31,9 @@ local xmlns_streams = "http://etherx.jabber.org/streams";
 local ns_separator = "\1";
 local ns_pattern = "^([^"..ns_separator.."]*)"..ns_separator.."?(.*)$";
 
+_M.ns_separator = ns_separator;
+_M.ns_pattern = ns_pattern;
+
 function new_sax_handlers(session, stream_callbacks)
        local xml_handlers = {};
        
@@ -42,7 +45,10 @@ function new_sax_handlers(session, stream_callbacks)
        local cb_handlestanza = stream_callbacks.handlestanza;
        
        local stream_ns = stream_callbacks.stream_ns or xmlns_streams;
-       local stream_tag = stream_ns..ns_separator..(stream_callbacks.stream_tag or "stream");
+       local stream_tag = stream_callbacks.stream_tag or "stream";
+       if stream_ns ~= "" then
+               stream_tag = stream_ns..ns_separator..stream_tag;
+       end
        local stream_error_tag = stream_ns..ns_separator..(stream_callbacks.error_tag or "error");
        
        local stream_default_ns = stream_callbacks.default_ns;
@@ -117,7 +123,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