Skip to content
Open
Show file tree
Hide file tree
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
21 changes: 11 additions & 10 deletions src/common/utility.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2014 ownCloud GmbH
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "config.h"

Check failure on line 6 in src/common/utility.cpp

View workflow job for this annotation

GitHub Actions / build

src/common/utility.cpp:6:10 [clang-diagnostic-error]

'config.h' file not found

#include "common/utility.h"
#include "common/filesystembase.h"
Expand Down Expand Up @@ -151,16 +151,17 @@
#endif
}

QByteArray Utility::userAgentString()
{
return QStringLiteral("Mozilla/5.0 (%1) mirall/%2 (%3, %4-%5 ClientArchitecture: %6 OsArchitecture: %7)")
.arg(platform(),
QStringLiteral(MIRALL_VERSION_STRING),
qApp->applicationName(),
QSysInfo::productType(),
QSysInfo::kernelVersion(),
QSysInfo::buildCpuArchitecture(),
QSysInfo::currentCpuArchitecture())
QByteArray Utility::userAgentString(const QString &synchronizationType)
{
return QStringLiteral("Mozilla/5.0 (%1) mirall/%2 (%3, %4-%5 ClientArchitecture: %6 OsArchitecture: %7 SyncType: %8)")
.arg(platform(),
QStringLiteral(MIRALL_VERSION_STRING),
qApp->applicationName(),
QSysInfo::productType(),
QSysInfo::kernelVersion(),
QSysInfo::buildCpuArchitecture(),
QSysInfo::currentCpuArchitecture(),
synchronizationType)
.toLatin1();
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define UTILITY_H


#include "csync/ocsynclib.h"

Check failure on line 11 in src/common/utility.h

View workflow job for this annotation

GitHub Actions / build

src/common/utility.h:11:10 [clang-diagnostic-error]

'csync/ocsynclib.h' file not found
#include <QString>
#include <QByteArray>
#include <QDateTime>
Expand Down Expand Up @@ -68,7 +68,7 @@

OCSYNC_EXPORT bool writeRandomFile(const QString &fname, int size = -1);
OCSYNC_EXPORT QString octetsToString(const qint64 octets);
OCSYNC_EXPORT QByteArray userAgentString();
OCSYNC_EXPORT QByteArray userAgentString(const QString &synchronizationType);
OCSYNC_EXPORT QByteArray friendlyUserAgentString();
/**
* @brief Return whether launch on startup is enabled system wide.
Expand Down
1 change: 1 addition & 0 deletions src/gui/creds/webflowcredentials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class WebFlowCredentialsAccessManager : public AccessManager
: AccessManager(parent)
, _cred(cred)
{
setSynchronizationType(QStringLiteral("login"));
}

protected:
Expand Down
1 change: 1 addition & 0 deletions src/gui/systray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,7 @@ AccessManagerFactory::AccessManagerFactory()
QNetworkAccessManager* AccessManagerFactory::create(QObject *parent)
{
const auto am = new AccessManager(parent);
am->setSynchronizationType(QStringLiteral("Systray"));
const auto diskCache = new QNetworkDiskCache(am);
diskCache->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
am->setCache(diskCache);
Expand Down
5 changes: 5 additions & 0 deletions src/gui/updater/ocupdater.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2014 ownCloud GmbH
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "theme.h"

Check failure on line 7 in src/gui/updater/ocupdater.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/updater/ocupdater.cpp:7:10 [clang-diagnostic-error]

'theme.h' file not found
#include "configfile.h"
#include "common/utility.h"
#include "accessmanager.h"
Expand Down Expand Up @@ -81,6 +81,7 @@
, _accessManager(new AccessManager(this))
, _timeoutWatchdog(new QTimer(this))
{
_accessManager->setSynchronizationType(QStringLiteral("updater"));
}

void OCUpdater::setUpdateUrl(const QUrl &url)
Expand Down Expand Up @@ -248,6 +249,10 @@
return currentVersion >= targetVersionInt;
}

QNetworkAccessManager *OCUpdater::qnam() const {
return _accessManager;
}

void OCUpdater::slotVersionInfoArrived()
{
qCDebug(lcUpdater) << "received a reply";
Expand Down
6 changes: 4 additions & 2 deletions src/gui/updater/ocupdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef OCUPDATER_H
#define OCUPDATER_H

#include <QObject>

Check failure on line 10 in src/gui/updater/ocupdater.h

View workflow job for this annotation

GitHub Actions / build

src/gui/updater/ocupdater.h:10:10 [clang-diagnostic-error]

'QObject' file not found
#include <QUrl>
#include <QTemporaryFile>
#include <QTimer>
Expand Down Expand Up @@ -73,6 +73,8 @@
QTimer _updateCheckTimer; /** Timer for the regular update check. */
};

class AccessManager;

/**
* @brief Class that uses an ownCloud proprietary XML format to fetch update information
* @ingroup gui
Expand Down Expand Up @@ -126,13 +128,13 @@
protected:
virtual void versionInfoArrived(const UpdateInfo &info) = 0;
[[nodiscard]] bool updateSucceeded() const;
[[nodiscard]] QNetworkAccessManager *qnam() const { return _accessManager; }
[[nodiscard]] QNetworkAccessManager *qnam() const;
[[nodiscard]] UpdateInfo updateInfo() const { return _updateInfo; }

private:
QUrl _updateUrl;
int _state = Unknown;
QNetworkAccessManager *_accessManager;
AccessManager *_accessManager;
QTimer *_timeoutWatchdog; /** Timer to guard the timeout of an individual network request */
UpdateInfo _updateInfo;
};
Expand Down
2 changes: 1 addition & 1 deletion src/gui/wizard/webview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
_interceptor = new WebViewPageUrlRequestInterceptor(this);
_schemeHandler = new WebViewPageUrlSchemeHandler(this);

const QString userAgent(Utility::userAgentString());
const QString userAgent(Utility::userAgentString(QStringLiteral("login")));

Check warning on line 91 in src/gui/wizard/webview.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/wizard/webview.cpp:91:19 [cppcoreguidelines-init-variables]

variable 'userAgent' is not initialized
_profile->setHttpUserAgent(userAgent);
QWebEngineProfile::defaultProfile()->setHttpUserAgent(userAgent);
_profile->setUrlRequestInterceptor(_interceptor);
Expand Down
13 changes: 12 additions & 1 deletion src/libsync/accessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include <QLoggingCategory>

Check failure on line 7 in src/libsync/accessmanager.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/accessmanager.cpp:7:10 [clang-diagnostic-error]

'QLoggingCategory' file not found
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QNetworkProxy>
Expand Down Expand Up @@ -38,6 +38,16 @@
});
}

const QString &AccessManager::synchronizationType() const
{
return _synchronizationType;
}

void AccessManager::setSynchronizationType(const QString &type)
{
_synchronizationType = type;
}

QByteArray AccessManager::generateRequestId()
{
return QUuid::createUuid().toByteArray(QUuid::WithoutBraces);
Expand All @@ -49,7 +59,8 @@

// Respect request specific user agent if any
if (!newRequest.header(QNetworkRequest::UserAgentHeader).isValid()) {
newRequest.setHeader(QNetworkRequest::UserAgentHeader, Utility::userAgentString());
Q_ASSERT(!_synchronizationType.isEmpty());
newRequest.setHeader(QNetworkRequest::UserAgentHeader, Utility::userAgentString(_synchronizationType));
}

// Some firewalls reject requests that have a "User-Agent" but no "Accept" header
Expand Down
7 changes: 7 additions & 0 deletions src/libsync/accessmanager.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2014 ownCloud GmbH
Expand All @@ -7,7 +7,7 @@
#ifndef MIRALL_ACCESS_MANAGER_H
#define MIRALL_ACCESS_MANAGER_H

#include "owncloudlib.h"

Check failure on line 10 in src/libsync/accessmanager.h

View workflow job for this annotation

GitHub Actions / build

src/libsync/accessmanager.h:10:10 [clang-diagnostic-error]

'owncloudlib.h' file not found
#include <QNetworkAccessManager>

class QByteArray;
Expand All @@ -28,8 +28,15 @@

AccessManager(QObject *parent = nullptr);

[[nodiscard]] const QString& synchronizationType() const;

void setSynchronizationType(const QString &type);

protected:
QNetworkReply *createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData = nullptr) override;

private:
QString _synchronizationType;
};

} // namespace OCC
Expand Down
20 changes: 20 additions & 0 deletions src/libsync/account.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2013 ownCloud GmbH
Expand Down Expand Up @@ -284,6 +284,11 @@
// processing slotHandleSslErrors().
_networkAccessManager = QSharedPointer<QNetworkAccessManager>(_credentials->createQNAM(), &QObject::deleteLater);

const auto accessManager = qobject_cast<AccessManager*>(_networkAccessManager.get());
if (accessManager) {
accessManager->setSynchronizationType(QStringLiteral("account"));
}

if (jar) {
_networkAccessManager->setCookieJar(jar);
}
Expand Down Expand Up @@ -414,6 +419,11 @@
// Make it call deleteLater to make sure that we can return to any QNAM stack frames safely.
_networkAccessManager = QSharedPointer<QNetworkAccessManager>(_credentials->createQNAM(), &QObject::deleteLater);

const auto accessManager = qobject_cast<AccessManager*>(_networkAccessManager.get());
if (accessManager) {
accessManager->setSynchronizationType(QStringLiteral("account"));
}

_networkAccessManager->setCookieJar(jar); // takes ownership of the old cookie jar
_networkAccessManager->setProxy(proxy); // Remember proxy (issue #2108)

Expand Down Expand Up @@ -1132,6 +1142,16 @@
Q_EMIT wantsAccountSaved(sharedFromThis());
}

const QString &Account::synchronizationType() const
{
return static_cast<AccessManager*>(_networkAccessManager.get())->synchronizationType();
}

void Account::setSynchronizationType(const QString &type)
{
static_cast<AccessManager*>(_networkAccessManager.get())->setSynchronizationType(type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once this is set, each request will contain SyncType: classical or SyncType: virtual

I only see SyncType: account (from above) at app startup, after a proper sync that value will change through this method

}

void Account::setAskUserForMnemonic(const bool ask)
{
_e2eAskUserForMnemonic = ask;
Expand Down
4 changes: 4 additions & 0 deletions src/libsync/account.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2013 ownCloud GmbH
Expand Down Expand Up @@ -418,6 +418,10 @@
[[nodiscard]] QByteArray encryptionCertificateFingerprint() const;
void setEncryptionCertificateFingerprint(const QByteArray &fingerprint);

[[nodiscard]] const QString& synchronizationType() const;

void setSynchronizationType(const QString &type);

public slots:
/// Used when forgetting credentials
void clearQNAMCache();
Expand Down
13 changes: 12 additions & 1 deletion src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2014 ownCloud GmbH
Expand Down Expand Up @@ -583,7 +583,18 @@

verStr.append(" SSL library ").append(QSslSocket::sslLibraryVersionString().toUtf8().data());
verStr.append(" on ").append(Utility::platformName());
qCInfo(lcEngine) << verStr;
qCInfo(lcEngine) << verStr << "vfs mode: " << _syncOptions._vfs->mode();

switch (_syncOptions._vfs->mode())
{
case Vfs::Off:
_account->setSynchronizationType(QStringLiteral("classical"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing break

Suggested change
_account->setSynchronizationType(QStringLiteral("classical"));
_account->setSynchronizationType(QStringLiteral("classical"));
break;

case Vfs::WithSuffix:
case Vfs::WindowsCfApi:
case Vfs::XAttr:
_account->setSynchronizationType(QStringLiteral("virtual"));
break;
}

// This creates the DB if it does not exist yet.
if (!_journal->open()) {
Expand Down
Loading