From: Alex Rousskov Date: Fri, 4 Apr 2008 16:26:01 +0000 (-0600) Subject: Moved AccessCheck object creation and check starting to AccessCheck::Start. X-Git-Tag: SQUID_3_1_0_1~49^2~302^2~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=abd4b6119cfac937348f13c4d7301ec0662d5bcb;p=thirdparty%2Fsquid.git Moved AccessCheck object creation and check starting to AccessCheck::Start. We may be able to simplify the callers further by migrating to the AsyncJobCall interface for callbacks. --- diff --git a/src/Server.cc b/src/Server.cc index e9bc416bd0..9e03698ee4 100644 --- a/src/Server.cc +++ b/src/Server.cc @@ -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()); diff --git a/src/adaptation/AccessCheck.cc b/src/adaptation/AccessCheck.cc index 1cc57331bf..6219b85b9e 100644 --- a/src/adaptation/AccessCheck.cc +++ b/src/adaptation/AccessCheck.cc @@ -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, diff --git a/src/adaptation/AccessCheck.h b/src/adaptation/AccessCheck.h index 15b29b0ab8..e21d7ac2f0 100644 --- a/src/adaptation/AccessCheck.h +++ b/src/adaptation/AccessCheck.h @@ -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(); diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 1beec35392..f374eb248c 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -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) {