]> git.ipfire.org Git - thirdparty/squid.git/blob - src/log/FormatSquidIcap.cc
Source Format Enforcement (#963)
[thirdparty/squid.git] / src / log / FormatSquidIcap.cc
1 /*
2 * Copyright (C) 1996-2022 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 ICAP Logging */
10
11 #include "squid.h"
12
13 #if ICAP_CLIENT
14
15 #include "AccessLogEntry.h"
16 #include "format/Quoting.h"
17 #include "HttpRequest.h"
18 #include "log/File.h"
19 #include "log/Formats.h"
20 #include "SquidConfig.h"
21 #include "SquidTime.h"
22
23 void
24 Log::Format::SquidIcap(const AccessLogEntry::Pointer &al, Logfile * logfile)
25 {
26 const char *user = NULL;
27 char tmp[MAX_IPSTRLEN], clientbuf[MAX_IPSTRLEN];
28
29 const auto client = al->getLogClientFqdn(clientbuf, sizeof(clientbuf));
30
31 #if USE_AUTH
32 if (al->request != NULL && al->request->auth_user_request != NULL)
33 user = ::Format::QuoteUrlEncodeUsername(al->request->auth_user_request->username());
34 #endif
35
36 if (!user)
37 user = ::Format::QuoteUrlEncodeUsername(al->getExtUser());
38
39 #if USE_OPENSSL
40 if (!user)
41 user = ::Format::QuoteUrlEncodeUsername(al->cache.ssluser);
42 #endif
43
44 if (!user)
45 user = ::Format::QuoteUrlEncodeUsername(al->getClientIdent());
46
47 if (user && !*user)
48 safe_free(user);
49
50 logfilePrintf(logfile, "%9ld.%03d %6ld %s %s/%03d %" PRId64 " %s %s %s -/%s -\n",
51 (long int) current_time.tv_sec,
52 (int) current_time.tv_usec / 1000,
53 tvToMsec(al->icap.trTime),
54 client,
55 al->icap.outcome,
56 al->icap.resStatus,
57 al->icap.bytesRead,
58 Adaptation::Icap::ICAP::methodStr(al->icap.reqMethod),
59 al->icap.reqUri.termedBuf(),
60 user ? user : "-",
61 al->icap.hostAddr.toStr(tmp, MAX_IPSTRLEN));
62 safe_free(user);
63 }
64 #endif
65