]> git.ipfire.org Git - thirdparty/squid.git/blob - src/log/FormatHttpdCommon.cc
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / log / FormatHttpdCommon.cc
1 /*
2 * Copyright (C) 1996-2020 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 common 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 #include "SquidTime.h"
21
22 void
23 Log::Format::HttpdCommon(const AccessLogEntry::Pointer &al, Logfile * logfile)
24 {
25 const char *user_auth = NULL;
26 #if USE_AUTH
27 if (al->request && al->request->auth_user_request != NULL)
28 user_auth = ::Format::QuoteUrlEncodeUsername(al->request->auth_user_request->username());
29 #endif
30 const char *user_ident = ::Format::QuoteUrlEncodeUsername(al->getClientIdent());
31
32 char clientip[MAX_IPSTRLEN];
33 al->getLogClientIp(clientip, MAX_IPSTRLEN);
34
35 const SBuf method(al->getLogMethod());
36
37 logfilePrintf(logfile, "%s %s %s [%s] \"" SQUIDSBUFPH " " SQUIDSBUFPH " %s/%d.%d\" %d %" PRId64 " %s:%s%s",
38 clientip,
39 user_ident ? user_ident : dash_str,
40 user_auth ? user_auth : dash_str,
41 Time::FormatHttpd(squid_curtime),
42 SQUIDSBUFPRINT(method),
43 SQUIDSBUFPRINT(al->url),
44 AnyP::ProtocolType_str[al->http.version.protocol],
45 al->http.version.major, al->http.version.minor,
46 al->http.code,
47 al->http.clientReplySz.messageTotal(),
48 al->cache.code.c_str(),
49 hier_code_str[al->hier.code],
50 (Config.onoff.log_mime_hdrs?"":"\n"));
51
52 safe_free(user_auth);
53 safe_free(user_ident);
54
55 if (Config.onoff.log_mime_hdrs) {
56 char *ereq = ::Format::QuoteMimeBlob(al->headers.request);
57 MemBuf mb;
58 mb.init();
59 al->packReplyHeaders(mb);
60 auto erep = ::Format::QuoteMimeBlob(mb.content());
61 logfilePrintf(logfile, " [%s] [%s]\n", ereq, erep);
62 safe_free(ereq);
63 safe_free(erep);
64 }
65 }
66