2 * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include "LDAPMessageQueue.h"
11 #include "LDAPRequest.h"
12 #include "LDAPAsynConnection.h"
13 #include "LDAPResult.h"
14 #include "LDAPSearchReference.h"
15 #include "LDAPSearchRequest.h"
17 #include "LDAPUrlList.h"
18 #include "LDAPException.h"
22 // TODO: How to handle unsolicited notifications, like notice of
25 LDAPMessageQueue::LDAPMessageQueue(LDAPRequest *req){
26 DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPMessageQueue::LDAPMessageQueue()" << endl);
27 m_activeReq.push(req);
28 m_issuedReq.push_back(req);
31 LDAPMessageQueue::~LDAPMessageQueue(){
32 DEBUG(LDAP_DEBUG_DESTROY, "LDAPMessageQueue::~LDAPMessageQueue()" << endl);
33 for(LDAPRequestList::iterator i=m_issuedReq.begin();
34 i != m_issuedReq.end(); i++){
41 LDAPMsg *LDAPMessageQueue::getNext(){
42 DEBUG(LDAP_DEBUG_TRACE,"LDAPMessageQueue::getNext()" << endl);
44 LDAPRequest *req=m_activeReq.top();
45 int msg_id = req->getMsgID();
47 const LDAPAsynConnection *con=req->getConnection();
48 res=ldap_result(con->getSessionHandle(),msg_id,0,0,&msg);
53 throw LDAPException(con);
55 const LDAPConstraints *constr=req->getConstraints();
57 //this can throw an exception (Decoding Error)
59 ret = LDAPMsg::create(req,msg);
61 }catch(LDAPException e){
67 switch (ret->getMessageType()) {
68 case LDAPMsg::SEARCH_REFERENCE :
69 if (constr->getReferralChase() ){
70 //throws Exception (limit Exceeded)
71 LDAPRequest *refReq=chaseReferral(ret);
73 m_activeReq.push(refReq);
74 m_issuedReq.push_back(refReq);
81 case LDAPMsg::SEARCH_ENTRY :
84 case LDAPMsg::SEARCH_DONE :
85 if(req->isReferral()){
88 switch ( ((LDAPResult*)ret)->getResultCode()) {
89 case LDAPResult::REFERRAL :
90 if(constr->getReferralChase()){
91 //throws Exception (limit Exceeded)
92 LDAPRequest *refReq=chaseReferral(ret);
95 m_activeReq.push(refReq);
96 m_issuedReq.push_back(refReq);
103 case LDAPResult::SUCCESS :
104 if(req->isReferral()){
119 //must be some kind of LDAPResultMessage
121 if(req->isReferral()){
124 LDAPResult* res_p=(LDAPResult*)ret;
125 switch (res_p->getResultCode()) {
126 case LDAPResult::REFERRAL :
127 if(constr->getReferralChase()){
128 //throws Exception (limit Exceeded)
129 LDAPRequest *refReq=chaseReferral(ret);
132 m_activeReq.push(refReq);
133 m_issuedReq.push_back(refReq);
149 // TODO Maybe moved to LDAPRequest::followReferral seems more reasonable
151 LDAPRequest* LDAPMessageQueue::chaseReferral(LDAPMsg* ref){
152 DEBUG(LDAP_DEBUG_TRACE,"LDAPMessageQueue::chaseReferral()" << endl);
153 LDAPRequest *req=m_activeReq.top();
154 LDAPRequest *refReq=req->followReferral(ref);
156 if(refReq->getConstraints()->getHopLimit() < refReq->getHopCount()){
158 throw LDAPException(LDAP_REFERRAL_LIMIT_EXCEEDED);
160 if(refReq->isCycle()){
162 throw LDAPException(LDAP_CLIENT_LOOP);
165 refReq->sendRequest();
167 }catch (LDAPException e){
168 DEBUG(LDAP_DEBUG_TRACE," caught exception" << endl);
176 LDAPRequestStack* LDAPMessageQueue::getRequestStack(){
177 DEBUG(LDAP_DEBUG_TRACE,"LDAPMessageQueue::getRequestStack()" << endl);