aboutsummaryrefslogtreecommitdiffstats
path: root/src/command
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-02-17 08:44:26 +0100
committerMichael Vetter <jubalh@iodoru.org>2020-02-17 08:51:43 +0100
commit86bcadcbe3806439ca2039b39af08afd4db70429 (patch)
tree65cdedab59a065e06be84cc40e286a033308a13c /src/command
parent36713a2ed73368cf1892ce1fa43bb74106657391 (diff)
downloadprofani-tty-86bcadcbe3806439ca2039b39af08afd4db70429.tar.gz
Make /sendfile in OTR session configurable
`/otr sendfile on` allows unencrypted file transfer in an OMEMO session. Regards https://github.com/profanity-im/profanity/pull/1270
Diffstat (limited to 'src/command')
-rw-r--r--src/command/cmd_ac.c13
-rw-r--r--src/command/cmd_defs.c11
-rw-r--r--src/command/cmd_funcs.c18
-rw-r--r--src/command/cmd_funcs.h1
4 files changed, 37 insertions, 6 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index 0e65c3fd..7d170d10 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -173,6 +173,7 @@ static Autocomplete bookmark_property_ac;
static Autocomplete otr_ac;
static Autocomplete otr_log_ac;
static Autocomplete otr_policy_ac;
+static Autocomplete otr_sendfile_ac;
static Autocomplete omemo_ac;
static Autocomplete omemo_log_ac;
static Autocomplete omemo_policy_ac;
@@ -605,6 +606,7 @@ cmd_ac_init(void)
autocomplete_add(otr_ac, "question");
autocomplete_add(otr_ac, "answer");
autocomplete_add(otr_ac, "char");
+ autocomplete_add(otr_ac, "sendfile");
otr_log_ac = autocomplete_new();
autocomplete_add(otr_log_ac, "on");
@@ -616,6 +618,10 @@ cmd_ac_init(void)
autocomplete_add(otr_policy_ac, "opportunistic");
autocomplete_add(otr_policy_ac, "always");
+ otr_sendfile_ac = autocomplete_new();
+ autocomplete_add(otr_sendfile_ac, "on");
+ autocomplete_add(otr_sendfile_ac, "off");
+
omemo_ac = autocomplete_new();
autocomplete_add(omemo_ac, "gen");
autocomplete_add(omemo_ac, "log");
@@ -1190,6 +1196,7 @@ cmd_ac_reset(ProfWin *window)
autocomplete_reset(otr_ac);
autocomplete_reset(otr_log_ac);
autocomplete_reset(otr_policy_ac);
+ autocomplete_reset(otr_sendfile_ac);
autocomplete_reset(omemo_ac);
autocomplete_reset(omemo_log_ac);
autocomplete_reset(omemo_policy_ac);
@@ -1335,6 +1342,7 @@ cmd_ac_uninit(void)
autocomplete_free(otr_ac);
autocomplete_free(otr_log_ac);
autocomplete_free(otr_policy_ac);
+ autocomplete_free(otr_sendfile_ac);
autocomplete_free(omemo_ac);
autocomplete_free(omemo_log_ac);
autocomplete_free(omemo_policy_ac);
@@ -2234,6 +2242,11 @@ _otr_autocomplete(ProfWin *window, const char *const input, gboolean previous)
return found;
}
+ found = autocomplete_param_with_ac(input, "/otr sendfile", otr_sendfile_ac, TRUE, previous);
+ if (found) {
+ return found;
+ }
+
found = autocomplete_param_with_ac(input, "/otr", otr_ac, TRUE, previous);
if (found) {
return found;
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 5d3d0067..3897efc1 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -1695,7 +1695,8 @@ static struct cmd_t command_defs[] =
{ "untrust", cmd_otr_untrust },
{ "secret", cmd_otr_secret },
{ "question", cmd_otr_question },
- { "answer", cmd_otr_answer })
+ { "answer", cmd_otr_answer },
+ { "sendfile", cmd_otr_sendfile })
CMD_NOMAINFUNC
CMD_TAGS(
CMD_TAG_CHAT,
@@ -1712,7 +1713,8 @@ static struct cmd_t command_defs[] =
"/otr answer <answer>",
"/otr policy manual|opportunistic|always [<contact>]",
"/otr log on|off|redact",
- "/otr char <char>")
+ "/otr char <char>",
+ "/otr sendfile on|off")
CMD_DESC(
"Off The Record (OTR) commands to manage keys, and perform OTR encryption during chat sessions.")
CMD_ARGS(
@@ -1734,7 +1736,8 @@ static struct cmd_t command_defs[] =
{ "policy always <contact>", "Set the OTR policy to always for a specific contact." },
{ "log on|off", "Enable or disable plaintext logging of OTR encrypted messages." },
{ "log redact", "Log OTR encrypted messages, but replace the contents with [redacted]. This is the default." },
- { "char <char>", "Set the character to be displayed next to OTR encrypted messages." })
+ { "char <char>", "Set the character to be displayed next to OTR encrypted messages." },
+ { "sendfile on|off", "Allow /sendfile to send unencrypted files while in an OTR session."})
CMD_EXAMPLES(
"/otr log off",
"/otr policy manual",
@@ -2266,7 +2269,7 @@ static struct cmd_t command_defs[] =
{ "policy manual", "Set the global OMEMO policy to manual, OMEMO sessions must be started manually." },
{ "policy automatic", "Set the global OMEMO policy to opportunistic, an OMEMO session will be attempted upon starting a conversation." },
{ "policy always", "Set the global OMEMO policy to always, an error will be displayed if an OMEMO session cannot be initiated upon starting a conversation." },
- { "sendfile", "Allow /sendfile to send unencrypted files while in an OMEMO session."},
+ { "sendfile on|off", "Allow /sendfile to send unencrypted files while in an OMEMO session."},
{ "clear_device_list", "Clear your own device list on server side. Each client will reannounce itself when connected back."})
CMD_EXAMPLES(
"/omemo gen",
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index e5c540c3..e93397cb 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -4819,7 +4819,7 @@ cmd_sendfile(ProfWin *window, const char *const command, gchar **args)
if ((chatwin->is_omemo && !prefs_get_boolean(PREF_OMEMO_SENDFILE))
|| (chatwin->pgp_send)
- || (chatwin->is_otr)) {
+ || (chatwin->is_otr && !prefs_get_boolean(PREF_OTR_SENDFILE))) {
cons_show_error("Uploading '%s' failed: Encrypted file uploads not yet implemented!", filename);
win_println(window, THEME_ERROR, '-', "Sending encrypted files via http_upload is not possible yet.");
free(filename);
@@ -4829,7 +4829,8 @@ cmd_sendfile(ProfWin *window, const char *const command, gchar **args)
}
case WIN_PRIVATE:
{
- break; //we don't support encryption in private muc windows anyway
+ //we don't support encryption in private muc windows
+ break;
}
default:
cons_show_error("Unsupported window for file transmission.");
@@ -7810,6 +7811,19 @@ cmd_otr_answer(ProfWin *window, const char *const command, gchar **args)
}
gboolean
+cmd_otr_sendfile(ProfWin *window, const char *const command, gchar **args)
+{
+#ifdef HAVE_LIBOTR
+ _cmd_set_boolean_preference(args[1], command, "Sending unencrypted files in an OTR session via /sendfile", PREF_OTR_SENDFILE);
+
+ return TRUE;
+#else
+ cons_show("This version of Profanity has not been built with OTR support enabled");
+ return TRUE;
+#endif
+}
+
+gboolean
cmd_command_list(ProfWin *window, const char *const command, gchar **args)
{
jabber_conn_status_t conn_status = connection_get_status();
diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h
index 389c35de..58d99635 100644
--- a/src/command/cmd_funcs.h
+++ b/src/command/cmd_funcs.h
@@ -201,6 +201,7 @@ gboolean cmd_otr_untrust(ProfWin *window, const char *const command, gchar **arg
gboolean cmd_otr_secret(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_otr_question(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_otr_answer(ProfWin *window, const char *const command, gchar **args);
+gboolean cmd_otr_sendfile(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_wins(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_wins_unread(ProfWin *window, const char *const command, gchar **args);