]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/icap/Launcher.cc
2 * DEBUG: section 93 ICAP (RFC 3507) Client
6 #include "acl/FilledChecklist.h"
7 #include "adaptation/Answer.h"
8 #include "adaptation/icap/Launcher.h"
9 #include "adaptation/icap/Xaction.h"
10 #include "adaptation/icap/ServiceRep.h"
11 #include "adaptation/icap/Config.h"
12 #include "base/TextException.h"
15 #include "HttpRequest.h"
16 #include "HttpReply.h"
18 Adaptation::Icap::Launcher::Launcher(const char *aTypeName
,
19 Adaptation::ServicePointer
&aService
):
21 Adaptation::Initiate(aTypeName
),
22 theService(aService
), theXaction(0), theLaunches(0)
26 Adaptation::Icap::Launcher::~Launcher()
31 void Adaptation::Icap::Launcher::start()
33 Adaptation::Initiate::start();
35 Must(theInitiator
.set());
36 launchXaction("first");
39 void Adaptation::Icap::Launcher::launchXaction(const char *xkind
)
43 debugs(93,4, HERE
<< "launching " << xkind
<< " xaction #" << theLaunches
);
44 Adaptation::Icap::Xaction
*x
= createXaction();
45 x
->attempts
= theLaunches
;
46 if (theLaunches
> 1) {
50 if (theLaunches
>= TheConfig
.repeat_limit
)
51 x
->disableRepeats("over icap_retry_limit");
52 theXaction
= initiateAdaptation(x
);
53 Must(initiated(theXaction
));
56 void Adaptation::Icap::Launcher::noteAdaptationAnswer(const Answer
&answer
)
58 debugs(93,5, HERE
<< "launches: " << theLaunches
<< " answer: " << answer
);
60 // XXX: akError is unused by ICAPXaction in favor of noteXactAbort()
61 Must(answer
.kind
!= Answer::akError
);
64 clearAdaptation(theXaction
);
68 void Adaptation::Icap::Launcher::noteInitiatorAborted()
71 announceInitiatorAbort(theXaction
); // propogate to the transaction
73 Must(done()); // should be nothing else to do
77 void Adaptation::Icap::Launcher::noteXactAbort(XactAbortInfo info
)
79 debugs(93,5, HERE
<< "theXaction:" << theXaction
<< " launches: " << theLaunches
);
81 // TODO: add more checks from FwdState::checkRetry()?
83 clearAdaptation(theXaction
);
84 launchXaction("retry");
85 } else if (canRepeat(info
)) {
86 clearAdaptation(theXaction
);
87 launchXaction("repeat");
89 debugs(93,3, HERE
<< "cannot retry or repeat a failed transaction");
90 clearAdaptation(theXaction
);
91 tellQueryAborted(false); // caller decides based on bypass, consumption
96 bool Adaptation::Icap::Launcher::doneAll() const
98 return (!theInitiator
|| !theXaction
) && Adaptation::Initiate::doneAll();
101 void Adaptation::Icap::Launcher::swanSong()
103 if (theInitiator
.set())
104 tellQueryAborted(true); // always final here because abnormal
106 if (theXaction
.set())
107 clearAdaptation(theXaction
);
109 Adaptation::Initiate::swanSong();
112 bool Adaptation::Icap::Launcher::canRetry(Adaptation::Icap::XactAbortInfo
&info
) const
114 // We do not check and can exceed zero repeat limit when retrying.
115 // This is by design as the limit does not apply to pconn retrying.
116 return !shutting_down
&& info
.isRetriable
;
119 bool Adaptation::Icap::Launcher::canRepeat(Adaptation::Icap::XactAbortInfo
&info
) const
121 debugs(93,9, HERE
<< shutting_down
);
122 if (theLaunches
>= TheConfig
.repeat_limit
|| shutting_down
)
125 debugs(93,9, HERE
<< info
.isRepeatable
); // TODO: update and use status()
126 if (!info
.isRepeatable
)
129 debugs(93,9, HERE
<< info
.icapReply
);
130 if (!info
.icapReply
) // did not get to read an ICAP reply; a timeout?
133 debugs(93,9, HERE
<< info
.icapReply
->sline
.status
);
134 if (!info
.icapReply
->sline
.status
) // failed to parse the reply; I/O err
137 ACLFilledChecklist
*cl
=
138 new ACLFilledChecklist(TheConfig
.repeat
, info
.icapRequest
, dash_str
);
139 cl
->reply
= info
.icapReply
;
140 HTTPMSGLOCK(cl
->reply
);
142 bool result
= cl
->fastCheck() == ACCESS_ALLOWED
;
147 /* ICAPXactAbortInfo */
149 Adaptation::Icap::XactAbortInfo::XactAbortInfo(HttpRequest
*anIcapRequest
,
150 HttpReply
*anIcapReply
, bool beRetriable
, bool beRepeatable
):
151 icapRequest(anIcapRequest
),
152 icapReply(anIcapReply
),
153 isRetriable(beRetriable
),
154 isRepeatable(beRepeatable
)
157 HTTPMSGLOCK(icapRequest
);
159 HTTPMSGLOCK(icapReply
);
162 Adaptation::Icap::XactAbortInfo::XactAbortInfo(const Adaptation::Icap::XactAbortInfo
&i
):
163 icapRequest(i
.icapRequest
),
164 icapReply(i
.icapReply
),
165 isRetriable(i
.isRetriable
),
166 isRepeatable(i
.isRepeatable
)
169 HTTPMSGLOCK(icapRequest
);
171 HTTPMSGLOCK(icapReply
);
174 Adaptation::Icap::XactAbortInfo::~XactAbortInfo()
176 HTTPMSGUNLOCK(icapRequest
);
177 HTTPMSGUNLOCK(icapReply
);