Przeglądaj źródła

[xfer] Implement xfer_vreopen() to properly handle redirections

When handling a redirection event, we need to close the existing
connection before opening the new connection.
tags/v0.9.8
Michael Brown 15 lat temu
rodzic
commit
323cdf8c4c

+ 1
- 1
src/arch/i386/interface/pxe/pxe_tftp.c Wyświetl plik

@@ -138,7 +138,7 @@ static void pxe_tftp_xfer_close ( struct xfer_interface *xfer __unused,
138 138
 
139 139
 static struct xfer_interface_operations pxe_tftp_xfer_ops = {
140 140
 	.close		= pxe_tftp_xfer_close,
141
-	.vredirect	= xfer_vopen,
141
+	.vredirect	= xfer_vreopen,
142 142
 	.window		= unlimited_xfer_window,
143 143
 	.alloc_iob	= default_xfer_alloc_iob,
144 144
 	.deliver_iob	= pxe_tftp_xfer_deliver_iob,

+ 1
- 1
src/core/downloader.c Wyświetl plik

@@ -205,7 +205,7 @@ static void downloader_xfer_close ( struct xfer_interface *xfer, int rc ) {
205 205
 /** Downloader data transfer interface operations */
206 206
 static struct xfer_interface_operations downloader_xfer_operations = {
207 207
 	.close		= downloader_xfer_close,
208
-	.vredirect	= xfer_vopen,
208
+	.vredirect	= xfer_vreopen,
209 209
 	.window		= unlimited_xfer_window,
210 210
 	.alloc_iob	= default_xfer_alloc_iob,
211 211
 	.deliver_iob	= downloader_xfer_deliver_iob,

+ 28
- 0
src/core/open.c Wyświetl plik

@@ -53,6 +53,8 @@ int xfer_open_uri ( struct xfer_interface *xfer, struct uri *uri ) {
53 53
 	/* Find opener which supports this URI scheme */
54 54
 	for_each_table_entry ( opener, URI_OPENERS ) {
55 55
 		if ( strcmp ( resolved_uri->scheme, opener->scheme ) == 0 ) {
56
+			DBGC ( xfer, "XFER %p opening %s URI\n",
57
+			       xfer, opener->scheme );
56 58
 			rc = opener->open ( xfer, resolved_uri );
57 59
 			goto done;
58 60
 		}
@@ -170,3 +172,29 @@ int xfer_open ( struct xfer_interface *xfer, int type, ... ) {
170 172
 	va_end ( args );
171 173
 	return rc;
172 174
 }
175
+
176
+/**
177
+ * Reopen location
178
+ *
179
+ * @v xfer		Data transfer interface
180
+ * @v type		Location type
181
+ * @v args		Remaining arguments depend upon location type
182
+ * @ret rc		Return status code
183
+ *
184
+ * This will close the existing connection and open a new connection
185
+ * using xfer_vopen().  It is intended to be used as a .vredirect
186
+ * method handler.
187
+ */
188
+int xfer_vreopen ( struct xfer_interface *xfer, int type, va_list args ) {
189
+	struct xfer_interface_operations *op = xfer->op;
190
+
191
+	/* Close existing connection */
192
+	xfer_nullify ( xfer );
193
+	xfer_close ( xfer, 0 );
194
+
195
+	/* Restore to operational status */
196
+	xfer->op = op;
197
+
198
+	/* Open new location */
199
+	return xfer_vopen ( xfer, type, args );
200
+}

+ 1
- 1
src/core/posix_io.c Wyświetl plik

@@ -137,7 +137,7 @@ posix_file_xfer_deliver_iob ( struct xfer_interface *xfer,
137 137
 /** POSIX file data transfer interface operations */
138 138
 static struct xfer_interface_operations posix_file_xfer_operations = {
139 139
 	.close		= posix_file_xfer_close,
140
-	.vredirect	= xfer_vopen,
140
+	.vredirect	= xfer_vreopen,
141 141
 	.window		= unlimited_xfer_window,
142 142
 	.alloc_iob	= default_xfer_alloc_iob,
143 143
 	.deliver_iob	= posix_file_xfer_deliver_iob,

+ 2
- 0
src/include/gpxe/open.h Wyświetl plik

@@ -97,5 +97,7 @@ extern int xfer_open_socket ( struct xfer_interface *xfer, int semantics,
97 97
 			      struct sockaddr *peer, struct sockaddr *local );
98 98
 extern int xfer_vopen ( struct xfer_interface *xfer, int type, va_list args );
99 99
 extern int xfer_open ( struct xfer_interface *xfer, int type, ... );
100
+extern int xfer_vreopen ( struct xfer_interface *xfer, int type,
101
+			  va_list args );
100 102
 
101 103
 #endif /* _GPXE_OPEN_H */

+ 2
- 2
src/net/tcp/ftp.c Wyświetl plik

@@ -335,7 +335,7 @@ static int ftp_control_deliver_raw ( struct xfer_interface *control,
335 335
 /** FTP control channel operations */
336 336
 static struct xfer_interface_operations ftp_control_operations = {
337 337
 	.close		= ftp_control_close,
338
-	.vredirect	= xfer_vopen,
338
+	.vredirect	= xfer_vreopen,
339 339
 	.window		= unlimited_xfer_window,
340 340
 	.alloc_iob	= default_xfer_alloc_iob,
341 341
 	.deliver_iob	= xfer_deliver_as_raw,
@@ -402,7 +402,7 @@ static int ftp_data_deliver_iob ( struct xfer_interface *data,
402 402
 /** FTP data channel operations */
403 403
 static struct xfer_interface_operations ftp_data_operations = {
404 404
 	.close		= ftp_data_closed,
405
-	.vredirect	= xfer_vopen,
405
+	.vredirect	= xfer_vreopen,
406 406
 	.window		= unlimited_xfer_window,
407 407
 	.alloc_iob	= default_xfer_alloc_iob,
408 408
 	.deliver_iob	= ftp_data_deliver_iob,

+ 1
- 1
src/net/tcp/http.c Wyświetl plik

@@ -464,7 +464,7 @@ static void http_socket_close ( struct xfer_interface *socket, int rc ) {
464 464
 /** HTTP socket operations */
465 465
 static struct xfer_interface_operations http_socket_operations = {
466 466
 	.close		= http_socket_close,
467
-	.vredirect	= xfer_vopen,
467
+	.vredirect	= xfer_vreopen,
468 468
 	.window		= unlimited_xfer_window,
469 469
 	.alloc_iob	= default_xfer_alloc_iob,
470 470
 	.deliver_iob	= http_socket_deliver_iob,

+ 1
- 1
src/net/tcp/iscsi.c Wyświetl plik

@@ -1514,7 +1514,7 @@ static int iscsi_vredirect ( struct xfer_interface *socket, int type,
1514 1514
 		va_end ( tmp );
1515 1515
 	}
1516 1516
 
1517
-	return xfer_vopen ( socket, type, args );
1517
+	return xfer_vreopen ( socket, type, args );
1518 1518
 }
1519 1519
 			     
1520 1520
 

+ 1
- 1
src/net/tls.c Wyświetl plik

@@ -1625,7 +1625,7 @@ static int tls_cipherstream_deliver_raw ( struct xfer_interface *xfer,
1625 1625
 /** TLS ciphertext stream operations */
1626 1626
 static struct xfer_interface_operations tls_cipherstream_operations = {
1627 1627
 	.close		= tls_cipherstream_close,
1628
-	.vredirect	= xfer_vopen,
1628
+	.vredirect	= xfer_vreopen,
1629 1629
 	.window		= filter_window,
1630 1630
 	.alloc_iob	= default_xfer_alloc_iob,
1631 1631
 	.deliver_iob	= xfer_deliver_as_raw,

+ 1
- 1
src/net/udp/dhcp.c Wyświetl plik

@@ -1107,7 +1107,7 @@ static int dhcp_deliver_iob ( struct xfer_interface *xfer,
1107 1107
 /** DHCP data transfer interface operations */
1108 1108
 static struct xfer_interface_operations dhcp_xfer_operations = {
1109 1109
 	.close		= ignore_xfer_close,
1110
-	.vredirect	= xfer_vopen,
1110
+	.vredirect	= xfer_vreopen,
1111 1111
 	.window		= unlimited_xfer_window,
1112 1112
 	.alloc_iob	= default_xfer_alloc_iob,
1113 1113
 	.deliver_iob	= dhcp_deliver_iob,

+ 1
- 1
src/net/udp/dns.c Wyświetl plik

@@ -459,7 +459,7 @@ static void dns_xfer_close ( struct xfer_interface *socket, int rc ) {
459 459
 /** DNS socket operations */
460 460
 static struct xfer_interface_operations dns_socket_operations = {
461 461
 	.close		= dns_xfer_close,
462
-	.vredirect	= xfer_vopen,
462
+	.vredirect	= xfer_vreopen,
463 463
 	.window		= unlimited_xfer_window,
464 464
 	.alloc_iob	= default_xfer_alloc_iob,
465 465
 	.deliver_iob	= xfer_deliver_as_raw,

+ 2
- 2
src/net/udp/slam.c Wyświetl plik

@@ -614,7 +614,7 @@ static void slam_socket_close ( struct xfer_interface *socket, int rc ) {
614 614
 /** SLAM unicast socket data transfer operations */
615 615
 static struct xfer_interface_operations slam_socket_operations = {
616 616
 	.close		= slam_socket_close,
617
-	.vredirect	= xfer_vopen,
617
+	.vredirect	= xfer_vreopen,
618 618
 	.window		= unlimited_xfer_window,
619 619
 	.alloc_iob	= default_xfer_alloc_iob,
620 620
 	.deliver_iob	= slam_socket_deliver,
@@ -640,7 +640,7 @@ static void slam_mc_socket_close ( struct xfer_interface *mc_socket, int rc ){
640 640
 /** SLAM multicast socket data transfer operations */
641 641
 static struct xfer_interface_operations slam_mc_socket_operations = {
642 642
 	.close		= slam_mc_socket_close,
643
-	.vredirect	= xfer_vopen,
643
+	.vredirect	= xfer_vreopen,
644 644
 	.window		= unlimited_xfer_window,
645 645
 	.alloc_iob	= default_xfer_alloc_iob,
646 646
 	.deliver_iob	= slam_mc_socket_deliver,

+ 2
- 2
src/net/udp/tftp.c Wyświetl plik

@@ -934,7 +934,7 @@ static int tftp_socket_deliver_iob ( struct xfer_interface *socket,
934 934
 /** TFTP socket operations */
935 935
 static struct xfer_interface_operations tftp_socket_operations = {
936 936
 	.close		= ignore_xfer_close,
937
-	.vredirect	= xfer_vopen,
937
+	.vredirect	= xfer_vreopen,
938 938
 	.window		= unlimited_xfer_window,
939 939
 	.alloc_iob	= default_xfer_alloc_iob,
940 940
 	.deliver_iob	= tftp_socket_deliver_iob,
@@ -961,7 +961,7 @@ static int tftp_mc_socket_deliver_iob ( struct xfer_interface *mc_socket,
961 961
 /** TFTP multicast socket operations */
962 962
 static struct xfer_interface_operations tftp_mc_socket_operations = {
963 963
 	.close		= ignore_xfer_close,
964
-	.vredirect	= xfer_vopen,
964
+	.vredirect	= xfer_vreopen,
965 965
 	.window		= unlimited_xfer_window,
966 966
 	.alloc_iob	= default_xfer_alloc_iob,
967 967
 	.deliver_iob	= tftp_mc_socket_deliver_iob,

Ładowanie…
Anuluj
Zapisz