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