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