]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/adaptation/AccessRule.cc
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / adaptation / AccessRule.cc
index c62d81948e004914afd1b79936b11049acaad99a..48add18ddcc23a6bb07ffcbff13409c58ef73f55 100644 (file)
@@ -1,52 +1,67 @@
-#include "squid.h"
-#include "structs.h"
+/*
+ * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
 
-#include "ConfigParser.h"
-#include "ACL.h"
+#include "squid.h"
+#include "acl/Gadgets.h"
+#include "acl/Tree.h"
 #include "adaptation/AccessRule.h"
 #include "adaptation/Service.h"
 #include "adaptation/ServiceGroups.h"
-
+#include "ConfigParser.h"
+#include "Debug.h"
 
 int Adaptation::AccessRule::LastId = 0;
 
-Adaptation::AccessRule::AccessRule(): id(++LastId), acl(NULL)
+Adaptation::AccessRule::AccessRule(const String &aGroupId): id(++LastId), groupId(aGroupId), acl(NULL)
 {
 }
 
 Adaptation::AccessRule::~AccessRule()
 {
-    // XXX: leaking acls here?
+    delete acl;
 }
 
 void
 Adaptation::AccessRule::parse(ConfigParser &parser)
 {
-    ConfigParser::ParseString(&groupId);
-    aclParseAccessLine(parser, &acl);
+    aclParseAccessLine("adaptation_access", parser, &acl);
 }
 
 void
 Adaptation::AccessRule::finalize()
 {
+    if (!group()) { // no explicit group
+        debugs(93,7, HERE << "no service group: " << groupId);
+        // try to add a one-service group
+        if (FindService(groupId) != NULL) {
+            ServiceGroupPointer g = new SingleService(groupId);
+            g->finalize(); // explicit groups were finalized before rules
+            AllGroups().push_back(g);
+        }
+    }
+
     if (!group()) {
-        debugs(93,0, "ERROR: Unknown adaptation service or group name: '" <<
-            groupId << "'"); // TODO: fail on failures
-       }
+        debugs(93, DBG_CRITICAL, "ERROR: Unknown adaptation service or group name: '" <<
+               groupId << "'"); // TODO: fail on failures
+    }
 }
 
-Adaptation::ServiceGroup *
+Adaptation::ServiceGroupPointer
 Adaptation::AccessRule::group()
 {
     return FindGroup(groupId);
 }
 
-
 Adaptation::AccessRules &
 Adaptation::AllRules()
 {
-    static AccessRules TheRules;
-    return TheRules;
+    static AccessRules *TheRules = new AccessRules;
+    return *TheRules;
 }
 
 // TODO: make AccessRules::find work
@@ -61,3 +76,16 @@ Adaptation::FindRule(const AccessRule::Id &id)
 
     return NULL;
 }
+
+Adaptation::AccessRule *
+Adaptation::FindRuleByGroupId(const String &groupId)
+{
+    typedef AccessRules::iterator ARI;
+    for (ARI i = AllRules().begin(); i != AllRules().end(); ++i) {
+        if ((*i)->groupId == groupId)
+            return *i;
+    }
+
+    return NULL;
+}
+