]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/icap/Xaction.h
c8860f2a80918746bf33dec7195fdc3707ba3e9c
[thirdparty/squid.git] / src / adaptation / icap / Xaction.h
1
2 /*
3 * $Id$
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
16 * sources; see the CREDITS file for full details.
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.
22 *
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.
27 *
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
37 #include "comm.h"
38 #include "CommCalls.h"
39 #include "MemBuf.h"
40 #include "adaptation/icap/ServiceRep.h"
41 #include "adaptation/Initiate.h"
42 #include "AccessLogEntry.h"
43
44 class HttpMsg;
45 class CommConnectCbParams;
46
47 namespace Adaptation
48 {
49 namespace Icap {
50
51 /*
52 * The ICAP Xaction implements common tasks for ICAP OPTIONS, REQMOD, and
53 * RESPMOD transactions. It is started by an Initiator. It terminates
54 * on its own, when done. Transactions communicate with Initiator using
55 * asynchronous messages because a transaction or Initiator may be gone at
56 * any time.
57 */
58
59 // Note: Xaction must be the first parent for object-unaware cbdata to work
60
61 class Xaction: public Adaptation::Initiate
62 {
63
64 public:
65 Xaction(const char *aTypeName, Adaptation::Initiator *anInitiator, ServiceRep::Pointer &aService);
66 virtual ~Xaction();
67
68 void disableRetries();
69 void disableRepeats(const char *reason);
70 bool retriable() const { return isRetriable; }
71 bool repeatable() const { return isRepeatable; }
72
73 // comm handler wrappers, treat as private
74 void noteCommConnected(const CommConnectCbParams &io);
75 void noteCommWrote(const CommIoCbParams &io);
76 void noteCommRead(const CommIoCbParams &io);
77 void noteCommTimedout(const CommTimeoutCbParams &io);
78 void noteCommClosed(const CommCloseCbParams &io);
79
80 // TODO: create these only when actually sending/receiving
81 HttpRequest *icapRequest; ///< sent (or at least created) ICAP request
82 HttpReply *icapReply; ///< received ICAP reply, if any
83
84 /// the number of times we tried to get to the service, including this time
85 int attempts;
86
87 protected:
88 virtual void start();
89 virtual void noteInitiatorAborted(); // TODO: move to Adaptation::Initiate
90
91 // comm hanndlers; called by comm handler wrappers
92 virtual void handleCommConnected() = 0;
93 virtual void handleCommWrote(size_t sz) = 0;
94 virtual void handleCommRead(size_t sz) = 0;
95 virtual void handleCommTimedout();
96 virtual void handleCommClosed();
97
98 void openConnection();
99 void closeConnection();
100 void dieOnConnectionFailure();
101
102 void scheduleRead();
103 void scheduleWrite(MemBuf &buf);
104 void updateTimeout();
105
106 void cancelRead();
107
108 bool parseHttpMsg(HttpMsg *msg); // true=success; false=needMore; throw=err
109 bool mayReadMore() const;
110
111 virtual bool doneReading() const;
112 virtual bool doneWriting() const;
113 bool doneWithIo() const;
114 virtual bool doneAll() const;
115
116 // called just before the 'done' transaction is deleted
117 virtual void swanSong();
118
119 // returns a temporary string depicting transaction status, for debugging
120 virtual const char *status() const;
121 virtual void fillPendingStatus(MemBuf &buf) const;
122 virtual void fillDoneStatus(MemBuf &buf) const;
123
124 // useful for debugging
125 virtual bool fillVirginHttpHeader(MemBuf&) const;
126
127 // custom exception handling and end-of-call checks
128 virtual void callException(const std::exception &e);
129 virtual void callEnd();
130
131 // logging
132 void setOutcome(const XactOutcome &xo);
133 virtual void finalizeLogInfo();
134
135 ServiceRep &service();
136
137 private:
138 void tellQueryAborted();
139 void maybeLog();
140
141 protected:
142 int connection; // FD of the ICAP server connection
143 Adaptation::Icap::ServiceRep::Pointer theService;
144
145 /*
146 * We have two read buffers. We would prefer to read directly
147 * into the MemBuf, but since comm_read isn't MemBuf-aware, and
148 * uses event-delayed callbacks, it leaves the MemBuf in an
149 * inconsistent state. There would be data in the buffer, but
150 * MemBuf.size won't be updated until the (delayed) callback
151 * occurs. To avoid that situation we use a plain buffer
152 * (commBuf) and then copy (append) its contents to readBuf in
153 * the callback. If comm_read ever becomes MemBuf-aware, we
154 * can eliminate commBuf and this extra buffer copy.
155 */
156 MemBuf readBuf;
157 char *commBuf;
158 size_t commBufSize;
159 bool commEof;
160 bool reuseConnection;
161 bool isRetriable; ///< can retry on persistent connection failures
162 bool isRepeatable; ///< can repeat if no or unsatisfactory response
163 bool ignoreLastWrite;
164
165 const char *stopReason;
166
167 // active (pending) comm callbacks for the ICAP server connection
168 AsyncCall::Pointer connector;
169 AsyncCall::Pointer reader;
170 AsyncCall::Pointer writer;
171 AsyncCall::Pointer closer;
172
173 AccessLogEntry al;
174
175 timeval icap_tr_start; /*time when the ICAP transaction was created */
176 timeval icap_tio_start; /*time when the first ICAP request byte was scheduled for sending*/
177 timeval icap_tio_finish; /*time when the last byte of the ICAP responsewas received*/
178
179 private:
180 //CBDATA_CLASS2(Xaction);
181 };
182
183
184 } // namespace Icap
185 } // namespace Adaptation
186
187 #endif /* SQUID_ICAPXACTION_H */