UI: ConfUtil: Simplify parseAppsText().

This commit is contained in:
Nodir Temirkhodjaev 2021-05-10 12:04:51 +03:00
parent a3334ba8b6
commit 482d80941a
2 changed files with 37 additions and 23 deletions

View File

@ -363,35 +363,23 @@ bool ConfUtil::parseAppsText(int groupIndex, bool blocked, const QString &text,
if (appPath.isEmpty())
continue;
appentry_map_t &appsMap = isWild ? wildAppsMap : (isPrefix ? prefixAppsMap : exeAppsMap);
quint32 &appsSize = isWild ? wildAppsSize : (isPrefix ? prefixAppsSize : exeAppsSize);
if (!addApp(groupIndex, true, blocked, false, true, appPath, appsMap, appsSize, false))
if (!addParsedApp(groupIndex, blocked, isWild, isPrefix, appPath, wildAppsMap,
prefixAppsMap, exeAppsMap, wildAppsSize, prefixAppsSize, exeAppsSize))
return false;
}
return true;
}
void ConfUtil::parseAppPeriod(
const AppGroup *appGroup, chars_arr_t &appPeriods, quint8 &appPeriodsCount)
bool ConfUtil::addParsedApp(int groupIndex, bool blocked, bool isWild, bool isPrefix,
const QString &appPath, appentry_map_t &wildAppsMap, appentry_map_t &prefixAppsMap,
appentry_map_t &exeAppsMap, quint32 &wildAppsSize, quint32 &prefixAppsSize,
quint32 &exeAppsSize)
{
quint8 fromHour = 0, fromMinute = 0;
quint8 toHour = 0, toMinute = 0;
appentry_map_t &appsMap = isWild ? wildAppsMap : (isPrefix ? prefixAppsMap : exeAppsMap);
quint32 &appsSize = isWild ? wildAppsSize : (isPrefix ? prefixAppsSize : exeAppsSize);
if (appGroup->periodEnabled()) {
DateUtil::parseTime(appGroup->periodFrom(), fromHour, fromMinute);
DateUtil::parseTime(appGroup->periodTo(), toHour, toMinute);
if (fromHour != 0 || fromMinute != 0 || toHour != 0 || toMinute != 0) {
++appPeriodsCount;
}
}
appPeriods.append(qint8(fromHour));
appPeriods.append(qint8(fromMinute));
appPeriods.append(qint8(toHour));
appPeriods.append(qint8(toMinute));
return addApp(groupIndex, true, blocked, false, true, appPath, appsMap, appsSize, false);
}
bool ConfUtil::addApp(int groupIndex, bool useGroupPerm, bool blocked, bool alerted, bool isNew,
@ -455,6 +443,27 @@ QString ConfUtil::parseAppPath(const StringView line, bool &isWild, bool &isPref
return path.toString();
}
void ConfUtil::parseAppPeriod(
const AppGroup *appGroup, chars_arr_t &appPeriods, quint8 &appPeriodsCount)
{
quint8 fromHour = 0, fromMinute = 0;
quint8 toHour = 0, toMinute = 0;
if (appGroup->periodEnabled()) {
DateUtil::parseTime(appGroup->periodFrom(), fromHour, fromMinute);
DateUtil::parseTime(appGroup->periodTo(), toHour, toMinute);
if (fromHour != 0 || fromMinute != 0 || toHour != 0 || toMinute != 0) {
++appPeriodsCount;
}
}
appPeriods.append(qint8(fromHour));
appPeriods.append(qint8(fromMinute));
appPeriods.append(qint8(toHour));
appPeriods.append(qint8(toMinute));
}
void ConfUtil::writeData(char *output, const FirewallConf &conf,
const addrranges_arr_t &addressRanges, const longs_arr_t &addressGroupOffsets,
const chars_arr_t &appPeriods, quint8 appPeriodsCount, const appentry_map_t &wildAppsMap,

View File

@ -73,8 +73,10 @@ private:
appentry_map_t &wildAppsMap, appentry_map_t &prefixAppsMap, appentry_map_t &exeAppsMap,
quint32 &wildAppsSize, quint32 &prefixAppsSize, quint32 &exeAppsSize);
static void parseAppPeriod(
const AppGroup *appGroup, chars_arr_t &appPeriods, quint8 &appPeriodsCount);
bool addParsedApp(int groupIndex, bool blocked, bool isWild, bool isPrefix,
const QString &appPath, appentry_map_t &wildAppsMap, appentry_map_t &prefixAppsMap,
appentry_map_t &exeAppsMap, quint32 &wildAppsSize, quint32 &prefixAppsSize,
quint32 &exeAppsSize);
bool addApp(int groupIndex, bool useGroupPerm, bool blocked, bool alerted, bool isNew,
const QString &appPath, appentry_map_t &appsMap, quint32 &appsSize,
@ -82,6 +84,9 @@ private:
static QString parseAppPath(const StringView line, bool &isWild, bool &isPrefix);
static void parseAppPeriod(
const AppGroup *appGroup, chars_arr_t &appPeriods, quint8 &appPeriodsCount);
static void writeData(char *output, const FirewallConf &conf,
const addrranges_arr_t &addressRanges, const longs_arr_t &addressGroupOffsets,
const chars_arr_t &appPeriods, quint8 appPeriodsCount,