File indexing completed on 2024-12-22 04:57:00
0001 /* 0002 SPDX-FileCopyrightText: 2015-2017 Krzysztof Nowicki <krissn@op.pl> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "ewseffectiverights.h" 0008 0009 #include <QBitArray> 0010 #include <QSharedData> 0011 #include <QXmlStreamReader> 0012 0013 #include "ewsclient_debug.h" 0014 0015 class EwsEffectiveRightsPrivate : public QSharedData 0016 { 0017 public: 0018 enum Right { 0019 CreateAssociated = 0, 0020 CreateContents, 0021 CreateHierarchy, 0022 Delete, 0023 Modify, 0024 Read, 0025 ViewPrivateItems, 0026 }; 0027 0028 EwsEffectiveRightsPrivate(); 0029 virtual ~EwsEffectiveRightsPrivate(); 0030 0031 bool readRight(QXmlStreamReader &reader, Right right); 0032 0033 bool mValid; 0034 0035 QBitArray mRights; 0036 }; 0037 0038 EwsEffectiveRightsPrivate::EwsEffectiveRightsPrivate() 0039 : mValid(false) 0040 , mRights(7) 0041 { 0042 } 0043 0044 EwsEffectiveRightsPrivate::~EwsEffectiveRightsPrivate() 0045 { 0046 } 0047 0048 bool EwsEffectiveRightsPrivate::readRight(QXmlStreamReader &reader, Right right) 0049 { 0050 QString elm = reader.name().toString(); 0051 if (reader.error() != QXmlStreamReader::NoError) { 0052 qCWarning(EWSCLI_LOG) << QStringLiteral("Failed to read %1 element - invalid %2 element.").arg(QStringLiteral("EffectiveRights"), elm); 0053 return false; 0054 } 0055 0056 const QString text = reader.readElementText(); 0057 if (text == QLatin1StringView("true")) { 0058 mRights.setBit(right); 0059 } else if (text == QLatin1StringView("false")) { 0060 mRights.clearBit(right); 0061 } else { 0062 qCWarning(EWSCLI_LOG) << QStringLiteral("Failed to read %1 element - invalid %2 element value: %3.").arg(QStringLiteral("EffectiveRights"), elm, text); 0063 return false; 0064 } 0065 0066 return true; 0067 } 0068 0069 EwsEffectiveRights::EwsEffectiveRights() 0070 : d(new EwsEffectiveRightsPrivate()) 0071 { 0072 } 0073 0074 EwsEffectiveRights::EwsEffectiveRights(QXmlStreamReader &reader) 0075 : d(new EwsEffectiveRightsPrivate()) 0076 { 0077 while (reader.readNextStartElement()) { 0078 if (reader.namespaceUri() != ewsTypeNsUri) { 0079 qCWarningNC(EWSCLI_LOG) << QStringLiteral("Unexpected namespace in mailbox element:") << reader.namespaceUri(); 0080 return; 0081 } 0082 const QStringView readerName = reader.name(); 0083 if (readerName == QLatin1StringView("CreateAssociated")) { 0084 if (!d->readRight(reader, EwsEffectiveRightsPrivate::CreateAssociated)) { 0085 return; 0086 } 0087 } else if (readerName == QLatin1StringView("CreateContents")) { 0088 if (!d->readRight(reader, EwsEffectiveRightsPrivate::CreateContents)) { 0089 return; 0090 } 0091 } else if (readerName == QLatin1StringView("CreateHierarchy")) { 0092 if (!d->readRight(reader, EwsEffectiveRightsPrivate::CreateHierarchy)) { 0093 return; 0094 } 0095 } else if (readerName == QLatin1StringView("Delete")) { 0096 if (!d->readRight(reader, EwsEffectiveRightsPrivate::Delete)) { 0097 return; 0098 } 0099 } else if (readerName == QLatin1StringView("Modify")) { 0100 if (!d->readRight(reader, EwsEffectiveRightsPrivate::Modify)) { 0101 return; 0102 } 0103 } else if (readerName == QLatin1StringView("Read")) { 0104 if (!d->readRight(reader, EwsEffectiveRightsPrivate::Read)) { 0105 return; 0106 } 0107 } else if (readerName == QLatin1StringView("ViewPrivateItems")) { 0108 if (!d->readRight(reader, EwsEffectiveRightsPrivate::ViewPrivateItems)) { 0109 return; 0110 } 0111 } else { 0112 qCWarning(EWSCLI_LOG) 0113 << QStringLiteral("Failed to read %1 element - unknown element: %2.").arg(QStringLiteral("EffectiveRights"), readerName.toString()); 0114 return; 0115 } 0116 } 0117 0118 d->mValid = true; 0119 } 0120 0121 EwsEffectiveRights::EwsEffectiveRights(const EwsEffectiveRights &other) 0122 : d(other.d) 0123 { 0124 } 0125 0126 EwsEffectiveRights::EwsEffectiveRights(EwsEffectiveRights &&other) 0127 : d(std::move(other.d)) 0128 { 0129 } 0130 0131 EwsEffectiveRights::~EwsEffectiveRights() 0132 { 0133 } 0134 0135 EwsEffectiveRights &EwsEffectiveRights::operator=(const EwsEffectiveRights &other) 0136 { 0137 d = other.d; 0138 return *this; 0139 } 0140 0141 EwsEffectiveRights &EwsEffectiveRights::operator=(EwsEffectiveRights &&other) 0142 { 0143 d = std::move(other.d); 0144 return *this; 0145 } 0146 0147 bool EwsEffectiveRights::isValid() const 0148 { 0149 return d->mValid; 0150 } 0151 0152 bool EwsEffectiveRights::canCreateAssociated() const 0153 { 0154 return d->mRights.testBit(EwsEffectiveRightsPrivate::CreateAssociated); 0155 } 0156 0157 bool EwsEffectiveRights::canCreateContents() const 0158 { 0159 return d->mRights.testBit(EwsEffectiveRightsPrivate::CreateContents); 0160 } 0161 0162 bool EwsEffectiveRights::canCreateHierarchy() const 0163 { 0164 return d->mRights.testBit(EwsEffectiveRightsPrivate::CreateHierarchy); 0165 } 0166 0167 bool EwsEffectiveRights::canDelete() const 0168 { 0169 return d->mRights.testBit(EwsEffectiveRightsPrivate::Delete); 0170 } 0171 0172 bool EwsEffectiveRights::canModify() const 0173 { 0174 return d->mRights.testBit(EwsEffectiveRightsPrivate::Modify); 0175 } 0176 0177 bool EwsEffectiveRights::canRead() const 0178 { 0179 return d->mRights.testBit(EwsEffectiveRightsPrivate::Read); 0180 } 0181 0182 bool EwsEffectiveRights::canViewPrivateItems() const 0183 { 0184 return d->mRights.testBit(EwsEffectiveRightsPrivate::ViewPrivateItems); 0185 }