Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-3.10] fixed detection of server version in cmd client similar to gui client (2nd try, signed off) #6033

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/cmd/cmd.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/cmd/cmd.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/cmd/cmd.cpp

File src/cmd/cmd.cpp (lines 464, 465): Code does not conform to Custom style guidelines.
* Copyright (C) by Olivier Goffart <ogoffart@owncloud.com>
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
* Copyright (C) by Daniel Heule <daniel.heule@gmail.com>
Expand Down Expand Up @@ -442,12 +442,40 @@
account->setTrustCertificates(options.trustSSL);

QEventLoop loop;
auto *csjob = new CheckServerJob(account);
csjob->setIgnoreCredentialFailure(true);
QObject::connect(csjob, &CheckServerJob::instanceFound, [&](const QUrl &, const QJsonObject &info) {
// see ConnectionValidator::slotCapabilitiesRecieved: only set server version if not empty
QString serverVersion = CheckServerJob::version(info);
if (!serverVersion.isEmpty()) {
account->setServerVersion(serverVersion);
}
loop.quit();
});
QObject::connect(csjob, &CheckServerJob::instanceNotFound, [&]() {
loop.quit();
});
QObject::connect(csjob, &CheckServerJob::timeout, [&](const QUrl &) {
loop.quit();
});
csjob->start();
loop.exec();

if (csjob->reply()->error() != QNetworkReply::NoError){
std::cout<<"Error connecting to server for status\n";
return EXIT_FAILURE;
}

auto *job = new JsonApiJob(account, QLatin1String("ocs/v1.php/cloud/capabilities"));
QObject::connect(job, &JsonApiJob::jsonReceived, [&](const QJsonDocument &json) {
auto caps = json.object().value("ocs").toObject().value("data").toObject().value("capabilities").toObject();
qDebug() << "Server capabilities" << caps;
account->setCapabilities(caps.toVariantMap());
account->setServerVersion(caps["core"].toObject()["status"].toObject()["version"].toString());
// see ConnectionValidator::slotCapabilitiesRecieved: only set server version if not empty
QString serverVersion = caps["core"].toObject()["status"].toObject()["version"].toString();
if (!serverVersion.isEmpty()) {
account->setServerVersion(serverVersion);
}
loop.quit();
});
job->start();
Expand Down
Loading