2 * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 #ifndef LDAP_ASYN_CONNECTION_H
8 #define LDAP_ASYN_CONNECTION_H
16 #include <LDAPMessageQueue.h>
17 #include <LDAPConstraints.h>
18 #include <LDAPModification.h>
19 #include <LDAPModList.h>
21 #include <LDAPUrlList.h>
26 //* Main class for an asynchronous LDAP connection
28 * This class represents an asynchronous connection to an LDAP-Server. It
29 * provides the methods for authentication, and all other LDAP-Operations
30 * (e.g. search, add, delete, etc.)
31 * All of the LDAP-Operations return a pointer to a LDAPMessageQueue-Object,
32 * which can be used to obtain the results of that operation.
33 * A basic example of this class could be like this: <BR>
34 * 1. Create a new LDAPAsynConnection Object: <BR>
35 * 2. Use the init-method to initialize the connection <BR>
36 * 3. Call the bind-method to authenticate to the directory <BR>
37 * 4. Obtain the bind results from the return LDAPMessageQueue-Object <BR>
38 * 5. Perform on of the operations on the directory (add, delete, search, ..)
40 * 6. Use the return LDAPMessageQueue to obtain the results of the operation
42 * 7. Close the connection (feature not implemented yet :) ) <BR>
44 class LDAPAsynConnection{
47 * Constant for the Search-Operation to indicate a Base-Level
50 static const int SEARCH_BASE=0;
53 * Constant for the Search-Operation to indicate a One-Level
56 static const int SEARCH_ONE=1;
59 * Constant for the Search-Operation to indicate a subtree
62 static const int SEARCH_SUB=2;
63 // static const int SEARCH_SUB=LDAP_SCOPE_SUBTREE;
64 // static const int SEARCH_ONE=LDAP_SCOPE_ONELEVEL;
65 // static const int SEARCH_SUB=LDAP_SCOPE_SUBTREE;
67 /** Construtor that initializes a connection to a server
68 * @param hostname Name (or IP-Adress) of the destination host
69 * @param port Port the LDAP server is running on
70 * @param cons Default constraints to use with operations over
73 LDAPAsynConnection(const std::string& hostname=std::string("localhost"),
74 int port=389, LDAPConstraints *cons=new LDAPConstraints() );
77 virtual ~LDAPAsynConnection();
80 * Initializes a connection to a server.
83 * communication to the server. Just the object is initialized
84 * (e.g. this method is called within the
85 * LDAPAsynConnection(char*,int,LDAPConstraints) constructor.)
86 * @param hostname The Name or IP-Address of the destination
88 * @param port The Network Port the server is running on
90 void init(const std::string& hostname, int port);
93 * Start TLS on this connection. This isn't in the constructor,
94 * because it could fail (i.e. server doesn't have SSL cert, client
95 * api wasn't compiled against OpenSSL, etc.).
96 * @throws LDAPException if the TLS Layer could not be setup
101 /** Simple authentication to a LDAP-Server
103 * @throws LDAPException If the Request could not be sent to the
104 * destination server, a LDAPException-object contains the
105 * error that occured.
106 * This method does a simple (username, password) bind to the server.
107 * Other, saver, authentcation methods are provided later
108 * @param dn the distiguished name to bind as
109 * @param passwd cleartext password to use
111 LDAPMessageQueue* bind(const std::string& dn="", const std::string& passwd="",
112 const LDAPConstraints *cons=0);
114 /** Performing a search on a directory tree.
116 * Use the search method to perform a search on the LDAP-Directory
117 * @throws LDAPException If the Request could not be sent to the
118 * destination server, a LDAPException-object contains the
119 * error that occured.
120 * @param base The distinguished name of the starting point for the
122 * @param scope The scope of the search. Possible values: <BR>
123 * LDAPAsynConnection::SEARCH_BASE, <BR>
124 * LDAPAsynConnection::SEARCH_ONE, <BR>
125 * LDAPAsynConnection::SEARCH_SUB
126 * @param filter The std::string representation of a search filter to
127 * use with this operation
128 * @param attrsOnly true if only the attributes names (no values)
130 * @param cons A set of constraints that should be used with this
133 LDAPMessageQueue* search(const std::string& base="", int scope=0,
134 const std::string& filter="objectClass=*",
135 const StringList& attrs=StringList(),
136 bool attrsOnly=false,
137 const LDAPConstraints *cons=0);
139 /** Delete an entry from the directory
141 * This method sends a delete request to the server
142 * @throws LDAPException If the Request could not be sent to the
143 * destination server, a LDAPException-object contains the
144 * error that occured.
145 * @param dn Distinguished name of the entry that should be deleted
146 * @param cons A set of constraints that should be used with this
149 LDAPMessageQueue* del(const std::string& dn, const LDAPConstraints *cons=0);
152 * Perform the COMPARE-operation on an attribute
154 * @throws LDAPException If the Request could not be sent to the
155 * destination server, a LDAPException-object contains the
156 * error that occured.
157 * @param dn Distinguished name of the entry for which the compare
158 * should be performed
159 * @param attr An Attribute (one (!) value) to use for the
161 * @param cons A set of constraints that should be used with this
164 LDAPMessageQueue* compare(const std::string& dn,
165 const LDAPAttribute& attr,
166 const LDAPConstraints *cons=0);
168 /** Add an entry to the directory
170 * @throws LDAPException If the Request could not be sent to the
171 * destination server, a LDAPException-object contains the
172 * error that occured.
173 * @param le The entry that will be added to the directory
175 LDAPMessageQueue* add( const LDAPEntry* le,
176 const LDAPConstraints *const=0);
178 /** Apply modifications to attributes of an entry
180 * @throws LDAPException If the Request could not be sent to the
181 * destination server, a LDAPException-object contains the
182 * error that occured.
183 * @param dn Distiguished Name of the Entry to modify
184 * @param modlist A set of modification that should be applied
186 * @param cons A set of constraints that should be used with this
189 LDAPMessageQueue* modify(const std::string& dn,
190 const LDAPModList *modlist,
191 const LDAPConstraints *cons=0);
193 /** modify the DN of an entry
195 * @throws LDAPException If the Request could not be sent to the
196 * destination server, a LDAPException-object contains the
197 * error that occured.
198 * @param dn DN to modify
199 * @param newRDN The new relative DN for the entry
200 * @param delOldRDN true=The old RDN will be removed from the
202 * false=The old RDN will still be present in the
203 * attributes of the entry
204 * @param newParentDN The DN of the new parent entry of the entry
205 * 0 to keep the old one
207 LDAPMessageQueue* rename(const std::string& dn,
208 const std::string& newRDN,
209 bool delOldRDN=false, const std::string& newParentDN="",
210 const LDAPConstraints* cons=0);
212 /** Perform a LDAP extended Operation
214 * @throws LDAPException If the Request could not be sent to the
215 * destination server, a LDAPException-object contains the
216 * error that occured.
217 * @param oid The dotted decimal representation of the extended
218 * Operation that should be performed
219 * @param value The data asociated with this operation
220 * @param cons A set of constraints that should be used with this
223 LDAPMessageQueue* extOperation(const std::string& oid,
224 const std::string& value="", const LDAPConstraints *cons=0);
226 /** End an outstanding request
228 * @param q All outstanding request related to this LDAPMessageQueue
231 void abandon(LDAPMessageQueue *q);
234 * Performs the UNBIND-operation on the destination server
236 * @throws LDAPException in any case of an error
241 * @returns The C-APIs LDAP-structure that is associated with the
244 LDAP* getSessionHandle() const ;
247 * @returns The Hostname of the destination server of the
250 const std::string& getHost() const;
253 * @returns The Port to which this connection is connecting to on
258 /** Change the default constraints of the connection
260 * @parameter cons cons New LDAPConstraints to use with the connection
262 void setConstraints(LDAPConstraints *cons);
264 /** Get the default constraints of the connection
266 * @return Pointer to the LDAPConstraints-Object that is currently
267 * used with the Connection
269 const LDAPConstraints* getConstraints() const;
272 * This method is used internally for automatic referral chasing.
273 * It tries to bind to a destination server of the URLs of a
276 * @throws LDAPException in any case of an error
277 * @param urls Contains a std::list of LDAP-Urls that indicate the
278 * destinations of a referral
279 * @param usedUrl After this method has successfully bind to one of
280 * the Destination URLs this parameter contains the URLs
281 * which was contacted.
282 * @param cons An LDAPConstraints-Object that should be used for
283 * the new connection. If this object contains a
284 * LDAPRebind-object it is used to bind to the new server
286 LDAPAsynConnection* referralConnect(const LDAPUrlList& urls,
287 LDAPUrlList::const_iterator& usedUrl,
288 const LDAPConstraints* cons) const;
292 * Private copy constructor. So nobody can call it.
294 LDAPAsynConnection(const LDAPAsynConnection& lc){};
297 * A pointer to the C-API LDAP-structure that is associated with
303 * A pointer to the default LDAPConstrains-object that is used when
304 * no LDAPConstraints-parameter is provided with a call for a
307 LDAPConstraints *m_constr;
310 * The name of the destination host
315 * The port the destination server is running on.
321 * Is caching enabled?
325 #endif //LDAP_ASYN_CONNECTION_H