Changeset View
Changeset View
Standalone View
Standalone View
src/common/davcollectionsfetchjob.cpp
Show All 14 Lines | 1 | /* | |||
---|---|---|---|---|---|
15 | along with this program; if not, write to the Free Software | 15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | #include "davcollectionsfetchjob.h" | 19 | #include "davcollectionsfetchjob.h" | ||
20 | 20 | | |||
21 | #include "davmanager.h" | 21 | #include "davmanager.h" | ||
22 | #include "davprincipalhomesetsfetchjob.h" | 22 | #include "davprincipalhomesetsfetchjob.h" | ||
23 | #include "davcollectionfetchjob.h" | ||||
23 | #include "davprotocolbase.h" | 24 | #include "davprotocolbase.h" | ||
24 | #include "utils.h" | 25 | #include "utils.h" | ||
25 | #include "daverror.h" | 26 | #include "daverror.h" | ||
26 | #include "davjob.h" | 27 | #include "davjob.h" | ||
27 | 28 | | |||
28 | #include "libkdav2_debug.h" | 29 | #include "libkdav2_debug.h" | ||
29 | 30 | | |||
30 | #include <QtCore/QBuffer> | 31 | #include <QtCore/QBuffer> | ||
Show All 40 Lines | |||||
71 | void DavCollectionsFetchJob::principalFetchFinished(KJob *job) | 72 | void DavCollectionsFetchJob::principalFetchFinished(KJob *job) | ||
72 | { | 73 | { | ||
73 | const DavPrincipalHomeSetsFetchJob *davJob = qobject_cast<DavPrincipalHomeSetsFetchJob *>(job); | 74 | const DavPrincipalHomeSetsFetchJob *davJob = qobject_cast<DavPrincipalHomeSetsFetchJob *>(job); | ||
74 | 75 | | |||
75 | if (davJob->error()) { | 76 | if (davJob->error()) { | ||
76 | if (davJob->latestResponseCode()) { | 77 | if (davJob->latestResponseCode()) { | ||
77 | // If we have a HTTP response code then this may mean that | 78 | // If we have a HTTP response code then this may mean that | ||
78 | // the URL was not a principal URL. Retry as if it were a calendar URL. | 79 | // the URL was not a principal URL. Retry as if it were a calendar URL. | ||
79 | qCDebug(KDAV2_LOG) << "Principal fetch failed, retrying: " << job->errorText(); | 80 | qCDebug(KDAV2_LOG) << "Principal fetch failed, retrying: " << job->errorText(); | ||
cmollekopf: Please keep the qCDebug everywhere. | |||||
80 | doCollectionsFetch(mUrl.url()); | 81 | doCollectionsFetch(mUrl.url()); | ||
81 | } else { | 82 | } else { | ||
82 | // Just give up here. | 83 | // Just give up here. | ||
83 | setDavError(davJob->davError()); | 84 | setDavError(davJob->davError()); | ||
84 | setErrorTextFromDavError(); | 85 | setErrorTextFromDavError(); | ||
85 | emitResult(); | 86 | emitResult(); | ||
86 | } | 87 | } | ||
87 | 88 | | |||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 125 | if (davJob->error()) { | |||
137 | setJobError(davJob->error()); | 138 | setJobError(davJob->error()); | ||
138 | setErrorTextFromDavError(); | 139 | setErrorTextFromDavError(); | ||
139 | } else { | 140 | } else { | ||
140 | // For use in the collectionDiscovered() signal | 141 | // For use in the collectionDiscovered() signal | ||
141 | QUrl _jobUrl = mUrl.url(); | 142 | QUrl _jobUrl = mUrl.url(); | ||
142 | _jobUrl.setUserInfo(QString()); | 143 | _jobUrl.setUserInfo(QString()); | ||
143 | const QString jobUrl = _jobUrl.toDisplayString(); | 144 | const QString jobUrl = _jobUrl.toDisplayString(); | ||
144 | 145 | | |||
146 | qCDebug(KDAV2_LOG).noquote() << davJob->response().toString(); | ||||
147 | | ||||
145 | // Validate that we got a valid PROPFIND response | 148 | // Validate that we got a valid PROPFIND response | ||
146 | QDomElement rootElement = davJob->response().documentElement(); | 149 | QDomElement rootElement = davJob->response().documentElement(); | ||
147 | if (rootElement.localName().compare(QStringLiteral("multistatus"), Qt::CaseInsensitive) != 0) { | 150 | if (rootElement.localName().compare(QStringLiteral("multistatus"), Qt::CaseInsensitive) != 0) { | ||
148 | setError(ERR_COLLECTIONFETCH); | 151 | setError(ERR_COLLECTIONFETCH); | ||
149 | setErrorTextFromDavError(); | 152 | setErrorTextFromDavError(); | ||
150 | subjobFinished(); | 153 | subjobFinished(); | ||
151 | return; | 154 | return; | ||
152 | } | 155 | } | ||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Line(s) | 240 | foreach (const DavCollection &seen, mCollections) { | |||
240 | } | 243 | } | ||
241 | } | 244 | } | ||
242 | if (alreadySeen) { | 245 | if (alreadySeen) { | ||
243 | responseElement = Utils::nextSiblingElementNS( | 246 | responseElement = Utils::nextSiblingElementNS( | ||
244 | responseElement, QStringLiteral("DAV:"), QStringLiteral("response")); | 247 | responseElement, QStringLiteral("DAV:"), QStringLiteral("response")); | ||
245 | continue; | 248 | continue; | ||
246 | } | 249 | } | ||
247 | 250 | | |||
251 | bool protocolSupportsCTags = DavManager::self()->davProtocol(mUrl.protocol())->supportsCTags(); | ||||
252 | if (protocolSupportsCTags && collection.CTag() == "") { | ||||
253 | qCDebug(KDAV2_LOG) << "No CTag found for" | ||||
254 | << collection.url().url().toDisplayString() | ||||
255 | << "from the home set, trying from the direct URL"; | ||||
256 | refreshIndividualCollection(collection); | ||||
257 | | ||||
258 | responseElement = Utils::nextSiblingElementNS( | ||||
259 | responseElement, QStringLiteral("DAV:"), QStringLiteral("response")); | ||||
260 | continue; | ||||
261 | } | ||||
262 | | ||||
248 | mCollections << collection; | 263 | mCollections << collection; | ||
249 | Q_EMIT collectionDiscovered(mUrl.protocol(), url.toDisplayString(), jobUrl); | 264 | Q_EMIT collectionDiscovered(mUrl.protocol(), url.toDisplayString(), jobUrl); | ||
250 | 265 | | |||
251 | responseElement = Utils::nextSiblingElementNS( | 266 | responseElement = Utils::nextSiblingElementNS( | ||
252 | responseElement, QStringLiteral("DAV:"), QStringLiteral("response")); | 267 | responseElement, QStringLiteral("DAV:"), QStringLiteral("response")); | ||
253 | } | 268 | } | ||
254 | } | 269 | } | ||
255 | } | 270 | } | ||
256 | 271 | | |||
257 | subjobFinished(); | 272 | subjobFinished(); | ||
258 | } | 273 | } | ||
259 | 274 | | |||
275 | // This is a workaroud for Google who doesn't support providing the CTag | ||||
276 | // directly from the home set. We refresh the collections individually from | ||||
277 | // their own URLs, but only if we haven't found a CTag with the home set | ||||
278 | // request. | ||||
279 | void DavCollectionsFetchJob::refreshIndividualCollection(const DavCollection &collection) | ||||
280 | { | ||||
281 | ++mSubJobCount; | ||||
282 | auto individualFetchJob = new DavCollectionFetchJob(collection, this); | ||||
283 | connect(individualFetchJob, &DavCollectionFetchJob::result, this, &DavCollectionsFetchJob::individualCollectionRefreshed); | ||||
284 | individualFetchJob->start(); | ||||
285 | } | ||||
286 | | ||||
287 | void DavCollectionsFetchJob::individualCollectionRefreshed(KJob *job) | ||||
288 | { | ||||
289 | const auto *davJob = qobject_cast<DavCollectionFetchJob *>(job); | ||||
290 | | ||||
291 | if (davJob->error()) { | ||||
292 | if (davJob->latestResponseCode()) { | ||||
293 | // If we have a HTTP response code then this may mean that | ||||
294 | // the URL was not a principal URL. Retry as if it were a calendar URL. | ||||
295 | qCDebug(KDAV2_LOG) << "Individual fetch failed, retrying: " << job->errorText(); | ||||
296 | doCollectionsFetch(mUrl.url()); | ||||
297 | } else { | ||||
298 | setDavError(davJob->davError()); | ||||
299 | setErrorTextFromDavError(); | ||||
300 | emitResult(); | ||||
301 | } | ||||
302 | return; | ||||
303 | } | ||||
304 | | ||||
305 | qCDebug(KDAV2_LOG) << "Collection" | ||||
306 | << davJob->collection().url().url().toDisplayString() << "refreshed"; | ||||
307 | | ||||
308 | if (davJob->collection().CTag() == "") { | ||||
309 | qWarning() << "Collection with an empty CTag"; | ||||
310 | } | ||||
311 | | ||||
312 | mCollections << davJob->collection(); | ||||
313 | subjobFinished(); | ||||
314 | } | ||||
315 | | ||||
260 | void DavCollectionsFetchJob::subjobFinished() | 316 | void DavCollectionsFetchJob::subjobFinished() | ||
261 | { | 317 | { | ||
262 | if (--mSubJobCount == 0) { | 318 | if (--mSubJobCount == 0) { | ||
263 | emitResult(); | 319 | emitResult(); | ||
264 | } | 320 | } | ||
265 | } | 321 | } | ||
266 | 322 | |
Please keep the qCDebug everywhere.