about summary refs log tree commit diff stats
path: root/src/otr
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-06-18 00:32:36 +0100
committerJames Booth <boothj5@gmail.com>2014-06-18 00:32:36 +0100
commit7344d3b8987f6e2edb12a3861a07006e27fb80e5 (patch)
treee6a037f4c4c4b4083731c6f73adff66e9db6cb35 /src/otr
parent79ddf1048486d1a77a1aee9b8152c8ffb25d8a11 (diff)
downloadprofani-tty-7344d3b8987f6e2edb12a3861a07006e27fb80e5.tar.gz
Added deallocation function for string prefs, added otr policy enum
Diffstat (limited to 'src/otr')
-rw-r--r--src/otr/otr.c33
-rw-r--r--src/otr/otr.h8
-rw-r--r--src/otr/otrlibv4.c4
3 files changed, 32 insertions, 13 deletions
diff --git a/src/otr/otr.c b/src/otr/otr.c
index 7a5733bf..b6b68dcd 100644
--- a/src/otr/otr.c
+++ b/src/otr/otr.c
@@ -520,43 +520,56 @@ _otr_get_their_fingerprint(const char * const recipient)
     }
 }
 
-static char *
+static prof_otrpolicy_t
 _otr_get_policy(const char * const recipient)
 {
     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)) {
         account_free(account);
-        return strdup("manual");
+        return PROF_OTRPOLICY_MANUAL;
     }
     if (g_list_find_custom(account->otr_opportunistic, recipient, (GCompareFunc)g_strcmp0)) {
         account_free(account);
-        return strdup("opportunistic");
+        return PROF_OTRPOLICY_OPPORTUNISTIC;
     }
     if (g_list_find_custom(account->otr_always, recipient, (GCompareFunc)g_strcmp0)) {
         account_free(account);
-        return strdup("always");
+        return PROF_OTRPOLICY_ALWAYS;
     }
 
     // check default account setting
     if (account->otr_policy != NULL) {
-        char *result;
+        prof_otrpolicy_t result;
         if (g_strcmp0(account->otr_policy, "manual") == 0) {
-            result = "manual";
+            result = PROF_OTRPOLICY_MANUAL;
         }
         if (g_strcmp0(account->otr_policy, "opportunistic") == 0) {
-            result = "opportunistic";
+            result = PROF_OTRPOLICY_OPPORTUNISTIC;
         }
         if (g_strcmp0(account->otr_policy, "always") == 0) {
-            result = "always";
+            result = PROF_OTRPOLICY_ALWAYS;
         }
         account_free(account);
-        return strdup(result);
+        return result;
     }
     account_free(account);
 
     // check global setting
-    return prefs_get_string(PREF_OTR_POLICY);
+    char *pref_otr_policy = prefs_get_string(PREF_OTR_POLICY);
+
+    // pref defaults to manual
+    prof_otrpolicy_t result = PROF_OTRPOLICY_MANUAL;
+
+    if (strcmp(pref_otr_policy, "opportunistic") == 0) {
+        result = PROF_OTRPOLICY_OPPORTUNISTIC;
+    } else if (strcmp(pref_otr_policy, "always") == 0) {
+        result = PROF_OTRPOLICY_ALWAYS;
+    }
+
+    prefs_free_string(pref_otr_policy);
+
+    return result;
 }
 
 static char *
diff --git a/src/otr/otr.h b/src/otr/otr.h
index f3000786..a8553280 100644
--- a/src/otr/otr.h
+++ b/src/otr/otr.h
@@ -28,6 +28,12 @@
 
 #include "config/accounts.h"
 
+typedef enum {
+    PROF_OTRPOLICY_MANUAL,
+    PROF_OTRPOLICY_OPPORTUNISTIC,
+    PROF_OTRPOLICY_ALWAYS
+} prof_otrpolicy_t;
+
 void otr_init_module(void);
 
 OtrlUserState otr_userstate(void);
@@ -63,6 +69,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);
+prof_otrpolicy_t (*otr_get_policy)(const char * const recipient);
 
 #endif
diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c
index 0bcd779c..a91bbe43 100644
--- a/src/otr/otrlibv4.c
+++ b/src/otr/otrlibv4.c
@@ -93,7 +93,7 @@ cb_otr_error_message_free(void *opdata, const char *err_msg)
 static void
 cb_timer_control(void *opdata, unsigned int interval)
 {
-    current_interval = interval; 
+    current_interval = interval;
 }
 
 static void
@@ -139,7 +139,7 @@ cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event,
                 ui_smp_answer_success(context->username);
             }
             break;
-            
+
         case OTRL_SMPEVENT_FAILURE:
             if (context->smstate->received_question == 0) {
                 if (nextMsg == OTRL_SMP_EXPECT3) {