--- /dev/null
+#include "config.h"
+#include "AccessLogEntry.h"
+#include "HttpRequest.h"
+
+void
+AccessLogEntry::getLogClientIp(char *buf, size_t bufsz) const
+{
+#if FOLLOW_X_FORWARDED_FOR
+ if (Config.onoff.log_uses_indirect_client && request)
+ request->indirect_client_addr.NtoA(buf, bufsz);
+ else
+#endif
+ if (tcpClient != NULL)
+ tcpClient->remote.NtoA(buf, bufsz);
+ else if (cache.caddr.IsNoAddr()) // e.g., ICAP OPTIONS lack client
+ strncpy(buf, "-", 1);
+ else
+ cache.caddr.NtoA(buf, bufsz);
+}
AccessLogEntry() : url(NULL), tcpClient(), reply(NULL), request(NULL),
adapted_request(NULL) {}
+ /// Fetch the client IP log string into the given buffer.
+ /// Knows about several alternate locations of the IP
+ /// including indirect forwarded-for IP if configured to log that
+ void getLogClientIp(char *buf, size_t bufsz) const;
+
const char *url;
/// TCP/IP level details about the client connection
squid_SOURCES = \
$(ACL_REGISTRATION_SOURCES) \
+ AccessLogEntry.cc \
AccessLogEntry.h \
AsyncEngine.cc \
AsyncEngine.h \
## Tests of the CacheManager module.
tests_testCacheManager_SOURCES = \
+ AccessLogEntry.cc \
$(ACL_REGISTRATION_SOURCES) \
debug.cc \
HttpParser.cc \
## Tests of the Even module.
tests_testEvent_SOURCES = \
+ AccessLogEntry.cc \
$(ACL_REGISTRATION_SOURCES) \
BodyPipe.cc \
CacheDigest.cc \
## Tests of the EventLoop module.
tests_testEventLoop_SOURCES = \
+ AccessLogEntry.cc \
$(ACL_REGISTRATION_SOURCES) \
BodyPipe.cc \
CacheDigest.cc \
$(SQUID_CPPUNIT_LA)
tests_test_http_range_SOURCES = \
+ AccessLogEntry.cc \
$(ACL_REGISTRATION_SOURCES) \
BodyPipe.cc \
cache_cf.cc \
## Tests of the HttpRequest module.
tests_testHttpRequest_SOURCES = \
+ AccessLogEntry.cc \
$(ACL_REGISTRATION_SOURCES) \
HttpParser.cc \
HttpParser.h \
## Tests of the URL module.
## TODO: Trim this down once the insanity is over.
tests_testURL_SOURCES = \
+ AccessLogEntry.cc \
$(ACL_REGISTRATION_SOURCES) \
BodyPipe.cc \
cache_cf.cc \
break;
case LFT_CLIENT_IP_ADDRESS:
- if (al->cache.caddr.IsNoAddr()) // e.g., ICAP OPTIONS lack client
- out = "-";
- else
- out = al->cache.caddr.NtoA(tmp,1024);
+ al->getLogClientIp(tmp, sizeof(tmp));
+ out = tmp;
break;
case LFT_CLIENT_FQDN:
void
Log::Format::HttpdCombined(AccessLogEntry * al, Logfile * logfile)
{
- char clientip[MAX_IPSTRLEN];
-
const char *user_ident = ::Format::QuoteUrlEncodeUsername(al->cache.rfc931);
const char *user_auth = ::Format::QuoteUrlEncodeUsername(al->cache.authuser);
if (!agent || *agent == '\0')
agent = "-";
+ char clientip[MAX_IPSTRLEN];
+ al->getLogClientIp(clientip, MAX_IPSTRLEN);
+
logfilePrintf(logfile, "%s %s %s [%s] \"%s %s %s/%d.%d\" %d %"PRId64" \"%s\" \"%s\" %s%s:%s%s",
- al->cache.caddr.NtoA(clientip,MAX_IPSTRLEN),
+ clientip,
user_ident ? user_ident : dash_str,
user_auth ? user_auth : dash_str,
Time::FormatHttpd(squid_curtime),
void
Log::Format::HttpdCommon(AccessLogEntry * al, Logfile * logfile)
{
- char clientip[MAX_IPSTRLEN];
const char *user_auth = ::Format::QuoteUrlEncodeUsername(al->cache.authuser);
const char *user_ident = ::Format::QuoteUrlEncodeUsername(al->cache.rfc931);
+ char clientip[MAX_IPSTRLEN];
+ al->getLogClientIp(clientip, MAX_IPSTRLEN);
+
logfilePrintf(logfile, "%s %s %s [%s] \"%s %s %s/%d.%d\" %d %"PRId64" %s%s:%s%s",
- al->cache.caddr.NtoA(clientip,MAX_IPSTRLEN),
+ clientip,
user_ident ? user_ident : dash_str,
user_auth ? user_auth : dash_str,
Time::FormatHttpd(squid_curtime),
safe_free(user);
char clientip[MAX_IPSTRLEN];
- if (al->tcpClient != NULL)
- al->tcpClient->remote.NtoA(clientip, sizeof(clientip));
- else
- al->cache.caddr.NtoA(clientip, sizeof(clientip));
+ al->getLogClientIp(clientip, MAX_IPSTRLEN);
logfilePrintf(logfile, "%9ld.%03d %6d %s %s%s/%03d %"PRId64" %s %s %s %s%s/%s %s%s",
(long int) current_time.tv_sec,
return;
char clientip[MAX_IPSTRLEN];
+ al->getLogClientIp(clientip, MAX_IPSTRLEN);
logfilePrintf(logfile, "%9ld.%03d %s %s %s\n",
(long int) current_time.tv_sec,
(int) current_time.tv_usec / 1000,
- al->cache.caddr.NtoA(clientip, MAX_IPSTRLEN),
+ clientip,
referer,
al->url ? al->url : "-");
}
void
Log::Format::SquidUserAgent(AccessLogEntry * al, Logfile * logfile)
{
- char clientip[MAX_IPSTRLEN];
-
const char *agent = al->request->header.getStr(HDR_USER_AGENT);
// do not log unless there is something to be displayed.
if (!agent || *agent == '\0')
return;
+ char clientip[MAX_IPSTRLEN];
+ al->getLogClientIp(clientip, MAX_IPSTRLEN);
+
logfilePrintf(logfile, "%s [%s] \"%s\"\n",
- al->cache.caddr.NtoA(clientip,MAX_IPSTRLEN),
+ clientip,
Time::FormatHttpd(squid_curtime),
agent);
}