From c99ff8d941ef5528cb228020936d6d6efcef6d20 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 26 Oct 2015 22:35:30 +0000 Subject: [PATCH 01/30] Extracted chatwin.c --- Makefile.am | 1 + src/ui/chatwin.c | 455 +++++++++++++++++++++++++++++++++++++++++++++++ src/ui/core.c | 410 ------------------------------------------ 3 files changed, 456 insertions(+), 410 deletions(-) create mode 100644 src/ui/chatwin.c diff --git a/Makefile.am b/Makefile.am index 4466e851..6b5a3928 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,6 +24,7 @@ core_sources = \ src/window_list.c src/window_list.h \ src/ui/rosterwin.c src/ui/occupantswin.c \ src/ui/buffer.c src/ui/buffer.h \ + src/ui/chatwin.c \ src/command/command.h src/command/command.c \ src/command/commands.h src/command/commands.c \ src/tools/parser.c \ diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c new file mode 100644 index 00000000..6cf5885a --- /dev/null +++ b/src/ui/chatwin.c @@ -0,0 +1,455 @@ +/* + * chatwin.c + * + * Copyright (C) 2012 - 2015 James Booth + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + * In addition, as a special exception, the copyright holders give permission to + * link the code of portions of this program with the OpenSSL library under + * certain conditions as described in each individual source file, and + * distribute linked combinations including the two. + * + * You must obey the GNU General Public License in all respects for all of the + * code used other than OpenSSL. If you modify file(s) with this exception, you + * may extend this exception to your version of the file(s), but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. If you delete this exception statement from all + * source files in the program, then also delete it here. + * + */ + +#include +#include + +#include "chat_session.h" +#include "window_list.h" +#include "roster_list.h" +#include "log.h" +#include "config/preferences.h" +#include "ui/ui.h" +#include "ui/window.h" +#include "ui/titlebar.h" + +static void _win_show_history(ProfChatWin *chatwin, const char *const contact); + +gboolean +ui_chat_win_exists(const char *const barejid) +{ + ProfChatWin *chatwin = wins_get_chat(barejid); + return (chatwin != NULL); +} + +void +ui_message_receipt(const char *const barejid, const char *const id) +{ + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + ProfWin *win = (ProfWin*) chatwin; + win_mark_received(win, id); + } +} + +void +ui_gone_secure(const char *const barejid, gboolean trusted) +{ + ProfWin *window = NULL; + + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + window = (ProfWin*)chatwin; + } else { + window = wins_new_chat(barejid); + chatwin = (ProfChatWin*)window; + } + + chatwin->is_otr = TRUE; + chatwin->otr_is_trusted = trusted; + if (trusted) { + win_print(window, '!', 0, NULL, 0, THEME_OTR_STARTED_TRUSTED, "", "OTR session started (trusted)."); + } else { + win_print(window, '!', 0, NULL, 0, THEME_OTR_STARTED_UNTRUSTED, "", "OTR session started (untrusted)."); + } + + if (wins_is_current(window)) { + title_bar_switch(); + } else { + int num = wins_get_num(window); + status_bar_new(num); + + int ui_index = num; + if (ui_index == 10) { + ui_index = 0; + } + cons_show("%s started an OTR session (%d).", barejid, ui_index); + cons_alert(); + } +} + +void +ui_gone_insecure(const char *const barejid) +{ + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + chatwin->is_otr = FALSE; + chatwin->otr_is_trusted = FALSE; + + ProfWin *window = (ProfWin*)chatwin; + win_print(window, '!', 0, NULL, 0, THEME_OTR_ENDED, "", "OTR session ended."); + if (wins_is_current(window)) { + title_bar_switch(); + } + } +} + +void +ui_smp_recipient_initiated(const char *const barejid) +{ + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s wants to authenticate your identity, use '/otr secret '.", barejid); + } +} + +void +ui_smp_recipient_initiated_q(const char *const barejid, const char *question) +{ + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s wants to authenticate your identity with the following question:", barejid); + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", " %s", question); + win_print((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "use '/otr answer '."); + } +} + +void +ui_smp_unsuccessful_sender(const char *const barejid) +{ + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Authentication failed, the secret you entered does not match the secret entered by %s.", barejid); + } +} + +void +ui_smp_unsuccessful_receiver(const char *const barejid) +{ + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Authentication failed, the secret entered by %s does not match yours.", barejid); + } +} + +void +ui_smp_aborted(const char *const barejid) +{ + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + win_print((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "SMP session aborted."); + } +} + +void +ui_smp_successful(const char *const barejid) +{ + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + win_print((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Authentication successful."); + } +} + +void +ui_smp_answer_success(const char *const barejid) +{ + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s successfully authenticated you.", barejid); + } +} + +void +ui_smp_answer_failure(const char *const barejid) +{ + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s failed to authenticate you.", barejid); + } +} + +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); + } +} + +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); + } +} + +void +ui_handle_otr_error(const char *const barejid, const char *const message) +{ + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + win_print((ProfWin*)chatwin, '!', 0, NULL, 0, THEME_ERROR, "", message); + } else { + cons_show_error("%s - %s", barejid, 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) +{ + if (barejid == NULL) + return; + if (resource == NULL) + return; + + gboolean show_message = TRUE; + + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + ChatSession *session = chat_session_get(barejid); + if (session && g_strcmp0(session->resource, resource) != 0) { + show_message = FALSE; + } + if (show_message) { + const char * display_usr = NULL; + PContact contact = roster_get_contact(barejid); + if (contact) { + if (p_contact_name(contact)) { + display_usr = p_contact_name(contact); + } else { + display_usr = barejid; + } + } else { + display_usr = barejid; + } + + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, THEME_GONE, "", "<- %s has left the conversation.", display_usr); + } + } +} + +ProfChatWin* +ui_new_chat_win(const char *const barejid) +{ + ProfWin *window = wins_new_chat(barejid); + ProfChatWin *chatwin = (ProfChatWin *)window; + + if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { + _win_show_history(chatwin, barejid); + } + + // if the contact is offline, show a message + PContact contact = roster_get_contact(barejid); + if (contact) { + if (strcmp(p_contact_presence(contact), "offline") == 0) { + const char * const show = p_contact_presence(contact); + const char * const status = p_contact_status(contact); + win_show_status_string(window, barejid, show, status, NULL, "--", "offline"); + } + } + + return chatwin; +} + +void +ui_incoming_msg(ProfChatWin *chatwin, const char *const resource, const char *const message, GDateTime *timestamp, gboolean win_created, prof_enc_t enc_mode) +{ + ProfWin *window = (ProfWin*)chatwin; + int num = wins_get_num(window); + + char *display_name = roster_get_msg_display_name(chatwin->barejid, resource); + + // currently viewing chat window with sender + if (wins_is_current(window)) { + win_print_incoming_message(window, timestamp, display_name, message, enc_mode); + title_bar_set_typing(FALSE); + status_bar_active(num); + + // not currently viewing chat window with sender + } else { + status_bar_new(num); + cons_show_incoming_message(display_name, num); + + if (prefs_get_boolean(PREF_FLASH)) { + flash(); + } + + chatwin->unread++; + if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { + _win_show_history(chatwin, chatwin->barejid); + } + + // show users status first, when receiving message via delayed delivery + if (timestamp && win_created) { + PContact pcontact = roster_get_contact(chatwin->barejid); + if (pcontact) { + win_show_contact(window, pcontact); + } + } + + win_print_incoming_message(window, timestamp, display_name, message, enc_mode); + } + + if (prefs_get_boolean(PREF_BEEP)) { + beep(); + } + + if (prefs_get_boolean(PREF_NOTIFY_MESSAGE)) { + notify_message(window, display_name, message); + } + + free(display_name); +} + +void +ui_outgoing_chat_msg(ProfChatWin *chatwin, const char *const message, char *id, prof_enc_t enc_mode) +{ + char enc_char = '-'; + if (enc_mode == PROF_MSG_OTR) { + enc_char = prefs_get_otr_char(); + } else if (enc_mode == PROF_MSG_PGP) { + enc_char = prefs_get_pgp_char(); + } + + if (prefs_get_boolean(PREF_RECEIPTS_REQUEST) && id) { + win_print_with_receipt((ProfWin*)chatwin, enc_char, 0, NULL, 0, THEME_TEXT_ME, "me", message, id); + } else { + win_print((ProfWin*)chatwin, enc_char, 0, NULL, 0, THEME_TEXT_ME, "me", message); + } +} + +void +ui_outgoing_chat_msg_carbon(const char *const barejid, const char *const message) +{ + ProfChatWin *chatwin = wins_get_chat(barejid); + + // create new window + if (!chatwin) { + chatwin = ui_new_chat_win(barejid); + } + + chat_state_active(chatwin->state); + + win_print((ProfWin*)chatwin, '-', 0, NULL, 0, THEME_TEXT_ME, "me", message); + + int num = wins_get_num((ProfWin*)chatwin); + status_bar_active(num); +} + +void +ui_chat_win_contact_online(PContact contact, Resource *resource, GDateTime *last_activity) +{ + const char *show = string_from_resource_presence(resource->presence); + char *display_str = p_contact_create_display_string(contact, resource->name); + const char *barejid = p_contact_barejid(contact); + + ProfWin *window = (ProfWin*)wins_get_chat(barejid); + if (window) { + win_show_status_string(window, display_str, show, resource->status, + last_activity, "++", "online"); + + } + + free(display_str); +} + +void +ui_chat_win_contact_offline(PContact contact, char *resource, char *status) +{ + char *display_str = p_contact_create_display_string(contact, resource); + const char *barejid = p_contact_barejid(contact); + + ProfWin *window = (ProfWin*)wins_get_chat(barejid); + if (window) { + win_show_status_string(window, display_str, "offline", status, NULL, "--", + "offline"); + } + + free(display_str); +} + +static void +_win_show_history(ProfChatWin *chatwin, const char *const contact) +{ + if (!chatwin->history_shown) { + Jid *jid = jid_create(jabber_get_fulljid()); + GSList *history = chat_log_get_previous(jid->barejid, contact); + jid_destroy(jid); + GSList *curr = history; + while (curr) { + char *line = curr->data; + // entry + if (line[2] == ':') { + char hh[3]; memcpy(hh, &line[0], 2); hh[2] = '\0'; int ihh = atoi(hh); + char mm[3]; memcpy(mm, &line[3], 2); mm[2] = '\0'; int imm = atoi(mm); + char ss[3]; memcpy(ss, &line[6], 2); ss[2] = '\0'; int iss = atoi(ss); + GDateTime *timestamp = g_date_time_new_local(2000, 1, 1, ihh, imm, iss); + win_print((ProfWin*)chatwin, '-', 0, timestamp, NO_COLOUR_DATE, 0, "", curr->data+11); + g_date_time_unref(timestamp); + // header + } else { + win_print((ProfWin*)chatwin, '-', 0, NULL, 0, 0, "", curr->data); + } + curr = g_slist_next(curr); + } + chatwin->history_shown = TRUE; + + g_slist_free_full(history, free); + } +} diff --git a/src/ui/core.c b/src/ui/core.c index 8d19f5b4..a804c53c 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -88,8 +88,6 @@ static Display *display; static GTimer *ui_idle_time; -//static void _win_handle_switch(const wint_t ch); -static void _win_show_history(ProfChatWin *chatwin, const char *const contact); static void _ui_draw_term_title(void); void @@ -301,13 +299,6 @@ ui_handle_stanza(const char *const msg) } } -gboolean -ui_chat_win_exists(const char *const barejid) -{ - ProfChatWin *chatwin = wins_get_chat(barejid); - return (chatwin != NULL); -} - void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity) { @@ -394,66 +385,6 @@ ui_get_chat_recipients(void) return recipients; } -void -ui_message_receipt(const char *const barejid, const char *const id) -{ - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - ProfWin *win = (ProfWin*) chatwin; - win_mark_received(win, id); - } -} - -void -ui_incoming_msg(ProfChatWin *chatwin, const char *const resource, const char *const message, GDateTime *timestamp, gboolean win_created, prof_enc_t enc_mode) -{ - ProfWin *window = (ProfWin*)chatwin; - int num = wins_get_num(window); - - char *display_name = roster_get_msg_display_name(chatwin->barejid, resource); - - // currently viewing chat window with sender - if (wins_is_current(window)) { - win_print_incoming_message(window, timestamp, display_name, message, enc_mode); - title_bar_set_typing(FALSE); - status_bar_active(num); - - // not currently viewing chat window with sender - } else { - status_bar_new(num); - cons_show_incoming_message(display_name, num); - - if (prefs_get_boolean(PREF_FLASH)) { - flash(); - } - - chatwin->unread++; - if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { - _win_show_history(chatwin, chatwin->barejid); - } - - // show users status first, when receiving message via delayed delivery - if (timestamp && win_created) { - PContact pcontact = roster_get_contact(chatwin->barejid); - if (pcontact) { - win_show_contact(window, pcontact); - } - } - - win_print_incoming_message(window, timestamp, display_name, message, enc_mode); - } - - if (prefs_get_boolean(PREF_BEEP)) { - beep(); - } - - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE)) { - notify_message(window, display_name, message); - } - - free(display_name); -} - void ui_incoming_private_msg(const char *const fulljid, const char *const message, GDateTime *timestamp) { @@ -848,193 +779,6 @@ ui_switch_win(ProfWin *window) status_bar_active(i); } -void -ui_gone_secure(const char *const barejid, gboolean trusted) -{ - ProfWin *window = NULL; - - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - window = (ProfWin*)chatwin; - } else { - window = wins_new_chat(barejid); - chatwin = (ProfChatWin*)window; - } - - chatwin->is_otr = TRUE; - chatwin->otr_is_trusted = trusted; - if (trusted) { - win_print(window, '!', 0, NULL, 0, THEME_OTR_STARTED_TRUSTED, "", "OTR session started (trusted)."); - } else { - win_print(window, '!', 0, NULL, 0, THEME_OTR_STARTED_UNTRUSTED, "", "OTR session started (untrusted)."); - } - - if (wins_is_current(window)) { - title_bar_switch(); - } else { - int num = wins_get_num(window); - status_bar_new(num); - - int ui_index = num; - if (ui_index == 10) { - ui_index = 0; - } - cons_show("%s started an OTR session (%d).", barejid, ui_index); - cons_alert(); - } -} - -void -ui_gone_insecure(const char *const barejid) -{ - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - chatwin->is_otr = FALSE; - chatwin->otr_is_trusted = FALSE; - - ProfWin *window = (ProfWin*)chatwin; - win_print(window, '!', 0, NULL, 0, THEME_OTR_ENDED, "", "OTR session ended."); - if (wins_is_current(window)) { - title_bar_switch(); - } - } -} - -void -ui_smp_recipient_initiated(const char *const barejid) -{ - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s wants to authenticate your identity, use '/otr secret '.", barejid); - } -} - -void -ui_smp_recipient_initiated_q(const char *const barejid, const char *question) -{ - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s wants to authenticate your identity with the following question:", barejid); - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", " %s", question); - win_print((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "use '/otr answer '."); - } -} - -void -ui_smp_unsuccessful_sender(const char *const barejid) -{ - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Authentication failed, the secret you entered does not match the secret entered by %s.", barejid); - } -} - -void -ui_smp_unsuccessful_receiver(const char *const barejid) -{ - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Authentication failed, the secret entered by %s does not match yours.", barejid); - } -} - -void -ui_smp_aborted(const char *const barejid) -{ - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - win_print((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "SMP session aborted."); - } -} - -void -ui_smp_successful(const char *const barejid) -{ - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - win_print((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Authentication successful."); - } -} - -void -ui_smp_answer_success(const char *const barejid) -{ - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s successfully authenticated you.", barejid); - } -} - -void -ui_smp_answer_failure(const char *const barejid) -{ - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s failed to authenticate you.", barejid); - } -} - -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); - } -} - -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); - } -} - -void -ui_handle_otr_error(const char *const barejid, const char *const message) -{ - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - win_print((ProfWin*)chatwin, '!', 0, NULL, 0, THEME_ERROR, "", message); - } else { - cons_show_error("%s - %s", barejid, 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_close_win(int index) { @@ -1172,40 +916,6 @@ ui_print_system_msg_from_recipient(const char *const barejid, const char *messag win_vprint(window, '-', 0, NULL, 0, 0, "", "*%s %s", barejid, message); } -void -ui_recipient_gone(const char *const barejid, const char *const resource) -{ - if (barejid == NULL) - return; - if (resource == NULL) - return; - - gboolean show_message = TRUE; - - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - ChatSession *session = chat_session_get(barejid); - if (session && g_strcmp0(session->resource, resource) != 0) { - show_message = FALSE; - } - if (show_message) { - const char * display_usr = NULL; - PContact contact = roster_get_contact(barejid); - if (contact) { - if (p_contact_name(contact)) { - display_usr = p_contact_name(contact); - } else { - display_usr = barejid; - } - } else { - display_usr = barejid; - } - - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, THEME_GONE, "", "<- %s has left the conversation.", display_usr); - } - } -} - ProfPrivateWin* ui_new_private_win(const char *const fulljid) { @@ -1229,64 +939,6 @@ ui_open_xmlconsole_win(void) } } -ProfChatWin* -ui_new_chat_win(const char *const barejid) -{ - ProfWin *window = wins_new_chat(barejid); - ProfChatWin *chatwin = (ProfChatWin *)window; - - if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { - _win_show_history(chatwin, barejid); - } - - // if the contact is offline, show a message - PContact contact = roster_get_contact(barejid); - if (contact) { - if (strcmp(p_contact_presence(contact), "offline") == 0) { - const char * const show = p_contact_presence(contact); - const char * const status = p_contact_status(contact); - win_show_status_string(window, barejid, show, status, NULL, "--", "offline"); - } - } - - return chatwin; -} - -void -ui_outgoing_chat_msg(ProfChatWin *chatwin, const char *const message, char *id, prof_enc_t enc_mode) -{ - char enc_char = '-'; - if (enc_mode == PROF_MSG_OTR) { - enc_char = prefs_get_otr_char(); - } else if (enc_mode == PROF_MSG_PGP) { - enc_char = prefs_get_pgp_char(); - } - - if (prefs_get_boolean(PREF_RECEIPTS_REQUEST) && id) { - win_print_with_receipt((ProfWin*)chatwin, enc_char, 0, NULL, 0, THEME_TEXT_ME, "me", message, id); - } else { - win_print((ProfWin*)chatwin, enc_char, 0, NULL, 0, THEME_TEXT_ME, "me", message); - } -} - -void -ui_outgoing_chat_msg_carbon(const char *const barejid, const char *const message) -{ - ProfChatWin *chatwin = wins_get_chat(barejid); - - // create new window - if (!chatwin) { - chatwin = ui_new_chat_win(barejid); - } - - chat_state_active(chatwin->state); - - win_print((ProfWin*)chatwin, '-', 0, NULL, 0, THEME_TEXT_ME, "me", message); - - int num = wins_get_num((ProfWin*)chatwin); - status_bar_active(num); -} - void ui_outgoing_private_msg(ProfPrivateWin *privwin, const char *const message) { @@ -2103,38 +1755,6 @@ ui_ask_pgp_passphrase(const char *hint, int prev_fail) return inp_get_password(); } -void -ui_chat_win_contact_online(PContact contact, Resource *resource, GDateTime *last_activity) -{ - const char *show = string_from_resource_presence(resource->presence); - char *display_str = p_contact_create_display_string(contact, resource->name); - const char *barejid = p_contact_barejid(contact); - - ProfWin *window = (ProfWin*)wins_get_chat(barejid); - if (window) { - win_show_status_string(window, display_str, show, resource->status, - last_activity, "++", "online"); - - } - - free(display_str); -} - -void -ui_chat_win_contact_offline(PContact contact, char *resource, char *status) -{ - char *display_str = p_contact_create_display_string(contact, resource); - const char *barejid = p_contact_barejid(contact); - - ProfWin *window = (ProfWin*)wins_get_chat(barejid); - if (window) { - win_show_status_string(window, display_str, "offline", status, NULL, "--", - "offline"); - } - - free(display_str); -} - void ui_contact_offline(char *barejid, char *resource, char *status) { @@ -2862,33 +2482,3 @@ ui_show_software_version(const char *const jid, const char *const presence, win_vprint(window, '-', 0, NULL, 0, 0, "", "OS : %s", os); } } - -static void -_win_show_history(ProfChatWin *chatwin, const char *const contact) -{ - if (!chatwin->history_shown) { - Jid *jid = jid_create(jabber_get_fulljid()); - GSList *history = chat_log_get_previous(jid->barejid, contact); - jid_destroy(jid); - GSList *curr = history; - while (curr) { - char *line = curr->data; - // entry - if (line[2] == ':') { - char hh[3]; memcpy(hh, &line[0], 2); hh[2] = '\0'; int ihh = atoi(hh); - char mm[3]; memcpy(mm, &line[3], 2); mm[2] = '\0'; int imm = atoi(mm); - char ss[3]; memcpy(ss, &line[6], 2); ss[2] = '\0'; int iss = atoi(ss); - GDateTime *timestamp = g_date_time_new_local(2000, 1, 1, ihh, imm, iss); - win_print((ProfWin*)chatwin, '-', 0, timestamp, NO_COLOUR_DATE, 0, "", curr->data+11); - g_date_time_unref(timestamp); - // header - } else { - win_print((ProfWin*)chatwin, '-', 0, NULL, 0, 0, "", curr->data); - } - curr = g_slist_next(curr); - } - chatwin->history_shown = TRUE; - - g_slist_free_full(history, free); - } -} From 8f45f332ade58b188f1f51d86304f525f1951647 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 26 Oct 2015 22:43:32 +0000 Subject: [PATCH 02/30] Removed ui_chat_win_exists --- src/event/server_events.c | 10 +++++----- src/ui/chatwin.c | 7 ------- src/ui/ui.h | 1 - src/window_list.c | 7 +++++++ src/window_list.h | 2 ++ tests/unittests/ui/stub_ui.c | 4 ---- 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index d58633ce..4173fa7f 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -318,7 +318,7 @@ void sv_ev_typing(char *barejid, char *resource) { ui_contact_typing(barejid, resource); - if (ui_chat_win_exists(barejid)) { + if (wins_chat_exists(barejid)) { chat_session_recipient_typing(barejid, resource); } } @@ -326,7 +326,7 @@ sv_ev_typing(char *barejid, char *resource) void sv_ev_paused(char *barejid, char *resource) { - if (ui_chat_win_exists(barejid)) { + if (wins_chat_exists(barejid)) { chat_session_recipient_paused(barejid, resource); } } @@ -334,7 +334,7 @@ sv_ev_paused(char *barejid, char *resource) void sv_ev_inactive(char *barejid, char *resource) { - if (ui_chat_win_exists(barejid)) { + if (wins_chat_exists(barejid)) { chat_session_recipient_inactive(barejid, resource); } } @@ -343,7 +343,7 @@ void sv_ev_gone(const char *const barejid, const char *const resource) { ui_recipient_gone(barejid, resource); - if (ui_chat_win_exists(barejid)) { + if (wins_chat_exists(barejid)) { chat_session_recipient_gone(barejid, resource); } } @@ -351,7 +351,7 @@ sv_ev_gone(const char *const barejid, const char *const resource) void sv_ev_activity(const char *const barejid, const char *const resource, gboolean send_states) { - if (ui_chat_win_exists(barejid)) { + if (wins_chat_exists(barejid)) { chat_session_recipient_active(barejid, resource, send_states); } } diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 6cf5885a..7f394b47 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -46,13 +46,6 @@ static void _win_show_history(ProfChatWin *chatwin, const char *const contact); -gboolean -ui_chat_win_exists(const char *const barejid) -{ - ProfChatWin *chatwin = wins_get_chat(barejid); - return (chatwin != NULL); -} - void ui_message_receipt(const char *const barejid, const char *const id) { diff --git a/src/ui/ui.h b/src/ui/ui.h index c7e3a8ee..a6795e25 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -210,7 +210,6 @@ void ui_show_lines(ProfWin *window, const gchar** lines); void ui_redraw_all_room_rosters(void); void ui_show_all_room_rosters(void); void ui_hide_all_room_rosters(void); -gboolean ui_chat_win_exists(const char *const barejid); void ui_handle_software_version_error(const char *const roomjid, const char *const message); void ui_show_software_version(const char *const jid, const char *const presence, const char *const name, const char *const version, const char *const os); diff --git a/src/window_list.c b/src/window_list.c index ad43f888..c026e875 100644 --- a/src/window_list.c +++ b/src/window_list.c @@ -69,6 +69,13 @@ wins_get_console(void) return g_hash_table_lookup(windows, GINT_TO_POINTER(1)); } +gboolean +wins_chat_exists(const char *const barejid) +{ + ProfChatWin *chatwin = wins_get_chat(barejid); + return (chatwin != NULL); +} + ProfChatWin* wins_get_chat(const char *const barejid) { diff --git a/src/window_list.h b/src/window_list.h index e3e446f4..4b7dca8c 100644 --- a/src/window_list.h +++ b/src/window_list.h @@ -45,6 +45,8 @@ ProfWin* wins_new_muc(const char *const roomjid); ProfWin* wins_new_muc_config(const char *const roomjid, DataForm *form); ProfWin* wins_new_private(const char *const fulljid); +gboolean wins_chat_exists(const char *const barejid); + ProfWin* wins_get_console(void); ProfChatWin* wins_get_chat(const char *const barejid); ProfMucWin* wins_get_muc(const char *const roomjid); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 3e8d532b..47e7e9e9 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -256,10 +256,6 @@ void ui_group_added(const char * const contact, const char * const group) {} void ui_group_removed(const char * const contact, const char * const group) {} void ui_chat_win_contact_online(PContact contact, Resource *resource, GDateTime *last_activity) {} void ui_chat_win_contact_offline(PContact contact, char *resource, char *status) {} -gboolean ui_chat_win_exists(const char * const barejid) -{ - return TRUE; -} void ui_contact_offline(char *barejid, char *resource, char *status) {} From 2efaa464bf6629a4f59be2834ce646d7abb8ecda Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 26 Oct 2015 22:54:06 +0000 Subject: [PATCH 03/30] ui_message_receipt takes ProfChatWin --- src/event/server_events.c | 6 +++++- src/ui/chatwin.c | 9 +++------ src/ui/ui.h | 2 +- tests/unittests/ui/stub_ui.c | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index 4173fa7f..1f8d53cc 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -311,7 +311,11 @@ sv_ev_delayed_private_message(const char *const fulljid, char *message, GDateTim void sv_ev_message_receipt(char *barejid, char *id) { - ui_message_receipt(barejid, id); + ProfChatWin *chatwin = wins_get_chat(barejid); + if (!chatwin) + return; + + ui_message_receipt(chatwin, id); } void diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 7f394b47..1f25d642 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -47,13 +47,10 @@ static void _win_show_history(ProfChatWin *chatwin, const char *const contact); void -ui_message_receipt(const char *const barejid, const char *const id) +ui_message_receipt(ProfChatWin *chatwin, const char *const id) { - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - ProfWin *win = (ProfWin*) chatwin; - win_mark_received(win, id); - } + ProfWin *win = (ProfWin*) chatwin; + win_mark_received(win, id); } void diff --git a/src/ui/ui.h b/src/ui/ui.h index a6795e25..c4d8d8cb 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -112,7 +112,7 @@ void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activi void ui_contact_typing(const char *const barejid, const char *const resource); void ui_incoming_msg(ProfChatWin *chatwin, const char *const resource, const char *const message, GDateTime *timestamp, gboolean win_created, prof_enc_t enc_mode); void ui_incoming_private_msg(const char *const fulljid, const char *const message, GDateTime *timestamp); -void ui_message_receipt(const char *const barejid, const char *const id); +void ui_message_receipt(ProfChatWin *chatwin, const char *const id); void ui_disconnected(void); void ui_recipient_gone(const char *const barejid, const char *const resource); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 47e7e9e9..8c648551 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -185,7 +185,7 @@ void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activi void ui_contact_typing(const char * const barejid, const char * const resource) {} void ui_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char * const message, GDateTime *timestamp, gboolean win_created, prof_enc_t enc_mode) {} -void ui_message_receipt(const char * const barejid, const char * const id) {} +void ui_message_receipt(ProfChatWin *chatwin, const char * const id) {} void ui_incoming_private_msg(const char * const fulljid, const char * const message, GDateTime *timestamp) {} From 4fb0b4b0da41525a8c9d70937fcc538aae2877cb Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 26 Oct 2015 23:04:45 +0000 Subject: [PATCH 04/30] ui_gone_secure takes ProfChatWin --- src/command/commands.c | 4 ++-- src/otr/otr.c | 8 +++++++- src/ui/chatwin.c | 16 ++++------------ src/ui/ui.h | 2 +- tests/unittests/ui/stub_ui.c | 2 +- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 6c5fa3ed..bab32c33 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1532,7 +1532,7 @@ cmd_msg(ProfWin *window, const char *const command, gchar **args) } else { #ifdef HAVE_LIBOTR if (otr_is_secure(barejid)) { - ui_gone_secure(barejid, otr_is_trusted(barejid)); + ui_gone_secure(chatwin, otr_is_trusted(barejid)); } #endif } @@ -4893,7 +4893,7 @@ cmd_otr(ProfWin *window, const char *const command, gchar **args) return TRUE; } - ui_gone_secure(barejid, otr_is_trusted(barejid)); + ui_gone_secure(chatwin, otr_is_trusted(barejid)); return TRUE; // no recipient, use current chat diff --git a/src/otr/otr.c b/src/otr/otr.c index 9ff4a503..6b9dd34d 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -42,6 +42,7 @@ #include "otr/otrlib.h" #include "log.h" #include "roster_list.h" +#include "window_list.h" #include "contact.h" #include "ui/ui.h" #include "config/preferences.h" @@ -143,7 +144,12 @@ cb_write_fingerprints(void *opdata) static void cb_gone_secure(void *opdata, ConnContext *context) { - ui_gone_secure(context->username, otr_is_trusted(context->username)); + ProfChatWin *chatwin = wins_get_chat(context->username); + if (!chatwin) { + chatwin = (ProfChatWin*) wins_new_chat(context->username); + } + + ui_gone_secure(chatwin, otr_is_trusted(context->username)); } char* diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 1f25d642..07159760 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -54,20 +54,12 @@ ui_message_receipt(ProfChatWin *chatwin, const char *const id) } void -ui_gone_secure(const char *const barejid, gboolean trusted) +ui_gone_secure(ProfChatWin *chatwin, gboolean trusted) { - ProfWin *window = NULL; - - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - window = (ProfWin*)chatwin; - } else { - window = wins_new_chat(barejid); - chatwin = (ProfChatWin*)window; - } - chatwin->is_otr = TRUE; chatwin->otr_is_trusted = trusted; + + ProfWin *window = (ProfWin*) chatwin; if (trusted) { win_print(window, '!', 0, NULL, 0, THEME_OTR_STARTED_TRUSTED, "", "OTR session started (trusted)."); } else { @@ -84,7 +76,7 @@ ui_gone_secure(const char *const barejid, gboolean trusted) if (ui_index == 10) { ui_index = 0; } - cons_show("%s started an OTR session (%d).", barejid, ui_index); + cons_show("%s started an OTR session (%d).", chatwin->barejid, ui_index); cons_alert(); } } diff --git a/src/ui/ui.h b/src/ui/ui.h index c4d8d8cb..693cda39 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -62,7 +62,7 @@ GSList* ui_get_chat_recipients(void); void ui_switch_win(ProfWin *window); void ui_sigwinch_handler(int sig); -void ui_gone_secure(const char *const barejid, gboolean trusted); +void ui_gone_secure(ProfChatWin *chatwin, gboolean trusted); void ui_gone_insecure(const char *const barejid); void ui_trust(const char *const barejid); void ui_untrust(const char *const barejid); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 8c648551..3b196f46 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -66,7 +66,7 @@ GSList* ui_get_chat_recipients(void) void ui_switch_win(ProfWin *win) {} -void ui_gone_secure(const char * const barejid, gboolean trusted) {} +void ui_gone_secure(ProfChatWin *chatwin, gboolean trusted) {} void ui_gone_insecure(const char * const barejid) {} void ui_trust(const char * const barejid) {} void ui_untrust(const char * const barejid) {} From 9d3bcf5f90af09eb073b1caf64ccfadaad599e4b Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 26 Oct 2015 23:10:30 +0000 Subject: [PATCH 05/30] ui_gone_insecure takes ProfChatWin --- src/command/commands.c | 2 +- src/otr/otr.c | 5 ++++- src/ui/chatwin.c | 17 +++++++---------- src/ui/ui.h | 2 +- tests/unittests/ui/stub_ui.c | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index bab32c33..e3dc5613 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -4939,7 +4939,7 @@ cmd_otr(ProfWin *window, const char *const command, gchar **args) return TRUE; } - ui_gone_insecure(chatwin->barejid); + ui_gone_insecure(chatwin); otr_end_session(chatwin->barejid); return TRUE; diff --git a/src/otr/otr.c b/src/otr/otr.c index 6b9dd34d..8d1ee545 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -739,7 +739,10 @@ otr_decrypt_message(const char *const from, const char *const message, gboolean if (tlv) { if (context) { otrl_context_force_plaintext(context); - ui_gone_insecure(from); + ProfChatWin *chatwin = wins_get_chat(from); + if (chatwin) { + ui_gone_insecure(chatwin); + } } } diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 07159760..9af332a3 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -82,18 +82,15 @@ ui_gone_secure(ProfChatWin *chatwin, gboolean trusted) } void -ui_gone_insecure(const char *const barejid) +ui_gone_insecure(ProfChatWin *chatwin) { - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - chatwin->is_otr = FALSE; - chatwin->otr_is_trusted = FALSE; + chatwin->is_otr = FALSE; + chatwin->otr_is_trusted = FALSE; - ProfWin *window = (ProfWin*)chatwin; - win_print(window, '!', 0, NULL, 0, THEME_OTR_ENDED, "", "OTR session ended."); - if (wins_is_current(window)) { - title_bar_switch(); - } + ProfWin *window = (ProfWin*)chatwin; + win_print(window, '!', 0, NULL, 0, THEME_OTR_ENDED, "", "OTR session ended."); + if (wins_is_current(window)) { + title_bar_switch(); } } diff --git a/src/ui/ui.h b/src/ui/ui.h index 693cda39..9df8d9d3 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -63,7 +63,7 @@ void ui_switch_win(ProfWin *window); void ui_sigwinch_handler(int sig); void ui_gone_secure(ProfChatWin *chatwin, gboolean trusted); -void ui_gone_insecure(const char *const barejid); +void ui_gone_insecure(ProfChatWin *chatwin); void ui_trust(const char *const barejid); void ui_untrust(const char *const barejid); void ui_smp_recipient_initiated(const char *const barejid); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 3b196f46..11f648a5 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -67,7 +67,7 @@ GSList* ui_get_chat_recipients(void) void ui_switch_win(ProfWin *win) {} void ui_gone_secure(ProfChatWin *chatwin, gboolean trusted) {} -void ui_gone_insecure(const char * const barejid) {} +void ui_gone_insecure(ProfChatWin *chatwin) {} void ui_trust(const char * const barejid) {} void ui_untrust(const char * const barejid) {} void ui_smp_recipient_initiated(const char * const barejid) {} From 93c3feeacf090262ee24a8610f451a9196d92581 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 26 Oct 2015 23:11:38 +0000 Subject: [PATCH 06/30] Add assert checks for ProfChatWin functions --- src/ui/chatwin.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 9af332a3..3b3d2e1c 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -34,6 +34,7 @@ #include #include +#include #include "chat_session.h" #include "window_list.h" @@ -49,6 +50,8 @@ static void _win_show_history(ProfChatWin *chatwin, const char *const contact); void ui_message_receipt(ProfChatWin *chatwin, const char *const id) { + assert(chatwin != NULL); + ProfWin *win = (ProfWin*) chatwin; win_mark_received(win, id); } @@ -56,6 +59,8 @@ ui_message_receipt(ProfChatWin *chatwin, const char *const id) void ui_gone_secure(ProfChatWin *chatwin, gboolean trusted) { + assert(chatwin != NULL); + chatwin->is_otr = TRUE; chatwin->otr_is_trusted = trusted; @@ -84,6 +89,8 @@ ui_gone_secure(ProfChatWin *chatwin, gboolean trusted) void ui_gone_insecure(ProfChatWin *chatwin) { + assert(chatwin != NULL); + chatwin->is_otr = FALSE; chatwin->otr_is_trusted = FALSE; From 55e857d6a8ccd3c5f993ac867c864e7b22be1645 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 26 Oct 2015 23:22:59 +0000 Subject: [PATCH 07/30] ui_smp_recipient_initiated takes ProfChatWin --- src/otr/otrlibv3.c | 5 ++++- src/otr/otrlibv4.c | 7 ++++++- src/ui/chatwin.c | 9 ++++----- src/ui/ui.h | 2 +- tests/unittests/ui/stub_ui.c | 2 +- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/otr/otrlibv3.c b/src/otr/otrlibv3.c index 9bab4eed..fa574bfc 100644 --- a/src/otr/otrlibv3.c +++ b/src/otr/otrlibv3.c @@ -140,7 +140,10 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext if (nextMsg != OTRL_SMP_EXPECT1) { otrl_message_abort_smp(user_state, ops, NULL, context); } else { - ui_smp_recipient_initiated(context->username); + ProfChatWin *chatwin = wins_get_chat(context->username); + if (chatwin) { + ui_smp_recipient_initiated(chatwin); + } g_hash_table_insert(smp_initiators, strdup(context->username), strdup(context->username)); } } diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index 8ed17fcf..1f2c4057 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -37,6 +37,7 @@ #include #include "ui/ui.h" +#include "window_list.h" #include "log.h" #include "otr/otr.h" #include "otr/otrlib.h" @@ -176,10 +177,14 @@ cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event, OtrlMessageAppOps *ops = otr_messageops(); GHashTable *smp_initiators = otr_smpinitators(); + ProfChatWin *chatwin = wins_get_chat(context->username); + switch(smp_event) { case OTRL_SMPEVENT_ASK_FOR_SECRET: - ui_smp_recipient_initiated(context->username); + if (chatwin) { + ui_smp_recipient_initiated(chatwin); + } g_hash_table_insert(smp_initiators, strdup(context->username), strdup(context->username)); break; diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 3b3d2e1c..7b1c3365 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -102,12 +102,11 @@ ui_gone_insecure(ProfChatWin *chatwin) } void -ui_smp_recipient_initiated(const char *const barejid) +ui_smp_recipient_initiated(ProfChatWin *chatwin) { - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s wants to authenticate your identity, use '/otr secret '.", barejid); - } + assert(chatwin != NULL); + + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s wants to authenticate your identity, use '/otr secret '.", chatwin->barejid); } void diff --git a/src/ui/ui.h b/src/ui/ui.h index 9df8d9d3..139a291f 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -66,7 +66,7 @@ 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_smp_recipient_initiated(const char *const barejid); +void ui_smp_recipient_initiated(ProfChatWin *chatwin); void ui_smp_recipient_initiated_q(const char *const barejid, const char *question); void ui_smp_successful(const char *const barejid); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 11f648a5..27a6314f 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -70,7 +70,7 @@ 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_smp_recipient_initiated(const char * const barejid) {} +void ui_smp_recipient_initiated(ProfChatWin *chatwin) {} void ui_smp_recipient_initiated_q(const char * const barejid, const char *question) {} void ui_smp_successful(const char * const barejid) {} From 3ce55de1e172c37ba32cdb7b2200b8758e2c8459 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 26 Oct 2015 23:29:01 +0000 Subject: [PATCH 08/30] ui_smp_recipient_initiated_q takes ProfChatWin --- src/otr/otrlibv3.c | 11 +++++++---- src/otr/otrlibv4.c | 4 +++- src/ui/chatwin.c | 13 ++++++------- src/ui/ui.h | 2 +- tests/unittests/ui/stub_ui.c | 2 +- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/otr/otrlibv3.c b/src/otr/otrlibv3.c index fa574bfc..52b9a022 100644 --- a/src/otr/otrlibv3.c +++ b/src/otr/otrlibv3.c @@ -152,10 +152,13 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext if (nextMsg != OTRL_SMP_EXPECT1) { otrl_message_abort_smp(user_state, ops, NULL, context); } else { - char *question = (char *)tlv->data; - char *eoq = memchr(question, '\0', tlv->len); - if (eoq) { - ui_smp_recipient_initiated_q(context->username, question); + ProfChatWin *chatwin = wins_get_chat(context->username); + if (chatwin) { + char *question = (char *)tlv->data; + char *eoq = memchr(question, '\0', tlv->len); + if (eoq) { + ui_smp_recipient_initiated_q(chatwin, question); + } } } } diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index 1f2c4057..59cd7a0d 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -189,7 +189,9 @@ cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event, break; case OTRL_SMPEVENT_ASK_FOR_ANSWER: - ui_smp_recipient_initiated_q(context->username, question); + if (chatwin) { + ui_smp_recipient_initiated_q(chatwin, question); + } break; case OTRL_SMPEVENT_SUCCESS: diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 7b1c3365..301fc45e 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -110,14 +110,13 @@ ui_smp_recipient_initiated(ProfChatWin *chatwin) } void -ui_smp_recipient_initiated_q(const char *const barejid, const char *question) +ui_smp_recipient_initiated_q(ProfChatWin *chatwin, const char *question) { - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s wants to authenticate your identity with the following question:", barejid); - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", " %s", question); - win_print((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "use '/otr answer '."); - } + assert(chatwin != NULL); + + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s wants to authenticate your identity with the following question:", chatwin->barejid); + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", " %s", question); + win_print((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "use '/otr answer '."); } void diff --git a/src/ui/ui.h b/src/ui/ui.h index 139a291f..41cc35fe 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -67,7 +67,7 @@ void ui_gone_insecure(ProfChatWin *chatwin); void ui_trust(const char *const barejid); void ui_untrust(const char *const barejid); void ui_smp_recipient_initiated(ProfChatWin *chatwin); -void ui_smp_recipient_initiated_q(const char *const barejid, const char *question); +void ui_smp_recipient_initiated_q(ProfChatWin *chatwin, const char *question); void ui_smp_successful(const char *const barejid); void ui_smp_unsuccessful_sender(const char *const barejid); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 27a6314f..f3c20627 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -71,7 +71,7 @@ void ui_gone_insecure(ProfChatWin *chatwin) {} void ui_trust(const char * const barejid) {} void ui_untrust(const char * const barejid) {} void ui_smp_recipient_initiated(ProfChatWin *chatwin) {} -void ui_smp_recipient_initiated_q(const char * const barejid, const char *question) {} +void ui_smp_recipient_initiated_q(ProfChatWin *chatwin, const char *question) {} void ui_smp_successful(const char * const barejid) {} void ui_smp_unsuccessful_sender(const char * const barejid) {} From d11f8d5ffc19ebaa2f7c1e3e44e18a92162cc0de Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 26 Oct 2015 23:36:11 +0000 Subject: [PATCH 09/30] ui_smp_unsuccessful_sender takes ProfChatWin --- src/otr/otrlibv3.c | 5 ++++- src/otr/otrlibv4.c | 4 +++- src/ui/chatwin.c | 16 +++++++++------- src/ui/ui.h | 2 +- tests/unittests/ui/stub_ui.c | 2 +- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/otr/otrlibv3.c b/src/otr/otrlibv3.c index 52b9a022..de388b8f 100644 --- a/src/otr/otrlibv3.c +++ b/src/otr/otrlibv3.c @@ -181,7 +181,10 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext ui_smp_successful(context->username); ui_trust(context->username); } else { - ui_smp_unsuccessful_sender(context->username); + ProfChatWin *chatwin = wins_get_chat(context->username); + if (chatwin) { + ui_smp_unsuccessful_sender(chatwin); + } ui_untrust(context->username); } } else { diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index 59cd7a0d..ebdc2996 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -206,7 +206,9 @@ cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event, case OTRL_SMPEVENT_FAILURE: if (context->smstate->received_question == 0) { if (nextMsg == OTRL_SMP_EXPECT3) { - ui_smp_unsuccessful_sender(context->username); + if (chatwin) { + ui_smp_unsuccessful_sender(chatwin); + } } else if (nextMsg == OTRL_SMP_EXPECT4) { ui_smp_unsuccessful_receiver(context->username); } diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 301fc45e..e782c0bc 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -106,7 +106,8 @@ ui_smp_recipient_initiated(ProfChatWin *chatwin) { assert(chatwin != NULL); - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s wants to authenticate your identity, use '/otr secret '.", chatwin->barejid); + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", + "%s wants to authenticate your identity, use '/otr secret '.", chatwin->barejid); } void @@ -114,18 +115,19 @@ ui_smp_recipient_initiated_q(ProfChatWin *chatwin, const char *question) { assert(chatwin != NULL); - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s wants to authenticate your identity with the following question:", chatwin->barejid); + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", + "%s wants to authenticate your identity with the following question:", chatwin->barejid); win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", " %s", question); win_print((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "use '/otr answer '."); } void -ui_smp_unsuccessful_sender(const char *const barejid) +ui_smp_unsuccessful_sender(ProfChatWin *chatwin) { - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Authentication failed, the secret you entered does not match the secret entered by %s.", barejid); - } + assert(chatwin != NULL); + + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", + "Authentication failed, the secret you entered does not match the secret entered by %s.", chatwin->barejid); } void diff --git a/src/ui/ui.h b/src/ui/ui.h index 41cc35fe..c1efb9ea 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -70,7 +70,7 @@ void ui_smp_recipient_initiated(ProfChatWin *chatwin); void ui_smp_recipient_initiated_q(ProfChatWin *chatwin, const char *question); void ui_smp_successful(const char *const barejid); -void ui_smp_unsuccessful_sender(const char *const barejid); +void ui_smp_unsuccessful_sender(ProfChatWin *chatwin); void ui_smp_unsuccessful_receiver(const char *const barejid); void ui_smp_aborted(const char *const barejid); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index f3c20627..93dd1ca5 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -74,7 +74,7 @@ void ui_smp_recipient_initiated(ProfChatWin *chatwin) {} void ui_smp_recipient_initiated_q(ProfChatWin *chatwin, const char *question) {} void ui_smp_successful(const char * const barejid) {} -void ui_smp_unsuccessful_sender(const char * const barejid) {} +void ui_smp_unsuccessful_sender(ProfChatWin *chatwin) {} void ui_smp_unsuccessful_receiver(const char * const barejid) {} void ui_smp_aborted(const char * const barejid) {} From 0b51f4d36f4fe91147d2d06930798f84d1878a49 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 26 Oct 2015 23:40:37 +0000 Subject: [PATCH 10/30] ui_smp_unsuccessful_receiver takes ProfChatWin --- src/otr/otrlibv3.c | 5 ++++- src/otr/otrlibv4.c | 4 +++- src/ui/chatwin.c | 10 +++++----- src/ui/ui.h | 2 +- tests/unittests/ui/stub_ui.c | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/otr/otrlibv3.c b/src/otr/otrlibv3.c index de388b8f..3fb85e0e 100644 --- a/src/otr/otrlibv3.c +++ b/src/otr/otrlibv3.c @@ -206,7 +206,10 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext ui_smp_successful(context->username); ui_trust(context->username); } else { - ui_smp_unsuccessful_receiver(context->username); + ProfChatWin *chatwin = wins_get_chat(context->username); + if (chatwin) { + ui_smp_unsuccessful_receiver(chatwin); + } ui_untrust(context->username); } } diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index ebdc2996..acce648e 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -210,7 +210,9 @@ cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event, ui_smp_unsuccessful_sender(chatwin); } } else if (nextMsg == OTRL_SMP_EXPECT4) { - ui_smp_unsuccessful_receiver(context->username); + if (chatwin) { + ui_smp_unsuccessful_receiver(chatwin); + } } ui_untrust(context->username); } else { diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index e782c0bc..35e50af1 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -131,12 +131,12 @@ ui_smp_unsuccessful_sender(ProfChatWin *chatwin) } void -ui_smp_unsuccessful_receiver(const char *const barejid) +ui_smp_unsuccessful_receiver(ProfChatWin *chatwin) { - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Authentication failed, the secret entered by %s does not match yours.", barejid); - } + assert(chatwin != NULL); + + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", + "Authentication failed, the secret entered by %s does not match yours.", chatwin->barejid); } void diff --git a/src/ui/ui.h b/src/ui/ui.h index c1efb9ea..140d3426 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -71,7 +71,7 @@ void ui_smp_recipient_initiated_q(ProfChatWin *chatwin, const char *question); void ui_smp_successful(const char *const barejid); void ui_smp_unsuccessful_sender(ProfChatWin *chatwin); -void ui_smp_unsuccessful_receiver(const char *const barejid); +void ui_smp_unsuccessful_receiver(ProfChatWin *chatwin); void ui_smp_aborted(const char *const barejid); void ui_smp_answer_success(const char *const barejid); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 93dd1ca5..719b51e9 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -75,7 +75,7 @@ void ui_smp_recipient_initiated_q(ProfChatWin *chatwin, const char *question) {} void ui_smp_successful(const char * const barejid) {} void ui_smp_unsuccessful_sender(ProfChatWin *chatwin) {} -void ui_smp_unsuccessful_receiver(const char * const barejid) {} +void ui_smp_unsuccessful_receiver(ProfChatWin *chatwin) {} void ui_smp_aborted(const char * const barejid) {} void ui_smp_answer_success(const char * const barejid) {} From 3cea2bc4f4ae6d57cf4cdead868c1e02311aca40 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 26 Oct 2015 23:45:39 +0000 Subject: [PATCH 11/30] ui_smp_aborted takes ProfChatWin --- src/otr/otrlibv3.c | 5 ++++- src/otr/otrlibv4.c | 4 +++- src/ui/chatwin.c | 9 ++++----- src/ui/ui.h | 2 +- tests/unittests/ui/stub_ui.c | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/otr/otrlibv3.c b/src/otr/otrlibv3.c index 3fb85e0e..b12abbff 100644 --- a/src/otr/otrlibv3.c +++ b/src/otr/otrlibv3.c @@ -217,7 +217,10 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP_ABORT); if (tlv) { context->smstate->nextExpected = OTRL_SMP_EXPECT1; - ui_smp_aborted(context->username); + ProfChatWin *chatwin = wins_get_chat(context->username); + if (chatwin) { + ui_smp_aborted(chatwin); + } ui_untrust(context->username); otr_untrust(context->username); } diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index acce648e..089585fb 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -229,7 +229,9 @@ cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event, break; case OTRL_SMPEVENT_ABORT: - ui_smp_aborted(context->username); + if (chatwin) { + ui_smp_aborted(chatwin); + } ui_untrust(context->username); break; diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 35e50af1..a5b2a9be 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -140,12 +140,11 @@ ui_smp_unsuccessful_receiver(ProfChatWin *chatwin) } void -ui_smp_aborted(const char *const barejid) +ui_smp_aborted(ProfChatWin *chatwin) { - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - win_print((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "SMP session aborted."); - } + assert(chatwin != NULL); + + win_print((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "SMP session aborted."); } void diff --git a/src/ui/ui.h b/src/ui/ui.h index 140d3426..11b0f9c6 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -72,7 +72,7 @@ void ui_smp_recipient_initiated_q(ProfChatWin *chatwin, const char *question); void ui_smp_successful(const char *const barejid); void ui_smp_unsuccessful_sender(ProfChatWin *chatwin); void ui_smp_unsuccessful_receiver(ProfChatWin *chatwin); -void ui_smp_aborted(const char *const barejid); +void ui_smp_aborted(ProfChatWin *chatwin); void ui_smp_answer_success(const char *const barejid); void ui_smp_answer_failure(const char *const barejid); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 719b51e9..f2b7b01e 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -76,7 +76,7 @@ void ui_smp_recipient_initiated_q(ProfChatWin *chatwin, const char *question) {} void ui_smp_successful(const char * const barejid) {} void ui_smp_unsuccessful_sender(ProfChatWin *chatwin) {} void ui_smp_unsuccessful_receiver(ProfChatWin *chatwin) {} -void ui_smp_aborted(const char * const barejid) {} +void ui_smp_aborted(ProfChatWin *chatwin) {} void ui_smp_answer_success(const char * const barejid) {} void ui_smp_answer_failure(const char * const barejid) {} From 8bd74cefcf73772a52b40c919a1e70da90be8a33 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 26 Oct 2015 23:50:56 +0000 Subject: [PATCH 12/30] ui_smp_successful takes ProfChatWin --- src/otr/otrlibv3.c | 12 ++++++++---- src/otr/otrlibv4.c | 4 +++- src/ui/chatwin.c | 9 ++++----- src/ui/ui.h | 2 +- tests/unittests/ui/stub_ui.c | 2 +- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/otr/otrlibv3.c b/src/otr/otrlibv3.c index b12abbff..05083dea 100644 --- a/src/otr/otrlibv3.c +++ b/src/otr/otrlibv3.c @@ -177,11 +177,13 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext } 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')) { - ui_smp_successful(context->username); + if (chatwin) { + ui_smp_successful(chatwin); + } ui_trust(context->username); } else { - ProfChatWin *chatwin = wins_get_chat(context->username); if (chatwin) { ui_smp_unsuccessful_sender(chatwin); } @@ -202,11 +204,13 @@ 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; + ProfChatWin *chatwin = wins_get_chat(context->username); if (context->active_fingerprint->trust && (context->active_fingerprint->trust[0] != '\0')) { - ui_smp_successful(context->username); + if (chatwin) { + ui_smp_successful(chatwin); + } ui_trust(context->username); } else { - ProfChatWin *chatwin = wins_get_chat(context->username); if (chatwin) { ui_smp_unsuccessful_receiver(chatwin); } diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index 089585fb..29d6d57a 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -196,7 +196,9 @@ cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event, case OTRL_SMPEVENT_SUCCESS: if (context->smstate->received_question == 0) { - ui_smp_successful(context->username); + if (chatwin) { + ui_smp_successful(chatwin); + } ui_trust(context->username); } else { ui_smp_answer_success(context->username); diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index a5b2a9be..5c8dbca6 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -148,12 +148,11 @@ ui_smp_aborted(ProfChatWin *chatwin) } void -ui_smp_successful(const char *const barejid) +ui_smp_successful(ProfChatWin *chatwin) { - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - win_print((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Authentication successful."); - } + assert(chatwin != NULL); + + win_print((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Authentication successful."); } void diff --git a/src/ui/ui.h b/src/ui/ui.h index 11b0f9c6..d497ea00 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -69,7 +69,7 @@ void ui_untrust(const char *const barejid); void ui_smp_recipient_initiated(ProfChatWin *chatwin); void ui_smp_recipient_initiated_q(ProfChatWin *chatwin, const char *question); -void ui_smp_successful(const char *const barejid); +void ui_smp_successful(ProfChatWin *chatwin); void ui_smp_unsuccessful_sender(ProfChatWin *chatwin); void ui_smp_unsuccessful_receiver(ProfChatWin *chatwin); void ui_smp_aborted(ProfChatWin *chatwin); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index f2b7b01e..77c8dd17 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -73,7 +73,7 @@ void ui_untrust(const char * const barejid) {} void ui_smp_recipient_initiated(ProfChatWin *chatwin) {} void ui_smp_recipient_initiated_q(ProfChatWin *chatwin, const char *question) {} -void ui_smp_successful(const char * const barejid) {} +void ui_smp_successful(ProfChatWin *chatwin) {} void ui_smp_unsuccessful_sender(ProfChatWin *chatwin) {} void ui_smp_unsuccessful_receiver(ProfChatWin *chatwin) {} void ui_smp_aborted(ProfChatWin *chatwin) {} From 124aaa9809ee13b382f47f6f3e175bd7fdb98dc5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 27 Oct 2015 00:19:22 +0000 Subject: [PATCH 13/30] remaining otr functions take ProfChatWin --- src/command/commands.c | 4 +- src/otr/otr.c | 14 ++++- src/otr/otrlibv3.c | 40 ++++++------- src/otr/otrlibv4.c | 28 +++++---- src/ui/chatwin.c | 106 +++++++++++++++++------------------ src/ui/ui.h | 12 ++-- tests/unittests/ui/stub_ui.c | 12 ++-- 7 files changed, 106 insertions(+), 110 deletions(-) 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) From 795360f446ee11b9d8d4426a06f7f85c05ff383b Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 27 Oct 2015 00:27:02 +0000 Subject: [PATCH 14/30] Added missing include --- src/otr/otrlibv3.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/otr/otrlibv3.c b/src/otr/otrlibv3.c index 8343f19f..c32bd239 100644 --- a/src/otr/otrlibv3.c +++ b/src/otr/otrlibv3.c @@ -36,6 +36,7 @@ #include #include "ui/ui.h" +#include "window_list.h" #include "otr/otr.h" #include "otr/otrlib.h" From 8087053f496ae2bb8c68e56bdcf3dd1eaf8c2827 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 27 Oct 2015 20:40:42 +0000 Subject: [PATCH 15/30] Removed ui_ev_focus_win --- src/command/commands.c | 14 +++++++------- src/event/ui_events.c | 8 -------- src/event/ui_events.h | 1 - src/ui/core.c | 18 +++++++++++------- src/ui/inputwin.c | 6 +++--- src/window_list.c | 6 +++--- 6 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index fbbb0a8a..4a0cd782 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -913,7 +913,7 @@ cmd_win(ProfWin *window, const char *const command, gchar **args) if (!focuswin) { cons_show("Window %d does not exist.", num); } else { - ui_ev_focus_win(focuswin); + ui_switch_win(focuswin); } return TRUE; @@ -1500,7 +1500,7 @@ cmd_msg(ProfWin *window, const char *const command, gchar **args) if (!privwin) { privwin = ui_ev_new_private_win(full_jid->str); } - ui_ev_focus_win((ProfWin*)privwin); + ui_switch_win((ProfWin*)privwin); if (msg) { cl_ev_send_priv_msg(privwin, msg); @@ -1525,7 +1525,7 @@ cmd_msg(ProfWin *window, const char *const command, gchar **args) if (!chatwin) { chatwin = ui_ev_new_chat_win(barejid); } - ui_ev_focus_win((ProfWin*)chatwin); + ui_switch_win((ProfWin*)chatwin); if (msg) { cl_ev_send_msg(chatwin, msg); @@ -2746,7 +2746,7 @@ cmd_form(ProfWin *window, const char *const command, gchar **args) if (!new_current) { new_current = wins_get_console(); } - ui_ev_focus_win(new_current); + ui_switch_win(new_current); wins_close_by_num(num); } @@ -3052,7 +3052,7 @@ cmd_room(ProfWin *window, const char *const command, gchar **args) ProfMucConfWin *confwin = wins_get_muc_conf(mucwin->roomjid); if (confwin) { - ui_ev_focus_win((ProfWin*)confwin); + ui_switch_win((ProfWin*)confwin); } else { iq_request_room_config_form(mucwin->roomjid); } @@ -4668,7 +4668,7 @@ cmd_pgp(ProfWin *window, const char *const command, gchar **args) if (!chatwin) { chatwin = ui_ev_new_chat_win(barejid); } - ui_ev_focus_win((ProfWin*)chatwin); + ui_switch_win((ProfWin*)chatwin); } else { chatwin = (ProfChatWin*)window; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); @@ -4869,7 +4869,7 @@ cmd_otr(ProfWin *window, const char *const command, gchar **args) if (!chatwin) { chatwin = ui_ev_new_chat_win(barejid); } - ui_ev_focus_win((ProfWin*)chatwin); + ui_switch_win((ProfWin*)chatwin); if (chatwin->pgp_send) { ui_current_print_formatted_line('!', 0, "You must disable PGP encryption before starting an OTR session."); diff --git a/src/event/ui_events.c b/src/event/ui_events.c index a9e71bbd..cbdece4e 100644 --- a/src/event/ui_events.c +++ b/src/event/ui_events.c @@ -35,14 +35,6 @@ #include "ui/ui.h" #include "window_list.h" -void -ui_ev_focus_win(ProfWin *win) -{ - if (!wins_is_current(win)) { - ui_switch_win(win); - } -} - ProfChatWin* ui_ev_new_chat_win(const char *const barejid) { diff --git a/src/event/ui_events.h b/src/event/ui_events.h index 279d1e2a..b42c6f01 100644 --- a/src/event/ui_events.h +++ b/src/event/ui_events.h @@ -35,7 +35,6 @@ #ifndef UI_EVENTS_H #define UI_EVENTS_H -void ui_ev_focus_win(ProfWin *win); ProfChatWin* ui_ev_new_chat_win(const char *const barejid); ProfPrivateWin* ui_ev_new_private_win(const char *const fulljid); diff --git a/src/ui/core.c b/src/ui/core.c index a804c53c..0b941b70 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -756,6 +756,10 @@ ui_switch_win(ProfWin *window) { assert(window != NULL); + if (wins_is_current(window)) { + return; + } + ProfWin *old_current = wins_get_current(); if (old_current->type == WIN_MUC_CONFIG) { ProfMucConfWin *confwin = (ProfMucConfWin*)old_current; @@ -927,7 +931,7 @@ void ui_create_xmlconsole_win(void) { ProfWin *window = wins_new_xmlconsole(); - ui_ev_focus_win(window); + ui_switch_win(window); } void @@ -935,7 +939,7 @@ ui_open_xmlconsole_win(void) { ProfXMLWin *xmlwin = wins_get_xmlconsole(); if (xmlwin) { - ui_ev_focus_win((ProfWin*)xmlwin); + ui_switch_win((ProfWin*)xmlwin); } } @@ -969,7 +973,7 @@ ui_room_join(const char *const roomjid, gboolean focus) if (focus) { - ui_ev_focus_win(window); + ui_switch_win(window); } else { int num = wins_get_num(window); status_bar_active(num); @@ -983,7 +987,7 @@ void ui_switch_to_room(const char *const roomjid) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); - ui_ev_focus_win(window); + ui_switch_win(window); } void @@ -2162,7 +2166,7 @@ ui_handle_room_configuration(const char *const roomjid, DataForm *form) ProfMucConfWin *confwin = (ProfMucConfWin*)window; assert(confwin->memcheck == PROFCONFWIN_MEMCHECK); - ui_ev_focus_win(window); + ui_switch_win(window); ui_show_form(confwin); win_print(window, '-', 0, NULL, 0, 0, "", ""); @@ -2214,11 +2218,11 @@ ui_handle_room_config_submit_result(const char *const roomjid) } if (muc_window) { - ui_ev_focus_win((ProfWin*)muc_window); + ui_switch_win((ProfWin*)muc_window); win_print(muc_window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Room configuration successful"); } else { ProfWin *console = wins_get_console(); - ui_ev_focus_win(console); + ui_switch_win(console); cons_show("Room configuration successful: %s", roomjid); } } else { diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 78cbfab3..21f945f3 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -466,7 +466,7 @@ _go_to_win(int i) { ProfWin *window = wins_get_by_num(i); if (window) { - ui_ev_focus_win(window); + ui_switch_win(window); } } @@ -545,7 +545,7 @@ _inp_rl_altleft_handler(int count, int key) { ProfWin *window = wins_get_previous(); if (window) { - ui_ev_focus_win(window); + ui_switch_win(window); } return 0; } @@ -555,7 +555,7 @@ _inp_rl_altright_handler(int count, int key) { ProfWin *window = wins_get_next(); if (window) { - ui_ev_focus_win(window); + ui_switch_win(window); } return 0; } diff --git a/src/window_list.c b/src/window_list.c index c026e875..19c405b4 100644 --- a/src/window_list.c +++ b/src/window_list.c @@ -537,7 +537,7 @@ wins_swap(int source_win, int target_win) } if (wins_get_current_num() == source_win) { wins_set_current_by_num(target_win); - ui_ev_focus_win(console); + ui_switch_win(console); } return TRUE; @@ -558,7 +558,7 @@ wins_swap(int source_win, int target_win) status_bar_active(source_win); } if ((wins_get_current_num() == source_win) || (wins_get_current_num() == target_win)) { - ui_ev_focus_win(console); + ui_switch_win(console); } return TRUE; } @@ -618,7 +618,7 @@ wins_tidy(void) windows = new_windows; current = 1; ProfWin *console = wins_get_console(); - ui_ev_focus_win(console); + ui_switch_win(console); g_list_free(keys); return TRUE; } else { From 61bcb59ee9a131c4adb413409c0d3077f6677027 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 27 Oct 2015 20:45:07 +0000 Subject: [PATCH 16/30] Removed ui_ev_new_chat_win --- src/command/commands.c | 6 +++--- src/event/ui_events.c | 6 ------ src/event/ui_events.h | 1 - 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 4a0cd782..cb68b6b9 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1523,7 +1523,7 @@ cmd_msg(ProfWin *window, const char *const command, gchar **args) ProfChatWin *chatwin = wins_get_chat(barejid); if (!chatwin) { - chatwin = ui_ev_new_chat_win(barejid); + chatwin = ui_new_chat_win(barejid); } ui_switch_win((ProfWin*)chatwin); @@ -4666,7 +4666,7 @@ cmd_pgp(ProfWin *window, const char *const command, gchar **args) chatwin = wins_get_chat(barejid); if (!chatwin) { - chatwin = ui_ev_new_chat_win(barejid); + chatwin = ui_new_chat_win(barejid); } ui_switch_win((ProfWin*)chatwin); } else { @@ -4867,7 +4867,7 @@ cmd_otr(ProfWin *window, const char *const command, gchar **args) ProfChatWin *chatwin = wins_get_chat(barejid); if (!chatwin) { - chatwin = ui_ev_new_chat_win(barejid); + chatwin = ui_new_chat_win(barejid); } ui_switch_win((ProfWin*)chatwin); diff --git a/src/event/ui_events.c b/src/event/ui_events.c index cbdece4e..63b7d244 100644 --- a/src/event/ui_events.c +++ b/src/event/ui_events.c @@ -35,12 +35,6 @@ #include "ui/ui.h" #include "window_list.h" -ProfChatWin* -ui_ev_new_chat_win(const char *const barejid) -{ - return ui_new_chat_win(barejid); -} - ProfPrivateWin* ui_ev_new_private_win(const char *const fulljid) { diff --git a/src/event/ui_events.h b/src/event/ui_events.h index b42c6f01..97fd916a 100644 --- a/src/event/ui_events.h +++ b/src/event/ui_events.h @@ -35,7 +35,6 @@ #ifndef UI_EVENTS_H #define UI_EVENTS_H -ProfChatWin* ui_ev_new_chat_win(const char *const barejid); ProfPrivateWin* ui_ev_new_private_win(const char *const fulljid); #endif From 0fd616167ee86562077327695f5f32974e9f5578 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 27 Oct 2015 20:49:06 +0000 Subject: [PATCH 17/30] Removed ui_events module --- Makefile.am | 2 -- src/command/commands.c | 3 +-- src/event/ui_events.c | 42 ------------------------------------------ src/event/ui_events.h | 40 ---------------------------------------- src/ui/core.c | 1 - src/ui/inputwin.c | 1 - src/window_list.c | 1 - 7 files changed, 1 insertion(+), 89 deletions(-) delete mode 100644 src/event/ui_events.c delete mode 100644 src/event/ui_events.h diff --git a/Makefile.am b/Makefile.am index 6b5a3928..a00ff6d3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -15,7 +15,6 @@ core_sources = \ src/xmpp/form.c src/xmpp/form.h \ src/event/server_events.c src/event/server_events.h \ src/event/client_events.c src/event/client_events.h \ - src/event/ui_events.c src/event/ui_events.h \ src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/core.c \ src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \ src/ui/titlebar.h src/ui/statusbar.h src/ui/inputwin.h \ @@ -67,7 +66,6 @@ unittest_sources = \ src/window_list.c src/window_list.h \ src/event/server_events.c src/event/server_events.h \ src/event/client_events.c src/event/client_events.h \ - src/event/ui_events.c src/event/ui_events.h \ tests/unittests/xmpp/stub_xmpp.c \ tests/unittests/ui/stub_ui.c \ tests/unittests/log/stub_log.c \ diff --git a/src/command/commands.c b/src/command/commands.c index cb68b6b9..c7cf9340 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -70,7 +70,6 @@ #include "ui/ui.h" #include "window_list.h" #include "event/client_events.h" -#include "event/ui_events.h" static void _update_presence(const resource_presence_t presence, const char *const show, gchar **args); @@ -1498,7 +1497,7 @@ cmd_msg(ProfWin *window, const char *const command, gchar **args) ProfPrivateWin *privwin = wins_get_private(full_jid->str); if (!privwin) { - privwin = ui_ev_new_private_win(full_jid->str); + privwin = ui_new_private_win(full_jid->str); } ui_switch_win((ProfWin*)privwin); diff --git a/src/event/ui_events.c b/src/event/ui_events.c deleted file mode 100644 index 63b7d244..00000000 --- a/src/event/ui_events.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * ui_events.c - * - * Copyright (C) 2012 - 2015 James Booth - * - * This file is part of Profanity. - * - * Profanity is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Profanity is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Profanity. If not, see . - * - * In addition, as a special exception, the copyright holders give permission to - * link the code of portions of this program with the OpenSSL library under - * certain conditions as described in each individual source file, and - * distribute linked combinations including the two. - * - * You must obey the GNU General Public License in all respects for all of the - * code used other than OpenSSL. If you modify file(s) with this exception, you - * may extend this exception to your version of the file(s), but you are not - * obligated to do so. If you do not wish to do so, delete this exception - * statement from your version. If you delete this exception statement from all - * source files in the program, then also delete it here. - * - */ - -#include "ui/ui.h" -#include "window_list.h" - -ProfPrivateWin* -ui_ev_new_private_win(const char *const fulljid) -{ - return ui_new_private_win(fulljid); -} diff --git a/src/event/ui_events.h b/src/event/ui_events.h deleted file mode 100644 index 97fd916a..00000000 --- a/src/event/ui_events.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * ui_events.h - * - * Copyright (C) 2012 - 2015 James Booth - * - * This file is part of Profanity. - * - * Profanity is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Profanity is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Profanity. If not, see . - * - * In addition, as a special exception, the copyright holders give permission to - * link the code of portions of this program with the OpenSSL library under - * certain conditions as described in each individual source file, and - * distribute linked combinations including the two. - * - * You must obey the GNU General Public License in all respects for all of the - * code used other than OpenSSL. If you modify file(s) with this exception, you - * may extend this exception to your version of the file(s), but you are not - * obligated to do so. If you do not wish to do so, delete this exception - * statement from your version. If you delete this exception statement from all - * source files in the program, then also delete it here. - * - */ - -#ifndef UI_EVENTS_H -#define UI_EVENTS_H - -ProfPrivateWin* ui_ev_new_private_win(const char *const fulljid); - -#endif diff --git a/src/ui/core.c b/src/ui/core.c index 0b941b70..ae446969 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -74,7 +74,6 @@ #include "ui/window.h" #include "window_list.h" #include "xmpp/xmpp.h" -#include "event/ui_events.h" static char *win_title; diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 21f945f3..038e1dda 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -64,7 +64,6 @@ #include "ui/inputwin.h" #include "ui/window.h" #include "window_list.h" -#include "event/ui_events.h" #include "xmpp/xmpp.h" static WINDOW *inp_win; diff --git a/src/window_list.c b/src/window_list.c index 19c405b4..6e3f85b1 100644 --- a/src/window_list.c +++ b/src/window_list.c @@ -46,7 +46,6 @@ #include "ui/ui.h" #include "ui/statusbar.h" #include "window_list.h" -#include "event/ui_events.h" static GHashTable *windows; static int current; From 40dcd597270c375ff2d0abc36554f6436f406a03 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 27 Oct 2015 21:23:56 +0000 Subject: [PATCH 18/30] Renamed chatwin OTR functions --- src/command/commands.c | 10 +++++----- src/event/server_events.c | 2 +- src/otr/otr.c | 10 +++++----- src/otr/otrlibv3.c | 28 ++++++++++++++-------------- src/otr/otrlibv4.c | 22 +++++++++++----------- src/ui/chatwin.c | 30 +++++++++++++++--------------- src/ui/ui.h | 30 +++++++++++++++--------------- tests/unittests/ui/stub_ui.c | 30 +++++++++++++++--------------- 8 files changed, 81 insertions(+), 81 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index c7cf9340..5ff92321 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1531,7 +1531,7 @@ cmd_msg(ProfWin *window, const char *const command, gchar **args) } else { #ifdef HAVE_LIBOTR if (otr_is_secure(barejid)) { - ui_gone_secure(chatwin, otr_is_trusted(barejid)); + chatwin_otr_secured(chatwin, otr_is_trusted(barejid)); } #endif } @@ -4892,7 +4892,7 @@ cmd_otr(ProfWin *window, const char *const command, gchar **args) return TRUE; } - ui_gone_secure(chatwin, otr_is_trusted(barejid)); + chatwin_otr_secured(chatwin, otr_is_trusted(barejid)); return TRUE; // no recipient, use current chat @@ -4938,7 +4938,7 @@ cmd_otr(ProfWin *window, const char *const command, gchar **args) return TRUE; } - ui_gone_insecure(chatwin); + chatwin_otr_unsecured(chatwin); otr_end_session(chatwin->barejid); return TRUE; @@ -4955,7 +4955,7 @@ cmd_otr(ProfWin *window, const char *const command, gchar **args) return TRUE; } - ui_trust(chatwin); + chatwin_otr_trust(chatwin); otr_trust(chatwin->barejid); return TRUE; @@ -4972,7 +4972,7 @@ cmd_otr(ProfWin *window, const char *const command, gchar **args) return TRUE; } - ui_untrust(chatwin); + chatwin_otr_untrust(chatwin); otr_untrust(chatwin->barejid); return TRUE; diff --git a/src/event/server_events.c b/src/event/server_events.c index 1f8d53cc..026b5147 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -315,7 +315,7 @@ sv_ev_message_receipt(char *barejid, char *id) if (!chatwin) return; - ui_message_receipt(chatwin, id); + chatwin_receipt_received(chatwin, id); } void diff --git a/src/otr/otr.c b/src/otr/otr.c index bdecf22d..c016501c 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -149,7 +149,7 @@ cb_gone_secure(void *opdata, ConnContext *context) chatwin = (ProfChatWin*) wins_new_chat(context->username); } - ui_gone_secure(chatwin, otr_is_trusted(context->username)); + chatwin_otr_secured(chatwin, otr_is_trusted(context->username)); } char* @@ -577,13 +577,13 @@ otr_smp_secret(const char *const recipient, const char *secret) if (g_hash_table_contains(smp_initiators, recipient)) { otrl_message_respond_smp(user_state, &ops, NULL, context, (const unsigned char*)secret, strlen(secret)); if (chatwin) { - ui_otr_authenticating(chatwin); + chatwin_otr_smp_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)); if (chatwin) { - ui_otr_authetication_waiting(chatwin); + chatwin_otr_smp_authenticaton_wait(chatwin); } } } @@ -604,7 +604,7 @@ 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)); ProfChatWin *chatwin = wins_get_chat(recipient); if (chatwin) { - ui_otr_authetication_waiting(chatwin); + chatwin_otr_smp_authenticaton_wait(chatwin); } } @@ -749,7 +749,7 @@ otr_decrypt_message(const char *const from, const char *const message, gboolean otrl_context_force_plaintext(context); ProfChatWin *chatwin = wins_get_chat(from); if (chatwin) { - ui_gone_insecure(chatwin); + chatwin_otr_unsecured(chatwin); } } } diff --git a/src/otr/otrlibv3.c b/src/otr/otrlibv3.c index c32bd239..8fa89a26 100644 --- a/src/otr/otrlibv3.c +++ b/src/otr/otrlibv3.c @@ -143,7 +143,7 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext } else { ProfChatWin *chatwin = wins_get_chat(context->username); if (chatwin) { - ui_smp_recipient_initiated(chatwin); + chatwin_otr_smp_init(chatwin); } g_hash_table_insert(smp_initiators, strdup(context->username), strdup(context->username)); } @@ -158,7 +158,7 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext char *question = (char *)tlv->data; char *eoq = memchr(question, '\0', tlv->len); if (eoq) { - ui_smp_recipient_initiated_q(chatwin, question); + chatwin_otr_smp_init_q(chatwin, question); } } } @@ -181,17 +181,17 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext 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(chatwin); + chatwin_otr_smp_success(chatwin); + chatwin_otr_trust(chatwin); } else { - ui_smp_unsuccessful_sender(chatwin); - ui_untrust(chatwin); + chatwin_otr_smp_sender_failed(chatwin); + chatwin_otr_untrust(chatwin); } } else { if (context->smstate->sm_prog_state == OTRL_SMP_PROG_SUCCEEDED) { - ui_smp_answer_success(chatwin); + chatwin_otr_smp_answer_success(chatwin); } else { - ui_smp_answer_failure(chatwin); + chatwin_otr_smp_answer_failure(chatwin); } } } @@ -206,11 +206,11 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext ProfChatWin *chatwin = wins_get_chat(context->username); if (chatwin) { if (context->active_fingerprint->trust && (context->active_fingerprint->trust[0] != '\0')) { - ui_smp_successful(chatwin); - ui_trust(chatwin); + chatwin_otr_smp_success(chatwin); + chatwin_otr_trust(chatwin); } else { - ui_smp_unsuccessful_receiver(chatwin); - ui_untrust(chatwin); + chatwin_otr_smp_receiver_failed(chatwin); + chatwin_otr_untrust(chatwin); } } } @@ -220,8 +220,8 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext context->smstate->nextExpected = OTRL_SMP_EXPECT1; ProfChatWin *chatwin = wins_get_chat(context->username); if (chatwin) { - ui_smp_aborted(chatwin); - ui_untrust(chatwin); + chatwin_otr_smp_aborted(chatwin); + chatwin_otr_untrust(chatwin); } otr_untrust(context->username); } diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index a82a98a8..cdfef5dd 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -183,24 +183,24 @@ cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event, { case OTRL_SMPEVENT_ASK_FOR_SECRET: if (chatwin) { - ui_smp_recipient_initiated(chatwin); + chatwin_otr_smp_init(chatwin); } g_hash_table_insert(smp_initiators, strdup(context->username), strdup(context->username)); break; case OTRL_SMPEVENT_ASK_FOR_ANSWER: if (chatwin) { - ui_smp_recipient_initiated_q(chatwin, question); + chatwin_otr_smp_init_q(chatwin, question); } break; case OTRL_SMPEVENT_SUCCESS: if (chatwin) { if (context->smstate->received_question == 0) { - ui_smp_successful(chatwin); - ui_trust(chatwin); + chatwin_otr_smp_success(chatwin); + chatwin_otr_trust(chatwin); } else { - ui_smp_answer_success(chatwin); + chatwin_otr_smp_answer_success(chatwin); } } break; @@ -209,13 +209,13 @@ cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event, if (chatwin) { if (context->smstate->received_question == 0) { if (nextMsg == OTRL_SMP_EXPECT3) { - ui_smp_unsuccessful_sender(chatwin); + chatwin_otr_smp_sender_failed(chatwin); } else if (nextMsg == OTRL_SMP_EXPECT4) { - ui_smp_unsuccessful_receiver(chatwin); + chatwin_otr_smp_receiver_failed(chatwin); } - ui_untrust(chatwin); + chatwin_otr_untrust(chatwin); } else { - ui_smp_answer_failure(chatwin); + chatwin_otr_smp_answer_failure(chatwin); } } break; @@ -230,8 +230,8 @@ cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event, case OTRL_SMPEVENT_ABORT: if (chatwin) { - ui_smp_aborted(chatwin); - ui_untrust(chatwin); + chatwin_otr_smp_aborted(chatwin); + chatwin_otr_untrust(chatwin); } break; diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 9d61a62b..004a24bd 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -48,7 +48,7 @@ static void _win_show_history(ProfChatWin *chatwin, const char *const contact); void -ui_message_receipt(ProfChatWin *chatwin, const char *const id) +chatwin_receipt_received(ProfChatWin *chatwin, const char *const id) { assert(chatwin != NULL); @@ -57,7 +57,7 @@ ui_message_receipt(ProfChatWin *chatwin, const char *const id) } void -ui_gone_secure(ProfChatWin *chatwin, gboolean trusted) +chatwin_otr_secured(ProfChatWin *chatwin, gboolean trusted) { assert(chatwin != NULL); @@ -87,7 +87,7 @@ ui_gone_secure(ProfChatWin *chatwin, gboolean trusted) } void -ui_gone_insecure(ProfChatWin *chatwin) +chatwin_otr_unsecured(ProfChatWin *chatwin) { assert(chatwin != NULL); @@ -102,7 +102,7 @@ ui_gone_insecure(ProfChatWin *chatwin) } void -ui_smp_recipient_initiated(ProfChatWin *chatwin) +chatwin_otr_smp_init(ProfChatWin *chatwin) { assert(chatwin != NULL); @@ -111,7 +111,7 @@ ui_smp_recipient_initiated(ProfChatWin *chatwin) } void -ui_smp_recipient_initiated_q(ProfChatWin *chatwin, const char *question) +chatwin_otr_smp_init_q(ProfChatWin *chatwin, const char *question) { assert(chatwin != NULL); @@ -122,7 +122,7 @@ ui_smp_recipient_initiated_q(ProfChatWin *chatwin, const char *question) } void -ui_smp_unsuccessful_sender(ProfChatWin *chatwin) +chatwin_otr_smp_sender_failed(ProfChatWin *chatwin) { assert(chatwin != NULL); @@ -131,7 +131,7 @@ ui_smp_unsuccessful_sender(ProfChatWin *chatwin) } void -ui_smp_unsuccessful_receiver(ProfChatWin *chatwin) +chatwin_otr_smp_receiver_failed(ProfChatWin *chatwin) { assert(chatwin != NULL); @@ -140,7 +140,7 @@ ui_smp_unsuccessful_receiver(ProfChatWin *chatwin) } void -ui_smp_aborted(ProfChatWin *chatwin) +chatwin_otr_smp_aborted(ProfChatWin *chatwin) { assert(chatwin != NULL); @@ -148,7 +148,7 @@ ui_smp_aborted(ProfChatWin *chatwin) } void -ui_smp_successful(ProfChatWin *chatwin) +chatwin_otr_smp_success(ProfChatWin *chatwin) { assert(chatwin != NULL); @@ -156,7 +156,7 @@ ui_smp_successful(ProfChatWin *chatwin) } void -ui_smp_answer_success(ProfChatWin *chatwin) +chatwin_otr_smp_answer_success(ProfChatWin *chatwin) { assert(chatwin != NULL); @@ -164,7 +164,7 @@ ui_smp_answer_success(ProfChatWin *chatwin) } void -ui_smp_answer_failure(ProfChatWin *chatwin) +chatwin_otr_smp_answer_failure(ProfChatWin *chatwin) { assert(chatwin != NULL); @@ -172,7 +172,7 @@ ui_smp_answer_failure(ProfChatWin *chatwin) } void -ui_otr_authenticating(ProfChatWin *chatwin) +chatwin_otr_smp_authenticating(ProfChatWin *chatwin) { assert(chatwin != NULL); @@ -180,7 +180,7 @@ ui_otr_authenticating(ProfChatWin *chatwin) } void -ui_otr_authetication_waiting(ProfChatWin *chatwin) +chatwin_otr_smp_authenticaton_wait(ProfChatWin *chatwin) { assert(chatwin != NULL); @@ -188,7 +188,7 @@ ui_otr_authetication_waiting(ProfChatWin *chatwin) } void -ui_trust(ProfChatWin *chatwin) +chatwin_otr_trust(ProfChatWin *chatwin) { assert(chatwin != NULL); @@ -203,7 +203,7 @@ ui_trust(ProfChatWin *chatwin) } void -ui_untrust(ProfChatWin *chatwin) +chatwin_otr_untrust(ProfChatWin *chatwin) { assert(chatwin != NULL); diff --git a/src/ui/ui.h b/src/ui/ui.h index 5d92797d..eed77ba7 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -62,23 +62,23 @@ GSList* ui_get_chat_recipients(void); void ui_switch_win(ProfWin *window); void ui_sigwinch_handler(int sig); -void ui_gone_secure(ProfChatWin *chatwin, gboolean trusted); -void ui_gone_insecure(ProfChatWin *chatwin); -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); +void chatwin_otr_secured(ProfChatWin *chatwin, gboolean trusted); +void chatwin_otr_unsecured(ProfChatWin *chatwin); +void chatwin_otr_trust(ProfChatWin *chatwin); +void chatwin_otr_untrust(ProfChatWin *chatwin); +void chatwin_otr_smp_init(ProfChatWin *chatwin); +void chatwin_otr_smp_init_q(ProfChatWin *chatwin, const char *question); -void ui_smp_successful(ProfChatWin *chatwin); -void ui_smp_unsuccessful_sender(ProfChatWin *chatwin); -void ui_smp_unsuccessful_receiver(ProfChatWin *chatwin); -void ui_smp_aborted(ProfChatWin *chatwin); +void chatwin_otr_smp_success(ProfChatWin *chatwin); +void chatwin_otr_smp_sender_failed(ProfChatWin *chatwin); +void chatwin_otr_smp_receiver_failed(ProfChatWin *chatwin); +void chatwin_otr_smp_aborted(ProfChatWin *chatwin); -void ui_smp_answer_success(ProfChatWin *chatwin); -void ui_smp_answer_failure(ProfChatWin *chatwin); +void chatwin_otr_smp_answer_success(ProfChatWin *chatwin); +void chatwin_otr_smp_answer_failure(ProfChatWin *chatwin); -void ui_otr_authenticating(ProfChatWin *chatwin); -void ui_otr_authetication_waiting(ProfChatWin *chatwin); +void chatwin_otr_smp_authenticating(ProfChatWin *chatwin); +void chatwin_otr_smp_authenticaton_wait(ProfChatWin *chatwin); void ui_handle_otr_error(const char *const barejid, const char *const message); @@ -112,7 +112,7 @@ void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activi void ui_contact_typing(const char *const barejid, const char *const resource); void ui_incoming_msg(ProfChatWin *chatwin, const char *const resource, const char *const message, GDateTime *timestamp, gboolean win_created, prof_enc_t enc_mode); void ui_incoming_private_msg(const char *const fulljid, const char *const message, GDateTime *timestamp); -void ui_message_receipt(ProfChatWin *chatwin, const char *const id); +void chatwin_receipt_received(ProfChatWin *chatwin, const char *const id); void ui_disconnected(void); void ui_recipient_gone(const char *const barejid, const char *const resource); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index f6f4cb78..de36676a 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -66,23 +66,23 @@ GSList* ui_get_chat_recipients(void) void ui_switch_win(ProfWin *win) {} -void ui_gone_secure(ProfChatWin *chatwin, gboolean trusted) {} -void ui_gone_insecure(ProfChatWin *chatwin) {} -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) {} +void chatwin_otr_secured(ProfChatWin *chatwin, gboolean trusted) {} +void chatwin_otr_unsecured(ProfChatWin *chatwin) {} +void chatwin_otr_trust(ProfChatWin *chatwin) {} +void chatwin_otr_untrust(ProfChatWin *chatwin) {} +void chatwin_otr_smp_init(ProfChatWin *chatwin) {} +void chatwin_otr_smp_init_q(ProfChatWin *chatwin, const char *question) {} -void ui_smp_successful(ProfChatWin *chatwin) {} -void ui_smp_unsuccessful_sender(ProfChatWin *chatwin) {} -void ui_smp_unsuccessful_receiver(ProfChatWin *chatwin) {} -void ui_smp_aborted(ProfChatWin *chatwin) {} +void chatwin_otr_smp_success(ProfChatWin *chatwin) {} +void chatwin_otr_smp_sender_failed(ProfChatWin *chatwin) {} +void chatwin_otr_smp_receiver_failed(ProfChatWin *chatwin) {} +void chatwin_otr_smp_aborted(ProfChatWin *chatwin) {} -void ui_smp_answer_success(ProfChatWin *chatwin) {} -void ui_smp_answer_failure(ProfChatWin *chatwin) {} +void chatwin_otr_smp_answer_success(ProfChatWin *chatwin) {} +void chatwin_otr_smp_answer_failure(ProfChatWin *chatwin) {} -void ui_otr_authenticating(ProfChatWin *chatwin) {} -void ui_otr_authetication_waiting(ProfChatWin *chatwin) {} +void chatwin_otr_smp_authenticating(ProfChatWin *chatwin) {} +void chatwin_otr_smp_authenticaton_wait(ProfChatWin *chatwin) {} void ui_sigwinch_handler(int sig) {} unsigned long ui_get_idle_time(void) @@ -185,7 +185,7 @@ void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activi void ui_contact_typing(const char * const barejid, const char * const resource) {} void ui_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char * const message, GDateTime *timestamp, gboolean win_created, prof_enc_t enc_mode) {} -void ui_message_receipt(ProfChatWin *chatwin, const char * const id) {} +void chatwin_receipt_received(ProfChatWin *chatwin, const char * const id) {} void ui_incoming_private_msg(const char * const fulljid, const char * const message, GDateTime *timestamp) {} From ff9abecd509f3a1d1f857a736dda28da9e94ad69 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 27 Oct 2015 22:25:02 +0000 Subject: [PATCH 19/30] Combined chatwin OTR SMP functions --- src/otr/otr.c | 6 +- src/otr/otr.h | 15 ++++- src/otr/otrlibv3.c | 18 +++--- src/otr/otrlibv4.c | 16 ++--- src/ui/chatwin.c | 122 ++++++++++++----------------------- src/ui/ui.h | 16 +---- src/ui/window.c | 12 ++++ tests/unittests/ui/stub_ui.c | 14 +--- 8 files changed, 93 insertions(+), 126 deletions(-) diff --git a/src/otr/otr.c b/src/otr/otr.c index c016501c..facfb4f7 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -577,13 +577,13 @@ otr_smp_secret(const char *const recipient, const char *secret) if (g_hash_table_contains(smp_initiators, recipient)) { otrl_message_respond_smp(user_state, &ops, NULL, context, (const unsigned char*)secret, strlen(secret)); if (chatwin) { - chatwin_otr_smp_authenticating(chatwin); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_AUTH, NULL); } g_hash_table_remove(smp_initiators, context->username); } else { otrl_message_initiate_smp(user_state, &ops, NULL, context, (const unsigned char*)secret, strlen(secret)); if (chatwin) { - chatwin_otr_smp_authenticaton_wait(chatwin); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_AUTH_WAIT, NULL); } } } @@ -604,7 +604,7 @@ 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)); ProfChatWin *chatwin = wins_get_chat(recipient); if (chatwin) { - chatwin_otr_smp_authenticaton_wait(chatwin); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_AUTH_WAIT, NULL); } } diff --git a/src/otr/otr.h b/src/otr/otr.h index f966239e..284b69b9 100644 --- a/src/otr/otr.h +++ b/src/otr/otr.h @@ -39,7 +39,7 @@ #include #include "config/accounts.h" -#include "ui/ui.h" +#include "ui/win_types.h" typedef enum { PROF_OTRPOLICY_MANUAL, @@ -47,6 +47,19 @@ typedef enum { PROF_OTRPOLICY_ALWAYS } prof_otrpolicy_t; +typedef enum { + PROF_OTR_SMP_INIT, + PROF_OTR_SMP_INIT_Q, + PROF_OTR_SMP_SENDER_FAIL, + PROF_OTR_SMP_RECEIVER_FAIL, + PROF_OTR_SMP_ABORT, + PROF_OTR_SMP_SUCCESS, + PROF_OTR_SMP_SUCCESS_Q, + PROF_OTR_SMP_FAIL_Q, + PROF_OTR_SMP_AUTH, + PROF_OTR_SMP_AUTH_WAIT +} prof_otr_smp_event_t; + OtrlUserState otr_userstate(void); OtrlMessageAppOps* otr_messageops(void); GHashTable* otr_smpinitators(void); diff --git a/src/otr/otrlibv3.c b/src/otr/otrlibv3.c index 8fa89a26..8af2b896 100644 --- a/src/otr/otrlibv3.c +++ b/src/otr/otrlibv3.c @@ -143,7 +143,7 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext } else { ProfChatWin *chatwin = wins_get_chat(context->username); if (chatwin) { - chatwin_otr_smp_init(chatwin); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_INIT. NULL); } g_hash_table_insert(smp_initiators, strdup(context->username), strdup(context->username)); } @@ -158,7 +158,7 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext char *question = (char *)tlv->data; char *eoq = memchr(question, '\0', tlv->len); if (eoq) { - chatwin_otr_smp_init_q(chatwin, question); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_INIT_Q, question); } } } @@ -181,17 +181,17 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext if (chatwin) { if (context->smstate->received_question == 0) { if (context->active_fingerprint->trust && (context->active_fingerprint->trust[0] != '\0')) { - chatwin_otr_smp_success(chatwin); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SUCCESS, NULL); chatwin_otr_trust(chatwin); } else { - chatwin_otr_smp_sender_failed(chatwin); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SENDER_FAIL, NULL); chatwin_otr_untrust(chatwin); } } else { if (context->smstate->sm_prog_state == OTRL_SMP_PROG_SUCCEEDED) { - chatwin_otr_smp_answer_success(chatwin); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SUCCESS_Q, NULL); } else { - chatwin_otr_smp_answer_failure(chatwin); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_FAIL_Q, NULL); } } } @@ -206,10 +206,10 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext ProfChatWin *chatwin = wins_get_chat(context->username); if (chatwin) { if (context->active_fingerprint->trust && (context->active_fingerprint->trust[0] != '\0')) { - chatwin_otr_smp_success(chatwin); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SUCCESS, NULL); chatwin_otr_trust(chatwin); } else { - chatwin_otr_smp_receiver_failed(chatwin); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_RECEIVER_FAIL, NULL); chatwin_otr_untrust(chatwin); } } @@ -220,7 +220,7 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext context->smstate->nextExpected = OTRL_SMP_EXPECT1; ProfChatWin *chatwin = wins_get_chat(context->username); if (chatwin) { - chatwin_otr_smp_aborted(chatwin); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_ABORT, NULL); chatwin_otr_untrust(chatwin); } otr_untrust(context->username); diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index cdfef5dd..548d2232 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -183,24 +183,24 @@ cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event, { case OTRL_SMPEVENT_ASK_FOR_SECRET: if (chatwin) { - chatwin_otr_smp_init(chatwin); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_INIT, NULL); } g_hash_table_insert(smp_initiators, strdup(context->username), strdup(context->username)); break; case OTRL_SMPEVENT_ASK_FOR_ANSWER: if (chatwin) { - chatwin_otr_smp_init_q(chatwin, question); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_INIT_Q, question); } break; case OTRL_SMPEVENT_SUCCESS: if (chatwin) { if (context->smstate->received_question == 0) { - chatwin_otr_smp_success(chatwin); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SUCCESS, NULL); chatwin_otr_trust(chatwin); } else { - chatwin_otr_smp_answer_success(chatwin); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SUCCESS_Q, NULL); } } break; @@ -209,13 +209,13 @@ cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event, if (chatwin) { if (context->smstate->received_question == 0) { if (nextMsg == OTRL_SMP_EXPECT3) { - chatwin_otr_smp_sender_failed(chatwin); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SENDER_FAIL, NULL); } else if (nextMsg == OTRL_SMP_EXPECT4) { - chatwin_otr_smp_receiver_failed(chatwin); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_RECEIVER_FAIL, NULL); } chatwin_otr_untrust(chatwin); } else { - chatwin_otr_smp_answer_failure(chatwin); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_FAIL_Q, NULL); } } break; @@ -230,7 +230,7 @@ cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event, case OTRL_SMPEVENT_ABORT: if (chatwin) { - chatwin_otr_smp_aborted(chatwin); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_ABORT, NULL); chatwin_otr_untrust(chatwin); } break; diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 004a24bd..7921e559 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -102,89 +102,51 @@ chatwin_otr_unsecured(ProfChatWin *chatwin) } void -chatwin_otr_smp_init(ProfChatWin *chatwin) +chatwin_otr_smp_event(ProfChatWin *chatwin, prof_otr_smp_event_t event, void *data) { assert(chatwin != NULL); - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", - "%s wants to authenticate your identity, use '/otr secret '.", chatwin->barejid); -} - -void -chatwin_otr_smp_init_q(ProfChatWin *chatwin, const char *question) -{ - assert(chatwin != NULL); - - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", - "%s wants to authenticate your identity with the following question:", chatwin->barejid); - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", " %s", question); - win_print((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "use '/otr answer '."); -} - -void -chatwin_otr_smp_sender_failed(ProfChatWin *chatwin) -{ - assert(chatwin != NULL); - - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", - "Authentication failed, the secret you entered does not match the secret entered by %s.", chatwin->barejid); -} - -void -chatwin_otr_smp_receiver_failed(ProfChatWin *chatwin) -{ - assert(chatwin != NULL); - - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", - "Authentication failed, the secret entered by %s does not match yours.", chatwin->barejid); -} - -void -chatwin_otr_smp_aborted(ProfChatWin *chatwin) -{ - assert(chatwin != NULL); - - win_print((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "SMP session aborted."); -} - -void -chatwin_otr_smp_success(ProfChatWin *chatwin) -{ - assert(chatwin != NULL); - - win_print((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Authentication successful."); -} - -void -chatwin_otr_smp_answer_success(ProfChatWin *chatwin) -{ - assert(chatwin != NULL); - - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s successfully authenticated you.", chatwin->barejid); -} - -void -chatwin_otr_smp_answer_failure(ProfChatWin *chatwin) -{ - assert(chatwin != NULL); - - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s failed to authenticate you.", chatwin->barejid); -} - -void -chatwin_otr_smp_authenticating(ProfChatWin *chatwin) -{ - assert(chatwin != NULL); - - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Authenticating %s...", chatwin->barejid); -} - -void -chatwin_otr_smp_authenticaton_wait(ProfChatWin *chatwin) -{ - assert(chatwin != NULL); - - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Awaiting authentication from %s...", chatwin->barejid); + switch (event) { + case PROF_OTR_SMP_INIT: + win_vprintln_ch((ProfWin*)chatwin, '!', + "%s wants to authenticate your identity, use '/otr secret '.", chatwin->barejid); + break; + case PROF_OTR_SMP_INIT_Q: + win_vprintln_ch((ProfWin*)chatwin, '!', + "%s wants to authenticate your identity with the following question:", chatwin->barejid); + win_vprintln_ch((ProfWin*)chatwin, '!', " %s", (char*)data); + win_vprintln_ch((ProfWin*)chatwin, '!', "use '/otr answer '."); + break; + case PROF_OTR_SMP_SENDER_FAIL: + win_vprintln_ch((ProfWin*)chatwin, '!', + "Authentication failed, the secret you entered does not match the secret entered by %s.", + chatwin->barejid); + break; + case PROF_OTR_SMP_RECEIVER_FAIL: + win_vprintln_ch((ProfWin*)chatwin, '!', + "Authentication failed, the secret entered by %s does not match yours.", chatwin->barejid); + break; + case PROF_OTR_SMP_ABORT: + win_vprintln_ch((ProfWin*)chatwin, '!', "SMP session aborted."); + break; + case PROF_OTR_SMP_SUCCESS: + win_vprintln_ch((ProfWin*)chatwin, '!', "Authentication successful."); + break; + case PROF_OTR_SMP_SUCCESS_Q: + win_vprintln_ch((ProfWin*)chatwin, '!', "%s successfully authenticated you.", chatwin->barejid); + break; + case PROF_OTR_SMP_FAIL_Q: + win_vprintln_ch((ProfWin*)chatwin, '!', "%s failed to authenticate you.", chatwin->barejid); + break; + case PROF_OTR_SMP_AUTH: + win_vprintln_ch((ProfWin*)chatwin, '!', "Authenticating %s...", chatwin->barejid); + break; + case PROF_OTR_SMP_AUTH_WAIT: + win_vprintln_ch((ProfWin*)chatwin, '!', "Awaiting authentication from %s...", chatwin->barejid); + break; + default: + break; + } } void diff --git a/src/ui/ui.h b/src/ui/ui.h index eed77ba7..5e634438 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -38,6 +38,7 @@ #include "command/commands.h" #include "ui/win_types.h" #include "muc.h" +#include "otr/otr.h" #define NO_ME 1 #define NO_DATE 2 @@ -66,19 +67,7 @@ void chatwin_otr_secured(ProfChatWin *chatwin, gboolean trusted); void chatwin_otr_unsecured(ProfChatWin *chatwin); void chatwin_otr_trust(ProfChatWin *chatwin); void chatwin_otr_untrust(ProfChatWin *chatwin); -void chatwin_otr_smp_init(ProfChatWin *chatwin); -void chatwin_otr_smp_init_q(ProfChatWin *chatwin, const char *question); - -void chatwin_otr_smp_success(ProfChatWin *chatwin); -void chatwin_otr_smp_sender_failed(ProfChatWin *chatwin); -void chatwin_otr_smp_receiver_failed(ProfChatWin *chatwin); -void chatwin_otr_smp_aborted(ProfChatWin *chatwin); - -void chatwin_otr_smp_answer_success(ProfChatWin *chatwin); -void chatwin_otr_smp_answer_failure(ProfChatWin *chatwin); - -void chatwin_otr_smp_authenticating(ProfChatWin *chatwin); -void chatwin_otr_smp_authenticaton_wait(ProfChatWin *chatwin); +void chatwin_otr_smp_event(ProfChatWin *chatwin, prof_otr_smp_event_t event, void *data); void ui_handle_otr_error(const char *const barejid, const char *const message); @@ -372,6 +361,7 @@ void win_show_occupant_info(ProfWin *window, const char *const room, Occupant *o void win_show_contact(ProfWin *window, PContact contact); void win_show_info(ProfWin *window, PContact contact); void win_println(ProfWin *window, int pad, const char *const message); +void win_vprintln_ch(ProfWin *window, char ch, const char *const message, ...); // desktop notifier actions void notifier_initialise(void); diff --git a/src/ui/window.c b/src/ui/window.c index 2b3a9c54..24baa63a 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -963,6 +963,18 @@ win_println(ProfWin *window, int pad, const char *const message) win_print(window, '-', pad, NULL, 0, 0, "", message); } +void +win_vprintln_ch(ProfWin *window, char ch, const char *const message, ...) +{ + va_list arg; + va_start(arg, message); + GString *fmt_msg = g_string_new(NULL); + g_string_vprintf(fmt_msg, message, arg); + win_print(window, ch, 0, NULL, 0, 0, "", fmt_msg->str); + g_string_free(fmt_msg, TRUE); + va_end(arg); +} + void win_newline(ProfWin *window) { diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index de36676a..14911282 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -70,19 +70,8 @@ void chatwin_otr_secured(ProfChatWin *chatwin, gboolean trusted) {} void chatwin_otr_unsecured(ProfChatWin *chatwin) {} void chatwin_otr_trust(ProfChatWin *chatwin) {} void chatwin_otr_untrust(ProfChatWin *chatwin) {} -void chatwin_otr_smp_init(ProfChatWin *chatwin) {} -void chatwin_otr_smp_init_q(ProfChatWin *chatwin, const char *question) {} +void chatwin_otr_smp_event(ProfChatWin *chatwin, prof_otr_smp_event_t event, void *data) {} -void chatwin_otr_smp_success(ProfChatWin *chatwin) {} -void chatwin_otr_smp_sender_failed(ProfChatWin *chatwin) {} -void chatwin_otr_smp_receiver_failed(ProfChatWin *chatwin) {} -void chatwin_otr_smp_aborted(ProfChatWin *chatwin) {} - -void chatwin_otr_smp_answer_success(ProfChatWin *chatwin) {} -void chatwin_otr_smp_answer_failure(ProfChatWin *chatwin) {} - -void chatwin_otr_smp_authenticating(ProfChatWin *chatwin) {} -void chatwin_otr_smp_authenticaton_wait(ProfChatWin *chatwin) {} void ui_sigwinch_handler(int sig) {} unsigned long ui_get_idle_time(void) @@ -552,6 +541,7 @@ void win_show_occupant_info(ProfWin *window, const char * const room, Occupant * void win_show_contact(ProfWin *window, PContact contact) {} void win_show_info(ProfWin *window, PContact contact) {} void win_println(ProfWin *window, int pad, const char * const message) {} +void win_vprintln_ch(ProfWin *window, char ch, const char *const message, ...) {} // desktop notifier actions void notifier_uninit(void) {} From f4fbf0ecf0686f3da83d08b46a4887e1f8180205 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 27 Oct 2015 22:39:48 +0000 Subject: [PATCH 20/30] Fixed otrlibv3 --- src/otr/otrlibv3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/otr/otrlibv3.c b/src/otr/otrlibv3.c index 8af2b896..f795949d 100644 --- a/src/otr/otrlibv3.c +++ b/src/otr/otrlibv3.c @@ -143,7 +143,7 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext } else { ProfChatWin *chatwin = wins_get_chat(context->username); if (chatwin) { - chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_INIT. NULL); + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_INIT, NULL); } g_hash_table_insert(smp_initiators, strdup(context->username), strdup(context->username)); } From 62c2febc11457baf00220f9c3951397dac7989d1 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 27 Oct 2015 23:05:20 +0000 Subject: [PATCH 21/30] Tidied ui_recipient_gone --- src/event/server_events.c | 16 ++++++++++++++- src/ui/chatwin.c | 40 +++++++++++------------------------- src/ui/ui.h | 2 +- tests/unittests/ui/stub_ui.c | 2 +- 4 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index 026b5147..2a66d6fe 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -346,7 +346,21 @@ sv_ev_inactive(char *barejid, char *resource) void sv_ev_gone(const char *const barejid, const char *const resource) { - ui_recipient_gone(barejid, resource); + if (barejid && resource) { + gboolean show_message = TRUE; + + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + ChatSession *session = chat_session_get(barejid); + if (session && g_strcmp0(session->resource, resource) != 0) { + show_message = FALSE; + } + if (show_message) { + ui_recipient_gone(chatwin); + } + } + } + if (wins_chat_exists(barejid)) { chat_session_recipient_gone(barejid, resource); } diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 7921e559..c4fe9507 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -191,37 +191,21 @@ ui_handle_otr_error(const char *const barejid, const char *const message) } void -ui_recipient_gone(const char *const barejid, const char *const resource) +ui_recipient_gone(ProfChatWin *chatwin) { - if (barejid == NULL) - return; - if (resource == NULL) - return; - - gboolean show_message = TRUE; - - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - ChatSession *session = chat_session_get(barejid); - if (session && g_strcmp0(session->resource, resource) != 0) { - show_message = FALSE; - } - if (show_message) { - const char * display_usr = NULL; - PContact contact = roster_get_contact(barejid); - if (contact) { - if (p_contact_name(contact)) { - display_usr = p_contact_name(contact); - } else { - display_usr = barejid; - } - } else { - display_usr = barejid; - } - - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, THEME_GONE, "", "<- %s has left the conversation.", display_usr); + const char *display_usr = NULL; + PContact contact = roster_get_contact(chatwin->barejid); + if (contact) { + if (p_contact_name(contact)) { + display_usr = p_contact_name(contact); + } else { + display_usr = chatwin->barejid; } + } else { + display_usr = chatwin->barejid; } + + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, THEME_GONE, "", "<- %s has left the conversation.", display_usr); } ProfChatWin* diff --git a/src/ui/ui.h b/src/ui/ui.h index 5e634438..81a600c3 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -104,7 +104,7 @@ void ui_incoming_private_msg(const char *const fulljid, const char *const messag void chatwin_receipt_received(ProfChatWin *chatwin, const char *const id); void ui_disconnected(void); -void ui_recipient_gone(const char *const barejid, const char *const resource); +void ui_recipient_gone(ProfChatWin *chatwin); void ui_outgoing_chat_msg(ProfChatWin *chatwin, const char *const message, char *id, prof_enc_t enc_mode); void ui_outgoing_chat_msg_carbon(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 14911282..4967d8b6 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -179,7 +179,7 @@ void chatwin_receipt_received(ProfChatWin *chatwin, const char * const id) {} void ui_incoming_private_msg(const char * const fulljid, const char * const message, GDateTime *timestamp) {} void ui_disconnected(void) {} -void ui_recipient_gone(const char * const barejid, const char * const resource) {} +void ui_recipient_gone(ProfChatWin *chatwin) {} void ui_outgoing_chat_msg(ProfChatWin *chatwin, const char * const message, char *id, prof_enc_t enc_mode) {} void ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const message) {} From ae890287727c8b3c6d9ea05bdf0621acbd4bc7bf Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 27 Oct 2015 23:06:27 +0000 Subject: [PATCH 22/30] Renamed ui_recipient_gone -> chatwin_recipeint_gone --- src/event/server_events.c | 2 +- src/ui/chatwin.c | 2 +- src/ui/ui.h | 2 +- tests/unittests/ui/stub_ui.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index 2a66d6fe..7d5ff5fe 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -356,7 +356,7 @@ sv_ev_gone(const char *const barejid, const char *const resource) show_message = FALSE; } if (show_message) { - ui_recipient_gone(chatwin); + chatwin_recipient_gone(chatwin); } } } diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index c4fe9507..f0453a7c 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -191,7 +191,7 @@ ui_handle_otr_error(const char *const barejid, const char *const message) } void -ui_recipient_gone(ProfChatWin *chatwin) +chatwin_recipient_gone(ProfChatWin *chatwin) { const char *display_usr = NULL; PContact contact = roster_get_contact(chatwin->barejid); diff --git a/src/ui/ui.h b/src/ui/ui.h index 81a600c3..5a7c8e1f 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -104,7 +104,7 @@ void ui_incoming_private_msg(const char *const fulljid, const char *const messag void chatwin_receipt_received(ProfChatWin *chatwin, const char *const id); void ui_disconnected(void); -void ui_recipient_gone(ProfChatWin *chatwin); +void chatwin_recipient_gone(ProfChatWin *chatwin); void ui_outgoing_chat_msg(ProfChatWin *chatwin, const char *const message, char *id, prof_enc_t enc_mode); void ui_outgoing_chat_msg_carbon(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 4967d8b6..a486099e 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -179,7 +179,7 @@ void chatwin_receipt_received(ProfChatWin *chatwin, const char * const id) {} void ui_incoming_private_msg(const char * const fulljid, const char * const message, GDateTime *timestamp) {} void ui_disconnected(void) {} -void ui_recipient_gone(ProfChatWin *chatwin) {} +void chatwin_recipient_gone(ProfChatWin *chatwin) {} void ui_outgoing_chat_msg(ProfChatWin *chatwin, const char * const message, char *id, prof_enc_t enc_mode) {} void ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const message) {} From dfd55d24cd06c151aeecaef442bfc94023826a2c Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 27 Oct 2015 23:12:46 +0000 Subject: [PATCH 23/30] Moved ui_handle_otr_error --- src/ui/chatwin.c | 11 ----------- src/ui/core.c | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index f0453a7c..b3ea45b1 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -179,17 +179,6 @@ chatwin_otr_untrust(ProfChatWin *chatwin) } } -void -ui_handle_otr_error(const char *const barejid, const char *const message) -{ - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - win_print((ProfWin*)chatwin, '!', 0, NULL, 0, THEME_ERROR, "", message); - } else { - cons_show_error("%s - %s", barejid, message); - } -} - void chatwin_recipient_gone(ProfChatWin *chatwin) { diff --git a/src/ui/core.c b/src/ui/core.c index ae446969..d8c9aa4e 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -549,6 +549,17 @@ ui_handle_recipient_error(const char *const recipient, const char *const err_msg } } +void +ui_handle_otr_error(const char *const barejid, const char *const message) +{ + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + win_print((ProfWin*)chatwin, '!', 0, NULL, 0, THEME_ERROR, "", message); + } else { + cons_show_error("%s - %s", barejid, message); + } +} + void ui_handle_error(const char *const err_msg) { From ea09dcda1850cb6fa29f9c1ca8efac870e033625 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 27 Oct 2015 23:15:28 +0000 Subject: [PATCH 24/30] Renamed ui_new_chat_win -> chatwin_new --- src/command/commands.c | 6 +++--- src/ui/chatwin.c | 4 ++-- src/ui/ui.h | 2 +- tests/unittests/ui/stub_ui.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 5ff92321..799a006e 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1522,7 +1522,7 @@ cmd_msg(ProfWin *window, const char *const command, gchar **args) ProfChatWin *chatwin = wins_get_chat(barejid); if (!chatwin) { - chatwin = ui_new_chat_win(barejid); + chatwin = chatwin_new(barejid); } ui_switch_win((ProfWin*)chatwin); @@ -4665,7 +4665,7 @@ cmd_pgp(ProfWin *window, const char *const command, gchar **args) chatwin = wins_get_chat(barejid); if (!chatwin) { - chatwin = ui_new_chat_win(barejid); + chatwin = chatwin_new(barejid); } ui_switch_win((ProfWin*)chatwin); } else { @@ -4866,7 +4866,7 @@ cmd_otr(ProfWin *window, const char *const command, gchar **args) ProfChatWin *chatwin = wins_get_chat(barejid); if (!chatwin) { - chatwin = ui_new_chat_win(barejid); + chatwin = chatwin_new(barejid); } ui_switch_win((ProfWin*)chatwin); diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index b3ea45b1..2ef35b10 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -198,7 +198,7 @@ chatwin_recipient_gone(ProfChatWin *chatwin) } ProfChatWin* -ui_new_chat_win(const char *const barejid) +chatwin_new(const char *const barejid) { ProfWin *window = wins_new_chat(barejid); ProfChatWin *chatwin = (ProfChatWin *)window; @@ -294,7 +294,7 @@ ui_outgoing_chat_msg_carbon(const char *const barejid, const char *const message // create new window if (!chatwin) { - chatwin = ui_new_chat_win(barejid); + chatwin = chatwin_new(barejid); } chat_state_active(chatwin->state); diff --git a/src/ui/ui.h b/src/ui/ui.h index 5a7c8e1f..1214fdab 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -74,7 +74,7 @@ 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); ProfPrivateWin* ui_new_private_win(const char *const fulljid); -ProfChatWin* ui_new_chat_win(const char *const barejid); +ProfChatWin* chatwin_new(const char *const barejid); void ui_print_system_msg_from_recipient(const char *const barejid, const char *message); gint ui_unread(void); void ui_close_connected_win(int index); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index a486099e..0069ee8b 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -85,7 +85,7 @@ ProfPrivateWin* ui_new_private_win(const char * const fulljid) return NULL; } -ProfChatWin* ui_new_chat_win(const char * const barejid) +ProfChatWin* chatwin_new(const char * const barejid) { return NULL; } From af1124f28ffc95a09d88d1fad25c31554106acd7 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 27 Oct 2015 23:18:42 +0000 Subject: [PATCH 25/30] Renamed ui_incoming_msg -> chatwin_incoming_msg --- src/event/server_events.c | 12 ++++----- src/ui/chatwin.c | 48 ++++++++++++++++++------------------ src/ui/ui.h | 2 +- tests/unittests/ui/stub_ui.c | 2 +- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index 7d5ff5fe..e4d19953 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -194,7 +194,7 @@ sv_ev_incoming_carbon(char *barejid, char *resource, char *message) new_win = TRUE; } - ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_MSG_PLAIN); + chatwin_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_MSG_PLAIN); chat_log_msg_in(barejid, message, NULL); } @@ -204,12 +204,12 @@ _sv_ev_incoming_pgp(ProfChatWin *chatwin, gboolean new_win, char *barejid, char { char *decrypted = p_gpg_decrypt(pgp_message); if (decrypted) { - ui_incoming_msg(chatwin, resource, decrypted, timestamp, new_win, PROF_MSG_PGP); + chatwin_incoming_msg(chatwin, resource, decrypted, timestamp, new_win, PROF_MSG_PGP); chat_log_pgp_msg_in(barejid, decrypted, timestamp); chatwin->pgp_recv = TRUE; p_gpg_free_decrypted(decrypted); } else { - ui_incoming_msg(chatwin, resource, message, timestamp, new_win, PROF_MSG_PLAIN); + chatwin_incoming_msg(chatwin, resource, message, timestamp, new_win, PROF_MSG_PLAIN); chat_log_msg_in(barejid, message, timestamp); chatwin->pgp_recv = FALSE; } @@ -224,10 +224,10 @@ _sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, char *barejid, char char *otr_res = otr_on_message_recv(barejid, resource, message, &decrypted); if (otr_res) { if (decrypted) { - ui_incoming_msg(chatwin, resource, otr_res, timestamp, new_win, PROF_MSG_OTR); + chatwin_incoming_msg(chatwin, resource, otr_res, timestamp, new_win, PROF_MSG_OTR); chatwin->pgp_send = FALSE; } else { - ui_incoming_msg(chatwin, resource, otr_res, timestamp, new_win, PROF_MSG_PLAIN); + chatwin_incoming_msg(chatwin, resource, otr_res, timestamp, new_win, PROF_MSG_PLAIN); } chat_log_otr_msg_in(barejid, otr_res, decrypted, timestamp); otr_free_message(otr_res); @@ -240,7 +240,7 @@ _sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, char *barejid, char static void _sv_ev_incoming_plain(ProfChatWin *chatwin, gboolean new_win, char *barejid, char *resource, char *message, GDateTime *timestamp) { - ui_incoming_msg(chatwin, resource, message, timestamp, new_win, PROF_MSG_PLAIN); + chatwin_incoming_msg(chatwin, resource, message, timestamp, new_win, PROF_MSG_PLAIN); chat_log_msg_in(barejid, message, timestamp); chatwin->pgp_recv = FALSE; } diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 2ef35b10..1202be9c 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -47,6 +47,29 @@ static void _win_show_history(ProfChatWin *chatwin, const char *const contact); +ProfChatWin* +chatwin_new(const char *const barejid) +{ + ProfWin *window = wins_new_chat(barejid); + ProfChatWin *chatwin = (ProfChatWin *)window; + + if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { + _win_show_history(chatwin, barejid); + } + + // if the contact is offline, show a message + PContact contact = roster_get_contact(barejid); + if (contact) { + if (strcmp(p_contact_presence(contact), "offline") == 0) { + const char * const show = p_contact_presence(contact); + const char * const status = p_contact_status(contact); + win_show_status_string(window, barejid, show, status, NULL, "--", "offline"); + } + } + + return chatwin; +} + void chatwin_receipt_received(ProfChatWin *chatwin, const char *const id) { @@ -197,31 +220,8 @@ chatwin_recipient_gone(ProfChatWin *chatwin) win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, THEME_GONE, "", "<- %s has left the conversation.", display_usr); } -ProfChatWin* -chatwin_new(const char *const barejid) -{ - ProfWin *window = wins_new_chat(barejid); - ProfChatWin *chatwin = (ProfChatWin *)window; - - if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { - _win_show_history(chatwin, barejid); - } - - // if the contact is offline, show a message - PContact contact = roster_get_contact(barejid); - if (contact) { - if (strcmp(p_contact_presence(contact), "offline") == 0) { - const char * const show = p_contact_presence(contact); - const char * const status = p_contact_status(contact); - win_show_status_string(window, barejid, show, status, NULL, "--", "offline"); - } - } - - return chatwin; -} - void -ui_incoming_msg(ProfChatWin *chatwin, const char *const resource, const char *const message, GDateTime *timestamp, gboolean win_created, prof_enc_t enc_mode) +chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const char *const message, GDateTime *timestamp, gboolean win_created, prof_enc_t enc_mode) { ProfWin *window = (ProfWin*)chatwin; int num = wins_get_num(window); diff --git a/src/ui/ui.h b/src/ui/ui.h index 1214fdab..fb56b6e1 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -99,7 +99,7 @@ void ui_handle_stanza(const char *const msg); // ui events void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity); void ui_contact_typing(const char *const barejid, const char *const resource); -void ui_incoming_msg(ProfChatWin *chatwin, const char *const resource, const char *const message, GDateTime *timestamp, gboolean win_created, prof_enc_t enc_mode); +void chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const char *const message, GDateTime *timestamp, gboolean win_created, prof_enc_t enc_mode); void ui_incoming_private_msg(const char *const fulljid, const char *const message, GDateTime *timestamp); void chatwin_receipt_received(ProfChatWin *chatwin, const char *const id); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 0069ee8b..0a13f8ec 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -173,7 +173,7 @@ void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activi } void ui_contact_typing(const char * const barejid, const char * const resource) {} -void ui_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char * const message, GDateTime *timestamp, gboolean win_created, prof_enc_t enc_mode) {} +void chatwin_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char * const message, GDateTime *timestamp, gboolean win_created, prof_enc_t enc_mode) {} void chatwin_receipt_received(ProfChatWin *chatwin, const char * const id) {} void ui_incoming_private_msg(const char * const fulljid, const char * const message, GDateTime *timestamp) {} From e7148bf82d8a0e0c68cb794dbce7b2f70d3d0e55 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 27 Oct 2015 23:20:03 +0000 Subject: [PATCH 26/30] Renamed ui_outgoing_chat_msg -> chatwin_outgoing_msg --- src/event/client_events.c | 12 ++++++------ src/otr/otr.c | 4 ++-- src/ui/chatwin.c | 2 +- src/ui/ui.h | 2 +- tests/unittests/ui/stub_ui.c | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/event/client_events.c b/src/event/client_events.c index ec9516a2..0579b07d 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -94,14 +94,14 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg) if (chatwin->pgp_send) { char *id = message_send_chat_pgp(chatwin->barejid, msg); chat_log_pgp_msg_out(chatwin->barejid, msg); - ui_outgoing_chat_msg(chatwin, msg, id, PROF_MSG_PGP); + chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PGP); free(id); } else { gboolean handled = otr_on_message_send(chatwin, msg); if (!handled) { char *id = message_send_chat(chatwin->barejid, msg); chat_log_msg_out(chatwin->barejid, msg); - ui_outgoing_chat_msg(chatwin, msg, id, PROF_MSG_PLAIN); + chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PLAIN); free(id); } } @@ -116,7 +116,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg) if (!handled) { char *id = message_send_chat(chatwin->barejid, msg); chat_log_msg_out(chatwin->barejid, msg); - ui_outgoing_chat_msg(chatwin, msg, id, PROF_MSG_PLAIN); + chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PLAIN); free(id); } return; @@ -129,12 +129,12 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg) if (chatwin->pgp_send) { char *id = message_send_chat_pgp(chatwin->barejid, msg); chat_log_pgp_msg_out(chatwin->barejid, msg); - ui_outgoing_chat_msg(chatwin, msg, id, PROF_MSG_PGP); + chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PGP); free(id); } else { char *id = message_send_chat(chatwin->barejid, msg); chat_log_msg_out(chatwin->barejid, msg); - ui_outgoing_chat_msg(chatwin, msg, id, PROF_MSG_PLAIN); + chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PLAIN); free(id); } return; @@ -146,7 +146,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg) #ifndef HAVE_LIBGPGME char *id = message_send_chat(chatwin->barejid, msg); chat_log_msg_out(chatwin->barejid, msg); - ui_outgoing_chat_msg(chatwin, msg, id, PROF_MSG_PLAIN); + chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PLAIN); free(id); return; #endif diff --git a/src/otr/otr.c b/src/otr/otr.c index facfb4f7..68ea3e11 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -331,7 +331,7 @@ otr_on_message_send(ProfChatWin *chatwin, const char *const message) if (encrypted) { id = message_send_chat_otr(chatwin->barejid, encrypted); chat_log_otr_msg_out(chatwin->barejid, message); - ui_outgoing_chat_msg(chatwin, message, id, PROF_MSG_OTR); + chatwin_outgoing_msg(chatwin, message, id, PROF_MSG_OTR); otr_free_message(encrypted); free(id); return TRUE; @@ -351,7 +351,7 @@ otr_on_message_send(ProfChatWin *chatwin, const char *const message) if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { char *otr_tagged_msg = otr_tag_message(message); id = message_send_chat_otr(chatwin->barejid, otr_tagged_msg); - ui_outgoing_chat_msg(chatwin, message, id, PROF_MSG_PLAIN); + chatwin_outgoing_msg(chatwin, message, id, PROF_MSG_PLAIN); chat_log_msg_out(chatwin->barejid, message); free(otr_tagged_msg); free(id); diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 1202be9c..35d502c0 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -271,7 +271,7 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha } void -ui_outgoing_chat_msg(ProfChatWin *chatwin, const char *const message, char *id, prof_enc_t enc_mode) +chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char *id, prof_enc_t enc_mode) { char enc_char = '-'; if (enc_mode == PROF_MSG_OTR) { diff --git a/src/ui/ui.h b/src/ui/ui.h index fb56b6e1..2375c5dc 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -106,7 +106,7 @@ void chatwin_receipt_received(ProfChatWin *chatwin, const char *const id); void ui_disconnected(void); void chatwin_recipient_gone(ProfChatWin *chatwin); -void ui_outgoing_chat_msg(ProfChatWin *chatwin, const char *const message, char *id, prof_enc_t enc_mode); +void chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char *id, prof_enc_t enc_mode); void ui_outgoing_chat_msg_carbon(const char *const barejid, const char *const message); void ui_outgoing_private_msg(ProfPrivateWin *privwin, const char *const message); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 0a13f8ec..f2f5369b 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -181,7 +181,7 @@ void ui_incoming_private_msg(const char * const fulljid, const char * const mess void ui_disconnected(void) {} void chatwin_recipient_gone(ProfChatWin *chatwin) {} -void ui_outgoing_chat_msg(ProfChatWin *chatwin, const char * const message, char *id, prof_enc_t enc_mode) {} +void chatwin_outgoing_msg(ProfChatWin *chatwin, const char * const message, char *id, prof_enc_t enc_mode) {} void ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const message) {} void ui_outgoing_private_msg(ProfPrivateWin *privwin, const char * const message) {} From 31016a21503c42c95eaa8115b8fe7f389c634dd0 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 27 Oct 2015 23:25:18 +0000 Subject: [PATCH 27/30] Tidied chatwin_outgoing_carbon --- src/event/server_events.c | 9 ++++++++- src/ui/chatwin.c | 18 ++++++++---------- src/ui/ui.h | 2 +- tests/unittests/ui/stub_ui.c | 2 +- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index e4d19953..b607c4f8 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -180,7 +180,14 @@ sv_ev_incoming_private_message(const char *const fulljid, char *message) void sv_ev_outgoing_carbon(char *barejid, char *message) { - ui_outgoing_chat_msg_carbon(barejid, message); + ProfChatWin *chatwin = wins_get_chat(barejid); + if (!chatwin) { + chatwin = chatwin_new(barejid); + } + + chat_state_active(chatwin->state); + + chatwin_outgoing_carbon(chatwin, message); } void diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 35d502c0..58b6c6eb 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -205,6 +205,8 @@ chatwin_otr_untrust(ProfChatWin *chatwin) void chatwin_recipient_gone(ProfChatWin *chatwin) { + assert(chatwin != NULL); + const char *display_usr = NULL; PContact contact = roster_get_contact(chatwin->barejid); if (contact) { @@ -223,6 +225,8 @@ chatwin_recipient_gone(ProfChatWin *chatwin) void chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const char *const message, GDateTime *timestamp, gboolean win_created, prof_enc_t enc_mode) { + assert(chatwin != NULL); + ProfWin *window = (ProfWin*)chatwin; int num = wins_get_num(window); @@ -273,6 +277,8 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha void chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char *id, prof_enc_t enc_mode) { + assert(chatwin != NULL); + char enc_char = '-'; if (enc_mode == PROF_MSG_OTR) { enc_char = prefs_get_otr_char(); @@ -288,19 +294,11 @@ chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char *id, } void -ui_outgoing_chat_msg_carbon(const char *const barejid, const char *const message) +chatwin_outgoing_carbon(ProfChatWin *chatwin, const char *const message) { - ProfChatWin *chatwin = wins_get_chat(barejid); - - // create new window - if (!chatwin) { - chatwin = chatwin_new(barejid); - } - - chat_state_active(chatwin->state); + assert(chatwin != NULL); win_print((ProfWin*)chatwin, '-', 0, NULL, 0, THEME_TEXT_ME, "me", message); - int num = wins_get_num((ProfWin*)chatwin); status_bar_active(num); } diff --git a/src/ui/ui.h b/src/ui/ui.h index 2375c5dc..fa8e45f1 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -107,7 +107,7 @@ void ui_disconnected(void); void chatwin_recipient_gone(ProfChatWin *chatwin); void chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char *id, prof_enc_t enc_mode); -void ui_outgoing_chat_msg_carbon(const char *const barejid, const char *const message); +void chatwin_outgoing_carbon(ProfChatWin *chatwin, const char *const message); void ui_outgoing_private_msg(ProfPrivateWin *privwin, const char *const message); void ui_room_join(const char *const roomjid, gboolean focus); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index f2f5369b..83d59135 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -182,7 +182,7 @@ void ui_disconnected(void) {} void chatwin_recipient_gone(ProfChatWin *chatwin) {} void chatwin_outgoing_msg(ProfChatWin *chatwin, const char * const message, char *id, prof_enc_t enc_mode) {} -void ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const message) {} +void chatwin_outgoing_carbon(ProfChatWin *chatwin, const char * const message) {} void ui_outgoing_private_msg(ProfPrivateWin *privwin, const char * const message) {} void ui_room_join(const char * const roomjid, gboolean focus) {} From 77e854c1e8c940a8dd939adab6ab00e909b9f133 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 27 Oct 2015 23:28:59 +0000 Subject: [PATCH 28/30] Renamed _win_show_history -> _chatwin_history --- src/ui/chatwin.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 58b6c6eb..591635bb 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -45,7 +45,7 @@ #include "ui/window.h" #include "ui/titlebar.h" -static void _win_show_history(ProfChatWin *chatwin, const char *const contact); +static void _chatwin_history(ProfChatWin *chatwin, const char *const contact); ProfChatWin* chatwin_new(const char *const barejid) @@ -54,7 +54,7 @@ chatwin_new(const char *const barejid) ProfChatWin *chatwin = (ProfChatWin *)window; if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { - _win_show_history(chatwin, barejid); + _chatwin_history(chatwin, barejid); } // if the contact is offline, show a message @@ -249,7 +249,7 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha chatwin->unread++; if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { - _win_show_history(chatwin, chatwin->barejid); + _chatwin_history(chatwin, chatwin->barejid); } // show users status first, when receiving message via delayed delivery @@ -336,7 +336,7 @@ ui_chat_win_contact_offline(PContact contact, char *resource, char *status) } static void -_win_show_history(ProfChatWin *chatwin, const char *const contact) +_chatwin_history(ProfChatWin *chatwin, const char *const contact) { if (!chatwin->history_shown) { Jid *jid = jid_create(jabber_get_fulljid()); From 3f7f1186a64ea8ed39e6b72b1bbe3dd0037a5617 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 27 Oct 2015 23:39:26 +0000 Subject: [PATCH 29/30] Tidied remaining chatwin functions --- src/ui/chatwin.c | 27 +++++++++++---------------- src/ui/core.c | 20 ++++++++++++++++---- src/ui/ui.h | 4 ++-- tests/unittests/ui/stub_ui.c | 4 ++-- 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 591635bb..0e78fc24 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -304,33 +304,28 @@ chatwin_outgoing_carbon(ProfChatWin *chatwin, const char *const message) } void -ui_chat_win_contact_online(PContact contact, Resource *resource, GDateTime *last_activity) +chatwin_contact_online(ProfChatWin *chatwin, Resource *resource, GDateTime *last_activity) { + assert(chatwin != NULL); + const char *show = string_from_resource_presence(resource->presence); + PContact contact = roster_get_contact(chatwin->barejid); char *display_str = p_contact_create_display_string(contact, resource->name); - const char *barejid = p_contact_barejid(contact); - ProfWin *window = (ProfWin*)wins_get_chat(barejid); - if (window) { - win_show_status_string(window, display_str, show, resource->status, - last_activity, "++", "online"); - - } + win_show_status_string((ProfWin*)chatwin, display_str, show, resource->status, last_activity, "++", "online"); free(display_str); } void -ui_chat_win_contact_offline(PContact contact, char *resource, char *status) +chatwin_contact_offline(ProfChatWin *chatwin, char *resource, char *status) { - char *display_str = p_contact_create_display_string(contact, resource); - const char *barejid = p_contact_barejid(contact); + assert(chatwin != NULL); - ProfWin *window = (ProfWin*)wins_get_chat(barejid); - if (window) { - win_show_status_string(window, display_str, "offline", status, NULL, "--", - "offline"); - } + PContact contact = roster_get_contact(chatwin->barejid); + char *display_str = p_contact_create_display_string(contact, resource); + + win_show_status_string((ProfWin*)chatwin, display_str, "offline", status, NULL, "--", "offline"); free(display_str); } diff --git a/src/ui/core.c b/src/ui/core.c index d8c9aa4e..eb36ba22 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -323,11 +323,17 @@ ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity) // show in chat win if "all" if (g_strcmp0(show_chat_win, "all") == 0) { - ui_chat_win_contact_online(contact, resource, last_activity); + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + chatwin_contact_online(chatwin, resource, last_activity); + } // show in char win if "online" and presence online } else if (g_strcmp0(show_chat_win, "online") == 0 && resource->presence == RESOURCE_ONLINE) { - ui_chat_win_contact_online(contact, resource, last_activity); + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + chatwin_contact_online(chatwin, resource, last_activity); + } } free(show_console); @@ -1790,11 +1796,17 @@ ui_contact_offline(char *barejid, char *resource, char *status) // show in chat win if "all" if (g_strcmp0(show_chat_win, "all") == 0) { - ui_chat_win_contact_offline(contact, resource, status); + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + chatwin_contact_offline(chatwin, resource, status); + } // show in char win if "online" and presence online } else if (g_strcmp0(show_chat_win, "online") == 0) { - ui_chat_win_contact_offline(contact, resource, status); + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + chatwin_contact_offline(chatwin, resource, status); + } } } } diff --git a/src/ui/ui.h b/src/ui/ui.h index fa8e45f1..100ca10a 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -168,8 +168,8 @@ void ui_contact_already_in_group(const char *const contact, const char *const gr void ui_contact_not_in_group(const char *const contact, const char *const group); void ui_group_added(const char *const contact, const char *const group); void ui_group_removed(const char *const contact, const char *const group); -void ui_chat_win_contact_online(PContact contact, Resource *resource, GDateTime *last_activity); -void ui_chat_win_contact_offline(PContact contact, char *resource, char *status); +void chatwin_contact_online(ProfChatWin *chatwin, Resource *resource, GDateTime *last_activity); +void chatwin_contact_offline(ProfChatWin *chatwin, char *resource, char *status); void ui_contact_offline(char *barejid, char *resource, char *status); void ui_handle_recipient_not_found(const char *const recipient, const char *const err_msg); void ui_handle_recipient_error(const char *const recipient, const char *const err_msg); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 83d59135..5e0ac484 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -243,8 +243,8 @@ void ui_contact_already_in_group(const char * const contact, const char * const void ui_contact_not_in_group(const char * const contact, const char * const group) {} void ui_group_added(const char * const contact, const char * const group) {} void ui_group_removed(const char * const contact, const char * const group) {} -void ui_chat_win_contact_online(PContact contact, Resource *resource, GDateTime *last_activity) {} -void ui_chat_win_contact_offline(PContact contact, char *resource, char *status) {} +void chatwin_contact_online(ProfChatWin *chatwin, Resource *resource, GDateTime *last_activity) {} +void chatwin_contact_offline(ProfChatWin *chatwin, char *resource, char *status) {} void ui_contact_offline(char *barejid, char *resource, char *status) {} From fa8a5323b6d93da37a9ac13164e8d37c7ed7f15b Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 27 Oct 2015 23:42:26 +0000 Subject: [PATCH 30/30] Reordered ui.h --- src/ui/ui.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ui/ui.h b/src/ui/ui.h index 100ca10a..088a5953 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -63,18 +63,25 @@ GSList* ui_get_chat_recipients(void); void ui_switch_win(ProfWin *window); void ui_sigwinch_handler(int sig); +ProfChatWin* chatwin_new(const char *const barejid); +void chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const char *const message, GDateTime *timestamp, gboolean win_created, prof_enc_t enc_mode); void chatwin_otr_secured(ProfChatWin *chatwin, gboolean trusted); void chatwin_otr_unsecured(ProfChatWin *chatwin); void chatwin_otr_trust(ProfChatWin *chatwin); void chatwin_otr_untrust(ProfChatWin *chatwin); void chatwin_otr_smp_event(ProfChatWin *chatwin, prof_otr_smp_event_t event, void *data); +void chatwin_receipt_received(ProfChatWin *chatwin, const char *const id); +void chatwin_recipient_gone(ProfChatWin *chatwin); +void chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char *id, prof_enc_t enc_mode); +void chatwin_outgoing_carbon(ProfChatWin *chatwin, const char *const message); +void chatwin_contact_online(ProfChatWin *chatwin, Resource *resource, GDateTime *last_activity); +void chatwin_contact_offline(ProfChatWin *chatwin, char *resource, char *status); 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); ProfPrivateWin* ui_new_private_win(const char *const fulljid); -ProfChatWin* chatwin_new(const char *const barejid); void ui_print_system_msg_from_recipient(const char *const barejid, const char *message); gint ui_unread(void); void ui_close_connected_win(int index); @@ -99,15 +106,10 @@ void ui_handle_stanza(const char *const msg); // ui events void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity); void ui_contact_typing(const char *const barejid, const char *const resource); -void chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const char *const message, GDateTime *timestamp, gboolean win_created, prof_enc_t enc_mode); void ui_incoming_private_msg(const char *const fulljid, const char *const message, GDateTime *timestamp); -void chatwin_receipt_received(ProfChatWin *chatwin, const char *const id); void ui_disconnected(void); -void chatwin_recipient_gone(ProfChatWin *chatwin); -void chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char *id, prof_enc_t enc_mode); -void chatwin_outgoing_carbon(ProfChatWin *chatwin, const char *const message); void ui_outgoing_private_msg(ProfPrivateWin *privwin, const char *const message); void ui_room_join(const char *const roomjid, gboolean focus); @@ -168,8 +170,6 @@ void ui_contact_already_in_group(const char *const contact, const char *const gr void ui_contact_not_in_group(const char *const contact, const char *const group); void ui_group_added(const char *const contact, const char *const group); void ui_group_removed(const char *const contact, const char *const group); -void chatwin_contact_online(ProfChatWin *chatwin, Resource *resource, GDateTime *last_activity); -void chatwin_contact_offline(ProfChatWin *chatwin, char *resource, char *status); void ui_contact_offline(char *barejid, char *resource, char *status); void ui_handle_recipient_not_found(const char *const recipient, const char *const err_msg); void ui_handle_recipient_error(const char *const recipient, const char *const err_msg);