From 49022068efc35709db9c6bb7ca9c0c546db7673c Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Mar 2015 01:26:09 +0000 Subject: [PATCH] Added OTR error messages --- src/otr/otrlibv4.c | 57 +++++++++++++++++++++++++++++++++++++++++----- src/ui/core.c | 11 +++++++++ src/ui/ui.h | 2 ++ 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index e090ead4..713e51ab 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -113,12 +113,57 @@ cb_handle_msg_event(void *opdata, OtrlMessageEvent msg_event, ConnContext *context, const char *message, gcry_error_t err) { - if (err != 0) { - if (message != NULL) { - cons_show_error("%s", message); - } else { - cons_show_error("OTR error event with no message."); - } + GString *err_msg; + switch (msg_event) + { + case OTRL_MSGEVENT_ENCRYPTION_REQUIRED: + ui_handle_otr_error(context->username, "OTR: Policy requires encryption, but attempting to send an unencrypted message."); + break; + case OTRL_MSGEVENT_ENCRYPTION_ERROR: + ui_handle_otr_error(context->username, "OTR: Error occured while encrypting a message, message not sent."); + break; + case OTRL_MSGEVENT_CONNECTION_ENDED: + ui_handle_otr_error(context->username, "OTR: Message not sent because contact has ended the private conversation."); + break; + case OTRL_MSGEVENT_SETUP_ERROR: + ui_handle_otr_error(context->username, "OTR: A private conversation could not be set up."); + break; + case OTRL_MSGEVENT_MSG_REFLECTED: + ui_handle_otr_error(context->username, "OTR: Received our own OTR message."); + break; + case OTRL_MSGEVENT_MSG_RESENT: + ui_handle_otr_error(context->username, "OTR: The previous message was resent."); + break; + case OTRL_MSGEVENT_RCVDMSG_NOT_IN_PRIVATE: + ui_handle_otr_error(context->username, "OTR: Received an encrypted message but no private connection established."); + break; + case OTRL_MSGEVENT_RCVDMSG_UNREADABLE: + ui_handle_otr_error(context->username, "OTR: Cannot read the received message."); + break; + case OTRL_MSGEVENT_RCVDMSG_MALFORMED: + ui_handle_otr_error(context->username, "OTR: The message received contains malformed data."); + break; + case OTRL_MSGEVENT_RCVDMSG_GENERAL_ERR: + err_msg = g_string_new("OTR: Received error: "); + g_string_append(err_msg, message); + g_string_append(err_msg, "."); + ui_handle_otr_error(context->username, err_msg->str); + g_string_free(err_msg, TRUE); + break; + case OTRL_MSGEVENT_RCVDMSG_UNENCRYPTED: + err_msg = g_string_new("OTR: Received an unencrypted message: "); + g_string_append(err_msg, message); + ui_handle_otr_error(context->username, err_msg->str); + g_string_free(err_msg, TRUE); + break; + case OTRL_MSGEVENT_RCVDMSG_UNRECOGNIZED: + ui_handle_otr_error(context->username, "OTR: Cannot recognize the type of message received."); + break; + case OTRL_MSGEVENT_RCVDMSG_FOR_OTHER_INSTANCE: + ui_handle_otr_error(context->username, "OTR: Received and discarded a message intended for another instance."); + break; + default: + break; } } diff --git a/src/ui/core.c b/src/ui/core.c index 967a379f..3a65b270 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1107,6 +1107,17 @@ ui_otr_authetication_waiting(const char * const barejid) } } +void +ui_handle_otr_error(const char * const barejid, const char * const message) +{ + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + win_save_print((ProfWin*)chatwin, '!', NULL, 0, THEME_ERROR, "", message); + } else { + cons_show_error(message); + } +} + void ui_trust(const char * const barejid) { diff --git a/src/ui/ui.h b/src/ui/ui.h index c7ffda83..dfb8c0a9 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -82,6 +82,8 @@ void ui_smp_answer_failure(const char * const barejid); void ui_otr_authenticating(const char * const barejid); void ui_otr_authetication_waiting(const char * const recipient); +void ui_handle_otr_error(const char * const barejid, const char * const message); + unsigned long ui_get_idle_time(void); void ui_reset_idle_time(void); void ui_new_chat_win(const char * const barejid);