KLdap

ldapobject.cpp
1/*
2 This file is part of libkldap.
3 SPDX-FileCopyrightText: 2004-2006 Szombathelyi György <gyurco@freemail.hu>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "ldapobject.h"
9#include "ldif.h"
10
11#include <QSharedData>
12
13using namespace KLDAPCore;
14
15class LdapObjectPrivate : public QSharedData
16{
17public:
18 LdapObjectPrivate() = default;
19
20 LdapObjectPrivate(const LdapObjectPrivate &other)
21 : QSharedData(other)
22 , mDn(other.mDn)
23 , mAttrs(other.mAttrs)
24 {
25 }
26
27 LdapDN mDn;
28 LdapAttrMap mAttrs;
29};
30
31LdapObject::LdapObject()
32 : d(new LdapObjectPrivate)
33{
34}
35
36LdapObject::LdapObject(const QString &dn)
37 : d(new LdapObjectPrivate)
38{
39 d->mDn = LdapDN(dn);
40}
41
42LdapObject::~LdapObject() = default;
43
44LdapObject::LdapObject(const LdapObject &that)
45
46 = default;
47
48LdapObject &LdapObject::operator=(const LdapObject &that)
49{
50 if (this != &that) {
51 d = that.d;
52 }
53
54 return *this;
55}
56
57void LdapObject::setDn(const LdapDN &dn)
58{
59 d->mDn = dn;
60}
61
63{
64 d->mDn = LdapDN(dn);
65}
66
68{
69 d->mAttrs = attrs;
70}
71
72LdapDN LdapObject::dn() const
73{
74 return d->mDn;
75}
76
78{
79 return d->mAttrs;
80}
81
83{
84 QString result = QStringLiteral("dn: %1\n").arg(d->mDn.toString());
85 LdapAttrMap::ConstIterator end(d->mAttrs.constEnd());
86 for (LdapAttrMap::ConstIterator it = d->mAttrs.constBegin(); it != end; ++it) {
87 const QString attr = it.key();
88 LdapAttrValue::ConstIterator end2((*it).constEnd());
89 for (LdapAttrValue::ConstIterator it2 = (*it).constBegin(); it2 != end2; ++it2) {
90 result += QString::fromUtf8(Ldif::assembleLine(attr, *it2, 76)) + QLatin1Char('\n');
91 }
92 }
93 return result;
94}
95
97{
98 d->mDn.clear();
99 d->mAttrs.clear();
100}
101
102void LdapObject::setValues(const QString &attributeName, const LdapAttrValue &values)
103{
104 d->mAttrs[attributeName] = values;
105}
106
107void LdapObject::addValue(const QString &attributeName, const QByteArray &value)
108{
109 d->mAttrs[attributeName].append(value);
110}
111
112LdapAttrValue LdapObject::values(const QString &attributeName) const
113{
114 if (hasAttribute(attributeName)) {
115 return d->mAttrs.value(attributeName);
116 } else {
117 return {};
118 }
119}
120
121QByteArray LdapObject::value(const QString &attributeName) const
122{
123 if (hasAttribute(attributeName)) {
124 return d->mAttrs.value(attributeName).first();
125 } else {
126 return {};
127 }
128}
129
130bool LdapObject::hasAttribute(const QString &attributeName) const
131{
132 return d->mAttrs.contains(attributeName);
133}
This class represents an LDAP Object.
Definition ldapobject.h:31
void setDn(const LdapDN &dn)
Sets the Distinguished Name of the object.
LdapDN dn() const
Return the Distinguished Name of the object.
bool hasAttribute(const QString &attributeName) const
Returns true if the given attributethe exists, false otherwise.
LdapAttrValue values(const QString &attributeName) const
Returns all values of the attribute with the given name.
QByteArray value(const QString &attributeName) const
Returns the first value of the attribute with the given name or an empty byte array if the attribute ...
void addValue(const QString &attributeName, const QByteArray &value)
Adds the given value to the specified attribute.
void setValues(const QString &attributeName, const LdapAttrValue &values)
Sets the given attribute values.
void setAttributes(const LdapAttrMap &attrs)
Sets the attributes and attribute values of the object.
const LdapAttrMap & attributes() const
Returns the attributes and their values.
void clear()
Clears the name and attributes of the object.
QString toString() const
Returns the text presentation (LDIF format) of the object.
static QByteArray assembleLine(const QString &fieldname, const QByteArray &value, uint linelen=0, bool url=false)
Assembles fieldname and value into a valid Ldif line, BASE64 encodes the value if necessary and optio...
Definition ldif.cpp:57
ConstIterator
QString arg(Args &&... args) const const
QString fromUtf8(QByteArrayView str)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:34:09 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.