Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/common/config/config_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -961,3 +961,37 @@ bool ConfigFile::Parameter::asBoolean() const
value.equalsNoCase("yes") ||
value.equalsNoCase("y");
}

/******************************************************************************
*
* Parse name as a section key
*/

ConfigFile::SectionType ConfigFile::Parameter::parseSectionKey() const
{
if (name == "database")
{
return SectionType::DATABASE;
}
else if (name == "databaseName")
{
return SectionType::DATABASE_NAME;
}
else if (name == "databaseRegex")
{
return SectionType::DATABASE_REGEX;
}
else if (name == "service")
{
return SectionType::SERVICE;
}
else
{
fatal_exception::raiseFmt("error while parsing trace configuration\n\t"
"line %d: wrong section header, \"database\", \"databaseName\", \"databaseRegex\" or \"service\" is expected",
line);

// Return something to calm down the compiler
return SectionType::DATABASE;
}
}
10 changes: 10 additions & 0 deletions src/common/config/config_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ class ConfigFile : public Firebird::AutoStorage, public Firebird::RefCounted
virtual const char* getFileName() const = 0;
};

// Possible section types
enum class SectionType
{
DATABASE,
DATABASE_NAME,
DATABASE_REGEX,
SERVICE
};

struct Parameter : public AutoStorage
{
Parameter(MemoryPool& p, const Parameter& par)
Expand All @@ -87,6 +96,7 @@ class ConfigFile : public Firebird::AutoStorage, public Firebird::RefCounted

SINT64 asInteger() const;
bool asBoolean() const;
SectionType parseSectionKey() const;

KeyType name;
String value;
Expand Down
16 changes: 7 additions & 9 deletions src/utilities/ntrace/TraceConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,8 @@ void TraceCfgReader::readConfig()
{
const ConfigFile::Parameter* section = &params[n];

const bool isDatabase = (section->name == "database");
if (!isDatabase && section->name != "services")
//continue;
fatal_exception::raiseFmt(ERROR_PREFIX
"line %d: wrong section header, \"database\" or \"service\" is expected",
section->line);
const ConfigFile::SectionType sectionType = section->parseSectionKey();
const bool isDatabase = sectionType != ConfigFile::SectionType::SERVICE;

const ConfigFile::String pattern = section->value;
bool match = false;
Expand Down Expand Up @@ -131,14 +127,16 @@ void TraceCfgReader::readConfig()
noQuotePattern.alltrim(" '\'");
PathName expandedName;

if (m_databaseName == noQuotePattern ||
if (sectionType != ConfigFile::SectionType::DATABASE_REGEX && (m_databaseName == noQuotePattern ||
(expandDatabaseName(noQuotePattern, expandedName, nullptr),
m_databaseName == expandedName) )
m_databaseName == expandedName) ))
{
// Compare by name
match = exactMatch = true;
}
else
else if (sectionType != ConfigFile::SectionType::DATABASE_NAME)
{
// Compare by regex
bool regExpOk = false;
try
{
Expand Down
6 changes: 6 additions & 0 deletions src/utilities/ntrace/fbtrace.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
# database = (%[\\/](e[[:DIGIT:]]{2}).fdb)
# type
# database = (%[\\/](e[[:DIGIT:]]{{2}}).fdb)
#
# It is also possible to specify exactly what type of database string is expected
# For example:
# databaseName = /var/dbs/primary-db.fdb
# type
# databaseRegex = (%[\\/](e[[:DIGIT:]]{{2}}).fdb)


database
Expand Down
Loading