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];
} 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

View File

@ -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;
}

View File

@ -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;