Back to index

openldap  2.4.31
LDAPModDNRequest.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 "LDAPModDNRequest.h"
00012 #include "LDAPException.h"
00013 #include "LDAPResult.h"
00014 #include "LDAPUrlList.h"
00015 
00016 using namespace std;
00017 
00018 LDAPModDNRequest::LDAPModDNRequest(const LDAPModDNRequest& req) :
00019         LDAPRequest(req){
00020     DEBUG(LDAP_DEBUG_CONSTRUCT, 
00021             "LDAPModDNRequest::LDAPModDNRequest(&)" << endl);
00022     m_dn = req.m_dn;
00023     m_newRDN = req.m_newRDN;
00024     m_newParentDN = req.m_newParentDN;
00025     m_deleteOld = req.m_deleteOld;
00026 }
00027 
00028 LDAPModDNRequest::LDAPModDNRequest(const string& dn, const string& newRDN, 
00029         bool deleteOld, const string& newParentDN, 
00030         LDAPAsynConnection *connect, 
00031         const LDAPConstraints *cons, bool isReferral, 
00032         const LDAPRequest* parent):
00033         LDAPRequest(connect, cons, isReferral, parent){
00034     DEBUG(LDAP_DEBUG_CONSTRUCT, 
00035             "LDAPModDNRequest::LDAPModDNRequest(&)" << endl);
00036     DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER, 
00037             "   dn:" << dn << endl << "   newRDN:" << newRDN << endl
00038             << "   deleteOld:" << deleteOld << endl 
00039             << "   newParent:" << newParentDN << endl);
00040     m_dn = dn;
00041     m_newRDN = newRDN;
00042     m_newParentDN = newParentDN;
00043     m_deleteOld=deleteOld;
00044 }
00045 
00046 LDAPModDNRequest::~LDAPModDNRequest(){
00047     DEBUG(LDAP_DEBUG_DESTROY, "LDAPModDNRequest::~LDAPModDNRequest()" << endl);
00048 }
00049 
00050 LDAPMessageQueue* LDAPModDNRequest::sendRequest(){
00051     DEBUG(LDAP_DEBUG_TRACE, "LDAPModDNRequest::sendRequest()" << endl);
00052     int msg_id;
00053     const char* newRDN = (m_newRDN == "" ? 0 :m_newRDN.c_str());
00054     const char* newParentDN = (m_newParentDN == "" ? 
00055             0 :
00056             m_newParentDN.c_str());
00057     LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray();
00058     LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
00059     int err=ldap_rename(m_connection->getSessionHandle(),m_dn.c_str(),newRDN,
00060             newParentDN,m_deleteOld ? 1 : 0, tmpSrvCtrls, tmpClCtrls,&msg_id);
00061     LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
00062     LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
00063     if(err!=LDAP_SUCCESS){
00064         throw LDAPException(err);
00065     }else{
00066         m_msgID=msg_id;
00067         return new LDAPMessageQueue(this);
00068     }
00069 }
00070 
00071 LDAPRequest* LDAPModDNRequest::followReferral(LDAPMsg* ref){
00072     DEBUG(LDAP_DEBUG_TRACE, "LDAPModifyRequest::followReferral()" << endl);
00073     LDAPUrlList::const_iterator usedUrl;
00074     LDAPUrlList urls = ((LDAPResult*)ref)->getReferralUrls();
00075     LDAPAsynConnection* con = 0;
00076     try {
00077         con = getConnection()->referralConnect(urls,usedUrl,m_cons);
00078     } catch(LDAPException e){
00079         delete con;
00080         return 0;
00081     }
00082     if(con != 0){
00083         return new LDAPModDNRequest(m_dn, m_newRDN, m_deleteOld, m_newParentDN,
00084                 con, m_cons,true,this);
00085     }
00086     return 0;
00087 }
00088