aboutsummaryrefslogtreecommitdiffstats
path: root/core/componentmanager.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2009-02-28 02:05:37 +0000
committerMatthew Wild <mwild1@gmail.com>2009-02-28 02:05:37 +0000
commit8c36520f60140741cde82860a05b39fbe1844535 (patch)
treeabae78c0783aea28c5cd826c2ae51550bcb1dbe7 /core/componentmanager.lua
parentc2b54ca16026643838440922fa966cea576f42d2 (diff)
downloadprosody-8c36520f60140741cde82860a05b39fbe1844535.tar.gz
prosody-8c36520f60140741cde82860a05b39fbe1844535.zip
core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler
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;