diff options
author | Michael Vetter <jubalh@iodoru.org> | 2023-03-10 07:50:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-10 07:50:30 +0100 |
commit | 96c1c44a9d1608475d61f4df7bc9114ed18c1821 (patch) | |
tree | 7f3e59fa4641501d630225e29fcb993ec8ec0655 /src/tools | |
parent | 792be5519ee767bb42305ef1d88eaf8570ff7cad (diff) | |
parent | d043d53948284ab7d1f3ae92c891703033cc98b1 (diff) | |
download | profani-tty-96c1c44a9d1608475d61f4df7bc9114ed18c1821.tar.gz |
Merge pull request #1795 from IsaacM88/master
Fix duplicate download IDs when using "/url save"
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/aesgcm_download.c | 14 | ||||
-rw-r--r-- | src/tools/aesgcm_download.h | 1 | ||||
-rw-r--r-- | src/tools/http_common.c | 8 | ||||
-rw-r--r-- | src/tools/http_common.h | 4 | ||||
-rw-r--r-- | src/tools/http_download.c | 15 | ||||
-rw-r--r-- | src/tools/http_download.h | 1 |
6 files changed, 24 insertions, 19 deletions
diff --git a/src/tools/aesgcm_download.c b/src/tools/aesgcm_download.c index e7b5b42c..da935156 100644 --- a/src/tools/aesgcm_download.c +++ b/src/tools/aesgcm_download.c @@ -71,7 +71,7 @@ aesgcm_file_get(void* userdata) // and tag stored in the URL fragment. if (omemo_parse_aesgcm_url(aesgcm_dl->url, &https_url, &fragment) != 0) { cons_show_error("Download failed: Cannot parse URL '%s'.", aesgcm_dl->url); - http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url, + http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id, "Download failed: Cannot parse URL '%s'.", aesgcm_dl->url); return NULL; @@ -82,7 +82,7 @@ aesgcm_file_get(void* userdata) gchar* tmpname = NULL; gint tmpfd; if ((tmpfd = g_file_open_tmp("profanity.XXXXXX", &tmpname, NULL)) == -1) { - http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url, + http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id, "Downloading '%s' failed: Unable to create " "temporary ciphertext file for writing " "(%s).", @@ -93,7 +93,7 @@ aesgcm_file_get(void* userdata) // Open the target file for storing the cleartext. FILE* outfh = fopen(aesgcm_dl->filename, "wb"); if (outfh == NULL) { - http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url, + http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id, "Downloading '%s' failed: Unable to open " "output file at '%s' for writing (%s).", https_url, aesgcm_dl->filename, @@ -106,6 +106,7 @@ aesgcm_file_get(void* userdata) HTTPDownload* http_dl = malloc(sizeof(HTTPDownload)); http_dl->window = aesgcm_dl->window; http_dl->worker = aesgcm_dl->worker; + http_dl->id = strdup(aesgcm_dl->id); http_dl->url = strdup(https_url); http_dl->filename = strdup(tmpname); http_dl->cmd_template = NULL; @@ -115,7 +116,7 @@ aesgcm_file_get(void* userdata) FILE* tmpfh = fopen(tmpname, "rb"); if (tmpfh == NULL) { - http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url, + http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id, "Downloading '%s' failed: Unable to open " "temporary file at '%s' for reading (%s).", aesgcm_dl->url, tmpname, @@ -136,7 +137,7 @@ aesgcm_file_get(void* userdata) g_free(tmpname); if (crypt_res != GPG_ERR_NO_ERROR) { - http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url, + http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id, "Downloading '%s' failed: Failed to decrypt " "file (%s).", https_url, gcry_strerror(crypt_res)); @@ -156,7 +157,7 @@ aesgcm_file_get(void* userdata) // TODO: Log the error. if (!call_external(argv)) { - http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url, + http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id, "Downloading '%s' failed: Unable to call " "command '%s' with file at '%s' (%s).", aesgcm_dl->url, @@ -169,6 +170,7 @@ aesgcm_file_get(void* userdata) free(aesgcm_dl->cmd_template); } + free(aesgcm_dl->id); free(aesgcm_dl->filename); free(aesgcm_dl->url); free(aesgcm_dl); diff --git a/src/tools/aesgcm_download.h b/src/tools/aesgcm_download.h index c0096f1d..796b9389 100644 --- a/src/tools/aesgcm_download.h +++ b/src/tools/aesgcm_download.h @@ -50,6 +50,7 @@ typedef struct aesgcm_download_t { + char* id; char* url; char* filename; char* cmd_template; diff --git a/src/tools/http_common.c b/src/tools/http_common.c index faad257f..4192a6ca 100644 --- a/src/tools/http_common.c +++ b/src/tools/http_common.c @@ -45,7 +45,7 @@ #define FALLBACK_MSG "" void -http_print_transfer_update(ProfWin* window, char* url, const char* fmt, ...) +http_print_transfer_update(ProfWin* window, char* id, const char* fmt, ...) { va_list args; @@ -54,13 +54,13 @@ http_print_transfer_update(ProfWin* window, char* url, const char* fmt, ...) g_string_vprintf(msg, fmt, args); va_end(args); - win_update_entry_message(window, url, msg->str); + win_update_entry_message(window, id, msg->str); g_string_free(msg, TRUE); } void -http_print_transfer(ProfWin* window, char* url, const char* fmt, ...) +http_print_transfer(ProfWin* window, char* id, const char* fmt, ...) { va_list args; @@ -69,7 +69,7 @@ http_print_transfer(ProfWin* window, char* url, const char* fmt, ...) g_string_vprintf(msg, fmt, args); va_end(args); - win_print_http_transfer(window, msg->str, url); + win_print_http_transfer(window, msg->str, id); g_string_free(msg, TRUE); } diff --git a/src/tools/http_common.h b/src/tools/http_common.h index ac51b5a8..733d4d17 100644 --- a/src/tools/http_common.h +++ b/src/tools/http_common.h @@ -38,7 +38,7 @@ #include "ui/window.h" -void http_print_transfer(ProfWin* window, char* url, const char* fmt, ...); -void http_print_transfer_update(ProfWin* window, char* url, const char* fmt, ...); +void http_print_transfer(ProfWin* window, char* id, const char* fmt, ...); +void http_print_transfer_update(ProfWin* window, char* id, const char* fmt, ...); #endif diff --git a/src/tools/http_download.c b/src/tools/http_download.c index 5a5b8ef8..71c9a1e1 100644 --- a/src/tools/http_download.c +++ b/src/tools/http_download.c @@ -112,12 +112,12 @@ http_file_get(void* userdata) download->bytes_received = 0; pthread_mutex_lock(&lock); - http_print_transfer(download->window, download->url, + http_print_transfer(download->window, download->id, "Downloading '%s': 0%%", download->url); FILE* outfh = fopen(download->filename, "wb"); if (outfh == NULL) { - http_print_transfer_update(download->window, download->url, + http_print_transfer_update(download->window, download->id, "Downloading '%s' failed: Unable to open " "output file at '%s' for writing (%s).", download->url, download->filename, @@ -177,22 +177,22 @@ http_file_get(void* userdata) g_free(cert_path); if (err) { if (download->cancel) { - http_print_transfer_update(download->window, download->url, + http_print_transfer_update(download->window, download->id, "Downloading '%s' failed: " "Download was canceled", download->url); } else { - http_print_transfer_update(download->window, download->url, + http_print_transfer_update(download->window, download->id, "Downloading '%s' failed: %s", download->url, err); } free(err); } else { if (!download->cancel) { - http_print_transfer_update(download->window, download->url, + http_print_transfer_update(download->window, download->id, "Downloading '%s': done\nSaved to '%s'", download->url, download->filename); - win_mark_received(download->window, download->url); + win_mark_received(download->window, download->id); } } @@ -203,7 +203,7 @@ http_file_get(void* userdata) // TODO: Log the error. if (!call_external(argv)) { - http_print_transfer_update(download->window, download->url, + http_print_transfer_update(download->window, download->id, "Downloading '%s' failed: Unable to call " "command '%s' with file at '%s' (%s).", download->url, @@ -221,6 +221,7 @@ out: download_processes = g_slist_remove(download_processes, download); pthread_mutex_unlock(&lock); + free(download->id); free(download->url); free(download->filename); free(download); diff --git a/src/tools/http_download.h b/src/tools/http_download.h index 23344f6c..2c8d8a3d 100644 --- a/src/tools/http_download.h +++ b/src/tools/http_download.h @@ -49,6 +49,7 @@ typedef struct http_download_t { + char* id; char* url; char* filename; char* cmd_template; |