/*
- * $Id: ftp.cc,v 1.296 2000/06/27 22:06:01 hno Exp $
+ * $Id: ftp.cc,v 1.297 2000/11/04 23:04:10 hno Exp $
*
* DEBUG: section 9 File Transfer Protocol (FTP)
* AUTHOR: Harvest Derived
wordlist *w;
char *dirup;
int i, j, k;
+ char *title;
storeBuffer(e);
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",
- ftpState->title_url);
+ html_quote(ftpState->title_url));
storeAppendPrintf(e, "</TITLE>\n");
if (ftpState->flags.use_base)
storeAppendPrintf(e, "<BASE HREF=\"%s\">\n",
- ftpState->base_href);
+ html_quote(ftpState->base_href));
storeAppendPrintf(e, "</HEAD><BODY>\n");
if (ftpState->cwd_message) {
storeAppendPrintf(e, "<PRE>\n");
for (w = ftpState->cwd_message; w; w = w->next)
- storeAppendPrintf(e, "%s\n", w->key);
+ storeAppendPrintf(e, "%s\n", html_quote(w->key));
storeAppendPrintf(e, "</PRE>\n");
storeAppendPrintf(e, "<HR>\n");
wordlistDestroy(&ftpState->cwd_message);
storeAppendPrintf(e, "FTP Directory: ");
/* "ftp://" == 6 characters */
assert(strlen(ftpState->title_url) >= 6);
- for (i = 6, j = 0; ftpState->title_url[i]; j = i) {
+ title = html_quote(ftpState->title_url);
+ for (i = 6, j = 0; title[i]; j = i) {
storeAppendPrintf(e, "<A HREF=\"");
- i += strcspn(&ftpState->title_url[i], "/");
- if (ftpState->title_url[i] == '/')
+ i += strcspn(&title[i], "/");
+ if (title[i] == '/')
i++;
for (k = 0; k < i; k++)
- storeAppendPrintf(e, "%c", ftpState->title_url[k]);
+ storeAppendPrintf(e, "%c", title[k]);
storeAppendPrintf(e, "\">");
for (k = j; k < i - 1; k++)
- storeAppendPrintf(e, "%c", ftpState->title_url[k]);
+ storeAppendPrintf(e, "%c", title[k]);
if (ftpState->title_url[k] != '/')
- storeAppendPrintf(e, "%c", ftpState->title_url[k++]);
+ storeAppendPrintf(e, "%c", title[k++]);
storeAppendPrintf(e, "</A>");
if (k < i)
- storeAppendPrintf(e, "%c", ftpState->title_url[k++]);
+ storeAppendPrintf(e, "%c", title[k++]);
if (i == j) {
/* Error guard, or "assert" */
storeAppendPrintf(e, "ERROR: Failed to parse URL: %s\n",
- ftpState->title_url);
+ html_quote(ftpState->title_url));
debug(9, 0) ("Failed to parse URL: %s\n", ftpState->title_url);
break;
}
return html;
}
/* Handle builtin <dirup> */
- if (!strcmp(line, "<internal-dirup>")) {
+ if (strcmp(line, "<internal-dirup>") == 0) {
/* <A HREF="{href}">{icon}</A> <A HREF="{href}">{text}</A> {link} */
snprintf(icon, 2048, "<IMG BORDER=0 SRC=\"%s\" ALT=\"%-6s\">",
mimeGetIconURL("internal-dirup"),
mimeGetIconURL("internal-link"),
"[LINK]");
/* sometimes there is an 'l' flag, but no "->" link */
- if (parts->link)
+ if (parts->link) {
+ char *link2 = xstrdup(html_quote(rfc1738_escape(parts->link)));
snprintf(link, 2048, " -> <A HREF=\"%s\">%s</A>",
- rfc1738_escape(parts->link),
- parts->link);
+ link2,
+ html_quote(parts->link));
+ safe_free(link2);
+ }
break;
case '\0':
snprintf(icon, 2048, "<IMG BORDER=0 SRC=\"%s\" ALT=\"%-6s\">",
"[UNKNOWN]");
snprintf(chdir, 2048, " <A HREF=\"%s/;type=d\"><IMG BORDER=0 SRC=\"%s\" "
"ALT=\"[DIR]\"></A>",
- rfc1738_escape(parts->name),
+ rfc1738_escape_part(parts->name),
mimeGetIconURL("internal-dir"));
break;
case '-':
if (parts->type != '\0') {
snprintf(html, 8192, "<A HREF=\"%s\">%s</A> <A HREF=\"%s\">%s</A>%s "
"%s%8s%s%s%s%s\n",
- href, icon, href, text, dots_fill(strlen(text)),
+ href, icon, href, html_quote(text), dots_fill(strlen(text)),
parts->date, size, chdir, view, download, link);
} else {
/* Plain listing. {icon} {text} ... {chdir}{view}{download} */
snprintf(html, 8192, "<A HREF=\"%s\">%s</A> <A HREF=\"%s\">%s</A>%s "
"%s%s%s%s\n",
- href, icon, href, text, dots_fill(strlen(text)),
+ href, icon, href, html_quote(text), dots_fill(strlen(text)),
chdir, view, download, link);
}
ftpListPartsFree(&parts);
/*
- * $Id: gopher.cc,v 1.155 2000/06/27 22:06:02 hno Exp $
+ * $Id: gopher.cc,v 1.156 2000/11/04 23:04:10 hno Exp $
*
* DEBUG: section 10 Gopher
* AUTHOR: Harvest Derived
break;
}
-
memset(tmpbuf, '\0', TEMP_BUF_SIZE);
if ((gtype == GOPHER_TELNET) || (gtype == GOPHER_3270)) {
if (strlen(escaped_selector) != 0)
- snprintf(tmpbuf, TEMP_BUF_SIZE, "<IMG BORDER=0 SRC=\"%s\"> <A HREF=\"telnet://%s@%s/\">%s</A>\n",
- icon_url, escaped_selector, host, name);
+ snprintf(tmpbuf, TEMP_BUF_SIZE, "<IMG BORDER=0 SRC=\"%s\"> <A HREF=\"telnet://%s@%s%s%s/\">%s</A>\n",
+ icon_url, escaped_selector, rfc1738_escape_part(host),
+ *port ? ":" : "", port, html_quote(name));
else
- snprintf(tmpbuf, TEMP_BUF_SIZE, "<IMG BORDER=0 SRC=\"%s\"> <A HREF=\"telnet://%s/\">%s</A>\n",
- icon_url, host, name);
+ snprintf(tmpbuf, TEMP_BUF_SIZE, "<IMG BORDER=0 SRC=\"%s\"> <A HREF=\"telnet://%s%s%s/\">%s</A>\n",
+ icon_url, rfc1738_escape_part(host), *port ? ":" : "",
+ port, html_quote(name));
} else {
snprintf(tmpbuf, TEMP_BUF_SIZE, "<IMG BORDER=0 SRC=\"%s\"> <A HREF=\"gopher://%s/%c%s\">%s</A>\n",
- icon_url, host, gtype, escaped_selector, name);
+ icon_url, host, gtype, escaped_selector, html_quote(name));
}
safe_free(escaped_selector);
strcat(outbuf, tmpbuf);
break;
if (gopherState->cso_recno != recno) {
- snprintf(tmpbuf, TEMP_BUF_SIZE, "</PRE><HR><H2>Record# %d<br><i>%s</i></H2>\n<PRE>", recno, result);
+ snprintf(tmpbuf, TEMP_BUF_SIZE, "</PRE><HR><H2>Record# %d<br><i>%s</i></H2>\n<PRE>", recno, html_quote(result));
gopherState->cso_recno = recno;
} else {
- snprintf(tmpbuf, TEMP_BUF_SIZE, "%s\n", result);
+ snprintf(tmpbuf, TEMP_BUF_SIZE, "%s\n", html_quote(result));
}
strcat(outbuf, tmpbuf);
gopherState->data_in = 1;
case 502: /* Too Many Matches */
{
/* Print the message the server returns */
- snprintf(tmpbuf, TEMP_BUF_SIZE, "</PRE><HR><H2>%s</H2>\n<PRE>", result);
+ snprintf(tmpbuf, TEMP_BUF_SIZE, "</PRE><HR><H2>%s</H2>\n<PRE>", html_quote(result));
strcat(outbuf, tmpbuf);
gopherState->data_in = 1;
break;