Squid Web Cache master
Loading...
Searching...
No Matches
FormatSquidNative.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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 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
21void
23{
24 char hierHost[MAX_IPSTRLEN];
25
26 const char *user = nullptr;
27
28#if USE_AUTH
29 if (al->request && al->request->auth_user_request != nullptr)
31#endif
32
33 if (!user)
35
36#if USE_OPENSSL
37 if (!user)
39#endif
40
41 if (user && !*user)
42 safe_free(user);
43
44 char clientip[MAX_IPSTRLEN];
45 al->getLogClientIp(clientip, MAX_IPSTRLEN);
46
47 const SBuf method(al->getLogMethod());
48
49 logfilePrintf(logfile, "%9ld.%03d %6ld %s %s/%03d %" PRId64 " " SQUIDSBUFPH " " SQUIDSBUFPH " %s %s%s/%s %s%s",
50 (long int) current_time.tv_sec,
51 (int) current_time.tv_usec / 1000,
53 clientip,
54 al->cache.code.c_str(),
55 al->http.code,
57 SQUIDSBUFPRINT(method),
59 user ? user : dash_str,
60 al->hier.ping.timedout ? "TIMEOUT_" : "",
62 al->hier.tcpServer != nullptr ? al->hier.tcpServer->remote.toStr(hierHost, sizeof(hierHost)) : "-",
64 (Config.onoff.log_mime_hdrs?"":"\n"));
65
66 safe_free(user);
67
69 char *ereq = ::Format::QuoteMimeBlob(al->headers.request);
70 MemBuf mb;
71 mb.init();
72 al->packReplyHeaders(mb);
73 auto erep = ::Format::QuoteMimeBlob(mb.content());
74 logfilePrintf(logfile, " [%s] [%s]\n", ereq, erep);
75 safe_free(ereq);
76 safe_free(erep);
77 }
78}
79
#define SQUIDSBUFPH
Definition SBuf.h:31
#define SQUIDSBUFPRINT(s)
Definition SBuf.h:32
class SquidConfig Config
struct timeval trTime
The response time.
MessageSizes clientReplySz
counters for the response sent to client
void getLogClientIp(char *buf, size_t bufsz) const
SBuf getLogMethod() const
Fetch the transaction method string (ICP opcode, HTCP opcode or HTTP method)
void packReplyHeaders(MemBuf &mb) const
dump all reply headers (for sending or risky logging)
class AccessLogEntry::CacheDetails cache
HierarchyLogEntry hier
class AccessLogEntry::Headers headers
class AccessLogEntry::HttpDetails http
HttpRequest * request
const char * getExtUser() const
Fetch the external ACL provided 'user=' string, or nil if none is available.
char const * username() const
Ip::Address remote
Definition Connection.h:152
Comm::ConnectionPointer tcpServer
TCP/IP level details of the last peer/server connection.
Auth::UserRequest::Pointer auth_user_request
char * toStr(char *buf, const unsigned int blen, int force=AF_UNSPEC) const
Definition Address.cc:804
const char * c_str() const
compute the status access.log field
Definition LogTags.cc:75
Definition File.h:39
void init(mb_size_t szInit, mb_size_t szMax)
Definition MemBuf.cc:93
char * content()
start of the added data
Definition MemBuf.h:41
uint64_t messageTotal() const
total message size
Definition SBuf.h:94
struct SquidConfig::@90 onoff
int timedout
Definition PingData.h:42
const char * dash_str
const char * hier_code_str[]
#define MAX_IPSTRLEN
Length of buffer that needs to be allocated to old a null-terminated IP-string.
Definition forward.h:25
void logfilePrintf(Logfile *lf, const char *fmt,...)
Definition File.cc:114
char * QuoteMimeBlob(const char *header)
Definition Quoting.cc:43
char * QuoteUrlEncodeUsername(const char *name)
Definition Quoting.cc:31
void SquidNative(const AccessLogEntryPointer &al, Logfile *logfile)
Native Squid Format Display.
struct timeval current_time
the current UNIX time in timeval {seconds, microseconds} format
Definition gadgets.cc:18
long int tvToMsec(struct timeval &t)
Definition gadgets.h:93
#define PRId64
Definition types.h:104
#define safe_free(x)
Definition xalloc.h:73