Navigation Menu

Skip to content

Commit

Permalink
[xfer] Expose xfer_uri_opener()
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Jan 27, 2011
1 parent aa69bf8 commit 35a5039
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
53 changes: 39 additions & 14 deletions src/core/open.c
Expand Up @@ -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
*
Expand All @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/include/ipxe/open.h
Expand Up @@ -89,6 +89,7 @@ struct socket_opener {
/** Register a socket opener */
#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_string ( struct interface *intf,
const char *uri_string );
Expand Down

0 comments on commit 35a5039

Please sign in to comment.