mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
fix formatting of JsonApi.cpp
This commit is contained in:
parent
a30e67fc11
commit
06118fbcee
@ -57,8 +57,7 @@
|
|||||||
using namespace hyperion;
|
using namespace hyperion;
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
|
|
||||||
constexpr std::chrono::milliseconds NEW_TOKEN_REQUEST_TIMEOUT{ 180000 };
|
constexpr std::chrono::milliseconds NEW_TOKEN_REQUEST_TIMEOUT{ 180000 };
|
||||||
|
|
||||||
@ -76,7 +75,10 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
JsonAPI::JsonAPI(QString peerAddress, Logger *log, bool localConnection, QObject *parent, bool noListener)
|
JsonAPI::JsonAPI(QString peerAddress, Logger *log, bool localConnection, QObject *parent, bool noListener)
|
||||||
: API(log, localConnection, parent), _noListener(noListener), _peerAddress(std::move(peerAddress)), _jsonCB(nullptr)
|
: API(log, localConnection, parent)
|
||||||
|
,_noListener(noListener)
|
||||||
|
,_peerAddress (std::move(peerAddress))
|
||||||
|
,_jsonCB (nullptr)
|
||||||
{
|
{
|
||||||
Q_INIT_RESOURCE(JSONRPC_schemas);
|
Q_INIT_RESOURCE(JSONRPC_schemas);
|
||||||
|
|
||||||
@ -186,12 +188,10 @@ void JsonAPI::handleMessage(const QString &messageString, const QString &httpAut
|
|||||||
if (!httpAuthHeader.isEmpty())
|
if (!httpAuthHeader.isEmpty())
|
||||||
{
|
{
|
||||||
int bearTokenLenght {0};
|
int bearTokenLenght {0};
|
||||||
if (httpAuthHeader.startsWith(BEARER_TOKEN_TAG, Qt::CaseInsensitive))
|
if (httpAuthHeader.startsWith(BEARER_TOKEN_TAG, Qt::CaseInsensitive)) {
|
||||||
{
|
|
||||||
bearTokenLenght = BEARER_TOKEN_TAG_LENGTH;
|
bearTokenLenght = BEARER_TOKEN_TAG_LENGTH;
|
||||||
}
|
}
|
||||||
else if (httpAuthHeader.startsWith(TOKEN_TAG, Qt::CaseInsensitive))
|
else if (httpAuthHeader.startsWith(TOKEN_TAG, Qt::CaseInsensitive)) {
|
||||||
{
|
|
||||||
bearTokenLenght = TOKEN_TAG_LENGTH;
|
bearTokenLenght = TOKEN_TAG_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,8 +253,7 @@ void JsonAPI::handleInstanceCommand(const JsonApiCommand &cmd, const QJsonObject
|
|||||||
if (instanceElement.isDouble())
|
if (instanceElement.isDouble())
|
||||||
{
|
{
|
||||||
instances.append(instanceElement);
|
instances.append(instanceElement);
|
||||||
}
|
} else if (instanceElement.isArray())
|
||||||
else if (instanceElement.isArray())
|
|
||||||
{
|
{
|
||||||
instances = instanceElement.toArray();
|
instances = instanceElement.toArray();
|
||||||
}
|
}
|
||||||
@ -272,8 +271,7 @@ void JsonAPI::handleInstanceCommand(const JsonApiCommand &cmd, const QJsonObject
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (const auto &instance : std::as_const(instances))
|
for (const auto &instance : std::as_const(instances)) {
|
||||||
{
|
|
||||||
|
|
||||||
quint8 instanceIdx = static_cast<quint8>(instance.toInt());
|
quint8 instanceIdx = static_cast<quint8>(instance.toInt());
|
||||||
if (instance.isDouble() && runningInstanceIdxs.contains(instanceIdx))
|
if (instance.isDouble() && runningInstanceIdxs.contains(instanceIdx))
|
||||||
@ -316,8 +314,7 @@ void JsonAPI::handleInstanceCommand(const JsonApiCommand &cmd, const QJsonObject
|
|||||||
|
|
||||||
void JsonAPI::handleCommand(const JsonApiCommand& cmd, const QJsonObject &message)
|
void JsonAPI::handleCommand(const JsonApiCommand& cmd, const QJsonObject &message)
|
||||||
{
|
{
|
||||||
switch (cmd.command)
|
switch (cmd.command) {
|
||||||
{
|
|
||||||
case Command::Authorize:
|
case Command::Authorize:
|
||||||
handleAuthorizeCommand(message, cmd);
|
handleAuthorizeCommand(message, cmd);
|
||||||
break;
|
break;
|
||||||
@ -495,8 +492,7 @@ void JsonAPI::handleColorCommand(const QJsonObject &message, const JsonApiComman
|
|||||||
colors.reserve(static_cast<std::vector<uint8_t>::size_type>(jsonColor.size()));
|
colors.reserve(static_cast<std::vector<uint8_t>::size_type>(jsonColor.size()));
|
||||||
// Transform each entry in jsonColor to uint8_t and append to colors
|
// Transform each entry in jsonColor to uint8_t and append to colors
|
||||||
std::transform(jsonColor.begin(), jsonColor.end(), std::back_inserter(colors),
|
std::transform(jsonColor.begin(), jsonColor.end(), std::back_inserter(colors),
|
||||||
[](const QJsonValue &value)
|
[](const QJsonValue &value) { return static_cast<uint8_t>(value.toInt()); });
|
||||||
{ return static_cast<uint8_t>(value.toInt()); });
|
|
||||||
|
|
||||||
API::setColor(priority, colors, duration, origin);
|
API::setColor(priority, colors, duration, origin);
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
@ -518,12 +514,9 @@ void JsonAPI::handleImageCommand(const QJsonObject &message, const JsonApiComman
|
|||||||
idata.data = QByteArray::fromBase64(QByteArray(message["imagedata"].toString().toUtf8()));
|
idata.data = QByteArray::fromBase64(QByteArray(message["imagedata"].toString().toUtf8()));
|
||||||
QString replyMsg;
|
QString replyMsg;
|
||||||
|
|
||||||
if (API::setImage(idata, COMP_IMAGE, replyMsg))
|
if (API::setImage(idata, COMP_IMAGE, replyMsg)) {
|
||||||
{
|
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sendErrorReply(replyMsg, cmd);
|
sendErrorReply(replyMsg, cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -542,12 +535,9 @@ void JsonAPI::handleEffectCommand(const QJsonObject &message, const JsonApiComma
|
|||||||
dat.data = message["imageData"].toString("").toUtf8();
|
dat.data = message["imageData"].toString("").toUtf8();
|
||||||
dat.args = message["effect"].toObject()["args"].toObject();
|
dat.args = message["effect"].toObject()["args"].toObject();
|
||||||
|
|
||||||
if (API::setEffect(dat))
|
if (API::setEffect(dat)) {
|
||||||
{
|
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sendErrorReply("Effect '" + dat.effectName + "' not found", cmd);
|
sendErrorReply("Effect '" + dat.effectName + "' not found", cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -575,8 +565,7 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject &message, const JsonApiC
|
|||||||
QJsonObject info {};
|
QJsonObject info {};
|
||||||
QStringList errorDetails;
|
QStringList errorDetails;
|
||||||
|
|
||||||
switch (cmd.getSubCommand())
|
switch (cmd.getSubCommand()) {
|
||||||
{
|
|
||||||
case SubCommand::Empty:
|
case SubCommand::Empty:
|
||||||
case SubCommand::GetInfo:
|
case SubCommand::GetInfo:
|
||||||
info["priorities"] = JsonInfo::getPrioritiestInfo(_hyperion);
|
info["priorities"] = JsonInfo::getPrioritiestInfo(_hyperion);
|
||||||
@ -620,8 +609,7 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject &message, const JsonApiC
|
|||||||
{
|
{
|
||||||
const QJsonObject ¶ms = message["data"].toObject();
|
const QJsonObject ¶ms = message["data"].toObject();
|
||||||
const QJsonArray &subscriptions = params["subscriptions"].toArray();
|
const QJsonArray &subscriptions = params["subscriptions"].toArray();
|
||||||
if (subscriptions.isEmpty())
|
if (subscriptions.isEmpty()) {
|
||||||
{
|
|
||||||
sendErrorReply("Invalid params", {"No subscriptions provided"}, cmd);
|
sendErrorReply("Invalid params", {"No subscriptions provided"}, cmd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -685,16 +673,14 @@ void JsonAPI::handleAdjustmentCommand(const QJsonObject &message, const JsonApiC
|
|||||||
const QJsonObject &adjustment = message["adjustment"].toObject();
|
const QJsonObject &adjustment = message["adjustment"].toObject();
|
||||||
|
|
||||||
const QList<QString> adjustmentIds = _hyperion->getAdjustmentIds();
|
const QList<QString> adjustmentIds = _hyperion->getAdjustmentIds();
|
||||||
if (adjustmentIds.isEmpty())
|
if (adjustmentIds.isEmpty()) {
|
||||||
{
|
|
||||||
sendErrorReply("No adjustment data available", cmd);
|
sendErrorReply("No adjustment data available", cmd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString adjustmentId = adjustment["id"].toString(adjustmentIds.first());
|
const QString adjustmentId = adjustment["id"].toString(adjustmentIds.first());
|
||||||
ColorAdjustment *colorAdjustment = _hyperion->getAdjustment(adjustmentId);
|
ColorAdjustment *colorAdjustment = _hyperion->getAdjustment(adjustmentId);
|
||||||
if (colorAdjustment == nullptr)
|
if (colorAdjustment == nullptr) {
|
||||||
{
|
|
||||||
Warning(_log, "Incorrect adjustment identifier: %s", adjustmentId.toStdString().c_str());
|
Warning(_log, "Incorrect adjustment identifier: %s", adjustmentId.toStdString().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -718,11 +704,9 @@ void JsonAPI::applyColorAdjustments(const QJsonObject &adjustment, ColorAdjustme
|
|||||||
|
|
||||||
void JsonAPI::applyColorAdjustment(const QString &colorName, const QJsonObject &adjustment, RgbChannelAdjustment &rgbAdjustment)
|
void JsonAPI::applyColorAdjustment(const QString &colorName, const QJsonObject &adjustment, RgbChannelAdjustment &rgbAdjustment)
|
||||||
{
|
{
|
||||||
if (adjustment.contains(colorName))
|
if (adjustment.contains(colorName)) {
|
||||||
{
|
|
||||||
const QJsonArray &values = adjustment[colorName].toArray();
|
const QJsonArray &values = adjustment[colorName].toArray();
|
||||||
if (values.size() >= 3)
|
if (values.size() >= 3) {
|
||||||
{
|
|
||||||
rgbAdjustment.setAdjustment(static_cast<uint8_t>(values[0U].toInt()),
|
rgbAdjustment.setAdjustment(static_cast<uint8_t>(values[0U].toInt()),
|
||||||
static_cast<uint8_t>(values[1U].toInt()),
|
static_cast<uint8_t>(values[1U].toInt()),
|
||||||
static_cast<uint8_t>(values[2U].toInt()));
|
static_cast<uint8_t>(values[2U].toInt()));
|
||||||
@ -746,8 +730,7 @@ void JsonAPI::applyTransforms(const QJsonObject &adjustment, ColorAdjustment *co
|
|||||||
|
|
||||||
void JsonAPI::applyGammaTransform(const QString &transformName, const QJsonObject &adjustment, RgbTransform &rgbTransform, char channel)
|
void JsonAPI::applyGammaTransform(const QString &transformName, const QJsonObject &adjustment, RgbTransform &rgbTransform, char channel)
|
||||||
{
|
{
|
||||||
if (adjustment.contains(transformName))
|
if (adjustment.contains(transformName)) {
|
||||||
{
|
|
||||||
rgbTransform.setGamma(channel == 'r' ? adjustment[transformName].toDouble() : rgbTransform.getGammaR(),
|
rgbTransform.setGamma(channel == 'r' ? adjustment[transformName].toDouble() : rgbTransform.getGammaR(),
|
||||||
channel == 'g' ? adjustment[transformName].toDouble() : rgbTransform.getGammaG(),
|
channel == 'g' ? adjustment[transformName].toDouble() : rgbTransform.getGammaG(),
|
||||||
channel == 'b' ? adjustment[transformName].toDouble() : rgbTransform.getGammaB());
|
channel == 'b' ? adjustment[transformName].toDouble() : rgbTransform.getGammaB());
|
||||||
@ -757,8 +740,7 @@ void JsonAPI::applyGammaTransform(const QString &transformName, const QJsonObjec
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(bool))
|
void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(bool))
|
||||||
{
|
{
|
||||||
if (adjustment.contains(transformName))
|
if (adjustment.contains(transformName)) {
|
||||||
{
|
|
||||||
(transform.*setFunction)(adjustment[transformName].toBool());
|
(transform.*setFunction)(adjustment[transformName].toBool());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -766,8 +748,7 @@ void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &ad
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(double))
|
void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(double))
|
||||||
{
|
{
|
||||||
if (adjustment.contains(transformName))
|
if (adjustment.contains(transformName)) {
|
||||||
{
|
|
||||||
(transform.*setFunction)(adjustment[transformName].toDouble());
|
(transform.*setFunction)(adjustment[transformName].toDouble());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -775,8 +756,7 @@ void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &ad
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(int))
|
void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(int))
|
||||||
{
|
{
|
||||||
if (adjustment.contains(transformName))
|
if (adjustment.contains(transformName)) {
|
||||||
{
|
|
||||||
(transform.*setFunction)(adjustment[transformName].toInt());
|
(transform.*setFunction)(adjustment[transformName].toInt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -784,8 +764,7 @@ void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &ad
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(uint8_t))
|
void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(uint8_t))
|
||||||
{
|
{
|
||||||
if (adjustment.contains(transformName))
|
if (adjustment.contains(transformName)) {
|
||||||
{
|
|
||||||
(transform.*setFunction)(static_cast<uint8_t>(adjustment[transformName].toInt()));
|
(transform.*setFunction)(static_cast<uint8_t>(adjustment[transformName].toInt()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -810,8 +789,7 @@ void JsonAPI::handleSourceSelectCommand(const QJsonObject &message, const JsonAp
|
|||||||
|
|
||||||
void JsonAPI::handleConfigCommand(const QJsonObject& message, const JsonApiCommand& cmd)
|
void JsonAPI::handleConfigCommand(const QJsonObject& message, const JsonApiCommand& cmd)
|
||||||
{
|
{
|
||||||
switch (cmd.subCommand)
|
switch (cmd.subCommand) {
|
||||||
{
|
|
||||||
case SubCommand::GetSchema:
|
case SubCommand::GetSchema:
|
||||||
handleSchemaGetCommand(message, cmd);
|
handleSchemaGetCommand(message, cmd);
|
||||||
break;
|
break;
|
||||||
@ -893,8 +871,7 @@ void JsonAPI::handleConfigSetCommand(const QJsonObject &message, const JsonApiCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
QMapIterator<quint8, QJsonObject> i (instancesNewConfigs);
|
QMapIterator<quint8, QJsonObject> i (instancesNewConfigs);
|
||||||
while (i.hasNext())
|
while (i.hasNext()) {
|
||||||
{
|
|
||||||
i.next();
|
i.next();
|
||||||
|
|
||||||
quint8 idx = i.key();
|
quint8 idx = i.key();
|
||||||
@ -927,10 +904,8 @@ void JsonAPI::handleConfigGetCommand(const QJsonObject &message, const JsonApiCo
|
|||||||
if (!globalConfig.isEmpty())
|
if (!globalConfig.isEmpty())
|
||||||
{
|
{
|
||||||
const QJsonArray globalTypes = globalConfig["types"].toArray();
|
const QJsonArray globalTypes = globalConfig["types"].toArray();
|
||||||
for (const auto &type : globalTypes)
|
for (const auto &type : globalTypes) {
|
||||||
{
|
if (type.isString()) {
|
||||||
if (type.isString())
|
|
||||||
{
|
|
||||||
globalFilterTypes.append(type.toString());
|
globalFilterTypes.append(type.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -944,10 +919,8 @@ void JsonAPI::handleConfigGetCommand(const QJsonObject &message, const JsonApiCo
|
|||||||
{
|
{
|
||||||
QList<quint8> configuredInstanceIds = _instanceManager->getInstanceIds();
|
QList<quint8> configuredInstanceIds = _instanceManager->getInstanceIds();
|
||||||
const QJsonArray instanceIds = instances["ids"].toArray();
|
const QJsonArray instanceIds = instances["ids"].toArray();
|
||||||
for (const auto &idx : instanceIds)
|
for (const auto &idx : instanceIds) {
|
||||||
{
|
if (idx.isDouble()) {
|
||||||
if (idx.isDouble())
|
|
||||||
{
|
|
||||||
quint8 instanceId = static_cast<quint8>(idx.toInt());
|
quint8 instanceId = static_cast<quint8>(idx.toInt());
|
||||||
if (configuredInstanceIds.contains(instanceId))
|
if (configuredInstanceIds.contains(instanceId))
|
||||||
{
|
{
|
||||||
@ -961,10 +934,8 @@ void JsonAPI::handleConfigGetCommand(const QJsonObject &message, const JsonApiCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QJsonArray instanceTypes = instances["types"].toArray();
|
const QJsonArray instanceTypes = instances["types"].toArray();
|
||||||
for (const auto &type : instanceTypes)
|
for (const auto &type : instanceTypes) {
|
||||||
{
|
if (type.isString()) {
|
||||||
if (type.isString())
|
|
||||||
{
|
|
||||||
instanceFilterTypes.append(type.toString());
|
instanceFilterTypes.append(type.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1095,20 +1066,16 @@ void JsonAPI::handleComponentStateCommand(const QJsonObject &message, const Json
|
|||||||
bool compState = componentState["state"].toBool(true);
|
bool compState = componentState["state"].toBool(true);
|
||||||
QString replyMsg;
|
QString replyMsg;
|
||||||
|
|
||||||
if (API::setComponentState(comp, compState, replyMsg))
|
if (API::setComponentState(comp, compState, replyMsg)) {
|
||||||
{
|
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sendErrorReply(replyMsg, cmd);
|
sendErrorReply(replyMsg, cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonAPI::handleLedColorsCommand(const QJsonObject& /*message*/, const JsonApiCommand& cmd)
|
void JsonAPI::handleLedColorsCommand(const QJsonObject& /*message*/, const JsonApiCommand& cmd)
|
||||||
{
|
{
|
||||||
switch (cmd.subCommand)
|
switch (cmd.subCommand) {
|
||||||
{
|
|
||||||
case SubCommand::LedStreamStart:
|
case SubCommand::LedStreamStart:
|
||||||
_jsonCB->subscribe( Subscription::LedColorsUpdate);
|
_jsonCB->subscribe( Subscription::LedColorsUpdate);
|
||||||
// push once
|
// push once
|
||||||
@ -1138,8 +1105,7 @@ void JsonAPI::handleLedColorsCommand(const QJsonObject & /*message*/, const Json
|
|||||||
|
|
||||||
void JsonAPI::handleLoggingCommand(const QJsonObject& /*message*/, const JsonApiCommand& cmd)
|
void JsonAPI::handleLoggingCommand(const QJsonObject& /*message*/, const JsonApiCommand& cmd)
|
||||||
{
|
{
|
||||||
switch (cmd.subCommand)
|
switch (cmd.subCommand) {
|
||||||
{
|
|
||||||
case SubCommand::Start:
|
case SubCommand::Start:
|
||||||
_jsonCB->subscribe("logmsg-update");
|
_jsonCB->subscribe("logmsg-update");
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
@ -1168,8 +1134,7 @@ void JsonAPI::handleVideoModeCommand(const QJsonObject &message, const JsonApiCo
|
|||||||
|
|
||||||
void JsonAPI::handleAuthorizeCommand(const QJsonObject &message, const JsonApiCommand& cmd)
|
void JsonAPI::handleAuthorizeCommand(const QJsonObject &message, const JsonApiCommand& cmd)
|
||||||
{
|
{
|
||||||
switch (cmd.subCommand)
|
switch (cmd.subCommand) {
|
||||||
{
|
|
||||||
case SubCommand::TokenRequired:
|
case SubCommand::TokenRequired:
|
||||||
handleTokenRequired(cmd);
|
handleTokenRequired(cmd);
|
||||||
break;
|
break;
|
||||||
@ -1244,12 +1209,9 @@ void JsonAPI::handleNewPassword(const QJsonObject &message, const JsonApiCommand
|
|||||||
{
|
{
|
||||||
const QString password = message["password"].toString().trimmed();
|
const QString password = message["password"].toString().trimmed();
|
||||||
const QString newPassword = message["newPassword"].toString().trimmed();
|
const QString newPassword = message["newPassword"].toString().trimmed();
|
||||||
if (API::updateHyperionPassword(password, newPassword))
|
if (API::updateHyperionPassword(password, newPassword)) {
|
||||||
{
|
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sendErrorReply("Failed to update user password", cmd);
|
sendErrorReply("Failed to update user password", cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1259,17 +1221,14 @@ void JsonAPI::handleCreateToken(const QJsonObject &message, const JsonApiCommand
|
|||||||
const QString &comment = message["comment"].toString().trimmed();
|
const QString &comment = message["comment"].toString().trimmed();
|
||||||
AuthManager::AuthDefinition def;
|
AuthManager::AuthDefinition def;
|
||||||
const QString createTokenResult = API::createToken(comment, def);
|
const QString createTokenResult = API::createToken(comment, def);
|
||||||
if (createTokenResult.isEmpty())
|
if (createTokenResult.isEmpty()) {
|
||||||
{
|
|
||||||
QJsonObject newTok;
|
QJsonObject newTok;
|
||||||
newTok["comment"] = def.comment;
|
newTok["comment"] = def.comment;
|
||||||
newTok["id"] = def.id;
|
newTok["id"] = def.id;
|
||||||
newTok["token"] = def.token;
|
newTok["token"] = def.token;
|
||||||
|
|
||||||
sendSuccessDataReply(newTok, cmd);
|
sendSuccessDataReply(newTok, cmd);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sendErrorReply("Token creation failed", {createTokenResult}, cmd);
|
sendErrorReply("Token creation failed", {createTokenResult}, cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1279,12 +1238,9 @@ void JsonAPI::handleRenameToken(const QJsonObject &message, const JsonApiCommand
|
|||||||
const QString &identifier = message["id"].toString().trimmed();
|
const QString &identifier = message["id"].toString().trimmed();
|
||||||
const QString &comment = message["comment"].toString().trimmed();
|
const QString &comment = message["comment"].toString().trimmed();
|
||||||
const QString renameTokenResult = API::renameToken(identifier, comment);
|
const QString renameTokenResult = API::renameToken(identifier, comment);
|
||||||
if (renameTokenResult.isEmpty())
|
if (renameTokenResult.isEmpty()) {
|
||||||
{
|
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sendErrorReply("Token rename failed", {renameTokenResult}, cmd);
|
sendErrorReply("Token rename failed", {renameTokenResult}, cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1293,12 +1249,9 @@ void JsonAPI::handleDeleteToken(const QJsonObject &message, const JsonApiCommand
|
|||||||
{
|
{
|
||||||
const QString &identifier = message["id"].toString().trimmed();
|
const QString &identifier = message["id"].toString().trimmed();
|
||||||
const QString deleteTokenResult = API::deleteToken(identifier);
|
const QString deleteTokenResult = API::deleteToken(identifier);
|
||||||
if (deleteTokenResult.isEmpty())
|
if (deleteTokenResult.isEmpty()) {
|
||||||
{
|
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sendErrorReply("Token deletion failed", {deleteTokenResult}, cmd);
|
sendErrorReply("Token deletion failed", {deleteTokenResult}, cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1308,12 +1261,9 @@ void JsonAPI::handleRequestToken(const QJsonObject &message, const JsonApiComman
|
|||||||
const QString &identifier = message["id"].toString().trimmed();
|
const QString &identifier = message["id"].toString().trimmed();
|
||||||
const QString &comment = message["comment"].toString().trimmed();
|
const QString &comment = message["comment"].toString().trimmed();
|
||||||
const bool &acc = message["accept"].toBool(true);
|
const bool &acc = message["accept"].toBool(true);
|
||||||
if (acc)
|
if (acc) {
|
||||||
{
|
|
||||||
API::setNewTokenRequest(comment, identifier, cmd.tan);
|
API::setNewTokenRequest(comment, identifier, cmd.tan);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
API::cancelNewTokenRequest(comment, identifier);
|
API::cancelNewTokenRequest(comment, identifier);
|
||||||
// client should wait for answer
|
// client should wait for answer
|
||||||
}
|
}
|
||||||
@ -1322,8 +1272,7 @@ void JsonAPI::handleRequestToken(const QJsonObject &message, const JsonApiComman
|
|||||||
void JsonAPI::handleGetPendingTokenRequests(const JsonApiCommand& cmd)
|
void JsonAPI::handleGetPendingTokenRequests(const JsonApiCommand& cmd)
|
||||||
{
|
{
|
||||||
QVector<AuthManager::AuthDefinition> vec;
|
QVector<AuthManager::AuthDefinition> vec;
|
||||||
if (API::getPendingTokenRequests(vec))
|
if (API::getPendingTokenRequests(vec)) {
|
||||||
{
|
|
||||||
QJsonArray pendingTokeRequests;
|
QJsonArray pendingTokeRequests;
|
||||||
for (const auto &entry : std::as_const(vec))
|
for (const auto &entry : std::as_const(vec))
|
||||||
{
|
{
|
||||||
@ -1342,12 +1291,9 @@ void JsonAPI::handleAnswerRequest(const QJsonObject &message, const JsonApiComma
|
|||||||
{
|
{
|
||||||
const QString &identifier = message["id"].toString().trimmed();
|
const QString &identifier = message["id"].toString().trimmed();
|
||||||
const bool &accept = message["accept"].toBool(false);
|
const bool &accept = message["accept"].toBool(false);
|
||||||
if (API::handlePendingTokenRequest(identifier, accept))
|
if (API::handlePendingTokenRequest(identifier, accept)) {
|
||||||
{
|
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sendErrorReply("Unable to handle token acceptance or denial", cmd);
|
sendErrorReply("Unable to handle token acceptance or denial", cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1379,12 +1325,9 @@ void JsonAPI::handleLogin(const QJsonObject &message, const JsonApiCommand &cmd)
|
|||||||
// userToken is longer than app token
|
// userToken is longer than app token
|
||||||
if (token.size() > APP_TOKEN_LENGTH)
|
if (token.size() > APP_TOKEN_LENGTH)
|
||||||
{
|
{
|
||||||
if (API::isUserTokenAuthorized(token))
|
if (API::isUserTokenAuthorized(token)) {
|
||||||
{
|
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sendNoAuthorization(cmd);
|
sendNoAuthorization(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1393,12 +1336,9 @@ void JsonAPI::handleLogin(const QJsonObject &message, const JsonApiCommand &cmd)
|
|||||||
|
|
||||||
if (token.size() == APP_TOKEN_LENGTH)
|
if (token.size() == APP_TOKEN_LENGTH)
|
||||||
{
|
{
|
||||||
if (API::isTokenAuthorized(token))
|
if (API::isTokenAuthorized(token)) {
|
||||||
{
|
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sendNoAuthorization(cmd);
|
sendNoAuthorization(cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1445,12 +1385,9 @@ void JsonAPI::handleTokenResponse(bool success, const QString &token, const QStr
|
|||||||
result["comment"] = comment;
|
result["comment"] = comment;
|
||||||
result["id"] = identifier;
|
result["id"] = identifier;
|
||||||
|
|
||||||
if (success)
|
if (success) {
|
||||||
{
|
|
||||||
sendSuccessDataReply(result, cmd, tan);
|
sendSuccessDataReply(result, cmd, tan);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sendErrorReply("Token request timeout or denied", {}, cmd, tan);
|
sendErrorReply("Token request timeout or denied", {}, cmd, tan);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1462,8 +1399,7 @@ void JsonAPI::handleInstanceCommand(const QJsonObject &message, const JsonApiCom
|
|||||||
const quint8 inst = static_cast<quint8>(message["instance"].toInt());
|
const quint8 inst = static_cast<quint8>(message["instance"].toInt());
|
||||||
const QString &name = message["name"].toString();
|
const QString &name = message["name"].toString();
|
||||||
|
|
||||||
switch (cmd.subCommand)
|
switch (cmd.subCommand) {
|
||||||
{
|
|
||||||
case SubCommand::SwitchTo:
|
case SubCommand::SwitchTo:
|
||||||
if (handleInstanceSwitch(inst))
|
if (handleInstanceSwitch(inst))
|
||||||
{
|
{
|
||||||
@ -1479,7 +1415,9 @@ void JsonAPI::handleInstanceCommand(const QJsonObject &message, const JsonApiCom
|
|||||||
case SubCommand::StartInstance:
|
case SubCommand::StartInstance:
|
||||||
//Only send update once
|
//Only send update once
|
||||||
weakConnect(this, &API::onStartInstanceResponse, [this, cmd] ()
|
weakConnect(this, &API::onStartInstanceResponse, [this, cmd] ()
|
||||||
{ sendSuccessReply(cmd); });
|
{
|
||||||
|
sendSuccessReply(cmd);
|
||||||
|
});
|
||||||
|
|
||||||
if (!API::startInstance(inst, cmd.tan))
|
if (!API::startInstance(inst, cmd.tan))
|
||||||
{
|
{
|
||||||
@ -1506,27 +1444,20 @@ void JsonAPI::handleInstanceCommand(const QJsonObject &message, const JsonApiCom
|
|||||||
case SubCommand::CreateInstance:
|
case SubCommand::CreateInstance:
|
||||||
case SubCommand::SaveName:
|
case SubCommand::SaveName:
|
||||||
// create and save name requires name
|
// create and save name requires name
|
||||||
if (name.isEmpty())
|
if (name.isEmpty()) {
|
||||||
{
|
|
||||||
sendErrorReply("Name string required for this command", cmd);
|
sendErrorReply("Name string required for this command", cmd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd.subCommand == SubCommand::CreateInstance)
|
if (cmd.subCommand == SubCommand::CreateInstance) {
|
||||||
{
|
|
||||||
replyMsg = API::createInstance(name);
|
replyMsg = API::createInstance(name);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
replyMsg = API::setInstanceName(inst, name);
|
replyMsg = API::setInstanceName(inst, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (replyMsg.isEmpty())
|
if (replyMsg.isEmpty()) {
|
||||||
{
|
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sendErrorReply(replyMsg, cmd);
|
sendErrorReply(replyMsg, cmd);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1540,8 +1471,7 @@ void JsonAPI::handleLedDeviceCommand(const QJsonObject &message, const JsonApiCo
|
|||||||
const QString &devType = message["ledDeviceType"].toString().trimmed();
|
const QString &devType = message["ledDeviceType"].toString().trimmed();
|
||||||
const LedDeviceRegistry& ledDevices = LedDeviceWrapper::getDeviceMap();
|
const LedDeviceRegistry& ledDevices = LedDeviceWrapper::getDeviceMap();
|
||||||
|
|
||||||
if (ledDevices.count(devType) == 0)
|
if (ledDevices.count(devType) == 0) {
|
||||||
{
|
|
||||||
sendErrorReply(QString("Unknown LED-Device type: %1").arg(devType), cmd);
|
sendErrorReply(QString("Unknown LED-Device type: %1").arg(devType), cmd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1549,8 +1479,7 @@ void JsonAPI::handleLedDeviceCommand(const QJsonObject &message, const JsonApiCo
|
|||||||
QJsonObject config { { "type", devType } };
|
QJsonObject config { { "type", devType } };
|
||||||
LedDevice* ledDevice = LedDeviceFactory::construct(config);
|
LedDevice* ledDevice = LedDeviceFactory::construct(config);
|
||||||
|
|
||||||
switch (cmd.subCommand)
|
switch (cmd.subCommand) {
|
||||||
{
|
|
||||||
case SubCommand::Discover:
|
case SubCommand::Discover:
|
||||||
handleLedDeviceDiscover(*ledDevice, message, cmd);
|
handleLedDeviceDiscover(*ledDevice, message, cmd);
|
||||||
break;
|
break;
|
||||||
@ -1600,19 +1529,16 @@ void JsonAPI::handleLedDeviceAddAuthorization(LedDevice &ledDevice, const QJsonO
|
|||||||
sendSuccessDataReply(response, cmd);
|
sendSuccessDataReply(response, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonAPI::handleInputSourceCommand(const QJsonObject &message, const JsonApiCommand &cmd)
|
void JsonAPI::handleInputSourceCommand(const QJsonObject& message, const JsonApiCommand& cmd) {
|
||||||
{
|
|
||||||
const QString& sourceType = message["sourceType"].toString().trimmed();
|
const QString& sourceType = message["sourceType"].toString().trimmed();
|
||||||
const QStringList sourceTypes {"screen", "video", "audio"};
|
const QStringList sourceTypes {"screen", "video", "audio"};
|
||||||
|
|
||||||
if (!sourceTypes.contains(sourceType))
|
if (!sourceTypes.contains(sourceType)) {
|
||||||
{
|
|
||||||
sendErrorReply(QString("Unknown input source type: %1").arg(sourceType), cmd);
|
sendErrorReply(QString("Unknown input source type: %1").arg(sourceType), cmd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd.subCommand == SubCommand::Discover)
|
if (cmd.subCommand == SubCommand::Discover) {
|
||||||
{
|
|
||||||
|
|
||||||
const QJsonObject& params = message["params"].toObject();
|
const QJsonObject& params = message["params"].toObject();
|
||||||
QJsonObject inputSourcesDiscovered = JsonInfo().discoverSources(sourceType, params);
|
QJsonObject inputSourcesDiscovered = JsonInfo().discoverSources(sourceType, params);
|
||||||
@ -1663,8 +1589,7 @@ void JsonAPI::handleServiceCommand(const QJsonObject &message, const JsonApiComm
|
|||||||
|
|
||||||
void JsonAPI::handleSystemCommand(const QJsonObject& /*message*/, const JsonApiCommand& cmd)
|
void JsonAPI::handleSystemCommand(const QJsonObject& /*message*/, const JsonApiCommand& cmd)
|
||||||
{
|
{
|
||||||
switch (cmd.subCommand)
|
switch (cmd.subCommand) {
|
||||||
{
|
|
||||||
case SubCommand::Suspend:
|
case SubCommand::Suspend:
|
||||||
emit signalEvent(Event::Suspend);
|
emit signalEvent(Event::Suspend);
|
||||||
break;
|
break;
|
||||||
@ -1835,8 +1760,7 @@ QString JsonAPI::findCommand(const QString &jsonString)
|
|||||||
static QRegularExpression regex("\"command\"\\s*:\\s*\"([^\"]+)\"");
|
static QRegularExpression regex("\"command\"\\s*:\\s*\"([^\"]+)\"");
|
||||||
QRegularExpressionMatch match = regex.match(jsonString);
|
QRegularExpressionMatch match = regex.match(jsonString);
|
||||||
|
|
||||||
if (match.hasMatch())
|
if (match.hasMatch()) {
|
||||||
{
|
|
||||||
commandValue = match.captured(1);
|
commandValue = match.captured(1);
|
||||||
}
|
}
|
||||||
return commandValue;
|
return commandValue;
|
||||||
@ -1848,8 +1772,7 @@ int JsonAPI::findTan(const QString &jsonString)
|
|||||||
static QRegularExpression regex("\"tan\"\\s*:\\s*(\\d+)");
|
static QRegularExpression regex("\"tan\"\\s*:\\s*(\\d+)");
|
||||||
QRegularExpressionMatch match = regex.match(jsonString);
|
QRegularExpressionMatch match = regex.match(jsonString);
|
||||||
|
|
||||||
if (match.hasMatch())
|
if (match.hasMatch()) {
|
||||||
{
|
|
||||||
QString valueStr = match.captured(1);
|
QString valueStr = match.captured(1);
|
||||||
tanValue = valueStr.toInt();
|
tanValue = valueStr.toInt();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user