1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-17 04:32:04 +01:00

Some small refactoring to handle the rare case when a disco request may return an unknown response and could cause an NPE.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@4624 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Alex Wenckus 2006-07-20 17:17:19 +00:00 committed by alex
parent 47abf627b7
commit 201d36e4d1

View file

@ -86,9 +86,9 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
private final XMPPConnection connection;
private List proxies;
private List<String> proxies;
private List streamHosts;
private List<String> streamHosts;
// locks the proxies during their initialization process
private final Object proxyLock = new Object();
@ -473,32 +473,49 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
return bs;
}
private void initProxies() {
proxies = new ArrayList();
ServiceDiscoveryManager manager = ServiceDiscoveryManager
.getInstanceFor(connection);
DiscoverItems discoItems;
try {
discoItems = manager.discoverItems(connection.getServiceName());
DiscoverItems.Item item;
/**
* Checks the service discovery item returned from a server component to verify if it is
* a File Transfer proxy or not.
*
* @param manager the service discovery manager which will be used to query the component
* @param item the discovered item on the server relating
* @return returns the JID of the proxy if it is a proxy or null if the item is not a proxy.
*/
private String checkIsProxy(ServiceDiscoveryManager manager, Item item) {
DiscoverInfo info;
DiscoverInfo.Identity identity;
Iterator it = discoItems.getItems();
while (it.hasNext()) {
item = (Item) it.next();
try {
info = manager.discoverInfo(item.getEntityID());
}
catch (XMPPException e) {
return null;
}
Iterator itx = info.getIdentities();
while (itx.hasNext()) {
identity = (Identity) itx.next();
if (identity.getCategory().equalsIgnoreCase("proxy")
&& identity.getType().equalsIgnoreCase(
"bytestreams")) {
proxies.add(info.getFrom());
DiscoverInfo.Identity identity = (Identity) itx.next();
if ("proxy".equalsIgnoreCase(identity.getCategory())
&& "bytestreams".equalsIgnoreCase(
identity.getType())) {
return info.getFrom();
}
}
return null;
}
private void initProxies() {
proxies = new ArrayList<String>();
ServiceDiscoveryManager manager = ServiceDiscoveryManager
.getInstanceFor(connection);
try {
DiscoverItems discoItems = manager.discoverItems(connection.getServiceName());
Iterator it = discoItems.getItems();
while (it.hasNext()) {
DiscoverItems.Item item = (Item) it.next();
String proxy = checkIsProxy(manager, item);
if(proxy != null) {
proxies.add(proxy);
}
}
}
catch (XMPPException e) {
@ -507,7 +524,6 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
if (proxies.size() > 0) {
initStreamHosts();
}
}
private void initStreamHosts() {