summaryrefslogtreecommitdiffstats
path: root/common/glib-helper.c
diff options
context:
space:
mode:
authorCidorvan Leite <cidorvan.leite@openbossa.org>2008-05-15 13:17:42 +0000
committerCidorvan Leite <cidorvan.leite@openbossa.org>2008-05-15 13:17:42 +0000
commit497dd72d04902511120a03b0f66333642426be47 (patch)
tree87dc38b0f1bfb0981e1f862a27d248408d2e9f89 /common/glib-helper.c
parent165b6e46b5524e2ed623925fa45d80d11032e716 (diff)
Added function for convert string to uuid128
Diffstat (limited to 'common/glib-helper.c')
-rw-r--r--common/glib-helper.c36
1 files changed, 36 insertions, 0 deletions
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;