1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Add OMEMO log command

This commit is contained in:
Paul Fariello 2019-03-22 19:20:23 +01:40
parent dadd0c0590
commit 306706bd2e
4 changed files with 49 additions and 0 deletions

View File

@ -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;

View File

@ -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 [<contact>]",
"/omemo trust [<contact>] <fingerprint>",
"/omemo end",
@ -2355,6 +2357,8 @@ static struct cmd_t command_defs[] =
{ "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," },
{ "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",

View File

@ -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)
{

View File

@ -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);