Mercurial > prosody-hg
comparison core/hostmanager.lua @ 3717:135128fdf565
hostmanager: Improved error handling.
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Thu, 09 Dec 2010 21:40:54 +0500 |
| parents | ebb2c6209e24 |
| children | 6be419e2f509 |
comparison
equal
deleted
inserted
replaced
| 3716:ebb2c6209e24 | 3717:135128fdf565 |
|---|---|
| 22 require "core.s2smanager"; | 22 require "core.s2smanager"; |
| 23 end | 23 end |
| 24 local incoming_s2s = _G.prosody.incoming_s2s; | 24 local incoming_s2s = _G.prosody.incoming_s2s; |
| 25 | 25 |
| 26 local pairs, setmetatable = pairs, setmetatable; | 26 local pairs, setmetatable = pairs, setmetatable; |
| 27 local tostring, type = tostring, type; | |
| 27 | 28 |
| 28 module "hostmanager" | 29 module "hostmanager" |
| 29 | 30 |
| 30 local hosts_loaded_once; | 31 local hosts_loaded_once; |
| 31 | 32 |
| 51 end | 52 end |
| 52 | 53 |
| 53 prosody_events.add_handler("server-starting", load_enabled_hosts); | 54 prosody_events.add_handler("server-starting", load_enabled_hosts); |
| 54 | 55 |
| 55 function activate(host, host_config) | 56 function activate(host, host_config) |
| 56 if hosts[host] then return nil, "host-already-exists"; end | 57 if hosts[host] then return nil, "The host "..host.." is already activated"; end |
| 57 host_config = host_config or configmanager.getconfig()[host]; | 58 host_config = host_config or configmanager.getconfig()[host]; |
| 59 if not host_config then return nil, "Couldn't find the host "..tostring(host).." defined in the current config"; end | |
| 58 local host_session = { | 60 local host_session = { |
| 59 host = host; | 61 host = host; |
| 60 s2sout = {}; | 62 s2sout = {}; |
| 61 events = events_new(); | 63 events = events_new(); |
| 62 dialback_secret = configmanager.get(host, "core", "dialback_secret") or uuid_gen(); | 64 dialback_secret = configmanager.get(host, "core", "dialback_secret") or uuid_gen(); |
| 86 return true; | 88 return true; |
| 87 end | 89 end |
| 88 | 90 |
| 89 function deactivate(host, reason) | 91 function deactivate(host, reason) |
| 90 local host_session = hosts[host]; | 92 local host_session = hosts[host]; |
| 93 if not host_session then return nil, "The host "..tostring(host).." is not activated"; end | |
| 91 log("info", "Deactivating host: %s", host); | 94 log("info", "Deactivating host: %s", host); |
| 92 prosody_events.fire_event("host-deactivating", host, host_session); | 95 prosody_events.fire_event("host-deactivating", host, host_session); |
| 93 | 96 |
| 94 reason = reason or { condition = "host-gone", text = "This server has stopped serving "..host }; | 97 if type(reason) ~= "table" then |
| 98 reason = { condition = "host-gone", text = tostring(reason or "This server has stopped serving "..host) }; | |
| 99 end | |
| 95 | 100 |
| 96 -- Disconnect local users, s2s connections | 101 -- Disconnect local users, s2s connections |
| 97 if host_session.sessions then | 102 if host_session.sessions then |
| 98 for username, user in pairs(host_session.sessions) do | 103 for username, user in pairs(host_session.sessions) do |
| 99 for resource, session in pairs(user.sessions) do | 104 for resource, session in pairs(user.sessions) do |
