From 2260155851574f150f02ebcd8410e744df14084b Mon Sep 17 00:00:00 2001 From: Murat Date: Tue, 8 Sep 2020 21:00:56 +0200 Subject: [PATCH 1/2] Return tan to API requests whenever possible --- include/api/JsonAPI.h | 2 +- libsrc/api/JsonAPI.cpp | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/api/JsonAPI.h b/include/api/JsonAPI.h index f83655544..0601415da 100644 --- a/include/api/JsonAPI.h +++ b/include/api/JsonAPI.h @@ -280,7 +280,7 @@ private slots: /// /// Handle an incoming JSON message of unknown type /// - void handleNotImplemented(); + void handleNotImplemented(const QString &command, int tan); /// /// Send a standard reply indicating success diff --git a/libsrc/api/JsonAPI.cpp b/libsrc/api/JsonAPI.cpp index 44ce26d7f..4933b0b5e 100644 --- a/libsrc/api/JsonAPI.cpp +++ b/libsrc/api/JsonAPI.cpp @@ -97,10 +97,14 @@ void JsonAPI::handleMessage(const QString &messageString, const QString &httpAut return; } + int tan = -1; + if (message.value("tan") != QJsonValue::Undefined) + tan = message["tan"].toInt(); + // check basic message if (!JsonUtils::validate(ident, message, ":schema", _log)) { - sendErrorReply("Errors during message validation, please consult the Hyperion Log."); + sendErrorReply("Errors during message validation, please consult the Hyperion Log.", "" /*command*/, tan); return; } @@ -108,12 +112,10 @@ void JsonAPI::handleMessage(const QString &messageString, const QString &httpAut const QString command = message["command"].toString(); if (!JsonUtils::validate(ident, message, QString(":schema-%1").arg(command), _log)) { - sendErrorReply("Errors during specific message validation, please consult the Hyperion Log", command); + sendErrorReply("Errors during specific message validation, please consult the Hyperion Log", command, tan); return; } - int tan = message["tan"].toInt(); - // client auth before everything else but not for http if (!_noListener && command == "authorize") { @@ -177,12 +179,12 @@ void JsonAPI::handleMessage(const QString &messageString, const QString &httpAut else if (command == "clearall") handleClearallCommand(message, command, tan); else if (command == "transform" || command == "correction" || command == "temperature") - sendErrorReply("The command " + command + "is deprecated, please use the Hyperion Web Interface to configure"); + sendErrorReply("The command " + command + "is deprecated, please use the Hyperion Web Interface to configure", command, tan); // END // handle not implemented commands else - handleNotImplemented(); + handleNotImplemented(command, tan); } void JsonAPI::handleColorCommand(const QJsonObject &message, const QString &command, int tan) @@ -1426,9 +1428,9 @@ void JsonAPI::handleLedDeviceCommand(const QJsonObject &message, const QString & } } -void JsonAPI::handleNotImplemented() +void JsonAPI::handleNotImplemented(const QString &command, int tan) { - sendErrorReply("Command not implemented"); + sendErrorReply("Command not implemented", command, tan); } void JsonAPI::sendSuccessReply(const QString &command, int tan) From b59eb8faebccecfb9ed711355f2186f29cb53cb9 Mon Sep 17 00:00:00 2001 From: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com> Date: Mon, 14 Sep 2020 20:07:51 +0200 Subject: [PATCH 2/2] Set default tan to value 0 --- libsrc/api/JsonAPI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/api/JsonAPI.cpp b/libsrc/api/JsonAPI.cpp index 4933b0b5e..a3b0d0314 100644 --- a/libsrc/api/JsonAPI.cpp +++ b/libsrc/api/JsonAPI.cpp @@ -97,7 +97,7 @@ void JsonAPI::handleMessage(const QString &messageString, const QString &httpAut return; } - int tan = -1; + int tan = 0; if (message.value("tan") != QJsonValue::Undefined) tan = message["tan"].toInt();