2
This file is part of libkldap.
3
Copyright (c) 2004-2006 Szombathelyi György <gyurco@freemail.hu>
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.
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.
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.
21
#ifndef KLDAP_LDAPOPERATION_H
22
#define KLDAP_LDAPOPERATION_H
24
#include <QtCore/QString>
25
#include <QtCore/QList>
26
#include <QtCore/QByteArray>
28
#include <kldap/ldapurl.h>
29
#include <kldap/ldapobject.h>
30
#include <kldap/ldapcontrol.h>
31
#include <kldap/ldapserver.h>
32
#include <kldap/ldapconnection.h>
34
#include <kldap/kldap.h>
38
/** This class allows sending an ldap operation
39
* (search, rename, modify, delete, compare, exop) to an LDAP server.
41
class KLDAP_EXPORT LdapOperation
44
typedef enum ModType{ Mod_None, Mod_Add, Mod_Replace, Mod_Del };
45
typedef enum ResultType {
47
RES_SEARCH_ENTRY = 0x64,
48
RES_SEARCH_REFERENCE = 0x73,
49
RES_SEARCH_RESULT = 0x65,
56
RES_EXTENDED_PARTIAL = 0x79
59
typedef struct ModOp {
62
QList<QByteArray> values;
65
typedef QList<ModOp> ModOps;
68
LdapOperation( LdapConnection &conn );
69
virtual ~LdapOperation();
72
* Sets the connection object. Without living connection object,
73
* LDAP operations are not possible.
75
void setConnection( LdapConnection &conn );
77
* Returns the connection object.
79
LdapConnection &connection();
81
* Sets the client controls which will sent with each operation.
83
void setClientControls( const LdapControls &ctrls );
85
* Sets the server controls which will sent with each operation.
87
void setServerControls( const LdapControls &ctrls );
89
* Returns the client controls (which set by setClientControls()).
91
const LdapControls &clientControls() const;
93
* Returns the server controls (which set by setServerControls()).
95
const LdapControls &serverControls() const;
98
* Starts a search operation with the given base DN, scope, filter and
99
* result attributes. Returns a message id if successful, -1 if not.
101
int search( const QString &base, LdapUrl::Scope scope,
102
const QString &filter, const QStringList& attrs );
104
* Starts an addition operation.
105
* Returns a message id if successful, -1 if not.
107
int add( const LdapObject &object );
109
* Adds the specified object to the LDAP database.
110
* Returns KLDAP_SUCCESS id if successful, else an LDAP error code.
112
int add_s( const LdapObject &object );
114
* Starts a modrdn operation on given DN, changing its RDN to newRdn,
115
* changing its parent to newSuperior (if it's not empty), and deletes
116
* the old dn if deleteold is true.
117
* Returns a message id if successful, -1 if not.
119
int rename( const QString &dn, const QString &newRdn,
120
const QString &newSuperior, bool deleteold = true );
122
* Performs a modrdn operation on given DN, changing its RDN to newRdn,
123
* changing its parent to newSuperior (if it's not empty), and deletes
124
* the old dn if deleteold is true. This is the synchronous version.
125
* Returns KLDAP_SUCCESS id if successful, else an LDAP error code.
127
int rename_s( const QString &dn, const QString &newRdn,
128
const QString &newSuperior, bool deleteold = true );
130
* Starts a delete operation on the given DN.
131
* Returns a message id if successful, -1 if not.
133
int del( const QString &dn );
135
* Deletes the given DN. This is the synchronous version.
136
* Returns KLDAP_SUCCESS id if successful, else an LDAP error code.
138
int del_s( const QString &dn );
140
* Starts a modify operation on the given DN.
141
* Returns a message id if successful, -1 if not.
143
int modify( const QString &dn, const ModOps &ops );
145
* Performs a modify operation on the given DN. This is the synchronous version.
146
* Returns KLDAP_SUCCESS id if successful, else an LDAP error code.
148
int modify_s( const QString &dn, const ModOps &ops );
150
* Starts a compare operation on the given DN, compares the specified
151
* attribute with the given value.
152
* Returns a message id if successful, -1 if not.
154
int compare( const QString &dn, const QString &attr, const QByteArray &value );
156
* Performs a compare operation on the given DN, compares the specified
157
* attribute with the given value. This is the synchronous version.
158
* Returns KLDAP_COMPARE_TRUE if the entry contains the attribute value
159
* and KLDAP_COMPARE_FALSE if it does not. Otherwise, some error code is returned.
161
int compare_s( const QString &dn, const QString &attr, const QByteArray &value );
163
* Starts an extended operation specified with oid and data.
164
* Returns a message id if successful, -1 if not.
166
int exop( const QString &oid, const QByteArray &data );
168
* Performs an extended operation specified with oid and data.
169
* This is the synchronous version.
170
* Returns KLDAP_SUCCESS id if successful, else an LDAP error code.
172
int exop_s( const QString &oid, const QByteArray &data );
174
* Abandons a long-running operation. Requires the message id.
176
int abandon( int id );
179
* Returns the type of the result LDAP message (RES_XXX constants). -1 if error occurred.
180
* Note! Return code -1 means that fetching the message resulted in error, not the LDAP
181
* operation error. Call connection().ldapErrorCode() to determine if the operation
184
int result( int id );
186
* Returns the result object if result() returned RES_SEARCH_ENTRY.
188
const LdapObject &object() const;
190
* Returns the server controls from the returned ldap message (grabbed by result()).
192
const LdapControls &controls() const;
195
class LdapOperationPrivate;
196
LdapOperationPrivate* const d;
198
Q_DISABLE_COPY( LdapOperation )