diff options
author | James Booth <boothj5@gmail.com> | 2013-01-27 00:02:28 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2013-01-27 00:02:28 +0000 |
commit | 1a30ee15e04bdd950bdab94e2d5e7b6e86c7e7c5 (patch) | |
tree | 0ca9abe7478f18cf9d199964b37bf4e2e9443003 /src/accounts.c | |
parent | 43841ee9eec525c52b60d40537781f9f286e053e (diff) | |
download | profani-tty-1a30ee15e04bdd950bdab94e2d5e7b6e86c7e7c5.tar.gz |
Added resource handling in account module
Handle old accounts on load
Diffstat (limited to 'src/accounts.c')
-rw-r--r-- | src/accounts.c | 36 |
1 files changed, 26 insertions, 10 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); |