/soc/2013/ankitkv/gobjectification: 43047b8c0fa8: Update version...
Ankit Vani
a at nevitus.org
Sun Jan 19 20:40:56 EST 2014
Changeset: 43047b8c0fa8ca85fea4aac99e3908f676cca5d0
Author: Ankit Vani <a at nevitus.org>
Date: 2014-01-20 07:08 +0530
Branch: soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/43047b8c0fa8
Description:
Update versions of XML files to "1.1", and warn if reading from a newer version
diffstat:
ChangeLog.API | 1 +
libpurple/accounts.c | 10 +++++++++-
libpurple/buddylist.c | 10 +++++++++-
libpurple/prefs.c | 22 ++++++++++++++++++----
libpurple/prefs.h | 5 -----
libpurple/savedstatuses.c | 10 +++++++++-
6 files changed, 46 insertions(+), 12 deletions(-)
diffs (216 lines):
diff --git a/ChangeLog.API b/ChangeLog.API
--- a/ChangeLog.API
+++ b/ChangeLog.API
@@ -457,6 +457,7 @@ version 3.0.0 (??/??/????):
* purple_plugins_unload_all
* purple_pounces_load
* purple_prefs_set_generic
+ * purple_prefs_update_old
* purple_presence_add_status
* purple_presence_add_list
* PurplePresenceContext
diff --git a/libpurple/accounts.c b/libpurple/accounts.c
--- a/libpurple/accounts.c
+++ b/libpurple/accounts.c
@@ -32,6 +32,8 @@
#include "network.h"
#include "pounce.h"
+#define ACCOUNTS_XML_VERSION "1.1"
+
static PurpleAccountUiOps *account_ui_ops = NULL;
static GList *accounts = NULL;
@@ -48,7 +50,7 @@ accounts_to_xmlnode(void)
GList *cur;
node = purple_xmlnode_new("account");
- purple_xmlnode_set_attrib(node, "version", "1.0");
+ purple_xmlnode_set_attrib(node, "version", ACCOUNTS_XML_VERSION);
for (cur = purple_accounts_get_all(); cur != NULL; cur = cur->next)
{
@@ -582,6 +584,7 @@ static void
load_accounts(void)
{
PurpleXmlNode *node, *child;
+ const char *version;
accounts_loaded = TRUE;
@@ -590,6 +593,11 @@ load_accounts(void)
if (node == NULL)
return;
+ version = purple_xmlnode_get_attrib(node, "version");
+ if (purple_version_strcmp(version, ACCOUNTS_XML_VERSION) > 0)
+ purple_debug_warning("accounts", "accounts.xml on disk is for a newer "
+ "version of libpurple");
+
for (child = purple_xmlnode_get_child(node, "account"); child != NULL;
child = purple_xmlnode_get_next_twin(child))
{
diff --git a/libpurple/buddylist.c b/libpurple/buddylist.c
--- a/libpurple/buddylist.c
+++ b/libpurple/buddylist.c
@@ -34,6 +34,8 @@
#include "util.h"
#include "xmlnode.h"
+#define BLIST_XML_VERSION "1.1"
+
#define PURPLE_BUDDY_LIST_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_BUDDY_LIST, PurpleBuddyListPrivate))
@@ -348,7 +350,7 @@ blist_to_xmlnode(void)
GList *cur;
node = purple_xmlnode_new("purple");
- purple_xmlnode_set_attrib(node, "version", "1.0");
+ purple_xmlnode_set_attrib(node, "version", BLIST_XML_VERSION);
/* Write groups */
child = purple_xmlnode_new_child(node, "blist");
@@ -608,6 +610,7 @@ static void
load_blist(void)
{
PurpleXmlNode *purple, *blist, *privacy;
+ const char *version;
blist_loaded = TRUE;
@@ -616,6 +619,11 @@ load_blist(void)
if (purple == NULL)
return;
+ version = purple_xmlnode_get_attrib(purple, "version");
+ if (purple_version_strcmp(version, BLIST_XML_VERSION) > 0)
+ purple_debug_warning("buddylist", "blist.xml on disk is for a newer "
+ "version of libpurple");
+
blist = purple_xmlnode_get_child(purple, "blist");
if (blist) {
PurpleXmlNode *groupnode;
diff --git a/libpurple/prefs.c b/libpurple/prefs.c
--- a/libpurple/prefs.c
+++ b/libpurple/prefs.c
@@ -39,6 +39,8 @@
#include "win32dep.h"
#endif
+#define PREFS_XML_VERSION "1.1"
+
struct pref_cb {
PurplePrefCallback func;
gpointer data;
@@ -184,7 +186,7 @@ prefs_to_xmlnode(void)
/* Create the root preference node */
node = purple_xmlnode_new("pref");
- purple_xmlnode_set_attrib(node, "version", "1");
+ purple_xmlnode_set_attrib(node, "version", PREFS_XML_VERSION);
purple_xmlnode_set_attrib(node, "name", "/");
/* All My Children */
@@ -239,6 +241,7 @@ schedule_prefs_save(void)
*********************************************************************/
static GList *prefs_stack = NULL;
+static gchar *xml_version = NULL;
static void
prefs_start_element_handler (GMarkupParseContext *context,
@@ -278,6 +281,12 @@ prefs_start_element_handler (GMarkupPars
return;
} else if(purple_strequal(attribute_names[i], "value")) {
pref_value = attribute_values[i];
+ } else if(purple_strequal(attribute_names[i], "version")) {
+ g_free(xml_version);
+ xml_version = g_strdup(attribute_values[i]);
+ if (purple_version_strcmp(xml_version, PREFS_XML_VERSION) > 0)
+ purple_debug_warning("prefs", "prefs.xml on disk is for a "
+ "newer version of libpurple");
}
}
@@ -1327,8 +1336,8 @@ purple_prefs_get_children_names(const ch
return list;
}
-void
-purple_prefs_update_old()
+static void
+update_old_prefs(void)
{
purple_prefs_rename("/core", "/purple");
@@ -1433,7 +1442,12 @@ purple_prefs_init(void)
purple_prefs_remove("/purple/contact/idle_score");
purple_prefs_load();
- purple_prefs_update_old();
+
+ if (purple_version_strcmp(xml_version, PREFS_XML_VERSION) < 0)
+ update_old_prefs();
+
+ g_free(xml_version);
+ xml_version = NULL;
}
void
diff --git a/libpurple/prefs.h b/libpurple/prefs.h
--- a/libpurple/prefs.h
+++ b/libpurple/prefs.h
@@ -336,11 +336,6 @@ void purple_prefs_trigger_callback(const
*/
gboolean purple_prefs_load(void);
-/**
- * Rename legacy prefs and delete some that no longer exist.
- */
-void purple_prefs_update_old(void);
-
/*@}*/
G_END_DECLS
diff --git a/libpurple/savedstatuses.c b/libpurple/savedstatuses.c
--- a/libpurple/savedstatuses.c
+++ b/libpurple/savedstatuses.c
@@ -35,6 +35,8 @@
#include "util.h"
#include "xmlnode.h"
+#define STATUS_XML_VERSION "1.1"
+
/**
* The maximum number of transient statuses to save. This
* is used during the shutdown process to clean out old
@@ -319,7 +321,7 @@ statuses_to_xmlnode(void)
GList *cur;
node = purple_xmlnode_new("statuses");
- purple_xmlnode_set_attrib(node, "version", "1.0");
+ purple_xmlnode_set_attrib(node, "version", STATUS_XML_VERSION);
for (cur = saved_statuses; cur != NULL; cur = cur->next)
{
@@ -530,6 +532,7 @@ static void
load_statuses(void)
{
PurpleXmlNode *statuses, *status;
+ const char *version;
statuses_loaded = TRUE;
@@ -538,6 +541,11 @@ load_statuses(void)
if (statuses == NULL)
return;
+ version = purple_xmlnode_get_attrib(statuses, "version");
+ if (purple_version_strcmp(version, STATUS_XML_VERSION) > 0)
+ purple_debug_warning("savedstatuses", "status.xml on disk is for a "
+ "newer version of libpurple");
+
for (status = purple_xmlnode_get_child(statuses, "status"); status != NULL;
status = purple_xmlnode_get_next_twin(status))
{
More information about the Commits
mailing list