]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/FilledChecklist.cc
Minor edits after audit
[thirdparty/squid.git] / src / acl / FilledChecklist.cc
CommitLineData
bbc27441 1/*
bde978a6 2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
bbc27441
AJ
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
582c2af2
FC
9#include "squid.h"
10#include "acl/FilledChecklist.h"
351fe86d 11#include "client_side.h"
582c2af2
FC
12#include "comm/Connection.h"
13#include "comm/forward.h"
abdd93d0 14#include "ExternalACLEntry.h"
582c2af2
FC
15#include "HttpReply.h"
16#include "HttpRequest.h"
4d5904f7 17#include "SquidConfig.h"
2f1431ea 18#if USE_AUTH
351fe86d 19#include "auth/AclProxyAuth.h"
602d9612 20#include "auth/UserRequest.h"
2f1431ea 21#endif
582c2af2 22
351fe86d
AR
23CBDATA_CLASS_INIT(ACLFilledChecklist);
24
351fe86d 25ACLFilledChecklist::ACLFilledChecklist() :
f53969cc
SM
26 dst_rdns(NULL),
27 request (NULL),
28 reply (NULL),
2f1431ea 29#if USE_AUTH
f53969cc 30 auth_user_request (NULL),
2f1431ea 31#endif
351fe86d 32#if SQUID_SNMP
f53969cc 33 snmp_community(NULL),
351fe86d 34#endif
cb4f4424 35#if USE_OPENSSL
f53969cc 36 sslErrors(NULL),
fa24d749 37#endif
3248e962 38 requestErrorType(ERR_MAX),
f53969cc
SM
39 conn_(NULL),
40 fd_(-1),
41 destinationDomainChecked_(false),
42 sourceDomainChecked_(false)
351fe86d 43{
4dd643d5
AJ
44 my_addr.setEmpty();
45 src_addr.setEmpty();
46 dst_addr.setEmpty();
351fe86d
AR
47 rfc931[0] = '\0';
48}
49
351fe86d
AR
50ACLFilledChecklist::~ACLFilledChecklist()
51{
52 assert (!asyncInProgress());
53
12ef783b
AJ
54 safe_free(dst_rdns); // created by xstrdup().
55
351fe86d
AR
56 HTTPMSGUNLOCK(request);
57
58 HTTPMSGUNLOCK(reply);
59
351fe86d
AR
60 cbdataReferenceDone(conn_);
61
cb4f4424 62#if USE_OPENSSL
7a957a93 63 cbdataReferenceDone(sslErrors);
fa24d749 64#endif
4fb72cb9 65
351fe86d
AR
66 debugs(28, 4, HERE << "ACLFilledChecklist destroyed " << this);
67}
68
351fe86d
AR
69ConnStateData *
70ACLFilledChecklist::conn() const
71{
72 return conn_;
73}
74
75void
76ACLFilledChecklist::conn(ConnStateData *aConn)
77{
16a16ffe
CT
78 if (conn() == aConn)
79 return;
351fe86d
AR
80 assert (conn() == NULL);
81 conn_ = cbdataReference(aConn);
82}
83
84int
85ACLFilledChecklist::fd() const
86{
73c36fd9 87 return (conn_ != NULL && conn_->clientConnection != NULL) ? conn_->clientConnection->fd : fd_;
351fe86d
AR
88}
89
90void
91ACLFilledChecklist::fd(int aDescriptor)
92{
73c36fd9 93 assert(!conn() || conn()->clientConnection == NULL || conn()->clientConnection->fd == aDescriptor);
351fe86d
AR
94 fd_ = aDescriptor;
95}
96
97bool
98ACLFilledChecklist::destinationDomainChecked() const
99{
100 return destinationDomainChecked_;
101}
102
103void
104ACLFilledChecklist::markDestinationDomainChecked()
105{
106 assert (!finished() && !destinationDomainChecked());
107 destinationDomainChecked_ = true;
108}
109
110bool
111ACLFilledChecklist::sourceDomainChecked() const
112{
113 return sourceDomainChecked_;
114}
115
116void
117ACLFilledChecklist::markSourceDomainChecked()
118{
119 assert (!finished() && !sourceDomainChecked());
120 sourceDomainChecked_ = true;
121}
122
123/*
124 * There are two common ACLFilledChecklist lifecycles paths:
125 *
126 * A) Using aclCheckFast(): The caller creates an ACLFilledChecklist object
127 * on stack and calls aclCheckFast().
128 *
129 * B) Using aclNBCheck() and callbacks: The caller allocates an
130 * ACLFilledChecklist object (via operator new) and passes it to
131 * aclNBCheck(). Control eventually passes to ACLChecklist::checkCallback(),
132 * which will invoke the callback function as requested by the
133 * original caller of aclNBCheck(). This callback function must
134 * *not* delete the list. After the callback function returns,
135 * checkCallback() will delete the list (i.e., self).
136 */
f4462b38 137ACLFilledChecklist::ACLFilledChecklist(const acl_access *A, HttpRequest *http_request, const char *ident):
f53969cc
SM
138 dst_rdns(NULL),
139 request(NULL),
140 reply(NULL),
cc8c4af2 141#if USE_AUTH
f53969cc 142 auth_user_request(NULL),
2f1431ea 143#endif
351fe86d 144#if SQUID_SNMP
f53969cc 145 snmp_community(NULL),
351fe86d 146#endif
cb4f4424 147#if USE_OPENSSL
f53969cc 148 sslErrors(NULL),
fa24d749 149#endif
cc8c4af2 150 requestErrorType(ERR_MAX),
f53969cc
SM
151 conn_(NULL),
152 fd_(-1),
153 destinationDomainChecked_(false),
154 sourceDomainChecked_(false)
351fe86d 155{
4dd643d5
AJ
156 my_addr.setEmpty();
157 src_addr.setEmpty();
158 dst_addr.setEmpty();
351fe86d 159 rfc931[0] = '\0';
af6a12ee 160
3d29e126 161 changeAcl(A);
351fe86d 162
f4462b38 163 if (http_request != NULL) {
b248c2a3
AJ
164 request = http_request;
165 HTTPMSGLOCK(request);
351fe86d
AR
166#if FOLLOW_X_FORWARDED_FOR
167 if (Config.onoff.acl_uses_indirect_client)
168 src_addr = request->indirect_client_addr;
169 else
170#endif /* FOLLOW_X_FORWARDED_FOR */
171 src_addr = request->client_addr;
172 my_addr = request->my_addr;
16a16ffe
CT
173
174 if (request->clientConnectionManager.valid())
76fae079 175 conn(request->clientConnectionManager.get());
351fe86d
AR
176 }
177
178#if USE_IDENT
179 if (ident)
180 xstrncpy(rfc931, ident, USER_IDENT_SZ);
181#endif
182}
f53969cc 183