Allow xfer_open() to take a struct uri as well as a URI string.
This commit is contained in:
parent
1ae549b892
commit
2c569fb240
@ -46,13 +46,33 @@ static struct socket_opener socket_openers_end[0]
|
|||||||
* Open URI
|
* Open URI
|
||||||
*
|
*
|
||||||
* @v xfer Data transfer interface
|
* @v xfer Data transfer interface
|
||||||
|
* @v uri URI
|
||||||
|
* @ret rc Return status code
|
||||||
|
*/
|
||||||
|
int xfer_open_uri ( struct xfer_interface *xfer, struct uri *uri ) {
|
||||||
|
struct uri_opener *opener;
|
||||||
|
|
||||||
|
for ( opener = uri_openers ; opener < uri_openers_end ; opener++ ) {
|
||||||
|
if ( strcmp ( uri->scheme, opener->scheme ) == 0 )
|
||||||
|
return opener->open ( xfer, uri );
|
||||||
|
}
|
||||||
|
|
||||||
|
DBGC ( xfer, "XFER %p attempted to open unsupported URI scheme "
|
||||||
|
"\"%s\"\n", xfer, uri->scheme );
|
||||||
|
return -ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open URI string
|
||||||
|
*
|
||||||
|
* @v xfer Data transfer interface
|
||||||
* @v uri_string URI string (e.g. "http://etherboot.org/kernel")
|
* @v uri_string URI string (e.g. "http://etherboot.org/kernel")
|
||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
*/
|
*/
|
||||||
int xfer_open_uri ( struct xfer_interface *xfer, const char *uri_string ) {
|
int xfer_open_uri_string ( struct xfer_interface *xfer,
|
||||||
|
const char *uri_string ) {
|
||||||
struct uri *uri;
|
struct uri *uri;
|
||||||
struct uri_opener *opener;
|
int rc;
|
||||||
int rc = -ENOTSUP;
|
|
||||||
|
|
||||||
DBGC ( xfer, "XFER %p opening URI %s\n", xfer, uri_string );
|
DBGC ( xfer, "XFER %p opening URI %s\n", xfer, uri_string );
|
||||||
|
|
||||||
@ -60,16 +80,8 @@ int xfer_open_uri ( struct xfer_interface *xfer, const char *uri_string ) {
|
|||||||
if ( ! uri )
|
if ( ! uri )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
for ( opener = uri_openers ; opener < uri_openers_end ; opener++ ) {
|
rc = xfer_open_uri ( xfer, uri );
|
||||||
if ( strcmp ( uri->scheme, opener->scheme ) == 0 ) {
|
|
||||||
rc = opener->open ( xfer, uri );
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DBGC ( xfer, "XFER %p attempted to open unsupported URI scheme "
|
|
||||||
"\"%s\"\n", xfer, uri->scheme );
|
|
||||||
done:
|
|
||||||
uri_put ( uri );
|
uri_put ( uri );
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -114,10 +126,12 @@ int xfer_open_socket ( struct xfer_interface *xfer, int semantics,
|
|||||||
*/
|
*/
|
||||||
int xfer_vopen ( struct xfer_interface *xfer, int type, va_list args ) {
|
int xfer_vopen ( struct xfer_interface *xfer, int type, va_list args ) {
|
||||||
switch ( type ) {
|
switch ( type ) {
|
||||||
case LOCATION_URI: {
|
case LOCATION_URI_STRING: {
|
||||||
const char *uri_string = va_arg ( args, const char * );
|
const char *uri_string = va_arg ( args, const char * );
|
||||||
|
|
||||||
return xfer_open_uri ( xfer, uri_string ); }
|
return xfer_open_uri_string ( xfer, uri_string ); }
|
||||||
|
case LOCATION_URI:
|
||||||
|
|
||||||
case LOCATION_SOCKET: {
|
case LOCATION_SOCKET: {
|
||||||
int semantics = va_arg ( args, int );
|
int semantics = va_arg ( args, int );
|
||||||
struct sockaddr *peer = va_arg ( args, struct sockaddr * );
|
struct sockaddr *peer = va_arg ( args, struct sockaddr * );
|
||||||
|
@ -224,7 +224,7 @@ int open ( const char *uri_string ) {
|
|||||||
INIT_LIST_HEAD ( &file->data );
|
INIT_LIST_HEAD ( &file->data );
|
||||||
|
|
||||||
/* Open URI on data transfer interface */
|
/* Open URI on data transfer interface */
|
||||||
if ( ( rc = xfer_open_uri ( &file->xfer, uri_string ) ) != 0 )
|
if ( ( rc = xfer_open_uri_string ( &file->xfer, uri_string ) ) != 0 )
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
/* Wait for open to succeed or fail */
|
/* Wait for open to succeed or fail */
|
||||||
|
@ -15,13 +15,20 @@ struct sockaddr;
|
|||||||
|
|
||||||
/** Location types */
|
/** Location types */
|
||||||
enum {
|
enum {
|
||||||
|
/** Location is a URI
|
||||||
|
*
|
||||||
|
* Parameter list for open() is:
|
||||||
|
*
|
||||||
|
* struct uri *uri;
|
||||||
|
*/
|
||||||
|
LOCATION_URI = 1,
|
||||||
/** Location is a URI string
|
/** Location is a URI string
|
||||||
*
|
*
|
||||||
* Parameter list for open() is:
|
* Parameter list for open() is:
|
||||||
*
|
*
|
||||||
* const char *uri_string;
|
* const char *uri_string;
|
||||||
*/
|
*/
|
||||||
LOCATION_URI = 1,
|
LOCATION_URI_STRING,
|
||||||
/** Location is a socket
|
/** Location is a socket
|
||||||
*
|
*
|
||||||
* Parameter list for open() is:
|
* Parameter list for open() is:
|
||||||
@ -73,7 +80,8 @@ struct socket_opener {
|
|||||||
/** Register a socket opener */
|
/** Register a socket opener */
|
||||||
#define __socket_opener __table ( struct socket_opener, socket_openers, 01 )
|
#define __socket_opener __table ( struct socket_opener, socket_openers, 01 )
|
||||||
|
|
||||||
extern int xfer_open_uri ( struct xfer_interface *xfer,
|
extern int xfer_open_uri ( struct xfer_interface *xfer, struct uri *uri );
|
||||||
|
extern int xfer_open_uri_string ( struct xfer_interface *xfer,
|
||||||
const char *uri_string );
|
const char *uri_string );
|
||||||
extern int xfer_open_named_socket ( struct xfer_interface *xfer,
|
extern int xfer_open_named_socket ( struct xfer_interface *xfer,
|
||||||
int semantics, struct sockaddr *peer,
|
int semantics, struct sockaddr *peer,
|
||||||
|
Reference in New Issue
Block a user