refactor: Remove CUrlList

Nowadays most of the loadbalancing is done on the server-side and hence
there is only a single datafile URL (and other URLs) inside the
boostrap.json.
The features of the CUrlList are hence not really used. This is also a
step into removing CUrl and using QUrl instead, to avoid maintaining a
separate URL class.
This commit is contained in:
Lars Toenning
2024-02-09 16:32:45 +01:00
parent 0d62facea7
commit 14c045e7b4
26 changed files with 153 additions and 584 deletions

View File

@@ -9,30 +9,18 @@
"ncepGlobalForecastSystemUrl25": { "ncepGlobalForecastSystemUrl25": {
"url": "http://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_0p25.pl" "url": "http://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_0p25.pl"
}, },
"onlineHelpUrls": { "onlineHelpUrl": {
"containerbase": [
{
"url": "https://datastore.swift-project.org/page/swifthelpdispatcher.html" "url": "https://datastore.swift-project.org/page/swifthelpdispatcher.html"
}
]
}, },
"predefinedServers": { "predefinedServers": {
"containerbase": [ "containerbase": [
] ]
}, },
"sharedUrls": { "sharedUrl": {
"containerbase": [
{
"url": "http://download.swift-project.org/shared/" "url": "http://download.swift-project.org/shared/"
}
]
}, },
"vatsimDataFileUrls": { "vatsimDataFileUrl": {
"containerbase": [
{
"url": "https://data.vatsim.net/v3/vatsim-data.json" "url": "https://data.vatsim.net/v3/vatsim-data.json"
}
]
}, },
"vatsimServerFileUrl": { "vatsimServerFileUrl": {
"url": "https://data.vatsim.net/v3/vatsim-servers.json" "url": "https://data.vatsim.net/v3/vatsim-servers.json"
@@ -40,19 +28,11 @@
"vatsimFsdHttpUrl": { "vatsimFsdHttpUrl": {
"url": "http://fsd.vatsim.net" "url": "http://fsd.vatsim.net"
}, },
"vatsimMetarsUrls": { "vatsimMetarsUrl": {
"containerbase": [
{
"url": "http://metar.vatsim.net/metar.php" "url": "http://metar.vatsim.net/metar.php"
}
]
}, },
"vatsimStatusFileUrls": { "vatsimStatusFileUrl": {
"containerbase": [
{
"url": "https://status.vatsim.net" "url": "https://status.vatsim.net"
}
]
}, },
"comNavEquipmentHelpUrl": { "comNavEquipmentHelpUrl": {
"url": "https://en.wikipedia.org/wiki/Equipment_codes#Radio_communication,_navigation_and_approach_aid_equipment_and_capabilities" "url": "https://en.wikipedia.org/wiki/Equipment_codes#Radio_communication,_navigation_and_approach_aid_equipment_and_capabilities"

View File

@@ -87,8 +87,6 @@
{ include: [ "\"fileutils.h\"", "private", "\"blackmisc/fileutils.h\"", "public" ] }, { include: [ "\"fileutils.h\"", "private", "\"blackmisc/fileutils.h\"", "public" ] },
{ include: [ "\"network/serverlist.h\"", "private", "\"blackmisc/network/serverlist.h\"", "public" ] }, { include: [ "\"network/serverlist.h\"", "private", "\"blackmisc/network/serverlist.h\"", "public" ] },
{ include: [ "\"serverlist.h\"", "private", "\"blackmisc/network/serverlist.h\"", "public" ] }, { include: [ "\"serverlist.h\"", "private", "\"blackmisc/network/serverlist.h\"", "public" ] },
{ include: [ "\"network/urllist.h\"", "private", "\"blackmisc/network/urllist.h\"", "public" ] },
{ include: [ "\"urllist.h\"", "private", "\"blackmisc/network/urllist.h\"", "public" ] },
{ include: [ "\"network/server.h\"", "private", "\"blackmisc/network/server.h\"", "public" ] }, { include: [ "\"network/server.h\"", "private", "\"blackmisc/network/server.h\"", "public" ] },
{ include: [ "\"server.h\"", "private", "\"blackmisc/network/server.h\"", "public" ] }, { include: [ "\"server.h\"", "private", "\"blackmisc/network/server.h\"", "public" ] },
{ include: [ "\"network/user.h\"", "private", "\"blackmisc/network/user.h\"", "public" ] }, { include: [ "\"network/user.h\"", "private", "\"blackmisc/network/user.h\"", "public" ] },

View File

@@ -1337,34 +1337,34 @@ namespace BlackCore
return requestMsgs; return requestMsgs;
} }
CUrlList CApplication::getVatsimMetarUrls() const CUrl CApplication::getVatsimMetarUrl() const
{ {
if (m_shutdown) { return CUrlList(); } if (m_shutdown) { return {}; }
if (m_webDataServices) if (m_webDataServices)
{ {
const CUrlList urls(m_webDataServices->getVatsimMetarUrls()); const CUrl url(m_webDataServices->getVatsimMetarUrl());
if (!urls.isEmpty()) { return urls; } if (!url.isEmpty()) { return url; }
} }
if (m_setupReader) if (m_setupReader)
{ {
return m_setupReader->getSetup().getVatsimMetarsUrls(); return m_setupReader->getSetup().getVatsimMetarsUrl();
} }
return CUrlList(); return {};
} }
CUrlList CApplication::getVatsimDataFileUrls() const CUrl CApplication::getVatsimDataFileUrl() const
{ {
if (m_shutdown) { return CUrlList(); } if (m_shutdown) { return {}; }
if (m_webDataServices) if (m_webDataServices)
{ {
const CUrlList urls(m_webDataServices->getVatsimDataFileUrls()); const CUrl url(m_webDataServices->getVatsimDataFileUrl());
if (!urls.isEmpty()) { return urls; } if (!url.isEmpty()) { return url; }
} }
if (m_setupReader) if (m_setupReader)
{ {
return m_setupReader->getSetup().getVatsimDataFileUrls(); return m_setupReader->getSetup().getVatsimDataFileUrl();
} }
return CUrlList(); return {};
} }
CUrl CApplication::getVatsimServerFileUrl() const CUrl CApplication::getVatsimServerFileUrl() const

View File

@@ -15,7 +15,7 @@
#include "blackcore/inputmanager.h" #include "blackcore/inputmanager.h"
#include "blackcore/webreaderflags.h" #include "blackcore/webreaderflags.h"
#include "blackmisc/db/updateinfo.h" #include "blackmisc/db/updateinfo.h"
#include "blackmisc/network/urllist.h" #include "blackmisc/network/url.h"
#include "blackmisc/network/networkutils.h" #include "blackmisc/network/networkutils.h"
#include "blackmisc/identifiable.h" #include "blackmisc/identifiable.h"
#include "blackmisc/slot.h" #include "blackmisc/slot.h"
@@ -395,11 +395,11 @@ namespace BlackCore
//! Consolidated version of METAR URLs, either from CGlobalSetup or CVatsimSetup //! Consolidated version of METAR URLs, either from CGlobalSetup or CVatsimSetup
//! \threadsafe //! \threadsafe
BlackMisc::Network::CUrlList getVatsimMetarUrls() const; BlackMisc::Network::CUrl getVatsimMetarUrl() const;
//! Consolidated version of data file URLs, either from CGlobalSetup or CVatsimSetup //! Consolidated version of data file URL, either from CGlobalSetup or CVatsimSetup
//! \threadsafe //! \threadsafe
BlackMisc::Network::CUrlList getVatsimDataFileUrls() const; BlackMisc::Network::CUrl getVatsimDataFileUrl() const;
//! Get URL to file which contains the list of VATSIM servers //! Get URL to file which contains the list of VATSIM servers
BlackMisc::Network::CUrl getVatsimServerFileUrl() const; BlackMisc::Network::CUrl getVatsimServerFileUrl() const;

View File

@@ -50,11 +50,10 @@ namespace BlackCore::Data
return getDbRootDirectoryUrl(); return getDbRootDirectoryUrl();
} }
const CUrlList &CGlobalSetup::getSwiftSharedUrls() const const CUrl &CGlobalSetup::getSwiftSharedUrl() const
{ {
return m_sharedUrls; return m_sharedUrl;
} }
CUrl CGlobalSetup::getDbHomePageUrl() const CUrl CGlobalSetup::getDbHomePageUrl() const
{ {
return getDbRootDirectoryUrl().withAppendedPath("/page/index.php"); return getDbRootDirectoryUrl().withAppendedPath("/page/index.php");
@@ -62,11 +61,9 @@ namespace BlackCore::Data
CUrl CGlobalSetup::getHelpPageUrl(const QString &context) const CUrl CGlobalSetup::getHelpPageUrl(const QString &context) const
{ {
const CUrlList urls(m_onlineHelpUrls);
// we display in the standard browser, // we display in the standard browser,
// so the user will realize if the URL does not work // so the user will realize if the URL does not work
CUrl url = (urls.size() < 2) ? urls.frontOrDefault() : urls.getRandomUrl(); CUrl url = m_onlineHelpUrl;
if (url.isEmpty()) { return url; } if (url.isEmpty()) { return url; }
// context string something like "application.moreSpecific.evenMoreSpecific" // context string something like "application.moreSpecific.evenMoreSpecific"
@@ -148,11 +145,11 @@ namespace BlackCore::Data
QString s = QString s =
u"Global setup loaded: " % separator % u"Mapping min.version: " % this->getMappingMinimumVersionString() % separator u"Global setup loaded: " % separator % u"Mapping min.version: " % this->getMappingMinimumVersionString() % separator
% u"Help URLs: " % m_onlineHelpUrls.toQString(i18n) % separator; % u"Help URL: " % m_onlineHelpUrl.toQString(i18n) % separator;
s += s +=
u"DB root directory: " % getDbRootDirectoryUrl().toQString(i18n) % separator % u"ICAO DB reader: " % getDbIcaoReaderUrl().toQString(i18n) % separator % u"Model DB reader: " % getDbModelReaderUrl().toQString(i18n) % separator % u"Airport DB reader: " % getDbAirportReaderUrl().toQString(i18n) % separator % u"DB home page: " % getDbHomePageUrl().toQString(i18n) % separator % u"DB login service: " % getDbLoginServiceUrl().toQString(i18n) % separator; u"DB root directory: " % getDbRootDirectoryUrl().toQString(i18n) % separator % u"ICAO DB reader: " % getDbIcaoReaderUrl().toQString(i18n) % separator % u"Model DB reader: " % getDbModelReaderUrl().toQString(i18n) % separator % u"Airport DB reader: " % getDbAirportReaderUrl().toQString(i18n) % separator % u"DB home page: " % getDbHomePageUrl().toQString(i18n) % separator % u"DB login service: " % getDbLoginServiceUrl().toQString(i18n) % separator;
s += s +=
u"VATSIM METARs: " % getVatsimMetarsUrls().toQString(i18n) % separator % u"VATSIM data file: " % getVatsimDataFileUrls().toQString(i18n) % separator % u"VATSIM server file: " % getVatsimServerFileUrl().toQString(i18n) % separator u"VATSIM METARs: " % getVatsimMetarsUrl().toQString(i18n) % separator % u"VATSIM data file: " % getVatsimDataFileUrl().toQString(i18n) % separator % u"VATSIM server file: " % getVatsimServerFileUrl().toQString(i18n) % separator
% u"Predefined servers: " % getPredefinedServers().toQString(i18n) % separator % u"Predefined servers: " % getPredefinedServers().toQString(i18n) % separator
@@ -174,8 +171,8 @@ namespace BlackCore::Data
case IndexDbHttpPort: return QVariant::fromValue(m_dbHttpPort); case IndexDbHttpPort: return QVariant::fromValue(m_dbHttpPort);
case IndexDbHttpsPort: return QVariant::fromValue(m_dbHttpsPort); case IndexDbHttpsPort: return QVariant::fromValue(m_dbHttpsPort);
case IndexDbLoginService: return QVariant::fromValue(this->getDbLoginServiceUrl()); case IndexDbLoginService: return QVariant::fromValue(this->getDbLoginServiceUrl());
case IndexVatsimStatus: return QVariant::fromValue(m_vatsimStatusFileUrls); case IndexVatsimStatus: return QVariant::fromValue(m_vatsimStatusFileUrl);
case IndexVatsimData: return QVariant::fromValue(m_vatsimDataFileUrls); case IndexVatsimData: return QVariant::fromValue(m_vatsimDataFileUrl);
case IndexVatsimServer: return QVariant::fromValue(m_vatsimServerFileUrl); case IndexVatsimServer: return QVariant::fromValue(m_vatsimServerFileUrl);
case IndexVatsimHttpFsd: return QVariant::fromValue(m_vatsimFsdHttpUrl); case IndexVatsimHttpFsd: return QVariant::fromValue(m_vatsimFsdHttpUrl);
case IndexVatsimMetars: return QVariant::fromValue(m_vatsimMetarsUrl); case IndexVatsimMetars: return QVariant::fromValue(m_vatsimMetarsUrl);
@@ -204,12 +201,12 @@ namespace BlackCore::Data
case IndexDbHttpPort: m_dbHttpPort = variant.toInt(); break; case IndexDbHttpPort: m_dbHttpPort = variant.toInt(); break;
case IndexDbHttpsPort: m_dbHttpsPort = variant.toInt(); break; case IndexDbHttpsPort: m_dbHttpsPort = variant.toInt(); break;
case IndexDbLoginService: break; // cannot be changed case IndexDbLoginService: break; // cannot be changed
case IndexVatsimData: m_vatsimDataFileUrls = variant.value<CUrlList>(); break; case IndexVatsimData: m_vatsimDataFileUrl = variant.value<CUrl>(); break;
case IndexVatsimServer: m_vatsimServerFileUrl = variant.value<CUrl>(); break; case IndexVatsimServer: m_vatsimServerFileUrl = variant.value<CUrl>(); break;
case IndexVatsimHttpFsd: m_vatsimFsdHttpUrl = variant.value<CUrl>(); break; case IndexVatsimHttpFsd: m_vatsimFsdHttpUrl = variant.value<CUrl>(); break;
case IndexVatsimMetars: m_vatsimMetarsUrls = variant.value<CUrlList>(); break; case IndexVatsimMetars: m_vatsimMetarsUrl = variant.value<CUrl>(); break;
case IndexSharedUrls: m_sharedUrls = variant.value<CUrlList>(); break; case IndexSharedUrl: m_sharedUrl = variant.value<CUrl>(); break;
case IndexOnlineHelpUrls: m_onlineHelpUrls = variant.value<CUrlList>(); break; case IndexOnlineHelpUrl: m_onlineHelpUrl = variant.value<CUrl>(); break;
case IndexMappingMinimumVersion: m_mappingMinimumVersion = variant.toString(); break; case IndexMappingMinimumVersion: m_mappingMinimumVersion = variant.toString(); break;
case IndexPredefinedServers: m_predefinedServers = variant.value<CServerList>(); break; case IndexPredefinedServers: m_predefinedServers = variant.value<CServerList>(); break;
case IndexAfvApiServerUrl: m_afvApiServerUrl = variant.value<CUrl>(); break; case IndexAfvApiServerUrl: m_afvApiServerUrl = variant.value<CUrl>(); break;

View File

@@ -9,7 +9,6 @@
#include "blackcore/blackcoreexport.h" #include "blackcore/blackcoreexport.h"
#include "blackmisc/network/serverlist.h" #include "blackmisc/network/serverlist.h"
#include "blackmisc/network/url.h" #include "blackmisc/network/url.h"
#include "blackmisc/network/urllist.h"
#include "blackmisc/identifiable.h" #include "blackmisc/identifiable.h"
#include "blackmisc/datacache.h" #include "blackmisc/datacache.h"
#include "blackmisc/metaclass.h" #include "blackmisc/metaclass.h"
@@ -43,8 +42,8 @@ namespace BlackCore::Data
IndexVatsimData, IndexVatsimData,
IndexVatsimServer, IndexVatsimServer,
IndexVatsimHttpFsd, IndexVatsimHttpFsd,
IndexOnlineHelpUrls, IndexOnlineHelpUrl,
IndexSharedUrls, IndexSharedUrl,
IndexMappingMinimumVersion, IndexMappingMinimumVersion,
IndexPredefinedServers, IndexPredefinedServers,
IndexAfvApiServerUrl, IndexAfvApiServerUrl,
@@ -97,17 +96,17 @@ namespace BlackCore::Data
//! \remark based on getDbRootDirectoryUrl //! \remark based on getDbRootDirectoryUrl
BlackMisc::Network::CUrl getDbLoginServiceUrl() const; BlackMisc::Network::CUrl getDbLoginServiceUrl() const;
//! Shared URLs //! Shared URL
const BlackMisc::Network::CUrlList &getSwiftSharedUrls() const; const BlackMisc::Network::CUrl &getSwiftSharedUrl() const;
//! VATSIM METAR URL //! VATSIM METAR URL
const BlackMisc::Network::CUrlList &getVatsimMetarsUrls() const { return m_vatsimMetarsUrls; } const BlackMisc::Network::CUrl &getVatsimMetarsUrl() const { return m_vatsimMetarsUrl; }
//! VATSIM status file URLs //! VATSIM status file URL
const BlackMisc::Network::CUrlList &getVatsimStatusFileUrls() const { return m_vatsimStatusFileUrls; } const BlackMisc::Network::CUrl &getVatsimStatusFileUrl() const { return m_vatsimStatusFileUrl; }
//! VATSIM data file URLs //! VATSIM data file URL
const BlackMisc::Network::CUrlList &getVatsimDataFileUrls() const { return m_vatsimDataFileUrls; } const BlackMisc::Network::CUrl &getVatsimDataFileUrl() const { return m_vatsimDataFileUrl; }
//! VATSIM server file URL //! VATSIM server file URL
BlackMisc::Network::CUrl getVatsimServerFileUrl() const { return m_vatsimServerFileUrl; } BlackMisc::Network::CUrl getVatsimServerFileUrl() const { return m_vatsimServerFileUrl; }
@@ -116,7 +115,6 @@ namespace BlackCore::Data
BlackMisc::Network::CUrl getVatsimFsdHttpUrl() const { return m_vatsimFsdHttpUrl; } BlackMisc::Network::CUrl getVatsimFsdHttpUrl() const { return m_vatsimFsdHttpUrl; }
//! Help page URL //! Help page URL
//! \remark working URL evaluated at runtime, based on getOnlineHelpUrls
BlackMisc::Network::CUrl getHelpPageUrl(const QString &context = {}) const; BlackMisc::Network::CUrl getHelpPageUrl(const QString &context = {}) const;
//! Predefined servers //! Predefined servers
@@ -171,13 +169,13 @@ namespace BlackCore::Data
int m_dbHttpsPort = 443; //!< SSL port int m_dbHttpsPort = 443; //!< SSL port
QString m_mappingMinimumVersion; //!< minimum version QString m_mappingMinimumVersion; //!< minimum version
BlackMisc::Network::CUrl m_dbRootDirectoryUrl; //!< Root directory of DB BlackMisc::Network::CUrl m_dbRootDirectoryUrl; //!< Root directory of DB
BlackMisc::Network::CUrlList m_vatsimMetarsUrls; //!< METAR data BlackMisc::Network::CUrl m_vatsimMetarsUrl; //!< METAR data
BlackMisc::Network::CUrlList m_vatsimStatusFileUrls; //!< Status file, where to find the VATSIM files (METAR, data, ATIS, other status files) BlackMisc::Network::CUrl m_vatsimStatusFileUrl; //!< Status file, where to find the VATSIM files (METAR, data, ATIS, other status files)
BlackMisc::Network::CUrlList m_vatsimDataFileUrls; //!< Overall VATSIM data file / merely for bootstrapping the first time BlackMisc::Network::CUrl m_vatsimDataFileUrl; //!< Overall VATSIM data file / merely for bootstrapping the first time
BlackMisc::Network::CUrl m_vatsimServerFileUrl; //!< URL to list of VATSIM servers BlackMisc::Network::CUrl m_vatsimServerFileUrl; //!< URL to list of VATSIM servers
BlackMisc::Network::CUrl m_vatsimFsdHttpUrl; //!< URL to HTTP FSD server (for load-balancing and automatic server selection) BlackMisc::Network::CUrl m_vatsimFsdHttpUrl; //!< URL to HTTP FSD server (for load-balancing and automatic server selection)
BlackMisc::Network::CUrlList m_sharedUrls; //!< where we can obtain shared info files such as bootstrap, .. BlackMisc::Network::CUrl m_sharedUrl; //!< where we can obtain shared info files such as bootstrap, ..
BlackMisc::Network::CUrlList m_onlineHelpUrls; //!< online help URLs BlackMisc::Network::CUrl m_onlineHelpUrl; //!< online help URL
BlackMisc::Network::CServerList m_predefinedServers; //!< Predefined servers loaded from setup file BlackMisc::Network::CServerList m_predefinedServers; //!< Predefined servers loaded from setup file
BlackMisc::Network::CUrl m_ncepGlobalForecastSystemUrl25; //!< NCEP GFS url 0.25 degree resolution BlackMisc::Network::CUrl m_ncepGlobalForecastSystemUrl25; //!< NCEP GFS url 0.25 degree resolution
BlackMisc::Network::CUrl m_comNavEquipmentHelpUrl; //!< Help URL for COM/NAV equipment codes BlackMisc::Network::CUrl m_comNavEquipmentHelpUrl; //!< Help URL for COM/NAV equipment codes
@@ -191,13 +189,13 @@ namespace BlackCore::Data
BLACK_METAMEMBER(dbRootDirectoryUrl, 0, RequiredForJson), BLACK_METAMEMBER(dbRootDirectoryUrl, 0, RequiredForJson),
BLACK_METAMEMBER(dbHttpPort, 0, RequiredForJson), BLACK_METAMEMBER(dbHttpPort, 0, RequiredForJson),
BLACK_METAMEMBER(dbHttpsPort, 0, RequiredForJson), BLACK_METAMEMBER(dbHttpsPort, 0, RequiredForJson),
BLACK_METAMEMBER(vatsimStatusFileUrls, 0, RequiredForJson), BLACK_METAMEMBER(vatsimStatusFileUrl, 0, RequiredForJson),
BLACK_METAMEMBER(vatsimDataFileUrls, 0, RequiredForJson), BLACK_METAMEMBER(vatsimDataFileUrl, 0, RequiredForJson),
BLACK_METAMEMBER(vatsimServerFileUrl, 0, RequiredForJson), BLACK_METAMEMBER(vatsimServerFileUrl, 0, RequiredForJson),
BLACK_METAMEMBER(vatsimFsdHttpUrl, 0, RequiredForJson), BLACK_METAMEMBER(vatsimFsdHttpUrl, 0, RequiredForJson),
BLACK_METAMEMBER(vatsimMetarsUrls, 0, RequiredForJson), BLACK_METAMEMBER(vatsimMetarsUrl, 0, RequiredForJson),
BLACK_METAMEMBER(sharedUrls, 0, RequiredForJson), BLACK_METAMEMBER(sharedUrl, 0, RequiredForJson),
BLACK_METAMEMBER(onlineHelpUrls, 0, RequiredForJson), BLACK_METAMEMBER(onlineHelpUrl, 0, RequiredForJson),
BLACK_METAMEMBER(predefinedServers, 0, RequiredForJson), BLACK_METAMEMBER(predefinedServers, 0, RequiredForJson),
BLACK_METAMEMBER(mappingMinimumVersion, 0, RequiredForJson), BLACK_METAMEMBER(mappingMinimumVersion, 0, RequiredForJson),
BLACK_METAMEMBER(ncepGlobalForecastSystemUrl25, 0, RequiredForJson), BLACK_METAMEMBER(ncepGlobalForecastSystemUrl25, 0, RequiredForJson),

View File

@@ -14,12 +14,12 @@ namespace BlackCore::Data
CVatsimSetup::CVatsimSetup() : ITimestampBased(0) CVatsimSetup::CVatsimSetup() : ITimestampBased(0)
{} {}
bool CVatsimSetup::setUrls(const CUrlList &dataFileUrls, const CUrlList &serverFileUrls, const CUrlList &metarFileUrls) bool CVatsimSetup::setUrls(const CUrl &dataFileUrl, const CUrl &serverFileUrl, const CUrl &metarFileUrl)
{ {
const bool changed = (dataFileUrls != getDataFileUrls() || serverFileUrls != getServerFileUrls() || metarFileUrls != getMetarFileUrls()); const bool changed = (dataFileUrl != getDataFileUrl() || serverFileUrl != getServerFileUrl() || metarFileUrl != getMetarFileUrl());
this->setServerFileUrls(serverFileUrls); this->setServerFileUrl(serverFileUrl);
this->setMetarFileUrls(metarFileUrls); this->setMetarFileUrl(metarFileUrl);
this->setDataFileUrls(dataFileUrls); this->setDataFileUrl(dataFileUrl);
return changed; return changed;
} }
@@ -43,7 +43,7 @@ namespace BlackCore::Data
s.append(separator); s.append(separator);
s.append("VATSIM data file: "); s.append("VATSIM data file: ");
s.append(getDataFileUrls().toQString(i18n)); s.append(getDataFileUrl().toQString(i18n));
s.append(separator); s.append(separator);
s.append("FSD servers: "); s.append("FSD servers: ");
@@ -60,7 +60,7 @@ namespace BlackCore::Data
switch (i) switch (i)
{ {
case IndexFsdServers: return QVariant::fromValue(this->m_fsdServers); case IndexFsdServers: return QVariant::fromValue(this->m_fsdServers);
case IndexDataFiles: return QVariant::fromValue(this->m_dataFileUrls); case IndexDataFiles: return QVariant::fromValue(this->m_dataFileUrl);
default: return CValueObject::propertyByIndex(index); default: return CValueObject::propertyByIndex(index);
} }
} }
@@ -82,7 +82,7 @@ namespace BlackCore::Data
switch (i) switch (i)
{ {
case IndexFsdServers: this->m_fsdServers = variant.value<CServerList>(); break; case IndexFsdServers: this->m_fsdServers = variant.value<CServerList>(); break;
case IndexDataFiles: this->m_dataFileUrls = variant.value<CUrlList>(); break; case IndexDataFiles: this->m_dataFileUrl = variant.value<CUrl>(); break;
default: CValueObject::setPropertyByIndex(index, variant); break; default: CValueObject::setPropertyByIndex(index, variant); break;
} }
} }

View File

@@ -10,7 +10,7 @@
#include "blackmisc/datacache.h" #include "blackmisc/datacache.h"
#include "blackmisc/metaclass.h" #include "blackmisc/metaclass.h"
#include "blackmisc/network/serverlist.h" #include "blackmisc/network/serverlist.h"
#include "blackmisc/network/urllist.h" #include "blackmisc/network/url.h"
#include "blackmisc/network/user.h" #include "blackmisc/network/user.h"
#include "blackmisc/propertyindex.h" #include "blackmisc/propertyindex.h"
#include "blackmisc/timestampbased.h" #include "blackmisc/timestampbased.h"
@@ -43,26 +43,26 @@ namespace BlackCore::Data
//! Default constructor //! Default constructor
CVatsimSetup(); CVatsimSetup();
//! VATSIM data file URLs //! VATSIM data file URL
const BlackMisc::Network::CUrlList &getDataFileUrls() const { return m_dataFileUrls; } const BlackMisc::Network::CUrl &getDataFileUrl() const { return m_dataFileUrl; }
//! Set VATSIM data file URLs //! Set VATSIM data file URL
void setDataFileUrls(const BlackMisc::Network::CUrlList &urls) { m_dataFileUrls = urls; } void setDataFileUrl(const BlackMisc::Network::CUrl &url) { m_dataFileUrl = url; }
//! Server file URLs (like data file, only servers) //! Server file URL
const BlackMisc::Network::CUrlList &getServerFileUrls() const { return m_serverFileUrls; } const BlackMisc::Network::CUrl &getServerFileUrl() const { return m_serverFileUrl; }
//! Set server file URLs (like data file, only servers) //! Set server file URL
void setServerFileUrls(const BlackMisc::Network::CUrlList &urls) { m_serverFileUrls = urls; } void setServerFileUrl(const BlackMisc::Network::CUrl &url) { m_serverFileUrl = url; }
//! METAR file URLs //! METAR file URL
const BlackMisc::Network::CUrlList &getMetarFileUrls() const { return m_metarFileUrls; } const BlackMisc::Network::CUrl &getMetarFileUrl() const { return m_metarFileUrl; }
//! METAR file URLs //! METAR file URL
void setMetarFileUrls(const BlackMisc::Network::CUrlList &urls) { m_metarFileUrls = urls; } void setMetarFileUrl(const BlackMisc::Network::CUrl &url) { m_metarFileUrl = url; }
//! Set all URLs and indicate if something has changed //! Set all URLs and indicate if something has changed
bool setUrls(const BlackMisc::Network::CUrlList &dataFileUrls, const BlackMisc::Network::CUrlList &serverFileUrls, const BlackMisc::Network::CUrlList &metarFileUrls); bool setUrls(const BlackMisc::Network::CUrl &dataFileUrl, const BlackMisc::Network::CUrl &serverFileUrl, const BlackMisc::Network::CUrl &metarFileUrl);
//! FSD servers //! FSD servers
const BlackMisc::Network::CServerList &getFsdServers() const { return m_fsdServers; } const BlackMisc::Network::CServerList &getFsdServers() const { return m_fsdServers; }
@@ -92,17 +92,17 @@ namespace BlackCore::Data
void setPropertyByIndex(BlackMisc::CPropertyIndexRef index, const QVariant &variant); void setPropertyByIndex(BlackMisc::CPropertyIndexRef index, const QVariant &variant);
private: private:
BlackMisc::Network::CUrlList m_serverFileUrls; //!< only the FSD servers BlackMisc::Network::CUrl m_serverFileUrl; //!< only the FSD servers
BlackMisc::Network::CUrlList m_dataFileUrls; //!< Full VATSIM files BlackMisc::Network::CUrl m_dataFileUrl; //!< Full VATSIM file
BlackMisc::Network::CUrlList m_metarFileUrls; //!< METAR files BlackMisc::Network::CUrl m_metarFileUrl; //!< METAR file
BlackMisc::Network::CServerList m_fsdServers; //!< FSD test servers BlackMisc::Network::CServerList m_fsdServers; //!< FSD test servers
BlackMisc::Network::CServerList m_voiceServers; //!< voice servers BlackMisc::Network::CServerList m_voiceServers; //!< voice servers
BLACK_METACLASS( BLACK_METACLASS(
CVatsimSetup, CVatsimSetup,
BLACK_METAMEMBER(serverFileUrls), BLACK_METAMEMBER(serverFileUrl),
BLACK_METAMEMBER(dataFileUrls), BLACK_METAMEMBER(dataFileUrl),
BLACK_METAMEMBER(metarFileUrls), BLACK_METAMEMBER(metarFileUrl),
BLACK_METAMEMBER(fsdServers), BLACK_METAMEMBER(fsdServers),
BLACK_METAMEMBER(voiceServers), BLACK_METAMEMBER(voiceServers),
BLACK_METAMEMBER(timestampMSecsSinceEpoch) BLACK_METAMEMBER(timestampMSecsSinceEpoch)

View File

@@ -10,7 +10,6 @@
#include "blackcore/data/globalsetup.h" #include "blackcore/data/globalsetup.h"
#include "blackmisc/db/updateinfo.h" #include "blackmisc/db/updateinfo.h"
#include "blackmisc/datacache.h" #include "blackmisc/datacache.h"
#include "blackmisc/network/urllist.h"
#include "blackmisc/statusmessagelist.h" #include "blackmisc/statusmessagelist.h"
#include <QCommandLineOption> #include <QCommandLineOption>

View File

@@ -10,7 +10,6 @@
#include "blackmisc/network/entityflags.h" #include "blackmisc/network/entityflags.h"
#include "blackmisc/network/server.h" #include "blackmisc/network/server.h"
#include "blackmisc/network/url.h" #include "blackmisc/network/url.h"
#include "blackmisc/network/urllist.h"
#include "blackmisc/network/user.h" #include "blackmisc/network/user.h"
#include "blackmisc/pq/frequency.h" #include "blackmisc/pq/frequency.h"
#include "blackmisc/pq/length.h" #include "blackmisc/pq/length.h"
@@ -168,12 +167,8 @@ namespace BlackCore::Vatsim
this->threadAssertCheck(); this->threadAssertCheck();
if (!this->doWorkCheck()) { return; } if (!this->doWorkCheck()) { return; }
// round robin for load balancing
// remark: Don't use QThread to run network operations in the background
// see http://qt-project.org/doc/qt-4.7/qnetworkaccessmanager.html
Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing application"); Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing application");
CFailoverUrlList urls(sApp->getVatsimDataFileUrls()); const QUrl url(sApp->getVatsimDataFileUrl());
const QUrl url(urls.obtainNextWorkingUrl(true));
if (url.isEmpty()) { return; } if (url.isEmpty()) { return; }
this->getFromNetworkAndLog(url, { this, &CVatsimDataFileReader::parseVatsimFile }); this->getFromNetworkAndLog(url, { this, &CVatsimDataFileReader::parseVatsimFile });
} }

View File

@@ -7,8 +7,6 @@
#include "blackmisc/logmessage.h" #include "blackmisc/logmessage.h"
#include "blackmisc/network/entityflags.h" #include "blackmisc/network/entityflags.h"
#include "blackmisc/network/url.h" #include "blackmisc/network/url.h"
#include "blackmisc/network/urllist.h"
#include "blackmisc/statusmessage.h"
#include <QByteArray> #include <QByteArray>
#include <QMetaObject> #include <QMetaObject>
@@ -67,8 +65,7 @@ namespace BlackCore::Vatsim
this->threadAssertCheck(); this->threadAssertCheck();
if (!this->doWorkCheck()) { return; } if (!this->doWorkCheck()) { return; }
CFailoverUrlList urls(sApp->getVatsimMetarUrls()); const CUrl url(sApp->getVatsimMetarUrl());
const CUrl url(urls.obtainNextWorkingUrl(true));
if (url.isEmpty()) { return; } if (url.isEmpty()) { return; }
Q_ASSERT_X(sApp, Q_FUNC_INFO, "No Application"); Q_ASSERT_X(sApp, Q_FUNC_INFO, "No Application");
this->getFromNetworkAndLog(url.withAppendedQuery("id=all"), { this, &CVatsimMetarReader::decodeMetars }); this->getFromNetworkAndLog(url.withAppendedQuery("id=all"), { this, &CVatsimMetarReader::decodeMetars });

View File

@@ -6,7 +6,6 @@
#include "blackcore/data/globalsetup.h" #include "blackcore/data/globalsetup.h"
#include "blackmisc/logmessage.h" #include "blackmisc/logmessage.h"
#include "blackmisc/network/url.h" #include "blackmisc/network/url.h"
#include "blackmisc/network/urllist.h"
#include "blackmisc/statusmessage.h" #include "blackmisc/statusmessage.h"
#include <QByteArray> #include <QByteArray>
@@ -45,14 +44,14 @@ namespace BlackCore::Vatsim
}); });
} }
CUrlList CVatsimStatusFileReader::getMetarFileUrls() const CUrl CVatsimStatusFileReader::getMetarFileUrl() const
{ {
return m_lastGoodSetup.get().getMetarFileUrls(); return m_lastGoodSetup.get().getMetarFileUrl();
} }
CUrlList CVatsimStatusFileReader::getDataFileUrls() const CUrl CVatsimStatusFileReader::getDataFileUrl() const
{ {
return m_lastGoodSetup.get().getDataFileUrls(); return m_lastGoodSetup.get().getDataFileUrl();
} }
void CVatsimStatusFileReader::read() void CVatsimStatusFileReader::read()
@@ -61,27 +60,10 @@ namespace BlackCore::Vatsim
if (!this->doWorkCheck()) { return; } if (!this->doWorkCheck()) { return; }
Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing application"); Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing application");
const CUrlList urls(sApp->getGlobalSetup().getVatsimStatusFileUrls()); const CUrl url(sApp->getGlobalSetup().getVatsimStatusFileUrl());
const CUrl url = urls.getRandomUrl();
if (url.isEmpty()) { return; } if (url.isEmpty()) { return; }
CLogMessage(this).info(u"Trigger read of VATSIM status file from '%1'") << url.toQString(true); CLogMessage(this).info(u"Trigger read of VATSIM status file from '%1'") << url.toQString(true);
this->getFromNetworkAndLog(url, { this, &CVatsimStatusFileReader::parseVatsimFile }); this->getFromNetworkAndLog(url, { this, &CVatsimStatusFileReader::parseVatsimFile });
if (urls.size() < 2) { return; }
const CUrl secondary = urls.getRandomWithout(url);
if (secondary.isEmpty()) { return; }
constexpr int DelayMs = 5000;
const QPointer<CVatsimStatusFileReader> myself(this);
QTimer::singleShot(DelayMs, this, [=] {
if (!myself) { return; }
const CVatsimSetup vs(m_lastGoodSetup.get());
if (vs.getTimeDifferenceToNowMs() > 2 * DelayMs)
{
// not yet read
this->getFromNetworkAndLog(url, { this, &CVatsimStatusFileReader::parseVatsimFile });
}
});
} }
void CVatsimStatusFileReader::parseVatsimFile(QNetworkReply *nwReplyPtr) void CVatsimStatusFileReader::parseVatsimFile(QNetworkReply *nwReplyPtr)
@@ -111,9 +93,9 @@ namespace BlackCore::Vatsim
const QList<QStringRef> lines = splitLinesRefs(dataFileData); const QList<QStringRef> lines = splitLinesRefs(dataFileData);
if (lines.isEmpty()) { return; } if (lines.isEmpty()) { return; }
CUrlList dataFileUrls; CUrl dataFileUrl;
CUrlList serverFileUrls; CUrl serverFileUrl;
CUrlList metarFileUrls; CUrl metarFileUrl;
QString currentLine; // declared outside of the for loop, to amortize the cost of allocation QString currentLine; // declared outside of the for loop, to amortize the cost of allocation
for (const QStringRef &clRef : lines) for (const QStringRef &clRef : lines)
@@ -136,17 +118,18 @@ namespace BlackCore::Vatsim
const QString key(parts[0].trimmed().toLower()); const QString key(parts[0].trimmed().toLower());
const QString value(parts[1].trimmed()); const QString value(parts[1].trimmed());
const CUrl url(value); const CUrl url(value);
// Always taking last in the file (at the time of writing, the status file also only contains a single URL for each type either)
if (key.startsWith("json3")) if (key.startsWith("json3"))
{ {
dataFileUrls.push_back(url); dataFileUrl = url;
} }
else if (key.startsWith("url1")) else if (key.startsWith("url1"))
{ {
serverFileUrls.push_back(url); serverFileUrl = url;
} }
else if (key.startsWith("metar")) else if (key.startsWith("metar"))
{ {
metarFileUrls.push_back(url); metarFileUrl = url;
} }
else if (key.startsWith("atis")) else if (key.startsWith("atis"))
{ {
@@ -156,14 +139,14 @@ namespace BlackCore::Vatsim
// cache itself is thread safe, avoid writing with unchanged data // cache itself is thread safe, avoid writing with unchanged data
CVatsimSetup vs(m_lastGoodSetup.get()); CVatsimSetup vs(m_lastGoodSetup.get());
const bool changed = vs.setUrls(dataFileUrls, serverFileUrls, metarFileUrls); const bool changed = vs.setUrls(dataFileUrl, serverFileUrl, metarFileUrl);
vs.setUtcTimestamp(QDateTime::currentDateTime()); vs.setUtcTimestamp(QDateTime::currentDateTime());
const CStatusMessage cacheMsg = m_lastGoodSetup.set(vs); const CStatusMessage cacheMsg = m_lastGoodSetup.set(vs);
if (cacheMsg.isFailure()) { CLogMessage::preformatted(cacheMsg); } if (cacheMsg.isFailure()) { CLogMessage::preformatted(cacheMsg); }
else else
{ {
CLogMessage(this).info(u"Read VATSIM status file from '%1', %2 data file URLs, %3 server file URLs, %4 METAR file URLs") CLogMessage(this).info(u"Read VATSIM status file from '%1'")
<< urlString << dataFileUrls.size() << serverFileUrls.size() << metarFileUrls.size(); << urlString;
} }
Q_UNUSED(changed); Q_UNUSED(changed);

View File

@@ -10,7 +10,7 @@
#include "blackcore/data/vatsimsetup.h" #include "blackcore/data/vatsimsetup.h"
#include "blackmisc/datacache.h" #include "blackmisc/datacache.h"
#include "blackmisc/network/entityflags.h" #include "blackmisc/network/entityflags.h"
#include "blackmisc/network/urllist.h" #include "blackmisc/network/url.h"
#include "blackcore/threadedreader.h" #include "blackcore/threadedreader.h"
#include <QObject> #include <QObject>
@@ -29,13 +29,13 @@ namespace BlackCore::Vatsim
//! Constructor //! Constructor
explicit CVatsimStatusFileReader(QObject *owner); explicit CVatsimStatusFileReader(QObject *owner);
//! METAR URLs //! METAR URL
//! \threadsafe //! \threadsafe
BlackMisc::Network::CUrlList getMetarFileUrls() const; BlackMisc::Network::CUrl getMetarFileUrl() const;
//! Data file URLs //! Data file URL
//! \threadsafe //! \threadsafe
BlackMisc::Network::CUrlList getDataFileUrls() const; BlackMisc::Network::CUrl getDataFileUrl() const;
//! Start reading in own thread //! Start reading in own thread
void readInBackgroundThread(); void readInBackgroundThread();

View File

@@ -109,16 +109,16 @@ namespace BlackCore
return CServerList(); return CServerList();
} }
CUrlList CWebDataServices::getVatsimMetarUrls() const CUrl CWebDataServices::getVatsimMetarUrl() const
{ {
if (m_vatsimStatusReader) { return m_vatsimStatusReader->getMetarFileUrls(); } if (m_vatsimStatusReader) { return m_vatsimStatusReader->getMetarFileUrl(); }
return CUrlList(); return {};
} }
CUrlList CWebDataServices::getVatsimDataFileUrls() const CUrl CWebDataServices::getVatsimDataFileUrl() const
{ {
if (m_vatsimStatusReader) { return m_vatsimStatusReader->getDataFileUrls(); } if (m_vatsimStatusReader) { return m_vatsimStatusReader->getDataFileUrl(); }
return CUrlList(); return {};
} }
CUserList CWebDataServices::getUsersForCallsign(const CCallsign &callsign) const CUserList CWebDataServices::getUsersForCallsign(const CCallsign &callsign) const

View File

@@ -20,7 +20,7 @@
#include "blackmisc/aviation/atcstationlist.h" #include "blackmisc/aviation/atcstationlist.h"
#include "blackmisc/aviation/liverylist.h" #include "blackmisc/aviation/liverylist.h"
#include "blackmisc/network/serverlist.h" #include "blackmisc/network/serverlist.h"
#include "blackmisc/network/urllist.h" #include "blackmisc/network/url.h"
#include "blackmisc/network/userlist.h" #include "blackmisc/network/userlist.h"
#include "blackmisc/network/entityflags.h" #include "blackmisc/network/entityflags.h"
#include "blackmisc/network/voicecapabilities.h" #include "blackmisc/network/voicecapabilities.h"
@@ -118,13 +118,13 @@ namespace BlackCore
//! \threadsafe //! \threadsafe
BlackMisc::Network::CServerList getVatsimFsdServers() const; BlackMisc::Network::CServerList getVatsimFsdServers() const;
//! METAR URLs (from status file) //! METAR URL (from status file)
//! \threadsafe //! \threadsafe
BlackMisc::Network::CUrlList getVatsimMetarUrls() const; BlackMisc::Network::CUrl getVatsimMetarUrl() const;
//! Data file locations (from status file) //! Data file location (from status file)
//! \threadsafe //! \threadsafe
BlackMisc::Network::CUrlList getVatsimDataFileUrls() const; BlackMisc::Network::CUrl getVatsimDataFileUrl() const;
//! Users by callsign //! Users by callsign
//! \threadsafe //! \threadsafe

View File

@@ -224,13 +224,12 @@ namespace BlackGui::Components
m_sharedValueCheckInProgress = true; // avoid processEvent (canConnect) calling this again before done m_sharedValueCheckInProgress = true; // avoid processEvent (canConnect) calling this again before done
const CUrlList sharedUrls(sGui->getGlobalSetup().getSwiftSharedUrls()); const CUrl sharedUrl(sGui->getGlobalSetup().getSwiftSharedUrl());
const QString valueHtml("<img src=\"%1\">&nbsp;%2"); const QString valueHtml("<img src=\"%1\">&nbsp;%2");
const QString urlLinkHtml("<a href=\"%1\">%2</a>"); const QString urlLinkHtml("<a href=\"%1\">%2</a>");
QStringList values; QStringList values;
for (const CUrl &sharedUrl : sharedUrls)
{
if (!sGui || sGui->isShuttingDown()) if (!sGui || sGui->isShuttingDown())
{ {
// shutdown during connect test // shutdown during connect test
@@ -240,16 +239,13 @@ namespace BlackGui::Components
const bool canConnect = CNetworkUtils::canConnect(sharedUrl); const bool canConnect = CNetworkUtils::canConnect(sharedUrl);
values.push_back( values.push_back(
valueHtml.arg(canConnect ? m_imgOk : m_imgFailed, urlLinkHtml.arg(sharedUrl.getFullUrl(), sharedUrl.getHost()))); valueHtml.arg(canConnect ? m_imgOk : m_imgFailed, urlLinkHtml.arg(sharedUrl.getFullUrl(), sharedUrl.getHost())));
}
const QString sharedUrlTable = toHtmTable(values, 2); const QString sharedUrlTable = toHtmTable(values, 2);
ui->lbl_SharedUrls->setText(sharedUrlTable); ui->lbl_SharedUrls->setText(sharedUrlTable);
ui->lbl_SharedUrls->setMinimumHeight(10 + (18 * sharedUrls.size())); ui->lbl_SharedUrls->setMinimumHeight(28);
const QString currentlyUsedSharedUrl = sGui->getGlobalSetup().getSwiftSharedUrl().toQString();
const CUrlList urls = sGui->getGlobalSetup().getSwiftSharedUrls();
Q_ASSERT_X(!urls.empty(), Q_FUNC_INFO, "Need at least one shared URL");
ui->lbl_SharedUrls->setToolTip( ui->lbl_SharedUrls->setToolTip(
urls[0].isEmpty() ? "No shared URL" : "currently used: " + urls[0].toQString()); currentlyUsedSharedUrl.isEmpty() ? "No shared URL" : "currently used: " + currentlyUsedSharedUrl);
m_sharedLastCheck = QDateTime::currentMSecsSinceEpoch(); m_sharedLastCheck = QDateTime::currentMSecsSinceEpoch();
m_sharedValueCheckInProgress = false; m_sharedValueCheckInProgress = false;

View File

@@ -37,7 +37,7 @@ namespace BlackGui::Components
if (r != QDialog::Accepted) { return r; } if (r != QDialog::Accepted) { return r; }
if (!ui->comp_UpdateInfo->isNewPilotClientVersionAvailable()) { return QDialog::Rejected; } if (!ui->comp_UpdateInfo->isNewPilotClientVersionAvailable()) { return QDialog::Rejected; }
const CDistribution distribution = ui->comp_UpdateInfo->getCurrentDistribution(); const CDistribution distribution = ui->comp_UpdateInfo->getCurrentDistribution();
if (!distribution.hasDownloadUrls()) { return QDialog::Rejected; } if (!distribution.hasDownloadUrl()) { return QDialog::Rejected; }
ui->comp_UpdateInfo->triggerDownload(); ui->comp_UpdateInfo->triggerDownload();
return r; return r;

View File

@@ -423,8 +423,6 @@ add_library(misc SHARED
network/textmessagelist.h network/textmessagelist.h
network/url.cpp network/url.cpp
network/url.h network/url.h
network/urllist.cpp
network/urllist.h
network/urllog.cpp network/urllog.cpp
network/urllog.h network/urllog.h
network/urlloglist.cpp network/urlloglist.cpp

View File

@@ -71,7 +71,7 @@ namespace BlackMisc::Db
if (!this->hasDistributions()) { return CRemoteFile(); } if (!this->hasDistributions()) { return CRemoteFile(); }
CRemoteFile rf(this->getName(), this->getFileSize()); CRemoteFile rf(this->getName(), this->getFileSize());
const CDistribution d = this->getMostStableDistribution(); const CDistribution d = this->getMostStableDistribution();
const CUrl url = d.getDownloadUrls().getRandomUrl(); const CUrl url = d.getDownloadUrl();
if (url.isEmpty()) { return CRemoteFile(); } if (url.isEmpty()) { return CRemoteFile(); }
rf.setUtcTimestamp(this->getUtcTimestamp()); rf.setUtcTimestamp(this->getUtcTimestamp());
rf.setUrl(url); rf.setUrl(url);

View File

@@ -24,15 +24,15 @@ namespace BlackMisc::Db
m_channel = channel.trimmed().toUpper(); m_channel = channel.trimmed().toUpper();
} }
void CDistribution::addDownloadUrl(const CUrl &url) void CDistribution::setDownloadUrl(const CUrl &url)
{ {
if (url.isEmpty()) { return; } if (url.isEmpty()) { return; }
m_downloadUrls.push_back(url); m_downloadUrl = url;
} }
bool CDistribution::hasDownloadUrls() const bool CDistribution::hasDownloadUrl() const
{ {
return !m_downloadUrls.isEmpty(); return !m_downloadUrl.isEmpty();
} }
CIcons::IconIndex CDistribution::getRestrictionIcon() const CIcons::IconIndex CDistribution::getRestrictionIcon() const
@@ -61,8 +61,8 @@ namespace BlackMisc::Db
return u"channel: " % return u"channel: " %
this->getChannel() % this->getChannel() %
separator % separator %
u"download URLs: " % u"download URL: " %
getDownloadUrls().toQString(i18n) % getDownloadUrl().toQString(i18n) %
separator % separator %
u"timestamp: " % u"timestamp: " %
this->getFormattedUtcTimestampYmdhms(); this->getFormattedUtcTimestampYmdhms();
@@ -83,7 +83,7 @@ namespace BlackMisc::Db
{ {
case IndexChannel: return QVariant::fromValue(m_channel); case IndexChannel: return QVariant::fromValue(m_channel);
case IndexStability: return QVariant::fromValue(m_stability); case IndexStability: return QVariant::fromValue(m_stability);
case IndexDownloadUrls: return QVariant::fromValue(m_downloadUrls); case IndexDownloadUrl: return QVariant::fromValue(m_downloadUrl);
case IndexRestricted: return QVariant::fromValue(m_restricted); case IndexRestricted: return QVariant::fromValue(m_restricted);
default: return CValueObject::propertyByIndex(index); default: return CValueObject::propertyByIndex(index);
} }
@@ -107,7 +107,7 @@ namespace BlackMisc::Db
{ {
case IndexChannel: this->setChannel(variant.value<QString>()); break; case IndexChannel: this->setChannel(variant.value<QString>()); break;
case IndexStability: m_stability = variant.toInt(); break; case IndexStability: m_stability = variant.toInt(); break;
case IndexDownloadUrls: m_downloadUrls = variant.value<CUrlList>(); break; case IndexDownloadUrl: m_downloadUrl = variant.value<CUrl>(); break;
case IndexRestricted: m_restricted = variant.toBool(); break; case IndexRestricted: m_restricted = variant.toBool(); break;
default: CValueObject::setPropertyByIndex(index, variant); break; default: CValueObject::setPropertyByIndex(index, variant); break;
} }
@@ -139,7 +139,7 @@ namespace BlackMisc::Db
const QString key = "url" + QString::number(i); const QString key = "url" + QString::number(i);
const QString url = json.value(key).toString(); const QString url = json.value(key).toString();
if (url.isEmpty()) { continue; } if (url.isEmpty()) { continue; }
distribution.addDownloadUrl(CUrl(url)); distribution.setDownloadUrl(CUrl(url));
} }
return distribution; return distribution;
} }

View File

@@ -8,7 +8,7 @@
#include "blackconfig/buildconfig.h" #include "blackconfig/buildconfig.h"
#include "blackmisc/blackmiscexport.h" #include "blackmisc/blackmiscexport.h"
#include "blackmisc/network/urllist.h" #include "blackmisc/network/url.h"
#include "blackmisc/db/datastore.h" #include "blackmisc/db/datastore.h"
#include "blackmisc/settingscache.h" #include "blackmisc/settingscache.h"
#include "blackmisc/dictionary.h" #include "blackmisc/dictionary.h"
@@ -34,7 +34,7 @@ namespace BlackMisc::Db
IndexChannel = CPropertyIndexRef::GlobalIndexCDistribution, IndexChannel = CPropertyIndexRef::GlobalIndexCDistribution,
IndexStability, IndexStability,
IndexRestricted, IndexRestricted,
IndexDownloadUrls IndexDownloadUrl
}; };
//! Default constructor //! Default constructor
@@ -55,14 +55,14 @@ namespace BlackMisc::Db
//! Order //! Order
void setStability(int stability) { m_stability = stability; } void setStability(int stability) { m_stability = stability; }
//! Download URLs, i.e. here one can download installer //! Download URL, i.e. here one can download installer
const Network::CUrlList &getDownloadUrls() const { return m_downloadUrls; } const Network::CUrl &getDownloadUrl() const { return m_downloadUrl; }
//! Add URL, ignored if empty //! Set URL, ignored if empty
void addDownloadUrl(const Network::CUrl &url); void setDownloadUrl(const BlackMisc::Network::CUrl &url);
//! At least one download URL? //! Has a download URL?
bool hasDownloadUrls() const; bool hasDownloadUrl() const;
//! Restricted channel? //! Restricted channel?
bool isRestricted() const { return m_restricted; } bool isRestricted() const { return m_restricted; }
@@ -107,7 +107,7 @@ namespace BlackMisc::Db
QString m_channel; //!< channel the files belong to QString m_channel; //!< channel the files belong to
int m_stability; //!< stability int m_stability; //!< stability
bool m_restricted = false; //!< restricted access (i.e. password for download needed) bool m_restricted = false; //!< restricted access (i.e. password for download needed)
Network::CUrlList m_downloadUrls; //!< download URLs, here I get the installer Network::CUrl m_downloadUrl; //!< download URL, here I get the installer
BLACK_METACLASS( BLACK_METACLASS(
CDistribution, CDistribution,
@@ -115,7 +115,7 @@ namespace BlackMisc::Db
BLACK_METAMEMBER(timestampMSecsSinceEpoch), BLACK_METAMEMBER(timestampMSecsSinceEpoch),
BLACK_METAMEMBER(channel), BLACK_METAMEMBER(channel),
BLACK_METAMEMBER(stability), BLACK_METAMEMBER(stability),
BLACK_METAMEMBER(downloadUrls) BLACK_METAMEMBER(downloadUrl)
); );
}; };
} // ns } // ns

View File

@@ -158,8 +158,8 @@ namespace BlackMisc::Db
const QString url = CBuildConfig::gitHubRepoUrl() + QStringLiteral("releases/download"); const QString url = CBuildConfig::gitHubRepoUrl() + QStringLiteral("releases/download");
CDistribution alphaDistribution("ALPHA", 5, false); CDistribution alphaDistribution("ALPHA", 5, false);
CDistribution betaDistribution("BETA", 10, false); CDistribution betaDistribution("BETA", 10, false);
alphaDistribution.addDownloadUrl(url); alphaDistribution.setDownloadUrl(url);
betaDistribution.addDownloadUrl(url); betaDistribution.setDownloadUrl(url);
CUpdateInfo result; CUpdateInfo result;
result.m_distributions = { alphaDistribution, betaDistribution }; result.m_distributions = { alphaDistribution, betaDistribution };

View File

@@ -25,7 +25,6 @@
#include "blackmisc/network/textmessage.h" #include "blackmisc/network/textmessage.h"
#include "blackmisc/network/textmessagelist.h" #include "blackmisc/network/textmessagelist.h"
#include "blackmisc/network/url.h" #include "blackmisc/network/url.h"
#include "blackmisc/network/urllist.h"
#include "blackmisc/network/urllog.h" #include "blackmisc/network/urllog.h"
#include "blackmisc/network/urlloglist.h" #include "blackmisc/network/urlloglist.h"
#include "blackmisc/network/user.h" #include "blackmisc/network/user.h"
@@ -63,8 +62,6 @@ namespace BlackMisc
CTextMessage::registerMetadata(); CTextMessage::registerMetadata();
CTextMessageList::registerMetadata(); CTextMessageList::registerMetadata();
CUrl::registerMetadata(); CUrl::registerMetadata();
CUrlList::registerMetadata();
CFailoverUrlList::registerMetadata();
CUrlLog::registerMetadata(); CUrlLog::registerMetadata();
CUrlLogList::registerMetadata(); CUrlLogList::registerMetadata();
CUser::registerMetadata(); CUser::registerMetadata();

View File

@@ -1,232 +0,0 @@
// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
#include "blackmisc/network/urllist.h"
#include "blackmisc/network/networkutils.h"
#include "blackmisc/math/mathutils.h"
#include "blackmisc/stringutils.h"
#include <QtGlobal>
using namespace BlackMisc::Math;
BLACK_DEFINE_SEQUENCE_MIXINS(BlackMisc::Network, CUrl, CUrlList)
namespace BlackMisc::Network
{
CUrlList::CUrlList() {}
CUrlList::CUrlList(const CSequence<CUrl> &other) : CSequence<CUrl>(other)
{}
CUrlList::CUrlList(const QStringList &listOfUrls, bool removeDuplicates)
{
QStringList urlList(listOfUrls);
if (removeDuplicates) { urlList.removeDuplicates(); }
for (const QString &url : urlList)
{
this->push_back(CUrl(url));
}
}
CUrl CUrlList::getRandomUrl() const
{
if (this->isEmpty()) { return CUrl(); }
if (this->size() == 1) { return this->front(); }
const int i = CMathUtils::randomInteger(0, this->size() - 1);
return (*this)[i];
}
CUrl CUrlList::getRandomWorkingUrl(int maxTrials, int timeoutMs) const
{
if (this->isEmpty()) { return CUrl(); }
if (maxTrials < 1) { return CUrl(); }
CUrlList trials;
if (timeoutMs < 0) { timeoutMs = CNetworkUtils::getTimeoutMs(); }
for (int t = 0; t < maxTrials && t < this->size(); t++)
{
const CUrl url(this->getRandomWithout(trials));
trials.push_back(url);
QString message;
if (CNetworkUtils::canConnect(url, message, timeoutMs)) { return url; }
}
return CUrl();
}
CUrl CUrlList::getRandomWithout(const CUrl &exclude) const
{
const CUrlList excludes({ exclude });
return this->getRandomWithout(excludes);
}
CUrl CUrlList::getRandomWithout(const CUrlList &exclude) const
{
CUrlList copy(*this);
copy.removeIfIn(exclude);
if (copy.isEmpty()) { return CUrl(); }
return copy.getRandomUrl();
}
CUrlList CUrlList::withAppendedPath(const QString &path) const
{
if (path.isEmpty() || this->isEmpty()) { return (*this); }
CUrlList urls;
for (const CUrl &url : (*this))
{
urls.push_back(url.withAppendedPath(path));
}
return urls;
}
CUrlList CUrlList::findByHost(const QString &host, Qt::CaseSensitivity cs) const
{
CUrlList result;
if (host.isEmpty() || this->isEmpty()) { return result; }
for (const CUrl &url : *this)
{
if (stringCompare(url.getHost(), host, cs))
{
result.push_back(url);
}
}
return result;
}
QString CUrlList::convertToQString(const QString &separator, bool i18n) const
{
const QStringList sl(toStringList(i18n));
return sl.join(separator);
}
CUrlList CUrlList::getWithoutDuplicates() const
{
if (this->size() < 2) { return (*this); }
CUrlList withoutDuplicates;
for (const CUrl &url : (*this))
{
withoutDuplicates.replaceOrAdd(url);
}
return withoutDuplicates;
}
int CUrlList::removeDuplicates()
{
if (this->size() < 2) { return 0; }
const CUrlList withoutDuplicates(getWithoutDuplicates());
if (this->size() == withoutDuplicates.size()) { return 0; }
int r = this->size() - withoutDuplicates.size();
(*this) = withoutDuplicates;
return r;
}
CFailoverUrlList::CFailoverUrlList(int maxTrials) : m_maxTrials(maxTrials)
{}
CFailoverUrlList::CFailoverUrlList(const QStringList &listOfUrls, int maxTrials) : CUrlList(listOfUrls), m_maxTrials(maxTrials)
{}
CFailoverUrlList::CFailoverUrlList(const CUrlList &urlIst, int maxTrials) : CUrlList(urlIst), m_maxTrials(maxTrials)
{}
CUrlList CFailoverUrlList::getWithoutFailed() const
{
CUrlList urls(*this);
urls.removeIfIn(m_failedUrls);
return urls;
}
bool CFailoverUrlList::addFailedUrl(const CUrl &failedUrl)
{
Q_ASSERT_X(!failedUrl.isEmpty(), Q_FUNC_INFO, "empty URL as failed");
m_failedUrls.push_back(failedUrl);
return hasMoreUrlsToTry();
}
bool CFailoverUrlList::addFailedUrls(const CUrlList &failedUrls)
{
m_failedUrls.push_back(failedUrls);
return hasMoreUrlsToTry();
}
bool CFailoverUrlList::addFailedHost(const CUrl &failedUrl)
{
Q_ASSERT_X(!failedUrl.isEmpty(), Q_FUNC_INFO, "empty URL as failed");
const QString host = failedUrl.getHost();
return CFailoverUrlList::addFailedHost(host);
}
bool CFailoverUrlList::addFailedHost(const QString &host, Qt::CaseSensitivity cs)
{
if (host.isEmpty()) { return this->hasMoreUrlsToTry(); }
const CUrlList failedUrls = this->findByHost(host, cs);
return addFailedUrls(failedUrls);
}
bool CFailoverUrlList::hasMoreUrlsToTry() const
{
return this->numberOfStillValidUrls() > 0;
}
int CFailoverUrlList::numberOfStillValidUrls() const
{
if (this->isEmpty()) { return 0; }
if (m_failedUrls.size() >= m_maxTrials) { return 0; }
const int trailsLeft1 = qMax(m_maxTrials - m_failedUrls.size(), 0);
const int trailsLeft2 = qMax(this->size() - m_failedUrls.size(), 0);
return qMin(trailsLeft1, trailsLeft2);
}
CUrl CFailoverUrlList::obtainNextWorkingUrl(bool random, int connectTimeoutMs)
{
if (!hasMoreUrlsToTry()) { return CUrl(); }
const CUrl url(this->obtainNextUrlWithout(random, m_failedUrls));
QString msg;
if (CNetworkUtils::canConnect(url, msg, connectTimeoutMs)) { return url; }
if (addFailedUrl(url))
{
if (!msg.isEmpty())
{
m_errorMsgs.append(QStringLiteral("URL: %1 error: %2").arg(url.toQString(), msg));
}
return obtainNextWorkingUrl(random, connectTimeoutMs);
}
return CUrl();
}
CUrl CFailoverUrlList::obtainNextUrl(bool randomStart)
{
if (this->isEmpty()) { return CUrl(); }
if (this->size() == 1) { return this->front(); }
if (m_currentIndexDistributedLoad < 0)
{
// random start point
m_currentIndexDistributedLoad = randomStart ?
CMathUtils::randomInteger(0, this->size() - 1) :
0;
}
else
{
m_currentIndexDistributedLoad++;
if (m_currentIndexDistributedLoad >= this->size())
{
m_currentIndexDistributedLoad = 0;
}
}
return (*this)[m_currentIndexDistributedLoad];
}
CUrl CFailoverUrlList::obtainNextUrlWithout(bool randomStart, const CUrlList &exclude) const
{
CFailoverUrlList copy(*this);
copy.removeIfIn(exclude);
if (copy.isEmpty()) { return CUrl(); }
return copy.obtainNextUrl(randomStart);
}
void CFailoverUrlList::reset(int maxTrials)
{
m_failedUrls.clear();
if (maxTrials >= 0) { m_maxTrials = maxTrials; }
}
} // namespace

View File

@@ -1,136 +0,0 @@
// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
//! \file
#ifndef BLACKMISC_NETWORK_URLLIST_H
#define BLACKMISC_NETWORK_URLLIST_H
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/collection.h"
#include "blackmisc/network/url.h"
#include "blackmisc/sequence.h"
#include <QMetaType>
#include <QString>
#include <QStringList>
BLACK_DECLARE_SEQUENCE_MIXINS(BlackMisc::Network, CUrl, CUrlList)
namespace BlackMisc::Network
{
//! Value object encapsulating a list of URLs.
class BLACKMISC_EXPORT CUrlList :
public CSequence<CUrl>,
public BlackMisc::Mixin::MetaType<CUrlList>
{
public:
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CUrlList)
using CSequence::CSequence;
//! Default constructor.
CUrlList();
//! Construct from a base class object.
CUrlList(const CSequence<CUrl> &other);
//! By list of URLs
explicit CUrlList(const QStringList &listOfUrls, bool removeDuplicates = true);
//! Random location for distributed load
CUrl getRandomUrl() const;
//! Random location for distributed load, tested
CUrl getRandomWorkingUrl(int maxTrials = 2, int timeoutMs = -1) const;
//! Random location for distributed load
CUrl getRandomWithout(const CUrl &exclude) const;
//! Random location for distributed load
CUrl getRandomWithout(const CUrlList &exclude) const;
//! Append path to all URLs
CUrlList withAppendedPath(const QString &path) const;
//! Find by host
CUrlList findByHost(const QString &host, Qt::CaseSensitivity cs = Qt::CaseInsensitive) const;
//! To formatted String
QString convertToQString(const QString &separator, bool i18n = false) const;
//! URLs without duplicates
CUrlList getWithoutDuplicates() const;
//! Remove duplicated URL and return number of removed elements
int removeDuplicates();
};
//! URL list with fail support
class BLACKMISC_EXPORT CFailoverUrlList : public CUrlList
{
public:
//! Default constructor.
CFailoverUrlList(int maxTrials = 2);
//! By list of URLs
explicit CFailoverUrlList(const QStringList &listOfUrls, int maxTrials = 2);
//! From url list
CFailoverUrlList(const CUrlList &urlIst, int maxTrials = 2);
//! All failed URLs
const CUrlList &getFailedUrls() const { return m_failedUrls; }
//! Size of failed URLs
int getFailedUrlsSize() const { return m_failedUrls.size(); }
//! Get without the failed URLs
CUrlList getWithoutFailed() const;
//! Failed URL
bool addFailedUrl(const CUrl &failedUrl);
//! Failed URLs
bool addFailedUrls(const CUrlList &failedUrls);
//! Failed host
bool addFailedHost(const CUrl &failedUrl);
//! Failed host
bool addFailedHost(const QString &host, Qt::CaseSensitivity cs = Qt::CaseInsensitive);
//! More URLs to try
bool hasMoreUrlsToTry() const;
//! Number of URLs which can be used for a retry
int numberOfStillValidUrls() const;
//! Next utl from this list
CUrl obtainNextUrl(bool randomStart = false);
//! Round robin with random start point
CUrl obtainNextUrlWithout(bool randomStart = false, const CUrlList &exclude = CUrlList()) const;
//! Next working URL, test if it can be connected
CUrl obtainNextWorkingUrl(bool random = false, int connectTimeoutMs = -1);
//! Get the error messages
const QStringList &getErrorMessages() const { return m_errorMsgs; }
//! Reset failed URL, allows to set an optional new number of max.trials
void reset(int maxTrials = -1);
private:
int m_currentIndexDistributedLoad = -1; //!< index for random access
int m_maxTrials = 2; //!< number of max trials
CUrlList m_failedUrls; //!< failed tested URLs
QStringList m_errorMsgs; //!< error messages while testing;
};
} // namespace
Q_DECLARE_METATYPE(BlackMisc::Network::CUrlList)
Q_DECLARE_METATYPE(BlackMisc::Network::CFailoverUrlList)
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Network::CUrl>)
#endif // guard

View File

@@ -9,7 +9,6 @@
#include "blackgui/foreignwindows.h" #include "blackgui/foreignwindows.h"
#include "blackgui/copyxswiftbusdialog.h" #include "blackgui/copyxswiftbusdialog.h"
#include "blackmisc/aviation/altitude.h" #include "blackmisc/aviation/altitude.h"
#include "blackmisc/network/urllist.h"
#include "blackmisc/pq/units.h" #include "blackmisc/pq/units.h"
#include "blackmisc/logmessage.h" #include "blackmisc/logmessage.h"
#include "blackconfig/buildconfig.h" #include "blackconfig/buildconfig.h"