diff options
author | Waqas Hussain <waqas20@gmail.com> | 2008-11-27 02:48:08 +0500 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2008-11-27 02:48:08 +0500 |
commit | ce81a26989d225926d3e713a264d95f1a53dd0b8 (patch) | |
tree | 5169906e62a82ae88bc90eefa3f2670aa08c6c74 /core | |
parent | 32d1450b6f627f87347cf44d36b3f337470046c9 (diff) | |
download | prosody-ce81a26989d225926d3e713a264d95f1a53dd0b8.tar.gz prosody-ce81a26989d225926d3e713a264d95f1a53dd0b8.zip |
Added options to limit the number of resources and for handling of resource conflicts
- core.max_resources: defaults to 10
- core.conflict_resolve: can be "random", "increment", "kick_new" and "kick_old" (default)
Diffstat (limited to 'core')
-rw-r--r-- | core/sessionmanager.lua | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index e83b7c23..24be2e69 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -13,6 +13,7 @@ local log = require "util.logger".init("sessionmanager"); local error = error; local uuid_generate = require "util.uuid".generate; local rm_load_roster = require "core.rostermanager".load_roster; +local config_get = require "core.configmanager".get; local st = require "util.stanza"; @@ -88,9 +89,35 @@ function bind_resource(session, resource) if not hosts[session.host].sessions[session.username] then hosts[session.host].sessions[session.username] = { sessions = {} }; else - if hosts[session.host].sessions[session.username].sessions[resource] then + local sessions = hosts[session.host].sessions[session.username].sessions; + local limit = config_get(session.host, "core", "max_resources") or 10; + if #sessions >= limit then + return nil, "cancel", "conflict", "Resource limit reached; only "..limit.." resources allowed"; + end + if sessions[resource] then -- Resource conflict - return nil, "cancel", "conflict", "Resource already exists"; -- TODO kick old resource + local policy = config_get(session.host, "core", "conflict_resolve"); + local increment; + if policy == "random" then + resource = uuid_generate(); + increment = true; + elseif policy == "increment" then + increment = true; -- TODO ping old resource + elseif policy == "kick_new" then + return nil, "cancel", "conflict", "Resource already exists"; + else -- if policy == "kick_old" then + hosts[session.host].sessions[session.username].sessions[resource]:close { + condition = "conflict"; + text = "Replaced by new connection"; + }; + end + if increment and sessions[resource] then + local count = 1; + while sessions[resource.."#"..count] do + count = count + 1; + end + resource = resource.."#"..count; + end end end |