1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Switch to g_strerror

This commit is contained in:
William Wennerström 2020-07-21 11:15:48 +02:00
parent 3d344cfeaa
commit ab83afe21b
No known key found for this signature in database
GPG Key ID: E1382990BEDD319B
3 changed files with 23 additions and 53 deletions

View File

@ -9156,37 +9156,11 @@ cmd_url_open(ProfWin* window, const char* const command, gchar** args)
} }
void void
_url_open_fallback_method(ProfWin* window, const char* url) _url_open_fallback_method(ProfWin* window, const char* url, const char* filename)
{ {
/* // TODO(wstrm): Use _url_save_fallback_method?.
gboolean is_omemo_aesgcm = false; // We probably want to do the cmd_url_open in a separate thread and wait for
gchar* scheme = g_uri_parse_scheme(url); // the transfer to be finished before calling call_external.
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);
}
*/
} }
void void

View File

@ -68,9 +68,6 @@ aesgcm_file_get(void* userdata)
char* https_url = NULL; char* https_url = NULL;
char* fragment = 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) { if (omemo_parse_aesgcm_url(aesgcm_dl->url, &https_url, &fragment) != 0) {
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url, http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url,
"Download failed: Cannot parse URL '%s'.", "Download failed: Cannot parse URL '%s'.",
@ -78,24 +75,29 @@ aesgcm_file_get(void* userdata)
return NULL; return NULL;
} }
char* tmpname = NULL; gchar* tmpname = NULL;
if (g_file_open_tmp("profanity.XXXXXX", &tmpname, NULL) == -1) { gint tmpfd;
strerror_r(errno, err_buf, err_len); 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->url,
"Downloading '%s' failed: Unable to create " "Downloading '%s' failed: Unable to create "
"temporary ciphertext file for writing " "temporary ciphertext file for writing "
"(%s).", "(%s).",
https_url, err_buf); https_url, g_strerror(errno));
return NULL; 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"); FILE* outfh = fopen(aesgcm_dl->filename, "wb");
if (outfh == NULL) { if (outfh == NULL) {
strerror_r(errno, err_buf, err_len);
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url, http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url,
"Downloading '%s' failed: Unable to open " "Downloading '%s' failed: Unable to open "
"output file at '%s' for writing (%s).", "output file at '%s' for writing (%s).",
https_url, aesgcm_dl->filename, err_buf); https_url, aesgcm_dl->filename,
g_strerror(errno));
return NULL; return NULL;
} }
@ -111,11 +113,11 @@ aesgcm_file_get(void* userdata)
FILE* tmpfh = fopen(tmpname, "rb"); FILE* tmpfh = fopen(tmpname, "rb");
if (tmpfh == NULL) { if (tmpfh == NULL) {
strerror_r(errno, err_buf, err_len);
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url, http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url,
"Downloading '%s' failed: Unable to open " "Downloading '%s' failed: Unable to open "
"temporary file at '%s' for reading (%s).", "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; return NULL;
} }
@ -124,12 +126,11 @@ aesgcm_file_get(void* userdata)
http_dl->bytes_received, fragment); http_dl->bytes_received, fragment);
if (fclose(tmpfh) == EOF) { if (fclose(tmpfh) == EOF) {
strerror_r(errno, err_buf, err_len); cons_show_error(g_strerror(errno));
cons_show_error(err_buf);
} }
remove(tmpname); remove(tmpname);
free(tmpname); g_free(tmpname);
if (crypt_res != GPG_ERR_NO_ERROR) { 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->url,
@ -139,8 +140,7 @@ aesgcm_file_get(void* userdata)
} }
if (fclose(outfh) == EOF) { if (fclose(outfh) == EOF) {
strerror_r(errno, err_buf, err_len); cons_show_error(g_strerror(errno));
cons_show_error(err_buf);
} }
free(https_url); free(https_url);

View File

@ -103,9 +103,6 @@ http_file_get(void* userdata)
{ {
HTTPDownload* download = (HTTPDownload*)userdata; HTTPDownload* download = (HTTPDownload*)userdata;
const size_t err_len = 100;
char err_buf[err_len];
char* err = NULL; char* err = NULL;
CURL* curl; CURL* curl;
@ -120,11 +117,11 @@ http_file_get(void* userdata)
FILE* outfh = fopen(download->filename, "wb"); FILE* outfh = fopen(download->filename, "wb");
if (outfh == NULL) { if (outfh == NULL) {
strerror_r(errno, err_buf, err_len);
http_print_transfer_update(download->window, download->url, http_print_transfer_update(download->window, download->url,
"Downloading '%s' failed: Unable to open " "Downloading '%s' failed: Unable to open "
"output file at '%s' for writing (%s).", "output file at '%s' for writing (%s).",
download->url, download->filename, err_buf); download->url, download->filename,
g_strerror(errno));
return NULL; return NULL;
} }
@ -161,8 +158,7 @@ http_file_get(void* userdata)
curl_global_cleanup(); curl_global_cleanup();
if (fclose(outfh) == EOF) { if (fclose(outfh) == EOF) {
strerror_r(errno, err_buf, err_len); err = strdup(g_strerror(errno));
err = strdup(err_buf);
} }
pthread_mutex_lock(&lock); pthread_mutex_lock(&lock);