Skip to content

Commit b39dd37

Browse files
author
Artyom Abakumov
committed
Use new section keys instead of specifiers
1 parent 397b51a commit b39dd37

File tree

4 files changed

+51
-41
lines changed

4 files changed

+51
-41
lines changed

src/common/config/config_file.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,3 +961,37 @@ bool ConfigFile::Parameter::asBoolean() const
961961
value.equalsNoCase("yes") ||
962962
value.equalsNoCase("y");
963963
}
964+
965+
/******************************************************************************
966+
*
967+
* Parse name as a section key
968+
*/
969+
970+
ConfigFile::SectionType ConfigFile::Parameter::parseSectionKey() const
971+
{
972+
if (name == "database")
973+
{
974+
return SectionType::DATABASE;
975+
}
976+
else if (name == "databaseName")
977+
{
978+
return SectionType::DATABASE_NAME;
979+
}
980+
else if (name == "databaseRegex")
981+
{
982+
return SectionType::DATABASE_REGEX;
983+
}
984+
else if (name == "service")
985+
{
986+
return SectionType::SERVICE;
987+
}
988+
else
989+
{
990+
fatal_exception::raiseFmt("error while parsing trace configuration\n\t"
991+
"line %d: wrong section header, \"database\", \"databaseName\", \"databaseRegex\" or \"service\" is expected",
992+
line);
993+
994+
// Return something to calm down the compiler
995+
return SectionType::DATABASE;
996+
}
997+
}

src/common/config/config_file.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ class ConfigFile : public Firebird::AutoStorage, public Firebird::RefCounted
7575
virtual const char* getFileName() const = 0;
7676
};
7777

78+
// Possible section types
79+
enum class SectionType
80+
{
81+
DATABASE,
82+
DATABASE_NAME,
83+
DATABASE_REGEX,
84+
SERVICE
85+
};
86+
7887
struct Parameter : public AutoStorage
7988
{
8089
Parameter(MemoryPool& p, const Parameter& par)
@@ -87,6 +96,7 @@ class ConfigFile : public Firebird::AutoStorage, public Firebird::RefCounted
8796

8897
SINT64 asInteger() const;
8998
bool asBoolean() const;
99+
SectionType parseSectionKey() const;
90100

91101
KeyType name;
92102
String value;

src/utilities/ntrace/TraceConfiguration.cpp

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,6 @@ void TraceCfgReader::readTraceConfiguration(const char* text,
7070

7171
#define ERROR_PREFIX "error while parsing trace configuration\n\t"
7272

73-
enum class AliasType
74-
{
75-
DETECT,
76-
NAME,
77-
REGEX
78-
};
79-
inline constexpr std::string_view REGEX_PREFIX = "regex ";
80-
inline constexpr std::string_view NAME_PREFIX = "name ";
81-
8273
void TraceCfgReader::readConfig()
8374
{
8475
ConfigFile cfgFile(ConfigFile::USE_TEXT, m_text, ConfigFile::HAS_SUB_CONF | ConfigFile::NATIVE_ORDER
@@ -98,12 +89,8 @@ void TraceCfgReader::readConfig()
9889
{
9990
const ConfigFile::Parameter* section = &params[n];
10091

101-
const bool isDatabase = (section->name == "database");
102-
if (!isDatabase && section->name != "services")
103-
//continue;
104-
fatal_exception::raiseFmt(ERROR_PREFIX
105-
"line %d: wrong section header, \"database\" or \"service\" is expected",
106-
section->line);
92+
const ConfigFile::SectionType sectionType = section->parseSectionKey();
93+
const bool isDatabase = sectionType != ConfigFile::SectionType::SERVICE;
10794

10895
const ConfigFile::String pattern = section->value;
10996
bool match = false;
@@ -136,39 +123,18 @@ void TraceCfgReader::readConfig()
136123
}
137124
else if (isDatabase && !m_databaseName.empty())
138125
{
139-
PathName noQuotePattern;
140-
141-
AliasType specifier = AliasType::DETECT;
142-
const std::string_view patternView(pattern.data(), pattern.length());
143-
144-
// Check for "name" or "regex" specific in the path.
145-
// Compare path in both ways if specifier is not specified
146-
if (patternView.find_first_of(REGEX_PREFIX) == 0)
147-
{
148-
noQuotePattern.assign(pattern.data() + REGEX_PREFIX.length());
149-
specifier = AliasType::REGEX;
150-
}
151-
else if (patternView.find_first_of(NAME_PREFIX) == 0)
152-
{
153-
noQuotePattern.assign(pattern.data() + NAME_PREFIX.length());
154-
specifier = AliasType::NAME;
155-
}
156-
else
157-
{
158-
noQuotePattern = pattern.ToPathName();
159-
}
160-
126+
PathName noQuotePattern = pattern.ToPathName();
161127
noQuotePattern.alltrim(" '\'");
162128
PathName expandedName;
163129

164-
if (specifier != AliasType::REGEX && (m_databaseName == noQuotePattern ||
130+
if (sectionType != ConfigFile::SectionType::DATABASE_REGEX && (m_databaseName == noQuotePattern ||
165131
(expandDatabaseName(noQuotePattern, expandedName, nullptr),
166132
m_databaseName == expandedName) ))
167133
{
168134
// Compare by name
169135
match = exactMatch = true;
170136
}
171-
else if (specifier != AliasType::NAME)
137+
else if (sectionType != ConfigFile::SectionType::DATABASE_NAME)
172138
{
173139
// Compare by regex
174140
bool regExpOk = false;

src/utilities/ntrace/fbtrace.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
#
2828
# It is also possible to specify exactly what type of database string is expected
2929
# For example:
30-
# database = name /var/dbs/primary-db.fdb
30+
# databaseName = /var/dbs/primary-db.fdb
3131
# type
32-
# database = regex (%[\\/](e[[:DIGIT:]]{{2}}).fdb)
32+
# databaseRegex = (%[\\/](e[[:DIGIT:]]{{2}}).fdb)
3333

3434

3535
database

0 commit comments

Comments
 (0)