mod_s2s: Don't try to close sessions that were destroyed before timeout
[prosody.git] / core / configmanager.lua
index b703bb8c6b92d8540ed20b32894db5638b0a9fe3..51b9f5fe8e6b54a479dbb0eb75fbab4001157859 100644 (file)
@@ -13,6 +13,7 @@ local format, math_max = string.format, math.max;
 
 local fire_event = prosody and prosody.events.fire_event or function () end;
 
+local envload = require"util.envload".envload;
 local lfs = require "lfs";
 local path_sep = package.config:sub(1,1);
 
@@ -41,12 +42,24 @@ function getconfig()
 end
 
 function get(host, section, key)
+       if not key then
+               section, key = "core", section;
+       end
        local sec = config[host][section];
        if sec then
                return sec[key];
        end
        return nil;
 end
+function _M.rawget(host, section, key)
+       local hostconfig = rawget(config, host);
+       if hostconfig then
+               local sectionconfig = rawget(hostconfig, section);
+               if sectionconfig then
+                       return rawget(sectionconfig, key);
+               end
+       end
+end
 
 local function set(config, host, section, key, value)
        if host and section and key then
@@ -79,7 +92,7 @@ do
                        local is_relative;
                        if path_sep == "/" and path:sub(1,1) ~= "/" then
                                is_relative = true;
-                       elseif path_sep == "\\" and (path:sub(1,1) ~= "/" and path:sub(2,3) ~= ":\\") then
+                       elseif path_sep == "\\" and (path:sub(1,1) ~= "/" and (path:sub(2,3) ~= ":\\" or path:sub(2,3) ~= ":/")) then
                                is_relative = true;
                        end
                        if is_relative then
@@ -152,8 +165,8 @@ end
 
 -- Built-in Lua parser
 do
-       local loadstring, pcall, setmetatable = _G.loadstring, _G.pcall, _G.setmetatable;
-       local setfenv, rawget, tostring = _G.setfenv, _G.rawget, _G.tostring;
+       local pcall, setmetatable = _G.pcall, _G.setmetatable;
+       local rawget, tostring = _G.rawget, _G.tostring;
        parsers.lua = {};
        function parsers.lua.load(data, config_file, config)
                local env;
@@ -234,11 +247,10 @@ do
                                        end
                                end
                        else
+                               local file = resolve_relative_path(config_file:gsub("[^"..path_sep.."]+$", ""), file);
                                local f, err = io.open(file);
                                if f then
-                                       local data = f:read("*a");
-                                       local file = resolve_relative_path(config_file:gsub("[^"..path_sep.."]+$", ""), file);
-                                       local ret, err = parsers.lua.load(data, file, config);
+                                       local ret, err = parsers.lua.load(f:read("*a"), file, config);
                                        if not ret then error(err:gsub("%[string.-%]", file), 0); end
                                end
                                if not f then error("Error loading included "..file..": "..err, 0); end
@@ -251,14 +263,12 @@ do
                        return dofile(resolve_relative_path(config_file:gsub("[^"..path_sep.."]+$", ""), file));
                end
                
-               local chunk, err = loadstring(data, "@"..config_file);
+               local chunk, err = envload(data, "@"..config_file, env);
                
                if not chunk then
                        return nil, err;
                end
                
-               setfenv(chunk, env);
-               
                local ok, err = pcall(chunk);
                
                if not ok then