]> git.ipfire.org Git - thirdparty/squid.git/blob - src/AccessLogEntry.h
72dffd85d7651de956f942d7b8e4e675f98b456c
[thirdparty/squid.git] / src / AccessLogEntry.h
1 /*
2 * Copyright (C) 1996-2017 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_HTTPACCESSLOGENTRY_H
10 #define SQUID_HTTPACCESSLOGENTRY_H
11
12 #include "anyp/PortCfg.h"
13 #include "base/RefCount.h"
14 #include "comm/Connection.h"
15 #include "HierarchyLogEntry.h"
16 #include "http/ProtocolVersion.h"
17 #include "http/RequestMethod.h"
18 #include "HttpHeader.h"
19 #include "icp_opcode.h"
20 #include "ip/Address.h"
21 #include "LogTags.h"
22 #include "MessageSizes.h"
23 #include "Notes.h"
24 #include "sbuf/SBuf.h"
25 #if ICAP_CLIENT
26 #include "adaptation/icap/Elements.h"
27 #endif
28 #if USE_OPENSSL
29 #include "ssl/gadgets.h"
30 #include "ssl/support.h"
31 #endif
32
33 /* forward decls */
34 class HttpReply;
35 class HttpRequest;
36 class CustomLog;
37
38 class AccessLogEntry: public RefCountable
39 {
40
41 public:
42 typedef RefCount<AccessLogEntry> Pointer;
43
44 AccessLogEntry() {}
45 ~AccessLogEntry();
46
47 /// Fetch the client IP log string into the given buffer.
48 /// Knows about several alternate locations of the IP
49 /// including indirect forwarded-for IP if configured to log that
50 void getLogClientIp(char *buf, size_t bufsz) const;
51
52 /// Fetch the client IDENT string, or nil if none is available.
53 const char *getClientIdent() const;
54
55 /// Fetch the external ACL provided 'user=' string, or nil if none is available.
56 const char *getExtUser() const;
57
58 /// Fetch the transaction method string (ICP opcode, HTCP opcode or HTTP method)
59 SBuf getLogMethod() const;
60
61 void syncNotes(HttpRequest *request);
62
63 SBuf url;
64
65 /// TCP/IP level details about the client connection
66 Comm::ConnectionPointer tcpClient;
67 // TCP/IP level details about the server or peer connection
68 // are stored in hier.tcpServer
69
70 /** \brief This subclass holds log info for HTTP protocol
71 * \todo Inner class declarations should be moved outside
72 * \todo details of HTTP held in the parent class need moving into here.
73 */
74 class HttpDetails
75 {
76
77 public:
78 HttpRequestMethod method;
79 int code = 0;
80 const char *content_type = nullptr;
81 AnyP::ProtocolVersion version;
82
83 /// counters for the original request received from client
84 // TODO calculate header and payload better (by parser)
85 // XXX payload encoding overheads not calculated at all yet.
86 MessageSizes clientRequestSz;
87
88 /// counters for the response sent to client
89 // TODO calculate header and payload better (by parser)
90 // XXX payload encoding overheads not calculated at all yet.
91 MessageSizes clientReplySz;
92
93 } http;
94
95 /** \brief This subclass holds log info for ICP protocol
96 * \todo Inner class declarations should be moved outside
97 */
98 class IcpDetails
99 {
100 public:
101 icp_opcode opcode = ICP_INVALID;
102 } icp;
103
104 /** \brief This subclass holds log info for HTCP protocol
105 * \todo Inner class declarations should be moved outside
106 */
107 class HtcpDetails
108 {
109 public:
110 const char *opcode = nullptr;
111 } htcp;
112
113 #if USE_OPENSSL
114 /// logging information specific to the SSL protocol
115 class SslDetails
116 {
117 public:
118 const char *user = nullptr; ///< emailAddress from the SSL client certificate
119 int bumpMode = ::Ssl::bumpEnd; ///< whether and how the request was SslBumped
120 } ssl;
121 #endif
122
123 /** \brief This subclass holds log info for Squid internal stats
124 * \todo Inner class declarations should be moved outside
125 * \todo some details relevant to particular protocols need shuffling to other sub-classes
126 * \todo this object field need renaming to 'squid' or something.
127 */
128 class CacheDetails
129 {
130 public:
131 CacheDetails() {
132 caddr.setNoAddr();
133 memset(&start_time, 0, sizeof(start_time));
134 memset(&trTime, 0, sizeof(start_time));
135 }
136
137 Ip::Address caddr;
138 int64_t highOffset = 0;
139 int64_t objectSize = 0;
140 LogTags code = LOG_TAG_NONE;
141 struct timeval start_time; ///< The time the master transaction started
142 struct timeval trTime; ///< The response time
143 const char *rfc931 = nullptr;
144 const char *extuser = nullptr;
145 #if USE_OPENSSL
146 const char *ssluser = nullptr;
147 Security::CertPointer sslClientCert; ///< cert received from the client
148 #endif
149 AnyP::PortCfgPointer port;
150 } cache;
151
152 /** \brief This subclass holds log info for various headers in raw format
153 * \todo shuffle this to the relevant protocol section.
154 */
155 class Headers
156 {
157 public:
158 char *request = nullptr; //< virgin HTTP request headers
159 char *adapted_request = nullptr; //< HTTP request headers after adaptation and redirection
160 char *reply = nullptr;
161 } headers;
162
163 #if USE_ADAPTATION
164 /** \brief This subclass holds general adaptation log info.
165 * \todo Inner class declarations should be moved outside.
166 */
167 class AdaptationDetails
168 {
169 public:
170 /// image of the last ICAP response header or eCAP meta received
171 char *last_meta = nullptr;
172 } adapt;
173 #endif
174
175 const char *lastAclName = nullptr; ///< string for external_acl_type %ACL format code
176 SBuf lastAclData; ///< string for external_acl_type %DATA format code
177
178 HierarchyLogEntry hier;
179 HttpReply *reply = nullptr;
180 HttpRequest *request = nullptr; //< virgin HTTP request
181 HttpRequest *adapted_request = nullptr; //< HTTP request after adaptation and redirection
182
183 /// key:value pairs set by squid.conf note directive and
184 /// key=value pairs returned from URL rewrite/redirect helper
185 NotePairs::Pointer notes;
186
187 #if ICAP_CLIENT
188 /** \brief This subclass holds log info for ICAP part of request
189 * \todo Inner class declarations should be moved outside
190 */
191 class IcapLogEntry
192 {
193 public:
194 IcapLogEntry() {
195 memset(&trTime, 0, sizeof(trTime));
196 memset(&ioTime, 0, sizeof(ioTime));
197 memset(&processingTime, 0, sizeof(processingTime));
198 }
199
200 Ip::Address hostAddr; ///< ICAP server IP address
201 String serviceName; ///< ICAP service name
202 String reqUri; ///< ICAP Request-URI
203 Adaptation::Icap::ICAP::Method reqMethod = Adaptation::methodNone; ///< ICAP request method
204 int64_t bytesSent = 0; ///< number of bytes sent to ICAP server so far
205 int64_t bytesRead = 0; ///< number of bytes read from ICAP server so far
206 /**
207 * number of ICAP body bytes read from ICAP server or -1 for no encapsulated
208 * message data in ICAP reply (eg 204 responses)
209 */
210 int64_t bodyBytesRead = -1;
211 HttpRequest* request = nullptr; ///< ICAP request
212 HttpReply* reply = nullptr; ///< ICAP reply
213
214 Adaptation::Icap::XactOutcome outcome = Adaptation::Icap::xoUnknown; ///< final transaction status
215 /** \brief Transaction response time.
216 * The timer starts when the ICAP transaction
217 * is created and stops when the result of the transaction is logged
218 */
219 struct timeval trTime;
220 /** \brief Transaction I/O time.
221 * The timer starts when the first ICAP request
222 * byte is scheduled for sending and stops when the lastbyte of the
223 * ICAP response is received.
224 */
225 struct timeval ioTime;
226 Http::StatusCode resStatus = Http::scNone; ///< ICAP response status code
227 struct timeval processingTime; ///< total ICAP processing time
228 }
229 icap;
230 #endif
231 };
232
233 class ACLChecklist;
234 class StoreEntry;
235
236 /* Should be in 'AccessLog.h' as the driver */
237 void accessLogLogTo(CustomLog* log, AccessLogEntry::Pointer &al, ACLChecklist* checklist = NULL);
238 void accessLogLog(AccessLogEntry::Pointer &, ACLChecklist * checklist);
239 void accessLogRotate(void);
240 void accessLogClose(void);
241 void accessLogInit(void);
242 const char *accessLogTime(time_t);
243
244 #endif /* SQUID_HTTPACCESSLOGENTRY_H */
245