mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Refactor fixing old accounts
This commit is contained in:
parent
5cca57f6fb
commit
b936154299
@ -38,6 +38,7 @@ static GKeyFile *accounts;
|
|||||||
static Autocomplete all_ac;
|
static Autocomplete all_ac;
|
||||||
static Autocomplete enabled_ac;
|
static Autocomplete enabled_ac;
|
||||||
|
|
||||||
|
static void _fix_legacy_accounts(const char * const account_name);
|
||||||
static void _save_accounts(void);
|
static void _save_accounts(void);
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -59,41 +60,12 @@ accounts_load(void)
|
|||||||
|
|
||||||
gsize i;
|
gsize i;
|
||||||
for (i = 0; i < naccounts; i++) {
|
for (i = 0; i < naccounts; i++) {
|
||||||
|
autocomplete_add(all_ac, strdup(account_names[i]));
|
||||||
if (g_key_file_get_boolean(accounts, account_names[i], "enabled", NULL)) {
|
if (g_key_file_get_boolean(accounts, account_names[i], "enabled", NULL)) {
|
||||||
autocomplete_add(enabled_ac, strdup(account_names[i]));
|
autocomplete_add(enabled_ac, strdup(account_names[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// fix old style accounts (no jid, or resource setting)
|
_fix_legacy_accounts(account_names[i]);
|
||||||
char *barejid = account_names[i];
|
|
||||||
char *resource = NULL;
|
|
||||||
Jid *jid = jid_create(account_names[i]);
|
|
||||||
if (jid != NULL) {
|
|
||||||
barejid = jid->barejid;
|
|
||||||
resource = jid->resourcepart;
|
|
||||||
}
|
|
||||||
|
|
||||||
// old accounts with no jid, use barejid (either account name,
|
|
||||||
// or account name with resource stripped)
|
|
||||||
if (!g_key_file_has_key(accounts, account_names[i], "jid", NULL)) {
|
|
||||||
g_key_file_set_string(accounts, account_names[i], "jid", barejid);
|
|
||||||
_save_accounts();
|
|
||||||
}
|
|
||||||
|
|
||||||
// old accounts with no resource, use resourcepart of account name,
|
|
||||||
// or "profanity" if there was no resourcepart
|
|
||||||
if (!g_key_file_has_key(accounts, account_names[i], "resource", NULL)) {
|
|
||||||
if (resource != NULL) {
|
|
||||||
g_key_file_set_string(accounts, account_names[i], "resource", resource);
|
|
||||||
} else {
|
|
||||||
g_key_file_set_string(accounts, account_names[i], "resource", "profanity");
|
|
||||||
}
|
|
||||||
|
|
||||||
_save_accounts();
|
|
||||||
}
|
|
||||||
|
|
||||||
autocomplete_add(all_ac, strdup(account_names[i]));
|
|
||||||
|
|
||||||
jid_destroy(jid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < naccounts; i++) {
|
for (i = 0; i < naccounts; i++) {
|
||||||
@ -137,17 +109,16 @@ accounts_reset_enabled_search(void)
|
|||||||
void
|
void
|
||||||
accounts_add(const char *account_name, const char *altdomain)
|
accounts_add(const char *account_name, const char *altdomain)
|
||||||
{
|
{
|
||||||
// assume account name is barejid, use default resource
|
// set account name and resource
|
||||||
const char *barejid = account_name;
|
const char *barejid = account_name;
|
||||||
const char *resource = "profanity";
|
const char *resource = "profanity";
|
||||||
|
|
||||||
// check if account name contains resourcepart and split
|
|
||||||
// into barejid and resourcepart if so
|
|
||||||
Jid *jid = jid_create(account_name);
|
Jid *jid = jid_create(account_name);
|
||||||
if (jid != NULL) {
|
if (jid != NULL) {
|
||||||
barejid = jid->barejid;
|
barejid = jid->barejid;
|
||||||
|
if (jid->resourcepart != NULL) {
|
||||||
resource = jid->resourcepart;
|
resource = jid->resourcepart;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// doesn't yet exist
|
// doesn't yet exist
|
||||||
if (!g_key_file_has_group(accounts, account_name)) {
|
if (!g_key_file_has_group(accounts, account_name)) {
|
||||||
@ -314,6 +285,35 @@ accounts_set_server(const char * const account_name, const char * const value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_fix_legacy_accounts(const char * const account_name)
|
||||||
|
{
|
||||||
|
// set barejid and resource
|
||||||
|
const char *barejid = account_name;
|
||||||
|
const char *resource = "profanity";
|
||||||
|
Jid *jid = jid_create(account_name);
|
||||||
|
if (jid != NULL) {
|
||||||
|
barejid = jid->barejid;
|
||||||
|
if (jid->resourcepart != NULL) {
|
||||||
|
resource = jid->resourcepart;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// accounts with no jid property
|
||||||
|
if (!g_key_file_has_key(accounts, account_name, "jid", NULL)) {
|
||||||
|
g_key_file_set_string(accounts, account_name, "jid", barejid);
|
||||||
|
_save_accounts();
|
||||||
|
}
|
||||||
|
|
||||||
|
// accounts with no resource, property
|
||||||
|
if (!g_key_file_has_key(accounts, account_name, "resource", NULL)) {
|
||||||
|
g_key_file_set_string(accounts, account_name, "resource", resource);
|
||||||
|
_save_accounts();
|
||||||
|
}
|
||||||
|
|
||||||
|
jid_destroy(jid);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_save_accounts(void)
|
_save_accounts(void)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user