From: wessels <> Date: Wed, 15 Jul 1998 04:59:15 +0000 (+0000) Subject: From: Henrik Nordstrom X-Git-Tag: SQUID_3_0_PRE1~3086 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ee16d4ab56e0aab0125306728e6ec05cf9fdee29;p=thirdparty%2Fsquid.git From: Henrik Nordstrom Here is a patch that fixes FTP directory listings on some FTP servers / directories. * Always include .. first in directory listings, regardless if the origin server lists one or not. This fixes both servers that don't list .., and directories that have strange files/directories that get listed before .. (UNIX example: ".-test") * Show a "empty" listing when the origin server returns a empty listing. This is much more intiutive than returning a 0-bytes object (which gives a "document contains no data" error box in most browsers). This is for example seen on protected directories where the user is not allowed to list the files (like bin and etc in most anon-ftp setups). --- diff --git a/src/ftp.cc b/src/ftp.cc index 17c070f1db..5dd14f49d8 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.233 1998/07/02 16:53:39 wessels Exp $ + * $Id: ftp.cc,v 1.234 1998/07/14 22:59:15 wessels Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -154,6 +154,7 @@ static CWCB ftpPutTransferDone; static void ftpUnhack(FtpStateData * ftpState); static void ftpScheduleReadControlReply(FtpStateData *, int); static void ftpHandleControlReply(FtpStateData *); +static char *ftpHtmlifyListEntry(char *line, FtpStateData * ftpState); /* State machine functions * send == state transition @@ -292,7 +293,7 @@ ftpLoginParser(const char *login, FtpStateData * ftpState) if ((s = strchr(ftpState->user, ':'))) { *s = 0; xstrncpy(ftpState->password, s + 1, MAX_URL); - rfc1738_unescape(ftpState->password); + rfc1738_unescape(ftpState->password); } else { xstrncpy(ftpState->password, null_string, MAX_URL); } @@ -332,6 +333,7 @@ ftpListingStart(FtpStateData * ftpState) { StoreEntry *e = ftpState->entry; wordlist *w; + char *dirup; storeBuffer(e); storeAppendPrintf(e, "\n", version_string); @@ -356,6 +358,8 @@ ftpListingStart(FtpStateData * ftpState) storeAppendPrintf(e, "FTP Directory: %s\n", ftpState->title_url); storeAppendPrintf(e, "\n"); storeAppendPrintf(e, "
\n");
+    dirup = ftpHtmlifyListEntry("", ftpState);
+    storeAppend(e, dirup, strlen(dirup));
     storeBufferFlush(e);
     ftpState->flags.html_header_sent = 1;
 }
@@ -573,16 +577,8 @@ ftpHtmlifyListEntry(char *line, FtpStateData * ftpState)
 	snprintf(html, 8192, "%s\n", line);
 	return html;
     }
-    if ((parts = ftpListParseParts(line, ftpState->flags)) == NULL) {
-	char *p;
-	snprintf(html, 8192, "%s\n", line);
-	for (p = line; *p && isspace(*p); p++);
-	if (*p && !isspace(*p))
-	    ftpState->flags.listformat_unknown = 1;
-	return html;
-    }
-    /* check .. as special case */
-    if (!strcmp(parts->name, "..")) {
+    /* Handle builtin  */
+    if (!strcmp(line, "")) {
 	snprintf(icon, 2048, "\"%-6s\"",
 	    mimeGetIconURL("internal-dirup"),
 	    "[DIRUP]");
@@ -612,7 +608,14 @@ ftpHtmlifyListEntry(char *line, FtpStateData * ftpState)
 		"Home Directory");
 	}
 	snprintf(html, 8192, "%s %s\n", icon, link);
-	ftpListPartsFree(&parts);
+	return html;
+    }
+    if ((parts = ftpListParseParts(line, ftpState->flags)) == NULL) {
+	char *p;
+	snprintf(html, 8192, "%s\n", line);
+	for (p = line; *p && isspace(*p); p++);
+	if (*p && !isspace(*p))
+	    ftpState->flags.listformat_unknown = 1;
 	return html;
     }
     if (!strcmp(parts->name, ".") || !strcmp(parts->name, "..")) {
@@ -809,6 +812,9 @@ ftpDataRead(int fd, void *data)
 	    j >>= 1;
 	IOStats.Ftp.read_hist[bin]++;
     }
+    if (ftpState->flags.isdir && !ftpState->flags.html_header_sent && len >= 0) {
+	ftpListingStart(ftpState);
+    }
     if (len < 0) {
 	debug(50, 1) ("ftpDataRead: read error: %s\n", xstrerror());
 	if (ignoreErrno(errno)) {
@@ -826,8 +832,6 @@ ftpDataRead(int fd, void *data)
 	ftpReadComplete(ftpState);
     } else {
 	if (ftpState->flags.isdir) {
-	    if (!ftpState->flags.html_header_sent)
-		ftpListingStart(ftpState);
 	    ftpParseListing(ftpState);
 	} else {
 	    storeAppend(entry, ftpState->data.buf, len);