2 * Copyright (C) 1996-2017 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_HTTPACCESSLOGENTRY_H
10 #define SQUID_HTTPACCESSLOGENTRY_H
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"
22 #include "MessageSizes.h"
24 #include "sbuf/SBuf.h"
26 #include "adaptation/icap/Elements.h"
29 #include "ssl/gadgets.h"
30 #include "ssl/support.h"
38 class AccessLogEntry
: public RefCountable
42 typedef RefCount
<AccessLogEntry
> Pointer
;
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;
52 /// Fetch the client IDENT string, or nil if none is available.
53 const char *getClientIdent() const;
55 /// Fetch the external ACL provided 'user=' string, or nil if none is available.
56 const char *getExtUser() const;
58 /// Fetch the transaction method string (ICP opcode, HTCP opcode or HTTP method)
59 SBuf
getLogMethod() const;
61 void syncNotes(HttpRequest
*request
);
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
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.
78 HttpRequestMethod method
;
80 const char *content_type
= nullptr;
81 AnyP::ProtocolVersion version
;
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
;
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
;
95 /** \brief This subclass holds log info for ICP protocol
96 * \todo Inner class declarations should be moved outside
101 icp_opcode opcode
= ICP_INVALID
;
104 /** \brief This subclass holds log info for HTCP protocol
105 * \todo Inner class declarations should be moved outside
110 const char *opcode
= nullptr;
114 /// logging information specific to the SSL protocol
118 const char *user
= nullptr; ///< emailAddress from the SSL client certificate
119 int bumpMode
= ::Ssl::bumpEnd
; ///< whether and how the request was SslBumped
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.
133 memset(&start_time
, 0, sizeof(start_time
));
134 memset(&trTime
, 0, sizeof(start_time
));
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;
146 const char *ssluser
= nullptr;
147 Security::CertPointer sslClientCert
; ///< cert received from the client
149 AnyP::PortCfgPointer port
;
152 /** \brief This subclass holds log info for various headers in raw format
153 * \todo shuffle this to the relevant protocol section.
158 char *request
= nullptr; //< virgin HTTP request headers
159 char *adapted_request
= nullptr; //< HTTP request headers after adaptation and redirection
160 char *reply
= nullptr;
164 /** \brief This subclass holds general adaptation log info.
165 * \todo Inner class declarations should be moved outside.
167 class AdaptationDetails
170 /// image of the last ICAP response header or eCAP meta received
171 char *last_meta
= nullptr;
175 const char *lastAclName
= nullptr; ///< string for external_acl_type %ACL format code
176 SBuf lastAclData
; ///< string for external_acl_type %DATA format code
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
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
;
188 /** \brief This subclass holds log info for ICAP part of request
189 * \todo Inner class declarations should be moved outside
195 memset(&trTime
, 0, sizeof(trTime
));
196 memset(&ioTime
, 0, sizeof(ioTime
));
197 memset(&processingTime
, 0, sizeof(processingTime
));
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
207 * number of ICAP body bytes read from ICAP server or -1 for no encapsulated
208 * message data in ICAP reply (eg 204 responses)
210 int64_t bodyBytesRead
= -1;
211 HttpRequest
* request
= nullptr; ///< ICAP request
212 HttpReply
* reply
= nullptr; ///< ICAP reply
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
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.
225 struct timeval ioTime
;
226 Http::StatusCode resStatus
= Http::scNone
; ///< ICAP response status code
227 struct timeval processingTime
; ///< total ICAP processing time
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);
244 #endif /* SQUID_HTTPACCESSLOGENTRY_H */