From e45afd5c09a5a4bea9cbf8f16eb6af3908344dba Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Jun 2015 01:48:25 +0100 Subject: Added pgp checks for message sending --- src/otr/otr.c | 37 ++++++++++++++++++++----------------- src/otr/otr.h | 2 +- 2 files changed, 21 insertions(+), 18 deletions(-) (limited to 'src/otr') diff --git a/src/otr/otr.c b/src/otr/otr.c index 1f63c8f9..f2f5833f 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -110,7 +110,7 @@ static void cb_inject_message(void *opdata, const char *accountname, const char *protocol, const char *recipient, const char *message) { - message_send_chat_encrypted(recipient, message); + message_send_chat_otr(recipient, message); } static void @@ -294,7 +294,7 @@ otr_on_message_recv(const char * const barejid, const char * const resource, con memmove(whitespace_base, whitespace_base+tag_length, tag_length); char *otr_query_message = otr_start_query(); cons_show("OTR Whitespace pattern detected. Attempting to start OTR session..."); - message_send_chat_encrypted(barejid, otr_query_message); + message_send_chat_otr(barejid, otr_query_message); } } } @@ -308,7 +308,7 @@ otr_on_message_recv(const char * const barejid, const char * const resource, con if (policy == PROF_OTRPOLICY_ALWAYS && !was_decrypted && !whitespace_base) { char *otr_query_message = otr_start_query(); cons_show("Attempting to start OTR session..."); - message_send_chat_encrypted(barejid, otr_query_message); + message_send_chat_otr(barejid, otr_query_message); } ui_incoming_msg(barejid, resource, decrypted, NULL); @@ -316,43 +316,46 @@ otr_on_message_recv(const char * const barejid, const char * const resource, con otr_free_message(decrypted); } -void +gboolean otr_on_message_send(ProfChatWin *chatwin, const char * const message) { char *id = NULL; - prof_otrpolicy_t policy = otr_get_policy(chatwin->barejid); + // Send encrypted message if (otr_is_secure(chatwin->barejid)) { char *encrypted = otr_encrypt_message(chatwin->barejid, message); if (encrypted) { - id = message_send_chat_encrypted(chatwin->barejid, encrypted); + id = message_send_chat_otr(chatwin->barejid, encrypted); chat_log_otr_msg_out(chatwin->barejid, message); ui_outgoing_chat_msg(chatwin, message, id); otr_free_message(encrypted); + free(id); + return TRUE; } else { ui_win_error_line((ProfWin*)chatwin, "Failed to encrypt and send message."); - return; + return TRUE; } + } - } else if (policy == PROF_OTRPOLICY_ALWAYS) { + // show error if not secure and policy always + if (policy == PROF_OTRPOLICY_ALWAYS) { ui_win_error_line((ProfWin*)chatwin, "Failed to send message. OTR policy set to: always"); - return; + return TRUE; + } - } else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { + // tag and send for policy opportunistic + if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { char *otr_tagged_msg = otr_tag_message(message); - id = message_send_chat_encrypted(chatwin->barejid, otr_tagged_msg); + id = message_send_chat_otr(chatwin->barejid, otr_tagged_msg); ui_outgoing_chat_msg(chatwin, message, id); chat_log_msg_out(chatwin->barejid, message); free(otr_tagged_msg); - - } else { - id = message_send_chat(chatwin->barejid, message); - ui_outgoing_chat_msg(chatwin, message, id); - chat_log_msg_out(chatwin->barejid, message); + free(id); + return TRUE; } - free(id); + return FALSE; } void diff --git a/src/otr/otr.h b/src/otr/otr.h index 3c46ac3d..6a358b52 100644 --- a/src/otr/otr.h +++ b/src/otr/otr.h @@ -59,7 +59,7 @@ void otr_poll(void); void otr_on_connect(ProfAccount *account); void otr_on_message_recv(const char * const barejid, const char * const resource, const char * const message); -void otr_on_message_send(ProfChatWin *chatwin, const char * const message); +gboolean otr_on_message_send(ProfChatWin *chatwin, const char * const message); void otr_keygen(ProfAccount *account); -- cgit 1.4.1-2-gfad0