about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/command/commands.c3
-rw-r--r--src/config/account.c12
-rw-r--r--src/config/account.h3
-rw-r--r--src/config/accounts.c21
-rw-r--r--src/config/accounts.h1
-rw-r--r--src/ui/console.c3
-rw-r--r--tests/test_cmd_account.c4
-rw-r--r--tests/test_cmd_connect.c6
-rw-r--r--tests/test_cmd_join.c8
-rw-r--r--tests/test_cmd_otr.c2
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;
     }
@@ -401,6 +408,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)
 {
     if (accounts_account_exists(account_name)) {
@@ -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);