KDAV

utils.cpp
1/*
2 SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "utils_p.h"
8
9#include "enums.h"
10
11#include <QString>
12
13using namespace KDAV;
14
15QDomElement Utils::firstChildElementNS(const QDomElement &parent, const QString &namespaceUri, const QString &tagName)
16{
17 for (QDomNode child = parent.firstChild(); !child.isNull(); child = child.nextSibling()) {
18 if (child.isElement()) {
19 const QDomElement elt = child.toElement();
20 if (tagName.isEmpty() || (elt.tagName() == tagName && elt.namespaceURI() == namespaceUri)) {
21 return elt;
22 }
23 }
24 }
25
26 return QDomElement();
27}
28
29QDomElement Utils::nextSiblingElementNS(const QDomElement &element, const QString &namespaceUri, const QString &tagName)
30{
31 for (QDomNode sib = element.nextSibling(); !sib.isNull(); sib = sib.nextSibling()) {
32 if (sib.isElement()) {
33 const QDomElement elt = sib.toElement();
34 if (tagName.isEmpty() || (elt.tagName() == tagName && elt.namespaceURI() == namespaceUri)) {
35 return elt;
36 }
37 }
38 }
39
40 return QDomElement();
41}
42
43Privileges Utils::extractPrivileges(const QDomElement &element)
44{
45 Privileges final = None;
46 QDomElement privElement = firstChildElementNS(element, QStringLiteral("DAV:"), QStringLiteral("privilege"));
47
48 while (!privElement.isNull()) {
49 QDomElement child = privElement.firstChildElement();
50
51 while (!child.isNull()) {
52 final |= parsePrivilege(child);
53 child = child.nextSiblingElement();
54 }
55
56 privElement = Utils::nextSiblingElementNS(privElement, QStringLiteral("DAV:"), QStringLiteral("privilege"));
57 }
58
59 return final;
60}
61
62Privileges Utils::parsePrivilege(const QDomElement &element)
63{
64 Privileges final = None;
65
66 if (!element.childNodes().isEmpty()) {
67 // This is an aggregate privilege, parse each of its children
68 QDomElement child = element.firstChildElement();
69 while (!child.isNull()) {
70 final |= parsePrivilege(child);
71 child = child.nextSiblingElement();
72 }
73 } else {
74 // This is a normal privilege
75 const QString privname = element.localName();
76
77 if (privname == QLatin1String("read")) {
78 final |= KDAV::Read;
79 } else if (privname == QLatin1String("write")) {
80 final |= KDAV::Write;
81 } else if (privname == QLatin1String("write-properties")) {
82 final |= KDAV::WriteProperties;
83 } else if (privname == QLatin1String("write-content")) {
84 final |= KDAV::WriteContent;
85 } else if (privname == QLatin1String("unlock")) {
86 final |= KDAV::Unlock;
87 } else if (privname == QLatin1String("read-acl")) {
88 final |= KDAV::ReadAcl;
89 } else if (privname == QLatin1String("read-current-user-privilege-set")) {
90 final |= KDAV::ReadCurrentUserPrivilegeSet;
91 } else if (privname == QLatin1String("write-acl")) {
92 final |= KDAV::WriteAcl;
93 } else if (privname == QLatin1String("bind")) {
94 final |= KDAV::Bind;
95 } else if (privname == QLatin1String("unbind")) {
96 final |= KDAV::Unbind;
97 } else if (privname == QLatin1String("all")) {
98 final |= KDAV::All;
99 }
100 }
101
102 return final;
103}
Privileges KPIMKDAV2_EXPORT parsePrivilege(const QDomElement &element)
QDomElement KPIMKDAV2_EXPORT firstChildElementNS(const QDomElement &parent, const QString &namespaceUri, const QString &tagName)
The KDAV namespace.
QString tagName() const const
QDomNodeList childNodes() const const
QDomNode firstChild() const const
QDomElement firstChildElement(const QString &tagName, const QString &namespaceURI) const const
bool isNull() const const
QString localName() const const
QString namespaceURI() const const
QDomNode nextSibling() const const
QDomElement nextSiblingElement(const QString &tagName, const QString &namespaceURI) const const
QDomElement toElement() const const
bool isEmpty() const const
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:52:04 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.