summaryrefslogtreecommitdiffstats
path: root/contrib/ldapc++/src/LDAPModDNRequest.cpp
blob: c81484a9fc07752f387bfbf975121b65d08b0b93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// $OpenLDAP$
/*
 * Copyright 2000-2022 The OpenLDAP Foundation, All Rights Reserved.
 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
 */

#include <ldap.h>

#include "debug.h"

#include "LDAPModDNRequest.h"
#include "LDAPException.h"
#include "LDAPResult.h"
#include "LDAPUrlList.h"

using namespace std;

LDAPModDNRequest::LDAPModDNRequest(const LDAPModDNRequest& req) :
        LDAPRequest(req){
    DEBUG(LDAP_DEBUG_CONSTRUCT, 
            "LDAPModDNRequest::LDAPModDNRequest(&)" << endl);
    m_dn = req.m_dn;
    m_newRDN = req.m_newRDN;
    m_newParentDN = req.m_newParentDN;
    m_deleteOld = req.m_deleteOld;
}

LDAPModDNRequest::LDAPModDNRequest(const string& dn, const string& newRDN, 
        bool deleteOld, const string& newParentDN, 
        LDAPAsynConnection *connect, 
        const LDAPConstraints *cons, bool isReferral, 
        const LDAPRequest* parent):
        LDAPRequest(connect, cons, isReferral, parent){
    DEBUG(LDAP_DEBUG_CONSTRUCT, 
            "LDAPModDNRequest::LDAPModDNRequest(&)" << endl);
    DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER, 
            "   dn:" << dn << endl << "   newRDN:" << newRDN << endl
            << "   deleteOld:" << deleteOld << endl 
            << "   newParent:" << newParentDN << endl);
    m_dn = dn;
    m_newRDN = newRDN;
    m_newParentDN = newParentDN;
    m_deleteOld=deleteOld;
}

LDAPModDNRequest::~LDAPModDNRequest(){
    DEBUG(LDAP_DEBUG_DESTROY, "LDAPModDNRequest::~LDAPModDNRequest()" << endl);
}

LDAPMessageQueue* LDAPModDNRequest::sendRequest(){
    DEBUG(LDAP_DEBUG_TRACE, "LDAPModDNRequest::sendRequest()" << endl);
    int msg_id;
    const char* newRDN = (m_newRDN == "" ? 0 :m_newRDN.c_str());
    const char* newParentDN = (m_newParentDN == "" ? 
            0 :
            m_newParentDN.c_str());
    LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray();
    LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
    int err=ldap_rename(m_connection->getSessionHandle(),m_dn.c_str(),newRDN,
            newParentDN,m_deleteOld ? 1 : 0, tmpSrvCtrls, tmpClCtrls,&msg_id);
    LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
    LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
    if(err!=LDAP_SUCCESS){
        throw LDAPException(err);
    }else{
        m_msgID=msg_id;
        return new LDAPMessageQueue(this);
    }
}

LDAPRequest* LDAPModDNRequest::followReferral(LDAPMsg* ref){
    DEBUG(LDAP_DEBUG_TRACE, "LDAPModifyRequest::followReferral()" << endl);
    LDAPUrlList::const_iterator usedUrl;
    LDAPUrlList urls = ((LDAPResult*)ref)->getReferralUrls();
    LDAPAsynConnection* con = 0;
    try {
        con = getConnection()->referralConnect(urls,usedUrl,m_cons);
    } catch(LDAPException e){
        delete con;
        return 0;
    }
    if(con != 0){
        return new LDAPModDNRequest(m_dn, m_newRDN, m_deleteOld, m_newParentDN,
                con, m_cons,true,this);
    }
    return 0;
}