From 6a32ab4f0a5c8437f55b2549428b3034fb1d53f8 Mon Sep 17 00:00:00 2001 From: Francesco Chemolli Date: Tue, 30 Dec 2014 23:13:01 +0100 Subject: [PATCH] Fixed Acl::Ip --- src/acl/Ip.cc | 35 +++++++++++++++-------------------- src/acl/Ip.h | 4 +--- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/acl/Ip.cc b/src/acl/Ip.cc index aded60f1e4..8b7a77bebe 100644 --- a/src/acl/Ip.cc +++ b/src/acl/Ip.cc @@ -30,18 +30,6 @@ ACLIP::operator delete (void *address) fatal ("ACLIP::operator delete: unused"); } -/** - * Writes an IP ACL data into a buffer, then copies the buffer into the wordlist given - * - \param ip ACL data structure to display - \param state wordlist structure which is being generated - */ -void -ACLIP::DumpIpListWalkee(acl_ip_data * const & ip, void *state) -{ - static_cast(state)->push_back(ip->toSBuf()); -} - /** * print/format an acl_ip_data structure for debugging output. * @@ -494,7 +482,7 @@ ACLIP::parse() /* pop each result off the list and add it to the data tree individually */ acl_ip_data *next_node = q->next; q->next = NULL; - data = data->insert(q, acl_ip_data::NetworkCompare); + data->insert(q, acl_ip_data::NetworkCompare); q = next_node; } } @@ -503,15 +491,22 @@ ACLIP::parse() ACLIP::~ACLIP() { if (data) - data->destroy(IPSplay::DefaultFree); + data->destroy(); } +struct IpAclDumpVisitor { + SBufList contents; + void operator() (acl_ip_data * const & ip) { + contents.push_back(ip->toSBuf()); + } +}; + SBufList ACLIP::dump() const { - SBufList sl; - data->walk(DumpIpListWalkee, &sl); - return sl; + IpAclDumpVisitor visitor; + data->visit(visitor); + return visitor.contents; } bool @@ -534,9 +529,9 @@ ACLIP::match(Ip::Address &clientip) ClientAddress.addr2.setEmpty(); ClientAddress.mask.setEmpty(); - data = data->splay(&ClientAddress, aclIpAddrNetworkCompare); - debugs(28, 3, "aclIpMatchIp: '" << clientip << "' " << (splayLastResult ? "NOT found" : "found")); - return !splayLastResult; + const acl_ip_data * const * result = data->find(&ClientAddress, aclIpAddrNetworkCompare); + debugs(28, 3, "aclIpMatchIp: '" << clientip << "' " << (result ? "found" : "NOT found")); + return (result != NULL); } acl_ip_data::acl_ip_data() :addr1(), addr2(), mask(), next (NULL) {} diff --git a/src/acl/Ip.h b/src/acl/Ip.h index 3995c20d73..9f065f9dd7 100644 --- a/src/acl/Ip.h +++ b/src/acl/Ip.h @@ -52,7 +52,7 @@ public: ~ACLIP(); - typedef SplayNode IPSplay; + typedef Splay IPSplay; virtual char const *typeString() const = 0; virtual void parse(); @@ -66,8 +66,6 @@ protected: int match(Ip::Address &); IPSplay *data; -private: - static void DumpIpListWalkee(acl_ip_data * const & ip, void *state); }; #endif /* SQUID_ACLIP_H */ -- 2.47.2