aboutsummaryrefslogtreecommitdiffstats
path: root/core/componentmanager.lua
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2009-03-03 17:48:04 +0100
committerTobias Markmann <tm@ayena.de>2009-03-03 17:48:04 +0100
commit7a7a89844a038b071f02fd1af309ba9ebbcda7de (patch)
tree73946c977be10a965d59de85b3ce6ba3743bc771 /core/componentmanager.lua
parent3d1e7adbbc0afb8395f02ecd42fe3c38ce6a8d36 (diff)
parentb6b9906c3c653935b55ad79ad4a2c41118f0a0e3 (diff)
downloadprosody-7a7a89844a038b071f02fd1af309ba9ebbcda7de.tar.gz
prosody-7a7a89844a038b071f02fd1af309ba9ebbcda7de.zip
Merged with main tip.
Diffstat (limited to 'core/componentmanager.lua')
-rw-r--r--core/componentmanager.lua76
1 files changed, 41 insertions, 35 deletions
diff --git a/core/componentmanager.lua b/core/componentmanager.lua
index 04909a07..15931167 100644
--- a/core/componentmanager.lua
+++ b/core/componentmanager.lua
@@ -7,20 +7,20 @@
--
-
-
+
+
local log = require "util.logger".init("componentmanager");
local configmanager = require "core.configmanager";
local eventmanager = require "core.eventmanager";
-local modulemanager = require "core.modulemanager";
-local jid_split = require "util.jid".split;
+local modulemanager = require "core.modulemanager";
+local jid_split = require "util.jid".split;
local hosts = hosts;
-local pairs, type, tostring = pairs, type, tostring;
-
-local components = {};
-
-module "componentmanager"
+local pairs, type, tostring = pairs, type, tostring;
+
+local components = {};
+
+module "componentmanager"
function load_enabled_components(config)
local defined_hosts = config or configmanager.getconfig();
@@ -39,34 +39,40 @@ function load_enabled_components(config)
end
eventmanager.add_event_hook("server-starting", load_enabled_components);
-
-function handle_stanza(origin, stanza)
- local node, host = jid_split(stanza.attr.to);
+
+function handle_stanza(origin, stanza)
+ local node, host = jid_split(stanza.attr.to);
local component = nil;
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
+ if not component then component = components[node.."@"..host]; end -- hack to allow hooking node@server
if not component then component = components[host]; end
- if component then
- log("debug", "stanza being handled by component: "..host);
- component(origin, stanza, hosts[host]);
- else
- log("error", "Component manager recieved a stanza for a non-existing component: " .. stanza.attr.to);
- end
-end
-
-function register_component(host, component)
- if not hosts[host] or (hosts[host].type == 'component' and not hosts[host].connected) then
- -- TODO check for host well-formedness
- components[host] = component;
- hosts[host] = { type = "component", host = host, connected = true, s2sout = {} };
+ if component then
+ log("debug", "stanza being handled by component: "..host);
+ component(origin, stanza, hosts[host]);
+ else
+ log("error", "Component manager recieved a stanza for a non-existing component: " .. stanza.attr.to);
+ end
+end
+
+function create_component(host, component)
+ -- TODO check for host well-formedness
+ session = session or { type = "component", host = host, connected = true, s2sout = {}, send = component };
+ return session;
+end
+
+function register_component(host, component, session)
+ if not hosts[host] or (hosts[host].type == 'component' and not hosts[host].connected) then
+ components[host] = component;
+ hosts[host] = session or create_component(host, component);
+
-- FIXME only load for a.b.c if b.c has dialback, and/or check in config
- modulemanager.load(host, "dialback");
- log("debug", "component added: "..host);
- return hosts[host];
- else
- log("error", "Attempt to set component for existing host: "..host);
- end
-end
+ modulemanager.load(host, "dialback");
+ log("debug", "component added: "..host);
+ return session or hosts[host];
+ else
+ log("error", "Attempt to set component for existing host: "..host);
+ end
+end
function deregister_component(host)
if components[host] then
@@ -79,5 +85,5 @@ function deregister_component(host)
log("error", "Attempt to remove component for non-existing host: "..host);
end
end
-
-return _M;
+
+return _M;