From d3d7976747142eb79af8eab88d031022730ece7c Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Fri, 31 Mar 2006 15:55:19 +0000 Subject: [PATCH] - use ldap_url_desc2str() to construct URL - throw Exception in initialization error --- contrib/ldapc++/src/LDAPAsynConnection.cpp | 21 ++++++++++++++++----- contrib/ldapc++/src/LDAPAsynConnection.h | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/contrib/ldapc++/src/LDAPAsynConnection.cpp b/contrib/ldapc++/src/LDAPAsynConnection.cpp index 5e192c3607..6ffb5af4c3 100644 --- a/contrib/ldapc++/src/LDAPAsynConnection.cpp +++ b/contrib/ldapc++/src/LDAPAsynConnection.cpp @@ -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; diff --git a/contrib/ldapc++/src/LDAPAsynConnection.h b/contrib/ldapc++/src/LDAPAsynConnection.h index acd8151483..dd8a72026d 100644 --- a/contrib/ldapc++/src/LDAPAsynConnection.h +++ b/contrib/ldapc++/src/LDAPAsynConnection.h @@ -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(); -- 2.39.5