]> git.ipfire.org Git - thirdparty/squid.git/blame - src/log/Config.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / log / Config.cc
CommitLineData
bbc27441 1/*
f70aedc4 2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
bbc27441
AJ
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
f7f3304a 9#include "squid.h"
8a01b99e 10#include "cache_cf.h"
2eceb328 11#include "ConfigParser.h"
af69c635 12#include "Debug.h"
82b7abe3
AJ
13#include "log/Config.h"
14
15Log::LogConfig Log::TheConfig;
20efa1c2
AJ
16
17void
18Log::LogConfig::parseFormats()
19{
20 char *name, *def;
21
2fec641d 22 if (!(name = ConfigParser::NextToken())) {
89d897e1 23 debugs(3, DBG_CRITICAL, "FATAL: missing logformat details in " << cfg_filename << " line " << config_lineno);
20efa1c2 24 self_destruct();
03eb3b04 25 return;
2fec641d 26 }
20efa1c2 27
89d897e1
AJ
28 // check for re-definition of built-in formats
29 if (strcmp(name, "squid") == 0 ||
7f9c1f03
SM
30 strcmp(name, "common") == 0 ||
31 strcmp(name, "combined") == 0 ||
32 strcmp(name, "useragent") == 0 ||
33 strcmp(name, "referrer") == 0) {
89d897e1
AJ
34 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: logformat " << name << " is already defined. Ignoring.");
35 return;
36 }
37
38 // check for re-definition of custom formats
39 for (auto i = logformats; i ; i = i->next) {
40 if (strcmp(i->name, name) == 0) {
41 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: logformat " << name << " is already defined. Ignoring.");
42 return;
43 }
44 }
45
2eceb328
CT
46 ::Format::Format *nlf = new ::Format::Format(name);
47
48 ConfigParser::EnableMacros();
2fec641d
AJ
49 if (!(def = ConfigParser::NextQuotedOrToEol())) {
50 delete nlf;
20efa1c2
AJ
51 self_destruct();
52 return;
53 }
2eceb328 54 ConfigParser::DisableMacros();
20efa1c2 55
38e16f92 56 debugs(3, 2, "Log Format for '" << name << "' is '" << def << "'");
20efa1c2 57
38e16f92 58 if (!nlf->parse(def)) {
2fec641d 59 delete nlf;
20efa1c2
AJ
60 self_destruct();
61 return;
62 }
63
64 // add to global config list
65 nlf->next = logformats;
66 logformats = nlf;
67}
f53969cc 68