| 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 "LDAPModifyRequest.h" |
| 12 |
#include "LDAPException.h" |
| 13 |
#include "LDAPMessageQueue.h" |
| 14 |
#include "LDAPResult.h" |
| 15 |
|
| 16 |
using namespace std; |
| 17 |
|
| 18 |
LDAPModifyRequest::LDAPModifyRequest(const LDAPModifyRequest& req) : |
| 19 |
LDAPRequest(req){ |
| 20 |
DEBUG(LDAP_DEBUG_CONSTRUCT, |
| 21 |
"LDAPModifyRequest::LDAPModifyRequest(&)" << endl); |
| 22 |
m_modList = new LDAPModList(*(req.m_modList)); |
| 23 |
m_dn = req.m_dn; |
| 24 |
} |
| 25 |
|
| 26 |
LDAPModifyRequest::LDAPModifyRequest(const string& dn, |
| 27 |
const LDAPModList *modList, LDAPAsynConnection *connect, |
| 28 |
const LDAPConstraints *cons, bool isReferral, |
| 29 |
const LDAPRequest* parent) : |
| 30 |
LDAPRequest(connect, cons, isReferral, parent){ |
| 31 |
DEBUG(LDAP_DEBUG_CONSTRUCT, |
| 32 |
"LDAPModifyRequest::LDAPModifyRequest(&)" << endl); |
| 33 |
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER, |
| 34 |
" dn:" << dn << endl); |
| 35 |
m_dn = dn; |
| 36 |
m_modList = new LDAPModList(*modList); |
| 37 |
} |
| 38 |
|
| 39 |
LDAPModifyRequest::~LDAPModifyRequest(){ |
| 40 |
DEBUG(LDAP_DEBUG_DESTROY, |
| 41 |
"LDAPModifyRequest::~LDAPModifyRequest()" << endl); |
| 42 |
delete m_modList; |
| 43 |
} |
| 44 |
|
| 45 |
LDAPMessageQueue* LDAPModifyRequest::sendRequest(){ |
| 46 |
DEBUG(LDAP_DEBUG_TRACE, "LDAPModifyRequest::sendRequest()" << endl); |
| 47 |
int msgID=0; |
| 48 |
LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray(); |
| 49 |
LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray(); |
| 50 |
LDAPMod** tmpMods=m_modList->toLDAPModArray(); |
| 51 |
int err=ldap_modify_ext(m_connection->getSessionHandle(),m_dn.c_str(), |
| 52 |
tmpMods, tmpSrvCtrls, tmpClCtrls,&msgID); |
| 53 |
LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls); |
| 54 |
LDAPControlSet::freeLDAPControlArray(tmpClCtrls); |
| 55 |
ldap_mods_free(tmpMods,1); |
| 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* LDAPModifyRequest::followReferral(LDAPMsg* ref){ |
| 65 |
DEBUG(LDAP_DEBUG_TRACE, "LDAPModifyRequest::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 |
delete con; |
| 73 |
return 0; |
| 74 |
} |
| 75 |
if(con != 0){ |
| 76 |
return new LDAPModifyRequest(m_dn, m_modList, con, m_cons,true,this); |
| 77 |
} |
| 78 |
return 0; |
| 79 |
} |
| 80 |
|
| 81 |
|