From 6c2578d43b71dfe93757e360d050de015ba455f5 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 3 Oct 2008 22:18:08 +0100 Subject: Move stream opening handling from xmlhandlers to sessionmanager --- core/sessionmanager.lua | 31 ++++++++++++++++++++++++++++++- core/xmlhandlers.lua | 21 ++------------------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index e89de262..deca21c0 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -1,11 +1,17 @@ -local tostring = tostring; +local tonumber, tostring = tonumber, tostring; +local ipairs = ipairs; + +local m_random = math.random; +local format = string.format; local print = print; local hosts = hosts; +local modulemanager = require "core.modulemanager"; local log = require "util.logger".init("sessionmanager"); +local error = error; module "sessionmanager" @@ -54,4 +60,27 @@ function bind_resource(session, resource) return true; end +function streamopened(session, attr) + local send = session.send; + session.host = attr.to or error("Client failed to specify destination hostname"); + session.version = tonumber(attr.version) or 0; + session.streamid = m_random(1000000, 99999999); + print(session, session.host, "Client opened stream"); + send(""); + send(format("", session.streamid, session.host)); + + local features = {}; + modulemanager.fire_event("stream-features", session, features); + + send(""); + + for _, feature in ipairs(features) do + send_to_session(session, tostring(features)); + end + + send(""); + log("info", "core", "Stream opened successfully"); + session.notopen = nil; +end + return _M; \ No newline at end of file diff --git a/core/xmlhandlers.lua b/core/xmlhandlers.lua index b6050c5a..1ce7527d 100644 --- a/core/xmlhandlers.lua +++ b/core/xmlhandlers.lua @@ -1,4 +1,5 @@ +local sessionmanager_streamopened = require "core.sessionmanager".streamopened; require "util.stanza" local st = stanza; @@ -27,7 +28,6 @@ function init_xmlhandlers(session) local stanza function xml_handlers:StartElement(name, attr) - log("info", "xmlhandlers", "Start element: " .. name); if stanza and #chardata > 0 then -- We have some character data in the buffer stanza:text(t_concat(chardata)); @@ -37,24 +37,7 @@ function init_xmlhandlers(session) if not stanza then if session.notopen then if name == "stream" then - session.host = attr.to or error("Client failed to specify destination hostname"); - session.version = attr.version or 0; - session.streamid = m_random(1000000, 99999999); - print(session, session.host, "Client opened stream"); - send(""); - send(format("", session.streamid, session.host)); - send(""); - if not session.username then - send(""); - send("PLAIN"); - send(""); - else - send(""); - end - --send [[ ]] - send(""); - log("info", "core", "Stream opened successfully"); - session.notopen = nil; + sessionmanager_streamopened(session, attr); return; end error("Client failed to open stream successfully"); -- cgit v1.2.3