File indexing completed on 2024-11-24 04:44:28

0001 /*
0002     This file is part of oxaccess.
0003 
0004     SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #include "davutils.h"
0010 
0011 using namespace OXA;
0012 
0013 QDomElement DAVUtils::addDavElement(QDomDocument &document, QDomNode &parentNode, const QString &tag)
0014 {
0015     const QDomElement element = document.createElementNS(QStringLiteral("DAV:"), QLatin1StringView("D:") + tag);
0016     parentNode.appendChild(element);
0017 
0018     return element;
0019 }
0020 
0021 QDomElement DAVUtils::addOxElement(QDomDocument &document, QDomNode &parentNode, const QString &tag, const QString &text)
0022 {
0023     QDomElement element = document.createElementNS(QStringLiteral("http://www.open-xchange.org"), QLatin1StringView("ox:") + tag);
0024 
0025     if (!text.isEmpty()) {
0026         const QDomText textNode = document.createTextNode(text);
0027         element.appendChild(textNode);
0028     }
0029 
0030     parentNode.appendChild(element);
0031 
0032     return element;
0033 }
0034 
0035 void DAVUtils::setOxAttribute(QDomElement &element, const QString &name, const QString &value)
0036 {
0037     element.setAttributeNS(QStringLiteral("http://www.open-xchange.org"), QStringLiteral("ox:") + name, value);
0038 }
0039 
0040 bool DAVUtils::davErrorOccurred(const QDomDocument &document, QString &errorText, QString &errorStatus)
0041 {
0042     const QDomElement documentElement = document.documentElement();
0043     const QDomNodeList propStats = documentElement.elementsByTagNameNS(QStringLiteral("DAV:"), QStringLiteral("propstat"));
0044 
0045     for (int i = 0; i < propStats.count(); ++i) {
0046         const QDomElement propStat = propStats.at(i).toElement();
0047         const QDomElement status = propStat.firstChildElement(QStringLiteral("status"));
0048         const QDomElement description = propStat.firstChildElement(QStringLiteral("responsedescription"));
0049 
0050         if (status.text() != QLatin1StringView("200")) {
0051             errorText = description.text();
0052             errorStatus = status.text();
0053             return true;
0054         }
0055     }
0056 
0057     return false;
0058 }