]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/icap/Xaction.h
6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
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
16 * sources; see the CREDITS file for full details.
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.
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.
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.
34 #ifndef SQUID_ICAPXACTION_H
35 #define SQUID_ICAPXACTION_H
38 #include "CommCalls.h"
40 #include "adaptation/icap/ServiceRep.h"
41 #include "adaptation/Initiate.h"
42 #include "AccessLogEntry.h"
45 class CommConnectCbParams
;
53 * The ICAP Xaction implements common tasks for ICAP OPTIONS, REQMOD, and
54 * RESPMOD transactions. It is started by an Initiator. It terminates
55 * on its own, when done. Transactions communicate with Initiator using
56 * asynchronous messages because a transaction or Initiator may be gone at
60 // Note: Xaction must be the first parent for object-unaware cbdata to work
62 class Xaction
: public Adaptation::Initiate
66 Xaction(const char *aTypeName
, ServiceRep::Pointer
&aService
);
69 void disableRetries();
70 void disableRepeats(const char *reason
);
71 bool retriable() const { return isRetriable
; }
72 bool repeatable() const { return isRepeatable
; }
74 // comm handler wrappers, treat as private
75 void noteCommConnected(const CommConnectCbParams
&io
);
76 void noteCommWrote(const CommIoCbParams
&io
);
77 void noteCommRead(const CommIoCbParams
&io
);
78 void noteCommTimedout(const CommTimeoutCbParams
&io
);
79 void noteCommClosed(const CommCloseCbParams
&io
);
81 // TODO: create these only when actually sending/receiving
82 HttpRequest
*icapRequest
; ///< sent (or at least created) ICAP request
83 HttpReply
*icapReply
; ///< received ICAP reply, if any
85 /// the number of times we tried to get to the service, including this time
90 virtual void noteInitiatorAborted(); // TODO: move to Adaptation::Initiate
92 // comm hanndlers; called by comm handler wrappers
93 virtual void handleCommConnected() = 0;
94 virtual void handleCommWrote(size_t sz
) = 0;
95 virtual void handleCommRead(size_t sz
) = 0;
96 virtual void handleCommTimedout();
97 virtual void handleCommClosed();
99 void openConnection();
100 void closeConnection();
101 void dieOnConnectionFailure();
104 void scheduleWrite(MemBuf
&buf
);
105 void updateTimeout();
109 bool parseHttpMsg(HttpMsg
*msg
); // true=success; false=needMore; throw=err
110 bool mayReadMore() const;
112 virtual bool doneReading() const;
113 virtual bool doneWriting() const;
114 bool doneWithIo() const;
115 virtual bool doneAll() const;
117 // called just before the 'done' transaction is deleted
118 virtual void swanSong();
120 // returns a temporary string depicting transaction status, for debugging
121 virtual const char *status() const;
122 virtual void fillPendingStatus(MemBuf
&buf
) const;
123 virtual void fillDoneStatus(MemBuf
&buf
) const;
125 // useful for debugging
126 virtual bool fillVirginHttpHeader(MemBuf
&) const;
129 // custom exception handling and end-of-call checks
130 virtual void callException(const std::exception
&e
);
131 virtual void callEnd();
135 void setOutcome(const XactOutcome
&xo
);
136 virtual void finalizeLogInfo();
138 ServiceRep
&service();
141 void tellQueryAborted();
145 int connection
; // FD of the ICAP server connection
146 Adaptation::Icap::ServiceRep::Pointer theService
;
149 * We have two read buffers. We would prefer to read directly
150 * into the MemBuf, but since comm_read isn't MemBuf-aware, and
151 * uses event-delayed callbacks, it leaves the MemBuf in an
152 * inconsistent state. There would be data in the buffer, but
153 * MemBuf.size won't be updated until the (delayed) callback
154 * occurs. To avoid that situation we use a plain buffer
155 * (commBuf) and then copy (append) its contents to readBuf in
156 * the callback. If comm_read ever becomes MemBuf-aware, we
157 * can eliminate commBuf and this extra buffer copy.
163 bool reuseConnection
;
164 bool isRetriable
; ///< can retry on persistent connection failures
165 bool isRepeatable
; ///< can repeat if no or unsatisfactory response
166 bool ignoreLastWrite
;
168 const char *stopReason
;
170 // active (pending) comm callbacks for the ICAP server connection
171 AsyncCall::Pointer connector
;
172 AsyncCall::Pointer reader
;
173 AsyncCall::Pointer writer
;
174 AsyncCall::Pointer closer
;
178 timeval icap_tr_start
; /*time when the ICAP transaction was created */
179 timeval icap_tio_start
; /*time when the first ICAP request byte was scheduled for sending*/
180 timeval icap_tio_finish
; /*time when the last byte of the ICAP responsewas received*/
183 //CBDATA_CLASS2(Xaction);
188 } // namespace Adaptation
190 #endif /* SQUID_ICAPXACTION_H */