From 1e32e38099383b442b48d5f8b61142226269dde0 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 29 Oct 2008 23:18:06 +0200 Subject: Fix duplicate UUID detection The original code didn't work because the continue statement in the innermost for-loop was supposed to act on the outer for-loop (which it obviously doesn't do). --- src/device.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/device.c b/src/device.c index 27e0ef25..95fec822 100644 --- a/src/device.c +++ b/src/device.c @@ -1107,6 +1107,26 @@ done: search_cb(recs, err, user_data); } +static gboolean is_in_uuid_list(const char *uuid) +{ + uint16_t uuid16; + int j; + + /* Check for Bluetooth UUID-16 */ + if (strlen(uuid) != 36 || strncmp(uuid, "0000", 4) || + strcasecmp(uuid + 8, "-0000-1000-8000-00805F9B34FB")) + return FALSE; + + uuid16 = strtol(uuid, NULL, 16); + + for (j = 0; uuid_list[j]; j++) { + if (uuid16 == uuid_list[j]) + return TRUE; + } + + return FALSE; +} + static void init_browse(struct browse_req *req, gboolean reverse) { GSList *l; @@ -1117,21 +1137,11 @@ static void init_browse(struct browse_req *req, gboolean reverse) for (i = 0; driver->uuids[i]; i++) { char *uuid; - int j; - - /* Eliminate duplicates of UUIDs in uuid_list[]... */ - if (strlen(driver->uuids[i]) == 36 && - !strncmp(driver->uuids[i], "0000", 4) && - !strcasecmp(driver->uuids[i] + 8, - "-0000-1000-8000-00805F9B34FB")) { - uint16_t uuid16 = strtol(driver->uuids[i], - NULL, 16); - for (j = 0; uuid_list[j]; j++) { - if (uuid16 == uuid_list[j]) - continue; - } - } + /* Check for duplicates in our default UUID list */ + if (is_in_uuid_list(driver->uuids[i])) + continue; + /* ... and of UUIDs another driver already asked for */ if (g_slist_find_custom(req->uuids, driver->uuids[i], (GCompareFunc) strcasecmp)) -- cgit