Software /
code /
prosody
Comparison
plugins/mod_component.lua @ 6913:c7a0d5299933
mod_component: Add config option for deciding what happens if a component connects while already connected (fixes #525)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 21 Oct 2015 01:56:07 +0200 |
parent | 6774:3965662ae091 |
child | 7300:66e7517bd8f3 |
comparison
equal
deleted
inserted
replaced
6912:cb5b14c95b7b | 6913:c7a0d5299933 |
---|---|
34 error("Don't load mod_component manually, it should be for a component, please see http://prosody.im/doc/components", 0); | 34 error("Don't load mod_component manually, it should be for a component, please see http://prosody.im/doc/components", 0); |
35 end | 35 end |
36 | 36 |
37 local env = module.environment; | 37 local env = module.environment; |
38 env.connected = false; | 38 env.connected = false; |
39 env.session = false; | |
39 | 40 |
40 local send; | 41 local send; |
41 | 42 |
42 local function on_destroy(session, err) | 43 local function on_destroy(session, err) |
43 env.connected = false; | 44 env.connected = false; |
45 env.session = false; | |
44 send = nil; | 46 send = nil; |
45 session.on_destroy = nil; | 47 session.on_destroy = nil; |
46 end | 48 end |
47 | 49 |
48 -- Handle authentication attempts by component | 50 -- Handle authentication attempts by component |
71 session:close{ condition = "not-authorized", text = "Given token does not match calculated token" }; | 73 session:close{ condition = "not-authorized", text = "Given token does not match calculated token" }; |
72 return true; | 74 return true; |
73 end | 75 end |
74 | 76 |
75 if env.connected then | 77 if env.connected then |
76 module:log("error", "Second component attempted to connect, denying connection"); | 78 local policy = module:get_option_string("component_conflict_resolve", "kick_new"); |
77 session:close{ condition = "conflict", text = "Component already connected" }; | 79 if policy == "kick_old" then |
78 return true; | 80 env.session:close{ condition = "conflict", text = "Replaced by a new connection" }; |
81 else -- kick_new | |
82 module:log("error", "Second component attempted to connect, denying connection"); | |
83 session:close{ condition = "conflict", text = "Component already connected" }; | |
84 return true; | |
85 end | |
79 end | 86 end |
80 | 87 |
81 env.connected = true; | 88 env.connected = true; |
89 env.session = session; | |
82 send = session.send; | 90 send = session.send; |
83 session.on_destroy = on_destroy; | 91 session.on_destroy = on_destroy; |
84 session.component_validate_from = module:get_option_boolean("validate_from_addresses", true); | 92 session.component_validate_from = module:get_option_boolean("validate_from_addresses", true); |
85 session.type = "component"; | 93 session.type = "component"; |
86 module:log("info", "External component successfully authenticated"); | 94 module:log("info", "External component successfully authenticated"); |