aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2008-12-04 18:47:26 +0000
committerMatthew Wild <mwild1@gmail.com>2008-12-04 18:47:26 +0000
commit327c81737eb11a340005c7078015c46fdfea6390 (patch)
tree0a9be2aaafe45ef79cb1ba525f2579b9898fc741 /core
parent533449b6d26621a0e410e84003f1902e319bbfb6 (diff)
downloadprosody-327c81737eb11a340005c7078015c46fdfea6390.tar.gz
prosody-327c81737eb11a340005c7078015c46fdfea6390.zip
Abstract xmlhandlers a bit more, also add error callbacks
Diffstat (limited to 'core')
-rw-r--r--core/xmlhandlers.lua20
1 files changed, 11 insertions, 9 deletions
diff --git a/core/xmlhandlers.lua b/core/xmlhandlers.lua
index ec3051b4..2872a036 100644
--- a/core/xmlhandlers.lua
+++ b/core/xmlhandlers.lua
@@ -52,12 +52,13 @@ function init_xmlhandlers(session, stream_callbacks)
local chardata = {};
local xml_handlers = {};
local log = session.log or default_log;
- --local print = function (...) log("info", "xmlhandlers", t_concatall({...}, "\t")); end
-
+
local send = session.send;
local cb_streamopened = stream_callbacks.streamopened;
local cb_streamclosed = stream_callbacks.streamclosed;
+ local cb_error = stream_callbacks.error or function (e) error("XML stream error: "..tostring(e)); end;
+ local cb_handlestanza = stream_callbacks.handlestanza;
local stanza
function xml_handlers:StartElement(name, attr)
@@ -92,12 +93,14 @@ function init_xmlhandlers(session, stream_callbacks)
if cb_streamopened then
cb_streamopened(session, attr);
end
- return;
+ else
+ -- Garbage before stream?
+ cb_error("no-stream");
end
- error("Client failed to open stream successfully");
+ return;
end
if curr_ns == "jabber:client" and name ~= "iq" and name ~= "presence" and name ~= "message" then
- error("Client sent invalid top-level stanza");
+ cb_error("invalid-top-level-element");
end
stanza = st.stanza(name, attr);
@@ -119,15 +122,14 @@ function init_xmlhandlers(session, stream_callbacks)
curr_ns,name = name:match("^(.+)|([%w%-]+)$");
if (not stanza) or (#stanza.last_add > 0 and name ~= stanza.last_add[#stanza.last_add].name) then
if name == "stream" then
- log("debug", "Stream closed");
if cb_streamclosed then
cb_streamclosed(session);
end
return;
elseif name == "error" then
- error("Stream error: "..tostring(name)..": "..tostring(stanza));
+ cb_error("stream-error", stanza);
else
- error("XML parse error in client stream with element: "..name);
+ cb_error("parse-error", "unexpected-element-close", name);
end
end
if stanza and #chardata > 0 then
@@ -137,7 +139,7 @@ function init_xmlhandlers(session, stream_callbacks)
end
-- Complete stanza
if #stanza.last_add == 0 then
- session.stanza_dispatch(stanza);
+ cb_handlestanza(session, stanza);
stanza = nil;
else
stanza:up();