From ddbb4872b3ac8e362b37bfa565f80c888718cf7a Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 11 May 2014 13:13:25 +0100 Subject: [PATCH 1/8] Moved global OTR settings to [otr] group --- src/config/preferences.c | 37 +++++++++++++++++++++++++++++-------- src/config/preferences.h | 4 ++-- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/config/preferences.c b/src/config/preferences.c index 5bbb36a2..5ba7d1dc 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -45,7 +45,7 @@ #define PREF_GROUP_PRESENCE "presence" #define PREF_GROUP_CONNECTION "connection" #define PREF_GROUP_ALIAS "alias" -#define PREF_GROUP_OTR_POLICY "policy" +#define PREF_GROUP_OTR "otr" static gchar *prefs_loc; static GKeyFile *prefs; @@ -79,6 +79,27 @@ prefs_load(void) g_error_free(err); } + // move pre 0.4.1 OTR preferences to [otr] group + err = NULL; + gboolean ui_otr_warn = g_key_file_get_boolean(prefs, PREF_GROUP_UI, "otr.warn", &err); + if (!err) { + g_key_file_set_boolean(prefs, PREF_GROUP_OTR, _get_key(PREF_OTR_WARN), ui_otr_warn); + g_key_file_remove_key(prefs, PREF_GROUP_UI, "otr.warn", NULL); + } + err = NULL; + gchar *ui_otr_log = g_key_file_get_string(prefs, PREF_GROUP_LOGGING, "otr", &err); + if (!err) { + g_key_file_set_string(prefs, PREF_GROUP_OTR, _get_key(PREF_OTR_LOG), ui_otr_log); + g_key_file_remove_key(prefs, PREF_GROUP_LOGGING, "otr", NULL); + } + err = NULL; + gchar *ui_otr_policy = g_key_file_get_string(prefs, "policy", "otr.policy", &err); + if (!err) { + g_key_file_set_string(prefs, PREF_GROUP_OTR, _get_key(PREF_OTR_POLICY), ui_otr_policy); + g_key_file_remove_group(prefs, "policy", NULL); + } + _save_prefs(); + boolean_choice_ac = autocomplete_new(); autocomplete_add(boolean_choice_ac, "on"); autocomplete_add(boolean_choice_ac, "off"); @@ -374,7 +395,6 @@ _get_group(preference_t pref) case PREF_STATUSES_CONSOLE: case PREF_STATUSES_CHAT: case PREF_STATUSES_MUC: - case PREF_OTR_WARN: return PREF_GROUP_UI; case PREF_STATES: case PREF_OUTTYPE: @@ -386,18 +406,19 @@ _get_group(preference_t pref) return PREF_GROUP_NOTIFICATIONS; case PREF_CHLOG: case PREF_GRLOG: - case PREF_OTR_LOG: case PREF_LOG_ROTATE: case PREF_LOG_SHARED: return PREF_GROUP_LOGGING; - case PREF_OTR_POLICY: - return PREF_GROUP_OTR_POLICY; case PREF_AUTOAWAY_CHECK: case PREF_AUTOAWAY_MODE: case PREF_AUTOAWAY_MESSAGE: return PREF_GROUP_PRESENCE; case PREF_CONNECT_ACCOUNT: return PREF_GROUP_CONNECTION; + case PREF_OTR_WARN: + case PREF_OTR_LOG: + case PREF_OTR_POLICY: + return PREF_GROUP_OTR; default: return NULL; } @@ -459,11 +480,11 @@ _get_key(preference_t pref) case PREF_CONNECT_ACCOUNT: return "account"; case PREF_OTR_LOG: - return "otr"; + return "log"; case PREF_OTR_WARN: - return "otr.warn"; + return "warn"; case PREF_OTR_POLICY: - return "otr.policy"; + return "policy"; case PREF_LOG_ROTATE: return "rotate"; case PREF_LOG_SHARED: diff --git a/src/config/preferences.h b/src/config/preferences.h index 3d2f6023..fb11d873 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -61,10 +61,10 @@ typedef enum { PREF_AUTOAWAY_MODE, PREF_AUTOAWAY_MESSAGE, PREF_CONNECT_ACCOUNT, - PREF_OTR_LOG, - PREF_OTR_WARN, PREF_LOG_ROTATE, PREF_LOG_SHARED, + PREF_OTR_LOG, + PREF_OTR_WARN, PREF_OTR_POLICY } preference_t; From 015780662edad1ff959ed3451a38a446cadb9e75 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 11 May 2014 13:32:59 +0100 Subject: [PATCH 2/8] Added /prefs otr --- src/command/command.c | 1 + src/command/commands.c | 4 +++ src/ui/console.c | 69 +++++++++++++++++++++++------------------- src/ui/ui.h | 3 +- 4 files changed, 44 insertions(+), 33 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 6fcd3df6..3b111c55 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -955,6 +955,7 @@ cmd_init(void) autocomplete_add(prefs_ac, "log"); autocomplete_add(prefs_ac, "conn"); autocomplete_add(prefs_ac, "presence"); + autocomplete_add(prefs_ac, "otr"); notify_ac = autocomplete_new(); autocomplete_add(notify_ac, "message"); diff --git a/src/command/commands.c b/src/command/commands.c index 8a1b66bf..b46815bb 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -653,6 +653,10 @@ cmd_prefs(gchar **args, struct cmd_help_t help) cons_show(""); cons_show_presence_prefs(); cons_show(""); + } else if (strcmp(args[0], "otr") == 0) { + cons_show(""); + cons_show_otr_prefs(); + cons_show(""); } else { cons_show("Usage: %s", help.usage); } diff --git a/src/ui/console.c b/src/ui/console.c index 7aac2e21..f5f352b5 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1075,9 +1075,9 @@ _cons_statuses_setting(void) char *chat = prefs_get_string(PREF_STATUSES_CHAT); char *muc = prefs_get_string(PREF_STATUSES_MUC); - cons_show("Console statuses (/statuses) : %s", console); - cons_show("Chat win statuses (/statuses) : %s", chat); - cons_show("Chat room statuses (/statuses) : %s", muc); + cons_show("Console statuses (/statuses) : %s", console); + cons_show("Chat statuses (/statuses) : %s", chat); + cons_show("MUC statuses (/statuses) : %s", muc); } static void @@ -1090,16 +1090,6 @@ _cons_titlebar_setting(void) } } -static void -_cons_otrwarn_setting(void) -{ - if (prefs_get_boolean(PREF_OTR_WARN)) { - cons_show("Warn non-OTR (/otr warn) : ON"); - } else { - cons_show("Warn non-OTR (/otr warn) : OFF"); - } -} - static void _cons_show_ui_prefs(void) { @@ -1114,7 +1104,6 @@ _cons_show_ui_prefs(void) cons_mouse_setting(); cons_statuses_setting(); cons_titlebar_setting(); - cons_otrwarn_setting(); if (wins_is_current(console)) { win_update_virtual(console); @@ -1271,20 +1260,6 @@ _cons_grlog_setting(void) cons_show("Groupchat logging (/grlog) : OFF"); } -static void -_cons_otr_log_setting(void) -{ - char *value = prefs_get_string(PREF_OTR_LOG); - - if (strcmp(value, "on") == 0) { - cons_show("OTR logging (/otr log) : ON"); - } else if (strcmp(value, "off") == 0) { - cons_show("OTR logging (/otr log) : OFF"); - } else { - cons_show("OTR logging (/otr log) : Redacted"); - } -} - static void _cons_show_log_prefs(void) { @@ -1294,7 +1269,6 @@ _cons_show_log_prefs(void) cons_log_setting(); cons_chlog_setting(); cons_grlog_setting(); - cons_otr_log_setting(); if (wins_is_current(console)) { win_update_virtual(console); @@ -1390,6 +1364,38 @@ _cons_show_connection_prefs(void) cons_alert(); } +static void +_cons_show_otr_prefs(void) +{ + ProfWin *console = wins_get_console(); + cons_show("OTR preferences:"); + cons_show(""); + + char *policy_value = prefs_get_string(PREF_OTR_POLICY); + cons_show("OTR policy (/otr policy) : %s", policy_value); + + if (prefs_get_boolean(PREF_OTR_WARN)) { + cons_show("Warn non-OTR (/otr warn) : ON"); + } else { + cons_show("Warn non-OTR (/otr warn) : OFF"); + } + + char *log_value = prefs_get_string(PREF_OTR_LOG); + + if (strcmp(log_value, "on") == 0) { + cons_show("OTR logging (/otr log) : ON"); + } else if (strcmp(log_value, "off") == 0) { + cons_show("OTR logging (/otr log) : OFF"); + } else { + cons_show("OTR logging (/otr log) : Redacted"); + } + + if (wins_is_current(console)) { + win_update_virtual(console); + } + cons_alert(); +} + static void _cons_show_themes(GSList *themes) { @@ -1429,6 +1435,8 @@ _cons_prefs(void) cons_show(""); cons_show_connection_prefs(); cons_show(""); + cons_show_otr_prefs(); + cons_show(""); if (wins_is_current(console)) { win_update_virtual(console); @@ -1767,11 +1775,10 @@ console_init_module(void) cons_log_setting = _cons_log_setting; cons_chlog_setting = _cons_chlog_setting; cons_grlog_setting = _cons_grlog_setting; - cons_otr_log_setting = _cons_otr_log_setting; - cons_otrwarn_setting = _cons_otrwarn_setting; cons_show_log_prefs = _cons_show_log_prefs; cons_autoaway_setting = _cons_autoaway_setting; cons_show_presence_prefs = _cons_show_presence_prefs; + cons_show_otr_prefs = _cons_show_otr_prefs; cons_reconnect_setting = _cons_reconnect_setting; cons_autoping_setting = _cons_autoping_setting; cons_priority_setting = _cons_priority_setting; diff --git a/src/ui/ui.h b/src/ui/ui.h index c4d42939..32bb782a 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -196,6 +196,7 @@ void (*cons_show_chat_prefs)(void); void (*cons_show_log_prefs)(void); void (*cons_show_presence_prefs)(void); void (*cons_show_connection_prefs)(void); +void (*cons_show_otr_prefs)(void); void (*cons_show_account)(ProfAccount *account); void (*cons_debug)(const char * const msg, ...); void (*cons_show_time)(void); @@ -246,8 +247,6 @@ void (*cons_history_setting)(void); void (*cons_log_setting)(void); void (*cons_chlog_setting)(void); void (*cons_grlog_setting)(void); -void (*cons_otr_log_setting)(void); -void (*cons_otrwarn_setting)(void); void (*cons_autoaway_setting)(void); void (*cons_reconnect_setting)(void); void (*cons_autoping_setting)(void); From f2ebbdb8de2725eae21419f18dce3f4ecffb6687 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 11 May 2014 13:48:41 +0100 Subject: [PATCH 3/8] Added autocompletion for /account set otr --- src/command/command.c | 21 ++++++++++++++++----- src/command/commands.c | 9 +++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 3b111c55..a46c1548 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1028,6 +1028,7 @@ cmd_init(void) autocomplete_add(account_set_ac, "password"); autocomplete_add(account_set_ac, "muc"); autocomplete_add(account_set_ac, "nick"); + autocomplete_add(account_set_ac, "otr"); account_clear_ac = autocomplete_new(); autocomplete_add(account_clear_ac, "password"); @@ -1979,15 +1980,25 @@ _account_autocomplete(char *input, int *size) gboolean result = FALSE; input[*size] = '\0'; - gchar **args = parse_args(input, 3, 3, &result); + gchar **args = parse_args(input, 3, 4, &result); if ((strncmp(input, "/account set", 12) == 0) && (result == TRUE)) { GString *beginning = g_string_new("/account set "); g_string_append(beginning, args[1]); - found = autocomplete_param_with_ac(input, size, beginning->str, account_set_ac); - g_string_free(beginning, TRUE); - if (found != NULL) { - return found; + if ((g_strv_length(args) > 3) && (g_strcmp0(args[2], "otr")) == 0) { + g_string_append(beginning, " "); + g_string_append(beginning, args[2]); + found = autocomplete_param_with_ac(input, size, beginning->str, otr_policy_ac); + g_string_free(beginning, TRUE); + if (found != NULL) { + return found; + } + } else { + found = autocomplete_param_with_ac(input, size, beginning->str, account_set_ac); + g_string_free(beginning, TRUE); + if (found != NULL) { + return found; + } } } diff --git a/src/command/commands.c b/src/command/commands.c index b46815bb..d2232155 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -265,6 +265,15 @@ cmd_account(gchar **args, struct cmd_help_t help) accounts_set_muc_nick(account_name, value); cons_show("Updated muc nick for account %s: %s", account_name, value); cons_show(""); + } else if (strcmp(property, "otr") == 0) { + if ((g_strcmp0(value, "manual") != 0) + && (g_strcmp0(value, "opportunistic") != 0) + && (g_strcmp0(value, "always") != 0)) { + cons_show("Invalid setting."); + } else { + cons_show("Updated OTR policy for account %s: %s", account_name, value); + cons_show(""); + } } else if (strcmp(property, "status") == 0) { if (!valid_resource_presence_string(value) && (strcmp(value, "last") != 0)) { cons_show("Invalid status: %s", value); From 95ff13136bfd84342074a606d7d6676a3c70d1e8 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 11 May 2014 14:13:15 +0100 Subject: [PATCH 4/8] Added OTR policy account preference --- src/command/commands.c | 3 ++- src/config/account.c | 12 +++++++++--- src/config/account.h | 3 ++- src/config/accounts.c | 21 +++++++++++++++++++-- src/config/accounts.h | 1 + src/ui/console.c | 3 +++ tests/test_cmd_account.c | 4 ++-- tests/test_cmd_connect.c | 6 +++--- tests/test_cmd_join.c | 8 ++++---- tests/test_cmd_otr.c | 2 +- 10 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index d2232155..aeae1f90 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -269,8 +269,9 @@ cmd_account(gchar **args, struct cmd_help_t help) if ((g_strcmp0(value, "manual") != 0) && (g_strcmp0(value, "opportunistic") != 0) && (g_strcmp0(value, "always") != 0)) { - cons_show("Invalid setting."); + cons_show("OTR policy must be one of: manual, opportunistic or always."); } else { + accounts_set_otr_policy(account_name, value); cons_show("Updated OTR policy for account %s: %s", account_name, value); cons_show(""); } diff --git a/src/config/account.c b/src/config/account.c index 4f52d280..d982fb88 100644 --- a/src/config/account.c +++ b/src/config/account.c @@ -34,7 +34,7 @@ account_new(const gchar * const name, const gchar * const jid, int port, const gchar * const resource, const gchar * const last_presence, const gchar * const login_presence, int priority_online, int priority_chat, int priority_away, int priority_xa, int priority_dnd, - const gchar * const muc_service, const gchar * const muc_nick) + const gchar * const muc_service, const gchar * const muc_nick, const gchar * const otr_policy) { ProfAccount *new_account = malloc(sizeof(ProfAccount)); @@ -111,6 +111,12 @@ account_new(const gchar * const name, const gchar * const jid, new_account->muc_nick = strdup(muc_nick); } + if (otr_policy != NULL) { + new_account->otr_policy = strdup(otr_policy); + } else { + new_account->otr_policy = NULL; + } + return new_account; } @@ -137,7 +143,7 @@ account_free(ProfAccount *account) free(account->login_presence); free(account->muc_service); free(account->muc_nick); + free(account->otr_policy); free(account); } -} - +} \ No newline at end of file diff --git a/src/config/account.h b/src/config/account.h index 6050b861..549e9124 100644 --- a/src/config/account.h +++ b/src/config/account.h @@ -42,6 +42,7 @@ typedef struct prof_account_t { gchar *muc_service; gchar *muc_nick; gboolean enabled; + gchar *otr_policy; } ProfAccount; ProfAccount* account_new(const gchar * const name, const gchar * const jid, @@ -49,7 +50,7 @@ ProfAccount* account_new(const gchar * const name, const gchar * const jid, int port, const gchar * const resource, const gchar * const last_presence, const gchar * const login_presence, int priority_online, int priority_chat, int priority_away, int priority_xa, int priority_dnd, - const gchar * const muc_service, const gchar * const muc_nick); + const gchar * const muc_service, const gchar * const muc_nick, const gchar * const otr_policy); char* account_create_full_jid(ProfAccount *account); diff --git a/src/config/accounts.c b/src/config/accounts.c index 4b1ddb1e..0f7be510 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -50,7 +50,8 @@ static gchar *string_keys[] = { "presence.last", "presence.login", "muc.service", - "muc.nick" + "muc.nick", + "otr.policy" }; static void _fix_legacy_accounts(const char * const account_name); @@ -212,10 +213,15 @@ _accounts_get_account(const char * const name) gchar *muc_service = g_key_file_get_string(accounts, name, "muc.service", NULL); gchar *muc_nick = g_key_file_get_string(accounts, 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); + } + ProfAccount *new_account = account_new(name, jid, password, enabled, server, port, resource, last_presence, login_presence, priority_online, priority_chat, priority_away, priority_xa, - priority_dnd, muc_service, muc_nick); + priority_dnd, muc_service, muc_nick, otr_policy); g_free(jid); g_free(password); @@ -225,6 +231,7 @@ _accounts_get_account(const char * const name) g_free(login_presence); g_free(muc_service); g_free(muc_nick); + g_free(otr_policy); return new_account; } @@ -400,6 +407,15 @@ _accounts_set_muc_nick(const char * const account_name, const char * const value } } +static void +_accounts_set_otr_policy(const char * const account_name, const char * const value) +{ + if (accounts_account_exists(account_name)) { + g_key_file_set_string(accounts, account_name, "otr.policy", value); + _save_accounts(); + } +} + static void _accounts_set_priority_online(const char * const account_name, const gint value) { @@ -660,6 +676,7 @@ accounts_init_module(void) accounts_set_password = _accounts_set_password; accounts_set_muc_service = _accounts_set_muc_service; accounts_set_muc_nick = _accounts_set_muc_nick; + accounts_set_otr_policy = _accounts_set_otr_policy; accounts_set_last_presence = _accounts_set_last_presence; accounts_set_login_presence = _accounts_set_login_presence; accounts_get_last_presence = _accounts_get_last_presence; diff --git a/src/config/accounts.h b/src/config/accounts.h index 335eba9d..de3c2a0f 100644 --- a/src/config/accounts.h +++ b/src/config/accounts.h @@ -52,6 +52,7 @@ void (*accounts_set_resource)(const char * const account_name, const char * cons void (*accounts_set_password)(const char * const account_name, const char * const value); void (*accounts_set_muc_service)(const char * const account_name, const char * const value); void (*accounts_set_muc_nick)(const char * const account_name, const char * const value); +void (*accounts_set_otr_policy)(const char * const account_name, const char * const value); void (*accounts_set_last_presence)(const char * const account_name, const char * const value); void (*accounts_set_login_presence)(const char * const account_name, const char * const value); resource_presence_t (*accounts_get_login_presence)(const char * const account_name); diff --git a/src/ui/console.c b/src/ui/console.c index f5f352b5..d9caf47f 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -885,6 +885,9 @@ _cons_show_account(ProfAccount *account) if (account->muc_nick != NULL) { cons_show ("muc nick : %s", account->muc_nick); } + if (account->otr_policy != NULL) { + cons_show ("OTR policy : %s", account->otr_policy); + } if (account->last_presence != NULL) { cons_show ("Last presence : %s", account->last_presence); } diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c index 51bb33f2..d03d757b 100644 --- a/tests/test_cmd_account.c +++ b/tests/test_cmd_account.c @@ -40,7 +40,7 @@ void cmd_account_shows_account_when_connected_and_no_args(void **state) mock_accounts_get_account(); CommandHelp *help = malloc(sizeof(CommandHelp)); ProfAccount *account = account_new("jabber_org", "me@jabber.org", NULL, - TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL); + TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL); gchar *args[] = { NULL }; mock_connection_status(JABBER_CONNECTED); @@ -119,7 +119,7 @@ void cmd_account_show_shows_account_when_exists(void **state) CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "show", "account_name", NULL }; ProfAccount *account = account_new("jabber_org", "me@jabber.org", NULL, - TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL); + TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL); accounts_get_account_return(account); diff --git a/tests/test_cmd_connect.c b/tests/test_cmd_connect.c index 33f49164..1007c034 100644 --- a/tests/test_cmd_connect.c +++ b/tests/test_cmd_connect.c @@ -424,7 +424,7 @@ void cmd_connect_asks_password_when_not_in_account(void **state) CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "jabber_org", NULL }; ProfAccount *account = account_new("jabber_org", "me@jabber.org", NULL, - TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL); + TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL); mock_connection_status(JABBER_DISCONNECTED); @@ -448,7 +448,7 @@ void cmd_connect_shows_message_when_connecting_with_account(void **state) CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "jabber_org", NULL }; ProfAccount *account = account_new("jabber_org", "user@jabber.org", "password", - TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL); + TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL); mock_connection_status(JABBER_DISCONNECTED); @@ -472,7 +472,7 @@ void cmd_connect_connects_with_account(void **state) CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "jabber_org", NULL }; ProfAccount *account = account_new("jabber_org", "me@jabber.org", "password", - TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL); + TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL); mock_connection_status(JABBER_DISCONNECTED); diff --git a/tests/test_cmd_join.c b/tests/test_cmd_join.c index 7a1949b7..134a99ab 100644 --- a/tests/test_cmd_join.c +++ b/tests/test_cmd_join.c @@ -98,7 +98,7 @@ void cmd_join_uses_account_mucservice_when_no_service_specified(void **state) CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { room, "nick", nick, NULL }; ProfAccount *account = account_new(account_name, "user@server.org", NULL, - TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, account_service, NULL); + TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, account_service, NULL, NULL); muc_init(); @@ -124,7 +124,7 @@ void cmd_join_uses_supplied_nick(void **state) CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { room, "nick", nick, NULL }; ProfAccount *account = account_new(account_name, "user@server.org", NULL, - TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL); + TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL); muc_init(); @@ -150,7 +150,7 @@ void cmd_join_uses_account_nick_when_not_supplied(void **state) CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { room, NULL }; ProfAccount *account = account_new(account_name, "user@server.org", NULL, - TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, account_nick); + TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, account_nick, NULL); muc_init(); @@ -179,7 +179,7 @@ void cmd_join_uses_password_when_supplied(void **state) CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { room, "password", password, NULL }; ProfAccount *account = account_new(account_name, "user@server.org", NULL, - TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, account_service, account_nick); + TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, account_service, account_nick, NULL); muc_init(); diff --git a/tests/test_cmd_otr.c b/tests/test_cmd_otr.c index 3bad3d8d..e6c87941 100644 --- a/tests/test_cmd_otr.c +++ b/tests/test_cmd_otr.c @@ -325,7 +325,7 @@ void cmd_otr_gen_generates_key_for_connected_account(void **state) gchar *args[] = { "gen", NULL }; char *account_name = "myaccount"; ProfAccount *account = account_new(account_name, "me@jabber.org", NULL, - TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL); + TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL); stub_cons_show(); mock_connection_status(JABBER_CONNECTED); From e8d84abb46681b68931d68094ca56214450e0670 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 11 May 2014 15:03:10 +0100 Subject: [PATCH 5/8] Moved OTR policy check to otr module --- src/command/command.c | 2 +- src/command/commands.c | 2 +- src/otr/otr.c | 9 +++++++++ src/otr/otr.h | 2 ++ src/server_events.c | 2 +- 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index a46c1548..59c5515c 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1363,7 +1363,7 @@ cmd_execute_default(const char * const inp) ui_current_print_line("You are not currently connected."); } else { #ifdef HAVE_LIBOTR - if ((strcmp(prefs_get_string(PREF_OTR_POLICY), "always") == 0) && !otr_is_secure(recipient)) { + if ((strcmp(otr_get_policy(recipient), "always") == 0) && !otr_is_secure(recipient)) { cons_show_error("Failed to send message. Please check OTR policy"); return TRUE; } diff --git a/src/command/commands.c b/src/command/commands.c index aeae1f90..03759b4b 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1004,7 +1004,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) cons_show_error("Failed to encrypt and send message,"); } } else { - char *policy = prefs_get_string(PREF_OTR_POLICY); + char *policy = otr_get_policy(usr_jid); if (strcmp(policy, "always") == 0) { cons_show_error("Failed to send message. Please check OTR policy"); diff --git a/src/otr/otr.c b/src/otr/otr.c index 043dc30f..dd715233 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -32,6 +32,7 @@ #include "roster_list.h" #include "contact.h" #include "ui/ui.h" +#include "config/preferences.h" #define PRESENCE_ONLINE 1 #define PRESENCE_OFFLINE 0 @@ -515,6 +516,13 @@ _otr_get_their_fingerprint(const char * const recipient) } } +static char * +_otr_get_policy(const char * const recipient) +{ + // check global setting + return prefs_get_string(PREF_OTR_POLICY); +} + static char * _otr_encrypt_message(const char * const to, const char * const message) { @@ -596,4 +604,5 @@ otr_init_module(void) otr_smp_secret = _otr_smp_secret; otr_smp_question = _otr_smp_question; otr_smp_answer = _otr_smp_answer; + otr_get_policy = _otr_get_policy; } diff --git a/src/otr/otr.h b/src/otr/otr.h index 87b34b45..f3000786 100644 --- a/src/otr/otr.h +++ b/src/otr/otr.h @@ -63,4 +63,6 @@ char * (*otr_decrypt_message)(const char * const from, const char * const messag void (*otr_free_message)(char *message); +char * (*otr_get_policy)(const char * const recipient); + #endif diff --git a/src/server_events.c b/src/server_events.c index 6fb06c74..52fdf052 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -227,7 +227,7 @@ handle_incoming_message(char *from, char *message, gboolean priv) gboolean was_decrypted = FALSE; char *newmessage; - char *policy = prefs_get_string(PREF_OTR_POLICY); + char *policy = otr_get_policy(from); char *whitespace_base = strstr(message,OTRL_MESSAGE_TAG_BASE); if (!priv) { From 6a38d57a0a875a61ae3167c64afa118f2cdd3d66 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 11 May 2014 15:20:24 +0100 Subject: [PATCH 6/8] Override global OTR policy with account OTR policy --- src/otr/otr.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/otr/otr.c b/src/otr/otr.c index dd715233..72e6817a 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -519,6 +519,14 @@ _otr_get_their_fingerprint(const char * const recipient) static char * _otr_get_policy(const char * const recipient) { + // check account setting + ProfAccount *account = accounts_get_account(jabber_get_account_name()); + if (account->otr_policy != NULL) { + account_free(account); + return account->otr_policy; + } + account_free(account); + // check global setting return prefs_get_string(PREF_OTR_POLICY); } From d44e954f6b4e24d5d2ba1da2f1dbc537a580a589 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 11 May 2014 15:26:45 +0100 Subject: [PATCH 7/8] Added otr property to /account help --- src/command/command.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/command/command.c b/src/command/command.c index 59c5515c..d355eb04 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -739,6 +739,7 @@ static struct cmd_t command_defs[] = "password : Password for the account, note this is currently stored in plaintext if set.", "muc : The default MUC chat service to use.", "nick : The default nickname to use when joining chat rooms.", + "otr : Override global OTR policy for this account: manual, opportunistic or always.", "", "The clear command may use one of the following for 'property'.", "password : Clears the password for the account.", From 3967b26aea502e9773651a3992925af510ddffa4 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 11 May 2014 15:32:38 +0100 Subject: [PATCH 8/8] Added otr to /account clear properties --- src/command/command.c | 1 + src/command/commands.c | 4 ++++ src/config/accounts.c | 10 ++++++++++ src/config/accounts.h | 1 + 4 files changed, 16 insertions(+) diff --git a/src/command/command.c b/src/command/command.c index d355eb04..9015fd2a 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1033,6 +1033,7 @@ cmd_init(void) account_clear_ac = autocomplete_new(); autocomplete_add(account_clear_ac, "password"); + autocomplete_add(account_clear_ac, "otr"); close_ac = autocomplete_new(); autocomplete_add(close_ac, "read"); diff --git a/src/command/commands.c b/src/command/commands.c index 03759b4b..d8721834 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -341,6 +341,10 @@ cmd_account(gchar **args, struct cmd_help_t help) accounts_clear_password(account_name); cons_show("Removed password for account %s", account_name); cons_show(""); + } else if (strcmp(property, "otr") == 0) { + accounts_clear_otr(account_name); + cons_show("OTR policy removed for account %s", account_name); + cons_show(""); } else { cons_show("Invalid property: %s", property); cons_show(""); diff --git a/src/config/accounts.c b/src/config/accounts.c index 0f7be510..cf7c4c93 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -389,6 +389,15 @@ _accounts_clear_password(const char * const account_name) } } +static void +_accounts_clear_otr(const char * const account_name) +{ + if (accounts_account_exists(account_name)) { + g_key_file_remove_key(accounts, account_name, "otr.policy", NULL); + _save_accounts(); + } +} + static void _accounts_set_muc_service(const char * const account_name, const char * const value) { @@ -689,5 +698,6 @@ accounts_init_module(void) accounts_set_priority_all = _accounts_set_priority_all; accounts_get_priority_for_presence_type = _accounts_get_priority_for_presence_type; accounts_clear_password = _accounts_clear_password; + accounts_clear_otr = _accounts_clear_otr; } diff --git a/src/config/accounts.h b/src/config/accounts.h index de3c2a0f..60f8aa04 100644 --- a/src/config/accounts.h +++ b/src/config/accounts.h @@ -66,5 +66,6 @@ void (*accounts_set_priority_all)(const char * const account_name, const gint va gint (*accounts_get_priority_for_presence_type)(const char * const account_name, resource_presence_t presence_type); void (*accounts_clear_password)(const char * const account_name); +void (*accounts_clear_otr)(const char * const account_name); #endif