]>
Commit | Line | Data |
---|---|---|
774c051c | 1 | |
2 | /* | |
262a0e14 | 3 | * $Id$ |
774c051c | 4 | * |
5 | * | |
6 | * SQUID Web Proxy Cache http://www.squid-cache.org/ | |
7 | * ---------------------------------------------------------- | |
8 | * | |
9 | * Squid is the result of efforts by numerous individuals from | |
10 | * the Internet community; see the CONTRIBUTORS file for full | |
11 | * details. Many organizations have provided support for Squid's | |
12 | * development; see the SPONSORS file for full details. Squid is | |
13 | * Copyrighted (C) 2001 by the Regents of the University of | |
14 | * California; see the COPYRIGHT file for full details. Squid | |
15 | * incorporates software developed and/or copyrighted by other | |
33ff9dbf | 16 | * sources; see the CREDITS file for full details. |
774c051c | 17 | * |
18 | * This program is free software; you can redistribute it and/or modify | |
19 | * it under the terms of the GNU General Public License as published by | |
20 | * the Free Software Foundation; either version 2 of the License, or | |
21 | * (at your option) any later version. | |
9e008dda | 22 | * |
774c051c | 23 | * This program is distributed in the hope that it will be useful, |
24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26 | * GNU General Public License for more details. | |
9e008dda | 27 | * |
774c051c | 28 | * You should have received a copy of the GNU General Public License |
29 | * along with this program; if not, write to the Free Software | |
30 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
31 | * | |
32 | */ | |
33 | ||
34 | #ifndef SQUID_ICAPXACTION_H | |
35 | #define SQUID_ICAPXACTION_H | |
36 | ||
2413d60a | 37 | #include "comm/forward.h" |
bd7f2ede | 38 | #include "CommCalls.h" |
774c051c | 39 | #include "MemBuf.h" |
26cc52cb | 40 | #include "adaptation/icap/ServiceRep.h" |
0bef8dd7 | 41 | #include "adaptation/Initiate.h" |
3ff65596 | 42 | #include "AccessLogEntry.h" |
c7d51c86 | 43 | #include "HttpReply.h" |
fb505fa1 | 44 | #include "ipcache.h" |
774c051c | 45 | |
bd7f2ede | 46 | class CommConnectCbParams; |
774c051c | 47 | |
af6a12ee AJ |
48 | namespace Adaptation |
49 | { | |
e1381638 AJ |
50 | namespace Icap |
51 | { | |
26cc52cb | 52 | |
5f8252d2 | 53 | /* |
54 | * The ICAP Xaction implements common tasks for ICAP OPTIONS, REQMOD, and | |
26cc52cb | 55 | * RESPMOD transactions. It is started by an Initiator. It terminates |
c824c43b | 56 | * on its own, when done. Transactions communicate with Initiator using |
57 | * asynchronous messages because a transaction or Initiator may be gone at | |
58 | * any time. | |
5f8252d2 | 59 | */ |
774c051c | 60 | |
26cc52cb | 61 | // Note: Xaction must be the first parent for object-unaware cbdata to work |
774c051c | 62 | |
26cc52cb | 63 | class Xaction: public Adaptation::Initiate |
774c051c | 64 | { |
65 | ||
66 | public: | |
4299f876 | 67 | Xaction(const char *aTypeName, ServiceRep::Pointer &aService); |
26cc52cb | 68 | virtual ~Xaction(); |
774c051c | 69 | |
c824c43b | 70 | void disableRetries(); |
3ff65596 AR |
71 | void disableRepeats(const char *reason); |
72 | bool retriable() const { return isRetriable; } | |
73 | bool repeatable() const { return isRepeatable; } | |
c824c43b | 74 | |
774c051c | 75 | // comm handler wrappers, treat as private |
bd7f2ede | 76 | void noteCommConnected(const CommConnectCbParams &io); |
77 | void noteCommWrote(const CommIoCbParams &io); | |
78 | void noteCommRead(const CommIoCbParams &io); | |
79 | void noteCommTimedout(const CommTimeoutCbParams &io); | |
80 | void noteCommClosed(const CommCloseCbParams &io); | |
774c051c | 81 | |
3ff65596 AR |
82 | // TODO: create these only when actually sending/receiving |
83 | HttpRequest *icapRequest; ///< sent (or at least created) ICAP request | |
c7d51c86 | 84 | HttpReply::Pointer icapReply; ///< received ICAP reply, if any |
3ff65596 AR |
85 | |
86 | /// the number of times we tried to get to the service, including this time | |
87 | int attempts; | |
88 | ||
774c051c | 89 | protected: |
c824c43b | 90 | virtual void start(); |
0bef8dd7 | 91 | virtual void noteInitiatorAborted(); // TODO: move to Adaptation::Initiate |
774c051c | 92 | |
93 | // comm hanndlers; called by comm handler wrappers | |
94 | virtual void handleCommConnected() = 0; | |
95 | virtual void handleCommWrote(size_t sz) = 0; | |
96 | virtual void handleCommRead(size_t sz) = 0; | |
97 | virtual void handleCommTimedout(); | |
98 | virtual void handleCommClosed(); | |
99 | ||
64b66b76 CT |
100 | /// record error detail if possible |
101 | virtual void detailError(int errDetail) {} | |
102 | ||
774c051c | 103 | void openConnection(); |
104 | void closeConnection(); | |
c99de607 | 105 | void dieOnConnectionFailure(); |
aed188fd | 106 | bool haveConnection() const; |
c99de607 | 107 | |
774c051c | 108 | void scheduleRead(); |
109 | void scheduleWrite(MemBuf &buf); | |
c99de607 | 110 | void updateTimeout(); |
774c051c | 111 | |
112 | void cancelRead(); | |
113 | ||
114 | bool parseHttpMsg(HttpMsg *msg); // true=success; false=needMore; throw=err | |
115 | bool mayReadMore() const; | |
c824c43b | 116 | |
774c051c | 117 | virtual bool doneReading() const; |
c99de607 | 118 | virtual bool doneWriting() const; |
119 | bool doneWithIo() const; | |
774c051c | 120 | virtual bool doneAll() const; |
774c051c | 121 | |
5f8252d2 | 122 | // called just before the 'done' transaction is deleted |
9e008dda | 123 | virtual void swanSong(); |
5f8252d2 | 124 | |
774c051c | 125 | // returns a temporary string depicting transaction status, for debugging |
c824c43b | 126 | virtual const char *status() const; |
774c051c | 127 | virtual void fillPendingStatus(MemBuf &buf) const; |
128 | virtual void fillDoneStatus(MemBuf &buf) const; | |
129 | ||
3cfc19b3 | 130 | // useful for debugging |
131 | virtual bool fillVirginHttpHeader(MemBuf&) const; | |
132 | ||
4299f876 | 133 | public: |
3ff65596 AR |
134 | // custom exception handling and end-of-call checks |
135 | virtual void callException(const std::exception &e); | |
c824c43b | 136 | virtual void callEnd(); |
129fe2a1 CT |
137 | // clear the error details on retries/repeats |
138 | virtual void clearError() {} | |
fb505fa1 | 139 | void dnsLookupDone(const ipcache_addrs *ia); |
c824c43b | 140 | |
4299f876 | 141 | protected: |
3ff65596 AR |
142 | // logging |
143 | void setOutcome(const XactOutcome &xo); | |
144 | virtual void finalizeLogInfo(); | |
145 | ||
2dba5b8e | 146 | public: |
26cc52cb | 147 | ServiceRep &service(); |
0bef8dd7 | 148 | |
3ff65596 AR |
149 | private: |
150 | void tellQueryAborted(); | |
151 | void maybeLog(); | |
152 | ||
774c051c | 153 | protected: |
aed188fd | 154 | Comm::ConnectionPointer connection; ///< ICAP server connection |
a22e6cd3 | 155 | Adaptation::Icap::ServiceRep::Pointer theService; |
774c051c | 156 | |
157 | /* | |
158 | * We have two read buffers. We would prefer to read directly | |
159 | * into the MemBuf, but since comm_read isn't MemBuf-aware, and | |
160 | * uses event-delayed callbacks, it leaves the MemBuf in an | |
161 | * inconsistent state. There would be data in the buffer, but | |
162 | * MemBuf.size won't be updated until the (delayed) callback | |
163 | * occurs. To avoid that situation we use a plain buffer | |
164 | * (commBuf) and then copy (append) its contents to readBuf in | |
165 | * the callback. If comm_read ever becomes MemBuf-aware, we | |
166 | * can eliminate commBuf and this extra buffer copy. | |
167 | */ | |
168 | MemBuf readBuf; | |
169 | char *commBuf; | |
170 | size_t commBufSize; | |
171 | bool commEof; | |
2dfede9e | 172 | bool reuseConnection; |
3ff65596 AR |
173 | bool isRetriable; ///< can retry on persistent connection failures |
174 | bool isRepeatable; ///< can repeat if no or unsatisfactory response | |
cfc68405 | 175 | bool ignoreLastWrite; |
774c051c | 176 | |
177 | const char *stopReason; | |
178 | ||
774c051c | 179 | // active (pending) comm callbacks for the ICAP server connection |
bd7f2ede | 180 | AsyncCall::Pointer connector; |
181 | AsyncCall::Pointer reader; | |
182 | AsyncCall::Pointer writer; | |
183 | AsyncCall::Pointer closer; | |
774c051c | 184 | |
3ff65596 AR |
185 | AccessLogEntry al; |
186 | ||
187 | timeval icap_tr_start; /*time when the ICAP transaction was created */ | |
188 | timeval icap_tio_start; /*time when the first ICAP request byte was scheduled for sending*/ | |
189 | timeval icap_tio_finish; /*time when the last byte of the ICAP responsewas received*/ | |
190 | ||
774c051c | 191 | private: |
26cc52cb | 192 | //CBDATA_CLASS2(Xaction); |
774c051c | 193 | }; |
194 | ||
26cc52cb AR |
195 | |
196 | } // namespace Icap | |
197 | } // namespace Adaptation | |
198 | ||
774c051c | 199 | #endif /* SQUID_ICAPXACTION_H */ |