diff --git a/src/common/config/config_file.cpp b/src/common/config/config_file.cpp index 0bb0df21c75..c64125f8168 100644 --- a/src/common/config/config_file.cpp +++ b/src/common/config/config_file.cpp @@ -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; + } +} diff --git a/src/common/config/config_file.h b/src/common/config/config_file.h index 50473e09188..ff4c35db5cd 100644 --- a/src/common/config/config_file.h +++ b/src/common/config/config_file.h @@ -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) @@ -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; diff --git a/src/utilities/ntrace/TraceConfiguration.cpp b/src/utilities/ntrace/TraceConfiguration.cpp index fb5518515d9..608cfc08e42 100644 --- a/src/utilities/ntrace/TraceConfiguration.cpp +++ b/src/utilities/ntrace/TraceConfiguration.cpp @@ -89,12 +89,8 @@ void TraceCfgReader::readConfig() { const ConfigFile::Parameter* section = ¶ms[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; @@ -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 { diff --git a/src/utilities/ntrace/fbtrace.conf b/src/utilities/ntrace/fbtrace.conf index ee9d421e5be..a8c6a359df7 100644 --- a/src/utilities/ntrace/fbtrace.conf +++ b/src/utilities/ntrace/fbtrace.conf @@ -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