X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fclient%2Fclientsyncer.cpp;h=952860a68390bc9765863410650e00b6dd04bfc4;hb=3d5ff3b49a93a3f375b6b454088caafec751dfb6;hp=b8cf4b29c148f45f148d459046beffef374e4ab2;hpb=ee6e4f90ce63d7eb3a54937cffb33510398d2349;p=quassel.git diff --git a/src/client/clientsyncer.cpp b/src/client/clientsyncer.cpp index b8cf4b29..952860a6 100644 --- a/src/client/clientsyncer.cpp +++ b/src/client/clientsyncer.cpp @@ -20,6 +20,8 @@ #include "clientsyncer.h" +#include + #include "client.h" #include "global.h" #include "identity.h" @@ -59,6 +61,10 @@ void ClientSyncer::coreHasData() { emit connectionError(msg["Error"].toString()); disconnectFromCore(); return; + } else if(msg["MsgType"] == "CoreSetupAck") { + emit coreSetupSuccess(); + } else if(msg["MsgType"] == "CoreSetupReject") { + emit coreSetupFailed(msg["Error"].toString()); } else if(msg["MsgType"] == "ClientLoginReject") { emit loginFailed(msg["Error"].toString()); } else if(msg["MsgType"] == "ClientLoginAck") { @@ -68,23 +74,12 @@ void ClientSyncer::coreHasData() { emit loginSuccess(); } else if(msg["MsgType"] == "SessionInit") { sessionStateReceived(msg["SessionState"].toMap()); + break; // this is definitively the last message we process here! } else { emit connectionError(tr("Invalid data received from core!
Disconnecting.")); disconnectFromCore(); return; } - /* - if (!msg["StartWizard"].toBool()) { - recvCoreState(msg["Reply"]); - } else { - qWarning("Core not configured!"); - qDebug() << "Available storage providers: " << msg["StorageProviders"].toStringList(); - emit showConfigWizard(msg); - } - blockSize = 0; - return; - } - */ } if(blockSize > 0) { emit recvPartialItem(socket->bytesAvailable(), blockSize); @@ -92,6 +87,7 @@ void ClientSyncer::coreHasData() { } void ClientSyncer::coreSocketError(QAbstractSocket::SocketError) { + qDebug() << "coreSocketError" << socket << socket->errorString(); emit connectionError(socket->errorString()); socket->deleteLater(); } @@ -125,7 +121,17 @@ void ClientSyncer::connectToCore(const QVariantMap &conn) { //clientMode = RemoteCore; //emit coreConnectionMsg(tr("Connecting...")); Q_ASSERT(!socket); + +#ifndef QT_NO_OPENSSL + QSslSocket *sock = new QSslSocket(Client::instance()); +#else QTcpSocket *sock = new QTcpSocket(Client::instance()); +#endif + + if(conn.contains("useProxy") && conn["useProxy"].toBool()) { + QNetworkProxy proxy((QNetworkProxy::ProxyType)conn["proxyType"].toInt(), conn["proxyHost"].toString(), conn["proxyPort"].toUInt(), conn["proxyUser"].toString(), conn["proxyPassword"].toString()); + sock->setProxy(proxy); + } socket = sock; connect(sock, SIGNAL(readyRead()), this, SLOT(coreHasData())); connect(sock, SIGNAL(connected()), this, SLOT(coreSocketConnected())); @@ -146,7 +152,8 @@ void ClientSyncer::coreSocketConnected() { clientInit["ClientVersion"] = Global::quasselVersion; clientInit["ClientDate"] = Global::quasselDate; clientInit["ClientBuild"] = Global::quasselBuild; // this is a minimum, since we probably won't update for every commit - clientInit["UseSsl"] = false; // FIXME implement SSL + clientInit["UseSsl"] = coreConnectionInfo["useSsl"]; + SignalProxy::writeDataToDevice(socket, clientInit); } @@ -168,16 +175,47 @@ void ClientSyncer::clientInitAck(const QVariantMap &msg) { // Core has accepted our version info and sent its own. Let's see if we accept it as well... if(msg["CoreBuild"].toUInt() < Global::coreBuildNeeded) { emit connectionError(tr("The Quassel Core you are trying to connect to is too old!
" - "Need at least a Core Version %1 (Build >= %2) to connect.").arg(Global::quasselVersion).arg(Global::quasselBuild)); + "Need at least a Core Version %1 (Build >= %2) to connect.").arg(Global::quasselVersion).arg(Global::coreBuildNeeded)); disconnectFromCore(); return; } emit connectionMsg(msg["CoreInfo"].toString()); - if(msg["LoginEnabled"].toBool()) { + if(coreConnectionInfo["useSsl"].toBool()) { + if(msg["SupportSsl"].toBool()) { + QSslSocket *sslSocket = qobject_cast(socket); + if(sslSocket) { + connect(sslSocket, SIGNAL(sslErrors(const QList &)), this, SLOT(sslErrors(const QList &))); + sslSocket->startClientEncryption(); + emit encrypted(true); + } else { + emit connectionError(tr("This client is built without SSL Support!
Disable the usage of SSL in the account settings.")); + emit encrypted(false); + disconnectFromCore(); + return; + } + } else { + emit connectionError(tr("The Quassel Core you are trying to connect to does not support SSL!
If you want to connect anyways, disable the usage of SSL in the account settings.")); + emit encrypted(false); + disconnectFromCore(); + return; + } + } + + if(!msg["Configured"].toBool()) { + // start wizard + emit startCoreSetup(msg["StorageBackends"].toList()); + } else if(msg["LoginEnabled"].toBool()) { emit startLogin(); } } +void ClientSyncer::doCoreSetup(const QVariant &setupData) { + QVariantMap setup; + setup["MsgType"] = "CoreSetupData"; + setup["SetupData"] = setupData; + SignalProxy::writeDataToDevice(socket, setup); +} + void ClientSyncer::loginToCore(const QString &user, const QString &passwd) { emit connectionMsg(tr("Logging in...")); QVariantMap clientLogin; @@ -321,3 +359,12 @@ void ClientSyncer::checkSyncState() { } } +void ClientSyncer::sslErrors(const QList &errors) { + qDebug() << "SSL Errors:"; + foreach(QSslError err, errors) + qDebug() << " " << err; + + QSslSocket *socket = qobject_cast(sender()); + if(socket) + socket->ignoreSslErrors(); +}