Annotate

core/componentmanager.lua @ 615:4ae3e81513f3

0.1 -> 0.2
author Matthew Wild <mwild1@gmail.com>
date Wed, 10 Dec 2008 15:44:03 +0000
parent 610:d98106902f74
child 638:1915c64c9436
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
615
4ae3e81513f3 0.1 -> 0.2
Matthew Wild <mwild1@gmail.com>
parents: 610
diff changeset
1 -- Prosody IM v0.2
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
2 -- Copyright (C) 2008 Matthew Wild
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
3 -- Copyright (C) 2008 Waqas Hussain
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
4 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
5 -- This program is free software; you can redistribute it and/or
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
6 -- modify it under the terms of the GNU General Public License
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
7 -- as published by the Free Software Foundation; either version 2
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
8 -- of the License, or (at your option) any later version.
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
9 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
10 -- This program is distributed in the hope that it will be useful,
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
13 -- GNU General Public License for more details.
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
14 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
15 -- You should have received a copy of the GNU General Public License
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
16 -- along with this program; if not, write to the Free Software
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
17 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
18 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
19
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 270
diff changeset
20
212
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22
610
d98106902f74 Enable dialback for components
Waqas Hussain <waqas20@gmail.com>
parents: 519
diff changeset
23 local log = require "util.logger".init("componentmanager");
d98106902f74 Enable dialback for components
Waqas Hussain <waqas20@gmail.com>
parents: 519
diff changeset
24 local module_load = require "core.modulemanager".load;
212
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
25 local jid_split = require "util.jid".split;
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26 local hosts = hosts;
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28 local components = {};
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
29
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
30 module "componentmanager"
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
31
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
32 function handle_stanza(origin, stanza)
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
33 local node, host = jid_split(stanza.attr.to);
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34 local component = components[host];
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35 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
36 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
37 if component then
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
38 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
39 component(origin, stanza, hosts[host]);
212
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
40 else
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
41 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
42 end
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
43 end
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
44
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
45 function register_component(host, component)
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
46 if not hosts[host] then
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47 -- TODO check for host well-formedness
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
48 components[host] = component;
610
d98106902f74 Enable dialback for components
Waqas Hussain <waqas20@gmail.com>
parents: 519
diff changeset
49 hosts[host] = { type = "component", host = host, connected = true, s2sout = {} };
d98106902f74 Enable dialback for components
Waqas Hussain <waqas20@gmail.com>
parents: 519
diff changeset
50 -- FIXME only load for a.b.c if b.c has dialback, and/or check in config
d98106902f74 Enable dialback for components
Waqas Hussain <waqas20@gmail.com>
parents: 519
diff changeset
51 module_load(host, "dialback");
212
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
52 log("debug", "component added: "..host);
270
837c7f701a56 Return registered host table when registering a component
Matthew Wild <mwild1@gmail.com>
parents: 261
diff changeset
53 return hosts[host];
212
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
54 else
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
55 log("error", "Attempt to set component for existing host: "..host);
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
56 end
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
57 end
9d6da9ed9063 Internal component support
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
58
217
d522f3a25dda Re-applying my changes to componentmanager. Sigh.
Matthew Wild <mwild1@gmail.com>
parents: 212
diff changeset
59 return _M;