mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-24 20:26:21 +00:00
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:
@@ -52,7 +52,8 @@ account_new(const gchar *const name, const gchar *const jid,
|
||||
int priority_away, int priority_xa, int priority_dnd,
|
||||
const gchar *const muc_service, const gchar *const muc_nick,
|
||||
const gchar *const otr_policy, GList *otr_manual, GList *otr_opportunistic,
|
||||
GList *otr_always, const gchar *const pgp_keyid, const char *const startscript,
|
||||
GList *otr_always, const gchar *const omemo_policy, GList *omemo_enabled,
|
||||
GList *omemo_disabled, const gchar *const pgp_keyid, const char *const startscript,
|
||||
const char *const theme, gchar *tls_policy)
|
||||
{
|
||||
ProfAccount *new_account = malloc(sizeof(ProfAccount));
|
||||
@@ -139,6 +140,15 @@ account_new(const gchar *const name, const gchar *const jid,
|
||||
new_account->otr_opportunistic = otr_opportunistic;
|
||||
new_account->otr_always = otr_always;
|
||||
|
||||
if (omemo_policy) {
|
||||
new_account->omemo_policy = strdup(omemo_policy);
|
||||
} else {
|
||||
new_account->omemo_policy = NULL;
|
||||
}
|
||||
|
||||
new_account->omemo_enabled = omemo_enabled;
|
||||
new_account->omemo_disabled = omemo_disabled;
|
||||
|
||||
if (pgp_keyid != NULL) {
|
||||
new_account->pgp_keyid = strdup(pgp_keyid);
|
||||
} else {
|
||||
@@ -232,6 +242,7 @@ account_free(ProfAccount *account)
|
||||
free(account->muc_service);
|
||||
free(account->muc_nick);
|
||||
free(account->otr_policy);
|
||||
free(account->omemo_policy);
|
||||
free(account->pgp_keyid);
|
||||
free(account->startscript);
|
||||
free(account->theme);
|
||||
@@ -239,6 +250,8 @@ account_free(ProfAccount *account)
|
||||
g_list_free_full(account->otr_manual, g_free);
|
||||
g_list_free_full(account->otr_opportunistic, g_free);
|
||||
g_list_free_full(account->otr_always, g_free);
|
||||
g_list_free_full(account->omemo_enabled, g_free);
|
||||
g_list_free_full(account->omemo_disabled, g_free);
|
||||
free(account);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,9 @@ typedef struct prof_account_t {
|
||||
GList *otr_manual;
|
||||
GList *otr_opportunistic;
|
||||
GList *otr_always;
|
||||
gchar *omemo_policy;
|
||||
GList *omemo_enabled;
|
||||
GList *omemo_disabled;
|
||||
gchar *pgp_keyid;
|
||||
gchar *startscript;
|
||||
gchar *theme;
|
||||
@@ -72,7 +75,8 @@ ProfAccount* account_new(const gchar *const name, const gchar *const jid,
|
||||
int priority_away, int priority_xa, int priority_dnd,
|
||||
const gchar *const muc_service, const gchar *const muc_nick,
|
||||
const gchar *const otr_policy, GList *otr_manual, GList *otr_opportunistic,
|
||||
GList *otr_always, const gchar *const pgp_keyid, const char *const startscript,
|
||||
GList *otr_always, const gchar *const omemo_policy, GList *omemo_enabled,
|
||||
GList *omemo_disabled, const gchar *const pgp_keyid, const char *const startscript,
|
||||
const char *const theme, gchar *tls_policy);
|
||||
char* account_create_connect_jid(ProfAccount *account);
|
||||
gboolean account_eval_password(ProfAccount *account);
|
||||
|
||||
@@ -275,6 +275,31 @@ accounts_get_account(const char *const name)
|
||||
g_strfreev(always);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
GList *omemo_enabled = NULL;
|
||||
gchar **enabled_list = g_key_file_get_string_list(accounts, name, "omemo.enabled", &length, NULL);
|
||||
if (enabled_list) {
|
||||
int i = 0;
|
||||
for (i = 0; i < length; i++) {
|
||||
omemo_enabled = g_list_append(omemo_enabled, strdup(enabled_list[i]));
|
||||
}
|
||||
g_strfreev(enabled_list);
|
||||
}
|
||||
|
||||
GList *omemo_disabled = NULL;
|
||||
gchar **disabled_list = g_key_file_get_string_list(accounts, name, "omemo.disabled", &length, NULL);
|
||||
if (disabled_list) {
|
||||
int i = 0;
|
||||
for (i = 0; i < length; i++) {
|
||||
omemo_disabled = g_list_append(omemo_disabled, strdup(disabled_list[i]));
|
||||
}
|
||||
g_strfreev(disabled_list);
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -304,7 +329,8 @@ accounts_get_account(const char *const name)
|
||||
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, pgp_keyid, startscript, theme, tls_policy);
|
||||
otr_opportunistic, otr_always, omemo_policy, omemo_enabled,
|
||||
omemo_disabled, pgp_keyid, startscript, theme, tls_policy);
|
||||
|
||||
g_free(jid);
|
||||
g_free(password);
|
||||
@@ -316,6 +342,7 @@ accounts_get_account(const char *const name)
|
||||
g_free(muc_service);
|
||||
g_free(muc_nick);
|
||||
g_free(otr_policy);
|
||||
g_free(omemo_policy);
|
||||
g_free(pgp_keyid);
|
||||
g_free(startscript);
|
||||
g_free(theme);
|
||||
@@ -385,6 +412,9 @@ accounts_rename(const char *const account_name, const char *const new_name)
|
||||
"otr.manual",
|
||||
"otr.opportunistic",
|
||||
"otr.always",
|
||||
"omemo.policy",
|
||||
"omemo.enabled",
|
||||
"omemo.disabled",
|
||||
"pgp.keyid",
|
||||
"last.activity",
|
||||
"script.start",
|
||||
@@ -633,6 +663,32 @@ accounts_add_otr_policy(const char *const account_name, const char *const contac
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
accounts_add_omemo_state(const char *const account_name, const char *const contact_jid, gboolean enabled)
|
||||
{
|
||||
if (accounts_account_exists(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);
|
||||
} else {
|
||||
conf_string_list_add(accounts, account_name, "omemo.disabled", contact_jid);
|
||||
conf_string_list_remove(accounts, account_name, "omemo.enabled", contact_jid);
|
||||
}
|
||||
|
||||
_save_accounts();
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
accounts_set_muc_service(const char *const account_name, const char *const value)
|
||||
{
|
||||
@@ -660,6 +716,15 @@ accounts_set_otr_policy(const char *const account_name, const char *const value)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
accounts_set_omemo_policy(const char *const account_name, const char *const value)
|
||||
{
|
||||
if (accounts_account_exists(account_name)) {
|
||||
g_key_file_set_string(accounts, account_name, "omemo.policy", value);
|
||||
_save_accounts();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
accounts_set_tls_policy(const char *const account_name, const char *const value)
|
||||
{
|
||||
|
||||
@@ -96,5 +96,7 @@ void accounts_clear_theme(const char *const account_name);
|
||||
void accounts_clear_muc(const char *const account_name);
|
||||
void accounts_clear_resource(const char *const account_name);
|
||||
void accounts_add_otr_policy(const char *const account_name, const char *const contact_jid, const char *const policy);
|
||||
void accounts_add_omemo_state(const char *const account_name, const char *const contact_jid, gboolean enabled);
|
||||
void accounts_clear_omemo_state(const char *const account_name, const char *const contact_jid);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1686,6 +1686,7 @@ _get_group(preference_t pref)
|
||||
case PREF_PLUGINS_SOURCEPATH:
|
||||
return PREF_GROUP_PLUGINS;
|
||||
case PREF_OMEMO_LOG:
|
||||
case PREF_OMEMO_POLICY:
|
||||
return PREF_GROUP_OMEMO;
|
||||
default:
|
||||
return NULL;
|
||||
@@ -1903,6 +1904,8 @@ _get_key(preference_t pref)
|
||||
return "statusbar.room";
|
||||
case PREF_OMEMO_LOG:
|
||||
return "log";
|
||||
case PREF_OMEMO_POLICY:
|
||||
return "policy";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
@@ -2023,6 +2026,8 @@ _get_default_string(preference_t pref)
|
||||
return "room";
|
||||
case PREF_OMEMO_LOG:
|
||||
return "redact";
|
||||
case PREF_OMEMO_POLICY:
|
||||
return "automatic";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -149,6 +149,7 @@ typedef enum {
|
||||
PREF_STATUSBAR_CHAT,
|
||||
PREF_STATUSBAR_ROOM,
|
||||
PREF_OMEMO_LOG,
|
||||
PREF_OMEMO_POLICY,
|
||||
} preference_t;
|
||||
|
||||
typedef struct prof_alias_t {
|
||||
|
||||
Reference in New Issue
Block a user