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