Add OMEMO policy
There is 3 policy: - manual: OMEMO session are only started manually - automatic: OMEMO session are only started if they have been started manually before - always: OMEMO session are always started unless they have been ended manually before Closes #1040 and fixes #1052
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "config/account.h"
|
||||
#include "config/files.h"
|
||||
#include "config/preferences.h"
|
||||
#include "log.h"
|
||||
#include "omemo/crypto.h"
|
||||
#include "omemo/omemo.h"
|
||||
@@ -921,21 +922,6 @@ omemo_known_device_identities(const char *const jid)
|
||||
return g_hash_table_get_keys(known_identities);
|
||||
}
|
||||
|
||||
gboolean
|
||||
omemo_is_trusted_jid(const char *const jid)
|
||||
{
|
||||
GHashTable *trusted = g_hash_table_lookup(omemo_ctx.identity_key_store.trusted, jid);
|
||||
if (!trusted) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (g_hash_table_size(trusted) > 0) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
omemo_is_trusted_identity(const char *const jid, const char *const fingerprint)
|
||||
{
|
||||
@@ -1197,6 +1183,67 @@ omemo_fingerprint_autocomplete_reset(void)
|
||||
autocomplete_reset(omemo_ctx.fingerprint_ac);
|
||||
}
|
||||
|
||||
gboolean
|
||||
omemo_automatic_start(const char *const recipient)
|
||||
{
|
||||
gboolean result;
|
||||
char *account_name = session_get_account_name();
|
||||
ProfAccount *account = accounts_get_account(account_name);
|
||||
prof_omemopolicy_t policy;
|
||||
|
||||
if (account->omemo_policy) {
|
||||
// check default account setting
|
||||
if (g_strcmp0(account->omemo_policy, "manual") == 0) {
|
||||
policy = PROF_OMEMOPOLICY_MANUAL;
|
||||
}
|
||||
if (g_strcmp0(account->omemo_policy, "opportunistic") == 0) {
|
||||
policy = PROF_OMEMOPOLICY_AUTOMATIC;
|
||||
}
|
||||
if (g_strcmp0(account->omemo_policy, "always") == 0) {
|
||||
policy = PROF_OMEMOPOLICY_ALWAYS;
|
||||
}
|
||||
} else {
|
||||
// check global setting
|
||||
char *pref_omemo_policy = prefs_get_string(PREF_OMEMO_POLICY);
|
||||
|
||||
// pref defaults to manual
|
||||
policy = PROF_OMEMOPOLICY_AUTOMATIC;
|
||||
|
||||
if (strcmp(pref_omemo_policy, "manual") == 0) {
|
||||
policy = PROF_OMEMOPOLICY_MANUAL;
|
||||
} else if (strcmp(pref_omemo_policy, "always") == 0) {
|
||||
policy = PROF_OMEMOPOLICY_ALWAYS;
|
||||
}
|
||||
|
||||
prefs_free_string(pref_omemo_policy);
|
||||
}
|
||||
|
||||
switch (policy) {
|
||||
case PROF_OMEMOPOLICY_MANUAL:
|
||||
result = FALSE;
|
||||
break;
|
||||
case PROF_OMEMOPOLICY_AUTOMATIC:
|
||||
if (g_list_find_custom(account->omemo_enabled, recipient, (GCompareFunc)g_strcmp0)) {
|
||||
result = TRUE;
|
||||
} else if (g_list_find_custom(account->omemo_disabled, recipient, (GCompareFunc)g_strcmp0)) {
|
||||
result = FALSE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
case PROF_OMEMOPOLICY_ALWAYS:
|
||||
if (g_list_find_custom(account->omemo_disabled, recipient, (GCompareFunc)g_strcmp0)) {
|
||||
result = FALSE;
|
||||
} else {
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
account_free(account);
|
||||
return result;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_load_identity(void)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user