add own config for Hostsfiles stuff #50

develop
Geoffrey Merck 1 year ago
parent 68c1562bf9
commit 340c322bf9

@ -170,7 +170,7 @@ bool CConfig::getValue(const std::string &section, const std::string& key, doubl
return true;
}
bool CConfig::getValue(const std::string &section, const std::string& key, unsigned int &value, unsigned int min, unsigned int max, int defaultValue) const
bool CConfig::getValue(const std::string &section, const std::string& key, unsigned int &value, unsigned int min, unsigned int max, unsigned int defaultValue) const
{
TConfigValue * val = lookupValue(section, key);
if(val == nullptr || val->m_value.empty()) {

@ -99,7 +99,7 @@ public:
bool getValue(const std::string &section, const std::string& key, bool &value, bool defaultValue) const;
bool getValue(const std::string &section, const std::string& key, int &value, int min, int max, int defaultValue) const;
bool getValue(const std::string &section, const std::string& key, double &value, double min, double max, double defaultValue) const;
bool getValue(const std::string &section, const std::string& key, unsigned int &value, unsigned int min, unsigned int max,int defaultValue) const;
bool getValue(const std::string &section, const std::string& key, unsigned int &value, unsigned int min, unsigned int max, unsigned int defaultValue) const;
bool getValue(const std::string &section, const std::string& key, unsigned char &value, unsigned char min, unsigned char max,unsigned char defaultValue) const;
bool getValue(const std::string &section, const std::string& key, std::string &value, unsigned int minLen, unsigned int maxLen, const std::string defaultValue) const;
bool getValue(const std::string &section, const std::string& key, std::string &value, const std::string defaultValue, const std::vector<std::string>& allowedValues) const;

@ -347,7 +347,10 @@ bool CDStarGatewayApp::createThread()
m_thread->setXLX(xlxConfig.enabled);
// Setup hostsfiles
CHostsFilesManager::setHostFilesDirectories(paths.dataDir, paths.customHostsFiles);
THostsFiles hostsFilesConfig;
m_config->getHostsFiles(hostsFilesConfig);
CHostsFilesManager::setHostFilesDirectories(hostsFilesConfig.downloadedHostFiles, hostsFilesConfig.customHostsFiles);
CHostsFilesManager::setDownloadTimeout(3600 * hostsFilesConfig.downloadTimeout);
CHostsFilesManager::setDextra(dextraConfig.enabled, dextraConfig.hostfileUrl);
CHostsFilesManager::setDCS (dcsConfig.enabled, dcsConfig.hostfileUrl);
CHostsFilesManager::setDPlus (dplusConfig.enabled, dplusConfig.hostfileUrl);

@ -45,6 +45,7 @@ bool CDStarGatewayConfig::load()
ret = loadIrcDDB(cfg) && ret;
ret = loadRepeaters(cfg) && ret;
ret = loadPaths(cfg) && ret;
ret = loadHostsFiles(cfg) && ret;
ret = loadLog(cfg) && ret;
ret = loadAPRS(cfg) && ret;
ret = loadDextra(cfg) && ret;
@ -195,14 +196,28 @@ bool CDStarGatewayConfig::loadLog(const CConfig & cfg)
bool CDStarGatewayConfig::loadPaths(const CConfig & cfg)
{
bool ret = cfg.getValue("paths", "data", m_paths.dataDir, 0, 2048, "/usr/local/share/dstargateway.d/");
ret = cfg.getValue("customHostfiles", "data", m_paths.customHostsFiles, 0, 2048, "/usr/local/share/dstargateway.d/hostfiles.d/") && ret;
if(ret && m_paths.dataDir[m_paths.dataDir.length() - 1] != '/') {
m_paths.dataDir.push_back('/');
}
if(ret && m_paths.dataDir[m_paths.customHostsFiles.length() - 1] != '/') {
m_paths.customHostsFiles.push_back('/');
//TODO 20211226 check if directory are accessible
return ret;
}
bool CDStarGatewayConfig::loadHostsFiles(const CConfig & cfg)
{
bool ret = cfg.getValue("HostsFiles", "downloadedHostsFiles", m_hostsFiles.downloadedHostFiles, 0, 2048, "/usr/local/share/dstargateway.d/");
ret = cfg.getValue("HostsFiles", "customHostsfiles", m_hostsFiles.customHostsFiles, 0, 2048, "/usr/local/share/dstargateway.d/hostsfiles.d/");
ret = cfg.getValue("HostsFiles", "downloadTimer", m_hostsFiles.downloadTimeout, 24U, 0xffffffffU, 72U);
if(ret && m_hostsFiles.downloadedHostFiles[m_hostsFiles.downloadedHostFiles.length() - 1] != '/') {
m_hostsFiles.downloadedHostFiles.push_back('/');
}
if(ret && m_hostsFiles.customHostsFiles[m_hostsFiles.customHostsFiles.length() - 1] != '/') {
m_hostsFiles.downloadedHostFiles.push_back('/');
}
//TODO 20211226 check if directory are accessible
@ -441,6 +456,11 @@ void CDStarGatewayConfig::getPaths(Tpaths & paths) const
paths = m_paths;
}
void CDStarGatewayConfig::getHostsFiles(THostsFiles & hostsFiles) const
{
hostsFiles = m_hostsFiles;
}
void CDStarGatewayConfig::getAPRS(TAPRS & aprs) const
{
aprs = m_aprs;

@ -80,9 +80,14 @@ typedef struct {
typedef struct {
std::string dataDir;
std::string customHostsFiles;
} Tpaths;
typedef struct {
std::string downloadedHostFiles;
std::string customHostsFiles;
unsigned int downloadTimeout;
} THostsFiles;
typedef struct {
std::string logDir;
LOG_SEVERITY displayLevel;
@ -160,6 +165,7 @@ public:
unsigned int getRepeaterCount() const;
void getLog(TLog& log) const;
void getPaths(Tpaths & paths) const;
void getHostsFiles(THostsFiles & hostsFiles) const;
void getAPRS(TAPRS & aprs) const;
void getDExtra(TDextra & dextra) const;
void getDPlus(TDplus & dplus) const;
@ -180,6 +186,7 @@ private:
bool loadRepeaters(const CConfig & cfg);
bool loadLog(const CConfig & cfg);
bool loadPaths(const CConfig & cfg);
bool loadHostsFiles(const CConfig & cfg);
bool loadAPRS(const CConfig & cfg);
bool loadDextra(const CConfig & cfg);
bool loadDPlus(const CConfig & cfg);
@ -196,6 +203,7 @@ private:
std::string m_fileName;
TGateway m_gateway;
Tpaths m_paths;
THostsFiles m_hostsFiles;
TAPRS m_aprs;
TDextra m_dextra;
TDplus m_dplus;

@ -155,10 +155,14 @@ displayLevel= # defaults to info, valid values are trace, debug, info, warning
repeatThreshold=#defaults to 2, valid values are disbaled and 1 to 10. Prevents flooding of logs from repeated log messages.
[Paths]
data=/usr/local/share/dstargateway.d/ # Path where the data (auto downbloaded hostfiles, audio files etc) can be found
customHostfiles=/usr/local/share/dstargateway.d/hostfiles.d/ # Place your custom host files in this directory, this dir must be different from datadir.
# Any hosts found here will override same host in downloaded files
data=/usr/local/share/dstargateway.d/ # Path where the data (audio files etc) can be found
[HostsFiles]
downloadedHostsFiles=/usr/local/share/dstargateway.d/ # Path where the downloaded host files are stored, make sure user dstar has write access
downloadTimer= # Redownload host files every X hours, must be greater than 24 hours. Defaults to 72 hours
customHostsfiles=/usr/local/share/dstargateway.d/hostfiles.d/ # Place your custom host files in this directory, this dir must be different from datadir.
# Any hosts found here will override same host in downloaded files
[DExtra]
enabled=true # There is no reason to disable this
maxDongles=5

Loading…
Cancel
Save

Powered by TurnKey Linux.