]>
Commit | Line | Data |
---|---|---|
2e4a5466 AR |
1 | #ifndef SQUID_ADAPTATION__INITIATOR_H |
2 | #define SQUID_ADAPTATION__INITIATOR_H | |
3 | ||
d1e045c3 | 4 | #include "base/AsyncJob.h" |
4299f876 | 5 | #include "base/CbcPointer.h" |
2e4a5466 | 6 | #include "adaptation/forward.h" |
3af10ac0 AR |
7 | #include "HttpMsg.h" |
8 | ||
9 | #include <iosfwd> | |
2e4a5466 AR |
10 | |
11 | /* | |
12 | * The ICAP Initiator is an ICAP vectoring point that initates ICAP | |
13 | * transactions. This interface exists to allow ICAP transactions to | |
14 | * signal their initiators that they have the answer from the ICAP server | |
15 | * or that the ICAP query has aborted and there will be no answer. It | |
16 | * is also handy for implementing common initiator actions such as starting | |
17 | * or aborting an ICAP transaction. | |
18 | */ | |
19 | ||
26ac0430 AJ |
20 | namespace Adaptation |
21 | { | |
2e4a5466 | 22 | |
3af10ac0 AR |
23 | /// summarizes adaptation service answer for the noteAdaptationAnswer() API |
24 | class Answer { | |
25 | public: | |
26 | /// helps interpret other members without a class hierarchy | |
27 | typedef enum { | |
28 | akForward, ///< forward the supplied adapted HTTP message | |
29 | akBlock, ///< block or deny the master xaction; see authority | |
30 | akError, ///< no adapted message will come; see bypassable | |
31 | } Kind; | |
32 | ||
33 | static Answer Error(bool final); ///< create an akError answer | |
34 | static Answer Forward(HttpMsg *aMsg); ///< create an akForward answer | |
35 | static Answer Block(const String &aRule); ///< create an akBlock answer | |
36 | ||
37 | std::ostream &print(std::ostream &os) const; | |
38 | ||
39 | public: | |
40 | HttpMsgPointerT<HttpMsg> message; ///< HTTP request or response to forward | |
41 | String ruleId; ///< ACL (or similar rule) name that blocked forwarding | |
42 | bool final; ///< whether the error, if any, cannot be bypassed | |
43 | Kind kind; ///< the type of the answer | |
44 | ||
45 | private: | |
46 | explicit Answer(Kind aKind); ///< use static creators instead | |
47 | }; | |
48 | ||
49 | inline | |
50 | std::ostream &operator <<(std::ostream &os, const Answer &answer) | |
51 | { | |
52 | return answer.print(os); | |
53 | } | |
54 | ||
2e4a5466 AR |
55 | class Initiator: virtual public AsyncJob |
56 | { | |
57 | public: | |
58 | Initiator(): AsyncJob("Initiator") {} | |
59 | virtual ~Initiator() {} | |
60 | ||
3af10ac0 AR |
61 | /// called with the initial adaptation decision (adapt, block, error); |
62 | /// virgin and/or adapted body transmission may continue after this | |
63 | virtual void noteAdaptationAnswer(const Answer &answer) = 0; | |
2e4a5466 AR |
64 | |
65 | protected: | |
4299f876 AR |
66 | ///< starts freshly created initiate and returns a safe pointer to it |
67 | CbcPointer<Initiate> initiateAdaptation(Initiate *x); | |
2e4a5466 | 68 | |
4299f876 AR |
69 | /// clears the pointer (does not call announceInitiatorAbort) |
70 | void clearAdaptation(CbcPointer<Initiate> &x); | |
2e4a5466 | 71 | |
4299f876 AR |
72 | /// inform the transaction about abnormal termination and clear the pointer |
73 | void announceInitiatorAbort(CbcPointer<Initiate> &x); | |
74 | ||
75 | /// Must(initiated(initiate)) instead of Must(initiate.set()), for clarity | |
76 | bool initiated(const CbcPointer<AsyncJob> &job) const { return job.set(); } | |
2e4a5466 AR |
77 | }; |
78 | ||
79 | } // namespace Adaptation | |
80 | ||
81 | #endif /* SQUID_ADAPTATION__INITIATOR_H */ |