From: wessels <> Date: Sat, 19 Jul 1997 07:33:53 +0000 (+0000) Subject: Started internal icon support X-Git-Tag: SQUID_3_0_PRE1~4863 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=365cb147361da291ede13989a58eca088b995559;p=thirdparty%2Fsquid.git Started internal icon support --- diff --git a/src/Makefile.in b/src/Makefile.in index c5e6f9098c..cc30a938f5 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -1,7 +1,7 @@ # # Makefile for the Squid Object Cache server # -# $Id: Makefile.in,v 1.82 1997/07/14 03:33:33 wessels Exp $ +# $Id: Makefile.in,v 1.83 1997/07/19 01:33:53 wessels Exp $ # # Uncomment and customize the following to suit your needs: # @@ -41,6 +41,7 @@ DEFAULT_PID_FILE = $(localstatedir)/logs/squid.pid DEFAULT_SWAP_DIR = $(localstatedir)/cache DEFAULT_PINGER = $(libexecdir)/pinger DEFAULT_UNLINKD = $(libexecdir)/unlinkd +DEFAULT_ICON_DIR = $(sysconfdir)/icons CC = @CC@ MAKEDEPEND = @MAKEDEPEND@ @@ -178,7 +179,8 @@ cf.data: cf.data.pre Makefile s%@DEFAULT_ACCESS_LOG@%$(DEFAULT_ACCESS_LOG)%g;\ s%@DEFAULT_STORE_LOG@%$(DEFAULT_STORE_LOG)%g;\ s%@DEFAULT_PID_FILE@%$(DEFAULT_PID_FILE)%g;\ - s%@DEFAULT_SWAP_DIR@%$(DEFAULT_SWAP_DIR)%g" < cf.data.pre >$@ + s%@DEFAULT_SWAP_DIR@%$(DEFAULT_SWAP_DIR)%g;\ + s%@DEFAULT_ICON_DIR@%$(DEFAULT_ICON_DIR)%g" < cf.data.pre >$@ install-mkdirs: -@if test ! -d $(prefix); then \ diff --git a/src/cf.data.pre b/src/cf.data.pre index 2bbccb6571..983b2c2f79 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -714,6 +714,14 @@ DOC_START ftp_user squid@ DOC_END +NAME: ftp_list_width +TYPE: int +DEFAULT: 32 +LOC: Config.Ftp.list_width +DOC_START +ftp_list_width 32 +DOC_END + NAME: cache_dns_program TYPE: pathname_stat @@ -1834,5 +1842,20 @@ DOC_START fake_user_agent none DOC_END +NAME: icon_directory +TYPE: pathname_stat +LOC: Config.icons.directory +DEFAULT: @DEFAULT_ICON_DIR@ +DOC_START + XXX +DOC_END + +NAME: icon_content_type +TYPE: string +LOC: Config.icons.content_type +DEFAULT: image/gif +DOC_START + XXX +DOC_END EOF diff --git a/src/defines.h b/src/defines.h index 6222423b0e..4e150497fb 100644 --- a/src/defines.h +++ b/src/defines.h @@ -210,6 +210,7 @@ #define DELAY_SENDING (1<<3) #define ENTRY_REVALIDATE (1<<2) #define DELETE_BEHIND (1<<1) +#define ENTRY_SPECIAL (1<<0) #define MAX_FILES_PER_DIR (1<<20) diff --git a/src/ftp.cc b/src/ftp.cc index 15733daef1..108ece04ec 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.133 1997/07/16 22:57:02 wessels Exp $ + * $Id: ftp.cc,v 1.134 1997/07/19 01:33:55 wessels Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -461,10 +461,9 @@ ftpHtmlifyListEntry(char *line, int flags) ftpListParts *parts; /* check .. as special case */ if (!strcmp(line, "..")) { - sprintf(icon, "\"%-6s\"", - Config.Ftp.icon_prefix, - "gopher-menu", - Config.Ftp.icon_suffix, + sprintf(icon, "\"%-6s\"", + "http://internal.squid/icons/", + "menu", "[DIR]"); sprintf(link, "%s", "../", "Parent Directory"); sprintf(html, "%s %s\n", icon, link); @@ -495,10 +494,9 @@ ftpHtmlifyListEntry(char *line, int flags) ename = xstrdup(rfc1738_escape(parts->name)); switch (parts->type) { case 'd': - sprintf(icon, "\"%-6s\"", - Config.Ftp.icon_prefix, + sprintf(icon, "\"%-6s\"", + "http://internal.squid/icons/", "menu", - Config.Ftp.icon_suffix, "[DIR]"); sprintf(link, "%s%s", ename, @@ -510,10 +508,9 @@ ftpHtmlifyListEntry(char *line, int flags) parts->date); break; case 'l': - sprintf(icon, "\"%-6s\"", - Config.Ftp.icon_prefix, + sprintf(icon, "\"%-6s\"", + "http://internal.squid/icons/", mimeGetIcon(parts->link), - Config.Ftp.icon_suffix, "[LINK]"); sprintf(link, "%s%s", ename, @@ -526,10 +523,9 @@ ftpHtmlifyListEntry(char *line, int flags) break; case '-': default: - sprintf(icon, "\"%-6s\"", - Config.Ftp.icon_prefix, + sprintf(icon, "\"%-6s\"", + "http://internal.squid/icons/", mimeGetIcon(parts->name), - Config.Ftp.icon_suffix, "[FILE]"); sprintf(link, "%s%s", ename, diff --git a/src/mime.cc b/src/mime.cc index a0a279fac3..8938ca60e4 100644 --- a/src/mime.cc +++ b/src/mime.cc @@ -1,5 +1,5 @@ /* - * $Id: mime.cc,v 1.32 1997/07/16 22:57:42 wessels Exp $ + * $Id: mime.cc,v 1.33 1997/07/19 01:33:57 wessels Exp $ * * DEBUG: section 25 MIME Parsing * AUTHOR: Harvest Derived @@ -120,6 +120,8 @@ typedef struct _mime_entry { static mimeEntry *MimeTable = NULL; static mimeEntry **MimeTableTail = NULL; +static void mimeLoadIconFile _PARAMS((const char *icon)); + char * mime_get_header(const char *mime, const char *name) { @@ -368,9 +370,63 @@ mimeInit(char *filename) m->transfer_mode = 'A'; else m->transfer_mode = 'I'; + mimeLoadIconFile(m->icon); debug(25, 5) ("mimeInit: added '%s'\n", buf); *MimeTableTail = m; MimeTableTail = &m->next; } fclose(fp); } + +static void +mimeLoadIconFile(const char *icon) +{ + int fd; + int n; + int l; + struct stat sb; + StoreEntry *e; + LOCAL_ARRAY(char, path, MAXPATHLEN); + LOCAL_ARRAY(char, url, MAX_URL); + char *buf; + snprintf(url, MAX_URL, "http://internal.squid/icons/%s", icon); + if (storeGet(url)) + return; + snprintf(path, MAXPATHLEN, "%s/%s", Config.icons.directory, icon); + fd = file_open(path, O_RDONLY, NULL, NULL); + if (fd < 0) { + debug(25,0)("mimeLoadIconFile: %s: %s\n", path, xstrerror()); + return; + } + if (fstat(fd, &sb) < 0) { + debug(50,0)("mimeLoadIconFile: FD %d: fstat: %s\n", fd, xstrerror()); + return; + } + e = storeCreateEntry(url, + url, + REQ_CACHABLE, + METHOD_GET); + assert(e != NULL); + e->mem_obj->request = requestLink(urlParse(METHOD_GET, url)); + buf = get_free_4k_page(); + l = 0; + l += snprintf(buf+l, SM_PAGE_SIZE-l, "HTTP/1.0 200 OK\r\n"); + l += snprintf(buf+l, SM_PAGE_SIZE-l, "Date: %s\r\n", mkrfc1123(squid_curtime)); + l += snprintf(buf+l, SM_PAGE_SIZE-l, "Server: Squid/%s\r\n", version_string); + l += snprintf(buf+l, SM_PAGE_SIZE-l, "Content-Type: %s\r\n", Config.icons.content_type); + l += snprintf(buf+l, SM_PAGE_SIZE-l, "Content-Length: %d\r\n", (int) sb.st_size); + l += snprintf(buf+l, SM_PAGE_SIZE-l, "Last-Modified: %s\r\n", mkrfc1123(sb.st_mtime)); + l += snprintf(buf+l, SM_PAGE_SIZE-l, "Expires: %s\r\n", mkrfc1123(squid_curtime + 86400)); + l += snprintf(buf+l, SM_PAGE_SIZE-l, "\r\n"); + httpParseReplyHeaders(buf, e->mem_obj->reply); + storeAppend(e, buf, l); + while ((n = read(fd, buf, SM_PAGE_SIZE)) > 0) + storeAppend(e, buf, n); + file_close(fd); + storeSetPublicKey(e); + storeComplete(e); + storeTimestampsSet(e); + BIT_SET(e->flag, ENTRY_SPECIAL); + debug(25,1)("Loaded icon %s\n", url); + put_free_4k_page(buf); +} diff --git a/src/store.cc b/src/store.cc index df99bc28e8..349d4ba862 100644 --- a/src/store.cc +++ b/src/store.cc @@ -1,6 +1,6 @@ /* - * $Id: store.cc,v 1.276 1997/07/16 22:58:25 wessels Exp $ + * $Id: store.cc,v 1.277 1997/07/19 01:33:58 wessels Exp $ * * DEBUG: section 20 Storeage Manager * AUTHOR: Harvest Derived @@ -2065,6 +2065,8 @@ storeEntryLocked(const StoreEntry * e) return 1; if (e->store_status == STORE_PENDING) return 1; + if (BIT_TEST(e->flag, ENTRY_SPECIAL)) + return 1; return 0; } diff --git a/src/structs.h b/src/structs.h index 7470c0c273..5205f52737 100644 --- a/src/structs.h +++ b/src/structs.h @@ -232,6 +232,10 @@ struct _SquidConfig { int n_configured; } cacheSwap; char *fake_ua; + struct { + char *directory; + char *content_type; + } icons; }; struct _SquidConfig2 {