From bc541cb8ac6be40a2ee1e38a99de7cf144361a2a Mon Sep 17 00:00:00 2001 From: Paul Fariello Date: Tue, 19 Mar 2019 17:10:20 +0100 Subject: [PATCH] Add OMEMO end command --- src/command/cmd_ac.c | 1 + src/command/cmd_defs.c | 3 +++ src/command/cmd_funcs.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/command/cmd_funcs.h | 1 + 4 files changed, 46 insertions(+) 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 []", "/omemo trust [] ", + "/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 []", "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 @@ -7995,6 +7995,47 @@ cmd_omemo_start(ProfWin *window, const char *const command, gchar **args) #endif } +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) { 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);