From 38d62506b39c8d582843217aafe717d1ee73f988 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Mon, 3 Jun 2024 12:42:10 +0300 Subject: [PATCH] Driver: fortconf: Tweak rule expr flags --- src/driver/common/fortconf.h | 28 +++++++++++----- src/ui/util/conf/ruletextparser.cpp | 52 ++++++++++++++++++++++------- src/ui/util/conf/ruletextparser.h | 20 +++++++++-- 3 files changed, 76 insertions(+), 24 deletions(-) diff --git a/src/driver/common/fortconf.h b/src/driver/common/fortconf.h index 183fccde..b775e65f 100644 --- a/src/driver/common/fortconf.h +++ b/src/driver/common/fortconf.h @@ -110,18 +110,28 @@ typedef struct fort_conf_addr_group char data[4]; } FORT_CONF_ADDR_GROUP, *PFORT_CONF_ADDR_GROUP; -#define FORT_RULE_EXPR_NOT 0x01 -#define FORT_RULE_EXPR_LIST 0x02 -#define FORT_RULE_EXPR_LOCAL 0x04 -#define FORT_RULE_EXPR_ADDRESS 0x08 -#define FORT_RULE_EXPR_PORT 0x10 -#define FORT_RULE_EXPR_PROTOCOL 0x20 -#define FORT_RULE_EXPR_DIRECTION 0x40 +#define FORT_RULE_EXPR_FLAG_LIST 0x01 +#define FORT_RULE_EXPR_FLAG_NOT 0x02 + +enum FortRuleExprList { + FORT_RULE_EXPR_LIST_OR = 0, + FORT_RULE_EXPR_LIST_AND, +}; + +enum FortRuleExprType { + FORT_RULE_EXPR_TYPE_ADDRESS = 0, + FORT_RULE_EXPR_TYPE_PORT, + FORT_RULE_EXPR_TYPE_LOCAL_ADDRESS, + FORT_RULE_EXPR_TYPE_LOCAL_PORT, + FORT_RULE_EXPR_TYPE_PROTOCOL, + FORT_RULE_EXPR_TYPE_DIRECTION, +}; typedef struct fort_conf_rule_expr { - UINT32 flags : 8; - UINT32 size : 24; + UINT32 flags : 2; + UINT32 type : 3; + UINT32 size : 27; } FORT_CONF_RULE_EXPR, *PFORT_CONF_RULE_EXPR; typedef struct fort_conf_rule_zones diff --git a/src/ui/util/conf/ruletextparser.cpp b/src/ui/util/conf/ruletextparser.cpp index ee2b10c3..c70ae1b2 100644 --- a/src/ui/util/conf/ruletextparser.cpp +++ b/src/ui/util/conf/ruletextparser.cpp @@ -15,23 +15,51 @@ void RuleTextParser::setupText(const QString &text) bool RuleTextParser::parse() { - while (m_p < m_end) { - processChar(*m_p++); - } + const auto charType = nextCharType(); return false; } -void RuleTextParser::processChar(const QChar c) +RuleTextParser::CharType RuleTextParser::nextCharType() { - if (m_skipLine) { - m_skipLine = (c != '\n'); - return; + bool skipLine = false; + + while (m_p < m_end) { + const QChar c = *m_p++; + + if (skipLine) { + skipLine = (c != '\n'); + continue; + } + + if (c.isLetter()) { + return CharNameBegin; + } + + if (c.isDigit()) { + return CharValueBegin; + } + + switch (c.unicode()) { + case '{': + return CharListBegin; + case '}': + return CharListEnd; + case '(': + return CharBracketBegin; + case ')': + return CharBracketEnd; + case '[': + return CharValueBegin; + case ',': + return CharValueSeparator; + case ':': + return CharColon; + case '#': { + skipLine = true; + } break; + } } - switch (c.unicode()) { - case '#': { - m_skipLine = true; - } break; - } + return CharNone; } diff --git a/src/ui/util/conf/ruletextparser.h b/src/ui/util/conf/ruletextparser.h index 466795f9..b24d059f 100644 --- a/src/ui/util/conf/ruletextparser.h +++ b/src/ui/util/conf/ruletextparser.h @@ -9,6 +9,7 @@ struct RuleExpr { quint8 flags = 0; + quint8 type = 0; quint16 listIndex = 0; quint16 listCount = 0; @@ -28,13 +29,26 @@ public: bool parse(); private: + enum CharType : qint8 { + CharNone = 0, + CharListBegin, // { + CharListEnd, // } + CharBracketBegin, // ( + CharBracketEnd, // ) + CharNameBegin, // a-zA-Z + CharName, // a-zA-Z0-9_- + CharValueBegin, // [0-9 + CharValue, // 0-9.:-/ + CharValueSeparator, // , + CharColon, // : + CharComment, // # + }; + void setupText(const QString &text); - void processChar(const QChar c); + RuleTextParser::CharType nextCharType(); private: - bool m_skipLine : 1 = false; - quint8 m_exprType = 0; const QChar *m_p = nullptr;