about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorWilliam Wennerström <william@wstrm.dev>2020-12-07 16:16:15 +0100
committerWilliam Wennerström <william@wstrm.dev>2020-12-07 16:16:15 +0100
commit867d89546931a37fd255cdd5af382e39b66ae09b (patch)
tree14ace04e2c2ed7528ec380cefbf3f8eca3ca6e26 /src
parent4a1c118b8b575e3fa3c576106bce57efb786f225 (diff)
downloadprofani-tty-867d89546931a37fd255cdd5af382e39b66ae09b.tar.gz
Add tests for format_call_external_argv
Diffstat (limited to 'src')
-rw-r--r--src/command/cmd_funcs.c43
-rw-r--r--src/tools/aesgcm_download.c4
2 files changed, 30 insertions, 17 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 3cff1ab5..024137d2 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -4809,8 +4809,7 @@ cmd_disco(ProfWin* window, const char* const command, gchar** args)
     return TRUE;
 }
 
-// TODO(wstrm): Move this into its own tools such as HTTPUpload or
-// AESGCMDownload.
+// TODO: Move this into its own tools such as HTTPUpload or AESGCMDownload.
 #ifdef HAVE_OMEMO
 char*
 _add_omemo_stream(int* fd, FILE** fh, char** err)
@@ -9126,35 +9125,39 @@ cmd_url_open(ProfWin* window, const char* const command, gchar** args)
         return TRUE;
     }
 
-    gchar* scheme = g_uri_parse_scheme(url);
+    gchar* scheme = NULL;
+    char* cmd_template = NULL;
+    char* filename = NULL;
+
+    scheme = g_uri_parse_scheme(url);
     if (scheme == NULL) {
         cons_show("URL '%s' is not valid.", args[1]);
-        return TRUE;
+        goto out;
     }
 
-    char* cmd_template = prefs_get_string_with_option(PREF_URL_OPEN_CMD, scheme);
+    cmd_template = prefs_get_string_with_option(PREF_URL_OPEN_CMD, scheme);
     if (cmd_template == NULL) {
         cons_show("No default open command found in url open preferences");
-        return TRUE;
+        goto out;
     }
 
 #ifdef HAVE_OMEMO
     // OMEMO URLs (aesgcm://) must be saved and decrypted before being opened.
     if (0 == g_strcmp0(scheme, "aesgcm")) {
-        char* filename = unique_filename_from_url(url, files_get_data_path(DIR_DOWNLOADS));
+        filename = unique_filename_from_url(url, files_get_data_path(DIR_DOWNLOADS));
         _url_aesgcm_method(window, cmd_template, url, filename);
-        free(filename);
         goto out;
     }
 #endif
 
     _url_external_method(cmd_template, url, NULL);
 
-#ifdef HAVE_OMEMO
 out:
-#endif
+
     free(cmd_template);
-    free(scheme);
+    free(filename);
+
+    g_free(scheme);
 
     return TRUE;
 }
@@ -9174,21 +9177,25 @@ cmd_url_save(ProfWin* window, const char* const command, gchar** args)
 
     gchar* url = args[1];
     gchar* path = g_strdup(args[2]);
+    gchar* scheme = NULL;
+    char* filename = NULL;
+    char* cmd_template = NULL;
 
-    gchar* scheme = g_uri_parse_scheme(url);
+    scheme = g_uri_parse_scheme(url);
     if (scheme == NULL) {
         cons_show("URL '%s' is not valid.", args[1]);
-        return TRUE;
+        goto out;
     }
 
-    char* filename = unique_filename_from_url(url, path);
+    filename = unique_filename_from_url(url, path);
     if (filename == NULL) {
         cons_show("Failed to generate unique filename"
                   "from URL '%s' for path '%s'",
                   url, path);
+        goto out;
     }
 
-    char* cmd_template = prefs_get_string_with_option(PREF_URL_SAVE_CMD, scheme);
+    cmd_template = prefs_get_string_with_option(PREF_URL_SAVE_CMD, scheme);
     if (cmd_template == NULL) {
         if (g_strcmp0(scheme, "http") == 0
             || g_strcmp0(scheme, "https") == 0) {
@@ -9204,8 +9211,14 @@ cmd_url_save(ProfWin* window, const char* const command, gchar** args)
         _url_external_method(cmd_template, url, filename);
     }
 
+out:
+
+    free(filename);
     free(cmd_template);
 
+    g_free(scheme);
+    g_free(path);
+
     return TRUE;
 }
 
diff --git a/src/tools/aesgcm_download.c b/src/tools/aesgcm_download.c
index 20397b82..96f8d7e8 100644
--- a/src/tools/aesgcm_download.c
+++ b/src/tools/aesgcm_download.c
@@ -155,7 +155,7 @@ aesgcm_file_get(void* userdata)
                                                  aesgcm_dl->filename,
                                                  aesgcm_dl->filename);
 
-        // TODO(wstrm): Log the error.
+        // TODO: 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 "
@@ -163,7 +163,7 @@ aesgcm_file_get(void* userdata)
                                        aesgcm_dl->url,
                                        aesgcm_dl->cmd_template,
                                        aesgcm_dl->filename,
-                                       "TODO(wstrm): Log the error");
+                                       "TODO: Log the error");
         }
 
         g_strfreev(argv);