Comparison

core/sessionmanager.lua @ 12880:b56a2731bf00

Merge 0.12->trunk
author Matthew Wild <mwild1@gmail.com>
date Thu, 09 Feb 2023 22:34:05 +0000
parent 12821:a4ac16e5b655
parent 12879:09a53ed8f4d5
child 12972:ead41e25ebc0
comparison
equal deleted inserted replaced
12876:0ed24f48b6a6 12880:b56a2731bf00
136 -- Retire the session we've pulled from, to avoid two sessions on the same connection 136 -- Retire the session we've pulled from, to avoid two sessions on the same connection
137 retire_session(from_session); 137 retire_session(from_session);
138 end 138 end
139 139
140 local function destroy_session(session, err) 140 local function destroy_session(session, err)
141 (session.log or log)("debug", "Destroying session for %s (%s@%s)%s",
142 session.full_jid or "(unknown)", session.username or "(unknown)",
143 session.host or "(unknown)", err and (": "..err) or "");
144
145 if session.destroyed then return; end 141 if session.destroyed then return; end
146 142
147 -- Remove session/resource from user's session list 143 -- Remove session/resource from user's session list
148 if session.full_jid then 144 if session.full_jid then
149 local host_session = hosts[session.host]; 145 local host_session = hosts[session.host];
150 146
151 -- Allow plugins to prevent session destruction 147 -- Allow plugins to prevent session destruction
152 if host_session.events.fire_event("pre-resource-unbind", {session=session, error=err}) then 148 if host_session.events.fire_event("pre-resource-unbind", {session=session, error=err}) then
149 (session.log or log)("debug", "Resource unbind prevented by module");
153 return; 150 return;
154 end 151 end
152
153 (session.log or log)("debug", "Unbinding resource for %s (%s@%s)%s",
154 session.full_jid or "(unknown)", session.username or "(unknown)",
155 session.host or "(unknown)", err and (": "..err) or "");
156
157 session.destroyed = true; -- Past this point the session is DOOMED!
155 158
156 host_session.sessions[session.username].sessions[session.resource] = nil; 159 host_session.sessions[session.username].sessions[session.resource] = nil;
157 full_sessions[session.full_jid] = nil; 160 full_sessions[session.full_jid] = nil;
158 161
159 if not next(host_session.sessions[session.username].sessions) then 162 if not next(host_session.sessions[session.username].sessions) then
161 host_session.sessions[session.username] = nil; 164 host_session.sessions[session.username] = nil;
162 bare_sessions[session.username..'@'..session.host] = nil; 165 bare_sessions[session.username..'@'..session.host] = nil;
163 end 166 end
164 167
165 host_session.events.fire_event("resource-unbind", {session=session, error=err}); 168 host_session.events.fire_event("resource-unbind", {session=session, error=err});
169 else
170 (session.log or log)("debug", "Destroying unbound session for <%s@%s>%s",
171 session.username or "(unknown)", session.host or "(unknown)",
172 err and (": "..err) or "");
166 end 173 end
167 174
168 retire_session(session); 175 retire_session(session);
169 end 176 end
170 177