From 0ff95b16160d80de3a43be87353ce30e58c86ec1 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 4 Nov 2016 13:48:21 +0100 Subject: mod_mam: Import from prosody-modules --- plugins/mod_mam/mod_mam.lua | 338 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 338 insertions(+) create mode 100644 plugins/mod_mam/mod_mam.lua (limited to 'plugins/mod_mam/mod_mam.lua') diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua new file mode 100644 index 00000000..fe69e333 --- /dev/null +++ b/plugins/mod_mam/mod_mam.lua @@ -0,0 +1,338 @@ +-- XEP-0313: Message Archive Management for Prosody +-- Copyright (C) 2011-2016 Kim Alvefur +-- +-- This file is MIT/X11 licensed. + +local xmlns_mam = "urn:xmpp:mam:0"; +local xmlns_delay = "urn:xmpp:delay"; +local xmlns_forward = "urn:xmpp:forward:0"; + +local um = require "core.usermanager"; +local st = require "util.stanza"; +local rsm = module:require "rsm"; +local get_prefs = module:require"mamprefs".get; +local set_prefs = module:require"mamprefs".set; +local prefs_to_stanza = module:require"mamprefsxml".tostanza; +local prefs_from_stanza = module:require"mamprefsxml".fromstanza; +local jid_bare = require "util.jid".bare; +local jid_split = require "util.jid".split; +local dataform = require "util.dataforms".new; +local host = module.host; + +local rm_load_roster = require "core.rostermanager".load_roster; + +local getmetatable = getmetatable; +local function is_stanza(x) + return getmetatable(x) == st.stanza_mt; +end + +local tostring = tostring; +local time_now = os.time; +local m_min = math.min; +local timestamp, timestamp_parse = require "util.datetime".datetime, require "util.datetime".parse; +local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50); +local global_default_policy = module:get_option("default_archive_policy", true); +if global_default_policy ~= "roster" then + global_default_policy = module:get_option_boolean("default_archive_policy", global_default_policy); +end + +local archive_store = "archive2"; +local archive = assert(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 ""); + 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"; +end + +local cleanup; + +-- Handle prefs. +module:hook("iq/self/"..xmlns_mam..":prefs", function(event) + local origin, stanza = event.origin, event.stanza; + local user = origin.username; + if stanza.attr.type == "get" then + local prefs = prefs_to_stanza(get_prefs(user)); + local reply = st.reply(stanza):add_child(prefs); + origin.send(reply); + else -- type == "set" + local new_prefs = stanza:get_child("prefs", xmlns_mam); + local prefs = prefs_from_stanza(new_prefs); + local ok, err = set_prefs(user, prefs); + if not ok then + origin.send(st.error_reply(stanza, "cancel", "internal-server-error", "Error storing preferences: "..tostring(err))); + else + origin.send(st.reply(stanza)); + end + end + return true; +end); + +local query_form = dataform { + { name = "FORM_TYPE"; type = "hidden"; value = xmlns_mam; }; + { name = "with"; type = "jid-single"; }; + { name = "start"; type = "text-single" }; + { name = "end"; type = "text-single"; }; +}; + +-- Serve form +module:hook("iq-get/self/"..xmlns_mam..":query", function(event) + local origin, stanza = event.origin, event.stanza; + origin.send(st.reply(stanza):add_child(query_form:form())); + return true; +end); + +-- Handle archive queries +module:hook("iq-set/self/"..xmlns_mam..":query", function(event) + local origin, stanza = event.origin, event.stanza; + local query = stanza.tags[1]; + local qid = query.attr.queryid; + + if cleanup then cleanup[origin.username] = true; end + + -- Search query parameters + local qwith, qstart, qend; + local form = query:get_child("x", "jabber:x:data"); + if form then + local err; + form, err = query_form:data(form); + if err then + origin.send(st.error_reply(stanza, "modify", "bad-request", select(2, next(err)))); + return true; + end + qwith, qstart, qend = form["with"], form["start"], form["end"]; + qwith = qwith and jid_bare(qwith); -- dataforms does jidprep + end + + if qstart or qend then -- Validate timestamps + local vstart, vend = (qstart and timestamp_parse(qstart)), (qend and timestamp_parse(qend)); + if (qstart and not vstart) or (qend and not vend) then + origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid timestamp")) + return true; + end + qstart, qend = vstart, vend; + end + + module:log("debug", "Archive query, id %s with %s from %s until %s)", + tostring(qid), qwith or "anyone", qstart or "the dawn of time", qend or "now"); + + -- RSM stuff + local qset = rsm.get(query); + local qmax = m_min(qset and qset.max or default_max_items, max_max_items); + local reverse = qset and qset.before or false; + local before, after = qset and qset.before, qset and qset.after; + if type(before) ~= "string" then before = nil; end + + + -- Load all the data! + local data, err = archive:find(origin.username, { + start = qstart; ["end"] = qend; -- Time range + with = qwith; + limit = qmax + 1; + before = before; after = after; + reverse = reverse; + total = true; + }); + + if not data then + origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err)); + return true; + end + local total = tonumber(err); + + origin.send(st.reply(stanza)); + local msg_reply_attr = { to = stanza.attr.from, from = stanza.attr.to }; + + local results = {}; + + -- Wrap it in stuff and deliver + local first, last; + local count = 0; + local complete = "true"; + for id, item, when in data do + count = count + 1; + if count > qmax then + complete = nil; + break; + end + local fwd_st = st.message(msg_reply_attr) + :tag("result", { xmlns = xmlns_mam, queryid = qid, id = id }) + :tag("forwarded", { xmlns = xmlns_forward }) + :tag("delay", { xmlns = xmlns_delay, stamp = timestamp(when) }):up(); + + if not is_stanza(item) then + item = st.deserialize(item); + end + item.attr.xmlns = "jabber:client"; + fwd_st:add_child(item); + + if not first then first = id; end + last = id; + + if reverse then + results[count] = fwd_st; + else + origin.send(fwd_st); + end + end + + if reverse then + for i = #results, 1, -1 do + origin.send(results[i]); + end + first, last = last, first; + end + + -- That's all folks! + module:log("debug", "Archive query %s completed", tostring(qid)); + + origin.send(st.message(msg_reply_attr) + :tag("fin", { xmlns = xmlns_mam, queryid = qid, complete = complete }) + :add_child(rsm.generate { + first = first, last = last, count = total })); + return true; +end); + +local function has_in_roster(user, who) + local roster = rm_load_roster(user, host); + module:log("debug", "%s has %s in roster? %s", user, who, roster[who] and "yes" or "no"); + return roster[who]; +end + +local function shall_store(user, who) + -- TODO Cache this? + if not um.user_exists(user, host) then + return false; + end + local prefs = get_prefs(user); + local rule = prefs[who]; + module:log("debug", "%s's rule for %s is %s", user, who, tostring(rule)); + if rule ~= nil then + return rule; + end + -- Below could be done by a metatable + local default = prefs[false]; + module:log("debug", "%s's default rule is %s", user, tostring(default)); + if default == nil then + default = global_default_policy; + module:log("debug", "Using global default rule, %s", tostring(default)); + end + if default == "roster" then + return has_in_roster(user, who); + end + return default; +end + +-- Handle messages +local function message_handler(event, c2s) + local origin, stanza = event.origin, event.stanza; + local log = c2s and origin.log or module._log; + local orig_type = stanza.attr.type or "normal"; + local orig_from = stanza.attr.from; + local orig_to = stanza.attr.to or orig_from; + -- Stanza without 'to' are treated as if it was to their own bare jid + + -- We store chat messages or normal messages that have a body + if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body")) ) then + log("debug", "Not archiving stanza: %s (type)", stanza:top_tag()); + return; + end + -- or if hints suggest we shouldn't + if stanza:get_child("no-permanent-storage", "urn:xmpp:hints") -- The XEP needs to decide on "store" or "storage" + or stanza:get_child("no-permanent-store", "urn:xmpp:hints") + or stanza:get_child("no-storage", "urn:xmpp:hints") + or stanza:get_child("no-store", "urn:xmpp:hints") then + log("debug", "Not archiving stanza: %s (hint)", stanza:top_tag()); + return; + end + + -- Whos storage do we put it in? + local store_user = c2s and origin.username or jid_split(orig_to); + -- And who are they chatting with? + local with = jid_bare(c2s and orig_to or orig_from); + + -- Check with the users preferences + if shall_store(store_user, with) then + log("debug", "Archiving stanza: %s", stanza:top_tag()); + + -- And stash it + local ok, id = archive:append(store_user, nil, stanza, time_now(), with); + if ok then + if cleanup then cleanup[store_user] = true; end + module:fire_event("archive-message-added", { origin = origin, stanza = stanza, for_user = store_user, id = id }); + end + else + log("debug", "Not archiving stanza: %s (prefs)", stanza:top_tag()); + end +end + +local function c2s_message_handler(event) + return message_handler(event, true); +end + +local cleanup_after = module:get_option_string("archive_expires_after", "1w"); +local cleanup_interval = module:get_option_number("archive_cleanup_interval", 4 * 60 * 60); +if cleanup_after ~= "never" then + local day = 86400; + local multipliers = { d = day, w = day * 7, m = 31 * day, y = 365.2425 * day }; + local n, m = cleanup_after:lower():match("(%d+)%s*([dwmy]?)"); + if not n then + module:log("error", "Could not parse archive_expires_after string %q", cleanup_after); + return false; + end + + cleanup_after = tonumber(n) * ( multipliers[m] or 1 ); + + module:log("debug", "archive_expires_after = %d -- in seconds", cleanup_after); + + if not archive.delete then + module:log("error", "archive_expires_after set but mod_%s does not support deleting", archive._provided_by); + return false; + end + + cleanup = {}; + + pcall(function () + for user in um.users(module.host) do + cleanup[user] = true; + end + end); + + module:add_timer(math.random(10, 60), function() + local user = next(cleanup); + if user then + module:log("debug", "Removing old messages for user %q", user); + local ok, err = archive:delete(user, { ["end"] = os.time() - cleanup_after; }) + if not ok then + module:log("warn", "Could not expire archives for user %s: %s", user, err); + else + -- :affected() is a recent addition for eg SQLite3 in LuaDBI + pcall(function(stmt) + module:log("debug", "Removed %d messages", stmt:affected()); + end, err); + end + cleanup[user] = nil; + end + return math.random(cleanup_interval, cleanup_interval * 2); + end); +end + +-- Stanzas sent by local clients +module:hook("pre-message/bare", c2s_message_handler, 2); +module:hook("pre-message/full", c2s_message_handler, 2); +-- Stanszas to local clients +module:hook("message/bare", message_handler, 2); +module:hook("message/full", message_handler, 2); + +module:add_feature(xmlns_mam); -- COMPAT with XEP-0313 v 0.1 + +module:hook("account-disco-info", function(event) + (event.reply or event.stanza):tag("feature", {var=xmlns_mam}):up(); +end); + -- cgit v1.2.3 From e7a31b6e19d3aaf4e20ea62cc072195c6a0734b0 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 26 Nov 2016 21:50:06 +0100 Subject: util.rsm: Move out from mod_mam directory --- plugins/mod_mam/mod_mam.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/mod_mam/mod_mam.lua') diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index fe69e333..39d1bcf5 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -9,7 +9,7 @@ local xmlns_forward = "urn:xmpp:forward:0"; local um = require "core.usermanager"; local st = require "util.stanza"; -local rsm = module:require "rsm"; +local rsm = require "rsm"; local get_prefs = module:require"mamprefs".get; local set_prefs = module:require"mamprefs".set; local prefs_to_stanza = module:require"mamprefsxml".tostanza; -- cgit v1.2.3 From 7f28edd090d2d1546ded116de193bab51bea268a Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 28 Nov 2016 07:35:49 +0100 Subject: mod_mam: Use is_stanza from util.stanza --- plugins/mod_mam/mod_mam.lua | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'plugins/mod_mam/mod_mam.lua') diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 39d1bcf5..bc348919 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -21,11 +21,7 @@ local host = module.host; local rm_load_roster = require "core.rostermanager".load_roster; -local getmetatable = getmetatable; -local function is_stanza(x) - return getmetatable(x) == st.stanza_mt; -end - +local is_stanza = st.is_stanza; local tostring = tostring; local time_now = os.time; local m_min = math.min; -- cgit v1.2.3 From 58cc91cd454783208c1b3a4b73d9f54808b4aef6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 4 Nov 2016 13:59:49 +0100 Subject: mod_mam: Update to XEP-0313 v0.5.1 --- plugins/mod_mam/mod_mam.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'plugins/mod_mam/mod_mam.lua') diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index bc348919..0caf4d07 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -3,7 +3,7 @@ -- -- This file is MIT/X11 licensed. -local xmlns_mam = "urn:xmpp:mam:0"; +local xmlns_mam = "urn:xmpp:mam:1"; local xmlns_delay = "urn:xmpp:delay"; local xmlns_forward = "urn:xmpp:forward:0"; @@ -142,7 +142,6 @@ module:hook("iq-set/self/"..xmlns_mam..":query", function(event) end local total = tonumber(err); - origin.send(st.reply(stanza)); local msg_reply_attr = { to = stanza.attr.from, from = stanza.attr.to }; local results = {}; @@ -188,7 +187,7 @@ module:hook("iq-set/self/"..xmlns_mam..":query", function(event) -- That's all folks! module:log("debug", "Archive query %s completed", tostring(qid)); - origin.send(st.message(msg_reply_attr) + origin.send(st.reply(stanza) :tag("fin", { xmlns = xmlns_mam, queryid = qid, complete = complete }) :add_child(rsm.generate { first = first, last = last, count = total })); -- cgit v1.2.3 From c02ea749092c025a0bcc20c53719a4707f4121fe Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 18 Nov 2016 10:44:27 +0100 Subject: mod_mam: Decrease priority to zero --- plugins/mod_mam/mod_mam.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'plugins/mod_mam/mod_mam.lua') diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 0caf4d07..a9c80e73 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -319,11 +319,11 @@ if cleanup_after ~= "never" then end -- Stanzas sent by local clients -module:hook("pre-message/bare", c2s_message_handler, 2); -module:hook("pre-message/full", c2s_message_handler, 2); +module:hook("pre-message/bare", c2s_message_handler, 0); +module:hook("pre-message/full", c2s_message_handler, 0); -- Stanszas to local clients -module:hook("message/bare", message_handler, 2); -module:hook("message/full", message_handler, 2); +module:hook("message/bare", message_handler, 0); +module:hook("message/full", message_handler, 0); module:add_feature(xmlns_mam); -- COMPAT with XEP-0313 v 0.1 -- cgit v1.2.3 From b39bde756e092de1e32cf97ea5f4cb04f3dbf46d Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 18 Nov 2016 10:44:56 +0100 Subject: mod_mam: Remove legacy feature advertising --- plugins/mod_mam/mod_mam.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'plugins/mod_mam/mod_mam.lua') diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index a9c80e73..383ed162 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -325,8 +325,6 @@ module:hook("pre-message/full", c2s_message_handler, 0); module:hook("message/bare", message_handler, 0); module:hook("message/full", message_handler, 0); -module:add_feature(xmlns_mam); -- COMPAT with XEP-0313 v 0.1 - module:hook("account-disco-info", function(event) (event.reply or event.stanza):tag("feature", {var=xmlns_mam}):up(); end); -- cgit v1.2.3 From bebab75dda323dc31dec03747b8b3e8508f90528 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 19 Nov 2016 18:26:09 +0100 Subject: mod_mam: Add some comments explaining archive expiry --- plugins/mod_mam/mod_mam.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'plugins/mod_mam/mod_mam.lua') diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 383ed162..d4dae6cc 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -238,6 +238,7 @@ local function message_handler(event, c2s) log("debug", "Not archiving stanza: %s (type)", stanza:top_tag()); return; end + -- or if hints suggest we shouldn't if stanza:get_child("no-permanent-storage", "urn:xmpp:hints") -- The XEP needs to decide on "store" or "storage" or stanza:get_child("no-permanent-store", "urn:xmpp:hints") @@ -291,14 +292,20 @@ if cleanup_after ~= "never" then return false; end + -- Set of known users to do message expiry for + -- Populated either below or when new messages are added cleanup = {}; + -- Iterating over users is not supported by all authentication modules + -- Catch and ignore error if not supported pcall(function () + -- If this works, then we schedule cleanup for all known known for user in um.users(module.host) do cleanup[user] = true; end end); + -- At odd intervals, delete old messages for one user module:add_timer(math.random(10, 60), function() local user = next(cleanup); if user then -- cgit v1.2.3 From 913534e983095746a2f459fa884f465a20c33548 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 19 Nov 2016 18:27:28 +0100 Subject: mod_mam: Alter hints processing --- plugins/mod_mam/mod_mam.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'plugins/mod_mam/mod_mam.lua') diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index d4dae6cc..3e14c022 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -240,12 +240,12 @@ local function message_handler(event, c2s) end -- or if hints suggest we shouldn't - if stanza:get_child("no-permanent-storage", "urn:xmpp:hints") -- The XEP needs to decide on "store" or "storage" - or stanza:get_child("no-permanent-store", "urn:xmpp:hints") - or stanza:get_child("no-storage", "urn:xmpp:hints") - or stanza:get_child("no-store", "urn:xmpp:hints") then - log("debug", "Not archiving stanza: %s (hint)", stanza:top_tag()); - return; + if not stanza:get_child("store", "urn:xmpp:hints") then -- No hint telling us we should store + if stanza:get_child("no-permanent-store", "urn:xmpp:hints") + or stanza:get_child("no-store", "urn:xmpp:hints") then -- Hint telling us we should NOT store + log("debug", "Not archiving stanza: %s (hint)", stanza:top_tag()); + return; + end end -- Whos storage do we put it in? -- cgit v1.2.3 From dbd0d9fea7c5ca61e2acceb91ef774ade00d6a42 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 19 Nov 2016 18:28:28 +0100 Subject: mod_mam: Find out which party is the user and which is the 'with' earlier --- plugins/mod_mam/mod_mam.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'plugins/mod_mam/mod_mam.lua') diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 3e14c022..2606f861 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -233,6 +233,11 @@ local function message_handler(event, c2s) local orig_to = stanza.attr.to or orig_from; -- Stanza without 'to' are treated as if it was to their own bare jid + -- Whos storage do we put it in? + local store_user = c2s and origin.username or jid_split(orig_to); + -- And who are they chatting with? + local with = jid_bare(c2s and orig_to or orig_from); + -- We store chat messages or normal messages that have a body if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body")) ) then log("debug", "Not archiving stanza: %s (type)", stanza:top_tag()); @@ -248,11 +253,6 @@ local function message_handler(event, c2s) end end - -- Whos storage do we put it in? - local store_user = c2s and origin.username or jid_split(orig_to); - -- And who are they chatting with? - local with = jid_bare(c2s and orig_to or orig_from); - -- Check with the users preferences if shall_store(store_user, with) then log("debug", "Archiving stanza: %s", stanza:top_tag()); -- cgit v1.2.3 From 99ad7ae5e6c1b2ac930bc0ec20cf028051fd9553 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 19 Nov 2016 18:28:59 +0100 Subject: mod_mam: Filter out spoofed XEP-0359 tags --- plugins/mod_mam/mod_mam.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'plugins/mod_mam/mod_mam.lua') diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 2606f861..cb7613b8 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -16,6 +16,7 @@ local prefs_to_stanza = module:require"mamprefsxml".tostanza; local prefs_from_stanza = module:require"mamprefsxml".fromstanza; local jid_bare = require "util.jid".bare; local jid_split = require "util.jid".split; +local jid_prepped_split = require "util.jid".prepped_split; local dataform = require "util.dataforms".new; local host = module.host; @@ -238,6 +239,17 @@ local function message_handler(event, c2s) -- And who are they chatting with? local with = jid_bare(c2s and orig_to or orig_from); + -- Filter out that claim to be from us + stanza:maptags(function (tag) + if tag.name == "stanza-id" and tag.attr.xmlns == "urn:xmpp:sid:0" then + local by_user, by_host, res = prepped_split(tag.attr.by); + if not res and by_host == module.host and by_user == store_user then + return nil; + end + end + return tag; + end); + -- We store chat messages or normal messages that have a body if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body")) ) then log("debug", "Not archiving stanza: %s (type)", stanza:top_tag()); -- cgit v1.2.3 From 34cb7607de0569c26dd36cd23cdd46d4e818b517 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 19 Nov 2016 18:29:08 +0100 Subject: mod_mam: Add XEP-0359 tag --- plugins/mod_mam/mod_mam.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins/mod_mam/mod_mam.lua') diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index cb7613b8..2bdf85dc 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -272,6 +272,7 @@ local function message_handler(event, c2s) -- And stash it local ok, id = archive:append(store_user, nil, stanza, time_now(), with); if ok then + stanza:tag("stanza-id", { xmlns = "urn:xmpp:sid:0", by = store_user.."@"..host, id = id }):up(); if cleanup then cleanup[store_user] = true; end module:fire_event("archive-message-added", { origin = origin, stanza = stanza, for_user = store_user, id = id }); end -- cgit v1.2.3 From f2b74c28b0e0a6399c0487d93a39e42c849f17fa Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 22 Nov 2016 18:19:55 +0100 Subject: mod_mam: If archive:delete() gives a number, this should be the number of deleted items --- plugins/mod_mam/mod_mam.lua | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'plugins/mod_mam/mod_mam.lua') diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 2bdf85dc..9d7aabde 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -326,11 +326,8 @@ if cleanup_after ~= "never" then local ok, err = archive:delete(user, { ["end"] = os.time() - cleanup_after; }) if not ok then module:log("warn", "Could not expire archives for user %s: %s", user, err); - else - -- :affected() is a recent addition for eg SQLite3 in LuaDBI - pcall(function(stmt) - module:log("debug", "Removed %d messages", stmt:affected()); - end, err); + elseif type(ok) == "number" then + module:log("debug", "Removed %d messages", ok); end cleanup[user] = nil; end -- cgit v1.2.3 From d15ec87e01e22633da78db6113d70ac3da2b0e3f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 19 Dec 2016 08:44:56 +0100 Subject: mod_mam: Allow a set of namespaces to be stripped from stored stanzas, default to chat states (fixes #763) --- plugins/mod_mam/mod_mam.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'plugins/mod_mam/mod_mam.lua') diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 9d7aabde..898b81c8 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -32,6 +32,7 @@ local global_default_policy = module:get_option("default_archive_policy", true); if global_default_policy ~= "roster" then global_default_policy = module:get_option_boolean("default_archive_policy", global_default_policy); end +local strip_tags = module:get_option_set("dont_archive_namespaces", { "http://jabber.org/protocol/chatstates" }); local archive_store = "archive2"; local archive = assert(module:open_store(archive_store, "archive")); @@ -265,6 +266,20 @@ local function message_handler(event, c2s) end end + if not strip_tags:empty() then + stanza = st.clone(stanza); + stanza:maptags(function (tag) + if strip_tags:contains(tag.attr.xmlns) then + return nil; + else + return tag; + end + end); + if #stanza.tags == 0 then + return; + end + end + -- Check with the users preferences if shall_store(store_user, with) then log("debug", "Archiving stanza: %s", stanza:top_tag()); -- cgit v1.2.3 From 8adfea849c2328eeeedbd0ea85afd0d65a9214eb Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 11 Jan 2017 13:08:50 +0100 Subject: mod_mam: Change store name to "archive" but make it configurable for people who have data in "archive2" --- plugins/mod_mam/mod_mam.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/mod_mam/mod_mam.lua') diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 898b81c8..cff542bb 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -34,7 +34,7 @@ if global_default_policy ~= "roster" then end local strip_tags = module:get_option_set("dont_archive_namespaces", { "http://jabber.org/protocol/chatstates" }); -local archive_store = "archive2"; +local archive_store = module:get_option_string("archive_store", "archive"); local archive = assert(module:open_store(archive_store, "archive")); if archive.name == "null" or not archive.find then -- cgit v1.2.3 From fcd827853a8dcda866ce6fda71424582238fd57f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 23 Jan 2017 19:18:15 +0100 Subject: mod_mam: Normalize copyright headers --- plugins/mod_mam/mod_mam.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'plugins/mod_mam/mod_mam.lua') diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index cff542bb..69977813 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -1,7 +1,13 @@ +-- 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. +-- -- XEP-0313: Message Archive Management for Prosody --- Copyright (C) 2011-2016 Kim Alvefur -- --- This file is MIT/X11 licensed. local xmlns_mam = "urn:xmpp:mam:1"; local xmlns_delay = "urn:xmpp:delay"; -- cgit v1.2.3 From b54ba7235144f22208ce22ca31da705a62531935 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 23 Jan 2017 19:32:07 +0100 Subject: mod_mam: Use correct local name for util.jid.prepped_split --- plugins/mod_mam/mod_mam.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/mod_mam/mod_mam.lua') diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 69977813..f6ca52c0 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -249,7 +249,7 @@ local function message_handler(event, c2s) -- Filter out that claim to be from us stanza:maptags(function (tag) if tag.name == "stanza-id" and tag.attr.xmlns == "urn:xmpp:sid:0" then - local by_user, by_host, res = prepped_split(tag.attr.by); + local by_user, by_host, res = jid_prepped_split(tag.attr.by); if not res and by_host == module.host and by_user == store_user then return nil; end -- cgit v1.2.3