]> git.ipfire.org Git - thirdparty/squid.git/blob - src/AccessLogEntry.h
author: Alex Rousskov <rousskov@measurement-factory.com>, Christos Tsantilas <chtsant...
[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 "comm/Connection.h"
35 #include "HttpVersion.h"
36 #include "HttpRequestMethod.h"
37 #include "HierarchyLogEntry.h"
38 #include "ip/Address.h"
39 #include "HttpRequestMethod.h"
40 #if ICAP_CLIENT
41 #include "adaptation/icap/Elements.h"
42 #endif
43 #include "RefCount.h"
44 #if USE_SSL
45 #include "ssl/gadgets.h"
46 #endif
47
48 /* forward decls */
49 class HttpReply;
50 class HttpRequest;
51
52 class AccessLogEntry: public RefCountable
53 {
54
55 public:
56 typedef RefCount<AccessLogEntry> Pointer;
57
58 AccessLogEntry() : url(NULL), tcpClient(), reply(NULL), request(NULL),
59 adapted_request(NULL) {}
60 ~AccessLogEntry();
61
62 /// Fetch the client IP log string into the given buffer.
63 /// Knows about several alternate locations of the IP
64 /// including indirect forwarded-for IP if configured to log that
65 void getLogClientIp(char *buf, size_t bufsz) const;
66
67 const char *url;
68
69 /// TCP/IP level details about the client connection
70 Comm::ConnectionPointer tcpClient;
71 // TCP/IP level details about the server or peer connection
72 // are stored in hier.tcpServer
73
74 /** \brief This subclass holds log info for HTTP protocol
75 * \todo Inner class declarations should be moved outside
76 * \todo details of HTTP held in the parent class need moving into here.
77 */
78 class HttpDetails
79 {
80
81 public:
82 HttpDetails() : method(METHOD_NONE), code(0), content_type(NULL),
83 timedout(false), aborted(false) {}
84
85 HttpRequestMethod method;
86 int code;
87 const char *content_type;
88 HttpVersion version;
89 bool timedout; ///< terminated due to a lifetime or I/O timeout
90 bool aborted; ///< other abnormal termination (e.g., I/O error)
91
92 /// compute suffix for the status access.log field
93 const char *statusSfx() const {
94 return timedout ? "_TIMEDOUT" : (aborted ? "_ABORTED" : "");
95 }
96 } http;
97
98 /** \brief This subclass holds log info for ICP protocol
99 * \todo Inner class declarations should be moved outside
100 */
101 class IcpDetails
102 {
103
104 public:
105 IcpDetails() : opcode(ICP_INVALID) {}
106
107 icp_opcode opcode;
108 } icp;
109
110 /** \brief This subclass holds log info for HTCP protocol
111 * \todo Inner class declarations should be moved outside
112 */
113 class HtcpDetails
114 {
115 public:
116 HtcpDetails() : opcode(NULL) {};
117
118 const char *opcode;
119 } htcp;
120
121 #if USE_SSL
122 /// logging information specific to the SSL protocol
123 class SslDetails {
124 public:
125 SslDetails();
126
127 const char *user; ///< emailAddress from the SSL client certificate
128 int bumpMode; ///< whether and how the request was SslBumped
129 } ssl;
130 #endif
131
132 /** \brief This subclass holds log info for Squid internal stats
133 * \todo Inner class declarations should be moved outside
134 * \todo some details relevant to particular protocols need shuffling to other sub-classes
135 * \todo this object field need renaming to 'squid' or something.
136 */
137 class CacheDetails
138 {
139
140 public:
141 CacheDetails() : caddr(),
142 requestSize(0),
143 replySize(0),
144 requestHeadersSize(0),
145 replyHeadersSize(0),
146 highOffset(0),
147 objectSize(0),
148 code (LOG_TAG_NONE),
149 msec(0),
150 rfc931 (NULL),
151 authuser (NULL),
152 extuser(NULL),
153 #if USE_SSL
154 ssluser(NULL),
155 #endif
156 port(NULL) {
157 ;
158 }
159
160 Ip::Address caddr;
161 int64_t requestSize;
162 int64_t replySize;
163 int requestHeadersSize; ///< received, including request line
164 int replyHeadersSize; ///< sent, including status line
165 int64_t highOffset;
166 int64_t objectSize;
167 log_type code;
168 int msec;
169 const char *rfc931;
170 const char *authuser;
171 const char *extuser;
172 #if USE_SSL
173
174 const char *ssluser;
175 Ssl::X509_Pointer sslClientCert; ///< cert received from the client
176 #endif
177 AnyP::PortCfg *port;
178
179 } cache;
180
181 /** \brief This subclass holds log info for various headers in raw format
182 * \todo shuffle this to the relevant protocol section.
183 */
184 class Headers
185 {
186
187 public:
188 Headers() : request(NULL),
189 adapted_request(NULL),
190 reply(NULL) {}
191
192 char *request; //< virgin HTTP request headers
193
194 char *adapted_request; //< HTTP request headers after adaptation and redirection
195
196 char *reply;
197 } headers;
198
199 #if USE_ADAPTATION
200 /** \brief This subclass holds general adaptation log info.
201 * \todo Inner class declarations should be moved outside.
202 */
203 class AdaptationDetails
204 {
205
206 public:
207 AdaptationDetails(): last_meta(NULL) {}
208
209 /// image of the last ICAP response header or eCAP meta received
210 char *last_meta;
211 } adapt;
212 #endif
213
214 // Why is this a sub-class and not a set of real "private:" fields?
215 // It looks like its duplicating HTTPRequestMethod anyway!
216 // TODO: shuffle this to the relevant protocol section OR replace with request->method
217 class Private
218 {
219
220 public:
221 Private() : method_str(NULL) {}
222
223 const char *method_str;
224 } _private;
225 HierarchyLogEntry hier;
226 HttpReply *reply;
227 HttpRequest *request; //< virgin HTTP request
228 HttpRequest *adapted_request; //< HTTP request after adaptation and redirection
229
230
231 #if ICAP_CLIENT
232 /** \brief This subclass holds log info for ICAP part of request
233 * \todo Inner class declarations should be moved outside
234 */
235 class IcapLogEntry
236 {
237 public:
238 IcapLogEntry():bodyBytesRead(-1),request(NULL),reply(NULL),outcome(Adaptation::Icap::xoUnknown),trTime(0),ioTime(0),resStatus(HTTP_STATUS_NONE) {}
239
240 Ip::Address hostAddr; ///< ICAP server IP address
241 String serviceName; ///< ICAP service name
242 String reqUri; ///< ICAP Request-URI
243 Adaptation::Icap::ICAP::Method reqMethod; ///< ICAP request method
244 int64_t bytesSent; ///< number of bytes sent to ICAP server so far
245 int64_t bytesRead; ///< number of bytes read from ICAP server so far
246 /**
247 * number of ICAP body bytes read from ICAP server or -1 for no encapsulated
248 * message data in ICAP reply (eg 204 responses)
249 */
250 int64_t bodyBytesRead;
251 HttpRequest* request; ///< ICAP request
252 HttpReply* reply; ///< ICAP reply
253
254 Adaptation::Icap::XactOutcome outcome; ///< final transaction status
255 /** \brief Transaction response time.
256 * The timer starts when the ICAP transaction
257 * is created and stops when the result of the transaction is logged
258 */
259 int trTime;
260 /** \brief Transaction I/O time.
261 * The timer starts when the first ICAP request
262 * byte is scheduled for sending and stops when the lastbyte of the
263 * ICAP response is received.
264 */
265 int ioTime;
266 http_status resStatus; ///< ICAP response status code
267 int processingTime; ///< total ICAP processing time in milliseconds
268 }
269 icap;
270 #endif
271 };
272
273 class ACLChecklist;
274 class StoreEntry;
275
276 /* Should be in 'AccessLog.h' as the driver */
277 extern void accessLogLogTo(customlog* log, AccessLogEntry::Pointer &al, ACLChecklist* checklist = NULL);
278 extern void accessLogLog(AccessLogEntry::Pointer &, ACLChecklist * checklist);
279 extern void accessLogRotate(void);
280 extern void accessLogClose(void);
281 extern void accessLogInit(void);
282 extern const char *accessLogTime(time_t);
283
284 #endif /* SQUID_HTTPACCESSLOGENTRY_H */