Bumper commit for the new modulemanager API \o/ Updates all the modules, though some...
[prosody.git] / core / componentmanager.lua
1 \r
2 \r
3 local log = require "util.logger".init("componentmanager")\r
4 local jid_split = require "util.jid".split;\r
5 local hosts = hosts;\r
6 \r
7 local components = {};\r
8 \r
9 module "componentmanager"\r
10 \r
11 function handle_stanza(origin, stanza)\r
12         local node, host = jid_split(stanza.attr.to);\r
13         local component = components[host];\r
14         if not component then component = components[node.."@"..host]; end -- hack to allow hooking node@server\r
15         if not component then component = components[stanza.attr.to]; end -- hack to allow hooking node@server/resource and server/resource\r
16         if component then\r
17                 log("debug", "stanza being handled by component: "..host);\r
18                 component(origin, stanza, hosts[host]);\r
19         else\r
20                 log("error", "Component manager recieved a stanza for a non-existing component: " .. stanza.attr.to);\r
21         end\r
22 end\r
23 \r
24 function register_component(host, component)\r
25         if not hosts[host] then\r
26                 -- TODO check for host well-formedness\r
27                 components[host] = component;\r
28                 hosts[host] = {type = "component", host = host, connected = true, s2sout = {} };\r
29                 log("debug", "component added: "..host);\r
30                 return hosts[host];\r
31         else\r
32                 log("error", "Attempt to set component for existing host: "..host);\r
33         end\r
34 end\r
35 \r
36 return _M;\r