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