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 <LDAPEntry.h>
17 #include <LDAPException.h>
18 #include <LDAPMessageQueue.h>
19 #include <LDAPConstraints.h>
20 #include <LDAPModification.h>
21 #include <LDAPModList.h>
23 #include <LDAPUrlList.h>
25 //* Main class for an asynchronous LDAP connection
27 * This class represents an asynchronous connection to an LDAP-Server. It
28 * provides the methods for authentication, and all other LDAP-Operations
29 * (e.g. search, add, delete, etc.)
30 * All of the LDAP-Operations return a pointer to a LDAPMessageQueue-Object,
31 * which can be used to obtain the results of that operation.
32 * A basic example of this class could be like this: <BR>
33 * 1. Create a new LDAPAsynConnection Object: <BR>
34 * 2. Use the init-method to initialize the connection <BR>
35 * 3. Call the bind-method to authenticate to the directory <BR>
36 * 4. Obtain the bind results from the return LDAPMessageQueue-Object <BR>
37 * 5. Perform on of the operations on the directory (add, delete, search, ..)
39 * 6. Use the return LDAPMessageQueue to obtain the results of the operation
41 * 7. Close the connection (feature not implemented yet :) ) <BR>
43 class LDAPAsynConnection{
46 * Constant for the Search-Operation to indicate a Base-Level
49 static const int SEARCH_BASE=0;
52 * Constant for the Search-Operation to indicate a One-Level
55 static const int SEARCH_ONE=1;
58 * Constant for the Search-Operation to indicate a subtree
61 static const int SEARCH_SUB=2;
62 // static const int SEARCH_SUB=LDAP_SCOPE_SUBTREE;
63 // static const int SEARCH_ONE=LDAP_SCOPE_ONELEVEL;
64 // static const int SEARCH_SUB=LDAP_SCOPE_SUBTREE;
66 /** Construtor that initializes a connection to a server
67 * @param hostname Name (or IP-Adress) of the destination host
68 * @param port Port the LDAP server is running on
69 * @param cons Default constraints to use with operations over
72 LDAPAsynConnection(const std::string& hostname=std::string("localhost"),
73 int port=0, LDAPConstraints *cons=new LDAPConstraints() );
76 virtual ~LDAPAsynConnection();
79 * Initializes a connection to a server.
82 * communication to the server. Just the object is initialized
83 * (e.g. this method is called within the
84 * LDAPAsynConnection(char*,int,LDAPConstraints) constructor.)
85 * @param hostname The Name or IP-Address of the destination
87 * @param port The Network Port the server is running on
89 void init(const std::string& hostname, int port);
92 * Initializes a connection to a server.
94 * There actually no communication to the server. Just the
95 * object is initialized
96 * @param uri The LDAP-Uri for the destination
98 void initialize(const std::string& uri);
101 * Start TLS on this connection. This isn't in the constructor,
102 * because it could fail (i.e. server doesn't have SSL cert, client
103 * api wasn't compiled against OpenSSL, etc.).
104 * @throws LDAPException if the TLS Layer could not be setup
109 /** Simple authentication to a LDAP-Server
111 * @throws LDAPException If the Request could not be sent to the
112 * destination server, a LDAPException-object contains the
113 * error that occured.
114 * This method does a simple (username, password) bind to the server.
115 * Other, saver, authentcation methods are provided later
116 * @param dn the distiguished name to bind as
117 * @param passwd cleartext password to use
119 LDAPMessageQueue* bind(const std::string& dn="", const std::string& passwd="",
120 const LDAPConstraints *cons=0);
122 /** Performing a search on a directory tree.
124 * Use the search method to perform a search on the LDAP-Directory
125 * @throws LDAPException If the Request could not be sent to the
126 * destination server, a LDAPException-object contains the
127 * error that occured.
128 * @param base The distinguished name of the starting point for the
130 * @param scope The scope of the search. Possible values: <BR>
131 * LDAPAsynConnection::SEARCH_BASE, <BR>
132 * LDAPAsynConnection::SEARCH_ONE, <BR>
133 * LDAPAsynConnection::SEARCH_SUB
134 * @param filter The std::string representation of a search filter to
135 * use with this operation
136 * @param attrsOnly true if only the attributes names (no values)
138 * @param cons A set of constraints that should be used with this
141 LDAPMessageQueue* search(const std::string& base="", int scope=0,
142 const std::string& filter="objectClass=*",
143 const StringList& attrs=StringList(),
144 bool attrsOnly=false,
145 const LDAPConstraints *cons=0);
147 /** Delete an entry from the directory
149 * This method sends a delete request to the server
150 * @throws LDAPException If the Request could not be sent to the
151 * destination server, a LDAPException-object contains the
152 * error that occured.
153 * @param dn Distinguished name of the entry that should be deleted
154 * @param cons A set of constraints that should be used with this
157 LDAPMessageQueue* del(const std::string& dn, const LDAPConstraints *cons=0);
160 * Perform the COMPARE-operation on an attribute
162 * @throws LDAPException If the Request could not be sent to the
163 * destination server, a LDAPException-object contains the
164 * error that occured.
165 * @param dn Distinguished name of the entry for which the compare
166 * should be performed
167 * @param attr An Attribute (one (!) value) to use for the
169 * @param cons A set of constraints that should be used with this
172 LDAPMessageQueue* compare(const std::string& dn,
173 const LDAPAttribute& attr,
174 const LDAPConstraints *cons=0);
176 /** Add an entry to the directory
178 * @throws LDAPException If the Request could not be sent to the
179 * destination server, a LDAPException-object contains the
180 * error that occured.
181 * @param le The entry that will be added to the directory
183 LDAPMessageQueue* add( const LDAPEntry* le,
184 const LDAPConstraints *const=0);
186 /** Apply modifications to attributes of an entry
188 * @throws LDAPException If the Request could not be sent to the
189 * destination server, a LDAPException-object contains the
190 * error that occured.
191 * @param dn Distiguished Name of the Entry to modify
192 * @param modlist A set of modification that should be applied
194 * @param cons A set of constraints that should be used with this
197 LDAPMessageQueue* modify(const std::string& dn,
198 const LDAPModList *modlist,
199 const LDAPConstraints *cons=0);
201 /** modify the DN of an entry
203 * @throws LDAPException If the Request could not be sent to the
204 * destination server, a LDAPException-object contains the
205 * error that occured.
206 * @param dn DN to modify
207 * @param newRDN The new relative DN for the entry
208 * @param delOldRDN true=The old RDN will be removed from the
210 * false=The old RDN will still be present in the
211 * attributes of the entry
212 * @param newParentDN The DN of the new parent entry of the entry
213 * 0 to keep the old one
215 LDAPMessageQueue* rename(const std::string& dn,
216 const std::string& newRDN,
217 bool delOldRDN=false, const std::string& newParentDN="",
218 const LDAPConstraints* cons=0);
220 /** Perform a LDAP extended Operation
222 * @throws LDAPException If the Request could not be sent to the
223 * destination server, a LDAPException-object contains the
224 * error that occured.
225 * @param oid The dotted decimal representation of the extended
226 * Operation that should be performed
227 * @param value The data asociated with this operation
228 * @param cons A set of constraints that should be used with this
231 LDAPMessageQueue* extOperation(const std::string& oid,
232 const std::string& value="", const LDAPConstraints *cons=0);
234 /** End an outstanding request
236 * @param q All outstanding request related to this LDAPMessageQueue
239 void abandon(LDAPMessageQueue *q);
242 * Performs the UNBIND-operation on the destination server
244 * @throws LDAPException in any case of an error
249 * @returns The C-APIs LDAP-structure that is associated with the
252 LDAP* getSessionHandle() const ;
255 * @returns The Hostname of the destination server of the
258 const std::string& getHost() const;
261 * @returns The Port to which this connection is connecting to on
266 /** Change the default constraints of the connection
268 * @parameter cons cons New LDAPConstraints to use with the connection
270 void setConstraints(LDAPConstraints *cons);
272 /** Get the default constraints of the connection
274 * @return Pointer to the LDAPConstraints-Object that is currently
275 * used with the Connection
277 const LDAPConstraints* getConstraints() const;
280 * This method is used internally for automatic referral chasing.
281 * It tries to bind to a destination server of the URLs of a
284 * @throws LDAPException in any case of an error
285 * @param urls Contains a std::list of LDAP-Urls that indicate the
286 * destinations of a referral
287 * @param usedUrl After this method has successfully bind to one of
288 * the Destination URLs this parameter contains the URLs
289 * which was contacted.
290 * @param cons An LDAPConstraints-Object that should be used for
291 * the new connection. If this object contains a
292 * LDAPRebind-object it is used to bind to the new server
294 LDAPAsynConnection* referralConnect(const LDAPUrlList& urls,
295 LDAPUrlList::const_iterator& usedUrl,
296 const LDAPConstraints* cons) const;
300 * Private copy constructor. So nobody can call it.
302 LDAPAsynConnection(const LDAPAsynConnection& lc){};
305 * A pointer to the C-API LDAP-structure that is associated with
311 * A pointer to the default LDAPConstrains-object that is used when
312 * no LDAPConstraints-parameter is provided with a call for a
315 LDAPConstraints *m_constr;
318 * The URI of this connection
324 * Is caching enabled?
328 #endif //LDAP_ASYN_CONNECTION_H