]> git.ipfire.org Git - thirdparty/squid.git/blame - src/AccessLogEntry.h
Cleanup: use SBuf::npos instead of npos in SBuf::append()
[thirdparty/squid.git] / src / AccessLogEntry.h
CommitLineData
450e0c10 1/*
bbc27441 2 * Copyright (C) 1996-2014 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"
602d9612 17#include "HttpHeader.h"
75cb38cb 18#include "HttpRequestMethod.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"
3ff65596
AR
24#if ICAP_CLIENT
25#include "adaptation/icap/Elements.h"
26#endif
cb4f4424 27#if USE_OPENSSL
f4698e0b
CT
28#include "ssl/gadgets.h"
29#endif
450e0c10 30
62ee09ca 31/* forward decls */
e1f7507e
AJ
32class HttpReply;
33class HttpRequest;
613924ee 34class CustomLog;
62ee09ca 35
41ebd397 36class AccessLogEntry: public RefCountable
450e0c10 37{
38
39public:
41ebd397
CT
40 typedef RefCount<AccessLogEntry> Pointer;
41
a14f38d0 42 AccessLogEntry() : url(NULL), tcpClient(), reply(NULL), request(NULL),
105d1937 43 adapted_request(NULL) {}
41ebd397 44 ~AccessLogEntry();
450e0c10 45
d4204018
AJ
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
450e0c10 51 const char *url;
52
a14f38d0
AJ
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
4e26d606
AJ
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 */
450e0c10 62 class HttpDetails
63 {
64
65 public:
c2a7cefd 66 HttpDetails() : method(Http::METHOD_NONE), code(0), content_type(NULL),
d6df21d2
AJ
67 timedout(false),
68 aborted(false),
cc0ca3b9
AJ
69 clientRequestSz(),
70 clientReplySz() {}
450e0c10 71
60745f24 72 HttpRequestMethod method;
450e0c10 73 int code;
74 const char *content_type;
526ed14e 75 Http::ProtocolVersion version;
f692498b
AJ
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 }
d6df21d2
AJ
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.
cc0ca3b9 87 MessageSizes clientRequestSz;
d6df21d2
AJ
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.
cc0ca3b9 92 MessageSizes clientReplySz;
d6df21d2 93
2fadd50d 94 } http;
450e0c10 95
4e26d606
AJ
96 /** \brief This subclass holds log info for ICP protocol
97 * \todo Inner class declarations should be moved outside
98 */
99 class IcpDetails
450e0c10 100 {
101
102 public:
4e26d606 103 IcpDetails() : opcode(ICP_INVALID) {}
450e0c10 104
105 icp_opcode opcode;
2fadd50d 106 } icp;
450e0c10 107
4e26d606
AJ
108 /** \brief This subclass holds log info for HTCP protocol
109 * \todo Inner class declarations should be moved outside
110 */
04f7fd38
AJ
111 class HtcpDetails
112 {
a8b1cdf6
AJ
113 public:
114 HtcpDetails() : opcode(NULL) {};
115
116 const char *opcode;
117 } htcp;
118
cb4f4424 119#if USE_OPENSSL
08097970 120 /// logging information specific to the SSL protocol
87f237a9
A
121 class SslDetails
122 {
08097970 123 public:
71cae389 124 SslDetails();
08097970
AR
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
4e26d606
AJ
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 */
450e0c10 136 class CacheDetails
137 {
138
139 public:
cc192b50 140 CacheDetails() : caddr(),
450e0c10 141 highOffset(0),
142 objectSize(0),
143 code (LOG_TAG_NONE),
144 msec(0),
145 rfc931 (NULL),
41ebd397 146 extuser(NULL),
cb4f4424 147#if USE_OPENSSL
41ebd397 148 ssluser(NULL),
450e0c10 149#endif
999aa5d2 150 port(NULL) {
d4806c91 151 caddr.setNoAddr();
450e0c10 152 }
153
b7ac5457 154 Ip::Address caddr;
47f6e231 155 int64_t highOffset;
156 int64_t objectSize;
02c8dde5 157 LogTags code;
af0ded40 158 struct timeval start_time; ///< The time the master transaction started
450e0c10 159 int msec;
160 const char *rfc931;
661ef4eb 161 const char *extuser;
cb4f4424 162#if USE_OPENSSL
450e0c10 163
164 const char *ssluser;
f4698e0b 165 Ssl::X509_Pointer sslClientCert; ///< cert received from the client
450e0c10 166#endif
fa720bfb 167 AnyP::PortCfgPointer port;
450e0c10 168
2fadd50d 169 } cache;
450e0c10 170
4e26d606
AJ
171 /** \brief This subclass holds log info for various headers in raw format
172 * \todo shuffle this to the relevant protocol section.
173 */
450e0c10 174 class Headers
175 {
176
177 public:
3ff65596 178 Headers() : request(NULL),
105d1937 179 adapted_request(NULL),
e1381638 180 reply(NULL) {}
450e0c10 181
6fca33e0
CT
182 char *request; //< virgin HTTP request headers
183
105d1937 184 char *adapted_request; //< HTTP request headers after adaptation and redirection
6fca33e0 185
99690f32
AR
186 char *reply;
187 } headers;
3ff65596 188
5038f9d8 189#if USE_ADAPTATION
99690f32
AR
190 /** \brief This subclass holds general adaptation log info.
191 * \todo Inner class declarations should be moved outside.
192 */
193 class AdaptationDetails
194 {
195
196 public:
197 AdaptationDetails(): last_meta(NULL) {}
5038f9d8 198
99690f32
AR
199 /// image of the last ICAP response header or eCAP meta received
200 char *last_meta;
201 } adapt;
3ff65596 202#endif
450e0c10 203
e1f7507e 204 // Why is this a sub-class and not a set of real "private:" fields?
7f06a3d8 205 // TODO: shuffle this to the relevant ICP/HTCP protocol section
450e0c10 206 class Private
207 {
208
209 public:
210 Private() : method_str(NULL) {}
211
212 const char *method_str;
2fadd50d 213 } _private;
450e0c10 214 HierarchyLogEntry hier;
215 HttpReply *reply;
105d1937 216 HttpRequest *request; //< virgin HTTP request
6fca33e0 217 HttpRequest *adapted_request; //< HTTP request after adaptation and redirection
d06e17ea 218
f4f55a21 219 /// key:value pairs set by squid.conf note directive and
cf9f0261 220 /// key=value pairs returned from URL rewrite/redirect helper
f4f55a21 221 NotePairs::Pointer notes;
6fca33e0 222
3ff65596
AR
223#if ICAP_CLIENT
224 /** \brief This subclass holds log info for ICAP part of request
225 * \todo Inner class declarations should be moved outside
226 */
e1381638
AJ
227 class IcapLogEntry
228 {
3ff65596 229 public:
f5d0906a 230 IcapLogEntry() : reqMethod(Adaptation::methodNone), bytesSent(0), bytesRead(0),
99c1b994
A
231 bodyBytesRead(-1), request(NULL), reply(NULL),
232 outcome(Adaptation::Icap::xoUnknown), trTime(0),
955394ce 233 ioTime(0), resStatus(Http::scNone), processingTime(0) {}
3ff65596 234
b7ac5457 235 Ip::Address hostAddr; ///< ICAP server IP address
3ff65596
AR
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
bae917ac 241 /**
dcaab393 242 * number of ICAP body bytes read from ICAP server or -1 for no encapsulated
bae917ac
CT
243 * message data in ICAP reply (eg 204 responses)
244 */
245 int64_t bodyBytesRead;
3ff65596
AR
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 int trTime;
255 /** \brief Transaction I/O time.
256 * The timer starts when the first ICAP request
e1381638 257 * byte is scheduled for sending and stops when the lastbyte of the
3ff65596
AR
258 * ICAP response is received.
259 */
260 int ioTime;
955394ce 261 Http::StatusCode resStatus; ///< ICAP response status code
3ff65596
AR
262 int processingTime; ///< total ICAP processing time in milliseconds
263 }
264 icap;
265#endif
450e0c10 266};
267
e1f7507e
AJ
268class ACLChecklist;
269class StoreEntry;
e1f7507e 270
450e0c10 271/* Should be in 'AccessLog.h' as the driver */
8a648e8d
FC
272void accessLogLogTo(CustomLog* log, AccessLogEntry::Pointer &al, ACLChecklist* checklist = NULL);
273void accessLogLog(AccessLogEntry::Pointer &, ACLChecklist * checklist);
274void accessLogRotate(void);
275void accessLogClose(void);
276void accessLogInit(void);
277const char *accessLogTime(time_t);
450e0c10 278
279#endif /* SQUID_HTTPACCESSLOGENTRY_H */