view mod_reload_components/mod_reload_components.lua @ 4738:5aee8d86629a

mod_bookmarks2: Fix handling of nick and password elements This form of child retrieval fails when the stanza elements internally don't have an 'xmlns' attribute, which can happen sometimes for some reason, including when they have been constructed via the stanza builder API. When that is the case then the explicit namespace arguemnt does not match the nil value of the internal attribute. Calling `:get_child()` without the namespace argument does the right thing here, with both nil and the parent namespace as valid values for the internal attribute.
author Kim Alvefur <zash@zash.se>
date Wed, 03 Nov 2021 21:11:55 +0100
parents 85d04dd87f14
children
line wrap: on
line source

module:set_global();

local configmanager = require "core.configmanager";
local hostmanager = require"core.hostmanager";

local function reload_components()

        --- Check if host configuration is a component
        --- @param h hostname
        local function config_is_component(h)
            return h ~= nil and configmanager.get(h, "component_module") ~= nil; -- If a host has a component module defined within it, then it is a component
        end;

        --- Check if host / component configuration is active
        --- @param h hostname / component name
        local function component_is_new(h)
                return h ~= "*" and not hosts[h]; -- If a host is not defined in hosts and it is not global, then it is new
        end

        --- Search for new components that are not activated
        for h, c in pairs(configmanager.getconfig()) do
            if config_is_component(h) and component_is_new(h) then
                module:log ("debug", "Loading new component %s", h );
                hostmanager.activate(h, c);
            end
        end

        --- Search for active components that are not enabled in the configmanager anymore
        local enabled = {}
        for h in pairs(configmanager.getconfig()) do
            enabled[h] = true; -- Set true if it is defined in the configuration file
        end
        for h, c in pairs(hosts) do
            if not enabled[h] then -- Deactivate if not present in the configuration file
                hostmanager.deactivate(h,c);
            end
        end
end

module:hook("config-reloaded", reload_components);