From be846ed3f2ef1b884b8cda639d822d2e74c07d5a Mon Sep 17 00:00:00 2001 From: Artyom Abakumov Date: Wed, 2 Apr 2025 16:49:21 +0300 Subject: [PATCH 1/2] Correct section name for services in fbtrace config --- src/common/config/config_file.cpp | 6 +++--- src/common/config/config_file.h | 2 +- src/utilities/ntrace/TraceConfiguration.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/config/config_file.cpp b/src/common/config/config_file.cpp index 5e78f54622f..667f115dd62 100644 --- a/src/common/config/config_file.cpp +++ b/src/common/config/config_file.cpp @@ -979,14 +979,14 @@ ConfigFile::SectionType ConfigFile::Parameter::parseSectionKey() const { return SectionType::DATABASE_REGEX; } - else if (name == "service") + else if (name == "services") { - return SectionType::SERVICE; + return SectionType::SERVICES; } else { fatal_exception::raiseFmt("error while parsing trace configuration\n\t" - "line %d: wrong section header, \"database\", \"databaseName\", \"databaseRegex\" or \"service\" is expected", + "line %d: wrong section header, \"database\", \"databaseName\", \"databaseRegex\" or \"services\" is expected", line); // Return something to calm down the compiler diff --git a/src/common/config/config_file.h b/src/common/config/config_file.h index 49b48a4a89e..83a25c7b6e2 100644 --- a/src/common/config/config_file.h +++ b/src/common/config/config_file.h @@ -81,7 +81,7 @@ class ConfigFile : public Firebird::AutoStorage, public Firebird::RefCounted DATABASE, DATABASE_NAME, DATABASE_REGEX, - SERVICE + SERVICES }; struct Parameter : public AutoStorage diff --git a/src/utilities/ntrace/TraceConfiguration.cpp b/src/utilities/ntrace/TraceConfiguration.cpp index 608cfc08e42..1092aa9980a 100644 --- a/src/utilities/ntrace/TraceConfiguration.cpp +++ b/src/utilities/ntrace/TraceConfiguration.cpp @@ -90,7 +90,7 @@ void TraceCfgReader::readConfig() const ConfigFile::Parameter* section = ¶ms[n]; const ConfigFile::SectionType sectionType = section->parseSectionKey(); - const bool isDatabase = (sectionType != ConfigFile::SectionType::SERVICE); + const bool isDatabase = (sectionType != ConfigFile::SectionType::SERVICES); const ConfigFile::String pattern = section->value; bool match = false; From 645c574890b6ddd057dbc4bfd29e311608565704 Mon Sep 17 00:00:00 2001 From: Artyom Abakumov Date: Wed, 2 Apr 2025 20:33:54 +0300 Subject: [PATCH 2/2] Move section type paring to trace reader class --- src/common/config/config_file.cpp | 33 ----------------- src/common/config/config_file.h | 10 ------ src/utilities/ntrace/TraceConfiguration.cpp | 39 ++++++++++++++++++--- src/utilities/ntrace/TraceConfiguration.h | 10 ++++++ 4 files changed, 45 insertions(+), 47 deletions(-) diff --git a/src/common/config/config_file.cpp b/src/common/config/config_file.cpp index 667f115dd62..dda28840f0f 100644 --- a/src/common/config/config_file.cpp +++ b/src/common/config/config_file.cpp @@ -960,36 +960,3 @@ bool ConfigFile::Parameter::asBoolean() const 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 == "services") - { - return SectionType::SERVICES; - } - else - { - fatal_exception::raiseFmt("error while parsing trace configuration\n\t" - "line %d: wrong section header, \"database\", \"databaseName\", \"databaseRegex\" or \"services\" 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 83a25c7b6e2..98a58bee5ea 100644 --- a/src/common/config/config_file.h +++ b/src/common/config/config_file.h @@ -75,15 +75,6 @@ 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, - SERVICES - }; - struct Parameter : public AutoStorage { Parameter(MemoryPool& p, const Parameter& par) @@ -96,7 +87,6 @@ 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 1092aa9980a..fba46d655fd 100644 --- a/src/utilities/ntrace/TraceConfiguration.cpp +++ b/src/utilities/ntrace/TraceConfiguration.cpp @@ -89,8 +89,8 @@ void TraceCfgReader::readConfig() { const ConfigFile::Parameter* section = ¶ms[n]; - const ConfigFile::SectionType sectionType = section->parseSectionKey(); - const bool isDatabase = (sectionType != ConfigFile::SectionType::SERVICES); + const SectionType sectionType = parseSectionKey(section); + const bool isDatabase = (sectionType != SectionType::SERVICES); const ConfigFile::String pattern = section->value; bool match = false; @@ -127,14 +127,14 @@ void TraceCfgReader::readConfig() noQuotePattern.alltrim(" '\'"); PathName expandedName; - if (sectionType != ConfigFile::SectionType::DATABASE_REGEX && (m_databaseName == noQuotePattern || + if (sectionType != SectionType::DATABASE_REGEX && (m_databaseName == noQuotePattern || (expandDatabaseName(noQuotePattern, expandedName, nullptr), m_databaseName == expandedName) )) { // Compare by name match = exactMatch = true; } - else if (sectionType != ConfigFile::SectionType::DATABASE_NAME) + else if (sectionType != SectionType::DATABASE_NAME) { // Compare by regex bool regExpOk = false; @@ -318,3 +318,34 @@ void TraceCfgReader::expandPattern(const ConfigFile::Parameter* el, PathName& va pos++; } } + +TraceCfgReader::SectionType TraceCfgReader::parseSectionKey(const ConfigFile::Parameter* el) const +{ + fb_assert(el); + + if (el->name == "database") + { + return SectionType::DATABASE; + } + else if (el->name == "databaseName") + { + return SectionType::DATABASE_NAME; + } + else if (el->name == "databaseRegex") + { + return SectionType::DATABASE_REGEX; + } + else if (el->name == "services") + { + return SectionType::SERVICES; + } + else + { + fatal_exception::raiseFmt("error while parsing trace configuration\n\t" + "line %d: wrong section header, \"database\", \"databaseName\", \"databaseRegex\" or \"services\" is expected", + el->line); + + // Return something to calm down the compiler + return SectionType::DATABASE; + } +} diff --git a/src/utilities/ntrace/TraceConfiguration.h b/src/utilities/ntrace/TraceConfiguration.h index 403b9c7ec33..aca47ba3d6e 100644 --- a/src/utilities/ntrace/TraceConfiguration.h +++ b/src/utilities/ntrace/TraceConfiguration.h @@ -49,6 +49,15 @@ class TraceCfgReader int end; }; + // Possible section types + enum class SectionType + { + DATABASE, + DATABASE_NAME, + DATABASE_REGEX, + SERVICES + }; + private: TraceCfgReader(const char* text, const Firebird::PathName& databaseName, TracePluginConfig& config) : m_text(text), @@ -61,6 +70,7 @@ class TraceCfgReader void expandPattern(const ConfigFile::Parameter* el, Firebird::PathName& valueToExpand); bool parseBoolean(const ConfigFile::Parameter* el) const; ULONG parseUInteger(const ConfigFile::Parameter* el) const; + SectionType parseSectionKey(const ConfigFile::Parameter* el) const; const char* const m_text; const Firebird::PathName& m_databaseName;