~ttx/openldap/lucid-gssapi-495418

« back to all changes in this revision

Viewing changes to contrib/ldapc++/src/LDAPExtRequest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2008-07-10 14:45:49 UTC
  • Revision ID: james.westby@ubuntu.com-20080710144549-wck73med0e72gfyo
Tags: upstream-2.4.10
ImportĀ upstreamĀ versionĀ 2.4.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2000-2007, OpenLDAP Foundation, All Rights Reserved.
 
3
 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
 
4
 */
 
5
 
 
6
#include <ldap.h>
 
7
#include <lber.h>
 
8
 
 
9
#include "debug.h"
 
10
 
 
11
#include "LDAPExtRequest.h"
 
12
#include "LDAPException.h"
 
13
#include "LDAPResult.h"
 
14
 
 
15
#include <cstdlib>
 
16
 
 
17
using namespace std;
 
18
 
 
19
LDAPExtRequest::LDAPExtRequest(const LDAPExtRequest& req) :
 
20
        LDAPRequest(req){
 
21
    DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPExtRequest::LDAPExtRequest(&)" << endl);
 
22
    m_data=req.m_data;
 
23
    m_oid=req.m_oid;
 
24
}
 
25
 
 
26
LDAPExtRequest::LDAPExtRequest(const string& oid, const string& data, 
 
27
        LDAPAsynConnection *connect, const LDAPConstraints *cons,
 
28
        bool isReferral, const LDAPRequest* parent) 
 
29
        : LDAPRequest(connect, cons, isReferral, parent){
 
30
    DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPExtRequest::LDAPExtRequest()" << endl);
 
31
    DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER, 
 
32
            "   oid:" << oid << endl);
 
33
    m_oid=oid;
 
34
    m_data=data;
 
35
}
 
36
 
 
37
LDAPExtRequest::~LDAPExtRequest(){
 
38
    DEBUG(LDAP_DEBUG_DESTROY, "LDAPExtRequest::~LDAPExtRequest()" << endl);
 
39
}
 
40
 
 
41
LDAPMessageQueue* LDAPExtRequest::sendRequest(){
 
42
    DEBUG(LDAP_DEBUG_TRACE, "LDAPExtRequest::sendRequest()" << endl);
 
43
    int msgID=0;
 
44
    BerValue* tmpdata=0;
 
45
    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
        m_data.copy(tmpdata->bv_val, string::npos);
 
50
    }
 
51
    LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray();
 
52
    LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
 
53
    int err=ldap_extended_operation(m_connection->getSessionHandle(),
 
54
            m_oid.c_str(), tmpdata, tmpSrvCtrls, tmpClCtrls, &msgID);
 
55
    LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
 
56
    LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
 
57
    ber_bvfree(tmpdata);
 
58
    if(err != LDAP_SUCCESS){
 
59
        delete this;
 
60
        throw LDAPException(err);
 
61
    }else{
 
62
        m_msgID=msgID;
 
63
        return new LDAPMessageQueue(this);
 
64
    }
 
65
}
 
66
 
 
67
LDAPRequest* LDAPExtRequest::followReferral(LDAPMsg* ref){
 
68
    DEBUG(LDAP_DEBUG_TRACE, "LDAPExtRequest::followReferral()" << endl);
 
69
    LDAPUrlList::const_iterator usedUrl;
 
70
    LDAPUrlList urls = ((LDAPResult*)ref)->getReferralUrls();
 
71
    LDAPAsynConnection* con = 0;
 
72
    try {
 
73
        con = getConnection()->referralConnect(urls,usedUrl,m_cons);
 
74
    } catch(LDAPException e){
 
75
        delete con;
 
76
        return 0;
 
77
    }
 
78
    if(con != 0){
 
79
        return new LDAPExtRequest(m_oid, m_data, con, m_cons,true,this);
 
80
    }
 
81
    return 0;
 
82
}
 
83
 
 
84