diff options
author | Matthew Wild <mwild1@gmail.com> | 2008-10-03 22:18:08 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2008-10-03 22:18:08 +0100 |
commit | 6c2578d43b71dfe93757e360d050de015ba455f5 (patch) | |
tree | a91e170bc3d50e16c59e40e1a3e4c817997d97d1 /core/sessionmanager.lua | |
parent | 4ac420e3b0324843b9647aeeb908a65e4c5a8e2e (diff) | |
download | prosody-6c2578d43b71dfe93757e360d050de015ba455f5.tar.gz prosody-6c2578d43b71dfe93757e360d050de015ba455f5.zip |
Move stream opening handling from xmlhandlers to sessionmanager
Diffstat (limited to 'core/sessionmanager.lua')
-rw-r--r-- | core/sessionmanager.lua | 31 |
1 files changed, 30 insertions, 1 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("<?xml version='1.0'?>"); + send(format("<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='%s' from='%s' version='1.0'>", session.streamid, session.host)); + + local features = {}; + modulemanager.fire_event("stream-features", session, features); + + send("<stream:features>"); + + for _, feature in ipairs(features) do + send_to_session(session, tostring(features)); + end + + send("</stream:features>"); + log("info", "core", "Stream opened successfully"); + session.notopen = nil; +end + return _M;
\ No newline at end of file |