Software /
code /
prosody
Comparison
core/hostmanager.lua @ 6706:60c692828cf6
hostmanager: Metatable with __tostring on hosts
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 18 May 2015 20:50:50 +0200 |
parent | 6618:469151b08065 |
child | 6721:3807af36d773 |
child | 6779:6236668da30a |
comparison
equal
deleted
inserted
replaced
6704:03afecdf2e3c | 6706:60c692828cf6 |
---|---|
24 local incoming_s2s = _G.prosody.incoming_s2s; | 24 local incoming_s2s = _G.prosody.incoming_s2s; |
25 local core_route_stanza = _G.prosody.core_route_stanza; | 25 local core_route_stanza = _G.prosody.core_route_stanza; |
26 | 26 |
27 local pairs, select, rawget = pairs, select, rawget; | 27 local pairs, select, rawget = pairs, select, rawget; |
28 local tostring, type = tostring, type; | 28 local tostring, type = tostring, type; |
29 local setmetatable = setmetatable; | |
29 | 30 |
30 module "hostmanager" | 31 module "hostmanager" |
32 | |
33 local host_mt = { } | |
34 function host_mt:__tostring() | |
35 if self.type == "component" then | |
36 local typ = configmanager.get(self.host, "component_module"); | |
37 if typ == "component" then | |
38 return ("Component %q"):format(self.host); | |
39 end | |
40 return ("Component %q %q"):format(self.host, typ); | |
41 elseif self.type == "local" then | |
42 return ("VirtualHost %q"):format(self.host); | |
43 end | |
44 end | |
31 | 45 |
32 local hosts_loaded_once; | 46 local hosts_loaded_once; |
33 | 47 |
34 local function load_enabled_hosts(config) | 48 local function load_enabled_hosts(config) |
35 local defined_hosts = config or configmanager.getconfig(); | 49 local defined_hosts = config or configmanager.getconfig(); |
74 s2sout = {}; | 88 s2sout = {}; |
75 events = events_new(); | 89 events = events_new(); |
76 send = host_send; | 90 send = host_send; |
77 modules = {}; | 91 modules = {}; |
78 }; | 92 }; |
93 setmetatable(host_session, host_mt); | |
79 if not host_config.component_module then -- host | 94 if not host_config.component_module then -- host |
80 host_session.type = "local"; | 95 host_session.type = "local"; |
81 host_session.sessions = {}; | 96 host_session.sessions = {}; |
82 else -- component | 97 else -- component |
83 host_session.type = "component"; | 98 host_session.type = "component"; |