1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-26 05:52:06 +01:00

Reworked DiscoverInfo and DiscoverItems

- Change the return type from Iterator to List
- Remove the synchronized blocks
This commit is contained in:
Florian Schmaus 2014-03-24 22:31:42 +01:00
parent 2619a63c21
commit c4f86762cb
13 changed files with 102 additions and 151 deletions

View file

@ -309,8 +309,7 @@ public class MultipleRecipientManager {
// Get the disco items and send the disco packet to each server item // Get the disco items and send the disco packet to each server item
DiscoverItems items = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems( DiscoverItems items = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems(
serviceName); serviceName);
for (Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext();) { for (DiscoverItems.Item item : items.getItems()) {
DiscoverItems.Item item = it.next();
info = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo( info = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(
item.getEntityID(), item.getNode()); item.getEntityID(), item.getNode());
if (info.containsFeature("http://jabber.org/protocol/address")) { if (info.containsFeature("http://jabber.org/protocol/address")) {

View file

@ -25,8 +25,6 @@ import org.jivesoftware.smackx.amp.packet.AMPExtension;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo; import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import java.util.Iterator;
/** /**
* Manages AMP stanzas within messages. A AMPManager provides a high level access to * Manages AMP stanzas within messages. A AMPManager provides a high level access to
* get and set AMP rules to messages. * get and set AMP rules to messages.
@ -114,9 +112,7 @@ public class AMPManager {
private static boolean isFeatureSupportedByServer(XMPPConnection connection, String featureName, String node) throws NoResponseException, XMPPErrorException, NotConnectedException { private static boolean isFeatureSupportedByServer(XMPPConnection connection, String featureName, String node) throws NoResponseException, XMPPErrorException, NotConnectedException {
ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(connection); ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
DiscoverInfo info = discoveryManager.discoverInfo(connection.getServiceName(), node); DiscoverInfo info = discoveryManager.discoverInfo(connection.getServiceName(), node);
Iterator<DiscoverInfo.Feature> it = info.getFeatures(); for (DiscoverInfo.Feature feature : info.getFeatures()){
while (it.hasNext()) {
DiscoverInfo.Feature feature = it.next();
if (featureName.equals(feature.getVar())) { if (featureName.equals(feature.getVar())) {
return true; return true;
} }

View file

@ -21,7 +21,6 @@ import java.net.Socket;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -559,12 +558,9 @@ public final class Socks5BytestreamManager implements BytestreamManager {
// get all items from XMPP server // get all items from XMPP server
DiscoverItems discoverItems = serviceDiscoveryManager.discoverItems(this.connection.getServiceName()); DiscoverItems discoverItems = serviceDiscoveryManager.discoverItems(this.connection.getServiceName());
Iterator<Item> itemIterator = discoverItems.getItems();
// query all items if they are SOCKS5 proxies // query all items if they are SOCKS5 proxies
while (itemIterator.hasNext()) { for (Item item : discoverItems.getItems()) {
Item item = itemIterator.next();
// skip blacklisted servers // skip blacklisted servers
if (this.proxyBlacklist.contains(item.getEntityID())) { if (this.proxyBlacklist.contains(item.getEntityID())) {
continue; continue;
@ -580,12 +576,8 @@ public final class Socks5BytestreamManager implements BytestreamManager {
continue; continue;
} }
Iterator<Identity> identities = proxyInfo.getIdentities();
// item must have category "proxy" and type "bytestream" // item must have category "proxy" and type "bytestream"
while (identities.hasNext()) { for (Identity identity : proxyInfo.getIdentities()) {
Identity identity = identities.next();
if ("proxy".equalsIgnoreCase(identity.getCategory()) if ("proxy".equalsIgnoreCase(identity.getCategory())
&& "bytestreams".equalsIgnoreCase(identity.getType())) { && "bytestreams".equalsIgnoreCase(identity.getType())) {
proxies.add(item.getEntityID()); proxies.add(item.getEntityID());

View file

@ -578,8 +578,8 @@ public class EntityCapsManager extends Manager {
// type MUST be included. // type MUST be included.
SortedSet<DiscoverInfo.Identity> sortedIdentities = new TreeSet<DiscoverInfo.Identity>(); SortedSet<DiscoverInfo.Identity> sortedIdentities = new TreeSet<DiscoverInfo.Identity>();
for (Iterator<DiscoverInfo.Identity> it = discoverInfo.getIdentities(); it.hasNext();) for (DiscoverInfo.Identity i : discoverInfo.getIdentities())
sortedIdentities.add(it.next()); sortedIdentities.add(i);
// 3. For each identity, append the 'category/type/lang/name' to S, // 3. For each identity, append the 'category/type/lang/name' to S,
// followed by the '<' character. // followed by the '<' character.
@ -597,8 +597,8 @@ public class EntityCapsManager extends Manager {
// 4. Sort the supported service discovery features. // 4. Sort the supported service discovery features.
SortedSet<String> features = new TreeSet<String>(); SortedSet<String> features = new TreeSet<String>();
for (Iterator<Feature> it = discoverInfo.getFeatures(); it.hasNext();) for (Feature f : discoverInfo.getFeatures())
features.add(it.next().getVar()); features.add(f.getVar());
// 5. For each feature, append the feature to S, followed by the '<' // 5. For each feature, append the feature to S, followed by the '<'
// character // character

View file

@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.jivesoftware.smackx.disco; package org.jivesoftware.smackx.disco;
import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NoResponseException;
@ -220,6 +219,26 @@ public class ServiceDiscoveryManager extends Manager {
renewEntityCapsVersion(); renewEntityCapsVersion();
} }
/**
* Sets the default identity the client will report.
*
* @param identity
*/
public void setIdentity(Identity identity) {
if (identity == null) throw new IllegalArgumentException("Identity can not be null");
this.identity = identity;
renewEntityCapsVersion();
}
/**
* Return the default identity of the client.
*
* @return the default identity.
*/
public Identity getIdentity() {
return identity;
}
/** /**
* Returns the type of client that will be returned when asked for the client identity in a * Returns the type of client that will be returned when asked for the client identity in a
* disco request. The valid types are defined by the category client. Follow this link to learn * disco request. The valid types are defined by the category client. Follow this link to learn
@ -233,21 +252,7 @@ public class ServiceDiscoveryManager extends Manager {
} }
/** /**
* Sets the type of client that will be returned when asked for the client identity in a * Add an further identity to the client.
* disco request. The valid types are defined by the category client. Follow this link to learn
* the possible types: <a href="http://xmpp.org/registrar/disco-categories.html#client">Jabber::Registrar</a>.
*
* @param type the type of client that will be returned when asked for the client identity in a
* disco request.
*/
@SuppressWarnings("deprecation")
public void setIdentityType(String type) {
identity.setType(type);
renewEntityCapsVersion();
}
/**
* Add an identity to the client.
* *
* @param identity * @param identity
*/ */

View file

@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.jivesoftware.smackx.disco.packet; package org.jivesoftware.smackx.disco.packet;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
@ -22,10 +21,8 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/** /**
* A DiscoverInfo IQ packet, which is used by XMPP clients to request and receive information * A DiscoverInfo IQ packet, which is used by XMPP clients to request and receive information
@ -36,12 +33,12 @@ import java.util.concurrent.CopyOnWriteArrayList;
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public class DiscoverInfo extends IQ { public class DiscoverInfo extends IQ implements Cloneable {
public static final String NAMESPACE = "http://jabber.org/protocol/disco#info"; public static final String NAMESPACE = "http://jabber.org/protocol/disco#info";
private final List<Feature> features = new CopyOnWriteArrayList<Feature>(); private final List<Feature> features = new LinkedList<Feature>();
private final List<Identity> identities = new CopyOnWriteArrayList<Identity>(); private final List<Identity> identities = new LinkedList<Identity>();
private String node; private String node;
public DiscoverInfo() { public DiscoverInfo() {
@ -60,17 +57,13 @@ public class DiscoverInfo extends IQ {
setNode(d.getNode()); setNode(d.getNode());
// Copy features // Copy features
synchronized (d.features) { for (Feature f : d.features) {
for (Feature f : d.features) { addFeature(f.clone());
addFeature(f);
}
} }
// Copy identities // Copy identities
synchronized (d.identities) { for (Identity i : d.identities) {
for (Identity i : d.identities) { addIdentity(i.clone());
addIdentity(i);
}
} }
} }
@ -96,20 +89,16 @@ public class DiscoverInfo extends IQ {
} }
private void addFeature(Feature feature) { private void addFeature(Feature feature) {
synchronized (features) { features.add(feature);
features.add(feature);
}
} }
/** /**
* Returns the discovered features of an XMPP entity. * Returns the discovered features of an XMPP entity.
* *
* @return an Iterator on the discovered features of an XMPP entity * @return an unmodifiable list of the discovered features of an XMPP entity
*/ */
public Iterator<Feature> getFeatures() { public List<Feature> getFeatures() {
synchronized (features) { return Collections.unmodifiableList(features);
return Collections.unmodifiableList(features).iterator();
}
} }
/** /**
@ -118,9 +107,7 @@ public class DiscoverInfo extends IQ {
* @param identity the discovered entity's identity * @param identity the discovered entity's identity
*/ */
public void addIdentity(Identity identity) { public void addIdentity(Identity identity) {
synchronized (identities) { identities.add(identity);
identities.add(identity);
}
} }
/** /**
@ -130,20 +117,16 @@ public class DiscoverInfo extends IQ {
*/ */
public void addIdentities(Collection<Identity> identitiesToAdd) { public void addIdentities(Collection<Identity> identitiesToAdd) {
if (identitiesToAdd == null) return; if (identitiesToAdd == null) return;
synchronized (identities) { identities.addAll(identitiesToAdd);
identities.addAll(identitiesToAdd);
}
} }
/** /**
* Returns the discovered identities of an XMPP entity. * Returns the discovered identities of an XMPP entity.
* *
* @return an Iterator on the discoveted identities * @return an unmodifiable list of the discovered identities
*/ */
public Iterator<Identity> getIdentities() { public List<Identity> getIdentities() {
synchronized (identities) { return Collections.unmodifiableList(identities);
return Collections.unmodifiableList(identities).iterator();
}
} }
/** /**
@ -179,8 +162,8 @@ public class DiscoverInfo extends IQ {
* @return true if the requestes feature has been discovered * @return true if the requestes feature has been discovered
*/ */
public boolean containsFeature(String feature) { public boolean containsFeature(String feature) {
for (Iterator<Feature> it = getFeatures(); it.hasNext();) { for (Feature f : getFeatures()) {
if (feature.equals(it.next().getVar())) if (feature.equals(f.getVar()))
return true; return true;
} }
return false; return false;
@ -193,15 +176,11 @@ public class DiscoverInfo extends IQ {
xml.xmlnsAttribute(NAMESPACE); xml.xmlnsAttribute(NAMESPACE);
xml.optAttribute("node", getNode()); xml.optAttribute("node", getNode());
xml.rightAngelBracket(); xml.rightAngelBracket();
synchronized (identities) { for (Identity identity : identities) {
for (Identity identity : identities) { xml.append(identity.toXML());
xml.append(identity.toXML());
}
} }
synchronized (features) { for (Feature feature : features) {
for (Feature feature : features) { xml.append(feature.toXML());
xml.append(feature.toXML());
}
} }
// Add packet extensions, if any are defined. // Add packet extensions, if any are defined.
xml.append(getExtensionsXML()); xml.append(getExtensionsXML());
@ -243,6 +222,11 @@ public class DiscoverInfo extends IQ {
return false; return false;
} }
@Override
public DiscoverInfo clone() {
return new DiscoverInfo(this);
}
/** /**
* Represents the identity of a given XMPP entity. An entity may have many identities but all * Represents the identity of a given XMPP entity. An entity may have many identities but all
* the identities SHOULD have the same name.<p> * the identities SHOULD have the same name.<p>
@ -252,23 +236,16 @@ public class DiscoverInfo extends IQ {
* attributes. * attributes.
* *
*/ */
public static class Identity implements Comparable<Identity> { public static class Identity implements Comparable<Identity>, Cloneable {
private String category; private final String category;
private String name; private String name;
private String type; private final String type;
private String lang; // 'xml:lang; private String lang; // 'xml:lang;
/** public Identity(Identity identity) {
* Creates a new identity for an XMPP entity. this(identity.category, identity.name, identity.type);
* lang = identity.lang;
* @param category the entity's category.
* @param name the entity's name.
* @deprecated As per the spec, the type field is mandatory and the 3 argument constructor should be used instead.
*/
public Identity(String category, String name) {
this.category = category;
this.name = name;
} }
/** /**
@ -327,17 +304,6 @@ public class DiscoverInfo extends IQ {
return type; return type;
} }
/**
* Sets the entity's type. To get the official registry of values for the
* 'type' attribute refer to <a href="http://www.jabber.org/registrar/disco-categories.html">Jabber::Registrar</a>
*
* @param type the identity's type.
* @deprecated As per the spec, this field is mandatory and the 3 argument constructor should be used instead.
*/
public void setType(String type) {
this.type = type;
}
/** /**
* Sets the natural language (xml:lang) for this identity (optional) * Sets the natural language (xml:lang) for this identity (optional)
* *
@ -447,6 +413,11 @@ public class DiscoverInfo extends IQ {
return category.compareTo(other.category); return category.compareTo(other.category);
} }
} }
@Override
public Identity clone() {
return new Identity(this);
}
} }
/** /**
@ -455,9 +426,13 @@ public class DiscoverInfo extends IQ {
* as well as specific feature types of interest, if any (e.g., for the purpose of feature * as well as specific feature types of interest, if any (e.g., for the purpose of feature
* negotiation). * negotiation).
*/ */
public static class Feature { public static class Feature implements Cloneable {
private String variable; private final String variable;
public Feature(Feature feature) {
this.variable = feature.variable;
}
/** /**
* Creates a new feature offered by an XMPP entity or item. * Creates a new feature offered by an XMPP entity or item.
@ -503,5 +478,10 @@ public class DiscoverInfo extends IQ {
public int hashCode() { public int hashCode() {
return 37 * variable.hashCode(); return 37 * variable.hashCode();
} }
@Override
public Feature clone() {
return new Feature(this);
}
} }
} }

View file

@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.jivesoftware.smackx.disco.packet; package org.jivesoftware.smackx.disco.packet;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
@ -22,9 +21,8 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/** /**
* A DiscoverItems IQ packet, which is used by XMPP clients to request and receive items * A DiscoverItems IQ packet, which is used by XMPP clients to request and receive items
@ -39,7 +37,7 @@ public class DiscoverItems extends IQ {
public static final String NAMESPACE = "http://jabber.org/protocol/disco#items"; public static final String NAMESPACE = "http://jabber.org/protocol/disco#items";
private final List<Item> items = new CopyOnWriteArrayList<Item>(); private final List<Item> items = new LinkedList<Item>();
private String node; private String node;
/** /**
@ -48,9 +46,7 @@ public class DiscoverItems extends IQ {
* @param item the discovered entity's item * @param item the discovered entity's item
*/ */
public void addItem(Item item) { public void addItem(Item item) {
synchronized (items) { items.add(item);
items.add(item);
}
} }
/** /**
@ -65,15 +61,14 @@ public class DiscoverItems extends IQ {
} }
} }
/** /**
* Returns the discovered items of the queried XMPP entity. * Returns the discovered items of the queried XMPP entity.
* *
* @return an Iterator on the discovered entity's items * @return an unmodifiable list of the discovered entity's items
*/ */
public Iterator<DiscoverItems.Item> getItems() { public List<DiscoverItems.Item> getItems() {
synchronized (items) { return Collections.unmodifiableList(items);
return Collections.unmodifiableList(items).iterator();
}
} }
/** /**
@ -109,11 +104,10 @@ public class DiscoverItems extends IQ {
xml.optAttribute("node", getNode()); xml.optAttribute("node", getNode());
xml.rightAngelBracket(); xml.rightAngelBracket();
synchronized (items) { for (Item item : items) {
for (Item item : items) { xml.append(item.toXML());
xml.append(item.toXML());
}
} }
xml.closeElement("query"); xml.closeElement("query");
return xml; return xml;
} }

View file

@ -225,8 +225,8 @@ public class MultiUserChat {
DiscoverItems result = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems( DiscoverItems result = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems(
user, discoNode); user, discoNode);
// Collect the entityID for each returned item // Collect the entityID for each returned item
for (Iterator<DiscoverItems.Item> items = result.getItems(); items.hasNext();) { for (DiscoverItems.Item item : result.getItems()) {
answer.add(items.next().getEntityID()); answer.add(item.getEntityID());
} }
return answer.iterator(); return answer.iterator();
} }
@ -262,8 +262,7 @@ public class MultiUserChat {
final List<String> answer = new ArrayList<String>(); final List<String> answer = new ArrayList<String>();
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection); ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
DiscoverItems items = discoManager.discoverItems(connection.getServiceName()); DiscoverItems items = discoManager.discoverItems(connection.getServiceName());
for (Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext();) { for (DiscoverItems.Item item : items.getItems()) {
DiscoverItems.Item item = it.next();
DiscoverInfo info = discoManager.discoverInfo(item.getEntityID()); DiscoverInfo info = discoManager.discoverInfo(item.getEntityID());
if (info.containsFeature(discoNamespace)) { if (info.containsFeature(discoNamespace)) {
answer.add(item.getEntityID()); answer.add(item.getEntityID());
@ -289,8 +288,8 @@ public class MultiUserChat {
List<HostedRoom> answer = new ArrayList<HostedRoom>(); List<HostedRoom> answer = new ArrayList<HostedRoom>();
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection); ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
DiscoverItems items = discoManager.discoverItems(serviceName); DiscoverItems items = discoManager.discoverItems(serviceName);
for (Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext();) { for (DiscoverItems.Item item : items.getItems()) {
answer.add(new HostedRoom(it.next())); answer.add(new HostedRoom(item));
} }
return answer; return answer;
} }
@ -885,9 +884,7 @@ public class MultiUserChat {
room, room,
"x-roomuser-item"); "x-roomuser-item");
// Look for an Identity that holds the reserved nickname and return its name // Look for an Identity that holds the reserved nickname and return its name
for (Iterator<DiscoverInfo.Identity> identities = result.getIdentities(); for (DiscoverInfo.Identity identity : result.getIdentities()) {
identities.hasNext();) {
DiscoverInfo.Identity identity = identities.next();
return identity.getName(); return identity.getName();
} }
} }

View file

@ -121,8 +121,7 @@ public class OfflineMessageManager {
List<OfflineMessageHeader> answer = new ArrayList<OfflineMessageHeader>(); List<OfflineMessageHeader> answer = new ArrayList<OfflineMessageHeader>();
DiscoverItems items = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems( DiscoverItems items = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems(
null, namespace); null, namespace);
for (Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext();) { for (DiscoverItems.Item item : items.getItems()) {
DiscoverItems.Item item = it.next();
answer.add(new OfflineMessageHeader(item)); answer.add(new OfflineMessageHeader(item));
} }
return answer.iterator(); return answer.iterator();

View file

@ -171,7 +171,7 @@ final public class PubSubManager
DiscoverInfo infoReply = (DiscoverInfo) con.createPacketCollectorAndSend(info).nextResultOrThrow(); DiscoverInfo infoReply = (DiscoverInfo) con.createPacketCollectorAndSend(info).nextResultOrThrow();
if (infoReply.getIdentities().next().getType().equals(NodeType.leaf.toString())) if (infoReply.getIdentities().get(0).getType().equals(NodeType.leaf.toString()))
node = new LeafNode(con, id); node = new LeafNode(con, id);
else else
node = new CollectionNode(con, id); node = new CollectionNode(con, id);

View file

@ -28,7 +28,6 @@ import org.jivesoftware.smackx.xdata.Form;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator;
import java.util.List; import java.util.List;
/** /**
@ -105,9 +104,7 @@ public class UserSearchManager {
final List<String> searchServices = new ArrayList<String>(); final List<String> searchServices = new ArrayList<String>();
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(con); ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(con);
DiscoverItems items = discoManager.discoverItems(con.getServiceName()); DiscoverItems items = discoManager.discoverItems(con.getServiceName());
Iterator<DiscoverItems.Item> iter = items.getItems(); for (DiscoverItems.Item item : items.getItems()) {
while (iter.hasNext()) {
DiscoverItems.Item item = iter.next();
try { try {
DiscoverInfo info; DiscoverInfo info;
try { try {

View file

@ -21,7 +21,6 @@ import java.net.InetAddress;
import java.net.NetworkInterface; import java.net.NetworkInterface;
import java.net.SocketException; import java.net.SocketException;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Iterator;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NoResponseException;
@ -435,9 +434,7 @@ public class RTPBridge extends IQ {
// } // }
DiscoverInfo discoInfo = disco.discoverInfo(connection.getServiceName()); DiscoverInfo discoInfo = disco.discoverInfo(connection.getServiceName());
Iterator<DiscoverInfo.Identity> iter = discoInfo.getIdentities(); for (DiscoverInfo.Identity identity : discoInfo.getIdentities()) {
while (iter.hasNext()) {
DiscoverInfo.Identity identity = iter.next();
if ((identity.getName() != null) && (identity.getName().startsWith("rtpbridge"))) { if ((identity.getName() != null) && (identity.getName().startsWith("rtpbridge"))) {
return true; return true;
} }

View file

@ -17,7 +17,6 @@
package org.jivesoftware.smackx.jingle.nat; package org.jivesoftware.smackx.jingle.nat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -222,14 +221,10 @@ public class STUN extends IQ {
ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(connection); ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(connection);
DiscoverItems items = disco.discoverItems(connection.getServiceName()); DiscoverItems items = disco.discoverItems(connection.getServiceName());
Iterator<DiscoverItems.Item> iter = items.getItems(); for (DiscoverItems.Item item : items.getItems()) {
while (iter.hasNext()) {
DiscoverItems.Item item = iter.next();
DiscoverInfo info = disco.discoverInfo(item.getEntityID()); DiscoverInfo info = disco.discoverInfo(item.getEntityID());
Iterator<DiscoverInfo.Identity> iter2 = info.getIdentities(); for (DiscoverInfo.Identity identity : info.getIdentities()) {
while (iter2.hasNext()) {
DiscoverInfo.Identity identity = iter2.next();
if (identity.getCategory().equals("proxy") && identity.getType().equals("stun")) if (identity.getCategory().equals("proxy") && identity.getType().equals("stun"))
if (info.containsFeature(NAMESPACE)) if (info.containsFeature(NAMESPACE))
return true; return true;