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

KLDAP Library

  • sources
  • kde-4.14
  • kdepimlibs
  • 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 
26 using namespace KLDAP;
27 
28 class 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 
46 LdapObject::LdapObject()
47  : d( new Private )
48 {
49 }
50 
51 LdapObject::LdapObject( const QString &dn )
52  : d( new Private )
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 
85 void LdapObject::setAttributes( const LdapAttrMap &attrs )
86 {
87  d->mAttrs = attrs;
88 }
89 
90 LdapDN LdapObject::dn() const
91 {
92  return d->mDn;
93 }
94 
95 const LdapAttrMap &LdapObject::attributes() const
96 {
97  return d->mAttrs;
98 }
99 
100 QString 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 
114 void LdapObject::clear()
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 }
KLDAP::LdapObject::toString
QString toString() const
Returns the text presentation (LDIF format) of the object.
Definition: ldapobject.cpp:100
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
QByteArray
QMap< QString, LdapAttrValue >
KLDAP::LdapObject::setValues
void setValues(const QString &attributeName, const LdapAttrValue &values)
Sets the given attribute values.
Definition: ldapobject.cpp:120
KLDAP::LdapObject::dn
LdapDN dn() const
Return the Distinguished Name of the object.
Definition: ldapobject.cpp:90
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
QSharedData
KLDAP::LdapObject::setAttributes
void setAttributes(const LdapAttrMap &attrs)
Sets the attributes and attribute values of the object.
Definition: ldapobject.cpp:85
QString::fromUtf8
QString fromUtf8(const char *str, int size)
KLDAP::LdapObject::hasAttribute
bool hasAttribute(const QString &attributeName) const
Returns true if the given attributethe exists, false otherwise.
Definition: ldapobject.cpp:148
KLDAP::LdapObject::setDn
void setDn(const LdapDN &dn)
Sets the Distinguished Name of the object.
Definition: ldapobject.cpp:75
QString
QList
KLDAP::LdapObject
This class represents an LDAP Object.
Definition: ldapobject.h:41
KLDAP::LdapObject::attributes
const LdapAttrMap & attributes() const
Returns the attributes and their values.
Definition: ldapobject.cpp:95
KLDAP::LdapObject::addValue
void addValue(const QString &attributeName, const QByteArray &value)
Adds the given value to the specified attribute.
Definition: ldapobject.cpp:125
QLatin1Char
KLDAP::LdapObject::clear
void clear()
Clears the name and attributes of the object.
Definition: ldapobject.cpp:114
QList::ConstIterator
typedef ConstIterator
KLDAP::LdapObject::values
LdapAttrValue values(const QString &attributeName) const
Returns all values of the attribute with the given name.
Definition: ldapobject.cpp:130
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QMap< QString, LdapAttrValue >::ConstIterator
typedef ConstIterator
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:58 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs 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

Search



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