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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors