aboutsummaryrefslogtreecommitdiffstats
path: root/src/tools
diff options
context:
space:
mode:
authorWilliam Wennerström <william@wstrm.dev>2020-12-03 16:43:07 +0100
committerWilliam Wennerström <william@wstrm.dev>2020-12-03 16:54:06 +0100
commit3a6597ee2967f91f49a1b4e17cf0595f37064587 (patch)
tree82d021e0c76b6980d908952edd4402272f14dcab /src/tools
parent1bb6cecee69d5167220a18cc4c125c215784de66 (diff)
downloadprofani-tty-3a6597ee2967f91f49a1b4e17cf0595f37064587.tar.gz
Refactor for threaded external executable for built-in download methods
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/aesgcm_download.c21
-rw-r--r--src/tools/aesgcm_download.h1
-rw-r--r--src/tools/http_common.h4
-rw-r--r--src/tools/http_download.c20
-rw-r--r--src/tools/http_download.h1
5 files changed, 45 insertions, 2 deletions
diff --git a/src/tools/aesgcm_download.c b/src/tools/aesgcm_download.c
index d6a85d06..d75cabe3 100644
--- a/src/tools/aesgcm_download.c
+++ b/src/tools/aesgcm_download.c
@@ -47,6 +47,7 @@
#include <gio/gio.h>
#include <pthread.h>
#include <assert.h>
+#include <errno.h>
#include "profanity.h"
#include "event/client_events.h"
@@ -146,8 +147,28 @@ aesgcm_file_get(void* userdata)
free(https_url);
free(fragment);
+ if (aesgcm_dl->cmd_template != NULL) {
+ gchar** argv = format_call_external_argv(aesgcm_dl->cmd_template,
+ aesgcm_dl->url,
+ aesgcm_dl->filename);
+
+ // TODO(wstrm): Log the error.
+ if (!call_external(argv, NULL, NULL)) {
+ http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url,
+ "Downloading '%s' failed: Unable to call "
+ "command '%s' with file at '%s' (%s).",
+ aesgcm_dl->url,
+ aesgcm_dl->cmd_template,
+ aesgcm_dl->filename,
+ "TODO(wstrm): Log the error");
+ }
+
+ g_strfreev(argv);
+ }
+
free(aesgcm_dl->filename);
free(aesgcm_dl->url);
+ free(aesgcm_dl->cmd_template);
free(aesgcm_dl);
return NULL;
diff --git a/src/tools/aesgcm_download.h b/src/tools/aesgcm_download.h
index e172b89a..c0096f1d 100644
--- a/src/tools/aesgcm_download.h
+++ b/src/tools/aesgcm_download.h
@@ -52,6 +52,7 @@ typedef struct aesgcm_download_t
{
char* url;
char* filename;
+ char* cmd_template;
ProfWin* window;
pthread_t worker;
HTTPDownload* http_dl;
diff --git a/src/tools/http_common.h b/src/tools/http_common.h
index 3fbc6fcd..c0a553de 100644
--- a/src/tools/http_common.h
+++ b/src/tools/http_common.h
@@ -40,7 +40,7 @@
char* http_basename_from_url(const char* url);
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_update(ProfWin* window, char* url, const char* fmt, ...);
+gchar** http_format_external_argv(const char* cmd, const char* url, const char* filename);
#endif
diff --git a/src/tools/http_download.c b/src/tools/http_download.c
index d14ab0e8..ef7e2906 100644
--- a/src/tools/http_download.c
+++ b/src/tools/http_download.c
@@ -47,6 +47,7 @@
#include <gio/gio.h>
#include <pthread.h>
#include <assert.h>
+#include <errno.h>
#include "profanity.h"
#include "event/client_events.h"
@@ -187,6 +188,25 @@ http_file_get(void* userdata)
download_processes = g_slist_remove(download_processes, download);
pthread_mutex_unlock(&lock);
+ if (download->cmd_template != NULL) {
+ gchar** argv = format_call_external_argv(download->cmd_template,
+ download->url,
+ download->filename);
+
+ // TODO(wstrm): Log the error.
+ if (!call_external(argv, NULL, NULL)) {
+ http_print_transfer_update(download->window, download->url,
+ "Downloading '%s' failed: Unable to call "
+ "command '%s' with file at '%s' (%s).",
+ download->url,
+ download->cmd_template,
+ download->filename,
+ "TODO(wstrm): Log the error");
+ }
+
+ g_strfreev(argv);
+ }
+
free(download->url);
free(download->filename);
free(download);
diff --git a/src/tools/http_download.h b/src/tools/http_download.h
index b6ce42ca..23344f6c 100644
--- a/src/tools/http_download.h
+++ b/src/tools/http_download.h
@@ -51,6 +51,7 @@ typedef struct http_download_t
{
char* url;
char* filename;
+ char* cmd_template;
curl_off_t bytes_received;
ProfWin* window;
pthread_t worker;