Software /
code /
prosody
Comparison
core/sessionmanager.lua @ 565:3a49d85cafbc
Backed out changeset 099d8a102deb (committed too much)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 05 Dec 2008 19:49:16 +0000 |
parent | 563:099d8a102deb |
child | 569:5216efe6088b |
comparison
equal
deleted
inserted
replaced
563:099d8a102deb | 565:3a49d85cafbc |
---|---|
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 gettime = require "socket".gettime; | |
39 | |
40 local st = require "util.stanza"; | 38 local st = require "util.stanza"; |
41 | 39 |
42 local newproxy = newproxy; | 40 local newproxy = newproxy; |
43 local getmetatable = getmetatable; | 41 local getmetatable = getmetatable; |
44 | 42 |
45 module "sessionmanager" | 43 module "sessionmanager" |
46 | 44 |
47 local open_sessions = 0; | 45 local open_sessions = 0; |
48 | 46 |
49 function new_session(conn) | 47 function new_session(conn) |
50 local session = { conn = conn, priority = 0, type = "c2s_unauthed", conntime = gettime() }; | 48 local session = { conn = conn, priority = 0, type = "c2s_unauthed" }; |
51 if true then | 49 if true then |
52 session.trace = newproxy(true); | 50 session.trace = newproxy(true); |
53 getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; print("Session got collected, now "..open_sessions.." sessions are allocated") end; | 51 getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; print("Session got collected, now "..open_sessions.." sessions are allocated") end; |
54 end | 52 end |
55 open_sessions = open_sessions + 1; | 53 open_sessions = open_sessions + 1; |
109 function bind_resource(session, resource) | 107 function bind_resource(session, resource) |
110 if not session.username then return nil, "auth", "not-authorized", "Cannot bind resource before authentication"; end | 108 if not session.username then return nil, "auth", "not-authorized", "Cannot bind resource before authentication"; end |
111 if session.resource then return nil, "cancel", "already-bound", "Cannot bind multiple resources on a single connection"; end | 109 if session.resource then return nil, "cancel", "already-bound", "Cannot bind multiple resources on a single connection"; end |
112 -- We don't support binding multiple resources | 110 -- We don't support binding multiple resources |
113 | 111 |
114 session.conntimetotal = gettime()-session.conntime; | |
115 | |
116 resource = resource or uuid_generate(); | 112 resource = resource or uuid_generate(); |
117 --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing | 113 --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing |
118 | 114 |
119 if not hosts[session.host].sessions[session.username] then | 115 if not hosts[session.host].sessions[session.username] then |
120 hosts[session.host].sessions[session.username] = { sessions = {} }; | 116 hosts[session.host].sessions[session.username] = { sessions = {} }; |