Software /
code /
prosody
Comparison
core/sessionmanager.lua @ 2449:678ca4e9a479
sessionmanager: Added resource prepping, and invalid resource checking to the bind_resource function.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 11 Jan 2010 18:59:06 +0500 |
parent | 2163:8d33f94dc3a1 |
child | 2580:61f0acd9086f |
comparison
equal
deleted
inserted
replaced
2448:542335c8a5bc | 2449:678ca4e9a479 |
---|---|
22 local error = error; | 22 local error = error; |
23 local uuid_generate = require "util.uuid".generate; | 23 local uuid_generate = require "util.uuid".generate; |
24 local rm_load_roster = require "core.rostermanager".load_roster; | 24 local rm_load_roster = require "core.rostermanager".load_roster; |
25 local config_get = require "core.configmanager".get; | 25 local config_get = require "core.configmanager".get; |
26 local nameprep = require "util.encodings".stringprep.nameprep; | 26 local nameprep = require "util.encodings".stringprep.nameprep; |
27 local resourceprep = require "util.encodings".stringprep.resourceprep; | |
27 | 28 |
28 local fire_event = require "core.eventmanager".fire_event; | 29 local fire_event = require "core.eventmanager".fire_event; |
29 local add_task = require "util.timer".add_task; | 30 local add_task = require "util.timer".add_task; |
30 local gettime = require "socket".gettime; | 31 local gettime = require "socket".gettime; |
31 | 32 |
103 function bind_resource(session, resource) | 104 function bind_resource(session, resource) |
104 if not session.username then return nil, "auth", "not-authorized", "Cannot bind resource before authentication"; end | 105 if not session.username then return nil, "auth", "not-authorized", "Cannot bind resource before authentication"; end |
105 if session.resource then return nil, "cancel", "already-bound", "Cannot bind multiple resources on a single connection"; end | 106 if session.resource then return nil, "cancel", "already-bound", "Cannot bind multiple resources on a single connection"; end |
106 -- We don't support binding multiple resources | 107 -- We don't support binding multiple resources |
107 | 108 |
108 resource = resource or uuid_generate(); | 109 resource = resourceprep(resource); |
110 resource = resource ~= "" and resource or uuid_generate(); | |
109 --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing | 111 --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing |
110 | 112 |
111 if not hosts[session.host].sessions[session.username] then | 113 if not hosts[session.host].sessions[session.username] then |
112 local sessions = { sessions = {} }; | 114 local sessions = { sessions = {} }; |
113 hosts[session.host].sessions[session.username] = sessions; | 115 hosts[session.host].sessions[session.username] = sessions; |