2012-12-01 20:29:42 -05:00
|
|
|
/*
|
|
|
|
* accounts.c
|
|
|
|
*
|
2016-02-14 17:54:46 -05:00
|
|
|
* Copyright (C) 2012 - 2016 James Booth <boothj5@gmail.com>
|
2012-12-01 20:29:42 -05:00
|
|
|
*
|
|
|
|
* This file is part of Profanity.
|
|
|
|
*
|
|
|
|
* Profanity is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Profanity is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2016-07-23 20:14:49 -04:00
|
|
|
* along with Profanity. If not, see <https://www.gnu.org/licenses/>.
|
2012-12-01 20:29:42 -05:00
|
|
|
*
|
2014-08-24 15:57:39 -04:00
|
|
|
* In addition, as a special exception, the copyright holders give permission to
|
|
|
|
* link the code of portions of this program with the OpenSSL library under
|
|
|
|
* certain conditions as described in each individual source file, and
|
|
|
|
* distribute linked combinations including the two.
|
|
|
|
*
|
|
|
|
* You must obey the GNU General Public License in all respects for all of the
|
|
|
|
* code used other than OpenSSL. If you modify file(s) with this exception, you
|
|
|
|
* may extend this exception to your version of the file(s), but you are not
|
|
|
|
* obligated to do so. If you do not wish to do so, delete this exception
|
|
|
|
* statement from your version. If you delete this exception statement from all
|
|
|
|
* source files in the program, then also delete it here.
|
|
|
|
*
|
2012-12-01 20:29:42 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
2014-10-18 16:23:42 -04:00
|
|
|
#include <glib/gstdio.h>
|
2012-12-09 17:14:38 -05:00
|
|
|
|
|
|
|
#include "accounts.h"
|
2013-02-02 15:55:58 -05:00
|
|
|
|
2013-01-26 17:25:00 -05:00
|
|
|
#include "common.h"
|
2016-07-24 10:43:51 -04:00
|
|
|
#include "log.h"
|
2016-07-24 11:22:15 -04:00
|
|
|
#include "config/files.h"
|
2014-01-22 17:22:01 -05:00
|
|
|
#include "config/account.h"
|
2015-11-23 18:54:14 -05:00
|
|
|
#include "config/conflists.h"
|
2013-02-02 16:43:59 -05:00
|
|
|
#include "tools/autocomplete.h"
|
2013-02-02 14:47:41 -05:00
|
|
|
#include "xmpp/xmpp.h"
|
2016-07-24 10:43:51 -04:00
|
|
|
#include "xmpp/jid.h"
|
2012-12-01 20:29:42 -05:00
|
|
|
|
2016-07-24 16:35:12 -04:00
|
|
|
static char *accounts_loc;
|
2012-12-01 20:29:42 -05:00
|
|
|
static GKeyFile *accounts;
|
|
|
|
|
2013-01-24 20:11:49 -05:00
|
|
|
static Autocomplete all_ac;
|
|
|
|
static Autocomplete enabled_ac;
|
2012-12-01 20:29:42 -05:00
|
|
|
|
|
|
|
static void _save_accounts(void);
|
2014-05-11 13:13:04 -04:00
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
|
|
|
accounts_load(void)
|
2012-12-01 20:29:42 -05:00
|
|
|
{
|
|
|
|
log_info("Loading accounts");
|
2013-01-24 20:11:49 -05:00
|
|
|
all_ac = autocomplete_new();
|
|
|
|
enabled_ac = autocomplete_new();
|
2016-07-24 16:35:12 -04:00
|
|
|
accounts_loc = files_get_data_path(FILE_ACCOUNTS);
|
2012-12-01 20:29:42 -05:00
|
|
|
|
2014-10-18 16:23:42 -04:00
|
|
|
if (g_file_test(accounts_loc, G_FILE_TEST_EXISTS)) {
|
|
|
|
g_chmod(accounts_loc, S_IRUSR | S_IWUSR);
|
|
|
|
}
|
|
|
|
|
2012-12-01 20:29:42 -05:00
|
|
|
accounts = g_key_file_new();
|
2015-09-28 15:42:59 -04:00
|
|
|
g_key_file_load_from_file(accounts, accounts_loc, G_KEY_FILE_KEEP_COMMENTS, NULL);
|
2012-12-01 20:29:42 -05:00
|
|
|
|
|
|
|
// create the logins searchable list for autocompletion
|
2013-01-27 12:59:37 -05:00
|
|
|
gsize naccounts;
|
2015-09-28 15:42:59 -04:00
|
|
|
gchar **account_names = g_key_file_get_groups(accounts, &naccounts);
|
2012-12-01 20:29:42 -05:00
|
|
|
|
|
|
|
gsize i;
|
2013-01-27 12:59:37 -05:00
|
|
|
for (i = 0; i < naccounts; i++) {
|
2013-08-25 20:29:50 -04:00
|
|
|
autocomplete_add(all_ac, account_names[i]);
|
2013-01-27 12:59:37 -05:00
|
|
|
if (g_key_file_get_boolean(accounts, account_names[i], "enabled", NULL)) {
|
2013-08-25 20:29:50 -04:00
|
|
|
autocomplete_add(enabled_ac, account_names[i]);
|
2012-12-09 19:53:57 -05:00
|
|
|
}
|
2012-12-01 20:29:42 -05:00
|
|
|
}
|
|
|
|
|
2013-08-25 07:54:34 -04:00
|
|
|
g_strfreev(account_names);
|
2012-12-01 20:29:42 -05:00
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
|
|
|
accounts_close(void)
|
2012-12-01 20:29:42 -05:00
|
|
|
{
|
2013-01-24 20:11:49 -05:00
|
|
|
autocomplete_free(all_ac);
|
|
|
|
autocomplete_free(enabled_ac);
|
2012-12-01 20:29:42 -05:00
|
|
|
g_key_file_free(accounts);
|
|
|
|
}
|
|
|
|
|
2015-10-24 19:46:12 -04:00
|
|
|
char*
|
|
|
|
accounts_find_enabled(const char *const prefix)
|
2012-12-09 19:53:57 -05:00
|
|
|
{
|
2014-07-09 15:23:47 -04:00
|
|
|
return autocomplete_complete(enabled_ac, prefix, TRUE);
|
2012-12-09 19:53:57 -05:00
|
|
|
}
|
|
|
|
|
2015-10-24 19:46:12 -04:00
|
|
|
char*
|
|
|
|
accounts_find_all(const char *const prefix)
|
2012-12-01 20:29:42 -05:00
|
|
|
{
|
2014-07-09 15:23:47 -04:00
|
|
|
return autocomplete_complete(all_ac, prefix, TRUE);
|
2012-12-01 20:29:42 -05:00
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
|
|
|
accounts_reset_all_search(void)
|
2012-12-01 20:29:42 -05:00
|
|
|
{
|
2013-01-24 20:11:49 -05:00
|
|
|
autocomplete_reset(all_ac);
|
2012-12-09 19:53:57 -05:00
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
|
|
|
accounts_reset_enabled_search(void)
|
2012-12-09 19:53:57 -05:00
|
|
|
{
|
2013-01-24 20:11:49 -05:00
|
|
|
autocomplete_reset(enabled_ac);
|
2012-12-01 20:29:42 -05:00
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-17 22:06:23 -04:00
|
|
|
accounts_add(const char *account_name, const char *altdomain, const int port, const char *const tls_policy)
|
2012-12-01 20:29:42 -05:00
|
|
|
{
|
2013-01-27 13:47:33 -05:00
|
|
|
// set account name and resource
|
2013-01-26 17:19:20 -05:00
|
|
|
const char *barejid = account_name;
|
2013-01-27 13:10:30 -05:00
|
|
|
const char *resource = "profanity";
|
2013-01-26 17:19:20 -05:00
|
|
|
Jid *jid = jid_create(account_name);
|
2015-05-04 17:32:42 -04:00
|
|
|
if (jid) {
|
2013-01-26 17:19:20 -05:00
|
|
|
barejid = jid->barejid;
|
2015-05-04 17:32:42 -04:00
|
|
|
if (jid->resourcepart) {
|
2013-01-27 13:47:33 -05:00
|
|
|
resource = jid->resourcepart;
|
|
|
|
}
|
2013-01-26 17:19:20 -05:00
|
|
|
}
|
|
|
|
|
2016-11-19 21:09:34 -05:00
|
|
|
if (g_key_file_has_group(accounts, account_name)) {
|
|
|
|
jid_destroy(jid);
|
|
|
|
return;
|
|
|
|
}
|
2013-09-12 18:30:35 -04:00
|
|
|
|
2016-11-19 21:09:34 -05:00
|
|
|
g_key_file_set_boolean(accounts, account_name, "enabled", TRUE);
|
|
|
|
g_key_file_set_string(accounts, account_name, "jid", barejid);
|
|
|
|
g_key_file_set_string(accounts, account_name, "resource", resource);
|
|
|
|
if (altdomain) {
|
|
|
|
g_key_file_set_string(accounts, account_name, "server", altdomain);
|
|
|
|
}
|
|
|
|
if (port != 0) {
|
|
|
|
g_key_file_set_integer(accounts, account_name, "port", port);
|
|
|
|
}
|
|
|
|
if (tls_policy) {
|
|
|
|
g_key_file_set_string(accounts, account_name, "tls.policy", tls_policy);
|
|
|
|
}
|
2013-09-12 18:30:35 -04:00
|
|
|
|
2016-11-19 21:09:34 -05:00
|
|
|
Jid *jidp = jid_create(barejid);
|
2012-12-06 19:10:00 -05:00
|
|
|
|
2016-11-19 21:09:34 -05:00
|
|
|
if (jidp->localpart == NULL) {
|
|
|
|
g_key_file_set_string(accounts, account_name, "muc.nick", jidp->domainpart);
|
|
|
|
} else {
|
|
|
|
g_key_file_set_string(accounts, account_name, "muc.nick", jidp->localpart);
|
2012-12-01 20:29:42 -05:00
|
|
|
}
|
2012-12-09 15:18:38 -05:00
|
|
|
|
2016-11-19 21:09:34 -05:00
|
|
|
jid_destroy(jidp);
|
|
|
|
|
|
|
|
g_key_file_set_string(accounts, account_name, "presence.last", "online");
|
|
|
|
g_key_file_set_string(accounts, account_name, "presence.login", "online");
|
|
|
|
g_key_file_set_integer(accounts, account_name, "priority.online", 0);
|
|
|
|
g_key_file_set_integer(accounts, account_name, "priority.chat", 0);
|
|
|
|
g_key_file_set_integer(accounts, account_name, "priority.away", 0);
|
|
|
|
g_key_file_set_integer(accounts, account_name, "priority.xa", 0);
|
|
|
|
g_key_file_set_integer(accounts, account_name, "priority.dnd", 0);
|
|
|
|
|
|
|
|
_save_accounts();
|
|
|
|
autocomplete_add(all_ac, account_name);
|
|
|
|
autocomplete_add(enabled_ac, account_name);
|
|
|
|
|
2013-01-26 17:19:20 -05:00
|
|
|
jid_destroy(jid);
|
2012-12-09 15:18:38 -05:00
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
int
|
|
|
|
accounts_remove(const char *account_name)
|
2014-11-23 16:37:10 -05:00
|
|
|
{
|
|
|
|
int r = g_key_file_remove_group(accounts, account_name, NULL);
|
|
|
|
_save_accounts();
|
|
|
|
autocomplete_remove(all_ac, account_name);
|
|
|
|
autocomplete_remove(enabled_ac, account_name);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
gchar**
|
|
|
|
accounts_get_list(void)
|
2012-12-09 15:18:38 -05:00
|
|
|
{
|
|
|
|
return g_key_file_get_groups(accounts, NULL);
|
2012-12-01 20:29:42 -05:00
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
ProfAccount*
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_get_account(const char *const name)
|
2012-12-09 17:14:38 -05:00
|
|
|
{
|
|
|
|
if (!g_key_file_has_group(accounts, name)) {
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
gchar *jid = g_key_file_get_string(accounts, name, "jid", NULL);
|
2014-01-22 17:22:01 -05:00
|
|
|
|
|
|
|
// fix accounts that have no jid property by setting to name
|
|
|
|
if (jid == NULL) {
|
2012-12-09 17:14:38 -05:00
|
|
|
g_key_file_set_string(accounts, name, "jid", name);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
2013-01-30 19:01:38 -05:00
|
|
|
|
2013-10-14 14:15:51 -04:00
|
|
|
gchar *password = g_key_file_get_string(accounts, name, "password", NULL);
|
2015-01-07 00:00:02 -05:00
|
|
|
gchar *eval_password = g_key_file_get_string(accounts, name, "eval_password", NULL);
|
2014-01-22 17:22:01 -05:00
|
|
|
gboolean enabled = g_key_file_get_boolean(accounts, name, "enabled", NULL);
|
2013-01-30 19:01:38 -05:00
|
|
|
|
2012-12-09 17:14:38 -05:00
|
|
|
gchar *server = g_key_file_get_string(accounts, name, "server", NULL);
|
2013-01-26 17:25:00 -05:00
|
|
|
gchar *resource = g_key_file_get_string(accounts, name, "resource", NULL);
|
2014-01-22 17:22:01 -05:00
|
|
|
int port = g_key_file_get_integer(accounts, name, "port", NULL);
|
2013-01-30 19:01:38 -05:00
|
|
|
|
2014-01-22 17:22:01 -05:00
|
|
|
gchar *last_presence = g_key_file_get_string(accounts, name, "presence.last", NULL);
|
|
|
|
gchar *login_presence = g_key_file_get_string(accounts, name, "presence.login", NULL);
|
2013-08-25 07:54:34 -04:00
|
|
|
|
2014-01-22 17:22:01 -05:00
|
|
|
int priority_online = g_key_file_get_integer(accounts, name, "priority.online", NULL);
|
|
|
|
int priority_chat = g_key_file_get_integer(accounts, name, "priority.chat", NULL);
|
|
|
|
int priority_away = g_key_file_get_integer(accounts, name, "priority.away", NULL);
|
|
|
|
int priority_xa = g_key_file_get_integer(accounts, name, "priority.xa", NULL);
|
|
|
|
int priority_dnd = g_key_file_get_integer(accounts, name, "priority.dnd", NULL);
|
2013-01-31 17:48:21 -05:00
|
|
|
|
2016-11-19 21:09:34 -05:00
|
|
|
gchar *muc_service = NULL;
|
|
|
|
if (g_key_file_has_key(accounts, name, "muc.service", NULL)) {
|
|
|
|
muc_service = g_key_file_get_string(accounts, name, "muc.service", NULL);
|
|
|
|
} else {
|
|
|
|
jabber_conn_status_t conn_status = connection_get_status();
|
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
char* conf_jid = connection_jid_for_feature(XMPP_FEATURE_MUC);
|
|
|
|
if (conf_jid) {
|
|
|
|
muc_service = strdup(conf_jid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-12 18:30:35 -04:00
|
|
|
gchar *muc_nick = g_key_file_get_string(accounts, name, "muc.nick", NULL);
|
2013-05-23 17:29:41 -04:00
|
|
|
|
2014-05-11 09:13:15 -04:00
|
|
|
gchar *otr_policy = NULL;
|
|
|
|
if (g_key_file_has_key(accounts, name, "otr.policy", NULL)) {
|
|
|
|
otr_policy = g_key_file_get_string(accounts, name, "otr.policy", NULL);
|
|
|
|
}
|
|
|
|
|
2014-05-11 14:32:07 -04:00
|
|
|
gsize length;
|
|
|
|
GList *otr_manual = NULL;
|
|
|
|
gchar **manual = g_key_file_get_string_list(accounts, name, "otr.manual", &length, NULL);
|
2015-05-04 17:32:42 -04:00
|
|
|
if (manual) {
|
2014-05-11 14:32:07 -04:00
|
|
|
int i = 0;
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
otr_manual = g_list_append(otr_manual, strdup(manual[i]));
|
|
|
|
}
|
|
|
|
g_strfreev(manual);
|
|
|
|
}
|
|
|
|
|
|
|
|
GList *otr_opportunistic = NULL;
|
|
|
|
gchar **opportunistic = g_key_file_get_string_list(accounts, name, "otr.opportunistic", &length, NULL);
|
2015-05-04 17:32:42 -04:00
|
|
|
if (opportunistic) {
|
2014-05-11 14:32:07 -04:00
|
|
|
int i = 0;
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
otr_opportunistic = g_list_append(otr_opportunistic, strdup(opportunistic[i]));
|
|
|
|
}
|
|
|
|
g_strfreev(opportunistic);
|
|
|
|
}
|
|
|
|
|
|
|
|
GList *otr_always = NULL;
|
|
|
|
gchar **always = g_key_file_get_string_list(accounts, name, "otr.always", &length, NULL);
|
2015-05-04 17:32:42 -04:00
|
|
|
if (always) {
|
2014-05-11 14:32:07 -04:00
|
|
|
int i = 0;
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
otr_always = g_list_append(otr_always, strdup(always[i]));
|
|
|
|
}
|
|
|
|
g_strfreev(always);
|
|
|
|
}
|
|
|
|
|
2015-03-23 19:38:06 -04:00
|
|
|
gchar *pgp_keyid = NULL;
|
|
|
|
if (g_key_file_has_key(accounts, name, "pgp.keyid", NULL)) {
|
|
|
|
pgp_keyid = g_key_file_get_string(accounts, name, "pgp.keyid", NULL);
|
|
|
|
}
|
|
|
|
|
2015-10-14 20:19:24 -04:00
|
|
|
gchar *startscript = NULL;
|
|
|
|
if (g_key_file_has_key(accounts, name, "script.start", NULL)) {
|
|
|
|
startscript = g_key_file_get_string(accounts, name, "script.start", NULL);
|
|
|
|
}
|
|
|
|
|
2016-01-21 20:06:28 -05:00
|
|
|
gchar *theme = NULL;
|
|
|
|
if (g_key_file_has_key(accounts, name, "theme", NULL)) {
|
|
|
|
theme = g_key_file_get_string(accounts, name, "theme", NULL);
|
|
|
|
}
|
|
|
|
|
2015-10-17 22:06:23 -04:00
|
|
|
gchar *tls_policy = g_key_file_get_string(accounts, name, "tls.policy", NULL);
|
|
|
|
if (tls_policy && ((g_strcmp0(tls_policy, "force") != 0) &&
|
|
|
|
(g_strcmp0(tls_policy, "allow") != 0) &&
|
|
|
|
(g_strcmp0(tls_policy, "disable") != 0))) {
|
|
|
|
g_free(tls_policy);
|
|
|
|
tls_policy = NULL;
|
|
|
|
}
|
|
|
|
|
2015-01-07 00:00:02 -05:00
|
|
|
ProfAccount *new_account = account_new(name, jid, password, eval_password, enabled,
|
2014-01-22 17:22:01 -05:00
|
|
|
server, port, resource, last_presence, login_presence,
|
|
|
|
priority_online, priority_chat, priority_away, priority_xa,
|
2014-05-11 14:32:07 -04:00
|
|
|
priority_dnd, muc_service, muc_nick, otr_policy, otr_manual,
|
2016-01-21 20:06:28 -05:00
|
|
|
otr_opportunistic, otr_always, pgp_keyid, startscript, theme, tls_policy);
|
2012-12-09 17:14:38 -05:00
|
|
|
|
2014-01-22 17:22:01 -05:00
|
|
|
g_free(jid);
|
|
|
|
g_free(password);
|
2015-01-07 00:00:02 -05:00
|
|
|
g_free(eval_password);
|
2014-01-22 17:22:01 -05:00
|
|
|
g_free(server);
|
|
|
|
g_free(resource);
|
|
|
|
g_free(last_presence);
|
|
|
|
g_free(login_presence);
|
|
|
|
g_free(muc_service);
|
|
|
|
g_free(muc_nick);
|
2014-05-11 09:13:15 -04:00
|
|
|
g_free(otr_policy);
|
2015-03-23 19:38:06 -04:00
|
|
|
g_free(pgp_keyid);
|
2015-10-14 20:19:24 -04:00
|
|
|
g_free(startscript);
|
2016-01-21 20:06:28 -05:00
|
|
|
g_free(theme);
|
2015-10-17 22:06:23 -04:00
|
|
|
g_free(tls_policy);
|
2013-12-15 15:32:30 -05:00
|
|
|
|
2014-01-22 17:22:01 -05:00
|
|
|
return new_account;
|
2012-12-09 17:14:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
gboolean
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_enable(const char *const name)
|
2012-12-09 19:08:03 -05:00
|
|
|
{
|
|
|
|
if (g_key_file_has_group(accounts, name)) {
|
|
|
|
g_key_file_set_boolean(accounts, name, "enabled", TRUE);
|
|
|
|
_save_accounts();
|
2013-08-25 20:29:50 -04:00
|
|
|
autocomplete_add(enabled_ac, name);
|
2012-12-09 19:08:03 -05:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
gboolean
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_disable(const char *const name)
|
2012-12-09 19:08:03 -05:00
|
|
|
{
|
|
|
|
if (g_key_file_has_group(accounts, name)) {
|
|
|
|
g_key_file_set_boolean(accounts, name, "enabled", FALSE);
|
|
|
|
_save_accounts();
|
2013-08-25 20:29:50 -04:00
|
|
|
autocomplete_remove(enabled_ac, name);
|
2012-12-09 19:08:03 -05:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
gboolean
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_rename(const char *const account_name, const char *const new_name)
|
2012-12-09 19:08:03 -05:00
|
|
|
{
|
|
|
|
if (g_key_file_has_group(accounts, new_name)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_key_file_has_group(accounts, account_name)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-09-28 16:24:49 -04:00
|
|
|
// treat all properties as strings for copy
|
|
|
|
gchar *string_keys[] = {
|
|
|
|
"enabled",
|
|
|
|
"jid",
|
|
|
|
"server",
|
|
|
|
"port",
|
|
|
|
"resource",
|
|
|
|
"password",
|
|
|
|
"eval_password",
|
|
|
|
"presence.last",
|
|
|
|
"presence.laststatus",
|
|
|
|
"presence.login",
|
|
|
|
"priority.online",
|
|
|
|
"priority.chat",
|
|
|
|
"priority.away",
|
|
|
|
"priority.xa",
|
|
|
|
"priority.dnd",
|
|
|
|
"muc.service",
|
|
|
|
"muc.nick",
|
|
|
|
"otr.policy",
|
|
|
|
"otr.manual",
|
|
|
|
"otr.opportunistic",
|
|
|
|
"otr.always",
|
|
|
|
"pgp.keyid",
|
2015-10-14 20:19:24 -04:00
|
|
|
"last.activity",
|
2015-10-17 22:06:23 -04:00
|
|
|
"script.start",
|
|
|
|
"tls.policy"
|
2015-09-28 16:24:49 -04:00
|
|
|
};
|
|
|
|
|
2013-01-30 20:37:42 -05:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(string_keys); i++) {
|
|
|
|
char *value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL);
|
2015-05-04 17:32:42 -04:00
|
|
|
if (value) {
|
2013-01-30 20:37:42 -05:00
|
|
|
g_key_file_set_string(accounts, new_name, string_keys[i], value);
|
2013-08-25 07:54:34 -04:00
|
|
|
g_free(value);
|
2013-01-30 20:37:42 -05:00
|
|
|
}
|
2013-01-26 17:25:00 -05:00
|
|
|
}
|
|
|
|
|
2012-12-09 19:08:03 -05:00
|
|
|
g_key_file_remove_group(accounts, account_name, NULL);
|
|
|
|
_save_accounts();
|
|
|
|
|
2013-08-25 20:29:50 -04:00
|
|
|
autocomplete_remove(all_ac, account_name);
|
|
|
|
autocomplete_add(all_ac, new_name);
|
2012-12-09 19:53:57 -05:00
|
|
|
if (g_key_file_get_boolean(accounts, new_name, "enabled", NULL)) {
|
2013-08-25 20:29:50 -04:00
|
|
|
autocomplete_remove(enabled_ac, account_name);
|
|
|
|
autocomplete_add(enabled_ac, new_name);
|
2012-12-09 19:53:57 -05:00
|
|
|
}
|
2012-12-09 19:08:03 -05:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
gboolean
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_account_exists(const char *const account_name)
|
2012-12-09 19:23:55 -05:00
|
|
|
{
|
|
|
|
return g_key_file_has_group(accounts, account_name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_jid(const char *const account_name, const char *const value)
|
2012-12-09 19:23:55 -05:00
|
|
|
{
|
2013-01-27 15:23:42 -05:00
|
|
|
Jid *jid = jid_create(value);
|
2015-05-04 17:32:42 -04:00
|
|
|
if (jid) {
|
2013-01-27 15:23:42 -05:00
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_set_string(accounts, account_name, "jid", jid->barejid);
|
2015-05-04 17:32:42 -04:00
|
|
|
if (jid->resourcepart) {
|
2013-01-27 15:23:42 -05:00
|
|
|
g_key_file_set_string(accounts, account_name, "resource", jid->resourcepart);
|
|
|
|
}
|
2013-09-12 18:30:35 -04:00
|
|
|
|
|
|
|
if (jid->localpart == NULL) {
|
|
|
|
g_key_file_set_string(accounts, account_name, "muc.nick", jid->domainpart);
|
|
|
|
} else {
|
|
|
|
g_key_file_set_string(accounts, account_name, "muc.nick", jid->localpart);
|
|
|
|
}
|
|
|
|
|
2013-01-27 15:23:42 -05:00
|
|
|
_save_accounts();
|
|
|
|
}
|
2015-06-24 15:53:04 -04:00
|
|
|
|
|
|
|
jid_destroy(jid);
|
2012-12-09 19:23:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_server(const char *const account_name, const char *const value)
|
2012-12-09 19:23:55 -05:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_set_string(accounts, account_name, "server", value);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_port(const char *const account_name, const int value)
|
2014-01-17 20:45:05 -05:00
|
|
|
{
|
|
|
|
if (value != 0) {
|
|
|
|
g_key_file_set_integer(accounts, account_name, "port", value);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_resource(const char *const account_name, const char *const value)
|
2013-01-27 15:34:56 -05:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_set_string(accounts, account_name, "resource", value);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_password(const char *const account_name, const char *const value)
|
2013-11-07 18:36:04 -05:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_set_string(accounts, account_name, "password", value);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-07 00:00:02 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_eval_password(const char *const account_name, const char *const value)
|
2015-01-07 00:00:02 -05:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_set_string(accounts, account_name, "eval_password", value);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-23 19:38:06 -04:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_pgp_keyid(const char *const account_name, const char *const value)
|
2015-03-23 19:38:06 -04:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_set_string(accounts, account_name, "pgp.keyid", value);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-14 20:19:24 -04:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_script_start(const char *const account_name, const char *const value)
|
2015-10-14 20:19:24 -04:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_set_string(accounts, account_name, "script.start", value);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-21 20:06:28 -05:00
|
|
|
void
|
|
|
|
accounts_set_theme(const char *const account_name, const char *const value)
|
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_set_string(accounts, account_name, "theme", value);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_clear_password(const char *const account_name)
|
2013-12-08 18:36:00 -05:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_remove_key(accounts, account_name, "password", NULL);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-07 01:17:59 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_clear_eval_password(const char *const account_name)
|
2015-01-07 01:17:59 -05:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_remove_key(accounts, account_name, "eval_password", NULL);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_clear_server(const char *const account_name)
|
2014-10-23 18:07:27 -04:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_remove_key(accounts, account_name, "server", NULL);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_clear_port(const char *const account_name)
|
2014-10-23 18:12:15 -04:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_remove_key(accounts, account_name, "port", NULL);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-23 19:38:06 -04:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_clear_pgp_keyid(const char *const account_name)
|
2015-03-23 19:38:06 -04:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_remove_key(accounts, account_name, "pgp.keyid", NULL);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-14 20:19:24 -04:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_clear_script_start(const char *const account_name)
|
2015-10-14 20:19:24 -04:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_remove_key(accounts, account_name, "script.start", NULL);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
2016-01-21 20:06:28 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
accounts_clear_theme(const char *const account_name)
|
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_remove_key(accounts, account_name, "theme", NULL);
|
|
|
|
_save_accounts();
|
2016-11-19 21:09:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
accounts_clear_muc(const char *const account_name)
|
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_remove_key(accounts, account_name, "muc.service", NULL);
|
|
|
|
_save_accounts();
|
2016-01-21 20:06:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_clear_otr(const char *const account_name)
|
2014-05-11 10:32:38 -04:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_remove_key(accounts, account_name, "otr.policy", NULL);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_add_otr_policy(const char *const account_name, const char *const contact_jid, const char *const policy)
|
2014-05-11 13:13:04 -04:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
GString *key = g_string_new("otr.");
|
|
|
|
g_string_append(key, policy);
|
2015-11-23 19:02:21 -05:00
|
|
|
conf_string_list_add(accounts, account_name, key->str, contact_jid);
|
2014-05-11 13:13:04 -04:00
|
|
|
g_string_free(key, TRUE);
|
|
|
|
|
|
|
|
// check for and remove from other lists
|
|
|
|
if (strcmp(policy, "manual") == 0) {
|
2015-11-23 18:54:14 -05:00
|
|
|
conf_string_list_remove(accounts, account_name, "otr.opportunistic", contact_jid);
|
|
|
|
conf_string_list_remove(accounts, account_name, "otr.always", contact_jid);
|
2014-05-11 13:13:04 -04:00
|
|
|
}
|
|
|
|
if (strcmp(policy, "opportunistic") == 0) {
|
2015-11-23 18:54:14 -05:00
|
|
|
conf_string_list_remove(accounts, account_name, "otr.manual", contact_jid);
|
|
|
|
conf_string_list_remove(accounts, account_name, "otr.always", contact_jid);
|
2014-05-11 13:13:04 -04:00
|
|
|
}
|
|
|
|
if (strcmp(policy, "always") == 0) {
|
2015-11-23 18:54:14 -05:00
|
|
|
conf_string_list_remove(accounts, account_name, "otr.opportunistic", contact_jid);
|
|
|
|
conf_string_list_remove(accounts, account_name, "otr.manual", contact_jid);
|
2014-05-11 13:13:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_muc_service(const char *const account_name, const char *const value)
|
2013-09-12 18:30:35 -04:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_set_string(accounts, account_name, "muc.service", value);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_muc_nick(const char *const account_name, const char *const value)
|
2013-09-12 18:30:35 -04:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_set_string(accounts, account_name, "muc.nick", value);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_otr_policy(const char *const account_name, const char *const value)
|
2014-05-11 09:13:15 -04:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_set_string(accounts, account_name, "otr.policy", value);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-17 22:06:23 -04:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_tls_policy(const char *const account_name, const char *const value)
|
2015-10-17 22:06:23 -04:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_set_string(accounts, account_name, "tls.policy", value);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_priority_online(const char *const account_name, const gint value)
|
2013-01-30 20:50:37 -05:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_set_integer(accounts, account_name, "priority.online", value);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_priority_chat(const char *const account_name, const gint value)
|
2013-01-30 20:50:37 -05:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_set_integer(accounts, account_name, "priority.chat", value);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_priority_away(const char *const account_name, const gint value)
|
2013-01-30 20:50:37 -05:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_set_integer(accounts, account_name, "priority.away", value);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_priority_xa(const char *const account_name, const gint value)
|
2013-01-30 20:50:37 -05:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_set_integer(accounts, account_name, "priority.xa", value);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_priority_dnd(const char *const account_name, const gint value)
|
2013-01-30 20:50:37 -05:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_set_integer(accounts, account_name, "priority.dnd", value);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_priority_all(const char *const account_name, const gint value)
|
2013-01-30 20:50:37 -05:00
|
|
|
{
|
2013-01-31 17:48:21 -05:00
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
accounts_set_priority_online(account_name, value);
|
|
|
|
accounts_set_priority_chat(account_name, value);
|
|
|
|
accounts_set_priority_away(account_name, value);
|
|
|
|
accounts_set_priority_xa(account_name, value);
|
|
|
|
accounts_set_priority_dnd(account_name, value);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
2013-01-30 20:50:37 -05:00
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
gint
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_get_priority_for_presence_type(const char *const account_name,
|
2013-02-10 12:13:19 -05:00
|
|
|
resource_presence_t presence_type)
|
2013-01-30 20:50:37 -05:00
|
|
|
{
|
2013-01-31 17:48:21 -05:00
|
|
|
gint result;
|
|
|
|
|
|
|
|
switch (presence_type)
|
|
|
|
{
|
2013-02-10 12:13:19 -05:00
|
|
|
case (RESOURCE_ONLINE):
|
2013-01-31 17:48:21 -05:00
|
|
|
result = g_key_file_get_integer(accounts, account_name, "priority.online", NULL);
|
|
|
|
break;
|
2013-02-10 12:13:19 -05:00
|
|
|
case (RESOURCE_CHAT):
|
2013-01-31 17:48:21 -05:00
|
|
|
result = g_key_file_get_integer(accounts, account_name, "priority.chat", NULL);
|
|
|
|
break;
|
2013-02-10 12:13:19 -05:00
|
|
|
case (RESOURCE_AWAY):
|
2013-01-31 17:48:21 -05:00
|
|
|
result = g_key_file_get_integer(accounts, account_name, "priority.away", NULL);
|
|
|
|
break;
|
2013-02-10 12:13:19 -05:00
|
|
|
case (RESOURCE_XA):
|
2013-01-31 17:48:21 -05:00
|
|
|
result = g_key_file_get_integer(accounts, account_name, "priority.xa", NULL);
|
|
|
|
break;
|
|
|
|
default:
|
2013-02-10 12:13:19 -05:00
|
|
|
result = g_key_file_get_integer(accounts, account_name, "priority.dnd", NULL);
|
2013-01-31 17:48:21 -05:00
|
|
|
break;
|
|
|
|
}
|
2013-02-03 18:46:20 -05:00
|
|
|
|
2013-02-03 15:09:56 -05:00
|
|
|
if (result < JABBER_PRIORITY_MIN || result > JABBER_PRIORITY_MAX)
|
|
|
|
result = 0;
|
2013-01-30 20:50:37 -05:00
|
|
|
|
2013-01-31 17:48:21 -05:00
|
|
|
return result;
|
2013-01-30 20:50:37 -05:00
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_last_presence(const char *const account_name, const char *const value)
|
2013-01-27 17:27:30 -05:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_set_string(accounts, account_name, "presence.last", value);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-27 18:08:30 -04:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_last_status(const char *const account_name, const char *const value)
|
2015-09-27 18:08:30 -04:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
if (value) {
|
|
|
|
g_key_file_set_string(accounts, account_name, "presence.laststatus", value);
|
|
|
|
} else {
|
|
|
|
g_key_file_remove_key(accounts, account_name, "presence.laststatus", NULL);
|
|
|
|
}
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-24 19:26:58 -04:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_last_activity(const char *const account_name)
|
2015-09-24 19:26:58 -04:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
GDateTime *nowdt = g_date_time_new_now_utc();
|
|
|
|
GTimeVal nowtv;
|
|
|
|
gboolean res = g_date_time_to_timeval(nowdt, &nowtv);
|
|
|
|
g_date_time_unref(nowdt);
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
char *timestr = g_time_val_to_iso8601(&nowtv);
|
|
|
|
g_key_file_set_string(accounts, account_name, "last.activity", timestr);
|
2015-09-27 18:53:06 -04:00
|
|
|
free(timestr);
|
2015-09-24 19:26:58 -04:00
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-24 19:46:12 -04:00
|
|
|
char*
|
|
|
|
accounts_get_last_activity(const char *const account_name)
|
2015-09-27 18:53:06 -04:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
return g_key_file_get_string(accounts, account_name, "last.activity", NULL);
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_set_login_presence(const char *const account_name, const char *const value)
|
2013-01-27 17:27:30 -05:00
|
|
|
{
|
|
|
|
if (accounts_account_exists(account_name)) {
|
|
|
|
g_key_file_set_string(accounts, account_name, "presence.login", value);
|
|
|
|
_save_accounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
resource_presence_t
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_get_last_presence(const char *const account_name)
|
2013-01-30 19:01:38 -05:00
|
|
|
{
|
2013-08-25 07:54:34 -04:00
|
|
|
resource_presence_t result;
|
2013-01-30 19:01:38 -05:00
|
|
|
gchar *setting = g_key_file_get_string(accounts, account_name, "presence.last", NULL);
|
2013-08-25 07:54:34 -04:00
|
|
|
|
2013-01-30 19:01:38 -05:00
|
|
|
if (setting == NULL || (strcmp(setting, "online") == 0)) {
|
2013-08-25 07:54:34 -04:00
|
|
|
result = RESOURCE_ONLINE;
|
2013-01-30 19:01:38 -05:00
|
|
|
} else if (strcmp(setting, "chat") == 0) {
|
2013-08-25 07:54:34 -04:00
|
|
|
result = RESOURCE_CHAT;
|
2013-01-30 19:01:38 -05:00
|
|
|
} else if (strcmp(setting, "away") == 0) {
|
2013-08-25 07:54:34 -04:00
|
|
|
result = RESOURCE_AWAY;
|
2013-01-30 19:01:38 -05:00
|
|
|
} else if (strcmp(setting, "xa") == 0) {
|
2013-08-25 07:54:34 -04:00
|
|
|
result = RESOURCE_XA;
|
2013-01-30 19:01:38 -05:00
|
|
|
} else if (strcmp(setting, "dnd") == 0) {
|
2013-08-25 07:54:34 -04:00
|
|
|
result = RESOURCE_DND;
|
2013-01-30 19:01:38 -05:00
|
|
|
} else {
|
|
|
|
log_warning("Error reading presence.last for account: '%s', value: '%s', defaulting to 'online'",
|
|
|
|
account_name, setting);
|
2013-08-25 07:54:34 -04:00
|
|
|
result = RESOURCE_ONLINE;
|
2013-01-30 19:01:38 -05:00
|
|
|
}
|
2013-08-25 07:54:34 -04:00
|
|
|
|
2015-05-04 17:32:42 -04:00
|
|
|
if (setting) {
|
2013-08-25 07:54:34 -04:00
|
|
|
g_free(setting);
|
|
|
|
}
|
|
|
|
return result;
|
2013-01-30 19:01:38 -05:00
|
|
|
}
|
|
|
|
|
2015-10-24 19:46:12 -04:00
|
|
|
char*
|
|
|
|
accounts_get_last_status(const char *const account_name)
|
2015-09-27 18:08:30 -04:00
|
|
|
{
|
|
|
|
return g_key_file_get_string(accounts, account_name, "presence.laststatus", NULL);
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
resource_presence_t
|
2015-10-24 19:46:12 -04:00
|
|
|
accounts_get_login_presence(const char *const account_name)
|
2013-01-30 17:59:09 -05:00
|
|
|
{
|
2013-08-25 07:54:34 -04:00
|
|
|
resource_presence_t result;
|
2013-01-30 17:59:09 -05:00
|
|
|
gchar *setting = g_key_file_get_string(accounts, account_name, "presence.login", NULL);
|
2013-08-25 07:54:34 -04:00
|
|
|
|
2013-01-30 19:01:38 -05:00
|
|
|
if (setting == NULL || (strcmp(setting, "online") == 0)) {
|
2013-08-25 07:54:34 -04:00
|
|
|
result = RESOURCE_ONLINE;
|
2013-01-30 19:01:38 -05:00
|
|
|
} else if (strcmp(setting, "chat") == 0) {
|
2013-08-25 07:54:34 -04:00
|
|
|
result = RESOURCE_CHAT;
|
2013-01-30 19:01:38 -05:00
|
|
|
} else if (strcmp(setting, "away") == 0) {
|
2013-08-25 07:54:34 -04:00
|
|
|
result = RESOURCE_AWAY;
|
2013-01-30 19:01:38 -05:00
|
|
|
} else if (strcmp(setting, "xa") == 0) {
|
2013-08-25 07:54:34 -04:00
|
|
|
result = RESOURCE_XA;
|
2013-01-30 19:01:38 -05:00
|
|
|
} else if (strcmp(setting, "dnd") == 0) {
|
2013-08-25 07:54:34 -04:00
|
|
|
result = RESOURCE_DND;
|
2013-01-30 19:01:38 -05:00
|
|
|
} else if (strcmp(setting, "last") == 0) {
|
2013-08-25 07:54:34 -04:00
|
|
|
result = accounts_get_last_presence(account_name);
|
2013-01-30 19:01:38 -05:00
|
|
|
} else {
|
2013-01-30 17:59:09 -05:00
|
|
|
log_warning("Error reading presence.login for account: '%s', value: '%s', defaulting to 'online'",
|
|
|
|
account_name, setting);
|
2013-08-25 07:54:34 -04:00
|
|
|
result = RESOURCE_ONLINE;
|
2013-01-30 17:59:09 -05:00
|
|
|
}
|
2013-08-25 07:54:34 -04:00
|
|
|
|
2015-05-04 17:32:42 -04:00
|
|
|
if (setting) {
|
2013-08-25 07:54:34 -04:00
|
|
|
g_free(setting);
|
|
|
|
}
|
|
|
|
return result;
|
2013-01-30 17:59:09 -05:00
|
|
|
}
|
|
|
|
|
2012-12-01 20:29:42 -05:00
|
|
|
static void
|
|
|
|
_save_accounts(void)
|
|
|
|
{
|
|
|
|
gsize g_data_size;
|
2013-08-25 07:54:34 -04:00
|
|
|
gchar *g_accounts_data = g_key_file_to_data(accounts, &g_data_size, NULL);
|
2016-07-24 16:35:12 -04:00
|
|
|
|
|
|
|
gchar *base = g_path_get_basename(accounts_loc);
|
|
|
|
gchar *true_loc = get_file_or_linked(accounts_loc, base);
|
2014-10-26 16:43:05 -04:00
|
|
|
g_file_set_contents(true_loc, g_accounts_data, g_data_size, NULL);
|
2014-10-18 16:23:42 -04:00
|
|
|
g_chmod(accounts_loc, S_IRUSR | S_IWUSR);
|
2016-07-24 16:35:12 -04:00
|
|
|
|
|
|
|
g_free(base);
|
2014-10-26 16:43:05 -04:00
|
|
|
free(true_loc);
|
2013-08-25 07:54:34 -04:00
|
|
|
g_free(g_accounts_data);
|
2015-01-07 00:00:02 -05:00
|
|
|
}
|