From b4be1bcd052c817d983e05c92787b4f9c677555f Mon Sep 17 00:00:00 2001 From: damencho Date: Thu, 5 Dec 2019 10:09:58 +0000 Subject: [PATCH] Adds some checks about async. There are modules that will not work with prosody 0.10 as they depend on util.async. Adds a safeguard and print error about it in the logs. And others that just do not work because of the muc module API that they use. --- resources/prosody-plugins/mod_muc_poltergeist.lua | 7 +++++++ resources/prosody-plugins/mod_muc_size.lua | 7 +++++++ .../prosody-plugins/mod_speakerstats_component.lua | 9 ++++++++- resources/prosody-plugins/util.lib.lua | 10 ++++++++-- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/resources/prosody-plugins/mod_muc_poltergeist.lua b/resources/prosody-plugins/mod_muc_poltergeist.lua index e3956a329..fe03dc5bd 100644 --- a/resources/prosody-plugins/mod_muc_poltergeist.lua +++ b/resources/prosody-plugins/mod_muc_poltergeist.lua @@ -4,6 +4,13 @@ local jid = require "util.jid"; local neturl = require "net.url"; local parse = neturl.parseQuery; local poltergeist = module:require "poltergeist"; + +local have_async = pcall(require, "util.async"); +if not have_async then + module:log("error", "requires a version of Prosody with util.async"); + return; +end + local wrap_async_run = module:require "util".wrap_async_run; -- Options diff --git a/resources/prosody-plugins/mod_muc_size.lua b/resources/prosody-plugins/mod_muc_size.lua index fe1b34580..abe7269bc 100644 --- a/resources/prosody-plugins/mod_muc_size.lua +++ b/resources/prosody-plugins/mod_muc_size.lua @@ -7,6 +7,13 @@ local it = require "util.iterators"; local json = require "util.json"; local iterators = require "util.iterators"; local array = require"util.array"; + +local have_async = pcall(require, "util.async"); +if not have_async then + module:log("error", "requires a version of Prosody with util.async"); + return; +end + local wrap_async_run = module:require "util".wrap_async_run; local tostring = tostring; diff --git a/resources/prosody-plugins/mod_speakerstats_component.lua b/resources/prosody-plugins/mod_speakerstats_component.lua index 4cfae6132..f32500802 100644 --- a/resources/prosody-plugins/mod_speakerstats_component.lua +++ b/resources/prosody-plugins/mod_speakerstats_component.lua @@ -6,6 +6,13 @@ local st = require "util.stanza"; local socket = require "socket"; local json = require "util.json"; +-- we use async to detect Prosody 0.10 and earlier +local have_async = pcall(require, "util.async"); +if not have_async then + module:log("warn", "speaker stats will not work with Prosody version 0.10 or less."); + return; +end + local muc_component_host = module:get_option_string("muc_component"); if muc_component_host == nil then log("error", "No muc_component specified. No muc to operate on!"); @@ -204,4 +211,4 @@ if prosody.hosts[muc_component_host] == nil then prosody.events.add_handler("host-activated", process_host); else process_host(muc_component_host); -end \ No newline at end of file +end diff --git a/resources/prosody-plugins/util.lib.lua b/resources/prosody-plugins/util.lib.lua index 34d39a348..70e00a45a 100644 --- a/resources/prosody-plugins/util.lib.lua +++ b/resources/prosody-plugins/util.lib.lua @@ -1,6 +1,5 @@ local jid = require "util.jid"; -local runner, waiter = require "util.async".runner, require "util.async".waiter; - +local have_async, async = pcall(require, "util.async"); local muc_domain_prefix = module:get_option_string("muc_mapper_domain_prefix", "conference"); @@ -62,6 +61,13 @@ end function wrap_async_run(event,handler) + local have_async = pcall(require, "util.async"); + if not have_async then + module:log("error", "requires a version of Prosody with util.async"); + return nil; + end + + local runner = async.runner; -- Grab a local response so that we can send the http response when -- the handler is done. local response = event.response;