diff options
author | Michael Brown | 2011-01-27 19:46:07 +0100 |
---|---|---|
committer | Michael Brown | 2011-01-27 19:46:07 +0100 |
commit | 35a50399a5881360303c0ed2d49918a660dd727d (patch) | |
tree | 3e503bea896139ebecc23e39bf40124ffc560607 /src/core/open.c | |
parent | [vxge] Add support for new function mode "multi-function 8 Direct IO" (diff) | |
download | ipxe-35a50399a5881360303c0ed2d49918a660dd727d.tar.gz ipxe-35a50399a5881360303c0ed2d49918a660dd727d.tar.xz ipxe-35a50399a5881360303c0ed2d49918a660dd727d.zip |
[xfer] Expose xfer_uri_opener()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/open.c')
-rw-r--r-- | src/core/open.c | 53 |
1 files changed, 39 insertions, 14 deletions
diff --git a/src/core/open.c b/src/core/open.c index f8ee9f3a..b026efcd 100644 --- a/src/core/open.c +++ b/src/core/open.c @@ -33,6 +33,22 @@ FILE_LICENCE ( GPL2_OR_LATER ); */ /** + * Find opener for URI scheme + * + * @v scheme URI scheme + * @ret opener Opener, or NULL + */ +struct uri_opener * xfer_uri_opener ( const char *scheme ) { + struct uri_opener *opener; + + for_each_table_entry ( opener, URI_OPENERS ) { + if ( strcmp ( scheme, opener->scheme ) == 0 ) + return opener; + } + return NULL; +} + +/** * Open URI * * @v intf Data transfer interface @@ -45,29 +61,38 @@ FILE_LICENCE ( GPL2_OR_LATER ); int xfer_open_uri ( struct interface *intf, struct uri *uri ) { struct uri_opener *opener; struct uri *resolved_uri; - int rc = -ENOTSUP; + int rc; /* Resolve URI */ resolved_uri = resolve_uri ( cwuri, uri ); - if ( ! resolved_uri ) - return -ENOMEM; + if ( ! resolved_uri ) { + rc = -ENOMEM; + goto err_resolve_uri; + } /* Find opener which supports this URI scheme */ - for_each_table_entry ( opener, URI_OPENERS ) { - if ( strcmp ( resolved_uri->scheme, opener->scheme ) == 0 ) { - DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT - " opening %s URI\n", INTF_DBG ( intf ), - resolved_uri->scheme ); - rc = opener->open ( intf, resolved_uri ); - goto done; - } + opener = xfer_uri_opener ( resolved_uri->scheme ); + if ( ! opener ) { + DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to open " + "unsupported URI scheme \"%s\"\n", + INTF_DBG ( intf ), resolved_uri->scheme ); + rc = -ENOTSUP; + goto err_opener; } - DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to open " - "unsupported URI scheme \"%s\"\n", + + /* Call opener */ + DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " opening %s URI\n", INTF_DBG ( intf ), resolved_uri->scheme ); + if ( ( rc = opener->open ( intf, resolved_uri ) ) != 0 ) { + DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " could not open: " + "%s\n", INTF_DBG ( intf ), strerror ( rc ) ); + goto err_open; + } - done: + err_open: + err_opener: uri_put ( resolved_uri ); + err_resolve_uri: return rc; } |