MUC: Don't limit affiliation changes to owners, and allow owners to remove themselves...
[prosody.git] / plugins / mod_pubsub.lua
index bbf16dd5514377c600b0bc9b4febd60b54e4faab..b8f7a882ccaf43ce86368899af6fca0794e56a87 100644 (file)
@@ -3,8 +3,6 @@ local st = require "util.stanza";
 local jid_bare = require "util.jid".bare;
 local uuid_generate = require "util.uuid".generate;
 
-require "core.modulemanager".load(module.host, "iq");
-
 local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
 local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors";
 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event";
@@ -74,7 +72,8 @@ function handlers.get_subscriptions(origin, stanza, subscriptions)
                return origin.send(pubsub_error_reply(stanza, ret));
        end
        local reply = st.reply(stanza)
-               :tag("subscriptions", { xmlns = xmlns_pubsub });
+               :tag("pubsub", { xmlns = xmlns_pubsub })
+                       :tag("subscriptions");
        for _, sub in ipairs(ret) do
                reply:tag("subscription", { node = sub.node, jid = sub.jid, subscription = 'subscribed' }):up();
        end
@@ -231,8 +230,23 @@ local function build_disco_info(service)
 end
 
 module:hook("iq-get/host/http://jabber.org/protocol/disco#info:query", function (event)
-       event.origin.send(st.reply(event.stanza):add_child(disco_info));
-       return true;
+       local origin, stanza = event.origin, event.stanza;
+       local node = stanza.tags[1].attr.node;
+       if not node then
+               return origin.send(st.reply(stanza):add_child(disco_info));
+       else
+               local ok, ret = service:get_nodes(stanza.attr.from);
+               if ok and not ret[node] then
+                       ok, ret = false, "item-not-found";
+               end
+               if not ok then
+                       return origin.send(pubsub_error_reply(stanza, ret));
+               end
+               local reply = st.reply(stanza)
+                       :tag("query", { xmlns = "http://jabber.org/protocol/disco#info", node = node })
+                               :tag("identity", { category = "pubsub", type = "leaf" });
+               return origin.send(reply);
+       end
 end);
 
 local function handle_disco_items_on_node(event)
@@ -245,7 +259,7 @@ local function handle_disco_items_on_node(event)
        end
        
        local reply = st.reply(stanza)
-               :tag("query", { xmlns = xmlns_disco_items });
+               :tag("query", { xmlns = "http://jabber.org/protocol/disco#items", node = node });
        
        for id, item in pairs(ret) do
                reply:tag("item", { jid = module.host, name = id }):up();