From: Markus Goetz Date: Wed, 19 Apr 2017 09:02:03 +0000 (+0200) Subject: Server: Parse version from capabilities too #5691 (#5698) X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~722^2~37 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=5ac58d3b83758b3bb5118c88aae0f75ae8ae2f53;p=nextcloud-desktop.git Server: Parse version from capabilities too #5691 (#5698) Newer servers will have the option of hiding version, versionstring, edition and productname. They will always send the full information in the capabilities. --- diff --git a/src/gui/creds/httpcredentialsgui.cpp b/src/gui/creds/httpcredentialsgui.cpp index 8eb5c40ee..dbfce8169 100644 --- a/src/gui/creds/httpcredentialsgui.cpp +++ b/src/gui/creds/httpcredentialsgui.cpp @@ -70,17 +70,19 @@ void HttpCredentialsGui::askFromUserAsync() QString HttpCredentialsGui::requestAppPasswordText(const Account* account) { - if (account->serverVersionInt() < Account::makeServerVersion(9, 1, 0)) { - // Older server than 9.1 does not have the feature to request App Password - return QString(); - } - + int version = account->serverVersionInt(); QString path; - if (account->serverVersionInt() < Account::makeServerVersion(10, 0, 0)) { + + // Version may not be available before login on new servers! + if (!version || version >= Account::makeServerVersion(10, 0, 0)) { + path = QLatin1String("/index.php/settings/personal?sectionid=security#apppasswords"); + } else if (version >= Account::makeServerVersion(9, 1, 0)) { path = QLatin1String("/index.php/settings/personal?section=apppasswords"); } else { - path = QLatin1String("/index.php/settings/personal?sectionid=security#apppasswords"); + // Older server than 9.1 does not have the feature to request App Password + return QString(); } + return tr("Click here to request an app password from the web interface.") .arg(account->url().toString() + path); } diff --git a/src/gui/owncloudsetupwizard.cpp b/src/gui/owncloudsetupwizard.cpp index 933d36bd8..971ccf827 100644 --- a/src/gui/owncloudsetupwizard.cpp +++ b/src/gui/owncloudsetupwizard.cpp @@ -183,6 +183,8 @@ void OwncloudSetupWizard::slotOwnCloudFoundAuth(const QUrl& url, const QVariantM Utility::escape(CheckServerJob::versionString(info)), Utility::escape(serverVersion))); + // Note with newer servers we get the version actually only later in capabilities + // https://github.com/owncloud/core/pull/27473/files _ocWizard->account()->setServerVersion(serverVersion); QString p = url.path(); diff --git a/src/libsync/account.h b/src/libsync/account.h index e081121b3..0f55c5a1d 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -145,9 +145,21 @@ public: const Capabilities &capabilities() const; void setCapabilities(const QVariantMap &caps); - /** Access the server version */ + /** Access the server version + * + * For servers >= 10.0.0, this can be the empty string until capabilities + * have been received. + */ QString serverVersion() const; + + /** Server version for easy comparison. + * + * Example: serverVersionInt() >= makeServerVersion(11, 2, 3) + * + * Will be 0 if the version is not available yet. + */ int serverVersionInt() const; + static int makeServerVersion(int majorVersion, int minorVersion, int patchVersion); void setServerVersion(const QString &version); diff --git a/src/libsync/connectionvalidator.cpp b/src/libsync/connectionvalidator.cpp index ec63685aa..76571f186 100644 --- a/src/libsync/connectionvalidator.cpp +++ b/src/libsync/connectionvalidator.cpp @@ -114,26 +114,21 @@ void ConnectionValidator::slotCheckServerAndAuth() void ConnectionValidator::slotStatusFound(const QUrl&url, const QVariantMap &info) { + // Newer servers don't disclose any version in status.php anymore + // https://github.com/owncloud/core/pull/27473/files + // so this string can be empty. + QString serverVersion = CheckServerJob::version(info); + // status.php was found. qDebug() << "** Application: ownCloud found: " << url << " with version " << CheckServerJob::versionString(info) - << "(" << CheckServerJob::version(info) << ")"; - - QString version = CheckServerJob::version(info); - _account->setServerVersion(version); + << "(" << serverVersion << ")"; - // We cannot deal with servers < 5.0.0 - if (version.contains('.') && version.split('.')[0].toInt() < 5) { - _errors.append( tr("The configured server for this client is too old") ); - _errors.append( tr("Please update to the latest server and restart the client.") ); - reportResult( ServerVersionMismatch ); + if (!serverVersion.isEmpty() && !setAndCheckServerVersion(serverVersion)) { return; } - // We attempt to work with servers >= 5.0.0 but warn users. - // Check usages of Account::serverVersionUnsupported() for details. - // now check the authentication if (_account->credentials()->ready()) QTimer::singleShot( 0, this, SLOT( checkAuthentication() )); @@ -235,6 +230,13 @@ void ConnectionValidator::slotCapabilitiesRecieved(const QVariantMap &json) auto caps = json.value("ocs").toMap().value("data").toMap().value("capabilities"); qDebug() << "Server capabilities" << caps; _account->setCapabilities(caps.toMap()); + + // New servers also report the version in the capabilities + QString serverVersion = caps.toMap()["core"].toMap()["status"].toMap()["version"].toString(); + if (!serverVersion.isEmpty() && !setAndCheckServerVersion(serverVersion)) { + return; + } + fetchUser(); } @@ -247,6 +249,26 @@ void ConnectionValidator::fetchUser() job->start(); } +bool ConnectionValidator::setAndCheckServerVersion(const QString& version) +{ + qDebug() << _account->url() << "has server version" << version; + _account->setServerVersion(version); + + // We cannot deal with servers < 5.0.0 + if (_account->serverVersionInt() + && _account->serverVersionInt() < Account::makeServerVersion(5, 0, 0)) { + _errors.append( tr("The configured server for this client is too old") ); + _errors.append( tr("Please update to the latest server and restart the client.") ); + reportResult( ServerVersionMismatch ); + return false; + } + + // We attempt to work with servers >= 5.0.0 but warn users. + // Check usages of Account::serverVersionUnsupported() for details. + + return true; +} + void ConnectionValidator::slotUserFetched(const QVariantMap &json) { QString user = json.value("ocs").toMap().value("data").toMap().value("id").toString(); diff --git a/src/libsync/connectionvalidator.h b/src/libsync/connectionvalidator.h index 13e1435a5..f740b2abd 100644 --- a/src/libsync/connectionvalidator.h +++ b/src/libsync/connectionvalidator.h @@ -125,6 +125,12 @@ private: void checkServerCapabilities(); void fetchUser(); + /** Sets the account's server version + * + * Returns false and reports ServerVersionMismatch for very old servers. + */ + bool setAndCheckServerVersion(const QString& version); + QStringList _errors; AccountPtr _account; bool _isCheckingServerAndAuth; diff --git a/src/libsync/networkjobs.cpp b/src/libsync/networkjobs.cpp index b12c65a8e..3bc494f39 100644 --- a/src/libsync/networkjobs.cpp +++ b/src/libsync/networkjobs.cpp @@ -474,10 +474,7 @@ bool CheckServerJob::finished() } qDebug() << "status.php returns: " << status << " " << reply()->error() << " Reply: " << reply(); - if( status.contains("installed") - && status.contains("version") - && status.contains("versionstring") ) { - + if( status.contains("installed") ) { emit instanceFound(reply()->url(), status); } else { qDebug() << "No proper answer on " << reply()->url();