mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
IPv6 support (#1369)
* hyperion-remote - Support IPv6 * LEDDevices - Remove IPv6 limitations * Separate JsonEditorHostValidation * Standalone grabbers & JSON/Flatbuffer forwarder: IPv6 support * remote: Fix setting multiple colors via Hex, add standard logging * IPv6 Updates -Add db migration activities * Addressing non-Windows compile issues * Code cleanup, address clang feedback * Update address (hostname, IPv4/IPv6) help text * Apply migration steps to "old" configurations imported * Show user the UI-Url, if hyperion is already running, address clang findings * Windows Cmake OpenSLL output * Minor Text update
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
|
||||
// util
|
||||
#include <utils/JsonUtils.h>
|
||||
#include <utils/QStringUtils.h>
|
||||
|
||||
#include <db/SettingsTable.h>
|
||||
#include "HyperionConfig.h"
|
||||
|
||||
@@ -14,6 +16,7 @@
|
||||
#include <utils/JsonUtils.h>
|
||||
|
||||
#include <utils/version.hpp>
|
||||
|
||||
using namespace semver;
|
||||
|
||||
// Constants
|
||||
@@ -25,23 +28,23 @@ QJsonObject SettingsManager::schemaJson;
|
||||
|
||||
SettingsManager::SettingsManager(quint8 instance, QObject* parent, bool readonlyMode)
|
||||
: QObject(parent)
|
||||
, _log(Logger::getInstance("SETTINGSMGR"))
|
||||
, _instance(instance)
|
||||
, _sTable(new SettingsTable(instance, this))
|
||||
, _configVersion(DEFAULT_VERSION)
|
||||
, _previousVersion(DEFAULT_VERSION)
|
||||
, _readonlyMode(readonlyMode)
|
||||
, _log(Logger::getInstance("SETTINGSMGR"))
|
||||
, _instance(instance)
|
||||
, _sTable(new SettingsTable(instance, this))
|
||||
, _configVersion(DEFAULT_VERSION)
|
||||
, _previousVersion(DEFAULT_VERSION)
|
||||
, _readonlyMode(readonlyMode)
|
||||
{
|
||||
_sTable->setReadonlyMode(_readonlyMode);
|
||||
// get schema
|
||||
if(schemaJson.isEmpty())
|
||||
if (schemaJson.isEmpty())
|
||||
{
|
||||
Q_INIT_RESOURCE(resource);
|
||||
try
|
||||
{
|
||||
schemaJson = QJsonFactory::readSchema(":/hyperion-schema");
|
||||
}
|
||||
catch(const std::runtime_error& error)
|
||||
catch (const std::runtime_error& error)
|
||||
{
|
||||
throw std::runtime_error(error.what());
|
||||
}
|
||||
@@ -49,7 +52,7 @@ SettingsManager::SettingsManager(quint8 instance, QObject* parent, bool readonly
|
||||
|
||||
// get default config
|
||||
QJsonObject defaultConfig;
|
||||
if(!JsonUtils::readFile(":/hyperion_default.config", defaultConfig, _log))
|
||||
if (!JsonUtils::readFile(":/hyperion_default.config", defaultConfig, _log))
|
||||
{
|
||||
throw std::runtime_error("Failed to read default config");
|
||||
}
|
||||
@@ -57,45 +60,51 @@ SettingsManager::SettingsManager(quint8 instance, QObject* parent, bool readonly
|
||||
// transform json to string lists
|
||||
QStringList keyList = defaultConfig.keys();
|
||||
QStringList defValueList;
|
||||
for(const auto & key : keyList)
|
||||
for (const auto& key : qAsConst(keyList))
|
||||
{
|
||||
if(defaultConfig[key].isObject())
|
||||
if (defaultConfig[key].isObject())
|
||||
{
|
||||
defValueList << QString(QJsonDocument(defaultConfig[key].toObject()).toJson(QJsonDocument::Compact));
|
||||
}
|
||||
else if(defaultConfig[key].isArray())
|
||||
else if (defaultConfig[key].isArray())
|
||||
{
|
||||
defValueList << QString(QJsonDocument(defaultConfig[key].toArray()).toJson(QJsonDocument::Compact));
|
||||
}
|
||||
}
|
||||
|
||||
// fill database with default data if required
|
||||
for(const auto & key : keyList)
|
||||
for (const auto& key : qAsConst(keyList))
|
||||
{
|
||||
QString val = defValueList.takeFirst();
|
||||
// prevent overwrite
|
||||
if(!_sTable->recordExist(key))
|
||||
_sTable->createSettingsRecord(key,val);
|
||||
if (!_sTable->recordExist(key))
|
||||
{
|
||||
_sTable->createSettingsRecord(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
// need to validate all data in database construct the entire data object
|
||||
// TODO refactor schemaChecker to accept QJsonArray in validate(); QJsonDocument container? To validate them per entry...
|
||||
QJsonObject dbConfig;
|
||||
for(const auto & key : keyList)
|
||||
for (const auto& key : qAsConst(keyList))
|
||||
{
|
||||
QJsonDocument doc = _sTable->getSettingsRecord(key);
|
||||
if(doc.isArray())
|
||||
if (doc.isArray())
|
||||
{
|
||||
dbConfig[key] = doc.array();
|
||||
}
|
||||
else
|
||||
{
|
||||
dbConfig[key] = doc.object();
|
||||
}
|
||||
}
|
||||
|
||||
//Check, if database requires migration
|
||||
bool isNewRelease = false;
|
||||
// Use instance independent SettingsManager to track migration status
|
||||
if ( instance == GLOABL_INSTANCE_ID)
|
||||
if (_instance == GLOABL_INSTANCE_ID)
|
||||
{
|
||||
if ( resolveConfigVersion(dbConfig) )
|
||||
if (resolveConfigVersion(dbConfig))
|
||||
{
|
||||
QJsonObject newGeneralConfig = dbConfig["general"].toObject();
|
||||
|
||||
@@ -107,16 +116,16 @@ SettingsManager::SettingsManager(quint8 instance, QObject* parent, bool readonly
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( _configVersion > BUILD_VERSION )
|
||||
if (_configVersion > BUILD_VERSION)
|
||||
{
|
||||
Error(_log, "Database version [%s] is greater than current Hyperion version [%s]", _configVersion.getVersion().c_str(), BUILD_VERSION.getVersion().c_str());
|
||||
// TODO: Remove version checking and Settingsmanager from components' constructor to be able to stop hyperion.
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( _previousVersion < BUILD_VERSION )
|
||||
if (_previousVersion < BUILD_VERSION)
|
||||
{
|
||||
if ( _configVersion == BUILD_VERSION )
|
||||
if (_configVersion == BUILD_VERSION)
|
||||
{
|
||||
newGeneralConfig["previousVersion"] = BUILD_VERSION.getVersion().c_str();
|
||||
dbConfig["general"] = newGeneralConfig;
|
||||
@@ -139,7 +148,7 @@ SettingsManager::SettingsManager(quint8 instance, QObject* parent, bool readonly
|
||||
|
||||
// possible data upgrade steps to prevent data loss
|
||||
bool migrated = handleConfigUpgrade(dbConfig);
|
||||
if ( isNewRelease || migrated )
|
||||
if (isNewRelease || migrated)
|
||||
{
|
||||
saveSettings(dbConfig, true);
|
||||
}
|
||||
@@ -147,28 +156,34 @@ SettingsManager::SettingsManager(quint8 instance, QObject* parent, bool readonly
|
||||
// validate full dbconfig against schema, on error we need to rewrite entire table
|
||||
QJsonSchemaChecker schemaChecker;
|
||||
schemaChecker.setSchema(schemaJson);
|
||||
QPair<bool,bool> valid = schemaChecker.validate(dbConfig);
|
||||
QPair<bool, bool> valid = schemaChecker.validate(dbConfig);
|
||||
// check if our main schema syntax is IO
|
||||
if (!valid.second)
|
||||
{
|
||||
for (auto & schemaError : schemaChecker.getMessages())
|
||||
for (auto& schemaError : schemaChecker.getMessages())
|
||||
{
|
||||
Error(_log, "Schema Syntax Error: %s", QSTRING_CSTR(schemaError));
|
||||
}
|
||||
throw std::runtime_error("The config schema has invalid syntax. This should never happen! Go fix it!");
|
||||
}
|
||||
if (!valid.first)
|
||||
{
|
||||
Info(_log,"Table upgrade required...");
|
||||
Info(_log, "Table upgrade required...");
|
||||
dbConfig = schemaChecker.getAutoCorrectedConfig(dbConfig);
|
||||
|
||||
for (auto & schemaError : schemaChecker.getMessages())
|
||||
for (auto& schemaError : schemaChecker.getMessages())
|
||||
{
|
||||
Warning(_log, "Config Fix: %s", QSTRING_CSTR(schemaError));
|
||||
}
|
||||
|
||||
saveSettings(dbConfig,true);
|
||||
saveSettings(dbConfig, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_qconfig = dbConfig;
|
||||
}
|
||||
|
||||
Debug(_log,"Settings database initialized");
|
||||
Debug(_log, "Settings database initialized");
|
||||
}
|
||||
|
||||
QJsonDocument SettingsManager::getSetting(settings::type type) const
|
||||
@@ -179,11 +194,11 @@ QJsonDocument SettingsManager::getSetting(settings::type type) const
|
||||
QJsonObject SettingsManager::getSettings() const
|
||||
{
|
||||
QJsonObject config;
|
||||
for(const auto & key : _qconfig.keys())
|
||||
for (const auto& key : _qconfig.keys())
|
||||
{
|
||||
//Read all records from database to ensure that global settings are read across instances
|
||||
QJsonDocument doc = _sTable->getSettingsRecord(key);
|
||||
if(doc.isArray())
|
||||
if (doc.isArray())
|
||||
{
|
||||
config.insert(key, doc.array());
|
||||
}
|
||||
@@ -195,26 +210,32 @@ QJsonObject SettingsManager::getSettings() const
|
||||
return config;
|
||||
}
|
||||
|
||||
bool SettingsManager::saveSettings(QJsonObject config, bool correct)
|
||||
bool SettingsManager::restoreSettings(QJsonObject config, bool correct)
|
||||
{
|
||||
// optional data upgrades e.g. imported legacy/older configs
|
||||
// handleConfigUpgrade(config);
|
||||
handleConfigUpgrade(config);
|
||||
return saveSettings(config, correct);
|
||||
}
|
||||
|
||||
bool SettingsManager::saveSettings(QJsonObject config, bool correct)
|
||||
{
|
||||
// we need to validate data against schema
|
||||
QJsonSchemaChecker schemaChecker;
|
||||
schemaChecker.setSchema(schemaJson);
|
||||
if (!schemaChecker.validate(config).first)
|
||||
{
|
||||
if(!correct)
|
||||
if (!correct)
|
||||
{
|
||||
Error(_log,"Failed to save configuration, errors during validation");
|
||||
Error(_log, "Failed to save configuration, errors during validation");
|
||||
return false;
|
||||
}
|
||||
Warning(_log,"Fixing json data!");
|
||||
Warning(_log, "Fixing json data!");
|
||||
config = schemaChecker.getAutoCorrectedConfig(config);
|
||||
|
||||
for (const auto & schemaError : schemaChecker.getMessages())
|
||||
for (const auto& schemaError : schemaChecker.getMessages())
|
||||
{
|
||||
Warning(_log, "Config Fix: %s", QSTRING_CSTR(schemaError));
|
||||
}
|
||||
}
|
||||
|
||||
// store the new config
|
||||
@@ -223,26 +244,26 @@ bool SettingsManager::saveSettings(QJsonObject config, bool correct)
|
||||
// extract keys and data
|
||||
QStringList keyList = config.keys();
|
||||
QStringList newValueList;
|
||||
for(const auto & key : keyList)
|
||||
for (const auto& key : qAsConst(keyList))
|
||||
{
|
||||
if(config[key].isObject())
|
||||
if (config[key].isObject())
|
||||
{
|
||||
newValueList << QString(QJsonDocument(config[key].toObject()).toJson(QJsonDocument::Compact));
|
||||
}
|
||||
else if(config[key].isArray())
|
||||
else if (config[key].isArray())
|
||||
{
|
||||
newValueList << QString(QJsonDocument(config[key].toArray()).toJson(QJsonDocument::Compact));
|
||||
}
|
||||
}
|
||||
|
||||
int rc = true;
|
||||
bool rc = true;
|
||||
// compare database data with new data to emit/save changes accordingly
|
||||
for(const auto & key : keyList)
|
||||
for (const auto& key : qAsConst(keyList))
|
||||
{
|
||||
QString data = newValueList.takeFirst();
|
||||
if(_sTable->getSettingsRecordString(key) != data)
|
||||
if (_sTable->getSettingsRecordString(key) != data)
|
||||
{
|
||||
if ( ! _sTable->createSettingsRecord(key, data) )
|
||||
if (!_sTable->createSettingsRecord(key, data))
|
||||
{
|
||||
rc = false;
|
||||
}
|
||||
@@ -255,7 +276,7 @@ bool SettingsManager::saveSettings(QJsonObject config, bool correct)
|
||||
return rc;
|
||||
}
|
||||
|
||||
inline QString fixVersion (const QString& version)
|
||||
inline QString fixVersion(const QString& version)
|
||||
{
|
||||
QString newVersion;
|
||||
//Try fixing version number, remove dot separated pre-release identifiers not supported
|
||||
@@ -279,12 +300,12 @@ bool SettingsManager::resolveConfigVersion(QJsonObject& config)
|
||||
QString configVersion = generalConfig["configVersion"].toString();
|
||||
QString previousVersion = generalConfig["previousVersion"].toString();
|
||||
|
||||
if ( !configVersion.isEmpty() )
|
||||
if (!configVersion.isEmpty())
|
||||
{
|
||||
isValid = _configVersion.setVersion(configVersion.toStdString());
|
||||
if (!isValid)
|
||||
{
|
||||
isValid = _configVersion.setVersion( fixVersion(configVersion).toStdString() );
|
||||
isValid = _configVersion.setVersion(fixVersion(configVersion).toStdString());
|
||||
if (isValid)
|
||||
{
|
||||
Info(_log, "Invalid config version [%s] fixed. Updated to [%s]", QSTRING_CSTR(configVersion), _configVersion.getVersion().c_str());
|
||||
@@ -293,16 +314,15 @@ bool SettingsManager::resolveConfigVersion(QJsonObject& config)
|
||||
}
|
||||
else
|
||||
{
|
||||
_configVersion.setVersion(DEFAULT_VERSION);
|
||||
isValid = true;
|
||||
}
|
||||
|
||||
if ( !previousVersion.isEmpty() && isValid )
|
||||
if (!previousVersion.isEmpty() && isValid)
|
||||
{
|
||||
isValid = _previousVersion.setVersion(previousVersion.toStdString());
|
||||
if (!isValid)
|
||||
{
|
||||
isValid = _previousVersion.setVersion( fixVersion(previousVersion).toStdString() );
|
||||
isValid = _previousVersion.setVersion(fixVersion(previousVersion).toStdString());
|
||||
if (isValid)
|
||||
{
|
||||
Info(_log, "Invalid previous version [%s] fixed. Updated to [%s]", QSTRING_CSTR(previousVersion), _previousVersion.getVersion().c_str());
|
||||
@@ -323,7 +343,7 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config)
|
||||
bool migrated = false;
|
||||
|
||||
//Only migrate, if valid versions are available
|
||||
if ( !resolveConfigVersion(config) )
|
||||
if (!resolveConfigVersion(config))
|
||||
{
|
||||
Warning(_log, "Invalid version information found in configuration. No database migration executed.");
|
||||
}
|
||||
@@ -333,26 +353,26 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config)
|
||||
if (_previousVersion < _configVersion)
|
||||
{
|
||||
//Migration steps for versions <= alpha 9
|
||||
semver::version targetVersion {"2.0.0-alpha.9"};
|
||||
if (_previousVersion <= targetVersion )
|
||||
semver::version targetVersion{ "2.0.0-alpha.9" };
|
||||
if (_previousVersion <= targetVersion)
|
||||
{
|
||||
Info(_log, "Instance [%u]: Migrate LED Layout from current version [%s] to version [%s] or later", _instance, _previousVersion.getVersion().c_str(), targetVersion.getVersion().c_str());
|
||||
Info(_log, "Instance [%u]: Migrate from version [%s] to version [%s] or later", _instance, _previousVersion.getVersion().c_str(), targetVersion.getVersion().c_str());
|
||||
|
||||
// LED LAYOUT UPGRADE
|
||||
// from { hscan: { minimum: 0.2, maximum: 0.3 }, vscan: { minimum: 0.2, maximum: 0.3 } }
|
||||
// from { h: { min: 0.2, max: 0.3 }, v: { min: 0.2, max: 0.3 } }
|
||||
// to { hmin: 0.2, hmax: 0.3, vmin: 0.2, vmax: 0.3}
|
||||
if(config.contains("leds"))
|
||||
if (config.contains("leds"))
|
||||
{
|
||||
const QJsonArray ledarr = config["leds"].toArray();
|
||||
const QJsonObject led = ledarr[0].toObject();
|
||||
|
||||
if(led.contains("hscan") || led.contains("h"))
|
||||
if (led.contains("hscan") || led.contains("h"))
|
||||
{
|
||||
const bool whscan = led.contains("hscan");
|
||||
QJsonArray newLedarr;
|
||||
|
||||
for(const auto & entry : ledarr)
|
||||
for (const auto& entry : ledarr)
|
||||
{
|
||||
const QJsonObject led = entry.toObject();
|
||||
QJsonObject hscan;
|
||||
@@ -363,7 +383,7 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config)
|
||||
QJsonValue vmax;
|
||||
QJsonObject nL;
|
||||
|
||||
if(whscan)
|
||||
if (whscan)
|
||||
{
|
||||
hscan = led["hscan"].toObject();
|
||||
vscan = led["vscan"].toObject();
|
||||
@@ -391,27 +411,27 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config)
|
||||
// replace
|
||||
config["leds"] = newLedarr;
|
||||
migrated = true;
|
||||
Info(_log,"Instance [%u]: LED Layout migrated", _instance);
|
||||
Info(_log, "Instance [%u]: LED Layout migrated", _instance);
|
||||
}
|
||||
}
|
||||
|
||||
if(config.contains("ledConfig"))
|
||||
if (config.contains("ledConfig"))
|
||||
{
|
||||
QJsonObject oldLedConfig = config["ledConfig"].toObject();
|
||||
if ( !oldLedConfig.contains("classic"))
|
||||
if (!oldLedConfig.contains("classic"))
|
||||
{
|
||||
QJsonObject newLedConfig;
|
||||
newLedConfig.insert("classic", oldLedConfig );
|
||||
QJsonObject defaultMatrixConfig {{"ledshoriz", 1}
|
||||
newLedConfig.insert("classic", oldLedConfig);
|
||||
QJsonObject defaultMatrixConfig{ {"ledshoriz", 1}
|
||||
,{"ledsvert", 1}
|
||||
,{"cabling","snake"}
|
||||
,{"start","top-left"}
|
||||
};
|
||||
newLedConfig.insert("matrix", defaultMatrixConfig );
|
||||
newLedConfig.insert("matrix", defaultMatrixConfig);
|
||||
|
||||
config["ledConfig"] = newLedConfig;
|
||||
migrated = true;
|
||||
Info(_log,"Instance [%u]: LED-Config migrated", _instance);
|
||||
Info(_log, "Instance [%u]: LED-Config migrated", _instance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -429,7 +449,7 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config)
|
||||
const QJsonArray ledarr = config["leds"].toArray();
|
||||
int layoutLedCount = ledarr.size();
|
||||
|
||||
if (hwLedcount < layoutLedCount )
|
||||
if (hwLedcount < layoutLedCount)
|
||||
{
|
||||
Warning(_log, "Instance [%u]: HwLedCount/Layout mismatch! Setting Hardware LED count to number of LEDs configured via layout", _instance);
|
||||
hwLedcount = layoutLedCount;
|
||||
@@ -442,7 +462,7 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config)
|
||||
if (newDeviceConfig.contains("type"))
|
||||
{
|
||||
QString type = newDeviceConfig["type"].toString();
|
||||
if (type == "atmoorb" || type == "fadecandy" || type == "philipshue" )
|
||||
if (type == "atmoorb" || type == "fadecandy" || type == "philipshue")
|
||||
{
|
||||
if (newDeviceConfig.contains("output"))
|
||||
{
|
||||
@@ -520,8 +540,150 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config)
|
||||
Debug(_log, "Framegrabber records migrated");
|
||||
}
|
||||
}
|
||||
|
||||
//Migration steps for versions <= 2.0.12
|
||||
_previousVersion = targetVersion;
|
||||
targetVersion.setVersion("2.0.12");
|
||||
if (_previousVersion <= targetVersion)
|
||||
{
|
||||
Info(_log, "Instance [%u]: Migrate from version [%s] to version [%s] or later", _instance, _previousVersion.getVersion().c_str(), targetVersion.getVersion().c_str());
|
||||
|
||||
// Have Hostname/IP-address separate from port for LED-Devices
|
||||
if (config.contains("device"))
|
||||
{
|
||||
QJsonObject newDeviceConfig = config["device"].toObject();
|
||||
|
||||
if (newDeviceConfig.contains("host"))
|
||||
{
|
||||
QString oldHost = newDeviceConfig["host"].toString();
|
||||
|
||||
// Resolve hostname and port
|
||||
QStringList addressparts = QStringUtils::split(oldHost, ":", QStringUtils::SplitBehavior::SkipEmptyParts);
|
||||
|
||||
newDeviceConfig["host"] = addressparts[0];
|
||||
|
||||
if (addressparts.size() > 1)
|
||||
{
|
||||
if (!newDeviceConfig.contains("port"))
|
||||
{
|
||||
newDeviceConfig["port"] = addressparts[1].toInt();
|
||||
}
|
||||
migrated = true;
|
||||
}
|
||||
|
||||
if (migrated)
|
||||
{
|
||||
config["device"] = newDeviceConfig;
|
||||
Debug(_log, "LED-Device records migrated");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Have Hostname/IP-address separate from port for Forwarder
|
||||
if (config.contains("forwarder"))
|
||||
{
|
||||
QJsonObject newForwarderConfig = config["forwarder"].toObject();
|
||||
|
||||
QJsonArray json;
|
||||
if (newForwarderConfig.contains("json"))
|
||||
{
|
||||
QJsonArray oldJson = newForwarderConfig["json"].toArray();
|
||||
QJsonObject newJsonConfig;
|
||||
|
||||
for (const QJsonValue& value : qAsConst(oldJson))
|
||||
{
|
||||
if (value.isString())
|
||||
{
|
||||
QString oldHost = value.toString();
|
||||
// Resolve hostname and port
|
||||
QStringList addressparts = QStringUtils::split(oldHost, ":", QStringUtils::SplitBehavior::SkipEmptyParts);
|
||||
QString host = addressparts[0];
|
||||
|
||||
if (host != "127.0.0.1")
|
||||
{
|
||||
newJsonConfig["host"] = host;
|
||||
|
||||
if (addressparts.size() > 1)
|
||||
{
|
||||
newJsonConfig["port"] = addressparts[1].toInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
newJsonConfig["port"] = 19444;
|
||||
}
|
||||
json.append(newJsonConfig);
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!json.isEmpty())
|
||||
{
|
||||
newForwarderConfig["json"] = json;
|
||||
}
|
||||
else
|
||||
{
|
||||
newForwarderConfig.remove("json");
|
||||
}
|
||||
}
|
||||
|
||||
QJsonArray flatbuffer;
|
||||
if (newForwarderConfig.contains("flat"))
|
||||
{
|
||||
QJsonArray oldFlatbuffer = newForwarderConfig["flat"].toArray();
|
||||
QJsonObject newFlattbufferConfig;
|
||||
|
||||
for (const QJsonValue& value : qAsConst(oldFlatbuffer))
|
||||
{
|
||||
if (value.isString())
|
||||
{
|
||||
QString oldHost = value.toString();
|
||||
// Resolve hostname and port
|
||||
QStringList addressparts = QStringUtils::split(oldHost, ":", QStringUtils::SplitBehavior::SkipEmptyParts);
|
||||
QString host = addressparts[0];
|
||||
|
||||
if (host != "127.0.0.1")
|
||||
{
|
||||
newFlattbufferConfig["host"] = host;
|
||||
|
||||
if (addressparts.size() > 1)
|
||||
{
|
||||
newFlattbufferConfig["port"] = addressparts[1].toInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
newFlattbufferConfig["port"] = 19400;
|
||||
}
|
||||
|
||||
flatbuffer.append(newFlattbufferConfig);
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flatbuffer.isEmpty())
|
||||
{
|
||||
newForwarderConfig["flat"] = flatbuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
newForwarderConfig.remove("flat");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (json.isEmpty() && flatbuffer.isEmpty())
|
||||
{
|
||||
newForwarderConfig["enable"] = false;
|
||||
}
|
||||
|
||||
if (migrated)
|
||||
{
|
||||
config["forwarder"] = newForwarderConfig;
|
||||
Debug(_log, "Forwarder records migrated");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return migrated;
|
||||
}
|
||||
|
Reference in New Issue
Block a user