Comparison

core/sessionmanager.lua @ 569:5216efe6088b

Add hostmanager, and eventmanager
author Matthew Wild <mwild1@gmail.com>
date Sat, 06 Dec 2008 03:41:49 +0000
parent 565:3a49d85cafbc
child 583:5821eaa80baa
comparison
equal deleted inserted replaced
568:b2464849c1b0 569:5216efe6088b
33 local error = error; 33 local error = error;
34 local uuid_generate = require "util.uuid".generate; 34 local uuid_generate = require "util.uuid".generate;
35 local rm_load_roster = require "core.rostermanager".load_roster; 35 local rm_load_roster = require "core.rostermanager".load_roster;
36 local config_get = require "core.configmanager".get; 36 local config_get = require "core.configmanager".get;
37 37
38 local fire_event = require "core.eventmanager".fire_event;
39
40 local gettime = require "socket".gettime;
41
38 local st = require "util.stanza"; 42 local st = require "util.stanza";
39 43
40 local newproxy = newproxy; 44 local newproxy = newproxy;
41 local getmetatable = getmetatable; 45 local getmetatable = getmetatable;
42 46
43 module "sessionmanager" 47 module "sessionmanager"
44 48
45 local open_sessions = 0; 49 local open_sessions = 0;
46 50
47 function new_session(conn) 51 function new_session(conn)
48 local session = { conn = conn, priority = 0, type = "c2s_unauthed" }; 52 local session = { conn = conn, priority = 0, type = "c2s_unauthed", conntime = gettime() };
49 if true then 53 if true then
50 session.trace = newproxy(true); 54 session.trace = newproxy(true);
51 getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; print("Session got collected, now "..open_sessions.." sessions are allocated") end; 55 getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; print("Session got collected, now "..open_sessions.." sessions are allocated") end;
52 end 56 end
53 open_sessions = open_sessions + 1; 57 open_sessions = open_sessions + 1;
107 function bind_resource(session, resource) 111 function bind_resource(session, resource)
108 if not session.username then return nil, "auth", "not-authorized", "Cannot bind resource before authentication"; end 112 if not session.username then return nil, "auth", "not-authorized", "Cannot bind resource before authentication"; end
109 if session.resource then return nil, "cancel", "already-bound", "Cannot bind multiple resources on a single connection"; end 113 if session.resource then return nil, "cancel", "already-bound", "Cannot bind multiple resources on a single connection"; end
110 -- We don't support binding multiple resources 114 -- We don't support binding multiple resources
111 115
116 session.conntimetotal = gettime()-session.conntime;
117
112 resource = resource or uuid_generate(); 118 resource = resource or uuid_generate();
113 --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing 119 --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing
114 120
115 if not hosts[session.host].sessions[session.username] then 121 if not hosts[session.host].sessions[session.username] then
116 hosts[session.host].sessions[session.username] = { sessions = {} }; 122 hosts[session.host].sessions[session.username] = { sessions = {} };
173 return; 179 return;
174 end 180 end
175 181
176 182
177 local features = st.stanza("stream:features"); 183 local features = st.stanza("stream:features");
178 modulemanager.fire_event("stream-features", session, features); 184 fire_event("stream-features", session, features);
179 185
180 send(features); 186 send(features);
181 187
182 (session.log or log)("info", "Sent reply <stream:stream> to client"); 188 (session.log or log)("info", "Sent reply <stream:stream> to client");
183 session.notopen = nil; 189 session.notopen = nil;