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 
40 static void
41 showDebugWarning(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 
51 void
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
68  al->request = request.getRaw();
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 
92 void
93 ACLFilledChecklist::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 
111 void
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 
128 int
130 {
131  const auto c = conn();
132  return (c && c->clientConnection) ? c->clientConnection->fd : fd_;
133 }
134 
135 void
136 ACLFilledChecklist::fd(int aDescriptor)
137 {
138  const auto c = conn();
139  assert(!c || !c->clientConnection || c->clientConnection->fd == aDescriptor);
140  fd_ = aDescriptor;
141 }
142 
143 bool
145 {
147 }
148 
149 void
151 {
154 }
155 
156 bool
158 {
159  return sourceDomainChecked_;
160 }
161 
162 void
164 {
166  sourceDomainChecked_ = true;
167 }
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  */
184 ACLFilledChecklist::ACLFilledChecklist(const acl_access * const A, HttpRequest * const http_request)
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 
208 void
210 {
211  if (!a)
212  return;
213 
214  al = a; // could have been set already (to a different value)
215  if (!request)
216  setRequest(a->request);
217  updateReply(a->reply);
218 }
219 
220 void
222 {
223  if (r)
224  reply_ = r; // may already be set, including to r
225 }
226 
Cbc * get() const
a temporary valid raw Cbc pointer or NULL
Definition: CbcPointer.h:159
void fillConnectionLevelDetails(ACLFilledChecklist &) const
CBDATA_CLASS_INIT(ACLFilledChecklist)
Ip::Address src_addr
bool isEmpty() const
Definition: SBuf.h:435
HttpReplyPointer reply
static void showDebugWarning(const char *msg)
C * getRaw() const
Definition: RefCount.h:89
int cbdataReferenceValid(const void *p)
Definition: cbdata.cc:270
AccessLogEntry::Pointer al
info for the future access.log, and external ACL
bool destinationDomainChecked() const
#define cbdataReference(var)
Definition: cbdata.h:348
bool asyncInProgress() const
async call has been started and has not finished (or failed) yet
Definition: Checklist.h:101
void syncAle(HttpRequest *adaptedRequest, const char *logUri) const override
assigns uninitialized adapted_request and url ALE components
void updateReply(const HttpReply::Pointer &)
int acl_uses_indirect_client
Definition: SquidConfig.h:326
HttpRequest * request
ConnStateData * conn() const
The client connection manager.
HttpReply::Pointer reply_
response added by updateReply() or nil
bool finished() const
whether markFinished() was called
Definition: Checklist.h:99
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
Ip::Address indirect_client_addr
Definition: HttpRequest.h:152
HttpRequest::Pointer request
#define safe_free(x)
Definition: xalloc.h:73
#define assert(EX)
Definition: assert.h:17
class AccessLogEntry::CacheDetails cache
void changeAcl(const acl_access *)
change the current ACL list
Definition: Checklist.cc:187
void HTTPMSGLOCK(Http::Message *a)
Definition: Message.h:161
#define cbdataReferenceDone(var)
Definition: cbdata.h:357
Ip::Address my_addr
Definition: HttpRequest.h:155
bool hasReply() const override
HttpRequest * adapted_request
ConnStateData * conn_
hack: client-to-Squid connection manager (if any)
void setConn(ConnStateData *)
set either conn
void setRequest(HttpRequest *)
configure client request-related fields for the first time
~ACLFilledChecklist() override
AnyP::PortCfgPointer port
#define Important(id)
Definition: Messages.h:93
AnyP::Port port
destination port of the request that caused serverConnection
Definition: client_side.h:145
void markDestinationDomainChecked()
struct SquidConfig::@90 onoff
const SBuf & effectiveRequestUri() const
RFC 7230 section 5.5 - Effective Request URI.
Definition: HttpRequest.cc:741
Ip::Address client_addr
Definition: HttpRequest.h:149
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192
void updateAle(const AccessLogEntry::Pointer &)
bool sourceDomainChecked() const
CbcPointer< ConnStateData > clientConnectionManager
Definition: HttpRequest.h:230
class SquidConfig Config
Definition: SquidConfig.cc:12

 

Introduction

Documentation

Support

Miscellaneous