about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-12-10 09:17:12 +0100
committerGitHub <noreply@github.com>2020-12-10 09:17:12 +0100
commitf0bfa6929673cdcf016b15ea4413e67c6a07291d (patch)
treed860654770066790a7ffb453fe461ef2ecd931ad /src/command
parentaa1f9071256596f5e94f602f10be38e2e43e9cfd (diff)
parenta1486012d2b92bd1472b3b33e90a237fccd12576 (diff)
downloadprofani-tty-f0bfa6929673cdcf016b15ea4413e67c6a07291d.tar.gz
Merge pull request #1450 from wstrm/issue-1449
Cast chat/muc window to correct type and refactor cmd_sendfile
Diffstat (limited to 'src/command')
-rw-r--r--src/command/cmd_funcs.c57
1 files changed, 33 insertions, 24 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 68153270..2397ccfc 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -4889,43 +4889,52 @@ cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
 
     FILE* fh = fdopen(fd, "rb");
 
+    gboolean omemo_enabled = FALSE;
+    gboolean sendfile_enabled = TRUE;
+
     switch (window->type) {
     case WIN_MUC:
+    {
+        ProfMucWin* mucwin = (ProfMucWin*)window;
+        assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
+        omemo_enabled = mucwin->is_omemo == TRUE;
+        break;
+    }
     case WIN_CHAT:
     {
         ProfChatWin* chatwin = (ProfChatWin*)window;
-
-#ifdef HAVE_OMEMO
-        if (chatwin->is_omemo) {
-            char* err = NULL;
-            alt_scheme = OMEMO_AESGCM_URL_SCHEME;
-            alt_fragment = _add_omemo_stream(&fd, &fh, &err);
-            if (err != NULL) {
-                cons_show_error(err);
-                win_println(window, THEME_ERROR, "-", err);
-                goto out;
-            }
-            break;
-        }
-#endif
-
-        if (window->type == WIN_CHAT) {
-            assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
-            if ((chatwin->pgp_send && !prefs_get_boolean(PREF_PGP_SENDFILE))
-                || (chatwin->is_otr && !prefs_get_boolean(PREF_OTR_SENDFILE))) {
-                cons_show_error("Uploading unencrypted files disabled. See /otr sendfile or /pgp sendfile.");
-                win_println(window, THEME_ERROR, "-", "Sending encrypted files via http_upload is not possible yet.");
-                goto out;
-            }
-        }
+        assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
+        omemo_enabled = chatwin->is_omemo == TRUE;
+        sendfile_enabled = !((chatwin->pgp_send == TRUE && !prefs_get_boolean(PREF_PGP_SENDFILE))
+                             || (chatwin->is_otr == TRUE && !prefs_get_boolean(PREF_OTR_SENDFILE)));
         break;
     }
+
     case WIN_PRIVATE: // We don't support encryption in private MUC windows.
     default:
         cons_show_error("Unsupported window for file transmission.");
         goto out;
     }
 
+    if (!sendfile_enabled) {
+        cons_show_error("Uploading unencrypted files disabled. See /otr sendfile or /pgp sendfile.");
+        win_println(window, THEME_ERROR, "-", "Sending encrypted files via http_upload is not possible yet.");
+        goto out;
+    }
+
+    if (omemo_enabled) {
+#ifdef HAVE_OMEMO
+        char* err = NULL;
+        alt_scheme = OMEMO_AESGCM_URL_SCHEME;
+        alt_fragment = _add_omemo_stream(&fd, &fh, &err);
+        if (err != NULL) {
+            cons_show_error(err);
+            win_println(window, THEME_ERROR, "-", err);
+            goto out;
+        }
+#endif
+    }
+
     HTTPUpload* upload = malloc(sizeof(HTTPUpload));
     upload->window = window;