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