Pārlūkot izejas kodu

[image] Ensure every image has a fully resolved URI

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 gadus atpakaļ
vecāks
revīzija
c165e8d1fc
3 mainītis faili ar 25 papildinājumiem un 26 dzēšanām
  1. 4
    12
      src/core/downloader.c
  2. 1
    2
      src/include/ipxe/downloader.h
  3. 20
    12
      src/usr/imgmgmt.c

+ 4
- 12
src/core/downloader.c Parādīt failu

@@ -20,7 +20,6 @@
20 20
 FILE_LICENCE ( GPL2_OR_LATER );
21 21
 
22 22
 #include <stdlib.h>
23
-#include <stdarg.h>
24 23
 #include <errno.h>
25 24
 #include <syslog.h>
26 25
 #include <ipxe/iobuf.h>
@@ -229,17 +228,13 @@ static struct interface_descriptor downloader_job_desc =
229 228
  *
230 229
  * @v job		Job control interface
231 230
  * @v image		Image to fill with downloaded file
232
- * @v type		Location type to pass to xfer_open()
233
- * @v ...		Remaining arguments to pass to xfer_open()
234 231
  * @ret rc		Return status code
235 232
  *
236
- * Instantiates a downloader object to download the specified URI into
237
- * the specified image object.
233
+ * Instantiates a downloader object to download the content of the
234
+ * specified image from its URI.
238 235
  */
239
-int create_downloader ( struct interface *job, struct image *image,
240
-			int type, ... ) {
236
+int create_downloader ( struct interface *job, struct image *image ) {
241 237
 	struct downloader *downloader;
242
-	va_list args;
243 238
 	int rc;
244 239
 
245 240
 	/* Allocate and initialise structure */
@@ -252,21 +247,18 @@ int create_downloader ( struct interface *job, struct image *image,
252 247
 	intf_init ( &downloader->xfer, &downloader_xfer_desc,
253 248
 		    &downloader->refcnt );
254 249
 	downloader->image = image_get ( image );
255
-	va_start ( args, type );
256 250
 
257 251
 	/* Instantiate child objects and attach to our interfaces */
258
-	if ( ( rc = xfer_vopen ( &downloader->xfer, type, args ) ) != 0 )
252
+	if ( ( rc = xfer_open_uri ( &downloader->xfer, image->uri ) ) != 0 )
259 253
 		goto err;
260 254
 
261 255
 	/* Attach parent interface, mortalise self, and return */
262 256
 	intf_plug_plug ( &downloader->job, job );
263 257
 	ref_put ( &downloader->refcnt );
264
-	va_end ( args );
265 258
 	return 0;
266 259
 
267 260
  err:
268 261
 	downloader_finished ( downloader, rc );
269 262
 	ref_put ( &downloader->refcnt );
270
-	va_end ( args );
271 263
 	return rc;
272 264
 }

+ 1
- 2
src/include/ipxe/downloader.h Parādīt failu

@@ -12,7 +12,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
12 12
 struct interface;
13 13
 struct image;
14 14
 
15
-extern int create_downloader ( struct interface *job, struct image *image,
16
-			       int type, ... );
15
+extern int create_downloader ( struct interface *job, struct image *image );
17 16
 
18 17
 #endif /* _IPXE_DOWNLOADER_H */

+ 20
- 12
src/usr/imgmgmt.c Parādīt failu

@@ -48,13 +48,6 @@ int imgdownload ( struct uri *uri, struct image **image ) {
48 48
 	char *uri_string_redacted;
49 49
 	int rc;
50 50
 
51
-	/* Allocate image */
52
-	*image = alloc_image ( uri );
53
-	if ( ! *image ) {
54
-		rc = -ENOMEM;
55
-		goto err_alloc_image;
56
-	}
57
-
58 51
 	/* Construct redacted URI */
59 52
 	password = uri->password;
60 53
 	if ( password )
@@ -63,12 +56,25 @@ int imgdownload ( struct uri *uri, struct image **image ) {
63 56
 	uri->password = password;
64 57
 	if ( ! uri_string_redacted ) {
65 58
 		rc = -ENOMEM;
66
-		goto err_uri;
59
+		goto err_uri_string;
60
+	}
61
+
62
+	/* Resolve URI */
63
+	uri = resolve_uri ( cwuri, uri );
64
+	if ( ! uri ) {
65
+		rc = -ENOMEM;
66
+		goto err_resolve_uri;
67
+	}
68
+
69
+	/* Allocate image */
70
+	*image = alloc_image ( uri );
71
+	if ( ! *image ) {
72
+		rc = -ENOMEM;
73
+		goto err_alloc_image;
67 74
 	}
68 75
 
69 76
 	/* Create downloader */
70
-	if ( ( rc = create_downloader ( &monojob, *image, LOCATION_URI,
71
-					uri ) ) != 0 ) {
77
+	if ( ( rc = create_downloader ( &monojob, *image ) ) != 0 ) {
72 78
 		printf ( "Could not start download: %s\n", strerror ( rc ) );
73 79
 		goto err_create_downloader;
74 80
 	}
@@ -86,10 +92,12 @@ int imgdownload ( struct uri *uri, struct image **image ) {
86 92
  err_register_image:
87 93
  err_monojob_wait:
88 94
  err_create_downloader:
89
-	free ( uri_string_redacted );
90
- err_uri:
91 95
 	image_put ( *image );
92 96
  err_alloc_image:
97
+	uri_put ( uri );
98
+ err_resolve_uri:
99
+	free ( uri_string_redacted );
100
+ err_uri_string:
93 101
 	return rc;
94 102
 }
95 103
 

Notiek ielāde…
Atcelt
Saglabāt