# HG changeset patch # User Matthew Wild # Date 1430936813 -3600 # Node ID 42fdc8dddf040d50b589fbcdc33c52b25f92eb96 # Parent cf15b18e981078452c7b51003a7fb73a4059c747# Parent e923d7cb843016acfa24b6c98bcc06b5f61a4196 Merge 0.10->trunk diff -r cf15b18e9810 -r 42fdc8dddf04 core/moduleapi.lua --- a/core/moduleapi.lua Tue May 05 01:34:20 2015 +0200 +++ b/core/moduleapi.lua Wed May 06 19:26:53 2015 +0100 @@ -10,11 +10,13 @@ local modulemanager; -- This gets set from modulemanager local array = require "util.array"; local set = require "util.set"; +local it = require "util.iterators"; local logger = require "util.logger"; local pluginloader = require "util.pluginloader"; local timer = require "util.timer"; local resolve_relative_path = require"util.paths".resolve_relative_path; local measure = require "core.statsmanager".measure; +local st = require "util.stanza"; local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat; local error, setmetatable, type = error, setmetatable, type; @@ -56,7 +58,7 @@ self.host = "*"; -- Update the logger local _log = logger.init("mod_"..self.name); - self.log = function (self, ...) return _log(...); end; + self.log = function (self, ...) return _log(...); end; --luacheck: ignore self self._log = _log; self.global = true; end @@ -64,8 +66,8 @@ function api:add_feature(xmlns) self:add_item("feature", xmlns); end -function api:add_identity(category, type, name) - self:add_item("identity", {category = category, type = type, name = name}); +function api:add_identity(category, identity_type, name) + self:add_item("identity", {category = category, type = identity_type, name = name}); end function api:add_extension(data) self:add_item("extension", data); @@ -76,9 +78,9 @@ end return false; end -function api:has_identity(category, type, name) +function api:has_identity(category, identity_type, name) for _, id in ipairs(self:get_host_items("identity")) do - if id.category == category and id.type == type and id.name == name then + if id.category == category and id.type == identity_type and id.name == name then return true; end end @@ -95,6 +97,7 @@ end function api:unhook_object_event(object, event, handler) + self.event_handlers:set(object, event, handler, nil); return object.remove_handler(event, handler); end @@ -131,7 +134,7 @@ end function api:wrap_global(event, handler) - return self:hook_object_event(prosody.events, event, handler, priority); + return self:hook_object_event(prosody.events, event, handler); end function api:require(lib) @@ -329,11 +332,11 @@ return result; end -function api:handle_items(type, added_cb, removed_cb, existing) - self:hook("item-added/"..type, added_cb); - self:hook("item-removed/"..type, removed_cb); +function api:handle_items(item_type, added_cb, removed_cb, existing) + self:hook("item-added/"..item_type, added_cb); + self:hook("item-removed/"..item_type, removed_cb); if existing ~= false then - for _, item in ipairs(self:get_host_items(type)) do + for _, item in ipairs(self:get_host_items(item_type)) do added_cb({ item = item }); end end @@ -364,6 +367,14 @@ return core_post_stanza(hosts[self.host], stanza); end +function api:broadcast(jids, stanza, iter) + for jid in (iter or it.values)(jids) do + local new_stanza = st.clone(stanza); + new_stanza.attr.to = jid; + core_post_stanza(hosts[self.host], new_stanza); + end +end + local timer_methods = { } local timer_mt = { __index = timer_methods; @@ -399,19 +410,19 @@ return io.open(path, mode); end -function api:open_store(name, type) - return require"core.storagemanager".open(self.host, name or self.name, type); +function api:open_store(name, store_type) + return require"core.storagemanager".open(self.host, name or self.name, store_type); end -function api:measure(name, type) - return measure(type, "/"..self.host.."/mod_"..self.name.."/"..name); +function api:measure(name, stat_type) + return measure(stat_type, "/"..self.host.."/mod_"..self.name.."/"..name); end function api:measure_object_event(events_object, event_name, stat_name) local m = self:measure(stat_name or event_name, "duration"); - local function handler(handlers, event_name, event_data) + local function handler(handlers, _event_name, _event_data) local finished = m(); - local ret = handlers(event_name, event_data); + local ret = handlers(_event_name, _event_data); finished(); return ret; end @@ -419,11 +430,11 @@ end function api:measure_event(event_name, stat_name) - return self:hook_object_event((hosts[self.host] or prosody).events.wrappers, event_name, handler); + return self:measure_object_event((hosts[self.host] or prosody).events.wrappers, event_name, stat_name); end function api:measure_global_event(event_name, stat_name) - return self:hook_object_event(prosody.events.wrappers, event_name, handler); + return self:measure_object_event(prosody.events.wrappers, event_name, stat_name); end function api.init(mm) diff -r cf15b18e9810 -r 42fdc8dddf04 core/modulemanager.lua --- a/core/modulemanager.lua Tue May 05 01:34:20 2015 +0200 +++ b/core/modulemanager.lua Wed May 06 19:26:53 2015 +0100 @@ -17,13 +17,13 @@ local hosts = hosts; local prosody = prosody; -local pcall, xpcall = pcall, xpcall; +local xpcall = xpcall; local setmetatable, rawget = setmetatable, rawget; local ipairs, pairs, type, tostring, t_insert = ipairs, pairs, type, tostring, table.insert; local debug_traceback = debug.traceback; local unpack, select = unpack, select; -pcall = function(f, ...) +local pcall = function(f, ...) local n = select("#", ...); local params = {...}; return xpcall(function() return f(unpack(params, 1, n)) end, function(e) return tostring(e).."\n"..debug_traceback(); end); @@ -131,7 +131,7 @@ local _log = logger.init(host..":"..module_name); local host_module_api = setmetatable({ host = host, event_handlers = new_multitable(), items = {}; - _log = _log, log = function (self, ...) return _log(...); end; + _log = _log, log = function (self, ...) return _log(...); end; --luacheck: ignore 212/self },{ __index = modulemap["*"][module_name].module; }); @@ -152,8 +152,9 @@ local _log = logger.init(host..":"..module_name); local api_instance = setmetatable({ name = module_name, host = host, - _log = _log, log = function (self, ...) return _log(...); end, event_handlers = new_multitable(), - reloading = not not state, saved_state = state~=true and state or nil } + _log = _log, log = function (self, ...) return _log(...); end, --luacheck: ignore 212/self + event_handlers = new_multitable(), reloading = not not state, + saved_state = state~=true and state or nil } , { __index = api }); local pluginenv = setmetatable({ module = api_instance }, { __index = _G }); diff -r cf15b18e9810 -r 42fdc8dddf04 core/portmanager.lua --- a/core/portmanager.lua Tue May 05 01:34:20 2015 +0200 +++ b/core/portmanager.lua Wed May 06 19:26:53 2015 +0100 @@ -41,7 +41,7 @@ --- Private helpers -local function error_to_friendly_message(service_name, port, err) +local function error_to_friendly_message(service_name, port, err) --luacheck: ignore 212/service_name local friendly_message = err; if err:match(" in use") then -- FIXME: Use service_name here diff -r cf15b18e9810 -r 42fdc8dddf04 core/rostermanager.lua --- a/core/rostermanager.lua Tue May 05 01:34:20 2015 +0200 +++ b/core/rostermanager.lua Wed May 06 19:26:53 2015 +0100 @@ -213,10 +213,10 @@ function is_contact_subscribed(username, host, jid) do local selfjid = username.."@"..host; - local subscription = _get_online_roster_subscription(selfjid, jid); - if subscription then return (subscription == "both" or subscription == "from"); end - local subscription = _get_online_roster_subscription(jid, selfjid); - if subscription then return (subscription == "both" or subscription == "to"); end + local user_subscription = _get_online_roster_subscription(selfjid, jid); + if user_subscription then return (user_subscription == "both" or user_subscription == "from"); end + local contact_subscription = _get_online_roster_subscription(jid, selfjid); + if contact_subscription then return (contact_subscription == "both" or contact_subscription == "to"); end end local roster, err = load_roster(username, host); local item = roster[jid]; diff -r cf15b18e9810 -r 42fdc8dddf04 core/s2smanager.lua --- a/core/s2smanager.lua Tue May 05 01:34:20 2015 +0200 +++ b/core/s2smanager.lua Wed May 06 19:26:53 2015 +0100 @@ -49,11 +49,11 @@ close = function (session) session.log("debug", "Attempt to close already-closed session"); end; - filter = function (type, data) return data; end; + filter = function (type, data) return data; end; --luacheck: ignore 212/type }; resting_session.__index = resting_session; function retire_session(session, reason) - local log = session.log or log; + local log = session.log or log; --luacheck: ignore 431/log for k in pairs(session) do if k ~= "log" and k ~= "id" and k ~= "conn" then session[k] = nil; diff -r cf15b18e9810 -r 42fdc8dddf04 core/sessionmanager.lua --- a/core/sessionmanager.lua Tue May 05 01:34:20 2015 +0200 +++ b/core/sessionmanager.lua Wed May 06 19:26:53 2015 +0100 @@ -54,11 +54,11 @@ close = function (session) session.log("debug", "Attempt to close already-closed session"); end; - filter = function (type, data) return data; end; + filter = function (type, data) return data; end; --luacheck: ignore 212/type }; resting_session.__index = resting_session; function retire_session(session) - local log = session.log or log; + local log = session.log or log; --luacheck: ignore 431/log for k in pairs(session) do if k ~= "log" and k ~= "id" then session[k] = nil; diff -r cf15b18e9810 -r 42fdc8dddf04 core/stanza_router.lua --- a/core/stanza_router.lua Tue May 05 01:34:20 2015 +0200 +++ b/core/stanza_router.lua Wed May 06 19:26:53 2015 +0100 @@ -30,7 +30,7 @@ deprecated_warning"core_route_stanza"; local valid_stanzas = { message = true, presence = true, iq = true }; -local function handle_unhandled_stanza(host, origin, stanza) +local function handle_unhandled_stanza(host, origin, stanza) --luacheck: ignore 212/host local name, xmlns, origin_type = stanza.name, stanza.attr.xmlns or "jabber:client", origin.type; if xmlns == "jabber:client" and valid_stanzas[name] then -- A normal stanza @@ -221,6 +221,8 @@ end end end + +--luacheck: ignore 122/prosody prosody.core_process_stanza = core_process_stanza; prosody.core_post_stanza = core_post_stanza; prosody.core_route_stanza = core_route_stanza; diff -r cf15b18e9810 -r 42fdc8dddf04 core/storagemanager.lua --- a/core/storagemanager.lua Tue May 05 01:34:20 2015 +0200 +++ b/core/storagemanager.lua Wed May 06 19:26:53 2015 +0100 @@ -23,7 +23,7 @@ name = "null", open = function (self) return self; end }, { - __index = function (self, method) + __index = function (self, method) --luacheck: ignore 212 return null_storage_method; end } diff -r cf15b18e9810 -r 42fdc8dddf04 core/usermanager.lua --- a/core/usermanager.lua Tue May 05 01:34:20 2015 +0200 +++ b/core/usermanager.lua Wed May 06 19:26:53 2015 +0100 @@ -29,7 +29,7 @@ local function dummy() return nil, "method not implemented"; end; local function dummy_get_sasl_handler() return sasl_new(nil, {}); end return setmetatable({name = "null", get_sasl_handler = dummy_get_sasl_handler}, { - __index = function(self, method) return dummy; end + __index = function(self, method) return dummy; end --luacheck: ignore 212 }); end diff -r cf15b18e9810 -r 42fdc8dddf04 plugins/mod_pubsub/mod_pubsub.lua --- a/plugins/mod_pubsub/mod_pubsub.lua Tue May 05 01:34:20 2015 +0200 +++ b/plugins/mod_pubsub/mod_pubsub.lua Wed May 06 19:26:53 2015 +0100 @@ -125,11 +125,15 @@ end); local admin_aff = module:get_option_string("default_admin_affiliation", "owner"); -local function get_affiliation(jid) +local unowned_aff = module:get_option_string("default_unowned_affiliation"); +local function get_affiliation(jid, node) local bare_jid = jid_bare(jid); if bare_jid == module.host or usermanager.is_admin(bare_jid, module.host) then return admin_aff; end + if not node then + return unowned_aff; + end end function set_service(new_service) diff -r cf15b18e9810 -r 42fdc8dddf04 plugins/mod_s2s/mod_s2s.lua --- a/plugins/mod_s2s/mod_s2s.lua Tue May 05 01:34:20 2015 +0200 +++ b/plugins/mod_s2s/mod_s2s.lua Wed May 06 19:26:53 2015 +0100 @@ -628,8 +628,9 @@ function listener.onreadtimeout(conn) local session = sessions[conn]; + local host = session.host or session.to_host; if session then - return (hosts[session.host] or prosody).events.fire_event("s2s-read-timeout", { session = session }); + return (hosts[host] or prosody).events.fire_event("s2s-read-timeout", { session = session }); end end diff -r cf15b18e9810 -r 42fdc8dddf04 util/events.lua --- a/util/events.lua Tue May 05 01:34:20 2015 +0200 +++ b/util/events.lua Wed May 06 19:26:53 2015 +0100 @@ -53,6 +53,9 @@ end end end; + local function get_handlers(event) + return handlers[event]; + end; local function add_handlers(handlers) for event, handler in pairs(handlers) do add_handler(event, handler); @@ -135,6 +138,7 @@ remove_handler = remove_handler; add_handlers = add_handlers; remove_handlers = remove_handlers; + get_handlers = get_handlers; wrappers = { add_handler = add_wrapper; remove_handler = remove_wrapper; diff -r cf15b18e9810 -r 42fdc8dddf04 util/xml.lua --- a/util/xml.lua Tue May 05 01:34:20 2015 +0200 +++ b/util/xml.lua Wed May 06 19:26:53 2015 +0100 @@ -11,6 +11,7 @@ local ns_separator = "\1"; local ns_pattern = "^([^"..ns_separator.."]*)"..ns_separator.."?(.*)$"; return function(xml) + --luacheck: ignore 212/self local handler = {}; local stanza = st.stanza("root"); function handler:StartElement(tagname, attr)