]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/acl/Eui64.cc
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / acl / Eui64.cc
index d023945316342a84a509e1cff4c210d4b188616a..30ea5f61cb4e4b5bc93ce366640d067db99cffd3 100644 (file)
@@ -1,52 +1,23 @@
 /*
- * DEBUG: section 28    Access Control
- * AUTHOR: Amos Jeffries
+ * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
  *
- * SQUID Web Proxy Cache          http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- *  Squid is the result of efforts by numerous individuals from
- *  the Internet community; see the CONTRIBUTORS file for full
- *  details.   Many organizations have provided support for Squid's
- *  development; see the SPONSORS file for full details.  Squid is
- *  Copyrighted (C) 2001 by the Regents of the University of
- *  California; see the COPYRIGHT file for full details.  Squid
- *  incorporates software developed and/or copyrighted by other
- *  sources; see the CREDITS file for full details.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
- *
- *
- * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
+/* DEBUG: section 28    Access Control */
+
 #include "squid.h"
 
 #if USE_SQUID_EUI
 
 #include "acl/Eui64.h"
 #include "acl/FilledChecklist.h"
+#include "Debug.h"
 #include "eui/Eui64.h"
-#include "ip/IpAddress.h"
-#include "wordlist.h"
-
-static void aclParseEuiList(SplayNode<Eui::Eui64 *> **curlist);
-static int aclMatchEui(SplayNode<Eui::Eui64 *> **dataptr, Ip::Address &c);
-static SplayNode<Eui::Eui64 *>::SPLAYCMP aclEui64Compare;
-static SplayNode<Eui::Eui64 *>::SPLAYWALKEE aclDumpEuiListWalkee;
-
+#include "globals.h"
+#include "ip/Address.h"
 
 ACL *
 ACLEui64::clone() const
@@ -54,19 +25,11 @@ ACLEui64::clone() const
     return new ACLEui64(*this);
 }
 
-ACLEui64::ACLEui64 (char const *theClass) : data (NULL), class_ (theClass)
+ACLEui64::ACLEui64 (char const *theClass) : class_ (theClass)
 {}
 
-ACLEui64::ACLEui64 (ACLEui64 const & old) : data (NULL), class_ (old.class_)
-{
-    /* we don't have copy constructors for the data yet */
-    assert (!old.data);
-}
-
-ACLEui64::~ACLEui64()
+ACLEui64::ACLEui64 (ACLEui64 const & old) : eui64Data(old.eui64Data), class_ (old.class_)
 {
-    if (data)
-        data->destroy(SplayNode<Eui::Eui64*>::DefaultFree);
 }
 
 char const *
@@ -78,7 +41,7 @@ ACLEui64::typeString() const
 bool
 ACLEui64::empty () const
 {
-    return data->empty();
+    return eui64Data.empty();
 }
 
 Eui::Eui64 *
@@ -89,43 +52,32 @@ aclParseEuiData(const char *t)
     debugs(28, 5, "aclParseEuiData: " << t);
 
     if (sscanf(t, "%[0-9a-fA-F:]", buf) != 1) {
-        debugs(28, 0, "aclParseEuiData: Bad EUI-64 address: '" << t << "'");
-        safe_free(q);
+        debugs(28, DBG_CRITICAL, "aclParseEuiData: Bad EUI-64 address: '" << t << "'");
+        delete q;
         return NULL;
     }
 
     if (!q->decode(buf)) {
-        debugs(28, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
-        debugs(28, 0, "aclParseEuiData: Ignoring invalid EUI-64 acl entry: can't parse '" << buf << "'");
-        safe_free(q);
+        debugs(28, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
+        debugs(28, DBG_CRITICAL, "aclParseEuiData: Ignoring invalid EUI-64 acl entry: can't parse '" << buf << "'");
+        delete q;
         return NULL;
     }
 
     return q;
 }
 
-
 /*******************/
 /* aclParseEuiList */
 /*******************/
 void
 ACLEui64::parse()
 {
-    aclParseEuiList(&data);
-}
-
-void
-aclParseEuiList(SplayNode<Eui::Eui64 *> **curlist)
-{
-    char *t = NULL;
-    SplayNode<Eui::Eui64*> **Top = curlist;
-    Eui::Eui64 *q = NULL;
-
-    while ((t = strtokFile())) {
-        if ((q = aclParseEuiData(t)) == NULL)
-            continue;
-
-        *Top = (*Top)->insert(q, aclEui64Compare);
+    while (const char * t = ConfigParser::strtokFile()) {
+        if (Eui::Eui64 * q = aclParseEuiData(t)) {
+            eui64Data.insert(*q);
+            delete q;
+        }
     }
 }
 
@@ -135,57 +87,33 @@ ACLEui64::match(ACLChecklist *cl)
     ACLFilledChecklist *checklist = Filled(cl);
 
     /* IPv4 does not do EUI-64 (yet) */
-    if (!checklist->src_addr.IsIPv6()) {
+    if (!checklist->src_addr.isIPv6()) {
         debugs(14, 3, "ACLEui64::match: IPv6 Required for EUI-64 Lookups. Skipping " << checklist->src_addr );
         return 0;
     }
 
-    return aclMatchEui(&data, checklist->src_addr);
-}
-
-/***************/
-/* aclMatchEui */
-/***************/
-int
-aclMatchEui(SplayNode<Eui::Eui64 *> **dataptr, Ip::Address &c)
-{
-    Eui::Eui64 result;
-    SplayNode<Eui::Eui64 *> **Top = dataptr;
-
-    if (result.lookup(c)) {
-        /* Do ACL match lookup */
-        *Top = (*Top)->splay(&result, aclEui64Compare);
-        debugs(28, 3, "aclMatchEui: '" << c << "' " << (splayLastResult ? "NOT found" : "found"));
-        return (0 == splayLastResult);
+    Eui::Eui64 lookingFor;
+    if (lookingFor.lookup(checklist->src_addr)) {
+        bool found = (eui64Data.find(lookingFor) != eui64Data.end());
+        debugs(28, 3,  checklist->src_addr << "' " << (found ? "found" : "NOT found"));
+        return found;
     }
 
-    /*
-     * Address was not found on any interface
-     */
-    debugs(28, 3, "aclMatchEui: " << c << " NOT found");
+    debugs(28, 3, checklist->src_addr << " NOT found");
     return 0;
 }
 
-static int
-aclEui64Compare(Eui::Eui64 * const &a, Eui::Eui64 * const &b)
-{
-    return memcmp(a, b, sizeof(Eui::Eui64));
-}
-
-static void
-aclDumpEuiListWalkee(Eui::Eui64 * const &node, void *state)
-{
-    static char buf[48];
-    node->encode(buf, 48);
-    wordlistAdd((wordlist **)state, buf);
-}
-
-wordlist *
+SBufList
 ACLEui64::dump() const
 {
-    wordlist *w = NULL;
-    data->walk(aclDumpEuiListWalkee, &w);
-    return w;
+    SBufList sl;
+    for (auto i = eui64Data.begin(); i != eui64Data.end(); ++i) {
+        static char buf[48];
+        i->encode(buf,48);
+        sl.push_back(SBuf(buf));
+    }
+    return sl;
 }
 
 #endif /* USE_SQUID_EUI */
+