]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/src/LDAPException.cpp
add LDAP_OPT_DIAGNOSTIC_MESSAGE; replace deprecated option names
[openldap] / contrib / ldapc++ / src / LDAPException.cpp
1 /*
2  * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5
6
7
8 #include <ldap.h>
9 #include "config.h"
10 #include "LDAPException.h"
11 #include "LDAPReferralException.h"
12
13 #include "LDAPAsynConnection.h"
14
15 using namespace std;
16
17 LDAPException::LDAPException(int res_code, const string& err_string){
18         m_res_code=res_code;
19         m_res_string=string(ldap_err2string(res_code));
20     m_err_string=err_string;
21 }
22
23 LDAPException::LDAPException(const LDAPAsynConnection *lc){
24     LDAP *l = lc->getSessionHandle();
25     ldap_get_option(l,LDAP_OPT_RESULT_CODE,&m_res_code);
26     const char *res_cstring = ldap_err2string(m_res_code);
27     if ( res_cstring ) {
28         m_res_string = string(res_cstring);
29     } else {
30         m_res_string = "";
31     }
32     const char* err_string;
33     ldap_get_option(l,LDAP_OPT_DIAGNOSTIC_MESSAGE,&err_string);
34     if ( err_string ) {
35         m_res_string = string(err_string);
36     } else {
37         m_res_string = "";
38     }
39 }
40
41 LDAPException::~LDAPException(){
42 }
43
44 int LDAPException::getResultCode() const{
45         return m_res_code;
46 }
47
48 const string& LDAPException::getResultMsg() const{
49         return m_res_string;
50 }
51
52 const string& LDAPException::getServerMsg() const{
53     return m_err_string;
54 }
55
56 ostream& operator << (ostream& s, LDAPException e){
57         s << "Error " << e.m_res_code << ": " << e.m_res_string;
58         if (!e.m_err_string.empty()) {
59                 s << endl <<  "additional info: " << e.m_err_string ;
60         }
61         return s;
62 }
63