diff libpurple/util.c @ 29523:ecd2136ff818

Broke out the generation of random UUIDs to its own function Adapted the Google group chat functionallity to use the new function
author Marcus Lundblad <ml@update.uu.se>
date Tue, 13 Oct 2009 22:13:57 +0000
parents 057372f5c319
children 422889fb57e0
line wrap: on
line diff
--- a/libpurple/util.c	Mon Oct 12 22:40:37 2009 +0000
+++ b/libpurple/util.c	Tue Oct 13 22:13:57 2009 +0000
@@ -4973,3 +4973,23 @@
 {
 	return g_get_host_name();
 }
+
+gchar *
+purple_uuid_random(void)
+{
+	guint32 tmp, a, b;
+
+	tmp = g_random_int();
+	a = 0x4000 | (tmp & 0xFFF); /* 0x4000 to 0x4FFF */
+	tmp >>= 12;
+	b = ((1 << 3) << 12) | (tmp & 0x3FFF); /* 0x8000 to 0xBFFF */
+
+	tmp = g_random_int();
+
+	return g_strdup_printf("%08x-%04x-%04x-%04x-%04x%08x",
+			g_random_int(),
+			tmp & 0xFFFF,
+			a,
+			b,
+			(tmp >> 16) & 0xFFFF, g_random_int());
+}