~ubuntu-branches/ubuntu/quantal/kdepimlibs/quantal-proposed

« back to all changes in this revision

Viewing changes to kldap/ldapoperation.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-09-06 22:45:39 UTC
  • Revision ID: james.westby@ubuntu.com-20060906224539-fiq8t03qdbqu7z3i
Tags: upstream-3.80.1
Import upstream version 3.80.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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_LDAPOPERATION_H
 
22
#define KLDAP_LDAPOPERATION_H
 
23
 
 
24
#include <QtCore/QString>
 
25
#include <QtCore/QList>
 
26
#include <QtCore/QByteArray>
 
27
 
 
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>
 
33
 
 
34
#include <kldap/kldap.h>
 
35
 
 
36
namespace KLDAP {
 
37
 
 
38
  /** This class allows sending an ldap operation 
 
39
   * (search, rename, modify, delete, compare, exop) to an LDAP server.
 
40
   */
 
41
  class KLDAP_EXPORT LdapOperation
 
42
  {
 
43
    public:
 
44
      typedef enum ModType{ Mod_None, Mod_Add, Mod_Replace, Mod_Del };
 
45
      typedef enum ResultType {
 
46
        RES_BIND = 0x61,
 
47
        RES_SEARCH_ENTRY = 0x64,
 
48
        RES_SEARCH_REFERENCE = 0x73,
 
49
        RES_SEARCH_RESULT = 0x65,
 
50
        RES_MODIFY = 0x67,
 
51
        RES_ADD = 0x69,
 
52
        RES_DELETE = 0x69,
 
53
        RES_MODDN = 0x6d,
 
54
        RES_COMPARE = 0x6f,
 
55
        RES_EXTENDED = 0x78,
 
56
        RES_EXTENDED_PARTIAL = 0x79
 
57
      };
 
58
 
 
59
      typedef struct ModOp {
 
60
        ModType type;
 
61
        QString attr;
 
62
        QList<QByteArray> values;
 
63
      };
 
64
 
 
65
      typedef QList<ModOp> ModOps;
 
66
 
 
67
      LdapOperation();
 
68
      LdapOperation( LdapConnection &conn );
 
69
      virtual ~LdapOperation();
 
70
 
 
71
      /**
 
72
       * Sets the connection object. Without living connection object, 
 
73
       * LDAP operations are not possible.
 
74
       */
 
75
      void setConnection( LdapConnection &conn );
 
76
      /**
 
77
       * Returns the connection object.
 
78
       */
 
79
      LdapConnection &connection();
 
80
      /**
 
81
       * Sets the client controls which will sent with each operation.
 
82
       */
 
83
      void setClientControls( const LdapControls &ctrls );
 
84
      /**
 
85
       * Sets the server controls which will sent with each operation.
 
86
       */
 
87
      void setServerControls( const LdapControls &ctrls );
 
88
      /**
 
89
       * Returns the client controls (which set by setClientControls()).
 
90
       */
 
91
      const LdapControls &clientControls() const;
 
92
      /**
 
93
       * Returns the server controls (which set by setServerControls()).
 
94
       */
 
95
      const LdapControls &serverControls() const;
 
96
 
 
97
      /**
 
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.
 
100
       */
 
101
      int search( const QString &base, LdapUrl::Scope scope, 
 
102
        const QString &filter, const QStringList& attrs );
 
103
      /**
 
104
       * Starts an addition operation.
 
105
       * Returns a message id if successful, -1 if not.
 
106
       */
 
107
      int add( const LdapObject &object );
 
108
      /**
 
109
       * Adds the specified object to the LDAP database.
 
110
       * Returns KLDAP_SUCCESS id if successful, else an LDAP error code.
 
111
       */
 
112
      int add_s( const LdapObject &object );
 
113
      /**
 
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.
 
118
       */
 
119
      int rename( const QString &dn, const QString &newRdn, 
 
120
        const QString &newSuperior, bool deleteold = true );
 
121
      /**
 
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.
 
126
       */
 
127
      int rename_s( const QString &dn, const QString &newRdn, 
 
128
        const QString &newSuperior, bool deleteold = true );
 
129
      /**
 
130
       * Starts a delete operation on the given DN.
 
131
       * Returns a message id if successful, -1 if not.
 
132
       */
 
133
      int del( const QString &dn );
 
134
      /**
 
135
       * Deletes the given DN. This is the synchronous version.
 
136
       * Returns KLDAP_SUCCESS id if successful, else an LDAP error code.
 
137
       */
 
138
      int del_s( const QString &dn );
 
139
      /**
 
140
       * Starts a modify operation on the given DN.
 
141
       * Returns a message id if successful, -1 if not.
 
142
       */
 
143
      int modify( const QString &dn, const ModOps &ops );
 
144
      /**
 
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.
 
147
       */
 
148
      int modify_s( const QString &dn, const ModOps &ops );
 
149
      /**
 
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.
 
153
       */
 
154
      int compare( const QString &dn, const QString &attr, const QByteArray &value );
 
155
      /**
 
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.
 
160
       */
 
161
      int compare_s( const QString &dn, const QString &attr, const QByteArray &value );
 
162
      /**
 
163
       * Starts an extended operation specified with oid and data.
 
164
       * Returns a message id if successful, -1 if not.
 
165
       */
 
166
      int exop( const QString &oid, const QByteArray &data );
 
167
      /**
 
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.
 
171
       */
 
172
      int exop_s( const QString &oid, const QByteArray &data );
 
173
      /**
 
174
       * Abandons a long-running operation. Requires the message id.
 
175
       */
 
176
      int abandon( int id );
 
177
      
 
178
      /**
 
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 
 
182
       * succeeded or not.
 
183
       */
 
184
      int result( int id );
 
185
      /**
 
186
       * Returns the result object if result() returned RES_SEARCH_ENTRY.
 
187
       */
 
188
      const LdapObject &object() const;
 
189
      /** 
 
190
       * Returns the server controls from the returned ldap message (grabbed by result()).
 
191
       */
 
192
      const LdapControls &controls() const;
 
193
 
 
194
    private:
 
195
      class LdapOperationPrivate;
 
196
      LdapOperationPrivate* const d;
 
197
 
 
198
      Q_DISABLE_COPY( LdapOperation )
 
199
  };
 
200
 
 
201
}
 
202
#endif