]> git.ipfire.org Git - thirdparty/squid.git/blob - src/AccessLogEntry.h
Polish: Http::MethodType upgrade
[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 "icp_opcode.h"
39 #include "ip/Address.h"
40 #include "HttpRequestMethod.h"
41 #if ICAP_CLIENT
42 #include "adaptation/icap/Elements.h"
43 #endif
44 #include "RefCount.h"
45 #if USE_SSL
46 #include "ssl/gadgets.h"
47 #endif
48
49 /* forward decls */
50 class HttpReply;
51 class HttpRequest;
52 class CustomLog;
53
54 class AccessLogEntry: public RefCountable
55 {
56
57 public:
58 typedef RefCount<AccessLogEntry> Pointer;
59
60 AccessLogEntry() : url(NULL), tcpClient(), reply(NULL), request(NULL),
61 adapted_request(NULL) {}
62 ~AccessLogEntry();
63
64 /// Fetch the client IP log string into the given buffer.
65 /// Knows about several alternate locations of the IP
66 /// including indirect forwarded-for IP if configured to log that
67 void getLogClientIp(char *buf, size_t bufsz) const;
68
69 const char *url;
70
71 /// TCP/IP level details about the client connection
72 Comm::ConnectionPointer tcpClient;
73 // TCP/IP level details about the server or peer connection
74 // are stored in hier.tcpServer
75
76 /** \brief This subclass holds log info for HTTP protocol
77 * \todo Inner class declarations should be moved outside
78 * \todo details of HTTP held in the parent class need moving into here.
79 */
80 class HttpDetails
81 {
82
83 public:
84 HttpDetails() : method(Http::METHOD_NONE), code(0), content_type(NULL),
85 timedout(false), aborted(false) {}
86
87 HttpRequestMethod method;
88 int code;
89 const char *content_type;
90 HttpVersion version;
91 bool timedout; ///< terminated due to a lifetime or I/O timeout
92 bool aborted; ///< other abnormal termination (e.g., I/O error)
93
94 /// compute suffix for the status access.log field
95 const char *statusSfx() const {
96 return timedout ? "_TIMEDOUT" : (aborted ? "_ABORTED" : "");
97 }
98 } http;
99
100 /** \brief This subclass holds log info for ICP protocol
101 * \todo Inner class declarations should be moved outside
102 */
103 class IcpDetails
104 {
105
106 public:
107 IcpDetails() : opcode(ICP_INVALID) {}
108
109 icp_opcode opcode;
110 } icp;
111
112 /** \brief This subclass holds log info for HTCP protocol
113 * \todo Inner class declarations should be moved outside
114 */
115 class HtcpDetails
116 {
117 public:
118 HtcpDetails() : opcode(NULL) {};
119
120 const char *opcode;
121 } htcp;
122
123 #if USE_SSL
124 /// logging information specific to the SSL protocol
125 class SslDetails
126 {
127 public:
128 SslDetails();
129
130 const char *user; ///< emailAddress from the SSL client certificate
131 int bumpMode; ///< whether and how the request was SslBumped
132 } ssl;
133 #endif
134
135 /** \brief This subclass holds log info for Squid internal stats
136 * \todo Inner class declarations should be moved outside
137 * \todo some details relevant to particular protocols need shuffling to other sub-classes
138 * \todo this object field need renaming to 'squid' or something.
139 */
140 class CacheDetails
141 {
142
143 public:
144 CacheDetails() : caddr(),
145 requestSize(0),
146 replySize(0),
147 requestHeadersSize(0),
148 replyHeadersSize(0),
149 highOffset(0),
150 objectSize(0),
151 code (LOG_TAG_NONE),
152 msec(0),
153 rfc931 (NULL),
154 authuser (NULL),
155 extuser(NULL),
156 #if USE_SSL
157 ssluser(NULL),
158 #endif
159 port(NULL) {
160 ;
161 }
162
163 Ip::Address caddr;
164 int64_t requestSize;
165 int64_t replySize;
166 int requestHeadersSize; ///< received, including request line
167 int replyHeadersSize; ///< sent, including status line
168 int64_t highOffset;
169 int64_t objectSize;
170 log_type code;
171 int msec;
172 const char *rfc931;
173 const char *authuser;
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 #if ICAP_CLIENT
234 /** \brief This subclass holds log info for ICAP part of request
235 * \todo Inner class declarations should be moved outside
236 */
237 class IcapLogEntry
238 {
239 public:
240 IcapLogEntry():bodyBytesRead(-1),request(NULL),reply(NULL),outcome(Adaptation::Icap::xoUnknown),trTime(0),ioTime(0),resStatus(HTTP_STATUS_NONE) {}
241
242 Ip::Address hostAddr; ///< ICAP server IP address
243 String serviceName; ///< ICAP service name
244 String reqUri; ///< ICAP Request-URI
245 Adaptation::Icap::ICAP::Method reqMethod; ///< ICAP request method
246 int64_t bytesSent; ///< number of bytes sent to ICAP server so far
247 int64_t bytesRead; ///< number of bytes read from ICAP server so far
248 /**
249 * number of ICAP body bytes read from ICAP server or -1 for no encapsulated
250 * message data in ICAP reply (eg 204 responses)
251 */
252 int64_t bodyBytesRead;
253 HttpRequest* request; ///< ICAP request
254 HttpReply* reply; ///< ICAP reply
255
256 Adaptation::Icap::XactOutcome outcome; ///< final transaction status
257 /** \brief Transaction response time.
258 * The timer starts when the ICAP transaction
259 * is created and stops when the result of the transaction is logged
260 */
261 int trTime;
262 /** \brief Transaction I/O time.
263 * The timer starts when the first ICAP request
264 * byte is scheduled for sending and stops when the lastbyte of the
265 * ICAP response is received.
266 */
267 int ioTime;
268 http_status resStatus; ///< ICAP response status code
269 int processingTime; ///< total ICAP processing time in milliseconds
270 }
271 icap;
272 #endif
273 };
274
275 class ACLChecklist;
276 class StoreEntry;
277
278 /* Should be in 'AccessLog.h' as the driver */
279 void accessLogLogTo(CustomLog* log, AccessLogEntry::Pointer &al, ACLChecklist* checklist = NULL);
280 void accessLogLog(AccessLogEntry::Pointer &, ACLChecklist * checklist);
281 void accessLogRotate(void);
282 void accessLogClose(void);
283 void accessLogInit(void);
284 const char *accessLogTime(time_t);
285
286 #endif /* SQUID_HTTPACCESSLOGENTRY_H */