]> git.ipfire.org Git - thirdparty/squid.git/blame - src/AccessLogEntry.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / AccessLogEntry.h
CommitLineData
450e0c10 1/*
4ac4a490 2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
450e0c10 3 *
bbc27441
AJ
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.
450e0c10 7 */
bbc27441 8
450e0c10 9#ifndef SQUID_HTTPACCESSLOGENTRY_H
10#define SQUID_HTTPACCESSLOGENTRY_H
11
65d448bc 12#include "anyp/PortCfg.h"
8bf217bd 13#include "base/RefCount.h"
a14f38d0 14#include "comm/Connection.h"
602d9612 15#include "HierarchyLogEntry.h"
526ed14e 16#include "http/ProtocolVersion.h"
f35c0145 17#include "http/RequestMethod.h"
e74be5fd 18#include "HttpHeader.h"
c8f1812b 19#include "icp_opcode.h"
96d89ea0 20#include "ip/Address.h"
02c8dde5 21#include "LogTags.h"
cc0ca3b9 22#include "MessageSizes.h"
02c8dde5 23#include "Notes.h"
f57ae909 24#include "sbuf/SBuf.h"
3ff65596
AR
25#if ICAP_CLIENT
26#include "adaptation/icap/Elements.h"
27#endif
cb4f4424 28#if USE_OPENSSL
f4698e0b
CT
29#include "ssl/gadgets.h"
30#endif
450e0c10 31
62ee09ca 32/* forward decls */
e1f7507e
AJ
33class HttpReply;
34class HttpRequest;
613924ee 35class CustomLog;
62ee09ca 36
41ebd397 37class AccessLogEntry: public RefCountable
450e0c10 38{
39
40public:
41ebd397
CT
41 typedef RefCount<AccessLogEntry> Pointer;
42
4ff6370b
AJ
43 AccessLogEntry() :
44 url(nullptr),
45 lastAclName(nullptr),
4ff6370b
AJ
46 reply(nullptr),
47 request(nullptr),
48 adapted_request(nullptr)
49 {}
41ebd397 50 ~AccessLogEntry();
450e0c10 51
d4204018
AJ
52 /// Fetch the client IP log string into the given buffer.
53 /// Knows about several alternate locations of the IP
54 /// including indirect forwarded-for IP if configured to log that
55 void getLogClientIp(char *buf, size_t bufsz) const;
56
58b148e1
AJ
57 /// Fetch the transaction method string (ICP opcode, HTCP opcode or HTTP method)
58 SBuf getLogMethod() const;
59
f57ae909 60 SBuf url;
450e0c10 61
a14f38d0
AJ
62 /// TCP/IP level details about the client connection
63 Comm::ConnectionPointer tcpClient;
64 // TCP/IP level details about the server or peer connection
65 // are stored in hier.tcpServer
66
4e26d606
AJ
67 /** \brief This subclass holds log info for HTTP protocol
68 * \todo Inner class declarations should be moved outside
69 * \todo details of HTTP held in the parent class need moving into here.
70 */
450e0c10 71 class HttpDetails
72 {
73
74 public:
91369933
AJ
75 HttpDetails() :
76 method(Http::METHOD_NONE),
77 code(0),
78 content_type(NULL),
f53969cc
SM
79 clientRequestSz(),
80 clientReplySz() {}
450e0c10 81
60745f24 82 HttpRequestMethod method;
450e0c10 83 int code;
84 const char *content_type;
2592bc70 85 AnyP::ProtocolVersion version;
d6df21d2
AJ
86
87 /// counters for the original request received from client
88 // TODO calculate header and payload better (by parser)
89 // XXX payload encoding overheads not calculated at all yet.
cc0ca3b9 90 MessageSizes clientRequestSz;
d6df21d2
AJ
91
92 /// counters for the response sent to client
93 // TODO calculate header and payload better (by parser)
94 // XXX payload encoding overheads not calculated at all yet.
cc0ca3b9 95 MessageSizes clientReplySz;
d6df21d2 96
2fadd50d 97 } http;
450e0c10 98
4e26d606
AJ
99 /** \brief This subclass holds log info for ICP protocol
100 * \todo Inner class declarations should be moved outside
101 */
102 class IcpDetails
450e0c10 103 {
104
105 public:
4e26d606 106 IcpDetails() : opcode(ICP_INVALID) {}
450e0c10 107
108 icp_opcode opcode;
2fadd50d 109 } icp;
450e0c10 110
4e26d606
AJ
111 /** \brief This subclass holds log info for HTCP protocol
112 * \todo Inner class declarations should be moved outside
113 */
04f7fd38
AJ
114 class HtcpDetails
115 {
a8b1cdf6
AJ
116 public:
117 HtcpDetails() : opcode(NULL) {};
118
119 const char *opcode;
120 } htcp;
121
cb4f4424 122#if USE_OPENSSL
08097970 123 /// logging information specific to the SSL protocol
87f237a9
A
124 class SslDetails
125 {
08097970 126 public:
71cae389 127 SslDetails();
08097970
AR
128
129 const char *user; ///< emailAddress from the SSL client certificate
130 int bumpMode; ///< whether and how the request was SslBumped
131 } ssl;
132#endif
133
4e26d606
AJ
134 /** \brief This subclass holds log info for Squid internal stats
135 * \todo Inner class declarations should be moved outside
136 * \todo some details relevant to particular protocols need shuffling to other sub-classes
137 * \todo this object field need renaming to 'squid' or something.
138 */
450e0c10 139 class CacheDetails
140 {
141
142 public:
cc192b50 143 CacheDetails() : caddr(),
f53969cc
SM
144 highOffset(0),
145 objectSize(0),
91369933 146 code(LOG_TAG_NONE),
f53969cc
SM
147 rfc931 (NULL),
148 extuser(NULL),
cb4f4424 149#if USE_OPENSSL
f53969cc 150 ssluser(NULL),
450e0c10 151#endif
f53969cc 152 port(NULL)
4579a6d0 153 {
d4806c91 154 caddr.setNoAddr();
4579a6d0 155 memset(&start_time, 0, sizeof(start_time));
01bd87d8 156 memset(&trTime, 0, sizeof(start_time));
450e0c10 157 }
158
b7ac5457 159 Ip::Address caddr;
47f6e231 160 int64_t highOffset;
161 int64_t objectSize;
02c8dde5 162 LogTags code;
af0ded40 163 struct timeval start_time; ///< The time the master transaction started
01bd87d8 164 struct timeval trTime; ///< The response time
450e0c10 165 const char *rfc931;
661ef4eb 166 const char *extuser;
cb4f4424 167#if USE_OPENSSL
450e0c10 168
169 const char *ssluser;
f97700a0 170 Security::CertPointer sslClientCert; ///< cert received from the client
450e0c10 171#endif
fa720bfb 172 AnyP::PortCfgPointer port;
450e0c10 173
2fadd50d 174 } cache;
450e0c10 175
4e26d606
AJ
176 /** \brief This subclass holds log info for various headers in raw format
177 * \todo shuffle this to the relevant protocol section.
178 */
450e0c10 179 class Headers
180 {
181
182 public:
3ff65596 183 Headers() : request(NULL),
f53969cc
SM
184 adapted_request(NULL),
185 reply(NULL) {}
450e0c10 186
6fca33e0
CT
187 char *request; //< virgin HTTP request headers
188
105d1937 189 char *adapted_request; //< HTTP request headers after adaptation and redirection
6fca33e0 190
99690f32
AR
191 char *reply;
192 } headers;
3ff65596 193
5038f9d8 194#if USE_ADAPTATION
99690f32
AR
195 /** \brief This subclass holds general adaptation log info.
196 * \todo Inner class declarations should be moved outside.
197 */
198 class AdaptationDetails
199 {
200
201 public:
202 AdaptationDetails(): last_meta(NULL) {}
5038f9d8 203
99690f32
AR
204 /// image of the last ICAP response header or eCAP meta received
205 char *last_meta;
206 } adapt;
3ff65596 207#endif
450e0c10 208
4ff6370b 209 const char *lastAclName; ///< string for external_acl_type %ACL format code
b0e14ce2 210 SBuf lastAclData; ///< string for external_acl_type %DATA format code
4ff6370b 211
450e0c10 212 HierarchyLogEntry hier;
213 HttpReply *reply;
105d1937 214 HttpRequest *request; //< virgin HTTP request
6fca33e0 215 HttpRequest *adapted_request; //< HTTP request after adaptation and redirection
d06e17ea 216
f4f55a21 217 /// key:value pairs set by squid.conf note directive and
cf9f0261 218 /// key=value pairs returned from URL rewrite/redirect helper
f4f55a21 219 NotePairs::Pointer notes;
6fca33e0 220
3ff65596
AR
221#if ICAP_CLIENT
222 /** \brief This subclass holds log info for ICAP part of request
223 * \todo Inner class declarations should be moved outside
224 */
e1381638
AJ
225 class IcapLogEntry
226 {
3ff65596 227 public:
f5d0906a 228 IcapLogEntry() : reqMethod(Adaptation::methodNone), bytesSent(0), bytesRead(0),
f53969cc
SM
229 bodyBytesRead(-1), request(NULL), reply(NULL),
230 outcome(Adaptation::Icap::xoUnknown), resStatus(Http::scNone)
01bd87d8
CT
231 {
232 memset(&trTime, 0, sizeof(trTime));
233 memset(&ioTime, 0, sizeof(ioTime));
234 memset(&processingTime, 0, sizeof(processingTime));
235 }
3ff65596 236
b7ac5457 237 Ip::Address hostAddr; ///< ICAP server IP address
3ff65596
AR
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
bae917ac 243 /**
dcaab393 244 * number of ICAP body bytes read from ICAP server or -1 for no encapsulated
bae917ac
CT
245 * message data in ICAP reply (eg 204 responses)
246 */
247 int64_t bodyBytesRead;
3ff65596
AR
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 */
01bd87d8 256 struct timeval trTime;
3ff65596
AR
257 /** \brief Transaction I/O time.
258 * The timer starts when the first ICAP request
e1381638 259 * byte is scheduled for sending and stops when the lastbyte of the
3ff65596
AR
260 * ICAP response is received.
261 */
01bd87d8 262 struct timeval ioTime;
955394ce 263 Http::StatusCode resStatus; ///< ICAP response status code
01bd87d8 264 struct timeval processingTime; ///< total ICAP processing time
3ff65596
AR
265 }
266 icap;
267#endif
450e0c10 268};
269
e1f7507e
AJ
270class ACLChecklist;
271class StoreEntry;
e1f7507e 272
450e0c10 273/* Should be in 'AccessLog.h' as the driver */
8a648e8d
FC
274void accessLogLogTo(CustomLog* log, AccessLogEntry::Pointer &al, ACLChecklist* checklist = NULL);
275void accessLogLog(AccessLogEntry::Pointer &, ACLChecklist * checklist);
276void accessLogRotate(void);
277void accessLogClose(void);
278void accessLogInit(void);
279const char *accessLogTime(time_t);
450e0c10 280
281#endif /* SQUID_HTTPACCESSLOGENTRY_H */
f53969cc 282