Browse Source

[xfer] Expose xfer_uri_opener()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
35a50399a5
2 changed files with 40 additions and 14 deletions
  1. 39
    14
      src/core/open.c
  2. 1
    0
      src/include/ipxe/open.h

+ 39
- 14
src/core/open.c View File

32
  *
32
  *
33
  */
33
  */
34
 
34
 
35
+/**
36
+ * Find opener for URI scheme
37
+ *
38
+ * @v scheme		URI scheme
39
+ * @ret opener		Opener, or NULL
40
+ */
41
+struct uri_opener * xfer_uri_opener ( const char *scheme ) {
42
+	struct uri_opener *opener;
43
+
44
+	for_each_table_entry ( opener, URI_OPENERS ) {
45
+		if ( strcmp ( scheme, opener->scheme ) == 0 )
46
+			return opener;
47
+	}
48
+	return NULL;
49
+}
50
+
35
 /**
51
 /**
36
  * Open URI
52
  * Open URI
37
  *
53
  *
45
 int xfer_open_uri ( struct interface *intf, struct uri *uri ) {
61
 int xfer_open_uri ( struct interface *intf, struct uri *uri ) {
46
 	struct uri_opener *opener;
62
 	struct uri_opener *opener;
47
 	struct uri *resolved_uri;
63
 	struct uri *resolved_uri;
48
-	int rc = -ENOTSUP;
64
+	int rc;
49
 
65
 
50
 	/* Resolve URI */
66
 	/* Resolve URI */
51
 	resolved_uri = resolve_uri ( cwuri, uri );
67
 	resolved_uri = resolve_uri ( cwuri, uri );
52
-	if ( ! resolved_uri )
53
-		return -ENOMEM;
68
+	if ( ! resolved_uri ) {
69
+		rc = -ENOMEM;
70
+		goto err_resolve_uri;
71
+	}
54
 
72
 
55
 	/* Find opener which supports this URI scheme */
73
 	/* Find opener which supports this URI scheme */
56
-	for_each_table_entry ( opener, URI_OPENERS ) {
57
-		if ( strcmp ( resolved_uri->scheme, opener->scheme ) == 0 ) {
58
-			DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT
59
-			       " opening %s URI\n", INTF_DBG ( intf ),
60
-			       resolved_uri->scheme );
61
-			rc = opener->open ( intf, resolved_uri );
62
-			goto done;
63
-		}
74
+	opener = xfer_uri_opener ( resolved_uri->scheme );
75
+	if ( ! opener ) {
76
+		DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to open "
77
+		       "unsupported URI scheme \"%s\"\n",
78
+		       INTF_DBG ( intf ), resolved_uri->scheme );
79
+		rc = -ENOTSUP;
80
+		goto err_opener;
64
 	}
81
 	}
65
-	DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to open "
66
-	       "unsupported URI scheme \"%s\"\n",
82
+
83
+	/* Call opener */
84
+	DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " opening %s URI\n",
67
 	       INTF_DBG ( intf ), resolved_uri->scheme );
85
 	       INTF_DBG ( intf ), resolved_uri->scheme );
86
+	if ( ( rc = opener->open ( intf, resolved_uri ) ) != 0 ) {
87
+		DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " could not open: "
88
+		       "%s\n", INTF_DBG ( intf ), strerror ( rc ) );
89
+		goto err_open;
90
+	}
68
 
91
 
69
- done:
92
+ err_open:
93
+ err_opener:
70
 	uri_put ( resolved_uri );
94
 	uri_put ( resolved_uri );
95
+ err_resolve_uri:
71
 	return rc;
96
 	return rc;
72
 }
97
 }
73
 
98
 

+ 1
- 0
src/include/ipxe/open.h View File

89
 /** Register a socket opener */
89
 /** Register a socket opener */
90
 #define __socket_opener __table_entry ( SOCKET_OPENERS, 01 )
90
 #define __socket_opener __table_entry ( SOCKET_OPENERS, 01 )
91
 
91
 
92
+extern struct uri_opener * xfer_uri_opener ( const char *scheme );
92
 extern int xfer_open_uri ( struct interface *intf, struct uri *uri );
93
 extern int xfer_open_uri ( struct interface *intf, struct uri *uri );
93
 extern int xfer_open_uri_string ( struct interface *intf,
94
 extern int xfer_open_uri_string ( struct interface *intf,
94
 				  const char *uri_string );
95
 				  const char *uri_string );

Loading…
Cancel
Save