From: Amos Jeffries Date: Wed, 2 Nov 2016 04:37:37 +0000 (+1300) Subject: Cleanup: use SBufList for /etc/hosts parsing X-Git-Tag: SQUID_4_0_17~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1bff41b7eef72c67376aab922f9b3155deda3070;p=thirdparty%2Fsquid.git Cleanup: use SBufList for /etc/hosts parsing Remove one more use of wordlist in favour of SBufList Also, fixes bug in layer-02-maximus configure options --- diff --git a/src/fqdncache.cc b/src/fqdncache.cc index 2e68cefd13..19a4dbe574 100644 --- a/src/fqdncache.cc +++ b/src/fqdncache.cc @@ -22,7 +22,6 @@ #include "StatCounters.h" #include "Store.h" #include "util.h" -#include "wordlist.h" #if SQUID_SNMP #include "snmp_core.h" @@ -642,27 +641,20 @@ fqdncache_restart(void) } /** - \ingroup FQDNCacheAPI - * * Adds a "static" entry from /etc/hosts. - \par - * The worldist is to be managed by the caller, - * including pointed-to strings * \param addr FQDN name to be added. - \param hostnames ?? + \param hostnames list of hostnames for the addr */ void -fqdncacheAddEntryFromHosts(char *addr, wordlist * hostnames) +fqdncacheAddEntryFromHosts(char *addr, SBufList &hostnames) { - fqdncache_entry *fce; - int j = 0; - - if ((fce = fqdncache_get(addr))) { + fqdncache_entry *fce= fqdncache_get(addr); + if (fce) { if (1 == fce->flags.fromhosts) { fqdncacheUnlockEntry(fce); } else if (fce->locks > 0) { - debugs(35, DBG_IMPORTANT, "fqdncacheAddEntryFromHosts: can't add static entry for locked address '" << addr << "'"); + debugs(35, DBG_IMPORTANT, "WARNING: can't add static entry for locked address '" << addr << "'"); return; } else { fqdncacheRelease(fce); @@ -671,11 +663,11 @@ fqdncacheAddEntryFromHosts(char *addr, wordlist * hostnames) fce = new fqdncache_entry(addr); - while (hostnames) { - fce->names[j] = xstrdup(hostnames->key); + int j = 0; + for (auto &h : hostnames) { + fce->names[j] = xstrdup(h.c_str()); Tolower(fce->names[j]); ++j; - hostnames = hostnames->next; if (j >= FQDN_MAX_NAMES) break; diff --git a/src/fqdncache.h b/src/fqdncache.h index 763c6d8644..c688497f88 100644 --- a/src/fqdncache.h +++ b/src/fqdncache.h @@ -12,9 +12,9 @@ #define SQUID_FQDNCACHE_H_ #include "ip/Address.h" +#include "sbuf/forward.h" class StoreEntry; -class wordlist; namespace Dns { class LookupDetails; @@ -27,7 +27,7 @@ void fqdnStats(StoreEntry *); void fqdncacheFreeMemory(void); void fqdncache_restart(void); void fqdncache_purgelru(void *); -void fqdncacheAddEntryFromHosts(char *addr, wordlist * hostnames); +void fqdncacheAddEntryFromHosts(char *addr, SBufList &hostnames); const char *fqdncache_gethostbyaddr(const Ip::Address &, int flags); void fqdncache_nbgethostbyaddr(const Ip::Address &, FQDNH *, void *); diff --git a/src/tools.cc b/src/tools.cc index 5c6c9e43e7..98faaf0061 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -1014,7 +1014,7 @@ parseEtcHosts(void) if (!fp) { int xerrno = errno; - debugs(1, DBG_IMPORTANT, "parseEtcHosts: " << Config.etcHostsPath << ": " << xstrerr(xerrno)); + debugs(1, DBG_IMPORTANT, "parseEtcHosts: '" << Config.etcHostsPath << "' : " << xstrerr(xerrno)); return; } @@ -1023,8 +1023,6 @@ parseEtcHosts(void) #endif while (fgets(buf, 1024, fp)) { /* for each line */ - wordlist *hosts = NULL; - char *addr; if (buf[0] == '#') /* MS-windows likes to add comments */ continue; @@ -1033,7 +1031,7 @@ parseEtcHosts(void) lt = buf; - addr = buf; + char *addr = buf; debugs(1, 5, "etc_hosts: line is '" << buf << "'"); @@ -1048,6 +1046,8 @@ parseEtcHosts(void) lt = nt + 1; + SBufList hosts; + while ((nt = strpbrk(lt, w_space))) { char *host = NULL; @@ -1073,19 +1073,16 @@ parseEtcHosts(void) if (ipcacheAddEntryFromHosts(host, addr) != 0) { /* invalid address, continuing is useless */ - wordlistDestroy(&hosts); - hosts = NULL; + hosts.clear(); break; } - wordlistAdd(&hosts, host); + hosts.emplace_back(SBuf(host)); lt = nt + 1; } - if (hosts) { + if (!hosts.empty()) fqdncacheAddEntryFromHosts(addr, hosts); - wordlistDestroy(&hosts); - } } fclose (fp); diff --git a/test-suite/buildtests/layer-02-maximus.opts b/test-suite/buildtests/layer-02-maximus.opts index ef0cb00863..3d51689531 100644 --- a/test-suite/buildtests/layer-02-maximus.opts +++ b/test-suite/buildtests/layer-02-maximus.opts @@ -82,7 +82,7 @@ DISTCHECK_CONFIGURE_FLAGS=" \ --enable-leakfinder \ --enable-follow-x-forwarded-for \ --enable-ident-lookups \ - --enable-default-hostsfile \ + --enable-default-hostsfile=/etc/hosts \ --enable-auth \ --enable-basic-auth-helpers \ --enable-ntlm-auth-helpers \