Config.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 #include "squid.h"
10 #include "cache_cf.h"
11 #include "ConfigParser.h"
12 #include "Debug.h"
13 #include "log/Config.h"
14 
16 
17 const char *
19 {
20  switch (logformatType) {
22  case Format::CLF_NONE:
23  case Format::CLF_CUSTOM:
24  return nullptr; // the above types are not built-in
25 
26  case Format::CLF_SQUID:
27  return "squid";
28 
30  return "combined";
31 
32  case Format::CLF_COMMON:
33  return "common";
34 
35 #if ICAP_CLIENT
37  return "icap_squid";
38 #endif
39 
41  return "useragent";
42 
44  return "referrer";
45  }
46 
47  // forgotten (by developers) type, invalid type, or unreachable code
48  return nullptr;
49 }
50 
52 Log::LogConfig::FindBuiltInFormat(const char *logformatName)
53 {
54  assert(logformatName);
55 
56  if (strcmp(logformatName, "auto") == 0) {
57  debugs(0, DBG_CRITICAL, "WARNING: Log format 'auto' no longer exists. Using 'squid' instead.");
58  return Format::CLF_SQUID;
59  }
60 
61  if (strcmp(logformatName, "squid") == 0)
62  return Format::CLF_SQUID;
63 
64  if (strcmp(logformatName, "common") == 0)
65  return Format::CLF_COMMON;
66 
67  if (strcmp(logformatName, "combined") == 0)
68  return Format::CLF_COMBINED;
69 
70 #if ICAP_CLIENT
71  if (strcmp(logformatName, "icap_squid") == 0)
73 #endif
74 
75  if (strcmp(logformatName, "useragent") == 0)
76  return Format::CLF_USERAGENT;
77 
78  if (strcmp(logformatName, "referrer") == 0)
79  return Format::CLF_REFERER;
80 
81  // CLF_NONE, CLF_UNKNOWN, CLF_CUSTOM types cannot be specified explicitly.
82  // TODO: Ban "none" and "unknown" custom logformat names to avoid confusion.
83  return Format::CLF_UNKNOWN;
84 }
85 
87 Log::LogConfig::findCustomFormat(const char *logformatName) const
88 {
89  assert(logformatName);
90  for (auto i = logformats; i ; i = i->next) {
91  if (strcmp(i->name, logformatName) == 0)
92  return i;
93  }
94  return nullptr;
95 }
96 
97 bool
98 Log::LogConfig::knownFormat(const char *logformatName) const
99 {
100  return FindBuiltInFormat(logformatName) || findCustomFormat(logformatName);
101 }
102 
103 void
105 {
106  char *name, *def;
107 
108  if (!(name = ConfigParser::NextToken())) {
109  debugs(3, DBG_CRITICAL, "FATAL: missing logformat details in " << cfg_filename << " line " << config_lineno);
110  self_destruct();
111  return;
112  }
113 
114  if (FindBuiltInFormat(name)) {
115  debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: logformat " << name << " is a built-in format. Ignoring redefinition attempt.");
116  return;
117  }
118 
119  if (findCustomFormat(name)) {
120  debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: logformat " << name << " is already defined. Ignoring redefinition attempt.");
121  return;
122  }
123 
124  ::Format::Format *nlf = new ::Format::Format(name);
125 
127  if (!(def = ConfigParser::NextQuotedOrToEol())) {
128  delete nlf;
129  self_destruct();
130  return;
131  }
133 
134  debugs(3, 2, "Log Format for '" << name << "' is '" << def << "'");
135 
136  if (!nlf->parse(def)) {
137  delete nlf;
138  self_destruct();
139  return;
140  }
141 
142  // add to global config list
143  nlf->next = logformats;
144  logformats = nlf;
145 }
146 
@ CLF_COMMON
Definition: Formats.h:29
static void EnableMacros()
Allow macros inside quoted strings.
Definition: ConfigParser.h:141
@ CLF_COMBINED
Definition: Formats.h:28
LogConfig TheConfig
Definition: Config.cc:15
::Format::Format * findCustomFormat(const char *logformatName) const
Definition: Config.cc:87
#define DBG_CRITICAL
Definition: Debug.h:40
@ CLF_CUSTOM
Definition: Formats.h:30
bool parse(const char *def)
Definition: Format.cc:67
#define DBG_IMPORTANT
Definition: Debug.h:41
void self_destruct(void)
Definition: cache_cf.cc:275
void parseFormats()
Definition: Config.cc:104
Format * next
Definition: Format.h:61
@ CLF_ICAP_SQUID
Definition: Formats.h:32
static void DisableMacros()
Do not allow macros inside quoted strings.
Definition: ConfigParser.h:144
@ CLF_SQUID
Definition: Formats.h:35
@ CLF_REFERER
Definition: Formats.h:34
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
@ CLF_UNKNOWN
Definition: Formats.h:27
#define assert(EX)
Definition: assert.h:19
const char * cfg_filename
Definition: cache_cf.cc:270
int config_lineno
Definition: cache_cf.cc:271
#define DBG_PARSE_NOTE(x)
Definition: Debug.h:45
static char * NextToken()
@ CLF_USERAGENT
Definition: Formats.h:36
static Format::log_type FindBuiltInFormat(const char *logformatName)
Definition: Config.cc:52
static char * NextQuotedOrToEol()
bool knownFormat(const char *logformatName) const
Definition: Config.cc:98
@ CLF_NONE
Definition: Formats.h:37
static const char * BuiltInFormatName(Format::log_type type)
Definition: Config.cc:18

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors