From c49356052ff3a574b2104fc94de574b3b2fffd2f Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Mon, 10 Jul 2006 16:56:14 +0000 Subject: [PATCH] Added support to return disco#info features of hosted nodes. SMACK-150 git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@4341 b35dd754-fafc-0310-a699-88a17e54d16e --- .../smackx/NodeInformationProvider.java | 18 ++++-- .../smackx/ServiceDiscoveryManager.java | 60 +++++++++++++------ .../smackx/muc/MultiUserChat.java | 4 ++ 3 files changed, 60 insertions(+), 22 deletions(-) diff --git a/source/org/jivesoftware/smackx/NodeInformationProvider.java b/source/org/jivesoftware/smackx/NodeInformationProvider.java index 2a06e2f8d..3c18fcfc2 100644 --- a/source/org/jivesoftware/smackx/NodeInformationProvider.java +++ b/source/org/jivesoftware/smackx/NodeInformationProvider.java @@ -24,10 +24,11 @@ import java.util.Iterator; /** - * The NodeInformationProvider is responsible for providing information (i.e. DiscoverItems.Item) - * about a given node. This information will be requested each time this XMPPP client receives a - * disco items requests on the given node. - * + * The NodeInformationProvider is responsible for providing supported features and hosted + * items (i.e. DiscoverItems.Item) about a given node. This information will be requested + * each time this XMPPP client receives a disco info or items requests on the given node. + * each time this XMPPP client receives a disco info or items requests on the given node. + * * @author Gaston Dombiak */ public interface NodeInformationProvider { @@ -41,4 +42,13 @@ public interface NodeInformationProvider { */ public abstract Iterator getNodeItems(); + /** + * Returns an Iterator on the features defined in the node. For + * example, the entity caps protocol specifies that an XMPP client + * should answer with each feature supported by the client version + * or extension. + * + * @return an Iterator on the feature strings defined in the node. + */ + public abstract Iterator getNodeFeatures(); } diff --git a/source/org/jivesoftware/smackx/ServiceDiscoveryManager.java b/source/org/jivesoftware/smackx/ServiceDiscoveryManager.java index 94b2ea4cf..c32d52a68 100644 --- a/source/org/jivesoftware/smackx/ServiceDiscoveryManager.java +++ b/source/org/jivesoftware/smackx/ServiceDiscoveryManager.java @@ -20,12 +20,17 @@ package org.jivesoftware.smackx; -import java.util.*; - import org.jivesoftware.smack.*; -import org.jivesoftware.smack.filter.*; -import org.jivesoftware.smack.packet.*; -import org.jivesoftware.smackx.packet.*; +import org.jivesoftware.smack.filter.PacketFilter; +import org.jivesoftware.smack.filter.PacketIDFilter; +import org.jivesoftware.smack.filter.PacketTypeFilter; +import org.jivesoftware.smack.packet.IQ; +import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.packet.XMPPError; +import org.jivesoftware.smackx.packet.DiscoverInfo; +import org.jivesoftware.smackx.packet.DiscoverItems; + +import java.util.*; /** * Manages discovery of services in XMPP entities. This class provides: @@ -158,19 +163,23 @@ public class ServiceDiscoveryManager { response.setType(IQ.Type.RESULT); response.setTo(discoverItems.getFrom()); response.setPacketID(discoverItems.getPacketID()); + response.setNode(discoverItems.getNode()); // Add the defined items related to the requested node. Look for // the NodeInformationProvider associated with the requested node. - if (getNodeInformationProvider(discoverItems.getNode()) != null) { - Iterator items = - getNodeInformationProvider(discoverItems.getNode()).getNodeItems(); - while (items.hasNext()) { - response.addItem((DiscoverItems.Item) items.next()); + NodeInformationProvider nodeInformationProvider = + getNodeInformationProvider(discoverItems.getNode()); + if (nodeInformationProvider != null) { + // Specified node was found + Iterator items = nodeInformationProvider.getNodeItems(); + if (items != null) { + while (items.hasNext()) { + response.addItem((DiscoverItems.Item) items.next()); + } } } else if(discoverItems.getNode() != null) { - // Return an error since the client - // doesn't contain the specified node - response.setNode(discoverItems.getNode()); + // Return error since client doesn't contain + // the specified node response.setType(IQ.Type.ERROR); response.setError(new XMPPError(404, "item-not-found")); } @@ -192,7 +201,8 @@ public class ServiceDiscoveryManager { response.setType(IQ.Type.RESULT); response.setTo(discoverInfo.getFrom()); response.setPacketID(discoverInfo.getPacketID()); - // Add the client's identity and features only if "node" is null + response.setNode(discoverInfo.getNode()); + // Add the client's identity and features only if "node" is null if (discoverInfo.getNode() == null) { // Set this client identity DiscoverInfo.Identity identity = new DiscoverInfo.Identity("client", @@ -207,10 +217,24 @@ public class ServiceDiscoveryManager { } } else { - // Return an error since a client doesn't have nodes - response.setNode(discoverInfo.getNode()); - response.setType(IQ.Type.ERROR); - response.setError(new XMPPError(404, "item-not-found")); + // Disco#info was sent to a node. Check if we have information of the + // specified node + NodeInformationProvider nodeInformationProvider = + getNodeInformationProvider(discoverInfo.getNode()); + if (nodeInformationProvider != null) { + // Node was found. Add node features + Iterator features = nodeInformationProvider.getNodeFeatures(); + if (features != null) { + while (features.hasNext()) { + response.addFeature((String) features.next()); + } + } + } + else { + // Return error since specified node was not found + response.setType(IQ.Type.ERROR); + response.setError(new XMPPError(404, "item-not-found")); + } } connection.sendPacket(response); } diff --git a/source/org/jivesoftware/smackx/muc/MultiUserChat.java b/source/org/jivesoftware/smackx/muc/MultiUserChat.java index 080084285..ea479dd21 100644 --- a/source/org/jivesoftware/smackx/muc/MultiUserChat.java +++ b/source/org/jivesoftware/smackx/muc/MultiUserChat.java @@ -93,6 +93,10 @@ public class MultiUserChat { } return answer.iterator(); } + + public Iterator getNodeFeatures() { + return null; + } }); } });