]> git.sur5r.net Git - openldap/blobdiff - contrib/ldapc++/src/LDAPAsynConnection.h
Update guide Copyright/License handling
[openldap] / contrib / ldapc++ / src / LDAPAsynConnection.h
index d57035d949752ca047ef426c5ab9e62d3074a1b7..12cf9d803fd1da44f5af78d3ad02f7ff76ed88fc 100644 (file)
@@ -1,5 +1,6 @@
+// $OpenLDAP$
 /*
- * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 2000-2011 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
 #include<string>
 
 #include<ldap.h>
-#include<lber.h>
 
+#include <LDAPEntry.h>
+#include <LDAPException.h>
 #include <LDAPMessageQueue.h>
 #include <LDAPConstraints.h>
 #include <LDAPModification.h>
 #include <LDAPModList.h>
 #include <LDAPUrl.h>
 #include <LDAPUrlList.h>
-
-class LDAPEntry;
-class LDAPAttribute;
+#include <SaslInteractionHandler.h>
+#include <TlsOptions.h>
 
 //* Main class for an asynchronous LDAP connection 
 /**
@@ -60,9 +61,6 @@ class LDAPAsynConnection{
          * Search
          */
         static const int SEARCH_SUB=2;
-//        static const int SEARCH_SUB=LDAP_SCOPE_SUBTREE;
-//        static const int SEARCH_ONE=LDAP_SCOPE_ONELEVEL;
-//        static const int SEARCH_SUB=LDAP_SCOPE_SUBTREE;
 
         /** Construtor that initializes a connection to a server
          * @param hostname Name (or IP-Adress) of the destination host
@@ -70,12 +68,11 @@ class LDAPAsynConnection{
          * @param cons Default constraints to use with operations over 
          *      this connection
          */
-        LDAPAsynConnection(const std::string& hostname=std::string("localhost"),
-                int port=389, LDAPConstraints *cons=new LDAPConstraints() );
+        LDAPAsynConnection(const std::string& url=std::string("localhost"),
+                int port=0, LDAPConstraints *cons=new LDAPConstraints() );
 
         //* Destructor
         virtual ~LDAPAsynConnection();
-
         /** 
          * Initializes a connection to a server. 
          * 
@@ -89,13 +86,23 @@ class LDAPAsynConnection{
          */
         void init(const std::string& hostname, int port);
 
+        /**
+         * Initializes a connection to a server. 
+         * 
+         * There actually no communication to the server. Just the
+         * object is initialized 
+         * @param uri  The LDAP-Uri for the destination
+         */ 
+        void initialize(const std::string& uri);
+
         /**
          * Start TLS on this connection.  This isn't in the constructor,
          * because it could fail (i.e. server doesn't have SSL cert, client
-         * api wasn't compiled against OpenSSL, etc.).  If you need TLS,
-         * then you should error if this call fails with an error code.
+         * api wasn't compiled against OpenSSL, etc.). 
+         * @throws LDAPException if the TLS Layer could not be setup 
+         * correctly
          */
-        int start_tls();
+        void start_tls();
 
         /** Simple authentication to a LDAP-Server
          *
@@ -107,7 +114,17 @@ class LDAPAsynConnection{
          * @param dn the distiguished name to bind as
          * @param passwd cleartext password to use
          */
-        LDAPMessageQueue* bind(const std::string& dn="", const std::string& passwd="",
+        LDAPMessageQueue* bind(const std::string& dn="", 
+                const std::string& passwd="",
+                const LDAPConstraints *cons=0);
+
+        LDAPMessageQueue* saslBind(const std::string& mech, 
+                const std::string& cred, 
+                const LDAPConstraints *cons=0);
+
+        LDAPMessageQueue* saslInteractiveBind(const std::string& mech,
+                int flags=0,
+                SaslInteractionHandler *sih=0,
                 const LDAPConstraints *cons=0);
 
         /** Performing a search on a directory tree.
@@ -134,7 +151,7 @@ class LDAPAsynConnection{
                                  const StringList& attrs=StringList(), 
                                  bool attrsOnly=false,
                                  const LDAPConstraints *cons=0);
-        
+
         /** Delete an entry from the directory
          *
          * This method sends a delete request to the server
@@ -146,7 +163,7 @@ class LDAPAsynConnection{
          *              request
          */
         LDAPMessageQueue* del(const std::string& dn, const LDAPConstraints *cons=0);
-        
+
         /** 
          * Perform the COMPARE-operation on an attribute 
          *
@@ -160,7 +177,8 @@ class LDAPAsynConnection{
          * @param cons  A set of constraints that should be used with this
          *              request
          */
-        LDAPMessageQueue* compare(const std::string& dn, const LDAPAttribute& attr, 
+        LDAPMessageQueue* compare(const std::string& dn, 
+                const LDAPAttribute& attr, 
                 const LDAPConstraints *cons=0);
 
         /** Add an entry to the directory
@@ -179,12 +197,13 @@ class LDAPAsynConnection{
          *      destination server, a LDAPException-object contains the
          *      error that occured.
          * @param dn Distiguished Name of the Entry to modify
-         * @param modstd::list A set of modification that should be applied
+         * @param modlist A set of modification that should be applied
          *      to the Entry
          * @param cons  A set of constraints that should be used with this
          *              request
          */
-        LDAPMessageQueue* modify(const std::string& dn, const LDAPModList *modlist,
+        LDAPMessageQueue* modify(const std::string& dn, 
+                const LDAPModList *modlist,
                 const LDAPConstraints *cons=0);
 
         /** modify the DN of an entry
@@ -201,10 +220,11 @@ class LDAPAsynConnection{
          * @param newParentDN   The DN of the new parent entry of the entry
          *                      0 to keep the old one
          */
-        LDAPMessageQueue* rename(const std::string& dn, const std::string& newRDN,
+        LDAPMessageQueue* rename(const std::string& dn, 
+                const std::string& newRDN,
                 bool delOldRDN=false, const std::string& newParentDN="",
                 const LDAPConstraints* cons=0);
-        
+
         /** Perform a LDAP extended Operation
          *
          * @throws LDAPException If the Request could not be sent to the
@@ -218,14 +238,14 @@ class LDAPAsynConnection{
          */
         LDAPMessageQueue* extOperation(const std::string& oid, 
                 const std::string& value="", const LDAPConstraints *cons=0);
-        
+
         /** End an outstanding request
          *
          * @param q All outstanding request related to this LDAPMessageQueue 
          *      will be abandoned
          */
         void abandon(LDAPMessageQueue *q);
-        
+
         /**
          * Performs the UNBIND-operation on the destination server
          * 
@@ -250,20 +270,20 @@ class LDAPAsynConnection{
          *      the remote server. 
          */
         int getPort() const;
-        
+
         /** Change the default constraints of the connection
          *
          * @parameter cons cons New LDAPConstraints to use with the connection
          */
         void setConstraints(LDAPConstraints *cons);
-        
+
         /** Get the default constraints of the connection
          *
          * @return Pointer to the LDAPConstraints-Object that is currently
          *      used with the Connection
          */
         const LDAPConstraints* getConstraints() const;
-
+        TlsOptions getTlsOptions() const;
         /**
          * This method is used internally for automatic referral chasing.
          * It tries to bind to a destination server of the URLs of a
@@ -283,28 +303,12 @@ class LDAPAsynConnection{
                 LDAPUrlList::const_iterator& usedUrl,
                 const LDAPConstraints* cons) const;
 
-        /**
-         * Turn on caching, maxmem is in MB and timeout is in seconds.
-         * maxmem can be zero if you want to restrict caching by timeout only.
-         */
-        int enableCache(long timeout, long maxmem);
-        /// disable caching.
-        void disableCache();
-        /// is cacheEnabled?
-        bool getCacheEnabled() { return m_cacheEnabled;};
-        /// uncache a specific dn.  Used internally by methods that write.
-        void uncache_entry(std::string &dn);
-        /// used to clear the cache.  Probably should be used after creating
-        /// an object that a cached search should find.
-        void flush_cache();
-        
-        
     private :
         /**
          * Private copy constructor. So nobody can call it.
          */
         LDAPAsynConnection(const LDAPAsynConnection& lc){};
-        
+
         /**
          * A pointer to the C-API LDAP-structure that is associated with
          * this connection
@@ -319,16 +323,11 @@ class LDAPAsynConnection{
         LDAPConstraints *m_constr;
 
         /**
-         * The name of the destination host
-         */
-        std::string m_host;
-
-        /**
-         * The port the destination server is running on.
+         * The URI of this connection
          */
-        int m_port;
+        LDAPUrl m_uri;
 
- protected:
   protected:
         /**
          * Is caching enabled?
          */