diff options
author | James Booth <boothj5@gmail.com> | 2014-01-11 17:03:01 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-01-11 17:03:01 +0000 |
commit | 9daefe170d7fa1f50620acdd0a9073b98ba373f9 (patch) | |
tree | a49f4852f9452bc4a594e8145a0fdc12529e455b /src/command | |
parent | 5c13538e6b71cc0d1f5fe49017a99dceecfd007a (diff) | |
download | profani-tty-9daefe170d7fa1f50620acdd0a9073b98ba373f9.tar.gz |
Require '/otr start' from both parties before encryption used both ways
Diffstat (limited to 'src/command')
-rw-r--r-- | src/command/command.c | 25 | ||||
-rw-r--r-- | src/command/commands.c | 47 |
2 files changed, 57 insertions, 15 deletions
diff --git a/src/command/command.c b/src/command/command.c index 3f220cee..1a7c23da 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1140,10 +1140,24 @@ cmd_execute_default(const char * const inp) ui_current_print_line("You are not currently connected."); } else { #ifdef HAVE_LIBOTR - char *encrypted = otr_encrypt_message(recipient, inp); - if (encrypted != NULL) { - message_send(encrypted, recipient); - otr_free_message(encrypted); + if (ui_current_win_is_otr()) { + char *encrypted = otr_encrypt_message(recipient, inp); + 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); + chat_log_chat(jidp->barejid, recipient, inp, PROF_OUT_LOG, NULL); + jid_destroy(jidp); + } + + ui_outgoing_msg("me", recipient, inp); + } else { + cons_show_error("Failed to send message."); + } + } else { + message_send(inp, recipient); if (prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); Jid *jidp = jid_create(jid); @@ -1152,8 +1166,6 @@ cmd_execute_default(const char * const inp) } ui_outgoing_msg("me", recipient, inp); - } else { - cons_show_error("Failed to send message."); } #else message_send(inp, recipient); @@ -1166,7 +1178,6 @@ cmd_execute_default(const char * const inp) ui_outgoing_msg("me", recipient, inp); #endif - } break; diff --git a/src/command/commands.c b/src/command/commands.c index 649c084e..6b0b38f9 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -42,6 +42,8 @@ #include "tools/parser.h" #include "tools/tinyurl.h" #include "ui/ui.h" +#include "ui/window.h" +#include "ui/windows.h" #include "xmpp/xmpp.h" #include "xmpp/bookmark.h" @@ -917,10 +919,24 @@ cmd_msg(gchar **args, struct cmd_help_t help) } if (msg != NULL) { #ifdef HAVE_LIBOTR - char *encrypted = otr_encrypt_message(usr_jid, msg); - if (encrypted != NULL) { - message_send(encrypted, usr_jid); - otr_free_message(encrypted); + if (ui_current_win_is_otr()) { + char *encrypted = otr_encrypt_message(usr_jid, msg); + if (encrypted != NULL) { + message_send(encrypted, usr_jid); + otr_free_message(encrypted); + ui_outgoing_msg("me", usr_jid, msg); + + if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) { + const char *jid = jabber_get_fulljid(); + Jid *jidp = jid_create(jid); + chat_log_chat(jidp->barejid, usr_jid, msg, PROF_OUT_LOG, NULL); + jid_destroy(jidp); + } + } else { + cons_show_error("Failed to encrypt and send message,"); + } + } else { + message_send(msg, usr_jid); ui_outgoing_msg("me", usr_jid, msg); if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) { @@ -929,10 +945,8 @@ cmd_msg(gchar **args, struct cmd_help_t help) chat_log_chat(jidp->barejid, usr_jid, msg, PROF_OUT_LOG, NULL); jid_destroy(jidp); } - } else { - cons_show_error("Failed to send message,"); } - + return TRUE; #else message_send(msg, usr_jid); ui_outgoing_msg("me", usr_jid, msg); @@ -942,9 +956,10 @@ cmd_msg(gchar **args, struct cmd_help_t help) Jid *jidp = jid_create(jid); chat_log_chat(jidp->barejid, usr_jid, msg, PROF_OUT_LOG, NULL); jid_destroy(jidp); + } + return TRUE; #endif - return TRUE; } else { const char * jid = NULL; @@ -2300,6 +2315,22 @@ cmd_otr(gchar **args, struct cmd_help_t help) char *fingerprint = otr_get_fingerprint(); cons_show("Your fingerprint: %s", fingerprint); return TRUE; + } else if (strcmp(args[0], "start") == 0) { + win_type_t win_type = ui_current_win_type(); + + if (win_type != WIN_CHAT) { + ui_current_print_line("You must be in a regular chat window to start an OTR session."); + } else if (ui_current_win_is_otr()) { + ui_current_print_line("You are already in an OTR session."); + } else { + if (!otr_key_loaded()) { + ui_current_print_line("You have not generated or loaded a private key, use '/otr gen'"); + } else { + ui_current_print_line("Starting OTR session"); + ui_current_set_otr(TRUE); + } + } + return TRUE; } else { cons_show("Usage: %s", help.usage); return TRUE; |