soc.2012.statscollector: 0c3d2c6f: Add version to stats.xml; reset XML if v...

sanket at soc.pidgin.im sanket at soc.pidgin.im
Sun Jun 10 02:42:10 EDT 2012


----------------------------------------------------------------------
Revision: 0c3d2c6f01fda956f65a0467ecbe5f145dfa4dd4
Parent:   06d63da16f8eb512947f3d4d2a3de2ceef06e453
Author:   sanket at soc.pidgin.im
Date:     06/09/12 14:08:02
Branch:   im.pidgin.soc.2012.statscollector
URL: http://d.pidgin.im/viewmtn/revision/info/0c3d2c6f01fda956f65a0467ecbe5f145dfa4dd4

Changelog: 

Add version to stats.xml; reset XML if version mismatch

We might be updating the stats file often(specially in the initial stages)
hence it's a good idea to reset the XML if the ``plugin'' installed supports
a different version of the XML. Though this makes life of the server all the
more difficult ;-).

Changes against parent 06d63da16f8eb512947f3d4d2a3de2ceef06e453

  patched  libpurple/plugins/statscollector.c

-------------- next part --------------
============================================================
--- libpurple/plugins/statscollector.c	a7dd7b2dfcf5c36844c2b88e1a7dbe02da924f79
+++ libpurple/plugins/statscollector.c	92590e287ff4b9388d1d9033784c3bc9c474ba82
@@ -33,6 +33,11 @@
 /* Sending URL */
 #define SEND_URL "http://pidgin-stats.alwaysdata.net/collectstats/collect/"
 
+/* Version of XML this plugin supports writing */
+
+#define STATS_XML_MAJOR_V "1"
+#define STATS_XML_MINOR_V "0"
+
 /* POSIX compliance is an issue that I have looked into some detail now
  * It seems like presence of unistd.h and _POSIX_VERSION being defined
  * confirms the presence of POSIX compliance. For this ofcourse we need
@@ -46,9 +51,6 @@
 # include <dlfcn.h>
 #endif
 
-#define STATS_MAJOR_VERSION 1
-#define STATS_MINOR_VERSION 0
-
 xmlnode *root_stats, *cpuinfo_xml, *ui_info;
 GHashTable *stats_acc_ht, *stats_plugins_ht, *stats_uis_ht;
 int save_timer = 0, send_handle = 0;
@@ -81,10 +83,15 @@ save_xml(){
   GHashTableIter iter;
   gpointer key, value;
   xmlnode *nroot, *nacc, *nplugins, *nuis, *node;
-  char *data;
+  char *data, *version;
 
   nroot = xmlnode_new("stats");
 
+  /* Set the string information */
+  version = g_strdup_printf("%s.%s", STATS_XML_MAJOR_V,\
+      STATS_XML_MINOR_V);
+  xmlnode_set_attrib(nroot, "version", version);
+
   /* Load CPUinfo strucutre */
   xmlnode_insert_child(nroot, cpuinfo_xml);
 
@@ -876,26 +883,54 @@ init_stats(){
   GList *loaded_plugins, *loaded_accounts;
   const gchar *filename;
   gchar *file_contents;
-  const char *id_node;
+  const char *id_node, *version;
+  char *major_v=NULL, *minor_v=NULL;
+  char **split_parts;
   gsize length;
   GError *error = NULL;
   xmlnode *stats_acc_xml, *stats_plugins_xml, *stats_uis_xml, *root, *start;
+  int reset_xml = 0;
 
   /* Load the xml */
   filename = g_build_filename(purple_user_dir(), "stats.xml", NULL);
   g_file_get_contents(filename, &file_contents, &length, &error);
-  purple_debug_info("STATS", "%s", file_contents);
-  root = xmlnode_from_str(file_contents, -1);
 
+  /* Initialize basic data-strcutures */
   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);
 
+  /* Check if the version is compatible with the plugin,
+   * this should generally change when we install a new
+   * version of the plugin
+   */
 
-  if(!root){
+  root = xmlnode_from_str(file_contents, -1);
 
-    /* Reset the XML if it does not exist or is corrupt */
+  if(root){
 
+    version = xmlnode_get_attrib((const xmlnode *)root, "version");
+
+    if(!version || !g_strcmp0(version, "")) reset_xml = 1;
+    else{
+
+      split_parts = g_strsplit(version, ".",10);
+      if(split_parts[0] && split_parts[1]){
+        major_v = g_strsplit(version, ".",10)[0];
+        minor_v = g_strsplit(version, ".",10)[1];
+      }
+
+      if(major_v && minor_v && (g_strcmp0(major_v, STATS_XML_MAJOR_V) \
+        || g_strcmp0(minor_v, STATS_XML_MINOR_V))){
+        reset_xml = 1;
+        purple_debug_info("STATS", "resetting XML file due to version ...");
+      }
+    }
+  }
+
+  if(!root || reset_xml){
+
+    /* Reset the XML if it does not exist or is corrupt or version mismatch */
     purple_debug_info("STATS", "failed to load stats.xml");
 
     /* Populate CPU info only on start as this will not change often */


More information about the Commits mailing list