X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=contrib%2Fldapc%2B%2B%2Fsrc%2FLDAPException.cpp;h=011d522b7a3f6b5c4de3285408d94565e98f4443;hb=4d0d12db27b3b44cc36acc089b0e640320480fe7;hp=46fd2faba489c80c75fdf7d2f23fcb41d878d38d;hpb=69e3a58b2bf22c3d9bf2f1a8f8354902f14f3066;p=openldap diff --git a/contrib/ldapc++/src/LDAPException.cpp b/contrib/ldapc++/src/LDAPException.cpp index 46fd2faba4..011d522b7a 100644 --- a/contrib/ldapc++/src/LDAPException.cpp +++ b/contrib/ldapc++/src/LDAPException.cpp @@ -1,26 +1,29 @@ +// $OpenLDAP$ /* - * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. + * Copyright 2000-2012 The OpenLDAP Foundation, All Rights Reserved. * COPYING RESTRICTIONS APPLY, see COPYRIGHT file */ - - #include #include "config.h" #include "LDAPException.h" -#include "LDAPReferralException.h" #include "LDAPAsynConnection.h" +#include "LDAPResult.h" using namespace std; -LDAPException::LDAPException(int res_code, const string& err_string){ +LDAPException::LDAPException(int res_code, const string& err_string) throw() + : std::runtime_error(err_string) +{ m_res_code=res_code; m_res_string=string(ldap_err2string(res_code)); m_err_string=err_string; } -LDAPException::LDAPException(const LDAPAsynConnection *lc){ +LDAPException::LDAPException(const LDAPAsynConnection *lc) throw() + : std::runtime_error("") +{ LDAP *l = lc->getSessionHandle(); ldap_get_option(l,LDAP_OPT_RESULT_CODE,&m_res_code); const char *res_cstring = ldap_err2string(m_res_code); @@ -30,7 +33,12 @@ LDAPException::LDAPException(const LDAPAsynConnection *lc){ m_res_string = ""; } const char* err_string; - ldap_get_option(l,LDAP_OPT_DIAGNOSTIC_MESSAGE,&err_string); + +#ifdef LDAP_OPT_DIAGNOSTIC_MESSAGE + ldap_get_option(l,LDAP_OPT_DIAGNOSTIC_MESSAGE ,&err_string); +#else + ldap_get_option(l,LDAP_OPT_ERROR_STRING,&err_string); +#endif if ( err_string ) { m_err_string = string(err_string); } else { @@ -38,22 +46,32 @@ LDAPException::LDAPException(const LDAPAsynConnection *lc){ } } -LDAPException::~LDAPException(){ +LDAPException::~LDAPException() throw() +{ } -int LDAPException::getResultCode() const{ +int LDAPException::getResultCode() const throw() +{ return m_res_code; } -const string& LDAPException::getResultMsg() const{ +const string& LDAPException::getResultMsg() const throw() +{ return m_res_string; } -const string& LDAPException::getServerMsg() const{ +const string& LDAPException::getServerMsg() const throw() +{ return m_err_string; } -ostream& operator << (ostream& s, LDAPException e){ +const char* LDAPException::what() const throw() +{ + return this->m_res_string.c_str(); +} + +ostream& operator << (ostream& s, LDAPException e) throw() +{ s << "Error " << e.m_res_code << ": " << e.m_res_string; if (!e.m_err_string.empty()) { s << endl << "additional info: " << e.m_err_string ; @@ -61,3 +79,18 @@ ostream& operator << (ostream& s, LDAPException e){ return s; } + +LDAPReferralException::LDAPReferralException(const LDAPUrlList& urls) throw() + : LDAPException(LDAPResult::REFERRAL) , m_urlList(urls) +{ +} + +LDAPReferralException::~LDAPReferralException() throw() +{ +} + +const LDAPUrlList& LDAPReferralException::getUrls() throw() +{ + return m_urlList; +} +