diff options
author | Michael Janssen <jamuraa@chromium.org> | 2014-12-09 15:08:33 -0800 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2014-12-10 09:54:23 +0200 |
commit | e5af5138b1531ef28fe30423d8dc6b5f9649dadb (patch) | |
tree | 1da892ca8763dd002fa51d3c4382d571415bb4c9 /lib/uuid.c | |
parent | 20dd67fd18a2e2bebbc7e5e4a76ff41133741e96 (diff) | |
download | bluez-e5af5138b1531ef28fe30423d8dc6b5f9649dadb.tar.gz |
lib/uuid: Simplify BT base UUIDs when possible
When converting a UUID from string to bt_uuid_t, prefer using
the 16-bit version when possible, which should generate shorter
sequences by increasing the number of 16-bit types.
Diffstat (limited to 'lib/uuid.c')
-rw-r--r-- | lib/uuid.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/uuid.c b/lib/uuid.c index 186a7e652..e3f31df94 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -190,6 +190,19 @@ static inline int is_uuid128(const char *string) string[23] == '-'); } +static inline int is_base_uuid128(const char *string) +{ + uint16_t uuid; + char dummy; + + if (!is_uuid128(string)) + return 0; + + return sscanf(string, + "0000%04hx-0000-1000-8000-00805%1[fF]9%1[bB]34%1[fF]%1[bB]", + &uuid, &dummy, &dummy, &dummy, &dummy) == 5; +} + static inline int is_uuid32(const char *string) { return (strlen(string) == 8 || strlen(string) == 10); @@ -206,7 +219,7 @@ static int bt_string_to_uuid16(bt_uuid_t *uuid, const char *string) char *endptr = NULL; u16 = strtol(string, &endptr, 16); - if (endptr && *endptr == '\0') { + if (endptr && (*endptr == '\0' || *endptr == '-')) { bt_uuid16_create(uuid, u16); return 0; } @@ -261,7 +274,9 @@ static int bt_string_to_uuid128(bt_uuid_t *uuid, const char *string) int bt_string_to_uuid(bt_uuid_t *uuid, const char *string) { - if (is_uuid128(string)) + if (is_base_uuid128(string)) + return bt_string_to_uuid16(uuid, string + 4); + else if (is_uuid128(string)) return bt_string_to_uuid128(uuid, string); else if (is_uuid32(string)) return bt_string_to_uuid32(uuid, string); |