diff -N -c -r -X exclude_files squid-1.0.beta6/src/ftpget.c squid-1.0.beta6.henrik/src/ftpget.c *** squid-1.0.beta6/src/ftpget.c Fri May 3 22:30:30 1996 --- squid-1.0.beta6.henrik/src/ftpget.c Sat May 4 14:33:30 1996 *************** *** 164,173 **** FAIL_HARD /* do cache these */ } state_t; - #define DFD_TYPE_NONE 0 - #define DFD_TYPE_PASV 1 - #define DFD_TYPE_PORT 2 - typedef struct _request { char *host; int port; --- 164,169 ---- *************** *** 181,187 **** int cfd; int sfd; int dfd; - int dfd_type; int conn_att; int login_att; state_t state; --- 177,182 ---- *************** *** 951,956 **** --- 946,991 ---- } /* + * close_dfd() + * Close any open data channel + */ + void close_dfd(r) + request_t *r; + { + if(r->dfd>=0) + close(r->dfd); + r->flags&=~F_NEEDACCEPT; + r->dfd=-1; + } + + /* + * is_dfd_open() + * Check if a data channel is already open + */ + int is_dfd_open(r) + request_t *r; + { + if (r->dfd >= 0 && !(r->flags&F_NEEDACCEPT)) { + fd_set R; + struct timeval tv; + FD_ZERO(&R); + FD_SET(r->dfd, &R); + tv.tv_sec = 0; + tv.tv_usec = 0; + if (select(r->dfd + 1, &R, NULL, NULL, &tv) == 0) { + Debug(26, 3, ("Data channel already connected (FD=%d)\n", r->dfd)); + return 1; + } else { + Debug(26, 2, ("Data channel closed by server (%s)\n", xstrerror())); + } + } else if(r->dfd >= 0) { + Debug(26, 2, ("Data socket not connected, closing\n")); + } + close_dfd(r); + return 0; + } + + /* * parse_request() * Perform validity checks on request parameters. * - lookup hostname *************** *** 1178,1201 **** int port = 0; static int init = 0; ! if (r->dfd >= 0 && r->dfd_type == DFD_TYPE_PORT) { ! fd_set R; ! struct timeval tv; ! FD_ZERO(&R); ! FD_SET(r->dfd, &R); ! tv.tv_sec = 0; ! tv.tv_usec = 0; ! if (select(r->dfd + 1, &R, NULL, NULL, &tv) == 0) { ! Debug(26, 3, ("do_port: FD %d Already connected\n", r->dfd)); ! r->flags |= F_NEEDACCEPT; ! return PORT_OK; ! } else { ! Debug(26, 2, ("Data connection closed by server (%s)\n", xstrerror())); ! close(r->dfd); ! r->dfd = -1; ! r->dfd_type = DFD_TYPE_NONE; ! } ! } if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) { r->errmsg = (char *) xmalloc(SMALLBUFSIZ); sprintf(r->errmsg, "socket: %s", xstrerror()); --- 1213,1221 ---- int port = 0; static int init = 0; ! if (is_dfd_open(r)) ! return PORT_OK; ! if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) { r->errmsg = (char *) xmalloc(SMALLBUFSIZ); sprintf(r->errmsg, "socket: %s", xstrerror()); *************** *** 1250,1256 **** if ((code = read_reply(r->sfd)) > 0) { if (code == 200) { r->dfd = sock; - r->dfd_type = DFD_TYPE_PORT; r->flags |= F_NEEDACCEPT; return PORT_OK; } --- 1270,1275 ---- *************** *** 1278,1301 **** if (!pasv_supported) return PASV_FAIL; ! if (r->dfd >= 0 && r->dfd_type == DFD_TYPE_PASV) { ! fd_set R; ! struct timeval tv; ! FD_ZERO(&R); ! FD_SET(r->dfd, &R); ! tv.tv_sec = 0; ! tv.tv_usec = 0; ! if (select(r->dfd + 1, &R, NULL, NULL, &tv) == 0) { ! Debug(26, 3, ("do_pasv: FD %d Already connected\n", r->dfd)); ! return PORT_OK; ! } else { ! Debug(26, 2, ("Data connection closed by server (%s)\n", xstrerror())); ! close(r->dfd); ! r->dfd = -1; ! r->dfd_type = DFD_TYPE_NONE; ! } ! } ! r->flags &= ~F_NEEDACCEPT; if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) { r->errmsg = (char *) xmalloc(SMALLBUFSIZ); --- 1297,1305 ---- if (!pasv_supported) return PASV_FAIL; ! /* If there already are a open data connection, use that */ ! if (is_dfd_open(r)) ! return PORT_OK; if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) { r->errmsg = (char *) xmalloc(SMALLBUFSIZ); *************** *** 1335,1341 **** return FAIL_SOFT; } r->dfd = sock; - r->dfd_type = DFD_TYPE_PASV; return PORT_OK; } --- 1339,1344 ---- *************** *** 1356,1362 **** if (code >= 200 && code < 300) return CWD_OK; #ifdef TRY_CWD_FIRST ! if (!r->flags & F_ISDIR) return CWD_FAIL; #endif r->errmsg = xstrdup(server_reply_msg); --- 1359,1365 ---- if (code >= 200 && code < 300) return CWD_OK; #ifdef TRY_CWD_FIRST ! if (!(r->flags & F_ISDIR)) return CWD_FAIL; #endif r->errmsg = xstrdup(server_reply_msg); *************** *** 1478,1488 **** r->rc = 3; return FAIL_SOFT; } ! r->flags &= ~F_NEEDACCEPT; ! if (r->dfd >= 0) ! close(r->dfd); r->dfd = sock; - r->dfd_type = DFD_TYPE_PORT; return DATA_TRANSFER; } --- 1481,1488 ---- r->rc = 3; return FAIL_SOFT; } ! close_dfd(r); r->dfd = sock; return DATA_TRANSFER; } *************** *** 1498,1518 **** if (n == READ_TIMEOUT) { return request_timeout(r); } else if (n < 0) { ! if (r->dfd >= 0) { ! close(r->dfd); ! r->dfd = -1; ! r->dfd_type = DFD_TYPE_NONE; ! } r->errmsg = (char *) xmalloc(SMALLBUFSIZ); sprintf(r->errmsg, "read: %s", xstrerror()); r->rc = 4; return FAIL_SOFT; } else if (n == 0) { ! if (r->dfd >= 0) { ! close(r->dfd); ! r->dfd = -1; ! r->dfd_type = DFD_TYPE_NONE; ! } if ((code = read_reply(r->sfd)) > 0) { if (code == 226) return TRANSFER_DONE; --- 1498,1510 ---- if (n == READ_TIMEOUT) { return request_timeout(r); } else if (n < 0) { ! close_dfd(r); r->errmsg = (char *) xmalloc(SMALLBUFSIZ); sprintf(r->errmsg, "read: %s", xstrerror()); r->rc = 4; return FAIL_SOFT; } else if (n == 0) { ! close_dfd(r); if ((code = read_reply(r->sfd)) > 0) { if (code == 226) return TRANSFER_DONE; *************** *** 1780,1786 **** readme->sfd = r->sfd; readme->dfd = r->dfd; r->dfd = -1; - r->dfd_type = DFD_TYPE_NONE; #ifdef TRY_CWD_FIRST readme->state = CWD_FAIL; #else --- 1772,1777 ---- *************** *** 1794,1805 **** readme->cfd = -1; } if (readme->dfd >= 0) { ! if (r->dfd == -1) ! r->dfd = readme->dfd; ! else ! close(readme->dfd); readme->dfd = -1; - readme->dfd_type = DFD_TYPE_NONE; } fp = fopen(tfname, "r"); unlink(tfname); --- 1785,1793 ---- readme->cfd = -1; } if (readme->dfd >= 0) { ! close_dfd(r); ! r->dfd = readme->dfd; readme->dfd = -1; } fp = fopen(tfname, "r"); unlink(tfname); *************** *** 1881,1891 **** xfree(t); } } ! if (r->dfd >= 0) { ! close(r->dfd); ! r->dfd = -1; ! r->dfd_type = DFD_TYPE_NONE; ! } if (n == READ_TIMEOUT) { return request_timeout(r); } else if (n < 0) { --- 1869,1875 ---- xfree(t); } } ! close_dfd(r); if (n == READ_TIMEOUT) { return request_timeout(r); } else if (n < 0) { *************** *** 2061,2069 **** } break; case FAIL_SOFT: - fail(r); - return (r->rc); - /* NOTREACHED */ case FAIL_HARD: fail(r); return (r->rc); --- 2045,2050 ---- *************** *** 2455,2461 **** r->port = port; r->sfd = -1; r->dfd = -1; - r->dfd_type = DFD_TYPE_NONE; r->size = -1; r->state = BEGIN; r->flags |= o_httpify ? F_HTTPIFY : 0; --- 2436,2441 ---- *************** *** 2510,2517 **** close(r->sfd); if (r->cfd >= 0) close(r->cfd); ! if (r->dfd >= 0) ! close(r->dfd); close(0); close(1); exit(rc); --- 2490,2496 ---- close(r->sfd); if (r->cfd >= 0) close(r->cfd); ! close_dfd(r); close(0); close(1); exit(rc);