3 * Copyright 2000-2011 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include"LDAPAsynConnection.h"
11 #include "LDAPRequest.h"
12 #include "LDAPException.h"
18 LDAPResult::LDAPResult(const LDAPRequest *req, LDAPMessage *msg) :
21 DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPResult::LDAPResult()" << endl);
22 const LDAPAsynConnection *con=req->getConnection();
24 LDAPControl** srvctrls=0;
27 int err=ldap_parse_result(con->getSessionHandle(),msg,&m_resCode,
28 &matchedDN, &errMsg,&refs,&srvctrls,0);
29 if(err != LDAP_SUCCESS){
30 ber_memvfree((void**) refs);
31 ldap_controls_free(srvctrls);
32 throw LDAPException(err);
35 m_referrals=LDAPUrlList(refs);
36 ber_memvfree((void**) refs);
39 m_srvControls = LDAPControlSet(srvctrls);
41 ldap_controls_free(srvctrls);
43 m_hasControls = false;
46 m_matchedDN=string(matchedDN);
50 m_errMsg=string(errMsg);
57 LDAPResult::LDAPResult(int type, int resultCode, const std::string &msg) :
58 LDAPMsg(type,0), m_resCode(resultCode), m_errMsg(msg)
62 LDAPResult::~LDAPResult(){
63 DEBUG(LDAP_DEBUG_DESTROY,"LDAPResult::~LDAPResult()" << endl);
66 int LDAPResult::getResultCode() const{
67 DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::getResultCode()" << endl);
71 string LDAPResult::resToString() const{
72 DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::resToString()" << endl);
73 return string(ldap_err2string(m_resCode));
76 const string& LDAPResult::getErrMsg() const{
77 DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::getErrMsg()" << endl);
81 const string& LDAPResult::getMatchedDN() const{
82 DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::getMatchedDN()" << endl);
86 const LDAPUrlList& LDAPResult::getReferralUrls() const{
87 DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::getReferralUrl()" << endl);
91 ostream& operator<<(ostream &s,LDAPResult &l){
92 return s << "Result: " << l.m_resCode << ": "
93 << ldap_err2string(l.m_resCode) << endl
94 << "Matched: " << l.m_matchedDN << endl << "ErrMsg: " << l.m_errMsg;