]> git.ipfire.org Git - thirdparty/squid.git/blame - src/log/FormatSquidNative.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / log / FormatSquidNative.cc
CommitLineData
20efa1c2 1/*
f70aedc4 2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
20efa1c2 3 *
bbc27441
AJ
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.
20efa1c2
AJ
7 */
8
bbc27441
AJ
9/* DEBUG: section 46 Access Log - Squid format */
10
f7f3304a 11#include "squid.h"
20efa1c2 12#include "AccessLogEntry.h"
38e16f92 13#include "format/Quoting.h"
31971e6a 14#include "format/Token.h"
582c2af2 15#include "globals.h"
c0e8c76f 16#include "HttpRequest.h"
20efa1c2
AJ
17#include "log/File.h"
18#include "log/Formats.h"
4d5904f7 19#include "SquidConfig.h"
20efa1c2
AJ
20#include "SquidTime.h"
21
22void
41ebd397 23Log::Format::SquidNative(const AccessLogEntry::Pointer &al, Logfile * logfile)
20efa1c2 24{
8652f8e7 25 char hierHost[MAX_IPSTRLEN];
20efa1c2 26
c0e8c76f
AJ
27 const char *user = NULL;
28
29#if USE_AUTH
30 if (al->request && al->request->auth_user_request != NULL)
31 user = ::Format::QuoteUrlEncodeUsername(al->request->auth_user_request->username());
32#endif
20efa1c2
AJ
33
34 if (!user)
e3bf07f5 35 user = ::Format::QuoteUrlEncodeUsername(al->getExtUser());
20efa1c2 36
cb4f4424 37#if USE_OPENSSL
20efa1c2 38 if (!user)
38e16f92 39 user = ::Format::QuoteUrlEncodeUsername(al->cache.ssluser);
20efa1c2
AJ
40#endif
41
42 if (!user)
e3bf07f5 43 user = ::Format::QuoteUrlEncodeUsername(al->getClientIdent());
20efa1c2
AJ
44
45 if (user && !*user)
46 safe_free(user);
47
8652f8e7 48 char clientip[MAX_IPSTRLEN];
d4204018 49 al->getLogClientIp(clientip, MAX_IPSTRLEN);
8652f8e7 50
58b148e1 51 const SBuf method(al->getLogMethod());
7f06a3d8 52
f57ae909 53 logfilePrintf(logfile, "%9ld.%03d %6ld %s %s/%03d %" PRId64 " " SQUIDSBUFPH " " SQUIDSBUFPH " %s %s%s/%s %s%s",
20efa1c2
AJ
54 (long int) current_time.tv_sec,
55 (int) current_time.tv_usec / 1000,
01bd87d8 56 tvToMsec(al->cache.trTime),
8652f8e7 57 clientip,
91369933 58 al->cache.code.c_str(),
20efa1c2 59 al->http.code,
cc0ca3b9 60 al->http.clientReplySz.messageTotal(),
7f06a3d8 61 SQUIDSBUFPRINT(method),
f57ae909 62 SQUIDSBUFPRINT(al->url),
20efa1c2
AJ
63 user ? user : dash_str,
64 al->hier.ping.timedout ? "TIMEOUT_" : "",
65 hier_code_str[al->hier.code],
4dd643d5 66 al->hier.tcpServer != NULL ? al->hier.tcpServer->remote.toStr(hierHost, sizeof(hierHost)) : "-",
20efa1c2
AJ
67 al->http.content_type,
68 (Config.onoff.log_mime_hdrs?"":"\n"));
69
70 safe_free(user);
71
72 if (Config.onoff.log_mime_hdrs) {
38e16f92 73 char *ereq = ::Format::QuoteMimeBlob(al->headers.request);
49f57088
EB
74 MemBuf mb;
75 mb.init();
76 al->packReplyHeaders(mb);
77 auto erep = ::Format::QuoteMimeBlob(mb.content());
20efa1c2
AJ
78 logfilePrintf(logfile, " [%s] [%s]\n", ereq, erep);
79 safe_free(ereq);
80 safe_free(erep);
81 }
82}
f53969cc 83