diff -N -c -r -X exclude_files squid-1.0.beta5/src/ftp.c squid-1.0.beta5.henrik/src/ftp.c *** squid-1.0.beta5/src/ftp.c Wed May 1 18:26:11 1996 --- squid-1.0.beta5.henrik/src/ftp.c Thu May 2 17:38:47 1996 *************** *** 441,454 **** mode = ftpBinary; } - /* Remove leading slash from FTP url-path so that we can - * handle ftp://user:pw@host/path objects where path and /path - * are quite different. -DW */ - if (!strcmp(path, "/")) - *path = '.'; - if (*path == '/') - path++; - /* Start building the buffer ... */ strcat(buf, getFtpProgram()); --- 441,446 ---- diff -N -c -r -X exclude_files squid-1.0.beta5/src/ftpget.c squid-1.0.beta5.henrik/src/ftpget.c *** squid-1.0.beta5/src/ftpget.c Wed May 1 18:26:12 1996 --- squid-1.0.beta5.henrik/src/ftpget.c Thu May 2 21:02:51 1996 *************** *** 1155,1160 **** --- 1155,1165 ---- int port = 0; static int init = 0; + if(r->dfd >= 0) { + Debug(26,3,("Already connected, fd=%d\n",r->dfd)); + return PORT_OK; + } + if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) { r->errmsg = (char *) xmalloc(SMALLBUFSIZ); sprintf(r->errmsg, "socket: %s", xstrerror()); *************** *** 1230,1240 **** --- 1235,1252 ---- static char junk[SMALLBUFSIZ]; static int pasv_supported = 1; + if(r->dfd >= 0) { + Debug(26,3,("Already connected, fd=%d\n",r->dfd)); + return PORT_OK; + } + /* if PASV previously failed, don't even try it again. Just return * PASV_FAIL and let the state machine fall back to using PORT */ if (!pasv_supported) return PASV_FAIL; + r->flags &= ~F_NEEDACCEPT; + if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) { r->errmsg = (char *) xmalloc(SMALLBUFSIZ); sprintf(r->errmsg, "socket: %s", xstrerror()); *************** *** 1281,1286 **** --- 1293,1300 ---- { int code; + Debug(26,10,("do_cwd: \"%s\"\n",r->path)); + if (!strcmp(r->path, ".")) return CWD_OK; *************** *** 1291,1302 **** if (code >= 200 && code < 300) return CWD_OK; #ifdef TRY_CWD_FIRST ! return CWD_FAIL; ! #else r->errmsg = xstrdup(server_reply_msg); r->rc = 10; return FAIL_HARD; - #endif } r->errmsg = xstrdup(server_reply_msg); r->rc = code < 0 ? 4 : 5; --- 1305,1316 ---- 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); r->rc = 10; return FAIL_HARD; } r->errmsg = xstrdup(server_reply_msg); r->rc = code < 0 ? 4 : 5; *************** *** 1345,1352 **** return FAIL_HARD; } #else - if (r->dfd > 0) - close(r->dfd); if (r->flags & F_TRYDIR) return RETR_FAIL; r->errmsg = xstrdup(server_reply_msg); --- 1359,1364 ---- *************** *** 1415,1421 **** r->rc = 3; return FAIL_SOFT; } ! close(r->dfd); r->dfd = sock; return DATA_TRANSFER; } --- 1427,1435 ---- r->rc = 3; return FAIL_SOFT; } ! r->flags &= ~F_NEEDACCEPT; ! if (r->dfd >= 0) ! close(r->dfd); r->dfd = sock; return DATA_TRANSFER; } *************** *** 1432,1442 **** --- 1446,1464 ---- if (n == READ_TIMEOUT) { return request_timeout(r); } else if (n < 0) { + if(r->dfd >= 0) { + close(r->dfd); + r->dfd=-1; + } 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; + } if ((code = read_reply(r->sfd)) > 0) { if (code == 226) return TRANSFER_DONE; *************** *** 1709,1718 **** readme->flags = F_NOERRS; process_request(readme); ! if (readme->cfd > 0) close(readme->cfd); ! if (readme->dfd > 0) ! close(readme->dfd); fp = fopen(tfname, "r"); unlink(tfname); --- 1731,1747 ---- readme->flags = F_NOERRS; process_request(readme); ! if (readme->cfd >= 0) { close(readme->cfd); ! readme->cfd=-1; ! } ! if (readme->dfd >= 0) { ! if ( r->dfd == -1 ) ! r->dfd = readme->dfd; ! else ! close(readme->dfd); ! readme->dfd=-1; ! } fp = fopen(tfname, "r"); unlink(tfname); *************** *** 1793,1798 **** --- 1822,1831 ---- xfree(t); } } + if (r->dfd >=0) { + close(r->dfd); + r->dfd=-1; + } if (n == READ_TIMEOUT) { return request_timeout(r); } else if (n < 0) { *************** *** 1861,1867 **** } break; case TYPE_OK: ! r->state = do_mdtm(r); break; case MDTM_OK: r->state = do_size(r); --- 1894,1903 ---- } break; case TYPE_OK: ! if(r->flags & F_ISDIR) ! r->state = do_cwd(r); ! else ! r->state = do_mdtm(r); break; case MDTM_OK: r->state = do_size(r); *************** *** 1874,1890 **** #endif break; case CWD_OK: r->flags |= F_ISDIR; if (strcmp(r->path, ".")) { /* tack on the trailing slash now that we know its a dir */ strcat(r->url, "/"); strcat(r->title_url, "/"); strcat(r->url_escaped, "/"); - if (*(r->path + strlen(r->path) - 1) != '/') - r->flags |= F_USEBASE; - } else { - /* We must do this only because Netscape's browser is broken */ - r->flags |= F_USEBASE; } if (r->flags & F_HTTPIFY) { if (cmd_msg) { --- 1910,1923 ---- #endif break; case CWD_OK: + if(!r->flags & F_ISDIR) + r->flags |= F_USEBASE; r->flags |= F_ISDIR; if (strcmp(r->path, ".")) { /* tack on the trailing slash now that we know its a dir */ strcat(r->url, "/"); strcat(r->title_url, "/"); strcat(r->url_escaped, "/"); } if (r->flags & F_HTTPIFY) { if (cmd_msg) { *************** *** 1899,1910 **** break; #ifdef TRY_CWD_FIRST case CWD_FAIL: - r->flags &= ~F_ISDIR; r->state = do_pasv(r); break; #else case RETR_FAIL: - r->flags |= F_ISDIR; r->state = do_cwd(r); break; #endif --- 1932,1941 ---- *************** *** 1950,1960 **** r->state = PARSE_OK; } break; - case FAIL_HARD: case FAIL_SOFT: fail(r); return (r->rc); /* NOTREACHED */ default: errorlog("Nothing to do with state %s\n", state_str[r->state]); --- 1981,1994 ---- r->state = PARSE_OK; } break; case FAIL_SOFT: fail(r); return (r->rc); /* NOTREACHED */ + case FAIL_HARD: + fail(r); + return (r->rc); + /* NOTREACHED */ default: errorlog("Nothing to do with state %s\n", state_str[r->state]); *************** *** 1981,1986 **** --- 2015,2032 ---- r->path = xstrdup("."); xfree(t); again = 1; + } else if ((l>=1) && (*(r->path + l - 1) == '/')) { + /* remove any trailing slashes from path */ + *(r->path + l - 1) = '\0'; + r->flags |= F_ISDIR; + r->flags &= ~F_USEBASE; + again = 1; + } else if ((l>=2) && (!strcmp(r->path + l - 2, "/."))) { + /* remove trailing /. */ + *(r->path + l - 2) = '\0'; + r->flags |= F_ISDIR; + r->flags &= ~F_USEBASE; + again = 1; } else if (*r->path == '/') { /* remove any leading slashes from path */ t = r->path; *************** *** 1993,2006 **** r->path = xstrdup(t + 2); xfree(t); again = 1; - } else if (*(r->path + l - 1) == '/') { - /* remove any trailing slashes from path */ - *(r->path + l - 1) = '\0'; - again = 1; - } else if (!strcmp(r->path + l - 2, "/.")) { - /* remove trailing /. */ - *(r->path + l - 2) = '\0'; - again = 1; } else if ((t = strstr(r->path, "/./"))) { /* remove /./ */ s = xstrdup(t + 2); --- 2039,2044 ---- *************** *** 2341,2346 **** --- 2379,2385 ---- r->state = BEGIN; r->flags |= o_httpify ? F_HTTPIFY : 0; r->flags |= F_TRYDIR; + r->flags |= F_USEBASE; r->rest_implemented = 1; if (*(r->type) != 'A' && *(r->type) != 'I') { *************** *** 2384,2396 **** strcpy(r->url_escaped, t); rc = process_request(MainRequest = r); ! if (r->sfd > 0) send_cmd(r->sfd, "QUIT"); ! if (r->sfd > 0) close(r->sfd); ! if (r->cfd > 0) close(r->cfd); ! if (r->dfd > 0) close(r->dfd); close(0); close(1); --- 2423,2435 ---- strcpy(r->url_escaped, t); rc = process_request(MainRequest = r); ! if (r->sfd >= 0) send_cmd(r->sfd, "QUIT"); ! if (r->sfd >= 0) close(r->sfd); ! if (r->cfd >= 0) close(r->cfd); ! if (r->dfd >= 0) close(r->dfd); close(0); close(1);