AccessLogEntry.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2020 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 #include "squid.h"
10 #include "AccessLogEntry.h"
11 #include "HttpReply.h"
12 #include "HttpRequest.h"
13 #include "MemBuf.h"
14 #include "proxyp/Header.h"
15 #include "SquidConfig.h"
16 #include "ssl/support.h"
17 
18 void
19 AccessLogEntry::getLogClientIp(char *buf, size_t bufsz) const
20 {
21  Ip::Address log_ip;
22 
23 #if FOLLOW_X_FORWARDED_FOR
25  log_ip = request->indirect_client_addr;
26  else
27 #endif
28  if (tcpClient)
29  log_ip = tcpClient->remote;
30  else
31  log_ip = cache.caddr;
32 
33  // internally generated requests (and some ICAP) lack client IP
34  if (log_ip.isNoAddr()) {
35  strncpy(buf, "-", bufsz);
36  return;
37  }
38 
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.
43 
45 
46  log_ip.toStr(buf, bufsz);
47 }
48 
49 SBuf
51 {
52  static const SBuf dash("-");
53  SBuf method;
54  if (icp.opcode)
56  else if (htcp.opcode)
57  method.append(htcp.opcode);
58  else if (http.method)
59  method = http.method.image();
60  else
61  method = dash;
62  return method;
63 }
64 
65 void
67 {
68  // XXX: auth code only has access to HttpRequest being authenticated
69  // so we must handle the case where HttpRequest is set without ALE being set.
70  assert(req);
71  if (!notes)
72  notes = req->notes();
73  else
74  assert(notes == req->notes());
75 }
76 
77 const char *
79 {
80  if (tcpClient)
81  return tcpClient->rfc931;
82 
83  if (cache.rfc931 && *cache.rfc931)
84  return cache.rfc931;
85 
86  return nullptr;
87 }
88 
89 const char *
91 {
92  if (request && request->extacl_user.size())
93  return request->extacl_user.termedBuf();
94 
95  if (cache.extuser && *cache.extuser)
96  return cache.extuser;
97 
98  return nullptr;
99 }
100 
102 
104 {
106 
107 #if USE_ADAPTATION
109 #endif
110 
113 
115 
117 #if ICAP_CLIENT
120 #endif
121 }
122 
123 ScopedId
125 {
126  if (request) {
127  if (const auto &mx = request->masterXaction)
128  return mx->id.detach();
129  }
130  // TODO: Carefully merge ALE and MasterXaction.
131  return ScopedId("ALE w/o master");
132 }
133 
134 std::ostream &
135 AccessLogEntry::detailCodeContext(std::ostream &os) const
136 {
137  // TODO: Consider printing all instead of the first most important detail.
138 
139  if (request) {
140  if (const auto &mx = request->masterXaction)
141  return os << Debug::Extra << "current master transaction: " << mx->id;
142  }
143 
144  // provide helpful details since we cannot identify the transaction exactly
145 
146  if (tcpClient)
147  return os << Debug::Extra << "current from-client connection: " << tcpClient;
148  else if (!cache.caddr.isNoAddr())
149  return os << Debug::Extra << "current client: " << cache.caddr;
150 
151  const auto optionalMethod = [this,&os]() {
152  if (hasLogMethod())
153  os << getLogMethod() << ' ';
154  return "";
155  };
156  if (const auto uri = effectiveVirginUrl())
157  return os << Debug::Extra << "current client request: " << optionalMethod() << *uri;
158  else if (!url.isEmpty())
159  return os << Debug::Extra << "current request: " << optionalMethod() << url;
160  else if (hasLogMethod())
161  return os << Debug::Extra << "current request method: " << getLogMethod();
162 
163  return os;
164 }
165 
166 const SBuf *
168 {
169  const SBuf *effectiveUrl = request ? &request->effectiveRequestUri() : &virginUrlForMissingRequest_;
170  if (effectiveUrl && !effectiveUrl->isEmpty())
171  return effectiveUrl;
172  // We can not use ALE::url here because it may contain a request URI after
173  // adaptation/redirection. When the request is missing, a non-empty ALE::url
174  // means that we missed a setVirginUrlForMissingRequest() call somewhere.
175  return nullptr;
176 }
177 
178 void
180 {
181  if (reply)
183 }
184 
const char * getClientIdent() const
Fetch the client IDENT string, or nil if none is available.
SBuf virginUrlForMissingRequest_
static std::ostream & Extra(std::ostream &os)
prefixes each grouped debugs() line after the first one in the group
Definition: Debug.h:104
bool isEmpty() const
Definition: SBuf.h:420
class AccessLogEntry::HtcpDetails htcp
HttpRequest * request
ICAP request.
HttpReplyPointer reply
Definition: SBuf.h:86
Ip::Address client_netmask
Definition: SquidConfig.h:245
const SBuf * effectiveVirginUrl() const
const SBuf & image() const
void HTTPMSGUNLOCK(M *&a)
Definition: Message.h:149
NotePairs::Pointer notes
void packHeadersUsingFastPacker(Packable &p) const
Definition: HttpReply.cc:86
String extacl_user
Definition: HttpRequest.h:179
char * toStr(char *buf, const unsigned int blen, int force=AF_UNSPEC) const
Definition: Address.cc:802
class AccessLogEntry::HttpDetails http
class AccessLogEntry::IcpDetails icp
class AccessLogEntry::IcapLogEntry icap
void syncNotes(HttpRequest *request)
HttpRequest * request
void applyClientMask(const Address &mask)
Definition: Address.cc:105
char rfc931[USER_IDENT_SZ]
Definition: Connection.h:186
char * last_meta
image of the last ICAP response header or eCAP meta received
Ip::Address indirect_client_addr
Definition: HttpRequest.h:152
Definition: MemBuf.h:23
const char * lastAclName
string for external_acl_type ACL format code
Comm::ConnectionPointer tcpClient
TCP/IP level details about the client connection.
#define safe_free(x)
Definition: xalloc.h:73
Ip::Address remote
Definition: Connection.h:159
MasterXaction::Pointer masterXaction
the master transaction this request belongs to. Never nil.
Definition: HttpRequest.h:239
#define assert(EX)
Definition: assert.h:19
class AccessLogEntry::CacheDetails cache
static uint32 C
Definition: md4.c:43
HttpRequestMethod method
HttpReply * reply
ICAP reply.
class AccessLogEntry::Headers headers
class AccessLogEntry::AdaptationDetails adapt
bool isNoAddr() const
Definition: Address.cc:284
struct SquidConfig::@112 onoff
virtual ~AccessLogEntry()
virtual std::ostream & detailCodeContext(std::ostream &os) const override
appends human-friendly context description line(s) to a cache.log record
int log_uses_indirect_client
Definition: SquidConfig.h:334
const char * termedBuf() const
Definition: SquidString.h:91
HttpRequest * adapted_request
size_type size() const
Definition: SquidString.h:72
void getLogClientIp(char *buf, size_t bufsz) const
size_t HttpReply *STUB StoreEntry const KeyScope scope const HttpRequestMethod & method
Definition: stub_store.cc:105
struct SquidConfig::@107 Addrs
void packReplyHeaders(MemBuf &mb) const
dump all reply headers (for sending or risky logging)
bool hasLogMethod() const
whether we know what the request method is
virtual ScopedId codeContextGist() const override
const SBuf & effectiveRequestUri() const
RFC 7230 section 5.5 - Effective Request URI.
Definition: HttpRequest.cc:705
NotePairs::Pointer notes()
Definition: HttpRequest.cc:713
const char * getExtUser() const
Fetch the external ACL provided 'user=' string, or nil if none is available.
SBuf getLogMethod() const
Fetch the transaction method string (ICP opcode, HTCP opcode or HTTP method)
void const char * buf
Definition: stub_helper.cc:16
const char * icp_opcode_str[]
class SquidConfig Config
Definition: SquidConfig.cc:12

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors