diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 1a554ce4..ada53f9d 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9156,37 +9156,11 @@ cmd_url_open(ProfWin* window, const char* const command, gchar** args) } void -_url_open_fallback_method(ProfWin* window, const char* url) +_url_open_fallback_method(ProfWin* window, const char* url, const char* filename) { - /* - gboolean is_omemo_aesgcm = false; - gchar* scheme = g_uri_parse_scheme(url); - if (g_strcmp0(scheme, "aesgcm")) { - is_omemo_aesgcm = true; - } - free(scheme); - - if (is_omemo_aesgcm) { - int tmpfd; - char* tmpname = NULL; - if ((tmpfd = g_file_open_tmp("profanity.XXXXXX", &tmpname, NULL)) == -1) { - *err = "Unable to create temporary file for decryption stream."; - return NULL; - } - FILE* tmpfh = fdopen(tmpfd, "wb"); - - unsigned char* nonce; - unsigned char* key; - char* https_url = omemo_parse_aesgcm_url(url, nonce, key); - - _url_save_fallback_method(window, https_url, tmpname); - - int crypt_res = omemo_decrypt_file(tmpfh, - - remove(tmpname); - free(tmpname); - } - */ + // TODO(wstrm): Use _url_save_fallback_method?. + // We probably want to do the cmd_url_open in a separate thread and wait for + // the transfer to be finished before calling call_external. } void diff --git a/src/tools/aesgcm_download.c b/src/tools/aesgcm_download.c index 6b60ba08..d6a85d06 100644 --- a/src/tools/aesgcm_download.c +++ b/src/tools/aesgcm_download.c @@ -68,9 +68,6 @@ aesgcm_file_get(void* userdata) char* https_url = NULL; char* fragment = NULL; - const size_t err_len = 100; - char err_buf[err_len]; - if (omemo_parse_aesgcm_url(aesgcm_dl->url, &https_url, &fragment) != 0) { http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url, "Download failed: Cannot parse URL '%s'.", @@ -78,24 +75,29 @@ aesgcm_file_get(void* userdata) return NULL; } - char* tmpname = NULL; - if (g_file_open_tmp("profanity.XXXXXX", &tmpname, NULL) == -1) { - strerror_r(errno, err_buf, err_len); + 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, "Downloading '%s' failed: Unable to create " "temporary ciphertext file for writing " "(%s).", - https_url, err_buf); + https_url, g_strerror(errno)); return NULL; + } else { + // TODO(wstrm): Maybe refactor this to use file handles so we do not + // have to open a dummy file descriptor and then close it. + // It's pretty ugly this way... + close(tmpfd); } FILE* outfh = fopen(aesgcm_dl->filename, "wb"); if (outfh == NULL) { - strerror_r(errno, err_buf, err_len); http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url, "Downloading '%s' failed: Unable to open " "output file at '%s' for writing (%s).", - https_url, aesgcm_dl->filename, err_buf); + https_url, aesgcm_dl->filename, + g_strerror(errno)); return NULL; } @@ -111,11 +113,11 @@ aesgcm_file_get(void* userdata) FILE* tmpfh = fopen(tmpname, "rb"); if (tmpfh == NULL) { - strerror_r(errno, err_buf, err_len); http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url, "Downloading '%s' failed: Unable to open " "temporary file at '%s' for reading (%s).", - aesgcm_dl->url, aesgcm_dl->filename, err_buf); + aesgcm_dl->url, aesgcm_dl->filename, + g_strerror(errno)); return NULL; } @@ -124,12 +126,11 @@ aesgcm_file_get(void* userdata) http_dl->bytes_received, fragment); if (fclose(tmpfh) == EOF) { - strerror_r(errno, err_buf, err_len); - cons_show_error(err_buf); + cons_show_error(g_strerror(errno)); } remove(tmpname); - free(tmpname); + g_free(tmpname); if (crypt_res != GPG_ERR_NO_ERROR) { http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url, @@ -139,8 +140,7 @@ aesgcm_file_get(void* userdata) } if (fclose(outfh) == EOF) { - strerror_r(errno, err_buf, err_len); - cons_show_error(err_buf); + cons_show_error(g_strerror(errno)); } free(https_url); diff --git a/src/tools/http_download.c b/src/tools/http_download.c index a470feec..d14ab0e8 100644 --- a/src/tools/http_download.c +++ b/src/tools/http_download.c @@ -103,9 +103,6 @@ http_file_get(void* userdata) { HTTPDownload* download = (HTTPDownload*)userdata; - const size_t err_len = 100; - char err_buf[err_len]; - char* err = NULL; CURL* curl; @@ -120,11 +117,11 @@ http_file_get(void* userdata) FILE* outfh = fopen(download->filename, "wb"); if (outfh == NULL) { - strerror_r(errno, err_buf, err_len); http_print_transfer_update(download->window, download->url, "Downloading '%s' failed: Unable to open " "output file at '%s' for writing (%s).", - download->url, download->filename, err_buf); + download->url, download->filename, + g_strerror(errno)); return NULL; } @@ -161,8 +158,7 @@ http_file_get(void* userdata) curl_global_cleanup(); if (fclose(outfh) == EOF) { - strerror_r(errno, err_buf, err_len); - err = strdup(err_buf); + err = strdup(g_strerror(errno)); } pthread_mutex_lock(&lock);