]> git.ipfire.org Git - thirdparty/squid.git/blob - src/CommCalls.cc
Various audit updates
[thirdparty/squid.git] / src / CommCalls.cc
1 #include "squid.h"
2 #include "comm/Connection.h"
3 #include "CommCalls.h"
4 #include "fde.h"
5 #include "globals.h"
6
7 /* CommCommonCbParams */
8
9 CommCommonCbParams::CommCommonCbParams(void *aData):
10 data(cbdataReference(aData)), conn(), flag(Comm::OK), xerrno(0), fd(-1)
11 {
12 }
13
14 CommCommonCbParams::CommCommonCbParams(const CommCommonCbParams &p):
15 data(cbdataReference(p.data)), conn(p.conn), flag(p.flag), xerrno(p.xerrno), fd(p.fd)
16 {
17 }
18
19 CommCommonCbParams::~CommCommonCbParams()
20 {
21 cbdataReferenceDone(data);
22 }
23
24 void
25 CommCommonCbParams::print(std::ostream &os) const
26 {
27 if (conn != NULL)
28 os << conn;
29 else
30 os << "FD " << fd;
31
32 if (xerrno)
33 os << ", errno=" << xerrno;
34 if (flag != Comm::OK)
35 os << ", flag=" << flag;
36 if (data)
37 os << ", data=" << data;
38 }
39
40 /* CommAcceptCbParams */
41
42 CommAcceptCbParams::CommAcceptCbParams(void *aData):
43 CommCommonCbParams(aData), xaction()
44 {
45 }
46
47 void
48 CommAcceptCbParams::print(std::ostream &os) const
49 {
50 CommCommonCbParams::print(os);
51
52 if (xaction != NULL)
53 os << ", " << xaction->id;
54 }
55
56 /* CommConnectCbParams */
57
58 CommConnectCbParams::CommConnectCbParams(void *aData):
59 CommCommonCbParams(aData)
60 {
61 }
62
63 bool
64 CommConnectCbParams::syncWithComm()
65 {
66 // drop the call if the call was scheduled before comm_close but
67 // is being fired after comm_close
68 if (fd >= 0 && fd_table[fd].closing()) {
69 debugs(5, 3, HERE << "dropping late connect call: FD " << fd);
70 return false;
71 }
72 return true; // now we are in sync and can handle the call
73 }
74
75 /* CommIoCbParams */
76
77 CommIoCbParams::CommIoCbParams(void *aData): CommCommonCbParams(aData),
78 buf(NULL), size(0)
79 {
80 }
81
82 bool
83 CommIoCbParams::syncWithComm()
84 {
85 // change parameters if the call was scheduled before comm_close but
86 // is being fired after comm_close
87 if ((conn->fd < 0 || fd_table[conn->fd].closing()) && flag != Comm::ERR_CLOSING) {
88 debugs(5, 3, HERE << "converting late call to Comm::ERR_CLOSING: " << conn);
89 flag = Comm::ERR_CLOSING;
90 }
91 return true; // now we are in sync and can handle the call
92 }
93
94 void
95 CommIoCbParams::print(std::ostream &os) const
96 {
97 CommCommonCbParams::print(os);
98 if (buf) {
99 os << ", size=" << size;
100 os << ", buf=" << (void*)buf;
101 }
102 }
103
104 /* CommCloseCbParams */
105
106 CommCloseCbParams::CommCloseCbParams(void *aData):
107 CommCommonCbParams(aData)
108 {
109 }
110
111 /* CommTimeoutCbParams */
112
113 CommTimeoutCbParams::CommTimeoutCbParams(void *aData):
114 CommCommonCbParams(aData)
115 {
116 }
117
118 /* FdeCbParams */
119
120 FdeCbParams::FdeCbParams(void *aData):
121 CommCommonCbParams(aData)
122 {
123 }
124
125 /* CommAcceptCbPtrFun */
126
127 CommAcceptCbPtrFun::CommAcceptCbPtrFun(IOACB *aHandler,
128 const CommAcceptCbParams &aParams):
129 CommDialerParamsT<CommAcceptCbParams>(aParams),
130 handler(aHandler)
131 {
132 }
133
134 CommAcceptCbPtrFun::CommAcceptCbPtrFun(const CommAcceptCbPtrFun &o):
135 CommDialerParamsT<CommAcceptCbParams>(o.params),
136 handler(o.handler)
137 {
138 }
139
140 void
141 CommAcceptCbPtrFun::dial()
142 {
143 handler(params);
144 }
145
146 void
147 CommAcceptCbPtrFun::print(std::ostream &os) const
148 {
149 os << '(';
150 params.print(os);
151 os << ')';
152 }
153
154 /* CommConnectCbPtrFun */
155
156 CommConnectCbPtrFun::CommConnectCbPtrFun(CNCB *aHandler,
157 const CommConnectCbParams &aParams):
158 CommDialerParamsT<CommConnectCbParams>(aParams),
159 handler(aHandler)
160 {
161 }
162
163 void
164 CommConnectCbPtrFun::dial()
165 {
166 handler(params.conn, params.flag, params.xerrno, params.data);
167 }
168
169 void
170 CommConnectCbPtrFun::print(std::ostream &os) const
171 {
172 os << '(';
173 params.print(os);
174 os << ')';
175 }
176
177 /* CommIoCbPtrFun */
178
179 CommIoCbPtrFun::CommIoCbPtrFun(IOCB *aHandler, const CommIoCbParams &aParams):
180 CommDialerParamsT<CommIoCbParams>(aParams),
181 handler(aHandler)
182 {
183 }
184
185 void
186 CommIoCbPtrFun::dial()
187 {
188 handler(params.conn, params.buf, params.size, params.flag, params.xerrno, params.data);
189 }
190
191 void
192 CommIoCbPtrFun::print(std::ostream &os) const
193 {
194 os << '(';
195 params.print(os);
196 os << ')';
197 }
198
199 /* CommCloseCbPtrFun */
200
201 CommCloseCbPtrFun::CommCloseCbPtrFun(CLCB *aHandler,
202 const CommCloseCbParams &aParams):
203 CommDialerParamsT<CommCloseCbParams>(aParams),
204 handler(aHandler)
205 {
206 }
207
208 void
209 CommCloseCbPtrFun::dial()
210 {
211 handler(params);
212 }
213
214 void
215 CommCloseCbPtrFun::print(std::ostream &os) const
216 {
217 os << '(';
218 params.print(os);
219 os << ')';
220 }
221
222 /* CommTimeoutCbPtrFun */
223
224 CommTimeoutCbPtrFun::CommTimeoutCbPtrFun(CTCB *aHandler,
225 const CommTimeoutCbParams &aParams):
226 CommDialerParamsT<CommTimeoutCbParams>(aParams),
227 handler(aHandler)
228 {
229 }
230
231 void
232 CommTimeoutCbPtrFun::dial()
233 {
234 handler(params);
235 }
236
237 void
238 CommTimeoutCbPtrFun::print(std::ostream &os) const
239 {
240 os << '(';
241 params.print(os);
242 os << ')';
243 }
244
245 /* FdeCbPtrFun */
246
247 FdeCbPtrFun::FdeCbPtrFun(FDECB *aHandler, const FdeCbParams &aParams) :
248 CommDialerParamsT<FdeCbParams>(aParams),
249 handler(aHandler)
250 {
251 }
252
253 void
254 FdeCbPtrFun::dial()
255 {
256 handler(params);
257 }
258
259 void
260 FdeCbPtrFun::print(std::ostream &os) const
261 {
262 os << '(';
263 params.print(os);
264 os << ')';
265 }