Back to index

openldap  2.4.31
LDAPRequest.cpp
Go to the documentation of this file.
00001 // $OpenLDAP$
00002 /*
00003  * Copyright 2000-2012 The OpenLDAP Foundation, All Rights Reserved.
00004  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
00005  */
00006 
00007 
00008 #include "debug.h"
00009 #include "LDAPRequest.h"
00010 
00011 using namespace std;
00012 
00013 LDAPRequest::LDAPRequest(){
00014     DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPRequest::LDAPRequest()" << endl);
00015 }
00016 
00017 LDAPRequest::LDAPRequest(const LDAPRequest& req){
00018     DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPRequest::LDAPRequest(&)" << endl);
00019     m_isReferral=req.m_isReferral;
00020     m_cons = new LDAPConstraints(*(req.m_cons));
00021     m_connection = req.m_connection;
00022     m_parent = req.m_parent;
00023     m_hopCount = req.m_hopCount;
00024     m_msgID = req.m_msgID;
00025 }
00026 
00027 LDAPRequest::LDAPRequest(LDAPAsynConnection* con, 
00028        const LDAPConstraints* cons,bool isReferral, const LDAPRequest* parent){
00029     DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPRequest::LDAPRequest()" << endl);
00030     m_connection=con;
00031     if(cons == 0){
00032         m_cons=new LDAPConstraints( *(con->getConstraints()) );
00033     }else{
00034         m_cons=new LDAPConstraints( *cons);
00035     }
00036     m_isReferral=isReferral; 
00037     if(m_isReferral){
00038         m_hopCount = (parent->getHopCount()+1);
00039         m_parent= parent;
00040     }else{
00041         m_hopCount=0;
00042         m_parent=0;
00043     }
00044 }
00045 
00046 LDAPRequest::~LDAPRequest(){
00047     DEBUG(LDAP_DEBUG_DESTROY,"LDAPRequest::~LDAPRequest()" << endl);
00048     delete m_cons;
00049 }
00050 
00051 LDAPMsg* LDAPRequest::getNextMessage() const 
00052 {
00053     DEBUG(LDAP_DEBUG_DESTROY,"LDAPRequest::getNextMessage()" << endl);
00054     int res;
00055     LDAPMessage *msg;
00056 
00057     res=ldap_result(this->m_connection->getSessionHandle(),
00058             this->m_msgID,0,0,&msg);
00059 
00060     if (res <= 0){
00061         if(msg != 0){
00062             ldap_msgfree(msg);
00063         }
00064         throw  LDAPException(this->m_connection);
00065     }else{    
00066         LDAPMsg *ret=0;
00067         //this can  throw an exception (Decoding Error)
00068         ret = LDAPMsg::create(this,msg);
00069         ldap_msgfree(msg);
00070         return ret;
00071     }
00072 }
00073 
00074 LDAPRequest* LDAPRequest::followReferral(LDAPMsg* /*urls*/){
00075     DEBUG(LDAP_DEBUG_TRACE,"LDAPBindRequest::followReferral()" << endl);
00076     DEBUG(LDAP_DEBUG_TRACE,
00077             "ReferralChasing not implemented for this operation" << endl);
00078     return 0;
00079 }
00080 
00081 const LDAPConstraints* LDAPRequest::getConstraints() const{
00082     DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getConstraints()" << endl);
00083     return m_cons;
00084 }
00085 
00086 const LDAPAsynConnection* LDAPRequest::getConnection() const{
00087     DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getConnection()" << endl);
00088     return m_connection;
00089 }
00090 
00091 int LDAPRequest::getType() const {
00092     DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getType()" << endl);
00093     return m_requestType;
00094 }
00095 
00096 int LDAPRequest::getMsgID() const {
00097     DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getMsgId()" << endl);
00098     return m_msgID;
00099 }
00100 
00101 int LDAPRequest::getHopCount() const {
00102     DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getHopCount()" << endl);
00103     return m_hopCount;
00104 }
00105 
00106 const LDAPRequest* LDAPRequest::getParent() const{
00107     DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getParent()" << endl);
00108     return m_parent;
00109 }
00110 
00111 bool LDAPRequest::isReferral() const {
00112     DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::isReferral()" << endl);
00113     return m_isReferral;
00114 }
00115 
00116 bool LDAPRequest::equals(const LDAPRequest* req) const{
00117     DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::equals()" << endl);
00118     if( (this->m_requestType == req->getType()) && 
00119         (this->m_connection->getHost() == req->m_connection->getHost()) && 
00120         (this->m_connection->getPort() == req->m_connection->getPort())
00121       ){
00122         return true;
00123     }return false;        
00124 }
00125 
00126 bool LDAPRequest::isCycle() const{
00127     DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::isCycle()" << endl);
00128     const LDAPRequest* parent=m_parent;
00129     if(parent != 0){
00130         do{
00131             if(this->equals(parent)){
00132                 return true;
00133             }else{
00134                 parent=parent->getParent();
00135             }
00136         }
00137         while(parent != 0);
00138     }
00139     return false;
00140 }
00141 
00142 void LDAPRequest::unbind() const{
00143     DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::unbind()" << endl);
00144     m_connection->unbind();
00145 }