mirror of https://github.com/ipxe/ipxe.git
[xfer] Expose xfer_uri_opener()
Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/1/head
parent
aa69bf84d2
commit
35a50399a5
|
@ -32,6 +32,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
|
* Open URI
|
||||||
*
|
*
|
||||||
|
@ -45,29 +61,38 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
int xfer_open_uri ( struct interface *intf, struct uri *uri ) {
|
int xfer_open_uri ( struct interface *intf, struct uri *uri ) {
|
||||||
struct uri_opener *opener;
|
struct uri_opener *opener;
|
||||||
struct uri *resolved_uri;
|
struct uri *resolved_uri;
|
||||||
int rc = -ENOTSUP;
|
int rc;
|
||||||
|
|
||||||
/* Resolve URI */
|
/* Resolve URI */
|
||||||
resolved_uri = resolve_uri ( cwuri, uri );
|
resolved_uri = resolve_uri ( cwuri, uri );
|
||||||
if ( ! resolved_uri )
|
if ( ! resolved_uri ) {
|
||||||
return -ENOMEM;
|
rc = -ENOMEM;
|
||||||
|
goto err_resolve_uri;
|
||||||
|
}
|
||||||
|
|
||||||
/* Find opener which supports this URI scheme */
|
/* Find opener which supports this URI scheme */
|
||||||
for_each_table_entry ( opener, URI_OPENERS ) {
|
opener = xfer_uri_opener ( resolved_uri->scheme );
|
||||||
if ( strcmp ( resolved_uri->scheme, opener->scheme ) == 0 ) {
|
if ( ! opener ) {
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to open "
|
DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to open "
|
||||||
"unsupported URI scheme \"%s\"\n",
|
"unsupported URI scheme \"%s\"\n",
|
||||||
INTF_DBG ( intf ), resolved_uri->scheme );
|
INTF_DBG ( intf ), resolved_uri->scheme );
|
||||||
|
rc = -ENOTSUP;
|
||||||
|
goto err_opener;
|
||||||
|
}
|
||||||
|
|
||||||
done:
|
/* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
err_open:
|
||||||
|
err_opener:
|
||||||
uri_put ( resolved_uri );
|
uri_put ( resolved_uri );
|
||||||
|
err_resolve_uri:
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,7 @@ struct socket_opener {
|
||||||
/** Register a socket opener */
|
/** Register a socket opener */
|
||||||
#define __socket_opener __table_entry ( SOCKET_OPENERS, 01 )
|
#define __socket_opener __table_entry ( SOCKET_OPENERS, 01 )
|
||||||
|
|
||||||
|
extern struct uri_opener * xfer_uri_opener ( const char *scheme );
|
||||||
extern int xfer_open_uri ( struct interface *intf, struct uri *uri );
|
extern int xfer_open_uri ( struct interface *intf, struct uri *uri );
|
||||||
extern int xfer_open_uri_string ( struct interface *intf,
|
extern int xfer_open_uri_string ( struct interface *intf,
|
||||||
const char *uri_string );
|
const char *uri_string );
|
||||||
|
|
Loading…
Reference in New Issue