aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.luacheckrc8
-rw-r--r--core/sessionmanager.lua8
-rw-r--r--util/dataforms.lua4
-rw-r--r--util/queue.lua54
-rw-r--r--util/serialization.lua2
-rw-r--r--util/set.lua11
-rw-r--r--util/sslconfig.lua8
-rw-r--r--util/xml.lua2
8 files changed, 80 insertions, 17 deletions
diff --git a/.luacheckrc b/.luacheckrc
new file mode 100644
index 00000000..3f147806
--- /dev/null
+++ b/.luacheckrc
@@ -0,0 +1,8 @@
+cache = true
+read_globals = { "prosody", "hosts" }
+globals = { "_M" }
+allow_defined_top = true
+module = true
+unused_secondaries = false
+codes = true
+ignore = { "411/err", "421/err", "411/ok", "421/ok" }
diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua
index 5e4e2991..33cc3d21 100644
--- a/core/sessionmanager.lua
+++ b/core/sessionmanager.lua
@@ -198,7 +198,7 @@ function send_to_available_resources(username, host, stanza)
local count = 0;
local user = bare_sessions[jid];
if user then
- for k, session in pairs(user.sessions) do
+ for _, session in pairs(user.sessions) do
if session.presence then
session.send(stanza);
count = count + 1;
@@ -208,12 +208,12 @@ function send_to_available_resources(username, host, stanza)
return count;
end
-function send_to_interested_resources(user, host, stanza)
- local jid = user.."@"..host;
+function send_to_interested_resources(username, host, stanza)
+ local jid = username.."@"..host;
local count = 0;
local user = bare_sessions[jid];
if user then
- for k, session in pairs(user.sessions) do
+ for _, session in pairs(user.sessions) do
if session.interested then
session.send(stanza);
count = count + 1;
diff --git a/util/dataforms.lua b/util/dataforms.lua
index b2988ae7..9f2693b1 100644
--- a/util/dataforms.lua
+++ b/util/dataforms.lua
@@ -7,7 +7,7 @@
--
local setmetatable = setmetatable;
-local pairs, ipairs = pairs, ipairs;
+local ipairs = ipairs;
local tostring, type, next = tostring, type, next;
local t_concat = table.concat;
local st = require "util.stanza";
@@ -32,7 +32,7 @@ function form_t.form(layout, data, formtype)
if layout.instructions then
form:tag("instructions"):text(layout.instructions):up();
end
- for n, field in ipairs(layout) do
+ for _, field in ipairs(layout) do
local field_type = field.type or "text-single";
-- Add field tag
form:tag("field", { type = field_type, var = field.name, label = field.label });
diff --git a/util/queue.lua b/util/queue.lua
new file mode 100644
index 00000000..afdcaf45
--- /dev/null
+++ b/util/queue.lua
@@ -0,0 +1,54 @@
+-- Prosody IM
+-- Copyright (C) 2008-2015 Matthew Wild
+-- Copyright (C) 2008-2015 Waqas Hussain
+--
+-- This project is MIT/X11 licensed. Please see the
+-- COPYING file in the source package for more information.
+--
+
+-- Small ringbuffer library (i.e. an efficient FIFO queue with a size limit)
+-- (because unbounded dynamically-growing queues are a bad thing...)
+
+local have_utable, utable = pcall(require, "util.table"); -- For pre-allocation of table
+
+local function new(size)
+ -- Head is next insert, tail is next read
+ local head, tail = 1, 1;
+ local items = 0; -- Number of stored items
+ local t = have_utable and utable.create(size, 0) or {}; -- Table to hold items
+
+ return {
+ size = size;
+ count = function (self) return items; end;
+ push = function (self, item)
+ if items >= size then
+ return nil, "queue full";
+ end
+ t[head] = item;
+ items = items + 1;
+ head = (head%size)+1;
+ return true;
+ end;
+ pop = function (self)
+ if items == 0 then
+ return nil;
+ end
+ local item;
+ item, t[tail] = t[tail], 0;
+ tail = (tail%size)+1;
+ items = items - 1;
+ return item;
+ end;
+ peek = function (self)
+ if items == 0 then
+ return nil;
+ end
+ return t[tail];
+ end;
+ };
+end
+
+return {
+ new = new;
+};
+
diff --git a/util/serialization.lua b/util/serialization.lua
index 06e45054..04901135 100644
--- a/util/serialization.lua
+++ b/util/serialization.lua
@@ -11,11 +11,9 @@ local type = type;
local tostring = tostring;
local t_insert = table.insert;
local t_concat = table.concat;
-local error = error;
local pairs = pairs;
local next = next;
-local loadstring = loadstring;
local pcall = pcall;
local debug_traceback = debug.traceback;
diff --git a/util/set.lua b/util/set.lua
index 04f5f0f4..4be39c17 100644
--- a/util/set.lua
+++ b/util/set.lua
@@ -34,7 +34,7 @@ function set_mt.__div(set, func)
return new_set;
end
function set_mt.__eq(set1, set2)
- local set1, set2 = set1._items, set2._items;
+ set1, set2 = set1._items, set2._items;
for item in pairs(set1) do
if not set2[item] then
return false;
@@ -66,6 +66,9 @@ function new(list)
local items = setmetatable({}, items_mt);
local set = { _items = items };
+ -- We access the set through an upvalue in these methods, so ignore 'self' being unused
+ --luacheck: ignore 212/self
+
function set:add(item)
items[item] = true;
end
@@ -82,9 +85,9 @@ function new(list)
items[item] = nil;
end
- function set:add_list(list)
- if list then
- for _, item in ipairs(list) do
+ function set:add_list(item_list)
+ if item_list then
+ for _, item in ipairs(item_list) do
items[item] = true;
end
end
diff --git a/util/sslconfig.lua b/util/sslconfig.lua
index 98e61341..42ce37d7 100644
--- a/util/sslconfig.lua
+++ b/util/sslconfig.lua
@@ -6,11 +6,11 @@ local id = function (v) return v end
function handlers.options(a, k, b)
local o = a[k] or { };
if type(b) ~= "table" then b = { b } end
- for k,v in pairs(b) do
- if v == true or v == false then
- o[k] = v;
+ for key, value in pairs(b) do
+ if value == true or value == false then
+ o[key] = value;
else
- o[v] = true;
+ o[value] = true;
end
end
a[k] = o;
diff --git a/util/xml.lua b/util/xml.lua
index 3c1d3e51..88ccedde 100644
--- a/util/xml.lua
+++ b/util/xml.lua
@@ -39,7 +39,7 @@ local parse_xml = (function()
function handler:CharacterData(data)
stanza:text(data);
end
- function handler:EndElement(tagname)
+ function handler:EndElement()
stanza:up();
end
local parser = lxp.new(handler, "\1");