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:
parent
47abf627b7
commit
201d36e4d1
1 changed files with 38 additions and 22 deletions
|
@ -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,31 +473,48 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
|
||||||
return bs;
|
return bs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
try {
|
||||||
|
info = manager.discoverInfo(item.getEntityID());
|
||||||
|
}
|
||||||
|
catch (XMPPException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Iterator itx = info.getIdentities();
|
||||||
|
while (itx.hasNext()) {
|
||||||
|
DiscoverInfo.Identity identity = (Identity) itx.next();
|
||||||
|
if ("proxy".equalsIgnoreCase(identity.getCategory())
|
||||||
|
&& "bytestreams".equalsIgnoreCase(
|
||||||
|
identity.getType())) {
|
||||||
|
return info.getFrom();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private void initProxies() {
|
private void initProxies() {
|
||||||
proxies = new ArrayList();
|
proxies = new ArrayList<String>();
|
||||||
ServiceDiscoveryManager manager = ServiceDiscoveryManager
|
ServiceDiscoveryManager manager = ServiceDiscoveryManager
|
||||||
.getInstanceFor(connection);
|
.getInstanceFor(connection);
|
||||||
|
|
||||||
DiscoverItems discoItems;
|
|
||||||
try {
|
try {
|
||||||
discoItems = manager.discoverItems(connection.getServiceName());
|
DiscoverItems discoItems = manager.discoverItems(connection.getServiceName());
|
||||||
|
|
||||||
DiscoverItems.Item item;
|
|
||||||
DiscoverInfo info;
|
|
||||||
DiscoverInfo.Identity identity;
|
|
||||||
|
|
||||||
Iterator it = discoItems.getItems();
|
Iterator it = discoItems.getItems();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
item = (Item) it.next();
|
DiscoverItems.Item item = (Item) it.next();
|
||||||
info = manager.discoverInfo(item.getEntityID());
|
String proxy = checkIsProxy(manager, item);
|
||||||
Iterator itx = info.getIdentities();
|
if(proxy != null) {
|
||||||
while (itx.hasNext()) {
|
proxies.add(proxy);
|
||||||
identity = (Identity) itx.next();
|
|
||||||
if (identity.getCategory().equalsIgnoreCase("proxy")
|
|
||||||
&& identity.getType().equalsIgnoreCase(
|
|
||||||
"bytestreams")) {
|
|
||||||
proxies.add(info.getFrom());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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() {
|
||||||
|
|
Loading…
Reference in a new issue