| 1 |
// $OpenLDAP$ |
| 2 |
/* |
| 3 |
* Copyright 2000-2024 The OpenLDAP Foundation, All Rights Reserved. |
| 4 |
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <ldap.h> |
| 8 |
|
| 9 |
#include "debug.h" |
| 10 |
|
| 11 |
#include "LDAPCompareRequest.h" |
| 12 |
#include "LDAPException.h" |
| 13 |
#include "LDAPMessageQueue.h" |
| 14 |
#include "LDAPResult.h" |
| 15 |
|
| 16 |
using namespace std; |
| 17 |
|
| 18 |
LDAPCompareRequest::LDAPCompareRequest(const LDAPCompareRequest& req){ |
| 19 |
DEBUG(LDAP_DEBUG_CONSTRUCT, |
| 20 |
"LDAPCompareRequest::LDAPCompareRequest(&)" << endl); |
| 21 |
m_dn=req.m_dn; |
| 22 |
m_attr=req.m_attr; |
| 23 |
} |
| 24 |
|
| 25 |
LDAPCompareRequest::LDAPCompareRequest(const string& dn, |
| 26 |
const LDAPAttribute& attr, LDAPAsynConnection *connect, |
| 27 |
const LDAPConstraints *cons, bool isReferral, |
| 28 |
const LDAPRequest* parent) : |
| 29 |
LDAPRequest(connect, cons, isReferral,parent){ |
| 30 |
DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPCompareRequest::LDAPCompareRequest()" |
| 31 |
<< endl); |
| 32 |
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER, " dn:" << dn << endl |
| 33 |
<< " attr:" << attr << endl); |
| 34 |
m_requestType=LDAPRequest::COMPARE; |
| 35 |
m_dn=dn; |
| 36 |
m_attr=attr; |
| 37 |
} |
| 38 |
|
| 39 |
LDAPCompareRequest::~LDAPCompareRequest(){ |
| 40 |
DEBUG(LDAP_DEBUG_DESTROY, "LDAPCompareRequest::~LDAPCompareRequest()" |
| 41 |
<< endl); |
| 42 |
} |
| 43 |
|
| 44 |
LDAPMessageQueue* LDAPCompareRequest::sendRequest(){ |
| 45 |
DEBUG(LDAP_DEBUG_TRACE, "LDAPCompareRequest::sendRequest()" << endl); |
| 46 |
int msgID=0; |
| 47 |
BerValue **val=m_attr.getBerValues(); |
| 48 |
LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray(); |
| 49 |
LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray(); |
| 50 |
int err=ldap_compare_ext(m_connection->getSessionHandle(),m_dn.c_str(), |
| 51 |
m_attr.getName().c_str(), val[0], tmpSrvCtrls, |
| 52 |
tmpClCtrls, &msgID); |
| 53 |
ber_bvecfree(val); |
| 54 |
LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls); |
| 55 |
LDAPControlSet::freeLDAPControlArray(tmpClCtrls); |
| 56 |
if(err != LDAP_SUCCESS){ |
| 57 |
throw LDAPException(err); |
| 58 |
}else{ |
| 59 |
m_msgID=msgID; |
| 60 |
return new LDAPMessageQueue(this); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
LDAPRequest* LDAPCompareRequest::followReferral(LDAPMsg* ref){ |
| 65 |
DEBUG(LDAP_DEBUG_TRACE, "LDAPCompareRequest::followReferral()" << endl); |
| 66 |
LDAPUrlList::const_iterator usedUrl; |
| 67 |
LDAPUrlList urls = ((LDAPResult*)ref)->getReferralUrls(); |
| 68 |
LDAPAsynConnection* con = 0; |
| 69 |
try{ |
| 70 |
con=getConnection()->referralConnect(urls,usedUrl,m_cons); |
| 71 |
}catch(LDAPException e){ |
| 72 |
return 0; |
| 73 |
} |
| 74 |
if(con != 0){ |
| 75 |
return new LDAPCompareRequest(m_dn, m_attr, con, m_cons, true, this); |
| 76 |
} |
| 77 |
return 0; |
| 78 |
} |
| 79 |
|