From 1ab5360fee85bbe0f9735813e89852ed6a832439 Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Tue, 3 Oct 2000 18:50:44 +0000 Subject: [PATCH] - some new Classes for sync. LDAP operations - Classes for handling Controls --- contrib/ldapc++/src/LDAPConnection.cpp | 293 ++++++++++++++++++ contrib/ldapc++/src/LDAPConnection.h | 47 +++ contrib/ldapc++/src/LDAPControlSet.cpp | 67 ++++ contrib/ldapc++/src/LDAPControlSet.h | 35 +++ contrib/ldapc++/src/LDAPEntryList.cpp | 35 +++ contrib/ldapc++/src/LDAPEntryList.h | 30 ++ contrib/ldapc++/src/LDAPExtResult.cpp | 46 +++ contrib/ldapc++/src/LDAPExtResult.h | 27 ++ contrib/ldapc++/src/LDAPRebind.cpp | 8 + contrib/ldapc++/src/LDAPRebind.h | 26 ++ contrib/ldapc++/src/LDAPRebindAuth.cpp | 37 +++ contrib/ldapc++/src/LDAPRebindAuth.h | 26 ++ contrib/ldapc++/src/LDAPReferenceList.cpp | 35 +++ contrib/ldapc++/src/LDAPReferenceList.h | 32 ++ contrib/ldapc++/src/LDAPReferralException.cpp | 24 ++ contrib/ldapc++/src/LDAPReferralException.h | 27 ++ contrib/ldapc++/src/LDAPSearchResults.cpp | 60 ++++ contrib/ldapc++/src/LDAPSearchResults.h | 31 ++ contrib/ldapc++/src/StringList.cpp | 69 +++++ contrib/ldapc++/src/StringList.h | 32 ++ 20 files changed, 987 insertions(+) create mode 100644 contrib/ldapc++/src/LDAPConnection.cpp create mode 100644 contrib/ldapc++/src/LDAPConnection.h create mode 100644 contrib/ldapc++/src/LDAPControlSet.cpp create mode 100644 contrib/ldapc++/src/LDAPControlSet.h create mode 100644 contrib/ldapc++/src/LDAPEntryList.cpp create mode 100644 contrib/ldapc++/src/LDAPEntryList.h create mode 100644 contrib/ldapc++/src/LDAPExtResult.cpp create mode 100644 contrib/ldapc++/src/LDAPExtResult.h create mode 100644 contrib/ldapc++/src/LDAPRebind.cpp create mode 100644 contrib/ldapc++/src/LDAPRebind.h create mode 100644 contrib/ldapc++/src/LDAPRebindAuth.cpp create mode 100644 contrib/ldapc++/src/LDAPRebindAuth.h create mode 100644 contrib/ldapc++/src/LDAPReferenceList.cpp create mode 100644 contrib/ldapc++/src/LDAPReferenceList.h create mode 100644 contrib/ldapc++/src/LDAPReferralException.cpp create mode 100644 contrib/ldapc++/src/LDAPReferralException.h create mode 100644 contrib/ldapc++/src/LDAPSearchResults.cpp create mode 100644 contrib/ldapc++/src/LDAPSearchResults.h create mode 100644 contrib/ldapc++/src/StringList.cpp create mode 100644 contrib/ldapc++/src/StringList.h diff --git a/contrib/ldapc++/src/LDAPConnection.cpp b/contrib/ldapc++/src/LDAPConnection.cpp new file mode 100644 index 0000000000..5c1d9c78a4 --- /dev/null +++ b/contrib/ldapc++/src/LDAPConnection.cpp @@ -0,0 +1,293 @@ +/* + * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#include "debug.h" + +#include "LDAPResult.h" +#include "LDAPException.h" +#include "LDAPReferralException.h" +#include "LDAPUrlList.h" + +#include "LDAPConnection.h" +const int LDAPConnection::SEARCH_BASE = LDAPAsynConnection::SEARCH_BASE; +const int LDAPConnection::SEARCH_ONE = LDAPAsynConnection::SEARCH_ONE; +const int LDAPConnection::SEARCH_SUB = LDAPAsynConnection::SEARCH_SUB; + +LDAPConnection::LDAPConnection(const string& hostname, int port, + LDAPConstraints* cons) : + LDAPAsynConnection(hostname, port, cons){ +} + +LDAPConnection::~LDAPConnection(){ +} + +void LDAPConnection::bind(const string& dn, const string& passwd, + LDAPConstraints* cons){ + DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::bind" << endl); + LDAPMessageQueue* msg=0; + LDAPResult* res=0; + try{ + msg = LDAPAsynConnection::bind(dn,passwd,cons); + res = (LDAPResult*)msg->getNext(); + }catch(LDAPException e){ + delete msg; + delete res; + throw; + } + int resCode=res->getResultCode(); + if(resCode != LDAPResult::SUCCESS) { + if(resCode == LDAPResult::REFERRAL){ + LDAPUrlList urls = res->getReferralUrls(); + delete res; + delete msg; + throw LDAPReferralException(urls); + }else{ + delete res; + delete msg; + throw LDAPException(resCode); + } + } + delete res; +} + +void LDAPConnection::unbind(){ + LDAPAsynConnection::unbind(); +} + +bool LDAPConnection::compare(const string& dn, const LDAPAttribute& attr, + LDAPConstraints* cons){ + DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::compare" << endl); + LDAPMessageQueue* msg=0; + LDAPResult* res=0; + try{ + msg = LDAPAsynConnection::compare(dn,attr,cons); + res = (LDAPResult*)msg->getNext(); + }catch(LDAPException e){ + delete msg; + delete res; + throw; + } + int resCode=res->getResultCode(); + switch (resCode){ + case LDAPResult::COMPARE_TRUE : + delete res; + delete msg; + return true; + break; + case LDAPResult::COMPARE_FALSE : + delete res; + delete msg; + return false; + break; + case LDAPResult::REFERRAL : + { + LDAPUrlList urls = res->getReferralUrls(); + delete res; + delete msg; + throw LDAPReferralException(urls); + } + break; + default : + delete res; + delete msg; + throw LDAPException(resCode); + } +} + +void LDAPConnection::del(const string& dn, const LDAPConstraints* cons){ + DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::del" << endl); + LDAPMessageQueue* msg=0; + LDAPResult* res=0; + try{ + msg = LDAPAsynConnection::del(dn,cons); + res = (LDAPResult*)msg->getNext(); + }catch(LDAPException e){ + delete msg; + delete res; + throw; + } + int resCode=res->getResultCode(); + switch (resCode){ + case LDAPResult::SUCCESS : + delete res; + delete msg; + break; + case LDAPResult::REFERRAL : + { + LDAPUrlList urls = res->getReferralUrls(); + delete res; + delete msg; + throw LDAPReferralException(urls); + } + break; + default : + delete res; + delete msg; + throw LDAPException(resCode); + } + +} + +void LDAPConnection::add(const LDAPEntry* le, const LDAPConstraints* cons=0){ + DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::add" << endl); + LDAPMessageQueue* msg=0; + LDAPResult* res=0; + try{ + msg = LDAPAsynConnection::add(le,cons); + res = (LDAPResult*)msg->getNext(); + }catch(LDAPException e){ + delete msg; + delete res; + throw; + } + int resCode=res->getResultCode(); + switch (resCode){ + case LDAPResult::SUCCESS : + delete res; + delete msg; + break; + case LDAPResult::REFERRAL : + { + LDAPUrlList urls = res->getReferralUrls(); + delete res; + delete msg; + throw LDAPReferralException(urls); + } + break; + default : + delete res; + delete msg; + throw LDAPException(resCode); + } +} + +void LDAPConnection::modify(const string& dn, const LDAPModList* mods, + const LDAPConstraints* cons){ + DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::modify" << endl); + LDAPMessageQueue* msg=0; + LDAPResult* res=0; + try{ + msg = LDAPAsynConnection::modify(dn,mods,cons); + res = (LDAPResult*)msg->getNext(); + }catch(LDAPException e){ + delete msg; + delete res; + throw; + } + int resCode=res->getResultCode(); + switch (resCode){ + case LDAPResult::SUCCESS : + delete res; + delete msg; + break; + case LDAPResult::REFERRAL : + { + LDAPUrlList urls = res->getReferralUrls(); + delete res; + delete msg; + throw LDAPReferralException(urls); + } + break; + default : + delete res; + delete msg; + throw LDAPException(resCode); + } + +} + +void LDAPConnection::rename(const string& dn, const string& newRDN, + bool delOldRDN, const string& newParentDN, + const LDAPConstraints* cons=0){ + DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::rename" << endl); + LDAPMessageQueue* msg=0; + LDAPResult* res=0; + try{ + msg = LDAPAsynConnection::rename(dn,newRDN,delOldRDN, newParentDN, + cons); + res = (LDAPResult*)msg->getNext(); + }catch(LDAPException e){ + delete msg; + delete res; + throw; + } + int resCode=res->getResultCode(); + switch (resCode){ + case LDAPResult::SUCCESS : + delete res; + delete msg; + break; + case LDAPResult::REFERRAL : + { + LDAPUrlList urls = res->getReferralUrls(); + delete res; + delete msg; + throw LDAPReferralException(urls); + } + break; + default : + delete res; + delete msg; + throw LDAPException(resCode); + } +} + +LDAPSearchResults* LDAPConnection::search(const string& base, int scope, + const string& filter, const StringList& attrs, bool attrsOnly, + const LDAPConstraints* cons){ + DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::search" << endl); + LDAPMessageQueue* msgq=0; + LDAPResult* res=0; + LDAPSearchResults* results= 0; + + try{ + msgq = LDAPAsynConnection::search(base,scope, filter, attrs, attrsOnly, + cons); + results = new LDAPSearchResults(); + res = results->readMessageQueue(msgq); + }catch(LDAPException e){ + delete msgq; + throw; + } + if(res != 0){ + int resCode=res->getResultCode(); + switch (resCode){ + case LDAPResult::SUCCESS : + delete res; + delete msgq; + return results; + break; + case LDAPResult::REFERRAL : + { + LDAPUrlList urls = res->getReferralUrls(); + delete res; + delete msgq; + throw LDAPReferralException(urls); + } + break; + default : + delete res; + delete msgq; + throw LDAPException(resCode); + } + } + return 0; +} + +const string& LDAPConnection::getHost() const{ + return LDAPAsynConnection::getHost(); +} + +int LDAPConnection::getPort() const{ + return LDAPAsynConnection::getPort(); +} + +void LDAPConnection::setConstraints(LDAPConstraints* cons){ + LDAPAsynConnection::setConstraints(cons); +} + +const LDAPConstraints* LDAPConnection::getConstraints() const{ + return LDAPAsynConnection::getConstraints(); +} diff --git a/contrib/ldapc++/src/LDAPConnection.h b/contrib/ldapc++/src/LDAPConnection.h new file mode 100644 index 0000000000..11fd746d53 --- /dev/null +++ b/contrib/ldapc++/src/LDAPConnection.h @@ -0,0 +1,47 @@ +/* + * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#ifndef LDAP_CONNECTION_H +#define LDAP_CONNECTION_H + +#include "LDAPSearchResults.h" + +#include "LDAPAsynConnection.h" + +class LDAPConnection : private LDAPAsynConnection { + + public : + static const int SEARCH_BASE; + static const int SEARCH_ONE; + static const int SEARCH_SUB; + LDAPConnection(const string& hostname="localhost", int port=389, + LDAPConstraints* cons=0); + ~LDAPConnection(); + + void init(const string& hostname, int port); + void bind(const string& dn="", const string& passwd="", + LDAPConstraints* cons=0); + void unbind(); + bool compare(const string&, const LDAPAttribute& attr, + LDAPConstraints* cons=0); + void del(const string& dn, const LDAPConstraints* cons=0); + void add(const LDAPEntry* le, const LDAPConstraints* cons=0); + void modify(const string& dn, const LDAPModList* mods, + const LDAPConstraints* cons=0); + void rename(const string& dn, const string& newRDN, + bool delOldRDN=false, const string& newParentDN="", + const LDAPConstraints* cons=0); + LDAPSearchResults* search(const string& base, int scope=0, + const string& filter="objectClass=*", + const StringList& attrs=StringList(), bool attrsOnly=false, + const LDAPConstraints* cons=0); + + const string& getHost() const; + int getPort() const; + void setConstraints(LDAPConstraints *cons); + const LDAPConstraints* getConstraints() const ; +}; + +#endif //LDAP_CONNECTION_H diff --git a/contrib/ldapc++/src/LDAPControlSet.cpp b/contrib/ldapc++/src/LDAPControlSet.cpp new file mode 100644 index 0000000000..08cdddc938 --- /dev/null +++ b/contrib/ldapc++/src/LDAPControlSet.cpp @@ -0,0 +1,67 @@ +/* + * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#include "debug.h" +#include "LDAPControlSet.h" + +LDAPControlSet::LDAPControlSet(){ +} + +LDAPControlSet::LDAPControlSet(const LDAPControlSet& cs){ + DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPControlSet::LDAPControlSet(&)" << endl); + data=cs.data; +} + +LDAPControlSet::LDAPControlSet(LDAPControl** controls){ + DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPControlSet::LDAPControlSet()" << endl); + if(controls != 0){ + LDAPControl** i; + for( i=controls; *i!=0;i++) { + add(LDAPCtrl(*i)); + } + } +} + +LDAPControlSet::~LDAPControlSet(){ + DEBUG(LDAP_DEBUG_DESTROY,"LDAPControlSet::~LDAPControlSet()" << endl); +} + +size_t LDAPControlSet::size() const { + DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::size()" << endl); + return data.size(); +} + +LDAPControlSet::const_iterator LDAPControlSet::begin() const{ + DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::begin()" << endl); + return data.begin(); +} + + +LDAPControlSet::const_iterator LDAPControlSet::end() const{ + DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::end()" << endl); + return data.end (); +} + +void LDAPControlSet::add(const LDAPCtrl& ctrl){ + DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::add()" << endl); + data.push_back(ctrl); +} + +LDAPControl** LDAPControlSet::toLDAPControlArray() const{ + DEBUG(LDAP_DEBUG_TRACE, "LDAPControlSet::toLDAPControlArray()" << endl); + if(data.size() == 0){ + return 0; + }else{ + LDAPControl** ret= new LDAPControl*[data.size()+1]; + CtrlList::const_iterator i; + int j=0; + for(i=data.begin(); i!=data.end(); i++,j++){ + ret[j] = i->getControlStruct(); + } + ret[data.size()]=0; + return ret; + } +} + diff --git a/contrib/ldapc++/src/LDAPControlSet.h b/contrib/ldapc++/src/LDAPControlSet.h new file mode 100644 index 0000000000..b3e107537d --- /dev/null +++ b/contrib/ldapc++/src/LDAPControlSet.h @@ -0,0 +1,35 @@ +/* + * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#ifndef LDAP_CONTROL_SET_H +#define LDAP_CONTROL_SET_H + +#include +#include +#include "LDAPControl.h" + +typedef list CtrlList; + + +class LDAPControlSet { + typedef CtrlList::const_iterator const_iterator; + public : + LDAPControlSet(); + LDAPControlSet(const LDAPControlSet& cs); + //!for internal use only + //untested til now. Due to lack of server that return Controls + LDAPControlSet(LDAPControl** controls); + ~LDAPControlSet(); + size_t size() const ; + const_iterator begin() const; + const_iterator end() const; + void add(const LDAPCtrl& ctrl); + + LDAPControl** toLDAPControlArray()const ; + + private : + CtrlList data; +} ; +#endif //LDAP_CONTROL_SET_H diff --git a/contrib/ldapc++/src/LDAPEntryList.cpp b/contrib/ldapc++/src/LDAPEntryList.cpp new file mode 100644 index 0000000000..7cf8aa23a7 --- /dev/null +++ b/contrib/ldapc++/src/LDAPEntryList.cpp @@ -0,0 +1,35 @@ +/* + * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + + +#include "LDAPEntryList.h" +#include "LDAPEntry.h" + +LDAPEntryList::LDAPEntryList(){ +} + +LDAPEntryList::LDAPEntryList(const LDAPEntryList& e){ + m_entries = e.m_entries; +} + +LDAPEntryList::~LDAPEntryList(){ +} + +size_t LDAPEntryList::size() const{ + return m_entries.size(); +} + +LDAPEntryList::const_iterator LDAPEntryList::begin() const{ + return m_entries.begin(); +} + +LDAPEntryList::const_iterator LDAPEntryList::end() const{ + return m_entries.end(); +} + +void LDAPEntryList::addEntry(const LDAPEntry& e){ + m_entries.push_back(e); +} + diff --git a/contrib/ldapc++/src/LDAPEntryList.h b/contrib/ldapc++/src/LDAPEntryList.h new file mode 100644 index 0000000000..b75aed8bca --- /dev/null +++ b/contrib/ldapc++/src/LDAPEntryList.h @@ -0,0 +1,30 @@ +/* + * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#ifndef LDAP_ENTRY_LIST_H +#define LDAP_ENTRY_LIST_H + +#include + +class LDAPEntry; + +typedef list EntryList; +class LDAPEntryList{ + typedef EntryList::const_iterator const_iterator; + + private: + EntryList m_entries; + + public: + LDAPEntryList(const LDAPEntryList& el); + LDAPEntryList(); + ~LDAPEntryList(); + + size_t size() const; + const_iterator begin() const; + const_iterator end() const; + void addEntry(const LDAPEntry& e); +}; +#endif // LDAP_ENTRY_LIST_H diff --git a/contrib/ldapc++/src/LDAPExtResult.cpp b/contrib/ldapc++/src/LDAPExtResult.cpp new file mode 100644 index 0000000000..ef5361c574 --- /dev/null +++ b/contrib/ldapc++/src/LDAPExtResult.cpp @@ -0,0 +1,46 @@ +/* + * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#include "debug.h" +#include +#include "LDAPRequest.h" +#include "LDAPException.h" + +#include "LDAPResult.h" +#include "LDAPExtResult.h" + +LDAPExtResult::LDAPExtResult(const LDAPRequest* req, LDAPMessage* msg) : + LDAPResult(req, msg){ + DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPExtResult::LDAPExtResult()" << endl); + char* oid = 0; + BerValue* data = 0; + LDAP* lc = req->getConnection()->getSessionHandle(); + int err=ldap_parse_extended_result(lc, msg, &oid, &data, 0); + if(err != LDAP_SUCCESS){ + ber_bvfree(data); + ldap_memfree(oid); + throw LDAPException(err); + }else{ + m_oid=string(oid); + ldap_memfree(oid); + if(data){ + m_data=string(data->bv_val, data->bv_len); + ber_bvfree(data); + } + } +} + +LDAPExtResult::~LDAPExtResult(){ + DEBUG(LDAP_DEBUG_DESTROY,"LDAPExtResult::~LDAPExtResult()" << endl); +} + +const string& LDAPExtResult::getResponseOid() const{ + return m_oid; +} + +const string& LDAPExtResult::getResponse() const{ + return m_data; +} + diff --git a/contrib/ldapc++/src/LDAPExtResult.h b/contrib/ldapc++/src/LDAPExtResult.h new file mode 100644 index 0000000000..1f7aeb63a0 --- /dev/null +++ b/contrib/ldapc++/src/LDAPExtResult.h @@ -0,0 +1,27 @@ +/* + * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#ifndef LDAP_EXT_RESULT_H +#define LDAP_EXT_RESULT_H + +#include + +class LDAPResult; +class LDAPRequest; + +class LDAPExtResult : public LDAPResult { + public : + LDAPExtResult(const LDAPRequest* req, LDAPMessage* msg); + virtual ~LDAPExtResult(); + + const string& getResponseOid() const; + const string& getResponse() const; + + private: + string m_oid; + string m_data; +}; + +#endif // LDAP_EXT_RESULT_H diff --git a/contrib/ldapc++/src/LDAPRebind.cpp b/contrib/ldapc++/src/LDAPRebind.cpp new file mode 100644 index 0000000000..570c7db7bf --- /dev/null +++ b/contrib/ldapc++/src/LDAPRebind.cpp @@ -0,0 +1,8 @@ +/* + * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#include "LDAPRebind.h" + + diff --git a/contrib/ldapc++/src/LDAPRebind.h b/contrib/ldapc++/src/LDAPRebind.h new file mode 100644 index 0000000000..7fa553a3ea --- /dev/null +++ b/contrib/ldapc++/src/LDAPRebind.h @@ -0,0 +1,26 @@ +/* + * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#ifndef LDAP_REBIND_H +#define LDAP_REBIND_H + +#include +#include "LDAPRebindAuth.h" + +/** + * Just an abstract class to provide a mechnism for rebind to another + * server when chasing referrals. Clients have to implement a class + * derived from this. To use authentication other than anonymous for + * referral chasing + */ + +class LDAPRebind{ + public: + virtual ~LDAPRebind() {} + virtual LDAPRebindAuth* getRebindAuth(const string& hostname, + int port) const = 0; +}; +#endif //LDAP_REBIND_H + diff --git a/contrib/ldapc++/src/LDAPRebindAuth.cpp b/contrib/ldapc++/src/LDAPRebindAuth.cpp new file mode 100644 index 0000000000..db7e5147fc --- /dev/null +++ b/contrib/ldapc++/src/LDAPRebindAuth.cpp @@ -0,0 +1,37 @@ +/* + * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#include + +#include "LDAPRebindAuth.h" +#include "debug.h" + +LDAPRebindAuth::LDAPRebindAuth(const string& dn, const string& pwd){ + DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPRebindAuth::LDAPRebindAuth()" << endl); + DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER," dn:" << dn << endl + << " pwd:" << pwd << endl); + m_dn=dn; + m_password=pwd; +} + +LDAPRebindAuth::LDAPRebindAuth(const LDAPRebindAuth& lra){ + DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPRebindAuth::LDAPRebindAuth(&)" << endl); + m_dn=lra.m_dn; + m_password=lra.m_password; +} + +LDAPRebindAuth::~LDAPRebindAuth(){ + DEBUG(LDAP_DEBUG_DESTROY,"LDAPRebindAuth::~LDAPRebindAuth()" << endl); +} + +const string& LDAPRebindAuth::getDN() const{ + DEBUG(LDAP_DEBUG_TRACE,"LDAPRebindAuth::getDN()" << endl); + return m_dn; +} + +const string& LDAPRebindAuth::getPassword() const{ + DEBUG(LDAP_DEBUG_TRACE,"LDAPRebindAuth::getPassword()" << endl); + return m_password; +} diff --git a/contrib/ldapc++/src/LDAPRebindAuth.h b/contrib/ldapc++/src/LDAPRebindAuth.h new file mode 100644 index 0000000000..c0441b90d5 --- /dev/null +++ b/contrib/ldapc++/src/LDAPRebindAuth.h @@ -0,0 +1,26 @@ +/* + * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#ifndef LDAP_REBIND_AUTH_H +#define LDAP_REBIND_AUTH_H + +#include + +class LDAPRebindAuth{ + public: + LDAPRebindAuth(const string& dn="", const string& pwd=""); + LDAPRebindAuth(const LDAPRebindAuth& lra); + virtual ~LDAPRebindAuth(); + + const string& getDN() const; + const string& getPassword() const; + + private: + string m_dn; + string m_password; +}; + +#endif //LDAP_REBIND_AUTH_H + diff --git a/contrib/ldapc++/src/LDAPReferenceList.cpp b/contrib/ldapc++/src/LDAPReferenceList.cpp new file mode 100644 index 0000000000..572c96a45d --- /dev/null +++ b/contrib/ldapc++/src/LDAPReferenceList.cpp @@ -0,0 +1,35 @@ +/* + * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + + +#include "LDAPReferenceList.h" +#include "LDAPSearchReference.h" + +LDAPReferenceList::LDAPReferenceList(){ +} + +LDAPReferenceList::LDAPReferenceList(const LDAPReferenceList& e){ + m_refs = e.m_refs; +} + +LDAPReferenceList::~LDAPReferenceList(){ +} + +size_t LDAPReferenceList::size() const{ + return m_refs.size(); +} + +LDAPReferenceList::const_iterator LDAPReferenceList::begin() const{ + return m_refs.begin(); +} + +LDAPReferenceList::const_iterator LDAPReferenceList::end() const{ + return m_refs.end(); +} + +void LDAPReferenceList::addReference(const LDAPSearchReference& e){ + m_refs.push_back(e); +} + diff --git a/contrib/ldapc++/src/LDAPReferenceList.h b/contrib/ldapc++/src/LDAPReferenceList.h new file mode 100644 index 0000000000..12b3419ea6 --- /dev/null +++ b/contrib/ldapc++/src/LDAPReferenceList.h @@ -0,0 +1,32 @@ +/* + * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#ifndef LDAP_REFERENCE_LIST_H +#define LDAP_REFERENCE_LIST_H + +#include + +class LDAPSearchReference; + +typedef list RefList; + +class LDAPReferenceList{ + typedef RefList::const_iterator const_iterator; + + public: + LDAPReferenceList(); + LDAPReferenceList(const LDAPReferenceList& rl); + ~LDAPReferenceList(); + + size_t size() const; + const_iterator begin() const; + const_iterator end() const; + void addReference(const LDAPSearchReference& e); + + private: + RefList m_refs; +}; +#endif // LDAP_REFERENCE_LIST_H + diff --git a/contrib/ldapc++/src/LDAPReferralException.cpp b/contrib/ldapc++/src/LDAPReferralException.cpp new file mode 100644 index 0000000000..0d050885d6 --- /dev/null +++ b/contrib/ldapc++/src/LDAPReferralException.cpp @@ -0,0 +1,24 @@ +/* + * 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 new file mode 100644 index 0000000000..1988107acd --- /dev/null +++ b/contrib/ldapc++/src/LDAPReferralException.h @@ -0,0 +1,27 @@ +/* + * 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 "LDAPMessage.h" +#include "LDAPUrlList.h" + +class LDAPUrlList; + +class LDAPReferralException : public LDAPException{ + + private : + LDAPUrlList m_urlList; + + public : + LDAPReferralException(const LDAPUrlList& urls); + ~LDAPReferralException(); + const LDAPUrlList& getUrls(); +}; + +#endif //LDAP_REFERRAL_EXCEPTION_H diff --git a/contrib/ldapc++/src/LDAPSearchResults.cpp b/contrib/ldapc++/src/LDAPSearchResults.cpp new file mode 100644 index 0000000000..88a68989e3 --- /dev/null +++ b/contrib/ldapc++/src/LDAPSearchResults.cpp @@ -0,0 +1,60 @@ +/* + * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + + +#include "LDAPException.h" +#include "LDAPSearchResult.h" +#include "LDAPResult.h" +#include "LDAPReferralException.h" + +#include "LDAPSearchResults.h" + +LDAPSearchResults::LDAPSearchResults(){ + entryPos = entryList.begin(); + refPos = refList.begin(); +} + +LDAPResult* LDAPSearchResults::readMessageQueue(LDAPMessageQueue* msg){ + if(msg != 0){ + LDAPMsg* res=0; + for(;;){ + try{ + res = msg->getNext(); + }catch (LDAPException e){ + throw; + } + switch(res->getMessageType()){ + case LDAPMsg::SEARCH_ENTRY : + entryList.addEntry(*((LDAPSearchResult*)res)->getEntry()); + break; + case LDAPMsg::SEARCH_REFERENCE : + refList.addReference(*((LDAPSearchReference*)res)); + break; + default: + entryPos=entryList.begin(); + refPos=refList.begin(); + return ((LDAPResult*) res); + } + delete res; + res=0; + } + } + return 0; +} + +LDAPEntry* LDAPSearchResults::getNext(){ + if( entryPos != entryList.end() ){ + LDAPEntry* ret= new LDAPEntry(*entryPos); + entryPos++; + return ret; + } + if( refPos != refList.end() ){ + LDAPUrlList urls= refPos->getUrls(); + refPos++; + throw(LDAPReferralException(urls)); + } + return 0; +} + diff --git a/contrib/ldapc++/src/LDAPSearchResults.h b/contrib/ldapc++/src/LDAPSearchResults.h new file mode 100644 index 0000000000..10d7b425bd --- /dev/null +++ b/contrib/ldapc++/src/LDAPSearchResults.h @@ -0,0 +1,31 @@ +/* + * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#ifndef LDAP_SEARCH_RESULTS_H +#define LDAP_SEARCH_RESULTS_H + +#include "LDAPEntry.h" +#include "LDAPEntryList.h" +#include "LDAPMessage.h" +#include "LDAPMessageQueue.h" +#include "LDAPReferenceList.h" +#include "LDAPSearchReference.h" + +class LDAPResult; + +class LDAPSearchResults{ + private : + LDAPEntryList entryList; + LDAPReferenceList refList; + LDAPEntryList::const_iterator entryPos; + LDAPReferenceList::const_iterator refPos; + public: + LDAPSearchResults(); + LDAPResult* readMessageQueue(LDAPMessageQueue* msg); + LDAPEntry* getNext(); +}; +#endif //LDAP_SEARCH_RESULTS_H + + diff --git a/contrib/ldapc++/src/StringList.cpp b/contrib/ldapc++/src/StringList.cpp new file mode 100644 index 0000000000..f77563fbb4 --- /dev/null +++ b/contrib/ldapc++/src/StringList.cpp @@ -0,0 +1,69 @@ +/* + * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#include "StringList.h" +#include "debug.h" + +StringList::StringList(){ +} + +StringList::StringList(const StringList& sl){ + m_data= ListType(sl.m_data); +} + +StringList::StringList(char** values){ + if(values == 0){ + m_data=ListType(); + }else{ + char** i; + for(i=values; *i != 0; i++){ + cerr << *i << endl; + m_data.push_back(string(*i)); + } + } +} + +StringList::~StringList(){ + DEBUG(LDAP_DEBUG_TRACE,"StringList::~StringList()" << endl); +} + +char** StringList::toCharArray() const{ + if(size() > 0){ + char** ret = new char*[size()+1]; + StringList::const_iterator i; + int j=0; + for(i=begin(); i != end(); i++,j++){ + ret[j]=new char[i->size()+1]; + i->copy(ret[j],string::npos); + ret[j][i->size()]=0; + } + ret[size()]=0; + return ret; + }else{ + return 0; + } +} + +void StringList::add(const string& value){ + m_data.push_back(value); +} + +size_t StringList::size() const{ + return m_data.size(); +} + +StringList::const_iterator StringList::begin() const{ + return m_data.begin(); +} + +StringList::const_iterator StringList::end() const{ + return m_data.end(); +} + + +void StringList::clear(){ + m_data.clear(); +} + diff --git a/contrib/ldapc++/src/StringList.h b/contrib/ldapc++/src/StringList.h new file mode 100644 index 0000000000..f51c4fdcf7 --- /dev/null +++ b/contrib/ldapc++/src/StringList.h @@ -0,0 +1,32 @@ +/* + * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#ifndef STRING_LIST_H +#define STRING_LIST_H + +#include +#include +typedef list ListType; + +class StringList{ + typedef ListType::const_iterator const_iterator; + + private: + ListType m_data; + + public: + StringList(); + StringList(const StringList& sl); + StringList(char** values); + ~StringList(); + + char** toCharArray() const; + void add(const string& value); + size_t size() const; + const_iterator begin() const; + const_iterator end() const; + void clear(); +}; +#endif //STRING_LIST_H -- 2.39.5