KLdap

ldapobject.cpp
1 /*
2  This file is part of libkldap.
3  Copyright (c) 2004-2006 Szombathelyi Gy├Ârgy <[email protected]>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "ldapobject.h"
22 #include "ldif.h"
23 
24 #include <QSharedData>
25 
26 using namespace KLDAP;
27 
28 class LdapObjectPrivate : public QSharedData
29 {
30 public:
31  LdapObjectPrivate()
32  {
33  }
34 
35  LdapObjectPrivate(const LdapObjectPrivate &other)
36  : QSharedData(other)
37  {
38  mDn = other.mDn;
39  mAttrs = other.mAttrs;
40  }
41 
42  LdapDN mDn;
43  LdapAttrMap mAttrs;
44 };
45 
46 LdapObject::LdapObject()
47  : d(new LdapObjectPrivate)
48 {
49 }
50 
51 LdapObject::LdapObject(const QString &dn)
52  : d(new LdapObjectPrivate)
53 {
54  d->mDn = LdapDN(dn);
55 }
56 
57 LdapObject::~LdapObject()
58 {
59 }
60 
61 LdapObject::LdapObject(const LdapObject &that)
62  : d(that.d)
63 {
64 }
65 
66 LdapObject &LdapObject::operator=(const LdapObject &that)
67 {
68  if (this != &that) {
69  d = that.d;
70  }
71 
72  return *this;
73 }
74 
75 void LdapObject::setDn(const LdapDN &dn)
76 {
77  d->mDn = dn;
78 }
79 
80 void LdapObject::setDn(const QString &dn)
81 {
82  d->mDn = LdapDN(dn);
83 }
84 
86 {
87  d->mAttrs = attrs;
88 }
89 
90 LdapDN LdapObject::dn() const
91 {
92  return d->mDn;
93 }
94 
96 {
97  return d->mAttrs;
98 }
99 
101 {
102  QString result = QStringLiteral("dn: %1\n").arg(d->mDn.toString());
103  LdapAttrMap::ConstIterator end(d->mAttrs.constEnd());
104  for (LdapAttrMap::ConstIterator it = d->mAttrs.constBegin(); it != end; ++it) {
105  const QString attr = it.key();
106  LdapAttrValue::ConstIterator end2((*it).constEnd());
107  for (LdapAttrValue::ConstIterator it2 = (*it).constBegin(); it2 != end2; ++it2) {
108  result += QString::fromUtf8(Ldif::assembleLine(attr, *it2, 76)) + QLatin1Char('\n');
109  }
110  }
111  return result;
112 }
113 
115 {
116  d->mDn.clear();
117  d->mAttrs.clear();
118 }
119 
120 void LdapObject::setValues(const QString &attributeName, const LdapAttrValue &values)
121 {
122  d->mAttrs[ attributeName ] = values;
123 }
124 
125 void LdapObject::addValue(const QString &attributeName, const QByteArray &value)
126 {
127  d->mAttrs[ attributeName ].append(value);
128 }
129 
130 LdapAttrValue LdapObject::values(const QString &attributeName) const
131 {
132  if (hasAttribute(attributeName)) {
133  return d->mAttrs.value(attributeName);
134  } else {
135  return LdapAttrValue();
136  }
137 }
138 
139 QByteArray LdapObject::value(const QString &attributeName) const
140 {
141  if (hasAttribute(attributeName)) {
142  return d->mAttrs.value(attributeName).first();
143  } else {
144  return QByteArray();
145  }
146 }
147 
148 bool LdapObject::hasAttribute(const QString &attributeName) const
149 {
150  return d->mAttrs.contains(attributeName);
151 }
QString toString() const
Returns the text presentation (LDIF format) of the object.
Definition: ldapobject.cpp:100
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 ...
Definition: ldapobject.cpp:139
void setValues(const QString &attributeName, const LdapAttrValue &values)
Sets the given attribute values.
Definition: ldapobject.cpp:120
LdapDN dn() const
Return the Distinguished Name of the object.
Definition: ldapobject.cpp:90
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:71
void setAttributes(const LdapAttrMap &attrs)
Sets the attributes and attribute values of the object.
Definition: ldapobject.cpp:85
QString fromUtf8(const char *str, int size)
Definition: ber.h:30
bool hasAttribute(const QString &attributeName) const
Returns true if the given attributethe exists, false otherwise.
Definition: ldapobject.cpp:148
void setDn(const LdapDN &dn)
Sets the Distinguished Name of the object.
Definition: ldapobject.cpp:75
This class represents an LDAP Object.
Definition: ldapobject.h:43
const LdapAttrMap & attributes() const
Returns the attributes and their values.
Definition: ldapobject.cpp:95
void addValue(const QString &attributeName, const QByteArray &value)
Adds the given value to the specified attribute.
Definition: ldapobject.cpp:125
void clear()
Clears the name and attributes of the object.
Definition: ldapobject.cpp:114
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
typedef ConstIterator
LdapAttrValue values(const QString &attributeName) const
Returns all values of the attribute with the given name.
Definition: ldapobject.cpp:130
typedef ConstIterator
QByteArray value() const
Returns the control&#39;s value.
Definition: ldapcontrol.cpp:93
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue May 26 2020 22:39:42 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.