]> git.ipfire.org Git - thirdparty/squid.git/blame - src/DelayId.cc
Various audit updates
[thirdparty/squid.git] / src / DelayId.cc
CommitLineData
b67e2c8c 1
2/*
b67e2c8c 3 * DEBUG: section 77 Delay Pools
4 * AUTHOR: Robert Collins <robertc@squid-cache.org>
5 * Based upon original delay pools code by
6 * David Luyer <david@luyer.net>
7 *
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
26ac0430 24 *
b67e2c8c 25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
26ac0430 29 *
b67e2c8c 30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 *
34 *
35 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
36 */
37
f7f3304a 38#include "squid.h"
b67e2c8c 39
454e8283 40/* MS Visual Studio Projects are monolithic, so we need the following
41 * #if to exclude the delay pools code from compile process when not needed.
42 */
9a0a18de 43#if USE_DELAY_POOLS
c0941a6a 44#include "acl/FilledChecklist.h"
582c2af2
FC
45#include "client_side_request.h"
46#include "CommRead.h"
47#include "DelayId.h"
b67e2c8c 48#include "DelayPool.h"
582c2af2 49#include "DelayPools.h"
8000a965 50#include "HttpRequest.h"
4d5904f7 51#include "SquidConfig.h"
a46d2c0e 52
53DelayId::DelayId () : pool_ (0), compositeId(NULL), markedAsNoDelay(false)
62e76326 54{}
b67e2c8c 55
62e76326 56DelayId::DelayId (unsigned short aPool) :
a46d2c0e 57 pool_ (aPool), compositeId (NULL), markedAsNoDelay (false)
b67e2c8c 58{
bf8fe701 59 debugs(77, 3, "DelayId::DelayId: Pool " << aPool << "u");
b67e2c8c 60}
61
62DelayId::~DelayId ()
62e76326 63{}
b67e2c8c 64
65void
66DelayId::compositePosition(DelayIdComposite::Pointer newPosition)
67{
68 compositeId = newPosition;
69}
70
71unsigned short
72DelayId::pool() const
73{
74 return pool_;
75}
76
77bool
78DelayId::operator == (DelayId const &rhs) const
79{
80 /* Doesn't compare composites properly....
26ac0430 81 * only use to test against default ID's
b67e2c8c 82 */
83 return pool_ == rhs.pool_ && compositeId == rhs.compositeId;
84}
85
62e76326 86DelayId::operator bool() const
b67e2c8c 87{
88 return pool_ || compositeId.getRaw();
89}
90
7ec8c6a2 91/* create a delay Id for a given request */
b67e2c8c 92DelayId
59a1efb2 93DelayId::DelayClient(ClientHttpRequest * http)
b67e2c8c 94{
190154cf 95 HttpRequest *r;
b67e2c8c 96 unsigned short pool;
97 assert(http);
98 r = http->request;
99
4dd643d5 100 if (r->client_addr.isNoAddr()) {
cc192b50 101 debugs(77, 2, "delayClient: WARNING: Called with 'NO_ADDR' address, ignoring");
62e76326 102 return DelayId();
b67e2c8c 103 }
104
95dc7ff4 105 for (pool = 0; pool < DelayPools::pools(); ++pool) {
b50e327b
AJ
106
107 /* pools require explicit 'allow' to assign a client into them */
108 if (!DelayPools::delay_data[pool].access) {
109 debugs(77, DBG_IMPORTANT, "delay_pool " << pool <<
110 " has no delay_access configured. This means that no clients will ever use it.");
111 continue;
112 }
113
c0941a6a 114 ACLFilledChecklist ch(DelayPools::delay_data[pool].access, r, NULL);
3d674977 115#if FOLLOW_X_FORWARDED_FOR
26ac0430
AJ
116 if (Config.onoff.delay_pool_uses_indirect_client)
117 ch.src_addr = r->indirect_client_addr;
118 else
119#endif /* FOLLOW_X_FORWARDED_FOR */
120 ch.src_addr = r->client_addr;
7ec8c6a2 121 ch.my_addr = r->my_addr;
62e76326 122
4d3a24ca 123 if (http->getConn() != NULL)
a2ac85d9 124 ch.conn(http->getConn());
62e76326 125
2efeb0b7 126 if (DelayPools::delay_data[pool].theComposite().getRaw() && ch.fastCheck() == ACCESS_ALLOWED) {
b50e327b 127
62e76326 128 DelayId result (pool + 1);
1e5562e3 129 CompositePoolNode::CompositeSelectionDetails details;
130 details.src_addr = ch.src_addr;
79fc6915 131#if USE_AUTH
1e5562e3 132 details.user = r->auth_user_request;
79fc6915 133#endif
1e5562e3 134 details.tag = r->tag;
135 result.compositePosition(DelayPools::delay_data[pool].theComposite()->id(details));
62e76326 136 return result;
137 }
7ec8c6a2 138 }
139
b67e2c8c 140 return DelayId();
141}
142
a46d2c0e 143void
144DelayId::setNoDelay(bool const newValue)
145{
146 markedAsNoDelay = newValue;
147}
148
b67e2c8c 149/*
150 * this returns the number of bytes the client is permitted. it does not take
151 * into account bytes already buffered - that is up to the caller.
152 */
153int
a748a390 154DelayId::bytesWanted(int minimum, int maximum) const
b67e2c8c 155{
156 /* unlimited */
62e76326 157
a46d2c0e 158 if (! (*this) || markedAsNoDelay)
a748a390 159 return max(minimum, maximum);
62e76326 160
b67e2c8c 161 /* limited */
a748a390 162 int nbytes = max(minimum, maximum);
62e76326 163
4d3a24ca 164 if (compositeId != NULL)
a748a390 165 nbytes = compositeId->bytesWanted(minimum, nbytes);
62e76326 166
b67e2c8c 167 return nbytes;
168}
169
170/*
2324cda2 171 * this records actual bytes received. always recorded, even if the
b67e2c8c 172 * class is disabled - it's more efficient to just do it than to do all
173 * the checks.
174 */
175void
176DelayId::bytesIn(int qty)
177{
178 if (! (*this))
62e76326 179 return;
b67e2c8c 180
a46d2c0e 181 if (markedAsNoDelay)
182 return;
183
e4a67a80 184 assert ((unsigned short)(pool() - 1) != 0xFFFF);
b67e2c8c 185
4d3a24ca 186 if (compositeId != NULL)
62e76326 187 compositeId->bytesIn(qty);
b67e2c8c 188}
62e76326 189
a46d2c0e 190void
191DelayId::delayRead(DeferredRead const &aRead)
192{
4d3a24ca 193 assert (compositeId != NULL);
a46d2c0e 194 compositeId->delayRead(aRead);
b67e2c8c 195
a46d2c0e 196}
454e8283 197
9a0a18de 198#endif /* USE_DELAY_POOLS */