util.pubsub: Allow setting a callback for validating items to be published
authorKim Alvefur <zash@zash.se>
Wed, 21 Mar 2018 23:40:45 +0100
changeset 8697 059183e5571e
parent 8696 6e24a69b03af
child 8698 09e7fd8b16cd
util.pubsub: Allow setting a callback for validating items to be published
util/pubsub.lua
--- a/util/pubsub.lua	Sun Mar 25 17:02:39 2018 +0200
+++ b/util/pubsub.lua	Wed Mar 21 23:40:45 2018 +0100
@@ -6,6 +6,7 @@
 local default_config = {
 	itemstore = function (config, _) return cache.new(config["max_items"]) end;
 	broadcaster = function () end;
+	itemcheck = function () return true; end;
 	get_affiliation = function () end;
 	capabilities = {};
 };
@@ -306,6 +307,9 @@
 		end
 		node_obj = self.nodes[node];
 	end
+	if not self.config.itemcheck(item) then
+		return nil, "internal-server-error";
+	end
 	local node_data = self.data[node];
 	local ok = node_data:set(id, item);
 	if not ok then