From 025c2fb1e0ed0915c90d4371c2f96ce9f9c8f957 Mon Sep 17 00:00:00 2001 From: Maximilian Wuttke Date: Mon, 29 Mar 2021 22:10:18 +0200 Subject: Msg sending: don't write to chatwin nor to log if sending failed Currently, only `chat_log_omemo_msg_out` can fail (i.e. return `NULL` instead of a stanza id). In this case, the message is neither printed to the chat window nor added to the log (since it wasn't sent). --- src/event/client_events.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/event/client_events.c b/src/event/client_events.c index 6db19463..bf519feb 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -134,27 +134,33 @@ cl_ev_send_msg_correct(ProfChatWin* chatwin, const char* const msg, const char* if (chatwin->is_omemo) { #ifdef HAVE_OMEMO char* id = omemo_on_message_send((ProfWin*)chatwin, plugin_msg, request_receipt, FALSE, replace_id); - chat_log_omemo_msg_out(chatwin->barejid, plugin_msg, NULL); - log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_OMEMO); - chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_OMEMO, request_receipt, replace_id); - free(id); + if (id != NULL) { + chat_log_omemo_msg_out(chatwin->barejid, plugin_msg, NULL); + log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_OMEMO); + chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_OMEMO, request_receipt, replace_id); + free(id); + } #endif } else if (chatwin->is_ox) { #ifdef HAVE_LIBGPGME // XEP-0373: OpenPGP for XMPP char* id = message_send_chat_ox(chatwin->barejid, plugin_msg, request_receipt, replace_id); - chat_log_pgp_msg_out(chatwin->barejid, plugin_msg, NULL); - log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_OX); - chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_OX, request_receipt, replace_id); - free(id); + if (id != NULL) { + chat_log_pgp_msg_out(chatwin->barejid, plugin_msg, NULL); + log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_OX); + chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_OX, request_receipt, replace_id); + free(id); + } #endif } else if (chatwin->pgp_send) { #ifdef HAVE_LIBGPGME char* id = message_send_chat_pgp(chatwin->barejid, plugin_msg, request_receipt, replace_id); - chat_log_pgp_msg_out(chatwin->barejid, plugin_msg, NULL); - log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_PGP); - chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PGP, request_receipt, replace_id); - free(id); + if (id != NULL) { + chat_log_pgp_msg_out(chatwin->barejid, plugin_msg, NULL); + log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_PGP); + chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PGP, request_receipt, replace_id); + free(id); + } #endif } else { gboolean handled = FALSE; -- cgit 1.4.1-2-gfad0