1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-30 10:12:06 +01:00

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
This commit is contained in:
Gaston Dombiak 2006-07-10 16:56:14 +00:00 committed by gato
parent f9ecbb3297
commit c49356052f
3 changed files with 60 additions and 22 deletions

View file

@ -24,9 +24,10 @@ import java.util.Iterator;
/** /**
* The NodeInformationProvider is responsible for providing information (i.e. DiscoverItems.Item) * The NodeInformationProvider is responsible for providing supported features and hosted
* about a given node. This information will be requested each time this XMPPP client receives a * items (i.e. DiscoverItems.Item) about a given node. This information will be requested
* disco items requests on the given node. * 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 * @author Gaston Dombiak
*/ */
@ -41,4 +42,13 @@ public interface NodeInformationProvider {
*/ */
public abstract Iterator getNodeItems(); 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();
} }

View file

@ -20,12 +20,17 @@
package org.jivesoftware.smackx; package org.jivesoftware.smackx;
import java.util.*;
import org.jivesoftware.smack.*; import org.jivesoftware.smack.*;
import org.jivesoftware.smack.filter.*; import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.*; import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smackx.packet.*; 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: * Manages discovery of services in XMPP entities. This class provides:
@ -158,19 +163,23 @@ public class ServiceDiscoveryManager {
response.setType(IQ.Type.RESULT); response.setType(IQ.Type.RESULT);
response.setTo(discoverItems.getFrom()); response.setTo(discoverItems.getFrom());
response.setPacketID(discoverItems.getPacketID()); response.setPacketID(discoverItems.getPacketID());
response.setNode(discoverItems.getNode());
// Add the defined items related to the requested node. Look for // Add the defined items related to the requested node. Look for
// the NodeInformationProvider associated with the requested node. // the NodeInformationProvider associated with the requested node.
if (getNodeInformationProvider(discoverItems.getNode()) != null) { NodeInformationProvider nodeInformationProvider =
Iterator items = getNodeInformationProvider(discoverItems.getNode());
getNodeInformationProvider(discoverItems.getNode()).getNodeItems(); if (nodeInformationProvider != null) {
// Specified node was found
Iterator items = nodeInformationProvider.getNodeItems();
if (items != null) {
while (items.hasNext()) { while (items.hasNext()) {
response.addItem((DiscoverItems.Item) items.next()); response.addItem((DiscoverItems.Item) items.next());
} }
}
} else if(discoverItems.getNode() != null) { } else if(discoverItems.getNode() != null) {
// Return an <item-not-found/> error since the client // Return <item-not-found/> error since client doesn't contain
// doesn't contain the specified node // the specified node
response.setNode(discoverItems.getNode());
response.setType(IQ.Type.ERROR); response.setType(IQ.Type.ERROR);
response.setError(new XMPPError(404, "item-not-found")); response.setError(new XMPPError(404, "item-not-found"));
} }
@ -192,6 +201,7 @@ public class ServiceDiscoveryManager {
response.setType(IQ.Type.RESULT); response.setType(IQ.Type.RESULT);
response.setTo(discoverInfo.getFrom()); response.setTo(discoverInfo.getFrom());
response.setPacketID(discoverInfo.getPacketID()); response.setPacketID(discoverInfo.getPacketID());
response.setNode(discoverInfo.getNode());
// Add the client's identity and features only if "node" is null // Add the client's identity and features only if "node" is null
if (discoverInfo.getNode() == null) { if (discoverInfo.getNode() == null) {
// Set this client identity // Set this client identity
@ -207,11 +217,25 @@ public class ServiceDiscoveryManager {
} }
} }
else { else {
// Return an <item-not-found/> error since a client doesn't have nodes // Disco#info was sent to a node. Check if we have information of the
response.setNode(discoverInfo.getNode()); // 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 <item-not-found/> error since specified node was not found
response.setType(IQ.Type.ERROR); response.setType(IQ.Type.ERROR);
response.setError(new XMPPError(404, "item-not-found")); response.setError(new XMPPError(404, "item-not-found"));
} }
}
connection.sendPacket(response); connection.sendPacket(response);
} }
} }

View file

@ -93,6 +93,10 @@ public class MultiUserChat {
} }
return answer.iterator(); return answer.iterator();
} }
public Iterator getNodeFeatures() {
return null;
}
}); });
} }
}); });