- if not component then component = components[stanza.attr.to]; end -- hack to allow hooking node@server/resource and server/resource
- if not component then component = components[node.."@"..host]; end -- hack to allow hooking node@server\r
- if not component then component = components[host]; end
- if component then\r
- log("debug", "stanza being handled by component: "..host);\r
- component(origin, stanza, hosts[host]);\r
- else\r
- log("error", "Component manager recieved a stanza for a non-existing component: " .. stanza.attr.to);\r
- end\r
-end\r
-\r
-function register_component(host, component)\r
- if not hosts[host] then\r
- -- TODO check for host well-formedness\r
- components[host] = component;\r
- hosts[host] = { type = "component", host = host, connected = true, s2sout = {} };
+ 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: " .. (stanza.attr.to or serialize(stanza)));
+ end
+end
+
+function create_component(host, component)
+ -- TODO check for host well-formedness
+ return { type = "component", host = host, connected = true, s2sout = {}, events = events_new() };
+end
+
+function register_component(host, component, session)
+ if not hosts[host] or (hosts[host].type == 'component' and not hosts[host].connected) then
+ local old_events = hosts[host] and hosts[host].events;
+
+ components[host] = component;
+ hosts[host] = session or create_component(host, component);
+
+ -- Add events object if not already one
+ if not hosts[host].events then
+ hosts[host].events = old_events or events_new();
+ end
+
+ -- add to disco_items
+ if not(host:find("@", 1, true) or host:find("/", 1, true)) and host:find(".", 1, true) then
+ disco_items:set(host:sub(host:find(".", 1, true)+1), host, true);
+ end