]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/src/LDAPException.cpp
Initial check of the LDAP C++ SDK written by Ralf Haferkamp <rhafer@suse.de>
[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 // $Id: LDAPException.cpp,v 1.7 2000/08/31 17:43:48 rhafer Exp $
7
8
9 #include <ldap.h>
10 #include "config.h"
11 #include "ac/string.h"
12 #include "LDAPException.h"
13
14 LDAPException::LDAPException(int res_code, char *err_string=0){
15         m_res_code=res_code;
16         m_res_string=ldap_err2string(res_code);
17         if(err_string != 0){
18         m_err_string=strdup(err_string);
19     }else{
20         m_err_string=0;
21     }
22 }
23
24 LDAPException::LDAPException(const LDAPAsynConnection *lc){
25         m_err_string=0;
26         m_res_string=0;
27         LDAP *l = lc->getSessionHandle();
28         ldap_get_option(l,LDAP_OPT_ERROR_NUMBER,&m_res_code);
29         m_res_string=ldap_err2string(m_res_code);
30         ldap_get_option(l,LDAP_OPT_ERROR_STRING,&m_err_string);
31 }
32
33 int LDAPException::getResultCode(){
34         return m_res_code;
35 }
36
37 char* LDAPException::getResultMsg(){
38         return strdup(m_res_string);
39 }
40
41 ostream& operator << (ostream& s, LDAPException e){
42         s << "Error " << e.m_res_code << ": " << e.m_res_string;
43         if (e.m_err_string != 0) {
44                 s << endl <<  "additional info: " << e.m_err_string ;
45         }
46         return s;
47 }
48