core/sessionmanager.lua

changeset 2746
3b9547fc0bed
parent 2622
5ced53147f86
child 2747
168104895051
equal deleted inserted replaced
2745:5cedad1bcb28 2746:3b9547fc0bed
6 -- COPYING file in the source package for more information. 6 -- COPYING file in the source package for more information.
7 -- 7 --
8 8
9 9
10 10
11 local tonumber, tostring = tonumber, tostring; 11 local tonumber, tostring, setmetatable = tonumber, tostring, setmetatable;
12 local ipairs, pairs, print, next= ipairs, pairs, print, next; 12 local ipairs, pairs, print, next= ipairs, pairs, print, next;
13 local format = import("string", "format"); 13 local format = import("string", "format");
14 14
15 local hosts = hosts; 15 local hosts = hosts;
16 local full_sessions = full_sessions; 16 local full_sessions = full_sessions;
64 end 64 end
65 65
66 return session; 66 return session;
67 end 67 end
68 68
69 local function null_data_handler(conn, data) log("debug", "Discarding data from destroyed c2s session: %s", data); end 69 local resting_session = { -- Resting, not dead
70 destroyed = true;
71 }; resting_session.__index = resting_session;
72
73 function retire_session(session)
74 local log = session.log or log;
75 for k in pairs(session) do
76 if k ~= "trace" and k ~= "log" and k ~= "id" then
77 session[k] = nil;
78 end
79 end
80
81 function session.send(data) log("debug", "Discarding data sent to resting session: %s", tostring(data)); end
82 function session.data(data) log("debug", "Discarding data received from resting session: %s", tostring(data)); end
83 return setmetatable(session, resting_session);
84 end
70 85
71 function destroy_session(session, err) 86 function destroy_session(session, err)
72 (session.log or log)("info", "Destroying session for %s (%s@%s)", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)"); 87 (session.log or log)("info", "Destroying session for %s (%s@%s)", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)");
73 88
74 -- Remove session/resource from user's session list 89 -- Remove session/resource from user's session list
83 end 98 end
84 99
85 hosts[session.host].events.fire_event("resource-unbind", {session=session, error=err}); 100 hosts[session.host].events.fire_event("resource-unbind", {session=session, error=err});
86 end 101 end
87 102
88 for k in pairs(session) do 103 retire_session(session);
89 if k ~= "trace" then
90 session[k] = nil;
91 end
92 end
93 session.data = null_data_handler;
94 end 104 end
95 105
96 function make_authenticated(session, username) 106 function make_authenticated(session, username)
97 session.username = username; 107 session.username = username;
98 if session.type == "c2s_unauthed" then 108 if session.type == "c2s_unauthed" then

mercurial