Handle logins using accounts

This commit is contained in:
James Booth
2012-12-09 22:14:38 +00:00
parent 324a85a2a5
commit ce6f227651
7 changed files with 144 additions and 5 deletions

View File

@@ -24,6 +24,8 @@
#include <string.h>
#include <glib.h>
#include "accounts.h"
#include "files.h"
#include "log.h"
#include "prof_autocomplete.h"
@@ -108,6 +110,54 @@ accounts_get_list(void)
return g_key_file_get_groups(accounts, NULL);
}
ProfAccount*
accounts_get_account(const char * const name)
{
if (!g_key_file_has_group(accounts, name)) {
return NULL;
} else {
ProfAccount *account = malloc(sizeof(ProfAccount));
account->name = strdup(name);
gchar *jid = g_key_file_get_string(accounts, name, "jid", NULL);
if (jid != NULL) {
account->jid = strdup(jid);
} else {
account->jid = strdup(name);
g_key_file_set_string(accounts, name, "jid", name);
_save_accounts();
}
account->enabled = g_key_file_get_boolean(accounts, name, "enabled", NULL);
gchar *server = g_key_file_get_string(accounts, name, "server", NULL);
if (server != NULL) {
account->server = strdup(server);
} else {
account->server = NULL;
}
return account;
}
}
void
accounts_free_account(ProfAccount *account)
{
if (account != NULL) {
if (account->name != NULL) {
free(account->name);
account->name = NULL;
}
if (account->jid != NULL) {
free(account->jid);
account->jid = NULL;
}
if (account->server != NULL) {
free(account->server);
account->server = NULL;
}
account = NULL;
}
}
static void
_save_accounts(void)
{