Comparison

net/xmppserver_listener.lua @ 2471:2aeb55a51f47

net.xmppserver_listener: Handle stream-error errors from xmlhandlers, and close session in response
author Matthew Wild <mwild1@gmail.com>
date Tue, 19 Jan 2010 04:38:43 +0000
parent 2470:2c3f05c01d7c
child 2560:56063f825199
comparison
equal deleted inserted replaced
2470:2c3f05c01d7c 2471:2aeb55a51f47
18 local s2s_destroy_session = require "core.s2smanager".destroy_session; 18 local s2s_destroy_session = require "core.s2smanager".destroy_session;
19 local s2s_attempt_connect = require "core.s2smanager".attempt_connection; 19 local s2s_attempt_connect = require "core.s2smanager".attempt_connection;
20 local stream_callbacks = { default_ns = "jabber:server", 20 local stream_callbacks = { default_ns = "jabber:server",
21 streamopened = s2s_streamopened, streamclosed = s2s_streamclosed, handlestanza = core_process_stanza }; 21 streamopened = s2s_streamopened, streamclosed = s2s_streamclosed, handlestanza = core_process_stanza };
22 22
23 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams";
24
23 function stream_callbacks.error(session, error, data) 25 function stream_callbacks.error(session, error, data)
24 if error == "no-stream" then 26 if error == "no-stream" then
25 session:close("invalid-namespace"); 27 session:close("invalid-namespace");
26 else 28 elseif error == "parse-error" then
27 session.log("debug", "Server-to-server XML parse error: %s", tostring(error)); 29 session.log("debug", "Server-to-server XML parse error: %s", tostring(error));
28 session:close("xml-not-well-formed"); 30 session:close("xml-not-well-formed");
31 elseif error == "stream-error" then
32 local condition, text = "undefined-condition";
33 for child in data:children() do
34 if child.attr.xmlns == xmlns_xmpp_streams then
35 if child.name ~= "text" then
36 condition = child.name;
37 else
38 text = child:get_text();
39 end
40 if condition ~= "undefined-condition" and text then
41 break;
42 end
43 end
44 end
45 text = condition .. (text and (" ("..text..")") or "");
46 session.log("info", "Session closed by remote with error: %s", text);
47 session:close(nil, text);
29 end 48 end
30 end 49 end
31 50
32 local function handleerr(err) log("error", "Traceback[s2s]: %s: %s", tostring(err), debug.traceback()); end 51 local function handleerr(err) log("error", "Traceback[s2s]: %s: %s", tostring(err), debug.traceback()); end
33 function stream_callbacks.handlestanza(a, b) 52 function stream_callbacks.handlestanza(a, b)