Annotate

core/componentmanager.lua @ 449:c0a4a1e63d70

Completely switched to new hashes library from the old md5 library
author Waqas Hussain <waqas20@gmail.com>
date Fri, 28 Nov 2008 01:16:26 +0500
parent 270:837c7f701a56
child 519:cccd610a0ef9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
212
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
1
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
2
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
3 local log = require "util.logger".init("componentmanager")
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
4 local jid_split = require "util.jid".split;
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
5 local hosts = hosts;
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
6
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
7 local components = {};
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
8
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
9 module "componentmanager"
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
10
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
11 function handle_stanza(origin, stanza)
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
12 local node, host = jid_split(stanza.attr.to);
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13 local component = components[host];
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14 if not component then component = components[node.."@"..host]; end -- hack to allow hooking node@server
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15 if not component then component = components[stanza.attr.to]; end -- hack to allow hooking node@server/resource and server/resource
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16 if component then
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
17 log("debug", "stanza being handled by component: "..host);
217
d522f3a25dda Re-applying my changes to componentmanager. Sigh.
Matthew Wild <mwild1@gmail.com>
parents: 212
diff changeset
18 component(origin, stanza, hosts[host]);
212
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19 else
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
20 log("error", "Component manager recieved a stanza for a non-existing component: " .. stanza.attr.to);
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21 end
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22 end
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24 function register_component(host, component)
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
25 if not hosts[host] then
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26 -- TODO check for host well-formedness
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27 components[host] = component;
261
790cf21e2af7 Fix outgoing s2s from components. Fixes #16
Matthew Wild <mwild1@gmail.com>
parents: 217
diff changeset
28 hosts[host] = {type = "component", host = host, connected = true, s2sout = {} };
212
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
29 log("debug", "component added: "..host);
270
837c7f701a56 Return registered host table when registering a component
Matthew Wild <mwild1@gmail.com>
parents: 261
diff changeset
30 return hosts[host];
212
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
31 else
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
32 log("error", "Attempt to set component for existing host: "..host);
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
33 end
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34 end
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35
217
d522f3a25dda Re-applying my changes to componentmanager. Sigh.
Matthew Wild <mwild1@gmail.com>
parents: 212
diff changeset
36 return _M;