From 2362e2559360c1b3a4cb55c8bfe29dbf606e0d93 Mon Sep 17 00:00:00 2001 From: Roland Rossgotterer Date: Wed, 16 Oct 2019 16:22:38 +0200 Subject: [PATCH] [AFV] Add client version to API auth --- samples/afvclient/afvclientbridge.h | 3 ++- src/blackconfig/buildconfig.cpp | 7 +++++++ src/blackconfig/buildconfig.h | 3 +++ src/blackcore/afv/clients/afvclient.cpp | 6 +++--- src/blackcore/afv/clients/afvclient.h | 2 +- src/blackcore/afv/connection/apiserverconnection.cpp | 6 ++++-- src/blackcore/afv/connection/apiserverconnection.h | 3 ++- src/blackcore/afv/connection/clientconnection.cpp | 4 ++-- src/blackcore/afv/connection/clientconnection.h | 2 +- src/blackcore/context/contextaudio.cpp | 4 +++- 10 files changed, 28 insertions(+), 12 deletions(-) diff --git a/samples/afvclient/afvclientbridge.h b/samples/afvclient/afvclientbridge.h index c5ead2272..8e426b7af 100644 --- a/samples/afvclient/afvclientbridge.h +++ b/samples/afvclient/afvclientbridge.h @@ -47,7 +47,8 @@ public: //! \copydoc BlackCore::Afv::Clients::CAfvClient::connectTo Q_INVOKABLE void connectTo(const QString &cid, const QString &password, const QString &callsign) { - m_afvClient->connectTo(cid, password, callsign); + const QString client = "swift " % BlackConfig::CBuildConfig::getShortVersionString(); + m_afvClient->connectTo(cid, password, callsign, client); } //! \copydoc BlackCore::Afv::Clients::CAfvClient::disconnectFrom diff --git a/src/blackconfig/buildconfig.cpp b/src/blackconfig/buildconfig.cpp index fd1af020b..ef06ec230 100644 --- a/src/blackconfig/buildconfig.cpp +++ b/src/blackconfig/buildconfig.cpp @@ -167,6 +167,13 @@ namespace BlackConfig return s; } + const QString &CBuildConfig::getShortVersionString() + { + static const QVersionNumber v { versionMajor(), versionMinor(), versionMicro() }; + static const QString s(v.toString()); + return s; + } + const QString &CBuildConfig::getVersionStringPlatform() { static const QString s = getPlatformString() % u' ' % getVersionString(); diff --git a/src/blackconfig/buildconfig.h b/src/blackconfig/buildconfig.h index 54fb6ff4e..cf1e80437 100644 --- a/src/blackconfig/buildconfig.h +++ b/src/blackconfig/buildconfig.h @@ -133,6 +133,9 @@ namespace BlackConfig //! Version as QVersionNumber static const QString &getVersionString(); + //! Version as QVersionNumber + static const QString &getShortVersionString(); + //! Version as QVersionNumber plus platform info static const QString &getVersionStringPlatform(); diff --git a/src/blackcore/afv/clients/afvclient.cpp b/src/blackcore/afv/clients/afvclient.cpp index 9e1044e90..5d22ebb3f 100644 --- a/src/blackcore/afv/clients/afvclient.cpp +++ b/src/blackcore/afv/clients/afvclient.cpp @@ -119,13 +119,13 @@ namespace BlackCore m_connectedWithContext = true; } - void CAfvClient::connectTo(const QString &cid, const QString &password, const QString &callsign) + void CAfvClient::connectTo(const QString &cid, const QString &password, const QString &callsign, const QString &client) { if (QThread::currentThread() != thread()) { // Method needs to be executed in the object thread since it will create new QObject children QPointer myself(this); - QMetaObject::invokeMethod(this, [ = ]() { if (myself) { connectTo(cid, password, callsign); }}); + QMetaObject::invokeMethod(this, [ = ]() { if (myself) { connectTo(cid, password, callsign, client); }}); return; } @@ -138,7 +138,7 @@ namespace BlackCore QMutexLocker lock(&m_mutexConnection); // async connection - m_connection->connectTo(cid, password, callsign, { this, [ = ](bool authenticated) + m_connection->connectTo(cid, password, callsign, client, { this, [ = ](bool authenticated) { // this is the callback when the connection has been established diff --git a/src/blackcore/afv/clients/afvclient.h b/src/blackcore/afv/clients/afvclient.h index 06120640f..d41889f4a 100644 --- a/src/blackcore/afv/clients/afvclient.h +++ b/src/blackcore/afv/clients/afvclient.h @@ -86,7 +86,7 @@ namespace BlackCore //! Connect to network //! \threadsafe //! \remark runs in thread of CAfvClient object and is ASYNC when called from another thread - Q_INVOKABLE void connectTo(const QString &cid, const QString &password, const QString &getCallsign); + Q_INVOKABLE void connectTo(const QString &cid, const QString &password, const QString &getCallsign, const QString &client); //! Disconnect from network //! \threadsafe diff --git a/src/blackcore/afv/connection/apiserverconnection.cpp b/src/blackcore/afv/connection/apiserverconnection.cpp index b5db29178..74184340f 100644 --- a/src/blackcore/afv/connection/apiserverconnection.cpp +++ b/src/blackcore/afv/connection/apiserverconnection.cpp @@ -43,13 +43,14 @@ namespace BlackCore CLogMessage(this).debug(u"ApiServerConnection instantiated"); } - void CApiServerConnection::connectTo(const QString &username, const QString &password, const QUuid &networkVersion, ConnectionCallback callback) + void CApiServerConnection::connectTo(const QString &username, const QString &password, const QString &client, const QUuid &networkVersion, ConnectionCallback callback) { if (isShuttingDown()) { return; } m_username = username; m_password = password; m_networkVersion = networkVersion; + m_client = client; m_isAuthenticated = false; QUrl url(m_addressUrl); @@ -60,6 +61,7 @@ namespace BlackCore {"username", username}, {"password", password}, {"networkversion", networkVersion.toString()}, + {"client", client} }; QNetworkRequest request(url); @@ -295,7 +297,7 @@ namespace BlackCore { if (QDateTime::currentDateTimeUtc() > m_expiryLocalUtc.addSecs(-5 * 60)) { - this->connectTo(m_username, m_password, m_networkVersion, { this, [ = ](bool) {}}); + this->connectTo(m_username, m_password, m_client, m_networkVersion, { this, [ = ](bool) {}}); } } diff --git a/src/blackcore/afv/connection/apiserverconnection.h b/src/blackcore/afv/connection/apiserverconnection.h index 78451955a..f1c4f442c 100644 --- a/src/blackcore/afv/connection/apiserverconnection.h +++ b/src/blackcore/afv/connection/apiserverconnection.h @@ -60,7 +60,7 @@ namespace BlackCore //! Connect to network //! \remark ASYNC, calling callback when done - void connectTo(const QString &username, const QString &password, const QUuid &networkVersion, ConnectionCallback callback); + void connectTo(const QString &username, const QString &password, const QString &client, const QUuid &networkVersion, ConnectionCallback callback); //! Add callsign to network PostCallsignResponseDto addCallsign(const QString &callsign); @@ -172,6 +172,7 @@ namespace BlackCore QString m_username; QString m_password; QUuid m_networkVersion; + QString m_client; QDateTime m_expiryLocalUtc; qint64 m_serverToUserOffsetMs; bool m_isAuthenticated = false; diff --git a/src/blackcore/afv/connection/clientconnection.cpp b/src/blackcore/afv/connection/clientconnection.cpp index ed58d30ea..f3a5e277d 100644 --- a/src/blackcore/afv/connection/clientconnection.cpp +++ b/src/blackcore/afv/connection/clientconnection.cpp @@ -37,7 +37,7 @@ namespace BlackCore connect(m_udpSocket, qOverload(&QUdpSocket::error), this, &CClientConnection::handleSocketError); } - void CClientConnection::connectTo(const QString &userName, const QString &password, const QString &callsign, ConnectionCallback callback) + void CClientConnection::connectTo(const QString &userName, const QString &password, const QString &callsign, const QString &client, ConnectionCallback callback) { if (m_connection.isConnected()) { @@ -49,7 +49,7 @@ namespace BlackCore m_connection.setCallsign(callsign); QPointer myself(this); - m_apiServerConnection->connectTo(userName, password, m_networkVersion, + m_apiServerConnection->connectTo(userName, password, client, m_networkVersion, { // callback called when connected this, [ = ](bool authenticated) diff --git a/src/blackcore/afv/connection/clientconnection.h b/src/blackcore/afv/connection/clientconnection.h index b99bdd8da..ad4a38702 100644 --- a/src/blackcore/afv/connection/clientconnection.h +++ b/src/blackcore/afv/connection/clientconnection.h @@ -46,7 +46,7 @@ namespace BlackCore //! Connect //! \remark ASYNC, calling callback when done - void connectTo(const QString &userName, const QString &password, const QString &callsign, ConnectionCallback callback); + void connectTo(const QString &userName, const QString &password, const QString &callsign, const QString &client, ConnectionCallback callback); //! Disconnect void disconnectFrom(const QString &reason = {}); diff --git a/src/blackcore/context/contextaudio.cpp b/src/blackcore/context/contextaudio.cpp index 94ec9dd18..88bfda667 100644 --- a/src/blackcore/context/contextaudio.cpp +++ b/src/blackcore/context/contextaudio.cpp @@ -19,6 +19,7 @@ #include "blackmisc/dbusserver.h" #include "blackmisc/verify.h" #include "blackmisc/icons.h" +#include "blackconfig/buildconfig.h" using namespace BlackMisc; using namespace BlackMisc::Aviation; @@ -399,7 +400,8 @@ namespace BlackCore m_voiceClient->updateVoiceServerUrl(vs.getAfvVoiceServerUrl()); const CUser connectedUser = this->getIContextNetwork()->getConnectedServer().getUser(); - m_voiceClient->connectTo(connectedUser.getId(), connectedUser.getPassword(), connectedUser.getCallsign().asString()); + const QString client = "swift " % BlackConfig::CBuildConfig::getShortVersionString(); + m_voiceClient->connectTo(connectedUser.getId(), connectedUser.getPassword(), connectedUser.getCallsign().asString(), client); } else if (to.isDisconnected()) {