Changeset

11631:6641ca266d94

mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items' Fixes #1643 API change: The argument to archive_itemstore() changes type to integer
author Kim Alvefur <zash@zash.se>
date Wed, 09 Jun 2021 15:58:49 +0200
parents 11630:855b065d5fd6
children 11632:21a1b9fb08a1
files doc/doap.xml plugins/mod_pep.lua plugins/mod_pubsub/mod_pubsub.lua plugins/mod_pubsub/pubsub.lib.lua spec/scansion/pep_pubsub_max.scs spec/scansion/pubsub_config.scs spec/scansion/pubsub_multi_items.scs spec/scansion/pubsub_preconditions.scs
diffstat 8 files changed, 78 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/doc/doap.xml	Fri Sep 18 12:18:51 2020 +0200
+++ b/doc/doap.xml	Wed Jun 09 15:58:49 2021 +0200
@@ -158,7 +158,7 @@
     <implements>
       <xmpp:SupportedXep>
         <xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0060.html"/>
-        <xmpp:version>1.15.8</xmpp:version>
+        <xmpp:version>1.20.0</xmpp:version>
         <xmpp:since>0.9.0</xmpp:since>
         <xmpp:status>partial</xmpp:status>
       </xmpp:SupportedXep>
--- a/plugins/mod_pep.lua	Fri Sep 18 12:18:51 2020 +0200
+++ b/plugins/mod_pep.lua	Wed Jun 09 15:58:49 2021 +0200
@@ -35,6 +35,13 @@
 
 local max_max_items = module:get_option_number("pep_max_items", 256);
 
+local function tonumber_max_items(n)
+	if n == "max" then
+		return max_max_items;
+	end
+	return tonumber(n);
+end
+
 function module.save()
 	return {
 		services = services;
@@ -56,7 +63,7 @@
 end
 
 function check_node_config(node, actor, new_config) -- luacheck: ignore 212/node 212/actor
-	if (new_config["max_items"] or 1) > max_max_items then
+	if (tonumber_max_items(new_config["max_items"]) or 1) > max_max_items then
 		return false;
 	end
 	if new_config["access_model"] ~= "presence"
@@ -102,13 +109,14 @@
 local function simple_itemstore(username)
 	local driver = storagemanager.get_driver(module.host, "pep_data");
 	return function (config, node)
+		local max_items = tonumber_max_items(config["max_items"]);
 		if config["persist_items"] then
 			module:log("debug", "Creating new persistent item store for user %s, node %q", username, node);
 			local archive = driver:open("pep_"..node, "archive");
-			return lib_pubsub.archive_itemstore(archive, config, username, node, false);
+			return lib_pubsub.archive_itemstore(archive, max_items, username, node, false);
 		else
 			module:log("debug", "Creating new ephemeral item store for user %s, node %q", username, node);
-			return cache.new(tonumber(config["max_items"]));
+			return cache.new(max_items);
 		end
 	end
 end
--- a/plugins/mod_pubsub/mod_pubsub.lua	Fri Sep 18 12:18:51 2020 +0200
+++ b/plugins/mod_pubsub/mod_pubsub.lua	Wed Jun 09 15:58:49 2021 +0200
@@ -39,13 +39,22 @@
 --   get(node_name)
 --   users(): iterator over (node_name)
 
+local max_max_items = module:get_option_number("pubsub_max_items", 256);
+
+local function tonumber_max_items(n)
+	if n == "max" then
+		return max_max_items;
+	end
+	return tonumber(n);
+end
 
 local node_store = module:open_store(module.name.."_nodes");
 
 local function create_simple_itemstore(node_config, node_name) --> util.cache like object
 	local driver = storagemanager.get_driver(module.host, "pubsub_data");
 	local archive = driver:open("pubsub_"..node_name, "archive");
-	return lib_pubsub.archive_itemstore(archive, node_config, nil, node_name);
+	local max_items = tonumber_max_items(node_config["max_items"]);
+	return lib_pubsub.archive_itemstore(archive, max_items, nil, node_name);
 end
 
 function simple_broadcast(kind, node, jids, item, actor, node_obj)
@@ -99,9 +108,8 @@
 	end
 end
 
-local max_max_items = module:get_option_number("pubsub_max_items", 256);
 function check_node_config(node, actor, new_config) -- luacheck: ignore 212/node 212/actor
-	if (new_config["max_items"] or 1) > max_max_items then
+	if (tonumber_max_items(new_config["max_items"]) or 1) > max_max_items then
 		return false;
 	end
 	if new_config["access_model"] ~= "whitelist"
--- a/plugins/mod_pubsub/pubsub.lib.lua	Fri Sep 18 12:18:51 2020 +0200
+++ b/plugins/mod_pubsub/pubsub.lib.lua	Wed Jun 09 15:58:49 2021 +0200
@@ -83,7 +83,7 @@
 	};
 	{
 		type = "text-single";
-		datatype = "xs:integer";
+		datatype = "pubsub:integer-or-max";
 		name = "max_items";
 		var = "pubsub#max_items";
 		label = "Max # of items to persist";
@@ -801,10 +801,9 @@
 	return item;
 end
 
-local function archive_itemstore(archive, config, user, node)
-	module:log("debug", "Creation of archive itemstore for node %s with config %q", node, config);
+local function archive_itemstore(archive, max_items, user, node)
+	module:log("debug", "Creation of archive itemstore for node %s with limit %d", node, max_items);
 	local get_set = {};
-	local max_items = config["max_items"];
 	function get_set:items() -- luacheck: ignore 212/self
 		local data, err = archive:find(user, {
 			limit = tonumber(max_items);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spec/scansion/pep_pubsub_max.scs	Wed Jun 09 15:58:49 2021 +0200
@@ -0,0 +1,47 @@
+# PEP max_items=max
+
+[Client] Romeo
+	jid: pep-test-maxitems@localhost
+	password: password
+
+-----
+
+Romeo connects
+
+Romeo sends:
+	<iq type="set" id="pub">
+		<pubsub xmlns="http://jabber.org/protocol/pubsub">
+			<publish node="urn:xmpp:microblog:0">
+				<item>
+					<entry xmlns='http://www.w3.org/2005/Atom'>
+						<title>Hello</title>
+					</entry>
+				</item>
+			</publish>
+			<publish-options>
+				<x xmlns="jabber:x:data" type="submit">
+					<field type="hidden" var="FORM_TYPE">
+						<value>http://jabber.org/protocol/pubsub#publish-options</value>
+					</field>
+					<field var="pubsub#persist_items">
+						<value>true</value>
+					</field>
+					<field var="pubsub#access_model">
+						<value>open</value>
+					</field>
+					<field var="pubsub#max_items">
+						<value>max</value>
+					</field>
+				</x>
+			</publish-options>
+		</pubsub>
+	</iq>
+
+Romeo receives:
+	<iq type="result" id="pub">
+		<pubsub xmlns="http://jabber.org/protocol/pubsub">
+			<publish node="urn:xmpp:microblog:0">
+				<item id="{scansion:any}"/>
+			</publish>
+		</pubsub>
+	</iq>
--- a/spec/scansion/pubsub_config.scs	Fri Sep 18 12:18:51 2020 +0200
+++ b/spec/scansion/pubsub_config.scs	Wed Jun 09 15:58:49 2021 +0200
@@ -48,7 +48,7 @@
 					<field var="pubsub#description" label="Description" type="text-single"/>
 					<field var="pubsub#type" label="The type of node data, usually specified by the namespace of the payload (if any)" type="text-single"/>
 					<field var="pubsub#max_items" label="Max # of items to persist" type="text-single">
-						<validate xmlns="http://jabber.org/protocol/xdata-validate" datatype="xs:integer"/>
+						<validate xmlns="http://jabber.org/protocol/xdata-validate" datatype="pubsub:integer-or-max"/>
 						<value>1</value>
 					</field>
 					<field var="pubsub#persist_items" label="Persist items to storage" type="boolean">
@@ -124,7 +124,7 @@
 					<field var="pubsub#description" type="text-single" label="Description"/>
 					<field var="pubsub#type" type="text-single" label="The type of node data, usually specified by the namespace of the payload (if any)"/>
 					<field var="pubsub#max_items" type="text-single" label="Max # of items to persist">
-						<validate xmlns="http://jabber.org/protocol/xdata-validate" datatype="xs:integer"/>
+						<validate xmlns="http://jabber.org/protocol/xdata-validate" datatype="pubsub:integer-or-max"/>
 						<value>1</value>
 					</field>
 					<field var="pubsub#persist_items" type="boolean" label="Persist items to storage">
--- a/spec/scansion/pubsub_multi_items.scs	Fri Sep 18 12:18:51 2020 +0200
+++ b/spec/scansion/pubsub_multi_items.scs	Wed Jun 09 15:58:49 2021 +0200
@@ -43,7 +43,7 @@
 		<field var="pubsub#description" label="Description" type="text-single"/>
 		<field var="pubsub#type" label="The type of node data, usually specified by the namespace of the payload (if any)" type="text-single"/>
 		<field var="pubsub#max_items" label="Max # of items to persist" type="text-single">
-		  <validate xmlns="http://jabber.org/protocol/xdata-validate" datatype="xs:integer"/>
+		  <validate xmlns="http://jabber.org/protocol/xdata-validate" datatype="pubsub:integer-or-max"/>
 		  <value>20</value>
 		</field>
 		<field var="pubsub#persist_items" label="Persist items to storage" type="boolean">
--- a/spec/scansion/pubsub_preconditions.scs	Fri Sep 18 12:18:51 2020 +0200
+++ b/spec/scansion/pubsub_preconditions.scs	Wed Jun 09 15:58:49 2021 +0200
@@ -47,7 +47,7 @@
 					<field var="pubsub#description" label="Description" type="text-single"/>
 					<field var="pubsub#type" label="The type of node data, usually specified by the namespace of the payload (if any)" type="text-single"/>
 					<field var="pubsub#max_items" label="Max # of items to persist" type="text-single">
-						<validate xmlns="http://jabber.org/protocol/xdata-validate" datatype="xs:integer"/>
+						<validate xmlns="http://jabber.org/protocol/xdata-validate" datatype="pubsub:integer-or-max"/>
 						<value>1</value>
 					</field>
 					<field var="pubsub#persist_items" label="Persist items to storage" type="boolean">
@@ -123,7 +123,7 @@
 					<field var="pubsub#description" type="text-single" label="Description"/>
 					<field var="pubsub#type" type="text-single" label="The type of node data, usually specified by the namespace of the payload (if any)"/>
 					<field var="pubsub#max_items" type="text-single" label="Max # of items to persist">
-						<validate xmlns="http://jabber.org/protocol/xdata-validate" datatype="xs:integer"/>
+						<validate xmlns="http://jabber.org/protocol/xdata-validate" datatype="pubsub:integer-or-max"/>
 						<value>1</value>
 					</field>
 					<field var="pubsub#persist_items" type="boolean" label="Persist items to storage">