From 306706bd2efa61f44a9234241d5de60c8e286abd Mon Sep 17 00:00:00 2001 From: Paul Fariello Date: Fri, 22 Mar 2019 19:20:23 +0140 Subject: [PATCH] Add OMEMO log command --- src/command/cmd_ac.c | 14 ++++++++++++++ src/command/cmd_defs.c | 4 ++++ src/command/cmd_funcs.c | 30 ++++++++++++++++++++++++++++++ src/command/cmd_funcs.h | 1 + 4 files changed, 49 insertions(+) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 8db9c035..86ef6ba9 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -159,6 +159,7 @@ static Autocomplete otr_ac; static Autocomplete otr_log_ac; static Autocomplete otr_policy_ac; static Autocomplete omemo_ac; +static Autocomplete omemo_log_ac; static Autocomplete connect_property_ac; static Autocomplete tls_property_ac; static Autocomplete alias_ac; @@ -578,12 +579,18 @@ cmd_ac_init(void) omemo_ac = autocomplete_new(); autocomplete_add(omemo_ac, "gen"); + autocomplete_add(omemo_ac, "log"); 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"); + omemo_log_ac = autocomplete_new(); + autocomplete_add(omemo_log_ac, "on"); + autocomplete_add(omemo_log_ac, "off"); + autocomplete_add(omemo_log_ac, "redact"); + connect_property_ac = autocomplete_new(); autocomplete_add(connect_property_ac, "server"); autocomplete_add(connect_property_ac, "port"); @@ -1063,6 +1070,7 @@ cmd_ac_reset(ProfWin *window) autocomplete_reset(otr_log_ac); autocomplete_reset(otr_policy_ac); autocomplete_reset(omemo_ac); + autocomplete_reset(omemo_log_ac); autocomplete_reset(connect_property_ac); autocomplete_reset(tls_property_ac); autocomplete_reset(alias_ac); @@ -1191,6 +1199,7 @@ cmd_ac_uninit(void) autocomplete_free(otr_log_ac); autocomplete_free(otr_policy_ac); autocomplete_free(omemo_ac); + autocomplete_free(omemo_log_ac); autocomplete_free(connect_property_ac); autocomplete_free(tls_property_ac); autocomplete_free(alias_ac); @@ -2144,6 +2153,11 @@ _omemo_autocomplete(ProfWin *window, const char *const input, gboolean previous) } } + found = autocomplete_param_with_ac(input, "/omemo log", omemo_log_ac, TRUE, previous); + if (found) { + return found; + } + found = autocomplete_param_with_ac(input, "/omemo", omemo_ac, TRUE, previous); if (found) { return found; diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 2d4ae061..311b404e 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2334,6 +2334,7 @@ static struct cmd_t command_defs[] = parse_args, 1, 3, NULL, CMD_SUBFUNCS( { "gen", cmd_omemo_gen }, + { "log", cmd_omemo_log }, { "start", cmd_omemo_start }, { "end", cmd_omemo_end }, { "trust", cmd_omemo_trust }, @@ -2345,6 +2346,7 @@ static struct cmd_t command_defs[] = CMD_TAG_UI) CMD_SYN( "/omemo gen", + "/omemo log on|off|redact", "/omemo start []", "/omemo trust [] ", "/omemo end", @@ -2355,6 +2357,8 @@ static struct cmd_t command_defs[] = { "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," }, + { "log on|off", "Enable or disable plaintext logging of OMEMO encrypted messages." }, + { "log redact", "Log OMEMO encrypted messages, but replace the contents with [redacted]. This is the default." }, { "fingerprint", "Show current device fingerprint." }) CMD_EXAMPLES( "/omemo gen", diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 49e20744..d254960d 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -7995,6 +7995,36 @@ cmd_omemo_start(ProfWin *window, const char *const command, gchar **args) #endif } +gboolean +cmd_omemo_log(ProfWin *window, const char *const command, gchar **args) +{ +#ifdef HAVE_OMEMO + char *choice = args[1]; + if (g_strcmp0(choice, "on") == 0) { + prefs_set_string(PREF_OMEMO_LOG, "on"); + cons_show("OMEMO messages will be logged as plaintext."); + if (!prefs_get_boolean(PREF_CHLOG)) { + cons_show("Chat logging is currently disabled, use '/chlog on' to enable."); + } + } else if (g_strcmp0(choice, "off") == 0) { + prefs_set_string(PREF_OMEMO_LOG, "off"); + cons_show("OMEMO message logging disabled."); + } else if (g_strcmp0(choice, "redact") == 0) { + prefs_set_string(PREF_OMEMO_LOG, "redact"); + cons_show("OMEMO messages will be logged as '[redacted]'."); + if (!prefs_get_boolean(PREF_CHLOG)) { + cons_show("Chat logging is currently disabled, use '/chlog on' to enable."); + } + } else { + cons_bad_cmd_usage(command); + } + return TRUE; +#else + cons_show("This version of Profanity has not been built with OMEMO support enabled"); + return TRUE; +#endif +} + gboolean cmd_omemo_end(ProfWin *window, const char *const command, gchar **args) { diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index 21e7a51f..3f3385a5 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -215,6 +215,7 @@ gboolean cmd_wins_swap(ProfWin *window, const char *const command, gchar **args) 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_log(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);