2 * Copyright (C) 1996-2019 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.
10 #include "AccessLogEntry.h"
11 #include "HttpReply.h"
12 #include "HttpRequest.h"
14 #include "proxyp/Header.h"
15 #include "SquidConfig.h"
16 #include "ssl/support.h"
19 AccessLogEntry::getLogClientIp(char *buf
, size_t bufsz
) const
23 #if FOLLOW_X_FORWARDED_FOR
24 if (Config
.onoff
.log_uses_indirect_client
&& request
)
25 log_ip
= request
->indirect_client_addr
;
29 log_ip
= tcpClient
->remote
;
33 // internally generated requests (and some ICAP) lack client IP
34 if (log_ip
.isNoAddr()) {
35 strncpy(buf
, "-", bufsz
);
39 // Apply so-called 'privacy masking' to IPv4 clients
40 // - localhost IP is always shown in full
41 // - IPv4 clients masked with client_netmask
42 // - IPv6 clients use 'privacy addressing' instead.
44 log_ip
.applyClientMask(Config
.Addrs
.client_netmask
);
46 log_ip
.toStr(buf
, bufsz
);
50 AccessLogEntry::getLogMethod() const
54 method
.append(icp_opcode_str
[icp
.opcode
]);
56 method
.append(htcp
.opcode
);
58 method
= http
.method
.image();
63 AccessLogEntry::syncNotes(HttpRequest
*req
)
65 // XXX: auth code only has access to HttpRequest being authenticated
66 // so we must handle the case where HttpRequest is set without ALE being set.
71 assert(notes
== req
->notes());
75 AccessLogEntry::getClientIdent() const
78 return tcpClient
->rfc931
;
80 if (cache
.rfc931
&& *cache
.rfc931
)
87 AccessLogEntry::getExtUser() const
89 if (request
&& request
->extacl_user
.size())
90 return request
->extacl_user
.termedBuf();
92 if (cache
.extuser
&& *cache
.extuser
)
98 AccessLogEntry::AccessLogEntry() {}
100 AccessLogEntry::~AccessLogEntry()
102 safe_free(headers
.request
);
105 safe_free(adapt
.last_meta
);
108 safe_free(headers
.adapted_request
);
109 HTTPMSGUNLOCK(adapted_request
);
111 safe_free(lastAclName
);
113 HTTPMSGUNLOCK(request
);
115 HTTPMSGUNLOCK(icap
.reply
);
116 HTTPMSGUNLOCK(icap
.request
);
121 AccessLogEntry::effectiveVirginUrl() const
123 const SBuf
*effectiveUrl
= request
? &request
->effectiveRequestUri() : &virginUrlForMissingRequest_
;
124 if (effectiveUrl
&& !effectiveUrl
->isEmpty())
126 // We can not use ALE::url here because it may contain a request URI after
127 // adaptation/redirection. When the request is missing, a non-empty ALE::url
128 // means that we missed a setVirginUrlForMissingRequest() call somewhere.
133 AccessLogEntry::packReplyHeaders(MemBuf
&mb
) const
136 reply
->packHeadersUsingFastPacker(mb
);