]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/src/LDAPModDNRequest.cpp
Happy New Year
[openldap] / contrib / ldapc++ / src / LDAPModDNRequest.cpp
1 // $OpenLDAP$
2 /*
3  * Copyright 2000-2018 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 "LDAPModDNRequest.h"
12 #include "LDAPException.h"
13 #include "LDAPResult.h"
14 #include "LDAPUrlList.h"
15
16 using namespace std;
17
18 LDAPModDNRequest::LDAPModDNRequest(const LDAPModDNRequest& req) :
19         LDAPRequest(req){
20     DEBUG(LDAP_DEBUG_CONSTRUCT, 
21             "LDAPModDNRequest::LDAPModDNRequest(&)" << endl);
22     m_dn = req.m_dn;
23     m_newRDN = req.m_newRDN;
24     m_newParentDN = req.m_newParentDN;
25     m_deleteOld = req.m_deleteOld;
26 }
27
28 LDAPModDNRequest::LDAPModDNRequest(const string& dn, const string& newRDN, 
29         bool deleteOld, const string& newParentDN, 
30         LDAPAsynConnection *connect, 
31         const LDAPConstraints *cons, bool isReferral, 
32         const LDAPRequest* parent):
33         LDAPRequest(connect, cons, isReferral, parent){
34     DEBUG(LDAP_DEBUG_CONSTRUCT, 
35             "LDAPModDNRequest::LDAPModDNRequest(&)" << endl);
36     DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER, 
37             "   dn:" << dn << endl << "   newRDN:" << newRDN << endl
38             << "   deleteOld:" << deleteOld << endl 
39             << "   newParent:" << newParentDN << endl);
40     m_dn = dn;
41     m_newRDN = newRDN;
42     m_newParentDN = newParentDN;
43     m_deleteOld=deleteOld;
44 }
45
46 LDAPModDNRequest::~LDAPModDNRequest(){
47     DEBUG(LDAP_DEBUG_DESTROY, "LDAPModDNRequest::~LDAPModDNRequest()" << endl);
48 }
49
50 LDAPMessageQueue* LDAPModDNRequest::sendRequest(){
51     DEBUG(LDAP_DEBUG_TRACE, "LDAPModDNRequest::sendRequest()" << endl);
52     int msg_id;
53     const char* newRDN = (m_newRDN == "" ? 0 :m_newRDN.c_str());
54     const char* newParentDN = (m_newParentDN == "" ? 
55             0 :
56             m_newParentDN.c_str());
57     LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray();
58     LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
59     int err=ldap_rename(m_connection->getSessionHandle(),m_dn.c_str(),newRDN,
60             newParentDN,m_deleteOld ? 1 : 0, tmpSrvCtrls, tmpClCtrls,&msg_id);
61     LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
62     LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
63     if(err!=LDAP_SUCCESS){
64         throw LDAPException(err);
65     }else{
66         m_msgID=msg_id;
67         return new LDAPMessageQueue(this);
68     }
69 }
70
71 LDAPRequest* LDAPModDNRequest::followReferral(LDAPMsg* ref){
72     DEBUG(LDAP_DEBUG_TRACE, "LDAPModifyRequest::followReferral()" << endl);
73     LDAPUrlList::const_iterator usedUrl;
74     LDAPUrlList urls = ((LDAPResult*)ref)->getReferralUrls();
75     LDAPAsynConnection* con = 0;
76     try {
77         con = getConnection()->referralConnect(urls,usedUrl,m_cons);
78     } catch(LDAPException e){
79         delete con;
80         return 0;
81     }
82     if(con != 0){
83         return new LDAPModDNRequest(m_dn, m_newRDN, m_deleteOld, m_newParentDN,
84                 con, m_cons,true,this);
85     }
86     return 0;
87 }
88