1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-09-29 11:19:34 +02: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 final XMPPConnection connection;
private List proxies; private List<String> proxies;
private List streamHosts; private List<String> streamHosts;
// locks the proxies during their initialization process // locks the proxies during their initialization process
private final Object proxyLock = new Object(); private final Object proxyLock = new Object();
@ -473,32 +473,49 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
return bs; 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 info;
DiscoverInfo.Identity identity; try {
Iterator it = discoItems.getItems();
while (it.hasNext()) {
item = (Item) it.next();
info = manager.discoverInfo(item.getEntityID()); info = manager.discoverInfo(item.getEntityID());
}
catch (XMPPException e) {
return null;
}
Iterator itx = info.getIdentities(); Iterator itx = info.getIdentities();
while (itx.hasNext()) { while (itx.hasNext()) {
identity = (Identity) itx.next(); DiscoverInfo.Identity identity = (Identity) itx.next();
if (identity.getCategory().equalsIgnoreCase("proxy") if ("proxy".equalsIgnoreCase(identity.getCategory())
&& identity.getType().equalsIgnoreCase( && "bytestreams".equalsIgnoreCase(
"bytestreams")) { identity.getType())) {
proxies.add(info.getFrom()); 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) { catch (XMPPException e) {
@ -507,7 +524,6 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
if (proxies.size() > 0) { if (proxies.size() > 0) {
initStreamHosts(); initStreamHosts();
} }
} }
private void initStreamHosts() { private void initStreamHosts() {