pidgin.next.minor: fa239a2e: Broke out the generation of random UUIDs...

malu at pidgin.im malu at pidgin.im
Tue Oct 13 18:17:03 EDT 2009


-----------------------------------------------------------------
Revision: fa239a2e49b49a05b3c8612ea2e2580e7286ac63
Ancestor: cee1a20c0e0c9fd6b198dae6c651b79846a70d19
Author: malu at pidgin.im
Date: 2009-10-13T22:13:57
Branch: im.pidgin.pidgin.next.minor
URL: http://d.pidgin.im/viewmtn/revision/info/fa239a2e49b49a05b3c8612ea2e2580e7286ac63

Modified files:
        ChangeLog.API libpurple/protocols/jabber/google.c
        libpurple/util.c libpurple/util.h

ChangeLog: 

Broke out the generation of random UUIDs to its own function
Adapted the Google group chat functionallity to use the new function

-------------- next part --------------
============================================================
--- ChangeLog.API	0cb42baa7b00db484a3314cd818f5cb7fc501fa4
+++ ChangeLog.API	4aaa95cf4bc660d9618a05eaf4daf2dcd40bf4b7
@@ -5,6 +5,7 @@ version 2.7.0 (??/??/????):
 		Added:
 		* purple_account_get_name_for_display
 		* purple_network_get_all_local_system_ips
+		* purple_uuid_random
 	
 	Pidgin:
 		Added:
============================================================
--- libpurple/protocols/jabber/google.c	2d90472f0343782c63ff6571fbe909e94072481a
+++ libpurple/protocols/jabber/google.c	0b966ac285ec1ea2a078d962e24a00005104467d
@@ -1434,7 +1434,7 @@ void google_buddy_node_chat(PurpleBlistN
 	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 @@ void google_buddy_node_chat(PurpleBlistN
 	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 @@ void google_buddy_node_chat(PurpleBlistN
 	}
 
 	g_free(room);
+	g_free(uuid);
 }
============================================================
--- libpurple/util.c	0f7aa59024a5a704ab0d827492e664e94c9f0139
+++ libpurple/util.c	7e100145f69aa203378691815073e1ce129ef422
@@ -4973,3 +4973,23 @@ purple_get_host_name(void)
 {
 	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());
+}
============================================================
--- libpurple/util.h	274bc7b30331d9ecde19c7af243be947462b545f
+++ libpurple/util.h	ff9e1117c2eca2a965358678ee2a87712ada89bc
@@ -1427,6 +1427,14 @@ const gchar *purple_get_host_name(void);
  */
 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


More information about the Commits mailing list