mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Support Qt6, Min Qt5.8, Fix Win32, Fix Servatrice
Add lock around deleting arrows for commanding cards Add support for Qt6 w/ Backwards Qt5 Handle Qt5/6 cross compilation better Last cleanups caps matter Fix serv Prevent crash on 6.3.0 Linux & bump to 5.8 min Prevent out of bounds indexing Delete shutdown timer if it exists Fixup ticket comments, remove unneeded guards Try to add support for missing OSes Update .ci/release_template.md Update PR based on comments Update XML name after done and remove Hirsute Address local game crash Address comments from PR (again) Tests don't work on mac, will see if a problem on other OSes make soundengine more consistent across qt versions disable tests on distros that are covered by others Fix Oracle Crash due to bad memory access Update Oracle to use new Qt6 way of adding translations Add support for Qt5/Qt6 compiling of Cockatrice Remove unneeded calls to QtMath/cmath/math.h Update how we handle bitwise comparisons for enums with Tray Icon Change header guards to not duplicate function Leave comment & Fix Path for GHA Qt Update common/server.h Update cockatrice/src/window_main.cpp Rollback change on cmake module path for NSIS check docker image requirements add size limit to ccache put variables in quotes properly set build type on mac avoid names used in cmake fix up cmake module path cmake 3.10 does not recognize prepend Support Tests in FindQtRuntime set ccache size on non debug builds as well immediately return when removing non existing client handle incTxBytes with a signal instead don't set common link libraries in cockatrice/CMakeLists.txt add comments set macos qt version to 6 Try upgrading XCode versions to latest they can be supported on Ensure Qt gets linked add tmate so i can see what's going on Qt6 points two directories further down than Qt5 with regard to the top lib path, so we need to account for this Establish Plugins directory for Qt6 Establish TLS plugins for Qt6 services Minor change for release channel network manager Let windows build in parallel cores Wrong symbols Qt6 patch up for signal add missing qt6 package on deb builds boolean expressions are hard negative indexes should go to the end Intentionally fail cache move size checks to individual zone types Hardcode libs needed for building on Windows, as the regex was annoying Update wording use the --parallel option in all builds clean up the .ci scripts some more tweak fedora build add os parameter to compile.sh I don't really like this but it seems the easiest way I'd prefer if these types of quirks would live in the main configuration file, the yml fixup yml readd appended cache key to vcpkg step fix windows 32 quirk the json hash is already added to the key as well remove os parameter and clean up ci files set name_build.sh to output relative paths set backwards compatible version of xcode and qt on mac set QTDIR for mac builds on qt5 has no effect for qt6 export BUILD_DIR to name_build.sh merge mac build steps merge homebrew steps, set package suffix link qt5 remove brew link set qtdir to qt5 only compile.sh vars need to be empty not 0 fix sets manager search bar on qt 5.12/15 fix oracle subprocess errors being ignored on qt 5 clean up translation loading move en@source translation file so it will not get included in packages NOTE: this needs to be done at transifex as well! Use generator platform over osname Short circuit if not Win defined
This commit is contained in:
parent
accd5e4df7
commit
b02adccf87
114 changed files with 1925 additions and 1603 deletions
|
|
@ -41,11 +41,12 @@ if(APPLE)
|
|||
set(servatrice_SOURCES ${servatrice_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/resources/appicon.icns)
|
||||
ENDIF(APPLE)
|
||||
|
||||
# Qt5
|
||||
find_package(Qt5 COMPONENTS Network Sql WebSockets REQUIRED)
|
||||
set(SERVATRICE_QT_MODULES Qt5::Core Qt5::Network Qt5::Sql Qt5::WebSockets)
|
||||
IF(Qt6_FOUND)
|
||||
Qt6_ADD_RESOURCES(servatrice_RESOURCES_RCC ${servatrice_RESOURCES})
|
||||
ELSEIF(Qt5_FOUND)
|
||||
Qt5_ADD_RESOURCES(servatrice_RESOURCES_RCC ${servatrice_RESOURCES})
|
||||
ENDIF()
|
||||
|
||||
QT5_ADD_RESOURCES(servatrice_RESOURCES_RCC ${servatrice_RESOURCES})
|
||||
SET(QT_DONT_USE_QTGUI TRUE)
|
||||
|
||||
# Mysql connector
|
||||
|
|
@ -59,15 +60,15 @@ elseif(WIN32)
|
|||
SET(MYSQLCLIENT_DEFAULT_PATHS "C:\\Program Files\\MySQL\\MySQL Server 5.7\\lib" "C:\\Program Files (x86)\\MySQL\\MySQL Server 5.7\\lib")
|
||||
endif()
|
||||
|
||||
find_library(MYSQLCLIENT_LIBRARIES NAMES mysqlclient PATHS ${MYSQLCLIENT_DEFAULT_PATHS} PATH_SUFFIXES mysql mariadb)
|
||||
if(${MYSQLCLIENT_LIBRARIES} MATCHES "NOTFOUND")
|
||||
find_library(MYSQL_CLIENT_LIBRARIES NAMES mysqlclient PATHS ${MYSQLCLIENT_DEFAULT_PATHS} PATH_SUFFIXES mysql mariadb)
|
||||
if(${MYSQL_CLIENT_LIBRARIES} MATCHES "NOTFOUND")
|
||||
set(MYSQLCLIENT_FOUND FALSE CACHE INTERNAL "")
|
||||
MESSAGE(STATUS "Mysql connector NOT FOUND: servatrice won't be able to connect to a mysql server")
|
||||
unset(MYSQLCLIENT_LIBRARIES)
|
||||
MESSAGE(STATUS "MySQL connector NOT FOUND: Servatrice won't be able to connect to a MySQL server")
|
||||
unset(MYSQL_CLIENT_LIBRARIES)
|
||||
else()
|
||||
set(MYSQLCLIENT_FOUND TRUE CACHE INTERNAL "")
|
||||
get_filename_component(MYSQLCLIENT_LIBRARY_DIR ${MYSQLCLIENT_LIBRARIES} PATH)
|
||||
MESSAGE(STATUS "Mysql connector found at: ${MYSQLCLIENT_LIBRARY_DIR}")
|
||||
get_filename_component(MYSQLCLIENT_LIBRARY_DIR ${MYSQL_CLIENT_LIBRARIES} PATH)
|
||||
MESSAGE(STATUS "Found MySQL connector at: ${MYSQL_CLIENT_LIBRARIES}")
|
||||
endif()
|
||||
|
||||
# Declare path variables
|
||||
|
|
@ -83,9 +84,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
|
|||
# Build servatrice binary and link it
|
||||
ADD_EXECUTABLE(servatrice MACOSX_BUNDLE ${servatrice_SOURCES} ${servatrice_RESOURCES_RCC} ${servatrice_MOC_SRCS})
|
||||
|
||||
if(MSVC)
|
||||
TARGET_LINK_LIBRARIES(servatrice cockatrice_common Threads::Threads ${SERVATRICE_QT_MODULES} Qt5::WinMain)
|
||||
elseif(CMAKE_HOST_SYSTEM MATCHES "FreeBSD")
|
||||
if(CMAKE_HOST_SYSTEM MATCHES "FreeBSD")
|
||||
TARGET_LINK_LIBRARIES(servatrice cockatrice_common Threads::Threads ${SERVATRICE_QT_MODULES} ${LIBEXECINFO_LIBRARY})
|
||||
else()
|
||||
TARGET_LINK_LIBRARIES(servatrice cockatrice_common Threads::Threads ${SERVATRICE_QT_MODULES})
|
||||
|
|
@ -124,15 +123,15 @@ if(APPLE)
|
|||
# these needs to be relative to CMAKE_INSTALL_PREFIX
|
||||
set(plugin_dest_dir servatrice.app/Contents/Plugins)
|
||||
set(qtconf_dest_dir servatrice.app/Contents/Resources)
|
||||
get_filename_component(QT_LIBRARY_DIR "${QT_LIBRARY_DIR}/.." ABSOLUTE)
|
||||
|
||||
# qt5 plugins: platforms, sqldrivers/mysql
|
||||
# Qt plugins: platforms, sqldrivers/mysql, tls (Qt6)
|
||||
install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime
|
||||
FILES_MATCHING
|
||||
PATTERN "*.dSYM" EXCLUDE
|
||||
PATTERN "*_debug.dylib" EXCLUDE
|
||||
PATTERN "platforms/*.dylib"
|
||||
PATTERN "sqldrivers/libqsqlmysql*.dylib"
|
||||
PATTERN "tls/*.dylib"
|
||||
)
|
||||
|
||||
install(CODE "
|
||||
|
|
@ -157,10 +156,18 @@ if(WIN32)
|
|||
|
||||
install(DIRECTORY "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/${CMAKE_BUILD_TYPE}/" DESTINATION ./ FILES_MATCHING PATTERN "*.dll")
|
||||
|
||||
# qt5 plugins: platforms, sqldrivers/mysql
|
||||
install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime
|
||||
FILES_MATCHING REGEX "(platforms/.*|sqldrivers/qsqlmysql)\\.dll"
|
||||
REGEX ".*d\\.dll" EXCLUDE)
|
||||
# Qt plugins: platforms, sqldrivers, tls (Qt6)
|
||||
install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime FILES_MATCHING
|
||||
PATTERN "platforms/qdirect2d.dll"
|
||||
PATTERN "platforms/qminimal.dll"
|
||||
PATTERN "platforms/qoffscreen.dll"
|
||||
PATTERN "platforms/qwindows.dll"
|
||||
PATTERN "tls/qcertonlybackend.dll"
|
||||
PATTERN "tls/qopensslbackend.dll"
|
||||
PATTERN "tls/qschannelbackend.dll"
|
||||
PATTERN "sqldrivers/qsqlite.dll"
|
||||
PATTERN "sqldrivers/qsqlodbc.dll"
|
||||
PATTERN "sqldrivers/qsqlpsql.dll")
|
||||
|
||||
install(CODE "
|
||||
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths]
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@
|
|||
#include <QMetaType>
|
||||
#include <QTextCodec>
|
||||
#include <QtGlobal>
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <iostream>
|
||||
|
||||
RNG_Abstract *rng;
|
||||
|
|
@ -70,17 +69,17 @@ void testRNG()
|
|||
}
|
||||
for (int i = 0; i <= maxMax - min; ++i) {
|
||||
std::cerr << (min + i);
|
||||
for (int j = 0; j < numbers.size(); ++j) {
|
||||
if (i < numbers[j].size())
|
||||
std::cerr << "\t" << numbers[j][i];
|
||||
for (auto &number : numbers) {
|
||||
if (i < number.size())
|
||||
std::cerr << "\t" << number[i];
|
||||
else
|
||||
std::cerr << "\t";
|
||||
}
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
std::cerr << std::endl << "Chi^2 =";
|
||||
for (int j = 0; j < chisq.size(); ++j)
|
||||
std::cerr << "\t" << QString::number(chisq[j], 'f', 3).toStdString();
|
||||
for (double j : chisq)
|
||||
std::cerr << "\t" << QString::number(j, 'f', 3).toStdString();
|
||||
std::cerr << std::endl << "k =";
|
||||
for (int j = 0; j < chisq.size(); ++j)
|
||||
std::cerr << "\t" << (j - min + minMax);
|
||||
|
|
@ -112,9 +111,9 @@ void myMessageOutput2(QtMsgType /*type*/, const QMessageLogContext &, const QStr
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
app.setOrganizationName("Cockatrice");
|
||||
app.setApplicationName("Servatrice");
|
||||
app.setApplicationVersion(VERSION_STRING);
|
||||
QCoreApplication::setOrganizationName("Cockatrice");
|
||||
QCoreApplication::setApplicationName("Servatrice");
|
||||
QCoreApplication::setApplicationVersion(VERSION_STRING);
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.addHelpOption();
|
||||
|
|
@ -183,7 +182,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
smtpClient = new SmtpClient();
|
||||
|
||||
Servatrice *server = new Servatrice();
|
||||
auto *server = new Servatrice();
|
||||
QObject::connect(server, SIGNAL(destroyed()), &app, SLOT(quit()), Qt::QueuedConnection);
|
||||
int retval = 0;
|
||||
if (server->initServer()) {
|
||||
|
|
@ -192,7 +191,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
qInstallMessageHandler(myMessageOutput);
|
||||
|
||||
retval = app.exec();
|
||||
retval = QCoreApplication::exec();
|
||||
|
||||
std::cerr << "Server quit." << std::endl;
|
||||
std::cerr << "-------------------------" << std::endl;
|
||||
|
|
@ -210,5 +209,6 @@ int main(int argc, char *argv[])
|
|||
// Delete all global objects allocated by libprotobuf.
|
||||
google::protobuf::ShutdownProtobufLibrary();
|
||||
|
||||
QCoreApplication::quit();
|
||||
return retval;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ Servatrice_GameServer::~Servatrice_GameServer()
|
|||
QThread *poolThread = connectionPools[i]->thread();
|
||||
connectionPools[i]->deleteLater(); // pool destructor calls thread()->quit()
|
||||
poolThread->wait();
|
||||
poolThread->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -84,6 +85,7 @@ void Servatrice_GameServer::incomingConnection(qintptr socketDescriptor)
|
|||
Servatrice_ConnectionPool *pool = findLeastUsedConnectionPool();
|
||||
|
||||
auto ssi = new TcpServerSocketInterface(server, pool->getDatabaseInterface());
|
||||
connect(ssi, SIGNAL(incTxBytes), this, SLOT(incTxBytes));
|
||||
ssi->moveToThread(pool->thread());
|
||||
pool->addClient();
|
||||
connect(ssi, SIGNAL(destroyed()), pool, SLOT(removeClient()));
|
||||
|
|
@ -144,6 +146,7 @@ Servatrice_WebsocketGameServer::~Servatrice_WebsocketGameServer()
|
|||
QThread *poolThread = connectionPools[i]->thread();
|
||||
connectionPools[i]->deleteLater(); // pool destructor calls thread()->quit()
|
||||
poolThread->wait();
|
||||
poolThread->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -152,6 +155,7 @@ void Servatrice_WebsocketGameServer::onNewConnection()
|
|||
Servatrice_ConnectionPool *pool = findLeastUsedConnectionPool();
|
||||
|
||||
auto ssi = new WebsocketServerSocketInterface(server, pool->getDatabaseInterface());
|
||||
connect(ssi, SIGNAL(incTxBytes), this, SLOT(incTxBytes));
|
||||
/*
|
||||
* Due to a Qt limitation, websockets can't be moved to another thread.
|
||||
* This will hopefully change in Qt6 if QtWebSocket will be integrated in QtNetwork
|
||||
|
|
@ -195,7 +199,7 @@ void Servatrice_IslServer::incomingConnection(qintptr socketDescriptor)
|
|||
|
||||
Servatrice::Servatrice(QObject *parent)
|
||||
: Server(parent), authenticationMethod(AuthenticationNone), uptime(0), txBytes(0), rxBytes(0),
|
||||
shutdownTimer(nullptr), isFirstShutdownMessage(true)
|
||||
shutdownTimer(nullptr)
|
||||
{
|
||||
qRegisterMetaType<QSqlDatabase>("QSqlDatabase");
|
||||
}
|
||||
|
|
@ -204,21 +208,16 @@ Servatrice::~Servatrice()
|
|||
{
|
||||
gameServer->close();
|
||||
|
||||
// clients live in other threads, we need to lock them
|
||||
clientsLock.lockForRead();
|
||||
// we are destroying the clients outside their thread!
|
||||
for (auto *client : clients) {
|
||||
QMetaObject::invokeMethod(client, "prepareDestroy", Qt::QueuedConnection);
|
||||
}
|
||||
clientsLock.unlock();
|
||||
|
||||
// client destruction is asynchronous, wait for all clients to be gone
|
||||
for (;;) {
|
||||
QThread::usleep(10);
|
||||
QReadLocker locker(&clientsLock);
|
||||
if (clients.isEmpty())
|
||||
break;
|
||||
client->prepareDestroy();
|
||||
}
|
||||
|
||||
if (shutdownTimer) {
|
||||
shutdownTimer->deleteLater();
|
||||
}
|
||||
|
||||
servatriceDatabaseInterface->deleteLater();
|
||||
prepareDestroy();
|
||||
}
|
||||
|
||||
|
|
@ -559,7 +558,7 @@ void Servatrice::updateLoginMessage()
|
|||
}
|
||||
}
|
||||
|
||||
void Servatrice::setRequiredFeatures(const QString featureList)
|
||||
void Servatrice::setRequiredFeatures(const QString &featureList)
|
||||
{
|
||||
FeatureSet features;
|
||||
serverRequiredFeatureList.clear();
|
||||
|
|
@ -570,8 +569,9 @@ void Servatrice::setRequiredFeatures(const QString featureList)
|
|||
QStringList listReqFeatures = featureList.split(",", QString::SkipEmptyParts);
|
||||
#endif
|
||||
if (!listReqFeatures.isEmpty())
|
||||
foreach (QString reqFeature, listReqFeatures)
|
||||
for (const QString &reqFeature : listReqFeatures) {
|
||||
features.enableRequiredFeature(serverRequiredFeatureList, reqFeature);
|
||||
}
|
||||
|
||||
qDebug() << "Set required client features to:" << serverRequiredFeatureList;
|
||||
}
|
||||
|
|
@ -715,8 +715,9 @@ void Servatrice::shutdownTimeout()
|
|||
clientsLock.unlock();
|
||||
delete se;
|
||||
|
||||
if (!shutdownMinutes)
|
||||
if (!shutdownMinutes) {
|
||||
deleteLater();
|
||||
}
|
||||
}
|
||||
shutdownMinutes--;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,9 +96,9 @@ private:
|
|||
public:
|
||||
Servatrice_IslServer(Servatrice *_server,
|
||||
const QSslCertificate &_cert,
|
||||
const QSslKey &_privateKey,
|
||||
QSslKey _privateKey,
|
||||
QObject *parent = nullptr)
|
||||
: QTcpServer(parent), server(_server), cert(_cert), privateKey(_privateKey)
|
||||
: QTcpServer(parent), server(_server), cert(_cert), privateKey(std::move(_privateKey))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -143,7 +143,7 @@ private slots:
|
|||
void shutdownTimeout();
|
||||
|
||||
protected:
|
||||
void doSendIslMessage(const IslMessage &msg, int serverId) override;
|
||||
void doSendIslMessage(const IslMessage &msg, int islServerId) override;
|
||||
|
||||
private:
|
||||
enum DatabaseType
|
||||
|
|
@ -160,7 +160,6 @@ private:
|
|||
mutable QMutex loginMessageMutex;
|
||||
QString loginMessage;
|
||||
QString dbPrefix;
|
||||
QString requiredFeatures;
|
||||
QMap<QString, bool> serverRequiredFeatureList;
|
||||
QString officialWarnings;
|
||||
Servatrice_DatabaseInterface *servatriceDatabaseInterface;
|
||||
|
|
@ -173,7 +172,6 @@ private:
|
|||
int shutdownMinutes;
|
||||
int nextShutdownMessageMinutes;
|
||||
QTimer *shutdownTimer;
|
||||
bool isFirstShutdownMessage;
|
||||
|
||||
mutable QMutex serverListMutex;
|
||||
QList<ServerProperties> serverList;
|
||||
|
|
@ -203,7 +201,7 @@ private:
|
|||
public slots:
|
||||
void scheduleShutdown(const QString &reason, int minutes);
|
||||
void updateLoginMessage();
|
||||
void setRequiredFeatures(QString featureList);
|
||||
void setRequiredFeatures(const QString &featureList);
|
||||
|
||||
public:
|
||||
explicit Servatrice(QObject *parent = nullptr);
|
||||
|
|
@ -213,10 +211,6 @@ public:
|
|||
{
|
||||
return serverRequiredFeatureList;
|
||||
}
|
||||
QString getOfficialWarningsList() const
|
||||
{
|
||||
return officialWarnings;
|
||||
}
|
||||
QString getServerName() const;
|
||||
QString getLoginMessage() const override
|
||||
{
|
||||
|
|
@ -282,9 +276,9 @@ public:
|
|||
void incRxBytes(quint64 num);
|
||||
void addDatabaseInterface(QThread *thread, Servatrice_DatabaseInterface *databaseInterface);
|
||||
|
||||
bool islConnectionExists(int serverId) const;
|
||||
void addIslInterface(int serverId, IslInterface *interface);
|
||||
void removeIslInterface(int serverId);
|
||||
bool islConnectionExists(int islServerId) const;
|
||||
void addIslInterface(int islServerId, IslInterface *interface);
|
||||
void removeIslInterface(int islServerId);
|
||||
QReadWriteLock islLock;
|
||||
|
||||
QList<ServerProperties> getServerList() const;
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ private:
|
|||
int clientCount;
|
||||
|
||||
public:
|
||||
Servatrice_ConnectionPool(Servatrice_DatabaseInterface *_databaseInterface);
|
||||
~Servatrice_ConnectionPool();
|
||||
explicit Servatrice_ConnectionPool(Servatrice_DatabaseInterface *_databaseInterface);
|
||||
~Servatrice_ConnectionPool() override;
|
||||
|
||||
Servatrice_DatabaseInterface *getDatabaseInterface() const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -113,12 +113,13 @@ bool Servatrice_DatabaseInterface::checkSql()
|
|||
|
||||
QSqlQuery *Servatrice_DatabaseInterface::prepareQuery(const QString &queryText)
|
||||
{
|
||||
if (preparedStatements.contains(queryText))
|
||||
if (preparedStatements.contains(queryText)) {
|
||||
return preparedStatements.value(queryText);
|
||||
}
|
||||
|
||||
QString prefixedQueryText = queryText;
|
||||
prefixedQueryText.replace("{prefix}", server->getDbPrefix());
|
||||
QSqlQuery *query = new QSqlQuery(sqlDatabase);
|
||||
auto *query = new QSqlQuery(sqlDatabase);
|
||||
query->prepare(prefixedQueryText);
|
||||
|
||||
preparedStatements.insert(queryText, query);
|
||||
|
|
|
|||
|
|
@ -36,14 +36,14 @@ protected:
|
|||
const QString &clientId,
|
||||
QString &reasonStr,
|
||||
int &banSecondsLeft,
|
||||
bool passwordNeedsHash);
|
||||
bool passwordNeedsHash) override;
|
||||
|
||||
public slots:
|
||||
void initDatabase(const QSqlDatabase &_sqlDatabase);
|
||||
|
||||
public:
|
||||
Servatrice_DatabaseInterface(int _instanceId, Servatrice *_server);
|
||||
~Servatrice_DatabaseInterface();
|
||||
explicit Servatrice_DatabaseInterface(int _instanceId, Servatrice *_server);
|
||||
~Servatrice_DatabaseInterface() override;
|
||||
bool initDatabase(const QString &type,
|
||||
const QString &hostName,
|
||||
const QString &databaseName,
|
||||
|
|
@ -58,66 +58,66 @@ public:
|
|||
return sqlDatabase;
|
||||
}
|
||||
|
||||
bool activeUserExists(const QString &user);
|
||||
bool userExists(const QString &user);
|
||||
QString getUserSalt(const QString &user);
|
||||
bool activeUserExists(const QString &user) override;
|
||||
bool userExists(const QString &user) override;
|
||||
QString getUserSalt(const QString &user) override;
|
||||
int getUserIdInDB(const QString &name);
|
||||
QMap<QString, ServerInfo_User> getBuddyList(const QString &name);
|
||||
QMap<QString, ServerInfo_User> getIgnoreList(const QString &name);
|
||||
bool isInBuddyList(const QString &whoseList, const QString &who);
|
||||
bool isInIgnoreList(const QString &whoseList, const QString &who);
|
||||
ServerInfo_User getUserData(const QString &name, bool withId = false);
|
||||
QMap<QString, ServerInfo_User> getBuddyList(const QString &name) override;
|
||||
QMap<QString, ServerInfo_User> getIgnoreList(const QString &name) override;
|
||||
bool isInBuddyList(const QString &whoseList, const QString &who) override;
|
||||
bool isInIgnoreList(const QString &whoseList, const QString &who) override;
|
||||
ServerInfo_User getUserData(const QString &name, bool withId = false) override;
|
||||
void storeGameInformation(const QString &roomName,
|
||||
const QStringList &roomGameTypes,
|
||||
const ServerInfo_Game &gameInfo,
|
||||
const QSet<QString> &allPlayersEver,
|
||||
const QSet<QString> &allSpectatorsEver,
|
||||
const QList<GameReplay *> &replayList);
|
||||
DeckList *getDeckFromDatabase(int deckId, int userId);
|
||||
const QList<GameReplay *> &replayList) override;
|
||||
DeckList *getDeckFromDatabase(int deckId, int userId) override;
|
||||
|
||||
int getNextGameId();
|
||||
int getNextReplayId();
|
||||
int getActiveUserCount(QString connectionType = QString());
|
||||
int getNextGameId() override;
|
||||
int getNextReplayId() override;
|
||||
int getActiveUserCount(QString connectionType = QString()) override;
|
||||
|
||||
qint64 startSession(const QString &userName,
|
||||
const QString &address,
|
||||
const QString &clientId,
|
||||
const QString &connectionType);
|
||||
void endSession(qint64 sessionId);
|
||||
void clearSessionTables();
|
||||
void lockSessionTables();
|
||||
void unlockSessionTables();
|
||||
bool userSessionExists(const QString &userName);
|
||||
bool usernameIsValid(const QString &user, QString &error);
|
||||
const QString &connectionType) override;
|
||||
void endSession(qint64 sessionId) override;
|
||||
void clearSessionTables() override;
|
||||
void lockSessionTables() override;
|
||||
void unlockSessionTables() override;
|
||||
bool userSessionExists(const QString &userName) override;
|
||||
bool usernameIsValid(const QString &user, QString &error) override;
|
||||
bool checkUserIsBanned(const QString &ipAddress,
|
||||
const QString &userName,
|
||||
const QString &clientId,
|
||||
QString &banReason,
|
||||
int &banSecondsRemaining);
|
||||
int checkNumberOfUserAccounts(const QString &email);
|
||||
int &banSecondsRemaining) override;
|
||||
int checkNumberOfUserAccounts(const QString &email) override;
|
||||
bool registerUser(const QString &userName,
|
||||
const QString &realName,
|
||||
const QString &password,
|
||||
bool passwordNeedsHash,
|
||||
const QString &emailAddress,
|
||||
const QString &country,
|
||||
bool active = false);
|
||||
bool activateUser(const QString &userName, const QString &token);
|
||||
void updateUsersClientID(const QString &userName, const QString &userClientID);
|
||||
void updateUsersLastLoginData(const QString &userName, const QString &clientVersion);
|
||||
bool active = false) override;
|
||||
bool activateUser(const QString &userName, const QString &token) override;
|
||||
void updateUsersClientID(const QString &userName, const QString &userClientID) override;
|
||||
void updateUsersLastLoginData(const QString &userName, const QString &clientVersion) override;
|
||||
void logMessage(const int senderId,
|
||||
const QString &senderName,
|
||||
const QString &senderIp,
|
||||
const QString &logMessage,
|
||||
LogMessage_TargetType targetType,
|
||||
const int targetId,
|
||||
const QString &targetName);
|
||||
bool changeUserPassword(const QString &user, const QString &password, bool passwordNeedsHash);
|
||||
const QString &targetName) override;
|
||||
bool changeUserPassword(const QString &user, const QString &password, bool passwordNeedsHash) override;
|
||||
bool changeUserPassword(const QString &user,
|
||||
const QString &oldPassword,
|
||||
bool oldPasswordNeedsHash,
|
||||
const QString &newPassword,
|
||||
bool newPasswordNeedsHash);
|
||||
bool newPasswordNeedsHash) override;
|
||||
QList<ServerInfo_Ban> getUserBanHistory(const QString userName);
|
||||
bool
|
||||
addWarning(const QString userName, const QString adminName, const QString warningReason, const QString clientID);
|
||||
|
|
@ -133,7 +133,7 @@ public:
|
|||
int &range,
|
||||
int &maxresults);
|
||||
bool addForgotPassword(const QString &user);
|
||||
bool removeForgotPassword(const QString &user);
|
||||
bool removeForgotPassword(const QString &user) override;
|
||||
bool doesForgotPasswordExist(const QString &user);
|
||||
bool updateUserToken(const QString &token, const QString &user);
|
||||
bool validateTableColumnStringData(const QString &table,
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ void ServerLogger::startLog(const QString &logFileName)
|
|||
connect(this, SIGNAL(sigFlushBuffer()), this, SLOT(flushBuffer()), Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void ServerLogger::logMessage(QString message, void *caller)
|
||||
void ServerLogger::logMessage(const QString &message, void *caller)
|
||||
{
|
||||
if (!logFile)
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public:
|
|||
~ServerLogger();
|
||||
public slots:
|
||||
void startLog(const QString &logFileName);
|
||||
void logMessage(QString message, void *caller = 0);
|
||||
void logMessage(const QString &message, void *caller = 0);
|
||||
void rotateLogs();
|
||||
private slots:
|
||||
void flushBuffer();
|
||||
|
|
|
|||
|
|
@ -74,7 +74,6 @@
|
|||
#include <QSqlError>
|
||||
#include <QSqlQuery>
|
||||
#include <QString>
|
||||
#include <QtMath>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
|
|
@ -388,7 +387,7 @@ bool AbstractServerSocketInterface::deckListHelper(int folderId, ServerInfo_Deck
|
|||
newItem->set_name(query->value(1).toString().toStdString());
|
||||
|
||||
ServerInfo_DeckStorage_File *newFile = newItem->mutable_file();
|
||||
newFile->set_creation_time(query->value(2).toDateTime().toTime_t());
|
||||
newFile->set_creation_time(query->value(2).toDateTime().toSecsSinceEpoch());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -551,7 +550,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdDeckUpload(const Comman
|
|||
ServerInfo_DeckStorage_TreeItem *fileInfo = re->mutable_new_file();
|
||||
fileInfo->set_id(query->lastInsertId().toInt());
|
||||
fileInfo->set_name(deckName.toStdString());
|
||||
fileInfo->mutable_file()->set_creation_time(QDateTime::currentDateTime().toTime_t());
|
||||
fileInfo->mutable_file()->set_creation_time(QDateTime::currentDateTime().toSecsSinceEpoch());
|
||||
rc.setResponseExtension(re);
|
||||
} else if (cmd.has_deck_id()) {
|
||||
QSqlQuery *query =
|
||||
|
|
@ -570,7 +569,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdDeckUpload(const Comman
|
|||
ServerInfo_DeckStorage_TreeItem *fileInfo = re->mutable_new_file();
|
||||
fileInfo->set_id(cmd.deck_id());
|
||||
fileInfo->set_name(deckName.toStdString());
|
||||
fileInfo->mutable_file()->set_creation_time(QDateTime::currentDateTime().toTime_t());
|
||||
fileInfo->mutable_file()->set_creation_time(QDateTime::currentDateTime().toSecsSinceEpoch());
|
||||
rc.setResponseExtension(re);
|
||||
} else
|
||||
return Response::RespInvalidData;
|
||||
|
|
@ -619,8 +618,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdReplayList(const Comman
|
|||
const int gameId = query1->value(0).toInt();
|
||||
matchInfo->set_game_id(gameId);
|
||||
matchInfo->set_room_name(query1->value(2).toString().toStdString());
|
||||
const int timeStarted = query1->value(3).toDateTime().toTime_t();
|
||||
const int timeFinished = query1->value(4).toDateTime().toTime_t();
|
||||
const int timeStarted = query1->value(3).toDateTime().toSecsSinceEpoch();
|
||||
const int timeFinished = query1->value(4).toDateTime().toSecsSinceEpoch();
|
||||
matchInfo->set_time_started(timeStarted);
|
||||
matchInfo->set_length(timeFinished - timeStarted);
|
||||
matchInfo->set_game_name(query1->value(5).toString().toStdString());
|
||||
|
|
@ -977,7 +976,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdBanFromServer(const Com
|
|||
if (cmd.has_visible_reason())
|
||||
event.set_reason_str(visibleReason.toStdString());
|
||||
if (minutes)
|
||||
event.set_end_time(QDateTime::currentDateTime().addSecs(60 * minutes).toTime_t());
|
||||
event.set_end_time(QDateTime::currentDateTime().addSecs(60 * minutes).toSecsSinceEpoch());
|
||||
for (int i = 0; i < userList.size(); ++i) {
|
||||
SessionEvent *se = userList[i]->prepareSessionEvent(event);
|
||||
userList[i]->sendProtocolItem(*se);
|
||||
|
|
@ -1148,7 +1147,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
|
|||
Response_Register *re = new Response_Register;
|
||||
re->set_denied_reason_str(banReason.toStdString());
|
||||
if (banSecondsRemaining != 0)
|
||||
re->set_denied_end_time(QDateTime::currentDateTime().addSecs(banSecondsRemaining).toTime_t());
|
||||
re->set_denied_end_time(QDateTime::currentDateTime().addSecs(banSecondsRemaining).toSecsSinceEpoch());
|
||||
rc.setResponseExtension(re);
|
||||
return Response::RespUserIsBanned;
|
||||
}
|
||||
|
|
@ -1649,7 +1648,7 @@ bool AbstractServerSocketInterface::removeAdminFlagFromUser(const QString &userN
|
|||
Event_ConnectionClosed event;
|
||||
event.set_reason(Event_ConnectionClosed::DEMOTED);
|
||||
event.set_reason_str("Your moderator and/or judge status has been revoked.");
|
||||
event.set_end_time(QDateTime::currentDateTime().toTime_t());
|
||||
event.set_end_time(QDateTime::currentDateTime().toSecsSinceEpoch());
|
||||
|
||||
SessionEvent *se = user->prepareSessionEvent(event);
|
||||
user->sendProtocolItem(*se);
|
||||
|
|
@ -1765,7 +1764,7 @@ void TcpServerSocketInterface::flushOutputQueue()
|
|||
locker.relock();
|
||||
}
|
||||
locker.unlock();
|
||||
servatrice->incTxBytes(totalBytes);
|
||||
emit incTxBytes(totalBytes);
|
||||
// see above wrt mutex
|
||||
flushSocket();
|
||||
}
|
||||
|
|
@ -1859,7 +1858,7 @@ bool TcpServerSocketInterface::initTcpSession()
|
|||
WebsocketServerSocketInterface::WebsocketServerSocketInterface(Servatrice *_server,
|
||||
Servatrice_DatabaseInterface *_databaseInterface,
|
||||
QObject *parent)
|
||||
: AbstractServerSocketInterface(_server, _databaseInterface, parent)
|
||||
: AbstractServerSocketInterface(_server, _databaseInterface, parent), socket(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -1885,17 +1884,12 @@ void WebsocketServerSocketInterface::initConnection(void *_socket)
|
|||
address = socket->peerAddress();
|
||||
|
||||
QByteArray websocketIPHeader = settingsCache->value("server/web_socket_ip_header", "").toByteArray();
|
||||
if (websocketIPHeader.length() > 0) {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
|
||||
if (socket->request().hasRawHeader(websocketIPHeader)) {
|
||||
QString header(socket->request().rawHeader(websocketIPHeader));
|
||||
QHostAddress parsed(header);
|
||||
if (!parsed.isNull())
|
||||
address = parsed;
|
||||
if (websocketIPHeader.length() > 0 && socket->request().hasRawHeader(websocketIPHeader)) {
|
||||
QString header(socket->request().rawHeader(websocketIPHeader));
|
||||
QHostAddress parsed(header);
|
||||
if (!parsed.isNull()) {
|
||||
address = parsed;
|
||||
}
|
||||
#else
|
||||
logger->logMessage(QString("Reading the websocket IP header is unsupported on this version of QT."));
|
||||
#endif
|
||||
}
|
||||
|
||||
connect(socket, SIGNAL(binaryMessageReceived(const QByteArray &)), this,
|
||||
|
|
@ -1905,7 +1899,7 @@ void WebsocketServerSocketInterface::initConnection(void *_socket)
|
|||
connect(socket, SIGNAL(disconnected()), this, SLOT(catchSocketDisconnected()));
|
||||
|
||||
// Add this object to the server's list of connections before it can receive socket events.
|
||||
// Otherwise, in case a of a socket error, it could be removed from the list before it is added.
|
||||
// Otherwise, in case of a socket error, it could be removed from the list before it is added.
|
||||
server->addClient(this);
|
||||
|
||||
logger->logMessage(
|
||||
|
|
@ -1949,7 +1943,7 @@ void WebsocketServerSocketInterface::flushOutputQueue()
|
|||
if (outputQueue.isEmpty())
|
||||
return;
|
||||
|
||||
int totalBytes = 0;
|
||||
qint64 totalBytes = 0;
|
||||
while (!outputQueue.isEmpty()) {
|
||||
ServerMessage item = outputQueue.takeFirst();
|
||||
locker.unlock();
|
||||
|
|
@ -1969,7 +1963,7 @@ void WebsocketServerSocketInterface::flushOutputQueue()
|
|||
locker.relock();
|
||||
}
|
||||
locker.unlock();
|
||||
servatrice->incTxBytes(totalBytes);
|
||||
emit incTxBytes(totalBytes);
|
||||
// see above wrt mutex
|
||||
flushSocket();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ protected slots:
|
|||
virtual void flushOutputQueue() = 0;
|
||||
signals:
|
||||
void outputQueueChanged();
|
||||
void incTxBytes(qint64 amount);
|
||||
|
||||
protected:
|
||||
void logDebugMessage(const QString &message);
|
||||
|
|
|
|||
|
|
@ -45,6 +45,6 @@ QString SettingsCache::guessConfigurationPath()
|
|||
return guessFileName;
|
||||
#endif
|
||||
|
||||
guessFileName = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/" + fileName;
|
||||
guessFileName = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/" + fileName;
|
||||
return guessFileName;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,9 +26,12 @@
|
|||
#define QXTMAIL_P_H
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QTextCodec>
|
||||
|
||||
#define QXT_MUST_QP(x) (x < char(32) || x > char(126) || x == '=' || x == '?')
|
||||
QByteArray qxt_fold_mime_header(const QString& key, const QString& value, QTextCodec* latin1,
|
||||
const QByteArray& prefix = QByteArray());
|
||||
QByteArray qxt_fold_mime_header(const QString &key,
|
||||
const QString &value,
|
||||
QTextCodec *latin1,
|
||||
const QByteArray &prefix = QByteArray());
|
||||
|
||||
#endif // QXTMAIL_P_H
|
||||
|
|
|
|||
|
|
@ -379,6 +379,8 @@ QByteArray QxtMailMessage::rfc2822() const
|
|||
line = line + ' ' + word;
|
||||
word = "";
|
||||
}
|
||||
if (line.isEmpty())
|
||||
continue;
|
||||
if (line[0] == '.')
|
||||
rv += ".";
|
||||
rv += line + "\r\n";
|
||||
|
|
|
|||
|
|
@ -23,39 +23,44 @@
|
|||
**
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/*!
|
||||
* \class QxtSmtp
|
||||
* \inmodule QxtNetwork
|
||||
* \brief The QxtSmtp class implements the SMTP protocol for sending email
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "qxtsmtp.h"
|
||||
#include "qxtsmtp_p.h"
|
||||
|
||||
#include "qxthmac.h"
|
||||
#include <QStringList>
|
||||
#include <QTcpSocket>
|
||||
#include "qxtsmtp_p.h"
|
||||
|
||||
#include <QNetworkInterface>
|
||||
#include <QSslSocket>
|
||||
#include <QStringList>
|
||||
#include <QTcpSocket>
|
||||
|
||||
QxtSmtpPrivate::QxtSmtpPrivate() : QObject(0)
|
||||
{
|
||||
// empty ctor
|
||||
}
|
||||
|
||||
QxtSmtp::QxtSmtp(QObject* parent) : QObject(parent)
|
||||
QxtSmtp::QxtSmtp(QObject *parent) : QObject(parent)
|
||||
{
|
||||
QXT_INIT_PRIVATE(QxtSmtp);
|
||||
qxt_d().state = QxtSmtpPrivate::Disconnected;
|
||||
qxt_d().nextID = 0;
|
||||
qxt_d().socket = new QSslSocket(this);
|
||||
QObject::connect(socket(), SIGNAL(encrypted()), this, SIGNAL(encrypted()));
|
||||
//QObject::connect(socket(), SIGNAL(encrypted()), &qxt_d(), SLOT(ehlo()));
|
||||
// QObject::connect(socket(), SIGNAL(encrypted()), &qxt_d(), SLOT(ehlo()));
|
||||
QObject::connect(socket(), SIGNAL(connected()), this, SIGNAL(connected()));
|
||||
QObject::connect(socket(), SIGNAL(disconnected()), this, SIGNAL(disconnected()));
|
||||
QObject::connect(socket(), SIGNAL(error(QAbstractSocket::SocketError)), &qxt_d(), SLOT(socketError(QAbstractSocket::SocketError)));
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
QObject::connect(socket(), SIGNAL(errorOccurred(QAbstractSocket::SocketError)), &qxt_d(),
|
||||
SLOT(socketError(QAbstractSocket::SocketError)));
|
||||
#else
|
||||
QObject::connect(socket(), SIGNAL(error(QAbstractSocket::SocketError)), &qxt_d(),
|
||||
SLOT(socketError(QAbstractSocket::SocketError)));
|
||||
#endif
|
||||
QObject::connect(this, SIGNAL(authenticated()), &qxt_d(), SLOT(sendNext()));
|
||||
QObject::connect(socket(), SIGNAL(readyRead()), &qxt_d(), SLOT(socketRead()));
|
||||
}
|
||||
|
|
@ -65,7 +70,7 @@ QByteArray QxtSmtp::username() const
|
|||
return qxt_d().username;
|
||||
}
|
||||
|
||||
void QxtSmtp::setUsername(const QByteArray& username)
|
||||
void QxtSmtp::setUsername(const QByteArray &username)
|
||||
{
|
||||
qxt_d().username = username;
|
||||
}
|
||||
|
|
@ -75,12 +80,12 @@ QByteArray QxtSmtp::password() const
|
|||
return qxt_d().password;
|
||||
}
|
||||
|
||||
void QxtSmtp::setPassword(const QByteArray& password)
|
||||
void QxtSmtp::setPassword(const QByteArray &password)
|
||||
{
|
||||
qxt_d().password = password;
|
||||
}
|
||||
|
||||
int QxtSmtp::send(const QxtMailMessage& message)
|
||||
int QxtSmtp::send(const QxtMailMessage &message)
|
||||
{
|
||||
int messageID = ++qxt_d().nextID;
|
||||
qxt_d().pending.append(qMakePair(messageID, message));
|
||||
|
|
@ -94,19 +99,19 @@ int QxtSmtp::pendingMessages() const
|
|||
return qxt_d().pending.count();
|
||||
}
|
||||
|
||||
QTcpSocket* QxtSmtp::socket() const
|
||||
QTcpSocket *QxtSmtp::socket() const
|
||||
{
|
||||
return qxt_d().socket;
|
||||
}
|
||||
|
||||
void QxtSmtp::connectToHost(const QString& hostName, quint16 port)
|
||||
void QxtSmtp::connectToHost(const QString &hostName, quint16 port)
|
||||
{
|
||||
qxt_d().useSecure = false;
|
||||
qxt_d().state = QxtSmtpPrivate::StartState;
|
||||
socket()->connectToHost(hostName, port);
|
||||
}
|
||||
|
||||
void QxtSmtp::connectToHost(const QHostAddress& address, quint16 port)
|
||||
void QxtSmtp::connectToHost(const QHostAddress &address, quint16 port)
|
||||
{
|
||||
connectToHost(address.toString(), port);
|
||||
}
|
||||
|
|
@ -126,157 +131,141 @@ void QxtSmtp::setStartTlsDisabled(bool disable)
|
|||
qxt_d().disableStartTLS = disable;
|
||||
}
|
||||
|
||||
QSslSocket* QxtSmtp::sslSocket() const
|
||||
QSslSocket *QxtSmtp::sslSocket() const
|
||||
{
|
||||
return qxt_d().socket;
|
||||
}
|
||||
|
||||
void QxtSmtp::connectToSecureHost(const QString& hostName, quint16 port)
|
||||
void QxtSmtp::connectToSecureHost(const QString &hostName, quint16 port)
|
||||
{
|
||||
qxt_d().useSecure = true;
|
||||
qxt_d().state = QxtSmtpPrivate::StartState;
|
||||
sslSocket()->connectToHostEncrypted(hostName, port);
|
||||
}
|
||||
|
||||
void QxtSmtp::connectToSecureHost(const QHostAddress& address, quint16 port)
|
||||
void QxtSmtp::connectToSecureHost(const QHostAddress &address, quint16 port)
|
||||
{
|
||||
connectToSecureHost(address.toString(), port);
|
||||
}
|
||||
|
||||
bool QxtSmtp::hasExtension(const QString& extension)
|
||||
bool QxtSmtp::hasExtension(const QString &extension)
|
||||
{
|
||||
return qxt_d().extensions.contains(extension);
|
||||
}
|
||||
|
||||
QString QxtSmtp::extensionData(const QString& extension)
|
||||
QString QxtSmtp::extensionData(const QString &extension)
|
||||
{
|
||||
return qxt_d().extensions[extension];
|
||||
}
|
||||
|
||||
void QxtSmtpPrivate::socketError(QAbstractSocket::SocketError err)
|
||||
{
|
||||
if (err == QAbstractSocket::SslHandshakeFailedError)
|
||||
{
|
||||
if (err == QAbstractSocket::SslHandshakeFailedError) {
|
||||
emit qxt_p().encryptionFailed();
|
||||
emit qxt_p().encryptionFailed( socket->errorString().toLatin1() );
|
||||
}
|
||||
else if (state == StartState)
|
||||
{
|
||||
emit qxt_p().encryptionFailed(socket->errorString().toLatin1());
|
||||
} else if (state == StartState) {
|
||||
emit qxt_p().connectionFailed();
|
||||
emit qxt_p().connectionFailed( socket->errorString().toLatin1() );
|
||||
emit qxt_p().connectionFailed(socket->errorString().toLatin1());
|
||||
}
|
||||
}
|
||||
|
||||
void QxtSmtpPrivate::socketRead()
|
||||
{
|
||||
buffer += socket->readAll();
|
||||
while (true)
|
||||
{
|
||||
while (true) {
|
||||
int pos = buffer.indexOf("\r\n");
|
||||
if (pos < 0) return;
|
||||
if (pos < 0)
|
||||
return;
|
||||
QByteArray line = buffer.left(pos);
|
||||
buffer = buffer.mid(pos + 2);
|
||||
QByteArray code = line.left(3);
|
||||
switch (state)
|
||||
{
|
||||
case StartState:
|
||||
if (code[0] != '2')
|
||||
{
|
||||
socket->disconnectFromHost();
|
||||
}
|
||||
else
|
||||
{
|
||||
ehlo();
|
||||
}
|
||||
break;
|
||||
case HeloSent:
|
||||
case EhloSent:
|
||||
case EhloGreetReceived:
|
||||
parseEhlo(code, (line[3] != ' '), line.mid(4));
|
||||
break;
|
||||
case StartTLSSent:
|
||||
if (code == "220")
|
||||
{
|
||||
socket->startClientEncryption();
|
||||
ehlo();
|
||||
}
|
||||
else
|
||||
{
|
||||
authenticate();
|
||||
}
|
||||
break;
|
||||
case AuthRequestSent:
|
||||
case AuthUsernameSent:
|
||||
if (authType == AuthPlain) authPlain();
|
||||
else if (authType == AuthLogin) authLogin();
|
||||
else authCramMD5(line.mid(4));
|
||||
break;
|
||||
case AuthSent:
|
||||
if (code[0] == '2')
|
||||
{
|
||||
state = Authenticated;
|
||||
emit qxt_p().authenticated();
|
||||
}
|
||||
else
|
||||
{
|
||||
state = Disconnected;
|
||||
emit qxt_p().authenticationFailed();
|
||||
emit qxt_p().authenticationFailed( line );
|
||||
emit socket->disconnectFromHost();
|
||||
}
|
||||
break;
|
||||
case MailToSent:
|
||||
case RcptAckPending:
|
||||
if (code[0] != '2') {
|
||||
emit qxt_p().mailFailed( pending.first().first, code.toInt() );
|
||||
emit qxt_p().mailFailed(pending.first().first, code.toInt(), line);
|
||||
// pending.removeFirst();
|
||||
// DO NOT remove it, the body sent state needs this message to assigned the next mail failed message that will
|
||||
// the sendNext
|
||||
// a reset will be sent to clear things out
|
||||
switch (state) {
|
||||
case StartState:
|
||||
if (code[0] != '2') {
|
||||
socket->disconnectFromHost();
|
||||
} else {
|
||||
ehlo();
|
||||
}
|
||||
break;
|
||||
case HeloSent:
|
||||
case EhloSent:
|
||||
case EhloGreetReceived:
|
||||
parseEhlo(code, (line[3] != ' '), line.mid(4));
|
||||
break;
|
||||
case StartTLSSent:
|
||||
if (code == "220") {
|
||||
socket->startClientEncryption();
|
||||
ehlo();
|
||||
} else {
|
||||
authenticate();
|
||||
}
|
||||
break;
|
||||
case AuthRequestSent:
|
||||
case AuthUsernameSent:
|
||||
if (authType == AuthPlain)
|
||||
authPlain();
|
||||
else if (authType == AuthLogin)
|
||||
authLogin();
|
||||
else
|
||||
authCramMD5(line.mid(4));
|
||||
break;
|
||||
case AuthSent:
|
||||
if (code[0] == '2') {
|
||||
state = Authenticated;
|
||||
emit qxt_p().authenticated();
|
||||
} else {
|
||||
state = Disconnected;
|
||||
emit qxt_p().authenticationFailed();
|
||||
emit qxt_p().authenticationFailed(line);
|
||||
emit socket->disconnectFromHost();
|
||||
}
|
||||
break;
|
||||
case MailToSent:
|
||||
case RcptAckPending:
|
||||
if (code[0] != '2') {
|
||||
emit qxt_p().mailFailed(pending.first().first, code.toInt());
|
||||
emit qxt_p().mailFailed(pending.first().first, code.toInt(), line);
|
||||
// pending.removeFirst();
|
||||
// DO NOT remove it, the body sent state needs this message to assigned the next mail failed message
|
||||
// that will the sendNext a reset will be sent to clear things out
|
||||
sendNext();
|
||||
state = BodySent;
|
||||
} else
|
||||
sendNextRcpt(code, line);
|
||||
break;
|
||||
case SendingBody:
|
||||
sendBody(code, line);
|
||||
break;
|
||||
case BodySent:
|
||||
if (pending.count()) {
|
||||
// if you removeFirst in RcpActpending/MailToSent on an error, and the queue is now empty,
|
||||
// you will get into this state and then crash because no check is done. CHeck added but shouldnt
|
||||
// be necessary since I commented out the removeFirst
|
||||
if (code[0] != '2') {
|
||||
emit qxt_p().mailFailed(pending.first().first, code.toInt());
|
||||
emit qxt_p().mailFailed(pending.first().first, code.toInt(), line);
|
||||
} else
|
||||
emit qxt_p().mailSent(pending.first().first);
|
||||
pending.removeFirst();
|
||||
}
|
||||
sendNext();
|
||||
state = BodySent;
|
||||
}
|
||||
else
|
||||
sendNextRcpt(code, line);
|
||||
break;
|
||||
case SendingBody:
|
||||
sendBody(code, line);
|
||||
break;
|
||||
case BodySent:
|
||||
if ( pending.count() )
|
||||
{
|
||||
// if you removeFirst in RcpActpending/MailToSent on an error, and the queue is now empty,
|
||||
// you will get into this state and then crash because no check is done. CHeck added but shouldnt
|
||||
// be necessary since I commented out the removeFirst
|
||||
if (code[0] != '2')
|
||||
{
|
||||
emit qxt_p().mailFailed(pending.first().first, code.toInt() );
|
||||
emit qxt_p().mailFailed(pending.first().first, code.toInt(), line);
|
||||
}
|
||||
else
|
||||
emit qxt_p().mailSent(pending.first().first);
|
||||
pending.removeFirst();
|
||||
}
|
||||
sendNext();
|
||||
break;
|
||||
case Resetting:
|
||||
if (code[0] != '2') {
|
||||
emit qxt_p().connectionFailed();
|
||||
emit qxt_p().connectionFailed( line );
|
||||
}
|
||||
else {
|
||||
state = Waiting;
|
||||
sendNext();
|
||||
}
|
||||
break;
|
||||
case Disconnected:
|
||||
case EhloExtensionsReceived:
|
||||
case EhloDone:
|
||||
case Authenticated:
|
||||
case Waiting:
|
||||
// only to make compiler happy
|
||||
break;
|
||||
break;
|
||||
case Resetting:
|
||||
if (code[0] != '2') {
|
||||
emit qxt_p().connectionFailed();
|
||||
emit qxt_p().connectionFailed(line);
|
||||
} else {
|
||||
state = Waiting;
|
||||
sendNext();
|
||||
}
|
||||
break;
|
||||
case Disconnected:
|
||||
case EhloExtensionsReceived:
|
||||
case EhloDone:
|
||||
case Authenticated:
|
||||
case Waiting:
|
||||
// only to make compiler happy
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -284,8 +273,7 @@ void QxtSmtpPrivate::socketRead()
|
|||
void QxtSmtpPrivate::ehlo()
|
||||
{
|
||||
QByteArray address = "127.0.0.1";
|
||||
foreach(const QHostAddress& addr, QNetworkInterface::allAddresses())
|
||||
{
|
||||
foreach (const QHostAddress &addr, QNetworkInterface::allAddresses()) {
|
||||
if (addr == QHostAddress::LocalHost || addr == QHostAddress::LocalHostIPv6)
|
||||
continue;
|
||||
address = addr.toString().toLatin1();
|
||||
|
|
@ -296,53 +284,40 @@ void QxtSmtpPrivate::ehlo()
|
|||
state = EhloSent;
|
||||
}
|
||||
|
||||
void QxtSmtpPrivate::parseEhlo(const QByteArray& code, bool cont, const QString& line)
|
||||
void QxtSmtpPrivate::parseEhlo(const QByteArray &code, bool cont, const QString &line)
|
||||
{
|
||||
if (code != "250")
|
||||
{
|
||||
if (code != "250") {
|
||||
// error!
|
||||
if (state != HeloSent)
|
||||
{
|
||||
if (state != HeloSent) {
|
||||
// maybe let's try HELO
|
||||
socket->write("helo\r\n");
|
||||
state = HeloSent;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// nope
|
||||
socket->write("QUIT\r\n");
|
||||
socket->flush();
|
||||
socket->disconnectFromHost();
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (state != EhloGreetReceived)
|
||||
{
|
||||
if (!cont)
|
||||
{
|
||||
} else if (state != EhloGreetReceived) {
|
||||
if (!cont) {
|
||||
// greeting only, no extensions
|
||||
state = EhloDone;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// greeting followed by extensions
|
||||
state = EhloGreetReceived;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
extensions[line.section(' ', 0, 0).toUpper()] = line.section(' ', 1);
|
||||
if (!cont)
|
||||
state = EhloDone;
|
||||
}
|
||||
if (state != EhloDone) return;
|
||||
if (extensions.contains("STARTTLS") && !disableStartTLS)
|
||||
{
|
||||
if (state != EhloDone)
|
||||
return;
|
||||
if (extensions.contains("STARTTLS") && !disableStartTLS) {
|
||||
startTLS();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
authenticate();
|
||||
}
|
||||
}
|
||||
|
|
@ -355,48 +330,35 @@ void QxtSmtpPrivate::startTLS()
|
|||
|
||||
void QxtSmtpPrivate::authenticate()
|
||||
{
|
||||
if (!extensions.contains("AUTH") || username.isEmpty() || password.isEmpty())
|
||||
{
|
||||
if (!extensions.contains("AUTH") || username.isEmpty() || password.isEmpty()) {
|
||||
state = Authenticated;
|
||||
emit qxt_p().authenticated();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
QStringList auth = extensions["AUTH"].toUpper().split(' ', Qt::SkipEmptyParts);
|
||||
#else
|
||||
QStringList auth = extensions["AUTH"].toUpper().split(' ', QString::SkipEmptyParts);
|
||||
#endif
|
||||
if (auth.contains("CRAM-MD5"))
|
||||
{
|
||||
if (auth.contains("CRAM-MD5")) {
|
||||
authCramMD5();
|
||||
}
|
||||
else if (auth.contains("PLAIN"))
|
||||
{
|
||||
} else if (auth.contains("PLAIN")) {
|
||||
authPlain();
|
||||
}
|
||||
else if (auth.contains("LOGIN"))
|
||||
{
|
||||
} else if (auth.contains("LOGIN")) {
|
||||
authLogin();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
state = Authenticated;
|
||||
emit qxt_p().authenticated();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QxtSmtpPrivate::authCramMD5(const QByteArray& challenge)
|
||||
void QxtSmtpPrivate::authCramMD5(const QByteArray &challenge)
|
||||
{
|
||||
if (state != AuthRequestSent)
|
||||
{
|
||||
if (state != AuthRequestSent) {
|
||||
socket->write("auth cram-md5\r\n");
|
||||
authType = AuthCramMD5;
|
||||
state = AuthRequestSent;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
QxtHmac hmac(QCryptographicHash::Md5);
|
||||
hmac.setKey(password);
|
||||
hmac.addData(QByteArray::fromBase64(challenge));
|
||||
|
|
@ -408,14 +370,11 @@ void QxtSmtpPrivate::authCramMD5(const QByteArray& challenge)
|
|||
|
||||
void QxtSmtpPrivate::authPlain()
|
||||
{
|
||||
if (state != AuthRequestSent)
|
||||
{
|
||||
if (state != AuthRequestSent) {
|
||||
socket->write("auth plain\r\n");
|
||||
authType = AuthPlain;
|
||||
state = AuthRequestSent;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
QByteArray auth;
|
||||
auth += '\0';
|
||||
auth += username;
|
||||
|
|
@ -428,60 +387,44 @@ void QxtSmtpPrivate::authPlain()
|
|||
|
||||
void QxtSmtpPrivate::authLogin()
|
||||
{
|
||||
if (state != AuthRequestSent && state != AuthUsernameSent)
|
||||
{
|
||||
if (state != AuthRequestSent && state != AuthUsernameSent) {
|
||||
socket->write("auth login\r\n");
|
||||
authType = AuthLogin;
|
||||
state = AuthRequestSent;
|
||||
}
|
||||
else if (state == AuthRequestSent)
|
||||
{
|
||||
} else if (state == AuthRequestSent) {
|
||||
socket->write(username.toBase64() + "\r\n");
|
||||
state = AuthUsernameSent;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
socket->write(password.toBase64() + "\r\n");
|
||||
state = AuthSent;
|
||||
}
|
||||
}
|
||||
|
||||
static QByteArray qxt_extract_address(const QString& address)
|
||||
static QByteArray qxt_extract_address(const QString &address)
|
||||
{
|
||||
int parenDepth = 0;
|
||||
int addrStart = -1;
|
||||
bool inQuote = false;
|
||||
int ct = address.length();
|
||||
|
||||
for (int i = 0; i < ct; i++)
|
||||
{
|
||||
for (int i = 0; i < ct; i++) {
|
||||
QChar ch = address[i];
|
||||
if (inQuote)
|
||||
{
|
||||
if (inQuote) {
|
||||
if (ch == '"')
|
||||
inQuote = false;
|
||||
}
|
||||
else if (addrStart != -1)
|
||||
{
|
||||
} else if (addrStart != -1) {
|
||||
if (ch == '>')
|
||||
return address.mid(addrStart, (i - addrStart)).toLatin1();
|
||||
}
|
||||
else if (ch == '(')
|
||||
{
|
||||
} else if (ch == '(') {
|
||||
parenDepth++;
|
||||
}
|
||||
else if (ch == ')')
|
||||
{
|
||||
} else if (ch == ')') {
|
||||
parenDepth--;
|
||||
if (parenDepth < 0) parenDepth = 0;
|
||||
}
|
||||
else if (ch == '"')
|
||||
{
|
||||
if (parenDepth < 0)
|
||||
parenDepth = 0;
|
||||
} else if (ch == '"') {
|
||||
if (parenDepth == 0)
|
||||
inQuote = true;
|
||||
}
|
||||
else if (ch == '<')
|
||||
{
|
||||
} else if (ch == '<') {
|
||||
if (!inQuote && parenDepth == 0)
|
||||
addrStart = i + 1;
|
||||
}
|
||||
|
|
@ -491,35 +434,31 @@ static QByteArray qxt_extract_address(const QString& address)
|
|||
|
||||
void QxtSmtpPrivate::sendNext()
|
||||
{
|
||||
if (state == Disconnected)
|
||||
{
|
||||
if (state == Disconnected) {
|
||||
// leave the mail in the queue if not ready to send
|
||||
return;
|
||||
}
|
||||
|
||||
if (pending.isEmpty())
|
||||
{
|
||||
if (pending.isEmpty()) {
|
||||
// if there are no additional mails to send, finish up
|
||||
state = Waiting;
|
||||
emit qxt_p().finished();
|
||||
return;
|
||||
}
|
||||
|
||||
if(state != Waiting) {
|
||||
if (state != Waiting) {
|
||||
state = Resetting;
|
||||
socket->write("rset\r\n");
|
||||
return;
|
||||
}
|
||||
const QxtMailMessage& msg = pending.first().second;
|
||||
const QxtMailMessage &msg = pending.first().second;
|
||||
rcptNumber = rcptAck = mailAck = 0;
|
||||
recipients = msg.recipients(QxtMailMessage::To) +
|
||||
msg.recipients(QxtMailMessage::Cc) +
|
||||
msg.recipients(QxtMailMessage::Bcc);
|
||||
if (recipients.count() == 0)
|
||||
{
|
||||
recipients =
|
||||
msg.recipients(QxtMailMessage::To) + msg.recipients(QxtMailMessage::Cc) + msg.recipients(QxtMailMessage::Bcc);
|
||||
if (recipients.count() == 0) {
|
||||
// can't send an e-mail with no recipients
|
||||
emit qxt_p().mailFailed(pending.first().first, QxtSmtp::NoRecipients );
|
||||
emit qxt_p().mailFailed(pending.first().first, QxtSmtp::NoRecipients, QByteArray( "e-mail has no recipients" ) );
|
||||
emit qxt_p().mailFailed(pending.first().first, QxtSmtp::NoRecipients);
|
||||
emit qxt_p().mailFailed(pending.first().first, QxtSmtp::NoRecipients, QByteArray("e-mail has no recipients"));
|
||||
pending.removeFirst();
|
||||
sendNext();
|
||||
return;
|
||||
|
|
@ -528,87 +467,67 @@ void QxtSmtpPrivate::sendNext()
|
|||
// interprets any string starting with an uppercase R as a request
|
||||
// to renegotiate the SSL connection.
|
||||
socket->write("mail from:<" + qxt_extract_address(msg.sender()) + ">\r\n");
|
||||
if (extensions.contains("PIPELINING")) // almost all do nowadays
|
||||
if (extensions.contains("PIPELINING")) // almost all do nowadays
|
||||
{
|
||||
foreach(const QString& rcpt, recipients)
|
||||
{
|
||||
foreach (const QString &rcpt, recipients) {
|
||||
socket->write("rcpt to:<" + qxt_extract_address(rcpt) + ">\r\n");
|
||||
}
|
||||
state = RcptAckPending;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
state = MailToSent;
|
||||
}
|
||||
}
|
||||
|
||||
void QxtSmtpPrivate::sendNextRcpt(const QByteArray& code, const QByteArray&line)
|
||||
void QxtSmtpPrivate::sendNextRcpt(const QByteArray &code, const QByteArray &line)
|
||||
{
|
||||
int messageID = pending.first().first;
|
||||
const QxtMailMessage& msg = pending.first().second;
|
||||
const QxtMailMessage &msg = pending.first().second;
|
||||
|
||||
if (code[0] != '2')
|
||||
{
|
||||
if (code[0] != '2') {
|
||||
// on failure, emit a warning signal
|
||||
if (!mailAck)
|
||||
{
|
||||
if (!mailAck) {
|
||||
emit qxt_p().senderRejected(messageID, msg.sender());
|
||||
emit qxt_p().senderRejected(messageID, msg.sender(), line );
|
||||
}
|
||||
else
|
||||
{
|
||||
emit qxt_p().senderRejected(messageID, msg.sender(), line);
|
||||
} else {
|
||||
emit qxt_p().recipientRejected(messageID, msg.sender());
|
||||
emit qxt_p().recipientRejected(messageID, msg.sender(), line);
|
||||
}
|
||||
}
|
||||
else if (!mailAck)
|
||||
{
|
||||
} else if (!mailAck) {
|
||||
mailAck = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
rcptAck++;
|
||||
}
|
||||
|
||||
if (rcptNumber == recipients.count())
|
||||
{
|
||||
if (rcptNumber == recipients.count()) {
|
||||
// all recipients have been sent
|
||||
if (rcptAck == 0)
|
||||
{
|
||||
if (rcptAck == 0) {
|
||||
// no recipients were considered valid
|
||||
emit qxt_p().mailFailed(messageID, code.toInt() );
|
||||
emit qxt_p().mailFailed(messageID, code.toInt());
|
||||
emit qxt_p().mailFailed(messageID, code.toInt(), line);
|
||||
pending.removeFirst();
|
||||
sendNext();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// at least one recipient was acknowledged, send mail body
|
||||
socket->write("data\r\n");
|
||||
state = SendingBody;
|
||||
}
|
||||
}
|
||||
else if (state != RcptAckPending)
|
||||
{
|
||||
} else if (state != RcptAckPending) {
|
||||
// send the next recipient unless we're only waiting on acks
|
||||
socket->write("rcpt to:<" + qxt_extract_address(recipients[rcptNumber]) + ">\r\n");
|
||||
rcptNumber++;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// If we're only waiting on acks, just count them
|
||||
rcptNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
void QxtSmtpPrivate::sendBody(const QByteArray& code, const QByteArray & line)
|
||||
void QxtSmtpPrivate::sendBody(const QByteArray &code, const QByteArray &line)
|
||||
{
|
||||
int messageID = pending.first().first;
|
||||
const QxtMailMessage& msg = pending.first().second;
|
||||
const QxtMailMessage &msg = pending.first().second;
|
||||
|
||||
if (code[0] != '3')
|
||||
{
|
||||
emit qxt_p().mailFailed(messageID, code.toInt() );
|
||||
if (code[0] != '3') {
|
||||
emit qxt_p().mailFailed(messageID, code.toInt());
|
||||
emit qxt_p().mailFailed(messageID, code.toInt(), line);
|
||||
pending.removeFirst();
|
||||
sendNext();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue