/soc/2012/sanket/statscollector-2.x.y: fde24faad6a6: Add version...

Sanket Agarwal sanket at soc.pidgin.im
Tue Jul 10 00:36:27 EDT 2012


Changeset: fde24faad6a60ac47fed5803e7366f365e588b7a
Author:	 Sanket Agarwal <sanket at soc.pidgin.im>
Date:	 2012-06-09 18:08 +0000
Branch:	 soc.2012.statscollector
URL: http://hg.pidgin.im/soc/2012/sanket/statscollector-2.x.y/rev/fde24faad6a6

Description:

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 ;-).

diffstat:

 libpurple/plugins/statscollector.c |  53 +++++++++++++++++++++++++++++++------
 1 files changed, 44 insertions(+), 9 deletions(-)

diffs (102 lines):

diff --git a/libpurple/plugins/statscollector.c b/libpurple/plugins/statscollector.c
--- a/libpurple/plugins/statscollector.c
+++ b/libpurple/plugins/statscollector.c
@@ -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 @@
   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 @@
   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