2020-07-12 20:27:56 +02:00
|
|
|
// Local-Hyperion includes
|
|
|
|
#include "ProviderRestApi.h"
|
|
|
|
|
|
|
|
// Qt includes
|
|
|
|
#include <QEventLoop>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QByteArray>
|
2021-08-31 10:55:49 +02:00
|
|
|
#include <QJsonObject>
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
//std includes
|
|
|
|
#include <iostream>
|
2021-03-19 22:52:04 +01:00
|
|
|
#include <chrono>
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
// Constants
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
const QChar ONE_SLASH = '/';
|
|
|
|
|
2022-12-27 08:36:10 +01:00
|
|
|
enum HttpStatusCode {
|
|
|
|
NoContent = 204,
|
|
|
|
BadRequest = 400,
|
|
|
|
UnAuthorized = 401,
|
2023-02-12 21:20:50 +01:00
|
|
|
Forbidden = 403,
|
2022-12-27 08:36:10 +01:00
|
|
|
NotFound = 404
|
|
|
|
};
|
2021-03-19 22:52:04 +01:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
} //End of constants
|
|
|
|
|
2023-02-12 21:20:50 +01:00
|
|
|
ProviderRestApi::ProviderRestApi(const QString& scheme, const QString& host, int port, const QString& basePath)
|
|
|
|
: _log(Logger::getInstance("LEDDEVICE"))
|
|
|
|
, _networkManager(nullptr)
|
|
|
|
, _requestTimeout(DEFAULT_REST_TIMEOUT)
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
|
|
|
_networkManager = new QNetworkAccessManager();
|
2023-02-12 21:20:50 +01:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
|
|
|
_networkManager->setRedirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy);
|
|
|
|
#endif
|
2020-07-12 20:27:56 +02:00
|
|
|
|
2023-02-12 21:20:50 +01:00
|
|
|
_apiUrl.setScheme(scheme);
|
2020-07-12 20:27:56 +02:00
|
|
|
_apiUrl.setHost(host);
|
|
|
|
_apiUrl.setPort(port);
|
|
|
|
_basePath = basePath;
|
|
|
|
}
|
|
|
|
|
2023-02-12 21:20:50 +01:00
|
|
|
ProviderRestApi::ProviderRestApi(const QString& scheme, const QString& host, int port)
|
|
|
|
: ProviderRestApi(scheme, host, port, "") {}
|
|
|
|
|
|
|
|
ProviderRestApi::ProviderRestApi(const QString& host, int port, const QString& basePath)
|
|
|
|
: ProviderRestApi("http", host, port, basePath) {}
|
|
|
|
|
2021-11-17 20:34:49 +01:00
|
|
|
ProviderRestApi::ProviderRestApi(const QString& host, int port)
|
2020-07-12 20:27:56 +02:00
|
|
|
: ProviderRestApi(host, port, "") {}
|
|
|
|
|
|
|
|
ProviderRestApi::ProviderRestApi()
|
|
|
|
: ProviderRestApi("", -1) {}
|
|
|
|
|
|
|
|
ProviderRestApi::~ProviderRestApi()
|
|
|
|
{
|
2020-10-18 17:05:07 +02:00
|
|
|
delete _networkManager;
|
2020-07-12 20:27:56 +02:00
|
|
|
}
|
|
|
|
|
2021-11-17 20:34:49 +01:00
|
|
|
void ProviderRestApi::setUrl(const QUrl& url)
|
|
|
|
{
|
|
|
|
_apiUrl = url;
|
|
|
|
_basePath = url.path();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProviderRestApi::setBasePath(const QString& basePath)
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
|
|
|
_basePath.clear();
|
2021-11-17 20:34:49 +01:00
|
|
|
appendPath(_basePath, basePath);
|
2020-07-12 20:27:56 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 21:20:50 +01:00
|
|
|
void ProviderRestApi::setPath(const QStringList& pathElements)
|
|
|
|
{
|
|
|
|
_path.clear();
|
|
|
|
appendPath(_path, pathElements.join(ONE_SLASH));
|
|
|
|
}
|
|
|
|
|
2021-11-17 20:34:49 +01:00
|
|
|
void ProviderRestApi::setPath(const QString& path)
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
|
|
|
_path.clear();
|
2021-11-17 20:34:49 +01:00
|
|
|
appendPath(_path, path);
|
2020-07-12 20:27:56 +02:00
|
|
|
}
|
|
|
|
|
2021-11-17 20:34:49 +01:00
|
|
|
void ProviderRestApi::appendPath(const QString& path)
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
2021-11-17 20:34:49 +01:00
|
|
|
appendPath(_path, path);
|
2020-07-12 20:27:56 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 21:20:50 +01:00
|
|
|
void ProviderRestApi::appendPath(const QStringList& pathElements)
|
|
|
|
{
|
|
|
|
appendPath(_path, pathElements.join(ONE_SLASH));
|
|
|
|
}
|
|
|
|
|
2021-03-19 22:52:04 +01:00
|
|
|
void ProviderRestApi::appendPath ( QString& path, const QString &appendPath)
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
2021-11-17 20:34:49 +01:00
|
|
|
if (!appendPath.isEmpty() && appendPath != ONE_SLASH)
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
2021-11-17 20:34:49 +01:00
|
|
|
if (path.isEmpty() || path == ONE_SLASH)
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
|
|
|
path.clear();
|
2021-11-17 20:34:49 +01:00
|
|
|
if (appendPath[0] != ONE_SLASH)
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
|
|
|
path.push_back(ONE_SLASH);
|
|
|
|
}
|
|
|
|
}
|
2021-11-17 20:34:49 +01:00
|
|
|
else if (path[path.size() - 1] == ONE_SLASH && appendPath[0] == ONE_SLASH)
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
|
|
|
path.chop(1);
|
|
|
|
}
|
2021-11-17 20:34:49 +01:00
|
|
|
else if (path[path.size() - 1] != ONE_SLASH && appendPath[0] != ONE_SLASH)
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
|
|
|
path.push_back(ONE_SLASH);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Only one slash.
|
|
|
|
}
|
|
|
|
|
|
|
|
path.append(appendPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-17 20:34:49 +01:00
|
|
|
void ProviderRestApi::setFragment(const QString& fragment)
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
|
|
|
_fragment = fragment;
|
|
|
|
}
|
|
|
|
|
2021-11-17 20:34:49 +01:00
|
|
|
void ProviderRestApi::setQuery(const QUrlQuery& query)
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
|
|
|
_query = query;
|
|
|
|
}
|
|
|
|
|
|
|
|
QUrl ProviderRestApi::getUrl() const
|
|
|
|
{
|
|
|
|
QUrl url = _apiUrl;
|
|
|
|
|
|
|
|
QString fullPath = _basePath;
|
2021-11-17 20:34:49 +01:00
|
|
|
appendPath(fullPath, _path);
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
url.setPath(fullPath);
|
2021-11-17 20:34:49 +01:00
|
|
|
url.setFragment(_fragment);
|
|
|
|
url.setQuery(_query);
|
2020-07-12 20:27:56 +02:00
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
httpResponse ProviderRestApi::get()
|
|
|
|
{
|
2021-11-17 20:34:49 +01:00
|
|
|
return get(getUrl());
|
2020-07-12 20:27:56 +02:00
|
|
|
}
|
|
|
|
|
2021-11-17 20:34:49 +01:00
|
|
|
httpResponse ProviderRestApi::get(const QUrl& url)
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
2023-02-12 21:20:50 +01:00
|
|
|
return executeOperation(QNetworkAccessManager::GetOperation, url);
|
2020-07-12 20:27:56 +02:00
|
|
|
}
|
|
|
|
|
2021-08-31 10:55:49 +02:00
|
|
|
httpResponse ProviderRestApi::put(const QJsonObject &body)
|
|
|
|
{
|
|
|
|
return put( getUrl(), QJsonDocument(body).toJson(QJsonDocument::Compact));
|
|
|
|
}
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
httpResponse ProviderRestApi::put(const QString &body)
|
|
|
|
{
|
2021-08-31 10:55:49 +02:00
|
|
|
return put( getUrl(), body.toUtf8() );
|
2020-07-12 20:27:56 +02:00
|
|
|
}
|
|
|
|
|
2021-08-31 10:55:49 +02:00
|
|
|
httpResponse ProviderRestApi::put(const QUrl &url, const QByteArray &body)
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
2023-02-12 21:20:50 +01:00
|
|
|
return executeOperation(QNetworkAccessManager::PutOperation, url, body);
|
2020-07-12 20:27:56 +02:00
|
|
|
}
|
|
|
|
|
2021-11-17 20:34:49 +01:00
|
|
|
httpResponse ProviderRestApi::post(const QJsonObject& body)
|
|
|
|
{
|
|
|
|
return post( getUrl(), QJsonDocument(body).toJson(QJsonDocument::Compact));
|
|
|
|
}
|
|
|
|
|
|
|
|
httpResponse ProviderRestApi::post(const QString& body)
|
|
|
|
{
|
|
|
|
return post( getUrl(), body.toUtf8() );
|
|
|
|
}
|
|
|
|
|
|
|
|
httpResponse ProviderRestApi::post(const QUrl& url, const QByteArray& body)
|
|
|
|
{
|
2023-02-12 21:20:50 +01:00
|
|
|
return executeOperation(QNetworkAccessManager::PostOperation, url, body);
|
2021-11-17 20:34:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
httpResponse ProviderRestApi::deleteResource(const QUrl& url)
|
2023-02-12 21:20:50 +01:00
|
|
|
{
|
|
|
|
return executeOperation(QNetworkAccessManager::DeleteOperation, url);
|
|
|
|
}
|
|
|
|
|
|
|
|
httpResponse ProviderRestApi::executeOperation(QNetworkAccessManager::Operation operation, const QUrl& url, const QByteArray& body)
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
2021-11-17 20:34:49 +01:00
|
|
|
// Perform request
|
|
|
|
QNetworkRequest request(_networkRequestHeaders);
|
|
|
|
request.setUrl(url);
|
2023-02-12 21:20:50 +01:00
|
|
|
request.setOriginatingObject(this);
|
2021-11-17 20:34:49 +01:00
|
|
|
|
mDNS Support (#1452)
* Allow build, if no grabbers are enabled
* Align available functions to right Qt version
* Update to next development version
* Align available functions to right Qt version
* fix workflows (apt/nightly)
* Disable QNetworkConfigurationManager deprecation warnings
* Initial go on Smart Pointers
* Add Deallocation
* Correct QT_WARNING_DISABLE_DEPRECATED (available since 5.9)
* Cluster Build Variables
* Hyperion Light
* Address build warnings
* Hyperion Light - UI
* Update Protobuf to latest master
* Removed compiler warnings
* Added restart ability to systray
* Correct Protobuf
* Ignore 'no-return' warning on protobuf build
* hyperion-remote: Fix auto discovery of hyperion server
* Fix Qt version override
* Update changelog
* Remove Grabber Components, if no Grabber exists
* Standalone Grabber - Fix fps default
* Remote Control - Have Source Selction accrosswhole screen
* Enable Blackborder detection only, if relevant input sources available
* Enable Blackborder detection only, if relevant input sources available
* Remote UI - rearrange containers
* Checkout
* Fix compilation on windows
* Re-added qmdnsengine template cmake
* chrono added for linux
* Removed existing AVAHI/Bonjour, allow to enable/disable mDNS
* hyperiond macos typo fix
* Fix macOS Bundle build
* Fix macOS bundle info details
* Correct CMake files
* Removed existing AVAHI/Bonjour (2)
* Share hyperion's services via mDNS
* Add mDNS Browser and mDNS for LED-Devices
* Support mDNS discovery for standalone grabbers
* Remove ZLib Dependency & Cleanup
* mDNS - hanle 2.local2 an ".local." domains equally
* Hue - Link discovery to bridge class, workaround port 443 for mDNS discovery
* Fix save button state when switching between devices
* Removed sessions (of other hyperions)
* mDNS Publisher - Simplify service naming
* mDNS refactoring & Forwarder discovery
* mDNS Updates to use device service name
* Consistency of standalone grabbers with mDNS Service Registry
* Merge branch 'hyperion-project:master' into mDNS
* Start JSON and WebServers only after Instance 0 is available
* Remove bespoke qDebug Output again
* MDNS updates and refactor Forwarder
* Minor updates
* Upgrade to CMake 3.1
* typo
* macOS fix
* Correct merge
* - Remove dynamic linker flag from standalone dispmanX Grabber
- Added ability to use system qmdns libs
* Cec handler library will load at runtime
* typo fix
* protobuf changes
* mDNS changes for Windows/macOS
* test window build qmdnsengine
* absolute path to protobuf cmake dir
* Rework Hue Wizard supporting mDNS
* LED-Devices - Retry support + Refactoring (excl. Hue)
* LED-Devices - Refactoring/Retry support Hue + additional alignments
* Address LGTM findings
* Fix CI-Build, revert test changes
* Build Windows in Release mode to avoid python problem
* Correct that WebServerObject is available earlier
* Ensure that instance name in logs for one instance are presented
* Update content LEDs
* Rework mDNS Address lookup
* Fix LED UI
* Fix for non mDNS Services (ignore default port)
* Disbale device when now input is available
* Revert back some updates, ensure last color is updated when switched on
* Handle reopening case and changed IP, port for API-calls
* Add UPD-DDP Device
* WLED support for DDP
* Fix printout
* LEDDevice - Allow more retries, udapte defaults
* LED-Net Devices - Select Custom device, if configured
Co-authored-by: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com>
Co-authored-by: Paulchen Panther <Paulchen-Panter@protonmail.com>
2022-05-01 19:42:47 +02:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
2023-02-12 21:20:50 +01:00
|
|
|
_networkManager->setTransferTimeout(_requestTimeout.count());
|
mDNS Support (#1452)
* Allow build, if no grabbers are enabled
* Align available functions to right Qt version
* Update to next development version
* Align available functions to right Qt version
* fix workflows (apt/nightly)
* Disable QNetworkConfigurationManager deprecation warnings
* Initial go on Smart Pointers
* Add Deallocation
* Correct QT_WARNING_DISABLE_DEPRECATED (available since 5.9)
* Cluster Build Variables
* Hyperion Light
* Address build warnings
* Hyperion Light - UI
* Update Protobuf to latest master
* Removed compiler warnings
* Added restart ability to systray
* Correct Protobuf
* Ignore 'no-return' warning on protobuf build
* hyperion-remote: Fix auto discovery of hyperion server
* Fix Qt version override
* Update changelog
* Remove Grabber Components, if no Grabber exists
* Standalone Grabber - Fix fps default
* Remote Control - Have Source Selction accrosswhole screen
* Enable Blackborder detection only, if relevant input sources available
* Enable Blackborder detection only, if relevant input sources available
* Remote UI - rearrange containers
* Checkout
* Fix compilation on windows
* Re-added qmdnsengine template cmake
* chrono added for linux
* Removed existing AVAHI/Bonjour, allow to enable/disable mDNS
* hyperiond macos typo fix
* Fix macOS Bundle build
* Fix macOS bundle info details
* Correct CMake files
* Removed existing AVAHI/Bonjour (2)
* Share hyperion's services via mDNS
* Add mDNS Browser and mDNS for LED-Devices
* Support mDNS discovery for standalone grabbers
* Remove ZLib Dependency & Cleanup
* mDNS - hanle 2.local2 an ".local." domains equally
* Hue - Link discovery to bridge class, workaround port 443 for mDNS discovery
* Fix save button state when switching between devices
* Removed sessions (of other hyperions)
* mDNS Publisher - Simplify service naming
* mDNS refactoring & Forwarder discovery
* mDNS Updates to use device service name
* Consistency of standalone grabbers with mDNS Service Registry
* Merge branch 'hyperion-project:master' into mDNS
* Start JSON and WebServers only after Instance 0 is available
* Remove bespoke qDebug Output again
* MDNS updates and refactor Forwarder
* Minor updates
* Upgrade to CMake 3.1
* typo
* macOS fix
* Correct merge
* - Remove dynamic linker flag from standalone dispmanX Grabber
- Added ability to use system qmdns libs
* Cec handler library will load at runtime
* typo fix
* protobuf changes
* mDNS changes for Windows/macOS
* test window build qmdnsengine
* absolute path to protobuf cmake dir
* Rework Hue Wizard supporting mDNS
* LED-Devices - Retry support + Refactoring (excl. Hue)
* LED-Devices - Refactoring/Retry support Hue + additional alignments
* Address LGTM findings
* Fix CI-Build, revert test changes
* Build Windows in Release mode to avoid python problem
* Correct that WebServerObject is available earlier
* Ensure that instance name in logs for one instance are presented
* Update content LEDs
* Rework mDNS Address lookup
* Fix LED UI
* Fix for non mDNS Services (ignore default port)
* Disbale device when now input is available
* Revert back some updates, ensure last color is updated when switched on
* Handle reopening case and changed IP, port for API-calls
* Add UPD-DDP Device
* WLED support for DDP
* Fix printout
* LEDDevice - Allow more retries, udapte defaults
* LED-Net Devices - Select Custom device, if configured
Co-authored-by: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com>
Co-authored-by: Paulchen Panther <Paulchen-Panter@protonmail.com>
2022-05-01 19:42:47 +02:00
|
|
|
#endif
|
|
|
|
|
2023-02-12 21:20:50 +01:00
|
|
|
QDateTime start = QDateTime::currentDateTime();
|
|
|
|
QString opCode;
|
|
|
|
QNetworkReply* reply;
|
|
|
|
switch (operation) {
|
|
|
|
case QNetworkAccessManager::GetOperation:
|
|
|
|
opCode = "GET";
|
|
|
|
reply = _networkManager->get(request);
|
|
|
|
break;
|
|
|
|
case QNetworkAccessManager::PutOperation:
|
|
|
|
opCode = "PUT";
|
|
|
|
reply = _networkManager->put(request, body);
|
|
|
|
break;
|
|
|
|
case QNetworkAccessManager::PostOperation:
|
|
|
|
opCode = "POST";
|
|
|
|
reply = _networkManager->post(request, body);
|
|
|
|
break;
|
|
|
|
case QNetworkAccessManager::DeleteOperation:
|
|
|
|
opCode = "DELETE";
|
|
|
|
reply = _networkManager->deleteResource(request);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Error(_log, "Unsupported operation");
|
|
|
|
return httpResponse();
|
|
|
|
}
|
|
|
|
|
2021-11-17 20:34:49 +01:00
|
|
|
// Connect requestFinished signal to quit slot of the loop.
|
|
|
|
QEventLoop loop;
|
|
|
|
QEventLoop::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
|
|
|
|
mDNS Support (#1452)
* Allow build, if no grabbers are enabled
* Align available functions to right Qt version
* Update to next development version
* Align available functions to right Qt version
* fix workflows (apt/nightly)
* Disable QNetworkConfigurationManager deprecation warnings
* Initial go on Smart Pointers
* Add Deallocation
* Correct QT_WARNING_DISABLE_DEPRECATED (available since 5.9)
* Cluster Build Variables
* Hyperion Light
* Address build warnings
* Hyperion Light - UI
* Update Protobuf to latest master
* Removed compiler warnings
* Added restart ability to systray
* Correct Protobuf
* Ignore 'no-return' warning on protobuf build
* hyperion-remote: Fix auto discovery of hyperion server
* Fix Qt version override
* Update changelog
* Remove Grabber Components, if no Grabber exists
* Standalone Grabber - Fix fps default
* Remote Control - Have Source Selction accrosswhole screen
* Enable Blackborder detection only, if relevant input sources available
* Enable Blackborder detection only, if relevant input sources available
* Remote UI - rearrange containers
* Checkout
* Fix compilation on windows
* Re-added qmdnsengine template cmake
* chrono added for linux
* Removed existing AVAHI/Bonjour, allow to enable/disable mDNS
* hyperiond macos typo fix
* Fix macOS Bundle build
* Fix macOS bundle info details
* Correct CMake files
* Removed existing AVAHI/Bonjour (2)
* Share hyperion's services via mDNS
* Add mDNS Browser and mDNS for LED-Devices
* Support mDNS discovery for standalone grabbers
* Remove ZLib Dependency & Cleanup
* mDNS - hanle 2.local2 an ".local." domains equally
* Hue - Link discovery to bridge class, workaround port 443 for mDNS discovery
* Fix save button state when switching between devices
* Removed sessions (of other hyperions)
* mDNS Publisher - Simplify service naming
* mDNS refactoring & Forwarder discovery
* mDNS Updates to use device service name
* Consistency of standalone grabbers with mDNS Service Registry
* Merge branch 'hyperion-project:master' into mDNS
* Start JSON and WebServers only after Instance 0 is available
* Remove bespoke qDebug Output again
* MDNS updates and refactor Forwarder
* Minor updates
* Upgrade to CMake 3.1
* typo
* macOS fix
* Correct merge
* - Remove dynamic linker flag from standalone dispmanX Grabber
- Added ability to use system qmdns libs
* Cec handler library will load at runtime
* typo fix
* protobuf changes
* mDNS changes for Windows/macOS
* test window build qmdnsengine
* absolute path to protobuf cmake dir
* Rework Hue Wizard supporting mDNS
* LED-Devices - Retry support + Refactoring (excl. Hue)
* LED-Devices - Refactoring/Retry support Hue + additional alignments
* Address LGTM findings
* Fix CI-Build, revert test changes
* Build Windows in Release mode to avoid python problem
* Correct that WebServerObject is available earlier
* Ensure that instance name in logs for one instance are presented
* Update content LEDs
* Rework mDNS Address lookup
* Fix LED UI
* Fix for non mDNS Services (ignore default port)
* Disbale device when now input is available
* Revert back some updates, ensure last color is updated when switched on
* Handle reopening case and changed IP, port for API-calls
* Add UPD-DDP Device
* WLED support for DDP
* Fix printout
* LEDDevice - Allow more retries, udapte defaults
* LED-Net Devices - Select Custom device, if configured
Co-authored-by: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com>
Co-authored-by: Paulchen Panther <Paulchen-Panter@protonmail.com>
2022-05-01 19:42:47 +02:00
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
|
2023-02-12 21:20:50 +01:00
|
|
|
ReplyTimeout* timeout = ReplyTimeout::set(reply, _requestTimeout.count());
|
mDNS Support (#1452)
* Allow build, if no grabbers are enabled
* Align available functions to right Qt version
* Update to next development version
* Align available functions to right Qt version
* fix workflows (apt/nightly)
* Disable QNetworkConfigurationManager deprecation warnings
* Initial go on Smart Pointers
* Add Deallocation
* Correct QT_WARNING_DISABLE_DEPRECATED (available since 5.9)
* Cluster Build Variables
* Hyperion Light
* Address build warnings
* Hyperion Light - UI
* Update Protobuf to latest master
* Removed compiler warnings
* Added restart ability to systray
* Correct Protobuf
* Ignore 'no-return' warning on protobuf build
* hyperion-remote: Fix auto discovery of hyperion server
* Fix Qt version override
* Update changelog
* Remove Grabber Components, if no Grabber exists
* Standalone Grabber - Fix fps default
* Remote Control - Have Source Selction accrosswhole screen
* Enable Blackborder detection only, if relevant input sources available
* Enable Blackborder detection only, if relevant input sources available
* Remote UI - rearrange containers
* Checkout
* Fix compilation on windows
* Re-added qmdnsengine template cmake
* chrono added for linux
* Removed existing AVAHI/Bonjour, allow to enable/disable mDNS
* hyperiond macos typo fix
* Fix macOS Bundle build
* Fix macOS bundle info details
* Correct CMake files
* Removed existing AVAHI/Bonjour (2)
* Share hyperion's services via mDNS
* Add mDNS Browser and mDNS for LED-Devices
* Support mDNS discovery for standalone grabbers
* Remove ZLib Dependency & Cleanup
* mDNS - hanle 2.local2 an ".local." domains equally
* Hue - Link discovery to bridge class, workaround port 443 for mDNS discovery
* Fix save button state when switching between devices
* Removed sessions (of other hyperions)
* mDNS Publisher - Simplify service naming
* mDNS refactoring & Forwarder discovery
* mDNS Updates to use device service name
* Consistency of standalone grabbers with mDNS Service Registry
* Merge branch 'hyperion-project:master' into mDNS
* Start JSON and WebServers only after Instance 0 is available
* Remove bespoke qDebug Output again
* MDNS updates and refactor Forwarder
* Minor updates
* Upgrade to CMake 3.1
* typo
* macOS fix
* Correct merge
* - Remove dynamic linker flag from standalone dispmanX Grabber
- Added ability to use system qmdns libs
* Cec handler library will load at runtime
* typo fix
* protobuf changes
* mDNS changes for Windows/macOS
* test window build qmdnsengine
* absolute path to protobuf cmake dir
* Rework Hue Wizard supporting mDNS
* LED-Devices - Retry support + Refactoring (excl. Hue)
* LED-Devices - Refactoring/Retry support Hue + additional alignments
* Address LGTM findings
* Fix CI-Build, revert test changes
* Build Windows in Release mode to avoid python problem
* Correct that WebServerObject is available earlier
* Ensure that instance name in logs for one instance are presented
* Update content LEDs
* Rework mDNS Address lookup
* Fix LED UI
* Fix for non mDNS Services (ignore default port)
* Disbale device when now input is available
* Revert back some updates, ensure last color is updated when switched on
* Handle reopening case and changed IP, port for API-calls
* Add UPD-DDP Device
* WLED support for DDP
* Fix printout
* LEDDevice - Allow more retries, udapte defaults
* LED-Net Devices - Select Custom device, if configured
Co-authored-by: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com>
Co-authored-by: Paulchen Panther <Paulchen-Panter@protonmail.com>
2022-05-01 19:42:47 +02:00
|
|
|
#endif
|
|
|
|
|
2023-02-12 21:20:50 +01:00
|
|
|
// Go into the loop until the request is finished.
|
|
|
|
loop.exec();
|
|
|
|
QDateTime end = QDateTime::currentDateTime();
|
|
|
|
|
|
|
|
httpResponse response = (reply->operation() == operation) ? getResponse(reply) : httpResponse();
|
|
|
|
|
|
|
|
Debug(_log, "%s took %lldms, HTTP %d: [%s] [%s]", QSTRING_CSTR(opCode), start.msecsTo(end), response.getHttpStatusCode(), QSTRING_CSTR(url.toString()), body.constData());
|
|
|
|
|
2021-11-17 20:34:49 +01:00
|
|
|
// Free space.
|
|
|
|
reply->deleteLater();
|
2020-07-12 20:27:56 +02:00
|
|
|
|
2021-11-17 20:34:49 +01:00
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
httpResponse ProviderRestApi::getResponse(QNetworkReply* const& reply)
|
|
|
|
{
|
|
|
|
httpResponse response;
|
|
|
|
|
2022-12-27 08:36:10 +01:00
|
|
|
HttpStatusCode httpStatusCode = static_cast<HttpStatusCode>(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
|
2020-07-12 20:27:56 +02:00
|
|
|
response.setHttpStatusCode(httpStatusCode);
|
|
|
|
response.setNetworkReplyError(reply->error());
|
|
|
|
|
2021-11-17 20:34:49 +01:00
|
|
|
if (reply->error() == QNetworkReply::NoError)
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
2023-02-12 21:20:50 +01:00
|
|
|
QByteArray replyData = reply->readAll();
|
|
|
|
|
|
|
|
if (!replyData.isEmpty())
|
|
|
|
{
|
|
|
|
QJsonParseError error;
|
|
|
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(replyData, &error);
|
2020-07-12 20:27:56 +02:00
|
|
|
|
2023-02-12 21:20:50 +01:00
|
|
|
if (error.error != QJsonParseError::NoError)
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
2023-02-12 21:20:50 +01:00
|
|
|
//Received not valid JSON response
|
|
|
|
response.setError(true);
|
|
|
|
response.setErrorReason(error.errorString());
|
2020-07-12 20:27:56 +02:00
|
|
|
}
|
|
|
|
else
|
2023-02-12 21:20:50 +01:00
|
|
|
{
|
|
|
|
response.setBody(jsonDoc);
|
2020-07-12 20:27:56 +02:00
|
|
|
}
|
|
|
|
}
|
2023-02-12 21:20:50 +01:00
|
|
|
else
|
|
|
|
{ // Create valid body which is empty
|
|
|
|
response.setBody(QJsonDocument());
|
|
|
|
}
|
2020-07-12 20:27:56 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString errorReason;
|
2021-11-17 20:34:49 +01:00
|
|
|
if (httpStatusCode > 0) {
|
|
|
|
QString httpReason = reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
|
2020-07-12 20:27:56 +02:00
|
|
|
QString advise;
|
|
|
|
switch ( httpStatusCode ) {
|
2022-12-27 08:36:10 +01:00
|
|
|
case HttpStatusCode::BadRequest:
|
2020-07-12 20:27:56 +02:00
|
|
|
advise = "Check Request Body";
|
|
|
|
break;
|
2022-12-27 08:36:10 +01:00
|
|
|
case HttpStatusCode::UnAuthorized:
|
2020-07-12 20:27:56 +02:00
|
|
|
advise = "Check Authentication Token (API Key)";
|
|
|
|
break;
|
2023-02-12 21:20:50 +01:00
|
|
|
case HttpStatusCode::Forbidden:
|
|
|
|
advise = "No permission to access the given resource";
|
|
|
|
break;
|
2022-12-27 08:36:10 +01:00
|
|
|
case HttpStatusCode::NotFound:
|
2020-07-12 20:27:56 +02:00
|
|
|
advise = "Check Resource given";
|
|
|
|
break;
|
|
|
|
default:
|
2023-02-12 21:20:50 +01:00
|
|
|
advise = httpReason;
|
2020-07-12 20:27:56 +02:00
|
|
|
break;
|
|
|
|
}
|
2021-11-16 18:12:56 +01:00
|
|
|
errorReason = QString ("[%3 %4] - %5").arg(httpStatusCode).arg(httpReason, advise);
|
2020-07-12 20:27:56 +02:00
|
|
|
}
|
mDNS Support (#1452)
* Allow build, if no grabbers are enabled
* Align available functions to right Qt version
* Update to next development version
* Align available functions to right Qt version
* fix workflows (apt/nightly)
* Disable QNetworkConfigurationManager deprecation warnings
* Initial go on Smart Pointers
* Add Deallocation
* Correct QT_WARNING_DISABLE_DEPRECATED (available since 5.9)
* Cluster Build Variables
* Hyperion Light
* Address build warnings
* Hyperion Light - UI
* Update Protobuf to latest master
* Removed compiler warnings
* Added restart ability to systray
* Correct Protobuf
* Ignore 'no-return' warning on protobuf build
* hyperion-remote: Fix auto discovery of hyperion server
* Fix Qt version override
* Update changelog
* Remove Grabber Components, if no Grabber exists
* Standalone Grabber - Fix fps default
* Remote Control - Have Source Selction accrosswhole screen
* Enable Blackborder detection only, if relevant input sources available
* Enable Blackborder detection only, if relevant input sources available
* Remote UI - rearrange containers
* Checkout
* Fix compilation on windows
* Re-added qmdnsengine template cmake
* chrono added for linux
* Removed existing AVAHI/Bonjour, allow to enable/disable mDNS
* hyperiond macos typo fix
* Fix macOS Bundle build
* Fix macOS bundle info details
* Correct CMake files
* Removed existing AVAHI/Bonjour (2)
* Share hyperion's services via mDNS
* Add mDNS Browser and mDNS for LED-Devices
* Support mDNS discovery for standalone grabbers
* Remove ZLib Dependency & Cleanup
* mDNS - hanle 2.local2 an ".local." domains equally
* Hue - Link discovery to bridge class, workaround port 443 for mDNS discovery
* Fix save button state when switching between devices
* Removed sessions (of other hyperions)
* mDNS Publisher - Simplify service naming
* mDNS refactoring & Forwarder discovery
* mDNS Updates to use device service name
* Consistency of standalone grabbers with mDNS Service Registry
* Merge branch 'hyperion-project:master' into mDNS
* Start JSON and WebServers only after Instance 0 is available
* Remove bespoke qDebug Output again
* MDNS updates and refactor Forwarder
* Minor updates
* Upgrade to CMake 3.1
* typo
* macOS fix
* Correct merge
* - Remove dynamic linker flag from standalone dispmanX Grabber
- Added ability to use system qmdns libs
* Cec handler library will load at runtime
* typo fix
* protobuf changes
* mDNS changes for Windows/macOS
* test window build qmdnsengine
* absolute path to protobuf cmake dir
* Rework Hue Wizard supporting mDNS
* LED-Devices - Retry support + Refactoring (excl. Hue)
* LED-Devices - Refactoring/Retry support Hue + additional alignments
* Address LGTM findings
* Fix CI-Build, revert test changes
* Build Windows in Release mode to avoid python problem
* Correct that WebServerObject is available earlier
* Ensure that instance name in logs for one instance are presented
* Update content LEDs
* Rework mDNS Address lookup
* Fix LED UI
* Fix for non mDNS Services (ignore default port)
* Disbale device when now input is available
* Revert back some updates, ensure last color is updated when switched on
* Handle reopening case and changed IP, port for API-calls
* Add UPD-DDP Device
* WLED support for DDP
* Fix printout
* LEDDevice - Allow more retries, udapte defaults
* LED-Net Devices - Select Custom device, if configured
Co-authored-by: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com>
Co-authored-by: Paulchen Panther <Paulchen-Panter@protonmail.com>
2022-05-01 19:42:47 +02:00
|
|
|
else
|
|
|
|
{
|
2023-02-12 21:20:50 +01:00
|
|
|
if (reply->error() == QNetworkReply::OperationCanceledError)
|
2021-03-19 22:52:04 +01:00
|
|
|
{
|
2023-02-12 21:20:50 +01:00
|
|
|
errorReason = "Network request timeout error";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
errorReason = reply->errorString();
|
2021-03-19 22:52:04 +01:00
|
|
|
}
|
2020-07-12 20:27:56 +02:00
|
|
|
|
2023-02-12 21:20:50 +01:00
|
|
|
}
|
|
|
|
response.setError(true);
|
|
|
|
response.setErrorReason(errorReason);
|
2020-07-12 20:27:56 +02:00
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2021-11-17 20:34:49 +01:00
|
|
|
void ProviderRestApi::setHeader(QNetworkRequest::KnownHeaders header, const QVariant& value)
|
|
|
|
{
|
|
|
|
QVariant headerValue = _networkRequestHeaders.header(header);
|
|
|
|
if (headerValue.isNull())
|
|
|
|
{
|
|
|
|
_networkRequestHeaders.setHeader(header, value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!headerValue.toString().contains(value.toString()))
|
|
|
|
{
|
|
|
|
_networkRequestHeaders.setHeader(header, headerValue.toString() + "," + value.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-02-12 21:20:50 +01:00
|
|
|
|
|
|
|
void ProviderRestApi::setHeader(const QByteArray &headerName, const QByteArray &headerValue)
|
|
|
|
{
|
|
|
|
_networkRequestHeaders.setRawHeader(headerName, headerValue);
|
|
|
|
}
|