summaryrefslogtreecommitdiffstats
path: root/src/client/net
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/net')
-rw-r--r--src/client/net/serverconnection.cpp45
-rw-r--r--src/client/net/serverconnection.h16
-rw-r--r--src/client/net/serverdiscovery.cpp23
-rw-r--r--src/client/net/serverdiscovery.h6
4 files changed, 40 insertions, 50 deletions
diff --git a/src/client/net/serverconnection.cpp b/src/client/net/serverconnection.cpp
index ca19c76..e500528 100644
--- a/src/client/net/serverconnection.cpp
+++ b/src/client/net/serverconnection.cpp
@@ -1,21 +1,20 @@
#include "serverconnection.h"
-#include <QtCore>
-#include <QPixmap>
-#include <QGuiApplication>
-#include <QHostInfo>
-#include <unistd.h>
-#include <cstdlib>
-#include <sys/types.h>
-#include <pwd.h>
-//#define verbose
#include "../vnc/vncserver.h"
-
#include "../../shared/util.h"
#include "../../shared/settings.h"
#include "../util/platform/blankscreen.h"
#include "../clientapp/clientapp.h"
+#include <QPixmap>
+#include <QGuiApplication>
+#include <QHostInfo>
+#include <QScreen>
+// For getting logged-in username
+#include <sys/types.h>
+#include <pwd.h>
+#include <unistd.h>
+
#define CHALLENGE_LEN 20
ServerConnection::ServerConnection(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect) :
@@ -23,16 +22,13 @@ ServerConnection::ServerConnection(const QString& host, const quint16 port, cons
{
_socket = new QSslSocket();
_blank = new BlankScreen();
- connect(_socket, SIGNAL(encrypted()), this, SLOT(sock_connected()));
- connect(_socket, SIGNAL(readyRead()), this, SLOT(sock_dataArrival()));
- connect(_socket, SIGNAL(disconnected()), this, SLOT(sock_closed()));
- connect(_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(sock_error(QAbstractSocket::SocketError)));
- connect(_socket,
- SIGNAL(sslErrors(const QList<QSslError> &)),
- this,
- SLOT(sslErrors(const QList<QSslError> &))
+ connect(_socket, &QSslSocket::encrypted, this, &ServerConnection::sock_connected);
+ connect(_socket, &QSslSocket::readyRead, this, &ServerConnection::sock_dataArrival);
+ connect(_socket, &QSslSocket::disconnected, this, &ServerConnection::sock_closed);
+ connect(_socket, &QSslSocket::errorOccurred, this, &ServerConnection::sock_error);
+ connect(_socket, QOverload<const QList<QSslError> &>::of(&QSslSocket::sslErrors),
+ this, &ServerConnection::sslErrors
);
- connect(_socket, &QSslSocket::peerVerifyError, [=](const QSslError &error) { qDebug() << "PVE:" << error.errorString(); });
qDebug("Connecting to %s on port %d", host.toUtf8().data(), int(port));
_socket->ignoreSslErrors();
_socket->connectToHostEncrypted(host, port);
@@ -40,7 +36,7 @@ ServerConnection::ServerConnection(const QString& host, const quint16 port, cons
_lastData = QDateTime::currentMSecsSinceEpoch() + PING_TIMEOUT_MS;
_timerConnectionCheck = startTimer(5000);
// Connect the vnc start/stop signal to this class, so we can tell the server about successful vnc server startup
- connect(VncServer::instance(), SIGNAL(started(int, QString&, QString&)), this, SLOT(onVncServerStartStop(int, QString&, QString&)));
+ connect(VncServer::instance(), &VncServer::started, this, &ServerConnection::onVncServerStartStop);
}
ServerConnection::~ServerConnection()
@@ -112,7 +108,7 @@ void ServerConnection::handleMsg()
emit stateChange(ConnectWindow::AwaitingChallengeResponse);
_myChallenge.resize(CHALLENGE_LEN);
for (int i = 0; i < CHALLENGE_LEN; ++i) {
- _myChallenge[i] = char(qrand() & 0xff);
+ _myChallenge[i] = char(slxrand() & 0xff);
}
QByteArray serverChallenge(_fromServer.getFieldBytes(_CHALLENGE));
_toServer.reset();
@@ -320,7 +316,7 @@ void ServerConnection::timerEvent(QTimerEvent *event)
* server was succesfully started, or was terminated (either planned or
* crashed).
*/
-void ServerConnection::onVncServerStartStop(int port, QString& ropass, QString& rwpass)
+void ServerConnection::onVncServerStartStop(int port, const QString &ropass, const QString &rwpass)
{
_toServer.reset();
_toServer.setField(_ID, _VNCSERVER);
@@ -357,9 +353,8 @@ void ServerConnection::onVncViewerStartStop(const bool started, const int client
void ServerConnection::sslErrors(const QList<QSslError> & errors)
{
_socket->ignoreSslErrors();
- for (QList<QSslError>::const_iterator it = errors.begin(); it != errors.end(); it++) {
- const QSslError &err = *it;
- qDebug("Connect SSL: %s", qPrintable(err.errorString()));
+ for (const auto &err : errors) {
+ qDebug("Connect SSL: %s", qPrintable(err.errorString()));
if (err.error() == QSslError::HostNameMismatch)
continue; // We don't pay attention to hostnames for validation
if (err.error() == QSslError::SelfSignedCertificate)
diff --git a/src/client/net/serverconnection.h b/src/client/net/serverconnection.h
index f5f6264..f434f0b 100644
--- a/src/client/net/serverconnection.h
+++ b/src/client/net/serverconnection.h
@@ -33,18 +33,15 @@ private:
void checkLocalConnection();
public:
- ServerConnection(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect);
+ ServerConnection(const QString& host, quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect);
void disconnectFromServer();
- ~ServerConnection();
+ ~ServerConnection() override;
inline bool isConnected() const
{
return _socket != nullptr && _socket->state() == QAbstractSocket::ConnectedState;
}
- const inline QString getPeerAdress() const
- {
- return _socket->peerAddress().toString();
- }
+ QString getPeerAdress() const { return _socket->peerAddress().toString(); }
bool isLocalConnection() {
if (_isLocalConnection == -1) {
@@ -57,7 +54,7 @@ public:
void sendAttention(bool on);
protected:
- void timerEvent(QTimerEvent *event);
+ void timerEvent(QTimerEvent *event) override;
private slots:
void sslErrors(const QList<QSslError> & errors); // triggered for errors that occur during SSL negotiation
@@ -66,9 +63,10 @@ private slots:
void sock_error(QAbstractSocket::SocketError errcode); // triggered if an error occurs on the socket
void sock_connected(); // triggered if the connection is established and ready to use
- void onVncServerStartStop(int port, QString& ropass, QString& rwpass); // triggered if the local vnc server was started
+ void onVncServerStartStop(int port, const QString &ropass, const QString &rwpass); // triggered if the local vnc server was started
- void onVncViewerStartStop(const bool started, const int clientId);
+public slots:
+ void onVncViewerStartStop(bool started, int clientId);
signals:
void openVnc(const QString& host, int port, const QString& passwd, bool ro, bool fullscreen, const QString& caption, const int clientId, const QByteArray& rawThumb);
diff --git a/src/client/net/serverdiscovery.cpp b/src/client/net/serverdiscovery.cpp
index b2d7605..efae165 100644
--- a/src/client/net/serverdiscovery.cpp
+++ b/src/client/net/serverdiscovery.cpp
@@ -4,8 +4,7 @@
#include "../../shared/network.h"
#include "../../shared/util.h"
#include "serverdiscovery.h"
-#include <assert.h>
-
+#include "../util/util.h"
/**
* Ctor
@@ -21,33 +20,31 @@ ServerDiscovery::ServerDiscovery(QObject *parent)
/* Try to get a UDP port for server discovery */
int tries = 10;
while (tries-- != 0) {
- quint16 port = quint16(16384 + qrand() % 32768);
+ quint16 port = quint16(16384 + slxrand() % 32768);
if (_discoverySocket.bind(QHostAddress::AnyIPv4, port))
break;
if (tries == 0)
qFatal("Could not bind to any UDP port for server discovery.");
}
// Handle incoming messages
- connect(&_discoverySocket, SIGNAL(readyRead()), this, SLOT(onUdpReadyRead()));
+ connect(&_discoverySocket, &QUdpSocket::readyRead, this, &ServerDiscovery::onUdpReadyRead);
/* Setup the discovery timer */
_discoveryTimer.setInterval(_minDiscoveryInterval);
_discoveryTimer.setSingleShot(true);
//
- connect(&_discoveryTimer, SIGNAL(timeout()), this, SLOT(doDiscovery()));
+ connect(&_discoveryTimer, &QTimer::timeout, this, &ServerDiscovery::doDiscovery);
}
/**
* Dtor
*/
-ServerDiscovery::~ServerDiscovery()
-{
-}
+ServerDiscovery::~ServerDiscovery() = default;
/**
* @brief start
*/
-void ServerDiscovery::start(const QByteArray& sessionName, QString mgrIP)
+void ServerDiscovery::start(const QByteArray& sessionName, const QString& mgrIP)
{
if (!mgrIP.isEmpty()) {
_mgrIP.setAddress(mgrIP);
@@ -98,8 +95,8 @@ void ServerDiscovery::doDiscovery()
if (_salt2.size() < SALT_LEN)
_salt2.resize(SALT_LEN);
for (int i = 0; i < SALT_LEN; ++i) {
- salt1[i] = char(qrand() & 0xff);
- _salt2[i] = char(qrand() & 0xff);
+ salt1[i] = char(slxrand() & 0xff);
+ _salt2[i] = char(slxrand() & 0xff);
}
_packet.reset();
_packet.setField(_HASH, genSha1(&_nameBytes, &salt1, &iplist));
@@ -141,7 +138,7 @@ void ServerDiscovery::onUdpReadyRead()
{
char data[UDPBUFSIZ];
QHostAddress addr;
- quint16 port;
+ quint16 peerPort;
while (_discoverySocket.hasPendingDatagrams()) {
// Discard any packets if discovery is stopped
if (!this->isActive()) {
@@ -149,7 +146,7 @@ void ServerDiscovery::onUdpReadyRead()
continue;
}
- const qint64 size = _discoverySocket.readDatagram(data, UDPBUFSIZ, &addr, &port);
+ const qint64 size = _discoverySocket.readDatagram(data, UDPBUFSIZ, &addr, &peerPort);
if (size <= 0) //|| clientApp->connection() != nullptr) // TODO CHECK
continue;
diff --git a/src/client/net/serverdiscovery.h b/src/client/net/serverdiscovery.h
index d7d6010..21f9bf9 100644
--- a/src/client/net/serverdiscovery.h
+++ b/src/client/net/serverdiscovery.h
@@ -17,10 +17,10 @@ public:
InvalidHash
};
- explicit ServerDiscovery(QObject *parent = 0);
- ~ServerDiscovery();
+ explicit ServerDiscovery(QObject *parent = nullptr);
+ ~ServerDiscovery() override;
- void start(const QByteArray& sessionName, QString mgrIP);
+ void start(const QByteArray& sessionName, const QString& mgrIP);
void stop();
inline bool isActive() { return _discoveryTimer.isActive(); }