mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Refactor Hyperion JSON-API (#1727)
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
#include <utils/FileUtils.h>
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QPair>
|
||||
#include <QStringList>
|
||||
#include <utils/Logger.h>
|
||||
|
||||
namespace JsonUtils {
|
||||
@@ -14,7 +16,7 @@ namespace JsonUtils {
|
||||
/// @param[in] ignError Ignore errors during file read (no log output)
|
||||
/// @return true on success else false
|
||||
///
|
||||
bool readFile(const QString& path, QJsonObject& obj, Logger* log, bool ignError=false);
|
||||
QPair<bool, QStringList> readFile(const QString& path, QJsonObject& obj, Logger* log, bool ignError=false);
|
||||
|
||||
///
|
||||
/// @brief read a schema file and resolve $refs
|
||||
@@ -33,7 +35,7 @@ namespace JsonUtils {
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @return true on success else false
|
||||
///
|
||||
bool parse(const QString& path, const QString& data, QJsonObject& obj, Logger* log);
|
||||
QPair<bool, QStringList> parse(const QString& path, const QString& data, QJsonObject& obj, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief parse a json QString and get a QJsonArray. Overloaded function
|
||||
@@ -42,8 +44,8 @@ namespace JsonUtils {
|
||||
/// @param[out] arr Retuns the parsed QJsonArray
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @return true on success else false
|
||||
///
|
||||
bool parse(const QString& path, const QString& data, QJsonArray& arr, Logger* log);
|
||||
//
|
||||
QPair<bool, QStringList> parse(const QString& path, const QString& data, QJsonArray& arr, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief parse a json QString and get a QJsonDocument
|
||||
@@ -53,7 +55,7 @@ namespace JsonUtils {
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @return true on success else false
|
||||
///
|
||||
bool parse(const QString& path, const QString& data, QJsonDocument& doc, Logger* log);
|
||||
QPair<bool, QStringList> parse(const QString& path, const QString& data, QJsonDocument& doc, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief Validate json data against a schema
|
||||
@@ -63,7 +65,7 @@ namespace JsonUtils {
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @return true on success else false
|
||||
///
|
||||
bool validate(const QString& file, const QJsonObject& json, const QString& schemaPath, Logger* log);
|
||||
QPair<bool, QStringList> validate(const QString& file, const QJsonObject& json, const QString& schemaPath, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief Validate json data against a schema
|
||||
@@ -73,7 +75,7 @@ namespace JsonUtils {
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @return true on success else false
|
||||
///
|
||||
bool validate(const QString& file, const QJsonObject& json, const QJsonObject& schema, Logger* log);
|
||||
QPair<bool, QStringList> validate(const QString& file, const QJsonObject& json, const QJsonObject& schema, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief Write json data to file
|
||||
|
@@ -47,7 +47,9 @@ private slots:
|
||||
private:
|
||||
Logger* _log;
|
||||
/// True when internet access is allowed
|
||||
bool _internetAccessAllowed;
|
||||
bool _isInternetAccessAllowed;
|
||||
/// True when internet access is restricted by a white list
|
||||
bool _isInternetAccessRestricted;
|
||||
/// Whitelisted ip addresses
|
||||
QList<QHostAddress> _ipWhitelist;
|
||||
|
||||
|
@@ -31,7 +31,9 @@ public:
|
||||
if (!schemaChecker.validate(configTree).first)
|
||||
{
|
||||
for (int i = 0; i < messages.size(); ++i)
|
||||
{
|
||||
std::cout << messages[i].toStdString() << std::endl;
|
||||
}
|
||||
|
||||
std::cerr << "Validation failed for configuration file: " << config.toStdString() << std::endl;
|
||||
return -3;
|
||||
@@ -61,9 +63,10 @@ public:
|
||||
if (error.error != QJsonParseError::NoError)
|
||||
{
|
||||
// report to the user the failure and their locations in the document.
|
||||
int errorLine(0), errorColumn(0);
|
||||
int errorLine(0);
|
||||
int errorColumn(0);
|
||||
|
||||
for( int i=0, count=qMin( error.offset,config.size()); i<count; ++i )
|
||||
for(long i=0, count=qMin( error.offset,config.size()); i<count; ++i )
|
||||
{
|
||||
++errorColumn;
|
||||
if(config.at(i) == '\n' )
|
||||
|
Reference in New Issue
Block a user