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