/*
- * $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
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);
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);
{
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);
}
} 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;
}
ftpState->flags.tried_nlst = 0;
/* And off we go */
if (ftpState->flags.isdir) {
- safe_free(ftpState->filepath);
ftpListDir(ftpState);
} else {
ftpGetFile(ftpState);