From 3f31c1a4e705a16284464a5798a23a3e0e701e82 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 23 Jan 2014 19:25:53 +0000 Subject: [PATCH 1/2] Encrypt /tiny command when in OTR session fixes #292 --- src/command/command.c | 1 + src/command/commands.c | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/command/command.c b/src/command/command.c index ceed2e01..fec14032 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1199,6 +1199,7 @@ cmd_execute_default(const char * const inp) win_type_t win_type = ui_current_win_type(); jabber_conn_status_t status = jabber_get_connection_status(); char *recipient = ui_current_recipient(); + cons_debug("Recipient: %s", recipient); switch (win_type) { diff --git a/src/command/commands.c b/src/command/commands.c index 9c16ef81..7943bfad 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1838,8 +1838,40 @@ cmd_tiny(gchar **args, struct cmd_help_t help) if (tiny != NULL) { if (win_type == WIN_CHAT) { char *recipient = ui_current_recipient(); - message_send(tiny, recipient); +#ifdef HAVE_LIBOTR + if (otr_is_secure(recipient)) { + char *encrypted = otr_encrypt_message(recipient, tiny); + if (encrypted != NULL) { + message_send(encrypted, recipient); + otr_free_message(encrypted); + if (prefs_get_boolean(PREF_CHLOG)) { + const char *jid = jabber_get_fulljid(); + Jid *jidp = jid_create(jid); + if (strcmp(prefs_get_string(PREF_OTR_LOG), "on") == 0) { + chat_log_chat(jidp->barejid, recipient, tiny, PROF_OUT_LOG, NULL); + } else if (strcmp(prefs_get_string(PREF_OTR_LOG), "redact") == 0) { + chat_log_chat(jidp->barejid, recipient, "[redacted]", PROF_OUT_LOG, NULL); + } + jid_destroy(jidp); + } + ui_outgoing_msg("me", recipient, tiny); + } else { + cons_show_error("Failed to send message."); + } + } else { + message_send(tiny, recipient); + if (prefs_get_boolean(PREF_CHLOG)) { + const char *jid = jabber_get_fulljid(); + Jid *jidp = jid_create(jid); + chat_log_chat(jidp->barejid, recipient, tiny, PROF_OUT_LOG, NULL); + jid_destroy(jidp); + } + + ui_outgoing_msg("me", recipient, tiny); + } +#else + message_send(tiny, recipient); if (prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); Jid *jidp = jid_create(jid); @@ -1848,6 +1880,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help) } ui_outgoing_msg("me", recipient, tiny); +#endif } else if (win_type == WIN_PRIVATE) { char *recipient = ui_current_recipient(); message_send(tiny, recipient); From b6c52007ee2ddc4001a2ab8a6586ca293d54ed18 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 23 Jan 2014 19:27:39 +0000 Subject: [PATCH 2/2] Removed debug --- src/command/command.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/command/command.c b/src/command/command.c index fec14032..ceed2e01 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1199,7 +1199,6 @@ cmd_execute_default(const char * const inp) win_type_t win_type = ui_current_win_type(); jabber_conn_status_t status = jabber_get_connection_status(); char *recipient = ui_current_recipient(); - cons_debug("Recipient: %s", recipient); switch (win_type) {