]> git.ozlabs.org Git - petitboot/blobdiff - ui/common/loader.c
ui/common/url: Add pb_url_scheme_name
[petitboot] / ui / common / loader.c
index babca28a34950d0cd73fc88c8fa2f0be328f2b51..74b3c76ed63ddb44a84e70662b414df7ad81a8b0 100644 (file)
@@ -94,7 +94,7 @@ static char *pb_load_nfs(void *ctx, struct pb_url *url)
        *p++ = local;                   /* 7 */
        *p++ = NULL;                    /* 8 */
 
-       result = pb_run_cmd(argv);
+       result = pb_run_cmd(argv, 1, 0);
 
        talloc_free(opts);
 
@@ -122,7 +122,7 @@ fail:
 static char *pb_load_sftp(void *ctx, struct pb_url __attribute__((unused)) *url)
 {
        int result;
-       const char *argv[5];
+       const char *argv[4];
        const char **p;
        char *local;
 
@@ -132,13 +132,12 @@ static char *pb_load_sftp(void *ctx, struct pb_url __attribute__((unused)) *url)
                return NULL;
 
        p = argv;
-       *p++ = pb_system_apps.sftp;     /* 1 */
-       *p++ = url->host;               /* 2 */
-       *p++ = url->path;               /* 3 */
-       *p++ = local;                   /* 4 */
-       *p++ = NULL;                    /* 5 */
+       *p++ = pb_system_apps.sftp;                                     /* 1 */
+       *p++ = talloc_asprintf(local, "%s:%s", url->host, url->path);   /* 2 */
+       *p++ = local;                                                   /* 3 */
+       *p++ = NULL;                                                    /* 4 */
 
-       result = pb_run_cmd(argv);
+       result = pb_run_cmd(argv, 1, 0);
 
        if (result)
                goto fail;
@@ -183,7 +182,7 @@ static char *pb_load_tftp(void *ctx, struct pb_url *url)
                *p++ = url->port;       /* 8 */
        *p++ = NULL;                    /* 9 */
 
-       result = pb_run_cmd(argv);
+       result = pb_run_cmd(argv, 1, 0);
 
        if (!result)
                return local;
@@ -203,7 +202,7 @@ static char *pb_load_tftp(void *ctx, struct pb_url *url)
        *p++ = local;                   /* 9 */
        *p++ = NULL;                    /* 10 */
 
-       result = pb_run_cmd(argv);
+       result = pb_run_cmd(argv, 1, 0);
 
        if (!result)
                return local;
@@ -227,7 +226,7 @@ enum wget_flags {
 static char *pb_load_wget(void *ctx, struct pb_url *url, enum wget_flags flags)
 {
        int result;
-       const char *argv[6];
+       const char *argv[7];
        const char **p;
        char *local;
 
@@ -238,14 +237,17 @@ static char *pb_load_wget(void *ctx, struct pb_url *url, enum wget_flags flags)
 
        p = argv;
        *p++ = pb_system_apps.wget;                     /* 1 */
-       *p++ = "-O";                                    /* 2 */
-       *p++ = local;                                   /* 3 */
-       *p++ = url->full;                               /* 4 */
+#if !defined(DEBUG)
+       *p++ = "--quiet";                               /* 2 */
+#endif
+       *p++ = "-O";                                    /* 3 */
+       *p++ = local;                                   /* 4 */
+       *p++ = url->full;                               /* 5 */
        if (flags & wget_no_check_certificate)
-               *p++ = "--no-check-certificate";        /* 5 */
-       *p++ = NULL;                                    /* 6 */
+               *p++ = "--no-check-certificate";        /* 6 */
+       *p++ = NULL;                                    /* 7 */
 
-       result = pb_run_cmd(argv);
+       result = pb_run_cmd(argv, 1, 0);
 
        if (result)
                goto fail;
@@ -260,16 +262,22 @@ fail:
 /**
  * pb_load_file - Loads a remote file and returns the local file path.
  * @ctx: The talloc context to associate with the returned string.
+ * @remote: The remote file URL.
+ * @tempfile: An optional variable pointer to be set when a temporary local
+ *  file is created.
  *
  * Returns the local file path in a talloc'ed character string on success,
  * or NULL on error.
  */
 
-char *pb_load_file(void *ctx, const char *remote)
+char *pb_load_file(void *ctx, const char *remote, unsigned int *tempfile)
 {
        char *local;
        struct pb_url *url = pb_url_parse(NULL, remote);
 
+       if (tempfile)
+               *tempfile = 0;
+
        if (!url)
                return NULL;
 
@@ -277,19 +285,28 @@ char *pb_load_file(void *ctx, const char *remote)
        case pb_url_ftp:
        case pb_url_http:
                local = pb_load_wget(ctx, url, 0);
+               if (tempfile && local)
+                       *tempfile = 1;
                break;
        case pb_url_https:
-               local = pb_load_wget(ctx, url,
-                       wget_no_check_certificate);
+               local = pb_load_wget(ctx, url, wget_no_check_certificate);
+               if (tempfile && local)
+                       *tempfile = 1;
                break;
        case pb_url_nfs:
                local = pb_load_nfs(ctx, url);
+               if (tempfile && local)
+                       *tempfile = 1;
                break;
        case pb_url_sftp:
                local = pb_load_sftp(ctx, url);
+               if (tempfile && local)
+                       *tempfile = 1;
                break;
        case pb_url_tftp:
                local = pb_load_tftp(ctx, url);
+               if (tempfile && local)
+                       *tempfile = 1;
                break;
        default:
                local = talloc_strdup(ctx, url->full);