]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/src/LDAPConnection.h
- some minor bugfixes
[openldap] / contrib / ldapc++ / src / LDAPConnection.h
1 /*
2  * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5
6 #ifndef LDAP_CONNECTION_H
7 #define LDAP_CONNECTION_H
8
9 #include "LDAPSearchResults.h"
10 #include "LDAPExtResult.h"
11 #include "LDAPAsynConnection.h" 
12
13 /** Main class for synchronous LDAP-Communication
14  *
15  * The class represent a LDAP-Connection to perform synchronous
16  * LDAP-Operations. This provides methodes for the different
17  * LDAP-Operations. All the methods for the LDAP-operations block until
18  * all results for the operation are received or until an error occurs
19  */
20 class LDAPConnection : private LDAPAsynConnection {
21
22     public :
23         /** 
24          * Constant for the Search-Operation to indicate a Base-Level
25          * Search
26          */
27         static const int SEARCH_BASE;
28
29         /** 
30          * Constant for the Search-Operation to indicate a One-Level
31          * Search
32          */
33         static const int SEARCH_ONE;
34         
35         /** 
36          * Constant for the Search-Operation to indicate a Subtree 
37          * Search
38          */
39         static const int SEARCH_SUB;
40         
41         /** This Constructor initializes synchronous LDAP-Connection 
42          * 
43          * During execution of this constructor no network communication
44          * is performed. Just some internal data structure are initialized
45          * @param hostname Name (or IP-Adress) of the destination host
46          * @param port Port the LDAP server is running on
47          * @param cons Default constraints to use with operations over 
48          *      this connection
49          */
50         LDAPConnection(const string& hostname="localhost", int port=389,
51                 LDAPConstraints* cons=0);
52         
53         /**
54          * Destructor
55          */
56         ~LDAPConnection();
57         
58         /** 
59          * Initzializes a synchronous connection to a server. 
60          * 
61          * There is actually no
62          * communication to the server. Just the object is initialized
63          * (e.g. this method is called within the 
64          * LDAPConnection(char*,int,LDAPConstraints) constructor.)
65          * @param hostname  The Name or IP-Address of the destination
66          *             LDAP-Server
67          * @param port      The Network Port the server is running on
68          */
69         void init(const string& hostname, int port);
70         
71         /** 
72          * Performs a simple authentication with the server
73          *
74          * @throws LDAPReferralException if a referral is received
75          * @throws LDAPException for any other error occuring during the
76          *              operation
77          * @param dn    The name of the entry to bind as
78          * @param passwd    The cleartext password for the entry
79          */
80         void bind(const string& dn="", const string& passwd="",
81                 LDAPConstraints* cons=0);
82         
83         /**
84          * Performs the UNBIND-operation on the destination server
85          * 
86          * @throws LDAPException in any case of an error
87          */
88         void unbind();
89         
90         /**
91          * Performs a COMPARE-operation on an entery of the destination 
92          * server.
93          *
94          * @throws LDAPReferralException if a referral is received
95          * @throws LDAPException for any other error occuring during the
96          *              operation
97          * @param dn    Distinguished name of the entry for which the compare
98          *              should be performed
99          * @param attr  An Attribute (one (!) value) to use for the
100          *      compare operation
101          * @param cons  A set of constraints that should be used with this
102          *              request
103          * @returns The result of the compare operation. true if the
104          *      attr-parameter matched an Attribute of the entry. false if it
105          *      did not match
106          */
107         bool compare(const string& dn, const LDAPAttribute& attr,
108                 LDAPConstraints* cons=0);
109        
110         /**
111          * Deletes an entry from the directory
112          *
113          * This method performs the DELETE operation on the server
114          * @throws LDAPReferralException if a referral is received
115          * @throws LDAPException for any other error occuring during the
116          *              operation
117          * @param dn    Distinguished name of the entry that should be deleted
118          * @param cons  A set of constraints that should be used with this
119          *              request
120          */
121         void del(const string& dn, const LDAPConstraints* cons=0);
122         
123         /**
124          * Use this method to perform the ADD-operation
125          *
126          * @throws LDAPReferralException if a referral is received
127          * @throws LDAPException for any other error occuring during the
128          *              operation
129          * @param le    the entry to add to the directory
130          * @param cons  A set of constraints that should be used with this
131          *              request
132          */
133         void add(const LDAPEntry* le, const LDAPConstraints* cons=0);
134         
135         /**
136          * To modify the attributes of an entry, this method can be used
137          *
138          * @throws LDAPReferralException if a referral is received
139          * @throws LDAPException for any other error occuring during the
140          *              operation
141          * @param dn    The DN of the entry which should be modified
142          * @param mods  A set of modifications for that entry.
143          * @param cons  A set of constraints that should be used with this
144          *              request
145          */
146         void modify(const string& dn, const LDAPModList* mods, 
147                 const LDAPConstraints* cons=0); 
148
149         /**
150          * This method performs the ModDN-operation.
151          *
152          * It can be used to rename or move an entry by modifing its DN.
153          *
154          * @throws LDAPReferralException if a referral is received
155          * @throws LDAPException for any other error occuring during the
156          *              operation
157          * @param dn    The DN that should be modified
158          * @param newRDN    If the RDN of the entry should be modified the
159          *                  new RDN can be put here.
160          * @param delOldRDN If the old RDN should be removed from the
161          *                  entry's attribute this parameter has to be
162          *                  "true"
163          * @param newParentDN   If the entry should be moved inside the
164          *                      DIT, the DN of the new parent of the entry
165          *                      can be given here.
166          * @param cons  A set of constraints that should be used with this
167          *              request
168          */
169         void rename(const string& dn, const string& newRDN, 
170                 bool delOldRDN=false, const string& newParentDN="",
171                 const LDAPConstraints* cons=0);
172         
173         /**
174          * This method can be used for the sync. SEARCH-operation.
175          *
176          * @throws LDAPReferralException if a referral is received
177          * @throws LDAPException for any other error occuring during the
178          *              operation
179          * @param base The distinguished name of the starting point for the
180          *      search
181          * @param scope The scope of the search. Possible values: <BR> 
182          *      LDAPAsynConnection::SEARCH_BASE, <BR> 
183          *      LDAPAsynConnection::SEARCH_ONE, <BR>
184          *      LDAPAsynConnection::SEARCH_SUB
185          * @param filter The string representation of a search filter to
186          *      use with this operation
187          * @param attrsOnly true if only the attributes names (no values) 
188          *      should be returned
189          * @param cons A set of constraints that should be used with this
190          *      request
191          * @returns A pointer to a LDAPSearchResults-object that can be
192          *      used to read the results of the search.
193          */
194         LDAPSearchResults* search(const string& base, int scope=0, 
195                 const string& filter="objectClass=*", 
196                 const StringList& attrs=StringList(), bool attrsOnly=false,
197                 const LDAPConstraints* cons=0);
198        
199         /**
200          * This method is for extended LDAP-Operations.
201          *
202          * @throws LDAPReferralException if a referral is received
203          * @throws LDAPException for any other error occuring during the
204          *              operation
205          * @param oid The Object Identifier of the Extended Operation that
206          *          should be performed.
207          * @param strint If the Extended Operation needs some additional
208          *          data it can be passed to the server by this parameter.
209          * @param cons A set of constraints that should be used with this
210          *      request
211          * @returns The result of the Extended Operation as an
212          *      pointer to a LDAPExtResult-object.
213          */
214         LDAPExtResult* extOperation(const string& oid, const string&
215                 value="", const LDAPConstraints *const = 0);
216         
217         const string& getHost() const;
218
219         int getPort() const;
220         
221         void setConstraints(LDAPConstraints *cons);
222         
223         const LDAPConstraints* getConstraints() const ;
224 };
225
226 #endif //LDAP_CONNECTION_H