--------------------- PatchSet 5206 Date: 2002/10/03 12:39:00 Author: adri Branch: commloops Tag: (none) Log: Convert over the ftp code to use the new comm_accept framework. Members: src/ftp.c:1.20.10.4->1.20.10.5 Index: squid/src/ftp.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ftp.c,v retrieving revision 1.20.10.4 retrieving revision 1.20.10.5 diff -u -r1.20.10.4 -r1.20.10.5 --- squid/src/ftp.c 3 Oct 2002 07:29:21 -0000 1.20.10.4 +++ squid/src/ftp.c 3 Oct 2002 12:39:00 -0000 1.20.10.5 @@ -1,6 +1,6 @@ /* - * $Id: ftp.c,v 1.20.10.4 2002/10/03 07:29:21 adri Exp $ + * $Id: ftp.c,v 1.20.10.5 2002/10/03 12:39:00 adri Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -1892,42 +1892,39 @@ /* "read" handler to accept data connection */ static void -ftpAcceptDataConnection(int fd, void *data) +ftpAcceptDataConnection(int sock, int newfd, struct sockaddr_in *me, struct sockaddr_in *my_peer, + comm_err_t flag, int xerrno, void *data) { FtpStateData *ftpState = data; - struct sockaddr_in my_peer, me; debug(9, 3) ("ftpAcceptDataConnection\n"); if (EBIT_TEST(ftpState->entry->flags, ENTRY_ABORTED)) { comm_close(ftpState->ctrl.fd); return; } - fd = comm_old_accept(fd, &my_peer, &me); + if (Config.Ftp.sanitycheck) { - char *ipaddr = inet_ntoa(my_peer.sin_addr); + char *ipaddr = inet_ntoa(my_peer->sin_addr); if (strcmp(fd_table[ftpState->ctrl.fd].ipaddr, ipaddr) != 0) { - debug(9, 1) ("FTP data connection from unexpected server (%s:%d), expecting %s\n", ipaddr, (int) ntohs(my_peer.sin_port), fd_table[ftpState->ctrl.fd].ipaddr); - comm_close(fd); - commSetSelect(ftpState->data.fd, - COMM_SELECT_READ, - ftpAcceptDataConnection, - ftpState, - 0); + debug(9, 1) ("FTP data connection from unexpected server (%s:%d), expecting %s\n", ipaddr, (int) ntohs(my_peer->sin_port), fd_table[ftpState->ctrl.fd].ipaddr); + comm_close(newfd); + comm_accept(ftpState->data.fd, ftpAcceptDataConnection, ftpState); return; } } - if (fd < 0) { - debug(9, 1) ("ftpHandleDataAccept: comm_old_accept(%d): %s", fd, xstrerror()); + if (flag != COMM_OK) { + errno = xerrno; + debug(9, 1) ("ftpHandleDataAccept: comm_old_accept(%d): %s", newfd, xstrerror()); /* XXX Need to set error message */ ftpFail(ftpState); return; } /* Replace the Listen socket with the accepted data socket */ comm_close(ftpState->data.fd); - debug(9, 3) ("ftpAcceptDataConnection: Connected data socket on FD %d\n", fd); - ftpState->data.fd = fd; - ftpState->data.port = ntohs(my_peer.sin_port); - ftpState->data.host = xstrdup(inet_ntoa(my_peer.sin_addr)); + debug(9, 3) ("ftpAcceptDataConnection: Connected data socket on FD %d\n", newfd); + ftpState->data.fd = newfd; + ftpState->data.port = ntohs(my_peer->sin_port); + ftpState->data.host = xstrdup(inet_ntoa(my_peer->sin_addr)); commSetTimeout(ftpState->ctrl.fd, -1, NULL, NULL); commSetTimeout(ftpState->data.fd, Config.Timeout.read, ftpTimeout, ftpState); @@ -2006,11 +2003,7 @@ } else if (code == 150) { /* Accept data channel */ debug(9, 3) ("ftpReadStor: accepting data channel\n"); - commSetSelect(ftpState->data.fd, - COMM_SELECT_READ, - ftpAcceptDataConnection, - ftpState, - 0); + comm_accept(ftpState->data.fd, ftpAcceptDataConnection, ftpState); } else { debug(9, 3) ("ftpReadStor: Unexpected reply code %03d\n", code); ftpFail(ftpState); @@ -2112,11 +2105,7 @@ return; } else if (code == 150) { /* Accept data channel */ - commSetSelect(ftpState->data.fd, - COMM_SELECT_READ, - ftpAcceptDataConnection, - ftpState, - 0); + comm_accept(ftpState->data.fd, ftpAcceptDataConnection, ftpState); /* * Cancel the timeout on the Control socket and establish one * on the data socket @@ -2166,11 +2155,7 @@ ftpState); } else if (code == 150) { /* Accept data channel */ - commSetSelect(ftpState->data.fd, - COMM_SELECT_READ, - ftpAcceptDataConnection, - ftpState, - 0); + comm_accept(ftpState->data.fd, ftpAcceptDataConnection, ftpState); /* * Cancel the timeout on the Control socket and establish one * on the data socket