about summary refs log tree commit diff stats
path: root/src/otr
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-05-11 19:32:07 +0100
committerJames Booth <boothj5@gmail.com>2014-05-11 19:32:07 +0100
commit9dda7036a9410a6d2124d3eb6c34eefb7a39a13a (patch)
tree314eef11f733a64b767250889b68359af62d5aa0 /src/otr
parent6d955609c56a2a303eb141cbd7ba0cc2a364ef37 (diff)
downloadprofani-tty-9dda7036a9410a6d2124d3eb6c34eefb7a39a13a.tar.gz
Implemented per contact OTR policy setting
Diffstat (limited to 'src/otr')
-rw-r--r--src/otr/otr.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/otr/otr.c b/src/otr/otr.c
index 72e6817a..58b401d7 100644
--- a/src/otr/otr.c
+++ b/src/otr/otr.c
@@ -519,15 +519,44 @@ _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());
+    // check contact specific setting
+    if (g_list_find_custom(account->otr_manual, recipient, (GCompareFunc)g_strcmp0)) {
+        cons_debug("Using contact setting manual");
+        account_free(account);
+        return "manual";
+    }
+    if (g_list_find_custom(account->otr_opportunistic, recipient, (GCompareFunc)g_strcmp0)) {
+        cons_debug("Using contact setting opportunistic");
+        account_free(account);
+        return "opportunistic";
+    }
+    if (g_list_find_custom(account->otr_always, recipient, (GCompareFunc)g_strcmp0)) {
+        cons_debug("Using contact setting always");
+        account_free(account);
+        return "always";
+    }
+
+    // check default account setting
     if (account->otr_policy != NULL) {
+        cons_debug("Using account setting %s", account->otr_policy);
+        char *result;
+        if (g_strcmp0(account->otr_policy, "manual") == 0) {
+            result = "manual";
+        }
+        if (g_strcmp0(account->otr_policy, "opportunistic") == 0) {
+            result = "opportunistic";
+        }
+        if (g_strcmp0(account->otr_policy, "always") == 0) {
+            result = "always";
+        }
         account_free(account);
-        return account->otr_policy;
+        return result;
     }
     account_free(account);
 
     // check global setting
+    cons_debug("Using global setting %s", prefs_get_string(PREF_OTR_POLICY));
     return prefs_get_string(PREF_OTR_POLICY);
 }