]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/src/LDAPResult.cpp
Notices and acknowledgements
[openldap] / contrib / ldapc++ / src / LDAPResult.cpp
1 /*
2  * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5
6
7 #include "debug.h"
8 #include"LDAPResult.h"
9 #include"LDAPAsynConnection.h"
10 #include "LDAPRequest.h"
11 #include "LDAPException.h"
12
13 using namespace std;
14
15 LDAPResult::LDAPResult(const LDAPRequest *req, LDAPMessage *msg) : 
16         LDAPMsg(msg){
17     if(msg != 0){
18         DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPResult::LDAPResult()" << endl);
19         const LDAPAsynConnection *con=req->getConnection();
20         char **refs=0;
21         LDAPControl** srvctrls=0;
22         char* matchedDN=0;
23         char* errMsg=0;
24         int err=ldap_parse_result(con->getSessionHandle(),msg,&m_resCode,
25                 &matchedDN, &errMsg,&refs,&srvctrls,0);
26         if(err != LDAP_SUCCESS){
27             ldap_value_free(refs);
28             ldap_controls_free(srvctrls);
29             throw LDAPException(err);
30         }else{
31             if (refs){
32                 m_referrals=LDAPUrlList(refs);
33                 ldap_value_free(refs);
34             }
35             if (srvctrls){
36                 m_srvControls = LDAPControlSet(srvctrls);
37                 m_hasControls = true;
38                 ldap_controls_free(srvctrls);
39             }else{
40                 m_hasControls = false;
41             }
42             if(matchedDN != 0){
43                 m_matchedDN=string(matchedDN);
44                 free(matchedDN);
45             }
46             if(errMsg != 0){
47                 m_errMsg=string(errMsg);
48                 free(errMsg);
49             }
50         }
51     }
52 }
53
54 LDAPResult::~LDAPResult(){
55     DEBUG(LDAP_DEBUG_DESTROY,"LDAPResult::~LDAPResult()" << endl);
56 }
57
58 int LDAPResult::getResultCode() const{
59     DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::getResultCode()" << endl);
60     return m_resCode;
61 }
62
63 string LDAPResult::resToString() const{
64     DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::resToString()" << endl);
65     return string(ldap_err2string(m_resCode));
66 }
67
68 const string& LDAPResult::getErrMsg() const{
69     DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::getErrMsg()" << endl);
70     return m_errMsg;
71 }
72
73 const string& LDAPResult::getMatchedDN() const{
74     DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::getMatchedDN()" << endl);
75     return m_matchedDN;
76 }
77
78 const LDAPUrlList& LDAPResult::getReferralUrls() const{
79     DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::getReferralUrl()" << endl);
80     return m_referrals;
81 }
82
83 ostream& operator<<(ostream &s,LDAPResult &l){
84     return s << "Result: " << l.m_resCode << ": "  
85         << ldap_err2string(l.m_resCode) << endl 
86         << "Matched: " << l.m_matchedDN << endl << "ErrMsg: " << l.m_errMsg;
87 }
88