]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Small change of Squid output for FTP
authorwessels <>
Tue, 12 Jan 1999 03:05:50 +0000 (03:05 +0000)
committerwessels <>
Tue, 12 Jan 1999 03:05:50 +0000 (03:05 +0000)
Henrik Nordstrom
Andrew Filonov <aef@shu.smolensk.su>

src/ftp.cc

index 340538afea7453ccdffec4b64d321b946a6ae167..839a318395dff190003db44b0aba078f95cde16a 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: ftp.cc,v 1.258 1999/01/08 21:12:11 wessels Exp $
+ * $Id: ftp.cc,v 1.259 1999/01/11 20:05:50 wessels Exp $
  *
  * DEBUG: section 9     File Transfer Protocol (FTP)
  * AUTHOR: Harvest Derived
@@ -339,6 +339,7 @@ ftpListingStart(FtpStateData * ftpState)
     StoreEntry *e = ftpState->entry;
     wordlist *w;
     char *dirup;
+    int i, j, k;
     storeBuffer(e);
     storeAppendPrintf(e, "<!-- HTML listing generated by Squid %s -->\n",
        version_string);
@@ -360,7 +361,32 @@ ftpListingStart(FtpStateData * ftpState)
        wordlistDestroy(&ftpState->cwd_message);
     }
     storeAppendPrintf(e, "<H2>\n");
-    storeAppendPrintf(e, "FTP Directory: %s\n", ftpState->title_url);
+    storeAppendPrintf(e, "FTP Directory: ");
+    /* "ftp://" == 6 characters */
+    assert(strlen(ftpState->title_url) >= 6);
+    for (i = 6, j = 0; ftpState->title_url[i]; j = i) {
+       storeAppendPrintf(e, "<A HREF=\"");
+       i += strcspn(&ftpState->title_url[i], "/");
+       if (ftpState->title_url[i] == '/')
+           i++;
+       for (k = 0; k < i; k++)
+           storeAppendPrintf(e, "%c", ftpState->title_url[k]);
+       storeAppendPrintf(e, "\">");
+       for (k = j; k < i - 1; k++)
+           storeAppendPrintf(e, "%c", ftpState->title_url[k]);
+       if (ftpState->title_url[k] != '/')
+           storeAppendPrintf(e, "%c", ftpState->title_url[k++]);
+       storeAppendPrintf(e, "</A>");
+       if (k < i)
+           storeAppendPrintf(e, "%c", ftpState->title_url[k++]);
+       if (i == j) {
+           /* Error guard, or "assert" */
+           storeAppendPrintf(e, "ERROR: Failed to parse URL: %s\n",
+               ftpState->title_url);
+           debug(9, 0) ("Failed to parse URL: %s\n", ftpState->title_url);
+           break;
+       }
+    }
     storeAppendPrintf(e, "</H2>\n");
     storeAppendPrintf(e, "<PRE>\n");
     dirup = ftpHtmlifyListEntry("<internal-dirup>", ftpState);
@@ -1366,11 +1392,14 @@ ftpReadType(FtpStateData * ftpState)
 {
     int code = ftpState->ctrl.replycode;
     char *path;
-    char *d;
+    char *d, *p;
     debug(9, 3) ("This is ftpReadType\n");
     if (code == 200) {
        path = xstrdup(strBuf(ftpState->request->urlpath));
-       for (d = strtok(path, "/"); d; d = strtok(NULL, "/")) {
+       for (d = p = path; *p; d = p) {
+           p += strcspn(p, "/");
+           if (*p)
+               *p++ = '\0';
            rfc1738_unescape(d);
            wordlistAdd(&ftpState->pathcomps, d);
        }
@@ -1423,7 +1452,10 @@ ftpSendCwd(FtpStateData * ftpState)
     } else {
        ftpState->flags.no_dotdot = 0;
     }
-    snprintf(cbuf, 1024, "CWD %s\r\n", path);
+    if (*path)
+       snprintf(cbuf, 1024, "CWD %s\r\n", path);
+    else
+       snprintf(cbuf, 1024, "CWD\r\n");
     ftpWriteCommand(cbuf, ftpState);
     ftpState->state = SENT_CWD;
 }
@@ -2077,7 +2109,6 @@ ftpTryDatachannelHack(FtpStateData * ftpState)
     ftpState->flags.tried_nlst = 0;
     /* And off we go */
     if (ftpState->flags.isdir) {
-       safe_free(ftpState->filepath);
        ftpListDir(ftpState);
     } else {
        ftpGetFile(ftpState);