2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_SRC_ACCESSLOGENTRY_H
10 #define SQUID_SRC_ACCESSLOGENTRY_H
12 #include "anyp/PortCfg.h"
13 #include "base/CodeContext.h"
14 #include "comm/Connection.h"
15 #include "error/Error.h"
16 #include "HierarchyLogEntry.h"
17 #include "http/ProtocolVersion.h"
18 #include "http/RequestMethod.h"
19 #include "HttpHeader.h"
20 #include "icp_opcode.h"
21 #include "ip/Address.h"
23 #include "MessageSizes.h"
25 #include "proxyp/forward.h"
26 #include "sbuf/forward.h"
28 #include "adaptation/icap/Elements.h"
31 #include "ssl/gadgets.h"
32 #include "ssl/support.h"
40 class AccessLogEntry
: public CodeContext
44 typedef RefCount
<AccessLogEntry
> Pointer
;
47 ~AccessLogEntry() override
;
50 std::ostream
&detailCodeContext(std::ostream
&os
) const override
;
51 ScopedId
codeContextGist() const override
;
53 /// Fetch the client IP log string into the given buffer.
54 /// Knows about several alternate locations of the IP
55 /// including indirect forwarded-for IP if configured to log that
56 void getLogClientIp(char *buf
, size_t bufsz
) const;
58 /// %>A: Compute client FQDN if possible, using the supplied buf if needed.
59 /// \returns result for immediate logging (not necessarily pointing to buf)
60 /// Side effect: Enables reverse DNS lookups of future client addresses.
61 const char *getLogClientFqdn(char *buf
, size_t bufSize
) const;
63 /// Fetch the external ACL provided 'user=' string, or nil if none is available.
64 const char *getExtUser() const;
66 /// whether we know what the request method is
67 bool hasLogMethod() const { return icp
.opcode
|| htcp
.opcode
|| http
.method
; }
69 /// Fetch the transaction method string (ICP opcode, HTCP opcode or HTTP method)
70 SBuf
getLogMethod() const;
72 void syncNotes(HttpRequest
*request
);
74 /// dump all reply headers (for sending or risky logging)
75 void packReplyHeaders(MemBuf
&mb
) const;
79 /// TCP/IP level details about the client connection
80 Comm::ConnectionPointer tcpClient
;
81 // TCP/IP level details about the server or peer connection
82 // are stored in hier.tcpServer
84 /** \brief This subclass holds log info for HTTP protocol
85 * TODO: Inner class declarations should be moved outside
86 * TODO: details of HTTP held in the parent class need moving into here.
92 HttpRequestMethod method
;
94 const char *content_type
= nullptr;
95 AnyP::ProtocolVersion version
;
97 /// counters for the original request received from client
98 // TODO calculate header and payload better (by parser)
99 // XXX payload encoding overheads not calculated at all yet.
100 MessageSizes clientRequestSz
;
102 /// counters for the response sent to client
103 // TODO calculate header and payload better (by parser)
104 // XXX payload encoding overheads not calculated at all yet.
105 MessageSizes clientReplySz
;
109 /** \brief This subclass holds log info for ICP protocol
110 * TODO: Inner class declarations should be moved outside
115 icp_opcode opcode
= ICP_INVALID
;
118 /** \brief This subclass holds log info for HTCP protocol
119 * TODO: Inner class declarations should be moved outside
124 const char *opcode
= nullptr;
128 /// logging information specific to the SSL protocol
132 const char *user
= nullptr; ///< emailAddress from the SSL client certificate
133 int bumpMode
= ::Ssl::bumpEnd
; ///< whether and how the request was SslBumped
137 /** \brief This subclass holds log info for Squid internal stats
138 * TODO: Inner class declarations should be moved outside
139 * TODO: some details relevant to particular protocols need shuffling to other sub-classes
140 * TODO: this object field need renaming to 'squid' or something.
147 memset(&start_time
, 0, sizeof(start_time
));
148 memset(&trTime
, 0, sizeof(start_time
));
152 int64_t highOffset
= 0;
153 int64_t objectSize
= 0;
155 struct timeval start_time
; ///< The time the master transaction started
156 struct timeval trTime
; ///< The response time
157 const char *extuser
= nullptr;
159 const char *ssluser
= nullptr;
160 Security::CertPointer sslClientCert
; ///< cert received from the client
162 AnyP::PortCfgPointer port
;
165 /** \brief This subclass holds log info for various headers in raw format
166 * TODO: shuffle this to the relevant protocol section.
171 char *request
= nullptr; //< virgin HTTP request headers
172 char *adapted_request
= nullptr; //< HTTP request headers after adaptation and redirection
176 /** \brief This subclass holds general adaptation log info.
177 * TODO: Inner class declarations should be moved outside.
179 class AdaptationDetails
182 /// image of the last ICAP response header or eCAP meta received
183 char *last_meta
= nullptr;
187 SBuf lastAclName
; ///< string for external_acl_type %ACL format code
188 SBuf lastAclData
; ///< string for external_acl_type %DATA format code
190 HierarchyLogEntry hier
;
191 HttpReplyPointer reply
;
192 HttpRequest
*request
= nullptr; //< virgin HTTP request
193 HttpRequest
*adapted_request
= nullptr; //< HTTP request after adaptation and redirection
195 /// key:value pairs set by squid.conf note directive and
196 /// key=value pairs returned from URL rewrite/redirect helper
197 NotePairs::Pointer notes
;
199 /// The total number of finished attempts to establish a connection.
200 /// Excludes discarded HappyConnOpener attempts. Includes failed
201 /// HappyConnOpener attempts and [always successful] persistent connection
202 /// reuse. See %request_attempts.
203 int requestAttempts
= 0;
205 /// see ConnStateData::proxyProtocolHeader_
206 ProxyProtocol::HeaderPointer proxyProtocolHeader
;
209 /** \brief This subclass holds log info for ICAP part of request
210 * TODO: Inner class declarations should be moved outside
216 memset(&trTime
, 0, sizeof(trTime
));
217 memset(&ioTime
, 0, sizeof(ioTime
));
218 memset(&processingTime
, 0, sizeof(processingTime
));
221 Ip::Address hostAddr
; ///< ICAP server IP address
222 String serviceName
; ///< ICAP service name
223 String reqUri
; ///< ICAP Request-URI
224 Adaptation::Icap::ICAP::Method reqMethod
= Adaptation::methodNone
; ///< ICAP request method
225 int64_t bytesSent
= 0; ///< number of bytes sent to ICAP server so far
226 int64_t bytesRead
= 0; ///< number of bytes read from ICAP server so far
228 * number of ICAP body bytes read from ICAP server or -1 for no encapsulated
229 * message data in ICAP reply (eg 204 responses)
231 int64_t bodyBytesRead
= -1;
232 HttpRequest
* request
= nullptr; ///< ICAP request
233 HttpReply
* reply
= nullptr; ///< ICAP reply
235 Adaptation::Icap::XactOutcome outcome
= Adaptation::Icap::xoUnknown
; ///< final transaction status
236 /** \brief Transaction response time.
237 * The timer starts when the ICAP transaction
238 * is created and stops when the result of the transaction is logged
240 struct timeval trTime
;
241 /** \brief Transaction I/O time.
242 * The timer starts when the first ICAP request
243 * byte is scheduled for sending and stops when the lastbyte of the
244 * ICAP response is received.
246 struct timeval ioTime
;
247 Http::StatusCode resStatus
= Http::scNone
; ///< ICAP response status code
248 struct timeval processingTime
; ///< total ICAP processing time
253 /// Effective URI of the received client (or equivalent) HTTP request or,
254 /// in rare cases where that information was not collected, a nil pointer.
255 /// Receiving errors are represented by "error:..." URIs.
256 /// Adaptations and redirections do not affect this URI.
257 const SBuf
*effectiveVirginUrl() const;
259 /// Remember Client URI (or equivalent) when there is no HttpRequest.
260 void setVirginUrlForMissingRequest(const SBuf
&vu
)
263 virginUrlForMissingRequest_
= vu
;
266 /// \returns stored transaction error information (or nil)
267 const Error
*error() const;
269 /// sets (or updates the already stored) transaction error as needed
270 void updateError(const Error
&);
273 /// transaction problem
274 /// if set, overrides (and should eventually replace) request->error
277 /// Client URI (or equivalent) for effectiveVirginUrl() when HttpRequest is
278 /// missing. This member is ignored unless the request member is nil.
279 SBuf virginUrlForMissingRequest_
;
285 /* Should be in 'AccessLog.h' as the driver */
286 void accessLogLogTo(CustomLog
*, const AccessLogEntryPointer
&, ACLChecklist
*checklist
= nullptr);
287 void accessLogLog(const AccessLogEntryPointer
&, ACLChecklist
*);
288 void accessLogRotate(void);
289 void accessLogClose(void);
290 void accessLogInit(void);
291 const char *accessLogTime(time_t);
293 #endif /* SQUID_SRC_ACCESSLOGENTRY_H */