From fee0730f2684c642bf8fc8ffb3ebffb7b94c7713 Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Thu, 20 Mar 2008 15:08:29 +0000 Subject: [PATCH] derive LDAPException from std::exception, merged ReferralException into the LDAPException files --- contrib/ldapc++/src/LDAPConnection.cpp | 1 - contrib/ldapc++/src/LDAPException.cpp | 45 +++++++++++++--- contrib/ldapc++/src/LDAPException.h | 51 ++++++++++++++++--- contrib/ldapc++/src/LDAPReferralException.cpp | 24 --------- contrib/ldapc++/src/LDAPReferralException.h | 42 --------------- contrib/ldapc++/src/LDAPSearchResults.cpp | 1 - contrib/ldapc++/src/Makefile.am | 2 - contrib/ldapc++/src/Makefile.in | 14 ++--- 8 files changed, 85 insertions(+), 95 deletions(-) delete mode 100644 contrib/ldapc++/src/LDAPReferralException.cpp delete mode 100644 contrib/ldapc++/src/LDAPReferralException.h diff --git a/contrib/ldapc++/src/LDAPConnection.cpp b/contrib/ldapc++/src/LDAPConnection.cpp index 5facda9b6f..2d5725c8c7 100644 --- a/contrib/ldapc++/src/LDAPConnection.cpp +++ b/contrib/ldapc++/src/LDAPConnection.cpp @@ -7,7 +7,6 @@ #include "LDAPResult.h" #include "LDAPException.h" -#include "LDAPReferralException.h" #include "LDAPUrlList.h" #include "LDAPConnection.h" diff --git a/contrib/ldapc++/src/LDAPException.cpp b/contrib/ldapc++/src/LDAPException.cpp index ce8ccc4873..ac679203ce 100644 --- a/contrib/ldapc++/src/LDAPException.cpp +++ b/contrib/ldapc++/src/LDAPException.cpp @@ -8,19 +8,23 @@ #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); @@ -43,22 +47,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 ; @@ -66,3 +80,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; +} + diff --git a/contrib/ldapc++/src/LDAPException.h b/contrib/ldapc++/src/LDAPException.h index 63d813dca1..3af993d79e 100644 --- a/contrib/ldapc++/src/LDAPException.h +++ b/contrib/ldapc++/src/LDAPException.h @@ -9,6 +9,9 @@ #include #include +#include + +#include class LDAPAsynConnection; @@ -16,7 +19,8 @@ class LDAPAsynConnection; * This class is only thrown as an Exception and used to signalize error * conditions during LDAP-operations */ -class LDAPException{ +class LDAPException : public std::runtime_error +{ public : /** @@ -26,7 +30,7 @@ class LDAPException{ * that happend (optional) */ LDAPException(int res_code, - const std::string& err_string=std::string()); + const std::string& err_string=std::string()) throw(); /** * Constructs a LDAPException-object from the error state of a @@ -34,38 +38,69 @@ class LDAPException{ * @param lc A LDAP-Connection for that an error has happend. The * Constructor tries to read its error state. */ - LDAPException(const LDAPAsynConnection *lc); + LDAPException(const LDAPAsynConnection *lc) throw(); /** * Destructor */ - virtual ~LDAPException(); + virtual ~LDAPException() throw(); /** * @return The Result code of the object */ - int getResultCode() const; + int getResultCode() const throw(); /** * @return The error message that is corresponding to the result * code . */ - const std::string& getResultMsg() const; + const std::string& getResultMsg() const throw(); /** * @return The addional error message of the error (if it was set) */ - const std::string& getServerMsg() const; + const std::string& getServerMsg() const throw(); + + + virtual const char* what() const throw(); /** * This method can be used to dump the data of a LDAPResult-Object. * It is only useful for debugging purposes at the moment */ - friend std::ostream& operator << (std::ostream &s, LDAPException e); + friend std::ostream& operator << (std::ostream &s, LDAPException e) throw(); private : int m_res_code; std::string m_res_string; std::string m_err_string; }; + +/** + * This class extends LDAPException and is used to signalize Referrals + * there were received during synchronous LDAP-operations + */ +class LDAPReferralException : public LDAPException +{ + + public : + /** + * Creates an object that is initialized with a list of URLs + */ + LDAPReferralException(const LDAPUrlList& urls) throw(); + + /** + * Destructor + */ + ~LDAPReferralException() throw(); + + /** + * @return The List of URLs of the Referral/Search Reference + */ + const LDAPUrlList& getUrls() throw(); + + private : + LDAPUrlList m_urlList; +}; + #endif //LDAP_EXCEPTION_H diff --git a/contrib/ldapc++/src/LDAPReferralException.cpp b/contrib/ldapc++/src/LDAPReferralException.cpp deleted file mode 100644 index 0d050885d6..0000000000 --- a/contrib/ldapc++/src/LDAPReferralException.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file - */ - - -#include -#include "LDAPException.h" -#include "LDAPReferralException.h" -#include "LDAPResult.h" -#include "LDAPRequest.h" -#include "LDAPUrl.h" - -LDAPReferralException::LDAPReferralException(const LDAPUrlList& urls) : - LDAPException(LDAPResult::REFERRAL) , m_urlList(urls){ -} - -LDAPReferralException::~LDAPReferralException(){ -} - -const LDAPUrlList& LDAPReferralException::getUrls(){ - return m_urlList; -} - diff --git a/contrib/ldapc++/src/LDAPReferralException.h b/contrib/ldapc++/src/LDAPReferralException.h deleted file mode 100644 index f604f67adc..0000000000 --- a/contrib/ldapc++/src/LDAPReferralException.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file - */ - - -#ifndef LDAP_REFERRAL_EXCEPTION_H -#define LDAP_REFERRAL_EXCEPTION_H - -#include -#include -#include - -class LDAPUrlList; - -/** - * This class extends LDAPException and is used to signalize Referrals - * there were received during synchronous LDAP-operations - */ -class LDAPReferralException : public LDAPException{ - - public : - /** - * Creates an object that is initialized with a list of URLs - */ - LDAPReferralException(const LDAPUrlList& urls); - - /** - * Destructor - */ - ~LDAPReferralException(); - - /** - * @return The List of URLs of the Referral/Search Reference - */ - const LDAPUrlList& getUrls(); - - private : - LDAPUrlList m_urlList; -}; - -#endif //LDAP_REFERRAL_EXCEPTION_H diff --git a/contrib/ldapc++/src/LDAPSearchResults.cpp b/contrib/ldapc++/src/LDAPSearchResults.cpp index 88a68989e3..3fef3dcaea 100644 --- a/contrib/ldapc++/src/LDAPSearchResults.cpp +++ b/contrib/ldapc++/src/LDAPSearchResults.cpp @@ -7,7 +7,6 @@ #include "LDAPException.h" #include "LDAPSearchResult.h" #include "LDAPResult.h" -#include "LDAPReferralException.h" #include "LDAPSearchResults.h" diff --git a/contrib/ldapc++/src/Makefile.am b/contrib/ldapc++/src/Makefile.am index 1e5cf8eebd..9e276d647a 100644 --- a/contrib/ldapc++/src/Makefile.am +++ b/contrib/ldapc++/src/Makefile.am @@ -31,7 +31,6 @@ libldapcpp_la_SOURCES = LDAPAddRequest.cpp \ LDAPObjClass.cpp \ LDAPRebind.cpp \ LDAPRebindAuth.cpp \ - LDAPReferralException.cpp \ LDAPReferenceList.cpp \ LDAPRequest.cpp \ LDAPResult.cpp \ @@ -66,7 +65,6 @@ include_HEADERS = LDAPAsynConnection.h \ LDAPObjClass.h \ LDAPRebind.h \ LDAPRebindAuth.h \ - LDAPReferralException.h \ LDAPReferenceList.h \ LDAPResult.h \ LDAPSaslBindResult.h \ diff --git a/contrib/ldapc++/src/Makefile.in b/contrib/ldapc++/src/Makefile.in index db1433d41a..c08542d99c 100644 --- a/contrib/ldapc++/src/Makefile.in +++ b/contrib/ldapc++/src/Makefile.in @@ -66,12 +66,11 @@ am_libldapcpp_la_OBJECTS = LDAPAddRequest.lo LDAPAsynConnection.lo \ LDAPMessage.lo LDAPMessageQueue.lo LDAPModDNRequest.lo \ LDAPModification.lo LDAPModifyRequest.lo LDAPModList.lo \ LDAPObjClass.lo LDAPRebind.lo LDAPRebindAuth.lo \ - LDAPReferralException.lo LDAPReferenceList.lo LDAPRequest.lo \ - LDAPResult.lo LDAPSaslBindResult.lo LDAPSchema.lo \ - LDAPSearchReference.lo LDAPSearchRequest.lo \ - LDAPSearchResult.lo LDAPSearchResults.lo LDAPUrl.lo \ - LDAPUrlList.lo SaslInteraction.lo SaslInteractionHandler.lo \ - StringList.lo + LDAPReferenceList.lo LDAPRequest.lo LDAPResult.lo \ + LDAPSaslBindResult.lo LDAPSchema.lo LDAPSearchReference.lo \ + LDAPSearchRequest.lo LDAPSearchResult.lo LDAPSearchResults.lo \ + LDAPUrl.lo LDAPUrlList.lo SaslInteraction.lo \ + SaslInteractionHandler.lo StringList.lo libldapcpp_la_OBJECTS = $(am_libldapcpp_la_OBJECTS) libldapcpp_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ @@ -228,7 +227,6 @@ libldapcpp_la_SOURCES = LDAPAddRequest.cpp \ LDAPObjClass.cpp \ LDAPRebind.cpp \ LDAPRebindAuth.cpp \ - LDAPReferralException.cpp \ LDAPReferenceList.cpp \ LDAPRequest.cpp \ LDAPResult.cpp \ @@ -263,7 +261,6 @@ include_HEADERS = LDAPAsynConnection.h \ LDAPObjClass.h \ LDAPRebind.h \ LDAPRebindAuth.h \ - LDAPReferralException.h \ LDAPReferenceList.h \ LDAPResult.h \ LDAPSaslBindResult.h \ @@ -403,7 +400,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LDAPRebind.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LDAPRebindAuth.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LDAPReferenceList.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LDAPReferralException.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LDAPRequest.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LDAPResult.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LDAPSaslBindResult.Plo@am__quote@ -- 2.39.5