losen dependency #50

develop
Geoffrey Merck 1 year ago
parent 2f2adedbc5
commit eb5525b6fd

@ -19,7 +19,6 @@
#include <cassert>
#include "HostsFilesManager.h"
#include "HostsFileDownloader.h"
#include "HostFile.h"
#include "StringUtils.h"
#include "UDPReaderWriter.h"
@ -41,12 +40,19 @@ std::string CHostsFilesManager::m_xlxUrl("");
CCacheManager * CHostsFilesManager::m_cache = nullptr;
CTimer CHostsFilesManager::m_downloadTimer(1000U, 60 * 60 * 24);
HostFileDownloadCallback CHostsFilesManager::m_downloadCallback = nullptr;
void CHostsFilesManager::setHostFilesDirectories(const std::string & hostFilesDir, const std::string & customHostFilesDir)
{
m_hostFilesDirectory.assign(hostFilesDir);
m_customFilesDirectory.assign(customHostFilesDir);
}
void CHostsFilesManager::setDownloadCallback(HostFileDownloadCallback callback)
{
m_downloadCallback = callback;
}
void CHostsFilesManager::setDextra(bool enabled, const std::string & url)
{
m_dextraEnabled = enabled;
@ -97,10 +103,10 @@ bool CHostsFilesManager::UpdateHostsFromInternet()
{
CLog::logInfo("Updating hosts files from internet");
bool ret = true;
if(m_dextraEnabled && !m_dextraUrl.empty()) ret = CHostsFileDownloader::download(m_dextraUrl, m_hostFilesDirectory + "/" + DEXTRA_HOSTS_FILE_NAME) && ret;
if(m_dcsEnabled && !m_dcsUrl.empty()) ret = CHostsFileDownloader::download(m_dcsUrl, m_hostFilesDirectory + "/" + DCS_HOSTS_FILE_NAME) && ret;
if(m_dplusEnabled && !m_dplusUrl.empty()) ret = CHostsFileDownloader::download(m_dplusUrl, m_hostFilesDirectory + "/" + DPLUS_HOSTS_FILE_NAME) && ret;
if(m_xlxEnabled && !m_xlxUrl.empty()) ret = CHostsFileDownloader::download(m_xlxUrl, m_hostFilesDirectory + "/" + XLX_HOSTS_FILE_NAME) && ret;
if(m_dextraEnabled && !m_dextraUrl.empty()) ret = m_downloadCallback(m_dextraUrl, m_hostFilesDirectory + "/" + DEXTRA_HOSTS_FILE_NAME) && ret;
if(m_dcsEnabled && !m_dcsUrl.empty()) ret = m_downloadCallback(m_dcsUrl, m_hostFilesDirectory + "/" + DCS_HOSTS_FILE_NAME) && ret;
if(m_dplusEnabled && !m_dplusUrl.empty()) ret = m_downloadCallback(m_dplusUrl, m_hostFilesDirectory + "/" + DPLUS_HOSTS_FILE_NAME) && ret;
if(m_xlxEnabled && !m_xlxUrl.empty()) ret = m_downloadCallback(m_xlxUrl, m_hostFilesDirectory + "/" + XLX_HOSTS_FILE_NAME) && ret;
if(!ret) CLog::logWarning("Some hosts files failed to downlaod");

@ -26,9 +26,12 @@
#include "Timer.h"
#include "DStarDefines.h"
typedef bool (*HostFileDownloadCallback)(const std::string &, const std::string &);
class CHostsFilesManager {
public:
static void setHostFilesDirectories(const std::string & hostFilesDir, const std::string & customHostFilesDir);
static void setDownloadCallback(HostFileDownloadCallback downloadCallback);
static void setDextra(bool enabled, const std::string & dextraUrl);
static void setDCS(bool enabled, const std::string & dcsUrl);
static void setDPlus(bool enabled, const std::string & dplusUrl);
@ -58,6 +61,8 @@ private:
static CCacheManager * m_cache;
static CTimer m_downloadTimer;
static HostFileDownloadCallback m_downloadCallback;
static void loadReflectors(const std::string & directory);
static void loadReflectors(const std::string & hostFileName, DSTAR_PROTOCOL proto);
};

@ -55,6 +55,7 @@
#include "Log.h"
#include "StringUtils.h"
#include "HostsFilesManager.h"
#include "HostsFileDownloader.h"
const std::string LOOPBACK_ADDRESS("127.0.0.1");
@ -138,6 +139,7 @@ CDStarGatewayThread::~CDStarGatewayThread()
void* CDStarGatewayThread::Entry()
{
CHostsFilesManager::setCache(&m_cache);
CHostsFilesManager::setDownloadCallback(CHostsFileDownloader::download);
CHostsFilesManager::UpdateHosts();
// Truncate the old Links.log file

Loading…
Cancel
Save

Powered by TurnKey Linux.