]> git.ipfire.org Git - thirdparty/squid.git/blob - src/log/FormatSquidReferer.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / log / FormatSquidReferer.cc
1 /*
2 * Copyright (C) 1996-2021 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 /* DEBUG: section 46 Access Log - Squid referer format */
10
11 #include "squid.h"
12 #include "AccessLogEntry.h"
13 #include "HttpRequest.h"
14 #include "log/File.h"
15 #include "log/Formats.h"
16 #include "SquidTime.h"
17
18 void
19 Log::Format::SquidReferer(const AccessLogEntry::Pointer &al, Logfile *logfile)
20 {
21 const char *referer = NULL;
22 if (al->request)
23 referer = al->request->header.getStr(Http::HdrType::REFERER);
24
25 if (!referer || *referer == '\0')
26 referer = "-";
27
28 char clientip[MAX_IPSTRLEN];
29 al->getLogClientIp(clientip, MAX_IPSTRLEN);
30
31 const SBuf url = !al->url.isEmpty() ? al->url : ::Format::Dash;
32
33 logfilePrintf(logfile, "%9ld.%03d %s %s " SQUIDSBUFPH "\n",
34 (long int) current_time.tv_sec,
35 (int) current_time.tv_usec / 1000,
36 clientip,
37 referer,
38 SQUIDSBUFPRINT(url));
39 }
40