Mercurial > prosody-hg
comparison core/sessionmanager.lua @ 1224:35fa588e43a6
sessionmanager: Add/remove sessions from full_sessions and bare_sessions when binding/unbinding sessions
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Fri, 29 May 2009 23:14:57 +0500 |
| parents | 9767e52f861c |
| children | 1e01a913baf5 |
comparison
equal
deleted
inserted
replaced
| 1223:9767e52f861c | 1224:35fa588e43a6 |
|---|---|
| 68 if session.host and session.username then | 68 if session.host and session.username then |
| 69 -- FIXME: How can the below ever be nil? (but they sometimes are...) | 69 -- FIXME: How can the below ever be nil? (but they sometimes are...) |
| 70 if hosts[session.host] and hosts[session.host].sessions[session.username] then | 70 if hosts[session.host] and hosts[session.host].sessions[session.username] then |
| 71 if session.resource then | 71 if session.resource then |
| 72 hosts[session.host].sessions[session.username].sessions[session.resource] = nil; | 72 hosts[session.host].sessions[session.username].sessions[session.resource] = nil; |
| 73 full_sessions[session.full_jid] = nil; | |
| 73 end | 74 end |
| 74 | 75 |
| 75 if not next(hosts[session.host].sessions[session.username].sessions) then | 76 if not next(hosts[session.host].sessions[session.username].sessions) then |
| 76 log("debug", "All resources of %s are now offline", session.username); | 77 log("debug", "All resources of %s are now offline", session.username); |
| 77 hosts[session.host].sessions[session.username] = nil; | 78 hosts[session.host].sessions[session.username] = nil; |
| 79 bare_sessions[session.host..'@'..session.username] = nil; | |
| 78 end | 80 end |
| 79 else | 81 else |
| 80 log("error", "host or session table didn't exist, please report this! Host: %s [%s] Sessions: %s [%s]", | 82 log("error", "host or session table didn't exist, please report this! Host: %s [%s] Sessions: %s [%s]", |
| 81 tostring(hosts[session.host]), tostring(session.host), | 83 tostring(hosts[session.host]), tostring(session.host), |
| 82 tostring(hosts[session.host].sessions[session.username] ), tostring(session.username)); | 84 tostring(hosts[session.host].sessions[session.username] ), tostring(session.username)); |
| 108 | 110 |
| 109 resource = resource or uuid_generate(); | 111 resource = resource or uuid_generate(); |
| 110 --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing | 112 --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing |
| 111 | 113 |
| 112 if not hosts[session.host].sessions[session.username] then | 114 if not hosts[session.host].sessions[session.username] then |
| 113 hosts[session.host].sessions[session.username] = { sessions = {} }; | 115 local sessions = { sessions = {} }; |
| 116 hosts[session.host].sessions[session.username] = sessions; | |
| 117 bare_sessions[session.host..'@'..session.username] = sessions; | |
| 114 else | 118 else |
| 115 local sessions = hosts[session.host].sessions[session.username].sessions; | 119 local sessions = hosts[session.host].sessions[session.username].sessions; |
| 116 local limit = config_get(session.host, "core", "max_resources") or 10; | 120 local limit = config_get(session.host, "core", "max_resources") or 10; |
| 117 if #sessions >= limit then | 121 if #sessions >= limit then |
| 118 return nil, "cancel", "conflict", "Resource limit reached; only "..limit.." resources allowed"; | 122 return nil, "cancel", "conflict", "Resource limit reached; only "..limit.." resources allowed"; |
| 148 end | 152 end |
| 149 | 153 |
| 150 session.resource = resource; | 154 session.resource = resource; |
| 151 session.full_jid = session.username .. '@' .. session.host .. '/' .. resource; | 155 session.full_jid = session.username .. '@' .. session.host .. '/' .. resource; |
| 152 hosts[session.host].sessions[session.username].sessions[resource] = session; | 156 hosts[session.host].sessions[session.username].sessions[resource] = session; |
| 157 full_sessions[session.full_jid] = session; | |
| 153 | 158 |
| 154 session.roster = rm_load_roster(session.username, session.host); | 159 session.roster = rm_load_roster(session.username, session.host); |
| 155 | 160 |
| 156 return true; | 161 return true; |
| 157 end | 162 end |
