]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ICAP/ICAPXaction.h
- Replaced BodyReader with BodyPipe. BodyReader was a
[thirdparty/squid.git] / src / ICAP / ICAPXaction.h
CommitLineData
774c051c 1
2/*
c99de607 3 * $Id: ICAPXaction.h,v 1.9 2006/10/31 23:30:58 wessels Exp $
774c051c 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
33ff9dbf 16 * sources; see the CREDITS file for full details.
774c051c 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
a553a5a3 37#include "comm.h"
774c051c 38#include "MemBuf.h"
39#include "ICAPServiceRep.h"
40
41class HttpMsg;
42
43class TextException;
44
45/* The ICAP Xaction implements message pipe sink and source interfaces. It
46 * receives virgin HTTP messages, communicates with the ICAP server, and sends
47 * the adapted messages back. ICAPClient is the "owner" of the ICAPXaction. */
48
49// Note: ICAPXaction must be the first parent for object-unaware cbdata to work
50
51class ICAPXaction: public RefCountable
52{
53
54public:
55 typedef RefCount<ICAPXaction> Pointer;
56
57public:
58 ICAPXaction(const char *aTypeName);
59 virtual ~ICAPXaction();
60
61 // comm handler wrappers, treat as private
62 void noteCommConnected(comm_err_t status);
63 void noteCommWrote(comm_err_t status, size_t sz);
64 void noteCommRead(comm_err_t status, size_t sz);
65 void noteCommTimedout();
66 void noteCommClosed();
67
68protected:
69 // Set or get service pointer; ICAPXaction cbdata-locks it.
70 void service(ICAPServiceRep::Pointer &aService);
71 ICAPServiceRep &service();
72
73 // comm hanndlers; called by comm handler wrappers
74 virtual void handleCommConnected() = 0;
75 virtual void handleCommWrote(size_t sz) = 0;
76 virtual void handleCommRead(size_t sz) = 0;
77 virtual void handleCommTimedout();
78 virtual void handleCommClosed();
79
80 void openConnection();
81 void closeConnection();
c99de607 82 void dieOnConnectionFailure();
83
774c051c 84 void scheduleRead();
85 void scheduleWrite(MemBuf &buf);
c99de607 86 void updateTimeout();
774c051c 87
88 void cancelRead();
89
90 bool parseHttpMsg(HttpMsg *msg); // true=success; false=needMore; throw=err
91 bool mayReadMore() const;
92 virtual bool doneReading() const;
c99de607 93 virtual bool doneWriting() const;
94 bool doneWithIo() const;
774c051c 95
96 bool done() const;
97 virtual bool doneAll() const;
98 virtual void doStop();
99 void mustStop(const char *reason);
100
101 // returns a temporary string depicting transaction status, for debugging
102 const char *status() const;
103 virtual void fillPendingStatus(MemBuf &buf) const;
104 virtual void fillDoneStatus(MemBuf &buf) const;
105
3cfc19b3 106 // useful for debugging
107 virtual bool fillVirginHttpHeader(MemBuf&) const;
108
774c051c 109protected:
110 int connection; // FD of the ICAP server connection
111
112 /*
113 * We have two read buffers. We would prefer to read directly
114 * into the MemBuf, but since comm_read isn't MemBuf-aware, and
115 * uses event-delayed callbacks, it leaves the MemBuf in an
116 * inconsistent state. There would be data in the buffer, but
117 * MemBuf.size won't be updated until the (delayed) callback
118 * occurs. To avoid that situation we use a plain buffer
119 * (commBuf) and then copy (append) its contents to readBuf in
120 * the callback. If comm_read ever becomes MemBuf-aware, we
121 * can eliminate commBuf and this extra buffer copy.
122 */
123 MemBuf readBuf;
124 char *commBuf;
125 size_t commBufSize;
126 bool commEof;
2dfede9e 127 bool reuseConnection;
774c051c 128
129 const char *stopReason;
130
131 // asynchronous call maintenance
132 bool callStart(const char *method);
133 void callException(const TextException &e);
134 void callEnd();
135
136 // active (pending) comm callbacks for the ICAP server connection
137 CNCB *connector;
138 IOCB *reader;
3a8c65c3 139 IOCB *writer;
774c051c 140 PF *closer;
141
142 const char *typeName; // the type of the final class (child), for debugging
143
144private:
145 ICAPServiceRep::Pointer theService;
146
147 const char *inCall; // name of the asynchronous call being executed, if any
148
f8376123 149 static void reusedConnection(void *data);
2dfede9e 150
774c051c 151 //CBDATA_CLASS2(ICAPXaction);
152};
153
154// call guards for all "asynchronous" note*() methods
155
156// asynchronous call entry:
157// - open the try clause;
158// - call callStart().
159#define ICAPXaction_Enter(method) \
c99de607 160 try { \
161 if (!callStart(#method)) \
162 return;
774c051c 163
164// asynchronous call exit:
165// - close the try clause;
166// - catch exceptions;
167// - let callEnd() handle transaction termination conditions
168#define ICAPXaction_Exit() \
c99de607 169 } \
170 catch (const TextException &e) { \
171 callException(e); \
172 } \
173 callEnd();
774c051c 174
175
176#endif /* SQUID_ICAPXACTION_H */