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"
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 LDAPRequest *req=m_activeReq.top();
44 int msg_id = req->getMsgID();
46 const LDAPAsynConnection *con=req->getConnection();
47 res=ldap_result(con->getSessionHandle(),msg_id,0,0,&msg);
52 throw LDAPException(con);
54 const LDAPConstraints *constr=req->getConstraints();
56 //this can throw an exception (Decoding Error)
58 ret = LDAPMsg::create(req,msg);
60 }catch(LDAPException e){
66 switch (ret->getMessageType()) {
67 case LDAPMsg::SEARCH_REFERENCE :
68 if (constr->getReferralChase() ){
69 //throws Exception (limit Exceeded)
70 LDAPRequest *refReq=chaseReferral(ret);
72 m_activeReq.push(refReq);
73 m_issuedReq.push_back(refReq);
80 case LDAPMsg::SEARCH_ENTRY :
83 case LDAPMsg::SEARCH_DONE :
84 if(req->isReferral()){
87 switch ( ((LDAPResult*)ret)->getResultCode()) {
88 case LDAPResult::REFERRAL :
89 if(constr->getReferralChase()){
90 //throws Exception (limit Exceeded)
91 LDAPRequest *refReq=chaseReferral(ret);
94 m_activeReq.push(refReq);
95 m_issuedReq.push_back(refReq);
102 case LDAPResult::SUCCESS :
103 if(req->isReferral()){
118 //must be some kind of LDAPResultMessage
120 if(req->isReferral()){
123 LDAPResult* res_p=(LDAPResult*)ret;
124 switch (res_p->getResultCode()) {
125 case LDAPResult::REFERRAL :
126 DEBUG(LDAP_DEBUG_TRACE,
127 "referral chasing to be implemented"
129 if(constr->getReferralChase()){
130 //throws Exception (limit Exceeded)
131 LDAPRequest *refReq=chaseReferral(ret);
134 m_activeReq.push(refReq);
135 m_issuedReq.push_back(refReq);
151 // TODO Maybe moved to LDAPRequest::followReferral seems more reasonable
153 LDAPRequest* LDAPMessageQueue::chaseReferral(LDAPMsg* ref){
154 DEBUG(LDAP_DEBUG_TRACE,"LDAPMessageQueue::chaseReferra()" << endl);
155 LDAPRequest *req=m_activeReq.top();
156 LDAPRequest *refReq=req->followReferral(ref);
158 if(refReq->getConstraints()->getHopLimit() < refReq->getHopCount()){
160 throw LDAPException(LDAP_REFERRAL_LIMIT_EXCEEDED);
162 if(refReq->isCycle()){
164 throw LDAPException(LDAP_CLIENT_LOOP);
167 refReq->sendRequest();
169 }catch (LDAPException e){
170 DEBUG(LDAP_DEBUG_TRACE," caught exception" << endl);
178 LDAPRequestStack* LDAPMessageQueue::getRequestStack(){
179 DEBUG(LDAP_DEBUG_TRACE,"LDAPMessageQueue::getRequestStack()" << endl);