Software /
code /
prosody
Comparison
net/xmppclient_listener.lua @ 2753:305428b14f76
net.xmppclient_listener: Fix to correctly handle stream errors from clients
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 14 Mar 2010 03:01:00 +0000 |
parent | 2466:0e44b6035210 |
child | 2925:692b3c6c5bd2 |
comparison
equal
deleted
inserted
replaced
2752:18d8009f06cb | 2753:305428b14f76 |
---|---|
31 local opt_keepalives = config.get("*", "core", "tcp_keepalives"); | 31 local opt_keepalives = config.get("*", "core", "tcp_keepalives"); |
32 | 32 |
33 local stream_callbacks = { default_ns = "jabber:client", | 33 local stream_callbacks = { default_ns = "jabber:client", |
34 streamopened = sm_streamopened, streamclosed = sm_streamclosed, handlestanza = core_process_stanza }; | 34 streamopened = sm_streamopened, streamclosed = sm_streamclosed, handlestanza = core_process_stanza }; |
35 | 35 |
36 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; | |
37 | |
36 function stream_callbacks.error(session, error, data) | 38 function stream_callbacks.error(session, error, data) |
37 if error == "no-stream" then | 39 if error == "no-stream" then |
38 session.log("debug", "Invalid opening stream header"); | 40 session.log("debug", "Invalid opening stream header"); |
39 session:close("invalid-namespace"); | 41 session:close("invalid-namespace"); |
40 elseif session.close then | 42 elseif error == "parse-error" then |
41 (session.log or log)("debug", "Client XML parse error: %s", tostring(error)); | 43 (session.log or log)("debug", "Client XML parse error: %s", tostring(data)); |
42 session:close("xml-not-well-formed"); | 44 session:close("xml-not-well-formed"); |
45 elseif error == "stream-error" then | |
46 local condition, text = "undefined-condition"; | |
47 for child in data:children() do | |
48 if child.attr.xmlns == xmlns_xmpp_streams then | |
49 if child.name ~= "text" then | |
50 condition = child.name; | |
51 else | |
52 text = child:get_text(); | |
53 end | |
54 if condition ~= "undefined-condition" and text then | |
55 break; | |
56 end | |
57 end | |
58 end | |
59 text = condition .. (text and (" ("..text..")") or ""); | |
60 session.log("info", "Session closed by remote with error: %s", text); | |
61 session:close(nil, text); | |
43 end | 62 end |
44 end | 63 end |
45 | 64 |
46 local function handleerr(err) log("error", "Traceback[c2s]: %s: %s", tostring(err), debug.traceback()); end | 65 local function handleerr(err) log("error", "Traceback[c2s]: %s: %s", tostring(err), debug.traceback()); end |
47 function stream_callbacks.handlestanza(a, b) | 66 function stream_callbacks.handlestanza(a, b) |