soc.2012.statscollector: 7e8830de: Add UI information

sanket at soc.pidgin.im sanket at soc.pidgin.im
Tue May 22 02:55:51 EDT 2012


----------------------------------------------------------------------
Revision: 7e8830de618c623ee27e5534743ffa8bb4ccefaf
Parent:   c255ae66ef0cdaf227e1ff863e3e150344624b42
Author:   sanket at soc.pidgin.im
Date:     05/22/12 03:49:30
Branch:   im.pidgin.soc.2012.statscollector
URL: http://d.pidgin.im/viewmtn/revision/info/7e8830de618c623ee27e5534743ffa8bb4ccefaf

Changelog: 

Add UI information

UI's are majorly Pidgin/Finch for pidgin installation but could be Instantbird,
nullclient etc for other applications running on top of libpurple. Also there
is functionality to capture if the same libpurple config is used for more than
one UI(e.g. using Pidgin/Finch together).

Currently the plugin is tested majorly for Pidgin/Finch but I need to test
it for * a null client running on top of libpurple and possibly * adium and
* instantbird.

Changes against parent c255ae66ef0cdaf227e1ff863e3e150344624b42

  patched  libpurple/plugins/statscollector.c

-------------- next part --------------
============================================================
--- libpurple/plugins/statscollector.c	0ba7b53a386db455975c38e67b0212d81b87469e
+++ libpurple/plugins/statscollector.c	95b6c16590dab258e425a0d071436aa3fd599a1c
@@ -31,8 +31,8 @@
 #define STATS_MAJOR_VERSION 1
 #define STATS_MINOR_VERSION 0
 
-xmlnode *root_stats, *cpuinfo_xml;
-GHashTable *stats_acc_ht, *stats_plugins_ht;
+xmlnode *root_stats, *cpuinfo_xml, *ui_info;
+GHashTable *stats_acc_ht, *stats_plugins_ht, *stats_uis_ht;
 int save_timer = 0;
 
 /* Types of Operating Systems */
@@ -49,7 +49,7 @@ save_xml(){
 
   GHashTableIter iter;
   gpointer key, value;
-  xmlnode *nroot, *nacc, *nplugins, *node;
+  xmlnode *nroot, *nacc, *nplugins, *nuis, *node;
   char *data;
 
   nroot = xmlnode_new("stats");
@@ -57,8 +57,12 @@ save_xml(){
   /* Load CPUinfo strucutre */
   xmlnode_insert_child(nroot, cpuinfo_xml);
 
+  /* Load UI info */
+  xmlnode_insert_child(nroot, ui_info);
+
   nacc = xmlnode_new_child(nroot, "accounts");
   nplugins = xmlnode_new_child(nroot, "plugins");
+  nuis = xmlnode_new_child(nroot, "uis");
 
   /* Use the hash tables to populate acc and plugins */
 
@@ -81,6 +85,15 @@ save_xml(){
 
   }
 
+  g_hash_table_iter_init(&iter, stats_uis_ht);
+
+  while(g_hash_table_iter_next(&iter, &key, &value)){
+
+    node = xmlnode_from_str(value, -1);
+    xmlnode_insert_child(nuis, node);
+
+  }
+
   data = xmlnode_to_formatted_str(nroot, NULL);
   purple_util_write_data_to_file("stats.xml", data, -1);
 
@@ -104,12 +117,12 @@ get_app_32_64(){
 
   /* Determines if the application is running in 32 or 64 bit mode */
   int pt_size;
-  xmlnode *bit_size;
+  xmlnode *bit_size_xml;
 
-  pt_size = sizeof(int)*8;
-  bit_size = xmlnode_new("app-bit");
-  xmlnode_insert_data(bit_size, g_strdup_printf("%d",pt_size), -1);
-  return bit_size;
+  pt_size = sizeof(int *)*8;
+  bit_size_xml = xmlnode_new("app-bit");
+  xmlnode_insert_data(bit_size_xml, g_strdup_printf("%d",pt_size), -1);
+  return bit_size_xml;
 
 }
 
@@ -447,7 +460,59 @@ get_cpuinfo_xml(){
 
 }
 
+static void
+get_ui_info(){
 
+  /* Obtains what UI and which version is being run by current client
+   * using libpurple.
+   */
+
+  GHashTable *ui_info_ht;
+  xmlnode *ui_info_xml, *ui_version_xml;
+  char *ui_name, *ui_version, *data;
+  GHashTableIter iter;
+  /* gpointer key, value; */
+
+  ui_info_ht = purple_core_get_ui_info();
+
+  ui_name = g_hash_table_lookup(ui_info_ht, "name");
+  ui_version = g_hash_table_lookup(ui_info_ht, "version");
+
+  /* If it's a null-client (?) then perhaps we should make it look like
+   * a client we don't perhaps know about!
+   */
+  if(!ui_name) ui_name = "other";
+  if(!ui_version) ui_version = "other";
+
+  /* Check if the UI info is already present in the hashtable */
+  if(g_hash_table_lookup(stats_uis_ht, ui_name)) return;
+
+  ui_info_xml = xmlnode_new("ui");
+  ui_version_xml = xmlnode_new("version");
+
+  xmlnode_set_attrib(ui_info_xml, "id", ui_name);
+  xmlnode_insert_data(ui_version_xml, ui_version, -1);
+  xmlnode_insert_child(ui_info_xml, ui_version_xml);
+
+  data = xmlnode_to_str(ui_info_xml, NULL);
+  g_hash_table_insert(stats_uis_ht, (void *)ui_name, (void *)data);
+
+  g_hash_table_iter_init(&iter, stats_uis_ht);
+
+  /* purple_debug_info("STATS UI", "starting ui info ... \\n %s: %s", ui_name, data); */
+
+  /* while(g_hash_table_iter_next(&iter, &key, &value)){ */
+
+  /*   purple_debug_info("STATS UI", "%s: %s\\n", (char *)key, (char *)value); */
+
+  /* } */
+
+  schedule_stats_save();
+
+
+}
+
+
 static const gchar *
 md5(const guchar *str)
 {
@@ -583,7 +648,7 @@ init_stats(){
   const char *id_node;
   gsize length;
   GError *error = NULL;
-  xmlnode *stats_acc_xml, *stats_plugins_xml, *root, *start;
+  xmlnode *stats_acc_xml, *stats_plugins_xml, *stats_uis_xml, *root, *start;
 
   /* Load the xml */
   filename = g_build_filename(purple_user_dir(), "stats.xml", NULL);
@@ -593,6 +658,7 @@ init_stats(){
 
   stats_acc_ht = g_hash_table_new(g_str_hash, g_str_equal);
   stats_plugins_ht = g_hash_table_new(g_str_hash, g_str_equal);
+  stats_uis_ht = g_hash_table_new(g_str_hash, g_str_equal);
 
 
   if(!root){
@@ -614,6 +680,7 @@ init_stats(){
     stats_acc_xml = xmlnode_get_child(root, "accounts");
     stats_plugins_xml = xmlnode_get_child(root, "plugins");
     cpuinfo_xml = xmlnode_get_child(root, "cpuinfo");
+    stats_uis_xml = xmlnode_get_child(root, "uis");
 
     purple_debug_info("STATS", "Accounts: %s", xmlnode_to_formatted_str(stats_acc_xml, NULL));
 
@@ -629,6 +696,7 @@ init_stats(){
 
     }
 
+    start = xmlnode_get_child(stats_plugins_xml, "plugin");
 
     for(;start;start = xmlnode_get_next_twin(start)){
 
@@ -639,7 +707,18 @@ init_stats(){
 
     }
 
+    start = xmlnode_get_child(stats_uis_xml, "ui");
 
+    for(;start;start = xmlnode_get_next_twin(start)){
+
+      id_node = xmlnode_get_attrib((const xmlnode *)start, "id");
+
+      g_hash_table_insert(stats_uis_ht, (gpointer)id_node,
+          (char *)xmlnode_to_formatted_str(start, NULL));
+
+    }
+
+
   }
 
   /* It's a good idea to get all loaded plugins and insert them
@@ -651,7 +730,12 @@ init_stats(){
 
   g_list_foreach(loaded_plugins, (GFunc)plugin_load_event, NULL);
 
+  /* The newly loaded UI might be different from what the user used
+   * last time. It's a good idea to note the UI down because this'll be
+   * required only once -- we should probably do it here itself
+   */
 
+  get_ui_info();
 
   /* Return the structure for modification */
   return root;


More information about the Commits mailing list