]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
From: Henrik Nordstrom <hno@hem.passagen.se>
authorwessels <>
Wed, 15 Jul 1998 04:59:15 +0000 (04:59 +0000)
committerwessels <>
Wed, 15 Jul 1998 04:59:15 +0000 (04:59 +0000)
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).

src/ftp.cc

index 17c070f1db4e673e64d4d2f59e6e2d18723cbd1b..5dd14f49d8cf282f5cbf5f7f33203878df6c2694 100644 (file)
@@ -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, "<!-- HTML listing generated by Squid %s -->\n",
        version_string);
@@ -356,6 +358,8 @@ ftpListingStart(FtpStateData * ftpState)
     storeAppendPrintf(e, "FTP Directory: %s\n", ftpState->title_url);
     storeAppendPrintf(e, "</H2>\n");
     storeAppendPrintf(e, "<PRE>\n");
+    dirup = ftpHtmlifyListEntry("<internal-dirup>", 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 <dirup> */
+    if (!strcmp(line, "<internal-dirup>")) {
        snprintf(icon, 2048, "<IMG BORDER=0 SRC=\"%s\" ALT=\"%-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);