Driver: fortconf: Tweak rule expr flags

This commit is contained in:
Nodir Temirkhodjaev 2024-06-03 12:42:10 +03:00
parent aeb7e7115a
commit 38d62506b3
3 changed files with 76 additions and 24 deletions

View File

@ -110,18 +110,28 @@ typedef struct fort_conf_addr_group
char data[4]; char data[4];
} FORT_CONF_ADDR_GROUP, *PFORT_CONF_ADDR_GROUP; } FORT_CONF_ADDR_GROUP, *PFORT_CONF_ADDR_GROUP;
#define FORT_RULE_EXPR_NOT 0x01 #define FORT_RULE_EXPR_FLAG_LIST 0x01
#define FORT_RULE_EXPR_LIST 0x02 #define FORT_RULE_EXPR_FLAG_NOT 0x02
#define FORT_RULE_EXPR_LOCAL 0x04
#define FORT_RULE_EXPR_ADDRESS 0x08 enum FortRuleExprList {
#define FORT_RULE_EXPR_PORT 0x10 FORT_RULE_EXPR_LIST_OR = 0,
#define FORT_RULE_EXPR_PROTOCOL 0x20 FORT_RULE_EXPR_LIST_AND,
#define FORT_RULE_EXPR_DIRECTION 0x40 };
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 typedef struct fort_conf_rule_expr
{ {
UINT32 flags : 8; UINT32 flags : 2;
UINT32 size : 24; UINT32 type : 3;
UINT32 size : 27;
} FORT_CONF_RULE_EXPR, *PFORT_CONF_RULE_EXPR; } FORT_CONF_RULE_EXPR, *PFORT_CONF_RULE_EXPR;
typedef struct fort_conf_rule_zones typedef struct fort_conf_rule_zones

View File

@ -15,23 +15,51 @@ void RuleTextParser::setupText(const QString &text)
bool RuleTextParser::parse() bool RuleTextParser::parse()
{ {
while (m_p < m_end) { const auto charType = nextCharType();
processChar(*m_p++);
}
return false; return false;
} }
void RuleTextParser::processChar(const QChar c) RuleTextParser::CharType RuleTextParser::nextCharType()
{ {
if (m_skipLine) { bool skipLine = false;
m_skipLine = (c != '\n');
return; 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()) { return CharNone;
case '#': {
m_skipLine = true;
} break;
}
} }

View File

@ -9,6 +9,7 @@
struct RuleExpr struct RuleExpr
{ {
quint8 flags = 0; quint8 flags = 0;
quint8 type = 0;
quint16 listIndex = 0; quint16 listIndex = 0;
quint16 listCount = 0; quint16 listCount = 0;
@ -28,13 +29,26 @@ public:
bool parse(); bool parse();
private: 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 setupText(const QString &text);
void processChar(const QChar c); RuleTextParser::CharType nextCharType();
private: private:
bool m_skipLine : 1 = false;
quint8 m_exprType = 0; quint8 m_exprType = 0;
const QChar *m_p = nullptr; const QChar *m_p = nullptr;