Browse Source

[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 years ago
parent
commit
323cdf8c4c

+ 1
- 1
src/arch/i386/interface/pxe/pxe_tftp.c View File

138
 
138
 
139
 static struct xfer_interface_operations pxe_tftp_xfer_ops = {
139
 static struct xfer_interface_operations pxe_tftp_xfer_ops = {
140
 	.close		= pxe_tftp_xfer_close,
140
 	.close		= pxe_tftp_xfer_close,
141
-	.vredirect	= xfer_vopen,
141
+	.vredirect	= xfer_vreopen,
142
 	.window		= unlimited_xfer_window,
142
 	.window		= unlimited_xfer_window,
143
 	.alloc_iob	= default_xfer_alloc_iob,
143
 	.alloc_iob	= default_xfer_alloc_iob,
144
 	.deliver_iob	= pxe_tftp_xfer_deliver_iob,
144
 	.deliver_iob	= pxe_tftp_xfer_deliver_iob,

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

205
 /** Downloader data transfer interface operations */
205
 /** Downloader data transfer interface operations */
206
 static struct xfer_interface_operations downloader_xfer_operations = {
206
 static struct xfer_interface_operations downloader_xfer_operations = {
207
 	.close		= downloader_xfer_close,
207
 	.close		= downloader_xfer_close,
208
-	.vredirect	= xfer_vopen,
208
+	.vredirect	= xfer_vreopen,
209
 	.window		= unlimited_xfer_window,
209
 	.window		= unlimited_xfer_window,
210
 	.alloc_iob	= default_xfer_alloc_iob,
210
 	.alloc_iob	= default_xfer_alloc_iob,
211
 	.deliver_iob	= downloader_xfer_deliver_iob,
211
 	.deliver_iob	= downloader_xfer_deliver_iob,

+ 28
- 0
src/core/open.c View File

53
 	/* Find opener which supports this URI scheme */
53
 	/* Find opener which supports this URI scheme */
54
 	for_each_table_entry ( opener, URI_OPENERS ) {
54
 	for_each_table_entry ( opener, URI_OPENERS ) {
55
 		if ( strcmp ( resolved_uri->scheme, opener->scheme ) == 0 ) {
55
 		if ( strcmp ( resolved_uri->scheme, opener->scheme ) == 0 ) {
56
+			DBGC ( xfer, "XFER %p opening %s URI\n",
57
+			       xfer, opener->scheme );
56
 			rc = opener->open ( xfer, resolved_uri );
58
 			rc = opener->open ( xfer, resolved_uri );
57
 			goto done;
59
 			goto done;
58
 		}
60
 		}
170
 	va_end ( args );
172
 	va_end ( args );
171
 	return rc;
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 View File

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

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

97
 			      struct sockaddr *peer, struct sockaddr *local );
97
 			      struct sockaddr *peer, struct sockaddr *local );
98
 extern int xfer_vopen ( struct xfer_interface *xfer, int type, va_list args );
98
 extern int xfer_vopen ( struct xfer_interface *xfer, int type, va_list args );
99
 extern int xfer_open ( struct xfer_interface *xfer, int type, ... );
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
 #endif /* _GPXE_OPEN_H */
103
 #endif /* _GPXE_OPEN_H */

+ 2
- 2
src/net/tcp/ftp.c View File

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

+ 1
- 1
src/net/tcp/http.c View File

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

+ 1
- 1
src/net/tcp/iscsi.c View File

1514
 		va_end ( tmp );
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 View File

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

+ 1
- 1
src/net/udp/dhcp.c View File

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

+ 1
- 1
src/net/udp/dns.c View File

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

+ 2
- 2
src/net/udp/slam.c View File

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

+ 2
- 2
src/net/udp/tftp.c View File

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

Loading…
Cancel
Save