UI: ConfUtil: Refactor writeConf()

This commit is contained in:
Nodir Temirkhodjaev 2024-10-28 11:15:41 +05:00
parent 190bb5bcc0
commit 26ad39851f
3 changed files with 18 additions and 14 deletions

View File

@ -271,9 +271,11 @@ bool ConfBuffer::write(
+ FORT_CONF_STR_DATA_SIZE(opt.prefixAppsSize)
+ FORT_CONF_STR_DATA_SIZE(opt.exeAppsSize));
buffer().resize(confIoSize);
buffer().resize(confIoSize); // shrink to actual size
ConfUtil::writeConf(buffer().data(), wca, opt);
char *data = buffer().data();
ConfUtil::writeConf(&data, wca, opt);
return true;
}

View File

@ -152,27 +152,29 @@ QString ConfUtil::parseAppPath(const QStringView &line, bool &isWild, bool &isPr
return path.toString();
}
void ConfUtil::writeConf(char *output, const WriteConfArgs &wca, AppParseOptions &opt)
void ConfUtil::writeConf(char **data, const WriteConfArgs &wca, AppParseOptions &opt)
{
PFORT_CONF_IO drvConfIo = (PFORT_CONF_IO) output;
PFORT_CONF_IO drvConfIo = PFORT_CONF_IO(*data);
PFORT_CONF drvConf = &drvConfIo->conf;
char *data = drvConf->data;
quint32 addrGroupsOff;
quint32 wildAppsOff, prefixAppsOff, exeAppsOff;
#define CONF_DATA_OFFSET quint32(data - drvConf->data)
*data = drvConf->data;
#define CONF_DATA_OFFSET quint32(*data - drvConf->data)
addrGroupsOff = CONF_DATA_OFFSET;
writeLongs(&data, wca.ad.addressGroupOffsets);
writeAddressRanges(&data, wca.ad.addressRanges);
writeLongs(data, wca.ad.addressGroupOffsets);
writeAddressRanges(data, wca.ad.addressRanges);
wildAppsOff = CONF_DATA_OFFSET;
writeApps(&data, opt.wildAppsMap);
writeApps(data, opt.wildAppsMap);
prefixAppsOff = CONF_DATA_OFFSET;
writeApps(&data, opt.prefixAppsMap, /*useHeader=*/true);
writeApps(data, opt.prefixAppsMap, /*useHeader=*/true);
exeAppsOff = CONF_DATA_OFFSET;
writeApps(&data, opt.exeAppsMap);
writeApps(data, opt.exeAppsMap);
#undef CONF_DATA_OFFSET
PFORT_CONF_GROUP conf_group = &drvConfIo->conf_group;
@ -181,8 +183,8 @@ void ConfUtil::writeConf(char *output, const WriteConfArgs &wca, AppParseOptions
writeLimits(conf_group, wca.conf.appGroups());
data = (char *) &drvConf->flags;
writeConfFlags(&data, wca.conf);
*data = (char *) &drvConf->flags;
writeConfFlags(data, wca.conf);
drvConf->proc_wild = opt.procWild;

View File

@ -42,7 +42,7 @@ public:
static QString parseAppPath(const QStringView &line, bool &isWild, bool &isPrefix);
static void writeConf(char *output, const WriteConfArgs &wca, AppParseOptions &opt);
static void writeConf(char **data, const WriteConfArgs &wca, AppParseOptions &opt);
static void writeConfFlags(char **data, const FirewallConf &conf);
static void writeAddressRanges(char **data, const addrranges_arr_t &addressRanges);