2 * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 #ifndef LDAP_CONNECTION_H
7 #define LDAP_CONNECTION_H
9 #include "LDAPSearchResults.h"
10 #include "LDAPExtResult.h"
11 #include "LDAPAsynConnection.h"
13 /** Main class for synchronous LDAP-Communication
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
20 class LDAPConnection : private LDAPAsynConnection {
24 * Constant for the Search-Operation to indicate a Base-Level
27 static const int SEARCH_BASE;
30 * Constant for the Search-Operation to indicate a One-Level
33 static const int SEARCH_ONE;
36 * Constant for the Search-Operation to indicate a Subtree
39 static const int SEARCH_SUB;
41 /** This Constructor initializes synchronous LDAP-Connection
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
50 LDAPConnection(const string& hostname="localhost", int port=389,
51 LDAPConstraints* cons=0);
59 * Initzializes a synchronous connection to a server.
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
67 * @param port The Network Port the server is running on
69 void init(const string& hostname, int port);
72 * Performs a simple authentication with the server
74 * @throws LDAPReferralException if a referral is received
75 * @throws LDAPException for any other error occuring during the
77 * @param dn The name of the entry to bind as
78 * @param passwd The cleartext password for the entry
80 void bind(const string& dn="", const string& passwd="",
81 LDAPConstraints* cons=0);
84 * Performs the UNBIND-operation on the destination server
86 * @throws LDAPException in any case of an error
91 * Performs a COMPARE-operation on an entery of the destination
94 * @throws LDAPReferralException if a referral is received
95 * @throws LDAPException for any other error occuring during the
97 * @param dn Distinguished name of the entry for which the compare
99 * @param attr An Attribute (one (!) value) to use for the
101 * @param cons A set of constraints that should be used with this
103 * @returns The result of the compare operation. true if the
104 * attr-parameter matched an Attribute of the entry. false if it
107 bool compare(const string& dn, const LDAPAttribute& attr,
108 LDAPConstraints* cons=0);
111 * Deletes an entry from the directory
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
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
121 void del(const string& dn, const LDAPConstraints* cons=0);
124 * Use this method to perform the ADD-operation
126 * @throws LDAPReferralException if a referral is received
127 * @throws LDAPException for any other error occuring during the
129 * @param le the entry to add to the directory
130 * @param cons A set of constraints that should be used with this
133 void add(const LDAPEntry* le, const LDAPConstraints* cons=0);
136 * To modify the attributes of an entry, this method can be used
138 * @throws LDAPReferralException if a referral is received
139 * @throws LDAPException for any other error occuring during the
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
146 void modify(const string& dn, const LDAPModList* mods,
147 const LDAPConstraints* cons=0);
150 * This method performs the ModDN-operation.
152 * It can be used to rename or move an entry by modifing its DN.
154 * @throws LDAPReferralException if a referral is received
155 * @throws LDAPException for any other error occuring during the
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
163 * @param newParentDN If the entry should be moved inside the
164 * DIT, the DN of the new parent of the entry
166 * @param cons A set of constraints that should be used with this
169 void rename(const string& dn, const string& newRDN,
170 bool delOldRDN=false, const string& newParentDN="",
171 const LDAPConstraints* cons=0);
174 * This method can be used for the sync. SEARCH-operation.
176 * @throws LDAPReferralException if a referral is received
177 * @throws LDAPException for any other error occuring during the
179 * @param base The distinguished name of the starting point for the
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)
189 * @param cons A set of constraints that should be used with this
191 * @returns A pointer to a LDAPSearchResults-object that can be
192 * used to read the results of the search.
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);
200 * This method is for extended LDAP-Operations.
202 * @throws LDAPReferralException if a referral is received
203 * @throws LDAPException for any other error occuring during the
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
211 * @returns The result of the Extended Operation as an
212 * pointer to a LDAPExtResult-object.
214 LDAPExtResult* extOperation(const string& oid, const string&
215 value="", const LDAPConstraints *const = 0);
217 const string& getHost() const;
221 void setConstraints(LDAPConstraints *cons);
223 const LDAPConstraints* getConstraints() const ;
226 #endif //LDAP_CONNECTION_H