Software /
code /
prosody
Comparison
core/modulemanager.lua @ 3595:ec1151d0c4a4
modulemanager: load_modules_for_host(): Inherit 'tls' and 'dialback' from global modules list for components, and load the component module. Also refactored to use util.set.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Wed, 10 Nov 2010 18:06:51 +0500 |
parent | 3588:1e570ed17147 |
child | 3596:bbeba9f2acf8 |
comparison
equal
deleted
inserted
replaced
3594:d3b57562cd87 | 3595:ec1151d0c4a4 |
---|---|
38 end | 38 end |
39 | 39 |
40 local array, set = require "util.array", require "util.set"; | 40 local array, set = require "util.array", require "util.set"; |
41 | 41 |
42 local autoload_modules = {"presence", "message", "iq"}; | 42 local autoload_modules = {"presence", "message", "iq"}; |
43 local component_inheritable_modules = {"tls", "dialback"}; | |
43 | 44 |
44 -- We need this to let modules access the real global namespace | 45 -- We need this to let modules access the real global namespace |
45 local _G = _G; | 46 local _G = _G; |
46 | 47 |
47 module "modulemanager" | 48 module "modulemanager" |
57 | 58 |
58 local NULL = {}; | 59 local NULL = {}; |
59 | 60 |
60 -- Load modules when a host is activated | 61 -- Load modules when a host is activated |
61 function load_modules_for_host(host) | 62 function load_modules_for_host(host) |
62 local disabled_set = {}; | 63 local component = config.get(host, "core", "component_module"); |
63 local modules_disabled = config.get(host, "core", "modules_disabled"); | 64 |
64 if modules_disabled then | 65 local global_modules_enabled = config.get("*", "core", "modules_enabled"); |
65 for _, module in ipairs(modules_disabled) do | 66 local global_modules_disabled = config.get("*", "core", "modules_disabled"); |
66 disabled_set[module] = true; | 67 local host_modules_enabled = config.get(host, "core", "modules_enabled"); |
67 end | 68 local host_modules_disabled = config.get(host, "core", "modules_disabled"); |
68 end | 69 |
69 | 70 if host_modules_enabled == global_modules_enabled then host_modules_enabled = nil; end |
70 -- Load auto-loaded modules for this host | 71 if host_modules_disabled == global_modules_disabled then host_modules_disabled = nil; end |
71 if hosts[host].type == "local" then | 72 |
72 for _, module in ipairs(autoload_modules) do | 73 local host_modules = set.new(host_modules_enabled) - set.new(host_modules_disabled); |
73 if not disabled_set[module] then | 74 local global_modules = set.new(autoload_modules) + set.new(global_modules_enabled) - set.new(global_modules_disabled); |
74 load(host, module); | 75 if component then |
75 end | 76 global_modules = set.new(component_inheritable_modules) - global_modules; |
76 end | 77 end |
77 end | 78 local modules = global_modules + host_modules; |
78 | 79 |
79 -- Load modules from global section | 80 if component then |
80 if config.get(host, "core", "load_global_modules") ~= false then | 81 load(host, component); |
81 local modules_enabled = config.get("*", "core", "modules_enabled"); | 82 end |
82 if modules_enabled then | 83 for module in modules do |
83 for _, module in ipairs(modules_enabled) do | 84 load(host, module); |
84 if not disabled_set[module] and not is_loaded(host, module) then | |
85 load(host, module); | |
86 end | |
87 end | |
88 end | |
89 end | |
90 | |
91 -- Load modules from just this host | |
92 local modules_enabled = config.get(host, "core", "modules_enabled"); | |
93 if modules_enabled and modules_enabled ~= config.get("*", "core", "modules_enabled") then | |
94 for _, module in pairs(modules_enabled) do | |
95 if not is_loaded(host, module) then | |
96 load(host, module); | |
97 end | |
98 end | |
99 end | 85 end |
100 end | 86 end |
101 prosody_events.add_handler("host-activated", load_modules_for_host); | 87 prosody_events.add_handler("host-activated", load_modules_for_host); |
102 prosody_events.add_handler("component-activated", load_modules_for_host); | 88 prosody_events.add_handler("component-activated", load_modules_for_host); |
103 -- | 89 -- |