Squid Web Cache master
Loading...
Searching...
No Matches
FilledChecklist.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9#include "squid.h"
10#include "acl/FilledChecklist.h"
11#include "client_side.h"
12#include "comm/Connection.h"
13#include "comm/forward.h"
14#include "debug/Messages.h"
15#include "ExternalACLEntry.h"
16#include "http/Stream.h"
17#include "HttpReply.h"
18#include "HttpRequest.h"
19#include "SquidConfig.h"
20#if USE_AUTH
21#include "auth/AclProxyAuth.h"
22#include "auth/UserRequest.h"
23#endif
24
26
28
30{
32
33 safe_free(dst_rdns); // created by xstrdup().
34
36
37 debugs(28, 4, "ACLFilledChecklist destroyed " << this);
38}
39
40static void
41showDebugWarning(const char *msg)
42{
43 static uint16_t count = 0;
44 if (count > 10)
45 return;
46
47 ++count;
48 debugs(28, Important(58), "ERROR: ALE missing " << msg);
49}
50
51void
53{
54 // make sure the ALE fields used by Format::assemble to
55 // fill the old external_acl_type codes are set if any
56 // data on them exists in the Checklist
57
58 if (!al->cache.port && conn()) {
59 showDebugWarning("listening port");
60 al->cache.port = conn()->port;
61 }
62
63 if (request) {
64 if (!al->request) {
65 showDebugWarning("HttpRequest object");
66 // XXX: al->request should be original,
67 // but the request may be already adapted
70 }
71
72 if (!al->adapted_request) {
73 showDebugWarning("adapted HttpRequest object");
76 }
77
78 if (al->url.isEmpty()) {
79 showDebugWarning("URL");
80 // XXX: al->url should be the request URL from client,
81 // but request->url may be different (e.g.,redirected)
83 }
84 }
85
86 if (hasReply() && !al->reply) {
87 showDebugWarning("HttpReply object");
88 al->reply = reply_;
89 }
90}
91
92void
93ACLFilledChecklist::syncAle(HttpRequest *adaptedRequest, const char *logUri) const
94{
95 if (!al)
96 return;
97 if (adaptedRequest && !al->adapted_request) {
98 al->adapted_request = adaptedRequest;
100 }
101 if (logUri && al->url.isEmpty())
102 al->url = logUri;
103}
104
107{
108 return cbdataReferenceValid(conn_) ? conn_ : nullptr;
109}
110
111void
113{
114 if (conn_ == aConn)
115 return; // no new information
116
117 // no conn_ replacement/removal to reduce inconsistent fill concerns
118 assert(!conn_);
119 assert(aConn);
120
121 // To reduce inconsistent fill concerns, we should be the only ones calling
122 // fillConnectionLevelDetails(). Set conn_ first so that the filling method
123 // can detect (some) direct calls from others.
124 conn_ = cbdataReference(aConn);
125 aConn->fillConnectionLevelDetails(*this);
126}
127
128int
130{
131 const auto c = conn();
132 return (c && c->clientConnection) ? c->clientConnection->fd : fd_;
133}
134
135void
137{
138 const auto c = conn();
139 assert(!c || !c->clientConnection || c->clientConnection->fd == aDescriptor);
140 fd_ = aDescriptor;
141}
142
143bool
148
149void
155
156bool
161
162void
168
169/*
170 * There are two common ACLFilledChecklist lifecycles paths:
171 *
172 * "Fast" (always synchronous or "blocking"): The user constructs an
173 * ACLFilledChecklist object on stack, configures it as needed, and calls one
174 * or both of its fastCheck() methods.
175 *
176 * "Slow" (usually asynchronous or "non-blocking"): The user allocates an
177 * ACLFilledChecklist object on heap (via Make()), configures it as needed,
178 * and passes it to NonBlockingCheck() while specifying the callback function
179 * to call with check results. NonBlockingCheck() calls the callback function
180 * (if the corresponding cbdata is still valid), either immediately/directly
181 * (XXX) or eventually/asynchronously. After this callback obligations are
182 * fulfilled, checkCallback() deletes the checklist object (i.e. "this").
183 */
185{
186 changeAcl(A);
187 setRequest(http_request);
188}
189
191{
192 assert(!request);
193 if (httpRequest) {
194 request = httpRequest;
195#if FOLLOW_X_FORWARDED_FOR
198 else
199#endif /* FOLLOW_X_FORWARDED_FOR */
202
203 if (const auto cmgr = request->clientConnectionManager.get())
204 setConn(cmgr);
205 }
206}
207
208void
210{
211 if (!a)
212 return;
213
214 al = a; // could have been set already (to a different value)
215 if (!request)
217 updateReply(a->reply);
218}
219
220void
222{
223 if (r)
224 reply_ = r; // may already be set, including to r
225}
226
static void showDebugWarning(const char *msg)
class SquidConfig Config
#define assert(EX)
Definition assert.h:17
int cbdataReferenceValid(const void *p)
Definition cbdata.cc:270
#define cbdataReferenceDone(var)
Definition cbdata.h:357
#define cbdataReference(var)
Definition cbdata.h:348
#define CBDATA_CLASS_INIT(type)
Definition cbdata.h:325
bool finished() const
whether markFinished() was called
Definition Checklist.h:99
void changeAcl(const acl_access *)
change the current ACL list
Definition Checklist.cc:187
bool asyncInProgress() const
async call has been started and has not finished (or failed) yet
Definition Checklist.h:101
bool destinationDomainChecked() const
ConnStateData * conn_
hack: client-to-Squid connection manager (if any)
ConnStateData * conn() const
The client connection manager.
void setRequest(HttpRequest *)
configure client request-related fields for the first time
~ACLFilledChecklist() override
void setConn(ConnStateData *)
set either conn
void updateAle(const AccessLogEntry::Pointer &)
void updateReply(const HttpReply::Pointer &)
int fd() const
The client side fd. It uses conn() if available.
void verifyAle() const override
warns if there are uninitialized ALE components and fills them
bool sourceDomainChecked() const
AccessLogEntry::Pointer al
info for the future access.log, and external ACL
HttpReply::Pointer reply_
response added by updateReply() or nil
void syncAle(HttpRequest *adaptedRequest, const char *logUri) const override
assigns uninitialized adapted_request and url ALE components
HttpRequest::Pointer request
bool hasReply() const override
AnyP::PortCfgPointer port
HttpReplyPointer reply
class AccessLogEntry::CacheDetails cache
HttpRequest * adapted_request
HttpRequest * request
Cbc * get() const
a temporary valid raw Cbc pointer or NULL
Definition CbcPointer.h:159
AnyP::Port port
destination port of the request that caused serverConnection
void fillConnectionLevelDetails(ACLFilledChecklist &) const
CbcPointer< ConnStateData > clientConnectionManager
Ip::Address indirect_client_addr
Ip::Address my_addr
Ip::Address client_addr
const SBuf & effectiveRequestUri() const
RFC 7230 section 5.5 - Effective Request URI.
C * getRaw() const
Definition RefCount.h:89
bool isEmpty() const
Definition SBuf.h:435
int acl_uses_indirect_client
struct SquidConfig::@90 onoff
#define Important(id)
Definition Messages.h:93
#define debugs(SECTION, LEVEL, CONTENT)
Definition Stream.h:192
void HTTPMSGLOCK(Http::Message *a)
Definition Message.h:161
#define safe_free(x)
Definition xalloc.h:73