diff options
Diffstat (limited to 'plugins/mod_mam')
-rw-r--r-- | plugins/mod_mam/fallback_archive.lib.lua | 91 | ||||
-rw-r--r-- | plugins/mod_mam/mamprefsxml.lib.lua | 14 | ||||
-rw-r--r-- | plugins/mod_mam/mod_mam.lua | 14 |
3 files changed, 13 insertions, 106 deletions
diff --git a/plugins/mod_mam/fallback_archive.lib.lua b/plugins/mod_mam/fallback_archive.lib.lua deleted file mode 100644 index 71e65274..00000000 --- a/plugins/mod_mam/fallback_archive.lib.lua +++ /dev/null @@ -1,91 +0,0 @@ --- Prosody IM --- Copyright (C) 2008-2017 Matthew Wild --- Copyright (C) 2008-2017 Waqas Hussain --- Copyright (C) 2011-2017 Kim Alvefur --- --- This project is MIT/X11 licensed. Please see the --- COPYING file in the source package for more information. --- --- luacheck: ignore 212/self - -local uuid = require "util.uuid".generate; -local store = module:shared("archive"); -local archive_store = { _provided_by = "mam"; name = "fallback"; }; - -function archive_store:append(username, key, value, when, with) - local archive = store[username]; - if not archive then - archive = { [0] = 0 }; - store[username] = archive; - end - local index = (archive[0] or #archive)+1; - local item = { key = key, when = when, with = with, value = value }; - if not key or archive[key] then - key = uuid(); - item.key = key; - end - archive[index] = item; - archive[key] = index; - archive[0] = index; - return key; -end - -function archive_store:find(username, query) - local archive = store[username] or {}; - local start, stop, step = 1, archive[0] or #archive, 1; - local qstart, qend, qwith = -math.huge, math.huge; - local limit; - - if query then - if query.reverse then - start, stop, step = stop, start, -1; - if query.before and archive[query.before] then - start = archive[query.before] - 1; - end - elseif query.after and archive[query.after] then - start = archive[query.after] + 1; - end - qwith = query.with; - limit = query.limit; - qstart = query.start or qstart; - qend = query["end"] or qend; - end - - return function () - if limit and limit <= 0 then return end - for i = start, stop, step do - local item = archive[i]; - if (not qwith or qwith == item.with) and item.when >= qstart and item.when <= qend then - if limit then limit = limit - 1; end - start = i + step; -- Start on next item - return item.key, item.value, item.when, item.with; - end - end - end -end - -function archive_store:delete(username, query) - if not query or next(query) == nil then - -- no specifics, delete everything - store[username] = nil; - return true; - end - local archive = store[username]; - if not archive then return true; end -- no messages, nothing to delete - - local qstart = query.start or -math.huge; - local qend = query["end"] or math.huge; - local qwith = query.with; - store[username] = nil; - for i = 1, #archive do - local item = archive[i]; - local when, with = item.when, item.when; - -- Add things that don't match the query - if not ((not qwith or qwith == item.with) and item.when >= qstart and item.when <= qend) then - self:append(username, item.key, item.value, when, with); - end - end - return true; -end - -return archive_store; diff --git a/plugins/mod_mam/mamprefsxml.lib.lua b/plugins/mod_mam/mamprefsxml.lib.lua index 8eee78d8..c408fbea 100644 --- a/plugins/mod_mam/mamprefsxml.lib.lua +++ b/plugins/mod_mam/mamprefsxml.lib.lua @@ -2,6 +2,7 @@ -- Copyright (C) 2008-2017 Matthew Wild -- Copyright (C) 2008-2017 Waqas Hussain -- Copyright (C) 2011-2017 Kim Alvefur +-- Copyright (C) 2018 Emmanuel Gil Peyrot -- -- This project is MIT/X11 licensed. Please see the -- COPYING file in the source package for more information. @@ -10,6 +11,7 @@ -- local st = require"util.stanza"; +local jid_prep = require"util.jid".prep; local xmlns_mam = "urn:xmpp:mam:2"; local default_attrs = { @@ -42,16 +44,20 @@ local function fromstanza(prefstanza) local always = prefstanza:get_child("always"); if always then for rule in always:childtags("jid") do - local jid = rule:get_text(); - prefs[jid] = true; + local jid = jid_prep(rule:get_text()); + if jid then + prefs[jid] = true; + end end end local never = prefstanza:get_child("never"); if never then for rule in never:childtags("jid") do - local jid = rule:get_text(); - prefs[jid] = false; + local jid = jid_prep(rule:get_text()); + if jid then + prefs[jid] = false; + end end end diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 2874ac23..94bedbb1 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -40,18 +40,10 @@ local strip_tags = module:get_option_set("dont_archive_namespaces", { "http://ja local archive_store = module:get_option_string("archive_store", "archive"); local archive = module:open_store(archive_store, "archive"); -if archive.name == "null" or not archive.find then - if not archive.find then - module:log("debug", "Attempt to open archive storage returned a valid driver but it does not seem to implement the storage API"); - module:log("debug", "mod_%s does not support archiving", archive._provided_by or archive.name and "storage_"..archive.name.."(?)" or "<unknown>"); - else - module:log("debug", "Attempt to open archive storage returned null driver"); - end - module:log("debug", "See https://prosody.im/doc/storage and https://prosody.im/doc/archiving for more information"); - module:log("info", "Using in-memory fallback archive driver"); - archive = module:require "fallback_archive"; +if not archive.find then + error("mod_"..(archive._provided_by or archive.name and "storage_"..archive.name).." does not support archiving\n" + .."See https://prosody.im/doc/storage and https://prosody.im/doc/archiving for more information"); end - local use_total = module:get_option_boolean("mam_include_total", true); local cleanup; |