diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/main.cpp | 2 | ||||
-rw-r--r-- | src/client/net/serverconnection.cpp | 6 | ||||
-rw-r--r-- | src/client/net/serverdiscovery.cpp | 14 | ||||
-rw-r--r-- | src/client/vnc/vncthread.cpp | 8 | ||||
-rw-r--r-- | src/server/main.cpp | 2 | ||||
-rw-r--r-- | src/server/mainwindow/mainwindow.cpp | 10 | ||||
-rw-r--r-- | src/server/net/client.cpp | 2 | ||||
-rw-r--r-- | src/server/net/discoverylistener.cpp | 18 | ||||
-rw-r--r-- | src/server/net/listenserver.cpp | 2 | ||||
-rw-r--r-- | src/server/net/sslserver.cpp | 2 | ||||
-rw-r--r-- | src/shared/networkmessage.cpp | 20 |
11 files changed, 45 insertions, 41 deletions
diff --git a/src/client/main.cpp b/src/client/main.cpp index 61ca0e9..eefd0d8 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -9,7 +9,7 @@ int main(int argc, char** argv) { ClientApp app(argc, argv); - qsrand((uint)QDateTime::currentMSecsSinceEpoch()); + qsrand(uint(QDateTime::currentMSecsSinceEpoch())); /* here we handle the arguments that were not handled by ClientApp */ for (QString a : app.arguments()) { diff --git a/src/client/net/serverconnection.cpp b/src/client/net/serverconnection.cpp index 6350418..ca19c76 100644 --- a/src/client/net/serverconnection.cpp +++ b/src/client/net/serverconnection.cpp @@ -33,7 +33,7 @@ ServerConnection::ServerConnection(const QString& host, const quint16 port, cons SLOT(sslErrors(const QList<QSslError> &)) ); connect(_socket, &QSslSocket::peerVerifyError, [=](const QSslError &error) { qDebug() << "PVE:" << error.errorString(); }); - qDebug("Connecting to %s on port %d", host.toUtf8().data(), (int)port); + qDebug("Connecting to %s on port %d", host.toUtf8().data(), int(port)); _socket->ignoreSslErrors(); _socket->connectToHostEncrypted(host, port); _timerId = startTimer(4000); @@ -112,7 +112,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(qrand() & 0xff); } QByteArray serverChallenge(_fromServer.getFieldBytes(_CHALLENGE)); _toServer.reset(); @@ -407,7 +407,7 @@ void ServerConnection::sock_closed() void ServerConnection::sock_error(QAbstractSocket::SocketError errcode) { - qDebug("Connection error: %d", (int)errcode); + qDebug("Connection error: %d", int(errcode)); this->disconnectFromServer(); } diff --git a/src/client/net/serverdiscovery.cpp b/src/client/net/serverdiscovery.cpp index 799fcbe..1b29398 100644 --- a/src/client/net/serverdiscovery.cpp +++ b/src/client/net/serverdiscovery.cpp @@ -21,7 +21,7 @@ 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 + qrand() % 32768); if (_discoverySocket.bind(QHostAddress::AnyIPv4, port)) break; if (tries == 0) @@ -98,8 +98,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(qrand() & 0xff); + _salt2[i] = char(qrand() & 0xff); } _packet.reset(); _packet.setField(_HASH, genSha1(&_nameBytes, &salt1, &iplist)); @@ -154,7 +154,7 @@ void ServerDiscovery::onUdpReadyRead() continue; _packet.reset(); - if (_packet.readMessage(data, (quint32)size) != NM_READ_OK) + if (_packet.readMessage(data, quint32(size)) != NM_READ_OK) continue; // Valid packet, process it: @@ -183,7 +183,11 @@ void ServerDiscovery::onUdpReadyRead() << addr.toString() + ":" + QString::fromUtf8(port) + "/" + _nameBytes; // Tell that a server hs been found - emit serverDetected(addr.toString(), (quint16)QString::fromUtf8(port).toInt(), _nameBytes, cert, (_mgrIP == addr)); + bool ok = false; + const ushort iport = QString::fromUtf8(port).toUShort(&ok); + if (ok) { + emit serverDetected(addr.toString(), quint16(iport), _nameBytes, cert, (_mgrIP == addr)); + } // Stop the discovery this->stop(); diff --git a/src/client/vnc/vncthread.cpp b/src/client/vnc/vncthread.cpp index e399e9b..1a903d5 100644 --- a/src/client/vnc/vncthread.cpp +++ b/src/client/vnc/vncthread.cpp @@ -89,7 +89,7 @@ void VncThread::run() _client->frameBuffer = nullptr; // save this instance in vnc-struct for callbacks - rfbClientSetClientData(_client, 0, this); + rfbClientSetClientData(_client, nullptr, this); // start client if (rfbInitClient(_client, nullptr, nullptr)) { @@ -172,7 +172,7 @@ void VncThread::emitStarted() */ char* VncThread::passwdHandler(rfbClient *client) { - VncThread* t = (VncThread*)rfbClientGetClientData(client, 0); + VncThread* t = reinterpret_cast<VncThread*>(rfbClientGetClientData(client, nullptr)); return strdup(t->_passwd.toUtf8()); } @@ -185,7 +185,7 @@ char* VncThread::passwdHandler(rfbClient *client) */ rfbBool VncThread::frameBufferHandler(rfbClient *client) { - VncThread *t = (VncThread*)rfbClientGetClientData(client, 0); + VncThread *t = reinterpret_cast<VncThread*>(rfbClientGetClientData(client, nullptr)); const int width = client->width, height = client->height, depth = 32; const int size = width * height * (depth / 8); qDebug("[%s] Remote desktop: %ix%ix%i", t->metaObject()->className(), width, height, depth); @@ -201,7 +201,7 @@ rfbBool VncThread::frameBufferHandler(rfbClient *client) ::exit(1); } client->frameBuffer = t->_img->bits(); - memset(client->frameBuffer, '\0', (size_t)size); + memset(client->frameBuffer, '\0', size_t(size)); client->format.trueColour = 1; client->format.bitsPerPixel = depth; client->format.redShift = 16; diff --git a/src/server/main.cpp b/src/server/main.cpp index 34a585c..769fedb 100644 --- a/src/server/main.cpp +++ b/src/server/main.cpp @@ -22,7 +22,7 @@ void usage() int main(int argc, char** argv) { - qsrand((uint)QDateTime::currentMSecsSinceEpoch()); + qsrand(uint(QDateTime::currentMSecsSinceEpoch())); ServerApp app(argc, argv); for (QString a : app.arguments()) { diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index dcf8973..73fcbaf 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -243,7 +243,7 @@ int distance(QPointF a, QPointF b) const qreal dx = a.x() - b.x(); const qreal dy = a.y() - b.y(); const qreal sum = dx * dx + dy * dy; - return (int)sum; + return int(sum); } /***************************************************************************//** @@ -460,13 +460,13 @@ enum AspectStatus { GRID_OK, GRID_TOO_WIDE, GRID_TOO_TALL }; * */ AspectStatus checkAspectRatio(const QSize& frameSize, const QSize& gridSize) { - float aspectRoom = ((float) gridSize.height()) / ((float) gridSize.width()); - float aspectFrame = ((float) frameSize.height()) / ((float) frameSize.width()); + float aspectRoom = float(gridSize.height()) / float(gridSize.width()); + float aspectFrame = float(frameSize.height()) / float(frameSize.width()); - if (aspectRoom / aspectFrame < 0.8) { + if (aspectRoom / aspectFrame < 0.8f) { return GRID_TOO_WIDE; } - if ( aspectFrame / aspectRoom < 0.8) { + if ( aspectFrame / aspectRoom < 0.8f) { return GRID_TOO_TALL; } return GRID_OK; diff --git a/src/server/net/client.cpp b/src/server/net/client.cpp index 9e96dec..9b2101f 100644 --- a/src/server/net/client.cpp +++ b/src/server/net/client.cpp @@ -44,7 +44,7 @@ Client::Client(QTcpSocket* socket) : _socket(socket) // Send challenge _challenge.resize(CHALLENGE_LEN); for (int i = 0; i < CHALLENGE_LEN; ++i) { - _challenge[i] = (char)(qrand() & 0xff); + _challenge[i] = char(qrand() & 0xff); } NetworkMessage msgChlng; msgChlng.setField(_ID, _CHALLENGE); diff --git a/src/server/net/discoverylistener.cpp b/src/server/net/discoverylistener.cpp index 978794e..cfeef82 100644 --- a/src/server/net/discoverylistener.cpp +++ b/src/server/net/discoverylistener.cpp @@ -33,7 +33,7 @@ DiscoveryListener::DiscoveryListener() : _socket(this), _counterResetPos(0) { if (!_socket.bind(QHostAddress::AnyIPv4, SERVICE_DISCOVERY_PORT)) - qFatal("Could not bind to service discovery port %d", (int)SERVICE_DISCOVERY_PORT); + qFatal("Could not bind to service discovery port %d", int(SERVICE_DISCOVERY_PORT)); connect(&_socket, SIGNAL(readyRead()), this, SLOT(onReadyRead())); for (int i = 0; i < SD_PACKET_TABLE_SIZE; ++i) _packetCounter[i] = 0; @@ -57,8 +57,8 @@ static quint16 hash(const QHostAddress& host) static quint16 seed1 = 0, seed2 = 0; while (seed1 == 0) { // Make sure the algorithm uses different seeds each time the program is // run to prevent hash collision attacks - seed1 = (quint16)(qrand() & 0xffff); - seed2 = (quint16)(qrand() & 0xffff); + seed1 = quint16(qrand() & 0xffff); + seed2 = quint16(qrand() & 0xffff); } quint8 data[16], len; if (host.protocol() == QAbstractSocket::IPv4Protocol) { @@ -79,14 +79,14 @@ static quint16 hash(const QHostAddress& host) } else { // Durr? len = 2; - data[0] = (quint8)qrand(); - data[1] = (quint8)qrand(); + data[0] = quint8(qrand()); + data[1] = quint8(qrand()); } quint16 result = 0; quint16 mod = seed1; for (quint8 i = 0; i < len; ++i) { - result = (quint16)(((result << 1) + data[i]) ^ mod); // because of the shift this algo is not suitable for len(input) > 8 - mod = (quint16)(mod + seed2 + data[i]); + result = quint16(((result << 1) + data[i]) ^ mod); // because of the shift this algo is not suitable for len(input) > 8 + mod = quint16(mod + seed2 + data[i]); } return result; } @@ -105,7 +105,7 @@ void DiscoveryListener::timerEvent(QTimerEvent* /* event */ ) if (++_counterResetPos >= SD_PACKET_TABLE_SIZE) _counterResetPos = 0; if (_packetCounter[_counterResetPos] > 10) { - _packetCounter[_counterResetPos] = (quint8)(_packetCounter[_counterResetPos] - 10); + _packetCounter[_counterResetPos] = quint8(_packetCounter[_counterResetPos] - 10); } else if (_packetCounter[_counterResetPos] != 0) { _packetCounter[_counterResetPos] = 0; } @@ -138,7 +138,7 @@ void DiscoveryListener::onReadyRead() } ++_packetCounter[bucket]; _packet.reset(); - if (_packet.readMessage(data, (quint32)size) != NM_READ_OK) + if (_packet.readMessage(data, quint32(size)) != NM_READ_OK) continue; // Valid packet, process it: const QByteArray iplist(_packet.getFieldBytes(_IPLIST)); diff --git a/src/server/net/listenserver.cpp b/src/server/net/listenserver.cpp index 628b62d..0438fb4 100644 --- a/src/server/net/listenserver.cpp +++ b/src/server/net/listenserver.cpp @@ -11,7 +11,7 @@ ListenServer::ListenServer(quint16 port) { if (!_server.listen(QHostAddress::AnyIPv4, port) || !_server.isListening()) - qFatal("Cannot bind to TCP port %d (incoming SSL clients)", (int)port); + qFatal("Cannot bind to TCP port %d (incoming SSL clients)", int(port)); connect(&_server, SIGNAL(newConnection()), this, SLOT(newClientConnection())); } diff --git a/src/server/net/sslserver.cpp b/src/server/net/sslserver.cpp index 9e1e82d..62fe3da 100644 --- a/src/server/net/sslserver.cpp +++ b/src/server/net/sslserver.cpp @@ -61,7 +61,7 @@ void SslServer::incomingConnection(qintptr socketDescriptor) if (++certFails > 5) { CertManager::fatal(); } - ::close((int)socketDescriptor); + ::close(int(socketDescriptor)); return; } QSslSocket *serverSocket = new QSslSocket(nullptr); diff --git a/src/shared/networkmessage.cpp b/src/shared/networkmessage.cpp index 0bdf3c5..3c6a687 100644 --- a/src/shared/networkmessage.cpp +++ b/src/shared/networkmessage.cpp @@ -26,14 +26,14 @@ static quint16 _htons(const quint16 x) { if (QSysInfo::ByteOrder == QSysInfo::BigEndian) return x; - return (quint16)BYTE_SWAP2(x); + return quint16(BYTE_SWAP2(x)); } static quint32 _htonl(const quint32 x) { if (QSysInfo::ByteOrder == QSysInfo::BigEndian) return x; - return (quint32)BYTE_SWAP4(x); + return quint32(BYTE_SWAP4(x)); } static quint16 _ntohs(const char *in) @@ -106,10 +106,10 @@ int NetworkMessage::readMessage(QAbstractSocket* socket) const qint64 ret = socket->read(_buffer + _bufferPos, _bufferSize - _bufferPos); //qDebug() << "Read " << ret << " bytes"; if (ret < 0 || ret > (_bufferSize - _bufferPos)) { - qDebug("Socket read failed (TCP), return code %d", (int)ret); + qDebug("Socket read failed (TCP), return code %d", int(ret)); return NM_READ_FAILED; } - _bufferPos += (quint32)ret; + _bufferPos += quint32(ret); //qDebug() << "Buffer has now " << _bufferPos << " of " << _bufferSize << " bytes"; } if (_bufferSize == _bufferPos) { @@ -137,7 +137,7 @@ int NetworkMessage::readMessage(char* data, quint32 len) if (!this->parseHeader(data)) return NM_READ_FAILED; if (len != _bufferSize + HEADER_LEN) { - qDebug("UDP packet has wrong size. Is %d, expected %d", (int)_bufferSize, len - HEADER_LEN); + qDebug("UDP packet has wrong size. Is %d, expected %d", int(_bufferSize), len - HEADER_LEN); return NM_READ_FAILED; } return this->parseMessage(data + HEADER_LEN) ? NM_READ_OK : NM_READ_FAILED; @@ -202,7 +202,7 @@ bool NetworkMessage::writeMessage(QAbstractSocket * const socket) return true; if (ret < 0 || ret > (_bufferSize - _bufferPos)) return false; - _bufferPos += (quint32)ret; + _bufferPos += quint32(ret); if (_bufferPos == _bufferSize) { _bufferPos = 0; _mode = 4; @@ -241,11 +241,11 @@ void NetworkMessage::serializeMessage() for (QHash<QByteArray, QByteArray>::const_iterator it = _fields.begin(); it != _fields.end(); ++it) { const QByteArray &ba = it.key(); const QByteArray &val = it.value(); - quint16 keyLen = _htons((quint16)ba.size()); - quint16 valLen = _htons((quint16)val.size()); + quint16 keyLen = _htons(quint16(ba.size())); + quint16 valLen = _htons(quint16(val.size())); //qDebug() << "Adding to msg(" << ba.size() << "/" << val.size() << "): " << ba << " -> " << val; - buf.append((char*)&keyLen, 2); - buf.append((char*)&valLen, 2); + buf.append(reinterpret_cast<const char*>(&keyLen), 2); + buf.append(reinterpret_cast<const char*>(&valLen), 2); buf.append(ba); buf.append(val); } |