]> git.ipfire.org Git - thirdparty/squid.git/blob - src/AccessLogEntry.h
Cleanup: Shuffle Squid result codes (aka log tags) into class LogTags
[thirdparty/squid.git] / src / AccessLogEntry.h
1 /*
2 * Copyright (C) 1996-2015 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() :
67 method(Http::METHOD_NONE),
68 code(0),
69 content_type(NULL),
70 clientRequestSz(),
71 clientReplySz() {}
72
73 HttpRequestMethod method;
74 int code;
75 const char *content_type;
76 AnyP::ProtocolVersion version;
77
78 /// counters for the original request received from client
79 // TODO calculate header and payload better (by parser)
80 // XXX payload encoding overheads not calculated at all yet.
81 MessageSizes clientRequestSz;
82
83 /// counters for the response sent to client
84 // TODO calculate header and payload better (by parser)
85 // XXX payload encoding overheads not calculated at all yet.
86 MessageSizes clientReplySz;
87
88 } http;
89
90 /** \brief This subclass holds log info for ICP protocol
91 * \todo Inner class declarations should be moved outside
92 */
93 class IcpDetails
94 {
95
96 public:
97 IcpDetails() : opcode(ICP_INVALID) {}
98
99 icp_opcode opcode;
100 } icp;
101
102 /** \brief This subclass holds log info for HTCP protocol
103 * \todo Inner class declarations should be moved outside
104 */
105 class HtcpDetails
106 {
107 public:
108 HtcpDetails() : opcode(NULL) {};
109
110 const char *opcode;
111 } htcp;
112
113 #if USE_OPENSSL
114 /// logging information specific to the SSL protocol
115 class SslDetails
116 {
117 public:
118 SslDetails();
119
120 const char *user; ///< emailAddress from the SSL client certificate
121 int bumpMode; ///< whether and how the request was SslBumped
122 } ssl;
123 #endif
124
125 /** \brief This subclass holds log info for Squid internal stats
126 * \todo Inner class declarations should be moved outside
127 * \todo some details relevant to particular protocols need shuffling to other sub-classes
128 * \todo this object field need renaming to 'squid' or something.
129 */
130 class CacheDetails
131 {
132
133 public:
134 CacheDetails() : caddr(),
135 highOffset(0),
136 objectSize(0),
137 code(LOG_TAG_NONE),
138 rfc931 (NULL),
139 extuser(NULL),
140 #if USE_OPENSSL
141 ssluser(NULL),
142 #endif
143 port(NULL)
144 {
145 caddr.setNoAddr();
146 memset(&start_time, 0, sizeof(start_time));
147 memset(&trTime, 0, sizeof(start_time));
148 }
149
150 Ip::Address caddr;
151 int64_t highOffset;
152 int64_t objectSize;
153 LogTags code;
154 struct timeval start_time; ///< The time the master transaction started
155 struct timeval trTime; ///< The response time
156 const char *rfc931;
157 const char *extuser;
158 #if USE_OPENSSL
159
160 const char *ssluser;
161 Ssl::X509_Pointer sslClientCert; ///< cert received from the client
162 #endif
163 AnyP::PortCfgPointer port;
164
165 } cache;
166
167 /** \brief This subclass holds log info for various headers in raw format
168 * \todo shuffle this to the relevant protocol section.
169 */
170 class Headers
171 {
172
173 public:
174 Headers() : request(NULL),
175 adapted_request(NULL),
176 reply(NULL) {}
177
178 char *request; //< virgin HTTP request headers
179
180 char *adapted_request; //< HTTP request headers after adaptation and redirection
181
182 char *reply;
183 } headers;
184
185 #if USE_ADAPTATION
186 /** \brief This subclass holds general adaptation log info.
187 * \todo Inner class declarations should be moved outside.
188 */
189 class AdaptationDetails
190 {
191
192 public:
193 AdaptationDetails(): last_meta(NULL) {}
194
195 /// image of the last ICAP response header or eCAP meta received
196 char *last_meta;
197 } adapt;
198 #endif
199
200 // Why is this a sub-class and not a set of real "private:" fields?
201 // TODO: shuffle this to the relevant ICP/HTCP protocol section
202 class Private
203 {
204
205 public:
206 Private() : method_str(NULL) {}
207
208 const char *method_str;
209 } _private;
210 HierarchyLogEntry hier;
211 HttpReply *reply;
212 HttpRequest *request; //< virgin HTTP request
213 HttpRequest *adapted_request; //< HTTP request after adaptation and redirection
214
215 /// key:value pairs set by squid.conf note directive and
216 /// key=value pairs returned from URL rewrite/redirect helper
217 NotePairs::Pointer notes;
218
219 #if ICAP_CLIENT
220 /** \brief This subclass holds log info for ICAP part of request
221 * \todo Inner class declarations should be moved outside
222 */
223 class IcapLogEntry
224 {
225 public:
226 IcapLogEntry() : reqMethod(Adaptation::methodNone), bytesSent(0), bytesRead(0),
227 bodyBytesRead(-1), request(NULL), reply(NULL),
228 outcome(Adaptation::Icap::xoUnknown), resStatus(Http::scNone)
229 {
230 memset(&trTime, 0, sizeof(trTime));
231 memset(&ioTime, 0, sizeof(ioTime));
232 memset(&processingTime, 0, sizeof(processingTime));
233 }
234
235 Ip::Address hostAddr; ///< ICAP server IP address
236 String serviceName; ///< ICAP service name
237 String reqUri; ///< ICAP Request-URI
238 Adaptation::Icap::ICAP::Method reqMethod; ///< ICAP request method
239 int64_t bytesSent; ///< number of bytes sent to ICAP server so far
240 int64_t bytesRead; ///< number of bytes read from ICAP server so far
241 /**
242 * number of ICAP body bytes read from ICAP server or -1 for no encapsulated
243 * message data in ICAP reply (eg 204 responses)
244 */
245 int64_t bodyBytesRead;
246 HttpRequest* request; ///< ICAP request
247 HttpReply* reply; ///< ICAP reply
248
249 Adaptation::Icap::XactOutcome outcome; ///< final transaction status
250 /** \brief Transaction response time.
251 * The timer starts when the ICAP transaction
252 * is created and stops when the result of the transaction is logged
253 */
254 struct timeval trTime;
255 /** \brief Transaction I/O time.
256 * The timer starts when the first ICAP request
257 * byte is scheduled for sending and stops when the lastbyte of the
258 * ICAP response is received.
259 */
260 struct timeval ioTime;
261 Http::StatusCode resStatus; ///< ICAP response status code
262 struct timeval processingTime; ///< total ICAP processing time
263 }
264 icap;
265 #endif
266 };
267
268 class ACLChecklist;
269 class StoreEntry;
270
271 /* Should be in 'AccessLog.h' as the driver */
272 void accessLogLogTo(CustomLog* log, AccessLogEntry::Pointer &al, ACLChecklist* checklist = NULL);
273 void accessLogLog(AccessLogEntry::Pointer &, ACLChecklist * checklist);
274 void accessLogRotate(void);
275 void accessLogClose(void);
276 void accessLogInit(void);
277 const char *accessLogTime(time_t);
278
279 #endif /* SQUID_HTTPACCESSLOGENTRY_H */
280