aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2010-05-09 20:48:21 +0100
committerMatthew Wild <mwild1@gmail.com>2010-05-09 20:48:21 +0100
commit42d89c47c763d1a9449cc99f7e4bfbfda842048d (patch)
tree347f907468606b2abb1935bffe1d5b562dc71b5b
parente01ef118810baf017693bdb4afc323207d2f479d (diff)
downloadprosody-42d89c47c763d1a9449cc99f7e4bfbfda842048d.tar.gz
prosody-42d89c47c763d1a9449cc99f7e4bfbfda842048d.zip
net.xmppclient_listener: Port to util.xmppstream \o/
-rw-r--r--net/xmppclient_listener.lua39
1 files changed, 18 insertions, 21 deletions
diff --git a/net/xmppclient_listener.lua b/net/xmppclient_listener.lua
index 94daa2b2..f3a372ae 100644
--- a/net/xmppclient_listener.lua
+++ b/net/xmppclient_listener.lua
@@ -11,7 +11,7 @@
local logger = require "logger";
local log = logger.init("xmppclient_listener");
local lxp = require "lxp"
-local init_xmlhandlers = require "core.xmlhandlers"
+local new_xmpp_stream = require "util.xmppstream".new;
local sm_new_session = require "core.sessionmanager".new_session;
local connlisteners_register = require "net.connlisteners".register;
@@ -72,23 +72,6 @@ local xmppclient = { default_port = 5222, default_mode = "*a" };
-- These are session methods --
-local function session_reset_stream(session)
- -- Reset stream
- local parser = lxp.new(init_xmlhandlers(session, stream_callbacks), "\1");
- session.parser = parser;
-
- session.notopen = true;
-
- function session.data(conn, data)
- local ok, err = parser:parse(data);
- if ok then return; end
- log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_"));
- session:close("xml-not-well-formed");
- end
-
- return true;
-end
-
local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'};
local default_stream_attr = { ["xmlns:stream"] = "http://etherx.jabber.org/streams", xmlns = stream_callbacks.default_ns, version = "1.0", id = "" };
local function session_close(session, reason)
@@ -145,15 +128,29 @@ function xmppclient.onincoming(conn, data)
conn:setoption("keepalive", opt_keepalives);
end
- session.reset_stream = session_reset_stream;
session.close = session_close;
- session_reset_stream(session); -- Initialise, ready for use
+ local stream = new_xmpp_stream(session, stream_callbacks);
+ session.stream = stream;
+
+ session.notopen = true;
+
+ function session.reset_stream()
+ session.notopen = true;
+ session.stream:reset();
+ end
+
+ function session.data(data)
+ local ok, err = stream:feed(data);
+ if ok then return; end
+ log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_"));
+ session:close("xml-not-well-formed");
+ end
session.dispatch_stanza = stream_callbacks.handlestanza;
end
if data then
- session.data(conn, data);
+ session.data(data);
end
end