about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-04-26 23:29:05 +0100
committerJames Booth <boothj5@gmail.com>2014-04-26 23:29:05 +0100
commit84c7fc9ae0453ecc2b95151ec5e15e28476f0d79 (patch)
treec23b279f3e2fdb3cc047d37f2a2dcfa726a7cb88
parentaff9eee4331a49cabdf9f64e7e03ec3e781c991c (diff)
downloadprofani-tty-84c7fc9ae0453ecc2b95151ec5e15e28476f0d79.tar.gz
Added SMP ui events
-rw-r--r--src/otr/otrlibv3.c12
-rw-r--r--src/ui/core.c78
-rw-r--r--src/ui/ui.h8
3 files changed, 92 insertions, 6 deletions
diff --git a/src/otr/otrlibv3.c b/src/otr/otrlibv3.c
index 76061c5d..a2e31b1c 100644
--- a/src/otr/otrlibv3.c
+++ b/src/otr/otrlibv3.c
@@ -117,7 +117,7 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext
             otrl_message_abort_smp(user_state, ops, NULL, context);
         } else {
             // [get secret from user and continue SMP];
-            cons_debug("%s initiated SMP with secret", context->username);
+            ui_smp_recipient_initiated(context->username);
             g_hash_table_insert(smp_initiators, strdup(context->username), strdup(context->username));
         }
     }
@@ -140,9 +140,9 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext
             context->smstate->nextExpected = OTRL_SMP_EXPECT1;
             // Report result to user
             if ((context->active_fingerprint->trust != NULL) && (context->active_fingerprint->trust[0] != '\0')) {
-                cons_debug("SMP SUCCESSFUL");
+                ui_smp_successful_sender(context->username);
             } else {
-                cons_debug("SMP UNSUCCESSFUL");
+                ui_smp_unsuccessful_sender(context->username);
             }
         }
     }
@@ -155,9 +155,9 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext
             context->smstate->nextExpected = OTRL_SMP_EXPECT1;
             // Report result to user
             if ((context->active_fingerprint->trust != NULL) && (context->active_fingerprint->trust[0] != '\0')) {
-                cons_debug("SMP SUCCESSFUL");
+                ui_smp_successful_receiver(context->username);
             } else {
-                cons_debug("SMP UNSUCCESSFUL");
+                ui_smp_unsuccessful_receiver(context->username);
             }
         }
     }
@@ -166,6 +166,6 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext
         // The message we are waiting for will not arrive, so reset
         // and prepare for the next SMP
         context->smstate->nextExpected = OTRL_SMP_EXPECT1;
-        cons_debug("SMP ABORTED");
+        ui_smp_aborted(context->username);
     }
 }
\ No newline at end of file
diff --git a/src/ui/core.c b/src/ui/core.c
index adebdadd..e59b2fda 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -785,6 +785,78 @@ _ui_gone_secure(const char * const recipient, gboolean trusted)
 }
 
 static void
+_ui_smp_recipient_initiated(const char * const recipient)
+{
+    ProfWin *window = wins_get_by_recipient(recipient);
+    if (window == NULL) {
+        return;
+    } else {
+        win_vprint_line(window, '!', 0, "%s initiated SMP with secret, use '/otr secret <secret>' to start a trusted session.", recipient);
+        win_update_virtual(window);
+    }
+}
+
+static void
+_ui_smp_successful_sender(const char * const recipient)
+{
+    ProfWin *window = wins_get_by_recipient(recipient);
+    if (window == NULL) {
+        return;
+    } else {
+        win_vprint_line(window, '!', 0, "SMP session started.");
+        win_update_virtual(window);
+    }
+}
+
+static void
+_ui_smp_unsuccessful_sender(const char * const recipient)
+{
+    ProfWin *window = wins_get_by_recipient(recipient);
+    if (window == NULL) {
+        return;
+    } else {
+        win_vprint_line(window, '!', 0, "SMP session failed, the secret you entered does not match the secret entered by %s.", recipient);
+        win_update_virtual(window);
+    }
+}
+
+static void
+_ui_smp_successful_receiver(const char * const recipient)
+{
+    ProfWin *window = wins_get_by_recipient(recipient);
+    if (window == NULL) {
+        return;
+    } else {
+        win_vprint_line(window, '!', 0, "SMP session started.");
+        win_update_virtual(window);
+    }
+}
+
+static void
+_ui_smp_unsuccessful_receiver(const char * const recipient)
+{
+    ProfWin *window = wins_get_by_recipient(recipient);
+    if (window == NULL) {
+        return;
+    } else {
+        win_vprint_line(window, '!', 0, "SMP session failed, the secret %s entered does not match the secret you entered.", recipient);
+        win_update_virtual(window);
+    }
+}
+
+static void
+_ui_smp_aborted(const char * const recipient)
+{
+    ProfWin *window = wins_get_by_recipient(recipient);
+    if (window == NULL) {
+        return;
+    } else {
+        win_vprint_line(window, '!', 0, "SMP session aborted.");
+        win_update_virtual(window);
+    }
+}
+
+static void
 _ui_gone_insecure(const char * const recipient)
 {
     ProfWin *window = wins_get_by_recipient(recipient);
@@ -1978,6 +2050,12 @@ ui_init_module(void)
     ui_gone_insecure = _ui_gone_insecure;
     ui_trust = _ui_trust;
     ui_untrust = _ui_untrust;
+    ui_smp_recipient_initiated = _ui_smp_recipient_initiated;
+    ui_smp_successful_sender = _ui_smp_successful_sender;
+    ui_smp_unsuccessful_sender = _ui_smp_unsuccessful_sender;
+    ui_smp_successful_receiver = _ui_smp_successful_receiver;
+    ui_smp_unsuccessful_receiver = _ui_smp_unsuccessful_receiver;
+    ui_smp_aborted = _ui_smp_aborted;
     ui_chat_win_contact_online = _ui_chat_win_contact_online;
     ui_chat_win_contact_offline = _ui_chat_win_contact_offline;
     ui_handle_recipient_not_found = _ui_handle_recipient_not_found;
diff --git a/src/ui/ui.h b/src/ui/ui.h
index d56c8f5d..cfc5aaf5 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -58,10 +58,18 @@ void (*ui_handle_special_keys)(const wint_t * const ch, const char * const inp,
 gboolean (*ui_switch_win)(const int i);
 void (*ui_next_win)(void);
 void (*ui_previous_win)(void);
+
 void (*ui_gone_secure)(const char * const recipient, gboolean trusted);
 void (*ui_gone_insecure)(const char * const recipient);
 void (*ui_trust)(const char * const recipient);
 void (*ui_untrust)(const char * const recipient);
+void (*ui_smp_recipient_initiated)(const char * const recipient);
+void (*ui_smp_successful_sender)(const char * const recipient);
+void (*ui_smp_unsuccessful_sender)(const char * const recipient);
+void (*ui_smp_successful_receiver)(const char * const recipient);
+void (*ui_smp_unsuccessful_receiver)(const char * const recipient);
+void (*ui_smp_aborted)(const char * const recipient);
+
 unsigned long (*ui_get_idle_time)(void);
 void (*ui_reset_idle_time)(void);
 void (*ui_new_chat_win)(const char * const to);