Software /
code /
prosody
Comparison
core/sessionmanager.lua @ 5776:bd0ff8ae98a8
Remove all trailing whitespace
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Fri, 09 Aug 2013 17:48:21 +0200 |
parent | 5459:3a821511b9ec |
child | 6404:938cc782c14d |
comparison
equal
deleted
inserted
replaced
5775:a6c2b8933507 | 5776:bd0ff8ae98a8 |
---|---|
1 -- Prosody IM | 1 -- Prosody IM |
2 -- Copyright (C) 2008-2010 Matthew Wild | 2 -- Copyright (C) 2008-2010 Matthew Wild |
3 -- Copyright (C) 2008-2010 Waqas Hussain | 3 -- Copyright (C) 2008-2010 Waqas Hussain |
4 -- | 4 -- |
5 -- This project is MIT/X11 licensed. Please see the | 5 -- This project is MIT/X11 licensed. Please see the |
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 local tostring, setmetatable = tostring, setmetatable; | 9 local tostring, setmetatable = tostring, setmetatable; |
42 end | 42 end |
43 end | 43 end |
44 session.ip = conn:ip(); | 44 session.ip = conn:ip(); |
45 local conn_name = "c2s"..tostring(session):match("[a-f0-9]+$"); | 45 local conn_name = "c2s"..tostring(session):match("[a-f0-9]+$"); |
46 session.log = logger.init(conn_name); | 46 session.log = logger.init(conn_name); |
47 | 47 |
48 return session; | 48 return session; |
49 end | 49 end |
50 | 50 |
51 local resting_session = { -- Resting, not dead | 51 local resting_session = { -- Resting, not dead |
52 destroyed = true; | 52 destroyed = true; |
71 end | 71 end |
72 | 72 |
73 function destroy_session(session, err) | 73 function destroy_session(session, err) |
74 (session.log or log)("debug", "Destroying session for %s (%s@%s)%s", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)", err and (": "..err) or ""); | 74 (session.log or log)("debug", "Destroying session for %s (%s@%s)%s", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)", err and (": "..err) or ""); |
75 if session.destroyed then return; end | 75 if session.destroyed then return; end |
76 | 76 |
77 -- Remove session/resource from user's session list | 77 -- Remove session/resource from user's session list |
78 if session.full_jid then | 78 if session.full_jid then |
79 local host_session = hosts[session.host]; | 79 local host_session = hosts[session.host]; |
80 | 80 |
81 -- Allow plugins to prevent session destruction | 81 -- Allow plugins to prevent session destruction |
82 if host_session.events.fire_event("pre-resource-unbind", {session=session, error=err}) then | 82 if host_session.events.fire_event("pre-resource-unbind", {session=session, error=err}) then |
83 return; | 83 return; |
84 end | 84 end |
85 | 85 |
86 host_session.sessions[session.username].sessions[session.resource] = nil; | 86 host_session.sessions[session.username].sessions[session.resource] = nil; |
87 full_sessions[session.full_jid] = nil; | 87 full_sessions[session.full_jid] = nil; |
88 | 88 |
89 if not next(host_session.sessions[session.username].sessions) then | 89 if not next(host_session.sessions[session.username].sessions) then |
90 log("debug", "All resources of %s are now offline", session.username); | 90 log("debug", "All resources of %s are now offline", session.username); |
91 host_session.sessions[session.username] = nil; | 91 host_session.sessions[session.username] = nil; |
92 bare_sessions[session.username..'@'..session.host] = nil; | 92 bare_sessions[session.username..'@'..session.host] = nil; |
93 end | 93 end |
94 | 94 |
95 host_session.events.fire_event("resource-unbind", {session=session, error=err}); | 95 host_session.events.fire_event("resource-unbind", {session=session, error=err}); |
96 end | 96 end |
97 | 97 |
98 retire_session(session); | 98 retire_session(session); |
99 end | 99 end |
100 | 100 |
101 function make_authenticated(session, username) | 101 function make_authenticated(session, username) |
102 username = nodeprep(username); | 102 username = nodeprep(username); |
117 -- We don't support binding multiple resources | 117 -- We don't support binding multiple resources |
118 | 118 |
119 resource = resourceprep(resource); | 119 resource = resourceprep(resource); |
120 resource = resource ~= "" and resource or uuid_generate(); | 120 resource = resource ~= "" and resource or uuid_generate(); |
121 --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing | 121 --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing |
122 | 122 |
123 if not hosts[session.host].sessions[session.username] then | 123 if not hosts[session.host].sessions[session.username] then |
124 local sessions = { sessions = {} }; | 124 local sessions = { sessions = {} }; |
125 hosts[session.host].sessions[session.username] = sessions; | 125 hosts[session.host].sessions[session.username] = sessions; |
126 bare_sessions[session.username..'@'..session.host] = sessions; | 126 bare_sessions[session.username..'@'..session.host] = sessions; |
127 else | 127 else |
154 end | 154 end |
155 resource = resource.."#"..count; | 155 resource = resource.."#"..count; |
156 end | 156 end |
157 end | 157 end |
158 end | 158 end |
159 | 159 |
160 session.resource = resource; | 160 session.resource = resource; |
161 session.full_jid = session.username .. '@' .. session.host .. '/' .. resource; | 161 session.full_jid = session.username .. '@' .. session.host .. '/' .. resource; |
162 hosts[session.host].sessions[session.username].sessions[resource] = session; | 162 hosts[session.host].sessions[session.username].sessions[resource] = session; |
163 full_sessions[session.full_jid] = session; | 163 full_sessions[session.full_jid] = session; |
164 | 164 |
165 local err; | 165 local err; |
166 session.roster, err = rm_load_roster(session.username, session.host); | 166 session.roster, err = rm_load_roster(session.username, session.host); |
167 if err then | 167 if err then |
168 full_sessions[session.full_jid] = nil; | 168 full_sessions[session.full_jid] = nil; |
169 hosts[session.host].sessions[session.username].sessions[resource] = nil; | 169 hosts[session.host].sessions[session.username].sessions[resource] = nil; |
174 hosts[session.host].sessions[session.username] = nil; | 174 hosts[session.host].sessions[session.username] = nil; |
175 end | 175 end |
176 session.log("error", "Roster loading failed: %s", err); | 176 session.log("error", "Roster loading failed: %s", err); |
177 return nil, "cancel", "internal-server-error", "Error loading roster"; | 177 return nil, "cancel", "internal-server-error", "Error loading roster"; |
178 end | 178 end |
179 | 179 |
180 hosts[session.host].events.fire_event("resource-bind", {session=session}); | 180 hosts[session.host].events.fire_event("resource-bind", {session=session}); |
181 | 181 |
182 return true; | 182 return true; |
183 end | 183 end |
184 | 184 |
185 function send_to_available_resources(user, host, stanza) | 185 function send_to_available_resources(user, host, stanza) |
186 local jid = user.."@"..host; | 186 local jid = user.."@"..host; |