mod_adhoc: Use mod_disco for disco handling
[prosody.git] / plugins / mod_bosh.lua
index 9a612ae0882652d45d9c885776a7fd0d81c3bac1..d109547e4820ed6e07205a871d3e2cf279485129 100644 (file)
@@ -20,6 +20,8 @@ local logger = require "util.logger";
 local log = logger.init("mod_bosh");
 local initialize_filters = require "util.filters".initialize;
 local math_min = math.min;
+local xpcall, tostring, type = xpcall, tostring, type;
+local traceback = debug.traceback;
 
 local xmlns_streams = "http://etherx.jabber.org/streams";
 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams";
@@ -347,12 +349,12 @@ function stream_callbacks.streamopened(context, attr)
        if session.notopen then
                local features = st.stanza("stream:features");
                hosts[session.host].events.fire_event("stream-features", { origin = session, features = features });
-               fire_event("stream-features", session, features);
                session.send(features);
                session.notopen = nil;
        end
 end
 
+local function handleerr(err) log("error", "Traceback[bosh]: %s", traceback(tostring(err), 2)); end
 function stream_callbacks.handlestanza(context, stanza)
        if context.ignore then return; end
        log("debug", "BOSH stanza received: %s\n", stanza:top_tag());
@@ -362,7 +364,9 @@ function stream_callbacks.handlestanza(context, stanza)
                        stanza.attr.xmlns = nil;
                end
                stanza = session.filter("stanzas/in", stanza);
-               core_process_stanza(session, stanza);
+               if stanza then
+                       return xpcall(function () return core_process_stanza(session, stanza) end, handleerr);
+               end
        end
 end