diff options
-rw-r--r-- | doc/doap.xml | 2 | ||||
-rw-r--r-- | plugins/mod_pep.lua | 14 | ||||
-rw-r--r-- | plugins/mod_pubsub/mod_pubsub.lua | 14 | ||||
-rw-r--r-- | plugins/mod_pubsub/pubsub.lib.lua | 7 | ||||
-rw-r--r-- | spec/scansion/pep_pubsub_max.scs | 47 | ||||
-rw-r--r-- | spec/scansion/pubsub_config.scs | 4 | ||||
-rw-r--r-- | spec/scansion/pubsub_multi_items.scs | 2 | ||||
-rw-r--r-- | spec/scansion/pubsub_preconditions.scs | 4 |
8 files changed, 78 insertions, 16 deletions
diff --git a/doc/doap.xml b/doc/doap.xml index b40db79e..34a696b4 100644 --- a/doc/doap.xml +++ b/doc/doap.xml @@ -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> diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua index da74639e..f9e2f808 100644 --- a/plugins/mod_pep.lua +++ b/plugins/mod_pep.lua @@ -35,6 +35,13 @@ local known_nodes = module:open_store("pep"); 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 @@ function is_item_stanza(item) 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 @@ end 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 diff --git a/plugins/mod_pubsub/mod_pubsub.lua b/plugins/mod_pubsub/mod_pubsub.lua index 2c3413fd..19834ad4 100644 --- a/plugins/mod_pubsub/mod_pubsub.lua +++ b/plugins/mod_pubsub/mod_pubsub.lua @@ -39,13 +39,22 @@ end -- 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 @@ function simple_broadcast(kind, node, jids, item, actor, node_obj) 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" diff --git a/plugins/mod_pubsub/pubsub.lib.lua b/plugins/mod_pubsub/pubsub.lib.lua index b53e0689..e7fa715d 100644 --- a/plugins/mod_pubsub/pubsub.lib.lua +++ b/plugins/mod_pubsub/pubsub.lib.lua @@ -83,7 +83,7 @@ local node_config_form = dataform { }; { 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 @@ local function create_encapsulating_item(id, payload) 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); diff --git a/spec/scansion/pep_pubsub_max.scs b/spec/scansion/pep_pubsub_max.scs new file mode 100644 index 00000000..6961304c --- /dev/null +++ b/spec/scansion/pep_pubsub_max.scs @@ -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> diff --git a/spec/scansion/pubsub_config.scs b/spec/scansion/pubsub_config.scs index d979aca5..2cad9115 100644 --- a/spec/scansion/pubsub_config.scs +++ b/spec/scansion/pubsub_config.scs @@ -48,7 +48,7 @@ Romeo receives: <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 @@ Romeo sends: <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"> diff --git a/spec/scansion/pubsub_multi_items.scs b/spec/scansion/pubsub_multi_items.scs index 147aaa8d..d76bc46c 100644 --- a/spec/scansion/pubsub_multi_items.scs +++ b/spec/scansion/pubsub_multi_items.scs @@ -43,7 +43,7 @@ Alice receives: <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"> diff --git a/spec/scansion/pubsub_preconditions.scs b/spec/scansion/pubsub_preconditions.scs index 25afaa8d..7e4e593b 100644 --- a/spec/scansion/pubsub_preconditions.scs +++ b/spec/scansion/pubsub_preconditions.scs @@ -47,7 +47,7 @@ Romeo receives: <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 @@ Romeo sends: <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"> |