Thu, 29 Jan 2009 02:13:30 +0000
configmanager: Add support for defining components
615 | 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 | 21 | |
22 | ||
610
d98106902f74
Enable dialback for components
Waqas Hussain <waqas20@gmail.com>
parents:
519
diff
changeset
|
23 | local log = require "util.logger".init("componentmanager"); |
673
c9bc58e84e96
componentmanager: Added support for component deregistering
Waqas Hussain <waqas20@gmail.com>
parents:
638
diff
changeset
|
24 | local module_load = require "core.modulemanager".load; |
c9bc58e84e96
componentmanager: Added support for component deregistering
Waqas Hussain <waqas20@gmail.com>
parents:
638
diff
changeset
|
25 | local module_unload = require "core.modulemanager".unload; |
212 | 26 | local jid_split = require "util.jid".split; |
27 | local hosts = hosts; | |
28 | ||
29 | local components = {}; | |
30 | ||
31 | module "componentmanager" | |
32 | ||
33 | function handle_stanza(origin, stanza) | |
34 | 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
|
35 | local component = nil; |
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
|
36 | if not component then component = components[stanza.attr.to]; end -- hack to allow hooking node@server/resource and server/resource |
212 | 37 | if not component then component = components[node.."@"..host]; end -- hack to allow hooking node@server |
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
|
38 | if not component then component = components[host]; end |
212 | 39 | if component then |
40 | 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
|
41 | component(origin, stanza, hosts[host]); |
212 | 42 | else |
43 | log("error", "Component manager recieved a stanza for a non-existing component: " .. stanza.attr.to); | |
44 | end | |
45 | end | |
46 | ||
47 | function register_component(host, component) | |
48 | if not hosts[host] then | |
49 | -- TODO check for host well-formedness | |
50 | components[host] = component; | |
610
d98106902f74
Enable dialback for components
Waqas Hussain <waqas20@gmail.com>
parents:
519
diff
changeset
|
51 | hosts[host] = { type = "component", host = host, connected = true, s2sout = {} }; |
d98106902f74
Enable dialback for components
Waqas Hussain <waqas20@gmail.com>
parents:
519
diff
changeset
|
52 | -- 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
|
53 | module_load(host, "dialback"); |
212 | 54 | log("debug", "component added: "..host); |
270
837c7f701a56
Return registered host table when registering a component
Matthew Wild <mwild1@gmail.com>
parents:
261
diff
changeset
|
55 | return hosts[host]; |
212 | 56 | else |
57 | log("error", "Attempt to set component for existing host: "..host); | |
58 | end | |
59 | end | |
673
c9bc58e84e96
componentmanager: Added support for component deregistering
Waqas Hussain <waqas20@gmail.com>
parents:
638
diff
changeset
|
60 | |
703
f9909efed20c
componentmanager: Removed unneeded parameter from componentmanager.deregister_component
Waqas Hussain <waqas20@gmail.com>
parents:
673
diff
changeset
|
61 | function deregister_component(host) |
673
c9bc58e84e96
componentmanager: Added support for component deregistering
Waqas Hussain <waqas20@gmail.com>
parents:
638
diff
changeset
|
62 | if components[host] then |
c9bc58e84e96
componentmanager: Added support for component deregistering
Waqas Hussain <waqas20@gmail.com>
parents:
638
diff
changeset
|
63 | module_unload(host, "dialback"); |
c9bc58e84e96
componentmanager: Added support for component deregistering
Waqas Hussain <waqas20@gmail.com>
parents:
638
diff
changeset
|
64 | components[host] = nil; |
c9bc58e84e96
componentmanager: Added support for component deregistering
Waqas Hussain <waqas20@gmail.com>
parents:
638
diff
changeset
|
65 | hosts[host] = nil; |
c9bc58e84e96
componentmanager: Added support for component deregistering
Waqas Hussain <waqas20@gmail.com>
parents:
638
diff
changeset
|
66 | log("debug", "component removed: "..host); |
c9bc58e84e96
componentmanager: Added support for component deregistering
Waqas Hussain <waqas20@gmail.com>
parents:
638
diff
changeset
|
67 | return true; |
c9bc58e84e96
componentmanager: Added support for component deregistering
Waqas Hussain <waqas20@gmail.com>
parents:
638
diff
changeset
|
68 | else |
c9bc58e84e96
componentmanager: Added support for component deregistering
Waqas Hussain <waqas20@gmail.com>
parents:
638
diff
changeset
|
69 | 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
|
70 | end |
c9bc58e84e96
componentmanager: Added support for component deregistering
Waqas Hussain <waqas20@gmail.com>
parents:
638
diff
changeset
|
71 | end |
212 | 72 | |
217
d522f3a25dda
Re-applying my changes to componentmanager. Sigh.
Matthew Wild <mwild1@gmail.com>
parents:
212
diff
changeset
|
73 | return _M; |