mod_pubsub: Handle disco#items on nodes

Wed, 22 Dec 2010 02:17:45 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 22 Dec 2010 02:17:45 +0000
changeset 3932
aa245e43b21e
parent 3931
6daed692264f
child 3933
24f0a7544a7a

mod_pubsub: Handle disco#items on nodes

plugins/mod_pubsub.lua file | annotate | diff | comparison | revisions
--- a/plugins/mod_pubsub.lua	Wed Dec 22 02:13:26 2010 +0000
+++ b/plugins/mod_pubsub.lua	Wed Dec 22 02:17:45 2010 +0000
@@ -219,7 +219,30 @@
 	return true;
 end);
 
+local function handle_disco_items_on_node(event)
+	local stanza, origin = event.stanza, event.origin;
+	local query = stanza.tags[1];
+	local node = query.attr.node;
+	local ok, ret = service:get_items(node, stanza.attr.from);
+	if not ok then
+		return origin.send(pubsub_error_reply(stanza, ret));
+	end
+	
+	local reply = st.reply(stanza)
+		:tag("query", { xmlns = xmlns_disco_items });
+	
+	for id, item in pairs(ret) do
+		reply:tag("item", { jid = module.host, name = id });
+	end
+	
+	return origin.send(reply);
+end
+
+
 module:hook("iq-get/host/http://jabber.org/protocol/disco#items:query", function (event)
+	if event.stanza.tags[1].attr.node then
+		return handle_disco_items_on_node(event);
+	end
 	local ok, ret = service:get_nodes(event.stanza.attr.from);
 	if not ok then
 		event.origin.send(pubsub_error_reply(stanza, ret));

mercurial