mirror of https://github.com/ipxe/ipxe.git
[image] Ensure every image has a fully resolved URI
Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/17/head
parent
7667536527
commit
c165e8d1fc
|
@ -20,7 +20,6 @@
|
||||||
FILE_LICENCE ( GPL2_OR_LATER );
|
FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <ipxe/iobuf.h>
|
#include <ipxe/iobuf.h>
|
||||||
|
@ -229,17 +228,13 @@ static struct interface_descriptor downloader_job_desc =
|
||||||
*
|
*
|
||||||
* @v job Job control interface
|
* @v job Job control interface
|
||||||
* @v image Image to fill with downloaded file
|
* @v image Image to fill with downloaded file
|
||||||
* @v type Location type to pass to xfer_open()
|
|
||||||
* @v ... Remaining arguments to pass to xfer_open()
|
|
||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
*
|
*
|
||||||
* Instantiates a downloader object to download the specified URI into
|
* Instantiates a downloader object to download the content of the
|
||||||
* the specified image object.
|
* specified image from its URI.
|
||||||
*/
|
*/
|
||||||
int create_downloader ( struct interface *job, struct image *image,
|
int create_downloader ( struct interface *job, struct image *image ) {
|
||||||
int type, ... ) {
|
|
||||||
struct downloader *downloader;
|
struct downloader *downloader;
|
||||||
va_list args;
|
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Allocate and initialise structure */
|
/* Allocate and initialise structure */
|
||||||
|
@ -252,21 +247,18 @@ int create_downloader ( struct interface *job, struct image *image,
|
||||||
intf_init ( &downloader->xfer, &downloader_xfer_desc,
|
intf_init ( &downloader->xfer, &downloader_xfer_desc,
|
||||||
&downloader->refcnt );
|
&downloader->refcnt );
|
||||||
downloader->image = image_get ( image );
|
downloader->image = image_get ( image );
|
||||||
va_start ( args, type );
|
|
||||||
|
|
||||||
/* Instantiate child objects and attach to our interfaces */
|
/* Instantiate child objects and attach to our interfaces */
|
||||||
if ( ( rc = xfer_vopen ( &downloader->xfer, type, args ) ) != 0 )
|
if ( ( rc = xfer_open_uri ( &downloader->xfer, image->uri ) ) != 0 )
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
/* Attach parent interface, mortalise self, and return */
|
/* Attach parent interface, mortalise self, and return */
|
||||||
intf_plug_plug ( &downloader->job, job );
|
intf_plug_plug ( &downloader->job, job );
|
||||||
ref_put ( &downloader->refcnt );
|
ref_put ( &downloader->refcnt );
|
||||||
va_end ( args );
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
downloader_finished ( downloader, rc );
|
downloader_finished ( downloader, rc );
|
||||||
ref_put ( &downloader->refcnt );
|
ref_put ( &downloader->refcnt );
|
||||||
va_end ( args );
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
struct interface;
|
struct interface;
|
||||||
struct image;
|
struct image;
|
||||||
|
|
||||||
extern int create_downloader ( struct interface *job, struct image *image,
|
extern int create_downloader ( struct interface *job, struct image *image );
|
||||||
int type, ... );
|
|
||||||
|
|
||||||
#endif /* _IPXE_DOWNLOADER_H */
|
#endif /* _IPXE_DOWNLOADER_H */
|
||||||
|
|
|
@ -48,13 +48,6 @@ int imgdownload ( struct uri *uri, struct image **image ) {
|
||||||
char *uri_string_redacted;
|
char *uri_string_redacted;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Allocate image */
|
|
||||||
*image = alloc_image ( uri );
|
|
||||||
if ( ! *image ) {
|
|
||||||
rc = -ENOMEM;
|
|
||||||
goto err_alloc_image;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Construct redacted URI */
|
/* Construct redacted URI */
|
||||||
password = uri->password;
|
password = uri->password;
|
||||||
if ( password )
|
if ( password )
|
||||||
|
@ -63,12 +56,25 @@ int imgdownload ( struct uri *uri, struct image **image ) {
|
||||||
uri->password = password;
|
uri->password = password;
|
||||||
if ( ! uri_string_redacted ) {
|
if ( ! uri_string_redacted ) {
|
||||||
rc = -ENOMEM;
|
rc = -ENOMEM;
|
||||||
goto err_uri;
|
goto err_uri_string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Resolve URI */
|
||||||
|
uri = resolve_uri ( cwuri, uri );
|
||||||
|
if ( ! uri ) {
|
||||||
|
rc = -ENOMEM;
|
||||||
|
goto err_resolve_uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Allocate image */
|
||||||
|
*image = alloc_image ( uri );
|
||||||
|
if ( ! *image ) {
|
||||||
|
rc = -ENOMEM;
|
||||||
|
goto err_alloc_image;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create downloader */
|
/* Create downloader */
|
||||||
if ( ( rc = create_downloader ( &monojob, *image, LOCATION_URI,
|
if ( ( rc = create_downloader ( &monojob, *image ) ) != 0 ) {
|
||||||
uri ) ) != 0 ) {
|
|
||||||
printf ( "Could not start download: %s\n", strerror ( rc ) );
|
printf ( "Could not start download: %s\n", strerror ( rc ) );
|
||||||
goto err_create_downloader;
|
goto err_create_downloader;
|
||||||
}
|
}
|
||||||
|
@ -86,10 +92,12 @@ int imgdownload ( struct uri *uri, struct image **image ) {
|
||||||
err_register_image:
|
err_register_image:
|
||||||
err_monojob_wait:
|
err_monojob_wait:
|
||||||
err_create_downloader:
|
err_create_downloader:
|
||||||
free ( uri_string_redacted );
|
|
||||||
err_uri:
|
|
||||||
image_put ( *image );
|
image_put ( *image );
|
||||||
err_alloc_image:
|
err_alloc_image:
|
||||||
|
uri_put ( uri );
|
||||||
|
err_resolve_uri:
|
||||||
|
free ( uri_string_redacted );
|
||||||
|
err_uri_string:
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue