Committing code to get nicer tracebacks for errors, also we no longer consider such...
[prosody.git] / net / xmppclient_listener.lua
index 7d5b3abef1a212e7f048871cf7e0313e1b8f3e91..64747bc5b960e47fb58cc3607a2ea0b924a8e698 100644 (file)
@@ -22,7 +22,7 @@ local xmppclient = { default_port = 5222 };
 
 local function session_reset_stream(session)
        -- Reset stream
-               local parser = lxp.new(init_xmlhandlers(session, sm_streamopened), ":");
+               local parser = lxp.new(init_xmlhandlers(session, sm_streamopened), "|");
                session.parser = parser;
                
                session.notopen = true;
@@ -60,7 +60,12 @@ function xmppclient.listener(conn, data)
                -- TODO: Below function should be session,stanza - and xmlhandlers should use :method() notation to call,
                -- this will avoid the useless indirection we have atm
                -- (I'm on a mission, no time to fix now)
-               session.stanza_dispatch = function (stanza) return core_process_stanza(session, stanza); end
+
+               -- Debug version --
+               local function handleerr() print("Traceback:", debug.traceback()); end
+               session.stanza_dispatch = function (stanza) return select(2, xpcall(function () return core_process_stanza(session, stanza); end, handleerr));  end
+
+--             session.stanza_dispatch = function (stanza) return core_process_stanza(session, stanza); end
 
        end
        if data then
@@ -69,6 +74,19 @@ function xmppclient.listener(conn, data)
 end
        
 function xmppclient.disconnect(conn)
+       local session = sessions[conn];
+       if session then
+               if session.last_presence and session.last_presence.attr.type ~= "unavailable" then
+                       local pres = st.presence{ type = "unavailable" };
+                       if err == "closed" then err = "connection closed"; end
+                       pres:tag("status"):text("Disconnected: "..err);
+                       session.stanza_dispatch(pres);
+               end
+               sm_destroy_session(session);
+               sessions[conn]  = nil;
+               session = nil;
+               collectgarbage("collect");
+       end
 end
 
 connlisteners_register("xmppclient", xmppclient);