Browse Source

[image] Ensure every image has a fully resolved URI

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
c165e8d1fc
3 changed files with 25 additions and 26 deletions
  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 View File

20
 FILE_LICENCE ( GPL2_OR_LATER );
20
 FILE_LICENCE ( GPL2_OR_LATER );
21
 
21
 
22
 #include <stdlib.h>
22
 #include <stdlib.h>
23
-#include <stdarg.h>
24
 #include <errno.h>
23
 #include <errno.h>
25
 #include <syslog.h>
24
 #include <syslog.h>
26
 #include <ipxe/iobuf.h>
25
 #include <ipxe/iobuf.h>
229
  *
228
  *
230
  * @v job		Job control interface
229
  * @v job		Job control interface
231
  * @v image		Image to fill with downloaded file
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
  * @ret rc		Return status code
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
 	struct downloader *downloader;
237
 	struct downloader *downloader;
242
-	va_list args;
243
 	int rc;
238
 	int rc;
244
 
239
 
245
 	/* Allocate and initialise structure */
240
 	/* Allocate and initialise structure */
252
 	intf_init ( &downloader->xfer, &downloader_xfer_desc,
247
 	intf_init ( &downloader->xfer, &downloader_xfer_desc,
253
 		    &downloader->refcnt );
248
 		    &downloader->refcnt );
254
 	downloader->image = image_get ( image );
249
 	downloader->image = image_get ( image );
255
-	va_start ( args, type );
256
 
250
 
257
 	/* Instantiate child objects and attach to our interfaces */
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
 		goto err;
253
 		goto err;
260
 
254
 
261
 	/* Attach parent interface, mortalise self, and return */
255
 	/* Attach parent interface, mortalise self, and return */
262
 	intf_plug_plug ( &downloader->job, job );
256
 	intf_plug_plug ( &downloader->job, job );
263
 	ref_put ( &downloader->refcnt );
257
 	ref_put ( &downloader->refcnt );
264
-	va_end ( args );
265
 	return 0;
258
 	return 0;
266
 
259
 
267
  err:
260
  err:
268
 	downloader_finished ( downloader, rc );
261
 	downloader_finished ( downloader, rc );
269
 	ref_put ( &downloader->refcnt );
262
 	ref_put ( &downloader->refcnt );
270
-	va_end ( args );
271
 	return rc;
263
 	return rc;
272
 }
264
 }

+ 1
- 2
src/include/ipxe/downloader.h View File

12
 struct interface;
12
 struct interface;
13
 struct image;
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
 #endif /* _IPXE_DOWNLOADER_H */
17
 #endif /* _IPXE_DOWNLOADER_H */

+ 20
- 12
src/usr/imgmgmt.c View File

48
 	char *uri_string_redacted;
48
 	char *uri_string_redacted;
49
 	int rc;
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
 	/* Construct redacted URI */
51
 	/* Construct redacted URI */
59
 	password = uri->password;
52
 	password = uri->password;
60
 	if ( password )
53
 	if ( password )
63
 	uri->password = password;
56
 	uri->password = password;
64
 	if ( ! uri_string_redacted ) {
57
 	if ( ! uri_string_redacted ) {
65
 		rc = -ENOMEM;
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
 	/* Create downloader */
76
 	/* Create downloader */
70
-	if ( ( rc = create_downloader ( &monojob, *image, LOCATION_URI,
71
-					uri ) ) != 0 ) {
77
+	if ( ( rc = create_downloader ( &monojob, *image ) ) != 0 ) {
72
 		printf ( "Could not start download: %s\n", strerror ( rc ) );
78
 		printf ( "Could not start download: %s\n", strerror ( rc ) );
73
 		goto err_create_downloader;
79
 		goto err_create_downloader;
74
 	}
80
 	}
86
  err_register_image:
92
  err_register_image:
87
  err_monojob_wait:
93
  err_monojob_wait:
88
  err_create_downloader:
94
  err_create_downloader:
89
-	free ( uri_string_redacted );
90
- err_uri:
91
 	image_put ( *image );
95
 	image_put ( *image );
92
  err_alloc_image:
96
  err_alloc_image:
97
+	uri_put ( uri );
98
+ err_resolve_uri:
99
+	free ( uri_string_redacted );
100
+ err_uri_string:
93
 	return rc;
101
 	return rc;
94
 }
102
 }
95
 
103
 

Loading…
Cancel
Save