diff options
| author | Michael Brown | 2006-12-05 20:07:47 +0100 |
|---|---|---|
| committer | Michael Brown | 2006-12-05 20:07:47 +0100 |
| commit | 89bcb57201d4175b08344eaf0ee4268abd7e8092 (patch) | |
| tree | 372ad6b3dbccb1ab08893e7ba999b58672882d0d /src/net | |
| parent | The VPD engine is broken and can't actually handle placing VPD (diff) | |
| download | ipxe-89bcb57201d4175b08344eaf0ee4268abd7e8092.tar.gz ipxe-89bcb57201d4175b08344eaf0ee4268abd7e8092.tar.xz ipxe-89bcb57201d4175b08344eaf0ee4268abd7e8092.zip | |
Update ftp.c to work with Nikhil's TCP stack.
Remove the now-totally-obsolete sockaddr_in field from tcp.h.
Diffstat (limited to 'src/net')
| -rw-r--r-- | src/net/tcp/ftp.c | 61 |
1 files changed, 43 insertions, 18 deletions
diff --git a/src/net/tcp/ftp.c b/src/net/tcp/ftp.c index 71a53ccf5..3ccae05e7 100644 --- a/src/net/tcp/ftp.c +++ b/src/net/tcp/ftp.c @@ -67,17 +67,22 @@ static inline struct ftp_request * tcp_to_ftp ( struct tcp_connection *conn ) { return container_of ( conn, struct ftp_request, tcp ); } +static void ftp_set_status ( struct ftp_request *ftp, int rc ) { + if ( ! ftp->rc ) + ftp->rc = rc; +} + +static void ftp_clear_status ( struct ftp_request *ftp ) { + ftp->rc = 0; +} + /** - * Mark FTP request as complete + * Mark FTP operation as complete * * @v ftp FTP request - * @v rc Return status code - * */ -static void ftp_done ( struct ftp_request *ftp, int rc ) { - tcp_close ( &ftp->tcp_data ); - tcp_close ( &ftp->tcp ); - async_done ( &ftp->aop, rc ); +static void ftp_done ( struct ftp_request *ftp ) { + async_done ( &ftp->aop, ftp->rc ); } /** @@ -128,13 +133,14 @@ static void ftp_reply ( struct ftp_request *ftp ) { /* Open passive connection when we get "PASV" response */ if ( ftp->state == FTP_PASV ) { char *ptr = ftp->passive_text; - - ftp_parse_value ( &ptr, - ( uint8_t * ) &ftp->tcp_data.sin.sin_addr, - sizeof ( ftp->tcp_data.sin.sin_addr ) ); - ftp_parse_value ( &ptr, - ( uint8_t * ) &ftp->tcp_data.sin.sin_port, - sizeof ( ftp->tcp_data.sin.sin_port ) ); + struct sockaddr_in *sin = + ( struct sockaddr_in * ) &ftp->tcp_data.peer; + + sin->sin_family = AF_INET; + ftp_parse_value ( &ptr, ( uint8_t * ) &sin->sin_addr, + sizeof ( sin->sin_addr ) ); + ftp_parse_value ( &ptr, ( uint8_t * ) &sin->sin_port, + sizeof ( sin->sin_port ) ); tcp_connect ( &ftp->tcp_data ); } @@ -146,7 +152,8 @@ static void ftp_reply ( struct ftp_request *ftp ) { err: /* Flag protocol error and close connections */ - ftp_done ( ftp, -EPROTO ); + ftp_set_status ( ftp, -EPROTO ); + tcp_close ( &ftp->tcp ); } /** @@ -249,7 +256,15 @@ static void ftp_senddata ( struct tcp_connection *conn, static void ftp_closed ( struct tcp_connection *conn, int status ) { struct ftp_request *ftp = tcp_to_ftp ( conn ); - ftp_done ( ftp, status ); + /* Close data channel and record status */ + ftp_set_status ( ftp, status ); + tcp_close ( &ftp->tcp_data ); + + /* Mark FTP operation as complete if we are the last + * connection to close + */ + if ( tcp_closed ( &ftp->tcp_data ) ) + ftp_done ( ftp ); } /** FTP control channel operations */ @@ -290,9 +305,18 @@ tcp_to_ftp_data ( struct tcp_connection *conn ) { */ static void ftp_data_closed ( struct tcp_connection *conn, int status ) { struct ftp_request *ftp = tcp_to_ftp_data ( conn ); + + /* If there was an error, close control channel and record status */ + if ( status ) { + ftp_set_status ( ftp, status ); + tcp_close ( &ftp->tcp ); + } - if ( status ) - ftp_done ( ftp, status ); + /* Mark FTP operation as complete if we are the last + * connection to close + */ + if ( tcp_closed ( &ftp->tcp ) ) + ftp_done ( ftp ); } /** @@ -333,6 +357,7 @@ struct async_operation * ftp_get ( struct ftp_request *ftp ) { ftp->tcp_data.tcp_op = &ftp_data_tcp_operations; ftp->recvbuf = ftp->status_text; ftp->recvsize = sizeof ( ftp->status_text ) - 1; + ftp_clear_status ( ftp ); tcp_connect ( &ftp->tcp ); return &ftp->aop; } |
