]> git.ipfire.org Git - thirdparty/squid.git/blob - src/AccessLogEntry.h
Add key_extras to proxy authentication schemes.
[thirdparty/squid.git] / src / AccessLogEntry.h
1 /*
2 * SQUID Web Proxy Cache http://www.squid-cache.org/
3 * ----------------------------------------------------------
4 *
5 * Squid is the result of efforts by numerous individuals from
6 * the Internet community; see the CONTRIBUTORS file for full
7 * details. Many organizations have provided support for Squid's
8 * development; see the SPONSORS file for full details. Squid is
9 * Copyrighted (C) 2001 by the Regents of the University of
10 * California; see the COPYRIGHT file for full details. Squid
11 * incorporates software developed and/or copyrighted by other
12 * sources; see the CREDITS file for full details.
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
27 *
28 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
29 */
30 #ifndef SQUID_HTTPACCESSLOGENTRY_H
31 #define SQUID_HTTPACCESSLOGENTRY_H
32
33 #include "anyp/PortCfg.h"
34 #include "base/RefCount.h"
35 #include "comm/Connection.h"
36 #include "HierarchyLogEntry.h"
37 #include "http/ProtocolVersion.h"
38 #include "HttpHeader.h"
39 #include "HttpRequestMethod.h"
40 #include "icp_opcode.h"
41 #include "ip/Address.h"
42 #include "LogTags.h"
43 #include "MessageSizes.h"
44 #include "Notes.h"
45 #if ICAP_CLIENT
46 #include "adaptation/icap/Elements.h"
47 #endif
48 #if USE_SSL
49 #include "ssl/gadgets.h"
50 #endif
51
52 /* forward decls */
53 class HttpReply;
54 class HttpRequest;
55 class CustomLog;
56
57 class AccessLogEntry: public RefCountable
58 {
59
60 public:
61 typedef RefCount<AccessLogEntry> Pointer;
62
63 AccessLogEntry() : url(NULL), tcpClient(), reply(NULL), request(NULL),
64 adapted_request(NULL) {}
65 ~AccessLogEntry();
66
67 /// Fetch the client IP log string into the given buffer.
68 /// Knows about several alternate locations of the IP
69 /// including indirect forwarded-for IP if configured to log that
70 void getLogClientIp(char *buf, size_t bufsz) const;
71
72 const char *url;
73
74 /// TCP/IP level details about the client connection
75 Comm::ConnectionPointer tcpClient;
76 // TCP/IP level details about the server or peer connection
77 // are stored in hier.tcpServer
78
79 /** \brief This subclass holds log info for HTTP protocol
80 * \todo Inner class declarations should be moved outside
81 * \todo details of HTTP held in the parent class need moving into here.
82 */
83 class HttpDetails
84 {
85
86 public:
87 HttpDetails() : method(Http::METHOD_NONE), code(0), content_type(NULL),
88 timedout(false),
89 aborted(false),
90 clientRequestSz(),
91 clientReplySz() {}
92
93 HttpRequestMethod method;
94 int code;
95 const char *content_type;
96 Http::ProtocolVersion version;
97 bool timedout; ///< terminated due to a lifetime or I/O timeout
98 bool aborted; ///< other abnormal termination (e.g., I/O error)
99
100 /// compute suffix for the status access.log field
101 const char *statusSfx() const {
102 return timedout ? "_TIMEDOUT" : (aborted ? "_ABORTED" : "");
103 }
104
105 /// counters for the original request received from client
106 // TODO calculate header and payload better (by parser)
107 // XXX payload encoding overheads not calculated at all yet.
108 MessageSizes clientRequestSz;
109
110 /// counters for the response sent to client
111 // TODO calculate header and payload better (by parser)
112 // XXX payload encoding overheads not calculated at all yet.
113 MessageSizes clientReplySz;
114
115 } http;
116
117 /** \brief This subclass holds log info for ICP protocol
118 * \todo Inner class declarations should be moved outside
119 */
120 class IcpDetails
121 {
122
123 public:
124 IcpDetails() : opcode(ICP_INVALID) {}
125
126 icp_opcode opcode;
127 } icp;
128
129 /** \brief This subclass holds log info for HTCP protocol
130 * \todo Inner class declarations should be moved outside
131 */
132 class HtcpDetails
133 {
134 public:
135 HtcpDetails() : opcode(NULL) {};
136
137 const char *opcode;
138 } htcp;
139
140 #if USE_SSL
141 /// logging information specific to the SSL protocol
142 class SslDetails
143 {
144 public:
145 SslDetails();
146
147 const char *user; ///< emailAddress from the SSL client certificate
148 int bumpMode; ///< whether and how the request was SslBumped
149 } ssl;
150 #endif
151
152 /** \brief This subclass holds log info for Squid internal stats
153 * \todo Inner class declarations should be moved outside
154 * \todo some details relevant to particular protocols need shuffling to other sub-classes
155 * \todo this object field need renaming to 'squid' or something.
156 */
157 class CacheDetails
158 {
159
160 public:
161 CacheDetails() : caddr(),
162 highOffset(0),
163 objectSize(0),
164 code (LOG_TAG_NONE),
165 msec(0),
166 rfc931 (NULL),
167 extuser(NULL),
168 #if USE_SSL
169 ssluser(NULL),
170 #endif
171 port(NULL) {
172 caddr.setNoAddr();
173 }
174
175 Ip::Address caddr;
176 int64_t highOffset;
177 int64_t objectSize;
178 LogTags code;
179 struct timeval start_time; ///< The time the master transaction started
180 int msec;
181 const char *rfc931;
182 const char *extuser;
183 #if USE_SSL
184
185 const char *ssluser;
186 Ssl::X509_Pointer sslClientCert; ///< cert received from the client
187 #endif
188 AnyP::PortCfg *port;
189
190 } cache;
191
192 /** \brief This subclass holds log info for various headers in raw format
193 * \todo shuffle this to the relevant protocol section.
194 */
195 class Headers
196 {
197
198 public:
199 Headers() : request(NULL),
200 adapted_request(NULL),
201 reply(NULL) {}
202
203 char *request; //< virgin HTTP request headers
204
205 char *adapted_request; //< HTTP request headers after adaptation and redirection
206
207 char *reply;
208 } headers;
209
210 #if USE_ADAPTATION
211 /** \brief This subclass holds general adaptation log info.
212 * \todo Inner class declarations should be moved outside.
213 */
214 class AdaptationDetails
215 {
216
217 public:
218 AdaptationDetails(): last_meta(NULL) {}
219
220 /// image of the last ICAP response header or eCAP meta received
221 char *last_meta;
222 } adapt;
223 #endif
224
225 // Why is this a sub-class and not a set of real "private:" fields?
226 // It looks like its duplicating HTTPRequestMethod anyway!
227 // TODO: shuffle this to the relevant protocol section OR replace with request->method
228 class Private
229 {
230
231 public:
232 Private() : method_str(NULL) {}
233
234 const char *method_str;
235 } _private;
236 HierarchyLogEntry hier;
237 HttpReply *reply;
238 HttpRequest *request; //< virgin HTTP request
239 HttpRequest *adapted_request; //< HTTP request after adaptation and redirection
240
241 /// key:value pairs set by squid.conf note directive and
242 /// key=value pairs returned from URL rewrite/redirect helper
243 NotePairs::Pointer notes;
244
245 #if ICAP_CLIENT
246 /** \brief This subclass holds log info for ICAP part of request
247 * \todo Inner class declarations should be moved outside
248 */
249 class IcapLogEntry
250 {
251 public:
252 IcapLogEntry() : reqMethod(Adaptation::methodNone), bytesSent(0), bytesRead(0),
253 bodyBytesRead(-1), request(NULL), reply(NULL),
254 outcome(Adaptation::Icap::xoUnknown), trTime(0),
255 ioTime(0), resStatus(Http::scNone), processingTime(0) {}
256
257 Ip::Address hostAddr; ///< ICAP server IP address
258 String serviceName; ///< ICAP service name
259 String reqUri; ///< ICAP Request-URI
260 Adaptation::Icap::ICAP::Method reqMethod; ///< ICAP request method
261 int64_t bytesSent; ///< number of bytes sent to ICAP server so far
262 int64_t bytesRead; ///< number of bytes read from ICAP server so far
263 /**
264 * number of ICAP body bytes read from ICAP server or -1 for no encapsulated
265 * message data in ICAP reply (eg 204 responses)
266 */
267 int64_t bodyBytesRead;
268 HttpRequest* request; ///< ICAP request
269 HttpReply* reply; ///< ICAP reply
270
271 Adaptation::Icap::XactOutcome outcome; ///< final transaction status
272 /** \brief Transaction response time.
273 * The timer starts when the ICAP transaction
274 * is created and stops when the result of the transaction is logged
275 */
276 int trTime;
277 /** \brief Transaction I/O time.
278 * The timer starts when the first ICAP request
279 * byte is scheduled for sending and stops when the lastbyte of the
280 * ICAP response is received.
281 */
282 int ioTime;
283 Http::StatusCode resStatus; ///< ICAP response status code
284 int processingTime; ///< total ICAP processing time in milliseconds
285 }
286 icap;
287 #endif
288 };
289
290 class ACLChecklist;
291 class StoreEntry;
292
293 /* Should be in 'AccessLog.h' as the driver */
294 void accessLogLogTo(CustomLog* log, AccessLogEntry::Pointer &al, ACLChecklist* checklist = NULL);
295 void accessLogLog(AccessLogEntry::Pointer &, ACLChecklist * checklist);
296 void accessLogRotate(void);
297 void accessLogClose(void);
298 void accessLogInit(void);
299 const char *accessLogTime(time_t);
300
301 #endif /* SQUID_HTTPACCESSLOGENTRY_H */