]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ICAP/ICAPXaction.h
Cleanup: zap CVS Id tags
[thirdparty/squid.git] / src / ICAP / ICAPXaction.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 "ICAPServiceRep.h"
41 #include "adaptation/Initiate.h"
42
43 class HttpMsg;
44 class CommConnectCbParams;
45
46 /*
47 * The ICAP Xaction implements common tasks for ICAP OPTIONS, REQMOD, and
48 * RESPMOD transactions. It is started by an ICAPInitiator. It terminates
49 * on its own, when done. Transactions communicate with Initiator using
50 * asynchronous messages because a transaction or Initiator may be gone at
51 * any time.
52 */
53
54 // Note: ICAPXaction must be the first parent for object-unaware cbdata to work
55
56 class ICAPXaction: public Adaptation::Initiate
57 {
58
59 public:
60 ICAPXaction(const char *aTypeName, Adaptation::Initiator *anInitiator, ICAPServiceRep::Pointer &aService);
61 virtual ~ICAPXaction();
62
63 void disableRetries();
64
65 // comm handler wrappers, treat as private
66 void noteCommConnected(const CommConnectCbParams &io);
67 void noteCommWrote(const CommIoCbParams &io);
68 void noteCommRead(const CommIoCbParams &io);
69 void noteCommTimedout(const CommTimeoutCbParams &io);
70 void noteCommClosed(const CommCloseCbParams &io);
71
72 protected:
73 virtual void start();
74 virtual void noteInitiatorAborted(); // TODO: move to Adaptation::Initiate
75
76 // comm hanndlers; called by comm handler wrappers
77 virtual void handleCommConnected() = 0;
78 virtual void handleCommWrote(size_t sz) = 0;
79 virtual void handleCommRead(size_t sz) = 0;
80 virtual void handleCommTimedout();
81 virtual void handleCommClosed();
82
83 void openConnection();
84 void closeConnection();
85 void dieOnConnectionFailure();
86
87 void scheduleRead();
88 void scheduleWrite(MemBuf &buf);
89 void updateTimeout();
90
91 void cancelRead();
92
93 bool parseHttpMsg(HttpMsg *msg); // true=success; false=needMore; throw=err
94 bool mayReadMore() const;
95
96 virtual bool doneReading() const;
97 virtual bool doneWriting() const;
98 bool doneWithIo() const;
99 virtual bool doneAll() const;
100
101 // called just before the 'done' transaction is deleted
102 virtual void swanSong();
103
104 // returns a temporary string depicting transaction status, for debugging
105 virtual const char *status() const;
106 virtual void fillPendingStatus(MemBuf &buf) const;
107 virtual void fillDoneStatus(MemBuf &buf) const;
108
109 // useful for debugging
110 virtual bool fillVirginHttpHeader(MemBuf&) const;
111
112 // custom end-of-call checks
113 virtual void callEnd();
114
115 ICAPServiceRep &service();
116
117 protected:
118 int connection; // FD of the ICAP server connection
119
120 /*
121 * We have two read buffers. We would prefer to read directly
122 * into the MemBuf, but since comm_read isn't MemBuf-aware, and
123 * uses event-delayed callbacks, it leaves the MemBuf in an
124 * inconsistent state. There would be data in the buffer, but
125 * MemBuf.size won't be updated until the (delayed) callback
126 * occurs. To avoid that situation we use a plain buffer
127 * (commBuf) and then copy (append) its contents to readBuf in
128 * the callback. If comm_read ever becomes MemBuf-aware, we
129 * can eliminate commBuf and this extra buffer copy.
130 */
131 MemBuf readBuf;
132 char *commBuf;
133 size_t commBufSize;
134 bool commEof;
135 bool reuseConnection;
136 bool isRetriable;
137 bool ignoreLastWrite;
138
139 const char *stopReason;
140
141 // active (pending) comm callbacks for the ICAP server connection
142 AsyncCall::Pointer connector;
143 AsyncCall::Pointer reader;
144 AsyncCall::Pointer writer;
145 AsyncCall::Pointer closer;
146
147 private:
148 //CBDATA_CLASS2(ICAPXaction);
149 };
150
151 #endif /* SQUID_ICAPXACTION_H */