A few patches to add support for create and configure support for pubsub 
nodes. Also fixed a couple disco feature registrations.

I created these patches using git, let me know if you need me to reformat 
them or if there is an other format you prefer.

-- 
You received this message because you are subscribed to the Google Groups 
"prosody-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to prosody-dev+unsubscr...@googlegroups.com.
To post to this group, send email to prosody-dev@googlegroups.com.
Visit this group at http://groups.google.com/group/prosody-dev.
For more options, visit https://groups.google.com/d/optout.
>From c8cdcc4f650d4632c61256818b855795b28ea236 Mon Sep 17 00:00:00 2001
From: tylorr <ty...@fastmail.com>
Date: Fri, 10 Jul 2015 23:02:56 -0400
Subject: [PATCH 1/3] add namespace and multi actions for pubsub

Add support for actions with same name but different namespaces.

Add support for multiple actions per stanza
---
 plugins/mod_pubsub/mod_pubsub.lua | 26 ++++++++++++++++++++------
 plugins/mod_pubsub/pubsub.lib.lua | 12 ++++++------
 2 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/plugins/mod_pubsub/mod_pubsub.lua b/plugins/mod_pubsub/mod_pubsub.lua
index 40c28d2..95a5521 100644
--- a/plugins/mod_pubsub/mod_pubsub.lua
+++ b/plugins/mod_pubsub/mod_pubsub.lua
@@ -23,20 +23,34 @@ module:depends("disco");
 module:add_identity("pubsub", "service", pubsub_disco_name);
 module:add_feature("http://jabber.org/protocol/pubsub";);
 
-function handle_pubsub_iq(event)
+function handle_pubsub_iq(event, namespace)
 	local origin, stanza = event.origin, event.stanza;
 	local pubsub = stanza.tags[1];
-	local action = pubsub.tags[1];
-	if not action then
+	local actions = pubsub.tags;
+	if not #actions then
 		return origin.send(st.error_reply(stanza, "cancel", "bad-request"));
 	end
-	local handler = handlers[stanza.attr.type.."_"..action.name];
+
+	local action_names = {};
+	for _, action in ipairs(actions) do
+		table.insert(action_names, action.name) 
+	end
+
+	local ns_ = namespace and namespace.."_" or "";
+	local compound_action = table.concat(action_names, "_");
+	local handler = handlers[stanza.attr.type.."_"..ns_..compound_action];
+
 	if handler then
-		handler(origin, stanza, action, service);
+		if #actions <= 1 then actions = actions[1] end
+		handler(origin, stanza, actions, service);
 		return true;
 	end
 end
 
+function handle_pubsub_owner_iq(event)
+	return handle_pubsub_iq(event, "owner");
+end
+
 function simple_broadcast(kind, node, jids, item, actor)
 	if item then
 		item = st.clone(item);
@@ -57,7 +71,7 @@ function simple_broadcast(kind, node, jids, item, actor)
 end
 
 module:hook("iq/host/"..xmlns_pubsub..":pubsub", handle_pubsub_iq);
-module:hook("iq/host/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq);
+module:hook("iq/host/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_owner_iq);
 
 local feature_map = {
 	create = { "create-nodes", "instant-nodes", "item-ids" };
diff --git a/plugins/mod_pubsub/pubsub.lib.lua b/plugins/mod_pubsub/pubsub.lib.lua
index d85c71b..c0cfb87 100644
--- a/plugins/mod_pubsub/pubsub.lib.lua
+++ b/plugins/mod_pubsub/pubsub.lib.lua
@@ -72,7 +72,7 @@ function handlers.get_items(origin, stanza, items, service)
 	return origin.send(reply);
 end
 
-function handlers.get_subscriptions(origin, stanza, subscriptions, service)
+function handlers.get_owner_subscriptions(origin, stanza, subscriptions, service)
 	local node = subscriptions.attr.node;
 	local ok, ret = service:get_subscriptions(node, stanza.attr.from, stanza.attr.from);
 	if not ok then
@@ -113,7 +113,7 @@ function handlers.set_create(origin, stanza, create, service)
 	return origin.send(reply);
 end
 
-function handlers.set_delete(origin, stanza, delete, service)
+function handlers.set_owner_delete(origin, stanza, delete, service)
 	local node = delete.attr.node;
 
 	local reply, notifier;
@@ -222,7 +222,7 @@ function handlers.set_retract(origin, stanza, retract, service)
 	return origin.send(reply);
 end
 
-function handlers.set_purge(origin, stanza, purge, service)
+function handlers.set_owner_purge(origin, stanza, purge, service)
 	local node, notify = purge.attr.node, purge.attr.notify;
 	notify = (notify == "1") or (notify == "true");
 	local reply;
@@ -238,7 +238,7 @@ function handlers.set_purge(origin, stanza, purge, service)
 	return origin.send(reply);
 end
 
-function handlers.get_configure(origin, stanza, config, service)
+function handlers.get_owner_configure(origin, stanza, config, service)
 	local node = config.attr.node;
 	if not node then
 		return origin.send(pubsub_error_reply(stanza, "nodeid-required"));
@@ -260,7 +260,7 @@ function handlers.get_configure(origin, stanza, config, service)
 	return origin.send(reply);
 end
 
-function handlers.set_configure(origin, stanza, config, service)
+function handlers.set_owner_configure(origin, stanza, config, service)
 	local node = config.attr.node;
 	if not node then
 		return origin.send(pubsub_error_reply(stanza, "nodeid-required"));
@@ -279,7 +279,7 @@ function handlers.set_configure(origin, stanza, config, service)
 	return origin.send(st.reply(stanza));
 end
 
-function handlers.get_default(origin, stanza, default, service)
+function handlers.get_owner_default(origin, stanza, default, service)
 	local reply = st.reply(stanza)
 		:tag("pubsub", { xmlns = xmlns_pubsub_owner })
 			:tag("default")
-- 
2.4.4


>From 627b2b4849d307b56cd39802f91eb813b79ad3ff Mon Sep 17 00:00:00 2001
From: tylorr <ty...@fastmail.com>
Date: Fri, 10 Jul 2015 23:10:55 -0400
Subject: [PATCH 2/3] fix pubsub config-node and retrieve-default disco

---
 plugins/mod_pubsub/mod_pubsub.lua | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/plugins/mod_pubsub/mod_pubsub.lua b/plugins/mod_pubsub/mod_pubsub.lua
index 95a5521..9916a5d 100644
--- a/plugins/mod_pubsub/mod_pubsub.lua
+++ b/plugins/mod_pubsub/mod_pubsub.lua
@@ -82,11 +82,13 @@ local feature_map = {
 	get_items = { "retrieve-items" };
 	add_subscription = { "subscribe" };
 	get_subscriptions = { "retrieve-subscriptions" };
-	set_configure = { "config-node" };
-	get_default = { "retrieve-default" };
+	set_node_config = { "config-node" };
 };
 
 local function add_disco_features_from_service(service)
+	-- not implemented by service, implemented by lib_pubsub
+	module:add_feature(xmlns_pubsub.."#retrieve-default");
+
 	for method, features in pairs(feature_map) do
 		if service[method] then
 			for _, feature in ipairs(features) do
-- 
2.4.4


>From 283991e43c45268e924977e0ef8e84cd60126d55 Mon Sep 17 00:00:00 2001
From: tylorr <ty...@fastmail.com>
Date: Fri, 10 Jul 2015 23:38:24 -0400
Subject: [PATCH 3/3] add create and configure support to pubsub nodes

---
 plugins/mod_pubsub/mod_pubsub.lua |  1 +
 plugins/mod_pubsub/pubsub.lib.lua | 96 +++++++++++++++++++++++++++------------
 2 files changed, 67 insertions(+), 30 deletions(-)

diff --git a/plugins/mod_pubsub/mod_pubsub.lua b/plugins/mod_pubsub/mod_pubsub.lua
index 9916a5d..8758aba 100644
--- a/plugins/mod_pubsub/mod_pubsub.lua
+++ b/plugins/mod_pubsub/mod_pubsub.lua
@@ -88,6 +88,7 @@ local feature_map = {
 local function add_disco_features_from_service(service)
 	-- not implemented by service, implemented by lib_pubsub
 	module:add_feature(xmlns_pubsub.."#retrieve-default");
+	module:add_feature(xmlns_pubsub.."#create-and-configure");
 
 	for method, features in pairs(feature_map) do
 		if service[method] then
diff --git a/plugins/mod_pubsub/pubsub.lib.lua b/plugins/mod_pubsub/pubsub.lib.lua
index c0cfb87..6c1b15a 100644
--- a/plugins/mod_pubsub/pubsub.lib.lua
+++ b/plugins/mod_pubsub/pubsub.lib.lua
@@ -87,32 +87,78 @@ function handlers.get_owner_subscriptions(origin, stanza, subscriptions, service
 	return origin.send(reply);
 end
 
-function handlers.set_create(origin, stanza, create, service)
+local function create_node(stanza, create, service)
 	local node = create.attr.node;
 	local ok, ret, reply;
+	local instant_node = nil;
 	if node then
-		ok, ret = service:create(node, stanza.attr.from);
-		if ok then
-			reply = st.reply(stanza);
-		else
-			reply = pubsub_error_reply(stanza, ret);
-		end
+	  ok, ret = service:create(node, stanza.attr.from);
+	  if ok then
+	    reply = st.reply(stanza);
+	  else
+	    reply = pubsub_error_reply(stanza, ret);
+	  end
 	else
-		repeat
-			node = uuid_generate();
-			ok, ret = service:create(node, stanza.attr.from);
-		until ok or ret ~= "conflict";
-		if ok then
-			reply = st.reply(stanza)
-				:tag("pubsub", { xmlns = xmlns_pubsub })
-					:tag("create", { node = node });
-		else
-			reply = pubsub_error_reply(stanza, ret);
-		end
+	  repeat
+	    node = uuid_generate();
+	    ok, ret = service:create(node, stanza.attr.from);
+	  until ok or ret ~= "conflict";
+	  if ok then
+	  	instant_node = node;
+	    reply = st.reply(stanza)
+	      :tag("pubsub", { xmlns = xmlns_pubsub })
+	        :tag("create", { node = node });
+	  else
+	    reply = pubsub_error_reply(stanza, ret);
+	  end
+	end
+	return ok, reply, instant_node;
+end
+
+local function configure_node(stanza, config, node, service)
+	local new_config, err = node_config_form:data(config.tags[1]);
+	if not new_config then
+		return false, 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 false, pubsub_error_reply(stanza, err);
+	end
+	return true, st.reply(stanza);
+end
+
+function handlers.set_create(origin, stanza, create, service)
+	local _, reply = create_node(stanza, create, service);
 	return origin.send(reply);
 end
 
+function handlers.set_configure_create(origin, stanza, actions, service)
+	return origin.send(st.error_reply(stanza, "modify", "bad-request"));
+end
+
+function handlers.set_create_configure(origin, stanza, actions, service)
+	local create = actions[1];
+	local config = actions[2];
+
+	local node = config.attr.node;
+	if node then
+		return origin.send(st.error_reply(stanza, "modify", "bad-request"));
+	end
+
+	local ok, create_reply, instant_node = create_node(stanza, create, service);
+	if ok then
+		local node = instant_node or create.attr.node;
+
+		local config_reply;
+		local ok, config_reply = configure_node(stanza, config, node, service);
+
+		if not ok then
+			return origin.send(config_reply);
+		end
+	end
+	return origin.send(create_reply);
+end
+
 function handlers.set_owner_delete(origin, stanza, delete, service)
 	local node = delete.attr.node;
 
@@ -265,18 +311,8 @@ function handlers.set_owner_configure(origin, stanza, config, service)
 	if not node then
 		return origin.send(pubsub_error_reply(stanza, "nodeid-required"));
 	end
-	if not service:may(node, stanza.attr.from, "configure") then
-		return origin.send(pubsub_error_reply(stanza, "forbidden"));
-	end
-	local new_config, err = node_config_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));
+	local _, reply = configure_node(stanza, config, node, service);
+	return origin.send(reply);
 end
 
 function handlers.get_owner_default(origin, stanza, default, service)
-- 
2.4.4

Reply via email to