--------------------- PatchSet 2633 Date: 2001/07/16 20:21:46 Author: serassio Branch: cygwin Tag: (none) Log: Added automatic hosts file lookup in Windows directories when /etc/hosts can't be found Members: src/tools.c:1.7.2.11->1.7.2.12 Index: squid/src/tools.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/tools.c,v retrieving revision 1.7.2.11 retrieving revision 1.7.2.12 diff -u -r1.7.2.11 -r1.7.2.12 --- squid/src/tools.c 27 May 2001 11:46:15 -0000 1.7.2.11 +++ squid/src/tools.c 16 Jul 2001 20:21:46 -0000 1.7.2.12 @@ -1,6 +1,6 @@ /* - * $Id: tools.c,v 1.7.2.11 2001/05/27 11:46:15 serassio Exp $ + * $Id: tools.c,v 1.7.2.12 2001/07/16 20:21:46 serassio Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -1011,15 +1011,47 @@ char *lt = buf; char *addr = buf; char *host = NULL; +#if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) + char * systemroot=NULL; +#endif if (NULL == Config.etcHostsPath) return; if (0 == strcmp(Config.etcHostsPath, "none")) return; fp = fopen(Config.etcHostsPath, "r"); if (fp == NULL) { +#if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) + switch (WIN32_OS_version) { + case _WIN_OS_WINNT: + case _WIN_OS_WIN2K: + if ((systemroot=getenv("SYSTEMROOT")) != NULL) { + strcpy(buf,systemroot); + strcat(buf,"\\system32\\drivers\\etc\\hosts"); + } + break; + case _WIN_OS_WIN95: + case _WIN_OS_WIN98: + if ((systemroot=getenv("WINDIR")) != NULL) { + strcpy(buf,systemroot); + strcat(buf,"\\hosts"); + } + break; + } + if (systemroot != NULL) { + safe_free(Config.etcHostsPath); + Config.etcHostsPath=xstrdup(buf); + fp = fopen(Config.etcHostsPath, "r"); + } + if (fp == NULL) { + debug(1, 1) ("parseEtcHosts: %s: %s\n", + Config.etcHostsPath, xstrerror()); + return; + } +#else debug(1, 1) ("parseEtcHosts: %s: %s\n", Config.etcHostsPath, xstrerror()); return; +#endif } #if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) setmode(fileno(fp), O_TEXT);