From d3060a3bd649451cb7c20f0aa2f860ae1aa13c25 Mon Sep 17 00:00:00 2001 From: akwizgran <akwizgran@users.sourceforge.net> Date: Fri, 28 Oct 2011 16:46:51 +0100 Subject: [PATCH] Class IDs may be in nested lists. Don't ask me why. --- .../plugins/bluetooth/AbstractListener.java | 15 +++++++++ .../plugins/bluetooth/ContactListener.java | 25 ++++++--------- .../plugins/bluetooth/InvitationListener.java | 32 +++++++------------ 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/components/net/sf/briar/plugins/bluetooth/AbstractListener.java b/components/net/sf/briar/plugins/bluetooth/AbstractListener.java index 171afa4ba7..e367d51874 100644 --- a/components/net/sf/briar/plugins/bluetooth/AbstractListener.java +++ b/components/net/sf/briar/plugins/bluetooth/AbstractListener.java @@ -1,10 +1,14 @@ package net.sf.briar.plugins.bluetooth; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; import java.util.concurrent.atomic.AtomicInteger; import javax.bluetooth.DataElement; import javax.bluetooth.DiscoveryAgent; import javax.bluetooth.DiscoveryListener; +import javax.bluetooth.UUID; abstract class AbstractListener implements DiscoveryListener { @@ -46,4 +50,15 @@ abstract class AbstractListener implements DiscoveryListener { } return null; } + + protected void findNestedClassIds(Object o, Collection<String> ids) { + o = getDataElementValue(o); + if(o instanceof Enumeration) { + for(Object o1 : Collections.list((Enumeration<?>) o)) { + findNestedClassIds(o1, ids); + } + } else if(o instanceof UUID) { + ids.add(o.toString()); + } + } } diff --git a/components/net/sf/briar/plugins/bluetooth/ContactListener.java b/components/net/sf/briar/plugins/bluetooth/ContactListener.java index e25493506e..daf546ce3f 100644 --- a/components/net/sf/briar/plugins/bluetooth/ContactListener.java +++ b/components/net/sf/briar/plugins/bluetooth/ContactListener.java @@ -1,14 +1,14 @@ package net.sf.briar.plugins.bluetooth; +import java.util.Collection; import java.util.Collections; -import java.util.Enumeration; import java.util.HashMap; import java.util.Map; +import java.util.TreeSet; import java.util.logging.Level; import java.util.logging.Logger; import javax.bluetooth.BluetoothStateException; -import javax.bluetooth.DataElement; import javax.bluetooth.DeviceClass; import javax.bluetooth.DiscoveryAgent; import javax.bluetooth.RemoteDevice; @@ -76,21 +76,14 @@ class ContactListener extends AbstractListener { ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false); if(serviceUrl == null) continue; // Does this service have the UUID we're looking for? - DataElement classIds = record.getAttributeValue(0x1); - Object o = getDataElementValue(classIds); - if(o instanceof Enumeration) { - Enumeration<?> e = (Enumeration<?>) o; - for(Object o1 : Collections.list(e)) { - Object o2 = getDataElementValue(o1); - if(o2 instanceof UUID) { - UUID serviceUuid = (UUID) o2; - if(uuid.equalsIgnoreCase(serviceUuid.toString())) { - // The UUID matches - store the URL - urls.put(c, serviceUrl); - } - } + Collection<String> uuids = new TreeSet<String>(); + findNestedClassIds(record.getAttributeValue(0x1), uuids); + for(String u : uuids) { + if(uuid.equalsIgnoreCase(u.toString())) { + // The UUID matches - store the URL + urls.put(c, serviceUrl); } } } } -} +} \ No newline at end of file diff --git a/components/net/sf/briar/plugins/bluetooth/InvitationListener.java b/components/net/sf/briar/plugins/bluetooth/InvitationListener.java index 9ed9f10c19..01663b99d2 100644 --- a/components/net/sf/briar/plugins/bluetooth/InvitationListener.java +++ b/components/net/sf/briar/plugins/bluetooth/InvitationListener.java @@ -1,12 +1,11 @@ package net.sf.briar.plugins.bluetooth; -import java.util.Collections; -import java.util.Enumeration; +import java.util.Collection; +import java.util.TreeSet; import java.util.logging.Level; import java.util.logging.Logger; import javax.bluetooth.BluetoothStateException; -import javax.bluetooth.DataElement; import javax.bluetooth.DeviceClass; import javax.bluetooth.DiscoveryAgent; import javax.bluetooth.RemoteDevice; @@ -56,23 +55,16 @@ class InvitationListener extends AbstractListener { ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false); if(serviceUrl == null) continue; // Does this service have the UUID we're looking for? - DataElement classIds = record.getAttributeValue(0x1); - Object o = getDataElementValue(classIds); - if(o instanceof Enumeration) { - Enumeration<?> e = (Enumeration<?>) o; - for(Object o1 : Collections.list(e)) { - Object o2 = getDataElementValue(o1); - if(o2 instanceof UUID) { - UUID serviceUuid = (UUID) o2; - if(uuid.equalsIgnoreCase(serviceUuid.toString())) { - // The UUID matches - store the URL - synchronized(this) { - url = serviceUrl; - finished = true; - notifyAll(); - return; - } - } + Collection<String> uuids = new TreeSet<String>(); + findNestedClassIds(record.getAttributeValue(0x1), uuids); + for(String u : uuids) { + if(uuid.equalsIgnoreCase(u)) { + // The UUID matches - store the URL + synchronized(this) { + url = serviceUrl; + finished = true; + notifyAll(); + return; } } } -- GitLab