diff options
author | Michael Brown | 2016-01-09 14:22:37 +0100 |
---|---|---|
committer | Michael Brown | 2016-01-09 14:22:37 +0100 |
commit | 57fa0db03f9d0a4c73b7fea5b23f98941a1e0e22 (patch) | |
tree | 4d901ff55e12cb93724673e6c0ab865d4df29193 /src/core/image.c | |
parent | [http] Handle relative redirection URIs (diff) | |
download | ipxe-57fa0db03f9d0a4c73b7fea5b23f98941a1e0e22.tar.gz ipxe-57fa0db03f9d0a4c73b7fea5b23f98941a1e0e22.tar.xz ipxe-57fa0db03f9d0a4c73b7fea5b23f98941a1e0e22.zip |
[image] Provide image_set_uri() to modify an image's URI
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/image.c')
-rw-r--r-- | src/core/image.c | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/src/core/image.c b/src/core/image.c index 529e3d72..4a4e9c2a 100644 --- a/src/core/image.c +++ b/src/core/image.c @@ -88,7 +88,6 @@ static void free_image ( struct refcnt *refcnt ) { * @ret image Executable image */ struct image * alloc_image ( struct uri *uri ) { - const char *name; struct image *image; int rc; @@ -99,24 +98,43 @@ struct image * alloc_image ( struct uri *uri ) { /* Initialise image */ ref_init ( &image->refcnt, free_image ); - if ( uri ) { - image->uri = uri_get ( uri ); - if ( uri->path ) { - name = basename ( ( char * ) uri->path ); - if ( ( rc = image_set_name ( image, name ) ) != 0 ) - goto err_set_name; - } - } + if ( uri && ( ( rc = image_set_uri ( image, uri ) ) != 0 ) ) + goto err_set_uri; return image; - err_set_name: + err_set_uri: image_put ( image ); err_alloc: return NULL; } /** + * Set image URI + * + * @v image Image + * @v uri New image URI + * @ret rc Return status code + */ +int image_set_uri ( struct image *image, struct uri *uri ) { + const char *name; + int rc; + + /* Set name, if image does not already have one */ + if ( uri->path && ( ! ( image->name && image->name[0] ) ) ) { + name = basename ( ( char * ) uri->path ); + if ( ( rc = image_set_name ( image, name ) ) != 0 ) + return rc; + } + + /* Update image URI */ + uri_put ( image->uri ); + image->uri = uri_get ( uri ); + + return 0; +} + +/** * Set image name * * @v image Image |