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.). If you need TLS,
96 * then you should error if this call fails with an error code.
100 /** Simple authentication to a LDAP-Server
102 * @throws LDAPException If the Request could not be sent to the
103 * destination server, a LDAPException-object contains the
104 * error that occured.
105 * This method does a simple (username, password) bind to the server.
106 * Other, saver, authentcation methods are provided later
107 * @param dn the distiguished name to bind as
108 * @param passwd cleartext password to use
110 LDAPMessageQueue* bind(const std::string& dn="", const std::string& passwd="",
111 const LDAPConstraints *cons=0);
113 /** Performing a search on a directory tree.
115 * Use the search method to perform a search on the LDAP-Directory
116 * @throws LDAPException If the Request could not be sent to the
117 * destination server, a LDAPException-object contains the
118 * error that occured.
119 * @param base The distinguished name of the starting point for the
121 * @param scope The scope of the search. Possible values: <BR>
122 * LDAPAsynConnection::SEARCH_BASE, <BR>
123 * LDAPAsynConnection::SEARCH_ONE, <BR>
124 * LDAPAsynConnection::SEARCH_SUB
125 * @param filter The std::string representation of a search filter to
126 * use with this operation
127 * @param attrsOnly true if only the attributes names (no values)
129 * @param cons A set of constraints that should be used with this
132 LDAPMessageQueue* search(const std::string& base="", int scope=0,
133 const std::string& filter="objectClass=*",
134 const StringList& attrs=StringList(),
135 bool attrsOnly=false,
136 const LDAPConstraints *cons=0);
138 /** Delete an entry from the directory
140 * This method sends a delete request to the server
141 * @throws LDAPException If the Request could not be sent to the
142 * destination server, a LDAPException-object contains the
143 * error that occured.
144 * @param dn Distinguished name of the entry that should be deleted
145 * @param cons A set of constraints that should be used with this
148 LDAPMessageQueue* del(const std::string& dn, const LDAPConstraints *cons=0);
151 * Perform the COMPARE-operation on an attribute
153 * @throws LDAPException If the Request could not be sent to the
154 * destination server, a LDAPException-object contains the
155 * error that occured.
156 * @param dn Distinguished name of the entry for which the compare
157 * should be performed
158 * @param attr An Attribute (one (!) value) to use for the
160 * @param cons A set of constraints that should be used with this
163 LDAPMessageQueue* compare(const std::string& dn,
164 const LDAPAttribute& attr,
165 const LDAPConstraints *cons=0);
167 /** Add an entry to the directory
169 * @throws LDAPException If the Request could not be sent to the
170 * destination server, a LDAPException-object contains the
171 * error that occured.
172 * @param le The entry that will be added to the directory
174 LDAPMessageQueue* add( const LDAPEntry* le,
175 const LDAPConstraints *const=0);
177 /** Apply modifications to attributes of an entry
179 * @throws LDAPException If the Request could not be sent to the
180 * destination server, a LDAPException-object contains the
181 * error that occured.
182 * @param dn Distiguished Name of the Entry to modify
183 * @param modlist A set of modification that should be applied
185 * @param cons A set of constraints that should be used with this
188 LDAPMessageQueue* modify(const std::string& dn,
189 const LDAPModList *modlist,
190 const LDAPConstraints *cons=0);
192 /** modify the DN of an entry
194 * @throws LDAPException If the Request could not be sent to the
195 * destination server, a LDAPException-object contains the
196 * error that occured.
197 * @param dn DN to modify
198 * @param newRDN The new relative DN for the entry
199 * @param delOldRDN true=The old RDN will be removed from the
201 * false=The old RDN will still be present in the
202 * attributes of the entry
203 * @param newParentDN The DN of the new parent entry of the entry
204 * 0 to keep the old one
206 LDAPMessageQueue* rename(const std::string& dn,
207 const std::string& newRDN,
208 bool delOldRDN=false, const std::string& newParentDN="",
209 const LDAPConstraints* cons=0);
211 /** Perform a LDAP extended Operation
213 * @throws LDAPException If the Request could not be sent to the
214 * destination server, a LDAPException-object contains the
215 * error that occured.
216 * @param oid The dotted decimal representation of the extended
217 * Operation that should be performed
218 * @param value The data asociated with this operation
219 * @param cons A set of constraints that should be used with this
222 LDAPMessageQueue* extOperation(const std::string& oid,
223 const std::string& value="", const LDAPConstraints *cons=0);
225 /** End an outstanding request
227 * @param q All outstanding request related to this LDAPMessageQueue
230 void abandon(LDAPMessageQueue *q);
233 * Performs the UNBIND-operation on the destination server
235 * @throws LDAPException in any case of an error
240 * @returns The C-APIs LDAP-structure that is associated with the
243 LDAP* getSessionHandle() const ;
246 * @returns The Hostname of the destination server of the
249 const std::string& getHost() const;
252 * @returns The Port to which this connection is connecting to on
257 /** Change the default constraints of the connection
259 * @parameter cons cons New LDAPConstraints to use with the connection
261 void setConstraints(LDAPConstraints *cons);
263 /** Get the default constraints of the connection
265 * @return Pointer to the LDAPConstraints-Object that is currently
266 * used with the Connection
268 const LDAPConstraints* getConstraints() const;
271 * This method is used internally for automatic referral chasing.
272 * It tries to bind to a destination server of the URLs of a
275 * @throws LDAPException in any case of an error
276 * @param urls Contains a std::list of LDAP-Urls that indicate the
277 * destinations of a referral
278 * @param usedUrl After this method has successfully bind to one of
279 * the Destination URLs this parameter contains the URLs
280 * which was contacted.
281 * @param cons An LDAPConstraints-Object that should be used for
282 * the new connection. If this object contains a
283 * LDAPRebind-object it is used to bind to the new server
285 LDAPAsynConnection* referralConnect(const LDAPUrlList& urls,
286 LDAPUrlList::const_iterator& usedUrl,
287 const LDAPConstraints* cons) const;
291 * Private copy constructor. So nobody can call it.
293 LDAPAsynConnection(const LDAPAsynConnection& lc){};
296 * A pointer to the C-API LDAP-structure that is associated with
302 * A pointer to the default LDAPConstrains-object that is used when
303 * no LDAPConstraints-parameter is provided with a call for a
306 LDAPConstraints *m_constr;
309 * The name of the destination host
314 * The port the destination server is running on.
320 * Is caching enabled?
324 #endif //LDAP_ASYN_CONNECTION_H