]>
Commit | Line | Data |
---|---|---|
774c051c | 1 | /* |
77b1029d | 2 | * Copyright (C) 1996-2020 The Squid Software Foundation and contributors |
774c051c | 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. | |
774c051c | 7 | */ |
8 | ||
9 | #ifndef SQUID_ICAPXACTION_H | |
10 | #define SQUID_ICAPXACTION_H | |
11 | ||
602d9612 | 12 | #include "AccessLogEntry.h" |
26cc52cb | 13 | #include "adaptation/icap/ServiceRep.h" |
0bef8dd7 | 14 | #include "adaptation/Initiate.h" |
5c720aa0 | 15 | #include "comm/ConnOpener.h" |
c7d51c86 | 16 | #include "HttpReply.h" |
fb505fa1 | 17 | #include "ipcache.h" |
65e41a45 | 18 | #include "sbuf/SBuf.h" |
84ae6223 | 19 | |
477f45eb | 20 | class MemBuf; |
774c051c | 21 | |
af6a12ee AJ |
22 | namespace Adaptation |
23 | { | |
e1381638 AJ |
24 | namespace Icap |
25 | { | |
26cc52cb | 26 | |
5f8252d2 | 27 | /* |
28 | * The ICAP Xaction implements common tasks for ICAP OPTIONS, REQMOD, and | |
26cc52cb | 29 | * RESPMOD transactions. It is started by an Initiator. It terminates |
c824c43b | 30 | * on its own, when done. Transactions communicate with Initiator using |
31 | * asynchronous messages because a transaction or Initiator may be gone at | |
32 | * any time. | |
5f8252d2 | 33 | */ |
774c051c | 34 | |
26cc52cb | 35 | // Note: Xaction must be the first parent for object-unaware cbdata to work |
774c051c | 36 | |
26cc52cb | 37 | class Xaction: public Adaptation::Initiate |
774c051c | 38 | { |
39 | ||
40 | public: | |
4299f876 | 41 | Xaction(const char *aTypeName, ServiceRep::Pointer &aService); |
26cc52cb | 42 | virtual ~Xaction(); |
774c051c | 43 | |
c824c43b | 44 | void disableRetries(); |
3ff65596 AR |
45 | void disableRepeats(const char *reason); |
46 | bool retriable() const { return isRetriable; } | |
47 | bool repeatable() const { return isRepeatable; } | |
c824c43b | 48 | |
774c051c | 49 | // comm handler wrappers, treat as private |
bd7f2ede | 50 | void noteCommConnected(const CommConnectCbParams &io); |
51 | void noteCommWrote(const CommIoCbParams &io); | |
52 | void noteCommRead(const CommIoCbParams &io); | |
53 | void noteCommTimedout(const CommTimeoutCbParams &io); | |
54 | void noteCommClosed(const CommCloseCbParams &io); | |
774c051c | 55 | |
3ff65596 AR |
56 | // TODO: create these only when actually sending/receiving |
57 | HttpRequest *icapRequest; ///< sent (or at least created) ICAP request | |
c7d51c86 | 58 | HttpReply::Pointer icapReply; ///< received ICAP reply, if any |
3ff65596 AR |
59 | |
60 | /// the number of times we tried to get to the service, including this time | |
61 | int attempts; | |
62 | ||
774c051c | 63 | protected: |
c824c43b | 64 | virtual void start(); |
0bef8dd7 | 65 | virtual void noteInitiatorAborted(); // TODO: move to Adaptation::Initiate |
774c051c | 66 | |
67 | // comm hanndlers; called by comm handler wrappers | |
68 | virtual void handleCommConnected() = 0; | |
69 | virtual void handleCommWrote(size_t sz) = 0; | |
70 | virtual void handleCommRead(size_t sz) = 0; | |
71 | virtual void handleCommTimedout(); | |
72 | virtual void handleCommClosed(); | |
73 | ||
1b091aec | 74 | void handleSecuredPeer(Security::EncryptorAnswer &answer); |
64b66b76 | 75 | /// record error detail if possible |
ced8def3 | 76 | virtual void detailError(int) {} |
64b66b76 | 77 | |
774c051c | 78 | void openConnection(); |
79 | void closeConnection(); | |
c99de607 | 80 | void dieOnConnectionFailure(); |
aed188fd | 81 | bool haveConnection() const; |
c99de607 | 82 | |
774c051c | 83 | void scheduleRead(); |
84 | void scheduleWrite(MemBuf &buf); | |
c99de607 | 85 | void updateTimeout(); |
774c051c | 86 | |
87 | void cancelRead(); | |
88 | ||
63df1d28 | 89 | bool parseHttpMsg(Http::Message *msg); // true=success; false=needMore; throw=err |
774c051c | 90 | bool mayReadMore() const; |
c824c43b | 91 | |
774c051c | 92 | virtual bool doneReading() const; |
c99de607 | 93 | virtual bool doneWriting() const; |
94 | bool doneWithIo() const; | |
774c051c | 95 | virtual bool doneAll() const; |
774c051c | 96 | |
5f8252d2 | 97 | // called just before the 'done' transaction is deleted |
9e008dda | 98 | virtual void swanSong(); |
5f8252d2 | 99 | |
774c051c | 100 | // returns a temporary string depicting transaction status, for debugging |
c824c43b | 101 | virtual const char *status() const; |
774c051c | 102 | virtual void fillPendingStatus(MemBuf &buf) const; |
103 | virtual void fillDoneStatus(MemBuf &buf) const; | |
104 | ||
3cfc19b3 | 105 | // useful for debugging |
106 | virtual bool fillVirginHttpHeader(MemBuf&) const; | |
107 | ||
4299f876 | 108 | public: |
3ff65596 AR |
109 | // custom exception handling and end-of-call checks |
110 | virtual void callException(const std::exception &e); | |
c824c43b | 111 | virtual void callEnd(); |
7a957a93 | 112 | /// clear stored error details, if any; used for retries/repeats |
129fe2a1 | 113 | virtual void clearError() {} |
d4ddb3e6 | 114 | virtual AccessLogEntry::Pointer masterLogEntry(); |
fb505fa1 | 115 | void dnsLookupDone(const ipcache_addrs *ia); |
c824c43b | 116 | |
4299f876 | 117 | protected: |
3ff65596 AR |
118 | // logging |
119 | void setOutcome(const XactOutcome &xo); | |
120 | virtual void finalizeLogInfo(); | |
121 | ||
2dba5b8e | 122 | public: |
26cc52cb | 123 | ServiceRep &service(); |
0bef8dd7 | 124 | |
3ff65596 AR |
125 | private: |
126 | void tellQueryAborted(); | |
127 | void maybeLog(); | |
128 | ||
774c051c | 129 | protected: |
aed188fd | 130 | Comm::ConnectionPointer connection; ///< ICAP server connection |
a22e6cd3 | 131 | Adaptation::Icap::ServiceRep::Pointer theService; |
774c051c | 132 | |
84ae6223 | 133 | SBuf readBuf; |
774c051c | 134 | bool commEof; |
2dfede9e | 135 | bool reuseConnection; |
3ff65596 AR |
136 | bool isRetriable; ///< can retry on persistent connection failures |
137 | bool isRepeatable; ///< can repeat if no or unsatisfactory response | |
cfc68405 | 138 | bool ignoreLastWrite; |
774c051c | 139 | |
140 | const char *stopReason; | |
141 | ||
774c051c | 142 | // active (pending) comm callbacks for the ICAP server connection |
bd7f2ede | 143 | AsyncCall::Pointer connector; |
144 | AsyncCall::Pointer reader; | |
145 | AsyncCall::Pointer writer; | |
146 | AsyncCall::Pointer closer; | |
774c051c | 147 | |
41ebd397 CT |
148 | AccessLogEntry::Pointer alep; ///< icap.log entry |
149 | AccessLogEntry &al; ///< short for *alep | |
3ff65596 AR |
150 | |
151 | timeval icap_tr_start; /*time when the ICAP transaction was created */ | |
152 | timeval icap_tio_start; /*time when the first ICAP request byte was scheduled for sending*/ | |
153 | timeval icap_tio_finish; /*time when the last byte of the ICAP responsewas received*/ | |
154 | ||
774c051c | 155 | private: |
5c720aa0 | 156 | Comm::ConnOpener::Pointer cs; |
1b091aec | 157 | AsyncCall::Pointer securer; ///< whether we are securing a connection |
774c051c | 158 | }; |
159 | ||
26cc52cb AR |
160 | } // namespace Icap |
161 | } // namespace Adaptation | |
162 | ||
774c051c | 163 | #endif /* SQUID_ICAPXACTION_H */ |
f53969cc | 164 |