]> git.ipfire.org Git - thirdparty/squid.git/blame - src/clientStream.h
Fixed HttpHdr::Private/NoCache(v) implementations and optimized their API.
[thirdparty/squid.git] / src / clientStream.h
CommitLineData
c8be6d7b 1
2/*
c8be6d7b 3 *
4 * SQUID Web Proxy Cache http://www.squid-cache.org/
5 * ----------------------------------------------------------
6 *
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.
15 *
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.
26ac0430 20 *
c8be6d7b 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.
26ac0430 25 *
c8be6d7b 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.
29 *
30 */
31
32#ifndef SQUID_CLIENTSTREAM_H
33#define SQUID_CLIENTSTREAM_H
34
8bf217bd 35#include "base/RefCount.h"
582c2af2 36#include "dlink.h"
92ae4c86 37#include "clientStreamForward.h"
582c2af2 38#include "StoreIOBuffer.h"
0655fa4d 39
63be0a78 40/**
41 \defgroup ClientStreamAPI Client Streams API
42 \ingroup Components
43 \section Introduction Introduction
44 \par
45 * A ClientStream implements a unidirectional, non-blocking,
46 * pull pipeline. They allow code to be inserted into the
47 * reply logic on an as-needed basis. For instance,
48 * transfer-encoding logic is only needed when sending a
49 * HTTP/1.1 reply.
50 *
51 \par
52 * Each node consists of four methods - read, callback, detach, and status,
53 * along with the stream housekeeping variables (a dlink node and pointer
54 * to the head of the list), context data for the node, and read request
55 * parameters - readbuf, readlen and readoff (in the body).
56 *
57 \par
58 * clientStream is the basic unit for scheduling, and the clientStreamRead()
59 * and clientStreamCallback() calls allow for deferred scheduled activity if
60 * desired.
61 *
62 \section OperationTheory Theory on stream operation
63 \par
64 \li Something creates a pipeline. At a minimum it needs a head with a
65 * status method and a read method, and a tail with a callback method
66 * and a valid initial read request.
67 \li Other nodes may be added into the pipeline.
68 \li The tail-1th node's read method is called.
69 *
70 \par
71 * For each node going up the pipeline, the node either:
72 \li satisfies the read request, or
73 \li inserts a new node above it and calls clientStreamRead(), or
74 \li calls clientStreamRead()
75 \todo DOCS: make the above list nested.
76 *
77 \par
78 * There is no requirement for the Read parameters from different
79 * nodes to have any correspondence, as long as the callbacks provided are
80 * correct.
81 *
82 \section WhatsInANode Whats in a node
83 *
84 \todo ClientStreams: These details should really be codified as a class which all ClientStream nodes inherit from.
85 *
26ac0430 86 \par Each node must have:
63be0a78 87 \li read method - to allow loose coupling in the pipeline. (The reader may
88 therefore change if the pipeline is altered, even mid-flow).
89 \li callback method - likewise.
90 \li status method - likewise.
91 \li detach method - used to ensure all resources are cleaned up properly.
92 \li dlink head pointer - to allow list inserts and deletes from within a node.
93 \li context data - to allow the called back nodes to maintain their private information.
94 \li read request parameters - For two reasons:
95 \li To allow a node to determine the requested data offset, length and target buffer dynamically. Again, this is to promote loose coupling.
96 \li Because of the callback nature of squid, every node would have to keep these parameters in their context anyway, so this reduces programmer overhead.
97 */
98
63be0a78 99/// \ingroup ClientStreamAPI
43ae1d95 100class clientStreamNode
62e76326 101{
62e76326 102
e6ccf245 103public:
43ae1d95 104 clientStreamNode *prev() const;
105 clientStreamNode *next() const;
0655fa4d 106 void removeFromStream();
c8be6d7b 107 dlink_node node;
108 dlink_list *head; /* sucks I know, but hey, the interface is limited */
109 CSR *readfunc;
110 CSCB *callback;
111 CSD *detach; /* tell this node the next one downstream wants no more data */
112 CSS *status;
0655fa4d 113 ClientStreamData data; /* Context for the node */
c8be6d7b 114 StoreIOBuffer readBuffer; /* what, where and how much this node wants */
115};
116
63be0a78 117/// \ingroup ClientStreamAPI
d9c252f2 118void clientStreamInit(dlink_list *, CSR *, CSD *, CSS *, ClientStreamData, CSCB *, CSD *, ClientStreamData, StoreIOBuffer tailBuffer);
63be0a78 119
120/// \ingroup ClientStreamAPI
d9c252f2 121void clientStreamInsertHead(dlink_list *, CSR *, CSCB *, CSD *, CSS *, ClientStreamData);
63be0a78 122
123/// \ingroup ClientStreamAPI
d9c252f2 124clientStreamNode *clientStreamNew(CSR *, CSCB *, CSD *, CSS *, ClientStreamData);
63be0a78 125
126/**
127 \ingroup ClientStreamAPI
128 *
129 * Call back the next node the in chain with it's requested data.
130 * Return data to the next node in the stream.
131 * The data may be returned immediately, or may be delayed for a later scheduling cycle.
132 *
133 \param thisObject 'this' reference for the client stream
134 \param http Superset of request data, being winnowed down over time. MUST NOT be NULL.
135 \param rep Not NULL on the first call back only. Ownership is passed down the pipeline.
136 Each node may alter the reply if appropriate.
137 \param replyBuffer - buffer, length - where and how much.
138 */
d9c252f2 139void clientStreamCallback(clientStreamNode *thisObject, ClientHttpRequest *http, HttpReply *rep, StoreIOBuffer replyBuffer);
63be0a78 140
141/**
142 \ingroup ClientStreamAPI
143 *
144 * Triggers a read of data that satisfies the httpClientRequest
145 * metainformation and (if appropriate) the offset,length and buffer
146 * parameters.
147 *
148 \param thisObject 'this' reference for the client stream
149 \param http Superset of request data, being winnowed down over time. MUST NOT be NULL.
150 \param readBuffer - offset, length, buffer - what, how much and where.
151 */
d9c252f2 152void clientStreamRead(clientStreamNode *thisObject, ClientHttpRequest *http, StoreIOBuffer readBuffer);
63be0a78 153
154/**
155 \ingroup ClientStreamAPI
156 *
157 * Removes this node from a clientStream. The stream infrastructure handles the removal.
158 * This node MUST have cleaned up all context data, UNLESS scheduled callbacks will take care of that.
159 * Informs the prev node in the list of this nodes detachment.
160 *
161 \param thisObject 'this' reference for the client stream
162 \param http MUST NOT be NULL.
163 */
d9c252f2 164void clientStreamDetach(clientStreamNode *thisObject, ClientHttpRequest *http);
63be0a78 165
166/**
167 \ingroup ClientStreamAPI
168 *
26ac0430 169 * Detachs the tail of the stream. CURRENTLY DOES NOT clean up the tail node data -
63be0a78 170 * this must be done separately. Thus Abort may ONLY be called by the tail node.
171 *
172 \param thisObject 'this' reference for the client stream
173 \param http MUST NOT be NULL.
174 */
d9c252f2 175void clientStreamAbort(clientStreamNode *thisObject, ClientHttpRequest *http);
63be0a78 176
177/**
178 \ingroup ClientStreamAPI
179 *
180 * Allows nodes to query the upstream nodes for :
181 \li stream ABORTS - request cancelled for some reason. upstream will not accept further reads().
182 \li stream COMPLETION - upstream has completed and will not accept further reads().
183 \li stream UNPLANNED COMPLETION - upstream has completed, but not at a pre-planned location (used for keepalive checking), and will not accept further reads().
184 \li stream NONE - no special status, further reads permitted.
185 *
186 \param thisObject 'this' reference for the client stream
187 \param http MUST NOT be NULL.
188 */
d9c252f2 189clientStream_status_t clientStreamStatus(clientStreamNode *thisObject, ClientHttpRequest *http);
c8be6d7b 190
191#endif /* SQUID_CLIENTSTREAM_H */