]>
Commit | Line | Data |
---|---|---|
450e0c10 | 1 | /* |
77b1029d | 2 | * Copyright (C) 1996-2020 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" |
ccfbe8f4 | 13 | #include "base/CodeContext.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" |
36c774f7 | 24 | #include "proxyp/forward.h" |
f57ae909 | 25 | #include "sbuf/SBuf.h" |
3ff65596 AR |
26 | #if ICAP_CLIENT |
27 | #include "adaptation/icap/Elements.h" | |
28 | #endif | |
cb4f4424 | 29 | #if USE_OPENSSL |
f4698e0b | 30 | #include "ssl/gadgets.h" |
78a4bf03 | 31 | #include "ssl/support.h" |
f4698e0b | 32 | #endif |
450e0c10 | 33 | |
62ee09ca | 34 | /* forward decls */ |
e1f7507e AJ |
35 | class HttpReply; |
36 | class HttpRequest; | |
613924ee | 37 | class CustomLog; |
62ee09ca | 38 | |
ccfbe8f4 | 39 | class AccessLogEntry: public CodeContext |
450e0c10 | 40 | { |
41 | ||
42 | public: | |
41ebd397 CT |
43 | typedef RefCount<AccessLogEntry> Pointer; |
44 | ||
36c774f7 | 45 | AccessLogEntry(); |
ccfbe8f4 AR |
46 | virtual ~AccessLogEntry(); |
47 | ||
48 | /* CodeContext API */ | |
49 | virtual std::ostream &detailCodeContext(std::ostream &os) const override; | |
50 | virtual ScopedId codeContextGist() const override; | |
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 | ||
e3bf07f5 AJ |
57 | /// Fetch the client IDENT string, or nil if none is available. |
58 | const char *getClientIdent() const; | |
59 | ||
60 | /// Fetch the external ACL provided 'user=' string, or nil if none is available. | |
61 | const char *getExtUser() const; | |
62 | ||
ec2c4acf AR |
63 | /// whether we know what the request method is |
64 | bool hasLogMethod() const { return icp.opcode || htcp.opcode || http.method; } | |
65 | ||
58b148e1 AJ |
66 | /// Fetch the transaction method string (ICP opcode, HTCP opcode or HTTP method) |
67 | SBuf getLogMethod() const; | |
68 | ||
75d47340 CT |
69 | void syncNotes(HttpRequest *request); |
70 | ||
49f57088 EB |
71 | /// dump all reply headers (for sending or risky logging) |
72 | void packReplyHeaders(MemBuf &mb) const; | |
73 | ||
f57ae909 | 74 | SBuf url; |
450e0c10 | 75 | |
a14f38d0 AJ |
76 | /// TCP/IP level details about the client connection |
77 | Comm::ConnectionPointer tcpClient; | |
78 | // TCP/IP level details about the server or peer connection | |
79 | // are stored in hier.tcpServer | |
80 | ||
4e26d606 | 81 | /** \brief This subclass holds log info for HTTP protocol |
9837567d AJ |
82 | * TODO: Inner class declarations should be moved outside |
83 | * TODO: details of HTTP held in the parent class need moving into here. | |
4e26d606 | 84 | */ |
450e0c10 | 85 | class HttpDetails |
86 | { | |
87 | ||
88 | public: | |
60745f24 | 89 | HttpRequestMethod method; |
78a4bf03 AJ |
90 | int code = 0; |
91 | const char *content_type = nullptr; | |
2592bc70 | 92 | AnyP::ProtocolVersion version; |
d6df21d2 AJ |
93 | |
94 | /// counters for the original request received from client | |
95 | // TODO calculate header and payload better (by parser) | |
96 | // XXX payload encoding overheads not calculated at all yet. | |
cc0ca3b9 | 97 | MessageSizes clientRequestSz; |
d6df21d2 AJ |
98 | |
99 | /// counters for the response sent to client | |
100 | // TODO calculate header and payload better (by parser) | |
101 | // XXX payload encoding overheads not calculated at all yet. | |
cc0ca3b9 | 102 | MessageSizes clientReplySz; |
d6df21d2 | 103 | |
2fadd50d | 104 | } http; |
450e0c10 | 105 | |
4e26d606 | 106 | /** \brief This subclass holds log info for ICP protocol |
9837567d | 107 | * TODO: Inner class declarations should be moved outside |
4e26d606 AJ |
108 | */ |
109 | class IcpDetails | |
450e0c10 | 110 | { |
450e0c10 | 111 | public: |
78a4bf03 | 112 | icp_opcode opcode = ICP_INVALID; |
2fadd50d | 113 | } icp; |
450e0c10 | 114 | |
4e26d606 | 115 | /** \brief This subclass holds log info for HTCP protocol |
9837567d | 116 | * TODO: Inner class declarations should be moved outside |
4e26d606 | 117 | */ |
04f7fd38 AJ |
118 | class HtcpDetails |
119 | { | |
a8b1cdf6 | 120 | public: |
78a4bf03 | 121 | const char *opcode = nullptr; |
a8b1cdf6 AJ |
122 | } htcp; |
123 | ||
cb4f4424 | 124 | #if USE_OPENSSL |
08097970 | 125 | /// logging information specific to the SSL protocol |
87f237a9 A |
126 | class SslDetails |
127 | { | |
08097970 | 128 | public: |
78a4bf03 AJ |
129 | const char *user = nullptr; ///< emailAddress from the SSL client certificate |
130 | int bumpMode = ::Ssl::bumpEnd; ///< whether and how the request was SslBumped | |
08097970 AR |
131 | } ssl; |
132 | #endif | |
133 | ||
4e26d606 | 134 | /** \brief This subclass holds log info for Squid internal stats |
9837567d AJ |
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. | |
4e26d606 | 138 | */ |
450e0c10 | 139 | class CacheDetails |
140 | { | |
450e0c10 | 141 | public: |
78a4bf03 | 142 | CacheDetails() { |
d4806c91 | 143 | caddr.setNoAddr(); |
4579a6d0 | 144 | memset(&start_time, 0, sizeof(start_time)); |
01bd87d8 | 145 | memset(&trTime, 0, sizeof(start_time)); |
450e0c10 | 146 | } |
147 | ||
b7ac5457 | 148 | Ip::Address caddr; |
78a4bf03 AJ |
149 | int64_t highOffset = 0; |
150 | int64_t objectSize = 0; | |
d2a6dcba | 151 | LogTags code; |
af0ded40 | 152 | struct timeval start_time; ///< The time the master transaction started |
01bd87d8 | 153 | struct timeval trTime; ///< The response time |
78a4bf03 AJ |
154 | const char *rfc931 = nullptr; |
155 | const char *extuser = nullptr; | |
cb4f4424 | 156 | #if USE_OPENSSL |
78a4bf03 | 157 | const char *ssluser = nullptr; |
f97700a0 | 158 | Security::CertPointer sslClientCert; ///< cert received from the client |
450e0c10 | 159 | #endif |
fa720bfb | 160 | AnyP::PortCfgPointer port; |
2fadd50d | 161 | } cache; |
450e0c10 | 162 | |
4e26d606 | 163 | /** \brief This subclass holds log info for various headers in raw format |
9837567d | 164 | * TODO: shuffle this to the relevant protocol section. |
4e26d606 | 165 | */ |
450e0c10 | 166 | class Headers |
167 | { | |
450e0c10 | 168 | public: |
78a4bf03 AJ |
169 | char *request = nullptr; //< virgin HTTP request headers |
170 | char *adapted_request = nullptr; //< HTTP request headers after adaptation and redirection | |
99690f32 | 171 | } headers; |
3ff65596 | 172 | |
5038f9d8 | 173 | #if USE_ADAPTATION |
99690f32 | 174 | /** \brief This subclass holds general adaptation log info. |
9837567d | 175 | * TODO: Inner class declarations should be moved outside. |
99690f32 AR |
176 | */ |
177 | class AdaptationDetails | |
178 | { | |
99690f32 | 179 | public: |
99690f32 | 180 | /// image of the last ICAP response header or eCAP meta received |
78a4bf03 | 181 | char *last_meta = nullptr; |
99690f32 | 182 | } adapt; |
3ff65596 | 183 | #endif |
450e0c10 | 184 | |
78a4bf03 | 185 | const char *lastAclName = nullptr; ///< string for external_acl_type %ACL format code |
b0e14ce2 | 186 | SBuf lastAclData; ///< string for external_acl_type %DATA format code |
4ff6370b | 187 | |
450e0c10 | 188 | HierarchyLogEntry hier; |
49f57088 | 189 | HttpReplyPointer reply; |
78a4bf03 AJ |
190 | HttpRequest *request = nullptr; //< virgin HTTP request |
191 | HttpRequest *adapted_request = nullptr; //< HTTP request after adaptation and redirection | |
d06e17ea | 192 | |
f4f55a21 | 193 | /// key:value pairs set by squid.conf note directive and |
cf9f0261 | 194 | /// key=value pairs returned from URL rewrite/redirect helper |
f4f55a21 | 195 | NotePairs::Pointer notes; |
6fca33e0 | 196 | |
36c774f7 EB |
197 | /// see ConnStateData::proxyProtocolHeader_ |
198 | ProxyProtocol::HeaderPointer proxyProtocolHeader; | |
199 | ||
3ff65596 AR |
200 | #if ICAP_CLIENT |
201 | /** \brief This subclass holds log info for ICAP part of request | |
9837567d | 202 | * TODO: Inner class declarations should be moved outside |
3ff65596 | 203 | */ |
e1381638 AJ |
204 | class IcapLogEntry |
205 | { | |
3ff65596 | 206 | public: |
78a4bf03 | 207 | IcapLogEntry() { |
01bd87d8 CT |
208 | memset(&trTime, 0, sizeof(trTime)); |
209 | memset(&ioTime, 0, sizeof(ioTime)); | |
210 | memset(&processingTime, 0, sizeof(processingTime)); | |
211 | } | |
3ff65596 | 212 | |
b7ac5457 | 213 | Ip::Address hostAddr; ///< ICAP server IP address |
3ff65596 AR |
214 | String serviceName; ///< ICAP service name |
215 | String reqUri; ///< ICAP Request-URI | |
78a4bf03 AJ |
216 | Adaptation::Icap::ICAP::Method reqMethod = Adaptation::methodNone; ///< ICAP request method |
217 | int64_t bytesSent = 0; ///< number of bytes sent to ICAP server so far | |
218 | int64_t bytesRead = 0; ///< number of bytes read from ICAP server so far | |
bae917ac | 219 | /** |
dcaab393 | 220 | * number of ICAP body bytes read from ICAP server or -1 for no encapsulated |
bae917ac CT |
221 | * message data in ICAP reply (eg 204 responses) |
222 | */ | |
78a4bf03 AJ |
223 | int64_t bodyBytesRead = -1; |
224 | HttpRequest* request = nullptr; ///< ICAP request | |
225 | HttpReply* reply = nullptr; ///< ICAP reply | |
3ff65596 | 226 | |
78a4bf03 | 227 | Adaptation::Icap::XactOutcome outcome = Adaptation::Icap::xoUnknown; ///< final transaction status |
3ff65596 AR |
228 | /** \brief Transaction response time. |
229 | * The timer starts when the ICAP transaction | |
230 | * is created and stops when the result of the transaction is logged | |
231 | */ | |
01bd87d8 | 232 | struct timeval trTime; |
3ff65596 AR |
233 | /** \brief Transaction I/O time. |
234 | * The timer starts when the first ICAP request | |
e1381638 | 235 | * byte is scheduled for sending and stops when the lastbyte of the |
3ff65596 AR |
236 | * ICAP response is received. |
237 | */ | |
01bd87d8 | 238 | struct timeval ioTime; |
78a4bf03 | 239 | Http::StatusCode resStatus = Http::scNone; ///< ICAP response status code |
01bd87d8 | 240 | struct timeval processingTime; ///< total ICAP processing time |
3ff65596 AR |
241 | } |
242 | icap; | |
243 | #endif | |
bec110e4 EB |
244 | |
245 | /// Effective URI of the received client (or equivalent) HTTP request or, | |
246 | /// in rare cases where that information was not collected, a nil pointer. | |
247 | /// Receiving errors are represented by "error:..." URIs. | |
248 | /// Adaptations and redirections do not affect this URI. | |
249 | const SBuf *effectiveVirginUrl() const; | |
250 | ||
251 | /// Remember Client URI (or equivalent) when there is no HttpRequest. | |
252 | void setVirginUrlForMissingRequest(const SBuf &vu) | |
253 | { | |
254 | if (!request) | |
255 | virginUrlForMissingRequest_ = vu; | |
256 | } | |
257 | ||
258 | private: | |
259 | /// Client URI (or equivalent) for effectiveVirginUrl() when HttpRequest is | |
260 | /// missing. This member is ignored unless the request member is nil. | |
261 | SBuf virginUrlForMissingRequest_; | |
450e0c10 | 262 | }; |
263 | ||
e1f7507e AJ |
264 | class ACLChecklist; |
265 | class StoreEntry; | |
e1f7507e | 266 | |
450e0c10 | 267 | /* Should be in 'AccessLog.h' as the driver */ |
8a648e8d FC |
268 | void accessLogLogTo(CustomLog* log, AccessLogEntry::Pointer &al, ACLChecklist* checklist = NULL); |
269 | void accessLogLog(AccessLogEntry::Pointer &, ACLChecklist * checklist); | |
270 | void accessLogRotate(void); | |
271 | void accessLogClose(void); | |
272 | void accessLogInit(void); | |
273 | const char *accessLogTime(time_t); | |
450e0c10 | 274 | |
275 | #endif /* SQUID_HTTPACCESSLOGENTRY_H */ | |
f53969cc | 276 |