4 * SQUID Web Proxy Cache http://www.squid-cache.org/
5 * ----------------------------------------------------------
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.
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.
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.
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.
32 #ifndef SQUID_ICAPXACTION_H
33 #define SQUID_ICAPXACTION_H
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"
44 class CommConnectCbParams
;
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
63 // Note: Xaction must be the first parent for object-unaware cbdata to work
65 class Xaction
: public Adaptation::Initiate
69 Xaction(const char *aTypeName
, ServiceRep::Pointer
&aService
);
72 void disableRetries();
73 void disableRepeats(const char *reason
);
74 bool retriable() const { return isRetriable
; }
75 bool repeatable() const { return isRepeatable
; }
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
);
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
88 /// the number of times we tried to get to the service, including this time
93 virtual void noteInitiatorAborted(); // TODO: move to Adaptation::Initiate
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();
102 /// record error detail if possible
103 virtual void detailError(int errDetail
) {}
105 void openConnection();
106 void closeConnection();
107 void dieOnConnectionFailure();
108 bool haveConnection() const;
111 void scheduleWrite(MemBuf
&buf
);
112 void updateTimeout();
116 bool parseHttpMsg(HttpMsg
*msg
); // true=success; false=needMore; throw=err
117 bool mayReadMore() const;
119 virtual bool doneReading() const;
120 virtual bool doneWriting() const;
121 bool doneWithIo() const;
122 virtual bool doneAll() const;
124 // called just before the 'done' transaction is deleted
125 virtual void swanSong();
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;
132 // useful for debugging
133 virtual bool fillVirginHttpHeader(MemBuf
&) const;
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
);
145 void setOutcome(const XactOutcome
&xo
);
146 virtual void finalizeLogInfo();
149 ServiceRep
&service();
152 void tellQueryAborted();
156 Comm::ConnectionPointer connection
; ///< ICAP server connection
157 Adaptation::Icap::ServiceRep::Pointer theService
;
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.
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
;
179 const char *stopReason
;
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
;
187 AccessLogEntry::Pointer alep
; ///< icap.log entry
188 AccessLogEntry
&al
; ///< short for *alep
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*/
195 Comm::ConnOpener
*cs
;
196 //CBDATA_CLASS2(Xaction);
200 } // namespace Adaptation
202 #endif /* SQUID_ICAPXACTION_H */