aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/configmanager.lua51
-rw-r--r--core/features.lua2
-rw-r--r--core/moduleapi.lua12
-rw-r--r--core/modulemanager.lua16
4 files changed, 75 insertions, 6 deletions
diff --git a/core/configmanager.lua b/core/configmanager.lua
index bd12e169..36df0171 100644
--- a/core/configmanager.lua
+++ b/core/configmanager.lua
@@ -161,15 +161,44 @@ do
end;
};
+ -- For reading config values out of files.
+ local function filereader(basepath, defaultmode)
+ return function(filename, mode)
+ local f, err = io.open(resolve_relative_path(basepath, filename));
+ if not f then error(err, 2); end
+ local content, err = f:read(mode or defaultmode);
+ f:close();
+ if not content then error(err, 2); end
+ return content;
+ end
+ end
+
+ -- Collect lines into an array
+ local function linereader(basepath)
+ return function(filename)
+ local ret = {};
+ for line in io.lines(resolve_relative_path(basepath, filename)) do
+ t_insert(ret, line);
+ end
+ return ret;
+ end
+ end
+
parser = {};
function parser.load(data, config_file, config_table)
local set_options = {}; -- set_options[host.."/"..option_name] = true (when the option has been set already in this file)
local warnings = {};
local env;
+ local config_path = config_file:gsub("[^"..path_sep.."]+$", "");
+
-- The ' = true' are needed so as not to set off __newindex when we assign the functions below
env = setmetatable({
Host = true, host = true, VirtualHost = true,
Component = true, component = true,
+ FileContents = true,
+ FileLine = true,
+ FileLines = true,
+ Credential = true,
Include = true, include = true, RunScript = true }, {
__index = function (_, k)
if k:match("^ENV_") then
@@ -293,7 +322,6 @@ do
end
local path_pos, glob = file:match("()([^"..path_sep.."]+)$");
local path = file:sub(1, math_max(path_pos-2,0));
- local config_path = config_file:gsub("[^"..path_sep.."]+$", "");
if #path > 0 then
path = resolve_relative_path(config_path, path);
else
@@ -308,7 +336,7 @@ do
return;
end
-- Not a wildcard, so resolve (potentially) relative path and run through config parser
- file = resolve_relative_path(config_file:gsub("[^"..path_sep.."]+$", ""), file);
+ file = resolve_relative_path(config_path, file);
local f, err = io.open(file);
if f then
local ret, err = parser.load(f:read("*a"), file, config_table);
@@ -325,7 +353,24 @@ do
env.include = env.Include;
function env.RunScript(file)
- return dofile(resolve_relative_path(config_file:gsub("[^"..path_sep.."]+$", ""), file));
+ return dofile(resolve_relative_path(config_path, file));
+ end
+
+ env.FileContents = filereader(config_path, "*a");
+ env.FileLine = filereader(config_path, "*l");
+ env.FileLines = linereader(config_path);
+
+ if _G.prosody.paths.credentials then
+ env.Credential = filereader(_G.prosody.paths.credentials, "*a");
+ elseif _G.prosody.process_type == "prosody" then
+ env.Credential = function() error("Credential() requires the $CREDENTIALS_DIRECTORY environment variable to be set", 2) end
+ else
+ env.Credential = function()
+ t_insert(warnings, ("%s:%d: Credential() requires the $CREDENTIALS_DIRECTORY environment variable to be set")
+ :format(config_file, get_line_number(config_file)));
+ return nil;
+ end
+
end
local chunk, err = envload(data, "@"..config_file, env);
diff --git a/core/features.lua b/core/features.lua
index 75cfa1d7..cd6618db 100644
--- a/core/features.lua
+++ b/core/features.lua
@@ -8,6 +8,8 @@ return {
"mod_server_info";
-- mod_flags bundled
"mod_flags";
+ -- mod_cloud_notify bundled
+ "mod_cloud_notify";
-- Roles, module.may and per-session authz
"permissions";
-- prosody.* namespace
diff --git a/core/moduleapi.lua b/core/moduleapi.lua
index fa5086cf..b93536b5 100644
--- a/core/moduleapi.lua
+++ b/core/moduleapi.lua
@@ -431,8 +431,16 @@ function api:handle_items(item_type, added_cb, removed_cb, existing)
self:hook("item-added/"..item_type, added_cb);
self:hook("item-removed/"..item_type, removed_cb);
if existing ~= false then
- for _, item in ipairs(self:get_host_items(item_type)) do
- added_cb({ item = item });
+ local modulemanager = require"prosody.core.modulemanager";
+ local modules = modulemanager.get_modules(self.host);
+
+ for _, module in pairs(modules) do
+ local mod = module.module;
+ if mod.items and mod.items[item_type] then
+ for _, item in ipairs(mod.items[item_type]) do
+ added_cb({ source = mod; item = item });
+ end
+ end
end
end
end
diff --git a/core/modulemanager.lua b/core/modulemanager.lua
index 873e08e5..b8ba2f35 100644
--- a/core/modulemanager.lua
+++ b/core/modulemanager.lua
@@ -26,7 +26,7 @@ local xpcall = require "prosody.util.xpcall".xpcall;
local debug_traceback = debug.traceback;
local setmetatable, rawget = setmetatable, rawget;
local ipairs, pairs, type, t_insert = ipairs, pairs, type, table.insert;
-local lua_version = _VERSION:match("5%.%d$");
+local lua_version = _VERSION:match("5%.%d+$");
local autoload_modules = {
prosody.platform,
@@ -66,6 +66,20 @@ local loader = pluginloader.init({
end
end
+ if metadata.lua then
+ local supported = false;
+ for supported_lua_version in metadata.lua:gmatch("[^, ]+") do
+ if supported_lua_version == lua_version then
+ supported = true;
+ break;
+ end
+ end
+ if not supported then
+ log("warn", "Not loading module, we have Lua %s but the module requires one of (%s): %s", lua_version, metadata.lua, path);
+ return; -- Don't load this module
+ end
+ end
+
if metadata.conflicts then
local conflicts_features = set.new(array.collect(metadata.conflicts:gmatch("[^, ]+")));
local conflicted_features = set.intersection(conflicts_features, core_features);