if (http_result_code == 207) {
// Parse DAV response
- auto items = QVariantMap();
auto domDocument = QDomDocument();
auto errorMsg = QString();
auto errorLine = -1;
if (!domDocument.setContent(reply(), true, &errorMsg, &errorLine, &errorColumn)) {
qCWarning(lcPropfindJob) << "XML parser error: " << errorMsg << errorLine << errorColumn;
emit finishedWithError(reply());
- return true;
+
+ } else {
+ const auto parsedItems = processPropfindDomDocument(domDocument);
+ emit result(parsedItems);
}
- const auto rootElement = domDocument.documentElement();
- const auto propNodes = rootElement.elementsByTagName(propfindPropElementTagName);
+ } else {
+ qCWarning(lcPropfindJob) << "*not* successful, http result code is" << http_result_code
+ << (http_result_code == 302 ? reply()->header(QNetworkRequest::LocationHeader).toString() : QLatin1String(""));
+ emit finishedWithError(reply());
+ }
- for (auto i = 0; i < propNodes.count(); ++i) {
- const auto propNode = propNodes.at(i);
- const auto propElement = propNode.toElement();
+ return true;
+}
- if (propElement.isNull() || propElement.tagName() != propfindPropElementTagName) {
- continue;
- }
+QVariantMap PropfindJob::processPropfindDomDocument(const QDomDocument &domDocument)
+{
+ if (!domDocument.hasChildNodes()) {
+ return {};
+ }
- auto propChildNode = propElement.firstChild();
+ auto items = QVariantMap();
- while (!propChildNode.isNull()) {
- const auto propChildElement = propChildNode.toElement();
+ const auto rootElement = domDocument.documentElement();
+ const auto propNodes = rootElement.elementsByTagName(propfindPropElementTagName);
- if (!propChildElement.isNull()) {
- items.insert(propChildElement.tagName(), propChildElement.text());
- }
+ for (auto i = 0; i < propNodes.count(); ++i) {
+ const auto propNode = propNodes.at(i);
+ const auto propElement = propNode.toElement();
+
+ if (propElement.isNull() || propElement.tagName() != propfindPropElementTagName) {
+ continue;
+ }
+
+ auto propChildNode = propElement.firstChild();
- propChildNode = propChildNode.nextSibling();
+ while (!propChildNode.isNull()) {
+ const auto propChildElement = propChildNode.toElement();
+
+ if (!propChildElement.isNull()) {
+ items.insert(propChildElement.tagName(), propChildElement.text());
}
- }
- emit result(items);
- } else {
- qCWarning(lcPropfindJob) << "*not* successful, http result code is" << http_result_code
- << (http_result_code == 302 ? reply()->header(QNetworkRequest::LocationHeader).toString() : QLatin1String(""));
- emit finishedWithError(reply());
+ propChildNode = propChildNode.nextSibling();
+ }
}
- return true;
+
+ return items;
}
/*********************************************************************************************/