소스 검색

[xfer] Expose xfer_uri_opener()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 년 전
부모
커밋
35a50399a5
2개의 변경된 파일40개의 추가작업 그리고 14개의 파일을 삭제
  1. 39
    14
      src/core/open.c
  2. 1
    0
      src/include/ipxe/open.h

+ 39
- 14
src/core/open.c 파일 보기

@@ -32,6 +32,22 @@ FILE_LICENCE ( GPL2_OR_LATER );
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 52
  * Open URI
37 53
  *
@@ -45,29 +61,38 @@ FILE_LICENCE ( GPL2_OR_LATER );
45 61
 int xfer_open_uri ( struct interface *intf, struct uri *uri ) {
46 62
 	struct uri_opener *opener;
47 63
 	struct uri *resolved_uri;
48
-	int rc = -ENOTSUP;
64
+	int rc;
49 65
 
50 66
 	/* Resolve URI */
51 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 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 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 94
 	uri_put ( resolved_uri );
95
+ err_resolve_uri:
71 96
 	return rc;
72 97
 }
73 98
 

+ 1
- 0
src/include/ipxe/open.h 파일 보기

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

Loading…
취소
저장