mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-31 14:06:21 +00:00
merge: sync upstream profanity-im/profanity
Sync with upstream profanity-im/profanity.
Major upstream changes incorporated:
Memory management
- Replace malloc+memset with g_new0 throughout codebase
- Adopt auto_gchar / auto_gcharv / auto_gerror / auto_jid cleanup macros
- Replace free() with g_free() for GAlloc'd memory
Editor rewrite
- Remove pthread-based async editor; use GChildWatch callback API
- New launch_editor(initial_content, callback, user_data) interface
- Proper signal handling (SIGINT, SIGTSTP, SIGPIPE reset in child)
- ui_suspend()/ui_resume() integration for TTY management
OMEMO improvements
- Dual backend support: libsignal-protocol-c and libomemo-c
- Proper pre-key removal after use (XEP-0384 compliance)
- Automatic pre-key regeneration when store drops below threshold
- New functions: omemo_is_device_active(), omemo_is_jid_trusted()
- omemo_get_jid_untrusted_fingerprints() for better error messages
- Fingerprint notifications on new device identity discovery
- Deterministic pre-key ID generation tracking max_pre_key_id
- omemo_trust_changed() UI updates on trust state changes
JID validation
- RFC 6122-compliant validation in jid_is_valid()
- Character-level checks (RFC 6122 forbidden chars: & ' / : < > @)
- Length limits: 1023 per component, 3071 total
- New jid_is_valid_user_jid() for user vs. service JID distinction
Database
- Schema migration v3: UNIQUE constraint on archive_id for deduplication
- Triggers for corrected message tracking (replaces_db_id / replaced_by_db_id)
- db_history_result_t return type, _truncate_datetime_suffix()
UI / console
- win_warn_needed() / win_warn_sent() warning deduplication hash table
- PAD_MIN_HEIGHT dynamic pad sizing with PAD_THRESHOLD auto-cleanup
- Spellcheck integration in input field with Unicode word detection
- cons_spellcheck_setting() for /settings ui output
- /[command]? shortcut for command help
Account config
- Account name sanitization for GKeyFile special chars ([ ] = # \n \r)
- Replace popen() with g_spawn_sync() for eval_password
- TLS policy: add "direct" option alongside legacy
Connection
- Port validation with g_assert (0–65535)
- SHA-256 certificate fingerprint support (XMPP_CERT_PUBKEY_FINGERPRINT_SHA256)
- "direct" TLS policy alias for legacy SSL
Common utilities
- str_xml_sanitize() for XML 1.0 illegal character removal
- string_matches_one_of() with formatted error messages
- valid_tls_policy_option() helper
- prof_date_time_format_iso8601() utility
- Improved strip_arg_quotes() with backslash unescaping
- prof_occurrences() uses g_slist_prepend + reverse for performance
PGP / OX
- Proper GPGME resource cleanup with goto-cleanup pattern
- g_string_free(xmppuri) leak fix in _ox_key_lookup
CSV export
- Use GString + g_file_set_contents instead of raw write() syscalls
Tests
- Restructured into subdirectories: command/, config/, xmpp/, ui/, omemo/, otr/, pgp/
- New test_cmd_ac.c for autocompleter unit tests
- Updated stubs for new UI suspend/resume functions
License headers
- Migrate to SPDX-3.0 identifiers (GPL-3.0-or-later WITH OpenSSL-exception)
────────────────────────────────────────────────────
cproof-specific preservations:
- XEP-0308 LMC: replace_id ?: id logic in message/stanza/omemo
- Force encryption: cmd_force_encryption, test_forced_encryption
- CWE-134: format string protection (cons_show("%s", ...))
- y_start_pos-based paging in window.c
- db_history_result_t return type, _truncate_datetime_suffix()
Merge-time fixes:
- common.c: format-security (-Werror) — cons_show(errmsg) → cons_show("%s", errmsg)
- database.c: null-deref guard — !msg->timestamp → msg && !msg->timestamp
- console.c: implicit size_t → int cast — (int)(maxlen + 1)
- tlscerts.c: %d for size_t — %zu
Build system:
- Kept autotools (Makefile.am, configure.ac); upstream uses Meson
- Restored deleted files: bootstrap.sh, autogen.sh, ax_valgrind_check.m4, configure-debug
- Updated Makefile.am test paths for subdirectory structure
- Added test_cmd_ac, test_forced_encryption to test sources
Functional tests:
- Use cproof version; upstream requires stbbr_for_xmlns from updated stabber
- Not yet available in devs/stabber fork
Closes #64
Merge author: jabber.developer2
Commits authors:
Michael Vetter <jubalh@iodoru.org>
& Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
@@ -3,35 +3,9 @@
|
||||
* vim: expandtab:ts=4:sts=4:sw=4
|
||||
*
|
||||
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
|
||||
* Copyright (C) 2019 - 2025 Michael Vetter <jubalh@iodoru.org>
|
||||
*
|
||||
* 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
|
||||
* along with Profanity. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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.
|
||||
* Copyright (C) 2019 - 2026 Michael Vetter <jubalh@iodoru.org>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
@@ -59,7 +33,74 @@ static GKeyFile* accounts;
|
||||
static Autocomplete all_ac;
|
||||
static Autocomplete enabled_ac;
|
||||
|
||||
static void _save_accounts(void);
|
||||
static gchar*
|
||||
_sanitize_account_name(const char* const name)
|
||||
{
|
||||
if (!name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gchar* sanitized = g_strdup(name);
|
||||
gchar* p = sanitized;
|
||||
while (*p) {
|
||||
// GKeyFile special characters: [ ] = # \n \r
|
||||
if (*p == '[' || *p == ']' || *p == '=' || *p == '#' || *p == '\n' || *p == '\r') {
|
||||
*p = '_';
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
return sanitized;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_accounts_has_group(const char* account_name)
|
||||
{
|
||||
if (!account_name || !accounts)
|
||||
return FALSE;
|
||||
|
||||
auto_gchar gchar* sanitized = _sanitize_account_name(account_name);
|
||||
return g_key_file_has_group(accounts, sanitized);
|
||||
}
|
||||
|
||||
static void
|
||||
_accounts_save(const char* account_name)
|
||||
{
|
||||
prof_keyfile_t current;
|
||||
|
||||
if (!load_data_keyfile(¤t, FILE_ACCOUNTS)) {
|
||||
log_error("Could not load accounts");
|
||||
return;
|
||||
}
|
||||
|
||||
auto_gchar gchar* sanitized = _sanitize_account_name(account_name);
|
||||
|
||||
if (_accounts_has_group(sanitized)) {
|
||||
// Remove keys from file that are no longer in memory
|
||||
gsize nkeys_disk;
|
||||
auto_gcharv gchar** keys_disk = g_key_file_get_keys(current.keyfile, sanitized, &nkeys_disk, NULL);
|
||||
if (keys_disk) {
|
||||
for (gsize j = 0; j < nkeys_disk; ++j) {
|
||||
if (!g_key_file_has_key(accounts_prof_keyfile.keyfile, sanitized, keys_disk[j], NULL)) {
|
||||
g_key_file_remove_key(current.keyfile, sanitized, keys_disk[j], NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gsize nkeys;
|
||||
auto_gcharv gchar** keys = g_key_file_get_keys(accounts_prof_keyfile.keyfile, sanitized, &nkeys, NULL);
|
||||
if (keys) {
|
||||
for (gsize j = 0; j < nkeys; ++j) {
|
||||
auto_gchar gchar* new_value = g_key_file_get_value(accounts_prof_keyfile.keyfile, sanitized, keys[j], NULL);
|
||||
g_key_file_set_value(current.keyfile, sanitized, keys[j], new_value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
g_key_file_remove_group(current.keyfile, sanitized, NULL);
|
||||
}
|
||||
save_keyfile(¤t);
|
||||
free_keyfile(¤t);
|
||||
}
|
||||
|
||||
static void
|
||||
_accounts_close(void)
|
||||
@@ -79,7 +120,9 @@ accounts_load(void)
|
||||
|
||||
all_ac = autocomplete_new();
|
||||
enabled_ac = autocomplete_new();
|
||||
load_data_keyfile(&accounts_prof_keyfile, FILE_ACCOUNTS);
|
||||
if (!load_data_keyfile(&accounts_prof_keyfile, FILE_ACCOUNTS)) {
|
||||
log_error("Could not load accounts");
|
||||
}
|
||||
accounts = accounts_prof_keyfile.keyfile;
|
||||
|
||||
// create the logins searchable list for autocompletion
|
||||
@@ -132,54 +175,58 @@ accounts_add(const char* account_name, const char* altdomain, const int port, co
|
||||
}
|
||||
}
|
||||
|
||||
if (g_key_file_has_group(accounts, account_name)) {
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
|
||||
if (_accounts_has_group(sanitized_account_name)) {
|
||||
log_error("Can't add account \"%s\", it already exists.", account_name);
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
g_key_file_set_boolean(accounts, sanitized_account_name, "enabled", TRUE);
|
||||
g_key_file_set_string(accounts, sanitized_account_name, "jid", barejid);
|
||||
g_key_file_set_string(accounts, sanitized_account_name, "resource", resource);
|
||||
if (altdomain) {
|
||||
g_key_file_set_string(accounts, account_name, "server", altdomain);
|
||||
g_key_file_set_string(accounts, sanitized_account_name, "server", altdomain);
|
||||
}
|
||||
if (port != 0) {
|
||||
g_key_file_set_integer(accounts, account_name, "port", port);
|
||||
g_key_file_set_integer(accounts, sanitized_account_name, "port", port);
|
||||
}
|
||||
if (tls_policy) {
|
||||
g_key_file_set_string(accounts, account_name, "tls.policy", tls_policy);
|
||||
g_key_file_set_string(accounts, sanitized_account_name, "tls.policy", tls_policy);
|
||||
}
|
||||
if (auth_policy) {
|
||||
g_key_file_set_string(accounts, account_name, "auth.policy", auth_policy);
|
||||
g_key_file_set_string(accounts, sanitized_account_name, "auth.policy", auth_policy);
|
||||
}
|
||||
|
||||
auto_jid Jid* jidp = jid_create(barejid);
|
||||
|
||||
if (jidp->localpart == NULL) {
|
||||
g_key_file_set_string(accounts, account_name, "muc.nick", jidp->domainpart);
|
||||
g_key_file_set_string(accounts, sanitized_account_name, "muc.nick", jidp->domainpart);
|
||||
} else {
|
||||
g_key_file_set_string(accounts, account_name, "muc.nick", jidp->localpart);
|
||||
g_key_file_set_string(accounts, sanitized_account_name, "muc.nick", jidp->localpart);
|
||||
}
|
||||
|
||||
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);
|
||||
g_key_file_set_string(accounts, sanitized_account_name, "presence.last", "online");
|
||||
g_key_file_set_string(accounts, sanitized_account_name, "presence.login", "online");
|
||||
g_key_file_set_integer(accounts, sanitized_account_name, "priority.online", 0);
|
||||
g_key_file_set_integer(accounts, sanitized_account_name, "priority.chat", 0);
|
||||
g_key_file_set_integer(accounts, sanitized_account_name, "priority.away", 0);
|
||||
g_key_file_set_integer(accounts, sanitized_account_name, "priority.xa", 0);
|
||||
g_key_file_set_integer(accounts, sanitized_account_name, "priority.dnd", 0);
|
||||
|
||||
_save_accounts();
|
||||
autocomplete_add(all_ac, account_name);
|
||||
autocomplete_add(enabled_ac, account_name);
|
||||
_accounts_save(account_name);
|
||||
autocomplete_add(all_ac, sanitized_account_name);
|
||||
autocomplete_add(enabled_ac, sanitized_account_name);
|
||||
}
|
||||
|
||||
int
|
||||
gboolean
|
||||
accounts_remove(const char* account_name)
|
||||
{
|
||||
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);
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
gboolean r = g_key_file_remove_group(accounts, sanitized_account_name, NULL);
|
||||
_accounts_save(account_name);
|
||||
autocomplete_remove(all_ac, sanitized_account_name);
|
||||
autocomplete_remove(enabled_ac, sanitized_account_name);
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -189,167 +236,123 @@ accounts_get_list(void)
|
||||
return g_key_file_get_groups(accounts, NULL);
|
||||
}
|
||||
|
||||
ProfAccount*
|
||||
accounts_get_account(const char* const name)
|
||||
static GList*
|
||||
_g_strv_to_glist(gchar** in, gsize length)
|
||||
{
|
||||
if (!g_key_file_has_group(accounts, name)) {
|
||||
if (in == NULL)
|
||||
return NULL;
|
||||
GList* out = NULL;
|
||||
for (gsize i = 0; i < length; i++) {
|
||||
out = g_list_append(out, in[i]);
|
||||
}
|
||||
g_free(in);
|
||||
return out;
|
||||
}
|
||||
|
||||
static GList*
|
||||
_accounts_get_glist(const gchar* sanitized_account_name,
|
||||
const gchar* key)
|
||||
{
|
||||
gsize length = 0;
|
||||
gchar** list = g_key_file_get_string_list(accounts, sanitized_account_name, key, &length, NULL);
|
||||
return _g_strv_to_glist(list, length);
|
||||
}
|
||||
|
||||
ProfAccount*
|
||||
accounts_get_account(const char* const account_name)
|
||||
{
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
if (!_accounts_has_group(sanitized_account_name)) {
|
||||
return NULL;
|
||||
} else {
|
||||
gchar* jid = g_key_file_get_string(accounts, name, "jid", NULL);
|
||||
gchar* jid = g_key_file_get_string(accounts, sanitized_account_name, "jid", NULL);
|
||||
|
||||
// fix accounts that have no jid property by setting to name
|
||||
// fix accounts that have no jid property by setting to account_name
|
||||
if (jid == NULL) {
|
||||
g_key_file_set_string(accounts, name, "jid", name);
|
||||
_save_accounts();
|
||||
g_key_file_set_string(accounts, sanitized_account_name, "jid", account_name);
|
||||
_accounts_save(account_name);
|
||||
}
|
||||
|
||||
gchar* password = g_key_file_get_string(accounts, name, "password", NULL);
|
||||
gchar* eval_password = g_key_file_get_string(accounts, name, "eval_password", NULL);
|
||||
gboolean enabled = g_key_file_get_boolean(accounts, name, "enabled", NULL);
|
||||
gchar* password = g_key_file_get_string(accounts, sanitized_account_name, "password", NULL);
|
||||
gchar* eval_password = g_key_file_get_string(accounts, sanitized_account_name, "eval_password", NULL);
|
||||
gboolean enabled = g_key_file_get_boolean(accounts, sanitized_account_name, "enabled", NULL);
|
||||
|
||||
gchar* server = g_key_file_get_string(accounts, name, "server", NULL);
|
||||
gchar* resource = g_key_file_get_string(accounts, name, "resource", NULL);
|
||||
int port = g_key_file_get_integer(accounts, name, "port", NULL);
|
||||
gchar* server = g_key_file_get_string(accounts, sanitized_account_name, "server", NULL);
|
||||
gchar* resource = g_key_file_get_string(accounts, sanitized_account_name, "resource", NULL);
|
||||
int port = g_key_file_get_integer(accounts, sanitized_account_name, "port", NULL);
|
||||
|
||||
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);
|
||||
gchar* last_presence = g_key_file_get_string(accounts, sanitized_account_name, "presence.last", NULL);
|
||||
gchar* login_presence = g_key_file_get_string(accounts, sanitized_account_name, "presence.login", NULL);
|
||||
|
||||
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);
|
||||
int priority_online = g_key_file_get_integer(accounts, sanitized_account_name, "priority.online", NULL);
|
||||
int priority_chat = g_key_file_get_integer(accounts, sanitized_account_name, "priority.chat", NULL);
|
||||
int priority_away = g_key_file_get_integer(accounts, sanitized_account_name, "priority.away", NULL);
|
||||
int priority_xa = g_key_file_get_integer(accounts, sanitized_account_name, "priority.xa", NULL);
|
||||
int priority_dnd = g_key_file_get_integer(accounts, sanitized_account_name, "priority.dnd", NULL);
|
||||
|
||||
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);
|
||||
if (g_key_file_has_key(accounts, sanitized_account_name, "muc.service", NULL)) {
|
||||
muc_service = g_key_file_get_string(accounts, sanitized_account_name, "muc.service", NULL);
|
||||
} else {
|
||||
jabber_conn_status_t conn_status = connection_get_status();
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
const char* conf_jid = connection_jid_for_feature(XMPP_FEATURE_MUC);
|
||||
if (conf_jid) {
|
||||
muc_service = strdup(conf_jid);
|
||||
muc_service = g_strdup(conf_jid);
|
||||
}
|
||||
}
|
||||
}
|
||||
gchar* muc_nick = g_key_file_get_string(accounts, name, "muc.nick", NULL);
|
||||
gchar* muc_nick = g_key_file_get_string(accounts, sanitized_account_name, "muc.nick", NULL);
|
||||
|
||||
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);
|
||||
}
|
||||
gchar* otr_policy = g_key_file_get_string(accounts, sanitized_account_name, "otr.policy", NULL);
|
||||
GList* otr_manual = _accounts_get_glist(sanitized_account_name, "otr.manual");
|
||||
GList* otr_opportunistic = _accounts_get_glist(sanitized_account_name, "otr.opportunistic");
|
||||
GList* otr_always = _accounts_get_glist(sanitized_account_name, "otr.always");
|
||||
|
||||
gsize length;
|
||||
GList* otr_manual = NULL;
|
||||
auto_gcharv gchar** manual = g_key_file_get_string_list(accounts, name, "otr.manual", &length, NULL);
|
||||
if (manual) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
otr_manual = g_list_append(otr_manual, strdup(manual[i]));
|
||||
}
|
||||
}
|
||||
gchar* omemo_policy = g_key_file_get_string(accounts, sanitized_account_name, "omemo.policy", NULL);
|
||||
GList* omemo_enabled = _accounts_get_glist(sanitized_account_name, "omemo.enabled");
|
||||
GList* omemo_disabled = _accounts_get_glist(sanitized_account_name, "omemo.disabled");
|
||||
|
||||
GList* otr_opportunistic = NULL;
|
||||
auto_gcharv gchar** opportunistic = g_key_file_get_string_list(accounts, name, "otr.opportunistic", &length, NULL);
|
||||
if (opportunistic) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
otr_opportunistic = g_list_append(otr_opportunistic, strdup(opportunistic[i]));
|
||||
}
|
||||
}
|
||||
GList* ox_enabled = _accounts_get_glist(sanitized_account_name, "ox.enabled");
|
||||
|
||||
GList* otr_always = NULL;
|
||||
auto_gcharv gchar** always = g_key_file_get_string_list(accounts, name, "otr.always", &length, NULL);
|
||||
if (always) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
otr_always = g_list_append(otr_always, strdup(always[i]));
|
||||
}
|
||||
}
|
||||
GList* pgp_enabled = _accounts_get_glist(sanitized_account_name, "pgp.enabled");
|
||||
|
||||
gchar* omemo_policy = NULL;
|
||||
if (g_key_file_has_key(accounts, name, "omemo.policy", NULL)) {
|
||||
omemo_policy = g_key_file_get_string(accounts, name, "omemo.policy", NULL);
|
||||
}
|
||||
gchar* pgp_keyid = g_key_file_get_string(accounts, sanitized_account_name, "pgp.keyid", NULL);
|
||||
|
||||
GList* omemo_enabled = NULL;
|
||||
auto_gcharv gchar** omemo_enabled_list = g_key_file_get_string_list(accounts, name, "omemo.enabled", &length, NULL);
|
||||
if (omemo_enabled_list) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
omemo_enabled = g_list_append(omemo_enabled, strdup(omemo_enabled_list[i]));
|
||||
}
|
||||
}
|
||||
gchar* startscript = g_key_file_get_string(accounts, sanitized_account_name, "script.start", NULL);
|
||||
|
||||
GList* omemo_disabled = NULL;
|
||||
auto_gcharv gchar** omemo_disabled_list = g_key_file_get_string_list(accounts, name, "omemo.disabled", &length, NULL);
|
||||
if (omemo_disabled_list) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
omemo_disabled = g_list_append(omemo_disabled, strdup(omemo_disabled_list[i]));
|
||||
}
|
||||
}
|
||||
gchar* client = g_key_file_get_string(accounts, sanitized_account_name, "client.account_name", NULL);
|
||||
|
||||
GList* ox_enabled = NULL;
|
||||
auto_gcharv gchar** ox_enabled_list = g_key_file_get_string_list(accounts, name, "ox.enabled", &length, NULL);
|
||||
if (ox_enabled_list) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
ox_enabled = g_list_append(ox_enabled, strdup(ox_enabled_list[i]));
|
||||
}
|
||||
}
|
||||
gchar* theme = g_key_file_get_string(accounts, sanitized_account_name, "theme", NULL);
|
||||
|
||||
GList* pgp_enabled = NULL;
|
||||
auto_gcharv gchar** pgp_enabled_list = g_key_file_get_string_list(accounts, name, "pgp.enabled", &length, NULL);
|
||||
if (pgp_enabled_list) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
pgp_enabled = g_list_append(pgp_enabled, strdup(pgp_enabled_list[i]));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
gchar* client = NULL;
|
||||
if (g_key_file_has_key(accounts, name, "client.name", NULL)) {
|
||||
client = g_key_file_get_string(accounts, name, "client.name", NULL);
|
||||
}
|
||||
|
||||
gchar* theme = NULL;
|
||||
if (g_key_file_has_key(accounts, name, "theme", NULL)) {
|
||||
theme = g_key_file_get_string(accounts, name, "theme", NULL);
|
||||
}
|
||||
|
||||
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, "trust") != 0) && (g_strcmp0(tls_policy, "disable") != 0) && (g_strcmp0(tls_policy, "legacy") != 0))) {
|
||||
gchar* tls_policy = g_key_file_get_string(accounts, sanitized_account_name, "tls.policy", NULL);
|
||||
if (tls_policy && !valid_tls_policy_option(tls_policy)) {
|
||||
g_free(tls_policy);
|
||||
tls_policy = NULL;
|
||||
}
|
||||
|
||||
gchar* auth_policy = g_key_file_get_string(accounts, name, "auth.policy", NULL);
|
||||
gchar* auth_policy = g_key_file_get_string(accounts, sanitized_account_name, "auth.policy", NULL);
|
||||
|
||||
int max_sessions = g_key_file_get_integer(accounts, name, "max.sessions", 0);
|
||||
int max_sessions = g_key_file_get_integer(accounts, sanitized_account_name, "max.sessions", 0);
|
||||
|
||||
ProfAccount* new_account = account_new(g_strdup(name), jid, password, eval_password, enabled,
|
||||
server, port, resource, last_presence, login_presence,
|
||||
priority_online, priority_chat, priority_away, priority_xa,
|
||||
priority_dnd, muc_service, muc_nick, otr_policy, otr_manual,
|
||||
otr_opportunistic, otr_always, omemo_policy, omemo_enabled,
|
||||
omemo_disabled, ox_enabled, pgp_enabled, pgp_keyid,
|
||||
startscript, theme, tls_policy, auth_policy, client, max_sessions);
|
||||
|
||||
return new_account;
|
||||
return account_new(g_strdup(account_name), jid, password, eval_password, enabled,
|
||||
server, port, resource, last_presence, login_presence,
|
||||
priority_online, priority_chat, priority_away, priority_xa,
|
||||
priority_dnd, muc_service, muc_nick, otr_policy, otr_manual,
|
||||
otr_opportunistic, otr_always, omemo_policy, omemo_enabled,
|
||||
omemo_disabled, ox_enabled, pgp_enabled, pgp_keyid,
|
||||
startscript, theme, tls_policy, auth_policy, client, max_sessions);
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
accounts_enable(const char* const name)
|
||||
accounts_enable(const char* const account_name)
|
||||
{
|
||||
if (g_key_file_has_group(accounts, name)) {
|
||||
g_key_file_set_boolean(accounts, name, "enabled", TRUE);
|
||||
_save_accounts();
|
||||
autocomplete_add(enabled_ac, name);
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
if (_accounts_has_group(sanitized_account_name)) {
|
||||
g_key_file_set_boolean(accounts, sanitized_account_name, "enabled", TRUE);
|
||||
_accounts_save(account_name);
|
||||
autocomplete_add(enabled_ac, sanitized_account_name);
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
@@ -357,12 +360,13 @@ accounts_enable(const char* const name)
|
||||
}
|
||||
|
||||
gboolean
|
||||
accounts_disable(const char* const name)
|
||||
accounts_disable(const char* const account_name)
|
||||
{
|
||||
if (g_key_file_has_group(accounts, name)) {
|
||||
g_key_file_set_boolean(accounts, name, "enabled", FALSE);
|
||||
_save_accounts();
|
||||
autocomplete_remove(enabled_ac, name);
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
if (_accounts_has_group(sanitized_account_name)) {
|
||||
g_key_file_set_boolean(accounts, sanitized_account_name, "enabled", FALSE);
|
||||
_accounts_save(account_name);
|
||||
autocomplete_remove(enabled_ac, sanitized_account_name);
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
@@ -372,63 +376,33 @@ accounts_disable(const char* const name)
|
||||
gboolean
|
||||
accounts_rename(const char* const account_name, const char* const new_name)
|
||||
{
|
||||
if (g_key_file_has_group(accounts, new_name)) {
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
auto_gchar gchar* sanitized_new_account_name = _sanitize_account_name(new_name);
|
||||
|
||||
if (_accounts_has_group(sanitized_new_account_name)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!g_key_file_has_group(accounts, account_name)) {
|
||||
if (!_accounts_has_group(sanitized_account_name)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// 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",
|
||||
"omemo.policy",
|
||||
"omemo.enabled",
|
||||
"omemo.disabled",
|
||||
"ox.enabled",
|
||||
"pgp.enabled",
|
||||
"pgp.keyid",
|
||||
"last.activity",
|
||||
"script.start",
|
||||
"tls.policy"
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(string_keys); i++) {
|
||||
auto_gchar gchar* value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL);
|
||||
if (value) {
|
||||
g_key_file_set_string(accounts, new_name, string_keys[i], value);
|
||||
}
|
||||
gsize nkeys;
|
||||
auto_gcharv gchar** keys = g_key_file_get_keys(accounts, sanitized_account_name, &nkeys, NULL);
|
||||
for (gsize i = 0; i < nkeys; i++) {
|
||||
auto_gchar gchar* new_value = g_key_file_get_value(accounts, sanitized_account_name, keys[i], NULL);
|
||||
g_key_file_set_value(accounts, sanitized_new_account_name, keys[i], new_value);
|
||||
}
|
||||
|
||||
g_key_file_remove_group(accounts, account_name, NULL);
|
||||
_save_accounts();
|
||||
g_key_file_remove_group(accounts, sanitized_account_name, NULL);
|
||||
_accounts_save(account_name);
|
||||
_accounts_save(new_name);
|
||||
|
||||
autocomplete_remove(all_ac, account_name);
|
||||
autocomplete_add(all_ac, new_name);
|
||||
if (g_key_file_get_boolean(accounts, new_name, "enabled", NULL)) {
|
||||
autocomplete_remove(enabled_ac, account_name);
|
||||
autocomplete_add(enabled_ac, new_name);
|
||||
autocomplete_remove(all_ac, sanitized_account_name);
|
||||
autocomplete_remove(enabled_ac, sanitized_account_name);
|
||||
autocomplete_add(all_ac, sanitized_new_account_name);
|
||||
if (g_key_file_get_boolean(accounts, sanitized_new_account_name, "enabled", NULL)) {
|
||||
autocomplete_add(enabled_ac, sanitized_new_account_name);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@@ -437,7 +411,7 @@ accounts_rename(const char* const account_name, const char* const new_name)
|
||||
gboolean
|
||||
accounts_account_exists(const char* const account_name)
|
||||
{
|
||||
return g_key_file_has_group(accounts, account_name);
|
||||
return _accounts_has_group(account_name);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -445,19 +419,20 @@ accounts_set_jid(const char* const account_name, const char* const value)
|
||||
{
|
||||
auto_jid Jid* jid = jid_create(value);
|
||||
if (jid) {
|
||||
if (accounts_account_exists(account_name)) {
|
||||
g_key_file_set_string(accounts, account_name, "jid", jid->barejid);
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
if (_accounts_has_group(sanitized_account_name)) {
|
||||
g_key_file_set_string(accounts, sanitized_account_name, "jid", jid->barejid);
|
||||
if (jid->resourcepart) {
|
||||
g_key_file_set_string(accounts, account_name, "resource", jid->resourcepart);
|
||||
g_key_file_set_string(accounts, sanitized_account_name, "resource", jid->resourcepart);
|
||||
}
|
||||
|
||||
if (jid->localpart == NULL) {
|
||||
g_key_file_set_string(accounts, account_name, "muc.nick", jid->domainpart);
|
||||
g_key_file_set_string(accounts, sanitized_account_name, "muc.nick", jid->domainpart);
|
||||
} else {
|
||||
g_key_file_set_string(accounts, account_name, "muc.nick", jid->localpart);
|
||||
g_key_file_set_string(accounts, sanitized_account_name, "muc.nick", jid->localpart);
|
||||
}
|
||||
|
||||
_save_accounts();
|
||||
_accounts_save(account_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -465,9 +440,10 @@ accounts_set_jid(const char* const account_name, const char* const value)
|
||||
void
|
||||
accounts_set_server(const char* const account_name, const char* const value)
|
||||
{
|
||||
if (accounts_account_exists(account_name)) {
|
||||
g_key_file_set_string(accounts, account_name, "server", value);
|
||||
_save_accounts();
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
if (_accounts_has_group(sanitized_account_name)) {
|
||||
g_key_file_set_string(accounts, sanitized_account_name, "server", value);
|
||||
_accounts_save(account_name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -475,35 +451,41 @@ void
|
||||
accounts_set_port(const char* const account_name, const int value)
|
||||
{
|
||||
if (value != 0) {
|
||||
g_key_file_set_integer(accounts, account_name, "port", value);
|
||||
_save_accounts();
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
if (_accounts_has_group(sanitized_account_name)) {
|
||||
g_key_file_set_integer(accounts, sanitized_account_name, "port", value);
|
||||
_accounts_save(account_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_accounts_set_string_option(const char* account_name, const char* const option, const char* const value)
|
||||
{
|
||||
if (accounts_account_exists(account_name)) {
|
||||
g_key_file_set_string(accounts, account_name, option, value ?: "");
|
||||
_save_accounts();
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
if (_accounts_has_group(sanitized_account_name)) {
|
||||
g_key_file_set_string(accounts, sanitized_account_name, option, value ?: "");
|
||||
_accounts_save(account_name);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_accounts_set_int_option(const char* account_name, const char* const option, int value)
|
||||
{
|
||||
if (accounts_account_exists(account_name)) {
|
||||
g_key_file_set_integer(accounts, account_name, option, value);
|
||||
_save_accounts();
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
if (_accounts_has_group(sanitized_account_name)) {
|
||||
g_key_file_set_integer(accounts, sanitized_account_name, option, value);
|
||||
_accounts_save(account_name);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_accounts_clear_string_option(const char* account_name, const char* const option)
|
||||
{
|
||||
if (accounts_account_exists(account_name)) {
|
||||
g_key_file_remove_key(accounts, account_name, option, NULL);
|
||||
_save_accounts();
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
if (_accounts_has_group(sanitized_account_name)) {
|
||||
g_key_file_remove_key(accounts, sanitized_account_name, option, NULL);
|
||||
_accounts_save(account_name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -630,83 +612,88 @@ accounts_clear_max_sessions(const char* const account_name)
|
||||
void
|
||||
accounts_add_otr_policy(const char* const account_name, const char* const contact_jid, const char* const policy)
|
||||
{
|
||||
if (accounts_account_exists(account_name)) {
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
if (_accounts_has_group(sanitized_account_name)) {
|
||||
GString* key = g_string_new("otr.");
|
||||
g_string_append(key, policy);
|
||||
conf_string_list_add(accounts, account_name, key->str, contact_jid);
|
||||
conf_string_list_add(accounts, sanitized_account_name, key->str, contact_jid);
|
||||
g_string_free(key, TRUE);
|
||||
|
||||
// check for and remove from other lists
|
||||
if (strcmp(policy, "manual") == 0) {
|
||||
conf_string_list_remove(accounts, account_name, "otr.opportunistic", contact_jid);
|
||||
conf_string_list_remove(accounts, account_name, "otr.always", contact_jid);
|
||||
conf_string_list_remove(accounts, sanitized_account_name, "otr.opportunistic", contact_jid);
|
||||
conf_string_list_remove(accounts, sanitized_account_name, "otr.always", contact_jid);
|
||||
}
|
||||
if (strcmp(policy, "opportunistic") == 0) {
|
||||
conf_string_list_remove(accounts, account_name, "otr.manual", contact_jid);
|
||||
conf_string_list_remove(accounts, account_name, "otr.always", contact_jid);
|
||||
conf_string_list_remove(accounts, sanitized_account_name, "otr.manual", contact_jid);
|
||||
conf_string_list_remove(accounts, sanitized_account_name, "otr.always", contact_jid);
|
||||
}
|
||||
if (strcmp(policy, "always") == 0) {
|
||||
conf_string_list_remove(accounts, account_name, "otr.opportunistic", contact_jid);
|
||||
conf_string_list_remove(accounts, account_name, "otr.manual", contact_jid);
|
||||
conf_string_list_remove(accounts, sanitized_account_name, "otr.opportunistic", contact_jid);
|
||||
conf_string_list_remove(accounts, sanitized_account_name, "otr.manual", contact_jid);
|
||||
}
|
||||
|
||||
_save_accounts();
|
||||
_accounts_save(account_name);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
accounts_add_omemo_state(const char* const account_name, const char* const contact_jid, gboolean enabled)
|
||||
{
|
||||
if (accounts_account_exists(account_name)) {
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
if (_accounts_has_group(sanitized_account_name)) {
|
||||
if (enabled) {
|
||||
conf_string_list_add(accounts, account_name, "omemo.enabled", contact_jid);
|
||||
conf_string_list_remove(accounts, account_name, "omemo.disabled", contact_jid);
|
||||
conf_string_list_add(accounts, sanitized_account_name, "omemo.enabled", contact_jid);
|
||||
conf_string_list_remove(accounts, sanitized_account_name, "omemo.disabled", contact_jid);
|
||||
} else {
|
||||
conf_string_list_add(accounts, account_name, "omemo.disabled", contact_jid);
|
||||
conf_string_list_remove(accounts, account_name, "omemo.enabled", contact_jid);
|
||||
conf_string_list_add(accounts, sanitized_account_name, "omemo.disabled", contact_jid);
|
||||
conf_string_list_remove(accounts, sanitized_account_name, "omemo.enabled", contact_jid);
|
||||
}
|
||||
|
||||
_save_accounts();
|
||||
_accounts_save(account_name);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
accounts_add_ox_state(const char* const account_name, const char* const contact_jid, gboolean enabled)
|
||||
{
|
||||
if (accounts_account_exists(account_name)) {
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
if (_accounts_has_group(sanitized_account_name)) {
|
||||
if (enabled) {
|
||||
conf_string_list_add(accounts, account_name, "ox.enabled", contact_jid);
|
||||
conf_string_list_add(accounts, sanitized_account_name, "ox.enabled", contact_jid);
|
||||
} else {
|
||||
conf_string_list_remove(accounts, account_name, "ox.enabled", contact_jid);
|
||||
conf_string_list_remove(accounts, sanitized_account_name, "ox.enabled", contact_jid);
|
||||
}
|
||||
|
||||
_save_accounts();
|
||||
_accounts_save(account_name);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
accounts_add_pgp_state(const char* const account_name, const char* const contact_jid, gboolean enabled)
|
||||
{
|
||||
if (accounts_account_exists(account_name)) {
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
if (_accounts_has_group(sanitized_account_name)) {
|
||||
if (enabled) {
|
||||
conf_string_list_add(accounts, account_name, "pgp.enabled", contact_jid);
|
||||
conf_string_list_remove(accounts, account_name, "pgp.disabled", contact_jid);
|
||||
conf_string_list_add(accounts, sanitized_account_name, "pgp.enabled", contact_jid);
|
||||
conf_string_list_remove(accounts, sanitized_account_name, "pgp.disabled", contact_jid);
|
||||
} else {
|
||||
conf_string_list_add(accounts, account_name, "pgp.disabled", contact_jid);
|
||||
conf_string_list_remove(accounts, account_name, "pgp.enabled", contact_jid);
|
||||
conf_string_list_add(accounts, sanitized_account_name, "pgp.disabled", contact_jid);
|
||||
conf_string_list_remove(accounts, sanitized_account_name, "pgp.enabled", contact_jid);
|
||||
}
|
||||
|
||||
_save_accounts();
|
||||
_accounts_save(account_name);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
accounts_clear_omemo_state(const char* const account_name, const char* const contact_jid)
|
||||
{
|
||||
if (accounts_account_exists(account_name)) {
|
||||
conf_string_list_remove(accounts, account_name, "omemo.enabled", contact_jid);
|
||||
conf_string_list_remove(accounts, account_name, "omemo.disabled", contact_jid);
|
||||
_save_accounts();
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
if (_accounts_has_group(sanitized_account_name)) {
|
||||
conf_string_list_remove(accounts, sanitized_account_name, "omemo.enabled", contact_jid);
|
||||
conf_string_list_remove(accounts, sanitized_account_name, "omemo.disabled", contact_jid);
|
||||
_accounts_save(account_name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -779,7 +766,8 @@ accounts_set_priority_dnd(const char* const account_name, const gint value)
|
||||
void
|
||||
accounts_set_priority_all(const char* const account_name, const gint value)
|
||||
{
|
||||
if (accounts_account_exists(account_name)) {
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
if (_accounts_has_group(sanitized_account_name)) {
|
||||
accounts_set_priority_online(account_name, value);
|
||||
accounts_set_priority_chat(account_name, value);
|
||||
accounts_set_priority_away(account_name, value);
|
||||
@@ -793,22 +781,23 @@ accounts_get_priority_for_presence_type(const char* const account_name,
|
||||
resource_presence_t presence_type)
|
||||
{
|
||||
gint result;
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
|
||||
switch (presence_type) {
|
||||
case (RESOURCE_ONLINE):
|
||||
result = g_key_file_get_integer(accounts, account_name, "priority.online", NULL);
|
||||
result = g_key_file_get_integer(accounts, sanitized_account_name, "priority.online", NULL);
|
||||
break;
|
||||
case (RESOURCE_CHAT):
|
||||
result = g_key_file_get_integer(accounts, account_name, "priority.chat", NULL);
|
||||
result = g_key_file_get_integer(accounts, sanitized_account_name, "priority.chat", NULL);
|
||||
break;
|
||||
case (RESOURCE_AWAY):
|
||||
result = g_key_file_get_integer(accounts, account_name, "priority.away", NULL);
|
||||
result = g_key_file_get_integer(accounts, sanitized_account_name, "priority.away", NULL);
|
||||
break;
|
||||
case (RESOURCE_XA):
|
||||
result = g_key_file_get_integer(accounts, account_name, "priority.xa", NULL);
|
||||
result = g_key_file_get_integer(accounts, sanitized_account_name, "priority.xa", NULL);
|
||||
break;
|
||||
default:
|
||||
result = g_key_file_get_integer(accounts, account_name, "priority.dnd", NULL);
|
||||
result = g_key_file_get_integer(accounts, sanitized_account_name, "priority.dnd", NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -833,7 +822,8 @@ accounts_set_last_status(const char* const account_name, const char* const value
|
||||
void
|
||||
accounts_set_last_activity(const char* const account_name)
|
||||
{
|
||||
if (accounts_account_exists(account_name)) {
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
if (_accounts_has_group(sanitized_account_name)) {
|
||||
GDateTime* nowdt = g_date_time_new_now_utc();
|
||||
GTimeVal nowtv;
|
||||
gboolean res = g_date_time_to_timeval(nowdt, &nowtv);
|
||||
@@ -841,8 +831,8 @@ accounts_set_last_activity(const char* const account_name)
|
||||
|
||||
if (res) {
|
||||
auto_char char* timestr = g_time_val_to_iso8601(&nowtv);
|
||||
g_key_file_set_string(accounts, account_name, "last.activity", timestr);
|
||||
_save_accounts();
|
||||
g_key_file_set_string(accounts, sanitized_account_name, "last.activity", timestr);
|
||||
_accounts_save(account_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -850,8 +840,9 @@ accounts_set_last_activity(const char* const account_name)
|
||||
gchar*
|
||||
accounts_get_last_activity(const char* const account_name)
|
||||
{
|
||||
if (accounts_account_exists(account_name)) {
|
||||
return g_key_file_get_string(accounts, account_name, "last.activity", NULL);
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
if (_accounts_has_group(sanitized_account_name)) {
|
||||
return g_key_file_get_string(accounts, sanitized_account_name, "last.activity", NULL);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
@@ -860,27 +851,30 @@ accounts_get_last_activity(const char* const account_name)
|
||||
gchar*
|
||||
accounts_get_resource(const char* const account_name)
|
||||
{
|
||||
if (!accounts_account_exists(account_name)) {
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
if (!_accounts_has_group(sanitized_account_name)) {
|
||||
return NULL;
|
||||
}
|
||||
return g_key_file_get_string(accounts, account_name, "resource", NULL);
|
||||
return g_key_file_get_string(accounts, sanitized_account_name, "resource", NULL);
|
||||
}
|
||||
|
||||
int
|
||||
accounts_get_max_sessions(const char* const account_name)
|
||||
{
|
||||
if (!accounts_account_exists(account_name)) {
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
if (!_accounts_has_group(sanitized_account_name)) {
|
||||
return 0;
|
||||
}
|
||||
return g_key_file_get_integer(accounts, account_name, "max.sessions", 0);
|
||||
return g_key_file_get_integer(accounts, sanitized_account_name, "max.sessions", 0);
|
||||
}
|
||||
|
||||
void
|
||||
accounts_set_login_presence(const char* const account_name, const char* const value)
|
||||
{
|
||||
if (accounts_account_exists(account_name)) {
|
||||
g_key_file_set_string(accounts, account_name, "presence.login", value);
|
||||
_save_accounts();
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
if (_accounts_has_group(sanitized_account_name)) {
|
||||
g_key_file_set_string(accounts, sanitized_account_name, "presence.login", value);
|
||||
_accounts_save(account_name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -888,7 +882,8 @@ resource_presence_t
|
||||
accounts_get_last_presence(const char* const account_name)
|
||||
{
|
||||
resource_presence_t result;
|
||||
auto_gchar gchar* setting = g_key_file_get_string(accounts, account_name, "presence.last", NULL);
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
auto_gchar gchar* setting = g_key_file_get_string(accounts, sanitized_account_name, "presence.last", NULL);
|
||||
|
||||
if (setting == NULL || (strcmp(setting, "online") == 0)) {
|
||||
result = RESOURCE_ONLINE;
|
||||
@@ -912,14 +907,16 @@ accounts_get_last_presence(const char* const account_name)
|
||||
char*
|
||||
accounts_get_last_status(const char* const account_name)
|
||||
{
|
||||
return g_key_file_get_string(accounts, account_name, "presence.laststatus", NULL);
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
return g_key_file_get_string(accounts, sanitized_account_name, "presence.laststatus", NULL);
|
||||
}
|
||||
|
||||
resource_presence_t
|
||||
accounts_get_login_presence(const char* const account_name)
|
||||
{
|
||||
resource_presence_t result;
|
||||
auto_gchar gchar* setting = g_key_file_get_string(accounts, account_name, "presence.login", NULL);
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
auto_gchar gchar* setting = g_key_file_get_string(accounts, sanitized_account_name, "presence.login", NULL);
|
||||
|
||||
if (setting == NULL || (strcmp(setting, "online") == 0)) {
|
||||
result = RESOURCE_ONLINE;
|
||||
@@ -944,7 +941,8 @@ accounts_get_login_presence(const char* const account_name)
|
||||
char*
|
||||
accounts_get_login_status(const char* const account_name)
|
||||
{
|
||||
auto_gchar gchar* setting = g_key_file_get_string(accounts, account_name, "presence.login", NULL);
|
||||
auto_gchar gchar* sanitized_account_name = _sanitize_account_name(account_name);
|
||||
auto_gchar gchar* setting = g_key_file_get_string(accounts, sanitized_account_name, "presence.login", NULL);
|
||||
gchar* status = NULL;
|
||||
|
||||
if (g_strcmp0(setting, "last") == 0) {
|
||||
@@ -953,9 +951,3 @@ accounts_get_login_status(const char* const account_name)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static void
|
||||
_save_accounts(void)
|
||||
{
|
||||
save_keyfile(&accounts_prof_keyfile);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user