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