]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/adaptation/icap/Launcher.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / adaptation / icap / Launcher.cc
index d95c3377f1e788942e75260eb9cc8c1b0984b057..a1cdde35e104d05e84dfbfa1086564c109fbca1c 100644 (file)
@@ -1,24 +1,31 @@
 /*
- * DEBUG: section 93  ICAP (RFC 3507) Client
+ * Copyright (C) 1996-2017 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.
  */
 
+/* DEBUG: section 93    ICAP (RFC 3507) Client */
+
 #include "squid.h"
 #include "acl/FilledChecklist.h"
+#include "adaptation/Answer.h"
+#include "adaptation/icap/Config.h"
 #include "adaptation/icap/Launcher.h"
-#include "adaptation/icap/Xaction.h"
 #include "adaptation/icap/ServiceRep.h"
-#include "adaptation/icap/Config.h"
+#include "adaptation/icap/Xaction.h"
 #include "base/TextException.h"
+#include "globals.h"
 #include "HttpMsg.h"
-#include "HttpRequest.h"
 #include "HttpReply.h"
-
+#include "HttpRequest.h"
 
 Adaptation::Icap::Launcher::Launcher(const char *aTypeName,
-                                     Adaptation::Initiator *anInitiator, Adaptation::ServicePointer &aService):
-        AsyncJob(aTypeName),
-        Adaptation::Initiate(aTypeName, anInitiator),
-        theService(aService), theXaction(0), theLaunches(0)
+                                     Adaptation::ServicePointer &aService):
+    AsyncJob(aTypeName),
+    Adaptation::Initiate(aTypeName),
+    theService(aService), theXaction(0), theLaunches(0)
 {
 }
 
@@ -31,7 +38,7 @@ void Adaptation::Icap::Launcher::start()
 {
     Adaptation::Initiate::start();
 
-    Must(theInitiator);
+    Must(theInitiator.set());
     launchXaction("first");
 }
 
@@ -42,20 +49,26 @@ void Adaptation::Icap::Launcher::launchXaction(const char *xkind)
     debugs(93,4, HERE << "launching " << xkind << " xaction #" << theLaunches);
     Adaptation::Icap::Xaction *x = createXaction();
     x->attempts = theLaunches;
-    if (theLaunches > 1)
+    if (theLaunches > 1) {
+        x->clearError();
         x->disableRetries();
+    }
     if (theLaunches >= TheConfig.repeat_limit)
         x->disableRepeats("over icap_retry_limit");
     theXaction = initiateAdaptation(x);
-    Must(theXaction);
+    Must(initiated(theXaction));
 }
 
-void Adaptation::Icap::Launcher::noteAdaptationAnswer(HttpMsg *message)
+void Adaptation::Icap::Launcher::noteAdaptationAnswer(const Answer &answer)
 {
-    sendAnswer(message);
+    debugs(93,5, HERE << "launches: " << theLaunches << " answer: " << answer);
+
+    // XXX: akError is unused by ICAPXaction in favor of noteXactAbort()
+    Must(answer.kind != Answer::akError);
+
+    sendAnswer(answer);
     clearAdaptation(theXaction);
     Must(done());
-    debugs(93,3, HERE << "Adaptation::Icap::Launcher::noteAdaptationAnswer exiting ");
 }
 
 void Adaptation::Icap::Launcher::noteInitiatorAborted()
@@ -67,16 +80,7 @@ void Adaptation::Icap::Launcher::noteInitiatorAborted()
 
 }
 
-// XXX: this call is unused by ICAPXaction in favor of ICAPLauncher::noteXactAbort
-void Adaptation::Icap::Launcher::noteAdaptationQueryAbort(bool final)
-{
-    debugs(93,5, HERE << "launches: " << theLaunches << "; final: " << final);
-    clearAdaptation(theXaction);
-
-    Must(done()); // swanSong will notify the initiator
-}
-
-void Adaptation::Icap::Launcher::noteXactAbort(XactAbortInfo &info)
+void Adaptation::Icap::Launcher::noteXactAbort(XactAbortInfo info)
 {
     debugs(93,5, HERE << "theXaction:" << theXaction << " launches: " << theLaunches);
 
@@ -102,10 +106,10 @@ bool Adaptation::Icap::Launcher::doneAll() const
 
 void Adaptation::Icap::Launcher::swanSong()
 {
-    if (theInitiator)
+    if (theInitiator.set())
         tellQueryAborted(true); // always final here because abnormal
 
-    if (theXaction)
+    if (theXaction.set())
         clearAdaptation(theXaction);
 
     Adaptation::Initiate::swanSong();
@@ -132,15 +136,18 @@ bool Adaptation::Icap::Launcher::canRepeat(Adaptation::Icap::XactAbortInfo &info
     if (!info.icapReply) // did not get to read an ICAP reply; a timeout?
         return true;
 
-    debugs(93,9, HERE << info.icapReply->sline.status);
-    if (!info.icapReply->sline.status) // failed to parse the reply; I/O err
+    debugs(93,9, info.icapReply->sline.status());
+    // XXX: Http::scNone is not the only sign of parse error
+    // XXX: if there is a specific HTTP error code describing the problem, that may be set
+    if (info.icapReply->sline.status() == Http::scNone) // failed to parse the reply; I/O err
         return true;
 
     ACLFilledChecklist *cl =
         new ACLFilledChecklist(TheConfig.repeat, info.icapRequest, dash_str);
-    cl->reply = HTTPMSGLOCK(info.icapReply);
+    cl->reply = info.icapReply;
+    HTTPMSGLOCK(cl->reply);
 
-    const bool result = cl->fastCheck();
+    bool result = cl->fastCheck() == ACCESS_ALLOWED;
     delete cl;
     return result;
 }
@@ -149,17 +156,27 @@ bool Adaptation::Icap::Launcher::canRepeat(Adaptation::Icap::XactAbortInfo &info
 
 Adaptation::Icap::XactAbortInfo::XactAbortInfo(HttpRequest *anIcapRequest,
         HttpReply *anIcapReply, bool beRetriable, bool beRepeatable):
-        icapRequest(anIcapRequest ? HTTPMSGLOCK(anIcapRequest) : NULL),
-        icapReply(anIcapReply ? HTTPMSGLOCK(anIcapReply) : NULL),
-        isRetriable(beRetriable), isRepeatable(beRepeatable)
+    icapRequest(anIcapRequest),
+    icapReply(anIcapReply),
+    isRetriable(beRetriable),
+    isRepeatable(beRepeatable)
 {
+    if (icapRequest)
+        HTTPMSGLOCK(icapRequest);
+    if (icapReply)
+        HTTPMSGLOCK(icapReply);
 }
 
 Adaptation::Icap::XactAbortInfo::XactAbortInfo(const Adaptation::Icap::XactAbortInfo &i):
-        icapRequest(i.icapRequest ? HTTPMSGLOCK(i.icapRequest) : NULL),
-        icapReply(i.icapReply ? HTTPMSGLOCK(i.icapReply) : NULL),
-        isRetriable(i.isRetriable), isRepeatable(i.isRepeatable)
+    icapRequest(i.icapRequest),
+    icapReply(i.icapReply),
+    isRetriable(i.isRetriable),
+    isRepeatable(i.isRepeatable)
 {
+    if (icapRequest)
+        HTTPMSGLOCK(icapRequest);
+    if (icapReply)
+        HTTPMSGLOCK(icapReply);
 }
 
 Adaptation::Icap::XactAbortInfo::~XactAbortInfo()
@@ -167,3 +184,4 @@ Adaptation::Icap::XactAbortInfo::~XactAbortInfo()
     HTTPMSGUNLOCK(icapRequest);
     HTTPMSGUNLOCK(icapReply);
 }
+