# HG changeset patch # User Matthew Wild # Date 1431532827 -3600 # Node ID 96e034508978700f0ddea6c9dcc534240ced809f # Parent 42fdc8dddf040d50b589fbcdc33c52b25f92eb96# Parent 343ca80ceb36e76d25367cf86a4491ba47ca9291 Merge 0.10->trunk diff -r 42fdc8dddf04 -r 96e034508978 .luacheckrc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.luacheckrc Wed May 13 17:00:27 2015 +0100 @@ -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 -r 42fdc8dddf04 -r 96e034508978 core/sessionmanager.lua --- a/core/sessionmanager.lua Wed May 06 19:26:53 2015 +0100 +++ b/core/sessionmanager.lua Wed May 13 17:00:27 2015 +0100 @@ -198,7 +198,7 @@ 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 @@ 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 -r 42fdc8dddf04 -r 96e034508978 util/dataforms.lua --- a/util/dataforms.lua Wed May 06 19:26:53 2015 +0100 +++ b/util/dataforms.lua Wed May 13 17:00:27 2015 +0100 @@ -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 @@ 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 -r 42fdc8dddf04 -r 96e034508978 util/queue.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/util/queue.lua Wed May 13 17:00:27 2015 +0100 @@ -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 -r 42fdc8dddf04 -r 96e034508978 util/serialization.lua --- a/util/serialization.lua Wed May 06 19:26:53 2015 +0100 +++ b/util/serialization.lua Wed May 13 17:00:27 2015 +0100 @@ -11,11 +11,9 @@ 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 -r 42fdc8dddf04 -r 96e034508978 util/set.lua --- a/util/set.lua Wed May 06 19:26:53 2015 +0100 +++ b/util/set.lua Wed May 13 17:00:27 2015 +0100 @@ -34,7 +34,7 @@ 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 @@ 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 @@ 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 -r 42fdc8dddf04 -r 96e034508978 util/sslconfig.lua --- a/util/sslconfig.lua Wed May 06 19:26:53 2015 +0100 +++ b/util/sslconfig.lua Wed May 13 17:00:27 2015 +0100 @@ -6,11 +6,11 @@ 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 -r 42fdc8dddf04 -r 96e034508978 util/xml.lua --- a/util/xml.lua Wed May 06 19:26:53 2015 +0100 +++ b/util/xml.lua Wed May 13 17:00:27 2015 +0100 @@ -39,7 +39,7 @@ function handler:CharacterData(data) stanza:text(data); end - function handler:EndElement(tagname) + function handler:EndElement() stanza:up(); end local parser = lxp.new(handler, "\1");