about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorPaul Fariello <paul@fariello.eu>2019-03-19 17:10:20 +0100
committerPaul Fariello <paul@fariello.eu>2019-04-10 17:12:31 +0200
commitbc541cb8ac6be40a2ee1e38a99de7cf144361a2a (patch)
tree7f5a08a7b73ad94ba5fba367860dcd26b2f9853c
parent9a66e74986876ded37bb027bd0f673cd1f975782 (diff)
downloadprofani-tty-bc541cb8ac6be40a2ee1e38a99de7cf144361a2a.tar.gz
Add OMEMO end command
-rw-r--r--src/command/cmd_ac.c1
-rw-r--r--src/command/cmd_defs.c3
-rw-r--r--src/command/cmd_funcs.c41
-rw-r--r--src/command/cmd_funcs.h1
4 files changed, 46 insertions, 0 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index 588c8b4f..8db9c035 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -579,6 +579,7 @@ cmd_ac_init(void)
     omemo_ac = autocomplete_new();
     autocomplete_add(omemo_ac, "gen");
     autocomplete_add(omemo_ac, "start");
+    autocomplete_add(omemo_ac, "end");
     autocomplete_add(omemo_ac, "trust");
     autocomplete_add(omemo_ac, "untrust");
     autocomplete_add(omemo_ac, "fingerprint");
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 70e4595e..2d4ae061 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -2335,6 +2335,7 @@ static struct cmd_t command_defs[] =
         CMD_SUBFUNCS(
             { "gen", cmd_omemo_gen },
             { "start", cmd_omemo_start },
+            { "end", cmd_omemo_end },
             { "trust", cmd_omemo_trust },
             { "untrust", cmd_omemo_untrust },
             { "fingerprint", cmd_omemo_fingerprint })
@@ -2346,12 +2347,14 @@ static struct cmd_t command_defs[] =
             "/omemo gen",
             "/omemo start [<contact>]",
             "/omemo trust [<contact>] <fingerprint>",
+            "/omemo end",
             "/omemo fingerprint")
         CMD_DESC(
             "Omemo commands to manage keys, and perform encryption during chat sessions.")
         CMD_ARGS(
             { "gen",               "Generate OMEMO crytographic materials for current account." },
             { "start [<contact>]", "Start an OMEMO session with contact, or current recipient if omitted." },
+            { "end",               "End the current OMEMO session," },
             { "fingerprint",       "Show current device fingerprint." })
         CMD_EXAMPLES(
             "/omemo gen",
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index f21da6e7..49e20744 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -7996,6 +7996,47 @@ cmd_omemo_start(ProfWin *window, const char *const command, gchar **args)
 }
 
 gboolean
+cmd_omemo_end(ProfWin *window, const char *const command, gchar **args)
+{
+#ifdef HAVE_OMEMO
+    if (connection_get_status() != JABBER_CONNECTED) {
+        cons_show("You must be connected with an account to load OMEMO information.");
+        return TRUE;
+    }
+
+    if (window->type == WIN_CHAT) {
+        ProfChatWin *chatwin = (ProfChatWin*)window;
+        assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
+
+        if (!chatwin->is_omemo) {
+            win_println(window, THEME_DEFAULT, '!', "You are not currently in an OMEMO session.");
+            return TRUE;
+        }
+
+        chatwin->is_omemo = FALSE;
+    } else if (window->type == WIN_MUC) {
+        ProfMucWin *mucwin = (ProfMucWin*)window;
+        assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
+
+        if (!mucwin->is_omemo) {
+            win_println(window, THEME_DEFAULT, '!', "You are not currently in an OMEMO session.");
+            return TRUE;
+        }
+
+        mucwin->is_omemo = FALSE;
+    } else {
+        win_println(window, THEME_DEFAULT, '-', "You must be in a regular chat window to start an OMEMO session.");
+        return TRUE;
+    }
+
+    return TRUE;
+#else
+    cons_show("This version of Profanity has not been built with OMEMO support enabled");
+    return TRUE;
+#endif
+}
+
+gboolean
 cmd_omemo_fingerprint(ProfWin *window, const char *const command, gchar **args)
 {
 #ifdef HAVE_OMEMO
diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h
index efa8cd83..21e7a51f 100644
--- a/src/command/cmd_funcs.h
+++ b/src/command/cmd_funcs.h
@@ -216,6 +216,7 @@ gboolean cmd_form_field(ProfWin *window, char *tag, gchar **args);
 
 gboolean cmd_omemo_gen(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_omemo_start(ProfWin *window, const char *const command, gchar **args);
+gboolean cmd_omemo_end(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_omemo_fingerprint(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_omemo_trust(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_omemo_untrust(ProfWin *window, const char *const command, gchar **args);