]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Moved AccessCheck object creation and check starting to AccessCheck::Start.
authorAlex Rousskov <rousskov@measurement-factory.com>
Fri, 4 Apr 2008 16:26:01 +0000 (10:26 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Fri, 4 Apr 2008 16:26:01 +0000 (10:26 -0600)
We may be able to simplify the callers further by migrating to the AsyncJobCall
interface for callbacks.

src/Server.cc
src/adaptation/AccessCheck.cc
src/adaptation/AccessCheck.h
src/client_side_request.cc

index e9bc416bd09eb8b8f4d696bac8cafb2598e9dc7a..9e03698ee4defa44b24eafb8999efa07073daa3f 100644 (file)
@@ -41,8 +41,7 @@
 
 #if USE_ADAPTATION
 #include "adaptation/AccessCheck.h"
-#include "ICAP/ICAPConfig.h"
-extern ICAPConfig TheICAPConfig;
+#include "adaptation/Service.h"
 #endif
 
 ServerStateData::ServerStateData(FwdState *theFwdState): AsyncJob("ServerStateData"),requestSender(NULL)
@@ -642,7 +641,7 @@ ServerStateData::adaptationAclCheckDone(Adaptation::ServicePointer service)
         sendBodyIsTooLargeError();
         return;
     }
-    // TODO: Should we check received5CBodyTooLarge on the server-side as well?
+    // TODO: Should we check receivedBodyTooLarge on the server-side as well?
 
     startedAdaptation = startAdaptation(service, originalRequest());
 
@@ -691,17 +690,13 @@ void
 ServerStateData::adaptOrFinalizeReply()
 {
 #if USE_ADAPTATION
-
-    if (TheICAPConfig.onoff) {
-         Adaptation::AccessCheck *check = new Adaptation::AccessCheck(
-            Adaptation::methodRespmod, ICAP::pointPreCache,
-                request, virginReply(), adaptationAclCheckDoneWrapper, this);
-
-        adaptationAccessCheckPending = true;
-        check->check(); // will eventually delete self
+    // TODO: merge with client side and return void to hide the on/off logic?
+    // The callback can be called with a NULL service if adaptation is off.
+    adaptationAccessCheckPending = Adaptation::AccessCheck::Start(
+        Adaptation::methodRespmod, Adaptation::pointPreCache,
+        request, virginReply(), adaptationAclCheckDoneWrapper, this);
+    if (adaptationAccessCheckPending)
         return;
-    }
-
 #endif
 
     setFinalReply(virginReply());
index 1cc57331bff1266bee9267e02d6f750685264c29..6219b85b9e47c793cb3445208c13d4ff712bff4f 100644 (file)
@@ -9,11 +9,27 @@
 #include "adaptation/Service.h"
 #include "adaptation/ServiceGroups.h"
 #include "adaptation/AccessRule.h"
+#include "adaptation/Config.h"
 #include "adaptation/AccessCheck.h"
 
 
 cbdata_type Adaptation::AccessCheck::CBDATA_AccessCheck = CBDATA_UNKNOWN;
 
+bool
+Adaptation::AccessCheck::Start(Method method, VectPoint vp,
+    HttpRequest *req, HttpReply *rep, AccessCheckCallback *cb, void *cbdata) {
+
+    if (Config::Enabled) {
+        // the new check will call the callback and delete self, eventually
+        AccessCheck *check = new AccessCheck(method, vp, req, rep, cb, cbdata);
+        check->check();
+        return true;
+       }
+
+    debugs(83, 3, HERE << "adaptation off, skipping");
+    return false;
+}
+
 Adaptation::AccessCheck::AccessCheck(Method aMethod,
                                  VectPoint aPoint,
                                  HttpRequest *aReq,
index 15b29b0ab82c111eb072f66fe4db0e35550c7634..e21d7ac2f0e73a7ffa0bb0391611f5a769a972eb 100644 (file)
@@ -15,9 +15,15 @@ class AccessRule;
 // checks adaptation_access rules to find a matching adaptation service
 class AccessCheck: public virtual AsyncJob
 {
-
 public:
     typedef void AccessCheckCallback(ServicePointer match, void *data);
+
+    // use this to start async ACL checks; returns true if started
+    static bool Start(Method method, VectPoint vp, HttpRequest *req, 
+        HttpReply *rep, AccessCheckCallback *cb, void *cbdata);
+
+protected:
+    // use Start to start adaptation checks
     AccessCheck(Method, VectPoint, HttpRequest *, HttpReply *, AccessCheckCallback *, void *);
     ~AccessCheck();
 
index 1beec35392f6f11372d6233efe2708d1eee77d44..f374eb248c81b1ea1ca71ce2535671bfa503b9c2 100644 (file)
@@ -61,7 +61,7 @@
 
 #if USE_ADAPTATION
 #include "adaptation/AccessCheck.h"
-#include "ICAP/ICAPConfig.h" /* XXX: replace with generic adaptation config */
+#include "adaptation/Service.h"
 static void adaptationAclCheckDoneWrapper(Adaptation::ServicePointer service, void *data);
 #endif
 
@@ -482,16 +482,6 @@ ClientRequestContext::clientAccessCheckDone(int answer)
 }
 
 #if USE_ADAPTATION
-void
-ClientRequestContext::adaptationAccessCheck()
-{
-    Adaptation::AccessCheck *check = new Adaptation::AccessCheck(
-        Adaptation::methodReqmod, Adaptation::pointPreCache,
-        http->request, NULL, adaptationAclCheckDoneWrapper, this);
-
-    check->check(); // will eventually delete self
-}
-
 static void
 adaptationAclCheckDoneWrapper(Adaptation::ServicePointer service, void *data)
 {
@@ -1063,13 +1053,13 @@ ClientHttpRequest::doCallouts()
     }
 
 #if USE_ADAPTATION
-    if (TheICAPConfig.onoff && !calloutContext->adaptation_acl_check_done) {
-        debugs(83, 3, HERE << "Doing calloutContext->adaptationAccessCheck()");
+    if (!calloutContext->adaptation_acl_check_done) {
         calloutContext->adaptation_acl_check_done = true;
-        calloutContext->adaptationAccessCheck();
-        return;
+        if (Adaptation::AccessCheck::Start(
+            Adaptation::methodReqmod, Adaptation::pointPreCache,
+            request, NULL, adaptationAclCheckDoneWrapper, this))
+            return; // will call callback
     }
-
 #endif
 
     if (!calloutContext->redirect_done) {