check config when writing (#405)

* check config when writing

* integrate #403
This commit is contained in:
redPanther 2017-02-26 15:30:10 +01:00 committed by GitHub
parent 26154befa4
commit 72e2f0bf18
3 changed files with 30 additions and 5 deletions

View File

@ -107,8 +107,8 @@ To generate make files on OS X:
After which you can run cmake with the correct qt5 path: After which you can run cmake with the correct qt5 path:
``` ```
cmake -DCMAKE_PREFIX_PATH=/usr/local/Cellar/qt5/5.7.0 -DCMAKE_BUILD_TYPE=Release .. export QVER=$(find /usr/local/Cellar/qt5 -type d -name "5.*" | sort -n | head -n1)
``` cmake -DCMAKE_PREFIX_PATH=$QVER -DCMAKE_BUILD_TYPE=Release ..```
### Run make to build Hyperion ### Run make to build Hyperion
The `-j $(nproc)` specifies the amount of CPU cores to use. The `-j $(nproc)` specifies the amount of CPU cores to use.

View File

@ -101,9 +101,34 @@ void CgiHandler::cmd_cfg_set()
if (error.error == QJsonParseError::NoError) if (error.error == QJsonParseError::NoError)
{ {
QJsonObject hyperionConfigJsonObj = hyperionConfig.object(); QJsonObject hyperionConfigJsonObj = hyperionConfig.object();
try
{
// make sure the resources are loaded (they may be left out after static linking)
Q_INIT_RESOURCE(resource);
QJsonObject schemaJson = QJsonFactory::readSchema(":/hyperion-schema-"+QString::number(_hyperion->getConfigVersionId()));
QJsonSchemaChecker schemaChecker;
schemaChecker.setSchema(schemaJson);
if ( schemaChecker.validate(hyperionConfigJsonObj) )
{
QJsonFactory::writeJson(QString::fromStdString(_hyperion->getConfigFileName()), hyperionConfigJsonObj); QJsonFactory::writeJson(QString::fromStdString(_hyperion->getConfigFileName()), hyperionConfigJsonObj);
} }
else else
{
std::string errorMsg = "ERROR: Json validation failed: \n";
for (std::list<std::string>::const_iterator i = schemaChecker.getMessages().begin(); i != schemaChecker.getMessages().end(); ++i)
{
Error(_log, "config write validation: %s", (*i).c_str());
errorMsg += *i + "\n";
}
throw std::runtime_error(errorMsg.c_str());
}
}
catch(const std::runtime_error& validate_error)
{
_reply->appendRawData (QString(validate_error.what()).toUtf8());
}
}
else
{ {
//Debug(_log, "error while saving: %s", error.errorString()).toLocal8bit.constData()); //Debug(_log, "error while saving: %s", error.errorString()).toLocal8bit.constData());
_reply->appendRawData (QString("Error while validating json: "+error.errorString()).toUtf8()); _reply->appendRawData (QString("Error while validating json: "+error.errorString()).toUtf8());