From 2967393ae804d87f2cd97c97bf8cf58b501f4e67 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 26 Sep 2014 17:16:46 +0100 Subject: net.server_select: When an SSL handshake is connected, if there is pending data to be written to the socket, mark the socket as waiting to send (thanks daurnimator) --- net/server_select.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/server_select.lua b/net/server_select.lua index d2192f0a..33c18a60 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -568,6 +568,9 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport _ = status and status( handler, "ssl-handshake-complete" ) if self.autostart_ssl and listeners.onconnect then listeners.onconnect(self); + if bufferqueuelen ~= 0 then + _sendlistlen = addsocket(_sendlist, client, _sendlistlen) + end end _readlistlen = addsocket(_readlist, client, _readlistlen) return true -- cgit v1.2.3 From 158ea2ce458caa15881087bcab6809ef91cb54c9 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 27 Sep 2014 19:53:39 +0200 Subject: mod_pubsub: Transplant pieces of cdcfd93e2f43 from trunk --- plugins/mod_pubsub/mod_pubsub.lua | 2 +- plugins/mod_pubsub/pubsub.lib.lua | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/mod_pubsub/mod_pubsub.lua b/plugins/mod_pubsub/mod_pubsub.lua index c6dbe831..33e729af 100644 --- a/plugins/mod_pubsub/mod_pubsub.lua +++ b/plugins/mod_pubsub/mod_pubsub.lua @@ -100,7 +100,7 @@ module:hook("host-disco-items-node", function (event) return; end - for id, item in pairs(ret) do + for _, id in ipairs(ret) do reply:tag("item", { jid = module.host, name = id }):up(); end event.exists = true; diff --git a/plugins/mod_pubsub/pubsub.lib.lua b/plugins/mod_pubsub/pubsub.lib.lua index 2b015e34..4e9acd68 100644 --- a/plugins/mod_pubsub/pubsub.lib.lua +++ b/plugins/mod_pubsub/pubsub.lib.lua @@ -42,8 +42,8 @@ function handlers.get_items(origin, stanza, items, service) end local data = st.stanza("items", { node = node }); - for _, entry in pairs(results) do - data:add_child(entry); + for _, id in ipairs(results) do + data:add_child(results[id]); end local reply; if data then -- cgit v1.2.3 From cf3215b032b9fc21e673f1a7029b5e644e650d67 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 27 Sep 2014 19:57:33 +0200 Subject: util.pubsub: Use local --- util/pubsub.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/pubsub.lua b/util/pubsub.lua index fc67cb1f..afab634a 100644 --- a/util/pubsub.lua +++ b/util/pubsub.lua @@ -278,7 +278,7 @@ function service:publish(node, actor, id, item) end local node_data = self.data[node]; remove_item_by_id(node_data, id); - node_data[#self.data[node] + 1] = id; + node_data[#node_data + 1] = id; node_data[id] = item; self.events.fire_event("item-published", { node = node, actor = actor, id = id, item = item }); self.config.broadcaster("items", node, node_obj.subscribers, item); -- cgit v1.2.3 From d8283439b246eaa29d7a7e1ba9bb0aa06ee49c69 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 28 Sep 2014 00:05:21 +0200 Subject: util.pubsub: One less table allocated per pubsub object created --- util/pubsub.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/pubsub.lua b/util/pubsub.lua index afab634a..3c67be90 100644 --- a/util/pubsub.lua +++ b/util/pubsub.lua @@ -6,16 +6,16 @@ module("pubsub", package.seeall); local service = {}; local service_mt = { __index = service }; -local default_config = { +local default_config = { __index = { broadcaster = function () end; get_affiliation = function () end; capabilities = {}; -}; +} }; function new(config) config = config or {}; return setmetatable({ - config = setmetatable(config, { __index = default_config }); + config = setmetatable(config, default_config); affiliations = {}; subscriptions = {}; nodes = {}; -- cgit v1.2.3 From 54252eecb4fb38317f51087c591aa878ad19df71 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 28 Sep 2014 01:45:59 +0200 Subject: util.pubsub: Add support for node configuration --- util/pubsub.lua | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/util/pubsub.lua b/util/pubsub.lua index 3c67be90..424a48c6 100644 --- a/util/pubsub.lua +++ b/util/pubsub.lua @@ -11,11 +11,14 @@ local default_config = { __index = { get_affiliation = function () end; capabilities = {}; } }; +local default_node_config = { __index = { +} }; function new(config) config = config or {}; return setmetatable({ config = setmetatable(config, default_config); + node_defaults = setmetatable(config.node_defaults or {}, default_node_config); affiliations = {}; subscriptions = {}; nodes = {}; @@ -204,7 +207,7 @@ function service:get_subscription(node, actor, jid) return true, node_obj.subscribers[jid]; end -function service:create(node, actor) +function service:create(node, actor, options) -- Access checking if not self:may(node, actor, "create") then return false, "forbidden"; @@ -218,7 +221,7 @@ function service:create(node, actor) self.nodes[node] = { name = node; subscribers = {}; - config = {}; + config = setmetatable(options or {}, {__index=self.node_defaults}); affiliations = {}; }; setmetatable(self.nodes[node], { __index = { data = self.data[node] } }); -- COMPAT @@ -411,4 +414,21 @@ function service:set_node_capabilities(node, actor, capabilities) return true; end +function service:set_node_config(node, actor, new_config) + if not self:may(node, actor, "configure") then + return false, "forbidden"; + end + + local node_obj = self.nodes[node]; + if not node_obj then + return false, "item-not-found"; + end + + for k,v in pairs(new_config) do + node_obj.config[k] = v; + end + + return true; +end + return _M; -- cgit v1.2.3 From 952a9b8b8500d67a37c983b93a0c3f00a3e38e95 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 28 Sep 2014 01:46:17 +0200 Subject: mod_pubsub: Add support for node configuration --- plugins/mod_pubsub/mod_pubsub.lua | 10 ++++++++ plugins/mod_pubsub/pubsub.lib.lua | 49 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/plugins/mod_pubsub/mod_pubsub.lua b/plugins/mod_pubsub/mod_pubsub.lua index 33e729af..1107061e 100644 --- a/plugins/mod_pubsub/mod_pubsub.lua +++ b/plugins/mod_pubsub/mod_pubsub.lua @@ -64,6 +64,7 @@ local feature_map = { get_items = { "retrieve-items" }; add_subscription = { "subscribe" }; get_subscriptions = { "retrieve-subscriptions" }; + set_configure = { "config-node" }; }; local function add_disco_features_from_service(service) @@ -195,6 +196,7 @@ function module.load() retract = true; delete = true; get_nodes = true; + configure = true; subscribe = true; unsubscribe = true; @@ -215,6 +217,14 @@ function module.load() }; }; + node_config_form = require"util.dataforms".new { + { + type = "hidden"; + name = "FORM_TYPE"; + value = "http://jabber.org/protocol/pubsub#node_config"; + }; + }; + autocreate_on_publish = autocreate_on_publish; autocreate_on_subscribe = autocreate_on_subscribe; diff --git a/plugins/mod_pubsub/pubsub.lib.lua b/plugins/mod_pubsub/pubsub.lib.lua index 4e9acd68..075182a2 100644 --- a/plugins/mod_pubsub/pubsub.lib.lua +++ b/plugins/mod_pubsub/pubsub.lib.lua @@ -3,6 +3,7 @@ local uuid_generate = require "util.uuid".generate; local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors"; +local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; local _M = {}; @@ -17,6 +18,7 @@ local pubsub_errors = { ["item-not-found"] = { "cancel", "item-not-found" }; ["not-subscribed"] = { "modify", "unexpected-request", nil, "not-subscribed" }; ["forbidden"] = { "cancel", "forbidden" }; + ["not-allowed"] = { "cancel", "not-allowed" }; }; local function pubsub_error_reply(stanza, error) local e = pubsub_errors[error]; @@ -222,4 +224,51 @@ function handlers.set_purge(origin, stanza, purge, service) return origin.send(reply); end +function handlers.get_configure(origin, stanza, config, service) + local node = config.attr.node; + if not node then + return origin.send(pubsub_error_reply(stanza, "nodeid-required")); + end + + if not service:may(node, actor, "configure") then + return origin.send(pubsub_error_reply(stanza, "forbidden")); + end + + local node_obj = service.nodes[node]; + if not node_obj then + return origin.send(pubsub_error_reply(stanza, "item-not-found")); + end + + local form = self.config.node_config_form; + if not form then + return origin.send(pubsub_error_reply(stanza, "not-allowed")); + end + + local reply = st.reply(stanza) + :tag("pubsub", { xmlns = xmlns_pubsub_owner }) + :tag("configure", { node = node }) + :add_child(form:form(node_obj.config)); + return origin.send(reply); +end + +function handlers.set_configure(origin, stanza, config, service) + local node = config.attr.node; + if not node then + return origin.send(pubsub_error_reply(stanza, "nodeid-required")); + end + local form, node_obj = service:get_node_config_form(node, stanza.attr.from); + if not form then + return origin.send(pubsub_error_reply(stanza, node_obj)); + end + local new_config, err = form:data(config.tags[1]); + if not new_config then + return origin.send(st.error_reply(stanza, "modify", "bad-request", err)); + end + local ok, err = service:set_node_config(node, stanza.attr.from, new_config); + if not ok then + return origin.send(pubsub_error_reply(stanza, err)); + end + return origin.send(st.reply(stanza)); +end + return _M; -- cgit v1.2.3 From 33530258c05b37a287da67cfbc35093f0ca5dcb2 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 28 Sep 2014 01:50:00 +0200 Subject: util.pubsub: Add support for limiting the number of item in a node (default to 20) --- util/pubsub.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/util/pubsub.lua b/util/pubsub.lua index 424a48c6..2f8525b6 100644 --- a/util/pubsub.lua +++ b/util/pubsub.lua @@ -12,6 +12,7 @@ local default_config = { __index = { capabilities = {}; } }; local default_node_config = { __index = { + ["pubsub#max_items"] = "20"; } }; function new(config) @@ -262,6 +263,14 @@ local function remove_item_by_id(data, id) end end +local function trim_items(data, max) + max = tonumber(max); + if not max or #data <= max then return end + repeat + data[t_remove(data, 1)] = nil; + until #data <= max +end + function service:publish(node, actor, id, item) -- Access checking if not self:may(node, actor, "publish") then @@ -283,6 +292,7 @@ function service:publish(node, actor, id, item) remove_item_by_id(node_data, id); node_data[#node_data + 1] = id; node_data[id] = item; + trim_items(node_data, node_obj.config["pubsub#max_items"]); self.events.fire_event("item-published", { node = node, actor = actor, id = id, item = item }); self.config.broadcaster("items", node, node_obj.subscribers, item); return true; @@ -427,6 +437,7 @@ function service:set_node_config(node, actor, new_config) for k,v in pairs(new_config) do node_obj.config[k] = v; end + trim_items(self.data[node], node_obj.config["pubsub#max_items"]); return true; end -- cgit v1.2.3 From e157a9d6ee57e31d42dfe72afcca6d43e6506cab Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 28 Sep 2014 01:50:17 +0200 Subject: mod_pubsub: Add max items to node config form --- plugins/mod_pubsub/mod_pubsub.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/mod_pubsub/mod_pubsub.lua b/plugins/mod_pubsub/mod_pubsub.lua index 1107061e..1364bd27 100644 --- a/plugins/mod_pubsub/mod_pubsub.lua +++ b/plugins/mod_pubsub/mod_pubsub.lua @@ -223,6 +223,11 @@ function module.load() name = "FORM_TYPE"; value = "http://jabber.org/protocol/pubsub#node_config"; }; + { + type = "text-single"; + name = "pubsub#max_items"; + label = "Max # of items to persist"; + }; }; autocreate_on_publish = autocreate_on_publish; -- cgit v1.2.3 From 55bacaf74f778f267bcf1f01c5c11caaa31ac671 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 28 Sep 2014 01:55:32 +0200 Subject: mod_pubsub: Add support for requesting default node configuration --- plugins/mod_pubsub/mod_pubsub.lua | 1 + plugins/mod_pubsub/pubsub.lib.lua | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/plugins/mod_pubsub/mod_pubsub.lua b/plugins/mod_pubsub/mod_pubsub.lua index 1364bd27..0ffa7981 100644 --- a/plugins/mod_pubsub/mod_pubsub.lua +++ b/plugins/mod_pubsub/mod_pubsub.lua @@ -65,6 +65,7 @@ local feature_map = { add_subscription = { "subscribe" }; get_subscriptions = { "retrieve-subscriptions" }; set_configure = { "config-node" }; + get_default = { "retrieve-default" }; }; local function add_disco_features_from_service(service) diff --git a/plugins/mod_pubsub/pubsub.lib.lua b/plugins/mod_pubsub/pubsub.lib.lua index 075182a2..8a22fa69 100644 --- a/plugins/mod_pubsub/pubsub.lib.lua +++ b/plugins/mod_pubsub/pubsub.lib.lua @@ -271,4 +271,12 @@ function handlers.set_configure(origin, stanza, config, service) return origin.send(st.reply(stanza)); end +function handlers.get_default(origin, stanza, default, service) + local reply = st.reply(stanza) + :tag("pubsub", { xmlns = xmlns_pubsub_owner }) + :tag("configure", { node = node }) + :add_child(form:form(service.node_default_config)); + return origin.send(reply); +end + return _M; -- cgit v1.2.3