# HG changeset patch # User Kim Alvefur # Date 1615761092 -3600 # Node ID b88f05c878ac310aa3c5782097e462b6f52c711b # Parent 97fac0ba046982f4f8175b78a2c4c1835795495f mod_firewall: Add basic LIST backend for receiving items from PubSub Relies on mod_pubsub_subscription diff -r 97fac0ba0469 -r b88f05c878ac mod_firewall/definitions.lib.lua --- a/mod_firewall/definitions.lib.lua Mon Mar 15 16:31:23 2021 +0100 +++ b/mod_firewall/definitions.lib.lua Sun Mar 14 23:31:32 2021 +0100 @@ -188,6 +188,55 @@ return self.items and self.items[item] == true; end; }; + + -- %LIST: pubsub:pubsub.example.com/node + -- TODO or the actual URI scheme? Bit overkill maybe? + -- TODO Publish items back to the service? + -- Step 1: Receiving pubsub events and storing them in the list + -- We'll start by using only the item id. + -- TODO Invent some custom schema for this? Needed for just a set of strings? + pubsubitemid = { + init = function(self, pubsub_spec, opts) + local service_addr, node = pubsub_spec:match("^([^/]*)/(.*)"); + module:depends("pubsub_subscription"); + module:add_item("pubsub-subscription", { + service = service_addr; + node = node; + on_subscribed = function () + self.items = {}; + end; + on_item = function (event) + self:add(event.item.attr.id); + end; + on_retract = function (event) + self:remove(event.item.attr.id); + end; + on_purge = function () + self.items = {}; + end; + on_unsubscribed = function () + self.items = nil; + end; + on_delete= function () + self.items = nil; + end; + }); + -- TODO Initial fetch? Or should mod_pubsub_subscription do this? + end; + add = function (self, item) + if self.items then + self.items[item] = true; + end + end; + remove = function (self, item) + if self.items then + self.items[item] = nil; + end + end; + contains = function (self, item) + return self.items and self.items[item] == true; + end; + }; }; list_backends.https = list_backends.http;