+// $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
/**
* 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
* @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.
*
*/
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
*
* @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.
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
* request
*/
LDAPMessageQueue* del(const std::string& dn, const LDAPConstraints *cons=0);
-
+
/**
* Perform the COMPARE-operation on an attribute
*
* @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
* 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
* @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
*/
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
*
* 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
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
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?
*/