From 7344d3b8987f6e2edb12a3861a07006e27fb80e5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 18 Jun 2014 00:32:36 +0100 Subject: Added deallocation function for string prefs, added otr policy enum --- src/otr/otr.c | 33 +++++++++++++++++++++++---------- src/otr/otr.h | 8 +++++++- src/otr/otrlibv4.c | 4 ++-- 3 files changed, 32 insertions(+), 13 deletions(-) (limited to 'src/otr') 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) { -- cgit 1.4.1-2-gfad0