iPXE
Functions
downloader.h File Reference

Image downloader. More...

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
int create_downloader (struct interface *job, struct image *image)
 Instantiate a downloader.

Detailed Description

Image downloader.

Definition in file downloader.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
int create_downloader ( struct interface job,
struct image image 
)

Instantiate a downloader.

Parameters:
jobJob control interface
imageImage to fill with downloaded file
Return values:
rcReturn status code

Instantiates a downloader object to download the content of the specified image from its URI.

Definition at line 258 of file downloader.c.

References downloader::buffer, image::data, downloader_finished(), downloader_free(), ENOMEM, downloader::image, image_get(), intf_init(), intf_plug_plug(), downloader::job, rc, ref_init, ref_put, downloader::refcnt, image::uri, downloader::xfer, xfer_open_uri(), and zalloc().

Referenced by imgdownload().

                                                                     {
        struct downloader *downloader;
        int rc;

        /* Allocate and initialise structure */
        downloader = zalloc ( sizeof ( *downloader ) );
        if ( ! downloader )
                return -ENOMEM;
        ref_init ( &downloader->refcnt, downloader_free );
        intf_init ( &downloader->job, &downloader_job_desc,
                    &downloader->refcnt );
        intf_init ( &downloader->xfer, &downloader_xfer_desc,
                    &downloader->refcnt );
        downloader->image = image_get ( image );
        xferbuf_umalloc_init ( &downloader->buffer, &image->data );

        /* Instantiate child objects and attach to our interfaces */
        if ( ( rc = xfer_open_uri ( &downloader->xfer, image->uri ) ) != 0 )
                goto err;

        /* Attach parent interface, mortalise self, and return */
        intf_plug_plug ( &downloader->job, job );
        ref_put ( &downloader->refcnt );
        return 0;

 err:
        downloader_finished ( downloader, rc );
        ref_put ( &downloader->refcnt );
        return rc;
}