core/sessionmanager.lua

changeset 40
2c0147bbd81a
parent 38
3fdfd6e0cb4e
child 41
68297fef35ff
equal deleted inserted replaced
39:89877d61ac51 40:2c0147bbd81a
1 1
2 local tostring = tostring; 2 local tonumber, tostring = tonumber, tostring;
3 local ipairs = ipairs;
4
5 local m_random = math.random;
6 local format = string.format;
3 7
4 local print = print; 8 local print = print;
5 9
6 local hosts = hosts; 10 local hosts = hosts;
7 11
12 local modulemanager = require "core.modulemanager";
8 local log = require "util.logger".init("sessionmanager"); 13 local log = require "util.logger".init("sessionmanager");
14 local error = error;
9 15
10 module "sessionmanager" 16 module "sessionmanager"
11 17
12 function new_session(conn) 18 function new_session(conn)
13 local session = { conn = conn, notopen = true, priority = 0, type = "c2s_unauthed" }; 19 local session = { conn = conn, notopen = true, priority = 0, type = "c2s_unauthed" };
52 hosts[session.host].sessions[session.username].sessions[resource] = session; 58 hosts[session.host].sessions[session.username].sessions[resource] = session;
53 59
54 return true; 60 return true;
55 end 61 end
56 62
63 function streamopened(session, attr)
64 local send = session.send;
65 session.host = attr.to or error("Client failed to specify destination hostname");
66 session.version = tonumber(attr.version) or 0;
67 session.streamid = m_random(1000000, 99999999);
68 print(session, session.host, "Client opened stream");
69 send("<?xml version='1.0'?>");
70 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));
71
72 local features = {};
73 modulemanager.fire_event("stream-features", session, features);
74
75 send("<stream:features>");
76
77 for _, feature in ipairs(features) do
78 send_to_session(session, tostring(features));
79 end
80
81 send("</stream:features>");
82 log("info", "core", "Stream opened successfully");
83 session.notopen = nil;
84 end
85
57 return _M; 86 return _M;

mercurial