]> git.sur5r.net Git - openldap/commitdiff
- use ldap_url_desc2str() to construct URL
authorRalf Haferkamp <ralf@openldap.org>
Fri, 31 Mar 2006 15:55:19 +0000 (15:55 +0000)
committerRalf Haferkamp <ralf@openldap.org>
Fri, 31 Mar 2006 15:55:19 +0000 (15:55 +0000)
- throw Exception in initialization error

contrib/ldapc++/src/LDAPAsynConnection.cpp
contrib/ldapc++/src/LDAPAsynConnection.h

index 5e192c36071db8e29a530aa8939e9c3fa264091a..6ffb5af4c3a4c6af85f2932f898f5b30a67601c8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 2000-2006, OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
@@ -49,10 +49,21 @@ void LDAPAsynConnection::init(const string& hostname, int port){
     DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
             "   hostname:" << hostname << endl
             << "   port:" << port << endl);
-    std::ostringstream urlstream;
-    urlstream << "ldap://" + hostname << ":" << port;
-    std::string url = urlstream.str();
-    ldap_initialize(&cur_session, url.c_str());
+
+    char* ldapuri;
+    LDAPURLDesc url;
+    memset( &url, 0, sizeof(url));
+
+    url.lud_scheme = "ldap";
+    url.lud_host = strdup(hostname.c_str());
+    url.lud_port = port;
+    url.lud_scope = LDAP_SCOPE_DEFAULT;
+
+    ldapuri = ldap_url_desc2str( &url );
+    int ret = ldap_initialize(&cur_session, ldapuri);
+    if ( ret != LDAP_SUCCESS ) {
+        throw LDAPException( ret );
+    }
     m_host=hostname;
     m_port=port;
     int opt=3;
index acd8151483e1274107d44ea67043a5b7bf059f44..dd8a72026d3a397107324023f2899b48d5e0764d 100644 (file)
@@ -71,7 +71,7 @@ class LDAPAsynConnection{
          *      this connection
          */
         LDAPAsynConnection(const std::string& hostname=std::string("localhost"),
-                int port=389, LDAPConstraints *cons=new LDAPConstraints() );
+                int port=0, LDAPConstraints *cons=new LDAPConstraints() );
 
         //* Destructor
         virtual ~LDAPAsynConnection();