diff --git a/src/command/commands.c b/src/command/commands.c index e3dc5613..fbbb0a8a 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -4956,7 +4956,7 @@ cmd_otr(ProfWin *window, const char *const command, gchar **args) return TRUE; } - ui_trust(chatwin->barejid); + ui_trust(chatwin); otr_trust(chatwin->barejid); return TRUE; @@ -4973,7 +4973,7 @@ cmd_otr(ProfWin *window, const char *const command, gchar **args) return TRUE; } - ui_untrust(chatwin->barejid); + ui_untrust(chatwin); otr_untrust(chatwin->barejid); return TRUE; diff --git a/src/otr/otr.c b/src/otr/otr.c index 8d1ee545..bdecf22d 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -573,13 +573,18 @@ otr_smp_secret(const char *const recipient, const char *secret) } // if recipient initiated SMP, send response, else initialise + ProfChatWin *chatwin = wins_get_chat(recipient); if (g_hash_table_contains(smp_initiators, recipient)) { otrl_message_respond_smp(user_state, &ops, NULL, context, (const unsigned char*)secret, strlen(secret)); - ui_otr_authenticating(recipient); + if (chatwin) { + ui_otr_authenticating(chatwin); + } g_hash_table_remove(smp_initiators, context->username); } else { otrl_message_initiate_smp(user_state, &ops, NULL, context, (const unsigned char*)secret, strlen(secret)); - ui_otr_authetication_waiting(recipient); + if (chatwin) { + ui_otr_authetication_waiting(chatwin); + } } } @@ -597,7 +602,10 @@ otr_smp_question(const char *const recipient, const char *question, const char * } otrl_message_initiate_smp_q(user_state, &ops, NULL, context, question, (const unsigned char*)answer, strlen(answer)); - ui_otr_authetication_waiting(recipient); + ProfChatWin *chatwin = wins_get_chat(recipient); + if (chatwin) { + ui_otr_authetication_waiting(chatwin); + } } void diff --git a/src/otr/otrlibv3.c b/src/otr/otrlibv3.c index 05083dea..8343f19f 100644 --- a/src/otr/otrlibv3.c +++ b/src/otr/otrlibv3.c @@ -176,24 +176,22 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext otrl_message_abort_smp(user_state, ops, NULL, context); } else { context->smstate->nextExpected = OTRL_SMP_EXPECT1; - if (context->smstate->received_question == 0) { - ProfChatWin *chatwin = wins_get_chat(context->username); - if (context->active_fingerprint->trust && (context->active_fingerprint->trust[0] != '\0')) { - if (chatwin) { + ProfChatWin *chatwin = wins_get_chat(context->username); + if (chatwin) { + if (context->smstate->received_question == 0) { + if (context->active_fingerprint->trust && (context->active_fingerprint->trust[0] != '\0')) { ui_smp_successful(chatwin); - } - ui_trust(context->username); - } else { - if (chatwin) { + ui_trust(chatwin); + } else { ui_smp_unsuccessful_sender(chatwin); + ui_untrust(chatwin); } - ui_untrust(context->username); - } - } else { - if (context->smstate->sm_prog_state == OTRL_SMP_PROG_SUCCEEDED) { - ui_smp_answer_success(context->username); } else { - ui_smp_answer_failure(context->username); + if (context->smstate->sm_prog_state == OTRL_SMP_PROG_SUCCEEDED) { + ui_smp_answer_success(chatwin); + } else { + ui_smp_answer_failure(chatwin); + } } } } @@ -205,16 +203,14 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext } else { context->smstate->nextExpected = OTRL_SMP_EXPECT1; ProfChatWin *chatwin = wins_get_chat(context->username); - if (context->active_fingerprint->trust && (context->active_fingerprint->trust[0] != '\0')) { - if (chatwin) { + if (chatwin) { + if (context->active_fingerprint->trust && (context->active_fingerprint->trust[0] != '\0')) { ui_smp_successful(chatwin); - } - ui_trust(context->username); - } else { - if (chatwin) { + ui_trust(chatwin); + } else { ui_smp_unsuccessful_receiver(chatwin); + ui_untrust(chatwin); } - ui_untrust(context->username); } } } @@ -224,8 +220,8 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext ProfChatWin *chatwin = wins_get_chat(context->username); if (chatwin) { ui_smp_aborted(chatwin); + ui_untrust(chatwin); } - ui_untrust(context->username); otr_untrust(context->username); } } diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index 29d6d57a..a82a98a8 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -195,30 +195,28 @@ cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event, break; case OTRL_SMPEVENT_SUCCESS: - if (context->smstate->received_question == 0) { - if (chatwin) { + if (chatwin) { + if (context->smstate->received_question == 0) { ui_smp_successful(chatwin); + ui_trust(chatwin); + } else { + ui_smp_answer_success(chatwin); } - ui_trust(context->username); - } else { - ui_smp_answer_success(context->username); } break; case OTRL_SMPEVENT_FAILURE: - if (context->smstate->received_question == 0) { - if (nextMsg == OTRL_SMP_EXPECT3) { - if (chatwin) { + if (chatwin) { + if (context->smstate->received_question == 0) { + if (nextMsg == OTRL_SMP_EXPECT3) { ui_smp_unsuccessful_sender(chatwin); - } - } else if (nextMsg == OTRL_SMP_EXPECT4) { - if (chatwin) { + } else if (nextMsg == OTRL_SMP_EXPECT4) { ui_smp_unsuccessful_receiver(chatwin); } + ui_untrust(chatwin); + } else { + ui_smp_answer_failure(chatwin); } - ui_untrust(context->username); - } else { - ui_smp_answer_failure(context->username); } break; @@ -233,8 +231,8 @@ cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event, case OTRL_SMPEVENT_ABORT: if (chatwin) { ui_smp_aborted(chatwin); + ui_untrust(chatwin); } - ui_untrust(context->username); break; case OTRL_SMPEVENT_IN_PROGRESS: diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 5c8dbca6..9d61a62b 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -156,38 +156,64 @@ ui_smp_successful(ProfChatWin *chatwin) } void -ui_smp_answer_success(const char *const barejid) +ui_smp_answer_success(ProfChatWin *chatwin) { - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s successfully authenticated you.", barejid); + assert(chatwin != NULL); + + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s successfully authenticated you.", chatwin->barejid); +} + +void +ui_smp_answer_failure(ProfChatWin *chatwin) +{ + assert(chatwin != NULL); + + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s failed to authenticate you.", chatwin->barejid); +} + +void +ui_otr_authenticating(ProfChatWin *chatwin) +{ + assert(chatwin != NULL); + + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Authenticating %s...", chatwin->barejid); +} + +void +ui_otr_authetication_waiting(ProfChatWin *chatwin) +{ + assert(chatwin != NULL); + + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Awaiting authentication from %s...", chatwin->barejid); +} + +void +ui_trust(ProfChatWin *chatwin) +{ + assert(chatwin != NULL); + + chatwin->is_otr = TRUE; + chatwin->otr_is_trusted = TRUE; + + ProfWin *window = (ProfWin*)chatwin; + win_print(window, '!', 0, NULL, 0, THEME_OTR_TRUSTED, "", "OTR session trusted."); + if (wins_is_current(window)) { + title_bar_switch(); } } void -ui_smp_answer_failure(const char *const barejid) +ui_untrust(ProfChatWin *chatwin) { - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s failed to authenticate you.", barejid); - } -} + assert(chatwin != NULL); -void -ui_otr_authenticating(const char *const barejid) -{ - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Authenticating %s...", barejid); - } -} + chatwin->is_otr = TRUE; + chatwin->otr_is_trusted = FALSE; -void -ui_otr_authetication_waiting(const char *const barejid) -{ - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Awaiting authentication from %s...", barejid); + ProfWin *window = (ProfWin*)chatwin; + win_print(window, '!', 0, NULL, 0, THEME_OTR_UNTRUSTED, "", "OTR session untrusted."); + if (wins_is_current(window)) { + title_bar_switch(); } } @@ -202,38 +228,6 @@ ui_handle_otr_error(const char *const barejid, const char *const message) } } -void -ui_trust(const char *const barejid) -{ - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - chatwin->is_otr = TRUE; - chatwin->otr_is_trusted = TRUE; - - ProfWin *window = (ProfWin*)chatwin; - win_print(window, '!', 0, NULL, 0, THEME_OTR_TRUSTED, "", "OTR session trusted."); - if (wins_is_current(window)) { - title_bar_switch(); - } - } -} - -void -ui_untrust(const char *const barejid) -{ - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - chatwin->is_otr = TRUE; - chatwin->otr_is_trusted = FALSE; - - ProfWin *window = (ProfWin*)chatwin; - win_print(window, '!', 0, NULL, 0, THEME_OTR_UNTRUSTED, "", "OTR session untrusted."); - if (wins_is_current(window)) { - title_bar_switch(); - } - } -} - void ui_recipient_gone(const char *const barejid, const char *const resource) { diff --git a/src/ui/ui.h b/src/ui/ui.h index d497ea00..5d92797d 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -64,8 +64,8 @@ void ui_sigwinch_handler(int sig); void ui_gone_secure(ProfChatWin *chatwin, gboolean trusted); void ui_gone_insecure(ProfChatWin *chatwin); -void ui_trust(const char *const barejid); -void ui_untrust(const char *const barejid); +void ui_trust(ProfChatWin *chatwin); +void ui_untrust(ProfChatWin *chatwin); void ui_smp_recipient_initiated(ProfChatWin *chatwin); void ui_smp_recipient_initiated_q(ProfChatWin *chatwin, const char *question); @@ -74,11 +74,11 @@ void ui_smp_unsuccessful_sender(ProfChatWin *chatwin); void ui_smp_unsuccessful_receiver(ProfChatWin *chatwin); void ui_smp_aborted(ProfChatWin *chatwin); -void ui_smp_answer_success(const char *const barejid); -void ui_smp_answer_failure(const char *const barejid); +void ui_smp_answer_success(ProfChatWin *chatwin); +void ui_smp_answer_failure(ProfChatWin *chatwin); -void ui_otr_authenticating(const char *const barejid); -void ui_otr_authetication_waiting(const char *const recipient); +void ui_otr_authenticating(ProfChatWin *chatwin); +void ui_otr_authetication_waiting(ProfChatWin *chatwin); void ui_handle_otr_error(const char *const barejid, const char *const message); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 77c8dd17..f6f4cb78 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -68,8 +68,8 @@ void ui_switch_win(ProfWin *win) {} void ui_gone_secure(ProfChatWin *chatwin, gboolean trusted) {} void ui_gone_insecure(ProfChatWin *chatwin) {} -void ui_trust(const char * const barejid) {} -void ui_untrust(const char * const barejid) {} +void ui_trust(ProfChatWin *chatwin) {} +void ui_untrust(ProfChatWin *chatwin) {} void ui_smp_recipient_initiated(ProfChatWin *chatwin) {} void ui_smp_recipient_initiated_q(ProfChatWin *chatwin, const char *question) {} @@ -78,11 +78,11 @@ void ui_smp_unsuccessful_sender(ProfChatWin *chatwin) {} void ui_smp_unsuccessful_receiver(ProfChatWin *chatwin) {} void ui_smp_aborted(ProfChatWin *chatwin) {} -void ui_smp_answer_success(const char * const barejid) {} -void ui_smp_answer_failure(const char * const barejid) {} +void ui_smp_answer_success(ProfChatWin *chatwin) {} +void ui_smp_answer_failure(ProfChatWin *chatwin) {} -void ui_otr_authenticating(const char * const barejid) {} -void ui_otr_authetication_waiting(const char * const recipient) {} +void ui_otr_authenticating(ProfChatWin *chatwin) {} +void ui_otr_authetication_waiting(ProfChatWin *chatwin) {} void ui_sigwinch_handler(int sig) {} unsigned long ui_get_idle_time(void)