From 497dd72d04902511120a03b0f66333642426be47 Mon Sep 17 00:00:00 2001 From: Cidorvan Leite Date: Thu, 15 May 2008 13:17:42 +0000 Subject: Added function for convert string to uuid128 --- common/glib-helper.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'common/glib-helper.c') diff --git a/common/glib-helper.c b/common/glib-helper.c index d43a3cf7..ef5a1d13 100644 --- a/common/glib-helper.c +++ b/common/glib-helper.c @@ -325,6 +325,42 @@ char *bt_uuid2string(uuid_t *uuid) return str; } +int bt_string2uuid(uuid_t *uuid, const char *string) +{ + uint16_t data1, data2, data3, data5; + uint32_t data0, data4; + + if (strlen(string) == 36 && + string[8] == '-' && + string[13] == '-' && + string[18] == '-' && + string[23] == '-' && + sscanf(string, "%08x-%04hx-%04hx-%04hx-%08x%04hx", + &data0, &data1, &data2, &data3, &data4, &data5) == 6) { + uint8_t val[16]; + + data0 = htonl(data0); + data1 = htons(data1); + data2 = htons(data2); + data3 = htons(data3); + data4 = htonl(data4); + data5 = htons(data5); + + memcpy(&val[0], &data0, 4); + memcpy(&val[4], &data1, 2); + memcpy(&val[6], &data2, 2); + memcpy(&val[8], &data3, 2); + memcpy(&val[10], &data4, 4); + memcpy(&val[14], &data5, 2); + + sdp_uuid128_create(uuid, val); + + return 0; + } + + return -1; +} + gchar *bt_list2string(GSList *list) { GSList *l; -- cgit