]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/icap/Launcher.cc
2 * DEBUG: section 93 ICAP (RFC 3507) Client
6 #include "TextException.h"
7 #include "HttpRequest.h"
9 #include "acl/FilledChecklist.h"
11 #include "adaptation/icap/Launcher.h"
12 #include "adaptation/icap/Xaction.h"
13 #include "adaptation/icap/ServiceRep.h"
14 #include "adaptation/icap/Config.h"
17 Adaptation::Icap::Launcher::Launcher(const char *aTypeName
,
18 Adaptation::Initiator
*anInitiator
, Adaptation::ServicePointer
&aService
):
20 Adaptation::Initiate(aTypeName
, anInitiator
),
21 theService(aService
), theXaction(0), theLaunches(0)
25 Adaptation::Icap::Launcher::~Launcher()
30 void Adaptation::Icap::Launcher::start()
32 Adaptation::Initiate::start();
35 launchXaction("first");
38 void Adaptation::Icap::Launcher::launchXaction(const char *xkind
)
42 debugs(93,4, HERE
<< "launching " << xkind
<< " xaction #" << theLaunches
);
43 Adaptation::Icap::Xaction
*x
= createXaction();
44 x
->attempts
= theLaunches
;
47 if (theLaunches
>= TheConfig
.repeat_limit
)
48 x
->disableRepeats("over icap_retry_limit");
49 theXaction
= initiateAdaptation(x
);
53 void Adaptation::Icap::Launcher::noteAdaptationAnswer(HttpMsg
*message
)
56 clearAdaptation(theXaction
);
58 debugs(93,3, HERE
<< "Adaptation::Icap::Launcher::noteAdaptationAnswer exiting ");
61 void Adaptation::Icap::Launcher::noteInitiatorAborted()
64 announceInitiatorAbort(theXaction
); // propogate to the transaction
66 Must(done()); // should be nothing else to do
70 // XXX: this call is unused by ICAPXaction in favor of ICAPLauncher::noteXactAbort
71 void Adaptation::Icap::Launcher::noteAdaptationQueryAbort(bool final
)
73 debugs(93,5, HERE
<< "launches: " << theLaunches
<< "; final: " << final
);
74 clearAdaptation(theXaction
);
76 Must(done()); // swanSong will notify the initiator
79 void Adaptation::Icap::Launcher::noteXactAbort(XactAbortInfo
&info
)
81 debugs(93,5, HERE
<< "theXaction:" << theXaction
<< " launches: " << theLaunches
);
83 // TODO: add more checks from FwdState::checkRetry()?
85 clearAdaptation(theXaction
);
86 launchXaction("retry");
87 } else if (canRepeat(info
)) {
88 clearAdaptation(theXaction
);
89 launchXaction("repeat");
91 debugs(93,3, HERE
<< "cannot retry or repeat a failed transaction");
92 clearAdaptation(theXaction
);
93 tellQueryAborted(false); // caller decides based on bypass, consumption
98 bool Adaptation::Icap::Launcher::doneAll() const
100 return (!theInitiator
|| !theXaction
) && Adaptation::Initiate::doneAll();
103 void Adaptation::Icap::Launcher::swanSong()
106 tellQueryAborted(true); // always final here because abnormal
109 clearAdaptation(theXaction
);
111 Adaptation::Initiate::swanSong();
114 bool Adaptation::Icap::Launcher::canRetry(Adaptation::Icap::XactAbortInfo
&info
) const
116 // We do not check and can exceed zero repeat limit when retrying.
117 // This is by design as the limit does not apply to pconn retrying.
118 return !shutting_down
&& info
.isRetriable
;
121 bool Adaptation::Icap::Launcher::canRepeat(Adaptation::Icap::XactAbortInfo
&info
) const
123 debugs(93,9, HERE
<< shutting_down
);
124 if (theLaunches
>= TheConfig
.repeat_limit
|| shutting_down
)
127 debugs(93,9, HERE
<< info
.isRepeatable
); // TODO: update and use status()
128 if (!info
.isRepeatable
)
131 debugs(93,9, HERE
<< info
.icapReply
);
132 if (!info
.icapReply
) // did not get to read an ICAP reply; a timeout?
135 debugs(93,9, HERE
<< info
.icapReply
->sline
.status
);
136 if (!info
.icapReply
->sline
.status
) // failed to parse the reply; I/O err
139 ACLFilledChecklist
*cl
=
140 new ACLFilledChecklist(TheConfig
.repeat
, info
.icapRequest
, dash_str
);
141 cl
->reply
= HTTPMSGLOCK(info
.icapReply
);
143 const bool result
= cl
->fastCheck();
148 /* ICAPXactAbortInfo */
150 Adaptation::Icap::XactAbortInfo::XactAbortInfo(HttpRequest
*anIcapRequest
,
151 HttpReply
*anIcapReply
, bool beRetriable
, bool beRepeatable
):
152 icapRequest(anIcapRequest
? HTTPMSGLOCK(anIcapRequest
) : NULL
),
153 icapReply(anIcapReply
? HTTPMSGLOCK(anIcapReply
) : NULL
),
154 isRetriable(beRetriable
), isRepeatable(beRepeatable
)
158 Adaptation::Icap::XactAbortInfo::XactAbortInfo(const Adaptation::Icap::XactAbortInfo
&i
):
159 icapRequest(i
.icapRequest
? HTTPMSGLOCK(i
.icapRequest
) : NULL
),
160 icapReply(i
.icapReply
? HTTPMSGLOCK(i
.icapReply
) : NULL
),
161 isRetriable(i
.isRetriable
), isRepeatable(i
.isRepeatable
)
165 Adaptation::Icap::XactAbortInfo::~XactAbortInfo()
167 HTTPMSGUNLOCK(icapRequest
);
168 HTTPMSGUNLOCK(icapReply
);