changeset 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 739886e6dac2
children c52dbc5503d0 fd2afe1b2d3c
files ChangeLog.API libpurple/protocols/jabber/google.c libpurple/util.c libpurple/util.h
diffstat 4 files changed, 32 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Mon Oct 12 22:40:37 2009 +0000
+++ b/ChangeLog.API	Tue Oct 13 22:13:57 2009 +0000
@@ -5,6 +5,7 @@
 		Added:
 		* purple_account_get_name_for_display
 		* purple_network_get_all_local_system_ips
+		* purple_uuid_random
 	
 	Pidgin:
 		Added:
--- a/libpurple/protocols/jabber/google.c	Mon Oct 12 22:40:37 2009 +0000
+++ b/libpurple/protocols/jabber/google.c	Tue Oct 13 22:13:57 2009 +0000
@@ -1434,7 +1434,7 @@
 	JabberStream *js;
 	JabberChat *chat;
 	gchar *room;
-	guint32 tmp, a, b;
+	gchar *uuid = purple_uuid_random();
 
 	g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
 
@@ -1443,20 +1443,7 @@
 	g_return_if_fail(gc != NULL);
 	js = purple_connection_get_protocol_data(gc);
 
-	/* Generate a version 4 UUID */
-	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();
-	room = g_strdup_printf("private-chat-%08x-%04x-%04x-%04x-%04x%08x",
-			g_random_int(),
-			tmp & 0xFFFF,
-			a,
-			b,
-			(tmp >> 16) & 0xFFFF, g_random_int());
-
+	room = g_strdup_printf("private-chat-%s", uuid);	
 	chat = jabber_join_chat(js, room, GOOGLE_GROUPCHAT_SERVER, js->user->node,
 	                        NULL, NULL);
 	if (chat) {
@@ -1465,4 +1452,5 @@
 	}
 
 	g_free(room);
+	g_free(uuid);
 }
--- 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());
+}
--- a/libpurple/util.h	Mon Oct 12 22:40:37 2009 +0000
+++ b/libpurple/util.h	Tue Oct 13 22:13:57 2009 +0000
@@ -1427,6 +1427,14 @@
  */
 const gchar *purple_get_host_name(void);
 
+/**
+ * Returns a type 4 (random) UUID
+ *
+ * @return A UUID, caller is responsible for freeing it
+ * @since 2.7.0
+ */
+gchar *purple_uuid_random(void);
+
 #ifdef __cplusplus
 }
 #endif