From 7660b45db95f5d0c2f8b67356ce8fab91b85dcf6 Mon Sep 17 00:00:00 2001 From: hno <> Date: Mon, 9 May 2005 07:41:25 +0000 Subject: [PATCH] Refactored the dst* acls as a Strategised acl --- src/ACLDestinationDomain.cc | 121 +++++++++++------------------------- src/ACLDestinationDomain.h | 59 +++++++++--------- src/ACLSourceDomain.cc | 7 +-- src/cf.data.pre | 8 +-- 4 files changed, 70 insertions(+), 125 deletions(-) diff --git a/src/ACLDestinationDomain.cc b/src/ACLDestinationDomain.cc index c403d80e2a..45042b1eab 100644 --- a/src/ACLDestinationDomain.cc +++ b/src/ACLDestinationDomain.cc @@ -1,5 +1,5 @@ /* - * $Id: ACLDestinationDomain.cc,v 1.10 2005/05/08 06:53:58 hno Exp $ + * $Id: ACLDestinationDomain.cc,v 1.11 2005/05/09 01:41:25 hno Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -36,60 +36,64 @@ #include "squid.h" #include "ACLDestinationDomain.h" -#include "authenticate.h" #include "ACLChecklist.h" #include "ACLRegexData.h" #include "ACLDomainData.h" #include "HttpRequest.h" -ACLDestinationDomain::~ACLDestinationDomain() -{ - delete data; -} - -ACLDestinationDomain::ACLDestinationDomain(ACLData *newData, char const *theType) : data (newData), type_(theType) {} - -ACLDestinationDomain::ACLDestinationDomain (ACLDestinationDomain const &old) : data (old.data->clone()), type_(old.type_) -{} +DestinationDomainLookup DestinationDomainLookup::instance_; -ACLDestinationDomain & -ACLDestinationDomain::operator= (ACLDestinationDomain const &rhs) +DestinationDomainLookup * +DestinationDomainLookup::Instance() { - data = rhs.data->clone(); - type_ = rhs.type_; - return *this; + return &instance_; } -char const * -ACLDestinationDomain::typeString() const +void +DestinationDomainLookup::checkForAsync(ACLChecklist *checklist)const { - return type_; + checklist->asyncInProgress(true); + fqdncache_nbgethostbyaddr(checklist->src_addr, LookupDone, checklist); } void -ACLDestinationDomain::parse() +DestinationDomainLookup::LookupDone(const char *fqdn, void *data) { - data->parse(); + ACLChecklist *checklist = (ACLChecklist *)data; + assert (checklist->asyncState() == DestinationDomainLookup::Instance()); + + checklist->asyncInProgress(false); + checklist->changeState (ACLChecklist::NullState::Instance()); + checklist->markDestinationDomainChecked(); + checklist->check(); } +ACL::Prototype ACLDestinationDomain::LiteralRegistryProtoype(&ACLDestinationDomain::LiteralRegistryEntry_, "dstdomain"); +ACLStrategised ACLDestinationDomain::LiteralRegistryEntry_(new ACLDomainData, ACLDestinationDomainStrategy::Instance(), "dstdomain"); +ACL::Prototype ACLDestinationDomain::RegexRegistryProtoype(&ACLDestinationDomain::RegexRegistryEntry_, "dstdom_regex"); +ACLStrategised ACLDestinationDomain::RegexRegistryEntry_(new ACLRegexData,ACLDestinationDomainStrategy::Instance() ,"dstdom_regex"); + int -ACLDestinationDomain::match(ACLChecklist *checklist) +ACLDestinationDomainStrategy::match (ACLData * &data, ACLChecklist *checklist) { const ipcache_addrs *ia = NULL; + if (data->match(checklist->request->host)) + return 1; + if ((ia = ipcacheCheckNumeric(checklist->request->host)) == NULL) - return data->match(checklist->request->host); + return 0; const char *fqdn = NULL; fqdn = fqdncache_gethostbyaddr(ia->in_addrs[0], FQDN_LOOKUP_IF_MISS); - if (fqdn) + if (fqdn) { return data->match(fqdn); - - if (!checklist->destinationDomainChecked()) { + } else if (!checklist->destinationDomainChecked()) { + /* FIXME: Using AclMatchedName here is not OO correct. Should find a way to the current acl */ debug(28, 3) ("aclMatchAcl: Can't yet compare '%s' ACL for '%s'\n", - name, inet_ntoa(ia->in_addrs[0])); + AclMatchedName, checklist->request->host); checklist->changeState(DestinationDomainLookup::Instance()); return 0; } @@ -97,65 +101,10 @@ ACLDestinationDomain::match(ACLChecklist *checklist) return data->match("none"); } -wordlist * -ACLDestinationDomain::dump() const -{ - return data->dump(); -} - -bool -ACLDestinationDomain::empty () const +ACLDestinationDomainStrategy * +ACLDestinationDomainStrategy::Instance() { - return data->empty(); + return &Instance_; } -DestinationDomainLookup DestinationDomainLookup::instance_; - -DestinationDomainLookup * -DestinationDomainLookup::Instance() -{ - return &instance_; -} - -void -DestinationDomainLookup::checkForAsync(ACLChecklist *checklist)const -{ - - ipcache_addrs *ia; - ia = ipcacheCheckNumeric(checklist->request->host); - - if (ia == NULL) { - /* Make fatal? XXX this is checked during match() */ - checklist->markDestinationDomainChecked(); - checklist->changeState (ACLChecklist::NullState::Instance()); - } else { - checklist->asyncInProgress(true); - checklist->dst_addr = ia->in_addrs[0]; - fqdncache_nbgethostbyaddr(checklist->dst_addr, - LookupDone, checklist); - } -} - -void -DestinationDomainLookup::LookupDone(const char *fqdn, void *data) -{ - ACLChecklist *checklist = (ACLChecklist *)data; - assert (checklist->asyncState() == DestinationDomainLookup::Instance()); - - checklist->asyncInProgress(false); - checklist->changeState (ACLChecklist::NullState::Instance()); - checklist->markDestinationDomainChecked(); - checklist->check(); -} - -ACL::Prototype ACLDestinationDomain::LiteralRegistryProtoype(&ACLDestinationDomain::LiteralRegistryEntry_, "dstdomain"); -ACL::Prototype ACLDestinationDomain::LegacyRegistryProtoype(&ACLDestinationDomain::LiteralRegistryEntry_, "domain"); -ACLDestinationDomain ACLDestinationDomain::LiteralRegistryEntry_(new ACLDomainData, "dstdomain"); -ACL::Prototype ACLDestinationDomain::RegexRegistryProtoype(&ACLDestinationDomain::RegexRegistryEntry_, "dstdom_regex"); -ACLDestinationDomain ACLDestinationDomain::RegexRegistryEntry_(new ACLRegexData, "dstdom_regex"); - -ACL * -ACLDestinationDomain::clone() const -{ - return new ACLDestinationDomain(*this); -} +ACLDestinationDomainStrategy ACLDestinationDomainStrategy::Instance_; diff --git a/src/ACLDestinationDomain.h b/src/ACLDestinationDomain.h index f35edc38e3..b5ddc57843 100644 --- a/src/ACLDestinationDomain.h +++ b/src/ACLDestinationDomain.h @@ -1,6 +1,6 @@ /* - * $Id: ACLDestinationDomain.h,v 1.7 2005/05/06 01:57:55 hno Exp $ + * $Id: ACLDestinationDomain.h,v 1.8 2005/05/09 01:41:25 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -33,11 +33,30 @@ * Copyright (c) 2003, Robert Collins */ -#ifndef SQUID_ACLDESTINATIONDOMAIN_H -#define SQUID_ACLDESTINATIONDOMAIN_H +#ifndef SQUID_ACLSOURCEDOMAIN_H +#define SQUID_ACLSOURCEDOMAIN_H #include "ACL.h" #include "ACLData.h" #include "ACLChecklist.h" +#include "ACLStrategised.h" + +class ACLDestinationDomainStrategy : public ACLStrategy +{ + +public: + virtual int match (ACLData * &, ACLChecklist *); + static ACLDestinationDomainStrategy *Instance(); + /* Not implemented to prevent copies of the instance. */ + /* Not private to prevent brain dead g+++ warnings about + * private constructors with no friends */ + ACLDestinationDomainStrategy(ACLDestinationDomainStrategy const &); + +private: + static ACLDestinationDomainStrategy Instance_; + ACLDestinationDomainStrategy(){} + + ACLDestinationDomainStrategy&operator=(ACLDestinationDomainStrategy const &); +}; class DestinationDomainLookup : public ACLChecklist::AsyncState { @@ -51,36 +70,14 @@ private: static void LookupDone(const char *, void *); }; -class ACLDestinationDomain : public ACL +class ACLDestinationDomain { -public: - MEMPROXY_CLASS(ACLDestinationDomain); - - ~ACLDestinationDomain(); - ACLDestinationDomain(ACLData *, char const *); - ACLDestinationDomain (ACLDestinationDomain const &); - ACLDestinationDomain &operator= (ACLDestinationDomain const &); - - virtual char const *typeString() const; - virtual void parse(); - virtual int match(ACLChecklist *checklist); - virtual wordlist *dump() const; - virtual bool empty () const; - virtual bool requiresRequest() const {return true;} - - virtual ACL *clone()const; - private: - static Prototype LiteralRegistryProtoype; - static Prototype LegacyRegistryProtoype; - static ACLDestinationDomain LiteralRegistryEntry_; - static Prototype RegexRegistryProtoype; - static ACLDestinationDomain RegexRegistryEntry_; - ACLData *data; - char const *type_; + static ACL::Prototype LiteralRegistryProtoype; + static ACLStrategised LiteralRegistryEntry_; + static ACL::Prototype RegexRegistryProtoype; + static ACLStrategised RegexRegistryEntry_; }; -MEMPROXY_CLASS_INLINE(ACLDestinationDomain) - -#endif /* SQUID_ACLDESTINATIONDOMAIN_H */ +#endif /* SQUID_ACLSOURCEDOMAIN_H */ diff --git a/src/ACLSourceDomain.cc b/src/ACLSourceDomain.cc index 42a6e6b2ce..ed71ac4517 100644 --- a/src/ACLSourceDomain.cc +++ b/src/ACLSourceDomain.cc @@ -1,5 +1,5 @@ /* - * $Id: ACLSourceDomain.cc,v 1.3 2003/02/21 22:50:04 robertc Exp $ + * $Id: ACLSourceDomain.cc,v 1.4 2005/05/09 01:41:25 hno Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -81,10 +81,9 @@ ACLSourceDomainStrategy::match (ACLData * &data, ACLChecklist *checkl if (fqdn) { return data->match(fqdn); } else if (!checklist->sourceDomainChecked()) { - /* FIXME: reinstate a means to get to "name" + /* FIXME: Using AclMatchedName here is not OO correct. Should find a way to the current acl */ debug(28, 3) ("aclMatchAcl: Can't yet compare '%s' ACL for '%s'\n", - name, inet_ntoa(checklist->src_addr)); - */ + AclMatchedName, inet_ntoa(checklist->src_addr)); checklist->changeState(SourceDomainLookup::Instance()); return 0; } diff --git a/src/cf.data.pre b/src/cf.data.pre index 8c9779fc6e..42d333beda 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -1,6 +1,6 @@ # -# $Id: cf.data.pre,v 1.389 2005/05/08 14:11:12 serassio Exp $ +# $Id: cf.data.pre,v 1.390 2005/05/09 01:41:25 hno Exp $ # # # SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -2493,9 +2493,9 @@ DOC_START acl aclname dstdomain .foo.com ... # Destination server from URL acl aclname srcdom_regex [-i] xxx ... # regex matching client name acl aclname dstdom_regex [-i] xxx ... # regex matching server - # For dstdomain and dstdom_regex a reverse lookup is tried if a IP - # based URL is used. The name "none" is used if the reverse lookup - # fails. + # For dstdomain and dstdom_regex a reverse lookup is tried if a IP + # based URL is used and no match is found. The name "none" is used + # if the reverse lookup fails. acl aclname time [day-abbrevs] [h1:m1-h2:m2] day-abbrevs: -- 2.47.3