Drop Qt4, libgcrypt, qtmobility dependencies

This commit is contained in:
Fabio Bas 2016-05-11 12:03:20 +02:00
parent e3fb308ea1
commit bb5292aa8d
54 changed files with 96 additions and 818 deletions

View file

@ -45,13 +45,8 @@ SmtpClient *smtpClient;
void testRNG();
void testHash();
#if QT_VERSION < 0x050000
void myMessageOutput(QtMsgType type, const char *msg);
void myMessageOutput2(QtMsgType type, const char *msg);
#else
void myMessageOutput(QtMsgType type, const QMessageLogContext &, const QString &msg);
void myMessageOutput2(QtMsgType type, const QMessageLogContext &, const QString &msg);
#endif
/* Implementations */
@ -100,18 +95,6 @@ void testHash()
std::cerr << startTime.secsTo(endTime) << "secs" << std::endl;
}
#if QT_VERSION < 0x050000
void myMessageOutput(QtMsgType /*type*/, const char *msg)
{
logger->logMessage(msg);
}
void myMessageOutput2(QtMsgType /*type*/, const char *msg)
{
logger->logMessage(msg);
std::cerr << msg << std::endl;
}
#else
void myMessageOutput(QtMsgType /*type*/, const QMessageLogContext &, const QString &msg)
{
logger->logMessage(msg);
@ -122,7 +105,6 @@ void myMessageOutput2(QtMsgType /*type*/, const QMessageLogContext &, const QStr
logger->logMessage(msg);
std::cerr << msg.toStdString() << std::endl;
}
#endif
int main(int argc, char *argv[])
{
@ -141,11 +123,6 @@ int main(int argc, char *argv[])
qRegisterMetaType<QList<int> >("QList<int>");
#if QT_VERSION < 0x050000
// gone in Qt5, all source files _MUST_ be utf8-encoded
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#endif
configPath = SettingsCache::guessConfigurationPath(configPath);
qWarning() << "Using configuration file: " << configPath;
settingsCache = new SettingsCache(configPath);
@ -158,17 +135,10 @@ int main(int argc, char *argv[])
loggerThread->start();
QMetaObject::invokeMethod(logger, "startLog", Qt::BlockingQueuedConnection, Q_ARG(QString, settingsCache->value("server/logfile", QString("server.log")).toString()));
#if QT_VERSION < 0x050000
if (logToConsole)
qInstallMsgHandler(myMessageOutput);
else
qInstallMsgHandler(myMessageOutput2);
#else
if (logToConsole)
qInstallMessageHandler(myMessageOutput);
else
qInstallMessageHandler(myMessageOutput2);
#endif
signalhandler = new SignalHandler();
@ -193,11 +163,7 @@ int main(int argc, char *argv[])
std::cerr << "-------------------------" << std::endl;
std::cerr << "Server initialized." << std::endl;
#if QT_VERSION < 0x050000
qInstallMsgHandler(myMessageOutput);
#else
qInstallMessageHandler(myMessageOutput);
#endif
retval = app.exec();

View file

@ -1,44 +1,13 @@
#include "passwordhasher.h"
#if QT_VERSION < 0x050000
#include <stdio.h>
#include <string.h>
#include <gcrypt.h>
#endif
#include <QCryptographicHash>
#include "rng_sfmt.h"
void PasswordHasher::initialize()
{
#if QT_VERSION < 0x050000
// These calls are required by libgcrypt before we use any of its functions.
gcry_check_version(0);
gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
#endif
// dummy
}
#if QT_VERSION < 0x050000
QString PasswordHasher::computeHash(const QString &password, const QString &salt)
{
const int algo = GCRY_MD_SHA512;
const int rounds = 1000;
QByteArray passwordBuffer = (salt + password).toUtf8();
int hashLen = gcry_md_get_algo_dlen(algo);
char *hash = new char[hashLen], *tmp = new char[hashLen];
gcry_md_hash_buffer(algo, hash, passwordBuffer.data(), passwordBuffer.size());
for (int i = 1; i < rounds; ++i) {
memcpy(tmp, hash, hashLen);
gcry_md_hash_buffer(algo, hash, tmp, hashLen);
}
QString hashedPass = salt + QString(QByteArray(hash, hashLen).toBase64());
delete[] tmp;
delete[] hash;
return hashedPass;
}
#else
QString PasswordHasher::computeHash(const QString &password, const QString &salt)
{
QCryptographicHash::Algorithm algo = QCryptographicHash::Sha512;
@ -51,7 +20,6 @@ QString PasswordHasher::computeHash(const QString &password, const QString &salt
QString hashedPass = salt + QString(hash.toBase64());
return hashedPass;
}
#endif
QString PasswordHasher::generateRandomSalt(const int len)
{

View file

@ -81,11 +81,7 @@ Servatrice_GameServer::~Servatrice_GameServer()
}
}
#if QT_VERSION < 0x050000
void Servatrice_GameServer::incomingConnection(int socketDescriptor)
#else
void Servatrice_GameServer::incomingConnection(qintptr socketDescriptor)
#endif
{
// Determine connection pool with smallest client count
int minClientCount = -1;
@ -110,11 +106,7 @@ void Servatrice_GameServer::incomingConnection(qintptr socketDescriptor)
QMetaObject::invokeMethod(ssi, "initConnection", Qt::QueuedConnection, Q_ARG(int, socketDescriptor));
}
#if QT_VERSION < 0x050000
void Servatrice_IslServer::incomingConnection(int socketDescriptor)
#else
void Servatrice_IslServer::incomingConnection(qintptr socketDescriptor)
#endif
{
QThread *thread = new QThread;
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
@ -317,16 +309,13 @@ bool Servatrice::initServer()
if (!certFile.open(QIODevice::ReadOnly))
throw QString("Error opening certificate file: %1").arg(certFileName);
QSslCertificate cert(&certFile);
#if QT_VERSION < 0x050000
if (!cert.isValid())
throw(QString("Invalid certificate."));
#else
const QDateTime currentTime = QDateTime::currentDateTime();
if(currentTime < cert.effectiveDate() ||
currentTime > cert.expiryDate() ||
cert.isBlacklisted())
throw(QString("Invalid certificate."));
#endif
qDebug() << "Loading private key...";
QFile keyFile(keyFileName);
if (!keyFile.open(QIODevice::ReadOnly))

View file

@ -53,11 +53,7 @@ public:
Servatrice_GameServer(Servatrice *_server, int _numberPools, const QSqlDatabase &_sqlDatabase, QObject *parent = 0);
~Servatrice_GameServer();
protected:
#if QT_VERSION < 0x050000
void incomingConnection(int socketDescriptor);
#else
void incomingConnection(qintptr socketDescriptor);
#endif
};
class Servatrice_IslServer : public QTcpServer {
@ -70,11 +66,7 @@ public:
Servatrice_IslServer(Servatrice *_server, const QSslCertificate &_cert, const QSslKey &_privateKey, QObject *parent = 0)
: QTcpServer(parent), server(_server), cert(_cert), privateKey(_privateKey) { }
protected:
#if QT_VERSION < 0x050000
void incomingConnection(int socketDescriptor);
#else
void incomingConnection(qintptr socketDescriptor);
#endif
};
class ServerProperties {

View file

@ -1,11 +1,7 @@
#include "settingscache.h"
#include <QCoreApplication>
#include <QFile>
#if QT_VERSION >= 0x050000
#include <QStandardPaths>
#else
#include <QDesktopServices>
#endif
#include <QStandardPaths>
SettingsCache::SettingsCache(const QString & fileName, QSettings::Format format, QObject * parent)
:QSettings(fileName, format, parent)
@ -36,10 +32,6 @@ QString SettingsCache::guessConfigurationPath(QString & specificPath)
return guessFileName;
#endif
#if QT_VERSION >= 0x050000
guessFileName = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/" + fileName;
#else
guessFileName = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/" + fileName;
#endif
return guessFileName;
}

View file

@ -26,9 +26,6 @@
#include "qxthmac.h"
#include <QtGlobal>
#if QT_VERSION >= 0x040300
/*
\class QxtHmac
@ -207,5 +204,3 @@ bool QxtHmac::verify(const QByteArray& key, const QByteArray& hmac, const QByteA
d->ohash->addData(inner);
return hmac == d->ohash->result();
}
#endif

View file

@ -27,11 +27,6 @@
#define QXTHMAC_H
#include <QtGlobal>
#if QT_VERSION < 0x040300
# warning QxtHmac requires Qt 4.3.0 or greater
#else
#include <QCryptographicHash>
#include "qxtglobal.h"
@ -61,4 +56,3 @@ private:
};
#endif
#endif