about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorIsaacM88 <izack23@gmail.com>2023-03-09 13:16:42 -0700
committerIsaacM88 <izack23@gmail.com>2023-03-09 15:02:26 -0700
commitd043d53948284ab7d1f3ae92c891703033cc98b1 (patch)
tree498b87e4012f5ae1f1a4b7ea1f5770ef26f889c2 /src/command
parent4887d21a119ed67756a1544ec953aa010257bcb1 (diff)
downloadprofani-tty-d043d53948284ab7d1f3ae92c891703033cc98b1.tar.gz
Fix duplicate download IDs.
Fixes https://github.com/profanity-im/profanity/issues/1794

Explanation
The problem is the download's identifier. Downloads are given an ID so they can be referenced later when their progress changes. Currently, the download's ID is the download's URL. When you download the same file twice, you have two downloads with the same ID. Download progress updates are shown on the first of both downloads with the same ID.

Solution
Change the download's ID from its URL to a random number. A random ID is generated when get_random_string() is called from cmd_funcs.c. Several other functions are updated to cope with the new ID format.
Diffstat (limited to 'src/command')
-rw-r--r--src/command/cmd_funcs.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 56a18bdb..dc471b90 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -9399,12 +9399,13 @@ cmd_slashguard(ProfWin* window, const char* const command, gchar** args)
 
 #ifdef HAVE_OMEMO
 void
-_url_aesgcm_method(ProfWin* window, const char* cmd_template, const char* url, const char* filename)
+_url_aesgcm_method(ProfWin* window, const char* cmd_template, const char* url, const char* filename, const char* id)
 {
     AESGCMDownload* download = malloc(sizeof(AESGCMDownload));
     download->window = window;
     download->url = strdup(url);
     download->filename = strdup(filename);
+    download->id = strdup(id);
     if (cmd_template != NULL) {
         download->cmd_template = strdup(cmd_template);
     } else {
@@ -9417,13 +9418,14 @@ _url_aesgcm_method(ProfWin* window, const char* cmd_template, const char* url, c
 #endif
 
 void
-_url_http_method(ProfWin* window, const char* cmd_template, const char* url, const char* filename)
+_url_http_method(ProfWin* window, const char* cmd_template, const char* url, const char* filename, const char* id)
 {
 
     HTTPDownload* download = malloc(sizeof(HTTPDownload));
     download->window = window;
     download->url = strdup(url);
     download->filename = strdup(filename);
+    download->id = strdup(id);
     if (cmd_template != NULL) {
         download->cmd_template = strdup(cmd_template);
     } else {
@@ -9499,7 +9501,9 @@ cmd_url_open(ProfWin* window, const char* const command, gchar** args)
 
         // Download, decrypt and open the cleartext version of the AESGCM
         // encrypted file.
-        _url_aesgcm_method(window, cmd_template, url, filename);
+        gchar* id = get_random_string(4);
+        _url_aesgcm_method(window, cmd_template, url, filename, id);
+        g_free(id);
         goto out;
     }
 #endif
@@ -9553,10 +9557,14 @@ cmd_url_save(ProfWin* window, const char* const command, gchar** args)
 
     cmd_template = prefs_get_string(PREF_URL_SAVE_CMD);
     if (cmd_template == NULL && (g_strcmp0(scheme, "http") == 0 || g_strcmp0(scheme, "https") == 0)) {
-        _url_http_method(window, cmd_template, url, filename);
+        gchar* id = get_random_string(4);
+        _url_http_method(window, cmd_template, url, filename, id);
+        g_free(id);
 #ifdef HAVE_OMEMO
     } else if (g_strcmp0(scheme, "aesgcm") == 0) {
-        _url_aesgcm_method(window, cmd_template, url, filename);
+        gchar* id = get_random_string(4);
+        _url_aesgcm_method(window, cmd_template, url, filename, id);
+        g_free(id);
 #endif
     } else if (cmd_template != NULL) {
         _url_external_method(cmd_template, url, filename);