Software /
code /
prosody
Comparison
core/sessionmanager.lua @ 304:7b28fa8bbfe5
Code cleanup for resource binding
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 16 Nov 2008 03:16:53 +0500 |
parent | 176:e5cd2a03891d |
child | 309:d9c8825b7332 |
comparison
equal
deleted
inserted
replaced
303:89e8f53b870e | 304:7b28fa8bbfe5 |
---|---|
66 session.type = "c2s"; | 66 session.type = "c2s"; |
67 end | 67 end |
68 return true; | 68 return true; |
69 end | 69 end |
70 | 70 |
71 -- returns true, nil on success | |
72 -- returns nil, err_type, err, err_message on failure | |
71 function bind_resource(session, resource) | 73 function bind_resource(session, resource) |
72 if not session.username then return false, "auth"; end | 74 if not session.username then return nil, "auth", "not-authorized", "Cannot bind resource before authentication"; end |
73 if session.resource then return false, "constraint"; end -- We don't support binding multiple resources | 75 if session.resource then return nil, "cancel", "already-bound", "Cannot bind multiple resources on a single connection"; end |
76 -- We don't support binding multiple resources | |
77 | |
74 resource = resource or uuid_generate(); | 78 resource = resource or uuid_generate(); |
75 --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing | 79 --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing |
76 | 80 |
77 if not hosts[session.host].sessions[session.username] then | 81 if not hosts[session.host].sessions[session.username] then |
78 hosts[session.host].sessions[session.username] = { sessions = {} }; | 82 hosts[session.host].sessions[session.username] = { sessions = {} }; |
79 else | 83 else |
80 if hosts[session.host].sessions[session.username].sessions[resource] then | 84 if hosts[session.host].sessions[session.username].sessions[resource] then |
81 -- Resource conflict | 85 -- Resource conflict |
82 return false, "conflict"; -- TODO kick old resource | 86 return nil, "cancel", "conflict", "Resource already exists"; -- TODO kick old resource |
83 end | 87 end |
84 end | 88 end |
85 | 89 |
86 session.resource = resource; | 90 session.resource = resource; |
87 session.full_jid = session.username .. '@' .. session.host .. '/' .. resource; | 91 session.full_jid = session.username .. '@' .. session.host .. '/' .. resource; |