32 end); |
32 end); |
33 |
33 |
34 |
34 |
35 module "componentmanager" |
35 module "componentmanager" |
36 |
36 |
|
37 local function default_component_handler(origin, stanza) |
|
38 origin.send(st.error_reply(stanza, "wait", "service-unavailable", "Component unavailable")); |
|
39 end |
|
40 |
|
41 |
37 function load_enabled_components(config) |
42 function load_enabled_components(config) |
38 local defined_hosts = config or configmanager.getconfig(); |
43 local defined_hosts = config or configmanager.getconfig(); |
39 |
44 |
40 for host, host_config in pairs(defined_hosts) do |
45 for host, host_config in pairs(defined_hosts) do |
41 if host ~= "*" and ((host_config.core.enabled == nil or host_config.core.enabled) and type(host_config.core.component_module) == "string") then |
46 if host ~= "*" and ((host_config.core.enabled == nil or host_config.core.enabled) and type(host_config.core.component_module) == "string") then |
42 hosts[host] = { type = "component", host = host, connected = false, s2sout = {} }; |
47 hosts[host] = { type = "component", host = host, connected = false, s2sout = {} }; |
|
48 components[host] = default_component_handler; |
43 local ok, err = modulemanager.load(host, host_config.core.component_module); |
49 local ok, err = modulemanager.load(host, host_config.core.component_module); |
44 if not ok then |
50 if not ok then |
45 log("error", "Error loading %s component %s: %s", tostring(host_config.core.component_module), tostring(host), tostring(err)); |
51 log("error", "Error loading %s component %s: %s", tostring(host_config.core.component_module), tostring(host), tostring(err)); |
46 else |
52 else |
47 log("info", "Activated %s component: %s", host_config.core.component_module, host); |
53 log("info", "Activated %s component: %s", host_config.core.component_module, host); |
91 |
97 |
92 function deregister_component(host) |
98 function deregister_component(host) |
93 if components[host] then |
99 if components[host] then |
94 modulemanager.unload(host, "dialback"); |
100 modulemanager.unload(host, "dialback"); |
95 components[host] = nil; |
101 components[host] = nil; |
96 hosts[host] = nil; |
102 local host_config = defined_hosts[host]; |
|
103 if ((host_config.core.enabled == nil or host_config.core.enabled) and type(host_config.core.component_module) == "string") then |
|
104 -- Set default handler |
|
105 else |
|
106 -- Component not in config, or disabled, remove |
|
107 hosts[host] = nil; |
|
108 end |
97 -- remove from disco_items |
109 -- remove from disco_items |
98 if not(host:find("@", 1, true) or host:find("/", 1, true)) and host:find(".", 1, true) then |
110 if not(host:find("@", 1, true) or host:find("/", 1, true)) and host:find(".", 1, true) then |
99 disco_items:remove(host:sub(host:find(".", 1, true)+1), host); |
111 disco_items:remove(host:sub(host:find(".", 1, true)+1), host); |
100 end |
112 end |
101 log("debug", "component removed: "..host); |
113 log("debug", "component removed: "..host); |