]> git.ipfire.org Git - thirdparty/squid.git/blob - src/AccessLogEntry.h
Merged from trunk (r12132, v3.2.0.17+)
[thirdparty/squid.git] / src / AccessLogEntry.h
1 /*
2 * SQUID Web Proxy Cache http://www.squid-cache.org/
3 * ----------------------------------------------------------
4 *
5 * Squid is the result of efforts by numerous individuals from
6 * the Internet community; see the CONTRIBUTORS file for full
7 * details. Many organizations have provided support for Squid's
8 * development; see the SPONSORS file for full details. Squid is
9 * Copyrighted (C) 2001 by the Regents of the University of
10 * California; see the COPYRIGHT file for full details. Squid
11 * incorporates software developed and/or copyrighted by other
12 * sources; see the CREDITS file for full details.
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
27 *
28 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
29 */
30 #ifndef SQUID_HTTPACCESSLOGENTRY_H
31 #define SQUID_HTTPACCESSLOGENTRY_H
32
33 #include "anyp/PortCfg.h"
34 #include "comm/Connection.h"
35 #include "HttpVersion.h"
36 #include "HttpRequestMethod.h"
37 #include "HierarchyLogEntry.h"
38 #include "ip/Address.h"
39 #include "HttpRequestMethod.h"
40 #if ICAP_CLIENT
41 #include "adaptation/icap/Elements.h"
42 #endif
43
44 /* forward decls */
45 class HttpReply;
46 class HttpRequest;
47
48 class AccessLogEntry
49 {
50
51 public:
52 AccessLogEntry() : url(NULL), tcpClient(), reply(NULL), request(NULL),
53 adapted_request(NULL) {}
54
55 /// Fetch the client IP log string into the given buffer.
56 /// Knows about several alternate locations of the IP
57 /// including indirect forwarded-for IP if configured to log that
58 void getLogClientIp(char *buf, size_t bufsz) const;
59
60 const char *url;
61
62 /// TCP/IP level details about the client connection
63 Comm::ConnectionPointer tcpClient;
64 // TCP/IP level details about the server or peer connection
65 // are stored in hier.tcpServer
66
67 /** \brief This subclass holds log info for HTTP protocol
68 * \todo Inner class declarations should be moved outside
69 * \todo details of HTTP held in the parent class need moving into here.
70 */
71 class HttpDetails
72 {
73
74 public:
75 HttpDetails() : method(METHOD_NONE), code(0), content_type(NULL),
76 timedout(false), aborted(false) {}
77
78 HttpRequestMethod method;
79 int code;
80 const char *content_type;
81 HttpVersion version;
82 bool timedout; ///< terminated due to a lifetime or I/O timeout
83 bool aborted; ///< other abnormal termination (e.g., I/O error)
84
85 /// compute suffix for the status access.log field
86 const char *statusSfx() const {
87 return timedout ? "_TIMEDOUT" : (aborted ? "_ABORTED" : "");
88 }
89 } http;
90
91 /** \brief This subclass holds log info for ICP protocol
92 * \todo Inner class declarations should be moved outside
93 */
94 class IcpDetails
95 {
96
97 public:
98 IcpDetails() : opcode(ICP_INVALID) {}
99
100 icp_opcode opcode;
101 } icp;
102
103 /** \brief This subclass holds log info for HTCP protocol
104 * \todo Inner class declarations should be moved outside
105 */
106 class HtcpDetails
107 {
108 public:
109 HtcpDetails() : opcode(NULL) {};
110
111 const char *opcode;
112 } htcp;
113
114 /** \brief This subclass holds log info for Squid internal stats
115 * \todo Inner class declarations should be moved outside
116 * \todo some details relevant to particular protocols need shuffling to other sub-classes
117 * \todo this object field need renaming to 'squid' or something.
118 */
119 class CacheDetails
120 {
121
122 public:
123 CacheDetails() : caddr(),
124 requestSize(0),
125 replySize(0),
126 requestHeadersSize(0),
127 replyHeadersSize(0),
128 highOffset(0),
129 objectSize(0),
130 code (LOG_TAG_NONE),
131 msec(0),
132 rfc931 (NULL),
133 authuser (NULL),
134 extuser(NULL)
135 #if USE_SSL
136 ,ssluser(NULL)
137 #endif
138 {;
139 }
140
141 Ip::Address caddr;
142 int64_t requestSize;
143 int64_t replySize;
144 int requestHeadersSize; ///< received, including request line
145 int replyHeadersSize; ///< sent, including status line
146 int64_t highOffset;
147 int64_t objectSize;
148 log_type code;
149 int msec;
150 const char *rfc931;
151 const char *authuser;
152 const char *extuser;
153 #if USE_SSL
154
155 const char *ssluser;
156 #endif
157 AnyP::PortCfg *port;
158
159 } cache;
160
161 /** \brief This subclass holds log info for various headers in raw format
162 * \todo shuffle this to the relevant protocol section.
163 */
164 class Headers
165 {
166
167 public:
168 Headers() : request(NULL),
169 adapted_request(NULL),
170 reply(NULL) {}
171
172 char *request; //< virgin HTTP request headers
173
174 char *adapted_request; //< HTTP request headers after adaptation and redirection
175
176 char *reply;
177 } headers;
178
179 #if USE_ADAPTATION
180 /** \brief This subclass holds general adaptation log info.
181 * \todo Inner class declarations should be moved outside.
182 */
183 class AdaptationDetails
184 {
185
186 public:
187 AdaptationDetails(): last_meta(NULL) {}
188
189 /// image of the last ICAP response header or eCAP meta received
190 char *last_meta;
191 } adapt;
192 #endif
193
194 // Why is this a sub-class and not a set of real "private:" fields?
195 // It looks like its duplicating HTTPRequestMethod anyway!
196 // TODO: shuffle this to the relevant protocol section OR replace with request->method
197 class Private
198 {
199
200 public:
201 Private() : method_str(NULL) {}
202
203 const char *method_str;
204 } _private;
205 HierarchyLogEntry hier;
206 HttpReply *reply;
207 HttpRequest *request; //< virgin HTTP request
208 HttpRequest *adapted_request; //< HTTP request after adaptation and redirection
209
210
211 #if ICAP_CLIENT
212 /** \brief This subclass holds log info for ICAP part of request
213 * \todo Inner class declarations should be moved outside
214 */
215 class IcapLogEntry
216 {
217 public:
218 IcapLogEntry():bodyBytesRead(-1),request(NULL),reply(NULL),outcome(Adaptation::Icap::xoUnknown),trTime(0),ioTime(0),resStatus(HTTP_STATUS_NONE) {}
219
220 Ip::Address hostAddr; ///< ICAP server IP address
221 String serviceName; ///< ICAP service name
222 String reqUri; ///< ICAP Request-URI
223 Adaptation::Icap::ICAP::Method reqMethod; ///< ICAP request method
224 int64_t bytesSent; ///< number of bytes sent to ICAP server so far
225 int64_t bytesRead; ///< number of bytes read from ICAP server so far
226 /**
227 * number of ICAP body bytes read from ICAP server or -1 for no encapsulated
228 * message data in ICAP reply (eg 204 responses)
229 */
230 int64_t bodyBytesRead;
231 HttpRequest* request; ///< ICAP request
232 HttpReply* reply; ///< ICAP reply
233
234 Adaptation::Icap::XactOutcome outcome; ///< final transaction status
235 /** \brief Transaction response time.
236 * The timer starts when the ICAP transaction
237 * is created and stops when the result of the transaction is logged
238 */
239 int trTime;
240 /** \brief Transaction I/O time.
241 * The timer starts when the first ICAP request
242 * byte is scheduled for sending and stops when the lastbyte of the
243 * ICAP response is received.
244 */
245 int ioTime;
246 http_status resStatus; ///< ICAP response status code
247 int processingTime; ///< total ICAP processing time in milliseconds
248 }
249 icap;
250 #endif
251 };
252
253 class ACLChecklist;
254 class StoreEntry;
255
256 /* Should be in 'AccessLog.h' as the driver */
257 extern void accessLogLogTo(customlog* log, AccessLogEntry* al, ACLChecklist* checklist = NULL);
258 extern void accessLogLog(AccessLogEntry *, ACLChecklist * checklist);
259 extern void accessLogRotate(void);
260 extern void accessLogClose(void);
261 extern void accessLogInit(void);
262 extern void accessLogFreeMemory(AccessLogEntry * aLogEntry);
263 extern const char *accessLogTime(time_t);
264
265 #endif /* SQUID_HTTPACCESSLOGENTRY_H */