]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/src/LDAPResult.cpp
Initial check of the LDAP C++ SDK written by Ralf Haferkamp <rhafer@suse.de>
[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 // $Id: LDAPResult.cpp,v 1.10 2000/08/31 17:43:49 rhafer Exp $
7
8 #include "debug.h"
9 #include"LDAPResult.h"
10 #include"LDAPAsynConnection.h"
11 #include "LDAPRequest.h"
12
13 LDAPResult::LDAPResult(LDAPRequest *req, LDAPMessage *msg) : LDAPMsg(msg){
14         if(msg != 0){
15         DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::LDAPResult()" << endl);
16         const LDAPAsynConnection *con=req->getConnection();
17
18         //TODO!!:
19         //handle referrals and controls
20         char **refs=0;
21                 ldap_parse_result(con->getSessionHandle(),msg,&m_resCode,
22                                 &m_matchedDN, &m_errMsg,&refs,0,0);
23         if (refs != 0){
24             for (char **tmp=refs;*tmp != 0; tmp++){
25                 DEBUG(LDAP_DEBUG_PARAMETER,"   url:" << *tmp << endl);
26             }
27         }
28         }
29 }
30
31 LDAPResult::~LDAPResult(){
32     DEBUG(LDAP_DEBUG_TRACE,"LDAPResult::~LDAPResult()" << endl);
33     delete[] m_matchedDN;
34     delete[] m_errMsg;
35 }
36
37 int LDAPResult::getResultCode(){
38     return m_resCode;
39 }
40
41 char* LDAPResult::resToString(){
42     return ldap_err2string(m_resCode);
43 }
44
45 char* LDAPResult::getErrMsg(){
46     return strdup(m_errMsg);
47 }
48
49 char* LDAPResult::getMatchedDN(){
50     return strdup(m_matchedDN);
51 }
52
53 ostream& operator<<(ostream &s,LDAPResult &l){
54         return s << "Result: " << l.m_resCode << ": "  
55         << ldap_err2string(l.m_resCode) << endl 
56         << "Matched: " << l.m_matchedDN << endl << "ErrMsg: " << l.m_errMsg;
57 }
58