ldapobject.h 3.43 KB
Newer Older
1 2 3
/*
  This file is part of libkldap.
  Copyright (c) 2004-2006 Szombathelyi György <gyurco@freemail.hu>
Allen Winter's avatar
Allen Winter committed
4

5 6 7 8
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Library General  Public
  License as published by the Free Software Foundation; either
  version 2 of the License, or (at your option) any later version.
Allen Winter's avatar
Allen Winter committed
9

10 11 12 13
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Library General Public License for more details.
Allen Winter's avatar
Allen Winter committed
14

15 16 17 18 19 20 21 22 23
  You should have received a copy of the GNU Library General Public License
  along with this library; see the file COPYING.LIB.  If not, write to
  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  Boston, MA 02110-1301, USA.
*/

#ifndef KLDAP_LDAPOBJECT_H
#define KLDAP_LDAPOBJECT_H

Laurent Montel's avatar
Laurent Montel committed
24 25 26 27
#include <QList>
#include <QMap>
#include <QSharedDataPointer>
#include <QString>
28
class LdapObjectPrivate;
29

Allen Winter's avatar
Allen Winter committed
30
#include "ldapdn.h"
31
#include "kldap_export.h"
32

33 34
// clazy:excludeall=copyable-polymorphic

Laurent Montel's avatar
Laurent Montel committed
35 36
namespace KLDAP
{
37

Allen Winter's avatar
Allen Winter committed
38
typedef QList<QByteArray> LdapAttrValue;
Laurent Montel's avatar
Laurent Montel committed
39
typedef QMap<QString, LdapAttrValue > LdapAttrMap;
Allen Winter's avatar
Allen Winter committed
40 41 42 43 44 45 46

/**
 * @brief
 * This class represents an LDAP Object
*/
class KLDAP_EXPORT LdapObject
{
Laurent Montel's avatar
Laurent Montel committed
47
public:
Allen Winter's avatar
Allen Winter committed
48
    LdapObject();
Laurent Montel's avatar
Laurent Montel committed
49
    explicit LdapObject(const QString &dn);
Allen Winter's avatar
Allen Winter committed
50 51
    virtual ~LdapObject();

Laurent Montel's avatar
Laurent Montel committed
52 53
    LdapObject(const LdapObject &that);
    LdapObject &operator=(const LdapObject &that);
Allen Winter's avatar
Allen Winter committed
54 55 56 57 58 59 60 61 62 63 64 65 66

    /**
     * Returns the text presentation (LDIF format) of the object.
     */
    QString toString() const;

    /**
     * Clears the name and attributes of the object.
     */
    void clear();
    /**
     * Sets the Distinguished Name of the object.
     */
Laurent Montel's avatar
Laurent Montel committed
67
    void setDn(const LdapDN &dn);
Allen Winter's avatar
Allen Winter committed
68 69 70
    /**
     * Sets the Distinguished Name of the object.
     */
Laurent Montel's avatar
Laurent Montel committed
71
    void setDn(const QString &dn);
Allen Winter's avatar
Allen Winter committed
72 73 74
    /**
     * Sets the attributes and attribute values of the object.
     */
Laurent Montel's avatar
Laurent Montel committed
75
    void setAttributes(const LdapAttrMap &attrs);
Allen Winter's avatar
Allen Winter committed
76 77 78
    /**
     * Sets the given attribute values. If the given attribute not exists,
     * then it's created, if exists, it's overwritten.
Kevin Krammer's avatar
Kevin Krammer committed
79 80
     * @param attributeName the attribute name for which to set values
     * @param values the values of attribute to set
Allen Winter's avatar
Allen Winter committed
81
     */
Laurent Montel's avatar
Laurent Montel committed
82
    void setValues(const QString &attributeName, const LdapAttrValue &values);
Allen Winter's avatar
Allen Winter committed
83 84 85
    /**
     * Adds the given value to the specified attribute. If the given attribute
     * not exists, then it's created.
Kevin Krammer's avatar
Kevin Krammer committed
86 87
     * @param attributeName the attribute for which to add a value
     * @param value the attribute  value to add
Allen Winter's avatar
Allen Winter committed
88
     */
Laurent Montel's avatar
Laurent Montel committed
89
    void addValue(const QString &attributeName, const QByteArray &value);
Allen Winter's avatar
Allen Winter committed
90 91 92 93 94 95 96 97 98 99 100
    /**
     * Return the Distinguished Name of the object.
     */
    LdapDN dn() const;
    /**
     * Returns the attributes and their values.
     */
    const LdapAttrMap &attributes() const;
    /**
     * Returns all values of the attribute with the given name.
     */
Laurent Montel's avatar
Laurent Montel committed
101
    LdapAttrValue values(const QString &attributeName) const;
Allen Winter's avatar
Allen Winter committed
102 103 104 105
    /**
     * Returns the first value of the attribute with the given name
     * or an empty byte array if the attribute does not exists.
     */
Laurent Montel's avatar
Laurent Montel committed
106
    QByteArray value(const QString &attributeName) const;
Allen Winter's avatar
Allen Winter committed
107 108 109
    /**
     * Returns true if the given attributethe exists, false otherwise.
     */
Laurent Montel's avatar
Laurent Montel committed
110
    bool hasAttribute(const QString &attributeName) const;
Allen Winter's avatar
Allen Winter committed
111

Laurent Montel's avatar
Laurent Montel committed
112
private:
113
    QSharedDataPointer<LdapObjectPrivate> d;
Allen Winter's avatar
Allen Winter committed
114 115
};

Laurent Montel's avatar
Laurent Montel committed
116
typedef QVector<LdapObject> LdapObjects;
117
}
Allen Winter's avatar
Allen Winter committed
118

119
#endif