diff options
| author | Michael Brown | 2007-01-15 09:49:10 +0100 |
|---|---|---|
| committer | Michael Brown | 2007-01-15 09:49:10 +0100 |
| commit | 4e20d73bb52326261f8cf49c20d6de2edea309ee (patch) | |
| tree | 3d24466a78c4c8f53294384b76e62e871eb96def /src/usr/fetch.c | |
| parent | Add missing include (diff) | |
| download | ipxe-4e20d73bb52326261f8cf49c20d6de2edea309ee.tar.gz ipxe-4e20d73bb52326261f8cf49c20d6de2edea309ee.tar.xz ipxe-4e20d73bb52326261f8cf49c20d6de2edea309ee.zip | |
Gave asynchronous operations approximate POSIX signal semantics. This
will enable us to cascade async operations, which is necessary in order to
properly support DNS. (For example, an HTTP request may have to redirect
to a new location and will have to perform a new DNS lookup, so we can't
just rely on doing the name lookup at the time of parsing the initial
URL).
Anything other than HTTP is probably broken right now; I'll fix the others
up asap.
Diffstat (limited to 'src/usr/fetch.c')
| -rw-r--r-- | src/usr/fetch.c | 63 |
1 files changed, 36 insertions, 27 deletions
diff --git a/src/usr/fetch.c b/src/usr/fetch.c index ce0fea954..9e3c2de6f 100644 --- a/src/usr/fetch.c +++ b/src/usr/fetch.c @@ -23,10 +23,12 @@ * */ +#include <errno.h> #include <vsprintf.h> #include <gpxe/emalloc.h> #include <gpxe/ebuffer.h> #include <gpxe/image.h> +#include <gpxe/uri.h> #include <usr/fetch.h> #include <byteswap.h> @@ -46,32 +48,30 @@ * caller is responsible for eventually freeing the buffer with * efree(). */ -int fetch ( const char *filename, userptr_t *data, size_t *len ) { +int fetch ( const char *uri_string, userptr_t *data, size_t *len ) { + struct uri *uri; struct buffer buffer; int rc; + /* Parse the URI */ + uri = parse_uri ( uri_string ); + if ( ! uri ) { + rc = -ENOMEM; + goto err_parse_uri; + } + /* Allocate an expandable buffer to hold the file */ - if ( ( rc = ebuffer_alloc ( &buffer, 0 ) ) != 0 ) - return rc; + if ( ( rc = ebuffer_alloc ( &buffer, 0 ) ) != 0 ) { + goto err_ebuffer_alloc; + } #warning "Temporary pseudo-URL parsing code" /* Retrieve the file */ - union { - struct sockaddr_tcpip st; - struct sockaddr_in sin; - } server; - struct tftp_session tftp; - struct http_request http; - struct async_operation *aop; - - memset ( &tftp, 0, sizeof ( tftp ) ); - memset ( &http, 0, sizeof ( http ) ); - memset ( &server, 0, sizeof ( server ) ); - server.sin.sin_family = AF_INET; - find_global_dhcp_ipv4_option ( DHCP_EB_SIADDR, - &server.sin.sin_addr ); + struct async async; + int ( * download ) ( struct uri *uri, struct buffer *buffer, + struct async *parent ); #if 0 server.sin.sin_port = htons ( TFTP_PORT ); @@ -80,22 +80,31 @@ int fetch ( const char *filename, userptr_t *data, size_t *len ) { tftp.buffer = &buffer; aop = tftp_get ( &tftp ); #else - server.sin.sin_port = htons ( HTTP_PORT ); - memcpy ( &http.server, &server, sizeof ( http.server ) ); - http.hostname = inet_ntoa ( server.sin.sin_addr ); - http.filename = filename; - http.buffer = &buffer; - aop = http_get ( &http ); + download = http_get; #endif - if ( ( rc = async_wait ( aop ) ) != 0 ) { - efree ( buffer.addr ); - return rc; - } + async_init_orphan ( &async ); + if ( ( rc = download ( uri, &buffer, &async ) ) != 0 ) + goto err; + uri = NULL; + async_wait ( &async, &rc, 1 ); + if ( rc != 0 ) + goto err; /* Fill in buffer address and length */ *data = buffer.addr; *len = buffer.fill; + /* Release temporary resources. The ebuffer storage is now + * owned by our caller, so we don't free it. + */ + return 0; + + err: + efree ( buffer.addr ); + err_ebuffer_alloc: + free_uri ( uri ); + err_parse_uri: + return rc; } |
