3 * Copyright 2000-2011 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include "LDAPMessageQueue.h"
11 #include "LDAPRequest.h"
12 #include "LDAPResult.h"
13 #include "LDAPSearchReference.h"
14 #include "LDAPSearchRequest.h"
16 #include "LDAPUrlList.h"
17 #include "LDAPException.h"
21 // TODO: How to handle unsolicited notifications, like notice of
24 LDAPMessageQueue::LDAPMessageQueue(LDAPRequest *req){
25 DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPMessageQueue::LDAPMessageQueue()" << endl);
26 m_activeReq.push(req);
27 m_issuedReq.push_back(req);
30 LDAPMessageQueue::~LDAPMessageQueue(){
31 DEBUG(LDAP_DEBUG_DESTROY, "LDAPMessageQueue::~LDAPMessageQueue()" << endl);
32 for(LDAPRequestList::iterator i=m_issuedReq.begin();
33 i != m_issuedReq.end(); i++){
40 LDAPMsg *LDAPMessageQueue::getNext(){
41 DEBUG(LDAP_DEBUG_TRACE,"LDAPMessageQueue::getNext()" << endl);
43 if ( m_activeReq.empty() ) {
47 LDAPRequest *req=m_activeReq.top();
51 ret = req->getNextMessage();
52 }catch(LDAPException e){
58 const LDAPConstraints *constr=req->getConstraints();
59 switch (ret->getMessageType()) {
60 case LDAPMsg::SEARCH_REFERENCE :
61 if (constr->getReferralChase() ){
62 //throws Exception (limit Exceeded)
63 LDAPRequest *refReq=chaseReferral(ret);
65 m_activeReq.push(refReq);
66 m_issuedReq.push_back(refReq);
73 case LDAPMsg::SEARCH_ENTRY :
76 case LDAPMsg::SEARCH_DONE :
77 if(req->isReferral()){
80 switch ( ((LDAPResult*)ret)->getResultCode()) {
81 case LDAPResult::REFERRAL :
82 if(constr->getReferralChase()){
83 //throws Exception (limit Exceeded)
84 LDAPRequest *refReq=chaseReferral(ret);
87 m_activeReq.push(refReq);
88 m_issuedReq.push_back(refReq);
95 case LDAPResult::SUCCESS :
96 if(req->isReferral()){
111 //must be some kind of LDAPResultMessage
113 if(req->isReferral()){
116 LDAPResult* res_p=(LDAPResult*)ret;
117 switch (res_p->getResultCode()) {
118 case LDAPResult::REFERRAL :
119 if(constr->getReferralChase()){
120 //throws Exception (limit Exceeded)
121 LDAPRequest *refReq=chaseReferral(ret);
124 m_activeReq.push(refReq);
125 m_issuedReq.push_back(refReq);
140 // TODO Maybe moved to LDAPRequest::followReferral seems more reasonable
142 LDAPRequest* LDAPMessageQueue::chaseReferral(LDAPMsg* ref){
143 DEBUG(LDAP_DEBUG_TRACE,"LDAPMessageQueue::chaseReferral()" << endl);
144 LDAPRequest *req=m_activeReq.top();
145 LDAPRequest *refReq=req->followReferral(ref);
147 if(refReq->getConstraints()->getHopLimit() < refReq->getHopCount()){
149 throw LDAPException(LDAP_REFERRAL_LIMIT_EXCEEDED);
151 if(refReq->isCycle()){
153 throw LDAPException(LDAP_CLIENT_LOOP);
156 refReq->sendRequest();
158 }catch (LDAPException e){
159 DEBUG(LDAP_DEBUG_TRACE," caught exception" << endl);
167 LDAPRequestStack* LDAPMessageQueue::getRequestStack(){
168 DEBUG(LDAP_DEBUG_TRACE,"LDAPMessageQueue::getRequestStack()" << endl);