From d043d53948284ab7d1f3ae92c891703033cc98b1 Mon Sep 17 00:00:00 2001 From: IsaacM88 Date: Thu, 9 Mar 2023 13:16:42 -0700 Subject: 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. --- src/command/cmd_funcs.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/command/cmd_funcs.c') 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); -- cgit 1.4.1-2-gfad0