Back to index

openldap  2.4.31
LDAPCompareRequest.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 #include <ldap.h>
00008 
00009 #include "debug.h"
00010 
00011 #include "LDAPCompareRequest.h"
00012 #include "LDAPException.h"
00013 #include "LDAPMessageQueue.h"
00014 #include "LDAPResult.h"
00015 
00016 using namespace std;
00017 
00018 LDAPCompareRequest::LDAPCompareRequest(const LDAPCompareRequest& req){
00019     DEBUG(LDAP_DEBUG_CONSTRUCT, 
00020             "LDAPCompareRequest::LDAPCompareRequest(&)" << endl);
00021     m_dn=req.m_dn;
00022     m_attr=req.m_attr;
00023 }
00024 
00025 LDAPCompareRequest::LDAPCompareRequest(const string& dn, 
00026         const LDAPAttribute& attr, LDAPAsynConnection *connect, 
00027         const LDAPConstraints *cons, bool isReferral, 
00028         const LDAPRequest* parent) :
00029         LDAPRequest(connect, cons, isReferral,parent){
00030     DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPCompareRequest::LDAPCompareRequest()" 
00031             << endl);
00032     DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER, "   dn:" << dn << endl 
00033             << "   attr:" << attr << endl);
00034     m_requestType=LDAPRequest::COMPARE;
00035     m_dn=dn;
00036     m_attr=attr;
00037 } 
00038     
00039 LDAPCompareRequest::~LDAPCompareRequest(){
00040     DEBUG(LDAP_DEBUG_DESTROY, "LDAPCompareRequest::~LDAPCompareRequest()" 
00041             << endl);
00042 }
00043 
00044 LDAPMessageQueue* LDAPCompareRequest::sendRequest(){
00045     DEBUG(LDAP_DEBUG_TRACE, "LDAPCompareRequest::sendRequest()" << endl);
00046     int msgID=0;
00047     BerValue **val=m_attr.getBerValues();
00048     LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray(); 
00049     LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray(); 
00050     int err=ldap_compare_ext(m_connection->getSessionHandle(),m_dn.c_str(),
00051             m_attr.getName().c_str(), val[0], tmpSrvCtrls, 
00052             tmpClCtrls, &msgID);
00053     ber_bvecfree(val);
00054     LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
00055     LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
00056     if(err != LDAP_SUCCESS){
00057         throw LDAPException(err);
00058     }else{
00059         m_msgID=msgID;
00060         return new LDAPMessageQueue(this);
00061     }
00062 }
00063 
00064 LDAPRequest* LDAPCompareRequest::followReferral(LDAPMsg* ref){
00065        DEBUG(LDAP_DEBUG_TRACE, "LDAPCompareRequest::followReferral()" << endl);
00066     LDAPUrlList::const_iterator usedUrl;
00067     LDAPUrlList urls = ((LDAPResult*)ref)->getReferralUrls();
00068     LDAPAsynConnection* con = 0;
00069     try{
00070         con=getConnection()->referralConnect(urls,usedUrl,m_cons);
00071     }catch(LDAPException e){
00072         return 0;
00073     }
00074     if(con != 0){
00075         return new LDAPCompareRequest(m_dn, m_attr, con, m_cons, true, this);
00076     }
00077     return 0;
00078 }
00079