Mercurial > prosody-hg
comparison core/hostmanager.lua @ 569:5216efe6088b
Add hostmanager, and eventmanager
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 06 Dec 2008 03:41:49 +0000 |
| parents | |
| children | 428c951d0a33 |
comparison
equal
deleted
inserted
replaced
| 568:b2464849c1b0 | 569:5216efe6088b |
|---|---|
| 1 | |
| 2 hosts = {}; | |
| 3 | |
| 4 local hosts = hosts; | |
| 5 local configmanager = require "core.configmanager"; | |
| 6 local eventmanager = require "core.eventmanager"; | |
| 7 | |
| 8 local pairs = pairs; | |
| 9 | |
| 10 module "hostmanager" | |
| 11 | |
| 12 local function load_enabled_hosts(config) | |
| 13 local defined_hosts = config or configmanager.getconfig(); | |
| 14 | |
| 15 for host, host_config in pairs(defined_hosts) do | |
| 16 if host ~= "*" and (host_config.core.enabled == nil or host_config.core.enabled) then | |
| 17 activate(host, host_config); | |
| 18 end | |
| 19 end | |
| 20 end | |
| 21 | |
| 22 eventmanager.add_event_hook("server-starting", load_enabled_hosts); | |
| 23 | |
| 24 function activate(host, host_config) | |
| 25 hosts[host] = {type = "local", connected = true, sessions = {}, host = host, s2sout = {} }; | |
| 26 | |
| 27 eventmanager.fire_event("host-activated", host, host_config); | |
| 28 end | |
| 29 | |
| 30 function deactivate(host) | |
| 31 local host_session = hosts[host]; | |
| 32 | |
| 33 eventmanager.fire_event("host-deactivating", host, host_session); | |
| 34 | |
| 35 -- Disconnect local users, s2s connections | |
| 36 for user, session_list in pairs(host_session.sessions) do | |
| 37 for resource, session in pairs(session_list) do | |
| 38 session:close("host-gone"); | |
| 39 end | |
| 40 end | |
| 41 -- Components? | |
| 42 | |
| 43 hosts[host] = nil; | |
| 44 eventmanager.fire_event("host-deactivated", host); | |
| 45 end | |
| 46 | |
| 47 function getconfig(name) | |
| 48 end | |
| 49 |
