mirror of https://github.com/ipxe/ipxe.git
Make URI structures reference-counted.
parent
bc694ec768
commit
656485c1f1
|
@ -121,7 +121,7 @@ int start_download ( const char *uri_string, struct async *parent,
|
||||||
err:
|
err:
|
||||||
async_uninit ( &download->async );
|
async_uninit ( &download->async );
|
||||||
ufree ( download->buffer.addr );
|
ufree ( download->buffer.addr );
|
||||||
free_uri ( download->uri );
|
uri_put ( download->uri );
|
||||||
free ( download );
|
free ( download );
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ static void download_sigchld ( struct async *async,
|
||||||
/* Discard the buffer */
|
/* Discard the buffer */
|
||||||
ufree ( download->buffer.addr );
|
ufree ( download->buffer.addr );
|
||||||
}
|
}
|
||||||
free_uri ( download->uri );
|
uri_put ( download->uri );
|
||||||
download->uri = NULL;
|
download->uri = NULL;
|
||||||
|
|
||||||
/* Terminate ourselves */
|
/* Terminate ourselves */
|
||||||
|
|
|
@ -52,6 +52,7 @@ static struct socket_opener socket_openers_end[0]
|
||||||
int xfer_open_uri ( struct xfer_interface *xfer, const char *uri_string ) {
|
int xfer_open_uri ( struct xfer_interface *xfer, const char *uri_string ) {
|
||||||
struct uri *uri;
|
struct uri *uri;
|
||||||
struct uri_opener *opener;
|
struct uri_opener *opener;
|
||||||
|
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 );
|
||||||
|
|
||||||
|
@ -61,14 +62,16 @@ int xfer_open_uri ( struct xfer_interface *xfer, const char *uri_string ) {
|
||||||
|
|
||||||
for ( opener = uri_openers ; opener < uri_openers_end ; opener++ ) {
|
for ( opener = uri_openers ; opener < uri_openers_end ; opener++ ) {
|
||||||
if ( strcmp ( uri->scheme, opener->scheme ) == 0 ) {
|
if ( strcmp ( uri->scheme, opener->scheme ) == 0 ) {
|
||||||
return opener->open ( xfer, uri );
|
rc = opener->open ( xfer, uri );
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DBGC ( xfer, "XFER %p attempted to open unsupported URI scheme "
|
DBGC ( xfer, "XFER %p attempted to open unsupported URI scheme "
|
||||||
"\"%s\"\n", xfer, uri->scheme );
|
"\"%s\"\n", xfer, uri->scheme );
|
||||||
free_uri ( uri );
|
done:
|
||||||
return -ENOTSUP;
|
uri_put ( uri );
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
*
|
*
|
||||||
* Splits a URI into its component parts. The return URI structure is
|
* Splits a URI into its component parts. The return URI structure is
|
||||||
* dynamically allocated and must eventually be freed by calling
|
* dynamically allocated and must eventually be freed by calling
|
||||||
* free_uri().
|
* uri_put().
|
||||||
*/
|
*/
|
||||||
struct uri * parse_uri ( const char *uri_string ) {
|
struct uri * parse_uri ( const char *uri_string ) {
|
||||||
struct uri *uri;
|
struct uri *uri;
|
||||||
|
|
|
@ -46,9 +46,6 @@ struct uri_opener {
|
||||||
* @v xfer Data transfer interface
|
* @v xfer Data transfer interface
|
||||||
* @v uri URI
|
* @v uri URI
|
||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
*
|
|
||||||
* This method takes ownership of the URI structure, and is
|
|
||||||
* responsible for eventually calling free_uri().
|
|
||||||
*/
|
*/
|
||||||
int ( * open ) ( struct xfer_interface *xfer, struct uri *uri );
|
int ( * open ) ( struct xfer_interface *xfer, struct uri *uri );
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <gpxe/refcnt.h>
|
||||||
|
|
||||||
/** A Uniform Resource Identifier
|
/** A Uniform Resource Identifier
|
||||||
*
|
*
|
||||||
|
@ -37,6 +38,8 @@
|
||||||
* query = "what=is", fragment = "this"
|
* query = "what=is", fragment = "this"
|
||||||
*/
|
*/
|
||||||
struct uri {
|
struct uri {
|
||||||
|
/** Reference count */
|
||||||
|
struct refcnt refcnt;
|
||||||
/** Scheme */
|
/** Scheme */
|
||||||
const char *scheme;
|
const char *scheme;
|
||||||
/** Opaque part */
|
/** Opaque part */
|
||||||
|
@ -100,15 +103,25 @@ static inline int uri_has_relative_path ( struct uri *uri ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free URI structure
|
* Increment URI reference count
|
||||||
*
|
*
|
||||||
* @v uri URI
|
* @v uri URI
|
||||||
*
|
* @ret uri URI
|
||||||
* Frees all the dynamically-allocated storage used by the URI
|
|
||||||
* structure.
|
|
||||||
*/
|
*/
|
||||||
static inline void free_uri ( struct uri *uri ) {
|
static inline __attribute__ (( always_inline )) struct uri *
|
||||||
free ( uri );
|
uri_get ( struct uri *uri ) {
|
||||||
|
ref_get ( &uri->refcnt );
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrement URI reference count
|
||||||
|
*
|
||||||
|
* @v uri URI
|
||||||
|
*/
|
||||||
|
static inline __attribute__ (( always_inline )) void
|
||||||
|
uri_put ( struct uri *uri ) {
|
||||||
|
ref_put ( &uri->refcnt );
|
||||||
}
|
}
|
||||||
|
|
||||||
extern struct uri * parse_uri ( const char *uri_string );
|
extern struct uri * parse_uri ( const char *uri_string );
|
||||||
|
|
Loading…
Reference in New Issue