Browse Source

Make URI structures reference-counted.

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
656485c1f1
5 changed files with 27 additions and 14 deletions
  1. 2
    2
      src/core/download.c
  2. 6
    3
      src/core/open.c
  3. 1
    1
      src/core/uri.c
  4. 0
    3
      src/include/gpxe/open.h
  5. 18
    5
      src/include/gpxe/uri.h

+ 2
- 2
src/core/download.c View File

121
  err:
121
  err:
122
 	async_uninit ( &download->async );
122
 	async_uninit ( &download->async );
123
 	ufree ( download->buffer.addr );
123
 	ufree ( download->buffer.addr );
124
-	free_uri ( download->uri );
124
+	uri_put ( download->uri );
125
 	free ( download );
125
 	free ( download );
126
 	return rc;
126
 	return rc;
127
 }
127
 }
150
 		/* Discard the buffer */
150
 		/* Discard the buffer */
151
 		ufree ( download->buffer.addr );
151
 		ufree ( download->buffer.addr );
152
 	}
152
 	}
153
-	free_uri ( download->uri );
153
+	uri_put ( download->uri );
154
 	download->uri = NULL;
154
 	download->uri = NULL;
155
 
155
 
156
 	/* Terminate ourselves */
156
 	/* Terminate ourselves */

+ 6
- 3
src/core/open.c View File

52
 int xfer_open_uri ( struct xfer_interface *xfer, const char *uri_string ) {
52
 int xfer_open_uri ( struct xfer_interface *xfer, const char *uri_string ) {
53
 	struct uri *uri;
53
 	struct uri *uri;
54
 	struct uri_opener *opener;
54
 	struct uri_opener *opener;
55
+	int rc = -ENOTSUP;
55
 
56
 
56
 	DBGC ( xfer, "XFER %p opening URI %s\n", xfer, uri_string );
57
 	DBGC ( xfer, "XFER %p opening URI %s\n", xfer, uri_string );
57
 
58
 
61
 
62
 
62
 	for ( opener = uri_openers ; opener < uri_openers_end ; opener++ ) {
63
 	for ( opener = uri_openers ; opener < uri_openers_end ; opener++ ) {
63
 		if ( strcmp ( uri->scheme, opener->scheme ) == 0 ) {
64
 		if ( strcmp ( uri->scheme, opener->scheme ) == 0 ) {
64
-			return opener->open ( xfer, uri );
65
+			rc = opener->open ( xfer, uri );
66
+			goto done;
65
 		}
67
 		}
66
 	}
68
 	}
67
 
69
 
68
 	DBGC ( xfer, "XFER %p attempted to open unsupported URI scheme "
70
 	DBGC ( xfer, "XFER %p attempted to open unsupported URI scheme "
69
 	       "\"%s\"\n", xfer, uri->scheme );
71
 	       "\"%s\"\n", xfer, uri->scheme );
70
-	free_uri ( uri );
71
-	return -ENOTSUP;
72
+ done:
73
+	uri_put ( uri );
74
+	return rc;
72
 }
75
 }
73
 
76
 
74
 /**
77
 /**

+ 1
- 1
src/core/uri.c View File

35
  *
35
  *
36
  * Splits a URI into its component parts.  The return URI structure is
36
  * Splits a URI into its component parts.  The return URI structure is
37
  * dynamically allocated and must eventually be freed by calling
37
  * dynamically allocated and must eventually be freed by calling
38
- * free_uri().
38
+ * uri_put().
39
  */
39
  */
40
 struct uri * parse_uri ( const char *uri_string ) {
40
 struct uri * parse_uri ( const char *uri_string ) {
41
 	struct uri *uri;
41
 	struct uri *uri;

+ 0
- 3
src/include/gpxe/open.h View File

46
 	 * @v xfer		Data transfer interface
46
 	 * @v xfer		Data transfer interface
47
 	 * @v uri		URI
47
 	 * @v uri		URI
48
 	 * @ret rc		Return status code
48
 	 * @ret rc		Return status code
49
-	 *
50
-	 * This method takes ownership of the URI structure, and is
51
-	 * responsible for eventually calling free_uri().
52
 	 */
49
 	 */
53
 	int ( * open ) ( struct xfer_interface *xfer, struct uri *uri );
50
 	int ( * open ) ( struct xfer_interface *xfer, struct uri *uri );
54
 };
51
 };

+ 18
- 5
src/include/gpxe/uri.h View File

8
  */
8
  */
9
 
9
 
10
 #include <stdlib.h>
10
 #include <stdlib.h>
11
+#include <gpxe/refcnt.h>
11
 
12
 
12
 /** A Uniform Resource Identifier
13
 /** A Uniform Resource Identifier
13
  *
14
  *
37
  *   query = "what=is", fragment = "this"
38
  *   query = "what=is", fragment = "this"
38
  */
39
  */
39
 struct uri {
40
 struct uri {
41
+	/** Reference count */
42
+	struct refcnt refcnt;
40
 	/** Scheme */
43
 	/** Scheme */
41
 	const char *scheme;
44
 	const char *scheme;
42
 	/** Opaque part */
45
 	/** Opaque part */
100
 }
103
 }
101
 
104
 
102
 /**
105
 /**
103
- * Free URI structure
106
+ * Increment URI reference count
104
  *
107
  *
105
  * @v uri		URI
108
  * @v uri		URI
109
+ * @ret uri		URI
110
+ */
111
+static inline __attribute__ (( always_inline )) struct uri *
112
+uri_get ( struct uri *uri ) {
113
+	ref_get ( &uri->refcnt );
114
+	return uri;
115
+}
116
+
117
+/**
118
+ * Decrement URI reference count
106
  *
119
  *
107
- * Frees all the dynamically-allocated storage used by the URI
108
- * structure.
120
+ * @v uri		URI
109
  */
121
  */
110
-static inline void free_uri ( struct uri *uri ) {
111
-	free ( uri );
122
+static inline __attribute__ (( always_inline )) void
123
+uri_put ( struct uri *uri ) {
124
+	ref_put ( &uri->refcnt );
112
 }
125
 }
113
 
126
 
114
 extern struct uri * parse_uri ( const char *uri_string );
127
 extern struct uri * parse_uri ( const char *uri_string );

Loading…
Cancel
Save