err:
async_uninit ( &download->async );
ufree ( download->buffer.addr );
- free_uri ( download->uri );
+ uri_put ( download->uri );
free ( download );
return rc;
}
/* Discard the buffer */
ufree ( download->buffer.addr );
}
- free_uri ( download->uri );
+ uri_put ( download->uri );
download->uri = NULL;
/* Terminate ourselves */
int xfer_open_uri ( struct xfer_interface *xfer, const char *uri_string ) {
struct uri *uri;
struct uri_opener *opener;
+ int rc = -ENOTSUP;
DBGC ( xfer, "XFER %p opening URI %s\n", xfer, uri_string );
for ( opener = uri_openers ; opener < uri_openers_end ; opener++ ) {
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 "
"\"%s\"\n", xfer, uri->scheme );
- free_uri ( uri );
- return -ENOTSUP;
+ done:
+ uri_put ( uri );
+ return rc;
}
/**
*
* Splits a URI into its component parts. The return URI structure is
* dynamically allocated and must eventually be freed by calling
- * free_uri().
+ * uri_put().
*/
struct uri * parse_uri ( const char *uri_string ) {
struct uri *uri;
* @v xfer Data transfer interface
* @v uri URI
* @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 );
};
*/
#include <stdlib.h>
+#include <gpxe/refcnt.h>
/** A Uniform Resource Identifier
*
* query = "what=is", fragment = "this"
*/
struct uri {
+ /** Reference count */
+ struct refcnt refcnt;
/** Scheme */
const char *scheme;
/** Opaque part */
}
/**
- * Free URI structure
+ * Increment URI reference count
*
* @v uri URI
+ * @ret uri URI
+ */
+static inline __attribute__ (( always_inline )) struct uri *
+uri_get ( struct uri *uri ) {
+ ref_get ( &uri->refcnt );
+ return uri;
+}
+
+/**
+ * Decrement URI reference count
*
- * Frees all the dynamically-allocated storage used by the URI
- * structure.
+ * @v uri URI
*/
-static inline void free_uri ( struct uri *uri ) {
- free ( 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 );