diff options
Diffstat (limited to 'src/omemo')
-rw-r--r-- | src/omemo/omemo.c | 77 | ||||
-rw-r--r-- | src/omemo/omemo.h | 8 |
2 files changed, 69 insertions, 16 deletions
diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c index b85029ee..06174da5 100644 --- a/src/omemo/omemo.c +++ b/src/omemo/omemo.c @@ -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" @@ -922,21 +923,6 @@ omemo_known_device_identities(const char *const jid) } 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) { GHashTable *known_identities = g_hash_table_lookup(omemo_ctx.known_devices, jid); @@ -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) { diff --git a/src/omemo/omemo.h b/src/omemo/omemo.h index 166a5292..8268491c 100644 --- a/src/omemo/omemo.h +++ b/src/omemo/omemo.h @@ -6,6 +6,12 @@ #define OMEMO_ERR_UNSUPPORTED_CRYPTO -10000 #define OMEMO_ERR_GCRYPT -20000 +typedef enum { + PROF_OMEMOPOLICY_MANUAL, + PROF_OMEMOPOLICY_AUTOMATIC, + PROF_OMEMOPOLICY_ALWAYS +} prof_omemopolicy_t; + typedef struct omemo_context_t omemo_context; typedef struct omemo_key { @@ -40,10 +46,10 @@ char *omemo_own_fingerprint(gboolean formatted); void omemo_trust(const char *const jid, const char *const fingerprint); void omemo_untrust(const char *const jid, const char *const fingerprint); GList *omemo_known_device_identities(const char *const jid); -gboolean omemo_is_trusted_jid(const char *const jid); gboolean omemo_is_trusted_identity(const char *const jid, const char *const fingerprint); char *omemo_fingerprint_autocomplete(const char *const search_str, gboolean previous); void omemo_fingerprint_autocomplete_reset(void); +gboolean omemo_automatic_start(const char *const recipient); void omemo_start_sessions(void); void omemo_start_session(const char *const barejid); |