2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef SQUID_ICAPLAUNCHER_H
10 #define SQUID_ICAPLAUNCHER_H
12 #include "adaptation/icap/ServiceRep.h"
13 #include "adaptation/Initiate.h"
14 #include "adaptation/Initiator.h"
17 * The ICAP Launcher starts an ICAP transaction. If the transaction fails
18 * due to what looks like a persistent connection race condition, the launcher
19 * starts a new ICAP transaction using a freshly opened connection.
21 * ICAPLauncher and one or more ICAP transactions initiated by it form an
24 * An ICAP Initiator deals with the ICAP Launcher and not an individual ICAP
25 * transaction because the latter may disappear and be replaced by another
28 * Specific ICAP launchers implement the createXaction() method to create
29 * REQMOD, RESPMOD, or OPTIONS transaction from initiator-supplied data.
31 * TODO: This class might be the right place to initiate ICAP ACL checks or
32 * implement more sophisticated ICAP transaction handling like chaining of
44 // Note: Initiate must be the first parent for cbdata to work. We use
45 // a temporary InitaitorHolder/toCbdata hacks and do not call cbdata
46 // operations on the initiator directly.
47 class Launcher
: public Adaptation::Initiate
, public Adaptation::Initiator
50 Launcher(const char *aTypeName
, Adaptation::ServicePointer
&aService
);
53 // Adaptation::Initiate: asynchronous communication with the initiator
54 void noteInitiatorAborted();
56 // Adaptation::Initiator: asynchronous communication with the current transaction
57 virtual void noteAdaptationAnswer(const Answer
&answer
);
58 virtual void noteXactAbort(XactAbortInfo info
);
61 bool canRetry(XactAbortInfo
&info
) const; //< true if can retry in the case of persistent connection failures
62 bool canRepeat(XactAbortInfo
&info
) const; //< true if can repeat in the case of no or unsatisfactory response
65 // Adaptation::Initiate API implementation
67 virtual bool doneAll() const;
68 virtual void swanSong();
70 // creates the right ICAP transaction using stored configuration params
71 virtual Xaction
*createXaction() = 0;
73 void launchXaction(const char *xkind
);
75 Adaptation::ServicePointer theService
; ///< ICAP service for all launches
76 CbcPointer
<Initiate
> theXaction
; ///< current ICAP transaction
77 int theLaunches
; // the number of transaction launches
80 /// helper class to pass information about aborted ICAP requests to
81 /// the Adaptation::Icap::Launcher class
85 XactAbortInfo(HttpRequest
*anIcapRequest
, HttpReply
*anIcapReply
,
86 bool beRetriable
, bool beRepeatable
);
87 XactAbortInfo(const XactAbortInfo
&);
90 std::ostream
&print(std::ostream
&os
) const {
91 return os
<< isRetriable
<< ',' << isRepeatable
;
94 HttpRequest
*icapRequest
;
100 XactAbortInfo
&operator =(const XactAbortInfo
&); // undefined
105 operator <<(std::ostream
&os
, const XactAbortInfo
&xai
)
107 return xai
.print(os
);
111 } // namespace Adaptation
113 #endif /* SQUID_ICAPLAUNCHER_H */