Config.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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/Stream.h"
13#include "log/Config.h"
14
16
17const char *
19{
20 switch (logformatType) {
24 return nullptr; // the above types are not built-in
25
27 return "squid";
28
30 return "combined";
31
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
52Log::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)
69
70#if ICAP_CLIENT
71 if (strcmp(logformatName, "icap_squid") == 0)
73#endif
74
75 if (strcmp(logformatName, "useragent") == 0)
77
78 if (strcmp(logformatName, "referrer") == 0)
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.
84}
85
87Log::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
97bool
98Log::LogConfig::knownFormat(const char *logformatName) const
99{
100 return FindBuiltInFormat(logformatName) || findCustomFormat(logformatName);
101}
102
103void
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);
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;
130 return;
131 }
133
134 debugs(3, 2, "Log Format for '" << name << "' is '" << def << "'");
135
136 if (!nlf->parse(def)) {
137 delete nlf;
139 return;
140 }
141
142 // add to global config list
143 nlf->next = logformats;
144 logformats = nlf;
145}
146
#define assert(EX)
Definition: assert.h:17
const char * cfg_filename
Definition: cache_cf.cc:272
int config_lineno
Definition: cache_cf.cc:273
void self_destruct(void)
Definition: cache_cf.cc:277
static void DisableMacros()
Do not allow macros inside quoted strings.
Definition: ConfigParser.h:147
static char * NextQuotedOrToEol()
static char * NextToken()
static void EnableMacros()
Allow macros inside quoted strings.
Definition: ConfigParser.h:144
bool parse(const char *def)
Definition: Format.cc:66
Format * next
Definition: Format.h:61
static const char * BuiltInFormatName(Format::log_type type)
Definition: Config.cc:18
bool knownFormat(const char *logformatName) const
Definition: Config.cc:98
static Format::log_type FindBuiltInFormat(const char *logformatName)
Definition: Config.cc:52
void parseFormats()
Definition: Config.cc:104
::Format::Format * findCustomFormat(const char *logformatName) const
Definition: Config.cc:87
#define DBG_PARSE_NOTE(x)
Definition: Stream.h:42
#define DBG_IMPORTANT
Definition: Stream.h:38
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
#define DBG_CRITICAL
Definition: Stream.h:37
@ CLF_COMBINED
Definition: Formats.h:28
@ CLF_ICAP_SQUID
Definition: Formats.h:32
@ CLF_COMMON
Definition: Formats.h:29
@ CLF_USERAGENT
Definition: Formats.h:36
@ CLF_SQUID
Definition: Formats.h:35
@ CLF_REFERER
Definition: Formats.h:34
@ CLF_NONE
Definition: Formats.h:37
@ CLF_UNKNOWN
Definition: Formats.h:27
@ CLF_CUSTOM
Definition: Formats.h:30
LogConfig TheConfig
Definition: Config.cc:15

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors