aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/dataforms.lua10
-rw-r--r--util/datamanager.lua18
-rw-r--r--util/logger.lua2
-rw-r--r--util/sasl.lua2
-rw-r--r--util/sasl_cyrus.lua8
-rw-r--r--util/stanza.lua4
-rw-r--r--util/throttle.lua3
7 files changed, 25 insertions, 22 deletions
diff --git a/util/dataforms.lua b/util/dataforms.lua
index 8cb39144..55bad998 100644
--- a/util/dataforms.lua
+++ b/util/dataforms.lua
@@ -185,7 +185,7 @@ field_readers["list-multi"] =
function (field_tag, required)
local result = {};
for value in field_tag:childtags("value") do
- result[#result+1] = value;
+ result[#result+1] = value:get_text();
end
return result, (required and #result == 0 and "Required value missing" or nil);
end
@@ -202,10 +202,10 @@ field_readers["text-multi"] =
field_readers["list-single"] =
field_readers["text-single"];
- local boolean_values = {
- ["1"] = true, ["true"] = true,
- ["0"] = false, ["false"] = false,
- };
+local boolean_values = {
+ ["1"] = true, ["true"] = true,
+ ["0"] = false, ["false"] = false,
+};
field_readers["boolean"] =
function (field_tag, required)
diff --git a/util/datamanager.lua b/util/datamanager.lua
index 884d1161..344d2eb1 100644
--- a/util/datamanager.lua
+++ b/util/datamanager.lua
@@ -116,18 +116,18 @@ function load(username, host, datastore)
if not data then
local mode = lfs.attributes(getpath(username, host, datastore), "mode");
if not mode then
- log("debug", "Assuming empty "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil"));
+ log("debug", "Assuming empty %s storage ('%s') for user: %s@%s", datastore, ret, username or "nil", host or "nil");
return nil;
else -- file exists, but can't be read
-- TODO more detailed error checking and logging?
- log("error", "Failed to load "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil"));
+ log("error", "Failed to load %s storage ('%s') for user: %s@%s", datastore, ret, username or "nil", host or "nil");
return nil, "Error reading storage";
end
end
local success, ret = pcall(data);
if not success then
- log("error", "Unable to load "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil"));
+ log("error", "Unable to load %s storage ('%s') for user: %s@%s", datastore, ret, username or "nil", host or "nil");
return nil, "Error reading storage";
end
return ret;
@@ -146,7 +146,7 @@ function store(username, host, datastore, data)
-- save the datastore
local f, msg = io_open(getpath(username, host, datastore, nil, true), "w+");
if not f then
- log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..(username or "nil").."@"..(host or "nil"));
+ log("error", "Unable to write to %s storage ('%s') for user: %s@%s", datastore, msg, username or "nil", host or "nil");
return nil, "Error saving to storage";
end
f:write("return ");
@@ -167,7 +167,7 @@ function list_append(username, host, datastore, data)
-- save the datastore
local f, msg = io_open(getpath(username, host, datastore, "list", true), "a+");
if not f then
- log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..(username or "nil").."@"..(host or "nil"));
+ log("error", "Unable to write to %s storage ('%s') for user: %s@%s", datastore, msg, username or "nil", host or "nil");
return;
end
f:write("item(");
@@ -185,7 +185,7 @@ function list_store(username, host, datastore, data)
-- save the datastore
local f, msg = io_open(getpath(username, host, datastore, "list", true), "w+");
if not f then
- log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..(username or "nil").."@"..(host or "nil"));
+ log("error", "Unable to write to %s storage ('%s') for user: %s@%s", datastore, msg, username or "nil", host or "nil");
return;
end
for _, d in ipairs(data) do
@@ -209,18 +209,18 @@ function list_load(username, host, datastore)
if not data then
local mode = lfs.attributes(getpath(username, host, datastore, "list"), "mode");
if not mode then
- log("debug", "Assuming empty "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil"));
+ log("debug", "Assuming empty %s storage ('%s') for user: %s@%s", datastore, ret, username or "nil", host or "nil");
return nil;
else -- file exists, but can't be read
-- TODO more detailed error checking and logging?
- log("error", "Failed to load "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil"));
+ log("error", "Failed to load %s storage ('%s') for user: %s@%s", datastore, ret, username or "nil", host or "nil");
return nil, "Error reading storage";
end
end
local success, ret = pcall(data);
if not success then
- log("error", "Unable to load "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil"));
+ log("error", "Unable to load %s storage ('%s') for user: %s@%s", datastore, ret, username or "nil", host or "nil");
return nil, "Error reading storage";
end
return items;
diff --git a/util/logger.lua b/util/logger.lua
index 4fadb4b9..26206d4d 100644
--- a/util/logger.lua
+++ b/util/logger.lua
@@ -23,8 +23,6 @@ function init(name)
local log_warn = make_logger(name, "warn");
local log_error = make_logger(name, "error");
- --name = nil; -- While this line is not commented, will automatically fill in file/line number info
- local namelen = #name;
return function (level, message, ...)
if level == "debug" then
return log_debug(message, ...);
diff --git a/util/sasl.lua b/util/sasl.lua
index 17d10b80..afb3861b 100644
--- a/util/sasl.lua
+++ b/util/sasl.lua
@@ -35,7 +35,7 @@ local mechanisms = {};
local backend_mechanism = {};
-- register a new SASL mechanims
-local function registerMechanism(name, backends, f)
+function registerMechanism(name, backends, f)
assert(type(name) == "string", "Parameter name MUST be a string.");
assert(type(backends) == "string" or type(backends) == "table", "Parameter backends MUST be either a string or a table.");
assert(type(f) == "function", "Parameter f MUST be a function.");
diff --git a/util/sasl_cyrus.lua b/util/sasl_cyrus.lua
index 002118fd..19684587 100644
--- a/util/sasl_cyrus.lua
+++ b/util/sasl_cyrus.lua
@@ -78,11 +78,15 @@ local function init(service_name)
end
-- create a new SASL object which can be used to authenticate clients
-function new(realm, service_name, app_name)
+-- host_fqdn may be nil in which case gethostname() gives the value.
+-- For GSSAPI, this determines the hostname in the service ticket (after
+-- reverse DNS canonicalization, only if [libdefaults] rdns = true which
+-- is the default).
+function new(realm, service_name, app_name, host_fqdn)
init(app_name or service_name);
- local st, ret = pcall(cyrussasl.server_new, service_name, nil, realm, nil, nil)
+ local st, ret = pcall(cyrussasl.server_new, service_name, host_fqdn, realm, nil, nil)
if not st then
log("error", "Creating SASL server connection failed: %s", ret);
return nil;
diff --git a/util/stanza.lua b/util/stanza.lua
index 1449f707..5c430f1d 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -133,14 +133,14 @@ function stanza_mt:children()
end
function stanza_mt:childtags(name, xmlns)
- xmlns = xmlns or self.attr.xmlns;
local tags = self.tags;
local start_i, max_i = 1, #tags;
return function ()
for i = start_i, max_i do
local v = tags[i];
if (not name or v.name == name)
- and (not xmlns or xmlns == v.attr.xmlns) then
+ and ((not xmlns and self.attr.xmlns == v.attr.xmlns)
+ or v.attr.xmlns == xmlns) then
start_i = i+1;
return v;
end
diff --git a/util/throttle.lua b/util/throttle.lua
index 2e901158..55e1d07b 100644
--- a/util/throttle.lua
+++ b/util/throttle.lua
@@ -1,6 +1,7 @@
local gettime = require "socket".gettime;
local setmetatable = setmetatable;
+local floor = math.floor;
module "throttle"
@@ -11,7 +12,7 @@ function throttle:update()
local newt = gettime();
local elapsed = newt - self.t;
self.t = newt;
- local balance = self.rate * elapsed + self.balance;
+ local balance = floor(self.rate * elapsed) + self.balance;
if balance > self.max then
self.balance = self.max;
else