]> git.ipfire.org Git - thirdparty/squid.git/blob - src/log/FormatHttpdCombined.cc
Maintenance: Removed most NULLs using modernize-use-nullptr (#1075)
[thirdparty/squid.git] / src / log / FormatHttpdCombined.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 - Apache combined format */
10
11 #include "squid.h"
12 #include "AccessLogEntry.h"
13 #include "format/Quoting.h"
14 #include "format/Token.h"
15 #include "globals.h"
16 #include "HttpRequest.h"
17 #include "log/File.h"
18 #include "log/Formats.h"
19 #include "SquidConfig.h"
20
21 void
22 Log::Format::HttpdCombined(const AccessLogEntry::Pointer &al, Logfile * logfile)
23 {
24 const char *user_ident = ::Format::QuoteUrlEncodeUsername(al->getClientIdent());
25 const char *user_auth = nullptr;
26 const char *referer = nullptr;
27 const char *agent = nullptr;
28
29 if (al->request) {
30 #if USE_AUTH
31 if (al->request->auth_user_request != nullptr)
32 user_auth = ::Format::QuoteUrlEncodeUsername(al->request->auth_user_request->username());
33 #endif
34 referer = al->request->header.getStr(Http::HdrType::REFERER);
35 agent = al->request->header.getStr(Http::HdrType::USER_AGENT);
36 }
37
38 if (!referer || *referer == '\0')
39 referer = "-";
40
41 if (!agent || *agent == '\0')
42 agent = "-";
43
44 char clientip[MAX_IPSTRLEN];
45 al->getLogClientIp(clientip, MAX_IPSTRLEN);
46
47 const SBuf method(al->getLogMethod());
48
49 logfilePrintf(logfile, "%s %s %s [%s] \"" SQUIDSBUFPH " " SQUIDSBUFPH " %s/%d.%d\" %d %" PRId64 " \"%s\" \"%s\" %s:%s%s",
50 clientip,
51 user_ident ? user_ident : dash_str,
52 user_auth ? user_auth : dash_str,
53 Time::FormatHttpd(squid_curtime),
54 SQUIDSBUFPRINT(method),
55 SQUIDSBUFPRINT(al->url),
56 AnyP::ProtocolType_str[al->http.version.protocol],
57 al->http.version.major, al->http.version.minor,
58 al->http.code,
59 al->http.clientReplySz.messageTotal(),
60 referer,
61 agent,
62 al->cache.code.c_str(),
63 hier_code_str[al->hier.code],
64 (Config.onoff.log_mime_hdrs?"":"\n"));
65
66 safe_free(user_ident);
67 safe_free(user_auth);
68
69 if (Config.onoff.log_mime_hdrs) {
70 char *ereq = ::Format::QuoteMimeBlob(al->headers.request);
71 MemBuf mb;
72 mb.init();
73 al->packReplyHeaders(mb);
74 auto erep = ::Format::QuoteMimeBlob(mb.content());
75 logfilePrintf(logfile, " [%s] [%s]\n", ereq, erep);
76 safe_free(ereq);
77 safe_free(erep);
78 }
79 }
80