/*
- * $Id: ftp.cc,v 1.362 2005/05/01 08:11:48 serassio Exp $
+ * $Id: ftp.cc,v 1.363 2005/06/26 17:12:47 serassio Exp $
*
* DEBUG: section 9 File Transfer Protocol (FTP)
* AUTHOR: Harvest Derived
wordlist *w;
char *dirup;
int i, j, k;
- char *title;
+ const char *title = ftpState->title_url.buf();
storeBuffer(e);
storeAppendPrintf(e, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n");
storeAppendPrintf(e, "<!-- HTML listing generated by Squid %s -->\n",
version_string);
storeAppendPrintf(e, "<!-- %s -->\n", mkrfc1123(squid_curtime));
storeAppendPrintf(e, "<HTML><HEAD><TITLE>\n");
- storeAppendPrintf(e, "FTP Directory: %s\n",
- html_quote(ftpState->title_url.buf()));
+ {
+ char *t = xstrdup(title);
+ rfc1738_unescape(t);
+ storeAppendPrintf(e, "FTP Directory: %s\n", html_quote(t));
+ xfree(t);
+ }
+
storeAppendPrintf(e, "</TITLE>\n");
storeAppendPrintf(e, "<STYLE type=\"text/css\"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}--></STYLE>\n");
storeAppendPrintf(e, "FTP Directory: ");
/* "ftp://" == 6 characters */
assert(ftpState->title_url.size() >= 6);
- title = html_quote(ftpState->title_url.buf());
+ k = 6 + strcspn(&title[6], "/");
for (i = 6, j = 0; title[i]; j = i) {
storeAppendPrintf(e, "<A HREF=\"");
i += strcspn(&title[i], "/");
- if (title[i] == '/')
- i++;
-
- for (k = 0; k < i; k++)
- storeAppendPrintf(e, "%c", title[k]);
-
- storeAppendPrintf(e, "\">");
-
- for (k = j; k < i - 1; k++)
- storeAppendPrintf(e, "%c", title[k]);
-
- if (ftpState->title_url.buf()[k] != '/')
- storeAppendPrintf(e, "%c", title[k++]);
+ if (i > j) {
+ char *url = xstrdup(title);
+ url[i] = '\0';
+ storeAppendPrintf(e, "%s", html_quote(url + k));
+ storeAppendPrintf(e, "/");
+ storeAppendPrintf(e, "\">");
+ rfc1738_unescape(url + j);
+ storeAppendPrintf(e, "%s", html_quote(url + j));
+ safe_free(url);
+ storeAppendPrintf(e, "</A>");
+ }
- storeAppendPrintf(e, "</A>");
+ storeAppendPrintf(e, "/");
- if (k < i)
- storeAppendPrintf(e, "%c", title[k++]);
+ if (title[i] == '/')
+ i++;
if (i == j) {
/* Error guard, or "assert" */
storeAppendPrintf(e, "ERROR: Failed to parse URL: %s\n",
- html_quote(ftpState->title_url.buf()));
- debug(9, 0) ("Failed to parse URL: %s\n", ftpState->title_url.buf());
+ html_quote(title));
+ debug(9, 0) ("Failed to parse URL: %s\n", title);
break;
}
}