]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Cleanup: use SBufList for /etc/hosts parsing
authorAmos Jeffries <squid3@treenet.co.nz>
Wed, 2 Nov 2016 04:37:37 +0000 (17:37 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 2 Nov 2016 04:37:37 +0000 (17:37 +1300)
Remove one more use of wordlist in favour of SBufList

Also, fixes bug in layer-02-maximus configure options

src/fqdncache.cc
src/fqdncache.h
src/tools.cc
test-suite/buildtests/layer-02-maximus.opts

index 2e68cefd13ae2aff42ae3ae7b71269bd36740cd9..19a4dbe5743838393b2343b10049c4211bc37ec4 100644 (file)
@@ -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;
index 763c6d8644c58a23469c77be8277e65df12210b1..c688497f8860f67d0bbd9df54ba9436d846b3a35 100644 (file)
@@ -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 *);
index 5c6c9e43e76278ed3306ec5634d64d7e8bae415e..98faaf00619abd488f22434873bf322f65b35636 100644 (file)
@@ -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);
index ef0cb00863bbf8d31ef904399375dde3817ed641..3d51689531dfab7f45280152ba5c7ffb99759c60 100644 (file)
@@ -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 \