Software /
code /
prosody
Comparison
core/componentmanager.lua @ 939:b832f786af62
Added: componentmanager: Automatically add component.host.name to the disco items list of host.name
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 30 Mar 2009 06:07:21 +0500 |
parent | 896:2c0b9e3c11c3 |
child | 945:699f0c46526a |
comparison
equal
deleted
inserted
replaced
938:663f75dd7b42 | 939:b832f786af62 |
---|---|
17 local hosts = hosts; | 17 local hosts = hosts; |
18 | 18 |
19 local pairs, type, tostring = pairs, type, tostring; | 19 local pairs, type, tostring = pairs, type, tostring; |
20 | 20 |
21 local components = {}; | 21 local components = {}; |
22 | |
23 local disco_items = require "util.multitable".new(); | |
24 local NULL = {}; | |
25 require "core.discomanager".addDiscoItemsHandler("*host", function(reply, to, from, node) | |
26 if #node == 0 and hosts[to] then | |
27 for jid in pairs(disco_items:get(to) or NULL) do | |
28 reply:tag("item", {jid = jid}):up(); | |
29 end | |
30 return true; | |
31 end | |
32 end); | |
33 | |
22 | 34 |
23 module "componentmanager" | 35 module "componentmanager" |
24 | 36 |
25 function load_enabled_components(config) | 37 function load_enabled_components(config) |
26 local defined_hosts = config or configmanager.getconfig(); | 38 local defined_hosts = config or configmanager.getconfig(); |
62 | 74 |
63 function register_component(host, component, session) | 75 function register_component(host, component, session) |
64 if not hosts[host] or (hosts[host].type == 'component' and not hosts[host].connected) then | 76 if not hosts[host] or (hosts[host].type == 'component' and not hosts[host].connected) then |
65 components[host] = component; | 77 components[host] = component; |
66 hosts[host] = session or create_component(host, component); | 78 hosts[host] = session or create_component(host, component); |
67 | 79 -- add to disco_items |
80 if not(host:find("@", 1, true) or host:find("/", 1, true)) and host:find(".", 1, true) then | |
81 disco_items:set(host:sub(host:find(".", 1, true)+1), host, true); | |
82 end | |
68 -- FIXME only load for a.b.c if b.c has dialback, and/or check in config | 83 -- FIXME only load for a.b.c if b.c has dialback, and/or check in config |
69 modulemanager.load(host, "dialback"); | 84 modulemanager.load(host, "dialback"); |
70 log("debug", "component added: "..host); | 85 log("debug", "component added: "..host); |
71 return session or hosts[host]; | 86 return session or hosts[host]; |
72 else | 87 else |
77 function deregister_component(host) | 92 function deregister_component(host) |
78 if components[host] then | 93 if components[host] then |
79 modulemanager.unload(host, "dialback"); | 94 modulemanager.unload(host, "dialback"); |
80 components[host] = nil; | 95 components[host] = nil; |
81 hosts[host] = nil; | 96 hosts[host] = nil; |
97 -- remove from disco_items | |
98 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); | |
100 end | |
82 log("debug", "component removed: "..host); | 101 log("debug", "component removed: "..host); |
83 return true; | 102 return true; |
84 else | 103 else |
85 log("error", "Attempt to remove component for non-existing host: "..host); | 104 log("error", "Attempt to remove component for non-existing host: "..host); |
86 end | 105 end |