Comparison

core/hostmanager.lua @ 3434:428f13c098d5

hostmanager: Remove dependency on eventmanager
author Matthew Wild <mwild1@gmail.com>
date Tue, 03 Aug 2010 10:55:17 +0100
parent 2984:3094166cfdd5
child 3571:675d65036f31
comparison
equal deleted inserted replaced
3433:b567ac8e2040 3434:428f13c098d5
6 -- COPYING file in the source package for more information. 6 -- COPYING file in the source package for more information.
7 -- 7 --
8 8
9 local ssl = ssl 9 local ssl = ssl
10 10
11 local hosts = hosts;
12 local certmanager = require "core.certmanager"; 11 local certmanager = require "core.certmanager";
13 local configmanager = require "core.configmanager"; 12 local configmanager = require "core.configmanager";
14 local eventmanager = require "core.eventmanager";
15 local modulemanager = require "core.modulemanager"; 13 local modulemanager = require "core.modulemanager";
16 local events_new = require "util.events".new; 14 local events_new = require "util.events".new;
17 15
18 local uuid_gen = require "util.uuid".generate; 16 local uuid_gen = require "util.uuid".generate;
19 17
18 local log = require "util.logger".init("hostmanager");
19
20 local hosts = hosts;
21 local prosody_events = prosody.events;
20 if not _G.prosody.incoming_s2s then 22 if not _G.prosody.incoming_s2s then
21 require "core.s2smanager"; 23 require "core.s2smanager";
22 end 24 end
23 local incoming_s2s = _G.prosody.incoming_s2s; 25 local incoming_s2s = _G.prosody.incoming_s2s;
24
25 local log = require "util.logger".init("hostmanager");
26 26
27 local pairs, setmetatable = pairs, setmetatable; 27 local pairs, setmetatable = pairs, setmetatable;
28 28
29 module "hostmanager" 29 module "hostmanager"
30 30
43 43
44 if not activated_any_host then 44 if not activated_any_host then
45 log("error", "No active VirtualHost entries in the config file. This may cause unexpected behaviour as no modules will be loaded."); 45 log("error", "No active VirtualHost entries in the config file. This may cause unexpected behaviour as no modules will be loaded.");
46 end 46 end
47 47
48 eventmanager.fire_event("hosts-activated", defined_hosts); 48 prosody_events.fire_event("hosts-activated", defined_hosts);
49 hosts_loaded_once = true; 49 hosts_loaded_once = true;
50 end 50 end
51 51
52 eventmanager.add_event_hook("server-starting", load_enabled_hosts); 52 prosody_events.add_handler("server-starting", load_enabled_hosts);
53 53
54 function activate(host, host_config) 54 function activate(host, host_config)
55 hosts[host] = {type = "local", connected = true, sessions = {}, 55 hosts[host] = {type = "local", connected = true, sessions = {},
56 host = host, s2sout = {}, events = events_new(), 56 host = host, s2sout = {}, events = events_new(),
57 disallow_s2s = configmanager.get(host, "core", "disallow_s2s") 57 disallow_s2s = configmanager.get(host, "core", "disallow_s2s")
67 67
68 hosts[host].ssl_ctx = certmanager.create_context(host, "client", host_config); -- for outgoing connections 68 hosts[host].ssl_ctx = certmanager.create_context(host, "client", host_config); -- for outgoing connections
69 hosts[host].ssl_ctx_in = certmanager.create_context(host, "server", host_config); -- for incoming connections 69 hosts[host].ssl_ctx_in = certmanager.create_context(host, "server", host_config); -- for incoming connections
70 70
71 log((hosts_loaded_once and "info") or "debug", "Activated host: %s", host); 71 log((hosts_loaded_once and "info") or "debug", "Activated host: %s", host);
72 eventmanager.fire_event("host-activated", host, host_config); 72 prosody_events.fire_event("host-activated", host, host_config);
73 end 73 end
74 74
75 function deactivate(host, reason) 75 function deactivate(host, reason)
76 local host_session = hosts[host]; 76 local host_session = hosts[host];
77 log("info", "Deactivating host: %s", host); 77 log("info", "Deactivating host: %s", host);
78 eventmanager.fire_event("host-deactivating", host, host_session); 78 prosody_events.fire_event("host-deactivating", host, host_session);
79 79
80 reason = reason or { condition = "host-gone", text = "This server has stopped serving "..host }; 80 reason = reason or { condition = "host-gone", text = "This server has stopped serving "..host };
81 81
82 -- Disconnect local users, s2s connections 82 -- Disconnect local users, s2s connections
83 if host_session.sessions then 83 if host_session.sessions then
109 modulemanager.unload(host, module); 109 modulemanager.unload(host, module);
110 end 110 end
111 end 111 end
112 112
113 hosts[host] = nil; 113 hosts[host] = nil;
114 eventmanager.fire_event("host-deactivated", host); 114 prosody_events.fire_event("host-deactivated", host);
115 log("info", "Deactivated host: %s", host); 115 log("info", "Deactivated host: %s", host);
116 end 116 end
117 117
118 function getconfig(name) 118 function getconfig(name)
119 end 119 end