about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-02-17 08:57:35 +0100
committerMichael Vetter <jubalh@iodoru.org>2020-02-17 08:57:35 +0100
commit7d596d8cef0c453ab2a4c57a7e5d51634e31af25 (patch)
tree14ec65a27e0735aec5ee068b641b51700dcef9ef /src/command
parent86bcadcbe3806439ca2039b39af08afd4db70429 (diff)
downloadprofani-tty-7d596d8cef0c453ab2a4c57a7e5d51634e31af25.tar.gz
Make /sendfile in PGP session configurable
`/pgp sendfile on` allows unencrypted file transfer in an PGP 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.c6
-rw-r--r--src/command/cmd_funcs.c7
3 files changed, 23 insertions, 3 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index 7d170d10..4d6c1d90 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -206,6 +206,7 @@ static Autocomplete inpblock_ac;
 static Autocomplete receipts_ac;
 static Autocomplete pgp_ac;
 static Autocomplete pgp_log_ac;
+static Autocomplete pgp_sendfile_ac;
 static Autocomplete tls_ac;
 static Autocomplete titlebar_ac;
 static Autocomplete titlebar_show_ac;
@@ -788,12 +789,17 @@ cmd_ac_init(void)
     autocomplete_add(pgp_ac, "end");
     autocomplete_add(pgp_ac, "log");
     autocomplete_add(pgp_ac, "char");
+    autocomplete_add(pgp_ac, "sendfile");
 
     pgp_log_ac = autocomplete_new();
     autocomplete_add(pgp_log_ac, "on");
     autocomplete_add(pgp_log_ac, "off");
     autocomplete_add(pgp_log_ac, "redact");
 
+    pgp_sendfile_ac = autocomplete_new();
+    autocomplete_add(pgp_sendfile_ac, "on");
+    autocomplete_add(pgp_sendfile_ac, "off");
+
     tls_ac = autocomplete_new();
     autocomplete_add(tls_ac, "allow");
     autocomplete_add(tls_ac, "always");
@@ -1229,6 +1235,7 @@ cmd_ac_reset(ProfWin *window)
     autocomplete_reset(receipts_ac);
     autocomplete_reset(pgp_ac);
     autocomplete_reset(pgp_log_ac);
+    autocomplete_reset(pgp_sendfile_ac);
     autocomplete_reset(tls_ac);
     autocomplete_reset(titlebar_ac);
     autocomplete_reset(titlebar_show_ac);
@@ -1374,6 +1381,7 @@ cmd_ac_uninit(void)
     autocomplete_free(receipts_ac);
     autocomplete_free(pgp_ac);
     autocomplete_free(pgp_log_ac);
+    autocomplete_free(pgp_sendfile_ac);
     autocomplete_free(tls_ac);
     autocomplete_free(titlebar_ac);
     autocomplete_free(titlebar_show_ac);
@@ -2274,6 +2282,11 @@ _pgp_autocomplete(ProfWin *window, const char *const input, gboolean previous)
         return found;
     }
 
+    found = autocomplete_param_with_ac(input, "/pgp sendfile", pgp_sendfile_ac, TRUE, previous);
+    if (found) {
+        return found;
+    }
+
 #ifdef HAVE_LIBGPGME
     gboolean result;
     gchar **args = parse_args(input, 2, 3, &result);
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 3897efc1..1e655a26 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -1657,7 +1657,8 @@ static struct cmd_t command_defs[] =
             "/pgp start [<contact>]",
             "/pgp end",
             "/pgp log on|off|redact",
-            "/pgp char <char>")
+            "/pgp char <char>",
+            "/pgp sendfile on|off")
         CMD_DESC(
             "Open PGP commands to manage keys, and perform PGP encryption during chat sessions. "
             "See the /account command to set your own PGP key.")
@@ -1670,7 +1671,8 @@ static struct cmd_t command_defs[] =
             { "end",                      "End PGP encrypted chat with the current recipient." },
             { "log on|off",               "Enable or disable plaintext logging of PGP encrypted messages." },
             { "log redact",               "Log PGP encrypted messages, but replace the contents with [redacted]. This is the default." },
-            { "char <char>",              "Set the character to be displayed next to PGP encrypted messages." })
+            { "char <char>",              "Set the character to be displayed next to PGP encrypted messages." },
+            { "sendfile on|off",          "Allow /sendfile to send unencrypted files while otherwise using PGP session."})
         CMD_EXAMPLES(
             "/pgp log off",
             "/pgp setkey buddy@buddychat.org BA19CACE5A9592C5",
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index e93397cb..7bc8a027 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -4818,7 +4818,7 @@ cmd_sendfile(ProfWin *window, const char *const command, gchar **args)
             assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
 
             if ((chatwin->is_omemo && !prefs_get_boolean(PREF_OMEMO_SENDFILE))
-                    || (chatwin->pgp_send)
+                    || (chatwin->pgp_send && !prefs_get_boolean(PREF_PGP_SENDFILE))
                     || (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.");
@@ -7337,6 +7337,11 @@ cmd_pgp(ProfWin *window, const char *const command, gchar **args)
         return TRUE;
     }
 
+    if (g_strcmp0(args[0], "sendfile") == 0) {
+        _cmd_set_boolean_preference(args[1], command, "Sending unencrypted files using /sendfile while otherwise using PGP", PREF_PGP_SENDFILE);
+        return TRUE;
+    }
+
     cons_bad_cmd_usage(command);
     return TRUE;
 #else