]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/src/LDAPException.cpp
f3022d06eb7c34c543035b5478d9133b844f35fe
[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 LDAPException::LDAPException(int res_code, const string& err_string){
16         m_res_code=res_code;
17         m_res_string=string(ldap_err2string(res_code));
18     m_err_string=err_string;
19 }
20
21 LDAPException::LDAPException(const LDAPAsynConnection *lc){
22         m_err_string=string();
23         m_res_string=string();
24         LDAP *l = lc->getSessionHandle();
25         ldap_get_option(l,LDAP_OPT_ERROR_NUMBER,&m_res_code);
26         m_res_string=string(ldap_err2string(m_res_code));
27     char* err_string;
28         ldap_get_option(l,LDAP_OPT_ERROR_STRING,&err_string);
29     m_err_string=string(err_string);
30 }
31
32 LDAPException::~LDAPException(){
33 }
34
35 int LDAPException::getResultCode() const{
36         return m_res_code;
37 }
38
39 const string& LDAPException::getResultMsg() const{
40         return m_res_string;
41 }
42
43 const string& LDAPException::getServerMsg() const{
44     return m_err_string;
45 }
46
47 ostream& operator << (ostream& s, LDAPException e){
48         s << "Error " << e.m_res_code << ": " << e.m_res_string;
49         if (e.m_err_string.size() > 0) {
50                 s << endl <<  "additional info: " << e.m_err_string ;
51         }
52         return s;
53 }
54