+function load_enabled_components(config)
+ local defined_hosts = config or configmanager.getconfig();
+
+ for host, host_config in pairs(defined_hosts) do
+ if host ~= "*" and ((host_config.core.enabled == nil or host_config.core.enabled) and type(host_config.core.component_module) == "string") then
+ hosts[host] = create_component(host);
+ hosts[host].connected = false;
+ components[host] = default_component_handler;
+ local ok, err = modulemanager.load(host, host_config.core.component_module);
+ if not ok then
+ log("error", "Error loading %s component %s: %s", tostring(host_config.core.component_module), tostring(host), tostring(err));
+ else
+ fire_event("component-activated", host, host_config);
+ log("debug", "Activated %s component: %s", host_config.core.component_module, host);
+ end
+ end
+ end
+end
+
+if prosody and prosody.events then
+ prosody.events.add_handler("server-starting", load_enabled_components);
+end
+
+function handle_stanza(origin, stanza)
+ local node, host = jid_split(stanza.attr.to);
+ local component = nil;
+ if host then
+ if node then component = components[node.."@"..host]; end -- hack to allow hooking node@server
+ if not component then component = components[host]; end
+ end
+ if component then
+ log("debug", "%s stanza being handled by component: %s", stanza.name, host);
+ component(origin, stanza, hosts[host]);
+ else
+ log("error", "Component manager recieved a stanza for a non-existing component: "..tostring(stanza));
+ default_component_handler(origin, stanza);
+ end
+end
+