]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/FilledChecklist.cc
Author: D Kazarov <d.y.kazarov@mail.ru>
[thirdparty/squid.git] / src / acl / FilledChecklist.cc
CommitLineData
351fe86d
AR
1#include "squid.h"
2#include "HttpRequest.h"
3#include "HttpReply.h"
4#include "client_side.h"
5#include "auth/UserRequest.h"
6#include "auth/AclProxyAuth.h"
7#include "acl/FilledChecklist.h"
8
9CBDATA_CLASS_INIT(ACLFilledChecklist);
10
351fe86d
AR
11void
12ACLFilledChecklist::checkCallback(allow_t answer)
13{
a1ce83aa 14 debugs(28, 5, HERE << this << " answer=" << answer);
351fe86d
AR
15
16 /* During reconfigure, we can end up not finishing call
17 * sequences into the auth code */
18
a33a428a 19 if (auth_user_request != NULL) {
351fe86d 20 /* the filled_checklist lock */
a33a428a 21 auth_user_request = NULL;
351fe86d 22 /* it might have been connection based */
3799d265 23 if (conn()) {
a33a428a 24 conn()->auth_user_request = NULL;
a33a428a 25 }
351fe86d
AR
26 }
27
af6a12ee 28 ACLChecklist::checkCallback(answer); // may delete us
351fe86d
AR
29}
30
31
32void *
33ACLFilledChecklist::operator new (size_t size)
34{
35 assert (size == sizeof(ACLFilledChecklist));
36 CBDATA_INIT_TYPE(ACLFilledChecklist);
37 ACLFilledChecklist *result = cbdataAlloc(ACLFilledChecklist);
38 return result;
39}
40
41void
42ACLFilledChecklist::operator delete (void *address)
43{
44 ACLFilledChecklist *t = static_cast<ACLFilledChecklist *>(address);
45 cbdataFree(t);
46}
47
48
49ACLFilledChecklist::ACLFilledChecklist() :
50 dst_peer(NULL),
12ef783b 51 dst_rdns(NULL),
351fe86d
AR
52 request (NULL),
53 reply (NULL),
54 auth_user_request (NULL),
55#if SQUID_SNMP
56 snmp_community(NULL),
57#endif
58#if USE_SSL
59 ssl_error(0),
60#endif
61 extacl_entry (NULL),
62 conn_(NULL),
63 fd_(-1),
64 destinationDomainChecked_(false),
65 sourceDomainChecked_(false)
66{
67 my_addr.SetEmpty();
68 src_addr.SetEmpty();
69 dst_addr.SetEmpty();
70 rfc931[0] = '\0';
71}
72
73
74ACLFilledChecklist::~ACLFilledChecklist()
75{
76 assert (!asyncInProgress());
77
12ef783b
AJ
78 safe_free(dst_rdns); // created by xstrdup().
79
351fe86d
AR
80 if (extacl_entry)
81 cbdataReferenceDone(extacl_entry);
82
83 HTTPMSGUNLOCK(request);
84
85 HTTPMSGUNLOCK(reply);
86
351fe86d
AR
87 cbdataReferenceDone(conn_);
88
89 debugs(28, 4, HERE << "ACLFilledChecklist destroyed " << this);
90}
91
92
93ConnStateData *
94ACLFilledChecklist::conn() const
95{
96 return conn_;
97}
98
99void
100ACLFilledChecklist::conn(ConnStateData *aConn)
101{
102 assert (conn() == NULL);
103 conn_ = cbdataReference(aConn);
104}
105
106int
107ACLFilledChecklist::fd() const
108{
109 return conn_ != NULL ? conn_->fd : fd_;
110}
111
112void
113ACLFilledChecklist::fd(int aDescriptor)
114{
115 assert(!conn() || conn()->fd == aDescriptor);
116 fd_ = aDescriptor;
117}
118
119bool
120ACLFilledChecklist::destinationDomainChecked() const
121{
122 return destinationDomainChecked_;
123}
124
125void
126ACLFilledChecklist::markDestinationDomainChecked()
127{
128 assert (!finished() && !destinationDomainChecked());
129 destinationDomainChecked_ = true;
130}
131
132bool
133ACLFilledChecklist::sourceDomainChecked() const
134{
135 return sourceDomainChecked_;
136}
137
138void
139ACLFilledChecklist::markSourceDomainChecked()
140{
141 assert (!finished() && !sourceDomainChecked());
142 sourceDomainChecked_ = true;
143}
144
145/*
146 * There are two common ACLFilledChecklist lifecycles paths:
147 *
148 * A) Using aclCheckFast(): The caller creates an ACLFilledChecklist object
149 * on stack and calls aclCheckFast().
150 *
151 * B) Using aclNBCheck() and callbacks: The caller allocates an
152 * ACLFilledChecklist object (via operator new) and passes it to
153 * aclNBCheck(). Control eventually passes to ACLChecklist::checkCallback(),
154 * which will invoke the callback function as requested by the
155 * original caller of aclNBCheck(). This callback function must
156 * *not* delete the list. After the callback function returns,
157 * checkCallback() will delete the list (i.e., self).
158 */
f4462b38 159ACLFilledChecklist::ACLFilledChecklist(const acl_access *A, HttpRequest *http_request, const char *ident):
af6a12ee 160 dst_peer(NULL),
12ef783b 161 dst_rdns(NULL),
af6a12ee
AJ
162 request(NULL),
163 reply(NULL),
164 auth_user_request(NULL),
351fe86d 165#if SQUID_SNMP
af6a12ee 166 snmp_community(NULL),
351fe86d
AR
167#endif
168#if USE_SSL
af6a12ee 169 ssl_error(0),
351fe86d 170#endif
af6a12ee
AJ
171 extacl_entry (NULL),
172 conn_(NULL),
173 fd_(-1),
174 destinationDomainChecked_(false),
175 sourceDomainChecked_(false)
351fe86d
AR
176{
177 my_addr.SetEmpty();
178 src_addr.SetEmpty();
179 dst_addr.SetEmpty();
180 rfc931[0] = '\0';
af6a12ee 181
351fe86d
AR
182 // cbdataReferenceDone() is in either fastCheck() or the destructor
183 if (A)
184 accessList = cbdataReference(A);
185
f4462b38
CT
186 if (http_request != NULL) {
187 request = HTTPMSGLOCK(http_request);
351fe86d
AR
188#if FOLLOW_X_FORWARDED_FOR
189 if (Config.onoff.acl_uses_indirect_client)
190 src_addr = request->indirect_client_addr;
191 else
192#endif /* FOLLOW_X_FORWARDED_FOR */
193 src_addr = request->client_addr;
194 my_addr = request->my_addr;
195 }
196
197#if USE_IDENT
198 if (ident)
199 xstrncpy(rfc931, ident, USER_IDENT_SZ);
200#endif
201}
202