/soc/2012/sanket/statscollector-2.x.y: 85dd9a57d1dd: [BUGFIX] Re...
Sanket Agarwal
sanket at soc.pidgin.im
Sun Aug 26 17:17:59 EDT 2012
Changeset: 85dd9a57d1dd5876c8c8a8a2e0aca3a7e1d13ba2
Author: Sanket Agarwal <sanket at soc.pidgin.im>
Date: 2012-08-25 10:47 +0530
Branch: soc.2012.statscollector
URL: http://hg.pidgin.im/soc/2012/sanket/statscollector-2.x.y/rev/85dd9a57d1dd
Description:
[BUGFIX] Refactor/Fix version mismatch logic
A rather mischievous bug! I am still unable to understand the root cause,
but it led to multiple seg-faults by quiting init_stats() function mysteriously
early! Refactoring it fixed the bug.
diffstat:
libpurple/plugins/statscollector.c | 51 ++++++++++++++-----------------------
1 files changed, 19 insertions(+), 32 deletions(-)
diffs (99 lines):
diff --git a/libpurple/plugins/statscollector.c b/libpurple/plugins/statscollector.c
--- a/libpurple/plugins/statscollector.c
+++ b/libpurple/plugins/statscollector.c
@@ -48,8 +48,7 @@ enum
/* Version of XML this plugin supports writing */
-#define STATS_XML_MAJOR_V "0" /* 0 -- Dev purposes */
-#define STATS_XML_MINOR_V "1"
+#define STATS_XML_V "0.1" /* 0 -- Dev purposes */
/* 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
@@ -133,8 +132,7 @@ save_xml(){
nroot = xmlnode_new("stats");
/* Set the string information */
- version = g_strdup_printf("%s.%s", STATS_XML_MAJOR_V,\
- STATS_XML_MINOR_V);
+ version = g_strdup_printf("%s", STATS_XML_V);
xmlnode_set_attrib(nroot, "version", version);
/* Load CPUinfo strucutre */
@@ -1022,6 +1020,21 @@ schedule_send(){
send_handle = purple_timeout_add_seconds(time_to_send, send_stats, NULL);
}
+static gboolean
+check_version(char *v){
+
+ /* Checks if the current stats.xml
+ * version matches plugin version
+ * Useful if a client upgrades his
+ * plugin
+ */
+ if(!v || g_strcmp0(v, STATS_XML_V)){
+ purple_debug_info("STATS", "resetting XML file due to version ...");
+ return TRUE;
+ }
+ return FALSE;
+}
+
static xmlnode *
@@ -1038,12 +1051,9 @@ init_stats(){
const gchar *filename;
gchar *file_contents;
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);
@@ -1061,28 +1071,7 @@ init_stats(){
root = xmlnode_from_str(file_contents, -1);
- 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){
+ if(!root || check_version(version)==TRUE){
/* Reset the XML if it does not exist or is corrupt or version mismatch */
purple_debug_info("STATS", "failed to load stats.xml");
@@ -1091,9 +1080,7 @@ init_stats(){
cpuinfo_xml = get_cpuinfo_xml();
schedule_stats_save();
- }
-
- else{
+ } else {
/* Populate the hash tables with account and plugin information */
More information about the Commits
mailing list