diff options
-rw-r--r-- | src/otr.c | 41 | ||||
-rw-r--r-- | src/otr.h | 3 | ||||
-rw-r--r-- | src/profanity.c | 3 |
3 files changed, 45 insertions, 2 deletions
diff --git a/src/otr.c b/src/otr.c index 7dd6aafd..6b10e3be 100644 --- a/src/otr.c +++ b/src/otr.c @@ -21,15 +21,52 @@ */ #include <libotr/proto.h> -#include <libotr/userstate.h> -#include <libotr/message.h> #include <libotr/privkey.h> +#include <glib.h> +#include "otr.h" #include "ui/ui.h" +static OtrlUserState user_state; + void otr_init(void) { cons_debug("otr_init()"); OTRL_INIT; } + +void +otr_account_load(ProfAccount *account) +{ + gcry_error_t err = 0; + cons_debug("otr_account_load()"); + GString *keys_filename = g_string_new("./"); + g_string_append(keys_filename, account->jid); + g_string_append(keys_filename, "_keys.txt"); + + GString *fp_filename = g_string_new("./"); + g_string_append(fp_filename, account->jid); + g_string_append(fp_filename, "_fingerprints.txt"); + + user_state = otrl_userstate_create(); + + err = otrl_privkey_read(user_state, keys_filename->str); + if (err != 0) { + cons_debug("Failed to load private keys"); + g_string_free(keys_filename, TRUE); + g_string_free(fp_filename, TRUE); + return; + } + + err = otrl_privkey_read_fingerprints(user_state, fp_filename->str, NULL, NULL); + if (err != 0) { + cons_debug("Failed to load fingerprints"); + g_string_free(keys_filename, TRUE); + g_string_free(fp_filename, TRUE); + return; + } + + g_string_free(keys_filename, TRUE); + g_string_free(fp_filename, TRUE); +} diff --git a/src/otr.h b/src/otr.h index 772c0f34..caa38ee5 100644 --- a/src/otr.h +++ b/src/otr.h @@ -23,6 +23,9 @@ #ifndef OTR_H #define OTR_H +#include "config/accounts.h" + void otr_init(void); +void otr_account_load(ProfAccount *account); #endif diff --git a/src/profanity.c b/src/profanity.c index ded96890..ac45b5f6 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -249,6 +249,9 @@ void prof_handle_login_account_success(char *account_name) { ProfAccount *account = accounts_get_account(account_name); +#ifdef HAVE_LIBOTR + otr_account_load(account); +#endif resource_presence_t resource_presence = accounts_get_login_presence(account->name); contact_presence_t contact_presence = contact_presence_from_resource_presence(resource_presence); cons_show_login_success(account); |