• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

KLDAP Library

  • kldap
ldapobject.cpp
1/*
2 This file is part of libkldap.
3 Copyright (c) 2004-2006 Szombathelyi György <gyurco@freemail.hu>
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 <QtCore/QSharedData>
25
26using namespace KLDAP;
27
28class LdapObject::Private : public QSharedData
29{
30 public:
31 Private()
32 {
33 }
34
35 Private( const Private &other )
36 : QSharedData( other )
37 {
38 mDn = other.mDn;
39 mAttrs = other.mAttrs;
40 }
41
42 LdapDN mDn;
43 LdapAttrMap mAttrs;
44};
45
46LdapObject::LdapObject()
47 : d( new Private )
48{
49}
50
51LdapObject::LdapObject( const QString &dn )
52 : d( new Private )
53{
54 d->mDn = LdapDN( dn );
55}
56
57LdapObject::~LdapObject()
58{
59}
60
61LdapObject::LdapObject( const LdapObject &that )
62 : d( that.d )
63{
64}
65
66LdapObject &LdapObject::operator=( const LdapObject &that )
67{
68 if ( this != &that ) {
69 d = that.d;
70 }
71
72 return *this;
73}
74
75void LdapObject::setDn( const LdapDN &dn )
76{
77 d->mDn = dn;
78}
79
80void LdapObject::setDn( const QString &dn )
81{
82 d->mDn = LdapDN( dn );
83}
84
85void LdapObject::setAttributes( const LdapAttrMap &attrs )
86{
87 d->mAttrs = attrs;
88}
89
90LdapDN LdapObject::dn() const
91{
92 return d->mDn;
93}
94
95const LdapAttrMap &LdapObject::attributes() const
96{
97 return d->mAttrs;
98}
99
100QString LdapObject::toString() const
101{
102 QString result = QString::fromLatin1( "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
114void LdapObject::clear()
115{
116 d->mDn.clear();
117 d->mAttrs.clear();
118}
119
120void LdapObject::setValues( const QString &attributeName, const LdapAttrValue &values )
121{
122 d->mAttrs[ attributeName ] = values;
123}
124
125void LdapObject::addValue( const QString &attributeName, const QByteArray &value )
126{
127 d->mAttrs[ attributeName ].append( value );
128}
129
130LdapAttrValue 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
139QByteArray 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
148bool LdapObject::hasAttribute( const QString &attributeName ) const
149{
150 return d->mAttrs.contains( attributeName );
151}
KLDAP::LdapObject
This class represents an LDAP Object.
Definition: ldapobject.h:42
KLDAP::LdapObject::setDn
void setDn(const LdapDN &dn)
Sets the Distinguished Name of the object.
Definition: ldapobject.cpp:75
KLDAP::LdapObject::dn
LdapDN dn() const
Return the Distinguished Name of the object.
Definition: ldapobject.cpp:90
KLDAP::LdapObject::hasAttribute
bool hasAttribute(const QString &attributeName) const
Returns true if the given attributethe exists, false otherwise.
Definition: ldapobject.cpp:148
KLDAP::LdapObject::values
LdapAttrValue values(const QString &attributeName) const
Returns all values of the attribute with the given name.
Definition: ldapobject.cpp:130
KLDAP::LdapObject::value
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
KLDAP::LdapObject::addValue
void addValue(const QString &attributeName, const QByteArray &value)
Adds the given value to the specified attribute.
Definition: ldapobject.cpp:125
KLDAP::LdapObject::setValues
void setValues(const QString &attributeName, const LdapAttrValue &values)
Sets the given attribute values.
Definition: ldapobject.cpp:120
KLDAP::LdapObject::setAttributes
void setAttributes(const LdapAttrMap &attrs)
Sets the attributes and attribute values of the object.
Definition: ldapobject.cpp:85
KLDAP::LdapObject::attributes
const LdapAttrMap & attributes() const
Returns the attributes and their values.
Definition: ldapobject.cpp:95
KLDAP::LdapObject::clear
void clear()
Clears the name and attributes of the object.
Definition: ldapobject.cpp:114
KLDAP::LdapObject::toString
QString toString() const
Returns the text presentation (LDIF format) of the object.
Definition: ldapobject.cpp:100
KLDAP::Ldif::assembleLine
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
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KLDAP Library

Skip menu "KLDAP Library"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal