From b52fb10b1363760715d7d4d75d182972ad960cb0 Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Tue, 11 Dec 2007 16:57:21 +0000 Subject: [PATCH] moved ldap_result() code to the LDAPRequest-Class --- contrib/ldapc++/src/LDAPMessageQueue.cpp | 183 +++++++++++------------ contrib/ldapc++/src/LDAPRequest.cpp | 23 +++ contrib/ldapc++/src/LDAPRequest.h | 1 + 3 files changed, 109 insertions(+), 98 deletions(-) diff --git a/contrib/ldapc++/src/LDAPMessageQueue.cpp b/contrib/ldapc++/src/LDAPMessageQueue.cpp index c557479bc9..b7afa50e16 100644 --- a/contrib/ldapc++/src/LDAPMessageQueue.cpp +++ b/contrib/ldapc++/src/LDAPMessageQueue.cpp @@ -6,10 +6,8 @@ #include "config.h" #include "debug.h" -#include #include "LDAPMessageQueue.h" #include "LDAPRequest.h" -#include "LDAPAsynConnection.h" #include "LDAPResult.h" #include "LDAPSearchReference.h" #include "LDAPSearchRequest.h" @@ -40,110 +38,99 @@ LDAPMessageQueue::~LDAPMessageQueue(){ LDAPMsg *LDAPMessageQueue::getNext(){ DEBUG(LDAP_DEBUG_TRACE,"LDAPMessageQueue::getNext()" << endl); - LDAPMessage *msg; + LDAPRequest *req=m_activeReq.top(); - int msg_id = req->getMsgID(); - int res; - const LDAPAsynConnection *con=req->getConnection(); - res=ldap_result(con->getSessionHandle(),msg_id,0,0,&msg); - if (res <= 0){ - if(msg != 0){ - ldap_msgfree(msg); - } - throw LDAPException(con); - }else{ - const LDAPConstraints *constr=req->getConstraints(); - LDAPMsg *ret=0; - //this can throw an exception (Decoding Error) - try{ - ret = LDAPMsg::create(req,msg); - ldap_msgfree(msg); - }catch(LDAPException e){ - //do some clean up - delete req; - m_activeReq.top(); - throw; - } - switch (ret->getMessageType()) { - case LDAPMsg::SEARCH_REFERENCE : - if (constr->getReferralChase() ){ - //throws Exception (limit Exceeded) - LDAPRequest *refReq=chaseReferral(ret); - if(refReq != 0){ - m_activeReq.push(refReq); - m_issuedReq.push_back(refReq); - delete ret; - return getNext(); - } - } - return ret; - break; - case LDAPMsg::SEARCH_ENTRY : - return ret; - break; - case LDAPMsg::SEARCH_DONE : - if(req->isReferral()){ - req->unbind(); + LDAPMsg *ret=0; + + try{ + ret = req->getNextMessage(); + }catch(LDAPException e){ + //do some clean up + delete req; + m_activeReq.top(); + throw; + } + + const LDAPConstraints *constr=req->getConstraints(); + switch (ret->getMessageType()) { + case LDAPMsg::SEARCH_REFERENCE : + if (constr->getReferralChase() ){ + //throws Exception (limit Exceeded) + LDAPRequest *refReq=chaseReferral(ret); + if(refReq != 0){ + m_activeReq.push(refReq); + m_issuedReq.push_back(refReq); + delete ret; + return getNext(); } - switch ( ((LDAPResult*)ret)->getResultCode()) { - case LDAPResult::REFERRAL : - if(constr->getReferralChase()){ - //throws Exception (limit Exceeded) - LDAPRequest *refReq=chaseReferral(ret); - if(refReq != 0){ - m_activeReq.pop(); - m_activeReq.push(refReq); - m_issuedReq.push_back(refReq); - delete ret; - return getNext(); - } - } - return ret; - break; - case LDAPResult::SUCCESS : - if(req->isReferral()){ - delete ret; + } + return ret; + break; + case LDAPMsg::SEARCH_ENTRY : + return ret; + break; + case LDAPMsg::SEARCH_DONE : + if(req->isReferral()){ + req->unbind(); + } + switch ( ((LDAPResult*)ret)->getResultCode()) { + case LDAPResult::REFERRAL : + if(constr->getReferralChase()){ + //throws Exception (limit Exceeded) + LDAPRequest *refReq=chaseReferral(ret); + if(refReq != 0){ m_activeReq.pop(); + m_activeReq.push(refReq); + m_issuedReq.push_back(refReq); + delete ret; return getNext(); - }else{ - m_activeReq.pop(); - return ret; } - break; - default: + } + return ret; + break; + case LDAPResult::SUCCESS : + if(req->isReferral()){ + delete ret; m_activeReq.pop(); - return ret; - break; - } - break; - //must be some kind of LDAPResultMessage - default: - if(req->isReferral()){ - req->unbind(); - } - LDAPResult* res_p=(LDAPResult*)ret; - switch (res_p->getResultCode()) { - case LDAPResult::REFERRAL : - if(constr->getReferralChase()){ - //throws Exception (limit Exceeded) - LDAPRequest *refReq=chaseReferral(ret); - if(refReq != 0){ - m_activeReq.pop(); - m_activeReq.push(refReq); - m_issuedReq.push_back(refReq); - delete ret; - return getNext(); - } - } - return ret; - break; - default: + return getNext(); + }else{ m_activeReq.pop(); return ret; - } - break; - } - } + } + break; + default: + m_activeReq.pop(); + return ret; + break; + } + break; + //must be some kind of LDAPResultMessage + default: + if(req->isReferral()){ + req->unbind(); + } + LDAPResult* res_p=(LDAPResult*)ret; + switch (res_p->getResultCode()) { + case LDAPResult::REFERRAL : + if(constr->getReferralChase()){ + //throws Exception (limit Exceeded) + LDAPRequest *refReq=chaseReferral(ret); + if(refReq != 0){ + m_activeReq.pop(); + m_activeReq.push(refReq); + m_issuedReq.push_back(refReq); + delete ret; + return getNext(); + } + } + return ret; + break; + default: + m_activeReq.pop(); + return ret; + } + break; + } } // TODO Maybe moved to LDAPRequest::followReferral seems more reasonable diff --git a/contrib/ldapc++/src/LDAPRequest.cpp b/contrib/ldapc++/src/LDAPRequest.cpp index 8457b087e3..3ce7b540cb 100644 --- a/contrib/ldapc++/src/LDAPRequest.cpp +++ b/contrib/ldapc++/src/LDAPRequest.cpp @@ -47,6 +47,29 @@ LDAPRequest::~LDAPRequest(){ delete m_cons; } +LDAPMsg* LDAPRequest::getNextMessage() const +{ + DEBUG(LDAP_DEBUG_DESTROY,"LDAPRequest::getNextMessage()" << endl); + int res; + LDAPMessage *msg; + + res=ldap_result(this->m_connection->getSessionHandle(), + this->m_msgID,0,0,&msg); + + if (res <= 0){ + if(msg != 0){ + ldap_msgfree(msg); + } + throw LDAPException(this->m_connection); + }else{ + LDAPMsg *ret=0; + //this can throw an exception (Decoding Error) + ret = LDAPMsg::create(this,msg); + ldap_msgfree(msg); + return ret; + } +} + const LDAPConstraints* LDAPRequest::getConstraints() const{ DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getConstraints()" << endl); return m_cons; diff --git a/contrib/ldapc++/src/LDAPRequest.h b/contrib/ldapc++/src/LDAPRequest.h index 7f3a3a2755..632297828e 100644 --- a/contrib/ldapc++/src/LDAPRequest.h +++ b/contrib/ldapc++/src/LDAPRequest.h @@ -40,6 +40,7 @@ class LDAPRequest{ const LDAPConstraints* getConstraints() const; const LDAPAsynConnection* getConnection() const; + LDAPMsg *getNextMessage() const; int getType()const; int getMsgID() const; int getHopCount() const; -- 2.39.5