]> git.sur5r.net Git - openldap/blobdiff - contrib/ldapc++/src/LDAPMessageQueue.cpp
Happy New Year (belated)
[openldap] / contrib / ldapc++ / src / LDAPMessageQueue.cpp
index 6d0e614d6f9d39ef2dcb536164bab8eae87e6eee..f9f623cb87695b5a8fdff36ddd7ce2b5d233dde3 100644 (file)
@@ -1,16 +1,14 @@
+// $OpenLDAP$
 /*
- * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 2000-2014 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
 
 #include "config.h"
 #include "debug.h"
-#include <ldap.h>
 #include "LDAPMessageQueue.h"
 #include "LDAPRequest.h"
-#include "LDAPAsynConnection.h"
-#include "LDAPMessage.h"
 #include "LDAPResult.h"
 #include "LDAPSearchReference.h"
 #include "LDAPSearchRequest.h"
@@ -18,6 +16,8 @@
 #include "LDAPUrlList.h"
 #include "LDAPException.h"
 
+using namespace std;
+
 // TODO: How to handle unsolicited notifications, like notice of
 //       disconnection
 
@@ -39,119 +39,108 @@ LDAPMessageQueue::~LDAPMessageQueue(){
 
 LDAPMsg *LDAPMessageQueue::getNext(){
     DEBUG(LDAP_DEBUG_TRACE,"LDAPMessageQueue::getNext()" << endl);
-       LDAPMessage *msg;
+
+    if ( m_activeReq.empty() ) {
+        return 0;
+    }
+
     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
+        m_activeReq.pop();
+        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 :
-                        DEBUG(LDAP_DEBUG_TRACE, 
-                               "referral chasing to be implemented" 
-                                << endl);
-                        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
 //there
 LDAPRequest* LDAPMessageQueue::chaseReferral(LDAPMsg* ref){
-    DEBUG(LDAP_DEBUG_TRACE,"LDAPMessageQueue::chaseReferra()" << endl);
+    DEBUG(LDAP_DEBUG_TRACE,"LDAPMessageQueue::chaseReferral()" << endl);
     LDAPRequest *req=m_activeReq.top();
     LDAPRequest *refReq=req->followReferral(ref);
     if(refReq !=0){