diff options
author | William Wennerström <william@wstrm.dev> | 2020-06-11 22:50:36 +0200 |
---|---|---|
committer | William Wennerström <william@wstrm.dev> | 2020-11-16 21:58:07 +0100 |
commit | 3370418d71de255c832da97113543e554ec0e86b (patch) | |
tree | 0a364790895088cb0415b4ff31bfd40a588735bc /src/tools | |
parent | 35aecd425fad6697e9cf72832cb287a156ec7942 (diff) | |
download | profani-tty-3370418d71de255c832da97113543e554ec0e86b.tar.gz |
Initial /sendfile OMEMO encryption
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/http_upload.c | 20 | ||||
-rw-r--r-- | src/tools/http_upload.h | 10 |
2 files changed, 15 insertions, 15 deletions
diff --git a/src/tools/http_upload.c b/src/tools/http_upload.c index 312fad46..68de57ed 100644 --- a/src/tools/http_upload.c +++ b/src/tools/http_upload.c @@ -146,7 +146,7 @@ http_file_put(void* userdata) pthread_mutex_lock(&lock); char* msg; - if (asprintf(&msg, "Uploading '%s': 0%%", upload->filename) == -1) { + if (asprintf(&msg, "Uploading '%s': 0%%", upload->filepath) == -1) { msg = strdup(FALLBACK_MSG); } win_print_http_upload(upload->window, msg, upload->put_url); @@ -186,8 +186,8 @@ http_file_put(void* userdata) curl_easy_setopt(curl, CURLOPT_USERAGENT, "profanity"); - if (!(fd = fopen(upload->filename, "rb"))) { - if (asprintf(&err, "failed to open '%s'", upload->filename) == -1) { + if (!(fd = fopen(upload->filepath, "rb"))) { + if (asprintf(&err, "failed to open '%s'", upload->filepath) == -1) { err = NULL; } goto end; @@ -294,6 +294,7 @@ end: pthread_mutex_unlock(&lock); free(upload->filename); + free(upload->filepath); free(upload->mime_type); free(upload->get_url); free(upload->put_url); @@ -303,18 +304,18 @@ end: } char* -file_mime_type(const char* const file_name) +file_mime_type(const char* const filepath) { char* out_mime_type; char file_header[FILE_HEADER_BYTES]; - FILE* fd; - if (!(fd = fopen(file_name, "rb"))) { + FILE *fd; + if (!(fd = fopen(filepath, "rb"))) { return strdup(FALLBACK_MIMETYPE); } size_t file_header_size = fread(file_header, 1, FILE_HEADER_BYTES, fd); fclose(fd); - char* content_type = g_content_type_guess(file_name, (unsigned char*)file_header, file_header_size, NULL); + char *content_type = g_content_type_guess(filepath, (unsigned char*)file_header, file_header_size, NULL); if (content_type != NULL) { char* mime_type = g_content_type_get_mime_type(content_type); out_mime_type = strdup(mime_type); @@ -326,11 +327,10 @@ file_mime_type(const char* const file_name) return out_mime_type; } -off_t -file_size(const char* const filename) +off_t file_size(const char* const filepath) { struct stat st; - stat(filename, &st); + stat(filepath, &st); return st.st_size; } diff --git a/src/tools/http_upload.h b/src/tools/http_upload.h index 3838a5e8..cbab96ed 100644 --- a/src/tools/http_upload.h +++ b/src/tools/http_upload.h @@ -45,9 +45,9 @@ #include "ui/win_types.h" -typedef struct http_upload_t -{ - char* filename; +typedef struct http_upload_t { + char *filename; + char *filepath; off_t filesize; curl_off_t bytes_sent; char* mime_type; @@ -60,8 +60,8 @@ typedef struct http_upload_t void* http_file_put(void* userdata); -char* file_mime_type(const char* const file_name); -off_t file_size(const char* const file_name); +char* file_mime_type(const char* const filepath); +off_t file_size(const char* const filepath); void http_upload_cancel_processes(ProfWin* window); void http_upload_add_upload(HTTPUpload* upload); |