Mercurial > prosody-hg
comparison core/sessionmanager.lua @ 4230:23b68616b6d8
sessionmanager: Fire pre-resource-unbind to allow plugins (such as mod_smacks) to hook and prevent/override session destruction
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 29 Mar 2011 14:10:00 +0100 |
| parents | 543f31cdde19 |
| children | 618e2a2b2d2c |
comparison
equal
deleted
inserted
replaced
| 4229:f15b4e9ba688 | 4230:23b68616b6d8 |
|---|---|
| 106 (session.log or log)("info", "Destroying session for %s (%s@%s)", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)"); | 106 (session.log or log)("info", "Destroying session for %s (%s@%s)", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)"); |
| 107 if session.destroyed then return; end | 107 if session.destroyed then return; end |
| 108 | 108 |
| 109 -- Remove session/resource from user's session list | 109 -- Remove session/resource from user's session list |
| 110 if session.full_jid then | 110 if session.full_jid then |
| 111 hosts[session.host].sessions[session.username].sessions[session.resource] = nil; | 111 local host_session = hosts[session.host]; |
| 112 | |
| 113 -- Allow plugins to prevent session destruction | |
| 114 if host_session.events.fire_event("pre-resource-unbind", {session=session, error=err}) then | |
| 115 return; | |
| 116 end | |
| 117 | |
| 118 host_session.sessions[session.username].sessions[session.resource] = nil; | |
| 112 full_sessions[session.full_jid] = nil; | 119 full_sessions[session.full_jid] = nil; |
| 113 | 120 |
| 114 if not next(hosts[session.host].sessions[session.username].sessions) then | 121 if not next(host_session.sessions[session.username].sessions) then |
| 115 log("debug", "All resources of %s are now offline", session.username); | 122 log("debug", "All resources of %s are now offline", session.username); |
| 116 hosts[session.host].sessions[session.username] = nil; | 123 host_session.sessions[session.username] = nil; |
| 117 bare_sessions[session.username..'@'..session.host] = nil; | 124 bare_sessions[session.username..'@'..session.host] = nil; |
| 118 end | 125 end |
| 119 | 126 |
| 120 hosts[session.host].events.fire_event("resource-unbind", {session=session, error=err}); | 127 host_session.events.fire_event("resource-unbind", {session=session, error=err}); |
| 121 end | 128 end |
| 122 | 129 |
| 123 retire_session(session); | 130 retire_session(session); |
| 124 end | 131 end |
| 125 | 132 |
