]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/src/LDAPAsynConnection.h
- removed char* in favour of string
[openldap] / contrib / ldapc++ / src / LDAPAsynConnection.h
1 /*
2  * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5
6
7 #ifndef LDAP_ASYN_CONNECTION_H
8 #define LDAP_ASYN_CONNECTION_H
9
10 #include<iostream>
11 #include<string>
12
13 #include<ldap.h>
14 #include<lber.h>
15
16 #include "LDAPMessageQueue.h"
17 #include "LDAPConstraints.h"
18 #include "LDAPModification.h"
19 #include "LDAPModList.h"
20 #include "LDAPUrl.h"
21 #include "LDAPUrlList.h"
22
23 class LDAPEntry;
24 class LDAPAttribute;
25
26 //* Main class for an asynchronous LDAP connection 
27 /**
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, ..)
39  *    <BR>
40  * 6. Use the return LDAPMessageQueue to obtain the results of the operation 
41  * <BR>
42  * 7. Close the connection (feature not implemented yet :) ) <BR>
43  */
44 class LDAPAsynConnection{
45     public :
46         static const int SEARCH_BASE=0;
47         static const int SEARCH_ONE=1;
48         static const int SEARCH_SUB=2;
49 //        static const int SEARCH_SUB=LDAP_SCOPE_SUBTREE;
50 //        static const int SEARCH_ONE=LDAP_SCOPE_ONELEVEL;
51 //        static const int SEARCH_SUB=LDAP_SCOPE_SUBTREE;
52
53         //* Construtor that initializes a connection to a server
54         /**
55          * @param hostname Name (or IP-Adress) of the destination host
56          * @param port Port the LDAP server is running on
57          * @param cons Default constraints to use with operations over 
58          *      this connection
59          */
60         LDAPAsynConnection(const string& hostname=string("localhost"),
61                 int port=389, LDAPConstraints *cons=new LDAPConstraints() );
62
63         //* Destructor
64         virtual ~LDAPAsynConnection();
65
66         /** 
67          * Initzializes a connection to a server. There actually no
68          * communication to the server. Just the object is initialized
69          * (e.g. this method is called with the 
70          * LDAPAsynConnection(char*,int,LDAPConstraints) constructor.)
71          */
72         void init(const string& hostname, int port);
73
74         //* Simple authentication to a LDAP-Server
75         /**
76          * This method does a simple (username, password) bind to the server.
77          * Other, saver, authentcation methods are provided later
78          * @param dn the distiguished name to bind as
79          * @param passwd cleartext password to use
80          */
81         LDAPMessageQueue* bind(const string& dn="", const string& passwd="",
82                 const LDAPConstraints *cons=0);
83
84         //* Performing a search on a directory tree.
85         /**
86          * Use the search method to perform a search on the LDAP-Directory
87          * @param base The distinguished name of the starting point for the
88          *      search operation
89          * @param scope The scope of the search. Possible values: <BR> 
90          *      LDAPAsynConnection::SEARCH_BASE, <BR> 
91          *      LDAPAsynConnection::SEARCH_ONE, <BR>
92          *      LDAPAsynConnection::SEARCH_SUB
93          * @param attrsOnly true if only the attributes names (no values) 
94          *      should be returned
95          * @param cons A set of constraints that should be used with this
96          *      request
97          */
98         LDAPMessageQueue* search(const string& base="", int scope=0, 
99                                  const string& filter="objectClass=*", 
100                                  const StringList& attrs=StringList(), 
101                                  bool attrsOnly=false,
102                                  const LDAPConstraints *cons=0);
103         
104         //* Delete an entry from the directory
105         /**
106          * This method sends a delete request to the server
107          * @param dn    Distinguished name of the entry that should be deleted
108          * @param cons  A set of constraints that should be used with this
109          *              request
110          */
111         LDAPMessageQueue* del(const string& dn, const LDAPConstraints *cons=0);
112         
113         //* Perform the compare operation on an attribute 
114         /**
115          * @param dn    Distinguished name of the entry for which the compare
116          *              should be performed
117          * @param attr  An Attribute (one (!) value) to use for the
118          *      compare operation
119          * @param cons  A set of constraints that should be used with this
120          *              request
121          */
122         LDAPMessageQueue* compare(const string& dn, const LDAPAttribute& attr, 
123                 const LDAPConstraints *cons=0);
124
125         //* Add an entry to the directory
126         /**
127          * @see LDAPEntry
128          * @param le The entry that will be added to the directory
129          */
130         LDAPMessageQueue* add( const LDAPEntry* le,
131                 const LDAPConstraints *const=0);
132
133         //* Apply modifications to attributes of an entry
134         /**
135          * @param dn Distiguished Name of the Entry to modify
136          * @param modlist A set of modification that should be applied
137          *      to the Entry
138          * @param cons  A set of constraints that should be used with this
139          *              request
140          */
141         LDAPMessageQueue* modify(const string& dn, const LDAPModList *modlist,
142                 const LDAPConstraints *cons=0);
143
144         //* modify the DN of an entry
145         /**
146          * @param dn            DN to modify
147          * @param newRDN        The new relative DN for the entry
148          * @param delOldRDN     true=The old RDN will be removed from the 
149          *                      attributes <BR>
150          *                      false=The old RDN will still be present in the
151          *                      attributes of the entry
152          * @param newParentDN   The DN of the new parent entry of the entry
153          *                      0 to keep the old one
154          */
155         LDAPMessageQueue* rename(const string& dn, const string& newRDN,
156                 bool delOldRDN=false, const string& newParentDN="",
157                 const LDAPConstraints* cons=0);
158         
159         //* Perform a LDAP extended Operation
160         /**
161          * e.g. requesting TLS security features
162          * @param oid The dotted decimal representation of the extended 
163          *      Operation that should be performed
164          * @param value The data asociated with this operation
165          * @param cons  A set of constraints that should be used with this
166          *              request
167          */
168         LDAPMessageQueue* extOperation(const string& oid, 
169                 const string& value="", const LDAPConstraints *cons=0);
170         
171         //* End an outstanding request
172         /**
173          * @param q All outstanding request related to this LDAPMessageQueue 
174          *      will be abandoned
175          */
176         void abandon(LDAPMessageQueue *q);
177         void unbind();
178         LDAP* getSessionHandle() const ;
179         const string& getHost() const;
180         int getPort() const;
181         
182         //* Change the default constraints of the connection
183         /**
184          * @cons cons New LDAPConstraints to use with the connection
185          */
186         void setConstraints(LDAPConstraints *cons);
187         
188         //* Get the default constraints of the connection
189         /**
190          * @return Pointer to the LDAPConstraints-Object that is currently
191          *      used with the Connection
192          */
193         const LDAPConstraints* getConstraints() const;
194
195         //* used internally only for automatic referral chasing
196         LDAPAsynConnection* referralConnect(const LDAPUrlList& urls,
197                 LDAPUrlList::const_iterator& usedUrl,
198                 const LDAPConstraints* cons) const;
199
200
201     private :
202         // no copy constructor
203         LDAPAsynConnection(const LDAPAsynConnection& lc){};
204         LDAP *cur_session;
205         LDAPConstraints *m_constr;
206         string m_host;
207         int m_port;
208
209 };
210 #endif //LDAP_ASYN_CONNECTION_H
211
212