/soc/2013/ankitkv/gobjectification: 3302a1d08cda: Migrate old pr...
Ankit Vani
a at nevitus.org
Mon Jan 20 13:14:29 EST 2014
Changeset: 3302a1d08cda865057f424b2f315c0c808ec6458
Author: Ankit Vani <a at nevitus.org>
Date: 2014-01-20 23:44 +0530
Branch: soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/3302a1d08cda
Description:
Migrate old protocol IDs to new if *.xml version < 1.1
diffstat:
libpurple/accounts.c | 23 ++++++++++++-----
libpurple/buddylist.c | 60 ++++++++++++++++++++++++++++++++++------------
libpurple/pounce.c | 18 ++++++++++++-
libpurple/prefs.c | 6 ++--
libpurple/savedstatuses.c | 18 ++++++++++---
5 files changed, 93 insertions(+), 32 deletions(-)
diffs (truncated from 329 to 300 lines):
diff --git a/libpurple/accounts.c b/libpurple/accounts.c
--- a/libpurple/accounts.c
+++ b/libpurple/accounts.c
@@ -461,17 +461,18 @@ parse_current_error(PurpleXmlNode *node,
}
static PurpleAccount *
-parse_account(PurpleXmlNode *node)
+parse_account(PurpleXmlNode *node, const gchar *version)
{
PurpleAccount *ret;
PurpleXmlNode *child;
- char *protocol_id = NULL;
+ char *read_proto = NULL, *protocol_id;
char *name = NULL;
char *data;
child = purple_xmlnode_get_child(node, "protocol");
if (child != NULL)
- protocol_id = purple_xmlnode_get_data(child);
+ read_proto = purple_xmlnode_get_data(child);
+ protocol_id = read_proto;
child = purple_xmlnode_get_child(node, "name");
if (child != NULL)
@@ -484,16 +485,24 @@ parse_account(PurpleXmlNode *node)
name = purple_xmlnode_get_data(child);
}
- if ((protocol_id == NULL) || (name == NULL))
+ if ((read_proto == NULL) || (name == NULL))
{
- g_free(protocol_id);
+ g_free(read_proto);
g_free(name);
return NULL;
}
+ if (purple_version_strcmp(version, "1.1") < 0) {
+ if (!strncmp(protocol_id, "prpl-", 5)) {
+ purple_debug_info("accounts", "accounts.xml: Migrating account %s "
+ "from version %s to 1.1\n", name, version);
+ protocol_id += 5;
+ }
+ }
+
ret = purple_account_new(name, protocol_id);
g_free(name);
- g_free(protocol_id);
+ g_free(read_proto);
/* Read the alias */
child = purple_xmlnode_get_child(node, "alias");
@@ -602,7 +611,7 @@ load_accounts(void)
child = purple_xmlnode_get_next_twin(child))
{
PurpleAccount *new_acct;
- new_acct = parse_account(child);
+ new_acct = parse_account(child, version);
purple_accounts_add(new_acct);
}
diff --git a/libpurple/buddylist.c b/libpurple/buddylist.c
--- a/libpurple/buddylist.c
+++ b/libpurple/buddylist.c
@@ -465,7 +465,8 @@ parse_setting(PurpleBlistNode *node, Pur
}
static void
-parse_buddy(PurpleGroup *group, PurpleContact *contact, PurpleXmlNode *bnode)
+parse_buddy(PurpleGroup *group, PurpleContact *contact, PurpleXmlNode *bnode,
+ const char *version)
{
PurpleAccount *account;
PurpleBuddy *buddy;
@@ -479,17 +480,26 @@ parse_buddy(PurpleGroup *group, PurpleCo
if (!acct_name || !proto)
return;
- account = purple_accounts_find(acct_name, proto);
-
- if (!account)
- return;
-
if ((x = purple_xmlnode_get_child(bnode, "name")))
name = purple_xmlnode_get_data(x);
if (!name)
return;
+ if (purple_version_strcmp(version, "1.1") < 0) {
+ if (!strncmp(proto, "prpl-", 5)) {
+ purple_debug_info("buddylist", "blist.xml: Migrating "
+ "buddy %s for account %s from version %s to 1.1\n",
+ name, acct_name, version);
+ proto += 5;
+ }
+ }
+
+ account = purple_accounts_find(acct_name, proto);
+
+ if (!account)
+ return;
+
if ((x = purple_xmlnode_get_child(bnode, "alias")))
alias = purple_xmlnode_get_data(x);
@@ -506,7 +516,7 @@ parse_buddy(PurpleGroup *group, PurpleCo
}
static void
-parse_contact(PurpleGroup *group, PurpleXmlNode *cnode)
+parse_contact(PurpleGroup *group, PurpleXmlNode *cnode, const char *version)
{
PurpleContact *contact = purple_contact_new();
PurpleXmlNode *x;
@@ -523,7 +533,7 @@ parse_contact(PurpleGroup *group, Purple
if (x->type != PURPLE_XMLNODE_TYPE_TAG)
continue;
if (purple_strequal(x->name, "buddy"))
- parse_buddy(group, contact, x);
+ parse_buddy(group, contact, x, version);
else if (purple_strequal(x->name, "setting"))
parse_setting(PURPLE_BLIST_NODE(contact), x);
}
@@ -534,7 +544,7 @@ parse_contact(PurpleGroup *group, Purple
}
static void
-parse_chat(PurpleGroup *group, PurpleXmlNode *cnode)
+parse_chat(PurpleGroup *group, PurpleXmlNode *cnode, const char *version)
{
PurpleChat *chat;
PurpleAccount *account;
@@ -549,14 +559,23 @@ parse_chat(PurpleGroup *group, PurpleXml
if (!acct_name || !proto)
return;
+ if ((x = purple_xmlnode_get_child(cnode, "alias")))
+ alias = purple_xmlnode_get_data(x);
+
+ if (purple_version_strcmp(version, "1.1") < 0) {
+ if (!strncmp(proto, "prpl-", 5)) {
+ purple_debug_info("buddylist", "blist.xml: Migrating "
+ "chat %s for account %s from version %s to 1.1\n",
+ alias ? alias : "(no alias)", acct_name, version);
+ proto += 5;
+ }
+ }
+
account = purple_accounts_find(acct_name, proto);
if (!account)
return;
- if ((x = purple_xmlnode_get_child(cnode, "alias")))
- alias = purple_xmlnode_get_data(x);
-
components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
for (x = purple_xmlnode_get_child(cnode, "component"); x; x = purple_xmlnode_get_next_twin(x)) {
@@ -580,7 +599,7 @@ parse_chat(PurpleGroup *group, PurpleXml
}
static void
-parse_group(PurpleXmlNode *groupnode)
+parse_group(PurpleXmlNode *groupnode, const char *version)
{
const char *name = purple_xmlnode_get_attrib(groupnode, "name");
PurpleGroup *group;
@@ -600,9 +619,9 @@ parse_group(PurpleXmlNode *groupnode)
parse_setting((PurpleBlistNode*)group, cnode);
else if (purple_strequal(cnode->name, "contact") ||
purple_strequal(cnode->name, "person"))
- parse_contact(group, cnode);
+ parse_contact(group, cnode, version);
else if (purple_strequal(cnode->name, "chat"))
- parse_chat(group, cnode);
+ parse_chat(group, cnode, version);
}
}
@@ -629,7 +648,7 @@ load_blist(void)
PurpleXmlNode *groupnode;
for (groupnode = purple_xmlnode_get_child(blist, "group"); groupnode != NULL;
groupnode = purple_xmlnode_get_next_twin(groupnode)) {
- parse_group(groupnode);
+ parse_group(groupnode, version);
}
}
@@ -649,6 +668,15 @@ load_blist(void)
if (!acct_name || !proto || !mode)
continue;
+ if (purple_version_strcmp(version, "1.1") < 0) {
+ if (!strncmp(proto, "prpl-", 5)) {
+ purple_debug_info("buddylist", "blist.xml: Migrating "
+ "privacy for account %s from version %s to 1.1\n",
+ acct_name, version);
+ proto += 5;
+ }
+ }
+
account = purple_accounts_find(acct_name, proto);
if (!account)
diff --git a/libpurple/pounce.c b/libpurple/pounce.c
--- a/libpurple/pounce.c
+++ b/libpurple/pounce.c
@@ -102,6 +102,7 @@ static GHashTable *pounce_handlers = NUL
static GList *pounces = NULL;
static guint save_timer = 0;
static gboolean pounces_loaded = FALSE;
+static gchar *xml_version = NULL;
/*********************************************************************
@@ -354,9 +355,10 @@ start_element_handler(GMarkupParseContex
}
if (purple_strequal(element_name, "pounces")) {
- const char *version = g_hash_table_lookup(atts, "version");
+ g_free(xml_version);
+ xml_version = g_strdup(g_hash_table_lookup(atts, "version"));
- if (purple_version_strcmp(version, POUNCES_XML_VERSION) > 0)
+ if (purple_version_strcmp(xml_version, POUNCES_XML_VERSION) > 0)
purple_debug_warning("pounce", "pounces.xml on disk is for a "
"newer version of libpurple");
}
@@ -375,6 +377,15 @@ start_element_handler(GMarkupParseContex
else if (purple_strequal(element_name, "account")) {
const char *protocol_id = g_hash_table_lookup(atts, "protocol");
+ if (purple_version_strcmp(xml_version, "1.1") < 0) {
+ if (protocol_id && !strncmp(protocol_id, "prpl-", 5)) {
+ purple_debug_info("pounce", "pounces.xml: Migrating "
+ "pounce for %s from version %s to 1.1\n",
+ data->ui_name, xml_version);
+ protocol_id += 5;
+ }
+ }
+
if (protocol_id == NULL) {
purple_debug(PURPLE_DEBUG_ERROR, "pounce",
"Unset 'protocol' parameter for account!\n");
@@ -1201,6 +1212,9 @@ purple_pounces_init(void)
handle, PURPLE_CALLBACK(received_message_cb), NULL);
purple_pounces_load();
+
+ g_free(xml_version);
+ xml_version = NULL;
}
void
diff --git a/libpurple/prefs.c b/libpurple/prefs.c
--- a/libpurple/prefs.c
+++ b/libpurple/prefs.c
@@ -1443,9 +1443,9 @@ purple_prefs_init(void)
purple_prefs_load();
- if (purple_version_strcmp(xml_version, PREFS_XML_VERSION) < 0) {
- purple_debug_info("prefs", "Migrating prefs.xml from version %s to %s\n",
- xml_version, PREFS_XML_VERSION);
+ if (purple_version_strcmp(xml_version, "1.1") < 0) {
+ purple_debug_info("prefs", "Migrating prefs.xml from version %s to 1.1\n",
+ xml_version);
update_old_prefs();
}
diff --git a/libpurple/savedstatuses.c b/libpurple/savedstatuses.c
--- a/libpurple/savedstatuses.c
+++ b/libpurple/savedstatuses.c
@@ -373,7 +373,7 @@ schedule_save(void)
*********************************************************************/
static PurpleSavedStatusSub *
-parse_substatus(PurpleXmlNode *substatus)
+parse_substatus(PurpleXmlNode *substatus, const char *version)
{
PurpleSavedStatusSub *ret;
PurpleXmlNode *node;
@@ -389,6 +389,16 @@ parse_substatus(PurpleXmlNode *substatus
const char *protocol;
acct_name = purple_xmlnode_get_data(node);
protocol = purple_xmlnode_get_attrib(node, "protocol");
+
+ if (purple_version_strcmp(version, "1.1") < 0) {
+ if (acct_name && protocol && !strncmp(protocol, "prpl-", 5)) {
+ purple_debug_info("savedstatuses", "status.xml: Migrating "
+ "substatus for account %s from version %s to 1.1\n",
+ acct_name, version);
+ protocol += 5;
+ }
+ }
+
if ((acct_name != NULL) && (protocol != NULL))
More information about the Commits
mailing list