]> git.ipfire.org Git - thirdparty/squid.git/blame - src/DelayId.cc
Bug 5428: Warn if pkg-config is not found (#1902)
[thirdparty/squid.git] / src / DelayId.cc
CommitLineData
b67e2c8c 1/*
b8ae064d 2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
26ac0430 3 *
bbc27441
AJ
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
b67e2c8c 7 */
8
bbc27441
AJ
9/* DEBUG: section 77 Delay Pools */
10
f7f3304a 11#include "squid.h"
b67e2c8c 12
454e8283 13/* MS Visual Studio Projects are monolithic, so we need the following
14 * #if to exclude the delay pools code from compile process when not needed.
15 */
9a0a18de 16#if USE_DELAY_POOLS
c0941a6a 17#include "acl/FilledChecklist.h"
a928fdfd 18#include "base/DelayedAsyncCalls.h"
582c2af2 19#include "client_side_request.h"
582c2af2 20#include "DelayId.h"
b67e2c8c 21#include "DelayPool.h"
582c2af2 22#include "DelayPools.h"
d3dddfb5 23#include "http/Stream.h"
8000a965 24#include "HttpRequest.h"
b78b376d 25#include "sbuf/StringConvert.h"
4d5904f7 26#include "SquidConfig.h"
a46d2c0e 27
aee3523a 28DelayId::DelayId () : pool_ (0), compositeId(nullptr), markedAsNoDelay(false)
62e76326 29{}
b67e2c8c 30
62e76326 31DelayId::DelayId (unsigned short aPool) :
aee3523a 32 pool_ (aPool), compositeId (nullptr), markedAsNoDelay (false)
b67e2c8c 33{
bf8fe701 34 debugs(77, 3, "DelayId::DelayId: Pool " << aPool << "u");
b67e2c8c 35}
36
37DelayId::~DelayId ()
62e76326 38{}
b67e2c8c 39
40void
71a99cad 41DelayId::compositePosition(const DelayIdComposite::Pointer &newPosition)
b67e2c8c 42{
43 compositeId = newPosition;
44}
45
46unsigned short
47DelayId::pool() const
48{
49 return pool_;
50}
51
52bool
53DelayId::operator == (DelayId const &rhs) const
54{
55 /* Doesn't compare composites properly....
26ac0430 56 * only use to test against default ID's
b67e2c8c 57 */
58 return pool_ == rhs.pool_ && compositeId == rhs.compositeId;
59}
60
62e76326 61DelayId::operator bool() const
b67e2c8c 62{
63 return pool_ || compositeId.getRaw();
64}
65
7ec8c6a2 66/* create a delay Id for a given request */
b67e2c8c 67DelayId
c4a9875e 68DelayId::DelayClient(ClientHttpRequest * http, HttpReply *reply)
b67e2c8c 69{
190154cf 70 HttpRequest *r;
b67e2c8c 71 unsigned short pool;
72 assert(http);
73 r = http->request;
74
4dd643d5 75 if (r->client_addr.isNoAddr()) {
cc192b50 76 debugs(77, 2, "delayClient: WARNING: Called with 'NO_ADDR' address, ignoring");
62e76326 77 return DelayId();
b67e2c8c 78 }
79
95dc7ff4 80 for (pool = 0; pool < DelayPools::pools(); ++pool) {
b50e327b
AJ
81
82 /* pools require explicit 'allow' to assign a client into them */
83 if (!DelayPools::delay_data[pool].access) {
84 debugs(77, DBG_IMPORTANT, "delay_pool " << pool <<
85 " has no delay_access configured. This means that no clients will ever use it.");
86 continue;
87 }
88
e94ff527 89 ACLFilledChecklist ch(DelayPools::delay_data[pool].access, r);
e227da8d 90 clientAclChecklistFill(ch, http);
b1c2ea7a 91 ch.updateReply(reply);
e227da8d 92 // overwrite ACLFilledChecklist acl_uses_indirect_client-based decision
3d674977 93#if FOLLOW_X_FORWARDED_FOR
26ac0430
AJ
94 if (Config.onoff.delay_pool_uses_indirect_client)
95 ch.src_addr = r->indirect_client_addr;
96 else
97#endif /* FOLLOW_X_FORWARDED_FOR */
98 ch.src_addr = r->client_addr;
62e76326 99
06bf5384 100 if (DelayPools::delay_data[pool].theComposite().getRaw() && ch.fastCheck().allowed()) {
b50e327b 101
62e76326 102 DelayId result (pool + 1);
b78b376d 103 CompositePoolNode::CompositeSelectionDetails details(ch.src_addr, StringToSBuf(r->tag));
79fc6915 104#if USE_AUTH
1e5562e3 105 details.user = r->auth_user_request;
79fc6915 106#endif
1e5562e3 107 result.compositePosition(DelayPools::delay_data[pool].theComposite()->id(details));
62e76326 108 return result;
109 }
7ec8c6a2 110 }
111
b67e2c8c 112 return DelayId();
113}
114
a46d2c0e 115void
116DelayId::setNoDelay(bool const newValue)
117{
118 markedAsNoDelay = newValue;
119}
120
b67e2c8c 121/*
122 * this returns the number of bytes the client is permitted. it does not take
123 * into account bytes already buffered - that is up to the caller.
124 */
125int
a748a390 126DelayId::bytesWanted(int minimum, int maximum) const
b67e2c8c 127{
128 /* unlimited */
62e76326 129
a46d2c0e 130 if (! (*this) || markedAsNoDelay)
a748a390 131 return max(minimum, maximum);
62e76326 132
b67e2c8c 133 /* limited */
a748a390 134 int nbytes = max(minimum, maximum);
62e76326 135
aee3523a 136 if (compositeId != nullptr)
a748a390 137 nbytes = compositeId->bytesWanted(minimum, nbytes);
62e76326 138
b67e2c8c 139 return nbytes;
140}
141
142/*
2324cda2 143 * this records actual bytes received. always recorded, even if the
b67e2c8c 144 * class is disabled - it's more efficient to just do it than to do all
145 * the checks.
146 */
147void
148DelayId::bytesIn(int qty)
149{
150 if (! (*this))
62e76326 151 return;
b67e2c8c 152
a46d2c0e 153 if (markedAsNoDelay)
154 return;
155
e4a67a80 156 assert ((unsigned short)(pool() - 1) != 0xFFFF);
b67e2c8c 157
aee3523a 158 if (compositeId != nullptr)
62e76326 159 compositeId->bytesIn(qty);
b67e2c8c 160}
62e76326 161
a46d2c0e 162void
a928fdfd 163DelayId::delayRead(const AsyncCall::Pointer &aRead)
a46d2c0e 164{
aee3523a 165 assert (compositeId != nullptr);
a46d2c0e 166 compositeId->delayRead(aRead);
b67e2c8c 167
a46d2c0e 168}
454e8283 169
9a0a18de 170#endif /* USE_DELAY_POOLS */
f53969cc 171