LDAPExtRequest.cpp 2.53 KB
Newer Older
1
/*
Quanah Gibson-Mount's avatar
Quanah Gibson-Mount committed
2
 * Copyright 2000-2018 The OpenLDAP Foundation, All Rights Reserved.
3
4
5
6
7
8
9
10
11
12
 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
 */

#include <ldap.h>
#include <lber.h>

#include "debug.h"

#include "LDAPExtRequest.h"
#include "LDAPException.h"
13
#include "LDAPResult.h"
14

15
16
#include <cstdlib>

17
18
using namespace std;

19
20
LDAPExtRequest::LDAPExtRequest(const LDAPExtRequest& req) :
        LDAPRequest(req){
21
22
23
    DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPExtRequest::LDAPExtRequest(&)" << endl);
    m_data=req.m_data;
    m_oid=req.m_oid;
24
25
}

26
27
28
29
30
31
32
33
34
LDAPExtRequest::LDAPExtRequest(const string& oid, const string& data, 
        LDAPAsynConnection *connect, const LDAPConstraints *cons,
        bool isReferral, const LDAPRequest* parent) 
        : LDAPRequest(connect, cons, isReferral, parent){
    DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPExtRequest::LDAPExtRequest()" << endl);
    DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER, 
            "   oid:" << oid << endl);
    m_oid=oid;
    m_data=data;
35
36
37
}

LDAPExtRequest::~LDAPExtRequest(){
38
    DEBUG(LDAP_DEBUG_DESTROY, "LDAPExtRequest::~LDAPExtRequest()" << endl);
39
40
41
42
43
}

LDAPMessageQueue* LDAPExtRequest::sendRequest(){
    DEBUG(LDAP_DEBUG_TRACE, "LDAPExtRequest::sendRequest()" << endl);
    int msgID=0;
44
45
    BerValue* tmpdata=0;
    if(m_data != ""){
46
        tmpdata=(BerValue*) malloc(sizeof(BerValue));
47
        tmpdata->bv_len = m_data.size();
48
        tmpdata->bv_val = (char*) malloc(sizeof(char) * (m_data.size()) );
49
50
51
52
53
54
        m_data.copy(tmpdata->bv_val, string::npos);
    }
    LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray();
    LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
    int err=ldap_extended_operation(m_connection->getSessionHandle(),
            m_oid.c_str(), tmpdata, tmpSrvCtrls, tmpClCtrls, &msgID);
55
56
    LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
    LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
57
    ber_bvfree(tmpdata);
58
59
60
61
62
63
64
65
66
    if(err != LDAP_SUCCESS){
        delete this;
        throw LDAPException(err);
    }else{
        m_msgID=msgID;
        return new LDAPMessageQueue(this);
    }
}

67
LDAPRequest* LDAPExtRequest::followReferral(LDAPMsg* ref){
68
    DEBUG(LDAP_DEBUG_TRACE, "LDAPExtRequest::followReferral()" << endl);
69
70
71
72
73
74
75
76
77
78
79
80
    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 LDAPExtRequest(m_oid, m_data, con, m_cons,true,this);
    }
81
82
83
    return 0;
}

84