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 "LDAPMessage.h"
14 #include "LDAPResult.h"
15 #include "LDAPSearchReference.h"
16 #include "LDAPSearchRequest.h"
18 #include "LDAPUrlList.h"
19 #include "LDAPException.h"
23 // TODO: How to handle unsolicited notifications, like notice of
26 LDAPMessageQueue::LDAPMessageQueue(LDAPRequest *req){
27 DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPMessageQueue::LDAPMessageQueue()" << endl);
28 m_activeReq.push(req);
29 m_issuedReq.push_back(req);
32 LDAPMessageQueue::~LDAPMessageQueue(){
33 DEBUG(LDAP_DEBUG_DESTROY, "LDAPMessageQueue::~LDAPMessageQueue()" << endl);
34 for(LDAPRequestList::iterator i=m_issuedReq.begin();
35 i != m_issuedReq.end(); i++){
42 LDAPMsg *LDAPMessageQueue::getNext(){
43 DEBUG(LDAP_DEBUG_TRACE,"LDAPMessageQueue::getNext()" << endl);
45 LDAPRequest *req=m_activeReq.top();
46 int msg_id = req->getMsgID();
48 const LDAPAsynConnection *con=req->getConnection();
49 res=ldap_result(con->getSessionHandle(),msg_id,0,0,&msg);
54 throw LDAPException(con);
56 const LDAPConstraints *constr=req->getConstraints();
58 //this can throw an exception (Decoding Error)
60 ret = LDAPMsg::create(req,msg);
62 }catch(LDAPException e){
68 switch (ret->getMessageType()) {
69 case LDAPMsg::SEARCH_REFERENCE :
70 if (constr->getReferralChase() ){
71 //throws Exception (limit Exceeded)
72 LDAPRequest *refReq=chaseReferral(ret);
74 m_activeReq.push(refReq);
75 m_issuedReq.push_back(refReq);
82 case LDAPMsg::SEARCH_ENTRY :
85 case LDAPMsg::SEARCH_DONE :
86 if(req->isReferral()){
89 switch ( ((LDAPResult*)ret)->getResultCode()) {
90 case LDAPResult::REFERRAL :
91 if(constr->getReferralChase()){
92 //throws Exception (limit Exceeded)
93 LDAPRequest *refReq=chaseReferral(ret);
96 m_activeReq.push(refReq);
97 m_issuedReq.push_back(refReq);
104 case LDAPResult::SUCCESS :
105 if(req->isReferral()){
120 //must be some kind of LDAPResultMessage
122 if(req->isReferral()){
125 LDAPResult* res_p=(LDAPResult*)ret;
126 switch (res_p->getResultCode()) {
127 case LDAPResult::REFERRAL :
128 if(constr->getReferralChase()){
129 //throws Exception (limit Exceeded)
130 LDAPRequest *refReq=chaseReferral(ret);
133 m_activeReq.push(refReq);
134 m_issuedReq.push_back(refReq);
150 // TODO Maybe moved to LDAPRequest::followReferral seems more reasonable
152 LDAPRequest* LDAPMessageQueue::chaseReferral(LDAPMsg* ref){
153 DEBUG(LDAP_DEBUG_TRACE,"LDAPMessageQueue::chaseReferra()" << endl);
154 LDAPRequest *req=m_activeReq.top();
155 LDAPRequest *refReq=req->followReferral(ref);
157 if(refReq->getConstraints()->getHopLimit() < refReq->getHopCount()){
159 throw LDAPException(LDAP_REFERRAL_LIMIT_EXCEEDED);
161 if(refReq->isCycle()){
163 throw LDAPException(LDAP_CLIENT_LOOP);
166 refReq->sendRequest();
168 }catch (LDAPException e){
169 DEBUG(LDAP_DEBUG_TRACE," caught exception" << endl);
177 LDAPRequestStack* LDAPMessageQueue::getRequestStack(){
178 DEBUG(LDAP_DEBUG_TRACE,"LDAPMessageQueue::getRequestStack()" << endl);