Merge 0.9->0.10
[prosody.git] / core / hostmanager.lua
index d10ecd3002dead8c7d851c6bdd02add310b0edf4..046722b1a0ff3ca80c40f4a5225e06354ba6e566 100644 (file)
@@ -13,7 +13,6 @@ local disco_items = require "util.multitable".new();
 local NULL = {};
 
 local jid_split = require "util.jid".split;
-local uuid_gen = require "util.uuid".generate;
 
 local log = require "util.logger".init("hostmanager");
 
@@ -27,9 +26,23 @@ local core_route_stanza = _G.prosody.core_route_stanza;
 
 local pairs, select, rawget = pairs, select, rawget;
 local tostring, type = tostring, type;
+local setmetatable = setmetatable;
 
 module "hostmanager"
 
+local host_mt = { }
+function host_mt:__tostring()
+       if self.type == "component" then
+               local typ = configmanager.get(self.host, "component_module");
+               if typ == "component" then
+                       return ("Component %q"):format(self.host);
+               end
+               return ("Component %q %q"):format(self.host, typ);
+       elseif self.type == "local" then
+               return ("VirtualHost %q"):format(self.host);
+       end
+end
+
 local hosts_loaded_once;
 
 local function load_enabled_hosts(config)
@@ -56,8 +69,8 @@ end
 prosody_events.add_handler("server-starting", load_enabled_hosts);
 
 local function host_send(stanza)
-       local name, type = stanza.name, stanza.attr.type;
-       if type == "error" or (name == "iq" and type == "result") then
+       local name, stanza_type = stanza.name, stanza.attr.type;
+       if stanza_type == "error" or (name == "iq" and stanza_type == "result") then
                local dest_host_name = select(2, jid_split(stanza.attr.to));
                local dest_host = hosts[dest_host_name] or { type = "unknown" };
                log("warn", "Unhandled response sent to %s host %s: %s", dest_host.type, dest_host_name, tostring(stanza));
@@ -77,6 +90,7 @@ function activate(host, host_config)
                send = host_send;
                modules = {};
        };
+       setmetatable(host_session, host_mt);
        if not host_config.component_module then -- host
                host_session.type = "local";
                host_session.sessions = {};