Software /
code /
prosody
Comparison
core/sessionmanager.lua @ 8872:4d7a822e837f
sessionmanager: Generate shorter random resoures
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 29 May 2018 06:51:52 +0200 |
parent | 8717:9ddd0fbbe53a |
child | 9062:1b272b51ae0f |
comparison
equal
deleted
inserted
replaced
8871:b67a861e883e | 8872:4d7a822e837f |
---|---|
18 local log = logger.init("sessionmanager"); | 18 local log = logger.init("sessionmanager"); |
19 local rm_load_roster = require "core.rostermanager".load_roster; | 19 local rm_load_roster = require "core.rostermanager".load_roster; |
20 local config_get = require "core.configmanager".get; | 20 local config_get = require "core.configmanager".get; |
21 local resourceprep = require "util.encodings".stringprep.resourceprep; | 21 local resourceprep = require "util.encodings".stringprep.resourceprep; |
22 local nodeprep = require "util.encodings".stringprep.nodeprep; | 22 local nodeprep = require "util.encodings".stringprep.nodeprep; |
23 local uuid_generate = require "util.uuid".generate; | 23 local generate_identifier = require "util.id".short; |
24 | 24 |
25 local initialize_filters = require "util.filters".initialize; | 25 local initialize_filters = require "util.filters".initialize; |
26 local gettime = require "socket".gettime; | 26 local gettime = require "socket".gettime; |
27 | 27 |
28 local _ENV = nil; | 28 local _ENV = nil; |
136 -- In case a plugin wants to poke at it | 136 -- In case a plugin wants to poke at it |
137 resource = event_payload.resource; | 137 resource = event_payload.resource; |
138 end | 138 end |
139 | 139 |
140 resource = resourceprep(resource); | 140 resource = resourceprep(resource); |
141 resource = resource ~= "" and resource or uuid_generate(); | 141 resource = resource ~= "" and resource or generate_identifier(); |
142 --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing | 142 --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing |
143 | 143 |
144 if not hosts[session.host].sessions[session.username] then | 144 if not hosts[session.host].sessions[session.username] then |
145 local sessions = { sessions = {} }; | 145 local sessions = { sessions = {} }; |
146 hosts[session.host].sessions[session.username] = sessions; | 146 hosts[session.host].sessions[session.username] = sessions; |
150 if sessions[resource] then | 150 if sessions[resource] then |
151 -- Resource conflict | 151 -- Resource conflict |
152 local policy = config_get(session.host, "conflict_resolve"); | 152 local policy = config_get(session.host, "conflict_resolve"); |
153 local increment; | 153 local increment; |
154 if policy == "random" then | 154 if policy == "random" then |
155 resource = uuid_generate(); | 155 resource = generate_identifier(); |
156 increment = true; | 156 increment = true; |
157 elseif policy == "increment" then | 157 elseif policy == "increment" then |
158 increment = true; -- TODO ping old resource | 158 increment = true; -- TODO ping old resource |
159 elseif policy == "kick_new" then | 159 elseif policy == "kick_new" then |
160 return nil, "cancel", "conflict", "Resource already exists"; | 160 return nil, "cancel", "conflict", "Resource already exists"; |