soc.2012.statscollector: 40203f38: Use inbuilt purple_uuid_random instead o...

sanket at soc.pidgin.im sanket at soc.pidgin.im
Wed Jun 6 02:55:52 EDT 2012


----------------------------------------------------------------------
Revision: 40203f3815406470eeb9cf929110145988887f66
Parent:   2a1ab2bc9b3cbe244cca1f0ba363686700649292
Author:   sanket at soc.pidgin.im
Date:     06/05/12 13:50:35
Branch:   im.pidgin.soc.2012.statscollector
URL: http://d.pidgin.im/viewmtn/revision/info/40203f3815406470eeb9cf929110145988887f66

Changelog: 

Use inbuilt purple_uuid_random instead of own implementation

I was too naive to be using a hand woven (and rather clumsy) implementation
of creating a 128bit random string. Pidgin already has an implementation of
uuid4 random generation.

Changes against parent 2a1ab2bc9b3cbe244cca1f0ba363686700649292

  patched  libpurple/plugins/statscollector.c

-------------- next part --------------
============================================================
--- libpurple/plugins/statscollector.c	5420093ae4545f16f443ad91c9c307df0e829f59
+++ libpurple/plugins/statscollector.c	5d94dc5ae6a12d2cbbb35a766e96c8d4e1c04303
@@ -69,33 +69,6 @@ get_time_sec(){
 
 }
 
-static char *
-rand_md5(){
-
-  char e[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
-  char *rand_str;
-  int i;
-  GTimeVal time;
-
-  g_get_current_time(&time);
-
-  /* Creates a random MD5 (16bytes) string */
-  rand_str = (char *)g_new0(char, 16*2+1);
-
-  /* Initialize the seed */
-  srand(time.tv_sec * time.tv_usec);
-
-  /* Randomly fill it */
-  for(i=0;i<32;i++){
-    rand_str[i] = e[rand()%16];
-  }
-
-  rand_str[i] = '\0';
-
-  return rand_str;
-
-}
-
 static void
 save_xml(){
 
@@ -993,7 +966,12 @@ init_plugin(PurplePlugin *plugin)
   purple_prefs_add_int("/plugins/core/statscollector/last-sent", 0);
 
   /* A random 16 byte string for identifying unique machines */
-  purple_prefs_add_string("/plugins/core/statscollector/send-key", rand_md5());
+  /* Unsure whether rand() is called when pidgin initializes
+   * it on startup
+   */
+  g_rand_new_with_seed(time(NULL));
+  purple_prefs_add_string("/plugins/core/statscollector/send-key", \
+      purple_uuid_random());
 }
 
 PURPLE_INIT_PLUGIN(statscollector, init_plugin, info)


More information about the Commits mailing list