]> git.sur5r.net Git - openldap/commitdiff
use URIs instead of hostname/port
authorQuanah Gibson-Mount <quanah@openldap.org>
Thu, 18 Oct 2007 19:18:30 +0000 (19:18 +0000)
committerQuanah Gibson-Mount <quanah@openldap.org>
Thu, 18 Oct 2007 19:18:30 +0000 (19:18 +0000)
contrib/ldapc++/src/LDAPAsynConnection.cpp
contrib/ldapc++/src/LDAPAsynConnection.h

index cb2542b514ce3c41a0edd4cb778e2619b52196e1..edff84d95cbc3cc12c911dca7e41a0b06372ca9d 100644 (file)
@@ -49,22 +49,26 @@ void LDAPAsynConnection::init(const string& hostname, int port){
             "   hostname:" << hostname << endl
             << "   port:" << port << endl);
 
-    char* ldapuri;
-    LDAPURLDesc url;
-    memset( &url, 0, sizeof(url));
-
-    url.lud_scheme = strdup("ldap");
-    url.lud_host = strdup(hostname.c_str());
-    url.lud_port = port;
-    url.lud_scope = LDAP_SCOPE_DEFAULT;
-
-    ldapuri = ldap_url_desc2str( &url );
+    m_uri.setScheme("ldap");
+    m_uri.setHost(hostname);
+    m_uri.setPort(port);
+    
+    const char *ldapuri = m_uri.getURLString().c_str();
     int ret = ldap_initialize(&cur_session, ldapuri);
     if ( ret != LDAP_SUCCESS ) {
         throw LDAPException( ret );
     }
-    m_host=hostname;
-    m_port=port;
+    int opt=3;
+    ldap_set_option(cur_session, LDAP_OPT_REFERRALS, LDAP_OPT_OFF);
+    ldap_set_option(cur_session, LDAP_OPT_PROTOCOL_VERSION, &opt);
+}
+
+void LDAPAsynConnection::initialize(const std::string& uri){
+       m_uri.setURLString(uri);
+    int ret = ldap_initialize(&cur_session, m_uri.getURLString().c_str());
+    if ( ret != LDAP_SUCCESS ) {
+        throw LDAPException( ret );
+    }
     int opt=3;
     ldap_set_option(cur_session, LDAP_OPT_REFERRALS, LDAP_OPT_OFF);
     ldap_set_option(cur_session, LDAP_OPT_PROTOCOL_VERSION, &opt);
@@ -250,12 +254,12 @@ LDAP* LDAPAsynConnection::getSessionHandle() const{
 
 const string& LDAPAsynConnection::getHost() const{
     DEBUG(LDAP_DEBUG_TRACE,"LDAPAsynConnection::setHost()" << endl);
-    return m_host;
+    return m_uri.getHost();
 }
 
 int LDAPAsynConnection::getPort() const{
     DEBUG(LDAP_DEBUG_TRACE,"LDAPAsynConnection::getPort()" << endl);
-    return m_port;
+    return m_uri.getPort();
 }
 
 LDAPAsynConnection* LDAPAsynConnection::referralConnect(
index fe00df9c2d522ae259ff4c0a84b926e814ac6b23..5ac36c581ab106503380107d523ce6939fdab96b 100644 (file)
@@ -88,6 +88,15 @@ 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
@@ -306,14 +315,9 @@ 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:
         /**