X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=contrib%2Fldapc%2B%2B%2Fsrc%2FLDAPResult.cpp;h=f7c7c75f23dcc838fe1a894702798fb287206613;hb=4d0d12db27b3b44cc36acc089b0e640320480fe7;hp=c86a0d8cfa48502d1253a7a366813fb774f7afe3;hpb=84d0e262348b5c3ac877ce49424df89d7cb5fdff;p=openldap diff --git a/contrib/ldapc++/src/LDAPResult.cpp b/contrib/ldapc++/src/LDAPResult.cpp index c86a0d8cfa..f7c7c75f23 100644 --- a/contrib/ldapc++/src/LDAPResult.cpp +++ b/contrib/ldapc++/src/LDAPResult.cpp @@ -1,57 +1,95 @@ +// $OpenLDAP$ /* - * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. + * Copyright 2000-2012 The OpenLDAP Foundation, All Rights Reserved. * COPYING RESTRICTIONS APPLY, see COPYRIGHT file */ -// $Id: LDAPResult.cpp,v 1.10 2000/08/31 17:43:49 rhafer Exp $ #include "debug.h" #include"LDAPResult.h" #include"LDAPAsynConnection.h" #include "LDAPRequest.h" +#include "LDAPException.h" -LDAPResult::LDAPResult(LDAPRequest *req, LDAPMessage *msg) : LDAPMsg(msg){ - if(msg != 0){ - DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::LDAPResult()" << endl); - const LDAPAsynConnection *con=req->getConnection(); +#include + +using namespace std; - //TODO!!: - //handle referrals and controls +LDAPResult::LDAPResult(const LDAPRequest *req, LDAPMessage *msg) : + LDAPMsg(msg){ + if(msg != 0){ + DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPResult::LDAPResult()" << endl); + const LDAPAsynConnection *con=req->getConnection(); char **refs=0; - ldap_parse_result(con->getSessionHandle(),msg,&m_resCode, - &m_matchedDN, &m_errMsg,&refs,0,0); - if (refs != 0){ - for (char **tmp=refs;*tmp != 0; tmp++){ - DEBUG(LDAP_DEBUG_PARAMETER," url:" << *tmp << endl); + LDAPControl** srvctrls=0; + char* matchedDN=0; + char* errMsg=0; + int err=ldap_parse_result(con->getSessionHandle(),msg,&m_resCode, + &matchedDN, &errMsg,&refs,&srvctrls,0); + if(err != LDAP_SUCCESS){ + ber_memvfree((void**) refs); + ldap_controls_free(srvctrls); + throw LDAPException(err); + }else{ + if (refs){ + m_referrals=LDAPUrlList(refs); + ber_memvfree((void**) refs); + } + if (srvctrls){ + m_srvControls = LDAPControlSet(srvctrls); + m_hasControls = true; + ldap_controls_free(srvctrls); + }else{ + m_hasControls = false; + } + if(matchedDN != 0){ + m_matchedDN=string(matchedDN); + free(matchedDN); + } + if(errMsg != 0){ + m_errMsg=string(errMsg); + free(errMsg); } } - } + } } +LDAPResult::LDAPResult(int type, int resultCode, const std::string &msg) : + LDAPMsg(type,0), m_resCode(resultCode), m_errMsg(msg) +{} + + LDAPResult::~LDAPResult(){ - DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::~LDAPResult()" << endl); - delete[] m_matchedDN; - delete[] m_errMsg; + DEBUG(LDAP_DEBUG_DESTROY,"LDAPResult::~LDAPResult()" << endl); } -int LDAPResult::getResultCode(){ +int LDAPResult::getResultCode() const{ + DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::getResultCode()" << endl); return m_resCode; } -char* LDAPResult::resToString(){ - return ldap_err2string(m_resCode); +string LDAPResult::resToString() const{ + DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::resToString()" << endl); + return string(ldap_err2string(m_resCode)); +} + +const string& LDAPResult::getErrMsg() const{ + DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::getErrMsg()" << endl); + return m_errMsg; } -char* LDAPResult::getErrMsg(){ - return strdup(m_errMsg); +const string& LDAPResult::getMatchedDN() const{ + DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::getMatchedDN()" << endl); + return m_matchedDN; } -char* LDAPResult::getMatchedDN(){ - return strdup(m_matchedDN); +const LDAPUrlList& LDAPResult::getReferralUrls() const{ + DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::getReferralUrl()" << endl); + return m_referrals; } ostream& operator<<(ostream &s,LDAPResult &l){ - return s << "Result: " << l.m_resCode << ": " + return s << "Result: " << l.m_resCode << ": " << ldap_err2string(l.m_resCode) << endl << "Matched: " << l.m_matchedDN << endl << "ErrMsg: " << l.m_errMsg; }