]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/icap/Launcher.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / adaptation / icap / Launcher.h
1 /*
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 #ifndef SQUID_ICAPLAUNCHER_H
10 #define SQUID_ICAPLAUNCHER_H
11
12 #include "adaptation/icap/ServiceRep.h"
13 #include "adaptation/Initiate.h"
14 #include "adaptation/Initiator.h"
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 *
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
33 * ICAP transactions.
34 */
35
36 namespace Adaptation
37 {
38 namespace Icap
39 {
40
41 class Xaction;
42 class XactAbortInfo;
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
46 // operations on the initiator directly.
47 class Launcher: public Adaptation::Initiate, public Adaptation::Initiator
48 {
49 public:
50 Launcher(const char *aTypeName, Adaptation::ServicePointer &aService);
51 virtual ~Launcher();
52
53 // Adaptation::Initiate: asynchronous communication with the initiator
54 void noteInitiatorAborted();
55
56 // Adaptation::Initiator: asynchronous communication with the current transaction
57 virtual void noteAdaptationAnswer(const Answer &answer);
58 virtual void noteXactAbort(XactAbortInfo info);
59
60 private:
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
63
64 protected:
65 // Adaptation::Initiate API implementation
66 virtual void start();
67 virtual bool doneAll() const;
68 virtual void swanSong();
69
70 // creates the right ICAP transaction using stored configuration params
71 virtual Xaction *createXaction() = 0;
72
73 void launchXaction(const char *xkind);
74
75 Adaptation::ServicePointer theService; ///< ICAP service for all launches
76 CbcPointer<Initiate> theXaction; ///< current ICAP transaction
77 int theLaunches; // the number of transaction launches
78 };
79
80 /// helper class to pass information about aborted ICAP requests to
81 /// the Adaptation::Icap::Launcher class
82 class XactAbortInfo
83 {
84 public:
85 XactAbortInfo(HttpRequest *anIcapRequest, HttpReply *anIcapReply,
86 bool beRetriable, bool beRepeatable);
87 XactAbortInfo(const XactAbortInfo &);
88 ~XactAbortInfo();
89
90 std::ostream &print(std::ostream &os) const {
91 return os << isRetriable << ',' << isRepeatable;
92 }
93
94 HttpRequest *icapRequest;
95 HttpReply *icapReply;
96 bool isRetriable;
97 bool isRepeatable;
98
99 private:
100 XactAbortInfo &operator =(const XactAbortInfo &); // undefined
101 };
102
103 inline
104 std::ostream &
105 operator <<(std::ostream &os, const XactAbortInfo &xai)
106 {
107 return xai.print(os);
108 }
109
110 } // namespace Icap
111 } // namespace Adaptation
112
113 #endif /* SQUID_ICAPLAUNCHER_H */
114