2000-09-01 14:46:32 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <ldap.h>
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "LDAPException.h"
|
2000-10-03 14:25:34 -04:00
|
|
|
#include "LDAPReferralException.h"
|
2000-09-01 14:46:32 -04:00
|
|
|
|
2000-10-03 14:25:34 -04:00
|
|
|
#include "LDAPAsynConnection.h"
|
|
|
|
|
|
2001-09-28 12:39:58 -04:00
|
|
|
using namespace std;
|
|
|
|
|
|
2000-10-03 14:25:34 -04:00
|
|
|
LDAPException::LDAPException(int res_code, const string& err_string){
|
2005-04-20 08:57:51 -04:00
|
|
|
m_res_code=res_code;
|
|
|
|
|
m_res_string=string(ldap_err2string(res_code));
|
2000-10-03 14:25:34 -04:00
|
|
|
m_err_string=err_string;
|
2000-09-01 14:46:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LDAPException::LDAPException(const LDAPAsynConnection *lc){
|
2005-10-05 13:26:27 -04:00
|
|
|
LDAP *l = lc->getSessionHandle();
|
|
|
|
|
ldap_get_option(l,LDAP_OPT_ERROR_NUMBER,&m_res_code);
|
|
|
|
|
const char *res_cstring = ldap_err2string(m_res_code);
|
|
|
|
|
if ( res_cstring ) {
|
|
|
|
|
m_res_string = string(res_cstring);
|
|
|
|
|
} else {
|
|
|
|
|
m_res_string = "";
|
|
|
|
|
}
|
|
|
|
|
const char* err_string;
|
|
|
|
|
ldap_get_option(l,LDAP_OPT_ERROR_STRING,&err_string);
|
|
|
|
|
if ( err_string ) {
|
|
|
|
|
m_res_string = string(err_string);
|
|
|
|
|
} else {
|
|
|
|
|
m_res_string = "";
|
|
|
|
|
}
|
2000-10-03 14:25:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LDAPException::~LDAPException(){
|
2000-09-01 14:46:32 -04:00
|
|
|
}
|
|
|
|
|
|
2000-10-03 14:25:34 -04:00
|
|
|
int LDAPException::getResultCode() const{
|
2005-04-20 08:57:51 -04:00
|
|
|
return m_res_code;
|
2000-09-01 14:46:32 -04:00
|
|
|
}
|
|
|
|
|
|
2000-10-03 14:25:34 -04:00
|
|
|
const string& LDAPException::getResultMsg() const{
|
2005-04-20 08:57:51 -04:00
|
|
|
return m_res_string;
|
2000-09-01 14:46:32 -04:00
|
|
|
}
|
|
|
|
|
|
2001-02-19 06:34:28 -05:00
|
|
|
const string& LDAPException::getServerMsg() const{
|
|
|
|
|
return m_err_string;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-01 14:46:32 -04:00
|
|
|
ostream& operator << (ostream& s, LDAPException e){
|
|
|
|
|
s << "Error " << e.m_res_code << ": " << e.m_res_string;
|
2001-09-07 13:43:55 -04:00
|
|
|
if (!e.m_err_string.empty()) {
|
2000-09-01 14:46:32 -04:00
|
|
|
s << endl << "additional info: " << e.m_err_string ;
|
|
|
|
|
}
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|