about summary refs log tree commit diff stats
path: root/src/command/commands.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-01-11 17:03:01 +0000
committerJames Booth <boothj5@gmail.com>2014-01-11 17:03:01 +0000
commit9daefe170d7fa1f50620acdd0a9073b98ba373f9 (patch)
treea49f4852f9452bc4a594e8145a0fdc12529e455b /src/command/commands.c
parent5c13538e6b71cc0d1f5fe49017a99dceecfd007a (diff)
downloadprofani-tty-9daefe170d7fa1f50620acdd0a9073b98ba373f9.tar.gz
Require '/otr start' from both parties before encryption used both ways
Diffstat (limited to 'src/command/commands.c')
-rw-r--r--src/command/commands.c47
1 files changed, 39 insertions, 8 deletions
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;