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#ifndef KLDAP_LDAPOBJECT_H
22#define KLDAP_LDAPOBJECT_H
23
24#include <QtCore/QList>
25#include <QtCore/QMap>
26#include <QtCore/QSharedDataPointer>
27#include <QtCore/QString>
28
29#include "ldapdn.h"
30#include "kldap_export.h"
31
32namespace KLDAP {
33
34typedef QList<QByteArray> LdapAttrValue;
35typedef QMap<QString,LdapAttrValue > LdapAttrMap;
36
37/**
38 * @brief
39 * This class represents an LDAP Object
40*/
41class KLDAP_EXPORT LdapObject
42{
43 public:
44 LdapObject();
45 explicit LdapObject( const QString &dn );
46 virtual ~LdapObject();
47
48 LdapObject( const LdapObject &that );
49 LdapObject &operator=( const LdapObject &that );
50
51 /**
52 * Returns the text presentation (LDIF format) of the object.
53 */
54 QString toString() const;
55
56 /**
57 * Clears the name and attributes of the object.
58 */
59 void clear();
60 /**
61 * Sets the Distinguished Name of the object.
62 */
63 void setDn( const LdapDN &dn );
64 /**
65 * Sets the Distinguished Name of the object.
66 */
67 void setDn( const QString &dn );
68 /**
69 * Sets the attributes and attribute values of the object.
70 */
71 void setAttributes( const LdapAttrMap &attrs );
72 /**
73 * Sets the given attribute values. If the given attribute not exists,
74 * then it's created, if exists, it's overwritten.
75 * @param attributeName the attribute name for which to set values
76 * @param values the values of attribute to set
77 */
78 void setValues( const QString &attributeName, const LdapAttrValue &values );
79 /**
80 * Adds the given value to the specified attribute. If the given attribute
81 * not exists, then it's created.
82 * @param attributeName the attribute for which to add a value
83 * @param value the attribute value to add
84 */
85 void addValue( const QString &attributeName, const QByteArray &value );
86 /**
87 * Return the Distinguished Name of the object.
88 */
89 LdapDN dn() const;
90 /**
91 * Returns the attributes and their values.
92 */
93 const LdapAttrMap &attributes() const;
94 /**
95 * Returns all values of the attribute with the given name.
96 */
97 LdapAttrValue values( const QString &attributeName ) const;
98 /**
99 * Returns the first value of the attribute with the given name
100 * or an empty byte array if the attribute does not exists.
101 */
102 QByteArray value( const QString &attributeName ) const;
103 /**
104 * Returns true if the given attributethe exists, false otherwise.
105 */
106 bool hasAttribute( const QString &attributeName ) const;
107
108 private:
109 class Private;
110 QSharedDataPointer<Private> d;
111};
112
113typedef QList<LdapObject> LdapObjects;
114}
115
116#endif
117