I split the patch file into 3 and fixed the commit messages. Patch 3
relies on patch 2.

On 7/11/2015 4:12 PM, Kim Alvefur wrote:
> Hi!
> 
> Thanks for the patch(es)!
> 
> On 2015-07-11 17:31, Tylor Reynolds wrote:
>>     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.
> 
> The fist patch, is it 3 different changes in one?  If so, could you
> perhaps split it into one per change?  We also usually try to have one
> line commit messages.
> 
> Also, if you could prefix your commit messages with the module or
> section they change, so eg "mod_pubsub: do stuff".
> 

-- 
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 094ac9c7a518705a1999c5a40fc3afa19009b4cc Mon Sep 17 00:00:00 2001
From: tylorr <ty...@fastmail.com>
Date: Fri, 10 Jul 2015 23:10:55 -0400
Subject: mod_pubsub: fix registration of config-node and retrieve-default
 features

---
 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 40c28d2..ba9df31 100644
--- a/plugins/mod_pubsub/mod_pubsub.lua
+++ b/plugins/mod_pubsub/mod_pubsub.lua
@@ -68,11 +68,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 596b2685d37289c2ea0a5884bb704c28c0f3db26 Mon Sep 17 00:00:00 2001
From: tylorr <ty...@fastmail.com>
Date: Fri, 10 Jul 2015 23:02:56 -0400
Subject: =?UTF-8?q?mod=5Fpubsub:=20add=20support=20for=20actions=20with=20?=
 =?UTF-8?q?same=20name=20but=20different=20namespaces=0Aand=20stanzas=20wi?=
 =?UTF-8?q?th=20multiple=20actions?=

---
 plugins/mod_pubsub/mod_pubsub.lua | 26 ++++++++++++++++++++------
 plugins/mod_pubsub/pubsub.lib.lua | 10 +++++-----
 2 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/plugins/mod_pubsub/mod_pubsub.lua 
b/plugins/mod_pubsub/mod_pubsub.lua
index ba9df31..9916a5d 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..cb40e05 100644
--- a/plugins/mod_pubsub/pubsub.lib.lua
+++ b/plugins/mod_pubsub/pubsub.lib.lua
@@ -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 b891da2a2724ab564653f3cd54f73d510d953011 Mon Sep 17 00:00:00 2001
From: tylorr <ty...@fastmail.com>
Date: Fri, 10 Jul 2015 23:38:24 -0400
Subject: mod_pubsub: 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 cb40e05..cd275ec 100644
--- a/plugins/mod_pubsub/pubsub.lib.lua
+++ b/plugins/mod_pubsub/pubsub.lib.lua
@@ -87,32 +87,78 @@ function handlers.get_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

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to