Software /
code /
prosody
Comparison
plugins/mod_pep.lua @ 9077:aefb96a52f5f
mod_pep: Add 'pep_max_items' option to set an upper limit, defaults to 256 (scientifically chosen)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 01 Aug 2018 19:18:31 +0100 |
parent | 9074:0462405b1cfb |
child | 9080:1b21f8ffaec8 |
comparison
equal
deleted
inserted
replaced
9076:00d89430d77e | 9077:aefb96a52f5f |
---|---|
24 local host = module.host; | 24 local host = module.host; |
25 | 25 |
26 local node_config = module:open_store("pep", "map"); | 26 local node_config = module:open_store("pep", "map"); |
27 local known_nodes = module:open_store("pep"); | 27 local known_nodes = module:open_store("pep"); |
28 | 28 |
29 local max_max_items = module:get_option_number("pep_max_items", 256); | |
30 | |
29 function module.save() | 31 function module.save() |
30 return { services = services }; | 32 return { services = services }; |
31 end | 33 end |
32 | 34 |
33 function module.restore(data) | 35 function module.restore(data) |
34 services = data.services; | 36 services = data.services; |
35 end | 37 end |
36 | 38 |
37 function is_item_stanza(item) | 39 function is_item_stanza(item) |
38 return st.is_stanza(item) and item.attr.xmlns == xmlns_pubsub and item.name == "item"; | 40 return st.is_stanza(item) and item.attr.xmlns == xmlns_pubsub and item.name == "item"; |
41 end | |
42 | |
43 function check_node_config(node, actor, new_config) | |
44 if (new_config["max_items"] or 1) > max_max_items then | |
45 return false; | |
46 end | |
39 end | 47 end |
40 | 48 |
41 local function subscription_presence(username, recipient) | 49 local function subscription_presence(username, recipient) |
42 local user_bare = jid_join(username, host); | 50 local user_bare = jid_join(username, host); |
43 local recipient_bare = jid_bare(recipient); | 51 local recipient_bare = jid_bare(recipient); |
234 return "subscriber"; | 242 return "subscriber"; |
235 end | 243 end |
236 end; | 244 end; |
237 | 245 |
238 normalize_jid = jid_bare; | 246 normalize_jid = jid_bare; |
247 | |
248 check_node_config = check_node_config; | |
239 }); | 249 }); |
240 local nodes, err = known_nodes:get(username); | 250 local nodes, err = known_nodes:get(username); |
241 if nodes then | 251 if nodes then |
242 module:log("debug", "Restoring nodes for user %s", username); | 252 module:log("debug", "Restoring nodes for user %s", username); |
243 for node in pairs(nodes) do | 253 for node in pairs(nodes) do |