summaryrefslogtreecommitdiffstats
path: root/src/client/net/serverconnection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/net/serverconnection.cpp')
-rw-r--r--src/client/net/serverconnection.cpp51
1 files changed, 26 insertions, 25 deletions
diff --git a/src/client/net/serverconnection.cpp b/src/client/net/serverconnection.cpp
index ca19c76..690ba23 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,14 @@ 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, QOverload<QAbstractSocket::SocketError>::of(&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 +37,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()
@@ -106,13 +103,18 @@ void ServerConnection::handleMsg()
_lastData = QDateTime::currentMSecsSinceEpoch() + PING_TIMEOUT_MS;
const QString &id = _fromServer.getFieldString(_ID);
+ if (id == _ERROR) {
+ qWarning() << "Server sent error message:" << _fromServer.getFieldString(_ERROR);
+ return;
+ }
+
if (_authed == 0) {
if (id == _CHALLENGE) {
// Initial challenge request by server
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 +322,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 +359,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)