From eb7d6bd6cbfc077ca677fa41253a29a1f1f9c6fb Mon Sep 17 00:00:00 2001 From: hno <> Date: Mon, 15 Jul 2002 06:30:54 +0000 Subject: [PATCH] Cleanup of Gopher HTML code to use a common header format, and the standard Squid signature. --- src/gopher.cc | 59 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/src/gopher.cc b/src/gopher.cc index 55505bb64f..58a77b7c98 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -1,6 +1,6 @@ /* - * $Id: gopher.cc,v 1.164 2002/04/21 22:14:08 hno Exp $ + * $Id: gopher.cc,v 1.165 2002/07/15 00:30:54 hno Exp $ * * DEBUG: section 10 Gopher * AUTHOR: Harvest Derived @@ -237,13 +237,39 @@ gopherCachable(const request_t * req) return cachable; } +static void +gopherHTMLHeader(StoreEntry * e, const char *title, const char *substring) +{ + storeAppendPrintf(e, ""); + storeAppendPrintf(e, title, substring); + storeAppendPrintf(e, "\n

"); + storeAppendPrintf(e, title, substring); + storeAppendPrintf(e, "

\n"); +} + +static void +gopherHTMLFooter(StoreEntry * e) +{ + storeAppendPrintf(e, "
\n"); + storeAppendPrintf(e, "
\n"); + storeAppendPrintf(e, "Generated %s by %s (%s)\n", + mkrfc1123(squid_curtime), + getMyHostname(), + full_appname_string); + storeAppendPrintf(e, "
\n"); +} + static void gopherEndHTML(GopherStateData * gopherState) { - if (!gopherState->data_in) - storeAppendPrintf(gopherState->entry, - "Server Return Nothing.\n" - "

Server Return Nothing.

\n"); + StoreEntry *e = gopherState->entry; + if (!gopherState->data_in) { + gopherHTMLHeader(e, "Server Return Nothing", NULL); + storeAppendPrintf(e, "

The Gopher query resulted in a blank response

"); + } else { + storeAppendPrintf(e, "\n"); + } + gopherHTMLFooter(e); } @@ -274,13 +300,12 @@ gopherToHTML(GopherStateData * gopherState, char *inbuf, int len) if (gopherState->conversion == HTML_INDEX_PAGE) { char *html_url = html_quote(storeUrl(entry)); + gopherHTMLHeader(entry, "Gopher Index %s", html_url); storeAppendPrintf(entry, - "Gopher Index %s\n" - "

%s
Gopher Search

\n" "

This is a searchable Gopher index. Use the search\n" "function of your browser to enter search terms.\n" - "\n", - html_url, html_url); + "\n"); + gopherHTMLFooter(entry); /* now let start sending stuff to client */ storeBufferFlush(entry); gopherState->data_in = 1; @@ -289,13 +314,12 @@ gopherToHTML(GopherStateData * gopherState, char *inbuf, int len) } if (gopherState->conversion == HTML_CSO_PAGE) { char *html_url = html_quote(storeUrl(entry)); + gopherHTMLHeader(entry, "CSO Search of %s", html_url); storeAppendPrintf(entry, - "CSO Search of %s\n" - "

%s
CSO Search

\n" "

A CSO database usually contains a phonebook or\n" "directory. Use the search function of your browser to enter\n" - "search terms.

\n", - html_url, html_url); + "search terms.

\n"); + gopherHTMLFooter(entry); /* now let start sending stuff to client */ storeBufferFlush(entry); gopherState->data_in = 1; @@ -306,11 +330,10 @@ gopherToHTML(GopherStateData * gopherState, char *inbuf, int len) if (!gopherState->HTML_header_added) { if (gopherState->conversion == HTML_CSO_RESULT) - strCat(outbuf, "CSO Search Result\n" - "

CSO Search Result

\n
\n");
+	    gopherHTMLHeader(entry, "CSO Search Result", NULL);
 	else
-	    strCat(outbuf, "Gopher Menu\n"
-		"

Gopher Menu

\n
\n");
+	    gopherHTMLHeader(entry, "Gopher Menu", NULL);
+	strCat(outbuf, "
");
 	gopherState->HTML_header_added = 1;
     }
     while ((pos != NULL) && (pos < inbuf + len)) {
@@ -746,7 +769,7 @@ gopherSendRequest(int fd, void *data)
     if (gopherState->type_id == GOPHER_CSO) {
 	const char *t = strchr(gopherState->request, '?');
 	if (t != NULL)
-	    t++; /* skip the ? */
+	    t++;		/* skip the ? */
 	else
 	    t = "";
 	snprintf(buf, 4096, "query %s\r\nquit\r\n", t);
-- 
2.47.3