derive LDAPException from std::exception, merged ReferralException into the

LDAPException files
This commit is contained in:
Ralf Haferkamp 2008-03-20 15:08:29 +00:00
parent 9277b5b45f
commit fee0730f26
8 changed files with 85 additions and 95 deletions

View file

@ -7,7 +7,6 @@
#include "LDAPResult.h"
#include "LDAPException.h"
#include "LDAPReferralException.h"
#include "LDAPUrlList.h"
#include "LDAPConnection.h"

View file

@ -8,19 +8,23 @@
#include <ldap.h>
#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;
}

View file

@ -9,6 +9,9 @@
#include <iostream>
#include <string>
#include <stdexcept>
#include <LDAPUrlList.h>
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

View file

@ -1,24 +0,0 @@
/*
* Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include <iostream>
#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;
}

View file

@ -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 <list>
#include <LDAPMessage.h>
#include <LDAPUrlList.h>
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

View file

@ -7,7 +7,6 @@
#include "LDAPException.h"
#include "LDAPSearchResult.h"
#include "LDAPResult.h"
#include "LDAPReferralException.h"
#include "LDAPSearchResults.h"

View file

@ -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 \

View file

@ -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@