aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Zeitz <florob@babelmonkeys.de>2010-12-01 23:38:47 +0100
committerFlorian Zeitz <florob@babelmonkeys.de>2010-12-01 23:38:47 +0100
commitf85b16f9fa8e1fde7abda68f0da1b024c926807c (patch)
treec87ae84d4766c375c9d47feb950ce08b99455080
parent2fd7797f35de1e31834e53d8a87f907f286b6afb (diff)
downloadprosody-f85b16f9fa8e1fde7abda68f0da1b024c926807c.tar.gz
prosody-f85b16f9fa8e1fde7abda68f0da1b024c926807c.zip
mod_pubsub, util.pubsub: Support node creation
-rw-r--r--plugins/mod_pubsub.lua22
-rw-r--r--util/pubsub.lua8
2 files changed, 30 insertions, 0 deletions
diff --git a/plugins/mod_pubsub.lua b/plugins/mod_pubsub.lua
index da2070f3..f92d27aa 100644
--- a/plugins/mod_pubsub.lua
+++ b/plugins/mod_pubsub.lua
@@ -55,6 +55,28 @@ function handlers.get_items(origin, stanza, items)
return origin.send(reply);
end
+function handlers.set_create(origin, stanza, create)
+ local node = create.attr.node;
+ local ok, ret, reply;
+ if node then
+ ok, ret = service:create(node, stanza.attr.from);
+ if ok then
+ reply = st.reply(stanza);
+ else
+ reply = st.error_reply(stanza, "cancel", ret);
+ end
+ else
+ repeat
+ node = uuid_generate();
+ ok, ret = service:create(node, stanza.attr.from);
+ until ok;
+ reply = st.reply(stanza)
+ :tag("pubsub", { xmlns = xmlns_pubsub })
+ :tag("create", { node = node });
+ end
+ origin.send(reply);
+end
+
function handlers.set_subscribe(origin, stanza, subscribe)
local node, jid = subscribe.attr.node, subscribe.attr.jid;
if jid_bare(jid) ~= jid_bare(stanza.attr.from) then
diff --git a/util/pubsub.lua b/util/pubsub.lua
index da90fdcc..dc3f3432 100644
--- a/util/pubsub.lua
+++ b/util/pubsub.lua
@@ -28,6 +28,14 @@ function service:get_subscription(node, actor, jid)
end
end
+function service:create(node, actor)
+ if not self.nodes[node] then
+ self.nodes[node] = { name = node, subscribers = {}, config = {}, data = {} };
+ return true;
+ end
+ return false, "conflict";
+end
+
function service:publish(node, actor, id, item)
local node_obj = self.nodes[node];
if not node_obj then