]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Refactored the dst* acls as a Strategised acl
authorhno <>
Mon, 9 May 2005 07:41:25 +0000 (07:41 +0000)
committerhno <>
Mon, 9 May 2005 07:41:25 +0000 (07:41 +0000)
src/ACLDestinationDomain.cc
src/ACLDestinationDomain.h
src/ACLSourceDomain.cc
src/cf.data.pre

index c403d80e2a5b96336594ffb7dd9f26b7e93a2d0e..45042b1eab8127a5c8f4aa75da92b427a42037eb 100644 (file)
@@ -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
 
 #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<char const *> *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<char const *> ACLDestinationDomain::LiteralRegistryEntry_(new ACLDomainData, ACLDestinationDomainStrategy::Instance(), "dstdomain");
+ACL::Prototype ACLDestinationDomain::RegexRegistryProtoype(&ACLDestinationDomain::RegexRegistryEntry_, "dstdom_regex");
+ACLStrategised<char const *> ACLDestinationDomain::RegexRegistryEntry_(new ACLRegexData,ACLDestinationDomainStrategy::Instance() ,"dstdom_regex");
+
 int
-ACLDestinationDomain::match(ACLChecklist *checklist)
+ACLDestinationDomainStrategy::match (ACLData<MatchType> * &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_;
index f35edc38e39ef2e3e867d5678b0b1ba1aded16e3..b5ddc57843899852684609bba3b66aa99aafd64e 100644 (file)
@@ -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/
  * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
  */
 
-#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<char const *>
+{
+
+public:
+    virtual int match (ACLData<MatchType> * &, 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 *> *, 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<char const *> *data;
-    char const *type_;
+    static ACL::Prototype LiteralRegistryProtoype;
+    static ACLStrategised<char const *> LiteralRegistryEntry_;
+    static ACL::Prototype RegexRegistryProtoype;
+    static ACLStrategised<char const *> RegexRegistryEntry_;
 };
 
-MEMPROXY_CLASS_INLINE(ACLDestinationDomain)
-
-#endif /* SQUID_ACLDESTINATIONDOMAIN_H */
+#endif /* SQUID_ACLSOURCEDOMAIN_H */
index 42a6e6b2cea730b44b41c0346fa93a0352ea112e..ed71ac45177b6c24b42ec7d037c1e17f51cd0eef 100644 (file)
@@ -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<MatchType> * &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;
     }
index 8c9779fc6e4a3be6f4c457f490280fd25e26fbad..42d333bedac9f6fc532c9704d7c68ab115e46ac7 100644 (file)
@@ -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: