From 7731832751ab9f3c6ddeb66f186d3d7fa1934a6d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 13:11:40 +0200 Subject: Adding upstream version 2.4.57+dfsg. Signed-off-by: Daniel Baumann --- contrib/ldapc++/src/LDAPResult.cpp | 96 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 contrib/ldapc++/src/LDAPResult.cpp (limited to 'contrib/ldapc++/src/LDAPResult.cpp') diff --git a/contrib/ldapc++/src/LDAPResult.cpp b/contrib/ldapc++/src/LDAPResult.cpp new file mode 100644 index 0000000..a96e155 --- /dev/null +++ b/contrib/ldapc++/src/LDAPResult.cpp @@ -0,0 +1,96 @@ +// $OpenLDAP$ +/* + * Copyright 2000-2021 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + + +#include "debug.h" +#include"LDAPResult.h" +#include"LDAPAsynConnection.h" +#include "LDAPRequest.h" +#include "LDAPException.h" + +#include + +using namespace std; + +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; + 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_DESTROY,"LDAPResult::~LDAPResult()" << endl); +} + +int LDAPResult::getResultCode() const{ + DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::getResultCode()" << endl); + return 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; +} + +const string& LDAPResult::getMatchedDN() const{ + DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::getMatchedDN()" << endl); + return 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 << ": " + << ldap_err2string(l.m_resCode) << endl + << "Matched: " << l.m_matchedDN << endl << "ErrMsg: " << l.m_errMsg; +} + -- cgit v1.2.3