File indexing completed on 2024-05-12 07:48:41
0001 /* 0002 SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "utils_p.h" 0008 0009 #include "enums.h" 0010 0011 #include <QString> 0012 0013 using namespace KDAV; 0014 0015 QDomElement Utils::firstChildElementNS(const QDomElement &parent, const QString &namespaceUri, const QString &tagName) 0016 { 0017 for (QDomNode child = parent.firstChild(); !child.isNull(); child = child.nextSibling()) { 0018 if (child.isElement()) { 0019 const QDomElement elt = child.toElement(); 0020 if (tagName.isEmpty() || (elt.tagName() == tagName && elt.namespaceURI() == namespaceUri)) { 0021 return elt; 0022 } 0023 } 0024 } 0025 0026 return QDomElement(); 0027 } 0028 0029 QDomElement Utils::nextSiblingElementNS(const QDomElement &element, const QString &namespaceUri, const QString &tagName) 0030 { 0031 for (QDomNode sib = element.nextSibling(); !sib.isNull(); sib = sib.nextSibling()) { 0032 if (sib.isElement()) { 0033 const QDomElement elt = sib.toElement(); 0034 if (tagName.isEmpty() || (elt.tagName() == tagName && elt.namespaceURI() == namespaceUri)) { 0035 return elt; 0036 } 0037 } 0038 } 0039 0040 return QDomElement(); 0041 } 0042 0043 Privileges Utils::extractPrivileges(const QDomElement &element) 0044 { 0045 Privileges final = None; 0046 QDomElement privElement = firstChildElementNS(element, QStringLiteral("DAV:"), QStringLiteral("privilege")); 0047 0048 while (!privElement.isNull()) { 0049 QDomElement child = privElement.firstChildElement(); 0050 0051 while (!child.isNull()) { 0052 final |= parsePrivilege(child); 0053 child = child.nextSiblingElement(); 0054 } 0055 0056 privElement = Utils::nextSiblingElementNS(privElement, QStringLiteral("DAV:"), QStringLiteral("privilege")); 0057 } 0058 0059 return final; 0060 } 0061 0062 Privileges Utils::parsePrivilege(const QDomElement &element) 0063 { 0064 Privileges final = None; 0065 0066 if (!element.childNodes().isEmpty()) { 0067 // This is an aggregate privilege, parse each of its children 0068 QDomElement child = element.firstChildElement(); 0069 while (!child.isNull()) { 0070 final |= parsePrivilege(child); 0071 child = child.nextSiblingElement(); 0072 } 0073 } else { 0074 // This is a normal privilege 0075 const QString privname = element.localName(); 0076 0077 if (privname == QLatin1String("read")) { 0078 final |= KDAV::Read; 0079 } else if (privname == QLatin1String("write")) { 0080 final |= KDAV::Write; 0081 } else if (privname == QLatin1String("write-properties")) { 0082 final |= KDAV::WriteProperties; 0083 } else if (privname == QLatin1String("write-content")) { 0084 final |= KDAV::WriteContent; 0085 } else if (privname == QLatin1String("unlock")) { 0086 final |= KDAV::Unlock; 0087 } else if (privname == QLatin1String("read-acl")) { 0088 final |= KDAV::ReadAcl; 0089 } else if (privname == QLatin1String("read-current-user-privilege-set")) { 0090 final |= KDAV::ReadCurrentUserPrivilegeSet; 0091 } else if (privname == QLatin1String("write-acl")) { 0092 final |= KDAV::WriteAcl; 0093 } else if (privname == QLatin1String("bind")) { 0094 final |= KDAV::Bind; 0095 } else if (privname == QLatin1String("unbind")) { 0096 final |= KDAV::Unbind; 0097 } else if (privname == QLatin1String("all")) { 0098 final |= KDAV::All; 0099 } 0100 } 0101 0102 return final; 0103 }