diff options
author | James Booth <boothj5@gmail.com> | 2012-12-09 22:14:38 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-12-09 22:14:38 +0000 |
commit | ce6f2276519f38378769780b060feb78494dfd35 (patch) | |
tree | 874f887c4198f4cc61d356f203b9427bec5f6a21 /src/accounts.c | |
parent | 324a85a2a501862e8e442ef8d7328b1bdcba1b69 (diff) | |
download | profani-tty-ce6f2276519f38378769780b060feb78494dfd35.tar.gz |
Handle logins using accounts
Diffstat (limited to 'src/accounts.c')
-rw-r--r-- | src/accounts.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/accounts.c b/src/accounts.c index 7a84397b..f471fbdb 100644 --- a/src/accounts.c +++ b/src/accounts.c @@ -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) { |