]> git.ipfire.org Git - thirdparty/squid.git/blame - src/adaptation/icap/Launcher.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / adaptation / icap / Launcher.h
CommitLineData
c824c43b 1/*
4ac4a490 2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
c824c43b 3 *
bbc27441
AJ
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.
c824c43b 7 */
8
9#ifndef SQUID_ICAPLAUNCHER_H
10#define SQUID_ICAPLAUNCHER_H
11
26cc52cb 12#include "adaptation/icap/ServiceRep.h"
602d9612
A
13#include "adaptation/Initiate.h"
14#include "adaptation/Initiator.h"
c824c43b 15
16/*
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.
20 *
21 * ICAPLauncher and one or more ICAP transactions initiated by it form an
22 * ICAP "query".
23 *
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
26 * transaction.
27 *
28 * Specific ICAP launchers implement the createXaction() method to create
29 * REQMOD, RESPMOD, or OPTIONS transaction from initiator-supplied data.
30 *
26ac0430
AJ
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
c824c43b 33 * ICAP transactions.
34 */
35
af6a12ee
AJ
36namespace Adaptation
37{
e1381638
AJ
38namespace Icap
39{
26cc52cb
AR
40
41class Xaction;
3ff65596 42class XactAbortInfo;
26cc52cb
AR
43
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
c824c43b 46// operations on the initiator directly.
26cc52cb 47class Launcher: public Adaptation::Initiate, public Adaptation::Initiator
c824c43b 48{
49public:
4299f876 50 Launcher(const char *aTypeName, Adaptation::ServicePointer &aService);
26cc52cb 51 virtual ~Launcher();
c824c43b 52
0bef8dd7 53 // Adaptation::Initiate: asynchronous communication with the initiator
c824c43b 54 void noteInitiatorAborted();
55
0bef8dd7 56 // Adaptation::Initiator: asynchronous communication with the current transaction
3af10ac0 57 virtual void noteAdaptationAnswer(const Answer &answer);
4299f876 58 virtual void noteXactAbort(XactAbortInfo info);
3ff65596
AR
59
60private:
61 bool canRetry(XactAbortInfo &info) const; //< true if can retry in the case of persistent connection failures
e1381638 62 bool canRepeat(XactAbortInfo &info) const; //< true if can repeat in the case of no or unsatisfactory response
c824c43b 63
c824c43b 64protected:
0bef8dd7 65 // Adaptation::Initiate API implementation
c824c43b 66 virtual void start();
67 virtual bool doneAll() const;
68 virtual void swanSong();
69
70 // creates the right ICAP transaction using stored configuration params
26cc52cb 71 virtual Xaction *createXaction() = 0;
c824c43b 72
3ff65596 73 void launchXaction(const char *xkind);
c824c43b 74
a22e6cd3 75 Adaptation::ServicePointer theService; ///< ICAP service for all launches
4299f876 76 CbcPointer<Initiate> theXaction; ///< current ICAP transaction
c824c43b 77 int theLaunches; // the number of transaction launches
78};
79
e1381638 80/// helper class to pass information about aborted ICAP requests to
3ff65596 81/// the Adaptation::Icap::Launcher class
e1381638
AJ
82class XactAbortInfo
83{
3ff65596
AR
84public:
85 XactAbortInfo(HttpRequest *anIcapRequest, HttpReply *anIcapReply,
86 bool beRetriable, bool beRepeatable);
87 XactAbortInfo(const XactAbortInfo &);
88 ~XactAbortInfo();
89
4299f876
AR
90 std::ostream &print(std::ostream &os) const {
91 return os << isRetriable << ',' << isRepeatable;
92 }
93
3ff65596
AR
94 HttpRequest *icapRequest;
95 HttpReply *icapReply;
96 bool isRetriable;
97 bool isRepeatable;
e1381638 98
3ff65596
AR
99private:
100 XactAbortInfo &operator =(const XactAbortInfo &); // undefined
101};
102
4299f876
AR
103inline
104std::ostream &
4cb2536f
A
105operator <<(std::ostream &os, const XactAbortInfo &xai)
106{
4299f876 107 return xai.print(os);
3ff65596
AR
108}
109
26cc52cb
AR
110} // namespace Icap
111} // namespace Adaptation
112
c824c43b 113#endif /* SQUID_ICAPLAUNCHER_H */
f53969cc 114