From 5f6cc5eaeaae252477858c83944ec97cf2223cfa Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 19:35:35 +0100 Subject: .luacheckrc: Commit initial config for luacheck --- .luacheckrc | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .luacheckrc 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" } -- cgit v1.2.3 From 526f5c061e65d09242799f2606c4c2e2db1d8216 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 19:38:29 +0100 Subject: util.dataforms: Remove unused import of pairs() (thanks luacheck) --- util/dataforms.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/dataforms.lua b/util/dataforms.lua index b2988ae7..5f246ee8 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"; -- cgit v1.2.3 From b731594e1332d03da90c30593f338345197dbad4 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 19:39:28 +0100 Subject: util.xml: Remove unused parameter (thanks, luacheck) --- util/xml.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"); -- cgit v1.2.3 From 72be71031ac21fa60622b34cb3219fbaefcfdd99 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 19:40:48 +0100 Subject: util.serialization: Remove unused imports of error() and loadstring() [luacheck] --- util/serialization.lua | 2 -- 1 file changed, 2 deletions(-) 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; -- cgit v1.2.3 From 6f2f3dde36a37f8c8890ad4a9b9adc1c98b6469e Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 19:43:28 +0100 Subject: util.sslconfig: Rename variable to avoid name clash [luacheck] --- util/sslconfig.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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; -- cgit v1.2.3 From 31bbce98bde53e453c551e99f3f1e368faa44ec1 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 19:43:51 +0100 Subject: util.dataforms: Rename unused loop counter to '_' [luacheck] --- util/dataforms.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/dataforms.lua b/util/dataforms.lua index 5f246ee8..9f2693b1 100644 --- a/util/dataforms.lua +++ b/util/dataforms.lua @@ -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 }); -- cgit v1.2.3 From 13a0eeca1affbd261616ea2ef8d360d71c3e537d Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 19:50:40 +0100 Subject: util.set: Remove unnecessary local declaration, arguments are already locals [luacheck] --- util/set.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/set.lua b/util/set.lua index 04f5f0f4..c160d28e 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; -- cgit v1.2.3 From d16104ebd4ea1a5e313367064c6731efb6feed21 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 19:51:07 +0100 Subject: util.set: Add luacheck annotation for methods not referencing 'self' --- util/set.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/util/set.lua b/util/set.lua index c160d28e..0a263440 100644 --- a/util/set.lua +++ b/util/set.lua @@ -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 -- cgit v1.2.3 From de51b150af7229ca6d30cdaa89e5201cfce59715 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 19:51:35 +0100 Subject: util.set: Rename method argument to avoid name clash [luacheck] --- util/set.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/set.lua b/util/set.lua index 0a263440..4be39c17 100644 --- a/util/set.lua +++ b/util/set.lua @@ -85,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 -- cgit v1.2.3 From 4d3004e3fc11a53b3668aac09a19e12fc8d19246 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 19:58:03 +0100 Subject: sessionmanager: Rename unused loop variables to '_' [luacheck] --- core/sessionmanager.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 5e4e2991..9ff42aed 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; @@ -213,7 +213,7 @@ function send_to_interested_resources(user, 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.interested then session.send(stanza); count = count + 1; -- cgit v1.2.3 From 1403b88f129f4d3892c3f4522a3e05a37d75d72e Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 19:58:33 +0100 Subject: sessionmanager: Rename argument to avoid name clash with local variable [luacheck] --- core/sessionmanager.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 9ff42aed..33cc3d21 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -208,8 +208,8 @@ 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 -- cgit v1.2.3 From 9bd85eabf029220d25431ab17bc86bf308b51b8d Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 13 May 2015 16:57:27 +0100 Subject: util.queue: Small fast FIFO/ringbuffer/queue library --- util/queue.lua | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 util/queue.lua 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; +}; + -- cgit v1.2.3