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