Merge 0.10->trunk
[prosody.git] / core / hostmanager.lua
index 7f9d1610f0a9a80e96a7dc2cb2f35d08aa8add79..c04e9e85b83f3074ed15f29550f9f843f3cab9fe 100644 (file)
@@ -26,11 +26,27 @@ 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 _ENV = nil;
+
+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 activate, deactivate;
+
 local function load_enabled_hosts(config)
        local defined_hosts = config or configmanager.getconfig();
        local activated_any_host;
@@ -55,13 +71,6 @@ 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 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));
-               return;
-       end
        core_route_stanza(nil, stanza);
 end
 
@@ -76,6 +85,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 = {};
@@ -149,8 +159,12 @@ function deactivate(host, reason)
        return true;
 end
 
-function get_children(host)
+local function get_children(host)
        return disco_items:get(host) or NULL;
 end
 
-return _M;
+return {
+       activate = activate;
+       deactivate = deactivate;
+       get_children = get_children;
+}