From 1a30ee15e04bdd950bdab94e2d5e7b6e86c7e7c5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 27 Jan 2013 00:02:28 +0000 Subject: [PATCH] Added resource handling in account module Handle old accounts on load --- src/accounts.c | 36 ++++++++++++++++++++++++++---------- src/command.c | 15 ++++++++++++--- src/windows.c | 11 +++++++---- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/accounts.c b/src/accounts.c index f15d02c0..2ada2fad 100644 --- a/src/accounts.c +++ b/src/accounts.c @@ -62,7 +62,33 @@ accounts_load(void) if (g_key_file_get_boolean(accounts, jids[i], "enabled", NULL)) { autocomplete_add(enabled_ac, strdup(jids[i])); } + + // fix old style accounts (no jid, or resource setting) + char *barejid = jids[i]; + char *resource = NULL; + Jid *jid = jid_create(jids[i]); + if (jid != NULL) { + barejid = jid->barejid; + resource = jid->resourcepart; + } + + if (!g_key_file_has_key(accounts, jids[i], "jid", NULL)) { + g_key_file_set_string(accounts, jids[i], "jid", barejid); + _save_accounts(); + } + if (!g_key_file_has_key(accounts, jids[i], "resource", NULL)) { + if (resource != NULL) { + g_key_file_set_string(accounts, jids[i], "resource", resource); + } else { + g_key_file_set_string(accounts, jids[i], "resource", "profanity"); + } + + _save_accounts(); + } + autocomplete_add(all_ac, strdup(jids[i])); + + jid_destroy(jid); } for (i = 0; i < njids; i++) { @@ -133,16 +159,6 @@ accounts_add_login(const char *account_name, const char *altdomain) _save_accounts(); autocomplete_add(all_ac, strdup(account_name)); autocomplete_add(enabled_ac, strdup(account_name)); - - // already exists, update old style accounts - } else { - g_key_file_set_string(accounts, account_name, "jid", barejid); - if (resource != NULL) { - g_key_file_set_string(accounts, account_name, "resource", resource); - } else { - g_key_file_set_string(accounts, account_name, "resource", "profanity"); - } - _save_accounts(); } jid_destroy(jid); diff --git a/src/command.c b/src/command.c index 1631f253..dc25ce71 100644 --- a/src/command.c +++ b/src/command.c @@ -1135,9 +1135,18 @@ _cmd_account(gchar **args, struct cmd_help_t help) cons_show(""); } else { if (strcmp(property, "jid") == 0) { - accounts_set_jid(account_name, value); - cons_show("Updated jid for account %s: %s", account_name, value); - cons_show(""); + Jid *jid = jid_create(args[3]); + if (jid == NULL) { + cons_show("Malformed jid: %s", value); + } else { + accounts_set_jid(account_name, jid->barejid); + cons_show("Updated jid for account %s: %s", account_name, jid->barejid); + if (jid->resourcepart != NULL) { + cons_show("Updated resource for account %s: %s", account_name, jid->resourcepart); + } + cons_show(""); + } + jid_destroy(jid); } else if (strcmp(property, "server") == 0) { accounts_set_server(account_name, value); cons_show("Updated server for account %s: %s", account_name, value); diff --git a/src/windows.c b/src/windows.c index da4b664f..01fe4b7a 100644 --- a/src/windows.c +++ b/src/windows.c @@ -1227,14 +1227,17 @@ void cons_show_account(ProfAccount *account) { cons_show("%s account details:", account->name); - cons_show("jid : %s", account->jid); if (account->enabled) { - cons_show("enabled : TRUE"); + cons_show("enabled : TRUE"); } else { - cons_show("enabled : FALSE"); + cons_show("enabled : FALSE"); + } + cons_show("jid : %s", account->jid); + if (account->resource != NULL) { + cons_show("resource : %s", account->resource); } if (account->server != NULL) { - cons_show("server : %s", account->server); + cons_show("server : %s", account->server); } cons_show(""); }