Comparar commits
84 Commits
| Autor | SHA1 | Data | |
|---|---|---|---|
| 5b0141cfed | |||
| 030e3a5d4a | |||
| 4fa4a6a5ed | |||
| 23fb07240b | |||
| 3912dba33a | |||
| d8c479ab1e | |||
| bec67455c1 | |||
| ba6a37a601 | |||
| 03f5091e73 | |||
| 6b6ff08821 | |||
| 35a0ee4893 | |||
| 3519391119 | |||
| 775a1c9ad8 | |||
| ac95844ebd | |||
| c5b90d9507 | |||
| d631f2e070 | |||
| 5bae2ed5ef | |||
| 5af2a657ca | |||
| 71231026a0 | |||
| dfca67b63a | |||
| 7dc6a3b89f | |||
| f985111b62 | |||
| e8d734b1c2 | |||
| a38864fcb4 | |||
| 47bab51474 | |||
| d0d5b2b4ee | |||
| 36967122db | |||
| 3fd67b9fb6 | |||
| 5bef1aa402 | |||
| de9ea19e7e | |||
| 4ac2b764a4 | |||
| 0614cda337 | |||
| 9e895b9b3e | |||
| f501211c63 | |||
| 77ac1b46dd | |||
| 745c21623c | |||
| b91c116518 | |||
| d090a3330a | |||
| d04e7841e2 | |||
| d7a4726544 | |||
| 19d2677db1 | |||
| a139d1a279 | |||
| 13e624c38f | |||
| acb155503b | |||
| 4cb80b08a2 | |||
| cd85b7c6d7 | |||
| 109056e676 | |||
| 51a1bea5de | |||
| 68f99bcc27 | |||
| 276985f6c3 | |||
| 7523db354d | |||
| 4919c9e7b1 | |||
| 49f8143f00 | |||
| bea7241910 | |||
| 61b4da944c | |||
| 6fe1868693 | |||
| 9641c7a1e7 | |||
| 3e59a9b316 | |||
| 16e28567a6 | |||
| 3bef42db6b | |||
| 27d23edacc | |||
| e1a48e3c33 | |||
| 5d13f9290f | |||
| c84140d293 | |||
| 838c072ccc | |||
| ed6a708460 | |||
| 0c9dcdafc2 | |||
| f0dc3b2deb | |||
| 84ede3f01f | |||
| 2daf895e43 | |||
| 3b651b2da9 | |||
| 6fd930908c | |||
| 62125a442d | |||
| 2d54fb2ff9 | |||
| e46fad52bb | |||
| f3cfd2b70b | |||
| 78caa1a712 | |||
| 0884ad6517 | |||
| 37fc4e4332 | |||
| 9cc90159f1 | |||
| 4ceee86c66 | |||
| b9ea7c3414 | |||
| 3033e693be | |||
| a1bc01d3b1 |
@@ -40,7 +40,6 @@ QT_PLUGINS = [
|
||||
'imageformats/libqico.dylib',
|
||||
'imageformats/libqjpeg.dylib',
|
||||
'imageformats/libqsvg.dylib',
|
||||
'imageformats/libqmng.dylib',
|
||||
]
|
||||
|
||||
QT_PLUGINS_SEARCH_PATH=[
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
From ea4dcc5931d455e4ee3e958ffa54a9f54ab022c8 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Molkentin <daniel@molkentin.de>
|
||||
Date: Mon, 5 Jan 2015 10:45:25 +0100
|
||||
Subject: [PATCH 1/3] Fix crash on Mac OS if PAC URL contains non-URL legal
|
||||
chars
|
||||
|
||||
macQueryInternal() was retrieving the PAC URL string as-entered by
|
||||
the user in the 'Proxies' tab of the system network settings dialog
|
||||
and passing it to CFURLCreateWithString().
|
||||
|
||||
CFURLCreateWithString() returns null if the input string contains
|
||||
non-URL legal chars or is empty.
|
||||
|
||||
Change-Id: I9166d0433a62c7b2274b5435a7dea0a16997d10e
|
||||
Patch-By: Robert Knight
|
||||
Task-number: QTBUG-36787
|
||||
Reviewed-by: Peter Hartmann <phartmann@blackberry.com>
|
||||
Reviewed-by: Markus Goetz <markus@woboq.com>
|
||||
---
|
||||
src/network/kernel/qnetworkproxy_mac.cpp | 6 +++++-
|
||||
1 file changed, 5 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/network/kernel/qnetworkproxy_mac.cpp b/src/network/kernel/qnetworkproxy_mac.cpp
|
||||
index 7d26246..81bce0c 100644
|
||||
--- a/src/network/kernel/qnetworkproxy_mac.cpp
|
||||
+++ b/src/network/kernel/qnetworkproxy_mac.cpp
|
||||
@@ -221,7 +221,11 @@ QList<QNetworkProxy> macQueryInternal(const QNetworkProxyQuery &query)
|
||||
int enabled;
|
||||
if (CFNumberGetValue(pacEnabled, kCFNumberIntType, &enabled) && enabled) {
|
||||
// PAC is enabled
|
||||
- CFStringRef cfPacLocation = (CFStringRef)CFDictionaryGetValue(dict, kSCPropNetProxiesProxyAutoConfigURLString);
|
||||
+ // kSCPropNetProxiesProxyAutoConfigURLString returns the URL string
|
||||
+ // as entered in the system proxy configuration dialog
|
||||
+ CFStringRef pacLocationSetting = (CFStringRef)CFDictionaryGetValue(dict, kSCPropNetProxiesProxyAutoConfigURLString);
|
||||
+ QCFType<CFStringRef> cfPacLocation = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, pacLocationSetting, NULL, NULL,
|
||||
+ kCFStringEncodingUTF8);
|
||||
|
||||
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) {
|
||||
QCFType<CFDataRef> pacData;
|
||||
--
|
||||
1.8.3.4 (Apple Git-47)
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
From a83e4d1d9dd90d4563ce60f27dfb7802a780e33e Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Molkentin <daniel@molkentin.de>
|
||||
Date: Mon, 5 Jan 2015 11:42:52 +0100
|
||||
Subject: [PATCH 2/3] Fix possible crash when passing an invalid PAC URL
|
||||
|
||||
This commit checks whether CFURLCreateWithString() succeeded.
|
||||
|
||||
It does not appear to be possible to enter an empty URL directly in the
|
||||
PAC configuration dialog but I can't rule out the possibility
|
||||
that it could find its way into the settings via some other means.
|
||||
|
||||
Change-Id: I6c2053d385503bf0330f5ae9fb1ec36a473d425d
|
||||
Patch-By: Robert Knight
|
||||
Task-number: QTBUG-36787
|
||||
Reviewed-by: Markus Goetz <markus@woboq.com>
|
||||
Reviewed-by: Peter Hartmann <phartmann@blackberry.com>
|
||||
---
|
||||
src/network/kernel/qnetworkproxy_mac.cpp | 4 ++++
|
||||
1 file changed, 4 insertions(+)
|
||||
|
||||
diff --git a/src/network/kernel/qnetworkproxy_mac.cpp b/src/network/kernel/qnetworkproxy_mac.cpp
|
||||
index 81bce0c..6be032e 100644
|
||||
--- a/src/network/kernel/qnetworkproxy_mac.cpp
|
||||
+++ b/src/network/kernel/qnetworkproxy_mac.cpp
|
||||
@@ -230,6 +230,10 @@ QList<QNetworkProxy> macQueryInternal(const QNetworkProxyQuery &query)
|
||||
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) {
|
||||
QCFType<CFDataRef> pacData;
|
||||
QCFType<CFURLRef> pacUrl = CFURLCreateWithString(kCFAllocatorDefault, cfPacLocation, NULL);
|
||||
+ if (!pacUrl) {
|
||||
+ qWarning("Invalid PAC URL \"%s\"", qPrintable(QCFString::toQString(cfPacLocation)));
|
||||
+ return result;
|
||||
+ }
|
||||
SInt32 errorCode;
|
||||
if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, pacUrl, &pacData, NULL, NULL, &errorCode)) {
|
||||
QString pacLocation = QCFString::toQString(cfPacLocation);
|
||||
--
|
||||
1.8.3.4 (Apple Git-47)
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
From 83bd9393e5564ea9168fda90c0f44456633a483a Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Molkentin <daniel@molkentin.de>
|
||||
Date: Mon, 5 Jan 2015 15:22:57 +0100
|
||||
Subject: [PATCH 3/3] Fix crash if PAC script retrieval returns a null CFData
|
||||
instance
|
||||
|
||||
The documentation for CFURLCreateDataAndPropertiesFromResource()
|
||||
does not make this clear but from looking at the CFNetwork implementation
|
||||
and a user stacktrace it appears that this function can return true
|
||||
but not set the data argument under certain circumstances.
|
||||
|
||||
Change-Id: I48034a640d6f47a51cd5883bbafacad4bcbd0415
|
||||
Task-number: QTBUG-36787
|
||||
Patch-By: Robert Knight
|
||||
Reviewed-by: Markus Goetz <markus@woboq.com>
|
||||
Reviewed-by: Peter Hartmann <phartmann@blackberry.com>
|
||||
---
|
||||
src/network/kernel/qnetworkproxy_mac.cpp | 5 ++++-
|
||||
1 file changed, 4 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/network/kernel/qnetworkproxy_mac.cpp b/src/network/kernel/qnetworkproxy_mac.cpp
|
||||
index 6be032e..a1ac349 100644
|
||||
--- a/src/network/kernel/qnetworkproxy_mac.cpp
|
||||
+++ b/src/network/kernel/qnetworkproxy_mac.cpp
|
||||
@@ -240,7 +240,10 @@ QList<QNetworkProxy> macQueryInternal(const QNetworkProxyQuery &query)
|
||||
qWarning("Unable to get the PAC script at \"%s\" (%s)", qPrintable(pacLocation), cfurlErrorDescription(errorCode));
|
||||
return result;
|
||||
}
|
||||
-
|
||||
+ if (!pacData) {
|
||||
+ qWarning("\"%s\" returned an empty PAC script", qPrintable(QCFString::toQString(cfPacLocation)));
|
||||
+ return result;
|
||||
+ }
|
||||
QCFType<CFStringRef> pacScript = CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, pacData, kCFStringEncodingISOLatin1);
|
||||
if (!pacScript) {
|
||||
// This should never happen, but the documentation says it may return NULL if there was a problem creating the object.
|
||||
--
|
||||
1.8.3.4 (Apple Git-47)
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
From 22f3d359350fd65e4bbe2e9420fcc4460e8a590a Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= <morten.sorvig@digia.com>
|
||||
Date: Tue, 10 Mar 2015 22:37:39 +0100
|
||||
Subject: [PATCH] Cocoa: Fix systray SVG icons.
|
||||
|
||||
Regression caused by f3699510.
|
||||
|
||||
Task-number: QTBUG-44686
|
||||
Change-Id: I546422a67d4da29fac196025b09bddcb45c1b641
|
||||
Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
|
||||
---
|
||||
src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm | 4 ++++
|
||||
1 file changed, 4 insertions(+)
|
||||
|
||||
diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
|
||||
index e449fd3..8a35705 100755
|
||||
--- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
|
||||
+++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
|
||||
@@ -234,6 +234,10 @@ void QCocoaSystemTrayIcon::updateIcon(const QIcon &icon)
|
||||
}
|
||||
}
|
||||
|
||||
+ // Handle SVG icons, which do not return anything for availableSizes().
|
||||
+ if (!selectedSize.isValid())
|
||||
+ selectedSize = icon.actualSize(QSize(maxPixmapHeight, maxPixmapHeight), mode);
|
||||
+
|
||||
QPixmap pixmap = icon.pixmap(selectedSize, mode);
|
||||
|
||||
// Draw a low-resolution icon if there is not enough pixels for a retina
|
||||
--
|
||||
1.9.1
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
From ee7fea33383726f0bb72e8082a357820e3ee3675 Mon Sep 17 00:00:00 2001
|
||||
From: Jocelyn Turcotte <jturcotte@woboq.com>
|
||||
Date: Tue, 24 Feb 2015 17:02:02 +0100
|
||||
Subject: [PATCH] OSX Fix disapearing tray icon
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
It would happen together with an error:
|
||||
QPainter::begin: Paint device returned engine == 0
|
||||
and would be caused by the size provided to QIcon::pixmap being empty,
|
||||
itself caused by the availableSizes list being empty for the Selected
|
||||
mode.
|
||||
|
||||
This bug was most often hidden by the fact that the Selected icon mode
|
||||
was not triggered properly since we usually only set menuVisible after
|
||||
calling updateIcon, and most of the time when it did, we would overwrite
|
||||
it right after with a Normal mode icon.
|
||||
|
||||
Fix the issue by disabling the broken feature completely since the
|
||||
default Selected icon is grayed out while tray icons are now usually
|
||||
black (or white when selected). To support the dark menu bar mode on
|
||||
10.10 we'll need to use NSImage's setTemplate anyway and that
|
||||
knowing in advance if we can invert the colors ourselves would also
|
||||
better solve the menuVisible usecase.
|
||||
|
||||
Task-number: QTBUG-42910
|
||||
Change-Id: If9ec9659af28ecceb841bfc2f11721e6029fe891
|
||||
Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
|
||||
---
|
||||
src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm | 17 +++--------------
|
||||
1 file changed, 3 insertions(+), 14 deletions(-)
|
||||
|
||||
diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
|
||||
index 8a35705..d366a3c 100755
|
||||
--- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
|
||||
+++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
|
||||
@@ -102,7 +102,6 @@ QT_USE_NAMESPACE
|
||||
QCocoaSystemTrayIcon *systray;
|
||||
NSStatusItem *item;
|
||||
QCocoaMenu *menu;
|
||||
- bool menuVisible;
|
||||
QIcon icon;
|
||||
QT_MANGLE_NAMESPACE(QNSImageView) *imageCell;
|
||||
}
|
||||
@@ -202,8 +201,6 @@ void QCocoaSystemTrayIcon::updateIcon(const QIcon &icon)
|
||||
|
||||
m_sys->item->icon = icon;
|
||||
|
||||
- const bool menuVisible = m_sys->item->menu && m_sys->item->menuVisible;
|
||||
-
|
||||
// The reccomended maximum title bar icon height is 18 points
|
||||
// (device independent pixels). The menu height on past and
|
||||
// current OS X versions is 22 points. Provide some future-proofing
|
||||
@@ -218,9 +215,8 @@ void QCocoaSystemTrayIcon::updateIcon(const QIcon &icon)
|
||||
// devicePixelRatio for the "best" screen on the system.
|
||||
qreal devicePixelRatio = qApp->devicePixelRatio();
|
||||
const int maxPixmapHeight = maxImageHeight * devicePixelRatio;
|
||||
- const QIcon::Mode mode = menuVisible ? QIcon::Selected : QIcon::Normal;
|
||||
QSize selectedSize;
|
||||
- Q_FOREACH (const QSize& size, sortByHeight(icon.availableSizes(mode))) {
|
||||
+ Q_FOREACH (const QSize& size, sortByHeight(icon.availableSizes())) {
|
||||
// Select a pixmap based on the height. We want the largest pixmap
|
||||
// with a height smaller or equal to maxPixmapHeight. The pixmap
|
||||
// may rectangular; assume it has a reasonable size. If there is
|
||||
@@ -236,9 +232,9 @@ void QCocoaSystemTrayIcon::updateIcon(const QIcon &icon)
|
||||
|
||||
// Handle SVG icons, which do not return anything for availableSizes().
|
||||
if (!selectedSize.isValid())
|
||||
- selectedSize = icon.actualSize(QSize(maxPixmapHeight, maxPixmapHeight), mode);
|
||||
+ selectedSize = icon.actualSize(QSize(maxPixmapHeight, maxPixmapHeight));
|
||||
|
||||
- QPixmap pixmap = icon.pixmap(selectedSize, mode);
|
||||
+ QPixmap pixmap = icon.pixmap(selectedSize);
|
||||
|
||||
// Draw a low-resolution icon if there is not enough pixels for a retina
|
||||
// icon. This prevents showing a small icon on retina displays.
|
||||
@@ -385,9 +381,6 @@ QT_END_NAMESPACE
|
||||
Q_UNUSED(notification);
|
||||
down = NO;
|
||||
|
||||
- parent->systray->updateIcon(parent->icon);
|
||||
- parent->menuVisible = false;
|
||||
-
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
@@ -397,8 +390,6 @@ QT_END_NAMESPACE
|
||||
int clickCount = [mouseEvent clickCount];
|
||||
[self setNeedsDisplay:YES];
|
||||
|
||||
- parent->systray->updateIcon(parent->icon);
|
||||
-
|
||||
if (clickCount == 2) {
|
||||
[self menuTrackingDone:nil];
|
||||
[parent doubleClickSelector:self];
|
||||
@@ -454,7 +445,6 @@ QT_END_NAMESPACE
|
||||
if (self) {
|
||||
item = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
|
||||
menu = 0;
|
||||
- menuVisible = false;
|
||||
systray = sys;
|
||||
imageCell = [[QNSImageView alloc] initWithParent:self];
|
||||
[item setView: imageCell];
|
||||
@@ -498,7 +488,6 @@ QT_END_NAMESPACE
|
||||
selector:@selector(menuTrackingDone:)
|
||||
name:NSMenuDidEndTrackingNotification
|
||||
object:m];
|
||||
- menuVisible = true;
|
||||
[item popUpStatusItemMenu: m];
|
||||
}
|
||||
}
|
||||
--
|
||||
1.9.1
|
||||
|
||||
@@ -1,691 +0,0 @@
|
||||
From cff39fba10ffc10ee4dcfdc66ff6528eb26462d3 Mon Sep 17 00:00:00 2001
|
||||
From: Markus Goetz <markus@woboq.com>
|
||||
Date: Fri, 10 Apr 2015 14:09:53 +0200
|
||||
Subject: [PATCH] QNAM: Fix upload corruptions when server closes connection
|
||||
|
||||
This patch fixes several upload corruptions if the server closes the connection
|
||||
while/before we send data into it. They happen inside multiple places in the HTTP
|
||||
layer and are explained in the comments.
|
||||
Corruptions are:
|
||||
* The upload byte device has an in-flight signal with pending upload data, if
|
||||
it gets reset (because server closes the connection) then the re-send of the
|
||||
request was sometimes taking this stale in-flight pending upload data.
|
||||
* Because some signals were DirectConnection and some were QueuedConnection, there
|
||||
was a chance that a direct signal overtakes a queued signal. The state machine
|
||||
then sent data down the socket which was buffered there (and sent later) although
|
||||
it did not match the current state of the state machine when it was actually sent.
|
||||
* A socket was seen as being able to have requests sent even though it was not
|
||||
encrypted yet. This relates to the previous corruption where data is stored inside
|
||||
the socket's buffer and then sent later.
|
||||
|
||||
The included auto test produces all fixed corruptions, I detected no regressions
|
||||
via the other tests.
|
||||
This code also adds a bit of sanity checking to protect from possible further
|
||||
problems.
|
||||
|
||||
[ChangeLog][QtNetwork] Fix HTTP(s) upload corruption when server closes connection
|
||||
|
||||
Change-Id: I54c883925ec897050941498f139c4b523030432e
|
||||
Reviewed-by: Peter Hartmann <peter-qt@hartmann.tk>
|
||||
---
|
||||
src/corelib/io/qnoncontiguousbytedevice.cpp | 18 +++
|
||||
src/corelib/io/qnoncontiguousbytedevice_p.h | 4 +
|
||||
.../access/qhttpnetworkconnectionchannel.cpp | 35 ++++-
|
||||
.../access/qhttpnetworkconnectionchannel_p.h | 2 +
|
||||
src/network/access/qhttpprotocolhandler.cpp | 7 +
|
||||
src/network/access/qhttpthreaddelegate_p.h | 36 ++++-
|
||||
src/network/access/qnetworkreplyhttpimpl.cpp | 25 ++-
|
||||
src/network/access/qnetworkreplyhttpimpl_p.h | 7 +-
|
||||
.../access/qnetworkreply/tst_qnetworkreply.cpp | 175 ++++++++++++++++++++-
|
||||
9 files changed, 279 insertions(+), 30 deletions(-)
|
||||
|
||||
diff --git a/src/corelib/io/qnoncontiguousbytedevice.cpp b/src/corelib/io/qnoncontiguousbytedevice.cpp
|
||||
index 11510a8..760ca3d 100644
|
||||
--- a/src/corelib/io/qnoncontiguousbytedevice.cpp
|
||||
+++ b/src/corelib/io/qnoncontiguousbytedevice.cpp
|
||||
@@ -236,6 +236,11 @@ qint64 QNonContiguousByteDeviceByteArrayImpl::size()
|
||||
return byteArray->size();
|
||||
}
|
||||
|
||||
+qint64 QNonContiguousByteDeviceByteArrayImpl::pos()
|
||||
+{
|
||||
+ return currentPosition;
|
||||
+}
|
||||
+
|
||||
QNonContiguousByteDeviceRingBufferImpl::QNonContiguousByteDeviceRingBufferImpl(QSharedPointer<QRingBuffer> rb)
|
||||
: QNonContiguousByteDevice(), currentPosition(0)
|
||||
{
|
||||
@@ -273,6 +278,11 @@ bool QNonContiguousByteDeviceRingBufferImpl::atEnd()
|
||||
return currentPosition >= size();
|
||||
}
|
||||
|
||||
+qint64 QNonContiguousByteDeviceRingBufferImpl::pos()
|
||||
+{
|
||||
+ return currentPosition;
|
||||
+}
|
||||
+
|
||||
bool QNonContiguousByteDeviceRingBufferImpl::reset()
|
||||
{
|
||||
if (resetDisabled)
|
||||
@@ -406,6 +416,14 @@ qint64 QNonContiguousByteDeviceIoDeviceImpl::size()
|
||||
return device->size() - initialPosition;
|
||||
}
|
||||
|
||||
+qint64 QNonContiguousByteDeviceIoDeviceImpl::pos()
|
||||
+{
|
||||
+ if (device->isSequential())
|
||||
+ return -1;
|
||||
+
|
||||
+ return device->pos();
|
||||
+}
|
||||
+
|
||||
QByteDeviceWrappingIoDevice::QByteDeviceWrappingIoDevice(QNonContiguousByteDevice *bd) : QIODevice((QObject*)0)
|
||||
{
|
||||
byteDevice = bd;
|
||||
diff --git a/src/corelib/io/qnoncontiguousbytedevice_p.h b/src/corelib/io/qnoncontiguousbytedevice_p.h
|
||||
index c05ae11..4d7b7b0 100644
|
||||
--- a/src/corelib/io/qnoncontiguousbytedevice_p.h
|
||||
+++ b/src/corelib/io/qnoncontiguousbytedevice_p.h
|
||||
@@ -61,6 +61,7 @@ public:
|
||||
virtual const char* readPointer(qint64 maximumLength, qint64 &len) = 0;
|
||||
virtual bool advanceReadPointer(qint64 amount) = 0;
|
||||
virtual bool atEnd() = 0;
|
||||
+ virtual qint64 pos() { return -1; }
|
||||
virtual bool reset() = 0;
|
||||
void disableReset();
|
||||
bool isResetDisabled() { return resetDisabled; }
|
||||
@@ -106,6 +107,7 @@ public:
|
||||
bool atEnd();
|
||||
bool reset();
|
||||
qint64 size();
|
||||
+ qint64 pos() Q_DECL_OVERRIDE;
|
||||
protected:
|
||||
QByteArray* byteArray;
|
||||
qint64 currentPosition;
|
||||
@@ -121,6 +123,7 @@ public:
|
||||
bool atEnd();
|
||||
bool reset();
|
||||
qint64 size();
|
||||
+ qint64 pos() Q_DECL_OVERRIDE;
|
||||
protected:
|
||||
QSharedPointer<QRingBuffer> ringBuffer;
|
||||
qint64 currentPosition;
|
||||
@@ -138,6 +141,7 @@ public:
|
||||
bool atEnd();
|
||||
bool reset();
|
||||
qint64 size();
|
||||
+ qint64 pos() Q_DECL_OVERRIDE;
|
||||
protected:
|
||||
QIODevice* device;
|
||||
QByteArray* currentReadBuffer;
|
||||
diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp
|
||||
index 9f63280..49c6793 100644
|
||||
--- a/src/network/access/qhttpnetworkconnectionchannel.cpp
|
||||
+++ b/src/network/access/qhttpnetworkconnectionchannel.cpp
|
||||
@@ -106,15 +106,19 @@ void QHttpNetworkConnectionChannel::init()
|
||||
socket->setProxy(QNetworkProxy::NoProxy);
|
||||
#endif
|
||||
|
||||
+ // We want all signals (except the interactive ones) be connected as QueuedConnection
|
||||
+ // because else we're falling into cases where we recurse back into the socket code
|
||||
+ // and mess up the state. Always going to the event loop (and expecting that when reading/writing)
|
||||
+ // is safer.
|
||||
QObject::connect(socket, SIGNAL(bytesWritten(qint64)),
|
||||
this, SLOT(_q_bytesWritten(qint64)),
|
||||
- Qt::DirectConnection);
|
||||
+ Qt::QueuedConnection);
|
||||
QObject::connect(socket, SIGNAL(connected()),
|
||||
this, SLOT(_q_connected()),
|
||||
- Qt::DirectConnection);
|
||||
+ Qt::QueuedConnection);
|
||||
QObject::connect(socket, SIGNAL(readyRead()),
|
||||
this, SLOT(_q_readyRead()),
|
||||
- Qt::DirectConnection);
|
||||
+ Qt::QueuedConnection);
|
||||
|
||||
// The disconnected() and error() signals may already come
|
||||
// while calling connectToHost().
|
||||
@@ -143,13 +147,13 @@ void QHttpNetworkConnectionChannel::init()
|
||||
// won't be a sslSocket if encrypt is false
|
||||
QObject::connect(sslSocket, SIGNAL(encrypted()),
|
||||
this, SLOT(_q_encrypted()),
|
||||
- Qt::DirectConnection);
|
||||
+ Qt::QueuedConnection);
|
||||
QObject::connect(sslSocket, SIGNAL(sslErrors(QList<QSslError>)),
|
||||
this, SLOT(_q_sslErrors(QList<QSslError>)),
|
||||
Qt::DirectConnection);
|
||||
QObject::connect(sslSocket, SIGNAL(encryptedBytesWritten(qint64)),
|
||||
this, SLOT(_q_encryptedBytesWritten(qint64)),
|
||||
- Qt::DirectConnection);
|
||||
+ Qt::QueuedConnection);
|
||||
|
||||
if (ignoreAllSslErrors)
|
||||
sslSocket->ignoreSslErrors();
|
||||
@@ -186,8 +190,11 @@ void QHttpNetworkConnectionChannel::close()
|
||||
// pendingEncrypt must only be true in between connected and encrypted states
|
||||
pendingEncrypt = false;
|
||||
|
||||
- if (socket)
|
||||
+ if (socket) {
|
||||
+ // socket can be 0 since the host lookup is done from qhttpnetworkconnection.cpp while
|
||||
+ // there is no socket yet.
|
||||
socket->close();
|
||||
+ }
|
||||
}
|
||||
|
||||
|
||||
@@ -353,6 +360,14 @@ bool QHttpNetworkConnectionChannel::ensureConnection()
|
||||
}
|
||||
return false;
|
||||
}
|
||||
+
|
||||
+ // This code path for ConnectedState
|
||||
+ if (pendingEncrypt) {
|
||||
+ // Let's only be really connected when we have received the encrypted() signal. Else the state machine seems to mess up
|
||||
+ // and corrupt the things sent to the server.
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -659,6 +674,12 @@ bool QHttpNetworkConnectionChannel::isSocketReading() const
|
||||
void QHttpNetworkConnectionChannel::_q_bytesWritten(qint64 bytes)
|
||||
{
|
||||
Q_UNUSED(bytes);
|
||||
+ if (ssl) {
|
||||
+ // In the SSL case we want to send data from encryptedBytesWritten signal since that one
|
||||
+ // is the one going down to the actual network, not only into some SSL buffer.
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
// bytes have been written to the socket. write even more of them :)
|
||||
if (isSocketWriting())
|
||||
sendRequest();
|
||||
@@ -734,7 +755,7 @@ void QHttpNetworkConnectionChannel::_q_connected()
|
||||
|
||||
// ### FIXME: if the server closes the connection unexpectedly, we shouldn't send the same broken request again!
|
||||
//channels[i].reconnectAttempts = 2;
|
||||
- if (pendingEncrypt) {
|
||||
+ if (ssl || pendingEncrypt) { // FIXME: Didn't work properly with pendingEncrypt only, we should refactor this into an EncrypingState
|
||||
#ifndef QT_NO_SSL
|
||||
if (connection->sslContext().isNull()) {
|
||||
// this socket is making the 1st handshake for this connection,
|
||||
diff --git a/src/network/access/qhttpnetworkconnectionchannel_p.h b/src/network/access/qhttpnetworkconnectionchannel_p.h
|
||||
index 692c0e6..231fe11 100644
|
||||
--- a/src/network/access/qhttpnetworkconnectionchannel_p.h
|
||||
+++ b/src/network/access/qhttpnetworkconnectionchannel_p.h
|
||||
@@ -83,6 +83,8 @@ typedef QPair<QHttpNetworkRequest, QHttpNetworkReply*> HttpMessagePair;
|
||||
class QHttpNetworkConnectionChannel : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
+ // TODO: Refactor this to add an EncryptingState (and remove pendingEncrypt).
|
||||
+ // Also add an Unconnected state so IdleState does not have double meaning.
|
||||
enum ChannelState {
|
||||
IdleState = 0, // ready to send request
|
||||
ConnectingState = 1, // connecting to host
|
||||
diff --git a/src/network/access/qhttpprotocolhandler.cpp b/src/network/access/qhttpprotocolhandler.cpp
|
||||
index 28e10f7..3357948 100644
|
||||
--- a/src/network/access/qhttpprotocolhandler.cpp
|
||||
+++ b/src/network/access/qhttpprotocolhandler.cpp
|
||||
@@ -368,6 +368,13 @@ bool QHttpProtocolHandler::sendRequest()
|
||||
// nothing to read currently, break the loop
|
||||
break;
|
||||
} else {
|
||||
+ if (m_channel->written != uploadByteDevice->pos()) {
|
||||
+ // Sanity check. This was useful in tracking down an upload corruption.
|
||||
+ qWarning() << "QHttpProtocolHandler: Internal error in sendRequest. Expected to write at position" << m_channel->written << "but read device is at" << uploadByteDevice->pos();
|
||||
+ Q_ASSERT(m_channel->written == uploadByteDevice->pos());
|
||||
+ m_connection->d_func()->emitReplyError(m_socket, m_reply, QNetworkReply::ProtocolFailure);
|
||||
+ return false;
|
||||
+ }
|
||||
qint64 currentWriteSize = m_socket->write(readPointer, currentReadSize);
|
||||
if (currentWriteSize == -1 || currentWriteSize != currentReadSize) {
|
||||
// socket broke down
|
||||
diff --git a/src/network/access/qhttpthreaddelegate_p.h b/src/network/access/qhttpthreaddelegate_p.h
|
||||
index 1661082..b553409 100644
|
||||
--- a/src/network/access/qhttpthreaddelegate_p.h
|
||||
+++ b/src/network/access/qhttpthreaddelegate_p.h
|
||||
@@ -187,6 +187,7 @@ protected:
|
||||
QByteArray m_dataArray;
|
||||
bool m_atEnd;
|
||||
qint64 m_size;
|
||||
+ qint64 m_pos; // to match calls of haveDataSlot with the expected position
|
||||
public:
|
||||
QNonContiguousByteDeviceThreadForwardImpl(bool aE, qint64 s)
|
||||
: QNonContiguousByteDevice(),
|
||||
@@ -194,7 +195,8 @@ public:
|
||||
m_amount(0),
|
||||
m_data(0),
|
||||
m_atEnd(aE),
|
||||
- m_size(s)
|
||||
+ m_size(s),
|
||||
+ m_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -202,6 +204,11 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
+ qint64 pos() Q_DECL_OVERRIDE
|
||||
+ {
|
||||
+ return m_pos;
|
||||
+ }
|
||||
+
|
||||
const char* readPointer(qint64 maximumLength, qint64 &len)
|
||||
{
|
||||
if (m_amount > 0) {
|
||||
@@ -229,11 +236,10 @@ public:
|
||||
|
||||
m_amount -= a;
|
||||
m_data += a;
|
||||
+ m_pos += a;
|
||||
|
||||
- // To main thread to inform about our state
|
||||
- emit processedData(a);
|
||||
-
|
||||
- // FIXME possible optimization, already ask user thread for some data
|
||||
+ // To main thread to inform about our state. The m_pos will be sent as a sanity check.
|
||||
+ emit processedData(m_pos, a);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -250,10 +256,21 @@ public:
|
||||
{
|
||||
m_amount = 0;
|
||||
m_data = 0;
|
||||
+ m_dataArray.clear();
|
||||
+
|
||||
+ if (wantDataPending) {
|
||||
+ // had requested the user thread to send some data (only 1 in-flight at any moment)
|
||||
+ wantDataPending = false;
|
||||
+ }
|
||||
|
||||
// Communicate as BlockingQueuedConnection
|
||||
bool b = false;
|
||||
emit resetData(&b);
|
||||
+ if (b) {
|
||||
+ // the reset succeeded, we're at pos 0 again
|
||||
+ m_pos = 0;
|
||||
+ // the HTTP code will anyway abort the request if !b.
|
||||
+ }
|
||||
return b;
|
||||
}
|
||||
|
||||
@@ -264,8 +281,13 @@ public:
|
||||
|
||||
public slots:
|
||||
// From user thread:
|
||||
- void haveDataSlot(QByteArray dataArray, bool dataAtEnd, qint64 dataSize)
|
||||
+ void haveDataSlot(qint64 pos, QByteArray dataArray, bool dataAtEnd, qint64 dataSize)
|
||||
{
|
||||
+ if (pos != m_pos) {
|
||||
+ // Sometimes when re-sending a request in the qhttpnetwork* layer there is a pending haveData from the
|
||||
+ // user thread on the way to us. We need to ignore it since it is the data for the wrong(later) chunk.
|
||||
+ return;
|
||||
+ }
|
||||
wantDataPending = false;
|
||||
|
||||
m_dataArray = dataArray;
|
||||
@@ -285,7 +307,7 @@ signals:
|
||||
|
||||
// to main thread:
|
||||
void wantData(qint64);
|
||||
- void processedData(qint64);
|
||||
+ void processedData(qint64 pos, qint64 amount);
|
||||
void resetData(bool *b);
|
||||
};
|
||||
|
||||
diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp
|
||||
index 4ce7303..974a101 100644
|
||||
--- a/src/network/access/qnetworkreplyhttpimpl.cpp
|
||||
+++ b/src/network/access/qnetworkreplyhttpimpl.cpp
|
||||
@@ -424,6 +424,7 @@ QNetworkReplyHttpImplPrivate::QNetworkReplyHttpImplPrivate()
|
||||
, synchronous(false)
|
||||
, state(Idle)
|
||||
, statusCode(0)
|
||||
+ , uploadByteDevicePosition(false)
|
||||
, uploadDeviceChoking(false)
|
||||
, outgoingData(0)
|
||||
, bytesUploaded(-1)
|
||||
@@ -863,9 +864,9 @@ void QNetworkReplyHttpImplPrivate::postRequest()
|
||||
q, SLOT(uploadByteDeviceReadyReadSlot()),
|
||||
Qt::QueuedConnection);
|
||||
|
||||
- // From main thread to user thread:
|
||||
- QObject::connect(q, SIGNAL(haveUploadData(QByteArray,bool,qint64)),
|
||||
- forwardUploadDevice, SLOT(haveDataSlot(QByteArray,bool,qint64)), Qt::QueuedConnection);
|
||||
+ // From user thread to http thread:
|
||||
+ QObject::connect(q, SIGNAL(haveUploadData(qint64,QByteArray,bool,qint64)),
|
||||
+ forwardUploadDevice, SLOT(haveDataSlot(qint64,QByteArray,bool,qint64)), Qt::QueuedConnection);
|
||||
QObject::connect(uploadByteDevice.data(), SIGNAL(readyRead()),
|
||||
forwardUploadDevice, SIGNAL(readyRead()),
|
||||
Qt::QueuedConnection);
|
||||
@@ -873,8 +874,8 @@ void QNetworkReplyHttpImplPrivate::postRequest()
|
||||
// From http thread to user thread:
|
||||
QObject::connect(forwardUploadDevice, SIGNAL(wantData(qint64)),
|
||||
q, SLOT(wantUploadDataSlot(qint64)));
|
||||
- QObject::connect(forwardUploadDevice, SIGNAL(processedData(qint64)),
|
||||
- q, SLOT(sentUploadDataSlot(qint64)));
|
||||
+ QObject::connect(forwardUploadDevice,SIGNAL(processedData(qint64, qint64)),
|
||||
+ q, SLOT(sentUploadDataSlot(qint64,qint64)));
|
||||
QObject::connect(forwardUploadDevice, SIGNAL(resetData(bool*)),
|
||||
q, SLOT(resetUploadDataSlot(bool*)),
|
||||
Qt::BlockingQueuedConnection); // this is the only one with BlockingQueued!
|
||||
@@ -1268,12 +1269,22 @@ void QNetworkReplyHttpImplPrivate::replySslConfigurationChanged(const QSslConfig
|
||||
void QNetworkReplyHttpImplPrivate::resetUploadDataSlot(bool *r)
|
||||
{
|
||||
*r = uploadByteDevice->reset();
|
||||
+ if (*r) {
|
||||
+ // reset our own position which is used for the inter-thread communication
|
||||
+ uploadByteDevicePosition = 0;
|
||||
+ }
|
||||
}
|
||||
|
||||
// Coming from QNonContiguousByteDeviceThreadForwardImpl in HTTP thread
|
||||
-void QNetworkReplyHttpImplPrivate::sentUploadDataSlot(qint64 amount)
|
||||
+void QNetworkReplyHttpImplPrivate::sentUploadDataSlot(qint64 pos, qint64 amount)
|
||||
{
|
||||
+ if (uploadByteDevicePosition + amount != pos) {
|
||||
+ // Sanity check, should not happen.
|
||||
+ error(QNetworkReply::UnknownNetworkError, "");
|
||||
+ return;
|
||||
+ }
|
||||
uploadByteDevice->advanceReadPointer(amount);
|
||||
+ uploadByteDevicePosition += amount;
|
||||
}
|
||||
|
||||
// Coming from QNonContiguousByteDeviceThreadForwardImpl in HTTP thread
|
||||
@@ -1298,7 +1309,7 @@ void QNetworkReplyHttpImplPrivate::wantUploadDataSlot(qint64 maxSize)
|
||||
QByteArray dataArray(data, currentUploadDataLength);
|
||||
|
||||
// Communicate back to HTTP thread
|
||||
- emit q->haveUploadData(dataArray, uploadByteDevice->atEnd(), uploadByteDevice->size());
|
||||
+ emit q->haveUploadData(uploadByteDevicePosition, dataArray, uploadByteDevice->atEnd(), uploadByteDevice->size());
|
||||
}
|
||||
|
||||
void QNetworkReplyHttpImplPrivate::uploadByteDeviceReadyReadSlot()
|
||||
diff --git a/src/network/access/qnetworkreplyhttpimpl_p.h b/src/network/access/qnetworkreplyhttpimpl_p.h
|
||||
index 77d9c5a..1940922 100644
|
||||
--- a/src/network/access/qnetworkreplyhttpimpl_p.h
|
||||
+++ b/src/network/access/qnetworkreplyhttpimpl_p.h
|
||||
@@ -120,7 +120,7 @@ public:
|
||||
|
||||
Q_PRIVATE_SLOT(d_func(), void resetUploadDataSlot(bool *r))
|
||||
Q_PRIVATE_SLOT(d_func(), void wantUploadDataSlot(qint64))
|
||||
- Q_PRIVATE_SLOT(d_func(), void sentUploadDataSlot(qint64))
|
||||
+ Q_PRIVATE_SLOT(d_func(), void sentUploadDataSlot(qint64,qint64))
|
||||
Q_PRIVATE_SLOT(d_func(), void uploadByteDeviceReadyReadSlot())
|
||||
Q_PRIVATE_SLOT(d_func(), void emitReplyUploadProgress(qint64, qint64))
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_cacheSaveDeviceAboutToClose())
|
||||
@@ -144,7 +144,7 @@ signals:
|
||||
|
||||
void startHttpRequestSynchronously();
|
||||
|
||||
- void haveUploadData(QByteArray dataArray, bool dataAtEnd, qint64 dataSize);
|
||||
+ void haveUploadData(const qint64 pos, QByteArray dataArray, bool dataAtEnd, qint64 dataSize);
|
||||
};
|
||||
|
||||
class QNetworkReplyHttpImplPrivate: public QNetworkReplyPrivate
|
||||
@@ -195,6 +195,7 @@ public:
|
||||
// upload
|
||||
QNonContiguousByteDevice* createUploadByteDevice();
|
||||
QSharedPointer<QNonContiguousByteDevice> uploadByteDevice;
|
||||
+ qint64 uploadByteDevicePosition;
|
||||
bool uploadDeviceChoking; // if we couldn't readPointer() any data at the moment
|
||||
QIODevice *outgoingData;
|
||||
QSharedPointer<QRingBuffer> outgoingDataBuffer;
|
||||
@@ -283,7 +284,7 @@ public:
|
||||
// From QNonContiguousByteDeviceThreadForwardImpl in HTTP thread:
|
||||
void resetUploadDataSlot(bool *r);
|
||||
void wantUploadDataSlot(qint64);
|
||||
- void sentUploadDataSlot(qint64);
|
||||
+ void sentUploadDataSlot(qint64, qint64);
|
||||
|
||||
// From user's QNonContiguousByteDevice
|
||||
void uploadByteDeviceReadyReadSlot();
|
||||
diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
|
||||
index 3ccedf6..d2edf67 100644
|
||||
--- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
|
||||
+++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
|
||||
@@ -457,6 +457,10 @@ private Q_SLOTS:
|
||||
|
||||
void putWithRateLimiting();
|
||||
|
||||
+#ifndef QT_NO_SSL
|
||||
+ void putWithServerClosingConnectionImmediately();
|
||||
+#endif
|
||||
+
|
||||
// NOTE: This test must be last!
|
||||
void parentingRepliesToTheApp();
|
||||
private:
|
||||
@@ -4718,18 +4722,22 @@ void tst_QNetworkReply::ioPostToHttpNoBufferFlag()
|
||||
class SslServer : public QTcpServer {
|
||||
Q_OBJECT
|
||||
public:
|
||||
- SslServer() : socket(0) {};
|
||||
+ SslServer() : socket(0), m_ssl(true) {}
|
||||
void incomingConnection(qintptr socketDescriptor) {
|
||||
QSslSocket *serverSocket = new QSslSocket;
|
||||
serverSocket->setParent(this);
|
||||
|
||||
if (serverSocket->setSocketDescriptor(socketDescriptor)) {
|
||||
+ connect(serverSocket, SIGNAL(readyRead()), this, SLOT(readyReadSlot()));
|
||||
+ if (!m_ssl) {
|
||||
+ emit newPlainConnection(serverSocket);
|
||||
+ return;
|
||||
+ }
|
||||
QString testDataDir = QFileInfo(QFINDTESTDATA("rfc3252.txt")).absolutePath();
|
||||
if (testDataDir.isEmpty())
|
||||
testDataDir = QCoreApplication::applicationDirPath();
|
||||
|
||||
connect(serverSocket, SIGNAL(encrypted()), this, SLOT(encryptedSlot()));
|
||||
- connect(serverSocket, SIGNAL(readyRead()), this, SLOT(readyReadSlot()));
|
||||
serverSocket->setProtocol(QSsl::AnyProtocol);
|
||||
connect(serverSocket, SIGNAL(sslErrors(QList<QSslError>)), serverSocket, SLOT(ignoreSslErrors()));
|
||||
serverSocket->setLocalCertificate(testDataDir + "/certs/server.pem");
|
||||
@@ -4740,11 +4748,12 @@ public:
|
||||
}
|
||||
}
|
||||
signals:
|
||||
- void newEncryptedConnection();
|
||||
+ void newEncryptedConnection(QSslSocket *s);
|
||||
+ void newPlainConnection(QSslSocket *s);
|
||||
public slots:
|
||||
void encryptedSlot() {
|
||||
socket = (QSslSocket*) sender();
|
||||
- emit newEncryptedConnection();
|
||||
+ emit newEncryptedConnection(socket);
|
||||
}
|
||||
void readyReadSlot() {
|
||||
// for the incoming sockets, not the server socket
|
||||
@@ -4753,6 +4762,7 @@ public slots:
|
||||
|
||||
public:
|
||||
QSslSocket *socket;
|
||||
+ bool m_ssl;
|
||||
};
|
||||
|
||||
// very similar to ioPostToHttpUploadProgress but for SSL
|
||||
@@ -4780,7 +4790,7 @@ void tst_QNetworkReply::ioPostToHttpsUploadProgress()
|
||||
QNetworkReplyPtr reply(manager.post(request, sourceFile));
|
||||
|
||||
QSignalSpy spy(reply.data(), SIGNAL(uploadProgress(qint64,qint64)));
|
||||
- connect(&server, SIGNAL(newEncryptedConnection()), &QTestEventLoop::instance(), SLOT(exitLoop()));
|
||||
+ connect(&server, SIGNAL(newEncryptedConnection(QSslSocket*)), &QTestEventLoop::instance(), SLOT(exitLoop()));
|
||||
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply.data(), SLOT(ignoreSslErrors()));
|
||||
|
||||
// get the request started and the incoming socket connected
|
||||
@@ -4788,7 +4798,7 @@ void tst_QNetworkReply::ioPostToHttpsUploadProgress()
|
||||
QVERIFY(!QTestEventLoop::instance().timeout());
|
||||
QTcpSocket *incomingSocket = server.socket;
|
||||
QVERIFY(incomingSocket);
|
||||
- disconnect(&server, SIGNAL(newEncryptedConnection()), &QTestEventLoop::instance(), SLOT(exitLoop()));
|
||||
+ disconnect(&server, SIGNAL(newEncryptedConnection(QSslSocket*)), &QTestEventLoop::instance(), SLOT(exitLoop()));
|
||||
|
||||
|
||||
incomingSocket->setReadBufferSize(1*1024);
|
||||
@@ -7905,6 +7915,159 @@ void tst_QNetworkReply::putWithRateLimiting()
|
||||
}
|
||||
|
||||
|
||||
+#ifndef QT_NO_SSL
|
||||
+
|
||||
+class PutWithServerClosingConnectionImmediatelyHandler: public QObject
|
||||
+{
|
||||
+ Q_OBJECT
|
||||
+public:
|
||||
+ bool m_parsedHeaders;
|
||||
+ QByteArray m_receivedData;
|
||||
+ QByteArray m_expectedData;
|
||||
+ QSslSocket *m_socket;
|
||||
+ PutWithServerClosingConnectionImmediatelyHandler(QSslSocket *s, QByteArray expected) :m_parsedHeaders(false), m_expectedData(expected), m_socket(s)
|
||||
+ {
|
||||
+ m_socket->setParent(this);
|
||||
+ connect(m_socket, SIGNAL(readyRead()), SLOT(readyReadSlot()));
|
||||
+ connect(m_socket, SIGNAL(disconnected()), SLOT(disconnectedSlot()));
|
||||
+ }
|
||||
+signals:
|
||||
+ void correctFileUploadReceived();
|
||||
+ void corruptFileUploadReceived();
|
||||
+
|
||||
+public slots:
|
||||
+ void closeDelayed() {
|
||||
+ m_socket->close();
|
||||
+ }
|
||||
+
|
||||
+ void readyReadSlot()
|
||||
+ {
|
||||
+ QByteArray data = m_socket->readAll();
|
||||
+ m_receivedData += data;
|
||||
+ if (!m_parsedHeaders && m_receivedData.contains("\r\n\r\n")) {
|
||||
+ m_parsedHeaders = true;
|
||||
+ QTimer::singleShot(qrand()%10, this, SLOT(closeDelayed())); // simulate random network latency
|
||||
+ // This server simulates a web server connection closing, e.g. because of Apaches MaxKeepAliveRequests or KeepAliveTimeout
|
||||
+ // In this case QNAM needs to re-send the upload data but it had a bug which then corrupts the upload
|
||||
+ // This test catches that.
|
||||
+ }
|
||||
+
|
||||
+ }
|
||||
+ void disconnectedSlot()
|
||||
+ {
|
||||
+ if (m_parsedHeaders) {
|
||||
+ //qDebug() << m_receivedData.left(m_receivedData.indexOf("\r\n\r\n"));
|
||||
+ m_receivedData = m_receivedData.mid(m_receivedData.indexOf("\r\n\r\n")+4); // check only actual data
|
||||
+ }
|
||||
+ if (m_receivedData.length() > 0 && !m_expectedData.startsWith(m_receivedData)) {
|
||||
+ // We had received some data but it is corrupt!
|
||||
+ qDebug() << "CORRUPT" << m_receivedData.count();
|
||||
+
|
||||
+ // Use this to track down the pattern of the corruption and conclude the source
|
||||
+// QFile a("/tmp/corrupt");
|
||||
+// a.open(QIODevice::WriteOnly);
|
||||
+// a.write(m_receivedData);
|
||||
+// a.close();
|
||||
+
|
||||
+// QFile b("/tmp/correct");
|
||||
+// b.open(QIODevice::WriteOnly);
|
||||
+// b.write(m_expectedData);
|
||||
+// b.close();
|
||||
+ //exit(1);
|
||||
+ emit corruptFileUploadReceived();
|
||||
+ } else {
|
||||
+ emit correctFileUploadReceived();
|
||||
+ }
|
||||
+ }
|
||||
+};
|
||||
+
|
||||
+class PutWithServerClosingConnectionImmediatelyServer: public SslServer
|
||||
+{
|
||||
+ Q_OBJECT
|
||||
+public:
|
||||
+ int m_correctUploads;
|
||||
+ int m_corruptUploads;
|
||||
+ int m_repliesFinished;
|
||||
+ int m_expectedReplies;
|
||||
+ QByteArray m_expectedData;
|
||||
+ PutWithServerClosingConnectionImmediatelyServer() : SslServer(), m_correctUploads(0), m_corruptUploads(0), m_repliesFinished(0), m_expectedReplies(0)
|
||||
+ {
|
||||
+ QObject::connect(this, SIGNAL(newEncryptedConnection(QSslSocket*)), this, SLOT(createHandlerForConnection(QSslSocket*)));
|
||||
+ QObject::connect(this, SIGNAL(newPlainConnection(QSslSocket*)), this, SLOT(createHandlerForConnection(QSslSocket*)));
|
||||
+ }
|
||||
+
|
||||
+public slots:
|
||||
+ void createHandlerForConnection(QSslSocket* s) {
|
||||
+ PutWithServerClosingConnectionImmediatelyHandler *handler = new PutWithServerClosingConnectionImmediatelyHandler(s, m_expectedData);
|
||||
+ handler->setParent(this);
|
||||
+ QObject::connect(handler, SIGNAL(correctFileUploadReceived()), this, SLOT(increaseCorrect()));
|
||||
+ QObject::connect(handler, SIGNAL(corruptFileUploadReceived()), this, SLOT(increaseCorrupt()));
|
||||
+ }
|
||||
+ void increaseCorrect() {
|
||||
+ m_correctUploads++;
|
||||
+ }
|
||||
+ void increaseCorrupt() {
|
||||
+ m_corruptUploads++;
|
||||
+ }
|
||||
+ void replyFinished() {
|
||||
+ m_repliesFinished++;
|
||||
+ if (m_repliesFinished == m_expectedReplies) {
|
||||
+ QTestEventLoop::instance().exitLoop();
|
||||
+ }
|
||||
+ }
|
||||
+};
|
||||
+
|
||||
+
|
||||
+
|
||||
+void tst_QNetworkReply::putWithServerClosingConnectionImmediately()
|
||||
+{
|
||||
+ const int numUploads = 40;
|
||||
+ qint64 wantedSize = 512*1024; // 512 kB
|
||||
+ QByteArray sourceFile;
|
||||
+ for (int i = 0; i < wantedSize; ++i) {
|
||||
+ sourceFile += (char)'a' +(i%26);
|
||||
+ }
|
||||
+ bool withSsl = false;
|
||||
+
|
||||
+ for (int s = 0; s <= 1; s++) {
|
||||
+ withSsl = (s == 1);
|
||||
+ // Test also needs to run several times because of 9c2ecf89
|
||||
+ for (int j = 0; j < 20; j++) {
|
||||
+ // emulate a minimal https server
|
||||
+ PutWithServerClosingConnectionImmediatelyServer server;
|
||||
+ server.m_ssl = withSsl;
|
||||
+ server.m_expectedData = sourceFile;
|
||||
+ server.m_expectedReplies = numUploads;
|
||||
+ server.listen(QHostAddress(QHostAddress::LocalHost), 0);
|
||||
+
|
||||
+ for (int i = 0; i < numUploads; i++) {
|
||||
+ // create the request
|
||||
+ QUrl url = QUrl(QString("http%1://127.0.0.1:%2/file=%3").arg(withSsl ? "s" : "").arg(server.serverPort()).arg(i));
|
||||
+ QNetworkRequest request(url);
|
||||
+ QNetworkReply *reply = manager.put(request, sourceFile);
|
||||
+ connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply, SLOT(ignoreSslErrors()));
|
||||
+ connect(reply, SIGNAL(finished()), &server, SLOT(replyFinished()));
|
||||
+ reply->setParent(&server);
|
||||
+ }
|
||||
+
|
||||
+ // get the request started and the incoming socket connected
|
||||
+ QTestEventLoop::instance().enterLoop(10);
|
||||
+
|
||||
+ //qDebug() << "correct=" << server.m_correctUploads << "corrupt=" << server.m_corruptUploads << "expected=" <<numUploads;
|
||||
+
|
||||
+ // Sanity check because ecause of 9c2ecf89 most replies will error out but we want to make sure at least some of them worked
|
||||
+ QVERIFY(server.m_correctUploads > 5);
|
||||
+ // Because actually important is that we don't get any corruption:
|
||||
+ QCOMPARE(server.m_corruptUploads, 0);
|
||||
+
|
||||
+ server.close();
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+
|
||||
+}
|
||||
+
|
||||
+#endif
|
||||
|
||||
// NOTE: This test must be last testcase in tst_qnetworkreply!
|
||||
void tst_QNetworkReply::parentingRepliesToTheApp()
|
||||
--
|
||||
1.9.1
|
||||
|
||||
@@ -1,434 +0,0 @@
|
||||
From eae0cb09f1310e755c2aff7c1112f7a6c09d7a53 Mon Sep 17 00:00:00 2001
|
||||
From: Markus Goetz <markus@woboq.com>
|
||||
Date: Fri, 19 Jun 2015 15:35:34 +0200
|
||||
Subject: [PATCH] Network: Fix up previous corruption patch
|
||||
|
||||
This is a fix-up for cff39fba10ffc10ee4dcfdc66ff6528eb26462d3.
|
||||
That patch lead to some internal state issues that lead to the QTBUG-47048
|
||||
or to QNetworkReply objects erroring with "Connection Closed" when
|
||||
the server closed the Keep-Alive connection.
|
||||
|
||||
This patch changes the QNAM socket slot connections to be DirectConnection.
|
||||
We don't close the socket anymore in slots where it is anyway in a closed state
|
||||
afterwards. This prevents event/stack recursions.
|
||||
We also flush QSslSocket/QTcpSocket receive buffers when receiving a disconnect
|
||||
so that the developer always gets the full decrypted data from the buffers.
|
||||
|
||||
[ChangeLog][QtNetwork] Fix HTTP issues with "Unknown Error" and "Connection Closed"
|
||||
[ChangeLog][QtNetwork][Sockets] Read OS/encrypted read buffers when connection
|
||||
closed by server.
|
||||
|
||||
Change-Id: Ib4d6a2d0d988317e3a5356f36e8dbcee4590beed
|
||||
Task-number: QTBUG-47048
|
||||
Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
|
||||
Reviewed-by: Richard J. Moore <rich@kde.org>
|
||||
---
|
||||
src/network/access/qhttpnetworkconnection.cpp | 1 -
|
||||
.../access/qhttpnetworkconnectionchannel.cpp | 108 +++++++++++++--------
|
||||
.../access/qhttpnetworkconnectionchannel_p.h | 1 +
|
||||
src/network/access/qhttpnetworkreply.cpp | 2 +-
|
||||
src/network/access/qhttpprotocolhandler.cpp | 1 -
|
||||
src/network/socket/qabstractsocket.cpp | 7 +-
|
||||
src/network/ssl/qsslsocket.cpp | 8 ++
|
||||
src/network/ssl/qsslsocket_openssl.cpp | 7 ++
|
||||
.../access/qnetworkreply/tst_qnetworkreply.cpp | 9 +-
|
||||
9 files changed, 94 insertions(+), 50 deletions(-)
|
||||
|
||||
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp
|
||||
index 365ce55..543c70e 100644
|
||||
--- a/src/network/access/qhttpnetworkconnection.cpp
|
||||
+++ b/src/network/access/qhttpnetworkconnection.cpp
|
||||
@@ -917,7 +917,6 @@ void QHttpNetworkConnectionPrivate::_q_startNextRequest()
|
||||
for (int i = 0; i < channelCount; ++i) {
|
||||
if (channels[i].resendCurrent && (channels[i].state != QHttpNetworkConnectionChannel::ClosingState)) {
|
||||
channels[i].resendCurrent = false;
|
||||
- channels[i].state = QHttpNetworkConnectionChannel::IdleState;
|
||||
|
||||
// if this is not possible, error will be emitted and connection terminated
|
||||
if (!channels[i].resetUploadData())
|
||||
diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp
|
||||
index 49c6793..e2f6307 100644
|
||||
--- a/src/network/access/qhttpnetworkconnectionchannel.cpp
|
||||
+++ b/src/network/access/qhttpnetworkconnectionchannel.cpp
|
||||
@@ -58,6 +58,11 @@ QT_BEGIN_NAMESPACE
|
||||
|
||||
// TODO: Put channel specific stuff here so it does not polute qhttpnetworkconnection.cpp
|
||||
|
||||
+// Because in-flight when sending a request, the server might close our connection (because the persistent HTTP
|
||||
+// connection times out)
|
||||
+// We use 3 because we can get a _q_error 3 times depending on the timing:
|
||||
+static const int reconnectAttemptsDefault = 3;
|
||||
+
|
||||
QHttpNetworkConnectionChannel::QHttpNetworkConnectionChannel()
|
||||
: socket(0)
|
||||
, ssl(false)
|
||||
@@ -69,7 +74,7 @@ QHttpNetworkConnectionChannel::QHttpNetworkConnectionChannel()
|
||||
, resendCurrent(false)
|
||||
, lastStatus(0)
|
||||
, pendingEncrypt(false)
|
||||
- , reconnectAttempts(2)
|
||||
+ , reconnectAttempts(reconnectAttemptsDefault)
|
||||
, authMethod(QAuthenticatorPrivate::None)
|
||||
, proxyAuthMethod(QAuthenticatorPrivate::None)
|
||||
, authenticationCredentialsSent(false)
|
||||
@@ -106,19 +111,18 @@ void QHttpNetworkConnectionChannel::init()
|
||||
socket->setProxy(QNetworkProxy::NoProxy);
|
||||
#endif
|
||||
|
||||
- // We want all signals (except the interactive ones) be connected as QueuedConnection
|
||||
- // because else we're falling into cases where we recurse back into the socket code
|
||||
- // and mess up the state. Always going to the event loop (and expecting that when reading/writing)
|
||||
- // is safer.
|
||||
+ // After some back and forth in all the last years, this is now a DirectConnection because otherwise
|
||||
+ // the state inside the *Socket classes gets messed up, also in conjunction with the socket notifiers
|
||||
+ // which behave slightly differently on Windows vs Linux
|
||||
QObject::connect(socket, SIGNAL(bytesWritten(qint64)),
|
||||
this, SLOT(_q_bytesWritten(qint64)),
|
||||
- Qt::QueuedConnection);
|
||||
+ Qt::DirectConnection);
|
||||
QObject::connect(socket, SIGNAL(connected()),
|
||||
this, SLOT(_q_connected()),
|
||||
- Qt::QueuedConnection);
|
||||
+ Qt::DirectConnection);
|
||||
QObject::connect(socket, SIGNAL(readyRead()),
|
||||
this, SLOT(_q_readyRead()),
|
||||
- Qt::QueuedConnection);
|
||||
+ Qt::DirectConnection);
|
||||
|
||||
// The disconnected() and error() signals may already come
|
||||
// while calling connectToHost().
|
||||
@@ -129,10 +133,10 @@ void QHttpNetworkConnectionChannel::init()
|
||||
qRegisterMetaType<QAbstractSocket::SocketError>();
|
||||
QObject::connect(socket, SIGNAL(disconnected()),
|
||||
this, SLOT(_q_disconnected()),
|
||||
- Qt::QueuedConnection);
|
||||
+ Qt::DirectConnection);
|
||||
QObject::connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),
|
||||
this, SLOT(_q_error(QAbstractSocket::SocketError)),
|
||||
- Qt::QueuedConnection);
|
||||
+ Qt::DirectConnection);
|
||||
|
||||
|
||||
#ifndef QT_NO_NETWORKPROXY
|
||||
@@ -147,13 +151,13 @@ void QHttpNetworkConnectionChannel::init()
|
||||
// won't be a sslSocket if encrypt is false
|
||||
QObject::connect(sslSocket, SIGNAL(encrypted()),
|
||||
this, SLOT(_q_encrypted()),
|
||||
- Qt::QueuedConnection);
|
||||
+ Qt::DirectConnection);
|
||||
QObject::connect(sslSocket, SIGNAL(sslErrors(QList<QSslError>)),
|
||||
this, SLOT(_q_sslErrors(QList<QSslError>)),
|
||||
Qt::DirectConnection);
|
||||
QObject::connect(sslSocket, SIGNAL(encryptedBytesWritten(qint64)),
|
||||
this, SLOT(_q_encryptedBytesWritten(qint64)),
|
||||
- Qt::QueuedConnection);
|
||||
+ Qt::DirectConnection);
|
||||
|
||||
if (ignoreAllSslErrors)
|
||||
sslSocket->ignoreSslErrors();
|
||||
@@ -397,7 +401,7 @@ void QHttpNetworkConnectionChannel::allDone()
|
||||
|
||||
// reset the reconnection attempts after we receive a complete reply.
|
||||
// in case of failures, each channel will attempt two reconnects before emitting error.
|
||||
- reconnectAttempts = 2;
|
||||
+ reconnectAttempts = reconnectAttemptsDefault;
|
||||
|
||||
// now the channel can be seen as free/idle again, all signal emissions for the reply have been done
|
||||
if (state != QHttpNetworkConnectionChannel::ClosingState)
|
||||
@@ -651,6 +655,15 @@ void QHttpNetworkConnectionChannel::closeAndResendCurrentRequest()
|
||||
QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
+void QHttpNetworkConnectionChannel::resendCurrentRequest()
|
||||
+{
|
||||
+ requeueCurrentlyPipelinedRequests();
|
||||
+ if (reply)
|
||||
+ resendCurrent = true;
|
||||
+ if (qobject_cast<QHttpNetworkConnection*>(connection))
|
||||
+ QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
|
||||
+}
|
||||
+
|
||||
bool QHttpNetworkConnectionChannel::isSocketBusy() const
|
||||
{
|
||||
return (state & QHttpNetworkConnectionChannel::BusyState);
|
||||
@@ -694,8 +707,8 @@ void QHttpNetworkConnectionChannel::_q_disconnected()
|
||||
return;
|
||||
}
|
||||
|
||||
- // read the available data before closing
|
||||
- if (isSocketWaiting() || isSocketReading()) {
|
||||
+ // read the available data before closing (also done in _q_error for other codepaths)
|
||||
+ if ((isSocketWaiting() || isSocketReading()) && socket->bytesAvailable()) {
|
||||
if (reply) {
|
||||
state = QHttpNetworkConnectionChannel::ReadingState;
|
||||
_q_receiveReply();
|
||||
@@ -707,7 +720,8 @@ void QHttpNetworkConnectionChannel::_q_disconnected()
|
||||
state = QHttpNetworkConnectionChannel::IdleState;
|
||||
|
||||
requeueCurrentlyPipelinedRequests();
|
||||
- close();
|
||||
+
|
||||
+ pendingEncrypt = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -789,11 +803,19 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket
|
||||
errorCode = QNetworkReply::ConnectionRefusedError;
|
||||
break;
|
||||
case QAbstractSocket::RemoteHostClosedError:
|
||||
- // try to reconnect/resend before sending an error.
|
||||
- // while "Reading" the _q_disconnected() will handle this.
|
||||
- if (state != QHttpNetworkConnectionChannel::IdleState && state != QHttpNetworkConnectionChannel::ReadingState) {
|
||||
+ // This error for SSL comes twice in a row, first from SSL layer ("The TLS/SSL connection has been closed") then from TCP layer.
|
||||
+ // Depending on timing it can also come three times in a row (first time when we try to write into a closing QSslSocket).
|
||||
+ // The reconnectAttempts handling catches the cases where we can re-send the request.
|
||||
+ if (!reply && state == QHttpNetworkConnectionChannel::IdleState) {
|
||||
+ // Not actually an error, it is normal for Keep-Alive connections to close after some time if no request
|
||||
+ // is sent on them. No need to error the other replies below. Just bail out here.
|
||||
+ // The _q_disconnected will handle the possibly pipelined replies
|
||||
+ return;
|
||||
+ } else if (state != QHttpNetworkConnectionChannel::IdleState && state != QHttpNetworkConnectionChannel::ReadingState) {
|
||||
+ // Try to reconnect/resend before sending an error.
|
||||
+ // While "Reading" the _q_disconnected() will handle this.
|
||||
if (reconnectAttempts-- > 0) {
|
||||
- closeAndResendCurrentRequest();
|
||||
+ resendCurrentRequest();
|
||||
return;
|
||||
} else {
|
||||
errorCode = QNetworkReply::RemoteHostClosedError;
|
||||
@@ -818,24 +840,15 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket
|
||||
// we can ignore the readbuffersize as the data is already
|
||||
// in memory and we will not receive more data on the socket.
|
||||
reply->setReadBufferSize(0);
|
||||
+ reply->setDownstreamLimited(false);
|
||||
_q_receiveReply();
|
||||
-#ifndef QT_NO_SSL
|
||||
- if (ssl) {
|
||||
- // QT_NO_OPENSSL. The QSslSocket can still have encrypted bytes in the plainsocket.
|
||||
- // So we need to check this if the socket is a QSslSocket. When the socket is flushed
|
||||
- // it will force a decrypt of the encrypted data in the plainsocket.
|
||||
- QSslSocket *sslSocket = static_cast<QSslSocket*>(socket);
|
||||
- qint64 beforeFlush = sslSocket->encryptedBytesAvailable();
|
||||
- while (sslSocket->encryptedBytesAvailable()) {
|
||||
- sslSocket->flush();
|
||||
- _q_receiveReply();
|
||||
- qint64 afterFlush = sslSocket->encryptedBytesAvailable();
|
||||
- if (afterFlush == beforeFlush)
|
||||
- break;
|
||||
- beforeFlush = afterFlush;
|
||||
- }
|
||||
+ if (!reply) {
|
||||
+ // No more reply assigned after the previous call? Then it had been finished successfully.
|
||||
+ requeueCurrentlyPipelinedRequests();
|
||||
+ state = QHttpNetworkConnectionChannel::IdleState;
|
||||
+ QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
|
||||
+ return;
|
||||
}
|
||||
-#endif
|
||||
}
|
||||
|
||||
errorCode = QNetworkReply::RemoteHostClosedError;
|
||||
@@ -846,7 +859,7 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket
|
||||
case QAbstractSocket::SocketTimeoutError:
|
||||
// try to reconnect/resend before sending an error.
|
||||
if (state == QHttpNetworkConnectionChannel::WritingState && (reconnectAttempts-- > 0)) {
|
||||
- closeAndResendCurrentRequest();
|
||||
+ resendCurrentRequest();
|
||||
return;
|
||||
}
|
||||
errorCode = QNetworkReply::TimeoutError;
|
||||
@@ -860,7 +873,7 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket
|
||||
case QAbstractSocket::ProxyConnectionClosedError:
|
||||
// try to reconnect/resend before sending an error.
|
||||
if (reconnectAttempts-- > 0) {
|
||||
- closeAndResendCurrentRequest();
|
||||
+ resendCurrentRequest();
|
||||
return;
|
||||
}
|
||||
errorCode = QNetworkReply::ProxyConnectionClosedError;
|
||||
@@ -868,7 +881,7 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket
|
||||
case QAbstractSocket::ProxyConnectionTimeoutError:
|
||||
// try to reconnect/resend before sending an error.
|
||||
if (reconnectAttempts-- > 0) {
|
||||
- closeAndResendCurrentRequest();
|
||||
+ resendCurrentRequest();
|
||||
return;
|
||||
}
|
||||
errorCode = QNetworkReply::ProxyTimeoutError;
|
||||
@@ -916,8 +929,18 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket
|
||||
// send the next request
|
||||
QMetaObject::invokeMethod(that, "_q_startNextRequest", Qt::QueuedConnection);
|
||||
|
||||
- if (that) //signal emission triggered event loop
|
||||
- close();
|
||||
+ if (that) {
|
||||
+ //signal emission triggered event loop
|
||||
+ if (!socket)
|
||||
+ state = QHttpNetworkConnectionChannel::IdleState;
|
||||
+ else if (socket->state() == QAbstractSocket::UnconnectedState)
|
||||
+ state = QHttpNetworkConnectionChannel::IdleState;
|
||||
+ else
|
||||
+ state = QHttpNetworkConnectionChannel::ClosingState;
|
||||
+
|
||||
+ // pendingEncrypt must only be true in between connected and encrypted states
|
||||
+ pendingEncrypt = false;
|
||||
+ }
|
||||
}
|
||||
|
||||
#ifndef QT_NO_NETWORKPROXY
|
||||
@@ -941,7 +964,8 @@ void QHttpNetworkConnectionChannel::_q_proxyAuthenticationRequired(const QNetwor
|
||||
|
||||
void QHttpNetworkConnectionChannel::_q_uploadDataReadyRead()
|
||||
{
|
||||
- sendRequest();
|
||||
+ if (reply)
|
||||
+ sendRequest();
|
||||
}
|
||||
|
||||
#ifndef QT_NO_SSL
|
||||
diff --git a/src/network/access/qhttpnetworkconnectionchannel_p.h b/src/network/access/qhttpnetworkconnectionchannel_p.h
|
||||
index 231fe11..a834b7d 100644
|
||||
--- a/src/network/access/qhttpnetworkconnectionchannel_p.h
|
||||
+++ b/src/network/access/qhttpnetworkconnectionchannel_p.h
|
||||
@@ -169,6 +169,7 @@ public:
|
||||
|
||||
void handleUnexpectedEOF();
|
||||
void closeAndResendCurrentRequest();
|
||||
+ void resendCurrentRequest();
|
||||
|
||||
bool isSocketBusy() const;
|
||||
bool isSocketWriting() const;
|
||||
diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp
|
||||
index 55863a3..8b71bd8 100644
|
||||
--- a/src/network/access/qhttpnetworkreply.cpp
|
||||
+++ b/src/network/access/qhttpnetworkreply.cpp
|
||||
@@ -191,7 +191,7 @@ QByteArray QHttpNetworkReply::readAny()
|
||||
return QByteArray();
|
||||
|
||||
// we'll take the last buffer, so schedule another read from http
|
||||
- if (d->downstreamLimited && d->responseData.bufferCount() == 1)
|
||||
+ if (d->downstreamLimited && d->responseData.bufferCount() == 1 && !isFinished())
|
||||
d->connection->d_func()->readMoreLater(this);
|
||||
return d->responseData.read();
|
||||
}
|
||||
diff --git a/src/network/access/qhttpprotocolhandler.cpp b/src/network/access/qhttpprotocolhandler.cpp
|
||||
index 3357948..380aaac 100644
|
||||
--- a/src/network/access/qhttpprotocolhandler.cpp
|
||||
+++ b/src/network/access/qhttpprotocolhandler.cpp
|
||||
@@ -250,7 +250,6 @@ bool QHttpProtocolHandler::sendRequest()
|
||||
if (!m_reply) {
|
||||
// heh, how should that happen!
|
||||
qWarning() << "QAbstractProtocolHandler::sendRequest() called without QHttpNetworkReply";
|
||||
- m_channel->state = QHttpNetworkConnectionChannel::IdleState;
|
||||
return false;
|
||||
}
|
||||
|
||||
diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp
|
||||
index 2666771..0e82d4a 100644
|
||||
--- a/src/network/socket/qabstractsocket.cpp
|
||||
+++ b/src/network/socket/qabstractsocket.cpp
|
||||
@@ -768,6 +768,7 @@ bool QAbstractSocketPrivate::canReadNotification()
|
||||
void QAbstractSocketPrivate::canCloseNotification()
|
||||
{
|
||||
Q_Q(QAbstractSocket);
|
||||
+ // Note that this method is only called on Windows. Other platforms close in the canReadNotification()
|
||||
|
||||
#if defined (QABSTRACTSOCKET_DEBUG)
|
||||
qDebug("QAbstractSocketPrivate::canCloseNotification()");
|
||||
@@ -777,7 +778,11 @@ void QAbstractSocketPrivate::canCloseNotification()
|
||||
if (isBuffered) {
|
||||
// Try to read to the buffer, if the read fail we can close the socket.
|
||||
newBytes = buffer.size();
|
||||
- if (!readFromSocket()) {
|
||||
+ qint64 oldReadBufferMaxSize = readBufferMaxSize;
|
||||
+ readBufferMaxSize = 0; // temporarily disable max read buffer, we want to empty the OS buffer
|
||||
+ bool hadReadFromSocket = readFromSocket();
|
||||
+ readBufferMaxSize = oldReadBufferMaxSize;
|
||||
+ if (!hadReadFromSocket) {
|
||||
q->disconnectFromHost();
|
||||
return;
|
||||
}
|
||||
diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp
|
||||
index c1fab94..2b9e923 100644
|
||||
--- a/src/network/ssl/qsslsocket.cpp
|
||||
+++ b/src/network/ssl/qsslsocket.cpp
|
||||
@@ -2294,6 +2294,14 @@ void QSslSocketPrivate::_q_errorSlot(QAbstractSocket::SocketError error)
|
||||
qCDebug(lcSsl) << "\tstate =" << q->state();
|
||||
qCDebug(lcSsl) << "\terrorString =" << q->errorString();
|
||||
#endif
|
||||
+ // this moves encrypted bytes from plain socket into our buffer
|
||||
+ if (plainSocket->bytesAvailable()) {
|
||||
+ qint64 tmpReadBufferMaxSize = readBufferMaxSize;
|
||||
+ readBufferMaxSize = 0; // reset temporarily so the plain sockets completely drained drained
|
||||
+ transmit();
|
||||
+ readBufferMaxSize = tmpReadBufferMaxSize;
|
||||
+ }
|
||||
+
|
||||
q->setSocketError(plainSocket->error());
|
||||
q->setErrorString(plainSocket->errorString());
|
||||
emit q->error(error);
|
||||
diff --git a/src/network/ssl/qsslsocket_openssl.cpp b/src/network/ssl/qsslsocket_openssl.cpp
|
||||
index ac4336a..94655fe 100644
|
||||
--- a/src/network/ssl/qsslsocket_openssl.cpp
|
||||
+++ b/src/network/ssl/qsslsocket_openssl.cpp
|
||||
@@ -1419,6 +1419,13 @@ void QSslSocketBackendPrivate::disconnected()
|
||||
{
|
||||
if (plainSocket->bytesAvailable() <= 0)
|
||||
destroySslContext();
|
||||
+ else {
|
||||
+ // Move all bytes into the plain buffer
|
||||
+ qint64 tmpReadBufferMaxSize = readBufferMaxSize;
|
||||
+ readBufferMaxSize = 0; // reset temporarily so the plain socket buffer is completely drained
|
||||
+ transmit();
|
||||
+ readBufferMaxSize = tmpReadBufferMaxSize;
|
||||
+ }
|
||||
//if there is still buffered data in the plain socket, don't destroy the ssl context yet.
|
||||
//it will be destroyed when the socket is deleted.
|
||||
}
|
||||
diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
|
||||
index d2edf67..138f528 100644
|
||||
--- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
|
||||
+++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
|
||||
@@ -1051,7 +1051,7 @@ protected:
|
||||
// clean up QAbstractSocket's residue:
|
||||
while (client->bytesToWrite() > 0) {
|
||||
qDebug() << "Still having" << client->bytesToWrite() << "bytes to write, doing that now";
|
||||
- if (!client->waitForBytesWritten(2000)) {
|
||||
+ if (!client->waitForBytesWritten(10000)) {
|
||||
qDebug() << "ERROR: FastSender:" << client->error() << "cleaning up residue";
|
||||
return;
|
||||
}
|
||||
@@ -1071,7 +1071,7 @@ protected:
|
||||
measuredSentBytes += writeNextData(client, bytesToWrite);
|
||||
|
||||
while (client->bytesToWrite() > 0) {
|
||||
- if (!client->waitForBytesWritten(2000)) {
|
||||
+ if (!client->waitForBytesWritten(10000)) {
|
||||
qDebug() << "ERROR: FastSender:" << client->error() << "during blocking write";
|
||||
return;
|
||||
}
|
||||
@@ -7946,7 +7946,7 @@ public slots:
|
||||
m_receivedData += data;
|
||||
if (!m_parsedHeaders && m_receivedData.contains("\r\n\r\n")) {
|
||||
m_parsedHeaders = true;
|
||||
- QTimer::singleShot(qrand()%10, this, SLOT(closeDelayed())); // simulate random network latency
|
||||
+ QTimer::singleShot(qrand()%60, this, SLOT(closeDelayed())); // simulate random network latency
|
||||
// This server simulates a web server connection closing, e.g. because of Apaches MaxKeepAliveRequests or KeepAliveTimeout
|
||||
// In this case QNAM needs to re-send the upload data but it had a bug which then corrupts the upload
|
||||
// This test catches that.
|
||||
@@ -8052,11 +8052,12 @@ void tst_QNetworkReply::putWithServerClosingConnectionImmediately()
|
||||
|
||||
// get the request started and the incoming socket connected
|
||||
QTestEventLoop::instance().enterLoop(10);
|
||||
+ QVERIFY(!QTestEventLoop::instance().timeout());
|
||||
|
||||
//qDebug() << "correct=" << server.m_correctUploads << "corrupt=" << server.m_corruptUploads << "expected=" <<numUploads;
|
||||
|
||||
// Sanity check because ecause of 9c2ecf89 most replies will error out but we want to make sure at least some of them worked
|
||||
- QVERIFY(server.m_correctUploads > 5);
|
||||
+ QVERIFY(server.m_correctUploads > 2);
|
||||
// Because actually important is that we don't get any corruption:
|
||||
QCOMPARE(server.m_corruptUploads, 0);
|
||||
|
||||
--
|
||||
1.9.1
|
||||
@@ -1,64 +0,0 @@
|
||||
From bc32c0ebc0bc00db84ca2f28eb16ab2e5b53a1b6 Mon Sep 17 00:00:00 2001
|
||||
From: Markus Goetz <markus@woboq.com>
|
||||
Date: Fri, 24 Jul 2015 09:53:20 +0200
|
||||
Subject: [PATCH] QNAM: Fix reply deadlocks on server closing connection
|
||||
|
||||
The _q_readyRead can also be called from readMoreLater() because we implemented
|
||||
it so that bandwidth limited reading can be implemented.
|
||||
This can lead to a race condition if the socket is closing at the specific moment
|
||||
and then deadlock the channel: It will stay unusable with a zombie request.
|
||||
The fix in QHttpProtocolaHandler checks if there is actually bytes available to read
|
||||
from the socket and only then continue.
|
||||
|
||||
The fix in the HTTP channel needs to be done to properly finish the reply in
|
||||
cases of a server replying with HTTP/1.0 or "Connection: close".
|
||||
The delayed incovation of _q_receiveReply will properly finish up the reply.
|
||||
|
||||
Change-Id: I19ce2ae595f91d56386cc7406ccacc9935672b6b
|
||||
Reviewed-by: Richard J. Moore <rich@kde.org>
|
||||
---
|
||||
src/network/access/qhttpnetworkconnectionchannel.cpp | 4 ++++
|
||||
src/network/access/qhttpprotocolhandler.cpp | 7 ++++++-
|
||||
2 files changed, 10 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp
|
||||
index 7428f9b..257aa13 100644
|
||||
--- a/src/network/access/qhttpnetworkconnectionchannel.cpp
|
||||
+++ b/src/network/access/qhttpnetworkconnectionchannel.cpp
|
||||
@@ -829,11 +829,15 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket
|
||||
|
||||
if (!reply->d_func()->expectContent()) {
|
||||
// No content expected, this is a valid way to have the connection closed by the server
|
||||
+ // We need to invoke this asynchronously to make sure the state() of the socket is on QAbstractSocket::UnconnectedState
|
||||
+ QMetaObject::invokeMethod(this, "_q_receiveReply", Qt::QueuedConnection);
|
||||
return;
|
||||
}
|
||||
if (reply->contentLength() == -1 && !reply->d_func()->isChunked()) {
|
||||
// There was no content-length header and it's not chunked encoding,
|
||||
// so this is a valid way to have the connection closed by the server
|
||||
+ // We need to invoke this asynchronously to make sure the state() of the socket is on QAbstractSocket::UnconnectedState
|
||||
+ QMetaObject::invokeMethod(this, "_q_receiveReply", Qt::QueuedConnection);
|
||||
return;
|
||||
}
|
||||
// ok, we got a disconnect even though we did not expect it
|
||||
diff --git a/src/network/access/qhttpprotocolhandler.cpp b/src/network/access/qhttpprotocolhandler.cpp
|
||||
index ab2e3da..a208315 100644
|
||||
--- a/src/network/access/qhttpprotocolhandler.cpp
|
||||
+++ b/src/network/access/qhttpprotocolhandler.cpp
|
||||
@@ -237,7 +237,12 @@ void QHttpProtocolHandler::_q_readyRead()
|
||||
}
|
||||
|
||||
if (m_channel->isSocketWaiting() || m_channel->isSocketReading()) {
|
||||
- m_channel->state = QHttpNetworkConnectionChannel::ReadingState;
|
||||
+ if (m_socket->bytesAvailable()) {
|
||||
+ // We might get a spurious call from readMoreLater()
|
||||
+ // call of the QHttpNetworkConnection even while the socket is disconnecting.
|
||||
+ // Therefore check if there is actually bytes available before changing the channel state.
|
||||
+ m_channel->state = QHttpNetworkConnectionChannel::ReadingState;
|
||||
+ }
|
||||
if (m_reply)
|
||||
_q_receiveReply();
|
||||
}
|
||||
--
|
||||
1.9.1
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
From 63cf5d3d26a6f65938c3cdec1734eac9faaaf8cb Mon Sep 17 00:00:00 2001
|
||||
From: Markus Goetz <markus@woboq.com>
|
||||
Date: Tue, 22 Sep 2015 14:26:24 -0400
|
||||
Subject: [PATCH] QNAM: Assign proper channel before sslErrors() emission
|
||||
|
||||
There can be a race condition where another channel connects
|
||||
and gets the sslErrors() from the socket first. Then the
|
||||
QSslConfiguration from the wrong socket (the default
|
||||
channel 0's socket) was used.
|
||||
|
||||
Task-number: QTBUG-18722
|
||||
Change-Id: Ibbfa48c27f181563745daf540fa792a57cc09682
|
||||
Reviewed-by: Richard J. Moore <rich@kde.org>
|
||||
---
|
||||
src/network/access/qhttpnetworkconnectionchannel.cpp | 2 ++
|
||||
1 file changed, 2 insertions(+)
|
||||
|
||||
diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp
|
||||
index 257aa13..477cba2 100644
|
||||
--- a/src/network/access/qhttpnetworkconnectionchannel.cpp
|
||||
+++ b/src/network/access/qhttpnetworkconnectionchannel.cpp
|
||||
@@ -1066,6 +1066,8 @@ void QHttpNetworkConnectionChannel::_q_sslErrors(const QList<QSslError> &errors)
|
||||
connection->d_func()->pauseConnection();
|
||||
if (pendingEncrypt && !reply)
|
||||
connection->d_func()->dequeueRequest(socket);
|
||||
+ if (reply) // a reply was actually dequeued.
|
||||
+ reply->d_func()->connectionChannel = this; // set correct channel like in sendRequest() and queueRequest();
|
||||
if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP) {
|
||||
if (reply)
|
||||
emit reply->sslErrors(errors);
|
||||
--
|
||||
1.9.1
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
From 0df5d079290b4c3b13e58e9397fabdc1dfdba96b Mon Sep 17 00:00:00 2001
|
||||
From: Ulf Hermann <ulf.hermann@theqtcompany.com>
|
||||
Date: Fri, 25 Sep 2015 13:23:46 +0200
|
||||
Subject: [PATCH] Don't let closed http sockets pass as valid connections
|
||||
|
||||
A QAbstractSocket can be close()'d at any time, independently of its
|
||||
current connection state. being closed means that we cannot use it to
|
||||
read or write data, but internally it might still have some data to
|
||||
send or receive, for example to an http server. We can even get a
|
||||
connected() signal after close()'ing the socket.
|
||||
|
||||
We need to catch this condition and mark any pending data not yet
|
||||
written to the socket for resending.
|
||||
|
||||
Task-number: QTBUG-48326
|
||||
Change-Id: I6f61c35f2c567f2a138f8cfe9ade7fd1ec039be6
|
||||
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
|
||||
---
|
||||
.../access/qhttpnetworkconnectionchannel.cpp | 7 ++-
|
||||
.../tst_qhttpnetworkconnection.cpp | 54 ++++++++++++++++++++++
|
||||
2 files changed, 60 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp
|
||||
index 293909c..b4eda34 100644
|
||||
--- a/src/network/access/qhttpnetworkconnectionchannel.cpp
|
||||
+++ b/src/network/access/qhttpnetworkconnectionchannel.cpp
|
||||
@@ -272,7 +272,12 @@ bool QHttpNetworkConnectionChannel::ensureConnection()
|
||||
QAbstractSocket::SocketState socketState = socket->state();
|
||||
|
||||
// resend this request after we receive the disconnected signal
|
||||
- if (socketState == QAbstractSocket::ClosingState) {
|
||||
+ // If !socket->isOpen() then we have already called close() on the socket, but there was still a
|
||||
+ // pending connectToHost() for which we hadn't seen a connected() signal, yet. The connected()
|
||||
+ // has now arrived (as indicated by socketState != ClosingState), but we cannot send anything on
|
||||
+ // such a socket anymore.
|
||||
+ if (socketState == QAbstractSocket::ClosingState ||
|
||||
+ (socketState != QAbstractSocket::UnconnectedState && !socket->isOpen())) {
|
||||
if (reply)
|
||||
resendCurrent = true;
|
||||
return false;
|
||||
diff --git a/tests/auto/network/access/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp b/tests/auto/network/access/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
|
||||
index 5d072af..0d188a8 100644
|
||||
--- a/tests/auto/network/access/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
|
||||
+++ b/tests/auto/network/access/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "private/qhttpnetworkconnection_p.h"
|
||||
#include "private/qnoncontiguousbytedevice_p.h"
|
||||
#include <QAuthenticator>
|
||||
+#include <QTcpServer>
|
||||
|
||||
#include "../../../network-settings.h"
|
||||
|
||||
@@ -106,6 +107,8 @@ private Q_SLOTS:
|
||||
|
||||
void getAndThenDeleteObject();
|
||||
void getAndThenDeleteObject_data();
|
||||
+
|
||||
+ void overlappingCloseAndWrite();
|
||||
};
|
||||
|
||||
tst_QHttpNetworkConnection::tst_QHttpNetworkConnection()
|
||||
@@ -1112,6 +1115,57 @@ void tst_QHttpNetworkConnection::getAndThenDeleteObject()
|
||||
}
|
||||
}
|
||||
|
||||
+class TestTcpServer : public QTcpServer
|
||||
+{
|
||||
+ Q_OBJECT
|
||||
+public:
|
||||
+ TestTcpServer() : errorCodeReports(0)
|
||||
+ {
|
||||
+ connect(this, &QTcpServer::newConnection, this, &TestTcpServer::onNewConnection);
|
||||
+ QVERIFY(listen(QHostAddress::LocalHost));
|
||||
+ }
|
||||
+
|
||||
+ int errorCodeReports;
|
||||
+
|
||||
+public slots:
|
||||
+ void onNewConnection()
|
||||
+ {
|
||||
+ QTcpSocket *socket = nextPendingConnection();
|
||||
+ if (!socket)
|
||||
+ return;
|
||||
+ // close socket instantly!
|
||||
+ connect(socket, &QTcpSocket::readyRead, socket, &QTcpSocket::close);
|
||||
+ }
|
||||
+
|
||||
+ void onReply(QNetworkReply::NetworkError code)
|
||||
+ {
|
||||
+ QCOMPARE(code, QNetworkReply::RemoteHostClosedError);
|
||||
+ ++errorCodeReports;
|
||||
+ }
|
||||
+};
|
||||
+
|
||||
+void tst_QHttpNetworkConnection::overlappingCloseAndWrite()
|
||||
+{
|
||||
+ // server accepts connections, but closes the socket instantly
|
||||
+ TestTcpServer server;
|
||||
+ QNetworkAccessManager accessManager;
|
||||
+
|
||||
+ // ten requests are scheduled. All should result in an RemoteHostClosed...
|
||||
+ QUrl url;
|
||||
+ url.setScheme(QStringLiteral("http"));
|
||||
+ url.setHost(server.serverAddress().toString());
|
||||
+ url.setPort(server.serverPort());
|
||||
+ for (int i = 0; i < 10; ++i) {
|
||||
+ QNetworkRequest request(url);
|
||||
+ QNetworkReply *reply = accessManager.get(request);
|
||||
+ // Not using Qt5 connection syntax here because of overly baroque syntax to discern between
|
||||
+ // different error() methods.
|
||||
+ QObject::connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
|
||||
+ &server, SLOT(onReply(QNetworkReply::NetworkError)));
|
||||
+ }
|
||||
+
|
||||
+ QTRY_COMPARE(server.errorCodeReports, 10);
|
||||
+}
|
||||
|
||||
|
||||
QTEST_MAIN(tst_QHttpNetworkConnection)
|
||||
--
|
||||
1.9.1
|
||||
@@ -1,113 +0,0 @@
|
||||
From c056e63cea1915667997c982f48296ce5acdcc80 Mon Sep 17 00:00:00 2001
|
||||
From: Lorn Potter <lorn.potter@gmail.com>
|
||||
Date: Tue, 2 Jun 2015 13:22:23 +1000
|
||||
Subject: [PATCH] Make sure to report correct NetworkAccessibility
|
||||
|
||||
Task-number: QTBUG-46323
|
||||
Change-Id: Ibdeb3280091a97d785d4314340678a63e88fb219
|
||||
Reviewed-by: Markus Goetz (Woboq GmbH) <markus@woboq.com>
|
||||
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
|
||||
---
|
||||
src/network/access/qnetworkaccessmanager.cpp | 25 +++++++++++++++++--------
|
||||
src/network/access/qnetworkaccessmanager_p.h | 2 ++
|
||||
2 files changed, 19 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
|
||||
index e878feb..84931cb 100644
|
||||
--- a/src/network/access/qnetworkaccessmanager.cpp
|
||||
+++ b/src/network/access/qnetworkaccessmanager.cpp
|
||||
@@ -472,11 +472,11 @@ QNetworkAccessManager::QNetworkAccessManager(QObject *parent)
|
||||
// the QNetworkSession's signals
|
||||
connect(&d->networkConfigurationManager, SIGNAL(onlineStateChanged(bool)),
|
||||
SLOT(_q_onlineStateChanged(bool)));
|
||||
- // we would need all active configurations to check for
|
||||
- // d->networkConfigurationManager.isOnline(), which is asynchronous
|
||||
- // and potentially expensive. We can just check the configuration here
|
||||
- d->online = (d->networkConfiguration.state() & QNetworkConfiguration::Active);
|
||||
}
|
||||
+ // we would need all active configurations to check for
|
||||
+ // d->networkConfigurationManager.isOnline(), which is asynchronous
|
||||
+ // and potentially expensive. We can just check the configuration here
|
||||
+ d->online = (d->networkConfiguration.state() & QNetworkConfiguration::Active);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -946,6 +946,7 @@ QNetworkConfiguration QNetworkAccessManager::activeConfiguration() const
|
||||
void QNetworkAccessManager::setNetworkAccessible(QNetworkAccessManager::NetworkAccessibility accessible)
|
||||
{
|
||||
Q_D(QNetworkAccessManager);
|
||||
+ d->defaultAccessControl = false;
|
||||
|
||||
if (d->networkAccessible != accessible) {
|
||||
NetworkAccessibility previous = networkAccessible();
|
||||
@@ -964,7 +965,6 @@ void QNetworkAccessManager::setNetworkAccessible(QNetworkAccessManager::NetworkA
|
||||
QNetworkAccessManager::NetworkAccessibility QNetworkAccessManager::networkAccessible() const
|
||||
{
|
||||
Q_D(const QNetworkAccessManager);
|
||||
-
|
||||
if (d->networkSessionRequired) {
|
||||
QSharedPointer<QNetworkSession> networkSession(d->getNetworkSession());
|
||||
if (networkSession) {
|
||||
@@ -975,7 +975,13 @@ QNetworkAccessManager::NetworkAccessibility QNetworkAccessManager::networkAccess
|
||||
return NotAccessible;
|
||||
} else {
|
||||
// Network accessibility is either disabled or unknown.
|
||||
- return (d->networkAccessible == NotAccessible) ? NotAccessible : UnknownAccessibility;
|
||||
+ if (d->defaultAccessControl) {
|
||||
+ if (d->online)
|
||||
+ return d->networkAccessible;
|
||||
+ else
|
||||
+ return NotAccessible;
|
||||
+ }
|
||||
+ return (d->networkAccessible);
|
||||
}
|
||||
} else {
|
||||
if (d->online)
|
||||
@@ -1568,7 +1574,7 @@ void QNetworkAccessManagerPrivate::createSession(const QNetworkConfiguration &co
|
||||
if (!networkSessionStrongRef) {
|
||||
online = false;
|
||||
|
||||
- if (networkAccessible == QNetworkAccessManager::NotAccessible)
|
||||
+ if (networkAccessible == QNetworkAccessManager::NotAccessible || !online)
|
||||
emit q->networkAccessibleChanged(QNetworkAccessManager::NotAccessible);
|
||||
else
|
||||
emit q->networkAccessibleChanged(QNetworkAccessManager::UnknownAccessibility);
|
||||
@@ -1616,11 +1622,14 @@ void QNetworkAccessManagerPrivate::_q_networkSessionStateChanged(QNetworkSession
|
||||
if (online) {
|
||||
if (state != QNetworkSession::Connected && state != QNetworkSession::Roaming) {
|
||||
online = false;
|
||||
- emit q->networkAccessibleChanged(QNetworkAccessManager::NotAccessible);
|
||||
+ networkAccessible = QNetworkAccessManager::NotAccessible;
|
||||
+ emit q->networkAccessibleChanged(networkAccessible);
|
||||
}
|
||||
} else {
|
||||
if (state == QNetworkSession::Connected || state == QNetworkSession::Roaming) {
|
||||
online = true;
|
||||
+ if (defaultAccessControl)
|
||||
+ networkAccessible = QNetworkAccessManager::Accessible;
|
||||
emit q->networkAccessibleChanged(networkAccessible);
|
||||
}
|
||||
}
|
||||
diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h
|
||||
index f513324..c715da0 100644
|
||||
--- a/src/network/access/qnetworkaccessmanager_p.h
|
||||
+++ b/src/network/access/qnetworkaccessmanager_p.h
|
||||
@@ -84,6 +84,7 @@ public:
|
||||
initializeSession(true),
|
||||
#endif
|
||||
cookieJarCreated(false),
|
||||
+ defaultAccessControl(true),
|
||||
authenticationManager(QSharedPointer<QNetworkAccessAuthenticationManager>::create())
|
||||
{ }
|
||||
~QNetworkAccessManagerPrivate();
|
||||
@@ -164,6 +165,7 @@ public:
|
||||
#endif
|
||||
|
||||
bool cookieJarCreated;
|
||||
+ bool defaultAccessControl;
|
||||
|
||||
// The cache with authorization data:
|
||||
QSharedPointer<QNetworkAccessAuthenticationManager> authenticationManager;
|
||||
--
|
||||
1.9.1
|
||||
|
||||
@@ -1,233 +0,0 @@
|
||||
From bb281eea179d50a413f4ec1ff172d27ee48d3a41 Mon Sep 17 00:00:00 2001
|
||||
From: Lorn Potter <lorn.potter@gmail.com>
|
||||
Date: Fri, 17 Jul 2015 15:32:23 +1000
|
||||
Subject: [PATCH] Make sure networkAccessibilityChanged is emitted
|
||||
|
||||
Task-number: QTBUG-46323
|
||||
Change-Id: I8297072b62763136f457ca6ae15282d1c22244f4
|
||||
Reviewed-by: Timo Jyrinki <timo.jyrinki@canonical.com>
|
||||
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
|
||||
---
|
||||
src/network/access/qnetworkaccessmanager.cpp | 70 +++++++++++++++-------
|
||||
src/network/access/qnetworkaccessmanager_p.h | 14 ++++-
|
||||
.../tst_qnetworkaccessmanager.cpp | 31 +++++-----
|
||||
3 files changed, 77 insertions(+), 38 deletions(-)
|
||||
|
||||
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
|
||||
index 84931cb..f9e9513 100644
|
||||
--- a/src/network/access/qnetworkaccessmanager.cpp
|
||||
+++ b/src/network/access/qnetworkaccessmanager.cpp
|
||||
@@ -278,7 +278,8 @@ static void ensureInitialized()
|
||||
|
||||
\snippet code/src_network_access_qnetworkaccessmanager.cpp 4
|
||||
|
||||
- Network requests can be reenabled again by calling
|
||||
+ Network requests can be re-enabled again, and this property will resume to
|
||||
+ reflect the actual device state by calling
|
||||
|
||||
\snippet code/src_network_access_qnetworkaccessmanager.cpp 5
|
||||
|
||||
@@ -467,16 +468,12 @@ QNetworkAccessManager::QNetworkAccessManager(QObject *parent)
|
||||
qRegisterMetaType<QSharedPointer<char> >();
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT
|
||||
- if (!d->networkSessionRequired) {
|
||||
- // if a session is required, we track online state through
|
||||
- // the QNetworkSession's signals
|
||||
- connect(&d->networkConfigurationManager, SIGNAL(onlineStateChanged(bool)),
|
||||
- SLOT(_q_onlineStateChanged(bool)));
|
||||
- }
|
||||
- // we would need all active configurations to check for
|
||||
- // d->networkConfigurationManager.isOnline(), which is asynchronous
|
||||
- // and potentially expensive. We can just check the configuration here
|
||||
- d->online = (d->networkConfiguration.state() & QNetworkConfiguration::Active);
|
||||
+ // if a session is required, we track online state through
|
||||
+ // the QNetworkSession's signals if a request is already made.
|
||||
+ // we need to track current accessibility state by default
|
||||
+ //
|
||||
+ connect(&d->networkConfigurationManager, SIGNAL(onlineStateChanged(bool)),
|
||||
+ SLOT(_q_onlineStateChanged(bool)));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -946,7 +943,8 @@ QNetworkConfiguration QNetworkAccessManager::activeConfiguration() const
|
||||
void QNetworkAccessManager::setNetworkAccessible(QNetworkAccessManager::NetworkAccessibility accessible)
|
||||
{
|
||||
Q_D(QNetworkAccessManager);
|
||||
- d->defaultAccessControl = false;
|
||||
+
|
||||
+ d->defaultAccessControl = accessible == NotAccessible ? false : true;
|
||||
|
||||
if (d->networkAccessible != accessible) {
|
||||
NetworkAccessibility previous = networkAccessible();
|
||||
@@ -965,6 +963,10 @@ void QNetworkAccessManager::setNetworkAccessible(QNetworkAccessManager::NetworkA
|
||||
QNetworkAccessManager::NetworkAccessibility QNetworkAccessManager::networkAccessible() const
|
||||
{
|
||||
Q_D(const QNetworkAccessManager);
|
||||
+
|
||||
+ if (d->networkConfiguration.state().testFlag(QNetworkConfiguration::Undefined))
|
||||
+ return UnknownAccessibility;
|
||||
+
|
||||
if (d->networkSessionRequired) {
|
||||
QSharedPointer<QNetworkSession> networkSession(d->getNetworkSession());
|
||||
if (networkSession) {
|
||||
@@ -1622,32 +1624,56 @@ void QNetworkAccessManagerPrivate::_q_networkSessionStateChanged(QNetworkSession
|
||||
if (online) {
|
||||
if (state != QNetworkSession::Connected && state != QNetworkSession::Roaming) {
|
||||
online = false;
|
||||
- networkAccessible = QNetworkAccessManager::NotAccessible;
|
||||
- emit q->networkAccessibleChanged(networkAccessible);
|
||||
+ if (networkAccessible != QNetworkAccessManager::NotAccessible) {
|
||||
+ networkAccessible = QNetworkAccessManager::NotAccessible;
|
||||
+ emit q->networkAccessibleChanged(networkAccessible);
|
||||
+ }
|
||||
}
|
||||
} else {
|
||||
if (state == QNetworkSession::Connected || state == QNetworkSession::Roaming) {
|
||||
online = true;
|
||||
if (defaultAccessControl)
|
||||
- networkAccessible = QNetworkAccessManager::Accessible;
|
||||
- emit q->networkAccessibleChanged(networkAccessible);
|
||||
+ if (networkAccessible != QNetworkAccessManager::Accessible) {
|
||||
+ networkAccessible = QNetworkAccessManager::Accessible;
|
||||
+ emit q->networkAccessibleChanged(networkAccessible);
|
||||
+ }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QNetworkAccessManagerPrivate::_q_onlineStateChanged(bool isOnline)
|
||||
{
|
||||
- // if the user set a config, we only care whether this one is active.
|
||||
+ Q_Q(QNetworkAccessManager);
|
||||
+ // if the user set a config, we only care whether this one is active.
|
||||
// Otherwise, this QNAM is online if there is an online config.
|
||||
if (customNetworkConfiguration) {
|
||||
online = (networkConfiguration.state() & QNetworkConfiguration::Active);
|
||||
} else {
|
||||
- if (isOnline && online != isOnline) {
|
||||
- networkSessionStrongRef.clear();
|
||||
- networkSessionWeakRef.clear();
|
||||
+ if (online != isOnline) {
|
||||
+ if (isOnline) {
|
||||
+ networkSessionStrongRef.clear();
|
||||
+ networkSessionWeakRef.clear();
|
||||
+ }
|
||||
+ online = isOnline;
|
||||
+ }
|
||||
+ }
|
||||
+ if (online) {
|
||||
+ if (defaultAccessControl) {
|
||||
+ if (networkAccessible != QNetworkAccessManager::Accessible) {
|
||||
+ networkAccessible = QNetworkAccessManager::Accessible;
|
||||
+ emit q->networkAccessibleChanged(networkAccessible);
|
||||
+ }
|
||||
+ }
|
||||
+ } else if (networkConfiguration.state().testFlag(QNetworkConfiguration::Undefined)) {
|
||||
+ if (networkAccessible != QNetworkAccessManager::UnknownAccessibility) {
|
||||
+ networkAccessible = QNetworkAccessManager::UnknownAccessibility;
|
||||
+ emit q->networkAccessibleChanged(networkAccessible);
|
||||
+ }
|
||||
+ } else {
|
||||
+ if (networkAccessible != QNetworkAccessManager::NotAccessible) {
|
||||
+ networkAccessible = QNetworkAccessManager::NotAccessible;
|
||||
+ emit q->networkAccessibleChanged(networkAccessible);
|
||||
}
|
||||
-
|
||||
- online = isOnline;
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h
|
||||
index c715da0..54ae114 100644
|
||||
--- a/src/network/access/qnetworkaccessmanager_p.h
|
||||
+++ b/src/network/access/qnetworkaccessmanager_p.h
|
||||
@@ -78,7 +78,6 @@ public:
|
||||
customNetworkConfiguration(false),
|
||||
networkSessionRequired(networkConfigurationManager.capabilities()
|
||||
& QNetworkConfigurationManager::NetworkSessionRequired),
|
||||
- networkAccessible(QNetworkAccessManager::Accessible),
|
||||
activeReplyCount(0),
|
||||
online(false),
|
||||
initializeSession(true),
|
||||
@@ -86,7 +85,18 @@ public:
|
||||
cookieJarCreated(false),
|
||||
defaultAccessControl(true),
|
||||
authenticationManager(QSharedPointer<QNetworkAccessAuthenticationManager>::create())
|
||||
- { }
|
||||
+ {
|
||||
+#ifndef QT_NO_BEARERMANAGEMENT
|
||||
+ // we would need all active configurations to check for
|
||||
+ // d->networkConfigurationManager.isOnline(), which is asynchronous
|
||||
+ // and potentially expensive. We can just check the configuration here
|
||||
+ online = (networkConfiguration.state().testFlag(QNetworkConfiguration::Active));
|
||||
+ if (online)
|
||||
+ networkAccessible = QNetworkAccessManager::Accessible;
|
||||
+ else
|
||||
+ networkAccessible = QNetworkAccessManager::NotAccessible;
|
||||
+#endif
|
||||
+ }
|
||||
~QNetworkAccessManagerPrivate();
|
||||
|
||||
void _q_replyFinished();
|
||||
diff --git a/tests/auto/network/access/qnetworkaccessmanager/tst_qnetworkaccessmanager.cpp b/tests/auto/network/access/qnetworkaccessmanager/tst_qnetworkaccessmanager.cpp
|
||||
index b4e4b9c..8ecb57d 100644
|
||||
--- a/tests/auto/network/access/qnetworkaccessmanager/tst_qnetworkaccessmanager.cpp
|
||||
+++ b/tests/auto/network/access/qnetworkaccessmanager/tst_qnetworkaccessmanager.cpp
|
||||
@@ -74,6 +74,10 @@ void tst_QNetworkAccessManager::networkAccessible()
|
||||
// if there is no session, we cannot know in which state we are in
|
||||
QNetworkAccessManager::NetworkAccessibility initialAccessibility =
|
||||
manager.networkAccessible();
|
||||
+
|
||||
+ if (initialAccessibility == QNetworkAccessManager::UnknownAccessibility)
|
||||
+ QSKIP("Unknown accessibility", SkipAll);
|
||||
+
|
||||
QCOMPARE(manager.networkAccessible(), initialAccessibility);
|
||||
|
||||
manager.setNetworkAccessible(QNetworkAccessManager::NotAccessible);
|
||||
@@ -94,29 +98,28 @@ void tst_QNetworkAccessManager::networkAccessible()
|
||||
QCOMPARE(manager.networkAccessible(), initialAccessibility);
|
||||
|
||||
QNetworkConfigurationManager configManager;
|
||||
- bool sessionRequired = (configManager.capabilities()
|
||||
- & QNetworkConfigurationManager::NetworkSessionRequired);
|
||||
QNetworkConfiguration defaultConfig = configManager.defaultConfiguration();
|
||||
if (defaultConfig.isValid()) {
|
||||
manager.setConfiguration(defaultConfig);
|
||||
|
||||
- // the accessibility has not changed if no session is required
|
||||
- if (sessionRequired) {
|
||||
+ QCOMPARE(spy.count(), 0);
|
||||
+
|
||||
+ if (defaultConfig.state().testFlag(QNetworkConfiguration::Active))
|
||||
+ QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::Accessible);
|
||||
+ else
|
||||
+ QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::NotAccessible);
|
||||
+
|
||||
+ manager.setNetworkAccessible(QNetworkAccessManager::NotAccessible);
|
||||
+
|
||||
+ if (defaultConfig.state().testFlag(QNetworkConfiguration::Active)) {
|
||||
QCOMPARE(spy.count(), 1);
|
||||
- QCOMPARE(spy.takeFirst().at(0).value<QNetworkAccessManager::NetworkAccessibility>(),
|
||||
- QNetworkAccessManager::Accessible);
|
||||
+ QCOMPARE(QNetworkAccessManager::NetworkAccessibility(spy.takeFirst().at(0).toInt()),
|
||||
+ QNetworkAccessManager::NotAccessible);
|
||||
} else {
|
||||
QCOMPARE(spy.count(), 0);
|
||||
}
|
||||
- QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::Accessible);
|
||||
-
|
||||
- manager.setNetworkAccessible(QNetworkAccessManager::NotAccessible);
|
||||
-
|
||||
- QCOMPARE(spy.count(), 1);
|
||||
- QCOMPARE(QNetworkAccessManager::NetworkAccessibility(spy.takeFirst().at(0).toInt()),
|
||||
- QNetworkAccessManager::NotAccessible);
|
||||
- QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::NotAccessible);
|
||||
}
|
||||
+ QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::NotAccessible);
|
||||
#endif
|
||||
}
|
||||
|
||||
--
|
||||
1.9.1
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
From e996d68f6130847637ba287518cff1289cfa48e5 Mon Sep 17 00:00:00 2001
|
||||
From: Lorn Potter <lorn.potter@gmail.com>
|
||||
Date: Fri, 6 Nov 2015 14:22:44 +1000
|
||||
Subject: [PATCH] Make UnknownAccessibility not block requests
|
||||
|
||||
This allows requests to proceed without needing bearer plugins.
|
||||
|
||||
Task-number: QTBUG-49267
|
||||
Change-Id: Ie5ce188ddefebd14d666bb5846e8f93ee2925ed1
|
||||
Reviewed-by: Markus Goetz (Woboq GmbH) <markus@woboq.com>
|
||||
---
|
||||
src/network/access/qnetworkaccessmanager.cpp | 3 +--
|
||||
src/network/access/qnetworkaccessmanager_p.h | 2 ++
|
||||
2 files changed, 3 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
|
||||
index 086140f..0e5870a 100644
|
||||
--- a/src/network/access/qnetworkaccessmanager.cpp
|
||||
+++ b/src/network/access/qnetworkaccessmanager.cpp
|
||||
@@ -976,7 +976,6 @@ QNetworkAccessManager::NetworkAccessibility QNetworkAccessManager::networkAccess
|
||||
else
|
||||
return NotAccessible;
|
||||
} else {
|
||||
- // Network accessibility is either disabled or unknown.
|
||||
if (d->defaultAccessControl) {
|
||||
if (d->online)
|
||||
return d->networkAccessible;
|
||||
@@ -1161,7 +1160,7 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
|
||||
#ifndef QT_NO_BEARERMANAGEMENT
|
||||
// Return a disabled network reply if network access is disabled.
|
||||
// Except if the scheme is empty or file://.
|
||||
- if (!d->networkAccessible && !isLocalFile) {
|
||||
+ if (d->networkAccessible == NotAccessible && !isLocalFile) {
|
||||
return new QDisabledNetworkReply(this, req, op);
|
||||
}
|
||||
|
||||
diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h
|
||||
index 54ae114..3fc33b5 100644
|
||||
--- a/src/network/access/qnetworkaccessmanager_p.h
|
||||
+++ b/src/network/access/qnetworkaccessmanager_p.h
|
||||
@@ -93,6 +93,8 @@ public:
|
||||
online = (networkConfiguration.state().testFlag(QNetworkConfiguration::Active));
|
||||
if (online)
|
||||
networkAccessible = QNetworkAccessManager::Accessible;
|
||||
+ else if (networkConfiguration.state().testFlag(QNetworkConfiguration::Undefined))
|
||||
+ networkAccessible = QNetworkAccessManager::UnknownAccessibility;
|
||||
else
|
||||
networkAccessible = QNetworkAccessManager::NotAccessible;
|
||||
#endif
|
||||
--
|
||||
1.9.1
|
||||
|
||||
@@ -1,152 +0,0 @@
|
||||
From ae9d3f4c6c1a732788cd1f24c6a928cee16c3991 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Molkentin <daniel@molkentin.de>
|
||||
Date: Tue, 27 Jan 2015 16:58:32 +0100
|
||||
Subject: [PATCH] Win32: Re-init system proxy if internet settings change
|
||||
|
||||
Because Proxy Auto Configuration performs DNS lookups,
|
||||
the proxy settings are being cached. For long-running
|
||||
programs this means that once users switch e.g. from or
|
||||
to company networks with a proxy, they instantly will
|
||||
lose connectivity because we cache the old setting.
|
||||
|
||||
To remedy this, we monitor the Registry (locations
|
||||
courtesy of Chromium's platform support) for changes
|
||||
in its settings, and requery for the current proxy in
|
||||
that case.
|
||||
|
||||
Task-number: QTBUG-3470
|
||||
Task-number: QTBUG-29990
|
||||
Change-Id: Id25a51387bcd232c5f879cea0371038986d0e2de
|
||||
Reviewed-by: Oliver Wolff <oliver.wolff@theqtcompany.com>
|
||||
---
|
||||
src/network/kernel/qnetworkproxy_win.cpp | 86 +++++++++++++++++++++++++++++++-
|
||||
1 file changed, 84 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/src/network/kernel/qnetworkproxy_win.cpp b/src/network/kernel/qnetworkproxy_win.cpp
|
||||
index da2c020..f7741ce 100644
|
||||
--- a/src/network/kernel/qnetworkproxy_win.cpp
|
||||
+++ b/src/network/kernel/qnetworkproxy_win.cpp
|
||||
@@ -345,12 +345,66 @@ static QList<QNetworkProxy> parseServerList(const QNetworkProxyQuery &query, con
|
||||
return removeDuplicateProxies(result);
|
||||
}
|
||||
|
||||
+#if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)
|
||||
+namespace {
|
||||
+class QRegistryWatcher {
|
||||
+public:
|
||||
+ void addLocation(HKEY hive, const QString& path)
|
||||
+ {
|
||||
+ HKEY openedKey;
|
||||
+ if (RegOpenKeyEx(hive, reinterpret_cast<const wchar_t*>(path.utf16()), 0, KEY_READ, &openedKey) != ERROR_SUCCESS)
|
||||
+ return;
|
||||
+
|
||||
+ const DWORD filter = REG_NOTIFY_CHANGE_NAME | REG_NOTIFY_CHANGE_ATTRIBUTES |
|
||||
+ REG_NOTIFY_CHANGE_LAST_SET | REG_NOTIFY_CHANGE_SECURITY;
|
||||
+
|
||||
+ // Watch the registry key for a change of value.
|
||||
+ HANDLE handle = CreateEvent(NULL, true, false, NULL);
|
||||
+ if (RegNotifyChangeKeyValue(openedKey, true, filter, handle, true) != ERROR_SUCCESS) {
|
||||
+ CloseHandle(handle);
|
||||
+ return;
|
||||
+ }
|
||||
+ m_watchEvents.append(handle);
|
||||
+ m_registryHandles.append(openedKey);
|
||||
+ }
|
||||
+
|
||||
+ bool hasChanged() const {
|
||||
+ return !isEmpty() &&
|
||||
+ WaitForMultipleObjects(m_watchEvents.size(), m_watchEvents.data(), false, 0) < WAIT_OBJECT_0 + m_watchEvents.size();
|
||||
+ }
|
||||
+
|
||||
+ bool isEmpty() const {
|
||||
+ return m_watchEvents.isEmpty();
|
||||
+ }
|
||||
+
|
||||
+ void clear() {
|
||||
+ foreach (HANDLE event, m_watchEvents)
|
||||
+ CloseHandle(event);
|
||||
+ foreach (HKEY key, m_registryHandles)
|
||||
+ RegCloseKey(key);
|
||||
+
|
||||
+ m_watchEvents.clear();
|
||||
+ m_registryHandles.clear();
|
||||
+ }
|
||||
+
|
||||
+ ~QRegistryWatcher() {
|
||||
+ clear();
|
||||
+ }
|
||||
+
|
||||
+private:
|
||||
+ QVector<HANDLE> m_watchEvents;
|
||||
+ QVector<HKEY> m_registryHandles;
|
||||
+};
|
||||
+} // namespace
|
||||
+#endif // !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)
|
||||
+
|
||||
class QWindowsSystemProxy
|
||||
{
|
||||
public:
|
||||
QWindowsSystemProxy();
|
||||
~QWindowsSystemProxy();
|
||||
void init();
|
||||
+ void reset();
|
||||
|
||||
QMutex mutex;
|
||||
|
||||
@@ -361,7 +415,9 @@ public:
|
||||
QStringList proxyServerList;
|
||||
QStringList proxyBypass;
|
||||
QList<QNetworkProxy> defaultResult;
|
||||
-
|
||||
+#if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)
|
||||
+ QRegistryWatcher proxySettingsWatcher;
|
||||
+#endif
|
||||
bool initialized;
|
||||
bool functional;
|
||||
bool isAutoConfig;
|
||||
@@ -381,16 +437,42 @@ QWindowsSystemProxy::~QWindowsSystemProxy()
|
||||
ptrWinHttpCloseHandle(hHttpSession);
|
||||
}
|
||||
|
||||
+void QWindowsSystemProxy::reset()
|
||||
+{
|
||||
+ autoConfigUrl.clear();
|
||||
+ proxyServerList.clear();
|
||||
+ proxyBypass.clear();
|
||||
+ defaultResult.clear();
|
||||
+ defaultResult << QNetworkProxy::NoProxy;
|
||||
+ functional = false;
|
||||
+ isAutoConfig = false;
|
||||
+}
|
||||
+
|
||||
void QWindowsSystemProxy::init()
|
||||
{
|
||||
- if (initialized)
|
||||
+ bool proxySettingsChanged = false;
|
||||
+#if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)
|
||||
+ proxySettingsChanged = proxySettingsWatcher.hasChanged();
|
||||
+#endif
|
||||
+
|
||||
+ if (initialized && !proxySettingsChanged)
|
||||
return;
|
||||
initialized = true;
|
||||
|
||||
+ reset();
|
||||
+
|
||||
#ifdef Q_OS_WINCE
|
||||
// Windows CE does not have any of the following API
|
||||
return;
|
||||
#else
|
||||
+
|
||||
+#if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)
|
||||
+ proxySettingsWatcher.clear(); // needs reset to trigger a new detection
|
||||
+ proxySettingsWatcher.addLocation(HKEY_CURRENT_USER, QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"));
|
||||
+ proxySettingsWatcher.addLocation(HKEY_LOCAL_MACHINE, QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"));
|
||||
+ proxySettingsWatcher.addLocation(HKEY_LOCAL_MACHINE, QStringLiteral("Software\\Policies\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"));
|
||||
+#endif
|
||||
+
|
||||
// load the winhttp.dll library
|
||||
QSystemLibrary lib(L"winhttp");
|
||||
if (!lib.load())
|
||||
--
|
||||
1.9.1
|
||||
@@ -1,32 +0,0 @@
|
||||
From c1a67e7dc3a6f8876efa32cdbabbfde1c5a37bc6 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Molkentin <daniel@molkentin.de>
|
||||
Date: Tue, 31 Mar 2015 17:43:44 +0200
|
||||
Subject: [PATCH] Windows: Do not crash if SSL context is gone after root cert
|
||||
lookup
|
||||
|
||||
On Windows, we perform an extra certificate lookup for root CAs that
|
||||
are not in Windows' (minimal) root store. This check can take up to
|
||||
15 seconds. The SSL context can already be gone once we return. Hence
|
||||
we now check for a non-null SSL context on Windows before proceeding.
|
||||
|
||||
Change-Id: I1951569d9b17da33fa604f7c9d8b33255acf200d
|
||||
Reviewed-by: Richard J. Moore <rich@kde.org>
|
||||
---
|
||||
src/network/ssl/qsslsocket_openssl.cpp | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/network/ssl/qsslsocket_openssl.cpp b/src/network/ssl/qsslsocket_openssl.cpp
|
||||
index 0e1a3e5..b132aec 100644
|
||||
--- a/src/network/ssl/qsslsocket_openssl.cpp
|
||||
+++ b/src/network/ssl/qsslsocket_openssl.cpp
|
||||
@@ -1281,7 +1281,7 @@ void QSslSocketBackendPrivate::_q_caRootLoaded(QSslCertificate cert, QSslCertifi
|
||||
if (plainSocket)
|
||||
plainSocket->resume();
|
||||
paused = false;
|
||||
- if (checkSslErrors())
|
||||
+ if (checkSslErrors() && ssl)
|
||||
continueHandshake();
|
||||
}
|
||||
|
||||
--
|
||||
1.9.1
|
||||
@@ -1,39 +0,0 @@
|
||||
From cf6881c03d9f08c6ace83defe461423bb87f30d8 Mon Sep 17 00:00:00 2001
|
||||
From: =?utf8?q?Tor=20Arne=20Vestb=C3=B8?= <tor.arne.vestbo@theqtcompany.com>
|
||||
Date: Fri, 15 Jan 2016 14:15:51 +0100
|
||||
Subject: [PATCH] OS X: Ensure system tray icon is prepared even when menu bar
|
||||
is hidden
|
||||
|
||||
On OS X 10.11 (El Capitan) the system menu bar can be automatically
|
||||
hidden, in which case the menu bar height is reported to be 0 when
|
||||
using the menuBarHeight API.
|
||||
|
||||
This resulted in failing to prepare an image for the system tray
|
||||
icon item, making the tray item "invisible".
|
||||
|
||||
Instead we now use the [[NSStatusBar systemStatusBar] thickness]
|
||||
API, which returns the correct height regardless of the menu bar
|
||||
being hidden or not.
|
||||
|
||||
Task-number: QTBUG-48960
|
||||
Change-Id: I208fb8df13754964a6f254cadfbff06dd56c6bab
|
||||
---
|
||||
src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
|
||||
index a3ffb5b..8152c57 100644
|
||||
--- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
|
||||
+++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
|
||||
@@ -198,7 +198,7 @@ void QCocoaSystemTrayIcon::updateIcon(const QIcon &icon)
|
||||
// current OS X versions is 22 points. Provide some future-proofing
|
||||
// by deriving the icon height from the menu height.
|
||||
const int padding = 4;
|
||||
- const int menuHeight = [[[NSApplication sharedApplication] mainMenu] menuBarHeight];
|
||||
+ const int menuHeight = [[NSStatusBar systemStatusBar] thickness];
|
||||
const int maxImageHeight = menuHeight - padding;
|
||||
|
||||
// Select pixmap based on the device pixel height. Ideally we would use
|
||||
--
|
||||
2.6.2.2.g1b5ffa3
|
||||
|
||||
@@ -1,55 +1,20 @@
|
||||
## Patches used
|
||||
|
||||
There are our patches on top of Qt 5.4.0, which we are currently
|
||||
using for our binary packages on Windows and Mac OS X. Most of them
|
||||
There are our patches on top of Qt 5.6.2, which we are currently
|
||||
using for our binary packages on Windows and macOS. Most of them
|
||||
have been sent upstream and are part of newer Qt releases.
|
||||
|
||||
All changes are designed to up upstream, and all those that are
|
||||
All changes are designed to be upstream, and all those that are
|
||||
special hacks to Qt will bear a NOUPSTREAM in their name
|
||||
|
||||
The git-style numeration is ordered by order of creation, their
|
||||
purpose is outlined in each patches' front matter.
|
||||
You can apply those patches on a git clone using:
|
||||
|
||||
### Part of Qt v5.4.1 and later
|
||||
* 0001-Fix-crash-on-Mac-OS-if-PAC-URL-contains-non-URL-lega.patch
|
||||
* 0002-Fix-possible-crash-when-passing-an-invalid-PAC-URL.patch
|
||||
* 0003-Fix-crash-if-PAC-script-retrieval-returns-a-null-CFD.patch
|
||||
|
||||
### Part of Qt v5.4.2 and later
|
||||
* 0004-Cocoa-Fix-systray-SVG-icons.patch
|
||||
* 0005-OSX-Fix-disapearing-tray-icon.patch
|
||||
* 0007-QNAM-Fix-upload-corruptions-when-server-closes-conne.patch
|
||||
* 0018-Windows-Do-not-crash-if-SSL-context-is-gone-after-ro.patch
|
||||
|
||||
### Part of Qt v5.5.0 and later
|
||||
* 0017-Win32-Re-init-system-proxy-if-internet-settings-chan.patch
|
||||
|
||||
### Part of Qt v5.5.1 and later
|
||||
* 0007-X-Network-Fix-up-previous-corruption-patch.patch
|
||||
* 0008-QNAM-Fix-reply-deadlocks-on-server-closing-connectio.patch
|
||||
* 0014-Fix-SNI-for-TlsV1_0OrLater-TlsV1_1OrLater-and-TlsV1_.patch
|
||||
* 0016-Fix-possible-crash-when-passing-an-invalid-PAC-URL.patch
|
||||
* 0011-Make-sure-to-report-correct-NetworkAccessibility.patch
|
||||
|
||||
### Part of Qt v5.5.2 (UNRELEASED!)
|
||||
* 0009-QNAM-Assign-proper-channel-before-sslErrors-emission.patch
|
||||
* 0010-Don-t-let-closed-http-sockets-pass-as-valid-connecti.patch
|
||||
* 0012-Make-sure-networkAccessibilityChanged-is-emitted.patch
|
||||
|
||||
### Part of Qt v5.6 and later
|
||||
* 0009-QNAM-Assign-proper-channel-before-sslErrors-emission.patch
|
||||
* 0010-Don-t-let-closed-http-sockets-pass-as-valid-connecti.patch
|
||||
* 0011-Make-sure-to-report-correct-NetworkAccessibility.patch
|
||||
* 0012-Make-sure-networkAccessibilityChanged-is-emitted.patch
|
||||
* 0013-Make-UnknownAccessibility-not-block-requests.patch
|
||||
* 0019-Ensure-system-tray-icon-is-prepared-even-when-menu-bar.patch
|
||||
|
||||
### Part of Qt 5.7 and later
|
||||
* 0015-Remove-legacy-platform-code-in-QSslSocket-for-OS-X-1.patch
|
||||
|
||||
### Not submitted upstream to be part of any release:
|
||||
* 0006-Fix-force-debug-info-with-macx-clang_NOUPSTREAM.patch
|
||||
This is only needed if you intent to harvest debugging symbols
|
||||
for breakpad.
|
||||
```
|
||||
git am <client>/admin/qt/patches/qtbase/*.patch
|
||||
```
|
||||
|
||||
You can update them using:
|
||||
|
||||
```
|
||||
git format-patch -N --no-signature -o <client>/admin/qt/patches/qtbase/ <v5.x.y>
|
||||
```
|
||||
|
||||
+9
-12
@@ -1,30 +1,27 @@
|
||||
From f3cd07c11e0b7327ffc629f48a89c8c457cdba75 Mon Sep 17 00:00:00 2001
|
||||
From 96c34ce85136cbdc16ef83effa8a13137f7ae4c5 Mon Sep 17 00:00:00 2001
|
||||
From: Jocelyn Turcotte <jturcotte@woboq.com>
|
||||
Date: Fri, 6 Mar 2015 16:12:37 +0100
|
||||
Subject: [PATCH] Fix -force-debug-info with macx-clang
|
||||
Subject: [PATCH] [NOUPSTREAM] Fix -force-debug-info with macx-clang
|
||||
|
||||
---
|
||||
mkspecs/common/clang.conf | 2 ++
|
||||
1 file changed, 2 insertions(+)
|
||||
|
||||
diff --git a/mkspecs/common/clang.conf b/mkspecs/common/clang.conf
|
||||
index 2c29bb8..110d380 100644
|
||||
index e003b94..e9b3291 100644
|
||||
--- a/mkspecs/common/clang.conf
|
||||
+++ b/mkspecs/common/clang.conf
|
||||
@@ -20,11 +20,13 @@ QMAKE_CFLAGS_ISYSTEM = -isystem
|
||||
QMAKE_CFLAGS_PRECOMPILE = -x c-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_PCH_OUTPUT}
|
||||
@@ -21,11 +21,13 @@ QMAKE_CFLAGS_PRECOMPILE = -x c-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_
|
||||
QMAKE_CFLAGS_USE_PRECOMPILE = -Xclang -include-pch -Xclang ${QMAKE_PCH_OUTPUT}
|
||||
QMAKE_CFLAGS_LTCG = -flto
|
||||
QMAKE_CFLAGS_DISABLE_LTCG = -fno-lto
|
||||
+QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO = $$QMAKE_CFLAGS_OPTIMIZE -g
|
||||
|
||||
QMAKE_CXXFLAGS_PRECOMPILE = -x c++-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_PCH_OUTPUT}
|
||||
QMAKE_CXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE
|
||||
QMAKE_CXXFLAGS_LTCG = $$QMAKE_CFLAGS_LTCG
|
||||
QMAKE_CXXFLAGS_CXX11 = -std=c++11
|
||||
QMAKE_CXXFLAGS_DISABLE_LTCG = $$QMAKE_CFLAGS_DISABLE_LTCG
|
||||
+QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO = $$QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO
|
||||
|
||||
QMAKE_LFLAGS_CXX11 =
|
||||
QMAKE_LFLAGS_LTCG = $$QMAKE_CFLAGS_LTCG
|
||||
--
|
||||
2.2.0
|
||||
|
||||
QMAKE_CXXFLAGS_CXX11 = -std=c++11
|
||||
QMAKE_CXXFLAGS_CXX14 = -std=c++1y
|
||||
QMAKE_CXXFLAGS_CXX1Z = -std=c++1z
|
||||
+17
-22
@@ -1,7 +1,7 @@
|
||||
From 06818f6d1c602aa3c4f9356324866432d2dd0195 Mon Sep 17 00:00:00 2001
|
||||
From e6bccb1f0d8ca59acb1ffdac74a823c06346e7f3 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Molkentin <daniel@molkentin.de>
|
||||
Date: Mon, 16 Nov 2015 15:02:37 +0100
|
||||
Subject: [PATCH 1/2] Remove legacy platform code in QSslSocket for OS X < 10.5
|
||||
Subject: [PATCH] Remove legacy platform code in QSslSocket for OS X < 10.5
|
||||
|
||||
This avoids manual symbol lookups and makes the code more readable.
|
||||
Mark identical code.
|
||||
@@ -16,20 +16,18 @@ Reviewed-by: Markus Goetz (Woboq GmbH) <markus@woboq.com>
|
||||
Conflicts:
|
||||
src/network/ssl/qsslsocket_openssl.cpp
|
||||
---
|
||||
src/network/ssl/qsslsocket_openssl.cpp | 83 +++++++++++-----------------------
|
||||
src/network/ssl/qsslsocket_openssl.cpp | 81 +++++++++++-----------------------
|
||||
src/network/ssl/qsslsocket_p.h | 6 +--
|
||||
2 files changed, 28 insertions(+), 61 deletions(-)
|
||||
2 files changed, 26 insertions(+), 61 deletions(-)
|
||||
|
||||
diff --git a/src/network/ssl/qsslsocket_openssl.cpp b/src/network/ssl/qsslsocket_openssl.cpp
|
||||
index 13fc534..7d0fe00 100644
|
||||
index 82644c1..415f147 100644
|
||||
--- a/src/network/ssl/qsslsocket_openssl.cpp
|
||||
+++ b/src/network/ssl/qsslsocket_openssl.cpp
|
||||
@@ -69,14 +69,19 @@
|
||||
#include <QtCore/qvarlengtharray.h>
|
||||
#include <QLibrary> // for loading the security lib for the CA store
|
||||
@@ -76,14 +76,17 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
+#include <string.h>
|
||||
+
|
||||
+#ifdef Q_OS_DARWIN
|
||||
+# include <private/qcore_mac_p.h>
|
||||
+#endif
|
||||
@@ -50,7 +48,7 @@ index 13fc534..7d0fe00 100644
|
||||
PtrCertOpenSystemStoreW QSslSocketPrivate::ptrCertOpenSystemStoreW = 0;
|
||||
PtrCertFindCertificateInStore QSslSocketPrivate::ptrCertFindCertificateInStore = 0;
|
||||
PtrCertCloseStore QSslSocketPrivate::ptrCertCloseStore = 0;
|
||||
@@ -482,23 +487,7 @@ void QSslSocketPrivate::ensureCiphersAndCertsLoaded()
|
||||
@@ -509,23 +512,7 @@ void QSslSocketPrivate::ensureCiphersAndCertsLoaded()
|
||||
|
||||
#ifndef QT_NO_LIBRARY
|
||||
//load symbols needed to receive certificates from system store
|
||||
@@ -59,23 +57,23 @@ index 13fc534..7d0fe00 100644
|
||||
- if (securityLib.load()) {
|
||||
- ptrSecCertificateCopyData = (PtrSecCertificateCopyData) securityLib.resolve("SecCertificateCopyData");
|
||||
- if (!ptrSecCertificateCopyData)
|
||||
- qWarning("could not resolve symbols in security library"); // should never happen
|
||||
- qCWarning(lcSsl, "could not resolve symbols in security library"); // should never happen
|
||||
-
|
||||
- ptrSecTrustSettingsCopyCertificates = (PtrSecTrustSettingsCopyCertificates) securityLib.resolve("SecTrustSettingsCopyCertificates");
|
||||
- if (!ptrSecTrustSettingsCopyCertificates) { // method was introduced in Leopard, use legacy method if it's not there
|
||||
- ptrSecTrustCopyAnchorCertificates = (PtrSecTrustCopyAnchorCertificates) securityLib.resolve("SecTrustCopyAnchorCertificates");
|
||||
- if (!ptrSecTrustCopyAnchorCertificates)
|
||||
- qWarning("could not resolve symbols in security library"); // should never happen
|
||||
- qCWarning(lcSsl, "could not resolve symbols in security library"); // should never happen
|
||||
- }
|
||||
- } else {
|
||||
- qWarning("could not load security library");
|
||||
- qCWarning(lcSsl, "could not load security library");
|
||||
- }
|
||||
-#elif defined(Q_OS_WIN)
|
||||
+#if defined(Q_OS_WIN)
|
||||
HINSTANCE hLib = LoadLibraryW(L"Crypt32");
|
||||
if (hLib) {
|
||||
#if defined(Q_OS_WINCE)
|
||||
@@ -635,40 +624,22 @@ QList<QSslCertificate> QSslSocketPrivate::systemCaCertificates()
|
||||
@@ -693,40 +680,22 @@ QList<QSslCertificate> QSslSocketPrivate::systemCaCertificates()
|
||||
timer.start();
|
||||
#endif
|
||||
QList<QSslCertificate> systemCerts;
|
||||
@@ -101,7 +99,7 @@ index 13fc534..7d0fe00 100644
|
||||
- data = ptrSecCertificateCopyData(cfCert);
|
||||
-
|
||||
- if (data == NULL) {
|
||||
- qWarning("error retrieving a CA certificate from the system store");
|
||||
- qCWarning(lcSsl, "error retrieving a CA certificate from the system store");
|
||||
- } else {
|
||||
- QByteArray rawCert = QByteArray::fromRawData((const char *)CFDataGetBytePtr(data), CFDataGetLength(data));
|
||||
- systemCerts.append(QSslCertificate::fromData(rawCert, QSsl::Der));
|
||||
@@ -127,15 +125,15 @@ index 13fc534..7d0fe00 100644
|
||||
- }
|
||||
- else {
|
||||
- // no detailed error handling here
|
||||
- qWarning("could not retrieve system CA certificates");
|
||||
- qCWarning(lcSsl, "could not retrieve system CA certificates");
|
||||
}
|
||||
}
|
||||
#elif defined(Q_OS_WIN)
|
||||
diff --git a/src/network/ssl/qsslsocket_p.h b/src/network/ssl/qsslsocket_p.h
|
||||
index 6e7a2c5..c1a6f05 100644
|
||||
index d651971..17cc7b4 100644
|
||||
--- a/src/network/ssl/qsslsocket_p.h
|
||||
+++ b/src/network/ssl/qsslsocket_p.h
|
||||
@@ -145,11 +145,7 @@ public:
|
||||
@@ -151,11 +151,7 @@ public:
|
||||
static bool isMatchingHostname(const QSslCertificate &cert, const QString &peerName);
|
||||
Q_AUTOTEST_EXPORT static bool isMatchingHostname(const QString &cn, const QString &hostname);
|
||||
|
||||
@@ -148,6 +146,3 @@ index 6e7a2c5..c1a6f05 100644
|
||||
static PtrCertOpenSystemStoreW ptrCertOpenSystemStoreW;
|
||||
static PtrCertFindCertificateInStore ptrCertFindCertificateInStore;
|
||||
static PtrCertCloseStore ptrCertCloseStore;
|
||||
--
|
||||
1.9.1
|
||||
|
||||
+13
-16
@@ -1,7 +1,7 @@
|
||||
From 6b9366e7748857f14d5b0f92ced70c08ab5235b7 Mon Sep 17 00:00:00 2001
|
||||
From 9d1120db0973ea7741b13a6555b20ae61f6d037e Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Molkentin <danimo@owncloud.com>
|
||||
Date: Wed, 25 Nov 2015 12:37:27 +0100
|
||||
Subject: [PATCH 2/2] QSslSocket: evaluate CAs in all keychain categories
|
||||
Subject: [PATCH] QSslSocket: evaluate CAs in all keychain categories
|
||||
|
||||
This will make sure that certs in the domainUser (login),
|
||||
and domainAdmin (per machine) keychain are being picked up
|
||||
@@ -15,7 +15,7 @@ it will be accepted.
|
||||
[ChangeLog][Platform Specific Changes] OS X now accepts trusted
|
||||
certificates from the login and system keychains.
|
||||
|
||||
(Backport of fe3a84138e266c425f11353f7d8dc28a588af89e to Qt 5.4)
|
||||
(Backport of fe3a84138e266c425f11353f7d8dc28a588af89e)
|
||||
|
||||
Task-number: QTBUG-32898
|
||||
Change-Id: Ia23083d5af74388eeee31ba07239735cbbe64368
|
||||
@@ -29,10 +29,10 @@ Reviewed-by: Markus Goetz (Woboq GmbH) <markus@woboq.com>
|
||||
create mode 100644 src/network/ssl/qsslsocket_mac_shared.cpp
|
||||
|
||||
diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp
|
||||
index 8887f47..6347c20 100644
|
||||
index 549906a..7b202b0 100644
|
||||
--- a/src/network/ssl/qsslsocket.cpp
|
||||
+++ b/src/network/ssl/qsslsocket.cpp
|
||||
@@ -1446,6 +1446,10 @@ QList<QSslCertificate> QSslSocket::defaultCaCertificates()
|
||||
@@ -1508,6 +1508,10 @@ QList<QSslCertificate> QSslSocket::defaultCaCertificates()
|
||||
returned by defaultCaCertificates(). You can replace that database
|
||||
with your own with setDefaultCaCertificates().
|
||||
|
||||
@@ -198,10 +198,10 @@ index 0000000..60fea4c
|
||||
+
|
||||
+QT_END_NAMESPACE
|
||||
diff --git a/src/network/ssl/qsslsocket_openssl.cpp b/src/network/ssl/qsslsocket_openssl.cpp
|
||||
index 7d0fe00..7415e32 100644
|
||||
index 415f147..7a3cb42 100644
|
||||
--- a/src/network/ssl/qsslsocket_openssl.cpp
|
||||
+++ b/src/network/ssl/qsslsocket_openssl.cpp
|
||||
@@ -71,14 +71,6 @@
|
||||
@@ -76,14 +76,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -216,15 +216,15 @@ index 7d0fe00..7415e32 100644
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
@@ -616,6 +608,7 @@ void QSslSocketPrivate::resetDefaultCiphers()
|
||||
setDefaultCiphers(defaultCiphers);
|
||||
@@ -672,6 +664,7 @@ void QSslSocketPrivate::resetDefaultEllipticCurves()
|
||||
setDefaultSupportedEllipticCurves(curves);
|
||||
}
|
||||
|
||||
+#ifndef Q_OS_DARWIN // Apple implementation in qsslsocket_mac_shared.cpp
|
||||
QList<QSslCertificate> QSslSocketPrivate::systemCaCertificates()
|
||||
{
|
||||
ensureInitialized();
|
||||
@@ -624,25 +617,7 @@ QList<QSslCertificate> QSslSocketPrivate::systemCaCertificates()
|
||||
@@ -680,25 +673,7 @@ QList<QSslCertificate> QSslSocketPrivate::systemCaCertificates()
|
||||
timer.start();
|
||||
#endif
|
||||
QList<QSslCertificate> systemCerts;
|
||||
@@ -251,7 +251,7 @@ index 7d0fe00..7415e32 100644
|
||||
if (ptrCertOpenSystemStoreW && ptrCertFindCertificateInStore && ptrCertCloseStore) {
|
||||
HCERTSTORE hSystemStore;
|
||||
#if defined(Q_OS_WINCE)
|
||||
@@ -719,6 +694,7 @@ QList<QSslCertificate> QSslSocketPrivate::systemCaCertificates()
|
||||
@@ -775,6 +750,7 @@ QList<QSslCertificate> QSslSocketPrivate::systemCaCertificates()
|
||||
|
||||
return systemCerts;
|
||||
}
|
||||
@@ -260,10 +260,10 @@ index 7d0fe00..7415e32 100644
|
||||
void QSslSocketBackendPrivate::startClientEncryption()
|
||||
{
|
||||
diff --git a/src/network/ssl/ssl.pri b/src/network/ssl/ssl.pri
|
||||
index 384e149..9546f18 100644
|
||||
index 29c47cd..8eb605b 100644
|
||||
--- a/src/network/ssl/ssl.pri
|
||||
+++ b/src/network/ssl/ssl.pri
|
||||
@@ -45,7 +45,9 @@ contains(QT_CONFIG, openssl) | contains(QT_CONFIG, openssl-linked) {
|
||||
@@ -62,7 +62,9 @@ contains(QT_CONFIG, openssl) | contains(QT_CONFIG, openssl-linked) {
|
||||
ssl/qsslsocket_openssl.cpp \
|
||||
ssl/qsslsocket_openssl_symbols.cpp
|
||||
|
||||
@@ -274,6 +274,3 @@ index 384e149..9546f18 100644
|
||||
|
||||
# Add optional SSL libs
|
||||
# Static linking of OpenSSL with msvc:
|
||||
--
|
||||
1.9.1
|
||||
|
||||
+8
-13
@@ -114,7 +114,7 @@ void csync_create(CSYNC **csync, const char *local) {
|
||||
*csync = ctx;
|
||||
}
|
||||
|
||||
void csync_init(CSYNC *ctx) {
|
||||
void csync_init(CSYNC *ctx, const char *db_file) {
|
||||
assert(ctx);
|
||||
/* Do not initialize twice */
|
||||
|
||||
@@ -125,6 +125,9 @@ void csync_init(CSYNC *ctx) {
|
||||
|
||||
ctx->remote.type = REMOTE_REPLICA;
|
||||
|
||||
SAFE_FREE(ctx->statedb.file);
|
||||
ctx->statedb.file = c_strdup(db_file);
|
||||
|
||||
c_rbtree_create(&ctx->local.tree, _key_cmp, _data_cmp);
|
||||
c_rbtree_create(&ctx->remote.tree, _key_cmp, _data_cmp);
|
||||
|
||||
@@ -146,19 +149,11 @@ int csync_update(CSYNC *ctx) {
|
||||
}
|
||||
ctx->status_code = CSYNC_STATUS_OK;
|
||||
|
||||
/* create/load statedb */
|
||||
rc = asprintf(&ctx->statedb.file, "%s/.csync_journal.db",
|
||||
ctx->local.uri);
|
||||
if (rc < 0) {
|
||||
ctx->status_code = CSYNC_STATUS_MEMORY_ERROR;
|
||||
return rc;
|
||||
}
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Journal: %s", ctx->statedb.file);
|
||||
|
||||
if (csync_statedb_load(ctx, ctx->statedb.file, &ctx->statedb.db) < 0) {
|
||||
/* Path of database file is set in csync_init */
|
||||
if (csync_statedb_load(ctx, ctx->statedb.file, &ctx->statedb.db) < 0) {
|
||||
rc = -1;
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
ctx->status_code = CSYNC_STATUS_OK;
|
||||
|
||||
@@ -515,7 +510,6 @@ static void _csync_clean_ctx(CSYNC *ctx)
|
||||
c_rbtree_free(ctx->local.tree);
|
||||
c_rbtree_free(ctx->remote.tree);
|
||||
|
||||
SAFE_FREE(ctx->statedb.file);
|
||||
SAFE_FREE(ctx->remote.root_perms);
|
||||
}
|
||||
|
||||
@@ -572,6 +566,7 @@ int csync_destroy(CSYNC *ctx) {
|
||||
|
||||
_csync_clean_ctx(ctx);
|
||||
|
||||
SAFE_FREE(ctx->statedb.file);
|
||||
SAFE_FREE(ctx->local.uri);
|
||||
SAFE_FREE(ctx->error_string);
|
||||
|
||||
|
||||
+1
-1
@@ -326,7 +326,7 @@ void OCSYNC_EXPORT csync_create(CSYNC **csync, const char *local);
|
||||
*
|
||||
* @param ctx The context to initialize.
|
||||
*/
|
||||
void OCSYNC_EXPORT csync_init(CSYNC *ctx);
|
||||
void OCSYNC_EXPORT csync_init(CSYNC *ctx, const char *db_file);
|
||||
|
||||
/**
|
||||
* @brief Update detection
|
||||
|
||||
@@ -230,6 +230,11 @@ static CSYNC_EXCLUDE_TYPE _csync_excluded_common(c_strlist_t *excludes, const ch
|
||||
}
|
||||
blen = strlen(bname);
|
||||
|
||||
rc = csync_fnmatch("._sync_*.db*", bname, 0);
|
||||
if (rc == 0) {
|
||||
match = CSYNC_FILE_SILENTLY_EXCLUDED;
|
||||
goto out;
|
||||
}
|
||||
rc = csync_fnmatch(".csync_journal.db*", bname, 0);
|
||||
if (rc == 0) {
|
||||
match = CSYNC_FILE_SILENTLY_EXCLUDED;
|
||||
|
||||
@@ -704,8 +704,6 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
|
||||
}
|
||||
|
||||
while ((dirent = csync_vio_readdir(ctx, dh))) {
|
||||
const char *path = NULL;
|
||||
size_t ulen = 0;
|
||||
int flen;
|
||||
int flag;
|
||||
|
||||
@@ -744,35 +742,6 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Create relative path: For local replica, we need to remove the base path. */
|
||||
path = filename;
|
||||
if (ctx->current == LOCAL_REPLICA) {
|
||||
ulen = strlen(ctx->local.uri) + 1;
|
||||
if (((size_t)flen) < ulen) {
|
||||
csync_vio_file_stat_destroy(dirent);
|
||||
dirent = NULL;
|
||||
ctx->status_code = CSYNC_STATUS_UNSUCCESSFUL;
|
||||
goto error;
|
||||
}
|
||||
path += ulen;
|
||||
}
|
||||
|
||||
|
||||
/* skip ".csync_journal.db" and ".csync_journal.db.ctmp" */
|
||||
/* Isn't this done via csync_exclude already? */
|
||||
if (c_streq(path, ".csync_journal.db")
|
||||
|| c_streq(path, ".csync_journal.db.ctmp")
|
||||
|| c_streq(path, ".csync_journal.db.ctmp-journal")
|
||||
|| c_streq(path, ".csync-progressdatabase")
|
||||
|| c_streq(path, ".csync_journal.db-shm")
|
||||
|| c_streq(path, ".csync_journal.db-wal")
|
||||
|| c_streq(path, ".csync_journal.db-journal")) {
|
||||
csync_vio_file_stat_destroy(dirent);
|
||||
dirent = NULL;
|
||||
SAFE_FREE(filename);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Only for the local replica we have to stat(), for the remote one we have all data already */
|
||||
if (ctx->replica == LOCAL_REPLICA) {
|
||||
res = csync_vio_stat(ctx, filename, dirent);
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#include "csync_private.h"
|
||||
|
||||
static void setup(void **state) {
|
||||
static int setup(void **state) {
|
||||
CSYNC *csync;
|
||||
int rc;
|
||||
|
||||
@@ -33,9 +33,11 @@ static void setup(void **state) {
|
||||
csync_create(&csync, "/tmp/check_csync1");
|
||||
|
||||
*state = csync;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup_module(void **state) {
|
||||
static int setup_module(void **state) {
|
||||
CSYNC *csync;
|
||||
int rc;
|
||||
|
||||
@@ -44,11 +46,13 @@ static void setup_module(void **state) {
|
||||
|
||||
csync_create(&csync, "/tmp/check_csync1");
|
||||
|
||||
csync_init(csync);
|
||||
csync_init(csync, "foo");
|
||||
*state = csync;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void teardown(void **state) {
|
||||
static int teardown(void **state) {
|
||||
CSYNC *csync = *state;
|
||||
int rc;
|
||||
|
||||
@@ -61,6 +65,8 @@ static void teardown(void **state) {
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
*state = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void check_csync_commit(void **state)
|
||||
@@ -88,10 +94,10 @@ static void check_csync_commit_dummy(void **state)
|
||||
|
||||
int torture_run_tests(void)
|
||||
{
|
||||
const UnitTest tests[] = {
|
||||
unit_test_setup_teardown(check_csync_commit, setup, teardown),
|
||||
unit_test_setup_teardown(check_csync_commit_dummy, setup_module, teardown),
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(check_csync_commit, setup, teardown),
|
||||
cmocka_unit_test_setup_teardown(check_csync_commit_dummy, setup_module, teardown),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
|
||||
@@ -50,11 +50,11 @@ static void check_csync_create(void **state)
|
||||
|
||||
int torture_run_tests(void)
|
||||
{
|
||||
const UnitTest tests[] = {
|
||||
unit_test(check_csync_destroy_null),
|
||||
unit_test(check_csync_create),
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(check_csync_destroy_null),
|
||||
cmocka_unit_test(check_csync_create),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,15 +29,16 @@
|
||||
|
||||
#define EXCLUDE_LIST_FILE SOURCEDIR"/../sync-exclude.lst"
|
||||
|
||||
static void setup(void **state) {
|
||||
static int setup(void **state) {
|
||||
CSYNC *csync;
|
||||
|
||||
csync_create(&csync, "/tmp/check_csync1");
|
||||
|
||||
*state = csync;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup_init(void **state) {
|
||||
static int setup_init(void **state) {
|
||||
CSYNC *csync;
|
||||
int rc;
|
||||
|
||||
@@ -59,9 +60,10 @@ static void setup_init(void **state) {
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
*state = csync;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void teardown(void **state) {
|
||||
static int teardown(void **state) {
|
||||
CSYNC *csync = *state;
|
||||
int rc;
|
||||
|
||||
@@ -74,6 +76,8 @@ static void teardown(void **state) {
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
*state = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void check_csync_exclude_add(void **state)
|
||||
@@ -143,6 +147,17 @@ static void check_csync_excluded(void **state)
|
||||
assert_int_equal(rc, CSYNC_FILE_SILENTLY_EXCLUDED);
|
||||
rc = csync_excluded_no_ctx(csync->excludes, "subdir/.csync_journal.db", CSYNC_FTW_TYPE_FILE);
|
||||
assert_int_equal(rc, CSYNC_FILE_SILENTLY_EXCLUDED);
|
||||
|
||||
/* also the new form of the database name */
|
||||
rc = csync_excluded_no_ctx(csync->excludes, "._sync_5bdd60bdfcfa.db", CSYNC_FTW_TYPE_FILE);
|
||||
assert_int_equal(rc, CSYNC_FILE_SILENTLY_EXCLUDED);
|
||||
rc = csync_excluded_no_ctx(csync->excludes, "._sync_5bdd60bdfcfa.db.ctmp", CSYNC_FTW_TYPE_FILE);
|
||||
assert_int_equal(rc, CSYNC_FILE_SILENTLY_EXCLUDED);
|
||||
rc = csync_excluded_no_ctx(csync->excludes, "._sync_5bdd60bdfcfa.db-shm", CSYNC_FTW_TYPE_FILE);
|
||||
assert_int_equal(rc, CSYNC_FILE_SILENTLY_EXCLUDED);
|
||||
rc = csync_excluded_no_ctx(csync->excludes, "subdir/._sync_5bdd60bdfcfa.db", CSYNC_FTW_TYPE_FILE);
|
||||
assert_int_equal(rc, CSYNC_FILE_SILENTLY_EXCLUDED);
|
||||
|
||||
|
||||
/* pattern ]*.directory - ignore and remove */
|
||||
rc = csync_excluded_no_ctx(csync->excludes, "my.~directory", CSYNC_FTW_TYPE_FILE);
|
||||
@@ -380,16 +395,16 @@ static void check_csync_exclude_expand_escapes(void **state)
|
||||
|
||||
int torture_run_tests(void)
|
||||
{
|
||||
const UnitTest tests[] = {
|
||||
unit_test_setup_teardown(check_csync_exclude_add, setup, teardown),
|
||||
unit_test_setup_teardown(check_csync_exclude_load, setup, teardown),
|
||||
unit_test_setup_teardown(check_csync_excluded, setup_init, teardown),
|
||||
unit_test_setup_teardown(check_csync_excluded_traversal, setup_init, teardown),
|
||||
unit_test_setup_teardown(check_csync_pathes, setup_init, teardown),
|
||||
unit_test_setup_teardown(check_csync_is_windows_reserved_word, setup_init, teardown),
|
||||
unit_test_setup_teardown(check_csync_excluded_performance, setup_init, teardown),
|
||||
unit_test(check_csync_exclude_expand_escapes),
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(check_csync_exclude_add, setup, teardown),
|
||||
cmocka_unit_test_setup_teardown(check_csync_exclude_load, setup, teardown),
|
||||
cmocka_unit_test_setup_teardown(check_csync_excluded, setup_init, teardown),
|
||||
cmocka_unit_test_setup_teardown(check_csync_excluded_traversal, setup_init, teardown),
|
||||
cmocka_unit_test_setup_teardown(check_csync_pathes, setup_init, teardown),
|
||||
cmocka_unit_test_setup_teardown(check_csync_is_windows_reserved_word, setup_init, teardown),
|
||||
cmocka_unit_test_setup_teardown(check_csync_excluded_performance, setup_init, teardown),
|
||||
cmocka_unit_test(check_csync_exclude_expand_escapes),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#include "csync_private.h"
|
||||
|
||||
static void setup(void **state) {
|
||||
static int setup(void **state) {
|
||||
CSYNC *csync;
|
||||
int rc;
|
||||
|
||||
@@ -33,9 +33,10 @@ static void setup(void **state) {
|
||||
csync_create(&csync, "/tmp/check_csync1");
|
||||
|
||||
*state = csync;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup_module(void **state) {
|
||||
static int setup_module(void **state) {
|
||||
CSYNC *csync;
|
||||
int rc;
|
||||
|
||||
@@ -45,9 +46,10 @@ static void setup_module(void **state) {
|
||||
csync_create(&csync, "/tmp/check_csync1");
|
||||
|
||||
*state = csync;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void teardown(void **state) {
|
||||
static int teardown(void **state) {
|
||||
CSYNC *csync = *state;
|
||||
int rc;
|
||||
|
||||
@@ -60,24 +62,27 @@ static void teardown(void **state) {
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
*state = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void check_csync_init(void **state)
|
||||
{
|
||||
CSYNC *csync = *state;
|
||||
|
||||
csync_init(csync);
|
||||
csync_init(csync, "");
|
||||
|
||||
assert_int_equal(csync->status & CSYNC_STATUS_INIT, 1);
|
||||
|
||||
}
|
||||
|
||||
int torture_run_tests(void)
|
||||
{
|
||||
const UnitTest tests[] = {
|
||||
unit_test_setup_teardown(check_csync_init, setup, teardown),
|
||||
unit_test_setup_teardown(check_csync_init, setup_module, teardown),
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(check_csync_init, setup, teardown),
|
||||
cmocka_unit_test_setup_teardown(check_csync_init, setup_module, teardown),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "csync_log.c"
|
||||
#include "c_private.h"
|
||||
|
||||
static void setup(void **state) {
|
||||
static int setup(void **state) {
|
||||
CSYNC *csync;
|
||||
int rc;
|
||||
|
||||
@@ -36,9 +36,11 @@ static void setup(void **state) {
|
||||
csync_create(&csync, "/tmp/check_csync1");
|
||||
|
||||
*state = csync;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void teardown(void **state) {
|
||||
static int teardown(void **state) {
|
||||
CSYNC *csync = *state;
|
||||
int rc;
|
||||
|
||||
@@ -51,6 +53,8 @@ static void teardown(void **state) {
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
*state = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void check_log_callback(int verbosity,
|
||||
@@ -134,11 +138,11 @@ static void check_logging(void **state)
|
||||
|
||||
int torture_run_tests(void)
|
||||
{
|
||||
const UnitTest tests[] = {
|
||||
unit_test(check_set_log_level),
|
||||
unit_test(check_set_auth_callback),
|
||||
unit_test_setup_teardown(check_logging, setup, teardown),
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(check_set_log_level),
|
||||
cmocka_unit_test(check_set_auth_callback),
|
||||
cmocka_unit_test_setup_teardown(check_logging, setup, teardown),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
|
||||
@@ -48,10 +48,10 @@ static void check_csync_normalize_etag(void **state)
|
||||
|
||||
int torture_run_tests(void)
|
||||
{
|
||||
const UnitTest tests[] = {
|
||||
unit_test(check_csync_normalize_etag),
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(check_csync_normalize_etag),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
#define TESTDB "/tmp/check_csync1/test.db"
|
||||
|
||||
static void setup(void **state) {
|
||||
static int setup(void **state) {
|
||||
CSYNC *csync;
|
||||
int rc;
|
||||
|
||||
@@ -47,9 +47,11 @@ static void setup(void **state) {
|
||||
|
||||
rc = sqlite3_close(db);
|
||||
assert_int_equal(rc, SQLITE_OK);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void teardown(void **state) {
|
||||
static int teardown(void **state) {
|
||||
CSYNC *csync = *state;
|
||||
int rc;
|
||||
|
||||
@@ -60,6 +62,8 @@ static void teardown(void **state) {
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
*state = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void check_csync_statedb_load(void **state)
|
||||
@@ -116,11 +120,11 @@ static void check_csync_statedb_close(void **state)
|
||||
|
||||
int torture_run_tests(void)
|
||||
{
|
||||
const UnitTest tests[] = {
|
||||
unit_test_setup_teardown(check_csync_statedb_load, setup, teardown),
|
||||
unit_test_setup_teardown(check_csync_statedb_close, setup, teardown),
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(check_csync_statedb_load, setup, teardown),
|
||||
cmocka_unit_test_setup_teardown(check_csync_statedb_close, setup, teardown),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
|
||||
|
||||
static void setup(void **state)
|
||||
static int setup(void **state)
|
||||
{
|
||||
CSYNC *csync;
|
||||
int rc = 0;
|
||||
@@ -39,7 +39,7 @@ static void setup(void **state)
|
||||
rc = system("mkdir -p /tmp/check_csync");
|
||||
assert_int_equal(rc, 0);
|
||||
csync_create(&csync, "/tmp/check_csync1");
|
||||
csync_init(csync);
|
||||
csync_init(csync, TESTDB);
|
||||
|
||||
sqlite3 *db = NULL;
|
||||
rc = sqlite3_open_v2(TESTDB, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
|
||||
@@ -51,9 +51,11 @@ static void setup(void **state)
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
*state = csync;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup_db(void **state)
|
||||
static int setup_db(void **state)
|
||||
{
|
||||
char *errmsg;
|
||||
int rc = 0;
|
||||
@@ -89,10 +91,12 @@ static void setup_db(void **state)
|
||||
assert_int_equal(rc, SQLITE_OK);
|
||||
|
||||
sqlite3_close(db);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static void teardown(void **state) {
|
||||
static int teardown(void **state) {
|
||||
CSYNC *csync = *state;
|
||||
int rc = 0;
|
||||
|
||||
@@ -104,6 +108,8 @@ static void teardown(void **state) {
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
*state = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -204,15 +210,15 @@ static void check_csync_statedb_get_stat_by_inode_not_found(void **state)
|
||||
|
||||
int torture_run_tests(void)
|
||||
{
|
||||
const UnitTest tests[] = {
|
||||
unit_test_setup_teardown(check_csync_statedb_query_statement, setup, teardown),
|
||||
unit_test_setup_teardown(check_csync_statedb_drop_tables, setup, teardown),
|
||||
unit_test_setup_teardown(check_csync_statedb_insert_metadata, setup, teardown),
|
||||
unit_test_setup_teardown(check_csync_statedb_write, setup, teardown),
|
||||
unit_test_setup_teardown(check_csync_statedb_get_stat_by_hash_not_found, setup_db, teardown),
|
||||
unit_test_setup_teardown(check_csync_statedb_get_stat_by_inode_not_found, setup_db, teardown),
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(check_csync_statedb_query_statement, setup, teardown),
|
||||
cmocka_unit_test_setup_teardown(check_csync_statedb_drop_tables, setup, teardown),
|
||||
cmocka_unit_test_setup_teardown(check_csync_statedb_insert_metadata, setup, teardown),
|
||||
cmocka_unit_test_setup_teardown(check_csync_statedb_write, setup, teardown),
|
||||
cmocka_unit_test_setup_teardown(check_csync_statedb_get_stat_by_hash_not_found, setup_db, teardown),
|
||||
cmocka_unit_test_setup_teardown(check_csync_statedb_get_stat_by_inode_not_found, setup_db, teardown),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ static void statedb_insert_metadata(sqlite3 *db)
|
||||
}
|
||||
}
|
||||
|
||||
static void setup(void **state)
|
||||
static int setup(void **state)
|
||||
{
|
||||
CSYNC *csync;
|
||||
int rc;
|
||||
@@ -92,7 +92,7 @@ static void setup(void **state)
|
||||
rc = system("mkdir -p /tmp/check_csync1");
|
||||
assert_int_equal(rc, 0);
|
||||
csync_create(&csync, "/tmp/check_csync1");
|
||||
csync_init(csync);
|
||||
csync_init(csync, TESTDB);
|
||||
|
||||
/* Create a new db with metadata */
|
||||
sqlite3 *db;
|
||||
@@ -109,9 +109,11 @@ static void setup(void **state)
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
*state = csync;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup_ftw(void **state)
|
||||
static int setup_ftw(void **state)
|
||||
{
|
||||
CSYNC *csync;
|
||||
int rc;
|
||||
@@ -121,7 +123,7 @@ static void setup_ftw(void **state)
|
||||
rc = system("mkdir -p /tmp/check_csync1");
|
||||
assert_int_equal(rc, 0);
|
||||
csync_create(&csync, "/tmp");
|
||||
csync_init(csync);
|
||||
csync_init(csync, TESTDB);
|
||||
|
||||
sqlite3 *db = NULL;
|
||||
rc = sqlite3_open_v2(TESTDB, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
|
||||
@@ -135,9 +137,11 @@ static void setup_ftw(void **state)
|
||||
|
||||
csync->statedb.file = c_strdup( TESTDB );
|
||||
*state = csync;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void teardown(void **state)
|
||||
static int teardown(void **state)
|
||||
{
|
||||
CSYNC *csync = *state;
|
||||
int rc;
|
||||
@@ -147,9 +151,11 @@ static void teardown(void **state)
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
*state = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void teardown_rm(void **state) {
|
||||
static int teardown_rm(void **state) {
|
||||
int rc;
|
||||
|
||||
teardown(state);
|
||||
@@ -158,6 +164,8 @@ static void teardown_rm(void **state) {
|
||||
assert_int_equal(rc, 0);
|
||||
rc = system("rm -rf /tmp/check_csync1");
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* create a file stat, caller must free memory */
|
||||
@@ -424,19 +432,19 @@ static void check_csync_ftw_failing_fn(void **state)
|
||||
|
||||
int torture_run_tests(void)
|
||||
{
|
||||
const UnitTest tests[] = {
|
||||
unit_test_setup_teardown(check_csync_detect_update, setup, teardown_rm),
|
||||
unit_test_setup_teardown(check_csync_detect_update_db_none, setup, teardown),
|
||||
unit_test_setup_teardown(check_csync_detect_update_db_eval, setup, teardown),
|
||||
unit_test_setup_teardown(check_csync_detect_update_db_rename, setup, teardown),
|
||||
unit_test_setup_teardown(check_csync_detect_update_db_new, setup, teardown_rm),
|
||||
unit_test_setup_teardown(check_csync_detect_update_null, setup, teardown_rm),
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(check_csync_detect_update, setup, teardown_rm),
|
||||
cmocka_unit_test_setup_teardown(check_csync_detect_update_db_none, setup, teardown),
|
||||
cmocka_unit_test_setup_teardown(check_csync_detect_update_db_eval, setup, teardown),
|
||||
cmocka_unit_test_setup_teardown(check_csync_detect_update_db_rename, setup, teardown),
|
||||
cmocka_unit_test_setup_teardown(check_csync_detect_update_db_new, setup, teardown_rm),
|
||||
cmocka_unit_test_setup_teardown(check_csync_detect_update_null, setup, teardown_rm),
|
||||
|
||||
unit_test_setup_teardown(check_csync_ftw, setup_ftw, teardown_rm),
|
||||
unit_test_setup_teardown(check_csync_ftw_empty_uri, setup_ftw, teardown_rm),
|
||||
unit_test_setup_teardown(check_csync_ftw_failing_fn, setup_ftw, teardown_rm),
|
||||
cmocka_unit_test_setup_teardown(check_csync_ftw, setup_ftw, teardown_rm),
|
||||
cmocka_unit_test_setup_teardown(check_csync_ftw_empty_uri, setup_ftw, teardown_rm),
|
||||
cmocka_unit_test_setup_teardown(check_csync_ftw_failing_fn, setup_ftw, teardown_rm),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,11 +43,11 @@ static void check_csync_memstat(void **state)
|
||||
|
||||
int torture_run_tests(void)
|
||||
{
|
||||
const UnitTest tests[] = {
|
||||
unit_test(check_csync_instruction_str),
|
||||
unit_test(check_csync_memstat),
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(check_csync_instruction_str),
|
||||
cmocka_unit_test(check_csync_memstat),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -457,6 +457,7 @@ sub traverse( $$;$ )
|
||||
|
||||
$isHere = 1 if( $acceptConflicts && !$isHere && $f =~ /_conflict/ );
|
||||
$isHere = 1 if( $f =~ /\.csync/ );
|
||||
$isHere = 1 if( $f =~ /\._sync_/ );
|
||||
assert( $isHere, "Filename local, but not remote: $f" );
|
||||
}
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ assertLocalAndRemoteDir( 'remoteToLocal1', 1);
|
||||
|
||||
printInfo("simulate a owncloud 5 update by removing all the fileid");
|
||||
## simulate a owncloud 5 update by removing all the fileid
|
||||
system( "sqlite3 " . localDir() . ".csync_journal.db \"UPDATE metadata SET fileid='';\"");
|
||||
system( "sqlite3 " . localDir() . "._sync_*.db \"UPDATE metadata SET fileid='';\"");
|
||||
#refresh the ids
|
||||
csync();
|
||||
assertLocalAndRemoteDir( 'remoteToLocal1', 1);
|
||||
|
||||
@@ -61,7 +61,7 @@ sub getETagFromJournal($$)
|
||||
{
|
||||
my ($name,$num) = @_;
|
||||
|
||||
my $sql = "sqlite3 " . localDir() . ".csync_journal.db \"SELECT md5 FROM metadata WHERE path='$name';\"";
|
||||
my $sql = "sqlite3 " . localDir() . "._sync_*.db \"SELECT md5 FROM metadata WHERE path='$name';\"";
|
||||
open(my $fh, '-|', $sql) or die $!;
|
||||
my $etag = <$fh>;
|
||||
close $fh;
|
||||
|
||||
@@ -37,8 +37,8 @@ sub assertCsyncJournalOk {
|
||||
my $path = $_[0];
|
||||
|
||||
# FIXME: should test also remoteperm but it's not working with owncloud6
|
||||
# my $cmd = 'sqlite3 ' . $path . '.csync_journal.db "SELECT count(*) from metadata where length(remotePerm) == 0 or length(fileId) == 0"';
|
||||
my $cmd = 'sqlite3 ' . $path . '.csync_journal.db "SELECT count(*) from metadata where length(fileId) == 0"';
|
||||
# my $cmd = 'sqlite3 ' . $path . '._sync_*.db "SELECT count(*) from metadata where length(remotePerm) == 0 or length(fileId) == 0"';
|
||||
my $cmd = 'sqlite3 ' . $path . '._sync_*.db "SELECT count(*) from metadata where length(fileId) == 0"';
|
||||
my $result = `$cmd`;
|
||||
assert($result == "0");
|
||||
}
|
||||
@@ -170,14 +170,14 @@ assertLocalAndRemoteDir( '', 0);
|
||||
|
||||
#######################################################################
|
||||
printInfo( "move a directory in a outside read only folder" );
|
||||
system("sqlite3 " . localDir().'.csync_journal.db .dump');
|
||||
system("sqlite3 " . localDir().'._sync_*.db .dump');
|
||||
|
||||
#Missing directory should be restored
|
||||
#new directory should be uploaded
|
||||
system("mv " . localDir().'readonlyDirectory_PERM_M_/subdir_PERM_CK_ ' . localDir().'normalDirectory_PERM_CKDNV_/subdir_PERM_CKDNV_' );
|
||||
|
||||
csync();
|
||||
system("sqlite3 " . localDir().'.csync_journal.db .dump');
|
||||
system("sqlite3 " . localDir().'._sync_*.db .dump');
|
||||
assertCsyncJournalOk(localDir());
|
||||
|
||||
# old name restored
|
||||
@@ -229,7 +229,7 @@ system("rm -r " . localDir(). "readonlyDirectory_PERM_M_/moved_PERM_CK_");
|
||||
|
||||
assertLocalAndRemoteDir( '', 0);
|
||||
|
||||
system("sqlite3 " . localDir().'.csync_journal.db .dump');
|
||||
system("sqlite3 " . localDir().'._sync_*.db .dump');
|
||||
|
||||
|
||||
#######################################################################
|
||||
|
||||
@@ -153,7 +153,8 @@ By default, the ownCloud Client ignores the following files:
|
||||
|
||||
* Files matched by one of the patterns defined in the Ignored Files Editor
|
||||
* Files containing characters that do not work on certain file systems ``(`\, /, :, ?, *, ", >, <, |`)``.
|
||||
* Files starting with ``.csync_journal.db``, as these files are reserved for journalling.
|
||||
* Files starting with ``._sync_xxxxxxx.db`` and the old format ``.csync_journal.db``,
|
||||
as these files are reserved for journalling.
|
||||
|
||||
If a pattern selected using a checkbox in the `ignoredFilesEditor-label` (or if
|
||||
a line in the exclude file starts with the character ``]`` directly followed by
|
||||
|
||||
+1
-9
@@ -68,17 +68,9 @@ To set up your build environment for development using HomeBrew_:
|
||||
|
||||
1. Install Xcode
|
||||
2. Install Xcode command line tools::
|
||||
<<<<<<< HEAD
|
||||
xcode-select --install
|
||||
|
||||
3. Install homebrew::
|
||||
=======
|
||||
|
||||
xcode-select --install
|
||||
|
||||
3. Install homebrew::
|
||||
|
||||
>>>>>>> ca9ec4625391ae23940b3a62aaa0afe89f3d98e8
|
||||
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
|
||||
|
||||
4. Add the ownCloud repository using the following command::
|
||||
@@ -91,7 +83,7 @@ To set up your build environment for development using HomeBrew_:
|
||||
|
||||
3. Add Qt from brew to the path::
|
||||
|
||||
export PATH=/usr/local/Cellar/qt5/5.x.y/bin/qmake
|
||||
export PATH=/usr/local/Cellar/qt5/5.x.y/bin:$PATH
|
||||
|
||||
Where ``x.z`` is the current version of Qt 5 that brew has installed
|
||||
on your machine.
|
||||
|
||||
@@ -514,6 +514,84 @@ X-GNOME-Autostart-Delay=3
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
|
||||
|
||||
# Translations
|
||||
Comment[oc]=@APPLICATION_NAME@ sincronizacion del client
|
||||
GenericName[oc]=Dorsièr de Sincronizacion
|
||||
|
||||
@@ -49,5 +49,6 @@ target_link_libraries(${OWNCLOUDDOLPHINOVERLAYPLUGIN} KF5::CoreAddons KF5::KIOCo
|
||||
set(OWNCLOUDDOLPHINACTIONPLUGIN ${APPLICATION_EXECUTABLE}dolphinactionplugin)
|
||||
add_library(${OWNCLOUDDOLPHINACTIONPLUGIN} MODULE ownclouddolphinactionplugin.cpp)
|
||||
target_link_libraries(${OWNCLOUDDOLPHINACTIONPLUGIN} KF5::CoreAddons KF5::KIOCore KF5::KIOWidgets ${OWNCLOUDDOLPHINHELPER})
|
||||
install(FILES ownclouddolphinactionplugin.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} RENAME ${OWNCLOUDDOLPHINACTIONPLUGIN}.desktop)
|
||||
configure_file(ownclouddolphinactionplugin.desktop.in ${OWNCLOUDDOLPHINACTIONPLUGIN}.desktop ESCAPE_QUOTES @ONLY)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${OWNCLOUDDOLPHINACTIONPLUGIN}.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
|
||||
install(TARGETS ${OWNCLOUDDOLPHINACTIONPLUGIN} DESTINATION ${KDE_INSTALL_PLUGINDIR})
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
[Desktop Entry]
|
||||
Type=Service
|
||||
Name=OwncloudAction
|
||||
Name=@APPLICATION_NAME@Action
|
||||
ServiceTypes=KFileItemAction/Plugin
|
||||
MimeType=application/octet-stream;inode/directory;
|
||||
X-KDE-Library=ownclouddolphinactionplugin
|
||||
X-KDE-Library=@APPLICATION_EXECUTABLE@dolphinactionplugin
|
||||
+15
-14
@@ -278,7 +278,6 @@ void selectiveSyncFixup(OCC::SyncJournalDb *journal, const QStringList &newList)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
@@ -329,8 +328,7 @@ int main(int argc, char **argv) {
|
||||
if( !options.target_url.contains( account->davPath() )) {
|
||||
options.target_url.append(account->davPath());
|
||||
}
|
||||
if (options.target_url.startsWith("http"))
|
||||
options.target_url.replace(0, 4, "owncloud");
|
||||
|
||||
QUrl url = QUrl::fromUserInput(options.target_url);
|
||||
|
||||
// Order of retrieval attempt (later attempts override earlier ones):
|
||||
@@ -371,23 +369,24 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
// ### ensure URL is free of credentials
|
||||
if (url.userName().isEmpty()) {
|
||||
url.setUserName(user);
|
||||
}
|
||||
if (url.password().isEmpty()) {
|
||||
url.setPassword(password);
|
||||
}
|
||||
|
||||
// take the unmodified url to pass to csync_create()
|
||||
QByteArray remUrl = options.target_url.toUtf8();
|
||||
|
||||
// Find the folder and the original owncloud url
|
||||
QStringList splitted = url.path().split(account->davPath());
|
||||
QStringList splitted = url.path().split("/" + account->davPath());
|
||||
url.setPath(splitted.value(0));
|
||||
|
||||
url.setScheme(url.scheme().replace("owncloud", "http"));
|
||||
QString folder = splitted.value(1);
|
||||
|
||||
QUrl credentialFreeUrl = url;
|
||||
credentialFreeUrl.setUserName(QString());
|
||||
credentialFreeUrl.setPassword(QString());
|
||||
|
||||
// Remote folders typically start with a / and don't end with one
|
||||
QString folder = "/" + splitted.value(1);
|
||||
if (folder.endsWith("/") && folder != "/") {
|
||||
folder.chop(1);
|
||||
}
|
||||
|
||||
SimpleSslErrorHandler *sslErrorHandler = new SimpleSslErrorHandler;
|
||||
|
||||
@@ -470,7 +469,9 @@ restart_sync:
|
||||
}
|
||||
|
||||
Cmd cmd;
|
||||
SyncJournalDb db(options.source_dir);
|
||||
QString dbPath = options.source_dir + SyncJournalDb::makeDbName(credentialFreeUrl, folder, user);
|
||||
SyncJournalDb db(dbPath);
|
||||
|
||||
if (!selectiveSyncList.empty()) {
|
||||
selectiveSyncFixup(&db, selectiveSyncList);
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) :
|
||||
|
||||
QAction *syncNowAction = new QAction(this);
|
||||
syncNowAction->setShortcut(QKeySequence(Qt::Key_F6));
|
||||
connect(syncNowAction, SIGNAL(triggered()), SLOT(slotSyncCurrentFolderNow()));
|
||||
connect(syncNowAction, SIGNAL(triggered()), SLOT(slotScheduleCurrentFolder()));
|
||||
addAction(syncNowAction);
|
||||
|
||||
connect(ui->_folderList, SIGNAL(clicked(const QModelIndex &)),
|
||||
@@ -214,8 +214,10 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
|
||||
}
|
||||
|
||||
tv->setCurrentIndex(index);
|
||||
QString alias = _model->data( index, FolderStatusDelegate::FolderAliasRole ).toString();
|
||||
bool folderPaused = _model->data( index, FolderStatusDelegate::FolderSyncPaused).toBool();
|
||||
bool folderConnected = _model->data( index, FolderStatusDelegate::FolderAccountConnected ).toBool();
|
||||
auto folderMan = FolderMan::instance();
|
||||
|
||||
QMenu *menu = new QMenu(tv);
|
||||
menu->setAttribute(Qt::WA_DeleteOnClose);
|
||||
@@ -229,6 +231,15 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
|
||||
connect(ac, SIGNAL(triggered(bool)), this, SLOT(doExpand()));
|
||||
}
|
||||
|
||||
if (!folderPaused) {
|
||||
ac = menu->addAction(tr("Force sync now"));
|
||||
if (folderMan->currentSyncFolder() == folderMan->folder(alias)) {
|
||||
ac->setText(tr("Restart sync"));
|
||||
}
|
||||
ac->setEnabled(folderConnected);
|
||||
connect(ac, SIGNAL(triggered(bool)), this, SLOT(slotForceSyncCurrentFolder()));
|
||||
}
|
||||
|
||||
ac = menu->addAction(folderPaused ? tr("Resume sync") : tr("Pause sync"));
|
||||
connect(ac, SIGNAL(triggered(bool)), this, SLOT(slotEnableCurrentFolder()));
|
||||
|
||||
@@ -290,7 +301,8 @@ void AccountSettings::slotFolderWizardAccepted()
|
||||
FolderDefinition definition;
|
||||
definition.localPath = FolderDefinition::prepareLocalPath(
|
||||
folderWizard->field(QLatin1String("sourceFolder")).toString());
|
||||
definition.targetPath = folderWizard->property("targetPath").toString();
|
||||
definition.targetPath = FolderDefinition::prepareTargetPath(
|
||||
folderWizard->property("targetPath").toString());
|
||||
|
||||
{
|
||||
QDir dir(definition.localPath);
|
||||
@@ -463,7 +475,7 @@ void AccountSettings::slotEnableCurrentFolder()
|
||||
}
|
||||
}
|
||||
|
||||
void AccountSettings::slotSyncCurrentFolderNow()
|
||||
void AccountSettings::slotScheduleCurrentFolder()
|
||||
{
|
||||
QModelIndex selected = ui->_folderList->selectionModel()->currentIndex();
|
||||
if( !selected.isValid() )
|
||||
@@ -474,6 +486,24 @@ void AccountSettings::slotSyncCurrentFolderNow()
|
||||
folderMan->scheduleFolder(folderMan->folder(alias));
|
||||
}
|
||||
|
||||
void AccountSettings::slotForceSyncCurrentFolder()
|
||||
{
|
||||
QModelIndex selected = ui->_folderList->selectionModel()->currentIndex();
|
||||
if( !selected.isValid() )
|
||||
return;
|
||||
QString alias = _model->data( selected, FolderStatusDelegate::FolderAliasRole ).toString();
|
||||
FolderMan *folderMan = FolderMan::instance();
|
||||
|
||||
// Terminate and reschedule any running sync
|
||||
if (Folder* current = folderMan->currentSyncFolder()) {
|
||||
folderMan->terminateSyncProcess();
|
||||
folderMan->scheduleFolder(current);
|
||||
}
|
||||
|
||||
// Insert the selected folder at the front of the queue
|
||||
folderMan->scheduleFolderNext(folderMan->folder(alias));
|
||||
}
|
||||
|
||||
void AccountSettings::slotOpenOC()
|
||||
{
|
||||
if( _OCUrl.isValid() )
|
||||
|
||||
@@ -71,7 +71,8 @@ public slots:
|
||||
protected slots:
|
||||
void slotAddFolder();
|
||||
void slotEnableCurrentFolder();
|
||||
void slotSyncCurrentFolderNow();
|
||||
void slotScheduleCurrentFolder();
|
||||
void slotForceSyncCurrentFolder();
|
||||
void slotRemoveCurrentFolder();
|
||||
void slotOpenCurrentFolder();
|
||||
void slotFolderWizardAccepted();
|
||||
|
||||
@@ -347,14 +347,6 @@ void Application::slotownCloudWizardDone( int res )
|
||||
}
|
||||
}
|
||||
|
||||
static void csyncLogCatcher(int /*verbosity*/,
|
||||
const char */*function*/,
|
||||
const char *buffer,
|
||||
void */*userdata*/)
|
||||
{
|
||||
Logger::instance()->csyncLog( QString::fromUtf8(buffer) );
|
||||
}
|
||||
|
||||
void Application::setupLogging()
|
||||
{
|
||||
// might be called from second instance
|
||||
@@ -370,10 +362,6 @@ void Application::setupLogging()
|
||||
.arg(property("ui_lang").toString())
|
||||
.arg(_theme->version())
|
||||
.arg(Utility::platformName());
|
||||
|
||||
// Setup CSYNC logging to forward to our own logger
|
||||
csync_set_log_callback( csyncLogCatcher );
|
||||
csync_set_log_level( Logger::instance()->isNoop() ? 0 : 11 );
|
||||
}
|
||||
|
||||
void Application::slotUseMonoIconsChanged(bool)
|
||||
|
||||
+74
-9
@@ -46,6 +46,7 @@
|
||||
|
||||
namespace OCC {
|
||||
|
||||
const char oldJournalPath[] = ".csync_journal.db";
|
||||
|
||||
Folder::Folder(const FolderDefinition& definition,
|
||||
AccountState* accountState,
|
||||
@@ -60,12 +61,10 @@ Folder::Folder(const FolderDefinition& definition,
|
||||
, _lastSyncDuration(0)
|
||||
, _consecutiveFailingSyncs(0)
|
||||
, _consecutiveFollowUpSyncs(0)
|
||||
, _journal(definition.localPath)
|
||||
, _journal(_definition.absoluteJournalPath())
|
||||
, _fileLog(new SyncRunFileLog)
|
||||
, _saveBackwardsCompatible(false)
|
||||
{
|
||||
qRegisterMetaType<SyncFileItemVector>("SyncFileItemVector");
|
||||
qRegisterMetaType<SyncFileItem::Direction>("SyncFileItem::Direction");
|
||||
|
||||
qsrand(QTime::currentTime().msec());
|
||||
_timeSinceLastSyncStart.start();
|
||||
_timeSinceLastSyncDone.start();
|
||||
@@ -124,6 +123,7 @@ Folder::~Folder()
|
||||
_engine.reset();
|
||||
}
|
||||
|
||||
|
||||
void Folder::checkLocalPath()
|
||||
{
|
||||
const QFileInfo fi(_definition.localPath);
|
||||
@@ -203,7 +203,7 @@ void Folder::setIgnoreHiddenFiles(bool ignore)
|
||||
_definition.ignoreHiddenFiles = ignore;
|
||||
}
|
||||
|
||||
QString Folder::cleanPath()
|
||||
QString Folder::cleanPath() const
|
||||
{
|
||||
QString cleanedPath = QDir::cleanPath(_canonicalLocalPath);
|
||||
|
||||
@@ -584,8 +584,33 @@ void Folder::slotThreadTreeWalkResult(const SyncFileItemVector& items)
|
||||
|
||||
void Folder::saveToSettings() const
|
||||
{
|
||||
// Remove first to make sure we don't get duplicates
|
||||
removeFromSettings();
|
||||
|
||||
auto settings = _accountState->settings();
|
||||
settings->beginGroup(QLatin1String("Folders"));
|
||||
|
||||
// The folder is saved to backwards-compatible "Folders"
|
||||
// section only if it has the migrate flag set (i.e. was in
|
||||
// there before) or if the folder is the only one for the
|
||||
// given target path.
|
||||
// This ensures that older clients will not read a configuration
|
||||
// where two folders for different accounts point at the same
|
||||
// local folders.
|
||||
bool oneAccountOnly = true;
|
||||
foreach (Folder* other, FolderMan::instance()->map()) {
|
||||
if (other != this && other->cleanPath() == this->cleanPath()) {
|
||||
oneAccountOnly = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool compatible = _saveBackwardsCompatible || oneAccountOnly;
|
||||
|
||||
if (compatible) {
|
||||
settings->beginGroup(QLatin1String("Folders"));
|
||||
} else {
|
||||
settings->beginGroup(QLatin1String("Multifolders"));
|
||||
}
|
||||
FolderDefinition::save(*settings, _definition);
|
||||
|
||||
settings->sync();
|
||||
@@ -594,9 +619,12 @@ void Folder::saveToSettings() const
|
||||
|
||||
void Folder::removeFromSettings() const
|
||||
{
|
||||
auto settings = _accountState->settings();
|
||||
auto settings = _accountState->settings();
|
||||
settings->beginGroup(QLatin1String("Folders"));
|
||||
settings->remove(FolderMan::escapeAlias(_definition.alias));
|
||||
settings->endGroup();
|
||||
settings->beginGroup(QLatin1String("Multifolders"));
|
||||
settings->remove(FolderMan::escapeAlias(_definition.alias));
|
||||
}
|
||||
|
||||
bool Folder::isFileExcludedAbsolute(const QString& fullPath) const
|
||||
@@ -628,12 +656,12 @@ void Folder::slotTerminateSync()
|
||||
// local folder is synced to the same ownCloud.
|
||||
void Folder::wipe()
|
||||
{
|
||||
QString stateDbFile = path()+QLatin1String(".csync_journal.db");
|
||||
QString stateDbFile = _engine->journal()->databaseFilePath();
|
||||
|
||||
// Delete files that have been partially downloaded.
|
||||
slotDiscardDownloadProgress();
|
||||
|
||||
//Unregister the socket API so it does not keep the .sync_journal file open
|
||||
//Unregister the socket API so it does not keep the ._sync_journal file open
|
||||
FolderMan::instance()->socketApi()->slotUnregisterPath(alias());
|
||||
_journal.close(); // close the sync journal
|
||||
|
||||
@@ -808,6 +836,9 @@ void Folder::slotSyncFinished(bool success)
|
||||
} else if( _syncResult.warnCount() > 0 ) {
|
||||
// there have been warnings on the way.
|
||||
_syncResult.setStatus(SyncResult::Problem);
|
||||
} else if( _definition.paused ) {
|
||||
// Maybe the sync was terminated because the user paused the folder
|
||||
_syncResult.setStatus(SyncResult::Paused);
|
||||
} else {
|
||||
_syncResult.setStatus(SyncResult::Success);
|
||||
}
|
||||
@@ -950,6 +981,11 @@ void Folder::scheduleThisFolderSoon()
|
||||
}
|
||||
}
|
||||
|
||||
void Folder::setSaveBackwardsCompatible(bool save)
|
||||
{
|
||||
_saveBackwardsCompatible = save;
|
||||
}
|
||||
|
||||
void Folder::slotAboutToRemoveAllFiles(SyncFileItem::Direction, bool *cancel)
|
||||
{
|
||||
ConfigFile cfgFile;
|
||||
@@ -1002,6 +1038,7 @@ void FolderDefinition::save(QSettings& settings, const FolderDefinition& folder)
|
||||
{
|
||||
settings.beginGroup(FolderMan::escapeAlias(folder.alias));
|
||||
settings.setValue(QLatin1String("localPath"), folder.localPath);
|
||||
settings.setValue(QLatin1String("journalPath"), folder.journalPath);
|
||||
settings.setValue(QLatin1String("targetPath"), folder.targetPath);
|
||||
settings.setValue(QLatin1String("paused"), folder.paused);
|
||||
settings.setValue(QLatin1String("ignoreHiddenFiles"), folder.ignoreHiddenFiles);
|
||||
@@ -1014,6 +1051,7 @@ bool FolderDefinition::load(QSettings& settings, const QString& alias,
|
||||
settings.beginGroup(alias);
|
||||
folder->alias = FolderMan::unescapeAlias(alias);
|
||||
folder->localPath = settings.value(QLatin1String("localPath")).toString();
|
||||
folder->journalPath = settings.value(QLatin1String("journalPath")).toString();
|
||||
folder->targetPath = settings.value(QLatin1String("targetPath")).toString();
|
||||
folder->paused = settings.value(QLatin1String("paused")).toBool();
|
||||
folder->ignoreHiddenFiles = settings.value(QLatin1String("ignoreHiddenFiles"), QVariant(true)).toBool();
|
||||
@@ -1023,6 +1061,9 @@ bool FolderDefinition::load(QSettings& settings, const QString& alias,
|
||||
// code we assum /, so clean it up now.
|
||||
folder->localPath = prepareLocalPath(folder->localPath);
|
||||
|
||||
// Target paths also have a convention
|
||||
folder->targetPath = prepareTargetPath(folder->targetPath);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1035,5 +1076,29 @@ QString FolderDefinition::prepareLocalPath(const QString& path)
|
||||
return p;
|
||||
}
|
||||
|
||||
QString FolderDefinition::prepareTargetPath(const QString &path)
|
||||
{
|
||||
QString p = path;
|
||||
if (p.endsWith(QLatin1Char('/'))) {
|
||||
p.chop(1);
|
||||
}
|
||||
// Doing this second ensures the empty string or "/" come
|
||||
// out as "/".
|
||||
if (!p.startsWith(QLatin1Char('/'))) {
|
||||
p.prepend(QLatin1Char('/'));
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
QString FolderDefinition::absoluteJournalPath() const
|
||||
{
|
||||
return QDir(localPath).filePath(journalPath);
|
||||
}
|
||||
|
||||
QString FolderDefinition::defaultJournalPath(AccountPtr account)
|
||||
{
|
||||
return SyncJournalDb::makeDbName(account->url(), targetPath, account->credentials()->user());
|
||||
}
|
||||
|
||||
} // namespace OCC
|
||||
|
||||
|
||||
+28
-1
@@ -53,6 +53,8 @@ public:
|
||||
QString alias;
|
||||
/// path on local machine
|
||||
QString localPath;
|
||||
/// path to the journal, usually relative to localPath
|
||||
QString journalPath;
|
||||
/// path on remote
|
||||
QString targetPath;
|
||||
/// whether the folder is paused
|
||||
@@ -69,6 +71,15 @@ public:
|
||||
|
||||
/// Ensure / as separator and trailing /.
|
||||
static QString prepareLocalPath(const QString& path);
|
||||
|
||||
/// Ensure starting / and no ending /.
|
||||
static QString prepareTargetPath(const QString& path);
|
||||
|
||||
/// journalPath relative to localPath.
|
||||
QString absoluteJournalPath() const;
|
||||
|
||||
/// Returns the relative journal path that's appropriate for this folder and account.
|
||||
QString defaultJournalPath(AccountPtr account);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -111,7 +122,7 @@ public:
|
||||
/**
|
||||
* wrapper for QDir::cleanPath("Z:\\"), which returns "Z:\\", but we need "Z:" instead
|
||||
*/
|
||||
QString cleanPath();
|
||||
QString cleanPath() const;
|
||||
|
||||
/**
|
||||
* remote folder path
|
||||
@@ -206,6 +217,12 @@ public:
|
||||
*/
|
||||
void scheduleThisFolderSoon();
|
||||
|
||||
/**
|
||||
* Migration: When this flag is true, this folder will save to
|
||||
* the backwards-compatible 'Folders' section in the config file.
|
||||
*/
|
||||
void setSaveBackwardsCompatible(bool save);
|
||||
|
||||
signals:
|
||||
void syncStateChange();
|
||||
void syncStarted();
|
||||
@@ -334,6 +351,16 @@ private:
|
||||
QScopedPointer<SyncRunFileLog> _fileLog;
|
||||
|
||||
QTimer _scheduleSelfTimer;
|
||||
|
||||
/**
|
||||
* When the same local path is synced to multiple accounts, only one
|
||||
* of them can be stored in the settings in a way that's compatible
|
||||
* with old clients that don't support it. This flag marks folders
|
||||
* that shall be written in a backwards-compatible way, by being set
|
||||
* on the *first* Folder instance that was configured for each local
|
||||
* path.
|
||||
*/
|
||||
bool _saveBackwardsCompatible;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+129
-44
@@ -209,18 +209,16 @@ int FolderMan::setupFolders()
|
||||
continue;
|
||||
}
|
||||
settings->beginGroup(id);
|
||||
|
||||
settings->beginGroup(QLatin1String("Folders"));
|
||||
foreach (const auto& folderAlias, settings->childGroups()) {
|
||||
FolderDefinition folderDefinition;
|
||||
if (FolderDefinition::load(*settings, folderAlias, &folderDefinition)) {
|
||||
Folder* f = addFolderInternal(std::move(folderDefinition), account.data());
|
||||
if (f) {
|
||||
scheduleFolder(f);
|
||||
emit folderSyncStateChange(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
settings->endGroup(); // Folders
|
||||
setupFoldersHelper(*settings, account, true);
|
||||
settings->endGroup();
|
||||
|
||||
// See Folder::saveToSettings for details about why this exists.
|
||||
settings->beginGroup(QLatin1String("Multifolders"));
|
||||
setupFoldersHelper(*settings, account, false);
|
||||
settings->endGroup();
|
||||
|
||||
settings->endGroup(); // <account>
|
||||
}
|
||||
|
||||
@@ -229,6 +227,34 @@ int FolderMan::setupFolders()
|
||||
return _folderMap.size();
|
||||
}
|
||||
|
||||
void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account, bool backwardsCompatible)
|
||||
{
|
||||
foreach (const auto& folderAlias, settings.childGroups()) {
|
||||
FolderDefinition folderDefinition;
|
||||
if (FolderDefinition::load(settings, folderAlias, &folderDefinition)) {
|
||||
// Migration: Old settings don't have journalPath
|
||||
if (folderDefinition.journalPath.isEmpty()) {
|
||||
folderDefinition.journalPath = folderDefinition.defaultJournalPath(account->account());
|
||||
}
|
||||
folderDefinition.defaultJournalPath(account->account());
|
||||
// Migration: If an old db is found, move it to the new name.
|
||||
if (backwardsCompatible) {
|
||||
SyncJournalDb::maybeMigrateDb(folderDefinition.localPath, folderDefinition.absoluteJournalPath());
|
||||
}
|
||||
|
||||
Folder* f = addFolderInternal(std::move(folderDefinition), account.data());
|
||||
if (f) {
|
||||
// Migration: Mark folders that shall be saved in a backwards-compatible way
|
||||
if (backwardsCompatible) {
|
||||
f->setSaveBackwardsCompatible(true);
|
||||
}
|
||||
scheduleFolder(f);
|
||||
emit folderSyncStateChange(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int FolderMan::setupFoldersMigration()
|
||||
{
|
||||
ConfigFile cfg;
|
||||
@@ -259,18 +285,16 @@ int FolderMan::setupFoldersMigration()
|
||||
return _folderMap.size();
|
||||
}
|
||||
|
||||
bool FolderMan::ensureJournalGone(const QString &localPath)
|
||||
bool FolderMan::ensureJournalGone( const QString& journalDbFile )
|
||||
{
|
||||
// FIXME move this to UI, not libowncloudsync
|
||||
// remove old .csync_journal file
|
||||
QString stateDbFile = localPath+QLatin1String("/.csync_journal.db");
|
||||
while (QFile::exists(stateDbFile) && !QFile::remove(stateDbFile)) {
|
||||
qDebug() << "Could not remove old db file at" << stateDbFile;
|
||||
// remove the old journal file
|
||||
while (QFile::exists(journalDbFile) && !QFile::remove(journalDbFile)) {
|
||||
qDebug() << "Could not remove old db file at" << journalDbFile;
|
||||
int ret = QMessageBox::warning(0, tr("Could not reset folder state"),
|
||||
tr("An old sync journal '%1' was found, "
|
||||
"but could not be removed. Please make sure "
|
||||
"that no application is currently using it.")
|
||||
.arg(QDir::fromNativeSeparators(QDir::cleanPath(stateDbFile))),
|
||||
.arg(QDir::fromNativeSeparators(QDir::cleanPath(journalDbFile))),
|
||||
QMessageBox::Retry|QMessageBox::Abort);
|
||||
if (ret == QMessageBox::Abort) {
|
||||
return false;
|
||||
@@ -520,6 +544,26 @@ void FolderMan::scheduleFolder( Folder *f )
|
||||
startScheduledSyncSoon();
|
||||
}
|
||||
|
||||
void FolderMan::scheduleFolderNext(Folder* f)
|
||||
{
|
||||
auto alias = f->alias();
|
||||
qDebug() << "Schedule folder " << alias << " to sync! Front-of-queue.";
|
||||
|
||||
if( !f->canSync() ) {
|
||||
qDebug() << "Folder is not ready to sync, not scheduled!";
|
||||
return;
|
||||
}
|
||||
|
||||
_scheduledFolders.removeAll(f);
|
||||
|
||||
f->prepareToSync();
|
||||
emit folderSyncStateChange(f);
|
||||
_scheduledFolders.prepend(f);
|
||||
emit scheduleQueueChanged();
|
||||
|
||||
startScheduledSyncSoon();
|
||||
}
|
||||
|
||||
void FolderMan::slotScheduleETagJob(const QString &/*alias*/, RequestEtagJob *job)
|
||||
{
|
||||
QObject::connect(job, SIGNAL(destroyed(QObject*)), this, SLOT(slotEtagJobDestroyed(QObject*)));
|
||||
@@ -833,11 +877,27 @@ void FolderMan::slotFolderSyncFinished( const SyncResult& )
|
||||
|
||||
Folder* FolderMan::addFolder(AccountState* accountState, const FolderDefinition& folderDefinition)
|
||||
{
|
||||
if (!ensureJournalGone(folderDefinition.localPath)) {
|
||||
// Choose a db filename
|
||||
auto definition = folderDefinition;
|
||||
definition.journalPath = definition.defaultJournalPath(accountState->account());
|
||||
|
||||
if (!ensureJournalGone(definition.absoluteJournalPath())) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto folder = addFolderInternal(folderDefinition, accountState);
|
||||
auto folder = addFolderInternal(definition, accountState);
|
||||
|
||||
// Migration: The first account that's configured for a local folder shall
|
||||
// be saved in a backwards-compatible way.
|
||||
bool oneAccountOnly = true;
|
||||
foreach (Folder* other, FolderMan::instance()->map()) {
|
||||
if (other != folder && other->cleanPath() == folder->cleanPath()) {
|
||||
oneAccountOnly = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
folder->setSaveBackwardsCompatible(oneAccountOnly);
|
||||
|
||||
if(folder) {
|
||||
folder->saveToSettings();
|
||||
emit folderSyncStateChange(folder);
|
||||
@@ -846,7 +906,8 @@ Folder* FolderMan::addFolder(AccountState* accountState, const FolderDefinition&
|
||||
return folder;
|
||||
}
|
||||
|
||||
Folder* FolderMan::addFolderInternal(FolderDefinition folderDefinition, AccountState* accountState)
|
||||
Folder* FolderMan::addFolderInternal(FolderDefinition folderDefinition,
|
||||
AccountState* accountState)
|
||||
{
|
||||
auto alias = folderDefinition.alias;
|
||||
int count = 0;
|
||||
@@ -1209,17 +1270,16 @@ QString FolderMan::statusToString( SyncResult syncStatus, bool paused ) const
|
||||
return folderMessage;
|
||||
}
|
||||
|
||||
QString FolderMan::checkPathValidityForNewFolder(const QString& path, bool forNewDirectory)
|
||||
QString FolderMan::checkPathValidityForNewFolder(const QString& path, const QUrl &serverUrl, bool forNewDirectory)
|
||||
{
|
||||
if (path.isEmpty()) {
|
||||
return tr("No valid folder selected!");
|
||||
}
|
||||
|
||||
QFileInfo selFile( path );
|
||||
QString userInput = selFile.canonicalFilePath();
|
||||
|
||||
if (!selFile.exists()) {
|
||||
return checkPathValidityForNewFolder(selFile.dir().path(), true);
|
||||
return checkPathValidityForNewFolder(selFile.dir().path(), serverUrl, true);
|
||||
}
|
||||
|
||||
if( !selFile.isDir() ) {
|
||||
@@ -1231,6 +1291,10 @@ QString FolderMan::checkPathValidityForNewFolder(const QString& path, bool forNe
|
||||
}
|
||||
|
||||
// check if the local directory isn't used yet in another ownCloud sync
|
||||
Qt::CaseSensitivity cs = Qt::CaseSensitive;
|
||||
if( Utility::fsCasePreserving() ) {
|
||||
cs = Qt::CaseInsensitive;
|
||||
}
|
||||
|
||||
for (auto i = _folderMap.constBegin(); i != _folderMap.constEnd(); ++i ) {
|
||||
Folder *f = static_cast<Folder*>(i.value());
|
||||
@@ -1238,39 +1302,60 @@ QString FolderMan::checkPathValidityForNewFolder(const QString& path, bool forNe
|
||||
if( folderDir.isEmpty() ) {
|
||||
continue;
|
||||
}
|
||||
if( ! folderDir.endsWith(QLatin1Char('/')) ) folderDir.append(QLatin1Char('/'));
|
||||
if( ! folderDir.endsWith(QLatin1Char('/'), cs) ) folderDir.append(QLatin1Char('/'));
|
||||
|
||||
if (QDir::cleanPath(f->path()) == QDir::cleanPath(userInput)
|
||||
&& QDir::cleanPath(QDir(f->path()).canonicalPath()) == QDir(userInput).canonicalPath()) {
|
||||
return tr("The local folder %1 is already used in a folder sync connection. "
|
||||
"Please pick another one!")
|
||||
.arg(QDir::toNativeSeparators(userInput));
|
||||
}
|
||||
if (!forNewDirectory && QDir::cleanPath(folderDir).startsWith(QDir::cleanPath(userInput)+'/')) {
|
||||
const QString folderDirClean = QDir::cleanPath(folderDir)+'/';
|
||||
const QString userDirClean = QDir::cleanPath(path)+'/';
|
||||
|
||||
// folderDir follows sym links, path not.
|
||||
bool differentPathes = !Utility::fileNamesEqual(QDir::cleanPath(folderDir), QDir::cleanPath(path));
|
||||
|
||||
if (!forNewDirectory && differentPathes && folderDirClean.startsWith(userDirClean,cs)) {
|
||||
return tr("The local folder %1 already contains a folder used in a folder sync connection. "
|
||||
"Please pick another one!")
|
||||
.arg(QDir::toNativeSeparators(userInput));
|
||||
.arg(QDir::toNativeSeparators(path));
|
||||
}
|
||||
|
||||
QString absCleanUserFolder = QDir::cleanPath(QDir(userInput).canonicalPath())+'/';
|
||||
if (!forNewDirectory && QDir::cleanPath(folderDir).startsWith(absCleanUserFolder) ) {
|
||||
return tr("The local folder %1 is a symbolic link. "
|
||||
"The link target already contains a folder used in a folder sync connection. "
|
||||
"Please pick another one!")
|
||||
.arg(QDir::toNativeSeparators(userInput));
|
||||
}
|
||||
// QDir::cleanPath keeps links
|
||||
// canonicalPath() remove symlinks and uses the symlink targets.
|
||||
QString absCleanUserFolder = QDir::cleanPath(QDir(path).canonicalPath())+'/';
|
||||
|
||||
if (QDir::cleanPath(QString(userInput)).startsWith( QDir::cleanPath(folderDir)+'/')) {
|
||||
if ( (forNewDirectory || differentPathes) && userDirClean.startsWith( folderDirClean, cs )) {
|
||||
return tr("The local folder %1 is already contained in a folder used in a folder sync connection. "
|
||||
"Please pick another one!")
|
||||
.arg(QDir::toNativeSeparators(userInput));
|
||||
.arg(QDir::toNativeSeparators(path));
|
||||
}
|
||||
|
||||
if (absCleanUserFolder.startsWith( QDir::cleanPath(folderDir)+'/')) {
|
||||
// both follow symlinks.
|
||||
bool cleanUserEqualsCleanFolder = Utility::fileNamesEqual(absCleanUserFolder, folderDirClean );
|
||||
if (differentPathes && absCleanUserFolder.startsWith( folderDirClean, cs ) &&
|
||||
! cleanUserEqualsCleanFolder ) {
|
||||
return tr("The local folder %1 is a symbolic link. "
|
||||
"The link target is already contained in a folder used in a folder sync connection. "
|
||||
"Please pick another one!")
|
||||
.arg(QDir::toNativeSeparators(userInput));
|
||||
.arg(QDir::toNativeSeparators(path));
|
||||
}
|
||||
|
||||
if (differentPathes && folderDirClean.startsWith(absCleanUserFolder, cs) &&
|
||||
!cleanUserEqualsCleanFolder && !forNewDirectory ) {
|
||||
return tr("The local folder %1 contains a symbolic link. "
|
||||
"The link target contains an already synced folder "
|
||||
"Please pick another one!")
|
||||
.arg(QDir::toNativeSeparators(path));
|
||||
}
|
||||
|
||||
// if both pathes are equal, the server url needs to be different
|
||||
// otherwise it would mean that a new connection from the same local folder
|
||||
// to the same account is added which is not wanted. The account must differ.
|
||||
if( serverUrl.isValid() && Utility::fileNamesEqual(absCleanUserFolder,folderDir ) ) {
|
||||
QUrl folderUrl = f->accountState()->account()->url();
|
||||
QString user = f->accountState()->account()->credentials()->user();
|
||||
folderUrl.setUserName(user);
|
||||
|
||||
if( serverUrl == folderUrl ) {
|
||||
return tr("There is already a sync from the server to this local folder. "
|
||||
"Please pick another local folder!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
-10
@@ -97,11 +97,11 @@ public:
|
||||
Folder* setupFolderFromOldConfigFile(const QString &, AccountState *account );
|
||||
|
||||
/**
|
||||
* Ensures that a given directory does not contain a .csync_journal.
|
||||
* Ensures that a given directory does not contain a sync journal file.
|
||||
*
|
||||
* @returns false if the journal could not be removed, true otherwise.
|
||||
*/
|
||||
static bool ensureJournalGone(const QString &path);
|
||||
static bool ensureJournalGone(const QString& journalDbFile);
|
||||
|
||||
/** Creates a new and empty local directory. */
|
||||
bool startFromScratch( const QString& );
|
||||
@@ -128,7 +128,7 @@ public:
|
||||
*
|
||||
* @returns an empty string if it is allowed, or an error if it is not allowed
|
||||
*/
|
||||
QString checkPathValidityForNewFolder(const QString &path, bool forNewDirectory = false);
|
||||
QString checkPathValidityForNewFolder(const QString &path, const QUrl& serverUrl = QUrl(), bool forNewDirectory = false);
|
||||
|
||||
/**
|
||||
* While ignoring hidden files can theoretically be switched per folder,
|
||||
@@ -161,12 +161,22 @@ public:
|
||||
/** Queues a folder for syncing. */
|
||||
void scheduleFolder(Folder*);
|
||||
|
||||
/** Puts a folder in the very front of the queue. */
|
||||
void scheduleFolderNext(Folder*);
|
||||
|
||||
/** Queues all folders for syncing. */
|
||||
void scheduleAllFolders();
|
||||
|
||||
void setDirtyProxy(bool value = true);
|
||||
void setDirtyNetworkLimits();
|
||||
|
||||
/**
|
||||
* Terminates the current folder sync.
|
||||
*
|
||||
* It does not switch the folder to paused state.
|
||||
*/
|
||||
void terminateSyncProcess();
|
||||
|
||||
signals:
|
||||
/**
|
||||
* signal to indicate a folder has changed its sync state.
|
||||
@@ -247,17 +257,12 @@ private slots:
|
||||
void slotScheduleFolderByTime();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Terminates the current folder sync.
|
||||
*
|
||||
* It does not switch the folder to paused state.
|
||||
*/
|
||||
void terminateSyncProcess();
|
||||
|
||||
/** Adds a new folder, does not add it to the account settings and
|
||||
* does not set an account on the new folder.
|
||||
*/
|
||||
Folder* addFolderInternal(FolderDefinition folderDefinition, AccountState* accountState);
|
||||
Folder* addFolderInternal(FolderDefinition folderDefinition,
|
||||
AccountState* accountState);
|
||||
|
||||
/* unloads a folder object, does not delete it */
|
||||
void unloadFolder( Folder * );
|
||||
@@ -273,6 +278,8 @@ private:
|
||||
// restarts the application (Linux only)
|
||||
void restartApplication();
|
||||
|
||||
void setupFoldersHelper(QSettings& settings, AccountStatePtr account, bool backwardsCompatible);
|
||||
|
||||
QSet<Folder*> _disabledFolders;
|
||||
Folder::Map _folderMap;
|
||||
QString _folderConfigPath;
|
||||
|
||||
@@ -527,10 +527,8 @@ void FolderStatusModel::fetchMore(const QModelIndex& parent)
|
||||
|
||||
if (!info || info->_fetched || info->_fetching)
|
||||
return;
|
||||
|
||||
info->_hasError = false;
|
||||
info->resetSubs(this, parent);
|
||||
info->_fetching = true;
|
||||
info->_fetchingLabel = false;
|
||||
QString path = info->_folder->remotePath();
|
||||
if (info->_path != QLatin1String("/")) {
|
||||
if (!path.endsWith(QLatin1Char('/'))) {
|
||||
@@ -698,17 +696,16 @@ void FolderStatusModel::slotLscolFinishedWithError(QNetworkReply* r)
|
||||
qDebug() << r->errorString();
|
||||
parentInfo->_lastErrorString = r->errorString();
|
||||
|
||||
parentInfo->resetSubs(this, idx);
|
||||
|
||||
if (r->error() == QNetworkReply::ContentNotFoundError) {
|
||||
parentInfo->_fetched = true;
|
||||
} else {
|
||||
if (!parentInfo->hasLabel()) {
|
||||
beginInsertRows(idx, 0, 0);
|
||||
endInsertRows();
|
||||
}
|
||||
Q_ASSERT(!parentInfo->hasLabel());
|
||||
beginInsertRows(idx, 0, 0);
|
||||
parentInfo->_hasError = true;
|
||||
endInsertRows();
|
||||
}
|
||||
parentInfo->_fetching = false;
|
||||
parentInfo->_fetchingLabel = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -169,7 +169,8 @@ void FolderWatcherPrivate::slotReceivedNotification(int fd)
|
||||
if (event->len > 0 && event->wd > -1) {
|
||||
QByteArray fileName(event->name);
|
||||
// qDebug() << Q_FUNC_INFO << event->name;
|
||||
if (fileName.startsWith(".csync_journal.db") ||
|
||||
if (fileName.startsWith("._sync_") ||
|
||||
fileName.startsWith(".csync_journal.db") ||
|
||||
fileName.startsWith(".owncloudsync.log")) {
|
||||
// qDebug() << "ignore journal";
|
||||
} else {
|
||||
|
||||
@@ -56,8 +56,9 @@ QString FormatWarningsWizardPage::formatWarnings(const QStringList &warnings) co
|
||||
return ret;
|
||||
}
|
||||
|
||||
FolderWizardLocalPath::FolderWizardLocalPath()
|
||||
: FormatWarningsWizardPage()
|
||||
FolderWizardLocalPath::FolderWizardLocalPath(const AccountPtr& account)
|
||||
: FormatWarningsWizardPage(),
|
||||
_account(account)
|
||||
{
|
||||
_ui.setupUi(this);
|
||||
registerField(QLatin1String("sourceFolder*"), _ui.localFolderLineEdit);
|
||||
@@ -89,8 +90,13 @@ void FolderWizardLocalPath::cleanupPage()
|
||||
|
||||
bool FolderWizardLocalPath::isComplete() const
|
||||
{
|
||||
QUrl serverUrl = _account->url();
|
||||
serverUrl.setUserName( _account->credentials()->user() );
|
||||
|
||||
QString errorStr = FolderMan::instance()->checkPathValidityForNewFolder(
|
||||
QDir::fromNativeSeparators(_ui.localFolderLineEdit->text()));
|
||||
QDir::fromNativeSeparators(_ui.localFolderLineEdit->text()), serverUrl);
|
||||
|
||||
|
||||
|
||||
bool isOk = errorStr.isEmpty();
|
||||
QStringList warnStrings;
|
||||
@@ -133,7 +139,7 @@ void FolderWizardLocalPath::slotChooseLocalFolder()
|
||||
}
|
||||
|
||||
// =================================================================================
|
||||
FolderWizardRemotePath::FolderWizardRemotePath(AccountPtr account)
|
||||
FolderWizardRemotePath::FolderWizardRemotePath(const AccountPtr& account)
|
||||
: FormatWarningsWizardPage()
|
||||
,_warnWasVisible(false)
|
||||
,_account(account)
|
||||
@@ -473,7 +479,7 @@ void FolderWizardRemotePath::showWarn( const QString& msg ) const
|
||||
|
||||
// ====================================================================================
|
||||
|
||||
FolderWizardSelectiveSync::FolderWizardSelectiveSync(AccountPtr account)
|
||||
FolderWizardSelectiveSync::FolderWizardSelectiveSync(const AccountPtr& account)
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
_treeView = new SelectiveSyncTreeView(account, this);
|
||||
@@ -527,7 +533,7 @@ void FolderWizardSelectiveSync::cleanupPage()
|
||||
|
||||
FolderWizard::FolderWizard(AccountPtr account, QWidget *parent)
|
||||
: QWizard(parent),
|
||||
_folderWizardSourcePage(new FolderWizardLocalPath),
|
||||
_folderWizardSourcePage(new FolderWizardLocalPath(account)),
|
||||
_folderWizardTargetPage(0),
|
||||
_folderWizardSelectiveSyncPage(new FolderWizardSelectiveSync(account))
|
||||
{
|
||||
|
||||
@@ -49,7 +49,7 @@ class FolderWizardLocalPath : public FormatWarningsWizardPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FolderWizardLocalPath();
|
||||
explicit FolderWizardLocalPath(const AccountPtr& account);
|
||||
~FolderWizardLocalPath();
|
||||
|
||||
virtual bool isComplete() const Q_DECL_OVERRIDE;
|
||||
@@ -63,6 +63,7 @@ protected slots:
|
||||
private:
|
||||
Ui_FolderWizardSourcePage _ui;
|
||||
Folder::Map _folderMap;
|
||||
AccountPtr _account;
|
||||
};
|
||||
|
||||
|
||||
@@ -75,7 +76,7 @@ class FolderWizardRemotePath : public FormatWarningsWizardPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FolderWizardRemotePath(AccountPtr account);
|
||||
explicit FolderWizardRemotePath(const AccountPtr& account);
|
||||
~FolderWizardRemotePath();
|
||||
|
||||
virtual bool isComplete() const Q_DECL_OVERRIDE;
|
||||
@@ -117,7 +118,7 @@ class FolderWizardSelectiveSync : public QWizardPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FolderWizardSelectiveSync(AccountPtr account);
|
||||
explicit FolderWizardSelectiveSync(const AccountPtr& account);
|
||||
~FolderWizardSelectiveSync();
|
||||
|
||||
virtual bool validatePage() Q_DECL_OVERRIDE;
|
||||
|
||||
@@ -110,8 +110,9 @@ LogBrowser::LogBrowser(QWidget *parent) :
|
||||
|
||||
setModal(false);
|
||||
|
||||
Logger::instance()->setLogWindowActivated(true);
|
||||
// Direct connection for log coming from this thread, and queued for the one in a different thread
|
||||
connect(Logger::instance(), SIGNAL(newLog(QString)),this,SLOT(slotNewLog(QString)), Qt::AutoConnection);
|
||||
connect(Logger::instance(), SIGNAL(logWindowLog(QString)),this,SLOT(slotNewLog(QString)), Qt::AutoConnection);
|
||||
|
||||
QAction *showLogWindow = new QAction(this);
|
||||
showLogWindow->setShortcut(QKeySequence("F12"));
|
||||
|
||||
@@ -521,7 +521,7 @@ void OwncloudSetupWizard::slotAssistantFinished( int result )
|
||||
qDebug() << "Adding folder definition for" << localFolder << _remoteFolder;
|
||||
FolderDefinition folderDefinition;
|
||||
folderDefinition.localPath = localFolder;
|
||||
folderDefinition.targetPath = _remoteFolder;
|
||||
folderDefinition.targetPath = FolderDefinition::prepareTargetPath(_remoteFolder);
|
||||
folderDefinition.ignoreHiddenFiles = folderMan->ignoreHiddenFiles();
|
||||
|
||||
auto f = folderMan->addFolder(account, folderDefinition);
|
||||
|
||||
@@ -125,8 +125,13 @@ void OwncloudAdvancedSetupPage::initializePage()
|
||||
void OwncloudAdvancedSetupPage::updateStatus()
|
||||
{
|
||||
const QString locFolder = localFolder();
|
||||
const QString url = static_cast<OwncloudWizard *>(wizard())->ocUrl();
|
||||
const QString user = static_cast<OwncloudWizard *>(wizard())->getCredentials()->user();
|
||||
|
||||
QUrl serverUrl(url);
|
||||
serverUrl.setUserName(user);
|
||||
// check if the local folder exists. If so, and if its not empty, show a warning.
|
||||
QString errorStr = FolderMan::instance()->checkPathValidityForNewFolder(locFolder);
|
||||
QString errorStr = FolderMan::instance()->checkPathValidityForNewFolder(locFolder, serverUrl);
|
||||
_localFolderValid = errorStr.isEmpty();
|
||||
|
||||
QString t;
|
||||
|
||||
@@ -52,7 +52,6 @@ set(libsync_SRCS
|
||||
propagateupload.cpp
|
||||
propagateuploadv1.cpp
|
||||
propagateuploadng.cpp
|
||||
propagatebundle.cpp
|
||||
propagateremotedelete.cpp
|
||||
propagateremotemove.cpp
|
||||
propagateremotemkdir.cpp
|
||||
|
||||
@@ -128,11 +128,6 @@ QNetworkReply *AbstractNetworkJob::davRequest(const QByteArray &verb, const QUrl
|
||||
return addTimer(_account->davRequest(verb, url, req, data));
|
||||
}
|
||||
|
||||
QNetworkReply *AbstractNetworkJob::multipartRequest(const QString &relPath, QNetworkRequest req, QHttpMultiPart *multiPart)
|
||||
{
|
||||
return addTimer(_account->multipartRequest(relPath, req, multiPart));
|
||||
}
|
||||
|
||||
QNetworkReply* AbstractNetworkJob::getRequest(const QString &relPath)
|
||||
{
|
||||
return addTimer(_account->getRequest(relPath));
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include "accountfwd.h"
|
||||
|
||||
class QUrl;
|
||||
class QHttpMultiPart;
|
||||
|
||||
namespace OCC {
|
||||
|
||||
@@ -79,7 +78,6 @@ protected:
|
||||
QNetworkReply* headRequest(const QString &relPath);
|
||||
QNetworkReply* headRequest(const QUrl &url);
|
||||
QNetworkReply* deleteRequest(const QUrl &url);
|
||||
QNetworkReply* multipartRequest(const QString &relPath, QNetworkRequest req, QHttpMultiPart *multiPart);
|
||||
|
||||
int maxRedirects() const { return 10; }
|
||||
virtual bool finished() = 0;
|
||||
|
||||
+11
-26
@@ -57,6 +57,11 @@ Account::~Account()
|
||||
|
||||
QString Account::davPath() const
|
||||
{
|
||||
if (capabilities().chunkingNg()) {
|
||||
// The chunking-ng means the server prefer to use the new webdav URL
|
||||
return QLatin1String("/remote.php/dav/files/") + davUser() + QLatin1Char('/');
|
||||
}
|
||||
|
||||
// make sure to have a trailing slash
|
||||
if( !_davPath.endsWith('/') ) {
|
||||
QString dp(_davPath);
|
||||
@@ -86,14 +91,6 @@ void Account::setDavUser(const QString &newDavUser)
|
||||
_davUser = newDavUser;
|
||||
}
|
||||
|
||||
QString Account::davFilesPath() const
|
||||
{
|
||||
//TODO DO NOT HARCODE PATH, GET IT FROM THE SERVER!!!!
|
||||
QString dfp("/remote.php/dav/files/");
|
||||
dfp.append(_credentials->user());
|
||||
return dfp;
|
||||
}
|
||||
|
||||
QString Account::displayName() const
|
||||
{
|
||||
QString dn = QString("%1@%2").arg(davUser(), _url.host());
|
||||
@@ -245,20 +242,6 @@ QNetworkReply *Account::davRequest(const QByteArray &verb, const QUrl &url, QNet
|
||||
return _am->sendCustomRequest(req, verb, data);
|
||||
}
|
||||
|
||||
QNetworkReply *Account::multipartRequest(const QString &relPath, QNetworkRequest req, QHttpMultiPart *multiPart)
|
||||
{
|
||||
return multipartRequest(Utility::concatUrlPath(url(), relPath), req, multiPart);
|
||||
}
|
||||
|
||||
QNetworkReply *Account::multipartRequest(const QUrl &url, QNetworkRequest req, QHttpMultiPart *multiPart)
|
||||
{
|
||||
req.setUrl(url);
|
||||
#if QT_VERSION > QT_VERSION_CHECK(4, 8, 4)
|
||||
req.setSslConfiguration(this->getOrCreateSslConfig());
|
||||
#endif
|
||||
return _am->post(req, multiPart);
|
||||
}
|
||||
|
||||
void Account::setCertificate(const QByteArray certficate, const QString privateKey)
|
||||
{
|
||||
_pemCertificate=certficate;
|
||||
@@ -396,8 +379,11 @@ void Account::slotHandleSslErrors(QNetworkReply *reply , QList<QSslError> errors
|
||||
// Keep a ref here on our stackframe to make sure that it doesn't get deleted before
|
||||
// handleErrors returns.
|
||||
QSharedPointer<QNetworkAccessManager> qnamLock = _am;
|
||||
QPointer<QObject> guard = reply;
|
||||
|
||||
if (_sslErrorHandler->handleErrors(errors, reply->sslConfiguration(), &approvedCerts, sharedFromThis())) {
|
||||
if (!guard) return;
|
||||
|
||||
QSslSocket::addDefaultCaCertificates(approvedCerts);
|
||||
addApprovedCerts(approvedCerts);
|
||||
emit wantsAccountSaved(this);
|
||||
@@ -409,6 +395,8 @@ void Account::slotHandleSslErrors(QNetworkReply *reply , QList<QSslError> errors
|
||||
// certificate changes.
|
||||
reply->ignoreSslErrors(errors);
|
||||
} else {
|
||||
if (!guard) return;
|
||||
|
||||
// Mark all involved certificates as rejected, so we don't ask the user again.
|
||||
foreach (const QSslError &error, errors) {
|
||||
if (!_rejectedCertificates.contains(error.certificate())) {
|
||||
@@ -497,9 +485,6 @@ void Account::setNonShib(bool nonShib)
|
||||
}
|
||||
}
|
||||
|
||||
bool Account::bundledRequestsEnabled() const
|
||||
{
|
||||
return _capabilities.bundledRequest();
|
||||
}
|
||||
|
||||
|
||||
} // namespace OCC
|
||||
|
||||
+9
-22
@@ -34,7 +34,6 @@ class QSettings;
|
||||
class QNetworkReply;
|
||||
class QUrl;
|
||||
class QNetworkAccessManager;
|
||||
class QHttpMultiPart;
|
||||
|
||||
namespace OCC {
|
||||
|
||||
@@ -65,25 +64,6 @@ public:
|
||||
class OWNCLOUDSYNC_EXPORT Account : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
/**
|
||||
* @brief The possibly themed dav path for the account. It has
|
||||
* a trailing slash.
|
||||
* @returns the (themeable) dav path for the account.
|
||||
*/
|
||||
QString davPath() const;
|
||||
|
||||
/**
|
||||
* @brief The possibly themed files dav path for the account. It has
|
||||
* a trailing slash.
|
||||
* @returns the (themeable) files dav path for the account.
|
||||
*/
|
||||
QString davFilesPath() const;
|
||||
void setDavPath(const QString&s) { _davPath = s; }
|
||||
void setNonShib(bool nonShib);
|
||||
|
||||
/// Functions for bundle support
|
||||
bool bundledRequestsEnabled() const;
|
||||
|
||||
static AccountPtr create();
|
||||
~Account();
|
||||
|
||||
@@ -108,6 +88,15 @@ public:
|
||||
void setUrl(const QUrl &url);
|
||||
QUrl url() const { return _url; }
|
||||
|
||||
/**
|
||||
* @brief The possibly themed dav path for the account. It has
|
||||
* a trailing slash.
|
||||
* @returns the (themeable) dav path for the account.
|
||||
*/
|
||||
QString davPath() const;
|
||||
void setDavPath(const QString&s) { _davPath = s; }
|
||||
void setNonShib(bool nonShib);
|
||||
|
||||
/** Returns webdav entry URL, based on url() */
|
||||
QUrl davUrl() const;
|
||||
|
||||
@@ -124,8 +113,6 @@ public:
|
||||
QNetworkReply* deleteRequest( const QUrl &url);
|
||||
QNetworkReply* davRequest(const QByteArray &verb, const QString &relPath, QNetworkRequest req, QIODevice *data = 0);
|
||||
QNetworkReply* davRequest(const QByteArray &verb, const QUrl &url, QNetworkRequest req, QIODevice *data = 0);
|
||||
QNetworkReply* multipartRequest(const QString &relPath, QNetworkRequest req, QHttpMultiPart *multiPart);
|
||||
QNetworkReply* multipartRequest(const QUrl &url, QNetworkRequest req, QHttpMultiPart *multiPart);
|
||||
|
||||
|
||||
/** The ssl configuration during the first connection */
|
||||
|
||||
@@ -47,15 +47,6 @@ bool Capabilities::sharePublicLink() const
|
||||
}
|
||||
}
|
||||
|
||||
bool Capabilities::bundledRequest() const
|
||||
{
|
||||
static const auto bundling = qgetenv("OWNCLOUD_BUNDLING");
|
||||
if (bundling == "0") return false;
|
||||
if (bundling == "1") return true;
|
||||
|
||||
return _capabilities["dav"].toMap()["bundlerequest"].toByteArray() >= "1.0";
|
||||
}
|
||||
|
||||
bool Capabilities::sharePublicLinkAllowUpload() const
|
||||
{
|
||||
return _capabilities["files_sharing"].toMap()["public"].toMap()["upload"].toBool();
|
||||
@@ -119,6 +110,9 @@ QByteArray Capabilities::uploadChecksumType() const
|
||||
|
||||
bool Capabilities::chunkingNg() const
|
||||
{
|
||||
static const auto chunkng = qgetenv("OWNCLOUD_CHUNKING_NG");
|
||||
if (chunkng == "0") return false;
|
||||
if (chunkng == "1") return true;
|
||||
return _capabilities["dav"].toMap()["chunking"].toByteArray() >= "1.0";
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ public:
|
||||
int sharePublicLinkExpireDateDays() const;
|
||||
bool shareResharing() const;
|
||||
bool chunkingNg() const;
|
||||
bool bundledRequest() const;
|
||||
|
||||
/// returns true if the capabilities report notifications
|
||||
bool notificationsAvailable() const;
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include <QThread>
|
||||
#include <qmetaobject.h>
|
||||
|
||||
#include "csync.h"
|
||||
|
||||
namespace OCC {
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
@@ -48,6 +50,14 @@ static void mirallLogCatcher(QtMsgType type, const QMessageLogContext &ctx, cons
|
||||
}
|
||||
#endif
|
||||
|
||||
static void csyncLogCatcher(int /*verbosity*/,
|
||||
const char * /*function*/,
|
||||
const char *buffer,
|
||||
void * /*userdata*/)
|
||||
{
|
||||
Logger::instance()->csyncLog( QString::fromUtf8(buffer) );
|
||||
}
|
||||
|
||||
Logger *Logger::instance()
|
||||
{
|
||||
static Logger log;
|
||||
@@ -55,7 +65,7 @@ Logger *Logger::instance()
|
||||
}
|
||||
|
||||
Logger::Logger( QObject* parent) : QObject(parent),
|
||||
_showTime(true), _doLogging(false), _doFileFlush(false), _logExpire(0)
|
||||
_showTime(true), _logWindowActivated(false), _doFileFlush(false), _logExpire(0)
|
||||
{
|
||||
#ifndef NO_MSG_HANDLER
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
|
||||
@@ -117,12 +127,8 @@ bool Logger::isNoop() const
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
return false;
|
||||
#else
|
||||
static auto signal = QMetaMethod::fromSignal(&Logger::newLog);
|
||||
if (isSignalConnected(signal)) {
|
||||
return false;
|
||||
}
|
||||
QMutexLocker lock(const_cast<QMutex *>(&_mutex));
|
||||
return !_logstream;
|
||||
return !_logstream && !_logWindowActivated;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -136,7 +142,7 @@ void Logger::doLog(const QString& msg)
|
||||
if( _doFileFlush ) _logstream->flush();
|
||||
}
|
||||
}
|
||||
emit newLog(msg);
|
||||
emit logWindowLog(msg);
|
||||
}
|
||||
|
||||
void Logger::csyncLog( const QString& message )
|
||||
@@ -164,10 +170,25 @@ void Logger::mirallLog( const QString& message )
|
||||
Logger::instance()->log( log_ );
|
||||
}
|
||||
|
||||
void Logger::setLogWindowActivated(bool activated)
|
||||
{
|
||||
QMutexLocker locker(&_mutex);
|
||||
|
||||
// Setup CSYNC logging to forward to our own logger
|
||||
csync_set_log_callback(csyncLogCatcher);
|
||||
csync_set_log_level(11);
|
||||
|
||||
_logWindowActivated = activated;
|
||||
}
|
||||
|
||||
void Logger::setLogFile(const QString & name)
|
||||
{
|
||||
QMutexLocker locker(&_mutex);
|
||||
|
||||
// Setup CSYNC logging to forward to our own logger
|
||||
csync_set_log_callback(csyncLogCatcher);
|
||||
csync_set_log_level(11);
|
||||
|
||||
if( _logstream ) {
|
||||
_logstream.reset(0);
|
||||
_logFile.close();
|
||||
|
||||
@@ -61,13 +61,15 @@ public:
|
||||
void postOptionalGuiLog(const QString& title, const QString& message);
|
||||
void postGuiMessage(const QString& title, const QString& message);
|
||||
|
||||
void setLogWindowActivated(bool activated);
|
||||
void setLogFile( const QString & name );
|
||||
void setLogExpire( int expire );
|
||||
void setLogDir( const QString& dir );
|
||||
void setLogFlush( bool flush );
|
||||
|
||||
signals:
|
||||
void newLog(const QString&);
|
||||
void logWindowLog(const QString&);
|
||||
|
||||
void guiLog(const QString&, const QString&);
|
||||
void guiMessage(const QString&, const QString&);
|
||||
void optionalGuiLog(const QString&, const QString&);
|
||||
@@ -80,7 +82,7 @@ private:
|
||||
~Logger();
|
||||
QList<Log> _logs;
|
||||
bool _showTime;
|
||||
bool _doLogging;
|
||||
bool _logWindowActivated;
|
||||
QFile _logFile;
|
||||
bool _doFileFlush;
|
||||
int _logExpire;
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "syncjournalfilerecord.h"
|
||||
#include "propagatedownload.h"
|
||||
#include "propagateupload.h"
|
||||
#include "propagatebundle.h"
|
||||
#include "propagateremotedelete.h"
|
||||
#include "propagateremotemove.h"
|
||||
#include "propagateremotemkdir.h"
|
||||
@@ -72,14 +71,6 @@ qint64 freeSpaceLimit()
|
||||
OwncloudPropagator::~OwncloudPropagator()
|
||||
{}
|
||||
|
||||
bool OwncloudPropagator::hasNetworkLimit()
|
||||
{
|
||||
if (_downloadLimit.fetchAndAddAcquire(0) != 0 || _uploadLimit.fetchAndAddAcquire(0) != 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* The maximum number of active jobs in parallel */
|
||||
int OwncloudPropagator::maximumActiveJob()
|
||||
{
|
||||
@@ -88,7 +79,7 @@ int OwncloudPropagator::maximumActiveJob()
|
||||
max = 3; //default
|
||||
}
|
||||
|
||||
if (hasNetworkLimit()) {
|
||||
if (_downloadLimit.fetchAndAddAcquire(0) != 0 || _uploadLimit.fetchAndAddAcquire(0) != 0) {
|
||||
// disable parallelism when there is a network limit.
|
||||
return 1;
|
||||
}
|
||||
@@ -117,6 +108,11 @@ static bool blacklistCheck(SyncJournalDb* journal, const SyncFileItem& item)
|
||||
|
||||
if (newEntry.isValid()) {
|
||||
journal->updateErrorBlacklistEntry(newEntry);
|
||||
// Also clear upload info if any so we don't resume from the same transfer-id if there was too many failures (#5344)
|
||||
// (maybe the reason is that the state for this transfer id is broken on the server.)
|
||||
if (newEntry._retryCount > 3) {
|
||||
journal->setUploadInfo(item._file, SyncJournalDb::UploadInfo());
|
||||
}
|
||||
} else if (oldEntry.isValid()) {
|
||||
journal->wipeErrorBlacklistEntry(item._file);
|
||||
}
|
||||
@@ -124,17 +120,18 @@ static bool blacklistCheck(SyncJournalDb* journal, const SyncFileItem& item)
|
||||
return newEntry.isValid();
|
||||
}
|
||||
|
||||
void PropagateItemJob::itemDone(SyncFileItemPtr item, SyncFileItem::Status status, const QString &errorString)
|
||||
void PropagateItemJob::done(SyncFileItem::Status status, const QString &errorString)
|
||||
{
|
||||
if (item->_isRestoration) {
|
||||
_state = Finished;
|
||||
if (_item->_isRestoration) {
|
||||
if( status == SyncFileItem::Success || status == SyncFileItem::Conflict) {
|
||||
status = SyncFileItem::Restoration;
|
||||
} else {
|
||||
item->_errorString += tr("; Restoration Failed: %1").arg(errorString);
|
||||
_item->_errorString += tr("; Restoration Failed: %1").arg(errorString);
|
||||
}
|
||||
} else {
|
||||
if( item->_errorString.isEmpty() ) {
|
||||
item->_errorString = errorString;
|
||||
if( _item->_errorString.isEmpty() ) {
|
||||
_item->_errorString = errorString;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,20 +147,20 @@ void PropagateItemJob::itemDone(SyncFileItemPtr item, SyncFileItem::Status statu
|
||||
// do not blacklist in case of soft error or fatal error.
|
||||
break;
|
||||
case SyncFileItem::NormalError:
|
||||
if (blacklistCheck(_propagator->_journal, *item) && item->_hasBlacklistEntry) {
|
||||
if (blacklistCheck(_propagator->_journal, *_item) && _item->_hasBlacklistEntry) {
|
||||
// do not error if the item was, and continues to be, blacklisted
|
||||
status = SyncFileItem::FileIgnored;
|
||||
item->_errorString.prepend(tr("Continue blacklisting:") + " ");
|
||||
_item->_errorString.prepend(tr("Continue blacklisting:") + " ");
|
||||
}
|
||||
break;
|
||||
case SyncFileItem::Success:
|
||||
case SyncFileItem::Restoration:
|
||||
if( item->_hasBlacklistEntry ) {
|
||||
if( _item->_hasBlacklistEntry ) {
|
||||
// wipe blacklist entry.
|
||||
_propagator->_journal->wipeErrorBlacklistEntry(item->_file);
|
||||
_propagator->_journal->wipeErrorBlacklistEntry(_item->_file);
|
||||
// remove a blacklist entry in case the file was moved.
|
||||
if( item->_originalFile != item->_file ) {
|
||||
_propagator->_journal->wipeErrorBlacklistEntry(item->_originalFile);
|
||||
if( _item->_originalFile != _item->_file ) {
|
||||
_propagator->_journal->wipeErrorBlacklistEntry(_item->_originalFile);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -174,15 +171,9 @@ void PropagateItemJob::itemDone(SyncFileItemPtr item, SyncFileItem::Status statu
|
||||
break;
|
||||
}
|
||||
|
||||
item->_status = status;
|
||||
_item->_status = status;
|
||||
|
||||
emit itemCompleted(*item, *this);
|
||||
}
|
||||
|
||||
void PropagateItemJob::done(SyncFileItem::Status status, const QString &errorString)
|
||||
{
|
||||
_state = Finished;
|
||||
itemDone(_item, status, errorString);
|
||||
emit itemCompleted(*_item, *this);
|
||||
emit finished(status);
|
||||
}
|
||||
|
||||
@@ -285,9 +276,7 @@ PropagateItemJob* OwncloudPropagator::createJob(const SyncFileItemPtr &item) {
|
||||
return job;
|
||||
} else {
|
||||
PropagateUploadFileCommon *job = 0;
|
||||
static const auto chunkng = qgetenv("OWNCLOUD_CHUNKING_NG");
|
||||
if (item->_size > chunkSize()
|
||||
&& (account()->capabilities().chunkingNg() || chunkng == "1") && chunkng != "0") {
|
||||
if (item->_size > chunkSize() && account()->capabilities().chunkingNg()) {
|
||||
job = new PropagateUploadFileNG(this, item);
|
||||
} else {
|
||||
job = new PropagateUploadFileV1(this, item);
|
||||
@@ -319,17 +308,18 @@ void OwncloudPropagator::start(const SyncFileItemVector& items)
|
||||
* In order to do that we loop over the items. (which are sorted by destination)
|
||||
* When we enter a directory, we can create the directory job and push it on the stack. */
|
||||
|
||||
/// root job is initialized as PropagateDirectory
|
||||
_rootJob.reset(new PropagateDirectory(this));
|
||||
|
||||
QStack<QPair<QString /* directory name */, PropagateDirectory* /* job */> > directories;
|
||||
directories.push(qMakePair(QString(), _rootJob.data()));
|
||||
QVector<PropagatorJob*> directoriesToRemove;
|
||||
QString removedDirectory;
|
||||
|
||||
quint64 chunkSize = OwncloudPropagator::chunkSize();
|
||||
|
||||
// TODO: here we should also check somehow if bundle is not blacklisted
|
||||
bool enableBundledRequests = _account->bundledRequestsEnabled() && !this->hasNetworkLimit();
|
||||
PropagateDataTransfers* dataTransfers = new PropagateDataTransfers(this);
|
||||
|
||||
/// directories will be used to create a sync logic
|
||||
/// this will create/update logical directories structure
|
||||
foreach(const SyncFileItemPtr &item, items) {
|
||||
|
||||
if (!removedDirectory.isEmpty() && item->_file.startsWith(removedDirectory)) {
|
||||
@@ -406,18 +396,12 @@ void OwncloudPropagator::start(const SyncFileItemVector& items)
|
||||
currentDirJob->append(dir);
|
||||
}
|
||||
directories.push(qMakePair(item->destination() + "/" , dir));
|
||||
} else if (enableBundledRequests
|
||||
&& (item->_instruction == CSYNC_INSTRUCTION_NEW)
|
||||
&& (item->_direction == SyncFileItem::Up)
|
||||
&& (item->_size < chunkSize)) {
|
||||
//this will create list of bundle files to sync for that bundlejob
|
||||
if (directories.top().second->_bundleJob.isNull()) {
|
||||
PropagateBundle* bundleJob = new PropagateBundle(this);
|
||||
directories.top().second->_bundleJob.reset(bundleJob);
|
||||
}
|
||||
PropagateBundle* bundleJob = qobject_cast<PropagateBundle*>(directories.top().second->_bundleJob.data());
|
||||
bundleJob->append(item);
|
||||
} else if (item->_instruction == CSYNC_INSTRUCTION_NEW
|
||||
|| item->_instruction == CSYNC_INSTRUCTION_SYNC){
|
||||
// for new/updated files add this to data transfers job
|
||||
dataTransfers->append(createJob(item));
|
||||
} else if (PropagateItemJob* current = createJob(item)) {
|
||||
// for conflics, ignore, move, delete etc sync items, add the to directories logic
|
||||
if (item->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE) {
|
||||
// will delete directories, so defer execution
|
||||
directoriesToRemove.prepend(current);
|
||||
@@ -428,6 +412,11 @@ void OwncloudPropagator::start(const SyncFileItemVector& items)
|
||||
}
|
||||
}
|
||||
|
||||
/// dataTransfers will be used to create a data transfer logic
|
||||
/// create/update files withing already created/updated directories structure
|
||||
_rootJob->append(dataTransfers);
|
||||
|
||||
/// directories to remove have to go last, nice there could be moves
|
||||
foreach(PropagatorJob* it, directoriesToRemove) {
|
||||
_rootJob->append(it);
|
||||
}
|
||||
@@ -632,16 +621,6 @@ bool PropagateDirectory::scheduleNextJob()
|
||||
if (_state == NotYetStarted) {
|
||||
_state = Running;
|
||||
|
||||
if(_bundleJob){
|
||||
PropagateBundle* bundle = qobject_cast<PropagateBundle*>(_bundleJob.take());
|
||||
bundle->_item->_direction = SyncFileItem::Direction::Up;
|
||||
bundle->_item->_type = SyncFileItem::Type::RequestsContainer;
|
||||
bundle->_item->_instruction = CSYNC_INSTRUCTION_NEW;
|
||||
bundle->_item->_size = bundle->syncItemsSize();
|
||||
bundle->_item->_originalFile = tr("%1 file(s)").arg(bundle->syncItemsNumber());
|
||||
_subJobs.append(bundle);
|
||||
}
|
||||
|
||||
if (!_firstJob && _subJobs.isEmpty()) {
|
||||
finalize();
|
||||
return true;
|
||||
@@ -680,7 +659,6 @@ bool PropagateDirectory::scheduleNextJob()
|
||||
Q_ASSERT(_subJobs.at(i)->_state == Running);
|
||||
|
||||
auto paral = _subJobs.at(i)->parallelism();
|
||||
|
||||
if (paral == WaitForFinished) {
|
||||
return false;
|
||||
}
|
||||
@@ -768,6 +746,97 @@ qint64 PropagateDirectory::committedDiskSpace() const
|
||||
return needed;
|
||||
}
|
||||
|
||||
|
||||
// ================================================================================
|
||||
|
||||
PropagatorJob::JobParallelism PropagateDataTransfers::parallelism()
|
||||
{
|
||||
// Upload and Download jobs parallelism is FullParallelism
|
||||
|
||||
return FullParallelism;
|
||||
}
|
||||
|
||||
|
||||
bool PropagateDataTransfers::scheduleNextJob()
|
||||
{
|
||||
if (_state == Finished) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_state == NotYetStarted) {
|
||||
_state = Running;
|
||||
|
||||
// at the begining of the Directory Job, update expected number of Jobs to be synced
|
||||
_totalJobs = _subJobs.count();
|
||||
|
||||
if (_subJobs.isEmpty()) {
|
||||
finalize();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
QMutableListIterator<PropagatorJob *> subJobsIterator(_subJobs);
|
||||
|
||||
while (subJobsIterator.hasNext()) {
|
||||
subJobsIterator.next();
|
||||
// get the state of the state of the sub job pointed by call next()
|
||||
// peekPrevious() will directly access the item through hash in the QList at that subjob
|
||||
if (subJobsIterator.peekPrevious()->_state == Finished) {
|
||||
// if this items is finish, remove it from the _subJobs list as it is not needed anymore
|
||||
subJobsIterator.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (possiblyRunNextJob(subJobsIterator.peekPrevious())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Q_ASSERT(subJobsIterator.peekPrevious()->_state == Running);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void PropagateDataTransfers::slotSubJobFinished(SyncFileItem::Status status)
|
||||
{
|
||||
if (status == SyncFileItem::FatalError) {
|
||||
abort();
|
||||
_state = Finished;
|
||||
emit finished(status);
|
||||
return;
|
||||
} else if (status == SyncFileItem::NormalError || status == SyncFileItem::SoftError) {
|
||||
_hasError = status;
|
||||
}
|
||||
_runningNow--;
|
||||
_jobsFinished++;
|
||||
|
||||
// We finished processing all the jobs
|
||||
// check if we finished
|
||||
if (_jobsFinished >= _totalJobs) {
|
||||
Q_ASSERT(!_runningNow); // how can we be finished if there are still jobs running now
|
||||
finalize();
|
||||
} else {
|
||||
emit ready();
|
||||
}
|
||||
}
|
||||
|
||||
void PropagateDataTransfers::finalize()
|
||||
{
|
||||
_state = Finished;
|
||||
emit finished(_hasError == SyncFileItem::NoStatus ? SyncFileItem::Success : _hasError);
|
||||
}
|
||||
|
||||
qint64 PropagateDataTransfers::committedDiskSpace() const
|
||||
{
|
||||
qint64 needed = 0;
|
||||
foreach (PropagatorJob* job, _subJobs) {
|
||||
needed += job->committedDiskSpace();
|
||||
}
|
||||
return needed;
|
||||
}
|
||||
|
||||
|
||||
// ================================================================================
|
||||
|
||||
CleanupPollsJob::~CleanupPollsJob()
|
||||
{}
|
||||
|
||||
|
||||
@@ -136,7 +136,6 @@ class PropagateItemJob : public PropagatorJob {
|
||||
Q_OBJECT
|
||||
protected:
|
||||
void done(SyncFileItem::Status status, const QString &errorString = QString());
|
||||
void itemDone(SyncFileItemPtr item, SyncFileItem::Status status, const QString &errorString = QString());
|
||||
|
||||
bool checkForProblemsWithShared(int httpStatusCode, const QString& msg);
|
||||
|
||||
@@ -179,7 +178,7 @@ public slots:
|
||||
|
||||
|
||||
/**
|
||||
* @brief Propagate a directory, and all its sub entries.
|
||||
* @brief Propagate a directory, and all its sub entries which are not uploads/downloads.
|
||||
* @ingroup libsync
|
||||
*/
|
||||
class OWNCLOUDSYNC_EXPORT PropagateDirectory : public PropagatorJob {
|
||||
@@ -188,9 +187,6 @@ public:
|
||||
// e.g: create the directory
|
||||
QScopedPointer<PropagateItemJob>_firstJob;
|
||||
|
||||
// bundling upload files job
|
||||
QScopedPointer<PropagateItemJob> _bundleJob;
|
||||
|
||||
// all the sub files or sub directories.
|
||||
QVector<PropagatorJob *> _subJobs;
|
||||
|
||||
@@ -203,7 +199,7 @@ public:
|
||||
|
||||
explicit PropagateDirectory(OwncloudPropagator *propagator, const SyncFileItemPtr &item = SyncFileItemPtr(new SyncFileItem))
|
||||
: PropagatorJob(propagator)
|
||||
, _firstJob(0),_bundleJob(0), _item(item), _jobsFinished(0), _runningNow(0), _hasError(SyncFileItem::NoStatus), _firstUnfinishedSubJob(0)
|
||||
, _firstJob(0), _item(item), _jobsFinished(0), _runningNow(0), _hasError(SyncFileItem::NoStatus), _firstUnfinishedSubJob(0)
|
||||
{ }
|
||||
|
||||
virtual ~PropagateDirectory() {
|
||||
@@ -247,6 +243,60 @@ private slots:
|
||||
void slotSubJobFinished(SyncFileItem::Status status);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Propagate new/updates of files to be uploaded/downloaded
|
||||
* @ingroup libsync
|
||||
*/
|
||||
class OWNCLOUDSYNC_EXPORT PropagateDataTransfers : public PropagatorJob {
|
||||
Q_OBJECT
|
||||
public:
|
||||
// all the file uploads and downloads
|
||||
QList<PropagatorJob *> _subJobs;
|
||||
|
||||
int _jobsFinished; // number of jobs that have completed
|
||||
int _runningNow; // number of subJobs running right now
|
||||
SyncFileItem::Status _hasError; // NoStatus, or NormalError / SoftError if there was an error
|
||||
int _totalJobs;
|
||||
|
||||
explicit PropagateDataTransfers(OwncloudPropagator *propagator)
|
||||
: PropagatorJob(propagator)
|
||||
, _jobsFinished(0), _runningNow(0), _hasError(SyncFileItem::NoStatus), _totalJobs(0)
|
||||
{ }
|
||||
|
||||
virtual ~PropagateDataTransfers() {
|
||||
qDeleteAll(_subJobs);
|
||||
}
|
||||
|
||||
void append(PropagatorJob *subJob) {
|
||||
_subJobs.append(subJob);
|
||||
}
|
||||
|
||||
virtual bool scheduleNextJob() Q_DECL_OVERRIDE;
|
||||
virtual JobParallelism parallelism() Q_DECL_OVERRIDE;
|
||||
virtual void abort() Q_DECL_OVERRIDE {
|
||||
foreach (PropagatorJob *j, _subJobs)
|
||||
j->abort();
|
||||
}
|
||||
|
||||
void finalize();
|
||||
|
||||
qint64 committedDiskSpace() const Q_DECL_OVERRIDE;
|
||||
|
||||
private slots:
|
||||
bool possiblyRunNextJob(PropagatorJob *next) {
|
||||
if (next->_state == NotYetStarted) {
|
||||
connect(next, SIGNAL(finished(SyncFileItem::Status)), this, SLOT(slotSubJobFinished(SyncFileItem::Status)), Qt::QueuedConnection);
|
||||
connect(next, SIGNAL(itemCompleted(const SyncFileItem &, const PropagatorJob &)),
|
||||
this, SIGNAL(itemCompleted(const SyncFileItem &, const PropagatorJob &)));
|
||||
connect(next, SIGNAL(progress(const SyncFileItem &,quint64)), this, SIGNAL(progress(const SyncFileItem &,quint64)));
|
||||
connect(next, SIGNAL(ready()), this, SIGNAL(ready()));
|
||||
_runningNow++;
|
||||
}
|
||||
return next->scheduleNextJob();
|
||||
}
|
||||
|
||||
void slotSubJobFinished(SyncFileItem::Status status);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Dummy job that just mark it as completed and ignored
|
||||
@@ -292,7 +342,7 @@ public:
|
||||
~OwncloudPropagator();
|
||||
|
||||
void start(const SyncFileItemVector &_syncedItems);
|
||||
bool hasNetworkLimit();
|
||||
|
||||
QAtomicInt _downloadLimit;
|
||||
QAtomicInt _uploadLimit;
|
||||
BandwidthManager _bandwidthManager;
|
||||
@@ -326,10 +376,6 @@ public:
|
||||
emitFinished(SyncFileItem::NormalError);
|
||||
}
|
||||
|
||||
int runningNowAtRootJob() const {
|
||||
return _rootJob->_runningNow;
|
||||
}
|
||||
|
||||
// timeout in seconds
|
||||
static int httpTimeout();
|
||||
|
||||
@@ -390,7 +436,6 @@ private:
|
||||
friend class PropagateRemoteMove;
|
||||
friend class PropagateUploadFileV1;
|
||||
friend class PropagateUploadFileNG;
|
||||
friend class PropagateBundle;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -97,6 +97,14 @@ bool SqlDatabase::openOrCreateReadWrite( const QString& filename )
|
||||
}
|
||||
|
||||
if( !checkDb() ) {
|
||||
// When disk space is low, checking the db may fail even though it's fine.
|
||||
qint64 freeSpace = Utility::freeDiskSpace(filename);
|
||||
if (freeSpace < 1000000) {
|
||||
qDebug() << "Consistency check failed, disk space is low, aborting" << freeSpace;
|
||||
close();
|
||||
return false;
|
||||
}
|
||||
|
||||
qDebug() << "Consistency check failed, removing broken db" << filename;
|
||||
close();
|
||||
QFile::remove(filename);
|
||||
|
||||
@@ -29,13 +29,11 @@ QString Progress::asResultString( const SyncFileItem& item)
|
||||
case CSYNC_INSTRUCTION_SYNC:
|
||||
case CSYNC_INSTRUCTION_NEW:
|
||||
case CSYNC_INSTRUCTION_TYPE_CHANGE:
|
||||
if (item._type != SyncFileItem::Type::RequestsContainer) {
|
||||
if (item._direction != SyncFileItem::Up) {
|
||||
return QCoreApplication::translate( "progress", "Downloaded");
|
||||
} else
|
||||
return QCoreApplication::translate( "progress", "Uploaded");
|
||||
}
|
||||
return QCoreApplication::translate( "progress", "Processed Bundle");
|
||||
if (item._direction != SyncFileItem::Up) {
|
||||
return QCoreApplication::translate( "progress", "Downloaded");
|
||||
} else {
|
||||
return QCoreApplication::translate( "progress", "Uploaded");
|
||||
}
|
||||
case CSYNC_INSTRUCTION_CONFLICT:
|
||||
return QCoreApplication::translate( "progress", "Server version downloaded, copied changed local file into conflict file");
|
||||
case CSYNC_INSTRUCTION_REMOVE:
|
||||
@@ -147,8 +145,12 @@ void ProgressInfo::reset()
|
||||
_sizeProgress = Progress();
|
||||
_fileProgress = Progress();
|
||||
_totalSizeOfCompletedJobs = 0;
|
||||
_maxBytesPerSecond = 100000.0;
|
||||
_maxFilesPerSecond = 2.0;
|
||||
|
||||
// Historically, these starting estimates were way lower, but that lead
|
||||
// to gross overestimation of ETA when a good estimate wasn't available.
|
||||
_maxBytesPerSecond = 2000000.0; // 2 MB/s
|
||||
_maxFilesPerSecond = 10.0;
|
||||
|
||||
_updateEstimatesTimer.stop();
|
||||
_lastCompletedItem = SyncFileItem();
|
||||
}
|
||||
|
||||
@@ -1,608 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) by Olivier Goffart <ogoffart@owncloud.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#include "propagateupload.h"
|
||||
#include "propagatebundle.h"
|
||||
#include "owncloudpropagator_p.h"
|
||||
#include "networkjobs.h"
|
||||
#include "account.h"
|
||||
#include "syncjournaldb.h"
|
||||
#include "syncjournalfilerecord.h"
|
||||
#include "utility.h"
|
||||
#include "filesystem.h"
|
||||
#include "propagatorjobs.h"
|
||||
#include "checksums.h"
|
||||
#include "syncengine.h"
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QFileInfo>
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 2)
|
||||
namespace {
|
||||
const char owncloudShouldSoftCancelPropertyName[] = "owncloud-should-soft-cancel";
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace OCC {
|
||||
|
||||
/**
|
||||
* We do not want to upload files that are currently being modified.
|
||||
* To avoid that, we don't upload files that have a modification time
|
||||
* that is too close to the current time.
|
||||
*
|
||||
* This interacts with the msBetweenRequestAndSync delay in the folder
|
||||
* manager. If that delay between file-change notification and sync
|
||||
* has passed, we should accept the file for upload here.
|
||||
*/
|
||||
static bool fileIsStillChanging(const SyncFileItem & item)
|
||||
{
|
||||
const QDateTime modtime = Utility::qDateTimeFromTime_t(item._modtime);
|
||||
const qint64 msSinceMod = modtime.msecsTo(QDateTime::currentDateTime());
|
||||
|
||||
return msSinceMod < SyncEngine::minimumFileAgeForUpload
|
||||
// if the mtime is too much in the future we *do* upload the file
|
||||
&& msSinceMod > -10000;
|
||||
}
|
||||
|
||||
void PropagateBundle::start()
|
||||
{
|
||||
if (_propagator->_abortRequested.fetchAndAddRelaxed(0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_itemsToChecksum.isEmpty()) {
|
||||
//this will block other threads from processing files and bundling while this will do that
|
||||
//after sufficient number of files being checksumed, flag will be unblocked
|
||||
_preparingBundle = true;
|
||||
|
||||
//this will add checksums and remove itself from activeJobList after is completed
|
||||
_propagator->_activeJobList.append(this);
|
||||
return slotComputeTransmissionChecksum();
|
||||
}
|
||||
|
||||
//this can generate itemDone(), dont add to activeJobList
|
||||
startBundle();
|
||||
}
|
||||
|
||||
void PropagateBundle::slotComputeTransmissionChecksum()
|
||||
{
|
||||
if (_propagator->_abortRequested.fetchAndAddRelaxed(0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const SyncFileItemPtr &item = _itemsToChecksum.first();
|
||||
const QString filePath = _propagator->getFilePath(item->_file);
|
||||
|
||||
// remember the modtime before checksumming to be able to detect a file
|
||||
// change during the checksum calculation
|
||||
item->_modtime = FileSystem::getModTime(filePath);
|
||||
|
||||
QByteArray checksumType = contentChecksumType();
|
||||
|
||||
// Maybe the discovery already computed the checksum?
|
||||
if (item->_contentChecksumType == checksumType
|
||||
&& !item->_contentChecksum.isEmpty()) {
|
||||
// Reuse the content checksum as the transmission checksum if possible
|
||||
const auto supportedTransmissionChecksums =
|
||||
_propagator->account()->capabilities().supportedChecksumTypes();
|
||||
if (supportedTransmissionChecksums.contains(checksumType)) {
|
||||
slotStartUpload(checksumType, item->_contentChecksum);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Compute the transmission checksum.
|
||||
auto computeChecksum = new ComputeChecksum(this);
|
||||
if (uploadChecksumEnabled()) {
|
||||
computeChecksum->setChecksumType(_propagator->account()->capabilities().uploadChecksumType());
|
||||
} else {
|
||||
computeChecksum->setChecksumType(QByteArray());
|
||||
}
|
||||
|
||||
connect(computeChecksum, SIGNAL(done(QByteArray,QByteArray)),
|
||||
SLOT(slotStartUpload(QByteArray,QByteArray)));
|
||||
computeChecksum->start(filePath);
|
||||
}
|
||||
|
||||
void PropagateBundle::slotStartUpload(const QByteArray& transmissionChecksumType, const QByteArray& transmissionChecksum)
|
||||
{
|
||||
const SyncFileItemPtr &item = _itemsToChecksum.takeFirst();
|
||||
|
||||
item->_contentChecksum = transmissionChecksum;
|
||||
item->_contentChecksumType = transmissionChecksumType;
|
||||
|
||||
// add this item to sync list, as it now has checksum computed
|
||||
_itemsToSync.append(item);
|
||||
|
||||
_currentBundleSize += item->_size;
|
||||
_currentRequestsNumber++;
|
||||
|
||||
// Remove ourselfs from the list of active job, before any posible call to itemDone()
|
||||
_propagator->_activeJobList.removeOne(this);
|
||||
|
||||
// check if we have anything to add to our bundle
|
||||
if (!_itemsToChecksum.empty()){
|
||||
SyncFileItemPtr nextItem = _itemsToChecksum.first();
|
||||
|
||||
// if next item will exceed bundle size, send the bundle now
|
||||
// otherwise, compute next checksum
|
||||
if (((_currentBundleSize + nextItem->_size) >= chunkSize())
|
||||
|| (_currentRequestsNumber >= checkBundledRequestsLimits())){
|
||||
_currentBundleSize = 0;
|
||||
_currentRequestsNumber = 0;
|
||||
startBundle();
|
||||
} else {
|
||||
start();
|
||||
}
|
||||
} else {
|
||||
//_itemsToChecksum is already empty, send what is left in _itemsToSync.
|
||||
startBundle();
|
||||
}
|
||||
}
|
||||
|
||||
void PropagateBundle::startBundle()
|
||||
{
|
||||
if (_propagator->_abortRequested.fetchAndAddRelaxed(0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// job takes ownership of device via a QScopedPointer. Job deletes itself when finishing
|
||||
MultipartJob* job = new MultipartJob(_propagator->account(), _propagator->account()->davFilesPath(), new QHttpMultiPart(QHttpMultiPart::RelatedType));
|
||||
|
||||
// start constructing the bundle metadata xml file
|
||||
QByteArray xml = "<?xml version='1.0' encoding='UTF-8'?>\n"
|
||||
"<d:multipart xmlns:d=\"DAV:\">\n";
|
||||
int contentID = 0;
|
||||
|
||||
while (!_itemsToSync.isEmpty()){
|
||||
const SyncFileItemPtr &item = _itemsToSync.takeFirst();
|
||||
const QString fullFilePath = _propagator->getFilePath(item->_file);
|
||||
|
||||
if (!FileSystem::fileExists(fullFilePath)) {
|
||||
itemDone(item, SyncFileItem::SoftError, tr("File Removed"));
|
||||
continue;
|
||||
}
|
||||
|
||||
time_t prevModtime = item->_modtime; // the _item value was set in PropagateUploadFileQNAM::start()
|
||||
// but a potential checksum calculation could have taken some time during which the file could
|
||||
// have been changed again, so better check again here.
|
||||
|
||||
item->_modtime = FileSystem::getModTime(fullFilePath);
|
||||
if( prevModtime != item->_modtime ) {
|
||||
_propagator->_anotherSyncNeeded = true;
|
||||
itemDone(item, SyncFileItem::SoftError, tr("Local file changed during syncing. It will be resumed."));
|
||||
continue;
|
||||
}
|
||||
|
||||
item->_size = FileSystem::getSize(fullFilePath);
|
||||
|
||||
// But skip the file if the mtime is too close to 'now'!
|
||||
// That usually indicates a file that is still being changed
|
||||
// or not yet fully copied to the destination.
|
||||
if (fileIsStillChanging(*item)) {
|
||||
_propagator->_anotherSyncNeeded = true;
|
||||
itemDone(item, SyncFileItem::SoftError, tr("Local file changed during sync."));
|
||||
continue;
|
||||
}
|
||||
|
||||
//TODO use Upload Device to support bandwith limitation on the client
|
||||
QFile *file = new QFile(fullFilePath);
|
||||
if (! file->open(QIODevice::ReadOnly)) {
|
||||
qDebug() << "ERR: Could not prepare upload device: " << file->errorString();
|
||||
|
||||
// If the file is currently locked, we want to retry the sync
|
||||
// when it becomes available again.
|
||||
if (FileSystem::isFileLocked(fullFilePath)) {
|
||||
emit _propagator->seenLockedFile(fullFilePath);
|
||||
}
|
||||
|
||||
// Soft error because this is likely caused by the user modifying his files while syncing
|
||||
itemDone(item, SyncFileItem::SoftError, tr("ERR: Could not prepare upload device"));
|
||||
} else {
|
||||
// add xml part for this specific file
|
||||
xml += " <d:part>\n"
|
||||
" <d:prop>\n";
|
||||
if (!item->_contentChecksumType.isEmpty()) {
|
||||
xml += " <d:oc-checksum>" + makeChecksumHeader(item->_contentChecksumType, item->_contentChecksum) + "</d:oc-checksum>\n";
|
||||
}
|
||||
|
||||
if(item->_file.contains(".sys.admin#recall#")) {
|
||||
xml += " <d:oc-tag>" + QByteArray(".sys.admin#recall#") + "</d:oc-tag>\n";
|
||||
}
|
||||
|
||||
xml += " <d:oc-path>" + getRemotePath(item->_file) + "</d:oc-path>\n"
|
||||
" <d:oc-mtime>" + QByteArray::number(qint64(item->_modtime)) + "</d:oc-mtime>\n"
|
||||
" <d:oc-id>" + QByteArray::number(contentID) + "</d:oc-id>\n"
|
||||
" <d:oc-total-length>" + QByteArray::number(qint64(item->_size)) + "</d:oc-total-length>\n"
|
||||
" </d:prop>\n"
|
||||
" </d:part>\n";
|
||||
|
||||
QHttpPart bundleContent;
|
||||
bundleContent.setRawHeader("Content-ID", QByteArray::number(qint64(contentID)));
|
||||
bundleContent.setBody(file->readAll());
|
||||
file->close();
|
||||
job->addItemPart(bundleContent, item);
|
||||
contentID++;
|
||||
}
|
||||
delete file;
|
||||
}
|
||||
|
||||
// finish xml building
|
||||
xml += "</d:multipart>";
|
||||
|
||||
if (!job->isEmpty())
|
||||
{
|
||||
QHttpPart bundleMetadata;
|
||||
bundleMetadata.setBody(xml);
|
||||
bundleMetadata.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("text/xml; charset=utf-8"));
|
||||
bundleMetadata.setHeader(QNetworkRequest::ContentLengthHeader, QByteArray::number(xml.size()));
|
||||
job->addRootPart(bundleMetadata);
|
||||
|
||||
_propagator->_activeJobList.append(this);
|
||||
job->_duration.start();
|
||||
_jobs.append(job);
|
||||
connect(job, SIGNAL(finishedSignal()), this, SLOT(slotMultipartFinished()));
|
||||
connect(job, SIGNAL(destroyed(QObject*)), this, SLOT(slotJobDestroyed(QObject*)));
|
||||
job->start();
|
||||
|
||||
// we have finished preparing bundles to send, allow other bundles to be send
|
||||
_preparingBundle = false;
|
||||
|
||||
// check if there are any items to be bundled and if you can run another parallel job
|
||||
if (!_itemsToChecksum.empty() && (_propagator->_activeJobList.count() < _propagator->maximumActiveJob())) {
|
||||
start();
|
||||
}
|
||||
} else {
|
||||
delete job;
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray PropagateBundle::getRemotePath(QString filePath){
|
||||
QString remotePath(_propagator->_remoteFolder+filePath);
|
||||
return remotePath.toStdString().c_str();
|
||||
}
|
||||
|
||||
void PropagateBundle::append(const SyncFileItemPtr &bundledFile){
|
||||
_size += bundledFile->_size;
|
||||
_itemsToChecksum.append(bundledFile);
|
||||
}
|
||||
|
||||
bool PropagateBundle::empty(){
|
||||
return _itemsToChecksum.empty();
|
||||
}
|
||||
|
||||
void PropagateBundle::slotMultipartFinished()
|
||||
{
|
||||
MultipartJob *job = qobject_cast<MultipartJob *>(sender());
|
||||
Q_ASSERT(job);
|
||||
slotJobDestroyed(job); // remove it from the _jobs list
|
||||
|
||||
qDebug() << Q_FUNC_INFO << job->reply()->request().url() << "FINISHED WITH STATUS"
|
||||
<< job->reply()->error()
|
||||
<< (job->reply()->error() == QNetworkReply::NoError ? QLatin1String("") : job->reply()->errorString())
|
||||
<< job->reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute)
|
||||
<< job->reply()->attribute(QNetworkRequest::HttpReasonPhraseAttribute);
|
||||
|
||||
_propagator->_activeJobList.removeOne(this);
|
||||
|
||||
QNetworkReply::NetworkError err = job->reply()->error();
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 2)
|
||||
if (job->reply()->error() == QNetworkReply::OperationCanceledError && job->reply()->property(owncloudShouldSoftCancelPropertyName).isValid()) {
|
||||
// Abort the job and try again later.
|
||||
// This works around a bug in QNAM wich might reuse a non-empty buffer for the next request.
|
||||
qDebug() << "Forcing job abort on HTTP connection reset with Qt < 5.4.2.";
|
||||
_propagator->_anotherSyncNeeded = true;
|
||||
abortWithError(SyncFileItem::SoftError, tr("Forcing job abort on HTTP connection reset with Qt < 5.4.2."));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err != QNetworkReply::NoError) {
|
||||
_item->_httpErrorCode = job->reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
|
||||
QByteArray replyContent = job->reply()->readAll();
|
||||
qDebug() << replyContent; // display the XML error in the debug
|
||||
QString errorString = errorMessage(job->errorString(), replyContent);
|
||||
|
||||
if (job->reply()->hasRawHeader("OC-ErrorString")) {
|
||||
errorString = job->reply()->rawHeader("OC-ErrorString");
|
||||
}
|
||||
|
||||
//TODO: soft error till other mechanism will be added - this will retry bundle later.
|
||||
abortWithError(SyncFileItem::SoftError, errorString);
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse DAV response
|
||||
QXmlStreamReader reader(job->reply());
|
||||
reader.addExtraNamespaceDeclaration(QXmlStreamNamespaceDeclaration("d", "DAV:"));
|
||||
|
||||
QString currentHref;
|
||||
QString currentOcPath;
|
||||
QString expectedPath(_propagator->account()->davFilesPath());
|
||||
QMap<QString, QString> itemProperties;
|
||||
QMap<QString, QMap<QString, QString> > responseObjectsProperties;
|
||||
bool insidePropstat = false;
|
||||
bool insideProp = false;
|
||||
bool insideError = false;
|
||||
|
||||
while (!reader.atEnd()) {
|
||||
QXmlStreamReader::TokenType type = reader.readNext();
|
||||
QString name = reader.name().toString();
|
||||
// Start elements with DAV:
|
||||
if (type == QXmlStreamReader::StartElement && reader.namespaceUri() == QLatin1String("DAV:")) {
|
||||
if (name == QLatin1String("href")) {
|
||||
// We don't use URL encoding in our request URL (which is the expected path) (QNAM will do it for us)
|
||||
// but the result will have URL encoding..
|
||||
QString hrefString = QString::fromUtf8(QByteArray::fromPercentEncoding(reader.readElementText().toUtf8()));
|
||||
if (!hrefString.startsWith(expectedPath)) {
|
||||
qDebug() << "Invalid href" << hrefString << "expected ending with" << expectedPath;
|
||||
}
|
||||
currentHref = hrefString;
|
||||
} else if (name == QLatin1String("response")) {
|
||||
continue;
|
||||
} else if (name == QLatin1String("propstat")) {
|
||||
insidePropstat = true;
|
||||
} else if (name == QLatin1String("status") && insidePropstat) {
|
||||
QString httpStatus = reader.readElementText();
|
||||
itemProperties.insert(name, httpStatus);
|
||||
} else if (name == QLatin1String("prop")) {
|
||||
insideProp = true;
|
||||
continue;
|
||||
} else if (name == QLatin1String("multistatus")) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (type == QXmlStreamReader::StartElement && insidePropstat && insideProp) {
|
||||
if (name == QLatin1String("oc-path")){
|
||||
currentOcPath = reader.readElementText(QXmlStreamReader::SkipChildElements);
|
||||
} else if (name == QLatin1String("error")){
|
||||
insideError = true;
|
||||
} else if (name == QLatin1String("exception") && insideError){
|
||||
itemProperties.insert(name, reader.readElementText(QXmlStreamReader::SkipChildElements));
|
||||
} else if (name == QLatin1String("message") && insideError){
|
||||
itemProperties.insert(name, reader.readElementText(QXmlStreamReader::SkipChildElements));
|
||||
} else{
|
||||
itemProperties.insert(name, reader.readElementText(QXmlStreamReader::SkipChildElements));
|
||||
}
|
||||
}
|
||||
|
||||
// End elements with DAV:
|
||||
if (type == QXmlStreamReader::EndElement) {
|
||||
if (reader.namespaceUri() == QLatin1String("DAV:")) {
|
||||
if (reader.name() == "response") {
|
||||
currentHref.clear();
|
||||
} else if (reader.name() == "propstat") {
|
||||
insidePropstat = false;
|
||||
if (!currentOcPath.isEmpty()){
|
||||
responseObjectsProperties.insert(currentOcPath, QMap<QString,QString>(itemProperties));
|
||||
}
|
||||
currentOcPath.clear();
|
||||
itemProperties.clear();
|
||||
} else if (reader.name() == "prop") {
|
||||
insideProp = false;
|
||||
} else if (reader.name() == "error") {
|
||||
insideError = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (reader.hasError()) {
|
||||
// XML Parser error? Whatever had been emitted before will come as directoryListingIterated
|
||||
qDebug() << "ERROR" << reader.errorString();
|
||||
abortWithError(SyncFileItem::SoftError, tr("Cannot parse multistatus response!"));
|
||||
return;
|
||||
}
|
||||
|
||||
QList<SyncFileItemPtr> syncItems = job->syncItems();
|
||||
|
||||
//get the total duration, and try to estimate sync time for single item in the bundle
|
||||
quint64 avgItemDuration = job->_duration.elapsed()/syncItems.count();
|
||||
|
||||
foreach(const SyncFileItemPtr &item, syncItems) {
|
||||
item->_requestDuration = avgItemDuration;
|
||||
item->_responseTimeStamp = job->responseTimestamp();
|
||||
slotItemFinished(item, responseObjectsProperties);
|
||||
}
|
||||
|
||||
// performance logging
|
||||
qDebug() << "*==* duration BUNDLE UPLOAD" << syncItems.count() << "items synced"
|
||||
<< "average duration" << avgItemDuration;
|
||||
// The job might stay alive for the whole sync, release this tiny bit of memory.
|
||||
|
||||
if (_jobs.empty() && _itemsToChecksum.isEmpty()){
|
||||
done(SyncFileItem::Success);
|
||||
} else if (!_preparingBundle){
|
||||
// This will be called only if some other thread is not currently preparing bundles (checksums)
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
void PropagateBundle::slotItemFinished(const SyncFileItemPtr &item, QMap<QString, QMap<QString, QString> > &responseObjectsProperties)
|
||||
{
|
||||
QString itemFilePath(getRemotePath(item->_file));
|
||||
QMap<QString, QString> fileProperties = responseObjectsProperties.value(itemFilePath);
|
||||
|
||||
item->_httpErrorCode = getHttpStatusCode(fileProperties.value("status"));
|
||||
|
||||
if (200 == item->_httpErrorCode){
|
||||
// Check if the file still exists
|
||||
const QString fullFilePath(_propagator->getFilePath(item->_file));
|
||||
if( !FileSystem::fileExists(fullFilePath) ) {
|
||||
_propagator->_anotherSyncNeeded = true;
|
||||
}
|
||||
|
||||
if (! FileSystem::verifyFileUnchanged(fullFilePath, item->_size, item->_modtime)) {
|
||||
_propagator->_anotherSyncNeeded = true;
|
||||
}
|
||||
|
||||
//OC-FileID section
|
||||
if (fileProperties.contains("oc-fileid")){
|
||||
QString fid = fileProperties.value("oc-fileid");
|
||||
if( !item->_fileId.isEmpty() && item->_fileId != fid ) {
|
||||
qDebug() << "WARN: File ID changed!" << item->_fileId << fid;
|
||||
}
|
||||
item->_fileId =fid.toStdString().c_str();
|
||||
}
|
||||
|
||||
//OC-ETag section
|
||||
QByteArray ocEtag = parseEtag(fileProperties.value("oc-etag").toStdString().c_str());
|
||||
QByteArray etag = parseEtag(fileProperties.value("etag").toStdString().c_str());
|
||||
item->_etag = ocEtag.isEmpty() ? etag : ocEtag;
|
||||
if (ocEtag.length() > 0 && ocEtag != etag) {
|
||||
qDebug() << "Quite peculiar, we have an etag != OC-Etag [no problem!]" << etag << ocEtag;
|
||||
}
|
||||
|
||||
if (fileProperties.value("oc-mtime") != "accepted"){
|
||||
// OC-MTime is supported since owncloud 5.0. But not when chunking.
|
||||
// Normally Owncloud 6 always puts OC-MTime
|
||||
qWarning() << "Server does not support OC-MTime" << fileProperties.value("oc-mtime");
|
||||
// Well, the mtime was not set
|
||||
itemDone(item, SyncFileItem::SoftError, "Server does not support OC-MTime");
|
||||
return;
|
||||
}
|
||||
} else{
|
||||
//We do not check for problems with shared folder since it is only CREATE
|
||||
//REMARK: if the file will support update, ensure to override checkForProblemsWithShared()
|
||||
|
||||
qDebug() << Q_FUNC_INFO << item->_file << "ERROR WITH STATUS"
|
||||
<< fileProperties.value("status")
|
||||
<< fileProperties.value("exception")
|
||||
<< fileProperties.value("message");
|
||||
|
||||
if (412 == _item->_httpErrorCode) {
|
||||
// Precondition Failed: Maybe the bad etag is in the database, we need to clear the
|
||||
// parent folder etag so we won't read from DB next sync.
|
||||
_propagator->_journal->avoidReadFromDbOnNextSync(item->_file);
|
||||
_propagator->_anotherSyncNeeded = true;
|
||||
}
|
||||
|
||||
item->_errorString = fileProperties.value("message");
|
||||
item->_status = classifyError(QNetworkReply::ContentOperationNotPermittedError, item->_httpErrorCode,
|
||||
&_propagator->_anotherSyncNeeded);
|
||||
itemDone(item, item->_status, item->_errorString);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_propagator->_journal->setFileRecord(SyncJournalFileRecord(*item, _propagator->getFilePath(item->_file)))) {
|
||||
itemDone(item, SyncFileItem::FatalError, tr("Error writing metadata to the database"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove from the progress database:
|
||||
_propagator->_journal->setUploadInfo(item->_file, SyncJournalDb::UploadInfo());
|
||||
_propagator->_journal->commit("upload file start");
|
||||
itemDone(item, SyncFileItem::Success);
|
||||
}
|
||||
|
||||
int PropagateBundle::getHttpStatusCode(const QString &status){
|
||||
//if cannot read code, it means that server is not supported and raise 500 Internal Server Error
|
||||
int code = 500;
|
||||
QStringList statusList = status.split(QRegExp("\\s+"));
|
||||
if (2 < statusList.size()){
|
||||
//we expect status list to be at least 3 elements and second element to be the http error code
|
||||
code = statusList.at(1).toInt();
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
void PropagateBundle::slotJobDestroyed(QObject* job)
|
||||
{
|
||||
_jobs.erase(std::remove(_jobs.begin(), _jobs.end(), job) , _jobs.end());
|
||||
}
|
||||
|
||||
// This function is used whenever there is an error occuring and we need to raise status for whole the bundle
|
||||
void PropagateBundle::abortWithError(SyncFileItem::Status status, const QString &error)
|
||||
{
|
||||
foreach(auto *job, _jobs) {
|
||||
if (job->reply()) {
|
||||
qDebug() << Q_FUNC_INFO << job;
|
||||
job->reply()->abort();
|
||||
}
|
||||
}
|
||||
|
||||
done(status, error);
|
||||
}
|
||||
|
||||
MultipartJob::~MultipartJob()
|
||||
{
|
||||
// Make sure that we destroy the QNetworkReply before our _device of which it keeps an internal pointer.
|
||||
setReply(0);
|
||||
}
|
||||
|
||||
void MultipartJob::start() {
|
||||
while(!_syncParts.empty()) {
|
||||
const QHttpPart &itemPart = _syncParts.takeFirst();
|
||||
_multipart->append(itemPart);
|
||||
}
|
||||
|
||||
QNetworkRequest req;
|
||||
setReply(multipartRequest(path(), req, _multipart));
|
||||
_multipart->setParent(reply()); // delete the multiPart with the job
|
||||
setupConnections(reply());
|
||||
|
||||
if( reply()->error() != QNetworkReply::NoError ) {
|
||||
qWarning() << Q_FUNC_INFO << " Network error: " << reply()->errorString();
|
||||
}
|
||||
|
||||
connect(this, SIGNAL(networkActivity()), account().data(), SIGNAL(propagatorNetworkActivity()));
|
||||
|
||||
//TODO this uses _device, and we have no access here to that
|
||||
// // For Qt versions not including https://codereview.qt-project.org/110150
|
||||
// // Also do the runtime check if compiled with an old Qt but running with fixed one.
|
||||
// // (workaround disabled on windows and mac because the binaries we ship have patched qt)
|
||||
//#if QT_VERSION < QT_VERSION_CHECK(4, 8, 7)
|
||||
// if (QLatin1String(qVersion()) < QLatin1String("4.8.7"))
|
||||
// connect(_device.data(), SIGNAL(wasReset()), this, SLOT(slotSoftAbort()));
|
||||
//#elif QT_VERSION > QT_VERSION_CHECK(5, 0, 0) && QT_VERSION < QT_VERSION_CHECK(5, 4, 2) && !defined Q_OS_WIN && !defined Q_OS_MAC
|
||||
// if (QLatin1String(qVersion()) < QLatin1String("5.4.2"))
|
||||
// connect(_device.data(), SIGNAL(wasReset()), this, SLOT(slotSoftAbort()));
|
||||
//#endif
|
||||
|
||||
AbstractNetworkJob::start();
|
||||
}
|
||||
|
||||
void MultipartJob::addItemPart(const QHttpPart &itemPart, const SyncFileItemPtr &item){
|
||||
// add itemPart to queue, this queue will be used to construct the multipart message
|
||||
_syncParts.append(itemPart);
|
||||
|
||||
// add item pointer to queue, it will be used to construct the response at the end.
|
||||
_syncItems.append(item);
|
||||
}
|
||||
|
||||
void MultipartJob::addRootPart(const QHttpPart &itemPart){
|
||||
// if used, this part will be added to the begining of multipart request
|
||||
_syncParts.prepend(itemPart);
|
||||
}
|
||||
|
||||
void MultipartJob::slotTimeout() {
|
||||
qDebug() << "Timeout" << (reply() ? reply()->request().url() : path());
|
||||
if (!reply())
|
||||
return;
|
||||
_errorString = tr("Connection Timeout");
|
||||
reply()->abort();
|
||||
}
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 2)
|
||||
void MultipartJob::slotSoftAbort() {
|
||||
reply()->setProperty(owncloudShouldSoftCancelPropertyName, true);
|
||||
reply()->abort();
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) by Olivier Goffart <ogoffart@owncloud.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "owncloudpropagator.h"
|
||||
#include "networkjobs.h"
|
||||
|
||||
#include <QHttpMultiPart>
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
|
||||
namespace OCC {
|
||||
|
||||
/**
|
||||
* @brief The MultipartJob class
|
||||
* @ingroup libsync
|
||||
*/
|
||||
class MultipartJob : public AbstractNetworkJob {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QHttpMultiPart* _multipart;
|
||||
|
||||
// Vector_syncItems is used in constructing a response at the response arrival
|
||||
QList<SyncFileItemPtr> _syncItems;
|
||||
|
||||
// Vector containing QHttpParts which will be later inserted into request body
|
||||
QList<QHttpPart> _syncParts;
|
||||
|
||||
// error string
|
||||
QString _errorString;
|
||||
public:
|
||||
QElapsedTimer _duration;
|
||||
// Takes ownership of the device
|
||||
explicit MultipartJob(AccountPtr account, const QString& path, QHttpMultiPart* multipart, QObject* parent = 0)
|
||||
: AbstractNetworkJob(account, path, parent), _multipart(multipart), _errorString(QString()) {}
|
||||
~MultipartJob();
|
||||
|
||||
virtual void start() Q_DECL_OVERRIDE;
|
||||
|
||||
virtual bool finished() Q_DECL_OVERRIDE {
|
||||
emit finishedSignal();
|
||||
return true;
|
||||
}
|
||||
|
||||
void addItemPart(const QHttpPart &itemPart, const SyncFileItemPtr &item);
|
||||
|
||||
void addRootPart(const QHttpPart &itemPart);
|
||||
|
||||
bool isEmpty() {
|
||||
return _syncItems.isEmpty();
|
||||
}
|
||||
|
||||
QString errorString() {
|
||||
return _errorString.isEmpty() ? reply()->errorString() : _errorString;
|
||||
}
|
||||
|
||||
QList<SyncFileItemPtr> syncItems() const {
|
||||
return _syncItems;
|
||||
}
|
||||
|
||||
virtual void slotTimeout() Q_DECL_OVERRIDE;
|
||||
|
||||
|
||||
signals:
|
||||
void finishedSignal();
|
||||
|
||||
private slots:
|
||||
#if QT_VERSION < 0x050402
|
||||
void slotSoftAbort();
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The PropagateBundle class
|
||||
* @ingroup libsync
|
||||
*/
|
||||
class PropagateBundle : public PropagateItemJob {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QLinkedList<SyncFileItemPtr> _itemsToSync;
|
||||
QLinkedList<SyncFileItemPtr> _itemsToChecksum;
|
||||
QVector<MultipartJob*> _jobs; /// network jobs that are currently in transit
|
||||
bool _preparingBundle; // Flag blocking processing the same files by many threads
|
||||
quint64 _size; // Tells what is the total size of _itemsToSync inside the bundle
|
||||
quint64 _currentBundleSize;
|
||||
quint64 _currentRequestsNumber;
|
||||
quint64 _totalFiles;
|
||||
// measure the performance of checksum calc and upload
|
||||
Utility::StopWatch _stopWatch;
|
||||
|
||||
public:
|
||||
PropagateBundle(OwncloudPropagator* propagator)
|
||||
: PropagateItemJob(propagator, SyncFileItemPtr(new SyncFileItem)), _preparingBundle(true), _size(0), _currentBundleSize(0), _currentRequestsNumber(0) {}
|
||||
void start() Q_DECL_OVERRIDE;
|
||||
void startBundle();
|
||||
void append(const SyncFileItemPtr &bundledFile);
|
||||
QByteArray getRemotePath(QString filePath);
|
||||
bool empty();
|
||||
bool scheduleNextJob() Q_DECL_OVERRIDE {
|
||||
if (_state == NotYetStarted){
|
||||
_state = Running;
|
||||
QMetaObject::invokeMethod(this, "start");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
quint64 syncItemsSize() const { return _size; }
|
||||
quint64 syncItemsNumber() const { return _itemsToChecksum.count(); }
|
||||
private slots:
|
||||
void slotComputeTransmissionChecksum();
|
||||
void slotStartUpload(const QByteArray& transmissionChecksumType, const QByteArray& transmissionChecksum);
|
||||
void slotMultipartFinished();
|
||||
void slotJobDestroyed(QObject *job);
|
||||
void abortWithError(SyncFileItem::Status status, const QString &error);
|
||||
|
||||
private:
|
||||
quint64 checkBundledRequestsLimits()
|
||||
{
|
||||
//TODO: obtain this value from the server or by other means
|
||||
quint64 maximumBundledFiles = 500;
|
||||
return (maximumBundledFiles/_propagator->maximumActiveJob());
|
||||
}
|
||||
quint64 chunkSize() const { return _propagator->chunkSize(); }
|
||||
int getHttpStatusCode(const QString &status);
|
||||
void slotItemFinished(const SyncFileItemPtr &item, QMap<QString, QMap<QString, QString> > &responseObjectsProperties);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -401,7 +401,7 @@ void PropagateDownloadFile::start()
|
||||
// Normal job, download from oC instance
|
||||
_job = new GETFileJob(_propagator->account(),
|
||||
_propagator->_remoteFolder + _item->_file,
|
||||
&_tmpFile, headers, expectedEtagForResume, _resumeStart);
|
||||
&_tmpFile, headers, expectedEtagForResume, _resumeStart, this);
|
||||
} else {
|
||||
// We were provided a direct URL, use that one
|
||||
qDebug() << Q_FUNC_INFO << "directDownloadUrl given for " << _item->_file << _item->_directDownloadUrl;
|
||||
@@ -413,7 +413,7 @@ void PropagateDownloadFile::start()
|
||||
QUrl url = QUrl::fromUserInput(_item->_directDownloadUrl);
|
||||
_job = new GETFileJob(_propagator->account(),
|
||||
url,
|
||||
&_tmpFile, headers, expectedEtagForResume, _resumeStart);
|
||||
&_tmpFile, headers, expectedEtagForResume, _resumeStart, this);
|
||||
}
|
||||
_job->setBandwidthManager(&_propagator->_bandwidthManager);
|
||||
connect(_job, SIGNAL(finishedSignal()), this, SLOT(slotGetFinished()));
|
||||
|
||||
@@ -177,7 +177,7 @@ void PropagateRemoteMove::finalize()
|
||||
record._contentChecksum = oldRecord._contentChecksum;
|
||||
record._contentChecksumType = oldRecord._contentChecksumType;
|
||||
if (record._fileSize != oldRecord._fileSize) {
|
||||
qDebug() << "Warning: file sizes differ on server vs csync_journal: " << record._fileSize << oldRecord._fileSize;
|
||||
qDebug() << "Warning: file sizes differ on server vs sync journal: " << record._fileSize << oldRecord._fileSize;
|
||||
record._fileSize = oldRecord._fileSize; // server might have claimed different size, we take the old one from the DB
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include <QDir>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 2)
|
||||
namespace {
|
||||
@@ -563,4 +562,5 @@ void PropagateUploadFileCommon::finalize()
|
||||
done(SyncFileItem::Success);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
#include "owncloudpropagator.h"
|
||||
#include "networkjobs.h"
|
||||
|
||||
#include <QHttpMultiPart>
|
||||
#include <QBuffer>
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
namespace OCC {
|
||||
class BandwidthManager;
|
||||
|
||||
@@ -321,5 +321,6 @@ private slots:
|
||||
void slotUploadProgress(qint64,qint64);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -268,10 +268,8 @@ void PropagateUploadFileNG::startNextChunk()
|
||||
Q_ASSERT(_jobs.isEmpty()); // There should be no running job anymore
|
||||
_finished = true;
|
||||
// Finish with a MOVE
|
||||
QString destination = _propagator->account()->url().path()
|
||||
+ QLatin1String("/remote.php/dav/files/") + _propagator->account()->davUser()
|
||||
+ _propagator->_remoteFolder + _item->_file;
|
||||
|
||||
QString destination = QDir::cleanPath(_propagator->account()->url().path() + QLatin1Char('/')
|
||||
+ _propagator->account()->davPath() + _propagator->_remoteFolder + _item->_file);
|
||||
auto headers = PropagateUploadFileCommon::headers();
|
||||
|
||||
// "If-Match applies to the source, but we are interested in comparing the etag of the destination
|
||||
@@ -317,7 +315,7 @@ void PropagateUploadFileNG::startNextChunk()
|
||||
QUrl url = chunkUrl(_currentChunk);
|
||||
|
||||
// job takes ownership of device via a QScopedPointer. Job deletes itself when finishing
|
||||
PUTFileJob* job = new PUTFileJob(_propagator->account(), url, device, headers, _currentChunk);
|
||||
PUTFileJob* job = new PUTFileJob(_propagator->account(), url, device, headers, _currentChunk, this);
|
||||
_jobs.append(job);
|
||||
connect(job, SIGNAL(finishedSignal()), this, SLOT(slotPutFinished()));
|
||||
connect(job, SIGNAL(uploadProgress(qint64,qint64)),
|
||||
|
||||
@@ -123,7 +123,7 @@ void PropagateUploadFileV1::startNextChunk()
|
||||
}
|
||||
|
||||
// job takes ownership of device via a QScopedPointer. Job deletes itself when finishing
|
||||
PUTFileJob* job = new PUTFileJob(_propagator->account(), _propagator->_remoteFolder + path, device, headers, _currentChunk);
|
||||
PUTFileJob* job = new PUTFileJob(_propagator->account(), _propagator->_remoteFolder + path, device, headers, _currentChunk, this);
|
||||
_jobs.append(job);
|
||||
connect(job, SIGNAL(finishedSignal()), this, SLOT(slotPutFinished()));
|
||||
connect(job, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(slotUploadProgress(qint64,qint64)));
|
||||
|
||||
@@ -78,12 +78,17 @@ SyncEngine::SyncEngine(AccountPtr account, const QString& localPath,
|
||||
qRegisterMetaType<SyncFileItem>("SyncFileItem");
|
||||
qRegisterMetaType<SyncFileItem::Status>("SyncFileItem::Status");
|
||||
qRegisterMetaType<SyncFileStatus>("SyncFileStatus");
|
||||
qRegisterMetaType<SyncFileItemVector>("SyncFileItemVector");
|
||||
qRegisterMetaType<SyncFileItem::Direction>("SyncFileItem::Direction");
|
||||
|
||||
// Everything in the SyncEngine expects a trailing slash for the localPath.
|
||||
Q_ASSERT(localPath.endsWith(QLatin1Char('/')));
|
||||
|
||||
csync_create(&_csync_ctx, localPath.toUtf8().data());
|
||||
csync_init(_csync_ctx);
|
||||
|
||||
const QString dbFile = _journal->databaseFilePath();
|
||||
csync_init(_csync_ctx, dbFile.toUtf8().data());
|
||||
|
||||
_excludedFiles.reset(new ExcludedFiles(&_csync_ctx->excludes));
|
||||
_syncFileStatusTracker.reset(new SyncFileStatusTracker(this));
|
||||
|
||||
|
||||
@@ -164,6 +164,8 @@ private slots:
|
||||
private:
|
||||
void handleSyncError(CSYNC *ctx, const char *state);
|
||||
|
||||
QString journalDbFilePath() const;
|
||||
|
||||
static int treewalkLocal( TREE_WALK_FILE*, void *);
|
||||
static int treewalkRemote( TREE_WALK_FILE*, void *);
|
||||
int treewalkFile( TREE_WALK_FILE*, bool );
|
||||
|
||||
@@ -46,7 +46,6 @@ public:
|
||||
|
||||
enum Type {
|
||||
UnknownType = 0,
|
||||
RequestsContainer = 7,
|
||||
File = CSYNC_FTW_TYPE_FILE,
|
||||
Directory = CSYNC_FTW_TYPE_DIR,
|
||||
SoftLink = CSYNC_FTW_TYPE_SLINK
|
||||
@@ -139,7 +138,7 @@ public:
|
||||
QString _file;
|
||||
QString _renameTarget;
|
||||
Type _type BITFIELD(3);
|
||||
Direction _direction BITFIELD(2);
|
||||
Direction _direction BITFIELD(3);
|
||||
bool _isDirectory BITFIELD(1);
|
||||
bool _serverHasIgnoredFiles BITFIELD(1);
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#include <QStringList>
|
||||
#include <QDebug>
|
||||
#include <QElapsedTimer>
|
||||
#include <QUrl>
|
||||
|
||||
#include "ownsql.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
@@ -30,17 +32,63 @@
|
||||
|
||||
namespace OCC {
|
||||
|
||||
SyncJournalDb::SyncJournalDb(const QString& path, QObject *parent) :
|
||||
QObject(parent), _transaction(0)
|
||||
SyncJournalDb::SyncJournalDb(const QString& dbFilePath, QObject *parent) :
|
||||
QObject(parent),
|
||||
_dbFile(dbFilePath),
|
||||
_transaction(0)
|
||||
{
|
||||
|
||||
_dbFile = path;
|
||||
if( !_dbFile.endsWith('/') ) {
|
||||
_dbFile.append('/');
|
||||
}
|
||||
|
||||
QString SyncJournalDb::makeDbName(const QUrl& remoteUrl,
|
||||
const QString& remotePath,
|
||||
const QString& user)
|
||||
{
|
||||
QString journalPath = QLatin1String("._sync_");
|
||||
|
||||
QString key = QString::fromUtf8("%1@%2:%3").arg(
|
||||
user,
|
||||
remoteUrl.toString(),
|
||||
remotePath);
|
||||
|
||||
QByteArray ba = QCryptographicHash::hash(key.toUtf8(), QCryptographicHash::Md5);
|
||||
journalPath.append( ba.left(6).toHex() );
|
||||
journalPath.append(".db");
|
||||
|
||||
return journalPath;
|
||||
}
|
||||
|
||||
bool SyncJournalDb::maybeMigrateDb(const QString& localPath, const QString& absoluteJournalPath)
|
||||
{
|
||||
const QString oldDbName = localPath + QLatin1String(".csync_journal.db");
|
||||
if( !FileSystem::fileExists(oldDbName) ) {
|
||||
return true;
|
||||
}
|
||||
_dbFile.append(".csync_journal.db");
|
||||
|
||||
const QString newDbName = absoluteJournalPath;
|
||||
|
||||
// Whenever there is an old db file, migrate it to the new db path.
|
||||
// This is done to make switching from older versions to newer versions
|
||||
// work correctly even if the user had previously used a new version
|
||||
// and therefore already has an (outdated) new-style db file.
|
||||
QString error;
|
||||
|
||||
if( FileSystem::fileExists( newDbName ) ) {
|
||||
if( !FileSystem::remove(newDbName, &error) ) {
|
||||
qDebug() << "Database migration: Could not remove db file" << newDbName
|
||||
<< "due to" << error;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if( !FileSystem::rename(oldDbName, newDbName, &error) ) {
|
||||
qDebug() << "Database migration: could not rename " << oldDbName
|
||||
<< "to" << newDbName << ":" << error;
|
||||
return false;
|
||||
}
|
||||
|
||||
qDebug() << "Journal successfully migrated from" << oldDbName << "to" << newDbName;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SyncJournalDb::exists()
|
||||
@@ -49,7 +97,7 @@ bool SyncJournalDb::exists()
|
||||
return (!_dbFile.isEmpty() && QFile::exists(_dbFile));
|
||||
}
|
||||
|
||||
QString SyncJournalDb::databaseFilePath()
|
||||
QString SyncJournalDb::databaseFilePath() const
|
||||
{
|
||||
return _dbFile;
|
||||
}
|
||||
@@ -135,8 +183,6 @@ bool SyncJournalDb::checkConnect()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isNewDb = !QFile::exists(_dbFile);
|
||||
|
||||
// The database file is created by this call (SQLITE_OPEN_CREATE)
|
||||
if( !_db.openOrCreateReadWrite(_dbFile) ) {
|
||||
QString error = _db.error();
|
||||
@@ -310,10 +356,9 @@ bool SyncJournalDb::checkConnect()
|
||||
SqlQuery versionQuery("SELECT major, minor, patch FROM version;", _db);
|
||||
if (!versionQuery.next()) {
|
||||
// If there was no entry in the table, it means we are likely upgrading from 1.5
|
||||
if (!isNewDb) {
|
||||
qDebug() << Q_FUNC_INFO << "possibleUpgradeFromMirall_1_5 detected!";
|
||||
forceRemoteDiscovery = true;
|
||||
}
|
||||
qDebug() << Q_FUNC_INFO << "possibleUpgradeFromMirall_1_5 detected!";
|
||||
forceRemoteDiscovery = true;
|
||||
|
||||
createQuery.prepare("INSERT INTO version VALUES (?1, ?2, ?3, ?4);");
|
||||
createQuery.bindValue(1, MIRALL_VERSION_MAJOR);
|
||||
createQuery.bindValue(2, MIRALL_VERSION_MINOR);
|
||||
|
||||
@@ -37,9 +37,17 @@ class OWNCLOUDSYNC_EXPORT SyncJournalDb : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SyncJournalDb(const QString& path, QObject *parent = 0);
|
||||
explicit SyncJournalDb(const QString& dbFilePath, QObject *parent = 0);
|
||||
virtual ~SyncJournalDb();
|
||||
|
||||
/// Create a journal path for a specific configuration
|
||||
static QString makeDbName(const QUrl& remoteUrl,
|
||||
const QString& remotePath,
|
||||
const QString& user);
|
||||
|
||||
/// Migrate a csync_journal to the new path, if necessary. Returns false on error
|
||||
static bool maybeMigrateDb(const QString& localPath, const QString& absoluteJournalPath);
|
||||
|
||||
// to verify that the record could be queried successfully check
|
||||
// with SyncJournalFileRecord::isValid()
|
||||
SyncJournalFileRecord getFileRecord(const QString& filename);
|
||||
@@ -58,7 +66,8 @@ public:
|
||||
bool exists();
|
||||
void walCheckpoint();
|
||||
|
||||
QString databaseFilePath();
|
||||
QString databaseFilePath() const;
|
||||
|
||||
static qint64 getPHash(const QString& );
|
||||
|
||||
void updateErrorBlacklistEntry( const SyncJournalErrorBlacklistRecord& item );
|
||||
|
||||
@@ -277,12 +277,26 @@ bool Utility::fsCasePreserving()
|
||||
if( isWindows() || isMac() ) {
|
||||
re = true;
|
||||
} else {
|
||||
static bool isTest = qgetenv("OWNCLOUD_TEST_CASE_PRESERVING").toInt();
|
||||
bool isTest = qgetenv("OWNCLOUD_TEST_CASE_PRESERVING").toInt();
|
||||
re = isTest;
|
||||
}
|
||||
return re;
|
||||
}
|
||||
|
||||
bool Utility::fileNamesEqual( const QString& fn1, const QString& fn2)
|
||||
{
|
||||
const QDir fd1(fn1);
|
||||
const QDir fd2(fn2);
|
||||
|
||||
// Attention: If the path does not exist, canonicalPath returns ""
|
||||
// ONLY use this function with existing pathes.
|
||||
const QString a = fd1.canonicalPath();
|
||||
const QString b = fd2.canonicalPath();
|
||||
bool re = !a.isEmpty() && QString::compare( a, b,
|
||||
fsCasePreserving() ? Qt::CaseInsensitive : Qt::CaseSensitive) == 0;
|
||||
return re;
|
||||
}
|
||||
|
||||
QDateTime Utility::qDateTimeFromTime_t(qint64 t)
|
||||
{
|
||||
return QDateTime::fromMSecsSinceEpoch(t * 1000);
|
||||
|
||||
@@ -105,6 +105,11 @@ namespace Utility
|
||||
// if false, the two cases are two different files.
|
||||
OWNCLOUDSYNC_EXPORT bool fsCasePreserving();
|
||||
|
||||
// Check if two pathes that MUST exist are equal. This function
|
||||
// uses QDir::canonicalPath() to judge and cares for the systems
|
||||
// case sensitivity.
|
||||
OWNCLOUDSYNC_EXPORT bool fileNamesEqual( const QString& fn1, const QString& fn2);
|
||||
|
||||
// Call the given command with the switch --version and rerun the first line
|
||||
// of the output.
|
||||
// If command is empty, the function calls the running application which, on
|
||||
|
||||
@@ -32,7 +32,6 @@ inline QString getFilePathFromUrl(const QUrl &url) {
|
||||
return {};
|
||||
}
|
||||
|
||||
static const QUrl sBundleRootUrl("owncloud://somehost/remote.php/dav/files/");
|
||||
|
||||
inline QString generateEtag() {
|
||||
return QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch(), 16);
|
||||
@@ -626,6 +625,7 @@ public:
|
||||
qint64 readData(char *, qint64) override { return 0; }
|
||||
};
|
||||
|
||||
|
||||
class FakeErrorReply : public QNetworkReply
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -649,223 +649,6 @@ public:
|
||||
qint64 readData(char *, qint64) override { return 0; }
|
||||
};
|
||||
|
||||
class FakeBundlePOSTReply : public QNetworkReply
|
||||
{
|
||||
Q_OBJECT
|
||||
FileInfo *fileInfo;
|
||||
QByteArray payload;
|
||||
public:
|
||||
FakeBundlePOSTReply(FileInfo &remoteRootFileInfo, QNetworkAccessManager::Operation op, const QNetworkRequest &request, const QByteArray &postPayload, QObject *parent)
|
||||
: QNetworkReply{parent} {
|
||||
setRequest(request);
|
||||
QUrl rawUrl = request.url();
|
||||
QString bundlePath(sBundleRootUrl.path()+rawUrl.userName());
|
||||
setUrl(rawUrl);
|
||||
setOperation(op);
|
||||
open(QIODevice::ReadOnly);
|
||||
const QString davUri{QStringLiteral("DAV:")};
|
||||
const QString ocUri{QStringLiteral("http://owncloud.org/ns")};
|
||||
const QString sabUri{QStringLiteral("http://sabredav.org/ns")};
|
||||
QBuffer buffer{&payload};
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
QXmlStreamWriter xml( &buffer );
|
||||
xml.writeNamespace(davUri, "d");
|
||||
xml.writeNamespace(ocUri, "o");
|
||||
xml.writeNamespace(sabUri, "s");
|
||||
|
||||
if ("erroruser" == rawUrl.userName()) {
|
||||
// ERROR CASE
|
||||
xml.writeStartDocument();
|
||||
xml.writeStartElement(davUri, QStringLiteral("error"));
|
||||
xml.writeTextElement(sabUri, QStringLiteral("exception"), QStringLiteral("OCA\\DAV\\Connector\\Sabre\\Exception\\Forbidden"));
|
||||
xml.writeTextElement(sabUri, QStringLiteral("message"), QStringLiteral("URL endpoint has to be instance of \\OCA\\DAV\\Files\\FilesHome"));
|
||||
xml.writeTextElement(ocUri, QStringLiteral("retry"), QStringLiteral("false"));
|
||||
xml.writeTextElement(ocUri, QStringLiteral("reason"), QStringLiteral("URL endpoint has to be instance of \\OCA\\DAV\\Files\\FilesHome"));
|
||||
xml.writeEndElement(); // error
|
||||
xml.writeEndDocument();
|
||||
setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 403);
|
||||
} else {
|
||||
//NORMAL CASE
|
||||
auto writeFileResponse = [&](const FileInfo &fileInfo) {
|
||||
xml.writeStartElement(davUri, QStringLiteral("response"));
|
||||
|
||||
//TODO: no need for X-OC-PATH, href could contain that, fix client/server
|
||||
xml.writeTextElement(davUri, QStringLiteral("href"), bundlePath);
|
||||
xml.writeStartElement(davUri, QStringLiteral("propstat"));
|
||||
xml.writeStartElement(davUri, QStringLiteral("prop"));
|
||||
|
||||
xml.writeTextElement(davUri, QStringLiteral("oc-etag"), fileInfo.etag);
|
||||
xml.writeTextElement(davUri, QStringLiteral("etag"), fileInfo.etag);
|
||||
xml.writeTextElement(davUri, QStringLiteral("oc-fileid"), fileInfo.fileId);
|
||||
xml.writeTextElement(davUri, QStringLiteral("oc-mtime"), QStringLiteral("accepted"));
|
||||
|
||||
//TODO: this slash to be fixed on client/server
|
||||
xml.writeTextElement(davUri, QStringLiteral("oc-path"), "/"+fileInfo.path());
|
||||
xml.writeEndElement(); // prop
|
||||
xml.writeTextElement(davUri, QStringLiteral("status"), "HTTP/1.1 200 OK");
|
||||
xml.writeEndElement(); // propstat
|
||||
xml.writeEndElement(); // response
|
||||
};
|
||||
auto writeFileErrorResponse = [&](const FileInfo &fileInfo, const QString &exception, const QString &message, const QString &status) {
|
||||
xml.writeStartElement(davUri, QStringLiteral("response"));
|
||||
|
||||
//TODO: no need for X-OC-PATH, href could contain that, fix client/server
|
||||
xml.writeTextElement(davUri, QStringLiteral("href"), bundlePath);
|
||||
xml.writeStartElement(davUri, QStringLiteral("propstat"));
|
||||
xml.writeStartElement(davUri, QStringLiteral("prop"));
|
||||
xml.writeStartElement(davUri, QStringLiteral("error"));
|
||||
xml.writeTextElement(sabUri, QStringLiteral("exception"), exception);
|
||||
xml.writeTextElement(sabUri, QStringLiteral("message"), message);
|
||||
xml.writeEndElement(); // error
|
||||
|
||||
//TODO: this slash to be fixed on client/server
|
||||
xml.writeTextElement(davUri, QStringLiteral("oc-path"), "/"+fileInfo.path());
|
||||
xml.writeEndElement(); // prop
|
||||
xml.writeTextElement(davUri, QStringLiteral("status"), status);
|
||||
xml.writeEndElement(); // propstat
|
||||
xml.writeEndElement(); // response
|
||||
};
|
||||
|
||||
Q_ASSERT(request.url().path().endsWith(bundlePath));
|
||||
xml.writeStartDocument();
|
||||
xml.writeStartElement(davUri, QStringLiteral("multistatus"));
|
||||
|
||||
QString headerSectEnd = "\r\n\r\n";
|
||||
QString headerEnd = "\r\n";
|
||||
QString headerConType= "Content-Type: ";
|
||||
QString headerConID= "Content-ID: ";
|
||||
QString multipartStart = "<d:multipart xmlns:d=\"DAV:\">";
|
||||
QString partStart = "<d:part>";
|
||||
QString pathStart = "<d:oc-path>";
|
||||
QString pathEnd = "</d:oc-path>";
|
||||
QString mtimeStart = "<d:oc-mtime>";
|
||||
QString mtimeEnd = "</d:oc-mtime>";
|
||||
QString cidStart = "<d:oc-id>";
|
||||
QString cidEnd = "</d:oc-id>";
|
||||
QString lengthStart = "<d:oc-total-length>";
|
||||
QString lenghtEnd = "</d:oc-total-length>";
|
||||
|
||||
//we will use it to navigate in the request body
|
||||
int indexPointer = 0;
|
||||
int indexPointerEnd = 0;
|
||||
QChar contentChar;
|
||||
|
||||
QMap<int, QMap<QString, QString>> pathMap;
|
||||
QMap<QString, QString> objectMap;
|
||||
/* Find Content-Type of bundle metadata.*/
|
||||
//find index of content type and move to its end
|
||||
indexPointer = postPayload.indexOf(headerConType,indexPointerEnd) + headerConType.length();
|
||||
//find index of \r\n, so end of HTTP header and move to its end
|
||||
indexPointerEnd = postPayload.indexOf(headerEnd,indexPointer);
|
||||
//assert if what is between these indexes is our desired content type
|
||||
Q_ASSERT(postPayload.mid(indexPointer,indexPointerEnd-indexPointer) == QString("text/xml; charset=utf-8"));
|
||||
|
||||
/* Verify if there is xml which contains multipartStart element*/
|
||||
//find index of nearest header end and move to its end
|
||||
indexPointer = postPayload.indexOf(headerSectEnd,indexPointerEnd) + headerSectEnd.length();
|
||||
//
|
||||
indexPointerEnd = postPayload.indexOf(multipartStart,indexPointer);
|
||||
//assert if what is between these indexes is our desired content type
|
||||
Q_ASSERT(postPayload.mid(indexPointer,indexPointerEnd-indexPointer) == QString("<?xml version='1.0' encoding='UTF-8'?>\n"));
|
||||
|
||||
|
||||
/*Check metadata contents*/
|
||||
while(postPayload.indexOf(partStart,indexPointerEnd) + partStart.length() >=indexPointerEnd) {
|
||||
//find oc-path
|
||||
indexPointer = postPayload.indexOf(pathStart,indexPointerEnd) + pathStart.length();
|
||||
indexPointerEnd = postPayload.indexOf(pathEnd,indexPointer);
|
||||
QString filePath(postPayload.mid(indexPointer,indexPointerEnd-indexPointer));
|
||||
Q_ASSERT(!filePath.isNull());
|
||||
|
||||
indexPointer = postPayload.indexOf(mtimeStart,indexPointerEnd) + mtimeStart.length();
|
||||
indexPointerEnd = postPayload.indexOf(mtimeEnd,indexPointer);
|
||||
QString fileMtime(postPayload.mid(indexPointer,indexPointerEnd-indexPointer));
|
||||
Q_ASSERT(!fileMtime.isNull());
|
||||
|
||||
indexPointer = postPayload.indexOf(cidStart,indexPointerEnd) + cidStart.length();
|
||||
indexPointerEnd = postPayload.indexOf(cidEnd,indexPointer);
|
||||
QString fileID(postPayload.mid(indexPointer,indexPointerEnd-indexPointer));
|
||||
Q_ASSERT(!fileID.isNull());
|
||||
|
||||
indexPointer = postPayload.indexOf(lengthStart,indexPointerEnd) + lengthStart.length();
|
||||
indexPointerEnd = postPayload.indexOf(lenghtEnd,indexPointer);
|
||||
QString fileLength(postPayload.mid(indexPointer,indexPointerEnd-indexPointer));
|
||||
Q_ASSERT(!fileLength.isNull());
|
||||
|
||||
objectMap["mtime"] = fileMtime;
|
||||
objectMap["path"] = filePath;
|
||||
objectMap["length"] = fileLength;
|
||||
pathMap[fileID.toInt()] = objectMap;
|
||||
|
||||
}
|
||||
|
||||
while(postPayload.indexOf(headerConID,indexPointerEnd) + headerConID.length() >=indexPointerEnd) {
|
||||
/* Find Content-ID of bundle binary.*/
|
||||
indexPointer = postPayload.indexOf(headerConID,indexPointerEnd) + headerConID.length();
|
||||
indexPointerEnd = postPayload.indexOf(headerEnd,indexPointer);
|
||||
//assert if what is between these indexes is our desired content type
|
||||
int id = QString(postPayload.mid(indexPointer,indexPointerEnd-indexPointer)).toInt();
|
||||
Q_ASSERT(pathMap.contains(id));
|
||||
|
||||
indexPointer = postPayload.indexOf(headerSectEnd,indexPointerEnd) + headerSectEnd.length();
|
||||
|
||||
Q_ASSERT(postPayload.mid(indexPointer,1).size()==1);
|
||||
QChar contentChar(postPayload.mid(indexPointer,1)[0]);
|
||||
QString filePath(pathMap[id]["path"]);
|
||||
QString fileSize(pathMap[id]["length"]);
|
||||
|
||||
if ((fileInfo = remoteRootFileInfo.find(filePath))) {
|
||||
fileInfo->size = fileSize.toInt();
|
||||
fileInfo->contentChar = contentChar.toAscii();
|
||||
} else {
|
||||
// Assume that the file is filled with the same character
|
||||
fileInfo = remoteRootFileInfo.create(filePath, fileSize.toInt(), contentChar.toAscii());
|
||||
}
|
||||
|
||||
if (!fileInfo) {
|
||||
abort();
|
||||
return;
|
||||
}
|
||||
|
||||
if (filePath.endsWith("normalerrorfile")){
|
||||
writeFileErrorResponse(*fileInfo, QStringLiteral("Sabre\\DAV\\Exception\\BadRequest"), QStringLiteral("Method not allowed - file exists - update of the file is not supported!"), QStringLiteral("HTTP/1.1 400 Bad Request"));
|
||||
} else if (filePath.endsWith("fatalerrorfile")){
|
||||
writeFileErrorResponse(*fileInfo, QStringLiteral("Sabre\\DAV\\Exception\\ServiceUnavailable"), QStringLiteral("Failed to check file size"), QStringLiteral("HTTP/1.1 503 Service Unavailable"));
|
||||
} else if (filePath.endsWith("softerrorfile")){
|
||||
writeFileErrorResponse(*fileInfo, QStringLiteral("OCA\\DAV\\Connector\\Sabre\\Exception\\FileLocked"), QStringLiteral("Target file is locked by another process."), QStringLiteral("HTTP/1.1 423 Locked (WebDAV; RFC 4918)"));
|
||||
} else {
|
||||
writeFileResponse(*fileInfo);
|
||||
}
|
||||
}
|
||||
xml.writeEndElement(); // multistatus
|
||||
xml.writeEndDocument();
|
||||
setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 207);
|
||||
setFinished(true);
|
||||
setHeader(QNetworkRequest::ContentTypeHeader, "application/xml; charset=utf-8");
|
||||
setHeader(QNetworkRequest::ContentLengthHeader, payload.size());
|
||||
}
|
||||
|
||||
QMetaObject::invokeMethod(this, "respond", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
Q_INVOKABLE void respond() {
|
||||
emit metaDataChanged();
|
||||
if (bytesAvailable())
|
||||
emit readyRead();
|
||||
emit finished();
|
||||
}
|
||||
|
||||
void abort() override { }
|
||||
|
||||
qint64 bytesAvailable() const override { return payload.size() + QIODevice::bytesAvailable(); }
|
||||
qint64 readData(char *data, qint64 maxlen) override {
|
||||
qint64 len = std::min(qint64{payload.size()}, maxlen);
|
||||
strncpy(data, payload.constData(), len);
|
||||
payload.remove(0, len);
|
||||
return len;
|
||||
}
|
||||
};
|
||||
|
||||
class FakeQNAM : public QNetworkAccessManager
|
||||
{
|
||||
FileInfo _remoteRootFileInfo;
|
||||
@@ -881,13 +664,7 @@ protected:
|
||||
QNetworkReply *createRequest(Operation op, const QNetworkRequest &request,
|
||||
QIODevice *outgoingData = 0) {
|
||||
const QString fileName = getFilePathFromUrl(request.url());
|
||||
|
||||
if (op != QNetworkAccessManager::PostOperation){
|
||||
Q_ASSERT(!fileName.isNull());
|
||||
} else {
|
||||
//For Bundle, fileName of bundle is "". Otherwise, assert
|
||||
Q_ASSERT(fileName.isNull());
|
||||
}
|
||||
Q_ASSERT(!fileName.isNull());
|
||||
if (_errorPaths.contains(fileName))
|
||||
return new FakeErrorReply{op, request, this};
|
||||
|
||||
@@ -910,9 +687,7 @@ protected:
|
||||
return new FakeMoveReply{info, op, request, this};
|
||||
else if (verb == QLatin1String("MOVE") && isUpload)
|
||||
return new FakeChunkMoveReply{info, _remoteRootFileInfo, op, request, this};
|
||||
else if (op == QNetworkAccessManager::PostOperation) {
|
||||
return new FakeBundlePOSTReply{_remoteRootFileInfo, op, request, outgoingData->readAll(), this};
|
||||
} else {
|
||||
else {
|
||||
qDebug() << verb << outgoingData;
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
@@ -962,7 +737,7 @@ public:
|
||||
_account->setUrl(QUrl(QStringLiteral("http://admin:admin@localhost/owncloud")));
|
||||
_account->setCredentials(new FakeCredentials{_fakeQnam});
|
||||
|
||||
_journalDb.reset(new OCC::SyncJournalDb(localPath()));
|
||||
_journalDb.reset(new OCC::SyncJournalDb(localPath() + "._sync_test.db"));
|
||||
_syncEngine.reset(new OCC::SyncEngine(_account, localPath(), "", _journalDb.get()));
|
||||
|
||||
// A new folder will update the local file state database on first sync.
|
||||
@@ -1032,10 +807,6 @@ public:
|
||||
return execUntilFinished();
|
||||
}
|
||||
|
||||
OCC::AccountPtr getAccount() {
|
||||
return _account;
|
||||
}
|
||||
|
||||
private:
|
||||
static void toDisk(QDir &dir, const FileInfo &templateFi) {
|
||||
foreach (const FileInfo &child, templateFi.children) {
|
||||
|
||||
@@ -16,9 +16,20 @@
|
||||
#include "account.h"
|
||||
#include "accountstate.h"
|
||||
#include "configfile.h"
|
||||
#include "creds/httpcredentials.h"
|
||||
|
||||
using namespace OCC;
|
||||
|
||||
class HttpCredentialsTest : public HttpCredentials {
|
||||
public:
|
||||
HttpCredentialsTest(const QString& user, const QString& password)
|
||||
: HttpCredentials(user, password, "", "")
|
||||
{}
|
||||
|
||||
void askFromUser() Q_DECL_OVERRIDE {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
static FolderDefinition folderDefinition(const QString &path) {
|
||||
FolderDefinition d;
|
||||
@@ -53,7 +64,13 @@ private slots:
|
||||
f.write("hello");
|
||||
}
|
||||
|
||||
AccountStatePtr newAccountState(new AccountState(Account::create()));
|
||||
AccountPtr account = Account::create();
|
||||
QUrl url("http://example.de");
|
||||
HttpCredentialsTest *cred = new HttpCredentialsTest("testuser", "secret");
|
||||
account->setCredentials(cred);
|
||||
account->setUrl( url );
|
||||
|
||||
AccountStatePtr newAccountState(new AccountState(account));
|
||||
FolderMan *folderman = FolderMan::instance();
|
||||
QCOMPARE(folderman, &_fm);
|
||||
QVERIFY(folderman->addFolder(newAccountState.data(), folderDefinition(dir.path() + "/sub/ownCloud1")));
|
||||
@@ -61,6 +78,8 @@ private slots:
|
||||
|
||||
|
||||
// those should be allowed
|
||||
// QString FolderMan::checkPathValidityForNewFolder(const QString& path, const QUrl &serverUrl, bool forNewDirectory)
|
||||
|
||||
QCOMPARE(folderman->checkPathValidityForNewFolder(dir.path() + "/sub/free"), QString());
|
||||
QCOMPARE(folderman->checkPathValidityForNewFolder(dir.path() + "/free2/"), QString());
|
||||
// Not an existing directory -> Ok
|
||||
@@ -71,11 +90,21 @@ private slots:
|
||||
// A file -> Error
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/file.txt").isNull());
|
||||
|
||||
// There are folders configured in those folders: -> ERROR
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/ownCloud1").isNull());
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/ownCloud2/").isNull());
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub").isNull());
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/").isNull());
|
||||
// There are folders configured in those folders, url needs to be taken into account: -> ERROR
|
||||
QUrl url2(url);
|
||||
const QString user = account->credentials()->user();
|
||||
url2.setUserName(user);
|
||||
|
||||
// The following both fail because they refer to the same account (user and url)
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/ownCloud1", url2).isNull());
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/ownCloud2/", url2).isNull());
|
||||
|
||||
// Now it will work because the account is different
|
||||
QUrl url3("http://anotherexample.org");
|
||||
url3.setUserName("dummy");
|
||||
QCOMPARE(folderman->checkPathValidityForNewFolder(dir.path() + "/sub/ownCloud1", url3), QString());
|
||||
QCOMPARE(folderman->checkPathValidityForNewFolder(dir.path() + "/ownCloud2/", url3), QString());
|
||||
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path()).isNull());
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/ownCloud1/folder").isNull());
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/ownCloud1/folder/f").isNull());
|
||||
@@ -93,7 +122,12 @@ private slots:
|
||||
|
||||
// Not Ok
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/link2").isNull());
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/link3").isNull());
|
||||
|
||||
// link 3 points to an existing sync folder. To make it fail, the account must be the same
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/link3", url2).isNull());
|
||||
// while with a different account, this is fine
|
||||
QCOMPARE(folderman->checkPathValidityForNewFolder(dir.path() + "/link3", url3), QString());
|
||||
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/link4").isNull());
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/link3/folder").isNull());
|
||||
|
||||
|
||||
@@ -31,16 +31,6 @@ bool itemDidCompleteSuccessfully(const QSignalSpy &spy, const QString &path)
|
||||
return false;
|
||||
}
|
||||
|
||||
SyncFileItem::Status itemDidCompleteWithStatus(const QSignalSpy &spy, const QString &path)
|
||||
{
|
||||
for(const QList<QVariant> &args : spy) {
|
||||
SyncFileItem item = args[0].value<SyncFileItem>();
|
||||
if (item.destination() == path)
|
||||
return item._status;
|
||||
}
|
||||
return SyncFileItem::NoStatus;
|
||||
}
|
||||
|
||||
class TestSyncEngine : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -64,71 +54,6 @@ private slots:
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
}
|
||||
|
||||
void testFileUploadBundled() {
|
||||
FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};
|
||||
|
||||
QVariantMap capBundle;
|
||||
capBundle["bundlerequest"] = "1.0";
|
||||
QVariantMap caps;
|
||||
caps["dav"] = capBundle;
|
||||
fakeFolder.getAccount()->setCapabilities(caps);
|
||||
|
||||
testFileUploadBundledAllFilesOK(fakeFolder);
|
||||
testFileUploadBundledErrorForFile(fakeFolder);
|
||||
|
||||
//TODO unfinished, cannot generate NetworkError
|
||||
//testFileUploadBundledNotHomeCollection(fakeFolder);
|
||||
}
|
||||
|
||||
void testFileUploadBundledAllFilesOK(FakeFolder &fakeFolder) {
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItem &, const PropagatorJob &)));
|
||||
fakeFolder.localModifier().insert("A/a3");
|
||||
fakeFolder.localModifier().insert("A/a4");
|
||||
fakeFolder.syncOnce();
|
||||
|
||||
//check separate files
|
||||
QVERIFY(itemDidCompleteSuccessfully(completeSpy, "A/a3"));
|
||||
QVERIFY(itemDidCompleteSuccessfully(completeSpy, "A/a4"));
|
||||
|
||||
//check whole bundle
|
||||
QVERIFY(itemDidCompleteSuccessfully(completeSpy, ""));
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
}
|
||||
|
||||
void testFileUploadBundledErrorForFile(FakeFolder &fakeFolder) {
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItem &, const PropagatorJob &)));
|
||||
fakeFolder.localModifier().insert("A/a5");
|
||||
fakeFolder.localModifier().insert("A/normalerrorfile");
|
||||
fakeFolder.localModifier().insert("A/fatalerrorfile");
|
||||
fakeFolder.localModifier().insert("A/softerrorfile");
|
||||
fakeFolder.syncOnce();
|
||||
|
||||
//check separate files
|
||||
QVERIFY(itemDidCompleteSuccessfully(completeSpy, "A/a5"));
|
||||
QVERIFY(SyncFileItem::NormalError == itemDidCompleteWithStatus(completeSpy, "A/normalerrorfile"));
|
||||
QVERIFY(SyncFileItem::FatalError == itemDidCompleteWithStatus(completeSpy, "A/fatalerrorfile"));
|
||||
QVERIFY(SyncFileItem::SoftError == itemDidCompleteWithStatus(completeSpy, "A/softerrorfile"));
|
||||
|
||||
//check whole bundle
|
||||
QVERIFY(itemDidCompleteSuccessfully(completeSpy, ""));
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
}
|
||||
|
||||
void testFileUploadBundledNotHomeCollection(FakeFolder &fakeFolder) {
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItem &, const PropagatorJob &)));
|
||||
fakeFolder.localModifier().insert("A/a7");
|
||||
fakeFolder.localModifier().insert("A/a8");
|
||||
fakeFolder.localModifier().insert("B/b4");
|
||||
|
||||
//add the user "erroruser" which is not a FilesHomeCollection
|
||||
fakeFolder.getAccount()->setUrl(QUrl(QStringLiteral("http://erroruser:admin@localhost/owncloud")));
|
||||
fakeFolder.syncOnce();
|
||||
|
||||
//check whole bundle
|
||||
QVERIFY(itemDidCompleteWithStatus(completeSpy, "") == SyncFileItem::SoftError);
|
||||
//QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
}
|
||||
|
||||
void testDirDownload() {
|
||||
FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItem &, const PropagatorJob &)));
|
||||
|
||||
@@ -13,18 +13,13 @@
|
||||
|
||||
using namespace OCC;
|
||||
|
||||
namespace {
|
||||
|
||||
const char testdbC[] = "/tmp";
|
||||
}
|
||||
|
||||
class TestSyncJournalDB : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TestSyncJournalDB()
|
||||
: _db(testdbC)
|
||||
: _db("/tmp/csync-test.db")
|
||||
{
|
||||
}
|
||||
|
||||
@@ -41,6 +36,8 @@ private slots:
|
||||
|
||||
void cleanupTestCase()
|
||||
{
|
||||
const QString file = _db.databaseFilePath();
|
||||
QFile::remove(file);
|
||||
}
|
||||
|
||||
void testFileRecord()
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
*/
|
||||
|
||||
#include <QtTest>
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
|
||||
#include <QTemporaryDir>
|
||||
#endif
|
||||
|
||||
#include "utility.h"
|
||||
|
||||
@@ -150,6 +153,52 @@ private slots:
|
||||
s = timeAgoInWords(earlyTS, laterTS );
|
||||
QCOMPARE(s, QLatin1String("Less than a minute ago"));
|
||||
}
|
||||
|
||||
void testFsCasePreserving()
|
||||
{
|
||||
qputenv("OWNCLOUD_TEST_CASE_PRESERVING", "1");
|
||||
QVERIFY(fsCasePreserving());
|
||||
qputenv("OWNCLOUD_TEST_CASE_PRESERVING", "0");
|
||||
QVERIFY(! fsCasePreserving());
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
|
||||
qunsetenv("OWNCLOUD_TEST_CASE_PRESERVING");
|
||||
QVERIFY(isMac() || isWindows() ? fsCasePreserving() : ! fsCasePreserving());
|
||||
#endif
|
||||
}
|
||||
|
||||
void testFileNamesEqual()
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
|
||||
qDebug() << "*** checking fileNamesEqual function";
|
||||
QTemporaryDir dir;
|
||||
QVERIFY(dir.isValid());
|
||||
QDir dir2(dir.path());
|
||||
QVERIFY(dir2.mkpath("test"));
|
||||
if( !fsCasePreserving() ) {
|
||||
QVERIFY(dir2.mkpath("TEST"));
|
||||
}
|
||||
QVERIFY(dir2.mkpath("test/TESTI"));
|
||||
QVERIFY(dir2.mkpath("TESTI"));
|
||||
|
||||
QString a = dir.path();
|
||||
QString b = dir.path();
|
||||
|
||||
QVERIFY(fileNamesEqual(a, b));
|
||||
|
||||
QVERIFY(fileNamesEqual(a+"/test", b+"/test")); // both exist
|
||||
QVERIFY(fileNamesEqual(a+"/test/TESTI", b+"/test/../test/TESTI")); // both exist
|
||||
|
||||
qputenv("OWNCLOUD_TEST_CASE_PRESERVING", "1");
|
||||
QVERIFY(fileNamesEqual(a+"/test", b+"/TEST")); // both exist
|
||||
|
||||
QVERIFY(!fileNamesEqual(a+"/test", b+"/test/TESTI")); // both are different
|
||||
|
||||
dir.remove();
|
||||
qunsetenv("OWNCLOUD_TEST_CASE_PRESERVING");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
QTEST_APPLESS_MAIN(TestUtility)
|
||||
|
||||
+240
-230
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
+241
-231
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
+242
-232
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
+241
-231
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
+240
-230
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
+243
-233
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
+240
-230
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
+240
-230
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Alguns arquivos não foram exibidos porque demasiados arquivos foram alterados neste diff Mostrar Mais
Referência em uma Nova Issue
Bloquear um usuário