]> git.ipfire.org Git - thirdparty/squid.git/blob - src/AccessLogEntry.h
Bug 5428: Warn if pkg-config is not found (#1902)
[thirdparty/squid.git] / src / AccessLogEntry.h
1 /*
2 * Copyright (C) 1996-2023 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_SRC_ACCESSLOGENTRY_H
10 #define SQUID_SRC_ACCESSLOGENTRY_H
11
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"
22 #include "LogTags.h"
23 #include "MessageSizes.h"
24 #include "Notes.h"
25 #include "proxyp/forward.h"
26 #include "sbuf/forward.h"
27 #if ICAP_CLIENT
28 #include "adaptation/icap/Elements.h"
29 #endif
30 #if USE_OPENSSL
31 #include "ssl/gadgets.h"
32 #include "ssl/support.h"
33 #endif
34
35 /* forward decls */
36 class HttpReply;
37 class HttpRequest;
38 class CustomLog;
39
40 class AccessLogEntry: public CodeContext
41 {
42
43 public:
44 typedef RefCount<AccessLogEntry> Pointer;
45
46 AccessLogEntry();
47 ~AccessLogEntry() override;
48
49 /* CodeContext API */
50 std::ostream &detailCodeContext(std::ostream &os) const override;
51 ScopedId codeContextGist() const override;
52
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;
57
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;
62
63 /// Fetch the external ACL provided 'user=' string, or nil if none is available.
64 const char *getExtUser() const;
65
66 /// whether we know what the request method is
67 bool hasLogMethod() const { return icp.opcode || htcp.opcode || http.method; }
68
69 /// Fetch the transaction method string (ICP opcode, HTCP opcode or HTTP method)
70 SBuf getLogMethod() const;
71
72 void syncNotes(HttpRequest *request);
73
74 /// dump all reply headers (for sending or risky logging)
75 void packReplyHeaders(MemBuf &mb) const;
76
77 SBuf url;
78
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
83
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.
87 */
88 class HttpDetails
89 {
90
91 public:
92 HttpRequestMethod method;
93 int code = 0;
94 const char *content_type = nullptr;
95 AnyP::ProtocolVersion version;
96
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;
101
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;
106
107 } http;
108
109 /** \brief This subclass holds log info for ICP protocol
110 * TODO: Inner class declarations should be moved outside
111 */
112 class IcpDetails
113 {
114 public:
115 icp_opcode opcode = ICP_INVALID;
116 } icp;
117
118 /** \brief This subclass holds log info for HTCP protocol
119 * TODO: Inner class declarations should be moved outside
120 */
121 class HtcpDetails
122 {
123 public:
124 const char *opcode = nullptr;
125 } htcp;
126
127 #if USE_OPENSSL
128 /// logging information specific to the SSL protocol
129 class SslDetails
130 {
131 public:
132 const char *user = nullptr; ///< emailAddress from the SSL client certificate
133 int bumpMode = ::Ssl::bumpEnd; ///< whether and how the request was SslBumped
134 } ssl;
135 #endif
136
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.
141 */
142 class CacheDetails
143 {
144 public:
145 CacheDetails() {
146 caddr.setNoAddr();
147 memset(&start_time, 0, sizeof(start_time));
148 memset(&trTime, 0, sizeof(start_time));
149 }
150
151 Ip::Address caddr;
152 int64_t highOffset = 0;
153 int64_t objectSize = 0;
154 LogTags code;
155 struct timeval start_time; ///< The time the master transaction started
156 struct timeval trTime; ///< The response time
157 const char *extuser = nullptr;
158 #if USE_OPENSSL
159 const char *ssluser = nullptr;
160 Security::CertPointer sslClientCert; ///< cert received from the client
161 #endif
162 AnyP::PortCfgPointer port;
163 } cache;
164
165 /** \brief This subclass holds log info for various headers in raw format
166 * TODO: shuffle this to the relevant protocol section.
167 */
168 class Headers
169 {
170 public:
171 char *request = nullptr; //< virgin HTTP request headers
172 char *adapted_request = nullptr; //< HTTP request headers after adaptation and redirection
173 } headers;
174
175 #if USE_ADAPTATION
176 /** \brief This subclass holds general adaptation log info.
177 * TODO: Inner class declarations should be moved outside.
178 */
179 class AdaptationDetails
180 {
181 public:
182 /// image of the last ICAP response header or eCAP meta received
183 char *last_meta = nullptr;
184 } adapt;
185 #endif
186
187 SBuf lastAclName; ///< string for external_acl_type %ACL format code
188 SBuf lastAclData; ///< string for external_acl_type %DATA format code
189
190 HierarchyLogEntry hier;
191 HttpReplyPointer reply;
192 HttpRequest *request = nullptr; //< virgin HTTP request
193 HttpRequest *adapted_request = nullptr; //< HTTP request after adaptation and redirection
194
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;
198
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;
204
205 /// see ConnStateData::proxyProtocolHeader_
206 ProxyProtocol::HeaderPointer proxyProtocolHeader;
207
208 #if ICAP_CLIENT
209 /** \brief This subclass holds log info for ICAP part of request
210 * TODO: Inner class declarations should be moved outside
211 */
212 class IcapLogEntry
213 {
214 public:
215 IcapLogEntry() {
216 memset(&trTime, 0, sizeof(trTime));
217 memset(&ioTime, 0, sizeof(ioTime));
218 memset(&processingTime, 0, sizeof(processingTime));
219 }
220
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
227 /**
228 * number of ICAP body bytes read from ICAP server or -1 for no encapsulated
229 * message data in ICAP reply (eg 204 responses)
230 */
231 int64_t bodyBytesRead = -1;
232 HttpRequest* request = nullptr; ///< ICAP request
233 HttpReply* reply = nullptr; ///< ICAP reply
234
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
239 */
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.
245 */
246 struct timeval ioTime;
247 Http::StatusCode resStatus = Http::scNone; ///< ICAP response status code
248 struct timeval processingTime; ///< total ICAP processing time
249 }
250 icap;
251 #endif
252
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;
258
259 /// Remember Client URI (or equivalent) when there is no HttpRequest.
260 void setVirginUrlForMissingRequest(const SBuf &vu)
261 {
262 if (!request)
263 virginUrlForMissingRequest_ = vu;
264 }
265
266 /// \returns stored transaction error information (or nil)
267 const Error *error() const;
268
269 /// sets (or updates the already stored) transaction error as needed
270 void updateError(const Error &);
271
272 private:
273 /// transaction problem
274 /// if set, overrides (and should eventually replace) request->error
275 Error error_;
276
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_;
280 };
281
282 class ACLChecklist;
283 class StoreEntry;
284
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);
292
293 #endif /* SQUID_SRC_ACCESSLOGENTRY_H */
294