core/componentmanager.lua

Wed, 13 Jan 2010 00:04:38 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 13 Jan 2010 00:04:38 +0000
changeset 2796
1e287badd033
parent 2768
c317bfef9b74
child 2447
9eb539222f22
child 2923
b7049746bd29
permissions
-rw-r--r--

prosodyctl: Use mode r+ for opening the file so 1) it fails if the file doesn't exist 2) we have write access to lock it

1523
841d61be198f Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents: 1442
diff changeset
1 -- Prosody IM
760
90ce865eebd8 Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents: 759
diff changeset
2 -- Copyright (C) 2008-2009 Matthew Wild
90ce865eebd8 Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents: 759
diff changeset
3 -- Copyright (C) 2008-2009 Waqas Hussain
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
4 --
758
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 751
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 751
diff changeset
6 -- COPYING file in the source package for more information.
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
7 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
8
1970
edab0c61fc02 componentmanager: Handle missing prosody object (helps us pass some tests)
Matthew Wild <mwild1@gmail.com>
parents: 1942
diff changeset
9 local prosody = _G.prosody;
610
d98106902f74 Enable dialback for components
Waqas Hussain <waqas20@gmail.com>
parents: 519
diff changeset
10 local log = require "util.logger".init("componentmanager");
751
7c22619fdb19 componentmanager: Add support for loading components defined in the config
Matthew Wild <mwild1@gmail.com>
parents: 703
diff changeset
11 local configmanager = require "core.configmanager";
847
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
12 local modulemanager = require "core.modulemanager";
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
13 local jid_split = require "util.jid".split;
1850
8f1871c1d456 componentmanager: Fire event on component activation
Matthew Wild <mwild1@gmail.com>
parents: 1849
diff changeset
14 local fire_event = require "core.eventmanager".fire_event;
1188
fa48e69c4786 core: hosts[*].events
Waqas Hussain <waqas20@gmail.com>
parents: 1177
diff changeset
15 local events_new = require "util.events".new;
982
dbbeb73952e6 componentmanager: Improve default component stanza handler
Matthew Wild <mwild1@gmail.com>
parents: 970
diff changeset
16 local st = require "util.stanza";
2768
c317bfef9b74 componentmanager: Set ssl_ctx[_in] for components correctly, and use global SSL context if available
Matthew Wild <mwild1@gmail.com>
parents: 2075
diff changeset
17 local prosody, hosts = prosody, prosody.hosts;
c317bfef9b74 componentmanager: Set ssl_ctx[_in] for components correctly, and use global SSL context if available
Matthew Wild <mwild1@gmail.com>
parents: 2075
diff changeset
18 local ssl = ssl;
751
7c22619fdb19 componentmanager: Add support for loading components defined in the config
Matthew Wild <mwild1@gmail.com>
parents: 703
diff changeset
19
2768
c317bfef9b74 componentmanager: Set ssl_ctx[_in] for components correctly, and use global SSL context if available
Matthew Wild <mwild1@gmail.com>
parents: 2075
diff changeset
20 local pairs, setmetatable, type, tostring = pairs, setmetatable, type, tostring;
847
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
21
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
22 local components = {};
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
23
939
b832f786af62 Added: componentmanager: Automatically add component.host.name to the disco items list of host.name
Waqas Hussain <waqas20@gmail.com>
parents: 894
diff changeset
24 local disco_items = require "util.multitable".new();
b832f786af62 Added: componentmanager: Automatically add component.host.name to the disco items list of host.name
Waqas Hussain <waqas20@gmail.com>
parents: 894
diff changeset
25 local NULL = {};
b832f786af62 Added: componentmanager: Automatically add component.host.name to the disco items list of host.name
Waqas Hussain <waqas20@gmail.com>
parents: 894
diff changeset
26
847
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
27 module "componentmanager"
751
7c22619fdb19 componentmanager: Add support for loading components defined in the config
Matthew Wild <mwild1@gmail.com>
parents: 703
diff changeset
28
961
b48ed2149d0a componentmanager: Reply with service-unavailable for unconnected components
Matthew Wild <mwild1@gmail.com>
parents: 945
diff changeset
29 local function default_component_handler(origin, stanza)
2075
b4bfa6cb3d83 componentmanager: Improved logging for stanzas being bounced for unavailable components.
Waqas Hussain <waqas20@gmail.com>
parents: 1992
diff changeset
30 log("warn", "Stanza being handled by default component; bouncing error for: %s", stanza:top_tag());
1773
f47aa1d336b5 ComponentManager: Fixed: Default handler sent error replies on result stanzas.
Waqas Hussain <waqas20@gmail.com>
parents: 1772
diff changeset
31 if stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then
1774
53bd9c9f3103 ComponentManager: Removed dependency on core_route_stanza. The default component handler now replies using origin.send().
Waqas Hussain <waqas20@gmail.com>
parents: 1773
diff changeset
32 origin.send(st.error_reply(stanza, "wait", "service-unavailable", "Component unavailable"));
982
dbbeb73952e6 componentmanager: Improve default component stanza handler
Matthew Wild <mwild1@gmail.com>
parents: 970
diff changeset
33 end
961
b48ed2149d0a componentmanager: Reply with service-unavailable for unconnected components
Matthew Wild <mwild1@gmail.com>
parents: 945
diff changeset
34 end
b48ed2149d0a componentmanager: Reply with service-unavailable for unconnected components
Matthew Wild <mwild1@gmail.com>
parents: 945
diff changeset
35
751
7c22619fdb19 componentmanager: Add support for loading components defined in the config
Matthew Wild <mwild1@gmail.com>
parents: 703
diff changeset
36 function load_enabled_components(config)
7c22619fdb19 componentmanager: Add support for loading components defined in the config
Matthew Wild <mwild1@gmail.com>
parents: 703
diff changeset
37 local defined_hosts = config or configmanager.getconfig();
7c22619fdb19 componentmanager: Add support for loading components defined in the config
Matthew Wild <mwild1@gmail.com>
parents: 703
diff changeset
38
7c22619fdb19 componentmanager: Add support for loading components defined in the config
Matthew Wild <mwild1@gmail.com>
parents: 703
diff changeset
39 for host, host_config in pairs(defined_hosts) do
7c22619fdb19 componentmanager: Add support for loading components defined in the config
Matthew Wild <mwild1@gmail.com>
parents: 703
diff changeset
40 if host ~= "*" and ((host_config.core.enabled == nil or host_config.core.enabled) and type(host_config.core.component_module) == "string") then
1849
5529d3c8eee7 componentmanager: Use create_component for, er, creating components
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
41 hosts[host] = create_component(host);
5529d3c8eee7 componentmanager: Use create_component for, er, creating components
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
42 hosts[host].connected = false;
961
b48ed2149d0a componentmanager: Reply with service-unavailable for unconnected components
Matthew Wild <mwild1@gmail.com>
parents: 945
diff changeset
43 components[host] = default_component_handler;
751
7c22619fdb19 componentmanager: Add support for loading components defined in the config
Matthew Wild <mwild1@gmail.com>
parents: 703
diff changeset
44 local ok, err = modulemanager.load(host, host_config.core.component_module);
7c22619fdb19 componentmanager: Add support for loading components defined in the config
Matthew Wild <mwild1@gmail.com>
parents: 703
diff changeset
45 if not ok then
7c22619fdb19 componentmanager: Add support for loading components defined in the config
Matthew Wild <mwild1@gmail.com>
parents: 703
diff changeset
46 log("error", "Error loading %s component %s: %s", tostring(host_config.core.component_module), tostring(host), tostring(err));
7c22619fdb19 componentmanager: Add support for loading components defined in the config
Matthew Wild <mwild1@gmail.com>
parents: 703
diff changeset
47 else
1850
8f1871c1d456 componentmanager: Fire event on component activation
Matthew Wild <mwild1@gmail.com>
parents: 1849
diff changeset
48 fire_event("component-activated", host, host_config);
1096
266ef0c6b1d0 componentmanager: Reduce log output at startup to 'debug'
Matthew Wild <mwild1@gmail.com>
parents: 1064
diff changeset
49 log("debug", "Activated %s component: %s", host_config.core.component_module, host);
751
7c22619fdb19 componentmanager: Add support for loading components defined in the config
Matthew Wild <mwild1@gmail.com>
parents: 703
diff changeset
50 end
7c22619fdb19 componentmanager: Add support for loading components defined in the config
Matthew Wild <mwild1@gmail.com>
parents: 703
diff changeset
51 end
7c22619fdb19 componentmanager: Add support for loading components defined in the config
Matthew Wild <mwild1@gmail.com>
parents: 703
diff changeset
52 end
7c22619fdb19 componentmanager: Add support for loading components defined in the config
Matthew Wild <mwild1@gmail.com>
parents: 703
diff changeset
53 end
7c22619fdb19 componentmanager: Add support for loading components defined in the config
Matthew Wild <mwild1@gmail.com>
parents: 703
diff changeset
54
1970
edab0c61fc02 componentmanager: Handle missing prosody object (helps us pass some tests)
Matthew Wild <mwild1@gmail.com>
parents: 1942
diff changeset
55 if prosody and prosody.events then
edab0c61fc02 componentmanager: Handle missing prosody object (helps us pass some tests)
Matthew Wild <mwild1@gmail.com>
parents: 1942
diff changeset
56 prosody.events.add_handler("server-starting", load_enabled_components);
edab0c61fc02 componentmanager: Handle missing prosody object (helps us pass some tests)
Matthew Wild <mwild1@gmail.com>
parents: 1942
diff changeset
57 end
847
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
58
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
59 function handle_stanza(origin, stanza)
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
60 local node, host = jid_split(stanza.attr.to);
638
1915c64c9436 Changed order of checking for component hosts to check the full and bare JIDs before the hostname
Waqas Hussain <waqas20@gmail.com>
parents: 615
diff changeset
61 local component = nil;
1177
97ecfcec2d71 componentmanager: Don't error on stanzas to bare component JID
Matthew Wild <mwild1@gmail.com>
parents: 1168
diff changeset
62 if host then
97ecfcec2d71 componentmanager: Don't error on stanzas to bare component JID
Matthew Wild <mwild1@gmail.com>
parents: 1168
diff changeset
63 if node then component = components[node.."@"..host]; end -- hack to allow hooking node@server
97ecfcec2d71 componentmanager: Don't error on stanzas to bare component JID
Matthew Wild <mwild1@gmail.com>
parents: 1168
diff changeset
64 if not component then component = components[host]; end
97ecfcec2d71 componentmanager: Don't error on stanzas to bare component JID
Matthew Wild <mwild1@gmail.com>
parents: 1168
diff changeset
65 end
847
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
66 if component then
983
460429a59c83 componentmanager: Small logging fix
Matthew Wild <mwild1@gmail.com>
parents: 982
diff changeset
67 log("debug", "%s stanza being handled by component: %s", stanza.name, host);
847
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
68 component(origin, stanza, hosts[host]);
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
69 else
1772
c0ba9cd6ee63 ComponentManager: Fixed a bit of logging.
Waqas Hussain <waqas20@gmail.com>
parents: 1705
diff changeset
70 log("error", "Component manager recieved a stanza for a non-existing component: "..tostring(stanza));
1990
b7fff80908b6 componentmanager: Let the default component handler handle stanzas if a component handler isn't available.
Waqas Hussain <waqas20@gmail.com>
parents: 1970
diff changeset
71 default_component_handler(origin, stanza);
847
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
72 end
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
73 end
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
74
1851
0a4d4ba01db8 componentmanager: Preserve existing events table (if any) when registering a component
Matthew Wild <mwild1@gmail.com>
parents: 1850
diff changeset
75 function create_component(host, component, events)
970
5516f9e66482 sessionmanager, componentmanager: Fix some wacky indentation (thanks greyback!)
Matthew Wild <mwild1@gmail.com>
parents: 961
diff changeset
76 -- TODO check for host well-formedness
2768
c317bfef9b74 componentmanager: Set ssl_ctx[_in] for components correctly, and use global SSL context if available
Matthew Wild <mwild1@gmail.com>
parents: 2075
diff changeset
77 local ssl_ctx, ssl_ctx_in;
c317bfef9b74 componentmanager: Set ssl_ctx[_in] for components correctly, and use global SSL context if available
Matthew Wild <mwild1@gmail.com>
parents: 2075
diff changeset
78 if host and ssl then
1939
2c295826a96d componentmanager: Use ssl_ctx of 'parent' host (should fix TLS for components)
Matthew Wild <mwild1@gmail.com>
parents: 1853
diff changeset
79 -- We need to find SSL context to use...
2c295826a96d componentmanager: Use ssl_ctx of 'parent' host (should fix TLS for components)
Matthew Wild <mwild1@gmail.com>
parents: 1853
diff changeset
80 -- Discussion in prosody@ concluded that
2c295826a96d componentmanager: Use ssl_ctx of 'parent' host (should fix TLS for components)
Matthew Wild <mwild1@gmail.com>
parents: 1853
diff changeset
81 -- 1 level back is usually enough by default
1940
85d51cea2c4c componentmanager: Fix oops in pattern for matching subdomain
Matthew Wild <mwild1@gmail.com>
parents: 1939
diff changeset
82 local base_host = host:gsub("^[^%.]+%.", "");
1939
2c295826a96d componentmanager: Use ssl_ctx of 'parent' host (should fix TLS for components)
Matthew Wild <mwild1@gmail.com>
parents: 1853
diff changeset
83 if hosts[base_host] then
2c295826a96d componentmanager: Use ssl_ctx of 'parent' host (should fix TLS for components)
Matthew Wild <mwild1@gmail.com>
parents: 1853
diff changeset
84 ssl_ctx = hosts[base_host].ssl_ctx;
2768
c317bfef9b74 componentmanager: Set ssl_ctx[_in] for components correctly, and use global SSL context if available
Matthew Wild <mwild1@gmail.com>
parents: 2075
diff changeset
85 ssl_ctx_in = hosts[base_host].ssl_ctx_in;
c317bfef9b74 componentmanager: Set ssl_ctx[_in] for components correctly, and use global SSL context if available
Matthew Wild <mwild1@gmail.com>
parents: 2075
diff changeset
86 elseif prosody.global_ssl_ctx then
c317bfef9b74 componentmanager: Set ssl_ctx[_in] for components correctly, and use global SSL context if available
Matthew Wild <mwild1@gmail.com>
parents: 2075
diff changeset
87 -- We have no cert, and no parent host to borrow a cert from
c317bfef9b74 componentmanager: Set ssl_ctx[_in] for components correctly, and use global SSL context if available
Matthew Wild <mwild1@gmail.com>
parents: 2075
diff changeset
88 -- Use global/default cert if there is one
c317bfef9b74 componentmanager: Set ssl_ctx[_in] for components correctly, and use global SSL context if available
Matthew Wild <mwild1@gmail.com>
parents: 2075
diff changeset
89 ssl_ctx = ssl.newcontext(prosody.global_ssl_ctx);
c317bfef9b74 componentmanager: Set ssl_ctx[_in] for components correctly, and use global SSL context if available
Matthew Wild <mwild1@gmail.com>
parents: 2075
diff changeset
90 ssl_ctx_in = ssl.newcontext(setmetatable({ mode = "server" }, { __index = prosody.global_ssl_ctx }));
1939
2c295826a96d componentmanager: Use ssl_ctx of 'parent' host (should fix TLS for components)
Matthew Wild <mwild1@gmail.com>
parents: 1853
diff changeset
91 end
2c295826a96d componentmanager: Use ssl_ctx of 'parent' host (should fix TLS for components)
Matthew Wild <mwild1@gmail.com>
parents: 1853
diff changeset
92 end
2c295826a96d componentmanager: Use ssl_ctx of 'parent' host (should fix TLS for components)
Matthew Wild <mwild1@gmail.com>
parents: 1853
diff changeset
93 return { type = "component", host = host, connected = true, s2sout = {},
2768
c317bfef9b74 componentmanager: Set ssl_ctx[_in] for components correctly, and use global SSL context if available
Matthew Wild <mwild1@gmail.com>
parents: 2075
diff changeset
94 ssl_ctx = ssl_ctx, ssl_ctx_in = ssl_ctx_in, events = events or events_new() };
847
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
95 end
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
96
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
97 function register_component(host, component, session)
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
98 if not hosts[host] or (hosts[host].type == 'component' and not hosts[host].connected) then
1264
498293bce4bf componentmanager: Create events object for configured hosts, and carry it over to a new component if one is registered with no events object
Matthew Wild <mwild1@gmail.com>
parents: 1257
diff changeset
99 local old_events = hosts[host] and hosts[host].events;
498293bce4bf componentmanager: Create events object for configured hosts, and carry it over to a new component if one is registered with no events object
Matthew Wild <mwild1@gmail.com>
parents: 1257
diff changeset
100
847
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
101 components[host] = component;
1851
0a4d4ba01db8 componentmanager: Preserve existing events table (if any) when registering a component
Matthew Wild <mwild1@gmail.com>
parents: 1850
diff changeset
102 hosts[host] = session or create_component(host, component, old_events);
1257
8c9f20d3a17f componentmanager: Add events object to registered components if they don't already have one
Matthew Wild <mwild1@gmail.com>
parents: 1188
diff changeset
103
8c9f20d3a17f componentmanager: Add events object to registered components if they don't already have one
Matthew Wild <mwild1@gmail.com>
parents: 1188
diff changeset
104 -- Add events object if not already one
8c9f20d3a17f componentmanager: Add events object to registered components if they don't already have one
Matthew Wild <mwild1@gmail.com>
parents: 1188
diff changeset
105 if not hosts[host].events then
1264
498293bce4bf componentmanager: Create events object for configured hosts, and carry it over to a new component if one is registered with no events object
Matthew Wild <mwild1@gmail.com>
parents: 1257
diff changeset
106 hosts[host].events = old_events or events_new();
1257
8c9f20d3a17f componentmanager: Add events object to registered components if they don't already have one
Matthew Wild <mwild1@gmail.com>
parents: 1188
diff changeset
107 end
8c9f20d3a17f componentmanager: Add events object to registered components if they don't already have one
Matthew Wild <mwild1@gmail.com>
parents: 1188
diff changeset
108
939
b832f786af62 Added: componentmanager: Automatically add component.host.name to the disco items list of host.name
Waqas Hussain <waqas20@gmail.com>
parents: 894
diff changeset
109 -- add to disco_items
b832f786af62 Added: componentmanager: Automatically add component.host.name to the disco items list of host.name
Waqas Hussain <waqas20@gmail.com>
parents: 894
diff changeset
110 if not(host:find("@", 1, true) or host:find("/", 1, true)) and host:find(".", 1, true) then
b832f786af62 Added: componentmanager: Automatically add component.host.name to the disco items list of host.name
Waqas Hussain <waqas20@gmail.com>
parents: 894
diff changeset
111 disco_items:set(host:sub(host:find(".", 1, true)+1), host, true);
b832f786af62 Added: componentmanager: Automatically add component.host.name to the disco items list of host.name
Waqas Hussain <waqas20@gmail.com>
parents: 894
diff changeset
112 end
847
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
113 modulemanager.load(host, "dialback");
1942
f74c267f7e1b componentmanager: Auto-load mod_tls for components #hack
Matthew Wild <mwild1@gmail.com>
parents: 1941
diff changeset
114 modulemanager.load(host, "tls");
847
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
115 log("debug", "component added: "..host);
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
116 return session or hosts[host];
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
117 else
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
118 log("error", "Attempt to set component for existing host: "..host);
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
119 end
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
120 end
673
c9bc58e84e96 componentmanager: Added support for component deregistering
Waqas Hussain <waqas20@gmail.com>
parents: 638
diff changeset
121
703
f9909efed20c componentmanager: Removed unneeded parameter from componentmanager.deregister_component
Waqas Hussain <waqas20@gmail.com>
parents: 673
diff changeset
122 function deregister_component(host)
673
c9bc58e84e96 componentmanager: Added support for component deregistering
Waqas Hussain <waqas20@gmail.com>
parents: 638
diff changeset
123 if components[host] then
1991
ed4cd15bf4dd componentmanager: Unload mod_tls for components before removing them.
Waqas Hussain <waqas20@gmail.com>
parents: 1990
diff changeset
124 modulemanager.unload(host, "tls");
751
7c22619fdb19 componentmanager: Add support for loading components defined in the config
Matthew Wild <mwild1@gmail.com>
parents: 703
diff changeset
125 modulemanager.unload(host, "dialback");
1064
3e945c3938ad core.componentmanager: Really fix marking components as disconnected when unregistered
Matthew Wild <mwild1@gmail.com>
parents: 1009
diff changeset
126 hosts[host].connected = nil;
984
9acc1c2ceb2c componentmanager: Restore default component when unregistering
Matthew Wild <mwild1@gmail.com>
parents: 983
diff changeset
127 local host_config = configmanager.getconfig()[host];
9acc1c2ceb2c componentmanager: Restore default component when unregistering
Matthew Wild <mwild1@gmail.com>
parents: 983
diff changeset
128 if host_config and ((host_config.core.enabled == nil or host_config.core.enabled) and type(host_config.core.component_module) == "string") then
961
b48ed2149d0a componentmanager: Reply with service-unavailable for unconnected components
Matthew Wild <mwild1@gmail.com>
parents: 945
diff changeset
129 -- Set default handler
984
9acc1c2ceb2c componentmanager: Restore default component when unregistering
Matthew Wild <mwild1@gmail.com>
parents: 983
diff changeset
130 components[host] = default_component_handler;
961
b48ed2149d0a componentmanager: Reply with service-unavailable for unconnected components
Matthew Wild <mwild1@gmail.com>
parents: 945
diff changeset
131 else
b48ed2149d0a componentmanager: Reply with service-unavailable for unconnected components
Matthew Wild <mwild1@gmail.com>
parents: 945
diff changeset
132 -- Component not in config, or disabled, remove
1992
bbaba17537a9 componentmanager: Added a FIXME comment.
Waqas Hussain <waqas20@gmail.com>
parents: 1991
diff changeset
133 hosts[host] = nil; -- FIXME do proper unload of all modules and other cleanup before removing
984
9acc1c2ceb2c componentmanager: Restore default component when unregistering
Matthew Wild <mwild1@gmail.com>
parents: 983
diff changeset
134 components[host] = nil;
961
b48ed2149d0a componentmanager: Reply with service-unavailable for unconnected components
Matthew Wild <mwild1@gmail.com>
parents: 945
diff changeset
135 end
939
b832f786af62 Added: componentmanager: Automatically add component.host.name to the disco items list of host.name
Waqas Hussain <waqas20@gmail.com>
parents: 894
diff changeset
136 -- remove from disco_items
b832f786af62 Added: componentmanager: Automatically add component.host.name to the disco items list of host.name
Waqas Hussain <waqas20@gmail.com>
parents: 894
diff changeset
137 if not(host:find("@", 1, true) or host:find("/", 1, true)) and host:find(".", 1, true) then
b832f786af62 Added: componentmanager: Automatically add component.host.name to the disco items list of host.name
Waqas Hussain <waqas20@gmail.com>
parents: 894
diff changeset
138 disco_items:remove(host:sub(host:find(".", 1, true)+1), host);
b832f786af62 Added: componentmanager: Automatically add component.host.name to the disco items list of host.name
Waqas Hussain <waqas20@gmail.com>
parents: 894
diff changeset
139 end
673
c9bc58e84e96 componentmanager: Added support for component deregistering
Waqas Hussain <waqas20@gmail.com>
parents: 638
diff changeset
140 log("debug", "component removed: "..host);
c9bc58e84e96 componentmanager: Added support for component deregistering
Waqas Hussain <waqas20@gmail.com>
parents: 638
diff changeset
141 return true;
c9bc58e84e96 componentmanager: Added support for component deregistering
Waqas Hussain <waqas20@gmail.com>
parents: 638
diff changeset
142 else
c9bc58e84e96 componentmanager: Added support for component deregistering
Waqas Hussain <waqas20@gmail.com>
parents: 638
diff changeset
143 log("error", "Attempt to remove component for non-existing host: "..host);
c9bc58e84e96 componentmanager: Added support for component deregistering
Waqas Hussain <waqas20@gmail.com>
parents: 638
diff changeset
144 end
c9bc58e84e96 componentmanager: Added support for component deregistering
Waqas Hussain <waqas20@gmail.com>
parents: 638
diff changeset
145 end
847
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
146
961
b48ed2149d0a componentmanager: Reply with service-unavailable for unconnected components
Matthew Wild <mwild1@gmail.com>
parents: 945
diff changeset
147 function set_component_handler(host, handler)
b48ed2149d0a componentmanager: Reply with service-unavailable for unconnected components
Matthew Wild <mwild1@gmail.com>
parents: 945
diff changeset
148 components[host] = handler;
b48ed2149d0a componentmanager: Reply with service-unavailable for unconnected components
Matthew Wild <mwild1@gmail.com>
parents: 945
diff changeset
149 end
b48ed2149d0a componentmanager: Reply with service-unavailable for unconnected components
Matthew Wild <mwild1@gmail.com>
parents: 945
diff changeset
150
1693
56e23b0b3893 componentmanager: Added function to get a list of children for a given hostname
Waqas Hussain <waqas20@gmail.com>
parents: 1523
diff changeset
151 function get_children(host)
56e23b0b3893 componentmanager: Added function to get a list of children for a given hostname
Waqas Hussain <waqas20@gmail.com>
parents: 1523
diff changeset
152 return disco_items:get(host) or NULL;
56e23b0b3893 componentmanager: Added function to get a list of children for a given hostname
Waqas Hussain <waqas20@gmail.com>
parents: 1523
diff changeset
153 end
56e23b0b3893 componentmanager: Added function to get a list of children for a given hostname
Waqas Hussain <waqas20@gmail.com>
parents: 1523
diff changeset
154
847
2d424936723c core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
Matthew Wild <mwild1@gmail.com>
parents: 777
diff changeset
155 return _M;

mercurial